Index: webrtc/modules/video_coding/codec_database.cc |
diff --git a/webrtc/modules/video_coding/codec_database.cc b/webrtc/modules/video_coding/codec_database.cc |
index 92ae5d23b5a71ffb33231446036559b0b5323f3f..2f5e7fbc3874451c5e5cfb48bcb163395a6b405f 100644 |
--- a/webrtc/modules/video_coding/codec_database.cc |
+++ b/webrtc/modules/video_coding/codec_database.cc |
@@ -71,6 +71,31 @@ VideoCodecH264 VideoEncoder::GetDefaultH264Settings() { |
return h264_settings; |
} |
+// Create an internal Decoder given a codec type |
+static std::unique_ptr<VCMGenericDecoder> CreateDecoder(VideoCodecType type) { |
+ switch (type) { |
+ case kVideoCodecVP8: |
+ return std::unique_ptr<VCMGenericDecoder>( |
+ new VCMGenericDecoder(VP8Decoder::Create())); |
+ case kVideoCodecVP9: |
+ return std::unique_ptr<VCMGenericDecoder>( |
+ new VCMGenericDecoder(VP9Decoder::Create())); |
+ case kVideoCodecI420: |
+ return std::unique_ptr<VCMGenericDecoder>( |
+ new VCMGenericDecoder(new I420Decoder())); |
+ case kVideoCodecH264: |
+ if (H264Decoder::IsSupported()) { |
+ return std::unique_ptr<VCMGenericDecoder>( |
+ new VCMGenericDecoder(H264Decoder::Create())); |
+ } |
+ break; |
+ default: |
+ break; |
+ } |
+ LOG(LS_WARNING) << "No internal decoder of this type exists."; |
+ return std::unique_ptr<VCMGenericDecoder>(); |
+} |
+ |
VCMDecoderMapItem::VCMDecoderMapItem(VideoCodec* settings, |
int number_of_cores, |
bool require_key_frame) |
@@ -98,13 +123,12 @@ VCMCodecDataBase::VCMCodecDataBase( |
external_encoder_(nullptr), |
internal_source_(false), |
encoded_frame_callback_(encoded_frame_callback), |
- ptr_decoder_(nullptr), |
dec_map_(), |
dec_external_map_() {} |
VCMCodecDataBase::~VCMCodecDataBase() { |
DeleteEncoder(); |
- ReleaseDecoder(ptr_decoder_); |
+ ptr_decoder_.reset(); |
for (auto& kv : dec_map_) |
delete kv.second; |
for (auto& kv : dec_external_map_) |
@@ -400,11 +424,10 @@ bool VCMCodecDataBase::DeregisterExternalDecoder(uint8_t payload_type) { |
// We can't use payload_type to check if the decoder is currently in use, |
// because payload type may be out of date (e.g. before we decode the first |
// frame after RegisterReceiveCodec) |
- if (ptr_decoder_ != nullptr && |
- ptr_decoder_->_decoder == (*it).second->external_decoder_instance) { |
+ if (ptr_decoder_ && |
+ ptr_decoder_->IsSameDecoder((*it).second->external_decoder_instance)) { |
// Release it if it was registered and in use. |
- ReleaseDecoder(ptr_decoder_); |
- ptr_decoder_ = nullptr; |
+ ptr_decoder_.reset(); |
} |
DeregisterReceiveCodec(payload_type); |
delete it->second; |
@@ -464,12 +487,11 @@ VCMGenericDecoder* VCMCodecDataBase::GetDecoder( |
RTC_DCHECK(decoded_frame_callback->UserReceiveCallback()); |
uint8_t payload_type = frame.PayloadType(); |
if (payload_type == receive_codec_.plType || payload_type == 0) { |
- return ptr_decoder_; |
+ return ptr_decoder_.get(); |
} |
// Check for exisitng decoder, if exists - delete. |
if (ptr_decoder_) { |
- ReleaseDecoder(ptr_decoder_); |
- ptr_decoder_ = nullptr; |
+ ptr_decoder_.reset(); |
memset(&receive_codec_, 0, sizeof(VideoCodec)); |
} |
ptr_decoder_ = CreateAndInitDecoder(frame, &receive_codec_); |
@@ -480,36 +502,26 @@ VCMGenericDecoder* VCMCodecDataBase::GetDecoder( |
callback->OnIncomingPayloadType(receive_codec_.plType); |
if (ptr_decoder_->RegisterDecodeCompleteCallback(decoded_frame_callback) < |
0) { |
- ReleaseDecoder(ptr_decoder_); |
- ptr_decoder_ = nullptr; |
+ ptr_decoder_.reset(); |
memset(&receive_codec_, 0, sizeof(VideoCodec)); |
return nullptr; |
} |
- return ptr_decoder_; |
+ return ptr_decoder_.get(); |
} |
-void VCMCodecDataBase::ReleaseDecoder(VCMGenericDecoder* decoder) const { |
- if (decoder) { |
- RTC_DCHECK(decoder->_decoder); |
- decoder->Release(); |
- if (!decoder->External()) { |
- delete decoder->_decoder; |
- } |
- delete decoder; |
- } |
+VCMGenericDecoder* VCMCodecDataBase::GetCurrentDecoder() { |
+ return ptr_decoder_.get(); |
} |
bool VCMCodecDataBase::PrefersLateDecoding() const { |
- if (!ptr_decoder_) |
- return true; |
- return ptr_decoder_->PrefersLateDecoding(); |
+ return ptr_decoder_ ? ptr_decoder_->PrefersLateDecoding() : true; |
} |
bool VCMCodecDataBase::MatchesCurrentResolution(int width, int height) const { |
return send_codec_.width == width && send_codec_.height == height; |
} |
-VCMGenericDecoder* VCMCodecDataBase::CreateAndInitDecoder( |
+std::unique_ptr<VCMGenericDecoder> VCMCodecDataBase::CreateAndInitDecoder( |
const VCMEncodedFrame& frame, |
VideoCodec* new_codec) const { |
uint8_t payload_type = frame.PayloadType(); |
@@ -522,13 +534,13 @@ VCMGenericDecoder* VCMCodecDataBase::CreateAndInitDecoder( |
<< static_cast<int>(payload_type); |
return nullptr; |
} |
- VCMGenericDecoder* ptr_decoder = nullptr; |
+ std::unique_ptr<VCMGenericDecoder> ptr_decoder; |
const VCMExtDecoderMapItem* external_dec_item = |
FindExternalDecoderItem(payload_type); |
if (external_dec_item) { |
// External codec. |
- ptr_decoder = new VCMGenericDecoder( |
- external_dec_item->external_decoder_instance, true); |
+ ptr_decoder.reset(new VCMGenericDecoder( |
+ external_dec_item->external_decoder_instance, true)); |
} else { |
// Create decoder. |
ptr_decoder = CreateDecoder(decoder_item->settings->codecType); |
@@ -547,7 +559,6 @@ VCMGenericDecoder* VCMCodecDataBase::CreateAndInitDecoder( |
} |
if (ptr_decoder->InitDecode(decoder_item->settings.get(), |
decoder_item->number_of_cores) < 0) { |
- ReleaseDecoder(ptr_decoder); |
return nullptr; |
} |
memcpy(new_codec, decoder_item->settings.get(), sizeof(VideoCodec)); |
@@ -561,26 +572,6 @@ void VCMCodecDataBase::DeleteEncoder() { |
ptr_encoder_.reset(); |
} |
-VCMGenericDecoder* VCMCodecDataBase::CreateDecoder(VideoCodecType type) const { |
- switch (type) { |
- case kVideoCodecVP8: |
- return new VCMGenericDecoder(VP8Decoder::Create()); |
- case kVideoCodecVP9: |
- return new VCMGenericDecoder(VP9Decoder::Create()); |
- case kVideoCodecI420: |
- return new VCMGenericDecoder(new I420Decoder()); |
- case kVideoCodecH264: |
- if (H264Decoder::IsSupported()) { |
- return new VCMGenericDecoder(H264Decoder::Create()); |
- } |
- break; |
- default: |
- break; |
- } |
- LOG(LS_WARNING) << "No internal decoder of this type exists."; |
- return nullptr; |
-} |
- |
const VCMDecoderMapItem* VCMCodecDataBase::FindDecoderItem( |
uint8_t payload_type) const { |
DecoderMap::const_iterator it = dec_map_.find(payload_type); |