| 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 |
| 11 // NOTICE: androidmediaencoder_jni.h must be included before | 11 // NOTICE: androidmediaencoder_jni.h must be included before |
| 12 // androidmediacodeccommon.h to avoid build errors. | 12 // androidmediacodeccommon.h to avoid build errors. |
| 13 #include "webrtc/api/java/jni/androidmediaencoder_jni.h" | 13 #include "webrtc/api/java/jni/androidmediaencoder_jni.h" |
| 14 | 14 |
| 15 #include <algorithm> | 15 #include <algorithm> |
| 16 #include <memory> |
| 16 #include <list> | 17 #include <list> |
| 17 | 18 |
| 18 #include "third_party/libyuv/include/libyuv/convert.h" | 19 #include "third_party/libyuv/include/libyuv/convert.h" |
| 19 #include "third_party/libyuv/include/libyuv/convert_from.h" | 20 #include "third_party/libyuv/include/libyuv/convert_from.h" |
| 20 #include "third_party/libyuv/include/libyuv/video_common.h" | 21 #include "third_party/libyuv/include/libyuv/video_common.h" |
| 21 #include "webrtc/api/java/jni/androidmediacodeccommon.h" | 22 #include "webrtc/api/java/jni/androidmediacodeccommon.h" |
| 22 #include "webrtc/api/java/jni/classreferenceholder.h" | 23 #include "webrtc/api/java/jni/classreferenceholder.h" |
| 23 #include "webrtc/api/java/jni/native_handle_impl.h" | 24 #include "webrtc/api/java/jni/native_handle_impl.h" |
| 24 #include "webrtc/base/bind.h" | 25 #include "webrtc/base/bind.h" |
| 25 #include "webrtc/base/checks.h" | 26 #include "webrtc/base/checks.h" |
| 26 #include "webrtc/base/logging.h" | 27 #include "webrtc/base/logging.h" |
| 27 #include "webrtc/base/thread.h" | 28 #include "webrtc/base/thread.h" |
| 28 #include "webrtc/base/thread_checker.h" | 29 #include "webrtc/base/thread_checker.h" |
| 29 #include "webrtc/common_types.h" | 30 #include "webrtc/common_types.h" |
| 30 #include "webrtc/modules/rtp_rtcp/source/h264_bitstream_parser.h" | 31 #include "webrtc/modules/rtp_rtcp/source/h264_bitstream_parser.h" |
| 31 #include "webrtc/modules/video_coding/include/video_codec_interface.h" | 32 #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
| 32 #include "webrtc/modules/video_coding/utility/quality_scaler.h" | 33 #include "webrtc/modules/video_coding/utility/quality_scaler.h" |
| 33 #include "webrtc/modules/video_coding/utility/vp8_header_parser.h" | 34 #include "webrtc/modules/video_coding/utility/vp8_header_parser.h" |
| 34 #include "webrtc/system_wrappers/include/field_trial.h" | 35 #include "webrtc/system_wrappers/include/field_trial.h" |
| 35 #include "webrtc/system_wrappers/include/logcat_trace_context.h" | 36 #include "webrtc/system_wrappers/include/logcat_trace_context.h" |
| 36 | 37 |
| 37 using rtc::Bind; | 38 using rtc::Bind; |
| 38 using rtc::Thread; | 39 using rtc::Thread; |
| 39 using rtc::ThreadManager; | 40 using rtc::ThreadManager; |
| 40 using rtc::scoped_ptr; | |
| 41 | 41 |
| 42 using webrtc::CodecSpecificInfo; | 42 using webrtc::CodecSpecificInfo; |
| 43 using webrtc::EncodedImage; | 43 using webrtc::EncodedImage; |
| 44 using webrtc::VideoFrame; | 44 using webrtc::VideoFrame; |
| 45 using webrtc::RTPFragmentationHeader; | 45 using webrtc::RTPFragmentationHeader; |
| 46 using webrtc::VideoCodec; | 46 using webrtc::VideoCodec; |
| 47 using webrtc::VideoCodecType; | 47 using webrtc::VideoCodecType; |
| 48 using webrtc::kVideoCodecH264; | 48 using webrtc::kVideoCodecH264; |
| 49 using webrtc::kVideoCodecVP8; | 49 using webrtc::kVideoCodecVP8; |
| 50 using webrtc::kVideoCodecVP9; | 50 using webrtc::kVideoCodecVP9; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 | 175 |
| 176 // Type of video codec. | 176 // Type of video codec. |
| 177 VideoCodecType codecType_; | 177 VideoCodecType codecType_; |
| 178 | 178 |
| 179 // Valid all the time since RegisterEncodeCompleteCallback() Invoke()s to | 179 // Valid all the time since RegisterEncodeCompleteCallback() Invoke()s to |
| 180 // |codec_thread_| synchronously. | 180 // |codec_thread_| synchronously. |
| 181 webrtc::EncodedImageCallback* callback_; | 181 webrtc::EncodedImageCallback* callback_; |
| 182 | 182 |
| 183 // State that is constant for the lifetime of this object once the ctor | 183 // State that is constant for the lifetime of this object once the ctor |
| 184 // returns. | 184 // returns. |
| 185 scoped_ptr<Thread> codec_thread_; // Thread on which to operate MediaCodec. | 185 std::unique_ptr<Thread> |
| 186 codec_thread_; // Thread on which to operate MediaCodec. |
| 186 rtc::ThreadChecker codec_thread_checker_; | 187 rtc::ThreadChecker codec_thread_checker_; |
| 187 ScopedGlobalRef<jclass> j_media_codec_video_encoder_class_; | 188 ScopedGlobalRef<jclass> j_media_codec_video_encoder_class_; |
| 188 ScopedGlobalRef<jobject> j_media_codec_video_encoder_; | 189 ScopedGlobalRef<jobject> j_media_codec_video_encoder_; |
| 189 jmethodID j_init_encode_method_; | 190 jmethodID j_init_encode_method_; |
| 190 jmethodID j_get_input_buffers_method_; | 191 jmethodID j_get_input_buffers_method_; |
| 191 jmethodID j_dequeue_input_buffer_method_; | 192 jmethodID j_dequeue_input_buffer_method_; |
| 192 jmethodID j_encode_buffer_method_; | 193 jmethodID j_encode_buffer_method_; |
| 193 jmethodID j_encode_texture_method_; | 194 jmethodID j_encode_texture_method_; |
| 194 jmethodID j_release_method_; | 195 jmethodID j_release_method_; |
| 195 jmethodID j_set_rates_method_; | 196 jmethodID j_set_rates_method_; |
| (...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 ". Key: " << key_frame << | 967 ". Key: " << key_frame << |
| 967 ". Size: " << payload_size << | 968 ". Size: " << payload_size << |
| 968 ". TS: " << (int)last_output_timestamp_ms_ << | 969 ". TS: " << (int)last_output_timestamp_ms_ << |
| 969 ". Latency: " << current_latency << | 970 ". Latency: " << current_latency << |
| 970 ". EncTime: " << frame_encoding_time_ms; | 971 ". EncTime: " << frame_encoding_time_ms; |
| 971 } | 972 } |
| 972 | 973 |
| 973 // Callback - return encoded frame. | 974 // Callback - return encoded frame. |
| 974 int32_t callback_status = 0; | 975 int32_t callback_status = 0; |
| 975 if (callback_) { | 976 if (callback_) { |
| 976 scoped_ptr<webrtc::EncodedImage> image( | 977 std::unique_ptr<webrtc::EncodedImage> image( |
| 977 new webrtc::EncodedImage(payload, payload_size, payload_size)); | 978 new webrtc::EncodedImage(payload, payload_size, payload_size)); |
| 978 image->_encodedWidth = width_; | 979 image->_encodedWidth = width_; |
| 979 image->_encodedHeight = height_; | 980 image->_encodedHeight = height_; |
| 980 image->_timeStamp = output_timestamp_; | 981 image->_timeStamp = output_timestamp_; |
| 981 image->capture_time_ms_ = output_render_time_ms_; | 982 image->capture_time_ms_ = output_render_time_ms_; |
| 982 image->rotation_ = output_rotation_; | 983 image->rotation_ = output_rotation_; |
| 983 image->_frameType = | 984 image->_frameType = |
| 984 (key_frame ? webrtc::kVideoFrameKey : webrtc::kVideoFrameDelta); | 985 (key_frame ? webrtc::kVideoFrameKey : webrtc::kVideoFrameDelta); |
| 985 image->_completeFrame = true; | 986 image->_completeFrame = true; |
| 986 image->adapt_reason_.quality_resolution_downscales = | 987 image->adapt_reason_.quality_resolution_downscales = |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1267 return supported_codecs_; | 1268 return supported_codecs_; |
| 1268 } | 1269 } |
| 1269 | 1270 |
| 1270 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( | 1271 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( |
| 1271 webrtc::VideoEncoder* encoder) { | 1272 webrtc::VideoEncoder* encoder) { |
| 1272 ALOGD << "Destroy video encoder."; | 1273 ALOGD << "Destroy video encoder."; |
| 1273 delete encoder; | 1274 delete encoder; |
| 1274 } | 1275 } |
| 1275 | 1276 |
| 1276 } // namespace webrtc_jni | 1277 } // namespace webrtc_jni |
| OLD | NEW |