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/common_video/video_render_frames.h" | 11 #include "webrtc/common_video/video_render_frames.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 | 14 |
15 #include "webrtc/base/timeutils.h" | 15 #include "webrtc/base/timeutils.h" |
16 #include "webrtc/modules/include/module_common_types.h" | 16 #include "webrtc/modules/include/module_common_types.h" |
17 #include "webrtc/system_wrappers/include/trace.h" | 17 #include "webrtc/system_wrappers/include/trace.h" |
18 | 18 |
19 namespace webrtc { | 19 namespace webrtc { |
20 namespace { | |
21 | 20 |
22 const uint32_t kEventMaxWaitTimeMs = 200; | 21 const uint32_t KEventMaxWaitTimeMs = 200; |
23 const uint32_t kMinRenderDelayMs = 10; | 22 const uint32_t kMinRenderDelayMs = 10; |
24 const uint32_t kMaxRenderDelayMs = 500; | 23 const uint32_t kMaxRenderDelayMs = 500; |
25 | 24 |
26 uint32_t EnsureValidRenderDelay(uint32_t render_delay) { | 25 VideoRenderFrames::VideoRenderFrames() |
27 return (render_delay < kMinRenderDelayMs || render_delay > kMaxRenderDelayMs) | 26 : render_delay_ms_(10) { |
28 ? kMinRenderDelayMs | |
29 : render_delay; | |
30 } | 27 } |
31 } // namespace | |
32 | |
33 VideoRenderFrames::VideoRenderFrames(uint32_t render_delay_ms) | |
34 : render_delay_ms_(EnsureValidRenderDelay(render_delay_ms)) {} | |
35 | 28 |
36 int32_t VideoRenderFrames::AddFrame(const VideoFrame& new_frame) { | 29 int32_t VideoRenderFrames::AddFrame(const VideoFrame& new_frame) { |
37 const int64_t time_now = rtc::TimeMillis(); | 30 const int64_t time_now = rtc::TimeMillis(); |
38 | 31 |
39 // Drop old frames only when there are other frames in the queue, otherwise, a | 32 // Drop old frames only when there are other frames in the queue, otherwise, a |
40 // really slow system never renders any frames. | 33 // really slow system never renders any frames. |
41 if (!incoming_frames_.empty() && | 34 if (!incoming_frames_.empty() && |
42 new_frame.render_time_ms() + KOldRenderTimestampMS < time_now) { | 35 new_frame.render_time_ms() + KOldRenderTimestampMS < time_now) { |
43 WEBRTC_TRACE(kTraceWarning, | 36 WEBRTC_TRACE(kTraceWarning, |
44 kTraceVideoRenderer, | 37 kTraceVideoRenderer, |
(...skipping 18 matching lines...) Expand all Loading... |
63 rtc::Optional<VideoFrame> VideoRenderFrames::FrameToRender() { | 56 rtc::Optional<VideoFrame> VideoRenderFrames::FrameToRender() { |
64 rtc::Optional<VideoFrame> render_frame; | 57 rtc::Optional<VideoFrame> render_frame; |
65 // Get the newest frame that can be released for rendering. | 58 // Get the newest frame that can be released for rendering. |
66 while (!incoming_frames_.empty() && TimeToNextFrameRelease() <= 0) { | 59 while (!incoming_frames_.empty() && TimeToNextFrameRelease() <= 0) { |
67 render_frame = rtc::Optional<VideoFrame>(incoming_frames_.front()); | 60 render_frame = rtc::Optional<VideoFrame>(incoming_frames_.front()); |
68 incoming_frames_.pop_front(); | 61 incoming_frames_.pop_front(); |
69 } | 62 } |
70 return render_frame; | 63 return render_frame; |
71 } | 64 } |
72 | 65 |
| 66 int32_t VideoRenderFrames::ReleaseAllFrames() { |
| 67 incoming_frames_.clear(); |
| 68 return 0; |
| 69 } |
| 70 |
73 uint32_t VideoRenderFrames::TimeToNextFrameRelease() { | 71 uint32_t VideoRenderFrames::TimeToNextFrameRelease() { |
74 if (incoming_frames_.empty()) { | 72 if (incoming_frames_.empty()) { |
75 return kEventMaxWaitTimeMs; | 73 return KEventMaxWaitTimeMs; |
76 } | 74 } |
77 const int64_t time_to_release = incoming_frames_.front().render_time_ms() - | 75 const int64_t time_to_release = incoming_frames_.front().render_time_ms() - |
78 render_delay_ms_ - | 76 render_delay_ms_ - |
79 rtc::TimeMillis(); | 77 rtc::TimeMillis(); |
80 return time_to_release < 0 ? 0u : static_cast<uint32_t>(time_to_release); | 78 return time_to_release < 0 ? 0u : static_cast<uint32_t>(time_to_release); |
81 } | 79 } |
82 | 80 |
| 81 int32_t VideoRenderFrames::SetRenderDelay( |
| 82 const uint32_t render_delay) { |
| 83 if (render_delay < kMinRenderDelayMs || |
| 84 render_delay > kMaxRenderDelayMs) { |
| 85 WEBRTC_TRACE(kTraceWarning, kTraceVideoRenderer, |
| 86 -1, "%s(%d): Invalid argument.", __FUNCTION__, |
| 87 render_delay); |
| 88 return -1; |
| 89 } |
| 90 |
| 91 render_delay_ms_ = render_delay; |
| 92 return 0; |
| 93 } |
| 94 |
83 } // namespace webrtc | 95 } // namespace webrtc |
OLD | NEW |