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