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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 params.input_frame_rate); | 184 params.input_frame_rate); |
183 } | 185 } |
184 } | 186 } |
185 } | 187 } |
186 | 188 |
187 EncoderParameters VCMGenericEncoder::GetEncoderParameters() const { | 189 EncoderParameters VCMGenericEncoder::GetEncoderParameters() const { |
188 rtc::CritScope lock(¶ms_lock_); | 190 rtc::CritScope lock(¶ms_lock_); |
189 return encoder_params_; | 191 return encoder_params_; |
190 } | 192 } |
191 | 193 |
192 int32_t | 194 int32_t VCMGenericEncoder::SetPeriodicKeyFrames(bool enable) { |
193 VCMGenericEncoder::SetPeriodicKeyFrames(bool enable) | 195 return encoder_->SetPeriodicKeyFrames(enable); |
194 { | |
195 return encoder_->SetPeriodicKeyFrames(enable); | |
196 } | 196 } |
197 | 197 |
198 int32_t VCMGenericEncoder::RequestFrame( | 198 int32_t VCMGenericEncoder::RequestFrame( |
199 const std::vector<FrameType>& frame_types) { | 199 const std::vector<FrameType>& frame_types) { |
200 VideoFrame image; | 200 VideoFrame image; |
201 return encoder_->Encode(image, NULL, &frame_types); | 201 return encoder_->Encode(image, NULL, &frame_types); |
202 } | 202 } |
203 | 203 |
204 bool | 204 bool VCMGenericEncoder::InternalSource() const { |
205 VCMGenericEncoder::InternalSource() const | 205 return internal_source_; |
206 { | |
207 return internal_source_; | |
208 } | 206 } |
209 | 207 |
210 void VCMGenericEncoder::OnDroppedFrame() { | 208 void VCMGenericEncoder::OnDroppedFrame() { |
211 encoder_->OnDroppedFrame(); | 209 encoder_->OnDroppedFrame(); |
212 } | 210 } |
213 | 211 |
214 bool VCMGenericEncoder::SupportsNativeHandle() const { | 212 bool VCMGenericEncoder::SupportsNativeHandle() const { |
215 return encoder_->SupportsNativeHandle(); | 213 return encoder_->SupportsNativeHandle(); |
216 } | 214 } |
217 | 215 |
218 int VCMGenericEncoder::GetTargetFramerate() { | 216 int VCMGenericEncoder::GetTargetFramerate() { |
219 return encoder_->GetTargetFramerate(); | 217 return encoder_->GetTargetFramerate(); |
220 } | 218 } |
221 | 219 |
222 /*************************** | 220 /*************************** |
223 * Callback Implementation | 221 * Callback Implementation |
224 ***************************/ | 222 ***************************/ |
225 VCMEncodedFrameCallback::VCMEncodedFrameCallback( | 223 VCMEncodedFrameCallback::VCMEncodedFrameCallback( |
226 EncodedImageCallback* post_encode_callback) | 224 EncodedImageCallback* post_encode_callback) |
227 : _sendCallback(), | 225 : _sendCallback(), |
228 _mediaOpt(NULL), | 226 _mediaOpt(NULL), |
229 _payloadType(0), | 227 _payloadType(0), |
230 _internalSource(false), | 228 _internalSource(false), |
231 _rotation(kVideoRotation_0), | 229 _rotation(kVideoRotation_0), |
232 post_encode_callback_(post_encode_callback) | 230 post_encode_callback_(post_encode_callback) |
233 #ifdef DEBUG_ENCODER_BIT_STREAM | 231 #ifdef DEBUG_ENCODER_BIT_STREAM |
234 , | 232 , |
235 _bitStreamAfterEncoder(NULL) | 233 _bitStreamAfterEncoder(NULL) |
236 #endif | 234 #endif |
237 { | 235 { |
238 #ifdef DEBUG_ENCODER_BIT_STREAM | 236 #ifdef DEBUG_ENCODER_BIT_STREAM |
239 _bitStreamAfterEncoder = fopen("encoderBitStream.bit", "wb"); | 237 _bitStreamAfterEncoder = fopen("encoderBitStream.bit", "wb"); |
240 #endif | 238 #endif |
241 } | 239 } |
242 | 240 |
243 VCMEncodedFrameCallback::~VCMEncodedFrameCallback() | 241 VCMEncodedFrameCallback::~VCMEncodedFrameCallback() { |
244 { | |
245 #ifdef DEBUG_ENCODER_BIT_STREAM | 242 #ifdef DEBUG_ENCODER_BIT_STREAM |
246 fclose(_bitStreamAfterEncoder); | 243 fclose(_bitStreamAfterEncoder); |
247 #endif | 244 #endif |
248 } | 245 } |
249 | 246 |
250 int32_t | 247 int32_t VCMEncodedFrameCallback::SetTransportCallback( |
251 VCMEncodedFrameCallback::SetTransportCallback(VCMPacketizationCallback* transpor
t) | 248 VCMPacketizationCallback* transport) { |
252 { | 249 _sendCallback = transport; |
253 _sendCallback = transport; | 250 return VCM_OK; |
254 return VCM_OK; | |
255 } | 251 } |
256 | 252 |
257 int32_t VCMEncodedFrameCallback::Encoded( | 253 int32_t VCMEncodedFrameCallback::Encoded( |
258 const EncodedImage& encodedImage, | 254 const EncodedImage& encodedImage, |
259 const CodecSpecificInfo* codecSpecificInfo, | 255 const CodecSpecificInfo* codecSpecificInfo, |
260 const RTPFragmentationHeader* fragmentationHeader) { | 256 const RTPFragmentationHeader* fragmentationHeader) { |
261 TRACE_EVENT_INSTANT1("webrtc", "VCMEncodedFrameCallback::Encoded", | 257 TRACE_EVENT_INSTANT1("webrtc", "VCMEncodedFrameCallback::Encoded", |
262 "timestamp", encodedImage._timeStamp); | 258 "timestamp", encodedImage._timeStamp); |
263 RTC_DCHECK(encodedImage._frameType == kVideoFrameKey || | 259 RTC_DCHECK(encodedImage._frameType == kVideoFrameKey || |
264 encodedImage._frameType == kVideoFrameDelta); | 260 encodedImage._frameType == kVideoFrameDelta); |
(...skipping 25 matching lines...) Expand all Loading... |
290 } | 286 } |
291 | 287 |
292 if (_mediaOpt != NULL) { | 288 if (_mediaOpt != NULL) { |
293 _mediaOpt->UpdateWithEncodedData(encodedImage); | 289 _mediaOpt->UpdateWithEncodedData(encodedImage); |
294 if (_internalSource) | 290 if (_internalSource) |
295 return _mediaOpt->DropFrame(); // Signal to encoder to drop next frame. | 291 return _mediaOpt->DropFrame(); // Signal to encoder to drop next frame. |
296 } | 292 } |
297 return VCM_OK; | 293 return VCM_OK; |
298 } | 294 } |
299 | 295 |
300 void | 296 void VCMEncodedFrameCallback::SetMediaOpt( |
301 VCMEncodedFrameCallback::SetMediaOpt( | 297 media_optimization::MediaOptimization* mediaOpt) { |
302 media_optimization::MediaOptimization *mediaOpt) | 298 _mediaOpt = mediaOpt; |
303 { | |
304 _mediaOpt = mediaOpt; | |
305 } | 299 } |
306 | 300 |
307 } // namespace webrtc | 301 } // namespace webrtc |
OLD | NEW |