Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 335 | 335 |
| 336 namespace webrtc { | 336 namespace webrtc { |
| 337 | 337 |
| 338 // .5 is set as a mininum to prevent overcompensating for large temporary | 338 // .5 is set as a mininum to prevent overcompensating for large temporary |
| 339 // overshoots. We don't want to degrade video quality too badly. | 339 // overshoots. We don't want to degrade video quality too badly. |
| 340 // .95 is set to prevent oscillations. When a lower bitrate is set on the | 340 // .95 is set to prevent oscillations. When a lower bitrate is set on the |
| 341 // encoder than previously set, its output seems to have a brief period of | 341 // encoder than previously set, its output seems to have a brief period of |
| 342 // drastically reduced bitrate, so we want to avoid that. In steady state | 342 // drastically reduced bitrate, so we want to avoid that. In steady state |
| 343 // conditions, 0.95 seems to give us better overall bitrate over long periods | 343 // conditions, 0.95 seems to give us better overall bitrate over long periods |
| 344 // of time. | 344 // of time. |
| 345 H264VideoToolboxEncoder::H264VideoToolboxEncoder( | 345 H264VideoToolboxEncoder::H264VideoToolboxEncoder(const cricket::VideoCodec& code c) |
| 346 const cricket::VideoCodec& codec) | |
| 347 : callback_(nullptr), | 346 : callback_(nullptr), |
| 348 compression_session_(nullptr), | 347 compression_session_(nullptr), |
| 349 bitrate_adjuster_(Clock::GetRealTimeClock(), .5, .95), | 348 bitrate_adjuster_(Clock::GetRealTimeClock(), .5, .95), |
| 349 packetization_mode_(H264PacketizationMode::NonInterleaved), | |
| 350 profile_(internal::ExtractProfile(codec)) { | 350 profile_(internal::ExtractProfile(codec)) { |
| 351 LOG(LS_INFO) << "Using profile " << internal::CFStringToString(profile_); | 351 LOG(LS_INFO) << "Using profile " << internal::CFStringToString(profile_); |
| 352 RTC_CHECK(cricket::CodecNamesEq(codec.name, cricket::kH264CodecName)); | |
| 352 } | 353 } |
| 353 | 354 |
| 354 H264VideoToolboxEncoder::~H264VideoToolboxEncoder() { | 355 H264VideoToolboxEncoder::~H264VideoToolboxEncoder() { |
| 355 DestroyCompressionSession(); | 356 DestroyCompressionSession(); |
| 356 } | 357 } |
| 357 | 358 |
| 358 int H264VideoToolboxEncoder::InitEncode(const VideoCodec* codec_settings, | 359 int H264VideoToolboxEncoder::InitEncode(const VideoCodec* codec_settings, |
| 359 int number_of_cores, | 360 int number_of_cores, |
| 360 size_t max_payload_size) { | 361 size_t max_payload_size) { |
| 361 RTC_DCHECK(codec_settings); | 362 RTC_DCHECK(codec_settings); |
| 362 RTC_DCHECK_EQ(codec_settings->codecType, kVideoCodecH264); | 363 RTC_DCHECK_EQ(codec_settings->codecType, kVideoCodecH264); |
| 363 | 364 |
| 364 width_ = codec_settings->width; | 365 width_ = codec_settings->width; |
| 365 height_ = codec_settings->height; | 366 height_ = codec_settings->height; |
| 366 // We can only set average bitrate on the HW encoder. | 367 // We can only set average bitrate on the HW encoder. |
| 367 target_bitrate_bps_ = codec_settings->startBitrate; | 368 target_bitrate_bps_ = codec_settings->startBitrate; |
| 368 bitrate_adjuster_.SetTargetBitrateBps(target_bitrate_bps_); | 369 bitrate_adjuster_.SetTargetBitrateBps(target_bitrate_bps_); |
| 369 | 370 |
| 370 // TODO(tkchin): Try setting payload size via | 371 // TODO(tkchin): Try setting payload size via |
| 371 // kVTCompressionPropertyKey_MaxH264SliceBytes. | 372 // kVTCompressionPropertyKey_MaxH264SliceBytes. |
| 372 | 373 |
| 373 return ResetCompressionSession(); | 374 return ResetCompressionSession(); |
| 374 } | 375 } |
| 375 | 376 |
| 376 int H264VideoToolboxEncoder::Encode( | 377 int H264VideoToolboxEncoder::Encode( |
| 377 const VideoFrame& frame, | 378 const VideoFrame& frame, |
| 378 const CodecSpecificInfo* codec_specific_info, | 379 const CodecSpecificInfo* codec_specific_info, |
|
hta-webrtc
2016/12/15 14:29:00
The next-level problem is probably that this param
kthelgason
2016/12/15 14:38:13
I think this param is always NULL, at least when I
| |
| 379 const std::vector<FrameType>* frame_types) { | 380 const std::vector<FrameType>* frame_types) { |
| 380 // |input_frame| size should always match codec settings. | 381 // |input_frame| size should always match codec settings. |
| 381 RTC_DCHECK_EQ(frame.width(), width_); | 382 RTC_DCHECK_EQ(frame.width(), width_); |
| 382 RTC_DCHECK_EQ(frame.height(), height_); | 383 RTC_DCHECK_EQ(frame.height(), height_); |
| 383 RTC_DCHECK(!frame.IsZeroSize()); | 384 RTC_DCHECK(!frame.IsZeroSize()); |
| 384 if (!callback_ || !compression_session_) { | 385 if (!callback_ || !compression_session_) { |
| 385 return WEBRTC_VIDEO_CODEC_UNINITIALIZED; | 386 return WEBRTC_VIDEO_CODEC_UNINITIALIZED; |
| 386 } | 387 } |
| 387 #if defined(WEBRTC_IOS) | 388 #if defined(WEBRTC_IOS) |
| 388 if (!RTCIsUIApplicationActive()) { | 389 if (!RTCIsUIApplicationActive()) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 464 if (is_keyframe_required) { | 465 if (is_keyframe_required) { |
| 465 CFTypeRef keys[] = {kVTEncodeFrameOptionKey_ForceKeyFrame}; | 466 CFTypeRef keys[] = {kVTEncodeFrameOptionKey_ForceKeyFrame}; |
| 466 CFTypeRef values[] = {kCFBooleanTrue}; | 467 CFTypeRef values[] = {kCFBooleanTrue}; |
| 467 frame_properties = internal::CreateCFDictionary(keys, values, 1); | 468 frame_properties = internal::CreateCFDictionary(keys, values, 1); |
| 468 } | 469 } |
| 469 std::unique_ptr<internal::FrameEncodeParams> encode_params; | 470 std::unique_ptr<internal::FrameEncodeParams> encode_params; |
| 470 encode_params.reset(new internal::FrameEncodeParams( | 471 encode_params.reset(new internal::FrameEncodeParams( |
| 471 this, codec_specific_info, width_, height_, frame.render_time_ms(), | 472 this, codec_specific_info, width_, height_, frame.render_time_ms(), |
| 472 frame.timestamp(), frame.rotation())); | 473 frame.timestamp(), frame.rotation())); |
| 473 | 474 |
| 475 encode_params->codec_specific_info.codecSpecific.H264.packetization_mode = | |
| 476 packetization_mode_; | |
|
hta-webrtc
2016/12/15 14:29:01
This is OK as a first-order fix; if internal::Fram
kthelgason
2016/12/15 14:38:13
In the implementation of this method in h264_encod
| |
| 477 | |
| 474 // Update the bitrate if needed. | 478 // Update the bitrate if needed. |
| 475 SetBitrateBps(bitrate_adjuster_.GetAdjustedBitrateBps()); | 479 SetBitrateBps(bitrate_adjuster_.GetAdjustedBitrateBps()); |
| 476 | 480 |
| 477 OSStatus status = VTCompressionSessionEncodeFrame( | 481 OSStatus status = VTCompressionSessionEncodeFrame( |
| 478 compression_session_, pixel_buffer, presentation_time_stamp, | 482 compression_session_, pixel_buffer, presentation_time_stamp, |
| 479 kCMTimeInvalid, frame_properties, encode_params.release(), nullptr); | 483 kCMTimeInvalid, frame_properties, encode_params.release(), nullptr); |
| 480 if (frame_properties) { | 484 if (frame_properties) { |
| 481 CFRelease(frame_properties); | 485 CFRelease(frame_properties); |
| 482 } | 486 } |
| 483 if (pixel_buffer) { | 487 if (pixel_buffer) { |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 730 } | 734 } |
| 731 bitrate_adjuster_.Update(frame._size); | 735 bitrate_adjuster_.Update(frame._size); |
| 732 } | 736 } |
| 733 | 737 |
| 734 VideoEncoder::ScalingSettings H264VideoToolboxEncoder::GetScalingSettings() | 738 VideoEncoder::ScalingSettings H264VideoToolboxEncoder::GetScalingSettings() |
| 735 const { | 739 const { |
| 736 return VideoEncoder::ScalingSettings(true, internal::kLowH264QpThreshold, | 740 return VideoEncoder::ScalingSettings(true, internal::kLowH264QpThreshold, |
| 737 internal::kHighH264QpThreshold); | 741 internal::kHighH264QpThreshold); |
| 738 } | 742 } |
| 739 } // namespace webrtc | 743 } // namespace webrtc |
| OLD | NEW |