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 |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include <sys/time.h> | 21 #include <sys/time.h> |
22 #endif | 22 #endif |
23 | 23 |
24 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 24 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
25 #include "webrtc/common_video/video_render_frames.h" | 25 #include "webrtc/common_video/video_render_frames.h" |
26 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 26 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
27 #include "webrtc/system_wrappers/include/event_wrapper.h" | 27 #include "webrtc/system_wrappers/include/event_wrapper.h" |
28 #include "webrtc/system_wrappers/include/thread_wrapper.h" | 28 #include "webrtc/system_wrappers/include/thread_wrapper.h" |
29 #include "webrtc/system_wrappers/include/tick_util.h" | 29 #include "webrtc/system_wrappers/include/tick_util.h" |
30 #include "webrtc/system_wrappers/include/trace.h" | 30 #include "webrtc/system_wrappers/include/trace.h" |
| 31 #include "webrtc/video_renderer.h" |
31 | 32 |
32 namespace webrtc { | 33 namespace webrtc { |
33 | 34 |
34 IncomingVideoStream::IncomingVideoStream(uint32_t stream_id) | 35 IncomingVideoStream::IncomingVideoStream(uint32_t stream_id) |
| 36 : IncomingVideoStream(stream_id, nullptr) {} |
| 37 |
| 38 IncomingVideoStream::IncomingVideoStream(uint32_t stream_id, |
| 39 VideoRenderer* renderer) |
35 : stream_id_(stream_id), | 40 : stream_id_(stream_id), |
| 41 renderer_(renderer), |
36 stream_critsect_(CriticalSectionWrapper::CreateCriticalSection()), | 42 stream_critsect_(CriticalSectionWrapper::CreateCriticalSection()), |
37 thread_critsect_(CriticalSectionWrapper::CreateCriticalSection()), | 43 thread_critsect_(CriticalSectionWrapper::CreateCriticalSection()), |
38 buffer_critsect_(CriticalSectionWrapper::CreateCriticalSection()), | 44 buffer_critsect_(CriticalSectionWrapper::CreateCriticalSection()), |
39 incoming_render_thread_(), | 45 incoming_render_thread_(), |
40 deliver_buffer_event_(EventTimerWrapper::Create()), | 46 deliver_buffer_event_(EventTimerWrapper::Create()), |
41 running_(false), | 47 running_(false), |
42 external_callback_(nullptr), | 48 external_callback_(nullptr), |
43 render_callback_(nullptr), | 49 render_callback_(nullptr), |
44 render_buffers_(new VideoRenderFrames()), | 50 render_buffers_(new VideoRenderFrames()), |
45 incoming_rate_(0), | 51 incoming_rate_(0), |
46 last_rate_calculation_time_ms_(0), | 52 last_rate_calculation_time_ms_(0), |
47 num_frames_since_last_calculation_(0), | 53 num_frames_since_last_calculation_(0), |
48 last_render_time_ms_(0), | 54 last_render_time_ms_(0), |
49 temp_frame_(), | 55 temp_frame_(), |
50 start_image_(), | 56 start_image_(), |
51 timeout_image_(), | 57 timeout_image_(), |
52 timeout_time_() { | 58 timeout_time_() {} |
53 } | |
54 | 59 |
55 IncomingVideoStream::~IncomingVideoStream() { | 60 IncomingVideoStream::~IncomingVideoStream() { |
56 Stop(); | 61 Stop(); |
57 } | 62 } |
58 | 63 |
59 VideoRenderCallback* IncomingVideoStream::ModuleCallback() { | 64 VideoRenderCallback* IncomingVideoStream::ModuleCallback() { |
60 CriticalSectionScoped cs(stream_critsect_.get()); | 65 CriticalSectionScoped cs(stream_critsect_.get()); |
61 return this; | 66 return this; |
62 } | 67 } |
63 | 68 |
(...skipping 11 matching lines...) Expand all Loading... |
75 if (now_ms >= last_rate_calculation_time_ms_ + kFrameRatePeriodMs) { | 80 if (now_ms >= last_rate_calculation_time_ms_ + kFrameRatePeriodMs) { |
76 incoming_rate_ = | 81 incoming_rate_ = |
77 static_cast<uint32_t>(1000 * num_frames_since_last_calculation_ / | 82 static_cast<uint32_t>(1000 * num_frames_since_last_calculation_ / |
78 (now_ms - last_rate_calculation_time_ms_)); | 83 (now_ms - last_rate_calculation_time_ms_)); |
79 num_frames_since_last_calculation_ = 0; | 84 num_frames_since_last_calculation_ = 0; |
80 last_rate_calculation_time_ms_ = now_ms; | 85 last_rate_calculation_time_ms_ = now_ms; |
81 } | 86 } |
82 | 87 |
83 // Insert frame. | 88 // Insert frame. |
84 CriticalSectionScoped csB(buffer_critsect_.get()); | 89 CriticalSectionScoped csB(buffer_critsect_.get()); |
85 if (render_buffers_->AddFrame(video_frame) == 1) | 90 if (render_buffers_->AddFrame(video_frame) == 1 || |
| 91 (renderer_ && renderer_->PrerendererSmoothingDisabled())) { |
86 deliver_buffer_event_->Set(); | 92 deliver_buffer_event_->Set(); |
87 | 93 } |
88 return 0; | 94 return 0; |
89 } | 95 } |
90 | 96 |
91 int32_t IncomingVideoStream::SetStartImage(const VideoFrame& video_frame) { | 97 int32_t IncomingVideoStream::SetStartImage(const VideoFrame& video_frame) { |
92 CriticalSectionScoped csS(thread_critsect_.get()); | 98 CriticalSectionScoped csS(thread_critsect_.get()); |
93 return start_image_.CopyFrame(video_frame); | 99 return start_image_.CopyFrame(video_frame); |
94 } | 100 } |
95 | 101 |
96 int32_t IncomingVideoStream::SetTimeoutImage(const VideoFrame& video_frame, | 102 int32_t IncomingVideoStream::SetTimeoutImage(const VideoFrame& video_frame, |
97 const uint32_t timeout) { | 103 const uint32_t timeout) { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 } | 213 } |
208 // Get a new frame to render and the time for the frame after this one. | 214 // Get a new frame to render and the time for the frame after this one. |
209 VideoFrame frame_to_render; | 215 VideoFrame frame_to_render; |
210 uint32_t wait_time; | 216 uint32_t wait_time; |
211 { | 217 { |
212 CriticalSectionScoped cs(buffer_critsect_.get()); | 218 CriticalSectionScoped cs(buffer_critsect_.get()); |
213 frame_to_render = render_buffers_->FrameToRender(); | 219 frame_to_render = render_buffers_->FrameToRender(); |
214 wait_time = render_buffers_->TimeToNextFrameRelease(); | 220 wait_time = render_buffers_->TimeToNextFrameRelease(); |
215 } | 221 } |
216 | 222 |
217 // Set timer for next frame to render. | 223 if (!renderer_ || !renderer_->PrerendererSmoothingDisabled()) { |
218 if (wait_time > kEventMaxWaitTimeMs) { | 224 // Set timer for next frame to render. |
219 wait_time = kEventMaxWaitTimeMs; | 225 if (wait_time > kEventMaxWaitTimeMs) { |
| 226 wait_time = kEventMaxWaitTimeMs; |
| 227 } |
| 228 deliver_buffer_event_->StartTimer(false, wait_time); |
220 } | 229 } |
221 deliver_buffer_event_->StartTimer(false, wait_time); | |
222 | 230 |
223 if (frame_to_render.IsZeroSize()) { | 231 if (frame_to_render.IsZeroSize()) { |
224 if (render_callback_) { | 232 if (render_callback_) { |
225 if (last_render_time_ms_ == 0 && !start_image_.IsZeroSize()) { | 233 if (last_render_time_ms_ == 0 && !start_image_.IsZeroSize()) { |
226 // We have not rendered anything and have a start image. | 234 // We have not rendered anything and have a start image. |
227 temp_frame_.CopyFrame(start_image_); | 235 temp_frame_.CopyFrame(start_image_); |
228 render_callback_->RenderFrame(stream_id_, temp_frame_); | 236 render_callback_->RenderFrame(stream_id_, temp_frame_); |
229 } else if (!timeout_image_.IsZeroSize() && | 237 } else if (!timeout_image_.IsZeroSize() && |
230 last_render_time_ms_ + timeout_time_ < | 238 last_render_time_ms_ + timeout_time_ < |
231 TickTime::MillisecondTimestamp()) { | 239 TickTime::MillisecondTimestamp()) { |
(...skipping 15 matching lines...) Expand all Loading... |
247 } | 255 } |
248 | 256 |
249 // We're done with this frame. | 257 // We're done with this frame. |
250 if (!frame_to_render.IsZeroSize()) | 258 if (!frame_to_render.IsZeroSize()) |
251 last_render_time_ms_ = frame_to_render.render_time_ms(); | 259 last_render_time_ms_ = frame_to_render.render_time_ms(); |
252 } | 260 } |
253 return true; | 261 return true; |
254 } | 262 } |
255 | 263 |
256 } // namespace webrtc | 264 } // namespace webrtc |
OLD | NEW |