| 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 6fcb0fbe3609441f5bac643d25d5c6f152241db3..d5998c032c6132c71cd9e84cf68594bb010665c9 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
|
| @@ -186,7 +187,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.
|
| @@ -302,9 +303,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_(
|
| @@ -392,9 +393,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;
|
| }
|
| @@ -404,9 +406,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->VP8().automaticResizeOn;
|
| - } else if (codecType_ != kVideoCodecVP9) {
|
| + } else if (codec_type != kVideoCodecVP9) {
|
| scale_ = true;
|
| }
|
|
|
| @@ -414,8 +416,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 {
|
| @@ -522,8 +524,8 @@ bool MediaCodecVideoEncoder::ResetCodecOnCodecThread() {
|
| bool MediaCodecVideoEncoder::ProcessHWErrorOnCodecThread(
|
| bool reset_if_fallback_unavailable) {
|
| ALOGE << "ProcessHWErrorOnCodecThread";
|
| - if (VideoEncoder::IsSupportedSoftware(
|
| - VideoEncoder::CodecToEncoderType(codecType_))) {
|
| + if (FindMatchingCodec(cricket::InternalEncoderFactory().supported_codecs(),
|
| + codec_)) {
|
| ALOGE << "Fallback to SW encoder.";
|
| sw_fallback_required_ = true;
|
| return false;
|
| @@ -550,9 +552,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_;
|
| }
|
| @@ -591,7 +593,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,
|
| @@ -1065,6 +1067,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_) {
|
| @@ -1083,8 +1086,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;
|
| @@ -1092,7 +1095,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;
|
| }
|
| @@ -1121,13 +1124,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;
|
| @@ -1135,7 +1138,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;
|
| @@ -1359,8 +1362,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;
|
|
|