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/modules/video_coding/video_coding_impl.h" |
| 12 |
| 13 #include <algorithm> |
| 14 |
11 #include "webrtc/common_types.h" | 15 #include "webrtc/common_types.h" |
12 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 16 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
13 #include "webrtc/modules/video_coding/include/video_codec_interface.h" | 17 #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
14 #include "webrtc/modules/video_coding/encoded_frame.h" | 18 #include "webrtc/modules/video_coding/encoded_frame.h" |
15 #include "webrtc/modules/video_coding/jitter_buffer.h" | 19 #include "webrtc/modules/video_coding/jitter_buffer.h" |
16 #include "webrtc/modules/video_coding/packet.h" | 20 #include "webrtc/modules/video_coding/packet.h" |
17 #include "webrtc/modules/video_coding/video_coding_impl.h" | |
18 #include "webrtc/system_wrappers/include/clock.h" | 21 #include "webrtc/system_wrappers/include/clock.h" |
19 | 22 |
20 namespace webrtc { | 23 namespace webrtc { |
21 namespace vcm { | 24 namespace vcm { |
22 | 25 |
23 int64_t | 26 int64_t VCMProcessTimer::Period() const { |
24 VCMProcessTimer::Period() const { | 27 return _periodMs; |
25 return _periodMs; | |
26 } | 28 } |
27 | 29 |
28 int64_t | 30 int64_t VCMProcessTimer::TimeUntilProcess() const { |
29 VCMProcessTimer::TimeUntilProcess() const { | 31 const int64_t time_since_process = _clock->TimeInMilliseconds() - _latestMs; |
30 const int64_t time_since_process = _clock->TimeInMilliseconds() - _latestMs; | 32 const int64_t time_until_process = _periodMs - time_since_process; |
31 const int64_t time_until_process = _periodMs - time_since_process; | 33 return std::max<int64_t>(time_until_process, 0); |
32 return std::max<int64_t>(time_until_process, 0); | |
33 } | 34 } |
34 | 35 |
35 void | 36 void VCMProcessTimer::Processed() { |
36 VCMProcessTimer::Processed() { | 37 _latestMs = _clock->TimeInMilliseconds(); |
37 _latestMs = _clock->TimeInMilliseconds(); | |
38 } | 38 } |
39 } // namespace vcm | 39 } // namespace vcm |
40 | 40 |
41 namespace { | 41 namespace { |
42 // This wrapper provides a way to modify the callback without the need to expose | 42 // This wrapper provides a way to modify the callback without the need to expose |
43 // a register method all the way down to the function calling it. | 43 // a register method all the way down to the function calling it. |
44 class EncodedImageCallbackWrapper : public EncodedImageCallback { | 44 class EncodedImageCallbackWrapper : public EncodedImageCallback { |
45 public: | 45 public: |
46 EncodedImageCallbackWrapper() | 46 EncodedImageCallbackWrapper() |
47 : cs_(CriticalSectionWrapper::CreateCriticalSection()), callback_(NULL) {} | 47 : cs_(CriticalSectionWrapper::CreateCriticalSection()), callback_(NULL) {} |
48 | 48 |
49 virtual ~EncodedImageCallbackWrapper() {} | 49 virtual ~EncodedImageCallbackWrapper() {} |
50 | 50 |
51 void Register(EncodedImageCallback* callback) { | 51 void Register(EncodedImageCallback* callback) { |
52 CriticalSectionScoped cs(cs_.get()); | 52 CriticalSectionScoped cs(cs_.get()); |
53 callback_ = callback; | 53 callback_ = callback; |
54 } | 54 } |
55 | 55 |
56 // TODO(andresp): Change to void as return value is ignored. | 56 // TODO(andresp): Change to void as return value is ignored. |
57 virtual int32_t Encoded(const EncodedImage& encoded_image, | 57 virtual int32_t Encoded(const EncodedImage& encoded_image, |
58 const CodecSpecificInfo* codec_specific_info, | 58 const CodecSpecificInfo* codec_specific_info, |
59 const RTPFragmentationHeader* fragmentation) { | 59 const RTPFragmentationHeader* fragmentation) { |
60 CriticalSectionScoped cs(cs_.get()); | 60 CriticalSectionScoped cs(cs_.get()); |
61 if (callback_) | 61 if (callback_) |
62 return callback_->Encoded( | 62 return callback_->Encoded(encoded_image, codec_specific_info, |
63 encoded_image, codec_specific_info, fragmentation); | 63 fragmentation); |
64 return 0; | 64 return 0; |
65 } | 65 } |
66 | 66 |
67 private: | 67 private: |
68 rtc::scoped_ptr<CriticalSectionWrapper> cs_; | 68 rtc::scoped_ptr<CriticalSectionWrapper> cs_; |
69 EncodedImageCallback* callback_ GUARDED_BY(cs_); | 69 EncodedImageCallback* callback_ GUARDED_BY(cs_); |
70 }; | 70 }; |
71 | 71 |
72 class VideoCodingModuleImpl : public VideoCodingModule { | 72 class VideoCodingModuleImpl : public VideoCodingModule { |
73 public: | 73 public: |
74 VideoCodingModuleImpl(Clock* clock, | 74 VideoCodingModuleImpl(Clock* clock, |
75 EventFactory* event_factory, | 75 EventFactory* event_factory, |
76 bool owns_event_factory, | 76 bool owns_event_factory, |
77 VideoEncoderRateObserver* encoder_rate_observer, | 77 VideoEncoderRateObserver* encoder_rate_observer, |
78 VCMQMSettingsCallback* qm_settings_callback) | 78 VCMQMSettingsCallback* qm_settings_callback) |
79 : VideoCodingModule(), | 79 : VideoCodingModule(), |
80 sender_(clock, | 80 sender_(clock, |
81 &post_encode_callback_, | 81 &post_encode_callback_, |
82 encoder_rate_observer, | 82 encoder_rate_observer, |
83 qm_settings_callback), | 83 qm_settings_callback), |
84 receiver_(clock, event_factory), | 84 receiver_(clock, event_factory), |
85 own_event_factory_(owns_event_factory ? event_factory : NULL) {} | 85 own_event_factory_(owns_event_factory ? event_factory : NULL) {} |
86 | 86 |
87 virtual ~VideoCodingModuleImpl() { | 87 virtual ~VideoCodingModuleImpl() { own_event_factory_.reset(); } |
88 own_event_factory_.reset(); | |
89 } | |
90 | 88 |
91 int64_t TimeUntilNextProcess() override { | 89 int64_t TimeUntilNextProcess() override { |
92 int64_t sender_time = sender_.TimeUntilNextProcess(); | 90 int64_t sender_time = sender_.TimeUntilNextProcess(); |
93 int64_t receiver_time = receiver_.TimeUntilNextProcess(); | 91 int64_t receiver_time = receiver_.TimeUntilNextProcess(); |
94 assert(sender_time >= 0); | 92 assert(sender_time >= 0); |
95 assert(receiver_time >= 0); | 93 assert(receiver_time >= 0); |
96 return VCM_MIN(sender_time, receiver_time); | 94 return VCM_MIN(sender_time, receiver_time); |
97 } | 95 } |
98 | 96 |
99 int32_t Process() override { | 97 int32_t Process() override { |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 } | 312 } |
315 | 313 |
316 VideoCodingModule* VideoCodingModule::Create( | 314 VideoCodingModule* VideoCodingModule::Create( |
317 Clock* clock, | 315 Clock* clock, |
318 VideoEncoderRateObserver* encoder_rate_observer, | 316 VideoEncoderRateObserver* encoder_rate_observer, |
319 VCMQMSettingsCallback* qm_settings_callback) { | 317 VCMQMSettingsCallback* qm_settings_callback) { |
320 return new VideoCodingModuleImpl(clock, new EventFactoryImpl, true, | 318 return new VideoCodingModuleImpl(clock, new EventFactoryImpl, true, |
321 encoder_rate_observer, qm_settings_callback); | 319 encoder_rate_observer, qm_settings_callback); |
322 } | 320 } |
323 | 321 |
324 VideoCodingModule* VideoCodingModule::Create( | 322 VideoCodingModule* VideoCodingModule::Create(Clock* clock, |
325 Clock* clock, | 323 EventFactory* event_factory) { |
326 EventFactory* event_factory) { | |
327 assert(clock); | 324 assert(clock); |
328 assert(event_factory); | 325 assert(event_factory); |
329 return new VideoCodingModuleImpl(clock, event_factory, false, nullptr, | 326 return new VideoCodingModuleImpl(clock, event_factory, false, nullptr, |
330 nullptr); | 327 nullptr); |
331 } | 328 } |
332 | 329 |
333 void VideoCodingModule::Destroy(VideoCodingModule* module) { | 330 void VideoCodingModule::Destroy(VideoCodingModule* module) { |
334 if (module != NULL) { | 331 if (module != NULL) { |
335 delete static_cast<VideoCodingModuleImpl*>(module); | 332 delete static_cast<VideoCodingModuleImpl*>(module); |
336 } | 333 } |
337 } | 334 } |
338 } // namespace webrtc | 335 } // namespace webrtc |
OLD | NEW |