| 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 0e6e96a6c0ab9b863d7fccd87ed6195e825983af..d670310d0d47a8fb2eca109b466ed0b7b7a6f2c3 100644
|
| --- a/webrtc/api/android/jni/androidmediaencoder_jni.cc
|
| +++ b/webrtc/api/android/jni/androidmediaencoder_jni.cc
|
| @@ -96,7 +96,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 +185,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 +301,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 +391,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 +404,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;
|
| - } else if (codecType_ != kVideoCodecVP9) {
|
| + } else if (codec_type != kVideoCodecVP9) {
|
| scale_ = true;
|
| }
|
|
|
| @@ -413,8 +414,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 +521,7 @@ bool MediaCodecVideoEncoder::ResetCodecOnCodecThread() {
|
| bool MediaCodecVideoEncoder::ProcessHWErrorOnCodecThread(
|
| bool reset_if_fallback_unavailable) {
|
| ALOGE << "ProcessHWErrorOnCodecThread";
|
| - if (VideoEncoder::IsSupportedSoftware(
|
| - VideoEncoder::CodecToEncoderType(codecType_))) {
|
| + if (VideoEncoder::IsSupportedSoftware(codec_)) {
|
| ALOGE << "Fallback to SW encoder.";
|
| sw_fallback_required_ = true;
|
| return false;
|
| @@ -548,9 +548,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 +589,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 +1063,7 @@ bool MediaCodecVideoEncoder::DeliverPendingOutputs(JNIEnv* jni) {
|
| }
|
|
|
| // Callback - return encoded frame.
|
| + const VideoCodecType codec_type = cricket::CodecTypeFromName(codec_.name);
|
| int32_t callback_status = 0;
|
| if (callback_) {
|
| std::unique_ptr<webrtc::EncodedImage> image(
|
| @@ -1080,8 +1081,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;
|
| @@ -1089,7 +1090,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;
|
| }
|
| @@ -1118,13 +1119,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;
|
| @@ -1132,7 +1133,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;
|
| @@ -1358,8 +1359,7 @@ webrtc::VideoEncoder* MediaCodecVideoEncoderFactory::CreateVideoEncoder(
|
| }
|
| if (IsCodecSupported(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;
|
|
|