From 79aab3ff51105d7ef38152e27cfcdb513313a6db Mon Sep 17 00:00:00 2001 From: philipel Date: Mon, 26 Mar 2018 14:31:23 +0200 Subject: [PATCH] VideoStreamDecoderImpl implementation, part 2. In this CL the GetDecoder support function is implemented. It will be called from the (not yet existing) Decode function whenever a frame is about to be decoded in order to get the correct decoder for the current frame. Bug: webrtc:8909 Change-Id: I35e40c108fb652d566b1a5fdff60a703f5615406 Reviewed-on: https://webrtc-review.googlesource.com/64448 Reviewed-by: Niels Moller Reviewed-by: Stefan Holmer Commit-Queue: Philip Eliasson Cr-Commit-Position: refs/heads/master@{#22627} --- video/video_stream_decoder_impl.cc | 44 ++++++++++++++++++++++++++++++ video/video_stream_decoder_impl.h | 5 ++++ 2 files changed, 49 insertions(+) diff --git a/video/video_stream_decoder_impl.cc b/video/video_stream_decoder_impl.cc index fc164901a9..3a9751e67f 100644 --- a/video/video_stream_decoder_impl.cc +++ b/video/video_stream_decoder_impl.cc @@ -67,4 +67,48 @@ void VideoStreamDecoderImpl::OnFrame( } } +VideoDecoder* VideoStreamDecoderImpl::GetDecoder(int payload_type) { + if (current_payload_type_ == payload_type) { + RTC_DCHECK(decoder_); + return decoder_.get(); + } + + current_payload_type_.reset(); + decoder_.reset(); + + auto decoder_settings_it = decoder_settings_.find(payload_type); + if (decoder_settings_it == decoder_settings_.end()) { + RTC_LOG(LS_WARNING) << "Payload type " << payload_type + << " not registered."; + return nullptr; + } + + const SdpVideoFormat& video_format = decoder_settings_it->second.first; + std::unique_ptr decoder = + decoder_factory_->CreateVideoDecoder(video_format); + if (!decoder) { + RTC_LOG(LS_WARNING) << "Failed to create decoder for payload type " + << payload_type << "."; + return nullptr; + } + + int num_cores = decoder_settings_it->second.second; + int32_t init_result = decoder->InitDecode(nullptr, num_cores); + if (init_result != WEBRTC_VIDEO_CODEC_OK) { + RTC_LOG(LS_WARNING) << "Failed to initialize decoder for payload type " + << payload_type << "."; + return nullptr; + } + + int32_t register_result = decoder->RegisterDecodeCompleteCallback(this); + if (register_result != WEBRTC_VIDEO_CODEC_OK) { + RTC_LOG(LS_WARNING) << "Failed to register decode callback."; + return nullptr; + } + + current_payload_type_.emplace(payload_type); + decoder_ = std::move(decoder); + return decoder_.get(); +} + } // namespace webrtc diff --git a/video/video_stream_decoder_impl.h b/video/video_stream_decoder_impl.h index 97de050104..55751764ef 100644 --- a/video/video_stream_decoder_impl.h +++ b/video/video_stream_decoder_impl.h @@ -15,6 +15,7 @@ #include #include +#include "api/optional.h" #include "api/video/video_stream_decoder.h" #include "modules/video_coding/frame_buffer2.h" #include "modules/video_coding/jitter_estimator.h" @@ -38,6 +39,8 @@ class VideoStreamDecoderImpl : public VideoStreamDecoder, void OnFrame(std::unique_ptr frame) override; private: + VideoDecoder* GetDecoder(int payload_type); + // Implements DecodedImageCallback interface int32_t Decoded(VideoFrame& decodedImage) override; int32_t Decoded(VideoFrame& decodedImage, int64_t decode_time_ms) override; @@ -60,6 +63,8 @@ class VideoStreamDecoderImpl : public VideoStreamDecoder, VCMTiming timing_; video_coding::FrameBuffer frame_buffer_; video_coding::VideoLayerFrameId last_continuous_id_; + rtc::Optional current_payload_type_; + std::unique_ptr decoder_; }; } // namespace webrtc