| 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/include/incoming_video_stream.h" | 11 #include "webrtc/common_video/include/incoming_video_stream.h" |
| 12 | 12 |
| 13 #include <assert.h> | 13 #include <assert.h> |
| 14 | 14 |
| 15 #include "webrtc/base/platform_thread.h" | 15 #include "webrtc/base/platform_thread.h" |
| 16 #include "webrtc/base/timeutils.h" | 16 #include "webrtc/base/timeutils.h" |
| 17 #include "webrtc/common_video/video_render_frames.h" | 17 #include "webrtc/common_video/video_render_frames.h" |
| 18 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 18 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
| 19 #include "webrtc/system_wrappers/include/event_wrapper.h" | 19 #include "webrtc/system_wrappers/include/event_wrapper.h" |
| 20 | 20 |
| 21 namespace webrtc { | 21 namespace webrtc { |
| 22 | 22 |
| 23 IncomingVideoStream::IncomingVideoStream(bool disable_prerenderer_smoothing) | 23 IncomingVideoStream::IncomingVideoStream(bool disable_prerenderer_smoothing) |
| 24 : disable_prerenderer_smoothing_(disable_prerenderer_smoothing), | 24 : disable_prerenderer_smoothing_(disable_prerenderer_smoothing), |
| 25 incoming_render_thread_(), | 25 incoming_render_thread_(), |
| 26 deliver_buffer_event_(EventTimerWrapper::Create()), | 26 deliver_buffer_event_(EventTimerWrapper::Create()), |
| 27 running_(false), | 27 running_(false), |
| 28 external_callback_(nullptr), | 28 external_callback_(nullptr), |
| 29 render_buffers_(new VideoRenderFrames()), | 29 render_buffers_(new VideoRenderFrames()) {} |
| 30 incoming_rate_(0), | |
| 31 last_rate_calculation_time_ms_(0), | |
| 32 num_frames_since_last_calculation_(0) {} | |
| 33 | 30 |
| 34 IncomingVideoStream::~IncomingVideoStream() { | 31 IncomingVideoStream::~IncomingVideoStream() { |
| 35 Stop(); | 32 Stop(); |
| 36 } | 33 } |
| 37 | 34 |
| 38 void IncomingVideoStream::OnFrame(const VideoFrame& video_frame) { | 35 void IncomingVideoStream::OnFrame(const VideoFrame& video_frame) { |
| 39 rtc::CritScope csS(&stream_critsect_); | 36 rtc::CritScope csS(&stream_critsect_); |
| 40 | 37 |
| 41 if (!running_) { | 38 if (!running_) { |
| 42 return; | 39 return; |
| 43 } | 40 } |
| 44 | 41 |
| 45 // Rate statistics. | |
| 46 num_frames_since_last_calculation_++; | |
| 47 int64_t now_ms = rtc::TimeMillis(); | |
| 48 if (now_ms >= last_rate_calculation_time_ms_ + kFrameRatePeriodMs) { | |
| 49 incoming_rate_ = | |
| 50 static_cast<uint32_t>(1000 * num_frames_since_last_calculation_ / | |
| 51 (now_ms - last_rate_calculation_time_ms_)); | |
| 52 num_frames_since_last_calculation_ = 0; | |
| 53 last_rate_calculation_time_ms_ = now_ms; | |
| 54 } | |
| 55 | |
| 56 // Hand over or insert frame. | 42 // Hand over or insert frame. |
| 57 if (disable_prerenderer_smoothing_) { | 43 if (disable_prerenderer_smoothing_) { |
| 58 DeliverFrame(video_frame); | 44 DeliverFrame(video_frame); |
| 59 } else { | 45 } else { |
| 60 rtc::CritScope csB(&buffer_critsect_); | 46 rtc::CritScope csB(&buffer_critsect_); |
| 61 if (render_buffers_->AddFrame(video_frame) == 1) { | 47 if (render_buffers_->AddFrame(video_frame) == 1) { |
| 62 deliver_buffer_event_->Set(); | 48 deliver_buffer_event_->Set(); |
| 63 } | 49 } |
| 64 } | 50 } |
| 65 } | 51 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 } | 112 } |
| 127 } | 113 } |
| 128 if (thread) { | 114 if (thread) { |
| 129 thread->Stop(); | 115 thread->Stop(); |
| 130 delete thread; | 116 delete thread; |
| 131 } | 117 } |
| 132 running_ = false; | 118 running_ = false; |
| 133 return 0; | 119 return 0; |
| 134 } | 120 } |
| 135 | 121 |
| 136 int32_t IncomingVideoStream::Reset() { | |
| 137 rtc::CritScope cs_buffer(&buffer_critsect_); | |
| 138 render_buffers_->ReleaseAllFrames(); | |
| 139 return 0; | |
| 140 } | |
| 141 | |
| 142 uint32_t IncomingVideoStream::IncomingRate() const { | |
| 143 rtc::CritScope cs(&stream_critsect_); | |
| 144 return incoming_rate_; | |
| 145 } | |
| 146 | |
| 147 bool IncomingVideoStream::IncomingVideoStreamThreadFun(void* obj) { | 122 bool IncomingVideoStream::IncomingVideoStreamThreadFun(void* obj) { |
| 148 return static_cast<IncomingVideoStream*>(obj)->IncomingVideoStreamProcess(); | 123 return static_cast<IncomingVideoStream*>(obj)->IncomingVideoStreamProcess(); |
| 149 } | 124 } |
| 150 | 125 |
| 151 bool IncomingVideoStream::IncomingVideoStreamProcess() { | 126 bool IncomingVideoStream::IncomingVideoStreamProcess() { |
| 152 if (kEventError != deliver_buffer_event_->Wait(kEventMaxWaitTimeMs)) { | 127 if (kEventError != deliver_buffer_event_->Wait(kEventMaxWaitTimeMs)) { |
| 153 rtc::CritScope cs(&thread_critsect_); | 128 rtc::CritScope cs(&thread_critsect_); |
| 154 if (incoming_render_thread_ == NULL) { | 129 if (incoming_render_thread_ == NULL) { |
| 155 // Terminating | 130 // Terminating |
| 156 return false; | 131 return false; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 180 void IncomingVideoStream::DeliverFrame(const VideoFrame& video_frame) { | 155 void IncomingVideoStream::DeliverFrame(const VideoFrame& video_frame) { |
| 181 rtc::CritScope cs(&thread_critsect_); | 156 rtc::CritScope cs(&thread_critsect_); |
| 182 | 157 |
| 183 // Send frame for rendering. | 158 // Send frame for rendering. |
| 184 if (external_callback_) { | 159 if (external_callback_) { |
| 185 external_callback_->OnFrame(video_frame); | 160 external_callback_->OnFrame(video_frame); |
| 186 } | 161 } |
| 187 } | 162 } |
| 188 | 163 |
| 189 } // namespace webrtc | 164 } // namespace webrtc |
| OLD | NEW |