Chromium Code Reviews| Index: webrtc/api/android/jni/androidmediaencoder_jni.cc |
| diff --git a/webrtc/api/android/jni/androidmediaencoder_jni.cc b/webrtc/api/android/jni/androidmediaencoder_jni.cc |
| index a4daa7a5391efde89045c566a3b8b36399701cbc..9fbe6f3eb27e971610a5ec9bf4edd24103922cc2 100644 |
| --- a/webrtc/api/android/jni/androidmediaencoder_jni.cc |
| +++ b/webrtc/api/android/jni/androidmediaencoder_jni.cc |
| @@ -30,6 +30,7 @@ |
| #include "webrtc/base/timeutils.h" |
| #include "webrtc/common_types.h" |
| #include "webrtc/common_video/h264/h264_bitstream_parser.h" |
| +#include "webrtc/media/engine/internalencoderfactory.h" |
| #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
| #include "webrtc/modules/video_coding/utility/quality_scaler.h" |
| #include "webrtc/modules/video_coding/utility/vp8_header_parser.h" |
| @@ -96,7 +97,7 @@ class MediaCodecVideoEncoder : public webrtc::VideoEncoder, |
| public: |
| virtual ~MediaCodecVideoEncoder(); |
| MediaCodecVideoEncoder(JNIEnv* jni, |
| - VideoCodecType codecType, |
| + const cricket::VideoCodec& codec, |
| jobject egl_context); |
| // webrtc::VideoEncoder implementation. Everything trampolines to |
| @@ -185,7 +186,7 @@ class MediaCodecVideoEncoder : public webrtc::VideoEncoder, |
| void LogStatistics(bool force_log); |
| // Type of video codec. |
| - VideoCodecType codecType_; |
| + const cricket::VideoCodec codec_; |
| // Valid all the time since RegisterEncodeCompleteCallback() Invoke()s to |
| // |codec_thread_| synchronously. |
| @@ -301,9 +302,9 @@ MediaCodecVideoEncoder::~MediaCodecVideoEncoder() { |
| } |
| MediaCodecVideoEncoder::MediaCodecVideoEncoder(JNIEnv* jni, |
| - VideoCodecType codecType, |
| + const cricket::VideoCodec& codec, |
| jobject egl_context) |
| - : codecType_(codecType), |
| + : codec_(codec), |
| callback_(NULL), |
| codec_thread_(new Thread()), |
| j_media_codec_video_encoder_class_( |
| @@ -391,9 +392,10 @@ int32_t MediaCodecVideoEncoder::InitEncode( |
| return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; |
| } |
| // Factory should guard against other codecs being used with us. |
| - RTC_CHECK(codec_settings->codecType == codecType_) |
| + const VideoCodecType codec_type = cricket::CodecTypeFromName(codec_.name); |
| + RTC_CHECK(codec_settings->codecType == codec_type) |
| << "Unsupported codec " << codec_settings->codecType << " for " |
| - << codecType_; |
| + << codec_type; |
| if (sw_fallback_required_) { |
| return WEBRTC_VIDEO_CODEC_OK; |
| } |
| @@ -403,9 +405,9 @@ int32_t MediaCodecVideoEncoder::InitEncode( |
| // Scaling is disabled for VP9, but optionally enabled for VP8. |
| // TODO(pbos): Extract automaticResizeOn out of VP8 settings. |
| scale_ = false; |
| - if (codecType_ == kVideoCodecVP8) { |
| + if (codec_type == kVideoCodecVP8) { |
| scale_ = codec_settings->codecSpecific.VP8.automaticResizeOn; |
|
hta-webrtc
2016/11/15 20:36:24
Sideswipe: This access to codecSpecific shoudldn't
magjed_webrtc
2016/11/16 13:44:11
Done.
|
| - } else if (codecType_ != kVideoCodecVP9) { |
| + } else if (codec_type != kVideoCodecVP9) { |
| scale_ = true; |
| } |
| @@ -413,8 +415,8 @@ int32_t MediaCodecVideoEncoder::InitEncode( |
| ALOGD << "Encoder automatic resize " << (scale_ ? "enabled" : "disabled"); |
| if (scale_) { |
| - if (codecType_ == kVideoCodecVP8 || codecType_ == kVideoCodecH264) { |
| - quality_scaler_.Init(codecType_, codec_settings->startBitrate, |
| + if (codec_type == kVideoCodecVP8 || codec_type == kVideoCodecH264) { |
| + quality_scaler_.Init(codec_type, codec_settings->startBitrate, |
| codec_settings->width, codec_settings->height, |
| codec_settings->maxFramerate); |
| } else { |
| @@ -520,8 +522,9 @@ bool MediaCodecVideoEncoder::ResetCodecOnCodecThread() { |
| bool MediaCodecVideoEncoder::ProcessHWErrorOnCodecThread( |
| bool reset_if_fallback_unavailable) { |
| ALOGE << "ProcessHWErrorOnCodecThread"; |
| - if (VideoEncoder::IsSupportedSoftware( |
| - VideoEncoder::CodecToEncoderType(codecType_))) { |
| + if (FindMatchingCodec( |
| + cricket::InternalEncoderFactory::GetInstance().supported_codecs(), |
| + codec_)) { |
| ALOGE << "Fallback to SW encoder."; |
| sw_fallback_required_ = true; |
| return false; |
| @@ -548,9 +551,9 @@ int32_t MediaCodecVideoEncoder::InitEncodeOnCodecThread( |
| JNIEnv* jni = AttachCurrentThreadIfNeeded(); |
| ScopedLocalRefFrame local_ref_frame(jni); |
| - ALOGD << "InitEncodeOnCodecThread Type: " << (int)codecType_ << ", " << |
| - width << " x " << height << ". Bitrate: " << kbps << |
| - " kbps. Fps: " << fps; |
| + const VideoCodecType codec_type = cricket::CodecTypeFromName(codec_.name); |
| + ALOGD << "InitEncodeOnCodecThread Type: " << (int)codec_type << ", " << width |
| + << " x " << height << ". Bitrate: " << kbps << " kbps. Fps: " << fps; |
| if (kbps == 0) { |
| kbps = last_set_bitrate_kbps_; |
| } |
| @@ -589,7 +592,7 @@ int32_t MediaCodecVideoEncoder::InitEncodeOnCodecThread( |
| // We enforce no extra stride/padding in the format creation step. |
| jobject j_video_codec_enum = JavaEnumFromIndexAndClassName( |
| - jni, "MediaCodecVideoEncoder$VideoCodecType", codecType_); |
| + jni, "MediaCodecVideoEncoder$VideoCodecType", codec_type); |
| const bool encode_status = jni->CallBooleanMethod( |
| *j_media_codec_video_encoder_, j_init_encode_method_, |
| j_video_codec_enum, width, height, kbps, fps, |
| @@ -1063,6 +1066,7 @@ bool MediaCodecVideoEncoder::DeliverPendingOutputs(JNIEnv* jni) { |
| } |
| // Callback - return encoded frame. |
| + const VideoCodecType codec_type = cricket::CodecTypeFromName(codec_.name); |
| webrtc::EncodedImageCallback::Result callback_result( |
| webrtc::EncodedImageCallback::Result::OK); |
| if (callback_) { |
| @@ -1081,8 +1085,8 @@ bool MediaCodecVideoEncoder::DeliverPendingOutputs(JNIEnv* jni) { |
| webrtc::CodecSpecificInfo info; |
| memset(&info, 0, sizeof(info)); |
| - info.codecType = codecType_; |
| - if (codecType_ == kVideoCodecVP8) { |
| + info.codecType = codec_type; |
| + if (codec_type == kVideoCodecVP8) { |
| info.codecSpecific.VP8.pictureId = picture_id_; |
| info.codecSpecific.VP8.nonReference = false; |
| info.codecSpecific.VP8.simulcastIdx = 0; |
| @@ -1090,7 +1094,7 @@ bool MediaCodecVideoEncoder::DeliverPendingOutputs(JNIEnv* jni) { |
| info.codecSpecific.VP8.layerSync = false; |
| info.codecSpecific.VP8.tl0PicIdx = webrtc::kNoTl0PicIdx; |
| info.codecSpecific.VP8.keyIdx = webrtc::kNoKeyIdx; |
| - } else if (codecType_ == kVideoCodecVP9) { |
| + } else if (codec_type == kVideoCodecVP9) { |
| if (key_frame) { |
| gof_idx_ = 0; |
| } |
| @@ -1119,13 +1123,13 @@ bool MediaCodecVideoEncoder::DeliverPendingOutputs(JNIEnv* jni) { |
| // Generate a header describing a single fragment. |
| webrtc::RTPFragmentationHeader header; |
| memset(&header, 0, sizeof(header)); |
| - if (codecType_ == kVideoCodecVP8 || codecType_ == kVideoCodecVP9) { |
| + if (codec_type == kVideoCodecVP8 || codec_type == kVideoCodecVP9) { |
| header.VerifyAndAllocateFragmentationHeader(1); |
| header.fragmentationOffset[0] = 0; |
| header.fragmentationLength[0] = image->_length; |
| header.fragmentationPlType[0] = 0; |
| header.fragmentationTimeDiff[0] = 0; |
| - if (codecType_ == kVideoCodecVP8 && scale_) { |
| + if (codec_type == kVideoCodecVP8 && scale_) { |
| int qp; |
| if (webrtc::vp8::GetQp(payload, payload_size, &qp)) { |
| current_acc_qp_ += qp; |
| @@ -1133,7 +1137,7 @@ bool MediaCodecVideoEncoder::DeliverPendingOutputs(JNIEnv* jni) { |
| image->qp_ = qp; |
| } |
| } |
| - } else if (codecType_ == kVideoCodecH264) { |
| + } else if (codec_type == kVideoCodecH264) { |
| if (scale_) { |
| h264_bitstream_parser_.ParseBitstream(payload, payload_size); |
| int qp; |
| @@ -1357,8 +1361,7 @@ webrtc::VideoEncoder* MediaCodecVideoEncoderFactory::CreateVideoEncoder( |
| } |
| if (FindMatchingCodec(supported_codecs_, codec)) { |
| ALOGD << "Create HW video encoder for " << codec.name; |
| - const VideoCodecType type = cricket::CodecTypeFromName(codec.name); |
| - return new MediaCodecVideoEncoder(AttachCurrentThreadIfNeeded(), type, |
| + return new MediaCodecVideoEncoder(AttachCurrentThreadIfNeeded(), codec, |
| egl_context_); |
| } |
| ALOGW << "Can not find HW video encoder for type " << codec.name; |