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 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 consecutive_full_queue_frame_drops_ = 0; | 662 consecutive_full_queue_frame_drops_ = 0; |
663 | 663 |
664 VideoFrame input_frame = frame; | 664 VideoFrame input_frame = frame; |
665 if (scale_) { | 665 if (scale_) { |
666 // Check framerate before spatial resolution change. | 666 // Check framerate before spatial resolution change. |
667 quality_scaler_.OnEncodeFrame(frame); | 667 quality_scaler_.OnEncodeFrame(frame); |
668 const webrtc::QualityScaler::Resolution scaled_resolution = | 668 const webrtc::QualityScaler::Resolution scaled_resolution = |
669 quality_scaler_.GetScaledResolution(); | 669 quality_scaler_.GetScaledResolution(); |
670 if (scaled_resolution.width != frame.width() || | 670 if (scaled_resolution.width != frame.width() || |
671 scaled_resolution.height != frame.height()) { | 671 scaled_resolution.height != frame.height()) { |
672 if (frame.native_handle() != nullptr) { | 672 if (frame.video_frame_buffer()->native_handle() != nullptr) { |
673 rtc::scoped_refptr<webrtc::VideoFrameBuffer> scaled_buffer( | 673 rtc::scoped_refptr<webrtc::VideoFrameBuffer> scaled_buffer( |
674 static_cast<AndroidTextureBuffer*>( | 674 static_cast<AndroidTextureBuffer*>( |
675 frame.video_frame_buffer().get())->ScaleAndRotate( | 675 frame.video_frame_buffer().get())->ScaleAndRotate( |
676 scaled_resolution.width, | 676 scaled_resolution.width, |
677 scaled_resolution.height, | 677 scaled_resolution.height, |
678 webrtc::kVideoRotation_0)); | 678 webrtc::kVideoRotation_0)); |
679 input_frame.set_video_frame_buffer(scaled_buffer); | 679 input_frame.set_video_frame_buffer(scaled_buffer); |
680 } else { | 680 } else { |
681 input_frame = quality_scaler_.GetScaledFrame(frame); | 681 input_frame = quality_scaler_.GetScaledFrame(frame); |
682 } | 682 } |
683 } | 683 } |
684 } | 684 } |
685 | 685 |
686 if (!MaybeReconfigureEncoderOnCodecThread(input_frame)) { | 686 if (!MaybeReconfigureEncoderOnCodecThread(input_frame)) { |
687 ALOGE << "Failed to reconfigure encoder."; | 687 ALOGE << "Failed to reconfigure encoder."; |
688 return WEBRTC_VIDEO_CODEC_ERROR; | 688 return WEBRTC_VIDEO_CODEC_ERROR; |
689 } | 689 } |
690 | 690 |
691 // Save time when input frame is sent to the encoder input. | 691 // Save time when input frame is sent to the encoder input. |
692 frame_rtc_times_ms_.push_back(GetCurrentTimeMs()); | 692 frame_rtc_times_ms_.push_back(GetCurrentTimeMs()); |
693 | 693 |
694 const bool key_frame = | 694 const bool key_frame = |
695 frame_types->front() != webrtc::kVideoFrameDelta || send_key_frame; | 695 frame_types->front() != webrtc::kVideoFrameDelta || send_key_frame; |
696 bool encode_status = true; | 696 bool encode_status = true; |
697 if (!input_frame.native_handle()) { | 697 if (!input_frame.video_frame_buffer()->native_handle()) { |
698 int j_input_buffer_index = jni->CallIntMethod(*j_media_codec_video_encoder_, | 698 int j_input_buffer_index = jni->CallIntMethod(*j_media_codec_video_encoder_, |
699 j_dequeue_input_buffer_method_); | 699 j_dequeue_input_buffer_method_); |
700 CHECK_EXCEPTION(jni); | 700 CHECK_EXCEPTION(jni); |
701 if (j_input_buffer_index == -1) { | 701 if (j_input_buffer_index == -1) { |
702 // Video codec falls behind - no input buffer available. | 702 // Video codec falls behind - no input buffer available. |
703 ALOGW << "Encoder drop frame - no input buffers available"; | 703 ALOGW << "Encoder drop frame - no input buffers available"; |
704 frame_rtc_times_ms_.erase(frame_rtc_times_ms_.begin()); | 704 frame_rtc_times_ms_.erase(frame_rtc_times_ms_.begin()); |
705 current_timestamp_us_ += rtc::kNumMicrosecsPerSec / last_set_fps_; | 705 current_timestamp_us_ += rtc::kNumMicrosecsPerSec / last_set_fps_; |
706 frames_dropped_media_encoder_++; | 706 frames_dropped_media_encoder_++; |
707 OnDroppedFrame(); | 707 OnDroppedFrame(); |
(...skipping 29 matching lines...) Expand all Loading... |
737 ResetCodecOnCodecThread(); | 737 ResetCodecOnCodecThread(); |
738 return WEBRTC_VIDEO_CODEC_ERROR; | 738 return WEBRTC_VIDEO_CODEC_ERROR; |
739 } | 739 } |
740 return WEBRTC_VIDEO_CODEC_OK; | 740 return WEBRTC_VIDEO_CODEC_OK; |
741 } | 741 } |
742 | 742 |
743 bool MediaCodecVideoEncoder::MaybeReconfigureEncoderOnCodecThread( | 743 bool MediaCodecVideoEncoder::MaybeReconfigureEncoderOnCodecThread( |
744 const webrtc::VideoFrame& frame) { | 744 const webrtc::VideoFrame& frame) { |
745 RTC_DCHECK(codec_thread_checker_.CalledOnValidThread()); | 745 RTC_DCHECK(codec_thread_checker_.CalledOnValidThread()); |
746 | 746 |
747 const bool is_texture_frame = frame.native_handle() != nullptr; | 747 const bool is_texture_frame = |
| 748 frame.video_frame_buffer()->native_handle() != nullptr; |
748 const bool reconfigure_due_to_format = is_texture_frame != use_surface_; | 749 const bool reconfigure_due_to_format = is_texture_frame != use_surface_; |
749 const bool reconfigure_due_to_size = | 750 const bool reconfigure_due_to_size = |
750 frame.width() != width_ || frame.height() != height_; | 751 frame.width() != width_ || frame.height() != height_; |
751 | 752 |
752 if (reconfigure_due_to_format) { | 753 if (reconfigure_due_to_format) { |
753 ALOGD << "Reconfigure encoder due to format change. " | 754 ALOGD << "Reconfigure encoder due to format change. " |
754 << (use_surface_ ? | 755 << (use_surface_ ? |
755 "Reconfiguring to encode from byte buffer." : | 756 "Reconfiguring to encode from byte buffer." : |
756 "Reconfiguring to encode from texture."); | 757 "Reconfiguring to encode from texture."); |
757 LogStatistics(true); | 758 LogStatistics(true); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 yuv_size_, | 799 yuv_size_, |
799 current_timestamp_us_); | 800 current_timestamp_us_); |
800 CHECK_EXCEPTION(jni); | 801 CHECK_EXCEPTION(jni); |
801 return encode_status; | 802 return encode_status; |
802 } | 803 } |
803 | 804 |
804 bool MediaCodecVideoEncoder::EncodeTextureOnCodecThread(JNIEnv* jni, | 805 bool MediaCodecVideoEncoder::EncodeTextureOnCodecThread(JNIEnv* jni, |
805 bool key_frame, const webrtc::VideoFrame& frame) { | 806 bool key_frame, const webrtc::VideoFrame& frame) { |
806 RTC_DCHECK(codec_thread_checker_.CalledOnValidThread()); | 807 RTC_DCHECK(codec_thread_checker_.CalledOnValidThread()); |
807 RTC_CHECK(use_surface_); | 808 RTC_CHECK(use_surface_); |
808 NativeHandleImpl* handle = | 809 NativeHandleImpl* handle = static_cast<NativeHandleImpl*>( |
809 static_cast<NativeHandleImpl*>(frame.native_handle()); | 810 frame.video_frame_buffer()->native_handle()); |
810 jfloatArray sampling_matrix = jni->NewFloatArray(16); | 811 jfloatArray sampling_matrix = jni->NewFloatArray(16); |
811 jni->SetFloatArrayRegion(sampling_matrix, 0, 16, handle->sampling_matrix); | 812 jni->SetFloatArrayRegion(sampling_matrix, 0, 16, handle->sampling_matrix); |
812 | 813 |
813 bool encode_status = jni->CallBooleanMethod(*j_media_codec_video_encoder_, | 814 bool encode_status = jni->CallBooleanMethod(*j_media_codec_video_encoder_, |
814 j_encode_texture_method_, | 815 j_encode_texture_method_, |
815 key_frame, | 816 key_frame, |
816 handle->oes_texture_id, | 817 handle->oes_texture_id, |
817 sampling_matrix, | 818 sampling_matrix, |
818 current_timestamp_us_); | 819 current_timestamp_us_); |
819 CHECK_EXCEPTION(jni); | 820 CHECK_EXCEPTION(jni); |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1252 return supported_codecs_; | 1253 return supported_codecs_; |
1253 } | 1254 } |
1254 | 1255 |
1255 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( | 1256 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( |
1256 webrtc::VideoEncoder* encoder) { | 1257 webrtc::VideoEncoder* encoder) { |
1257 ALOGD << "Destroy video encoder."; | 1258 ALOGD << "Destroy video encoder."; |
1258 delete encoder; | 1259 delete encoder; |
1259 } | 1260 } |
1260 | 1261 |
1261 } // namespace webrtc_jni | 1262 } // namespace webrtc_jni |
1262 | |
OLD | NEW |