OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
345 jni, j_output_buffer_info_class, "presentationTimestampUs", "J"); | 345 jni, j_output_buffer_info_class, "presentationTimestampUs", "J"); |
346 CHECK_EXCEPTION(jni) << "MediaCodecVideoEncoder ctor failed"; | 346 CHECK_EXCEPTION(jni) << "MediaCodecVideoEncoder ctor failed"; |
347 srand(time(NULL)); | 347 srand(time(NULL)); |
348 AllowBlockingCalls(); | 348 AllowBlockingCalls(); |
349 } | 349 } |
350 | 350 |
351 int32_t MediaCodecVideoEncoder::InitEncode( | 351 int32_t MediaCodecVideoEncoder::InitEncode( |
352 const webrtc::VideoCodec* codec_settings, | 352 const webrtc::VideoCodec* codec_settings, |
353 int32_t /* number_of_cores */, | 353 int32_t /* number_of_cores */, |
354 size_t /* max_payload_size */) { | 354 size_t /* max_payload_size */) { |
355 const int kMinDimension = 180; | |
356 if (codec_settings == NULL) { | 355 if (codec_settings == NULL) { |
357 ALOGE << "NULL VideoCodec instance"; | 356 ALOGE << "NULL VideoCodec instance"; |
358 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; | 357 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; |
359 } | 358 } |
360 // Factory should guard against other codecs being used with us. | 359 // Factory should guard against other codecs being used with us. |
361 RTC_CHECK(codec_settings->codecType == codecType_) | 360 RTC_CHECK(codec_settings->codecType == codecType_) |
362 << "Unsupported codec " << codec_settings->codecType << " for " | 361 << "Unsupported codec " << codec_settings->codecType << " for " |
363 << codecType_; | 362 << codecType_; |
364 | 363 |
365 codec_mode_ = codec_settings->mode; | 364 codec_mode_ = codec_settings->mode; |
(...skipping 24 matching lines...) Expand all Loading... | |
390 quality_scaler_.Init(kLowQpThreshold, kBadQpThreshold, false, | 389 quality_scaler_.Init(kLowQpThreshold, kBadQpThreshold, false, |
391 codec_settings->startBitrate, codec_settings->width, | 390 codec_settings->startBitrate, codec_settings->width, |
392 codec_settings->height, | 391 codec_settings->height, |
393 codec_settings->maxFramerate); | 392 codec_settings->maxFramerate); |
394 } else { | 393 } else { |
395 // When adding codec support to additional hardware codecs, also configure | 394 // When adding codec support to additional hardware codecs, also configure |
396 // their QP thresholds for scaling. | 395 // their QP thresholds for scaling. |
397 RTC_NOTREACHED() << "Unsupported codec without configured QP thresholds."; | 396 RTC_NOTREACHED() << "Unsupported codec without configured QP thresholds."; |
398 scale_ = false; | 397 scale_ = false; |
399 } | 398 } |
400 quality_scaler_.SetMinResolution(kMinDimension, kMinDimension); | |
401 QualityScaler::Resolution res = quality_scaler_.GetScaledResolution(); | 399 QualityScaler::Resolution res = quality_scaler_.GetScaledResolution(); |
402 init_width = std::max(res.width, kMinDimension); | 400 init_width = res.width; |
403 init_height = std::max(res.height, kMinDimension); | 401 init_height = res.height; |
404 ALOGD << "Scaled resolution: " << init_width << " x " << init_height; | 402 ALOGD << "Scaled resolution: " << init_width << " x " << init_height; |
405 } | 403 } |
406 | 404 |
407 return codec_thread_->Invoke<int32_t>( | 405 return codec_thread_->Invoke<int32_t>( |
408 Bind(&MediaCodecVideoEncoder::InitEncodeOnCodecThread, | 406 Bind(&MediaCodecVideoEncoder::InitEncodeOnCodecThread, |
409 this, | 407 this, |
410 init_width, | 408 init_width, |
411 init_height, | 409 init_height, |
412 codec_settings->startBitrate, | 410 codec_settings->startBitrate, |
413 codec_settings->maxFramerate, | 411 codec_settings->maxFramerate, |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
633 ALOGW << "Encoder drop frame - failed callback."; | 631 ALOGW << "Encoder drop frame - failed callback."; |
634 drop_next_input_frame_ = false; | 632 drop_next_input_frame_ = false; |
635 current_timestamp_us_ += rtc::kNumMicrosecsPerSec / last_set_fps_; | 633 current_timestamp_us_ += rtc::kNumMicrosecsPerSec / last_set_fps_; |
636 frames_dropped_media_encoder_++; | 634 frames_dropped_media_encoder_++; |
637 OnDroppedFrame(); | 635 OnDroppedFrame(); |
638 return WEBRTC_VIDEO_CODEC_OK; | 636 return WEBRTC_VIDEO_CODEC_OK; |
639 } | 637 } |
640 | 638 |
641 RTC_CHECK(frame_types->size() == 1) << "Unexpected stream count"; | 639 RTC_CHECK(frame_types->size() == 1) << "Unexpected stream count"; |
642 | 640 |
643 // Check if we accumulated too many frames in encoder input buffers and drop | 641 // Check if we accumulated too many frames in encoder input buffers and drop |
pbos-webrtc
2016/04/13 14:00:54
(Sorry, this is part of a rebase.)
| |
644 // frame if so. | 642 // frame if so. |
645 if (frames_in_queue_ > MAX_ENCODER_Q_SIZE) { | 643 if (frames_in_queue_ > MAX_ENCODER_Q_SIZE) { |
646 ALOGD << "Already " << frames_in_queue_ << " frames in the queue, dropping" | 644 ALOGD << "Already " << frames_in_queue_ << " frames in the queue, dropping" |
647 << ". TS: " << (int)(current_timestamp_us_ / 1000) | 645 << ". TS: " << (int)(current_timestamp_us_ / 1000) |
648 << ". Fps: " << last_set_fps_ | 646 << ". Fps: " << last_set_fps_ |
649 << ". Consecutive drops: " << consecutive_full_queue_frame_drops_; | 647 << ". Consecutive drops: " << consecutive_full_queue_frame_drops_; |
650 current_timestamp_us_ += rtc::kNumMicrosecsPerSec / last_set_fps_; | 648 current_timestamp_us_ += rtc::kNumMicrosecsPerSec / last_set_fps_; |
651 consecutive_full_queue_frame_drops_++; | 649 consecutive_full_queue_frame_drops_++; |
652 if (consecutive_full_queue_frame_drops_ >= | 650 if (consecutive_full_queue_frame_drops_ >= |
653 ENCODER_STALL_FRAMEDROP_THRESHOLD) { | 651 ENCODER_STALL_FRAMEDROP_THRESHOLD) { |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1253 } | 1251 } |
1254 | 1252 |
1255 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( | 1253 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( |
1256 webrtc::VideoEncoder* encoder) { | 1254 webrtc::VideoEncoder* encoder) { |
1257 ALOGD << "Destroy video encoder."; | 1255 ALOGD << "Destroy video encoder."; |
1258 delete encoder; | 1256 delete encoder; |
1259 } | 1257 } |
1260 | 1258 |
1261 } // namespace webrtc_jni | 1259 } // namespace webrtc_jni |
1262 | 1260 |
OLD | NEW |