| 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 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 case kVideoCodecGeneric: | 84 case kVideoCodecGeneric: |
| 85 rtp->codec = kRtpVideoGeneric; | 85 rtp->codec = kRtpVideoGeneric; |
| 86 rtp->simulcastIdx = info->codecSpecific.generic.simulcast_idx; | 86 rtp->simulcastIdx = info->codecSpecific.generic.simulcast_idx; |
| 87 return; | 87 return; |
| 88 default: | 88 default: |
| 89 return; | 89 return; |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 } // namespace | 92 } // namespace |
| 93 | 93 |
| 94 // #define DEBUG_ENCODER_BIT_STREAM | |
| 95 | |
| 96 VCMGenericEncoder::VCMGenericEncoder( | 94 VCMGenericEncoder::VCMGenericEncoder( |
| 97 VideoEncoder* encoder, | 95 VideoEncoder* encoder, |
| 98 VideoEncoderRateObserver* rate_observer, | 96 VideoEncoderRateObserver* rate_observer, |
| 99 VCMEncodedFrameCallback* encoded_frame_callback, | 97 VCMEncodedFrameCallback* encoded_frame_callback, |
| 100 bool internalSource) | 98 bool internalSource) |
| 101 : encoder_(encoder), | 99 : encoder_(encoder), |
| 102 rate_observer_(rate_observer), | 100 rate_observer_(rate_observer), |
| 103 vcm_encoded_frame_callback_(encoded_frame_callback), | 101 vcm_encoded_frame_callback_(encoded_frame_callback), |
| 104 internal_source_(internalSource), | 102 internal_source_(internalSource), |
| 105 encoder_params_({0, 0, 0, 0}), | 103 encoder_params_({0, 0, 0, 0}), |
| (...skipping 18 matching lines...) Expand all Loading... |
| 124 } | 122 } |
| 125 | 123 |
| 126 is_screenshare_ = settings->mode == VideoCodecMode::kScreensharing; | 124 is_screenshare_ = settings->mode == VideoCodecMode::kScreensharing; |
| 127 if (encoder_->InitEncode(settings, numberOfCores, maxPayloadSize) != 0) { | 125 if (encoder_->InitEncode(settings, numberOfCores, maxPayloadSize) != 0) { |
| 128 LOG(LS_ERROR) << "Failed to initialize the encoder associated with " | 126 LOG(LS_ERROR) << "Failed to initialize the encoder associated with " |
| 129 "payload name: " | 127 "payload name: " |
| 130 << settings->plName; | 128 << settings->plName; |
| 131 return -1; | 129 return -1; |
| 132 } | 130 } |
| 133 encoder_->RegisterEncodeCompleteCallback(vcm_encoded_frame_callback_); | 131 encoder_->RegisterEncodeCompleteCallback(vcm_encoded_frame_callback_); |
| 132 vcm_encoded_frame_callback_->codec_type_ = settings->codecType; |
| 134 return 0; | 133 return 0; |
| 135 } | 134 } |
| 136 | 135 |
| 137 int32_t VCMGenericEncoder::Encode(const VideoFrame& inputFrame, | 136 int32_t VCMGenericEncoder::Encode(const VideoFrame& inputFrame, |
| 138 const CodecSpecificInfo* codecSpecificInfo, | 137 const CodecSpecificInfo* codecSpecificInfo, |
| 139 const std::vector<FrameType>& frameTypes) { | 138 const std::vector<FrameType>& frameTypes) { |
| 140 TRACE_EVENT1("webrtc", "VCMGenericEncoder::Encode", "timestamp", | 139 TRACE_EVENT1("webrtc", "VCMGenericEncoder::Encode", "timestamp", |
| 141 inputFrame.timestamp()); | 140 inputFrame.timestamp()); |
| 142 | 141 |
| 143 for (FrameType frame_type : frameTypes) | 142 for (FrameType frame_type : frameTypes) |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 /*************************** | 226 /*************************** |
| 228 * Callback Implementation | 227 * Callback Implementation |
| 229 ***************************/ | 228 ***************************/ |
| 230 VCMEncodedFrameCallback::VCMEncodedFrameCallback( | 229 VCMEncodedFrameCallback::VCMEncodedFrameCallback( |
| 231 EncodedImageCallback* post_encode_callback) | 230 EncodedImageCallback* post_encode_callback) |
| 232 : send_callback_(), | 231 : send_callback_(), |
| 233 _mediaOpt(NULL), | 232 _mediaOpt(NULL), |
| 234 _payloadType(0), | 233 _payloadType(0), |
| 235 _internalSource(false), | 234 _internalSource(false), |
| 236 _rotation(kVideoRotation_0), | 235 _rotation(kVideoRotation_0), |
| 237 post_encode_callback_(post_encode_callback) | 236 post_encode_callback_(post_encode_callback) {} |
| 238 #ifdef DEBUG_ENCODER_BIT_STREAM | |
| 239 , | |
| 240 _bitStreamAfterEncoder(NULL) | |
| 241 #endif | |
| 242 { | |
| 243 #ifdef DEBUG_ENCODER_BIT_STREAM | |
| 244 _bitStreamAfterEncoder = fopen("encoderBitStream.bit", "wb"); | |
| 245 #endif | |
| 246 } | |
| 247 | 237 |
| 248 VCMEncodedFrameCallback::~VCMEncodedFrameCallback() { | 238 VCMEncodedFrameCallback::~VCMEncodedFrameCallback() {} |
| 249 #ifdef DEBUG_ENCODER_BIT_STREAM | |
| 250 fclose(_bitStreamAfterEncoder); | |
| 251 #endif | |
| 252 } | |
| 253 | 239 |
| 254 int32_t VCMEncodedFrameCallback::SetTransportCallback( | 240 int32_t VCMEncodedFrameCallback::SetTransportCallback( |
| 255 VCMPacketizationCallback* transport) { | 241 VCMPacketizationCallback* transport) { |
| 256 send_callback_ = transport; | 242 send_callback_ = transport; |
| 257 return VCM_OK; | 243 return VCM_OK; |
| 258 } | 244 } |
| 259 | 245 |
| 260 int32_t VCMEncodedFrameCallback::Encoded( | 246 int32_t VCMEncodedFrameCallback::Encoded( |
| 261 const EncodedImage& encoded_image, | 247 const EncodedImage& encoded_image, |
| 262 const CodecSpecificInfo* codecSpecificInfo, | 248 const CodecSpecificInfo* codecSpecificInfo, |
| 263 const RTPFragmentationHeader* fragmentationHeader) { | 249 const RTPFragmentationHeader* fragmentationHeader) { |
| 264 TRACE_EVENT_INSTANT1("webrtc", "VCMEncodedFrameCallback::Encoded", | 250 TRACE_EVENT_INSTANT1("webrtc", "VCMEncodedFrameCallback::Encoded", |
| 265 "timestamp", encoded_image._timeStamp); | 251 "timestamp", encoded_image._timeStamp); |
| 266 post_encode_callback_->Encoded(encoded_image, NULL, NULL); | 252 post_encode_callback_->Encoded(encoded_image, NULL, NULL); |
| 267 | 253 |
| 268 if (send_callback_ == NULL) { | 254 if (send_callback_ == NULL) { |
| 269 return VCM_UNINITIALIZED; | 255 return VCM_UNINITIALIZED; |
| 270 } | 256 } |
| 271 | 257 |
| 272 #ifdef DEBUG_ENCODER_BIT_STREAM | 258 if (kEnableFrameRecording) { |
| 273 if (_bitStreamAfterEncoder != NULL) { | 259 int layer = GetLayer(*codecSpecificInfo); |
| 274 fwrite(encoded_image._buffer, 1, encoded_image._length, | 260 if (file_writers_[layer] == nullptr) { |
| 275 _bitStreamAfterEncoder); | 261 uint64_t instance_id = reinterpret_cast<uint64_t>(this); |
| 262 std::ostringstream oss; |
| 263 oss << "bitstream_" << instance_id << "_" << layer << ".ivf"; |
| 264 file_writers_[layer] = |
| 265 IvfFileWriter::Open(oss.str().c_str(), codec_type_); |
| 266 } |
| 267 if (file_writers_[layer].get() != nullptr) { |
| 268 bool ok = file_writers_[layer]->WriteFrame(encoded_image); |
| 269 RTC_DCHECK(ok); |
| 270 } |
| 276 } | 271 } |
| 277 #endif | |
| 278 | 272 |
| 279 RTPVideoHeader rtpVideoHeader; | 273 RTPVideoHeader rtpVideoHeader; |
| 280 memset(&rtpVideoHeader, 0, sizeof(RTPVideoHeader)); | 274 memset(&rtpVideoHeader, 0, sizeof(RTPVideoHeader)); |
| 281 RTPVideoHeader* rtpVideoHeaderPtr = &rtpVideoHeader; | 275 RTPVideoHeader* rtpVideoHeaderPtr = &rtpVideoHeader; |
| 282 if (codecSpecificInfo) { | 276 if (codecSpecificInfo) { |
| 283 CopyCodecSpecific(codecSpecificInfo, rtpVideoHeaderPtr); | 277 CopyCodecSpecific(codecSpecificInfo, rtpVideoHeaderPtr); |
| 284 } | 278 } |
| 285 rtpVideoHeader.rotation = _rotation; | 279 rtpVideoHeader.rotation = _rotation; |
| 286 | 280 |
| 287 int32_t callbackReturn = send_callback_->SendData( | 281 int32_t callbackReturn = send_callback_->SendData( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 302 media_optimization::MediaOptimization* mediaOpt) { | 296 media_optimization::MediaOptimization* mediaOpt) { |
| 303 _mediaOpt = mediaOpt; | 297 _mediaOpt = mediaOpt; |
| 304 } | 298 } |
| 305 | 299 |
| 306 void VCMEncodedFrameCallback::SignalLastEncoderImplementationUsed( | 300 void VCMEncodedFrameCallback::SignalLastEncoderImplementationUsed( |
| 307 const char* implementation_name) { | 301 const char* implementation_name) { |
| 308 if (send_callback_) | 302 if (send_callback_) |
| 309 send_callback_->OnEncoderImplementationName(implementation_name); | 303 send_callback_->OnEncoderImplementationName(implementation_name); |
| 310 } | 304 } |
| 311 | 305 |
| 306 int VCMEncodedFrameCallback::GetLayer(const CodecSpecificInfo& codec_specific) { |
| 307 switch (codec_type_) { |
| 308 case kVideoCodecVP8: |
| 309 return codec_specific.codecSpecific.VP8.simulcastIdx; |
| 310 case kVideoCodecVP9: |
| 311 case kVideoCodecH264: |
| 312 return 1; |
| 313 default: |
| 314 RTC_NOTREACHED(); |
| 315 return -1; |
| 316 } |
| 317 } |
| 318 |
| 312 } // namespace webrtc | 319 } // namespace webrtc |
| OLD | NEW |