Replace WebRtcVideoEncoderFactory::VideoCodec with cricket::VideoCodec
This CL introduces two new functions to the WebRtcVideoEncoderFactory
interface based on cricket::VideoFormat instead of
WebRtcVideoEncoderFactory::VideoCodec. The functions are:
WebRtcVideoEncoderFactory::CreateVideoEncoder() and
WebRtcVideoEncoderFactory::supported_codecs(). In order to make a smooth
transition to the new interface, the old functions are kept, and default
implementations are provided for both the old and new functions so that
external clients can switch from the old to the new functions in peace.
The default implementations will just convert between
cricket::VideoFormat and WebRtcVideoEncoderFactory::VideoCodec. Once all
external clients have updated their code, the plan is to remove the old
functions and all default implementations to make
WebRtcVideoEncoderFactory a pure interface again.
BUG=webrtc:6402,webrtc:6337
Review-Url: https://codereview.webrtc.org/2449993003
Cr-Commit-Position: refs/heads/master@{#14826}
diff --git a/webrtc/api/android/jni/androidmediaencoder_jni.cc b/webrtc/api/android/jni/androidmediaencoder_jni.cc
index c5c8454..0e6e96a 100644
--- a/webrtc/api/android/jni/androidmediaencoder_jni.cc
+++ b/webrtc/api/android/jni/androidmediaencoder_jni.cc
@@ -57,9 +57,6 @@
#define H264_SC_LENGTH 4
// Maximum allowed NALUs in one output frame.
#define MAX_NALUS_PERFRAME 32
-// Maximum supported HW video encoder resolution.
-#define MAX_VIDEO_WIDTH 1280
-#define MAX_VIDEO_HEIGHT 1280
// Maximum supported HW video encoder fps.
#define MAX_VIDEO_FPS 30
// Maximum allowed fps value in SetRates() call.
@@ -1310,8 +1307,7 @@
CHECK_EXCEPTION(jni);
if (is_vp8_hw_supported) {
ALOGD << "VP8 HW Encoder supported.";
- supported_codecs_.push_back(VideoCodec(kVideoCodecVP8, "VP8",
- MAX_VIDEO_WIDTH, MAX_VIDEO_HEIGHT, MAX_VIDEO_FPS));
+ supported_codecs_.push_back(cricket::VideoCodec("VP8"));
}
bool is_vp9_hw_supported = jni->CallStaticBooleanMethod(
@@ -1320,8 +1316,7 @@
CHECK_EXCEPTION(jni);
if (is_vp9_hw_supported) {
ALOGD << "VP9 HW Encoder supported.";
- supported_codecs_.push_back(VideoCodec(kVideoCodecVP9, "VP9",
- MAX_VIDEO_WIDTH, MAX_VIDEO_HEIGHT, MAX_VIDEO_FPS));
+ supported_codecs_.push_back(cricket::VideoCodec("VP9"));
}
bool is_h264_hw_supported = jni->CallStaticBooleanMethod(
@@ -1330,8 +1325,7 @@
CHECK_EXCEPTION(jni);
if (is_h264_hw_supported) {
ALOGD << "H.264 HW Encoder supported.";
- supported_codecs_.push_back(VideoCodec(kVideoCodecH264, "H264",
- MAX_VIDEO_WIDTH, MAX_VIDEO_HEIGHT, MAX_VIDEO_FPS));
+ supported_codecs_.push_back(cricket::VideoCodec("H264"));
}
}
@@ -1357,26 +1351,23 @@
}
webrtc::VideoEncoder* MediaCodecVideoEncoderFactory::CreateVideoEncoder(
- VideoCodecType type) {
+ const cricket::VideoCodec& codec) {
if (supported_codecs_.empty()) {
- ALOGW << "No HW video encoder for type " << (int)type;
+ ALOGW << "No HW video encoder for codec " << codec.name;
return nullptr;
}
- for (std::vector<VideoCodec>::const_iterator it = supported_codecs_.begin();
- it != supported_codecs_.end(); ++it) {
- if (it->type == type) {
- ALOGD << "Create HW video encoder for type " << (int)type <<
- " (" << it->name << ").";
- return new MediaCodecVideoEncoder(AttachCurrentThreadIfNeeded(), type,
- egl_context_);
- }
+ 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,
+ egl_context_);
}
- ALOGW << "Can not find HW video encoder for type " << (int)type;
+ ALOGW << "Can not find HW video encoder for type " << codec.name;
return nullptr;
}
-const std::vector<MediaCodecVideoEncoderFactory::VideoCodec>&
-MediaCodecVideoEncoderFactory::codecs() const {
+const std::vector<cricket::VideoCodec>&
+MediaCodecVideoEncoderFactory::supported_codecs() const {
return supported_codecs_;
}
diff --git a/webrtc/api/android/jni/androidmediaencoder_jni.h b/webrtc/api/android/jni/androidmediaencoder_jni.h
index 460eac3..74442dd 100644
--- a/webrtc/api/android/jni/androidmediaencoder_jni.h
+++ b/webrtc/api/android/jni/androidmediaencoder_jni.h
@@ -28,16 +28,20 @@
void SetEGLContext(JNIEnv* jni, jobject egl_context);
// WebRtcVideoEncoderFactory implementation.
- webrtc::VideoEncoder* CreateVideoEncoder(webrtc::VideoCodecType type)
- override;
- const std::vector<VideoCodec>& codecs() const override;
+ webrtc::VideoEncoder* CreateVideoEncoder(
+ const cricket::VideoCodec& codec) override;
+ const std::vector<cricket::VideoCodec>& supported_codecs() const override;
void DestroyVideoEncoder(webrtc::VideoEncoder* encoder) override;
private:
+ // Disable overloaded virtual function warning. TODO(magjed): Remove once
+ // http://crbug/webrtc/6402 is fixed.
+ using cricket::WebRtcVideoEncoderFactory::CreateVideoEncoder;
+
jobject egl_context_;
// Empty if platform support is lacking, const after ctor returns.
- std::vector<VideoCodec> supported_codecs_;
+ std::vector<cricket::VideoCodec> supported_codecs_;
};
} // namespace webrtc_jni