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 |
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/timeutils.h" | 13 #include "webrtc/base/timeutils.h" |
14 #include "webrtc/base/trace_event.h" | 14 #include "webrtc/base/trace_event.h" |
15 #include "webrtc/modules/video_coding/include/video_coding.h" | 15 #include "webrtc/modules/video_coding/include/video_coding.h" |
16 #include "webrtc/modules/video_coding/generic_decoder.h" | 16 #include "webrtc/modules/video_coding/generic_decoder.h" |
17 #include "webrtc/modules/video_coding/internal_defines.h" | 17 #include "webrtc/modules/video_coding/internal_defines.h" |
18 #include "webrtc/system_wrappers/include/clock.h" | 18 #include "webrtc/system_wrappers/include/clock.h" |
19 | 19 |
20 namespace webrtc { | 20 namespace webrtc { |
21 | 21 |
22 VCMDecodedFrameCallback::VCMDecodedFrameCallback(VCMTiming* timing, | 22 VCMDecodedFrameCallback::VCMDecodedFrameCallback(VCMTiming* timing, |
23 Clock* clock) | 23 Clock* clock) |
24 : _clock(clock), | 24 : _clock(clock), |
25 _timing(timing), | 25 _timing(timing), |
26 _timestampMap(kDecoderFrameMemoryLength), | 26 _timestampMap(kDecoderFrameMemoryLength), |
27 _lastReceivedPictureID(0) {} | 27 _lastReceivedPictureID(0) { |
| 28 ntp_offset_ = |
| 29 _clock->CurrentNtpInMilliseconds() - _clock->TimeInMilliseconds(); |
| 30 } |
28 | 31 |
29 VCMDecodedFrameCallback::~VCMDecodedFrameCallback() { | 32 VCMDecodedFrameCallback::~VCMDecodedFrameCallback() { |
30 } | 33 } |
31 | 34 |
32 void VCMDecodedFrameCallback::SetUserReceiveCallback( | 35 void VCMDecodedFrameCallback::SetUserReceiveCallback( |
33 VCMReceiveCallback* receiveCallback) { | 36 VCMReceiveCallback* receiveCallback) { |
34 RTC_DCHECK(construction_thread_.CalledOnValidThread()); | 37 RTC_DCHECK(construction_thread_.CalledOnValidThread()); |
35 RTC_DCHECK((!_receiveCallback && receiveCallback) || | 38 RTC_DCHECK((!_receiveCallback && receiveCallback) || |
36 (_receiveCallback && !receiveCallback)); | 39 (_receiveCallback && !receiveCallback)); |
37 _receiveCallback = receiveCallback; | 40 _receiveCallback = receiveCallback; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 } | 81 } |
79 | 82 |
80 const int64_t now_ms = _clock->TimeInMilliseconds(); | 83 const int64_t now_ms = _clock->TimeInMilliseconds(); |
81 if (!decode_time_ms) { | 84 if (!decode_time_ms) { |
82 decode_time_ms = | 85 decode_time_ms = |
83 rtc::Optional<int32_t>(now_ms - frameInfo->decodeStartTimeMs); | 86 rtc::Optional<int32_t>(now_ms - frameInfo->decodeStartTimeMs); |
84 } | 87 } |
85 _timing->StopDecodeTimer(decodedImage.timestamp(), *decode_time_ms, now_ms, | 88 _timing->StopDecodeTimer(decodedImage.timestamp(), *decode_time_ms, now_ms, |
86 frameInfo->renderTimeMs); | 89 frameInfo->renderTimeMs); |
87 | 90 |
| 91 // Report timing information. |
| 92 if (frameInfo->timing.is_timing_frame) { |
| 93 // Convert remote timestamps to local time from ntp timestamps. |
| 94 frameInfo->timing.encode_start_ms -= ntp_offset_; |
| 95 frameInfo->timing.encode_finish_ms -= ntp_offset_; |
| 96 frameInfo->timing.packetization_finish_ms -= ntp_offset_; |
| 97 frameInfo->timing.pacer_exit_ms -= ntp_offset_; |
| 98 frameInfo->timing.network_timestamp_ms -= ntp_offset_; |
| 99 frameInfo->timing.network2_timestamp_ms -= ntp_offset_; |
| 100 // TODO(ilnik): Report timing information here. |
| 101 // Capture time: decodedImage.ntp_time_ms() - ntp_offset |
| 102 // Encode start: frameInfo->timing.encode_start_ms |
| 103 // Encode finish: frameInfo->timing.encode_finish_ms |
| 104 // Packetization done: frameInfo->timing.packetization_finish_ms |
| 105 // Pacer exit: frameInfo->timing.pacer_exit_ms |
| 106 // Network timestamp: frameInfo->timing.network_timestamp_ms |
| 107 // Network2 timestamp: frameInfo->timing.network2_timestamp_ms |
| 108 // Receive start: frameInfo->timing.receive_start_ms |
| 109 // Receive finish: frameInfo->timing.receive_finish_ms |
| 110 // Decode start: frameInfo->decodeStartTimeMs |
| 111 // Decode finish: now_ms |
| 112 // Render time: frameInfo->renderTimeMs |
| 113 } |
| 114 |
88 decodedImage.set_timestamp_us( | 115 decodedImage.set_timestamp_us( |
89 frameInfo->renderTimeMs * rtc::kNumMicrosecsPerMillisec); | 116 frameInfo->renderTimeMs * rtc::kNumMicrosecsPerMillisec); |
90 decodedImage.set_rotation(frameInfo->rotation); | 117 decodedImage.set_rotation(frameInfo->rotation); |
91 _receiveCallback->FrameToRender(decodedImage, qp, frameInfo->content_type); | 118 _receiveCallback->FrameToRender(decodedImage, qp, frameInfo->content_type); |
92 } | 119 } |
93 | 120 |
94 int32_t VCMDecodedFrameCallback::ReceivedDecodedReferenceFrame( | 121 int32_t VCMDecodedFrameCallback::ReceivedDecodedReferenceFrame( |
95 const uint64_t pictureId) { | 122 const uint64_t pictureId) { |
96 return _receiveCallback->ReceivedDecodedReferenceFrame(pictureId); | 123 return _receiveCallback->ReceivedDecodedReferenceFrame(pictureId); |
97 } | 124 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 171 |
145 return _decoder->InitDecode(settings, numberOfCores); | 172 return _decoder->InitDecode(settings, numberOfCores); |
146 } | 173 } |
147 | 174 |
148 int32_t VCMGenericDecoder::Decode(const VCMEncodedFrame& frame, int64_t nowMs) { | 175 int32_t VCMGenericDecoder::Decode(const VCMEncodedFrame& frame, int64_t nowMs) { |
149 TRACE_EVENT1("webrtc", "VCMGenericDecoder::Decode", "timestamp", | 176 TRACE_EVENT1("webrtc", "VCMGenericDecoder::Decode", "timestamp", |
150 frame.EncodedImage()._timeStamp); | 177 frame.EncodedImage()._timeStamp); |
151 _frameInfos[_nextFrameInfoIdx].decodeStartTimeMs = nowMs; | 178 _frameInfos[_nextFrameInfoIdx].decodeStartTimeMs = nowMs; |
152 _frameInfos[_nextFrameInfoIdx].renderTimeMs = frame.RenderTimeMs(); | 179 _frameInfos[_nextFrameInfoIdx].renderTimeMs = frame.RenderTimeMs(); |
153 _frameInfos[_nextFrameInfoIdx].rotation = frame.rotation(); | 180 _frameInfos[_nextFrameInfoIdx].rotation = frame.rotation(); |
| 181 _frameInfos[_nextFrameInfoIdx].timing = frame.video_timing(); |
154 // Set correctly only for key frames. Thus, use latest key frame | 182 // Set correctly only for key frames. Thus, use latest key frame |
155 // content type. If the corresponding key frame was lost, decode will fail | 183 // content type. If the corresponding key frame was lost, decode will fail |
156 // and content type will be ignored. | 184 // and content type will be ignored. |
157 if (frame.FrameType() == kVideoFrameKey) { | 185 if (frame.FrameType() == kVideoFrameKey) { |
158 _frameInfos[_nextFrameInfoIdx].content_type = frame.contentType(); | 186 _frameInfos[_nextFrameInfoIdx].content_type = frame.contentType(); |
159 _last_keyframe_content_type = frame.contentType(); | 187 _last_keyframe_content_type = frame.contentType(); |
160 } else { | 188 } else { |
161 _frameInfos[_nextFrameInfoIdx].content_type = _last_keyframe_content_type; | 189 _frameInfos[_nextFrameInfoIdx].content_type = _last_keyframe_content_type; |
162 } | 190 } |
163 _callback->Map(frame.TimeStamp(), &_frameInfos[_nextFrameInfoIdx]); | 191 _callback->Map(frame.TimeStamp(), &_frameInfos[_nextFrameInfoIdx]); |
(...skipping 30 matching lines...) Expand all Loading... |
194 | 222 |
195 bool VCMGenericDecoder::External() const { | 223 bool VCMGenericDecoder::External() const { |
196 return _isExternal; | 224 return _isExternal; |
197 } | 225 } |
198 | 226 |
199 bool VCMGenericDecoder::PrefersLateDecoding() const { | 227 bool VCMGenericDecoder::PrefersLateDecoding() const { |
200 return _decoder->PrefersLateDecoding(); | 228 return _decoder->PrefersLateDecoding(); |
201 } | 229 } |
202 | 230 |
203 } // namespace webrtc | 231 } // namespace webrtc |
OLD | NEW |