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 { |
20 | 21 |
21 const uint32_t KEventMaxWaitTimeMs = 200; | 22 const uint32_t kEventMaxWaitTimeMs = 200; |
22 const uint32_t kMinRenderDelayMs = 10; | 23 const uint32_t kMinRenderDelayMs = 10; |
23 const uint32_t kMaxRenderDelayMs = 500; | 24 const uint32_t kMaxRenderDelayMs = 500; |
24 | 25 |
25 VideoRenderFrames::VideoRenderFrames() | 26 uint32_t EnsureValidRenderDelay(uint32_t render_delay) { |
26 : render_delay_ms_(10) { | 27 return (render_delay < kMinRenderDelayMs || render_delay > kMaxRenderDelayMs) |
| 28 ? kMinRenderDelayMs |
| 29 : render_delay; |
27 } | 30 } |
| 31 } // namespace |
| 32 |
| 33 VideoRenderFrames::VideoRenderFrames(uint32_t render_delay_ms) |
| 34 : render_delay_ms_(EnsureValidRenderDelay(render_delay_ms)) {} |
28 | 35 |
29 int32_t VideoRenderFrames::AddFrame(const VideoFrame& new_frame) { | 36 int32_t VideoRenderFrames::AddFrame(const VideoFrame& new_frame) { |
30 const int64_t time_now = rtc::TimeMillis(); | 37 const int64_t time_now = rtc::TimeMillis(); |
31 | 38 |
32 // Drop old frames only when there are other frames in the queue, otherwise, a | 39 // Drop old frames only when there are other frames in the queue, otherwise, a |
33 // really slow system never renders any frames. | 40 // really slow system never renders any frames. |
34 if (!incoming_frames_.empty() && | 41 if (!incoming_frames_.empty() && |
35 new_frame.render_time_ms() + KOldRenderTimestampMS < time_now) { | 42 new_frame.render_time_ms() + KOldRenderTimestampMS < time_now) { |
36 WEBRTC_TRACE(kTraceWarning, | 43 WEBRTC_TRACE(kTraceWarning, |
37 kTraceVideoRenderer, | 44 kTraceVideoRenderer, |
(...skipping 18 matching lines...) Expand all Loading... |
56 rtc::Optional<VideoFrame> VideoRenderFrames::FrameToRender() { | 63 rtc::Optional<VideoFrame> VideoRenderFrames::FrameToRender() { |
57 rtc::Optional<VideoFrame> render_frame; | 64 rtc::Optional<VideoFrame> render_frame; |
58 // Get the newest frame that can be released for rendering. | 65 // Get the newest frame that can be released for rendering. |
59 while (!incoming_frames_.empty() && TimeToNextFrameRelease() <= 0) { | 66 while (!incoming_frames_.empty() && TimeToNextFrameRelease() <= 0) { |
60 render_frame = rtc::Optional<VideoFrame>(incoming_frames_.front()); | 67 render_frame = rtc::Optional<VideoFrame>(incoming_frames_.front()); |
61 incoming_frames_.pop_front(); | 68 incoming_frames_.pop_front(); |
62 } | 69 } |
63 return render_frame; | 70 return render_frame; |
64 } | 71 } |
65 | 72 |
66 int32_t VideoRenderFrames::ReleaseAllFrames() { | |
67 incoming_frames_.clear(); | |
68 return 0; | |
69 } | |
70 | |
71 uint32_t VideoRenderFrames::TimeToNextFrameRelease() { | 73 uint32_t VideoRenderFrames::TimeToNextFrameRelease() { |
72 if (incoming_frames_.empty()) { | 74 if (incoming_frames_.empty()) { |
73 return KEventMaxWaitTimeMs; | 75 return kEventMaxWaitTimeMs; |
74 } | 76 } |
75 const int64_t time_to_release = incoming_frames_.front().render_time_ms() - | 77 const int64_t time_to_release = incoming_frames_.front().render_time_ms() - |
76 render_delay_ms_ - | 78 render_delay_ms_ - |
77 rtc::TimeMillis(); | 79 rtc::TimeMillis(); |
78 return time_to_release < 0 ? 0u : static_cast<uint32_t>(time_to_release); | 80 return time_to_release < 0 ? 0u : static_cast<uint32_t>(time_to_release); |
79 } | 81 } |
80 | 82 |
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 | |
95 } // namespace webrtc | 83 } // namespace webrtc |
OLD | NEW |