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/generic_encoder.h" |
| 12 |
| 13 #include <vector> |
| 14 |
11 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
12 #include "webrtc/base/logging.h" | 16 #include "webrtc/base/logging.h" |
13 #include "webrtc/base/trace_event.h" | 17 #include "webrtc/base/trace_event.h" |
14 #include "webrtc/engine_configurations.h" | 18 #include "webrtc/engine_configurations.h" |
15 #include "webrtc/modules/video_coding/encoded_frame.h" | 19 #include "webrtc/modules/video_coding/encoded_frame.h" |
16 #include "webrtc/modules/video_coding/generic_encoder.h" | |
17 #include "webrtc/modules/video_coding/media_optimization.h" | 20 #include "webrtc/modules/video_coding/media_optimization.h" |
18 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 21 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
19 | 22 |
20 namespace webrtc { | 23 namespace webrtc { |
21 namespace { | 24 namespace { |
22 // Map information from info into rtp. If no relevant information is found | 25 // Map information from info into rtp. If no relevant information is found |
23 // in info, rtp is set to NULL. | 26 // in info, rtp is set to NULL. |
24 void CopyCodecSpecific(const CodecSpecificInfo* info, RTPVideoHeader* rtp) { | 27 void CopyCodecSpecific(const CodecSpecificInfo* info, RTPVideoHeader* rtp) { |
25 RTC_DCHECK(info); | 28 RTC_DCHECK(info); |
26 switch (info->codecType) { | 29 switch (info->codecType) { |
27 case kVideoCodecVP8: { | 30 case kVideoCodecVP8: { |
28 rtp->codec = kRtpVideoVp8; | 31 rtp->codec = kRtpVideoVp8; |
29 rtp->codecHeader.VP8.InitRTPVideoHeaderVP8(); | 32 rtp->codecHeader.VP8.InitRTPVideoHeaderVP8(); |
30 rtp->codecHeader.VP8.pictureId = info->codecSpecific.VP8.pictureId; | 33 rtp->codecHeader.VP8.pictureId = info->codecSpecific.VP8.pictureId; |
31 rtp->codecHeader.VP8.nonReference = | 34 rtp->codecHeader.VP8.nonReference = info->codecSpecific.VP8.nonReference; |
32 info->codecSpecific.VP8.nonReference; | |
33 rtp->codecHeader.VP8.temporalIdx = info->codecSpecific.VP8.temporalIdx; | 35 rtp->codecHeader.VP8.temporalIdx = info->codecSpecific.VP8.temporalIdx; |
34 rtp->codecHeader.VP8.layerSync = info->codecSpecific.VP8.layerSync; | 36 rtp->codecHeader.VP8.layerSync = info->codecSpecific.VP8.layerSync; |
35 rtp->codecHeader.VP8.tl0PicIdx = info->codecSpecific.VP8.tl0PicIdx; | 37 rtp->codecHeader.VP8.tl0PicIdx = info->codecSpecific.VP8.tl0PicIdx; |
36 rtp->codecHeader.VP8.keyIdx = info->codecSpecific.VP8.keyIdx; | 38 rtp->codecHeader.VP8.keyIdx = info->codecSpecific.VP8.keyIdx; |
37 rtp->simulcastIdx = info->codecSpecific.VP8.simulcastIdx; | 39 rtp->simulcastIdx = info->codecSpecific.VP8.simulcastIdx; |
38 return; | 40 return; |
39 } | 41 } |
40 case kVideoCodecVP9: { | 42 case kVideoCodecVP9: { |
41 rtp->codec = kRtpVideoVp9; | 43 rtp->codec = kRtpVideoVp9; |
42 rtp->codecHeader.VP9.InitRTPVideoHeaderVP9(); | 44 rtp->codecHeader.VP9.InitRTPVideoHeaderVP9(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 case kVideoCodecGeneric: | 84 case kVideoCodecGeneric: |
83 rtp->codec = kRtpVideoGeneric; | 85 rtp->codec = kRtpVideoGeneric; |
84 rtp->simulcastIdx = info->codecSpecific.generic.simulcast_idx; | 86 rtp->simulcastIdx = info->codecSpecific.generic.simulcast_idx; |
85 return; | 87 return; |
86 default: | 88 default: |
87 return; | 89 return; |
88 } | 90 } |
89 } | 91 } |
90 } // namespace | 92 } // namespace |
91 | 93 |
92 //#define DEBUG_ENCODER_BIT_STREAM | 94 // #define DEBUG_ENCODER_BIT_STREAM |
93 | 95 |
94 VCMGenericEncoder::VCMGenericEncoder( | 96 VCMGenericEncoder::VCMGenericEncoder( |
95 VideoEncoder* encoder, | 97 VideoEncoder* encoder, |
96 VideoEncoderRateObserver* rate_observer, | 98 VideoEncoderRateObserver* rate_observer, |
97 VCMEncodedFrameCallback* encoded_frame_callback, | 99 VCMEncodedFrameCallback* encoded_frame_callback, |
98 bool internalSource) | 100 bool internalSource) |
99 : encoder_(encoder), | 101 : encoder_(encoder), |
100 rate_observer_(rate_observer), | 102 rate_observer_(rate_observer), |
101 vcm_encoded_frame_callback_(encoded_frame_callback), | 103 vcm_encoded_frame_callback_(encoded_frame_callback), |
102 internal_source_(internalSource), | 104 internal_source_(internalSource), |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 params.input_frame_rate); | 190 params.input_frame_rate); |
189 } | 191 } |
190 } | 192 } |
191 } | 193 } |
192 | 194 |
193 EncoderParameters VCMGenericEncoder::GetEncoderParameters() const { | 195 EncoderParameters VCMGenericEncoder::GetEncoderParameters() const { |
194 rtc::CritScope lock(¶ms_lock_); | 196 rtc::CritScope lock(¶ms_lock_); |
195 return encoder_params_; | 197 return encoder_params_; |
196 } | 198 } |
197 | 199 |
198 int32_t | 200 int32_t VCMGenericEncoder::SetPeriodicKeyFrames(bool enable) { |
199 VCMGenericEncoder::SetPeriodicKeyFrames(bool enable) | 201 return encoder_->SetPeriodicKeyFrames(enable); |
200 { | |
201 return encoder_->SetPeriodicKeyFrames(enable); | |
202 } | 202 } |
203 | 203 |
204 int32_t VCMGenericEncoder::RequestFrame( | 204 int32_t VCMGenericEncoder::RequestFrame( |
205 const std::vector<FrameType>& frame_types) { | 205 const std::vector<FrameType>& frame_types) { |
206 VideoFrame image; | 206 VideoFrame image; |
207 return encoder_->Encode(image, NULL, &frame_types); | 207 return encoder_->Encode(image, NULL, &frame_types); |
208 } | 208 } |
209 | 209 |
210 bool | 210 bool VCMGenericEncoder::InternalSource() const { |
211 VCMGenericEncoder::InternalSource() const | 211 return internal_source_; |
212 { | |
213 return internal_source_; | |
214 } | 212 } |
215 | 213 |
216 void VCMGenericEncoder::OnDroppedFrame() { | 214 void VCMGenericEncoder::OnDroppedFrame() { |
217 encoder_->OnDroppedFrame(); | 215 encoder_->OnDroppedFrame(); |
218 } | 216 } |
219 | 217 |
220 bool VCMGenericEncoder::SupportsNativeHandle() const { | 218 bool VCMGenericEncoder::SupportsNativeHandle() const { |
221 return encoder_->SupportsNativeHandle(); | 219 return encoder_->SupportsNativeHandle(); |
222 } | 220 } |
223 | 221 |
224 int VCMGenericEncoder::GetTargetFramerate() { | 222 int VCMGenericEncoder::GetTargetFramerate() { |
225 return encoder_->GetTargetFramerate(); | 223 return encoder_->GetTargetFramerate(); |
226 } | 224 } |
227 | 225 |
228 /*************************** | 226 /*************************** |
229 * Callback Implementation | 227 * Callback Implementation |
230 ***************************/ | 228 ***************************/ |
231 VCMEncodedFrameCallback::VCMEncodedFrameCallback( | 229 VCMEncodedFrameCallback::VCMEncodedFrameCallback( |
232 EncodedImageCallback* post_encode_callback) | 230 EncodedImageCallback* post_encode_callback) |
233 : send_callback_(), | 231 : send_callback_(), |
234 _mediaOpt(NULL), | 232 _mediaOpt(NULL), |
235 _payloadType(0), | 233 _payloadType(0), |
236 _internalSource(false), | 234 _internalSource(false), |
237 _rotation(kVideoRotation_0), | 235 _rotation(kVideoRotation_0), |
238 post_encode_callback_(post_encode_callback) | 236 post_encode_callback_(post_encode_callback) |
239 #ifdef DEBUG_ENCODER_BIT_STREAM | 237 #ifdef DEBUG_ENCODER_BIT_STREAM |
240 , | 238 , |
241 _bitStreamAfterEncoder(NULL) | 239 _bitStreamAfterEncoder(NULL) |
242 #endif | 240 #endif |
243 { | 241 { |
244 #ifdef DEBUG_ENCODER_BIT_STREAM | 242 #ifdef DEBUG_ENCODER_BIT_STREAM |
245 _bitStreamAfterEncoder = fopen("encoderBitStream.bit", "wb"); | 243 _bitStreamAfterEncoder = fopen("encoderBitStream.bit", "wb"); |
246 #endif | 244 #endif |
247 } | 245 } |
248 | 246 |
249 VCMEncodedFrameCallback::~VCMEncodedFrameCallback() | 247 VCMEncodedFrameCallback::~VCMEncodedFrameCallback() { |
250 { | |
251 #ifdef DEBUG_ENCODER_BIT_STREAM | 248 #ifdef DEBUG_ENCODER_BIT_STREAM |
252 fclose(_bitStreamAfterEncoder); | 249 fclose(_bitStreamAfterEncoder); |
253 #endif | 250 #endif |
254 } | 251 } |
255 | 252 |
256 int32_t | 253 int32_t VCMEncodedFrameCallback::SetTransportCallback( |
257 VCMEncodedFrameCallback::SetTransportCallback(VCMPacketizationCallback* transpor
t) | 254 VCMPacketizationCallback* transport) { |
258 { | 255 send_callback_ = transport; |
259 send_callback_ = transport; | 256 return VCM_OK; |
260 return VCM_OK; | |
261 } | 257 } |
262 | 258 |
263 int32_t VCMEncodedFrameCallback::Encoded( | 259 int32_t VCMEncodedFrameCallback::Encoded( |
264 const EncodedImage& encoded_image, | 260 const EncodedImage& encoded_image, |
265 const CodecSpecificInfo* codecSpecificInfo, | 261 const CodecSpecificInfo* codecSpecificInfo, |
266 const RTPFragmentationHeader* fragmentationHeader) { | 262 const RTPFragmentationHeader* fragmentationHeader) { |
267 TRACE_EVENT_INSTANT1("webrtc", "VCMEncodedFrameCallback::Encoded", | 263 TRACE_EVENT_INSTANT1("webrtc", "VCMEncodedFrameCallback::Encoded", |
268 "timestamp", encoded_image._timeStamp); | 264 "timestamp", encoded_image._timeStamp); |
269 post_encode_callback_->Encoded(encoded_image, NULL, NULL); | 265 post_encode_callback_->Encoded(encoded_image, NULL, NULL); |
270 | 266 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 _mediaOpt = mediaOpt; | 302 _mediaOpt = mediaOpt; |
307 } | 303 } |
308 | 304 |
309 void VCMEncodedFrameCallback::SignalLastEncoderImplementationUsed( | 305 void VCMEncodedFrameCallback::SignalLastEncoderImplementationUsed( |
310 const char* implementation_name) { | 306 const char* implementation_name) { |
311 if (send_callback_) | 307 if (send_callback_) |
312 send_callback_->OnEncoderImplementationName(implementation_name); | 308 send_callback_->OnEncoderImplementationName(implementation_name); |
313 } | 309 } |
314 | 310 |
315 } // namespace webrtc | 311 } // namespace webrtc |
OLD | NEW |