Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: webrtc/modules/video_coding/generic_decoder.cc

Issue 2744013002: Updates to VCMDecodedFrameCallback, VideoReceiver and a few related classes/tests. (Closed)
Patch Set: Address comments and replace a few assert calls with RTC_DCHECK Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 #include "webrtc/base/checks.h" 11 #include "webrtc/base/checks.h"
12 #include "webrtc/base/logging.h" 12 #include "webrtc/base/logging.h"
13 #include "webrtc/base/trace_event.h" 13 #include "webrtc/base/trace_event.h"
14 #include "webrtc/modules/video_coding/include/video_coding.h" 14 #include "webrtc/modules/video_coding/include/video_coding.h"
15 #include "webrtc/modules/video_coding/generic_decoder.h" 15 #include "webrtc/modules/video_coding/generic_decoder.h"
16 #include "webrtc/modules/video_coding/internal_defines.h" 16 #include "webrtc/modules/video_coding/internal_defines.h"
17 #include "webrtc/system_wrappers/include/clock.h" 17 #include "webrtc/system_wrappers/include/clock.h"
18 18
19 namespace webrtc { 19 namespace webrtc {
20 20
21 VCMDecodedFrameCallback::VCMDecodedFrameCallback(VCMTiming* timing, 21 VCMDecodedFrameCallback::VCMDecodedFrameCallback(VCMTiming* timing,
22 Clock* clock) 22 Clock* clock)
23 : _critSect(CriticalSectionWrapper::CreateCriticalSection()), 23 : _clock(clock),
24 _clock(clock),
25 _receiveCallback(NULL),
26 _timing(timing), 24 _timing(timing),
27 _timestampMap(kDecoderFrameMemoryLength), 25 _timestampMap(kDecoderFrameMemoryLength),
28 _lastReceivedPictureID(0) {} 26 _lastReceivedPictureID(0) {}
29 27
30 VCMDecodedFrameCallback::~VCMDecodedFrameCallback() { 28 VCMDecodedFrameCallback::~VCMDecodedFrameCallback() {
31 delete _critSect;
32 } 29 }
33 30
34 void VCMDecodedFrameCallback::SetUserReceiveCallback( 31 void VCMDecodedFrameCallback::SetUserReceiveCallback(
35 VCMReceiveCallback* receiveCallback) { 32 VCMReceiveCallback* receiveCallback) {
36 CriticalSectionScoped cs(_critSect); 33 RTC_DCHECK(construction_thread_.CalledOnValidThread());
34 RTC_DCHECK((!_receiveCallback && receiveCallback) ||
35 (_receiveCallback && !receiveCallback));
37 _receiveCallback = receiveCallback; 36 _receiveCallback = receiveCallback;
38 } 37 }
39 38
40 VCMReceiveCallback* VCMDecodedFrameCallback::UserReceiveCallback() { 39 VCMReceiveCallback* VCMDecodedFrameCallback::UserReceiveCallback() {
41 CriticalSectionScoped cs(_critSect); 40 // Called on the decode thread via VCMCodecDataBase::GetDecoder.
41 // The callback must always have been set before this happens.
42 RTC_DCHECK(_receiveCallback);
42 return _receiveCallback; 43 return _receiveCallback;
43 } 44 }
44 45
45 int32_t VCMDecodedFrameCallback::Decoded(VideoFrame& decodedImage) { 46 int32_t VCMDecodedFrameCallback::Decoded(VideoFrame& decodedImage) {
46 return Decoded(decodedImage, -1); 47 return Decoded(decodedImage, -1);
47 } 48 }
48 49
49 int32_t VCMDecodedFrameCallback::Decoded(VideoFrame& decodedImage, 50 int32_t VCMDecodedFrameCallback::Decoded(VideoFrame& decodedImage,
50 int64_t decode_time_ms) { 51 int64_t decode_time_ms) {
51 Decoded(decodedImage, 52 Decoded(decodedImage,
52 decode_time_ms >= 0 ? rtc::Optional<int32_t>(decode_time_ms) 53 decode_time_ms >= 0 ? rtc::Optional<int32_t>(decode_time_ms)
53 : rtc::Optional<int32_t>(), 54 : rtc::Optional<int32_t>(),
54 rtc::Optional<uint8_t>()); 55 rtc::Optional<uint8_t>());
55 return WEBRTC_VIDEO_CODEC_OK; 56 return WEBRTC_VIDEO_CODEC_OK;
56 } 57 }
57 58
58 void VCMDecodedFrameCallback::Decoded(VideoFrame& decodedImage, 59 void VCMDecodedFrameCallback::Decoded(VideoFrame& decodedImage,
59 rtc::Optional<int32_t> decode_time_ms, 60 rtc::Optional<int32_t> decode_time_ms,
60 rtc::Optional<uint8_t> qp) { 61 rtc::Optional<uint8_t> qp) {
62 RTC_DCHECK(_receiveCallback) << "Callback must not be null at this point";
61 TRACE_EVENT_INSTANT1("webrtc", "VCMDecodedFrameCallback::Decoded", 63 TRACE_EVENT_INSTANT1("webrtc", "VCMDecodedFrameCallback::Decoded",
62 "timestamp", decodedImage.timestamp()); 64 "timestamp", decodedImage.timestamp());
63 // TODO(holmer): We should improve this so that we can handle multiple 65 // TODO(holmer): We should improve this so that we can handle multiple
64 // callbacks from one call to Decode(). 66 // callbacks from one call to Decode().
65 VCMFrameInformation* frameInfo; 67 VCMFrameInformation* frameInfo;
66 VCMReceiveCallback* callback;
67 { 68 {
68 CriticalSectionScoped cs(_critSect); 69 rtc::CritScope cs(&lock_);
69 frameInfo = _timestampMap.Pop(decodedImage.timestamp()); 70 frameInfo = _timestampMap.Pop(decodedImage.timestamp());
70 callback = _receiveCallback;
71 } 71 }
72 72
73 if (frameInfo == NULL) { 73 if (frameInfo == NULL) {
74 LOG(LS_WARNING) << "Too many frames backed up in the decoder, dropping " 74 LOG(LS_WARNING) << "Too many frames backed up in the decoder, dropping "
75 "this one."; 75 "this one.";
76 return; 76 return;
77 } 77 }
78 78
79 const int64_t now_ms = _clock->TimeInMilliseconds(); 79 const int64_t now_ms = _clock->TimeInMilliseconds();
80 if (!decode_time_ms) { 80 if (!decode_time_ms) {
81 decode_time_ms = 81 decode_time_ms =
82 rtc::Optional<int32_t>(now_ms - frameInfo->decodeStartTimeMs); 82 rtc::Optional<int32_t>(now_ms - frameInfo->decodeStartTimeMs);
83 } 83 }
84 _timing->StopDecodeTimer(decodedImage.timestamp(), *decode_time_ms, now_ms, 84 _timing->StopDecodeTimer(decodedImage.timestamp(), *decode_time_ms, now_ms,
85 frameInfo->renderTimeMs); 85 frameInfo->renderTimeMs);
86 86
87 decodedImage.set_timestamp_us( 87 decodedImage.set_timestamp_us(
88 frameInfo->renderTimeMs * rtc::kNumMicrosecsPerMillisec); 88 frameInfo->renderTimeMs * rtc::kNumMicrosecsPerMillisec);
89 decodedImage.set_rotation(frameInfo->rotation); 89 decodedImage.set_rotation(frameInfo->rotation);
90 // TODO(sakal): Investigate why callback is NULL sometimes and replace if 90 _receiveCallback->FrameToRender(decodedImage, qp);
91 // statement with a DCHECK.
92 if (callback) {
93 callback->FrameToRender(decodedImage, qp);
94 } else {
95 LOG(LS_WARNING) << "No callback, dropping frame.";
96 }
97 } 91 }
98 92
99 int32_t VCMDecodedFrameCallback::ReceivedDecodedReferenceFrame( 93 int32_t VCMDecodedFrameCallback::ReceivedDecodedReferenceFrame(
100 const uint64_t pictureId) { 94 const uint64_t pictureId) {
101 CriticalSectionScoped cs(_critSect); 95 return _receiveCallback->ReceivedDecodedReferenceFrame(pictureId);
102 if (_receiveCallback != NULL) {
103 return _receiveCallback->ReceivedDecodedReferenceFrame(pictureId);
104 }
105 return -1;
106 } 96 }
107 97
108 int32_t VCMDecodedFrameCallback::ReceivedDecodedFrame( 98 int32_t VCMDecodedFrameCallback::ReceivedDecodedFrame(
109 const uint64_t pictureId) { 99 const uint64_t pictureId) {
110 _lastReceivedPictureID = pictureId; 100 _lastReceivedPictureID = pictureId;
111 return 0; 101 return 0;
112 } 102 }
113 103
114 uint64_t VCMDecodedFrameCallback::LastReceivedPictureID() const { 104 uint64_t VCMDecodedFrameCallback::LastReceivedPictureID() const {
115 return _lastReceivedPictureID; 105 return _lastReceivedPictureID;
116 } 106 }
117 107
118 void VCMDecodedFrameCallback::OnDecoderImplementationName( 108 void VCMDecodedFrameCallback::OnDecoderImplementationName(
119 const char* implementation_name) { 109 const char* implementation_name) {
120 CriticalSectionScoped cs(_critSect); 110 _receiveCallback->OnDecoderImplementationName(implementation_name);
121 if (_receiveCallback)
122 _receiveCallback->OnDecoderImplementationName(implementation_name);
123 } 111 }
124 112
125 void VCMDecodedFrameCallback::Map(uint32_t timestamp, 113 void VCMDecodedFrameCallback::Map(uint32_t timestamp,
126 VCMFrameInformation* frameInfo) { 114 VCMFrameInformation* frameInfo) {
127 CriticalSectionScoped cs(_critSect); 115 rtc::CritScope cs(&lock_);
128 _timestampMap.Add(timestamp, frameInfo); 116 _timestampMap.Add(timestamp, frameInfo);
129 } 117 }
130 118
131 int32_t VCMDecodedFrameCallback::Pop(uint32_t timestamp) { 119 int32_t VCMDecodedFrameCallback::Pop(uint32_t timestamp) {
132 CriticalSectionScoped cs(_critSect); 120 rtc::CritScope cs(&lock_);
133 if (_timestampMap.Pop(timestamp) == NULL) { 121 if (_timestampMap.Pop(timestamp) == NULL) {
134 return VCM_GENERAL_ERROR; 122 return VCM_GENERAL_ERROR;
135 } 123 }
136 return VCM_OK; 124 return VCM_OK;
137 } 125 }
138 126
139 VCMGenericDecoder::VCMGenericDecoder(VideoDecoder* decoder, bool isExternal) 127 VCMGenericDecoder::VCMGenericDecoder(VideoDecoder* decoder, bool isExternal)
140 : _callback(NULL), 128 : _callback(NULL),
141 _frameInfos(), 129 _frameInfos(),
142 _nextFrameInfoIdx(0), 130 _nextFrameInfoIdx(0),
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 183
196 bool VCMGenericDecoder::External() const { 184 bool VCMGenericDecoder::External() const {
197 return _isExternal; 185 return _isExternal;
198 } 186 }
199 187
200 bool VCMGenericDecoder::PrefersLateDecoding() const { 188 bool VCMGenericDecoder::PrefersLateDecoding() const {
201 return _decoder->PrefersLateDecoding(); 189 return _decoder->PrefersLateDecoding();
202 } 190 }
203 191
204 } // namespace webrtc 192 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698