niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
mikhal@webrtc.org | a2031d5 | 2012-07-31 15:53:44 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/video_coding/generic_decoder.h" |
tommi | 5b7fc8c | 2017-07-05 16:45:57 -0700 | [diff] [blame] | 12 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 13 | #include <stddef.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 14 | |
ilnik | 2edc684 | 2017-07-06 03:06:50 -0700 | [diff] [blame] | 15 | #include <algorithm> |
| 16 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 17 | #include "api/video/video_timing.h" |
| 18 | #include "modules/video_coding/include/video_error_codes.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "rtc_base/checks.h" |
| 20 | #include "rtc_base/logging.h" |
Johannes Kron | 7ddea57 | 2019-09-11 12:00:22 +0200 | [diff] [blame] | 21 | #include "rtc_base/thread.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 22 | #include "rtc_base/time_utils.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 23 | #include "rtc_base/trace_event.h" |
| 24 | #include "system_wrappers/include/clock.h" |
Johannes Kron | 7ddea57 | 2019-09-11 12:00:22 +0200 | [diff] [blame] | 25 | #include "system_wrappers/include/field_trial.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | |
| 27 | namespace webrtc { |
| 28 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 29 | VCMDecodedFrameCallback::VCMDecodedFrameCallback(VCMTiming* timing, |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 +0000 | [diff] [blame] | 30 | Clock* clock) |
Johannes Kron | 7ddea57 | 2019-09-11 12:00:22 +0200 | [diff] [blame] | 31 | : _clock(clock), |
| 32 | _timing(timing), |
| 33 | _timestampMap(kDecoderFrameMemoryLength), |
| 34 | _extra_decode_time("t", absl::nullopt) { |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 35 | ntp_offset_ = |
| 36 | _clock->CurrentNtpInMilliseconds() - _clock->TimeInMilliseconds(); |
Johannes Kron | 7ddea57 | 2019-09-11 12:00:22 +0200 | [diff] [blame] | 37 | |
| 38 | ParseFieldTrial({&_extra_decode_time}, |
| 39 | field_trial::FindFullName("WebRTC-SlowDownDecoder")); |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 40 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 41 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 42 | VCMDecodedFrameCallback::~VCMDecodedFrameCallback() {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | |
stefan@webrtc.org | 06887ae | 2011-10-10 14:17:46 +0000 | [diff] [blame] | 44 | void VCMDecodedFrameCallback::SetUserReceiveCallback( |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 45 | VCMReceiveCallback* receiveCallback) { |
Sebastian Jansson | c01367d | 2019-04-08 15:20:44 +0200 | [diff] [blame] | 46 | RTC_DCHECK(construction_thread_.IsCurrent()); |
tommi | d0a71ba | 2017-03-14 04:16:20 -0700 | [diff] [blame] | 47 | RTC_DCHECK((!_receiveCallback && receiveCallback) || |
| 48 | (_receiveCallback && !receiveCallback)); |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 49 | _receiveCallback = receiveCallback; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 50 | } |
| 51 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 52 | VCMReceiveCallback* VCMDecodedFrameCallback::UserReceiveCallback() { |
tommi | d0a71ba | 2017-03-14 04:16:20 -0700 | [diff] [blame] | 53 | // Called on the decode thread via VCMCodecDataBase::GetDecoder. |
| 54 | // The callback must always have been set before this happens. |
| 55 | RTC_DCHECK(_receiveCallback); |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 56 | return _receiveCallback; |
wuchengli@chromium.org | 0d94c2f | 2013-08-12 14:20:49 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 59 | int32_t VCMDecodedFrameCallback::Decoded(VideoFrame& decodedImage) { |
Per | 327d8ba | 2015-11-10 14:00:27 +0100 | [diff] [blame] | 60 | return Decoded(decodedImage, -1); |
| 61 | } |
| 62 | |
| 63 | int32_t VCMDecodedFrameCallback::Decoded(VideoFrame& decodedImage, |
| 64 | int64_t decode_time_ms) { |
sakal | cc452e1 | 2017-02-09 04:53:45 -0800 | [diff] [blame] | 65 | Decoded(decodedImage, |
Danil Chapovalov | 0040b66 | 2018-06-18 10:48:16 +0200 | [diff] [blame] | 66 | decode_time_ms >= 0 ? absl::optional<int32_t>(decode_time_ms) |
| 67 | : absl::nullopt, |
| 68 | absl::nullopt); |
sakal | cc452e1 | 2017-02-09 04:53:45 -0800 | [diff] [blame] | 69 | return WEBRTC_VIDEO_CODEC_OK; |
| 70 | } |
| 71 | |
| 72 | void VCMDecodedFrameCallback::Decoded(VideoFrame& decodedImage, |
Danil Chapovalov | 0040b66 | 2018-06-18 10:48:16 +0200 | [diff] [blame] | 73 | absl::optional<int32_t> decode_time_ms, |
| 74 | absl::optional<uint8_t> qp) { |
Johannes Kron | 7ddea57 | 2019-09-11 12:00:22 +0200 | [diff] [blame] | 75 | // Wait some extra time to simulate a slow decoder. |
| 76 | if (_extra_decode_time) { |
| 77 | rtc::Thread::SleepMs(_extra_decode_time->ms()); |
| 78 | } |
| 79 | |
tommi | d0a71ba | 2017-03-14 04:16:20 -0700 | [diff] [blame] | 80 | RTC_DCHECK(_receiveCallback) << "Callback must not be null at this point"; |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 81 | TRACE_EVENT_INSTANT1("webrtc", "VCMDecodedFrameCallback::Decoded", |
| 82 | "timestamp", decodedImage.timestamp()); |
| 83 | // TODO(holmer): We should improve this so that we can handle multiple |
| 84 | // callbacks from one call to Decode(). |
Lu Liu | 352314a | 2018-02-21 19:38:59 +0000 | [diff] [blame] | 85 | VCMFrameInformation* frameInfo; |
| 86 | { |
| 87 | rtc::CritScope cs(&lock_); |
| 88 | frameInfo = _timestampMap.Pop(decodedImage.timestamp()); |
| 89 | } |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 90 | |
| 91 | if (frameInfo == NULL) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 92 | RTC_LOG(LS_WARNING) << "Too many frames backed up in the decoder, dropping " |
| 93 | "this one."; |
Johannes Kron | 0c141c5 | 2019-08-26 15:04:43 +0200 | [diff] [blame] | 94 | _receiveCallback->OnDroppedFrames(1); |
sakal | cc452e1 | 2017-02-09 04:53:45 -0800 | [diff] [blame] | 95 | return; |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 96 | } |
| 97 | |
Ilya Nikolaevskiy | 2ebf523 | 2019-05-13 16:13:36 +0200 | [diff] [blame] | 98 | decodedImage.set_ntp_time_ms(frameInfo->ntp_time_ms); |
Chen Xing | f00bf42 | 2019-06-20 10:05:55 +0200 | [diff] [blame] | 99 | decodedImage.set_packet_infos(frameInfo->packet_infos); |
Ilya Nikolaevskiy | 2ebf523 | 2019-05-13 16:13:36 +0200 | [diff] [blame] | 100 | decodedImage.set_rotation(frameInfo->rotation); |
| 101 | |
Johannes Kron | 05f8487 | 2020-01-16 14:09:33 +0100 | [diff] [blame^] | 102 | const Timestamp now = _clock->CurrentTime(); |
| 103 | RTC_DCHECK(frameInfo->decodeStart); |
sakal | cc452e1 | 2017-02-09 04:53:45 -0800 | [diff] [blame] | 104 | if (!decode_time_ms) { |
Johannes Kron | 05f8487 | 2020-01-16 14:09:33 +0100 | [diff] [blame^] | 105 | decode_time_ms = (now - *frameInfo->decodeStart).ms(); |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 106 | } |
Johannes Kron | 05f8487 | 2020-01-16 14:09:33 +0100 | [diff] [blame^] | 107 | _timing->StopDecodeTimer(*decode_time_ms, now.ms()); |
| 108 | decodedImage.set_processing_time({*frameInfo->decodeStart, now}); |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 109 | |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 110 | // Report timing information. |
Benjamin Wright | 3f10ca8 | 2018-12-07 03:45:19 -0800 | [diff] [blame] | 111 | TimingFrameInfo timing_frame_info; |
Ilya Nikolaevskiy | b6c462d | 2018-06-05 15:21:32 +0200 | [diff] [blame] | 112 | if (frameInfo->timing.flags != VideoSendTiming::kInvalid) { |
ilnik | 2edc684 | 2017-07-06 03:06:50 -0700 | [diff] [blame] | 113 | int64_t capture_time_ms = decodedImage.ntp_time_ms() - ntp_offset_; |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 114 | // Convert remote timestamps to local time from ntp timestamps. |
| 115 | frameInfo->timing.encode_start_ms -= ntp_offset_; |
| 116 | frameInfo->timing.encode_finish_ms -= ntp_offset_; |
| 117 | frameInfo->timing.packetization_finish_ms -= ntp_offset_; |
| 118 | frameInfo->timing.pacer_exit_ms -= ntp_offset_; |
| 119 | frameInfo->timing.network_timestamp_ms -= ntp_offset_; |
| 120 | frameInfo->timing.network2_timestamp_ms -= ntp_offset_; |
ilnik | 2edc684 | 2017-07-06 03:06:50 -0700 | [diff] [blame] | 121 | |
| 122 | int64_t sender_delta_ms = 0; |
| 123 | if (decodedImage.ntp_time_ms() < 0) { |
| 124 | // Sender clock is not estimated yet. Make sure that sender times are all |
| 125 | // negative to indicate that. Yet they still should be relatively correct. |
| 126 | sender_delta_ms = |
| 127 | std::max({capture_time_ms, frameInfo->timing.encode_start_ms, |
| 128 | frameInfo->timing.encode_finish_ms, |
| 129 | frameInfo->timing.packetization_finish_ms, |
| 130 | frameInfo->timing.pacer_exit_ms, |
| 131 | frameInfo->timing.network_timestamp_ms, |
| 132 | frameInfo->timing.network2_timestamp_ms}) + |
| 133 | 1; |
| 134 | } |
| 135 | |
ilnik | 2edc684 | 2017-07-06 03:06:50 -0700 | [diff] [blame] | 136 | timing_frame_info.capture_time_ms = capture_time_ms - sender_delta_ms; |
| 137 | timing_frame_info.encode_start_ms = |
| 138 | frameInfo->timing.encode_start_ms - sender_delta_ms; |
| 139 | timing_frame_info.encode_finish_ms = |
| 140 | frameInfo->timing.encode_finish_ms - sender_delta_ms; |
| 141 | timing_frame_info.packetization_finish_ms = |
| 142 | frameInfo->timing.packetization_finish_ms - sender_delta_ms; |
| 143 | timing_frame_info.pacer_exit_ms = |
| 144 | frameInfo->timing.pacer_exit_ms - sender_delta_ms; |
| 145 | timing_frame_info.network_timestamp_ms = |
| 146 | frameInfo->timing.network_timestamp_ms - sender_delta_ms; |
| 147 | timing_frame_info.network2_timestamp_ms = |
| 148 | frameInfo->timing.network2_timestamp_ms - sender_delta_ms; |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Benjamin Wright | 3f10ca8 | 2018-12-07 03:45:19 -0800 | [diff] [blame] | 151 | timing_frame_info.flags = frameInfo->timing.flags; |
Johannes Kron | 05f8487 | 2020-01-16 14:09:33 +0100 | [diff] [blame^] | 152 | timing_frame_info.decode_start_ms = frameInfo->decodeStart->ms(); |
| 153 | timing_frame_info.decode_finish_ms = now.ms(); |
Benjamin Wright | 3f10ca8 | 2018-12-07 03:45:19 -0800 | [diff] [blame] | 154 | timing_frame_info.render_time_ms = frameInfo->renderTimeMs; |
| 155 | timing_frame_info.rtp_timestamp = decodedImage.timestamp(); |
| 156 | timing_frame_info.receive_start_ms = frameInfo->timing.receive_start_ms; |
| 157 | timing_frame_info.receive_finish_ms = frameInfo->timing.receive_finish_ms; |
| 158 | _timing->SetTimingFrameInfo(timing_frame_info); |
| 159 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 160 | decodedImage.set_timestamp_us(frameInfo->renderTimeMs * |
| 161 | rtc::kNumMicrosecsPerMillisec); |
Johannes Kron | bfd343b | 2019-07-01 10:07:50 +0200 | [diff] [blame] | 162 | _receiveCallback->FrameToRender(decodedImage, qp, *decode_time_ms, |
| 163 | frameInfo->content_type); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 166 | void VCMDecodedFrameCallback::OnDecoderImplementationName( |
| 167 | const char* implementation_name) { |
tommi | d0a71ba | 2017-03-14 04:16:20 -0700 | [diff] [blame] | 168 | _receiveCallback->OnDecoderImplementationName(implementation_name); |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 169 | } |
| 170 | |
pbos | 1968d3f | 2015-09-28 08:52:18 -0700 | [diff] [blame] | 171 | void VCMDecodedFrameCallback::Map(uint32_t timestamp, |
| 172 | VCMFrameInformation* frameInfo) { |
Lu Liu | 352314a | 2018-02-21 19:38:59 +0000 | [diff] [blame] | 173 | rtc::CritScope cs(&lock_); |
pbos | 1968d3f | 2015-09-28 08:52:18 -0700 | [diff] [blame] | 174 | _timestampMap.Add(timestamp, frameInfo); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 175 | } |
| 176 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 177 | int32_t VCMDecodedFrameCallback::Pop(uint32_t timestamp) { |
Lu Liu | 352314a | 2018-02-21 19:38:59 +0000 | [diff] [blame] | 178 | rtc::CritScope cs(&lock_); |
| 179 | if (_timestampMap.Pop(timestamp) == NULL) { |
| 180 | return VCM_GENERAL_ERROR; |
| 181 | } |
Johannes Kron | 0c141c5 | 2019-08-26 15:04:43 +0200 | [diff] [blame] | 182 | _receiveCallback->OnDroppedFrames(1); |
Lu Liu | 352314a | 2018-02-21 19:38:59 +0000 | [diff] [blame] | 183 | return VCM_OK; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 184 | } |
| 185 | |
Magnus Jedvert | 46a2765 | 2017-11-13 14:10:02 +0100 | [diff] [blame] | 186 | VCMGenericDecoder::VCMGenericDecoder(std::unique_ptr<VideoDecoder> decoder) |
| 187 | : VCMGenericDecoder(decoder.release(), false /* isExternal */) {} |
| 188 | |
Peter Boström | 187db63 | 2015-12-01 17:20:01 +0100 | [diff] [blame] | 189 | VCMGenericDecoder::VCMGenericDecoder(VideoDecoder* decoder, bool isExternal) |
| 190 | : _callback(NULL), |
| 191 | _frameInfos(), |
| 192 | _nextFrameInfoIdx(0), |
tommi | 5b7fc8c | 2017-07-05 16:45:57 -0700 | [diff] [blame] | 193 | decoder_(decoder), |
Kári Tristan Helgason | 84ccb2d | 2018-08-16 14:35:26 +0200 | [diff] [blame] | 194 | _codecType(kVideoCodecGeneric), |
guidou | c337258 | 2017-04-04 07:16:21 -0700 | [diff] [blame] | 195 | _isExternal(isExternal), |
tommi | 5b7fc8c | 2017-07-05 16:45:57 -0700 | [diff] [blame] | 196 | _last_keyframe_content_type(VideoContentType::UNSPECIFIED) { |
| 197 | RTC_DCHECK(decoder_); |
| 198 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 199 | |
tommi | 5b7fc8c | 2017-07-05 16:45:57 -0700 | [diff] [blame] | 200 | VCMGenericDecoder::~VCMGenericDecoder() { |
| 201 | decoder_->Release(); |
| 202 | if (_isExternal) |
| 203 | decoder_.release(); |
tommi | 058aa71 | 2017-07-15 11:33:35 -0700 | [diff] [blame] | 204 | RTC_DCHECK(_isExternal || decoder_); |
tommi | 5b7fc8c | 2017-07-05 16:45:57 -0700 | [diff] [blame] | 205 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 206 | |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 207 | int32_t VCMGenericDecoder::InitDecode(const VideoCodec* settings, |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 208 | int32_t numberOfCores) { |
| 209 | TRACE_EVENT0("webrtc", "VCMGenericDecoder::InitDecode"); |
| 210 | _codecType = settings->codecType; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 211 | |
tommi | 5b7fc8c | 2017-07-05 16:45:57 -0700 | [diff] [blame] | 212 | return decoder_->InitDecode(settings, numberOfCores); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Johannes Kron | 05f8487 | 2020-01-16 14:09:33 +0100 | [diff] [blame^] | 215 | int32_t VCMGenericDecoder::Decode(const VCMEncodedFrame& frame, Timestamp now) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 216 | TRACE_EVENT1("webrtc", "VCMGenericDecoder::Decode", "timestamp", |
Niels Möller | 2377588 | 2018-08-16 10:24:12 +0200 | [diff] [blame] | 217 | frame.Timestamp()); |
Johannes Kron | 05f8487 | 2020-01-16 14:09:33 +0100 | [diff] [blame^] | 218 | _frameInfos[_nextFrameInfoIdx].decodeStart = now; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 219 | _frameInfos[_nextFrameInfoIdx].renderTimeMs = frame.RenderTimeMs(); |
| 220 | _frameInfos[_nextFrameInfoIdx].rotation = frame.rotation(); |
| 221 | _frameInfos[_nextFrameInfoIdx].timing = frame.video_timing(); |
Ilya Nikolaevskiy | 2ebf523 | 2019-05-13 16:13:36 +0200 | [diff] [blame] | 222 | _frameInfos[_nextFrameInfoIdx].ntp_time_ms = |
| 223 | frame.EncodedImage().ntp_time_ms_; |
Chen Xing | f00bf42 | 2019-06-20 10:05:55 +0200 | [diff] [blame] | 224 | _frameInfos[_nextFrameInfoIdx].packet_infos = frame.PacketInfos(); |
Ilya Nikolaevskiy | 2ebf523 | 2019-05-13 16:13:36 +0200 | [diff] [blame] | 225 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 226 | // Set correctly only for key frames. Thus, use latest key frame |
| 227 | // content type. If the corresponding key frame was lost, decode will fail |
| 228 | // and content type will be ignored. |
Niels Möller | 8f7ce22 | 2019-03-21 15:43:58 +0100 | [diff] [blame] | 229 | if (frame.FrameType() == VideoFrameType::kVideoFrameKey) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 230 | _frameInfos[_nextFrameInfoIdx].content_type = frame.contentType(); |
| 231 | _last_keyframe_content_type = frame.contentType(); |
| 232 | } else { |
| 233 | _frameInfos[_nextFrameInfoIdx].content_type = _last_keyframe_content_type; |
| 234 | } |
Niels Möller | 2377588 | 2018-08-16 10:24:12 +0200 | [diff] [blame] | 235 | _callback->Map(frame.Timestamp(), &_frameInfos[_nextFrameInfoIdx]); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 236 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 237 | _nextFrameInfoIdx = (_nextFrameInfoIdx + 1) % kDecoderFrameMemoryLength; |
| 238 | int32_t ret = decoder_->Decode(frame.EncodedImage(), frame.MissingFrame(), |
Niels Möller | 7aacdd9 | 2019-03-25 09:11:40 +0100 | [diff] [blame] | 239 | frame.RenderTimeMs()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 240 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 241 | _callback->OnDecoderImplementationName(decoder_->ImplementationName()); |
| 242 | if (ret < WEBRTC_VIDEO_CODEC_OK) { |
| 243 | RTC_LOG(LS_WARNING) << "Failed to decode frame with timestamp " |
Niels Möller | 2377588 | 2018-08-16 10:24:12 +0200 | [diff] [blame] | 244 | << frame.Timestamp() << ", error code: " << ret; |
| 245 | _callback->Pop(frame.Timestamp()); |
Lu Liu | 352314a | 2018-02-21 19:38:59 +0000 | [diff] [blame] | 246 | return ret; |
Niels Möller | 9cccf85 | 2018-12-04 11:01:26 +0100 | [diff] [blame] | 247 | } else if (ret == WEBRTC_VIDEO_CODEC_NO_OUTPUT) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 248 | // No output |
Niels Möller | 2377588 | 2018-08-16 10:24:12 +0200 | [diff] [blame] | 249 | _callback->Pop(frame.Timestamp()); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 250 | } |
| 251 | return ret; |
guidou | c337258 | 2017-04-04 07:16:21 -0700 | [diff] [blame] | 252 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 253 | |
Peter Boström | 187db63 | 2015-12-01 17:20:01 +0100 | [diff] [blame] | 254 | int32_t VCMGenericDecoder::RegisterDecodeCompleteCallback( |
| 255 | VCMDecodedFrameCallback* callback) { |
| 256 | _callback = callback; |
tommi | 5b7fc8c | 2017-07-05 16:45:57 -0700 | [diff] [blame] | 257 | return decoder_->RegisterDecodeCompleteCallback(callback); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 258 | } |
| 259 | |
perkj | 796cfaf | 2015-12-10 09:27:38 -0800 | [diff] [blame] | 260 | bool VCMGenericDecoder::PrefersLateDecoding() const { |
tommi | 5b7fc8c | 2017-07-05 16:45:57 -0700 | [diff] [blame] | 261 | return decoder_->PrefersLateDecoding(); |
perkj | 796cfaf | 2015-12-10 09:27:38 -0800 | [diff] [blame] | 262 | } |
| 263 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 264 | } // namespace webrtc |