OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
501 } | 501 } |
502 | 502 |
503 VideoCodecType VCMCodecDataBase::ReceiveCodec() const { | 503 VideoCodecType VCMCodecDataBase::ReceiveCodec() const { |
504 if (!ptr_decoder_) { | 504 if (!ptr_decoder_) { |
505 return kVideoCodecUnknown; | 505 return kVideoCodecUnknown; |
506 } | 506 } |
507 return receive_codec_.codecType; | 507 return receive_codec_.codecType; |
508 } | 508 } |
509 | 509 |
510 VCMGenericDecoder* VCMCodecDataBase::GetDecoder( | 510 VCMGenericDecoder* VCMCodecDataBase::GetDecoder( |
511 uint8_t payload_type, VCMDecodedFrameCallback* decoded_frame_callback) { | 511 const VCMEncodedFrame& frame, |
512 VCMDecodedFrameCallback* decoded_frame_callback) { | |
513 uint8_t payload_type = frame.PayloadType(); | |
512 if (payload_type == receive_codec_.plType || payload_type == 0) { | 514 if (payload_type == receive_codec_.plType || payload_type == 0) { |
513 return ptr_decoder_; | 515 return ptr_decoder_; |
514 } | 516 } |
515 // Check for exisitng decoder, if exists - delete. | 517 // Check for exisitng decoder, if exists - delete. |
516 if (ptr_decoder_) { | 518 if (ptr_decoder_) { |
517 ReleaseDecoder(ptr_decoder_); | 519 ReleaseDecoder(ptr_decoder_); |
518 ptr_decoder_ = NULL; | 520 ptr_decoder_ = NULL; |
519 memset(&receive_codec_, 0, sizeof(VideoCodec)); | 521 memset(&receive_codec_, 0, sizeof(VideoCodec)); |
520 } | 522 } |
521 ptr_decoder_ = CreateAndInitDecoder(payload_type, &receive_codec_); | 523 ptr_decoder_ = CreateAndInitDecoder(frame, &receive_codec_); |
522 if (!ptr_decoder_) { | 524 if (!ptr_decoder_) { |
523 return NULL; | 525 return NULL; |
524 } | 526 } |
525 VCMReceiveCallback* callback = decoded_frame_callback->UserReceiveCallback(); | 527 VCMReceiveCallback* callback = decoded_frame_callback->UserReceiveCallback(); |
526 if (callback) callback->OnIncomingPayloadType(receive_codec_.plType); | 528 if (callback) callback->OnIncomingPayloadType(receive_codec_.plType); |
527 if (ptr_decoder_->RegisterDecodeCompleteCallback(decoded_frame_callback) | 529 if (ptr_decoder_->RegisterDecodeCompleteCallback(decoded_frame_callback) |
528 < 0) { | 530 < 0) { |
529 ReleaseDecoder(ptr_decoder_); | 531 ReleaseDecoder(ptr_decoder_); |
530 ptr_decoder_ = NULL; | 532 ptr_decoder_ = NULL; |
531 memset(&receive_codec_, 0, sizeof(VideoCodec)); | 533 memset(&receive_codec_, 0, sizeof(VideoCodec)); |
(...skipping 19 matching lines...) Expand all Loading... | |
551 if (ext_item == nullptr) | 553 if (ext_item == nullptr) |
552 return true; | 554 return true; |
553 return ext_item->internal_render_timing; | 555 return ext_item->internal_render_timing; |
554 } | 556 } |
555 | 557 |
556 bool VCMCodecDataBase::MatchesCurrentResolution(int width, int height) const { | 558 bool VCMCodecDataBase::MatchesCurrentResolution(int width, int height) const { |
557 return send_codec_.width == width && send_codec_.height == height; | 559 return send_codec_.width == width && send_codec_.height == height; |
558 } | 560 } |
559 | 561 |
560 VCMGenericDecoder* VCMCodecDataBase::CreateAndInitDecoder( | 562 VCMGenericDecoder* VCMCodecDataBase::CreateAndInitDecoder( |
561 uint8_t payload_type, | 563 const VCMEncodedFrame& frame, |
562 VideoCodec* new_codec) const { | 564 VideoCodec* new_codec) const { |
565 uint8_t payload_type = frame.PayloadType(); | |
563 assert(new_codec); | 566 assert(new_codec); |
564 const VCMDecoderMapItem* decoder_item = FindDecoderItem(payload_type); | 567 const VCMDecoderMapItem* decoder_item = FindDecoderItem(payload_type); |
565 if (!decoder_item) { | 568 if (!decoder_item) { |
566 LOG(LS_ERROR) << "Can't find a decoder associated with payload type: " | 569 LOG(LS_ERROR) << "Can't find a decoder associated with payload type: " |
567 << static_cast<int>(payload_type); | 570 << static_cast<int>(payload_type); |
568 return NULL; | 571 return NULL; |
569 } | 572 } |
570 VCMGenericDecoder* ptr_decoder = NULL; | 573 VCMGenericDecoder* ptr_decoder = NULL; |
571 const VCMExtDecoderMapItem* external_dec_item = | 574 const VCMExtDecoderMapItem* external_dec_item = |
572 FindExternalDecoderItem(payload_type); | 575 FindExternalDecoderItem(payload_type); |
573 if (external_dec_item) { | 576 if (external_dec_item) { |
574 // External codec. | 577 // External codec. |
575 ptr_decoder = new VCMGenericDecoder( | 578 ptr_decoder = new VCMGenericDecoder( |
576 *external_dec_item->external_decoder_instance, true); | 579 *external_dec_item->external_decoder_instance, true); |
577 } else { | 580 } else { |
578 // Create decoder. | 581 // Create decoder. |
579 ptr_decoder = CreateDecoder(decoder_item->settings->codecType); | 582 ptr_decoder = CreateDecoder(decoder_item->settings->codecType); |
580 } | 583 } |
581 if (!ptr_decoder) | 584 if (!ptr_decoder) |
582 return NULL; | 585 return NULL; |
583 | 586 |
587 // Copy over input resolutions to prevent codec reinitialization due to | |
588 // the first frame being of a different resolution than the database values. | |
589 // This is best effort, since there's no guarantee that width/height have been | |
590 // parsed yet (and may be zero). | |
591 if (frame.EncodedImage()._encodedWidth > 0 && | |
592 frame.EncodedImage()._encodedHeight > 0) { | |
593 decoder_item->settings->width = frame.EncodedImage()._encodedWidth; | |
594 decoder_item->settings->height = frame.EncodedImage()._encodedHeight; | |
595 } | |
584 if (ptr_decoder->InitDecode(decoder_item->settings.get(), | 596 if (ptr_decoder->InitDecode(decoder_item->settings.get(), |
585 decoder_item->number_of_cores) < 0) { | 597 decoder_item->number_of_cores) < 0) { |
586 ReleaseDecoder(ptr_decoder); | 598 ReleaseDecoder(ptr_decoder); |
587 return NULL; | 599 return nullptr; |
mflodman
2015/11/27 09:20:21
I'd prefer to use NULL or nullptr, not mix both in
pbos-webrtc
2015/11/27 13:23:40
Done.
| |
588 } | 600 } |
589 memcpy(new_codec, decoder_item->settings.get(), sizeof(VideoCodec)); | 601 memcpy(new_codec, decoder_item->settings.get(), sizeof(VideoCodec)); |
590 return ptr_decoder; | 602 return ptr_decoder; |
591 } | 603 } |
592 | 604 |
593 void VCMCodecDataBase::DeleteEncoder() { | 605 void VCMCodecDataBase::DeleteEncoder() { |
594 if (!ptr_encoder_) | 606 if (!ptr_encoder_) |
595 return; | 607 return; |
596 ptr_encoder_->Release(); | 608 ptr_encoder_->Release(); |
597 ptr_encoder_.reset(); | 609 ptr_encoder_.reset(); |
(...skipping 30 matching lines...) Expand all Loading... | |
628 | 640 |
629 const VCMExtDecoderMapItem* VCMCodecDataBase::FindExternalDecoderItem( | 641 const VCMExtDecoderMapItem* VCMCodecDataBase::FindExternalDecoderItem( |
630 uint8_t payload_type) const { | 642 uint8_t payload_type) const { |
631 ExternalDecoderMap::const_iterator it = dec_external_map_.find(payload_type); | 643 ExternalDecoderMap::const_iterator it = dec_external_map_.find(payload_type); |
632 if (it != dec_external_map_.end()) { | 644 if (it != dec_external_map_.end()) { |
633 return (*it).second; | 645 return (*it).second; |
634 } | 646 } |
635 return NULL; | 647 return NULL; |
636 } | 648 } |
637 } // namespace webrtc | 649 } // namespace webrtc |
OLD | NEW |