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" | 11 #include "webrtc/modules/video_coding/video_coding_impl.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
| 14 #include <utility> |
14 | 15 |
15 #include "webrtc/common_types.h" | 16 #include "webrtc/common_types.h" |
| 17 #include "webrtc/common_video/include/video_bitrate_allocator.h" |
16 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 18 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
17 #include "webrtc/base/criticalsection.h" | 19 #include "webrtc/base/criticalsection.h" |
| 20 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" |
| 21 #include "webrtc/modules/video_coding/include/video_codec_initializer.h" |
18 #include "webrtc/modules/video_coding/include/video_codec_interface.h" | 22 #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
19 #include "webrtc/modules/video_coding/encoded_frame.h" | 23 #include "webrtc/modules/video_coding/encoded_frame.h" |
20 #include "webrtc/modules/video_coding/jitter_buffer.h" | 24 #include "webrtc/modules/video_coding/jitter_buffer.h" |
21 #include "webrtc/modules/video_coding/packet.h" | 25 #include "webrtc/modules/video_coding/packet.h" |
22 #include "webrtc/system_wrappers/include/clock.h" | 26 #include "webrtc/system_wrappers/include/clock.h" |
23 | 27 |
24 namespace webrtc { | 28 namespace webrtc { |
25 namespace vcm { | 29 namespace vcm { |
26 | 30 |
27 int64_t VCMProcessTimer::Period() const { | 31 int64_t VCMProcessTimer::Period() const { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 } | 101 } |
98 | 102 |
99 void Process() override { | 103 void Process() override { |
100 sender_.Process(); | 104 sender_.Process(); |
101 receiver_.Process(); | 105 receiver_.Process(); |
102 } | 106 } |
103 | 107 |
104 int32_t RegisterSendCodec(const VideoCodec* sendCodec, | 108 int32_t RegisterSendCodec(const VideoCodec* sendCodec, |
105 uint32_t numberOfCores, | 109 uint32_t numberOfCores, |
106 uint32_t maxPayloadSize) override { | 110 uint32_t maxPayloadSize) override { |
| 111 if (sendCodec != nullptr && sendCodec->codecType == kVideoCodecVP8) { |
| 112 // Set up a rate allocator and temporal layers factory for this vp8 |
| 113 // instance. The codec impl will have a raw pointer to the TL factory, |
| 114 // and will call it when initializing. Since this can happen |
| 115 // asynchronously keep the instance alive until destruction or until a |
| 116 // new send codec is registered. |
| 117 VideoCodec vp8_codec = *sendCodec; |
| 118 std::unique_ptr<TemporalLayersFactory> tl_factory( |
| 119 new TemporalLayersFactory()); |
| 120 vp8_codec.VP8()->tl_factory = tl_factory.get(); |
| 121 rate_allocator_ = VideoCodecInitializer::CreateBitrateAllocator( |
| 122 vp8_codec, std::move(tl_factory)); |
| 123 return sender_.RegisterSendCodec(&vp8_codec, numberOfCores, |
| 124 maxPayloadSize); |
| 125 } |
107 return sender_.RegisterSendCodec(sendCodec, numberOfCores, maxPayloadSize); | 126 return sender_.RegisterSendCodec(sendCodec, numberOfCores, maxPayloadSize); |
108 } | 127 } |
109 | 128 |
110 int32_t RegisterExternalEncoder(VideoEncoder* externalEncoder, | 129 int32_t RegisterExternalEncoder(VideoEncoder* externalEncoder, |
111 uint8_t payloadType, | 130 uint8_t payloadType, |
112 bool internalSource) override { | 131 bool internalSource) override { |
113 sender_.RegisterExternalEncoder(externalEncoder, payloadType, | 132 sender_.RegisterExternalEncoder(externalEncoder, payloadType, |
114 internalSource); | 133 internalSource); |
115 return 0; | 134 return 0; |
116 } | 135 } |
117 | 136 |
118 int Bitrate(unsigned int* bitrate) const override { | 137 int Bitrate(unsigned int* bitrate) const override { |
119 return sender_.Bitrate(bitrate); | 138 return sender_.Bitrate(bitrate); |
120 } | 139 } |
121 | 140 |
122 int FrameRate(unsigned int* framerate) const override { | 141 int FrameRate(unsigned int* framerate) const override { |
123 return sender_.FrameRate(framerate); | 142 return sender_.FrameRate(framerate); |
124 } | 143 } |
125 | 144 |
126 int32_t SetChannelParameters(uint32_t target_bitrate, // bits/s. | 145 int32_t SetChannelParameters(uint32_t target_bitrate, // bits/s. |
127 uint8_t lossRate, | 146 uint8_t lossRate, |
128 int64_t rtt) override { | 147 int64_t rtt) override { |
129 return sender_.SetChannelParameters(target_bitrate, lossRate, rtt); | 148 return sender_.SetChannelParameters(target_bitrate, lossRate, rtt, |
| 149 rate_allocator_.get()); |
130 } | 150 } |
131 | 151 |
132 int32_t RegisterProtectionCallback( | 152 int32_t RegisterProtectionCallback( |
133 VCMProtectionCallback* protection) override { | 153 VCMProtectionCallback* protection) override { |
134 return sender_.RegisterProtectionCallback(protection); | 154 return sender_.RegisterProtectionCallback(protection); |
135 } | 155 } |
136 | 156 |
137 int32_t SetVideoProtection(VCMVideoProtection videoProtection, | 157 int32_t SetVideoProtection(VCMVideoProtection videoProtection, |
138 bool enable) override { | 158 bool enable) override { |
139 // TODO(pbos): Remove enable from receive-side protection modes as well. | 159 // TODO(pbos): Remove enable from receive-side protection modes as well. |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 void RegisterPostEncodeImageCallback( | 269 void RegisterPostEncodeImageCallback( |
250 EncodedImageCallback* observer) override { | 270 EncodedImageCallback* observer) override { |
251 post_encode_callback_.Register(observer); | 271 post_encode_callback_.Register(observer); |
252 } | 272 } |
253 | 273 |
254 void TriggerDecoderShutdown() override { receiver_.TriggerDecoderShutdown(); } | 274 void TriggerDecoderShutdown() override { receiver_.TriggerDecoderShutdown(); } |
255 | 275 |
256 private: | 276 private: |
257 EncodedImageCallbackWrapper post_encode_callback_; | 277 EncodedImageCallbackWrapper post_encode_callback_; |
258 vcm::VideoSender sender_; | 278 vcm::VideoSender sender_; |
| 279 std::unique_ptr<VideoBitrateAllocator> rate_allocator_; |
259 vcm::VideoReceiver receiver_; | 280 vcm::VideoReceiver receiver_; |
260 }; | 281 }; |
261 } // namespace | 282 } // namespace |
262 | 283 |
263 void VideoCodingModule::Codec(VideoCodecType codecType, VideoCodec* codec) { | 284 void VideoCodingModule::Codec(VideoCodecType codecType, VideoCodec* codec) { |
264 VCMCodecDataBase::Codec(codecType, codec); | 285 VCMCodecDataBase::Codec(codecType, codec); |
265 } | 286 } |
266 | 287 |
267 // Create method for the new jitter buffer. | 288 // Create method for the new jitter buffer. |
268 VideoCodingModule* VideoCodingModule::Create( | 289 VideoCodingModule* VideoCodingModule::Create( |
(...skipping 22 matching lines...) Expand all Loading... |
291 EventFactory* event_factory, | 312 EventFactory* event_factory, |
292 NackSender* nack_sender, | 313 NackSender* nack_sender, |
293 KeyFrameRequestSender* keyframe_request_sender) { | 314 KeyFrameRequestSender* keyframe_request_sender) { |
294 assert(clock); | 315 assert(clock); |
295 assert(event_factory); | 316 assert(event_factory); |
296 return new VideoCodingModuleImpl(clock, event_factory, nack_sender, | 317 return new VideoCodingModuleImpl(clock, event_factory, nack_sender, |
297 keyframe_request_sender, nullptr); | 318 keyframe_request_sender, nullptr); |
298 } | 319 } |
299 | 320 |
300 } // namespace webrtc | 321 } // namespace webrtc |
OLD | NEW |