Android: Remove use of EGLContexts in PeerConnectionFactory
Since the legacy video codecs seem to be around for some time more, we need to make them injectable and provide a migration path for clients that still use them so that we can clean up PeerConnectionFactory. This CL moves the creation of EglContexts into the legacy codec factories. Clients can then migrate to setEGLContext() instead of using setVideoHwAccelerationOptions(). Bug: webrtc:9502 Change-Id: I608607b32db73ce3df7704a061e66d9d53946af5 Reviewed-on: https://webrtc-review.googlesource.com/87941 Reviewed-by: Sami Kalliomäki <sakal@webrtc.org> Commit-Queue: Magnus Jedvert <magjed@webrtc.org> Cr-Commit-Position: refs/heads/master@{#23934}
This commit is contained in:
committed by
Commit Bot
parent
2234121cfb
commit
0f0e7a6f18
@ -64,7 +64,7 @@ class MediaCodecVideoDecoder : public VideoDecoder, public rtc::MessageHandler {
|
||||
public:
|
||||
explicit MediaCodecVideoDecoder(JNIEnv* jni,
|
||||
VideoCodecType codecType,
|
||||
jobject render_egl_context);
|
||||
bool use_surface);
|
||||
~MediaCodecVideoDecoder() override;
|
||||
|
||||
int32_t InitDecode(const VideoCodec* codecSettings,
|
||||
@ -105,14 +105,10 @@ class MediaCodecVideoDecoder : public VideoDecoder, public rtc::MessageHandler {
|
||||
// Type of video codec.
|
||||
VideoCodecType codecType_;
|
||||
|
||||
// Render EGL context - owned by factory, should not be allocated/destroyed
|
||||
// by VideoDecoder.
|
||||
jobject render_egl_context_;
|
||||
|
||||
bool key_frame_required_;
|
||||
bool inited_;
|
||||
bool sw_fallback_required_;
|
||||
bool use_surface_;
|
||||
const bool use_surface_;
|
||||
VideoCodec codec_;
|
||||
I420BufferPool decoded_frame_pool_;
|
||||
DecodedImageCallback* callback_;
|
||||
@ -141,12 +137,12 @@ class MediaCodecVideoDecoder : public VideoDecoder, public rtc::MessageHandler {
|
||||
|
||||
MediaCodecVideoDecoder::MediaCodecVideoDecoder(JNIEnv* jni,
|
||||
VideoCodecType codecType,
|
||||
jobject render_egl_context)
|
||||
bool use_surface)
|
||||
: codecType_(codecType),
|
||||
render_egl_context_(render_egl_context),
|
||||
key_frame_required_(true),
|
||||
inited_(false),
|
||||
sw_fallback_required_(false),
|
||||
use_surface_(use_surface),
|
||||
codec_thread_(Thread::Create()),
|
||||
j_media_codec_video_decoder_(
|
||||
jni,
|
||||
@ -154,7 +150,6 @@ MediaCodecVideoDecoder::MediaCodecVideoDecoder(JNIEnv* jni,
|
||||
codec_thread_->SetName("MediaCodecVideoDecoder", NULL);
|
||||
RTC_CHECK(codec_thread_->Start()) << "Failed to start MediaCodecVideoDecoder";
|
||||
|
||||
use_surface_ = (render_egl_context_ != NULL);
|
||||
ALOGD << "MediaCodecVideoDecoder ctor. Use surface: " << use_surface_;
|
||||
memset(&codec_, 0, sizeof(codec_));
|
||||
AllowBlockingCalls();
|
||||
@ -228,10 +223,9 @@ int32_t MediaCodecVideoDecoder::InitDecodeOnCodecThread() {
|
||||
|
||||
ScopedJavaLocalRef<jobject> j_video_codec_enum =
|
||||
Java_VideoCodecType_fromNativeIndex(jni, codecType_);
|
||||
jobject j_egl_context = use_surface_ ? render_egl_context_ : nullptr;
|
||||
bool success = Java_MediaCodecVideoDecoder_initDecode(
|
||||
jni, j_media_codec_video_decoder_, j_video_codec_enum, codec_.width,
|
||||
codec_.height, JavaParamRef<jobject>(j_egl_context));
|
||||
codec_.height);
|
||||
|
||||
if (CheckException(jni) || !success) {
|
||||
ALOGE << "Codec initialization error - fallback to SW codec.";
|
||||
@ -779,8 +773,7 @@ void MediaCodecVideoDecoder::OnMessage(rtc::Message* msg) {
|
||||
codec_thread_->PostDelayed(RTC_FROM_HERE, kMediaCodecPollMs, this);
|
||||
}
|
||||
|
||||
MediaCodecVideoDecoderFactory::MediaCodecVideoDecoderFactory()
|
||||
: egl_context_(nullptr) {
|
||||
MediaCodecVideoDecoderFactory::MediaCodecVideoDecoderFactory() {
|
||||
ALOGD << "MediaCodecVideoDecoderFactory ctor";
|
||||
JNIEnv* jni = AttachCurrentThreadIfNeeded();
|
||||
ScopedLocalRefFrame local_ref_frame(jni);
|
||||
@ -807,23 +800,6 @@ MediaCodecVideoDecoderFactory::MediaCodecVideoDecoderFactory()
|
||||
|
||||
MediaCodecVideoDecoderFactory::~MediaCodecVideoDecoderFactory() {
|
||||
ALOGD << "MediaCodecVideoDecoderFactory dtor";
|
||||
if (egl_context_) {
|
||||
JNIEnv* jni = AttachCurrentThreadIfNeeded();
|
||||
jni->DeleteGlobalRef(egl_context_);
|
||||
}
|
||||
}
|
||||
|
||||
void MediaCodecVideoDecoderFactory::SetEGLContext(JNIEnv* jni,
|
||||
jobject egl_context) {
|
||||
ALOGD << "MediaCodecVideoDecoderFactory::SetEGLContext";
|
||||
if (egl_context_) {
|
||||
jni->DeleteGlobalRef(egl_context_);
|
||||
egl_context_ = nullptr;
|
||||
}
|
||||
egl_context_ = jni->NewGlobalRef(egl_context);
|
||||
if (CheckException(jni)) {
|
||||
ALOGE << "error calling NewGlobalRef for EGL Context.";
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<SdpVideoFormat> MediaCodecVideoDecoderFactory::GetSupportedFormats()
|
||||
@ -843,7 +819,8 @@ std::unique_ptr<VideoDecoder> MediaCodecVideoDecoderFactory::CreateVideoDecoder(
|
||||
JNIEnv* jni = AttachCurrentThreadIfNeeded();
|
||||
ScopedLocalRefFrame local_ref_frame(jni);
|
||||
return rtc::MakeUnique<MediaCodecVideoDecoder>(
|
||||
jni, PayloadStringToCodecType(format.name), egl_context_);
|
||||
jni, PayloadStringToCodecType(format.name),
|
||||
Java_MediaCodecVideoDecoder_useSurface(jni));
|
||||
}
|
||||
}
|
||||
ALOGW << "Can not find HW video decoder for type " << format.name;
|
||||
|
||||
Reference in New Issue
Block a user