Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(515)

Side by Side Diff: webrtc/api/android/jni/androidmediaencoder_jni.cc

Issue 2398963003: Move usage of QualityScaler to ViEEncoder. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 12 matching lines...) Expand all
23 #include "webrtc/api/android/jni/classreferenceholder.h" 23 #include "webrtc/api/android/jni/classreferenceholder.h"
24 #include "webrtc/api/android/jni/native_handle_impl.h" 24 #include "webrtc/api/android/jni/native_handle_impl.h"
25 #include "webrtc/base/bind.h" 25 #include "webrtc/base/bind.h"
26 #include "webrtc/base/checks.h" 26 #include "webrtc/base/checks.h"
27 #include "webrtc/base/logging.h" 27 #include "webrtc/base/logging.h"
28 #include "webrtc/base/thread.h" 28 #include "webrtc/base/thread.h"
29 #include "webrtc/base/thread_checker.h" 29 #include "webrtc/base/thread_checker.h"
30 #include "webrtc/base/timeutils.h" 30 #include "webrtc/base/timeutils.h"
31 #include "webrtc/common_types.h" 31 #include "webrtc/common_types.h"
32 #include "webrtc/modules/video_coding/include/video_codec_interface.h" 32 #include "webrtc/modules/video_coding/include/video_codec_interface.h"
33 #include "webrtc/modules/video_coding/utility/h264_bitstream_parser.h"
34 #include "webrtc/modules/video_coding/utility/quality_scaler.h"
35 #include "webrtc/modules/video_coding/utility/vp8_header_parser.h"
36 #include "webrtc/system_wrappers/include/field_trial.h" 33 #include "webrtc/system_wrappers/include/field_trial.h"
37 #include "webrtc/system_wrappers/include/logcat_trace_context.h" 34 #include "webrtc/system_wrappers/include/logcat_trace_context.h"
38 35
39 using rtc::Bind; 36 using rtc::Bind;
40 using rtc::Thread; 37 using rtc::Thread;
41 using rtc::ThreadManager; 38 using rtc::ThreadManager;
42 39
43 using webrtc::CodecSpecificInfo; 40 using webrtc::CodecSpecificInfo;
44 using webrtc::EncodedImage; 41 using webrtc::EncodedImage;
45 using webrtc::VideoFrame; 42 using webrtc::VideoFrame;
46 using webrtc::RTPFragmentationHeader; 43 using webrtc::RTPFragmentationHeader;
47 using webrtc::VideoCodec; 44 using webrtc::VideoCodec;
48 using webrtc::VideoCodecType; 45 using webrtc::VideoCodecType;
49 using webrtc::kVideoCodecH264; 46 using webrtc::kVideoCodecH264;
50 using webrtc::kVideoCodecVP8; 47 using webrtc::kVideoCodecVP8;
51 using webrtc::kVideoCodecVP9; 48 using webrtc::kVideoCodecVP9;
52 using webrtc::QualityScaler;
53 49
54 namespace webrtc_jni { 50 namespace webrtc_jni {
55 51
56 // H.264 start code length. 52 // H.264 start code length.
57 #define H264_SC_LENGTH 4 53 #define H264_SC_LENGTH 4
58 // Maximum allowed NALUs in one output frame. 54 // Maximum allowed NALUs in one output frame.
59 #define MAX_NALUS_PERFRAME 32 55 #define MAX_NALUS_PERFRAME 32
60 // Maximum supported HW video encoder resolution. 56 // Maximum supported HW video encoder resolution.
61 #define MAX_VIDEO_WIDTH 1280 57 #define MAX_VIDEO_WIDTH 1280
62 #define MAX_VIDEO_HEIGHT 1280 58 #define MAX_VIDEO_HEIGHT 1280
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 const int64_t frame_input_time_ms); 145 const int64_t frame_input_time_ms);
150 bool EncodeByteBufferOnCodecThread(JNIEnv* jni, 146 bool EncodeByteBufferOnCodecThread(JNIEnv* jni,
151 bool key_frame, const webrtc::VideoFrame& frame, int input_buffer_index); 147 bool key_frame, const webrtc::VideoFrame& frame, int input_buffer_index);
152 bool EncodeTextureOnCodecThread(JNIEnv* jni, 148 bool EncodeTextureOnCodecThread(JNIEnv* jni,
153 bool key_frame, const webrtc::VideoFrame& frame); 149 bool key_frame, const webrtc::VideoFrame& frame);
154 150
155 int32_t RegisterEncodeCompleteCallbackOnCodecThread( 151 int32_t RegisterEncodeCompleteCallbackOnCodecThread(
156 webrtc::EncodedImageCallback* callback); 152 webrtc::EncodedImageCallback* callback);
157 int32_t ReleaseOnCodecThread(); 153 int32_t ReleaseOnCodecThread();
158 int32_t SetRatesOnCodecThread(uint32_t new_bit_rate, uint32_t frame_rate); 154 int32_t SetRatesOnCodecThread(uint32_t new_bit_rate, uint32_t frame_rate);
159 void OnDroppedFrameOnCodecThread();
160 155
161 // Helper accessors for MediaCodecVideoEncoder$OutputBufferInfo members. 156 // Helper accessors for MediaCodecVideoEncoder$OutputBufferInfo members.
162 int GetOutputBufferInfoIndex(JNIEnv* jni, jobject j_output_buffer_info); 157 int GetOutputBufferInfoIndex(JNIEnv* jni, jobject j_output_buffer_info);
163 jobject GetOutputBufferInfoBuffer(JNIEnv* jni, jobject j_output_buffer_info); 158 jobject GetOutputBufferInfoBuffer(JNIEnv* jni, jobject j_output_buffer_info);
164 bool GetOutputBufferInfoIsKeyFrame(JNIEnv* jni, jobject j_output_buffer_info); 159 bool GetOutputBufferInfoIsKeyFrame(JNIEnv* jni, jobject j_output_buffer_info);
165 jlong GetOutputBufferInfoPresentationTimestampUs( 160 jlong GetOutputBufferInfoPresentationTimestampUs(
166 JNIEnv* jni, jobject j_output_buffer_info); 161 JNIEnv* jni, jobject j_output_buffer_info);
167 162
168 // Deliver any outputs pending in the MediaCodec to our |callback_| and return 163 // Deliver any outputs pending in the MediaCodec to our |callback_| and return
169 // true on success. 164 // true on success.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 // |input_frame_infos_|. 247 // |input_frame_infos_|.
253 webrtc::VideoRotation output_rotation_; // Last output frame rotation from 248 webrtc::VideoRotation output_rotation_; // Last output frame rotation from
254 // |input_frame_infos_|. 249 // |input_frame_infos_|.
255 // Frame size in bytes fed to MediaCodec. 250 // Frame size in bytes fed to MediaCodec.
256 int yuv_size_; 251 int yuv_size_;
257 // True only when between a callback_->Encoded() call return a positive value 252 // True only when between a callback_->Encoded() call return a positive value
258 // and the next Encode() call being ignored. 253 // and the next Encode() call being ignored.
259 bool drop_next_input_frame_; 254 bool drop_next_input_frame_;
260 // Global references; must be deleted in Release(). 255 // Global references; must be deleted in Release().
261 std::vector<jobject> input_buffers_; 256 std::vector<jobject> input_buffers_;
262 QualityScaler quality_scaler_;
263 // Dynamic resolution change, off by default.
264 bool scale_;
265
266 // H264 bitstream parser, used to extract QP from encoded bitstreams.
267 webrtc::H264BitstreamParser h264_bitstream_parser_;
268 257
269 // VP9 variables to populate codec specific structure. 258 // VP9 variables to populate codec specific structure.
270 webrtc::GofInfoVP9 gof_; // Contains each frame's temporal information for 259 webrtc::GofInfoVP9 gof_; // Contains each frame's temporal information for
271 // non-flexible VP9 mode. 260 // non-flexible VP9 mode.
272 uint8_t tl0_pic_idx_; 261 uint8_t tl0_pic_idx_;
273 size_t gof_idx_; 262 size_t gof_idx_;
274 263
275 // EGL context - owned by factory, should not be allocated/destroyed 264 // EGL context - owned by factory, should not be allocated/destroyed
276 // by MediaCodecVideoEncoder. 265 // by MediaCodecVideoEncoder.
277 jobject egl_context_; 266 jobject egl_context_;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; 364 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
376 } 365 }
377 // Factory should guard against other codecs being used with us. 366 // Factory should guard against other codecs being used with us.
378 RTC_CHECK(codec_settings->codecType == codecType_) 367 RTC_CHECK(codec_settings->codecType == codecType_)
379 << "Unsupported codec " << codec_settings->codecType << " for " 368 << "Unsupported codec " << codec_settings->codecType << " for "
380 << codecType_; 369 << codecType_;
381 370
382 codec_mode_ = codec_settings->mode; 371 codec_mode_ = codec_settings->mode;
383 int init_width = codec_settings->width; 372 int init_width = codec_settings->width;
384 int init_height = codec_settings->height; 373 int init_height = codec_settings->height;
385 // Scaling is disabled for VP9, but optionally enabled for VP8.
386 // TODO(pbos): Extract automaticResizeOn out of VP8 settings.
387 scale_ = false;
388 if (codecType_ == kVideoCodecVP8) {
389 scale_ = codec_settings->codecSpecific.VP8.automaticResizeOn;
390 } else if (codecType_ != kVideoCodecVP9) {
391 scale_ = true;
392 }
393
394 ALOGD << "InitEncode request: " << init_width << " x " << init_height; 374 ALOGD << "InitEncode request: " << init_width << " x " << init_height;
395 ALOGD << "Encoder automatic resize " << (scale_ ? "enabled" : "disabled");
396
397 if (scale_) {
398 if (codecType_ == kVideoCodecVP8 || codecType_ == kVideoCodecH264) {
399 quality_scaler_.Init(codecType_, codec_settings->startBitrate,
400 codec_settings->width, codec_settings->height,
401 codec_settings->maxFramerate);
402 } else {
403 // When adding codec support to additional hardware codecs, also configure
404 // their QP thresholds for scaling.
405 RTC_NOTREACHED() << "Unsupported codec without configured QP thresholds.";
406 scale_ = false;
407 }
408 QualityScaler::Resolution res = quality_scaler_.GetScaledResolution();
409 init_width = res.width;
410 init_height = res.height;
411 ALOGD << "Scaled resolution: " << init_width << " x " << init_height;
412 }
413 375
414 return codec_thread_->Invoke<int32_t>( 376 return codec_thread_->Invoke<int32_t>(
415 RTC_FROM_HERE, 377 RTC_FROM_HERE,
416 Bind(&MediaCodecVideoEncoder::InitEncodeOnCodecThread, this, init_width, 378 Bind(&MediaCodecVideoEncoder::InitEncodeOnCodecThread, this, init_width,
417 init_height, codec_settings->startBitrate, 379 init_height, codec_settings->startBitrate,
418 codec_settings->maxFramerate, 380 codec_settings->maxFramerate,
419 codec_settings->expect_encode_from_texture)); 381 codec_settings->expect_encode_from_texture));
420 } 382 }
421 383
422 int32_t MediaCodecVideoEncoder::Encode( 384 int32_t MediaCodecVideoEncoder::Encode(
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 << ". TS: " << (int)(current_timestamp_us_ / 1000) 599 << ". TS: " << (int)(current_timestamp_us_ / 1000)
638 << ". Q: " << input_frame_infos_.size() << ". Fps: " << last_set_fps_ 600 << ". Q: " << input_frame_infos_.size() << ". Fps: " << last_set_fps_
639 << ". Kbps: " << last_set_bitrate_kbps_; 601 << ". Kbps: " << last_set_bitrate_kbps_;
640 } 602 }
641 603
642 if (drop_next_input_frame_) { 604 if (drop_next_input_frame_) {
643 ALOGW << "Encoder drop frame - failed callback."; 605 ALOGW << "Encoder drop frame - failed callback.";
644 drop_next_input_frame_ = false; 606 drop_next_input_frame_ = false;
645 current_timestamp_us_ += rtc::kNumMicrosecsPerSec / last_set_fps_; 607 current_timestamp_us_ += rtc::kNumMicrosecsPerSec / last_set_fps_;
646 frames_dropped_media_encoder_++; 608 frames_dropped_media_encoder_++;
647 OnDroppedFrameOnCodecThread();
648 return WEBRTC_VIDEO_CODEC_OK; 609 return WEBRTC_VIDEO_CODEC_OK;
649 } 610 }
650 611
651 RTC_CHECK(frame_types->size() == 1) << "Unexpected stream count"; 612 RTC_CHECK(frame_types->size() == 1) << "Unexpected stream count";
652 613
653 // Check if we accumulated too many frames in encoder input buffers and drop 614 // Check if we accumulated too many frames in encoder input buffers and drop
654 // frame if so. 615 // frame if so.
655 if (input_frame_infos_.size() > MAX_ENCODER_Q_SIZE) { 616 if (input_frame_infos_.size() > MAX_ENCODER_Q_SIZE) {
656 ALOGD << "Already " << input_frame_infos_.size() 617 ALOGD << "Already " << input_frame_infos_.size()
657 << " frames in the queue, dropping" 618 << " frames in the queue, dropping"
658 << ". TS: " << (int)(current_timestamp_us_ / 1000) 619 << ". TS: " << (int)(current_timestamp_us_ / 1000)
659 << ". Fps: " << last_set_fps_ 620 << ". Fps: " << last_set_fps_
660 << ". Consecutive drops: " << consecutive_full_queue_frame_drops_; 621 << ". Consecutive drops: " << consecutive_full_queue_frame_drops_;
661 current_timestamp_us_ += rtc::kNumMicrosecsPerSec / last_set_fps_; 622 current_timestamp_us_ += rtc::kNumMicrosecsPerSec / last_set_fps_;
662 consecutive_full_queue_frame_drops_++; 623 consecutive_full_queue_frame_drops_++;
663 if (consecutive_full_queue_frame_drops_ >= 624 if (consecutive_full_queue_frame_drops_ >=
664 ENCODER_STALL_FRAMEDROP_THRESHOLD) { 625 ENCODER_STALL_FRAMEDROP_THRESHOLD) {
665 ALOGE << "Encoder got stuck. Reset."; 626 ALOGE << "Encoder got stuck. Reset.";
666 ResetCodecOnCodecThread(); 627 ResetCodecOnCodecThread();
667 return WEBRTC_VIDEO_CODEC_ERROR; 628 return WEBRTC_VIDEO_CODEC_ERROR;
668 } 629 }
669 frames_dropped_media_encoder_++; 630 frames_dropped_media_encoder_++;
670 OnDroppedFrameOnCodecThread();
671 return WEBRTC_VIDEO_CODEC_OK; 631 return WEBRTC_VIDEO_CODEC_OK;
672 } 632 }
673 consecutive_full_queue_frame_drops_ = 0; 633 consecutive_full_queue_frame_drops_ = 0;
674 634
675 rtc::scoped_refptr<webrtc::VideoFrameBuffer> input_buffer( 635 rtc::scoped_refptr<webrtc::VideoFrameBuffer> input_buffer(
676 frame.video_frame_buffer()); 636 frame.video_frame_buffer());
677 if (scale_) {
678 // Check framerate before spatial resolution change.
679 quality_scaler_.OnEncodeFrame(frame.width(), frame.height());
680 const webrtc::QualityScaler::Resolution scaled_resolution =
681 quality_scaler_.GetScaledResolution();
682 if (scaled_resolution.width != frame.width() ||
683 scaled_resolution.height != frame.height()) {
684 if (input_buffer->native_handle() != nullptr) {
685 input_buffer = static_cast<AndroidTextureBuffer*>(input_buffer.get())
686 ->CropScaleAndRotate(frame.width(), frame.height(),
687 0, 0,
688 scaled_resolution.width,
689 scaled_resolution.height,
690 webrtc::kVideoRotation_0);
691 } else {
692 input_buffer = quality_scaler_.GetScaledBuffer(input_buffer);
693 }
694 }
695 }
696 637
697 VideoFrame input_frame(input_buffer, frame.timestamp(), 638 VideoFrame input_frame(input_buffer, frame.timestamp(),
698 frame.render_time_ms(), frame.rotation()); 639 frame.render_time_ms(), frame.rotation());
699 640
700 if (!MaybeReconfigureEncoderOnCodecThread(input_frame)) { 641 if (!MaybeReconfigureEncoderOnCodecThread(input_frame)) {
701 ALOGE << "Failed to reconfigure encoder."; 642 ALOGE << "Failed to reconfigure encoder.";
702 return WEBRTC_VIDEO_CODEC_ERROR; 643 return WEBRTC_VIDEO_CODEC_ERROR;
703 } 644 }
704 645
705 const bool key_frame = 646 const bool key_frame =
706 frame_types->front() != webrtc::kVideoFrameDelta || send_key_frame; 647 frame_types->front() != webrtc::kVideoFrameDelta || send_key_frame;
707 bool encode_status = true; 648 bool encode_status = true;
708 if (!input_frame.video_frame_buffer()->native_handle()) { 649 if (!input_frame.video_frame_buffer()->native_handle()) {
709 int j_input_buffer_index = jni->CallIntMethod(*j_media_codec_video_encoder_, 650 int j_input_buffer_index = jni->CallIntMethod(*j_media_codec_video_encoder_,
710 j_dequeue_input_buffer_method_); 651 j_dequeue_input_buffer_method_);
711 CHECK_EXCEPTION(jni); 652 CHECK_EXCEPTION(jni);
712 if (j_input_buffer_index == -1) { 653 if (j_input_buffer_index == -1) {
713 // Video codec falls behind - no input buffer available. 654 // Video codec falls behind - no input buffer available.
714 ALOGW << "Encoder drop frame - no input buffers available"; 655 ALOGW << "Encoder drop frame - no input buffers available";
715 if (frames_received_ > 1) { 656 if (frames_received_ > 1) {
716 current_timestamp_us_ += rtc::kNumMicrosecsPerSec / last_set_fps_; 657 current_timestamp_us_ += rtc::kNumMicrosecsPerSec / last_set_fps_;
717 frames_dropped_media_encoder_++; 658 frames_dropped_media_encoder_++;
718 OnDroppedFrameOnCodecThread();
719 } else { 659 } else {
720 // Input buffers are not ready after codec initialization, HW is still 660 // Input buffers are not ready after codec initialization, HW is still
721 // allocating thme - this is expected and should not result in drop 661 // allocating thme - this is expected and should not result in drop
722 // frame report. 662 // frame report.
723 frames_received_ = 0; 663 frames_received_ = 0;
724 } 664 }
725 return WEBRTC_VIDEO_CODEC_OK; // TODO(fischman): see webrtc bug 2887. 665 return WEBRTC_VIDEO_CODEC_OK; // TODO(fischman): see webrtc bug 2887.
726 } else if (j_input_buffer_index == -2) { 666 } else if (j_input_buffer_index == -2) {
727 ResetCodecOnCodecThread(); 667 ResetCodecOnCodecThread();
728 return WEBRTC_VIDEO_CODEC_ERROR; 668 return WEBRTC_VIDEO_CODEC_ERROR;
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 815
876 int32_t MediaCodecVideoEncoder::SetRatesOnCodecThread(uint32_t new_bit_rate, 816 int32_t MediaCodecVideoEncoder::SetRatesOnCodecThread(uint32_t new_bit_rate,
877 uint32_t frame_rate) { 817 uint32_t frame_rate) {
878 RTC_DCHECK(codec_thread_checker_.CalledOnValidThread()); 818 RTC_DCHECK(codec_thread_checker_.CalledOnValidThread());
879 frame_rate = (frame_rate < MAX_ALLOWED_VIDEO_FPS) ? 819 frame_rate = (frame_rate < MAX_ALLOWED_VIDEO_FPS) ?
880 frame_rate : MAX_ALLOWED_VIDEO_FPS; 820 frame_rate : MAX_ALLOWED_VIDEO_FPS;
881 if (last_set_bitrate_kbps_ == new_bit_rate && 821 if (last_set_bitrate_kbps_ == new_bit_rate &&
882 last_set_fps_ == frame_rate) { 822 last_set_fps_ == frame_rate) {
883 return WEBRTC_VIDEO_CODEC_OK; 823 return WEBRTC_VIDEO_CODEC_OK;
884 } 824 }
885 if (scale_) {
886 quality_scaler_.ReportFramerate(frame_rate);
887 }
888 JNIEnv* jni = AttachCurrentThreadIfNeeded(); 825 JNIEnv* jni = AttachCurrentThreadIfNeeded();
889 ScopedLocalRefFrame local_ref_frame(jni); 826 ScopedLocalRefFrame local_ref_frame(jni);
890 if (new_bit_rate > 0) { 827 if (new_bit_rate > 0) {
891 last_set_bitrate_kbps_ = new_bit_rate; 828 last_set_bitrate_kbps_ = new_bit_rate;
892 } 829 }
893 if (frame_rate > 0) { 830 if (frame_rate > 0) {
894 last_set_fps_ = frame_rate; 831 last_set_fps_ = frame_rate;
895 } 832 }
896 bool ret = jni->CallBooleanMethod(*j_media_codec_video_encoder_, 833 bool ret = jni->CallBooleanMethod(*j_media_codec_video_encoder_,
897 j_set_rates_method_, 834 j_set_rates_method_,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 std::unique_ptr<webrtc::EncodedImage> image( 917 std::unique_ptr<webrtc::EncodedImage> image(
981 new webrtc::EncodedImage(payload, payload_size, payload_size)); 918 new webrtc::EncodedImage(payload, payload_size, payload_size));
982 image->_encodedWidth = width_; 919 image->_encodedWidth = width_;
983 image->_encodedHeight = height_; 920 image->_encodedHeight = height_;
984 image->_timeStamp = output_timestamp_; 921 image->_timeStamp = output_timestamp_;
985 image->capture_time_ms_ = output_render_time_ms_; 922 image->capture_time_ms_ = output_render_time_ms_;
986 image->rotation_ = output_rotation_; 923 image->rotation_ = output_rotation_;
987 image->_frameType = 924 image->_frameType =
988 (key_frame ? webrtc::kVideoFrameKey : webrtc::kVideoFrameDelta); 925 (key_frame ? webrtc::kVideoFrameKey : webrtc::kVideoFrameDelta);
989 image->_completeFrame = true; 926 image->_completeFrame = true;
990 image->adapt_reason_.quality_resolution_downscales =
991 scale_ ? quality_scaler_.downscale_shift() : -1;
992
993 webrtc::CodecSpecificInfo info; 927 webrtc::CodecSpecificInfo info;
994 memset(&info, 0, sizeof(info)); 928 memset(&info, 0, sizeof(info));
995 info.codecType = codecType_; 929 info.codecType = codecType_;
996 if (codecType_ == kVideoCodecVP8) { 930 if (codecType_ == kVideoCodecVP8) {
997 info.codecSpecific.VP8.pictureId = picture_id_; 931 info.codecSpecific.VP8.pictureId = picture_id_;
998 info.codecSpecific.VP8.nonReference = false; 932 info.codecSpecific.VP8.nonReference = false;
999 info.codecSpecific.VP8.simulcastIdx = 0; 933 info.codecSpecific.VP8.simulcastIdx = 0;
1000 info.codecSpecific.VP8.temporalIdx = webrtc::kNoTemporalIdx; 934 info.codecSpecific.VP8.temporalIdx = webrtc::kNoTemporalIdx;
1001 info.codecSpecific.VP8.layerSync = false; 935 info.codecSpecific.VP8.layerSync = false;
1002 info.codecSpecific.VP8.tl0PicIdx = webrtc::kNoTl0PicIdx; 936 info.codecSpecific.VP8.tl0PicIdx = webrtc::kNoTl0PicIdx;
(...skipping 26 matching lines...) Expand all
1029 963
1030 // Generate a header describing a single fragment. 964 // Generate a header describing a single fragment.
1031 webrtc::RTPFragmentationHeader header; 965 webrtc::RTPFragmentationHeader header;
1032 memset(&header, 0, sizeof(header)); 966 memset(&header, 0, sizeof(header));
1033 if (codecType_ == kVideoCodecVP8 || codecType_ == kVideoCodecVP9) { 967 if (codecType_ == kVideoCodecVP8 || codecType_ == kVideoCodecVP9) {
1034 header.VerifyAndAllocateFragmentationHeader(1); 968 header.VerifyAndAllocateFragmentationHeader(1);
1035 header.fragmentationOffset[0] = 0; 969 header.fragmentationOffset[0] = 0;
1036 header.fragmentationLength[0] = image->_length; 970 header.fragmentationLength[0] = image->_length;
1037 header.fragmentationPlType[0] = 0; 971 header.fragmentationPlType[0] = 0;
1038 header.fragmentationTimeDiff[0] = 0; 972 header.fragmentationTimeDiff[0] = 0;
1039 if (codecType_ == kVideoCodecVP8 && scale_) {
1040 int qp;
1041 if (webrtc::vp8::GetQp(payload, payload_size, &qp)) {
1042 current_acc_qp_ += qp;
1043 quality_scaler_.ReportQP(qp);
1044 image->qp_ = qp;
1045 }
1046 }
1047 } else if (codecType_ == kVideoCodecH264) { 973 } else if (codecType_ == kVideoCodecH264) {
1048 if (scale_) {
1049 h264_bitstream_parser_.ParseBitstream(payload, payload_size);
1050 int qp;
1051 if (h264_bitstream_parser_.GetLastSliceQp(&qp)) {
1052 current_acc_qp_ += qp;
1053 quality_scaler_.ReportQP(qp);
1054 }
1055 }
1056 // For H.264 search for start codes. 974 // For H.264 search for start codes.
1057 int32_t scPositions[MAX_NALUS_PERFRAME + 1] = {}; 975 int32_t scPositions[MAX_NALUS_PERFRAME + 1] = {};
1058 int32_t scPositionsLength = 0; 976 int32_t scPositionsLength = 0;
1059 int32_t scPosition = 0; 977 int32_t scPosition = 0;
1060 while (scPositionsLength < MAX_NALUS_PERFRAME) { 978 while (scPositionsLength < MAX_NALUS_PERFRAME) {
1061 int32_t naluPosition = NextNaluPosition( 979 int32_t naluPosition = NextNaluPosition(
1062 payload + scPosition, payload_size - scPosition); 980 payload + scPosition, payload_size - scPosition);
1063 if (naluPosition < 0) { 981 if (naluPosition < 0) {
1064 break; 982 break;
1065 } 983 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 if (head[3] != 0x01) { // got 000000xx 1099 if (head[3] != 0x01) { // got 000000xx
1182 head++; // xx != 1, continue searching. 1100 head++; // xx != 1, continue searching.
1183 continue; 1101 continue;
1184 } 1102 }
1185 return (int32_t)(head - buffer); 1103 return (int32_t)(head - buffer);
1186 } 1104 }
1187 return -1; 1105 return -1;
1188 } 1106 }
1189 1107
1190 void MediaCodecVideoEncoder::OnDroppedFrame() { 1108 void MediaCodecVideoEncoder::OnDroppedFrame() {
1191 // Methods running on the codec thread should call OnDroppedFrameOnCodecThread
1192 // directly.
1193 RTC_DCHECK(!codec_thread_checker_.CalledOnValidThread()); 1109 RTC_DCHECK(!codec_thread_checker_.CalledOnValidThread());
1194 codec_thread_->Invoke<void>(
1195 RTC_FROM_HERE,
1196 Bind(&MediaCodecVideoEncoder::OnDroppedFrameOnCodecThread, this));
1197 }
1198
1199 void MediaCodecVideoEncoder::OnDroppedFrameOnCodecThread() {
1200 RTC_DCHECK(codec_thread_checker_.CalledOnValidThread());
1201 // Report dropped frame to quality_scaler_.
1202 if (scale_)
1203 quality_scaler_.ReportDroppedFrame();
1204 } 1110 }
1205 1111
1206 const char* MediaCodecVideoEncoder::ImplementationName() const { 1112 const char* MediaCodecVideoEncoder::ImplementationName() const {
1207 return "MediaCodec"; 1113 return "MediaCodec";
1208 } 1114 }
1209 1115
1210 MediaCodecVideoEncoderFactory::MediaCodecVideoEncoderFactory() 1116 MediaCodecVideoEncoderFactory::MediaCodecVideoEncoderFactory()
1211 : egl_context_(nullptr) { 1117 : egl_context_(nullptr) {
1212 JNIEnv* jni = AttachCurrentThreadIfNeeded(); 1118 JNIEnv* jni = AttachCurrentThreadIfNeeded();
1213 ScopedLocalRefFrame local_ref_frame(jni); 1119 ScopedLocalRefFrame local_ref_frame(jni);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1290 return supported_codecs_; 1196 return supported_codecs_;
1291 } 1197 }
1292 1198
1293 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( 1199 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder(
1294 webrtc::VideoEncoder* encoder) { 1200 webrtc::VideoEncoder* encoder) {
1295 ALOGD << "Destroy video encoder."; 1201 ALOGD << "Destroy video encoder.";
1296 delete encoder; 1202 delete encoder;
1297 } 1203 }
1298 1204
1299 } // namespace webrtc_jni 1205 } // namespace webrtc_jni
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698