Bug 1350250 - Add a GeckoHlsResourceWrapper java glue.
MozReview-Commit-ID: KMAqkJSk2tT
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -463,16 +463,17 @@ gvjar.sources += [geckoview_thirdparty_s
if CONFIG['MOZ_ANDROID_HLS_SUPPORT']:
gvjar.sources += [geckoview_source_dir + 'java/org/mozilla/gecko/' + x for x in [
'media/GeckoAudioInfo.java',
'media/GeckoHlsAudioRenderer.java',
'media/GeckoHlsDemuxerWrapper.java',
'media/GeckoHlsPlayer.java',
'media/GeckoHlsRendererBase.java',
+ 'media/GeckoHlsResourceWrapper.java',
'media/GeckoHlsSample.java',
'media/GeckoHlsVideoRenderer.java',
'media/GeckoVideoInfo.java',
'media/Utils.java',
]]
gvjar.extra_jars += [
new file mode 100644
--- /dev/null
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/GeckoHlsResourceWrapper.java
@@ -0,0 +1,79 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package org.mozilla.gecko.media;
+
+import android.util.Log;
+
+import org.mozilla.gecko.annotation.WrapForJNI;
+import org.mozilla.gecko.mozglue.JNIObject;
+
+public class GeckoHlsResourceWrapper {
+ private static final String LOGTAG = "GeckoHlsResourceWrapper";
+ private static final boolean DEBUG = false;
+ private GeckoHlsPlayer mPlayer = null;
+ private boolean mDestroy = false;
+
+ public static class HlsResourceCallbacks extends JNIObject
+ implements GeckoHlsPlayer.ResourceCallbacks {
+ @WrapForJNI(calledFrom = "gecko")
+ HlsResourceCallbacks() {}
+
+ @Override
+ @WrapForJNI(dispatchTo = "gecko")
+ public native void onDataArrived();
+
+ @Override
+ @WrapForJNI(dispatchTo = "gecko")
+ public native void onError(int errorCode);
+
+ @Override // JNIObject
+ protected void disposeNative() {
+ throw new UnsupportedOperationException();
+ }
+ } // HlsResourceCallbacks
+
+ private GeckoHlsResourceWrapper(String url,
+ GeckoHlsPlayer.ResourceCallbacks callback) {
+ if (DEBUG) Log.d(LOGTAG, "GeckoHlsResourceWrapper created with url = " + url);
+ assertTrue(callback != null);
+
+ mPlayer = new GeckoHlsPlayer();
+ mPlayer.addResourceWrapperCallbackListener(callback);
+ mPlayer.init(url);
+ }
+
+ @WrapForJNI(calledFrom = "gecko")
+ public static GeckoHlsResourceWrapper create(String url,
+ GeckoHlsPlayer.ResourceCallbacks callback) {
+ return new GeckoHlsResourceWrapper(url, callback);
+ }
+
+ @WrapForJNI(calledFrom = "gecko")
+ public GeckoHlsPlayer GetPlayer() {
+ // GeckoHlsResourceWrapper should always be created before others
+ assertTrue(!mDestroy);
+ assertTrue(mPlayer != null);
+ return mPlayer;
+ }
+
+ private static void assertTrue(boolean condition) {
+ if (DEBUG && !condition) {
+ throw new AssertionError("Expected condition to be true");
+ }
+ }
+
+ @WrapForJNI // Called when native object is mDestroy.
+ private void destroy() {
+ if (DEBUG) Log.d(LOGTAG, "destroy!! Native object is destroyed.");
+ if (mDestroy) {
+ return;
+ }
+ mDestroy = true;
+ if (mPlayer != null) {
+ mPlayer.release();
+ mPlayer = null;
+ }
+ }
+}
--- a/widget/android/GeneratedJNINatives.h
+++ b/widget/android/GeneratedJNINatives.h
@@ -517,16 +517,35 @@ const JNINativeMethod GeckoHlsDemuxerWra
::template Wrap<&Impl::OnError>),
mozilla::jni::MakeNativeMethod<GeckoHlsDemuxerWrapper::HlsDemuxerCallbacks::OnInitialized_t>(
mozilla::jni::NativeStub<GeckoHlsDemuxerWrapper::HlsDemuxerCallbacks::OnInitialized_t, Impl>
::template Wrap<&Impl::OnInitialized>)
};
template<class Impl>
+class GeckoHlsResourceWrapper::HlsResourceCallbacks::Natives : public mozilla::jni::NativeImpl<HlsResourceCallbacks, Impl>
+{
+public:
+ static const JNINativeMethod methods[2];
+};
+
+template<class Impl>
+const JNINativeMethod GeckoHlsResourceWrapper::HlsResourceCallbacks::Natives<Impl>::methods[] = {
+
+ mozilla::jni::MakeNativeMethod<GeckoHlsResourceWrapper::HlsResourceCallbacks::OnDataArrived_t>(
+ mozilla::jni::NativeStub<GeckoHlsResourceWrapper::HlsResourceCallbacks::OnDataArrived_t, Impl>
+ ::template Wrap<&Impl::OnDataArrived>),
+
+ mozilla::jni::MakeNativeMethod<GeckoHlsResourceWrapper::HlsResourceCallbacks::OnError_t>(
+ mozilla::jni::NativeStub<GeckoHlsResourceWrapper::HlsResourceCallbacks::OnError_t, Impl>
+ ::template Wrap<&Impl::OnError>)
+};
+
+template<class Impl>
class MediaDrmProxy::NativeMediaDrmProxyCallbacks::Natives : public mozilla::jni::NativeImpl<NativeMediaDrmProxyCallbacks, Impl>
{
public:
static const JNINativeMethod methods[7];
};
template<class Impl>
const JNINativeMethod MediaDrmProxy::NativeMediaDrmProxyCallbacks::Natives<Impl>::methods[] = {
--- a/widget/android/GeneratedJNIWrappers.cpp
+++ b/widget/android/GeneratedJNIWrappers.cpp
@@ -2018,16 +2018,60 @@ auto GeckoHlsDemuxerWrapper::HlsDemuxerC
}
constexpr char GeckoHlsDemuxerWrapper::HlsDemuxerCallbacks::OnError_t::name[];
constexpr char GeckoHlsDemuxerWrapper::HlsDemuxerCallbacks::OnError_t::signature[];
constexpr char GeckoHlsDemuxerWrapper::HlsDemuxerCallbacks::OnInitialized_t::name[];
constexpr char GeckoHlsDemuxerWrapper::HlsDemuxerCallbacks::OnInitialized_t::signature[];
+const char GeckoHlsResourceWrapper::name[] =
+ "org/mozilla/gecko/media/GeckoHlsResourceWrapper";
+
+constexpr char GeckoHlsResourceWrapper::GetPlayer_t::name[];
+constexpr char GeckoHlsResourceWrapper::GetPlayer_t::signature[];
+
+auto GeckoHlsResourceWrapper::GetPlayer() const -> mozilla::jni::Object::LocalRef
+{
+ return mozilla::jni::Method<GetPlayer_t>::Call(GeckoHlsResourceWrapper::mCtx, nullptr);
+}
+
+constexpr char GeckoHlsResourceWrapper::Create_t::name[];
+constexpr char GeckoHlsResourceWrapper::Create_t::signature[];
+
+auto GeckoHlsResourceWrapper::Create(mozilla::jni::String::Param a0, mozilla::jni::Object::Param a1) -> GeckoHlsResourceWrapper::LocalRef
+{
+ return mozilla::jni::Method<Create_t>::Call(GeckoHlsResourceWrapper::Context(), nullptr, a0, a1);
+}
+
+constexpr char GeckoHlsResourceWrapper::Destroy_t::name[];
+constexpr char GeckoHlsResourceWrapper::Destroy_t::signature[];
+
+auto GeckoHlsResourceWrapper::Destroy() const -> void
+{
+ return mozilla::jni::Method<Destroy_t>::Call(GeckoHlsResourceWrapper::mCtx, nullptr);
+}
+
+const char GeckoHlsResourceWrapper::HlsResourceCallbacks::name[] =
+ "org/mozilla/gecko/media/GeckoHlsResourceWrapper$HlsResourceCallbacks";
+
+constexpr char GeckoHlsResourceWrapper::HlsResourceCallbacks::New_t::name[];
+constexpr char GeckoHlsResourceWrapper::HlsResourceCallbacks::New_t::signature[];
+
+auto GeckoHlsResourceWrapper::HlsResourceCallbacks::New() -> HlsResourceCallbacks::LocalRef
+{
+ return mozilla::jni::Constructor<New_t>::Call(HlsResourceCallbacks::Context(), nullptr);
+}
+
+constexpr char GeckoHlsResourceWrapper::HlsResourceCallbacks::OnDataArrived_t::name[];
+constexpr char GeckoHlsResourceWrapper::HlsResourceCallbacks::OnDataArrived_t::signature[];
+
+constexpr char GeckoHlsResourceWrapper::HlsResourceCallbacks::OnError_t::name[];
+constexpr char GeckoHlsResourceWrapper::HlsResourceCallbacks::OnError_t::signature[];
+
const char GeckoHlsSample::name[] =
"org/mozilla/gecko/media/GeckoHlsSample";
constexpr char GeckoHlsSample::IsEOS_t::name[];
constexpr char GeckoHlsSample::IsEOS_t::signature[];
auto GeckoHlsSample::IsEOS() const -> bool
{
--- a/widget/android/GeneratedJNIWrappers.h
+++ b/widget/android/GeneratedJNIWrappers.h
@@ -5818,16 +5818,156 @@ public:
};
static const mozilla::jni::CallingThread callingThread =
mozilla::jni::CallingThread::ANY;
template<class Impl> class Natives;
};
+class GeckoHlsResourceWrapper : public mozilla::jni::ObjectBase<GeckoHlsResourceWrapper>
+{
+public:
+ static const char name[];
+
+ explicit GeckoHlsResourceWrapper(const Context& ctx) : ObjectBase<GeckoHlsResourceWrapper>(ctx) {}
+
+ class HlsResourceCallbacks;
+
+ struct GetPlayer_t {
+ typedef GeckoHlsResourceWrapper Owner;
+ typedef mozilla::jni::Object::LocalRef ReturnType;
+ typedef mozilla::jni::Object::Param SetterType;
+ typedef mozilla::jni::Args<> Args;
+ static constexpr char name[] = "GetPlayer";
+ static constexpr char signature[] =
+ "()Lorg/mozilla/gecko/media/GeckoHlsPlayer;";
+ static const bool isStatic = false;
+ static const mozilla::jni::ExceptionMode exceptionMode =
+ mozilla::jni::ExceptionMode::ABORT;
+ static const mozilla::jni::CallingThread callingThread =
+ mozilla::jni::CallingThread::GECKO;
+ static const mozilla::jni::DispatchTarget dispatchTarget =
+ mozilla::jni::DispatchTarget::CURRENT;
+ };
+
+ auto GetPlayer() const -> mozilla::jni::Object::LocalRef;
+
+ struct Create_t {
+ typedef GeckoHlsResourceWrapper Owner;
+ typedef GeckoHlsResourceWrapper::LocalRef ReturnType;
+ typedef GeckoHlsResourceWrapper::Param SetterType;
+ typedef mozilla::jni::Args<
+ mozilla::jni::String::Param,
+ mozilla::jni::Object::Param> Args;
+ static constexpr char name[] = "create";
+ static constexpr char signature[] =
+ "(Ljava/lang/String;Lorg/mozilla/gecko/media/GeckoHlsPlayer$ResourceCallbacks;)Lorg/mozilla/gecko/media/GeckoHlsResourceWrapper;";
+ static const bool isStatic = true;
+ static const mozilla::jni::ExceptionMode exceptionMode =
+ mozilla::jni::ExceptionMode::ABORT;
+ static const mozilla::jni::CallingThread callingThread =
+ mozilla::jni::CallingThread::GECKO;
+ static const mozilla::jni::DispatchTarget dispatchTarget =
+ mozilla::jni::DispatchTarget::CURRENT;
+ };
+
+ static auto Create(mozilla::jni::String::Param, mozilla::jni::Object::Param) -> GeckoHlsResourceWrapper::LocalRef;
+
+ struct Destroy_t {
+ typedef GeckoHlsResourceWrapper Owner;
+ typedef void ReturnType;
+ typedef void SetterType;
+ typedef mozilla::jni::Args<> Args;
+ static constexpr char name[] = "destroy";
+ static constexpr char signature[] =
+ "()V";
+ static const bool isStatic = false;
+ static const mozilla::jni::ExceptionMode exceptionMode =
+ mozilla::jni::ExceptionMode::ABORT;
+ static const mozilla::jni::CallingThread callingThread =
+ mozilla::jni::CallingThread::ANY;
+ static const mozilla::jni::DispatchTarget dispatchTarget =
+ mozilla::jni::DispatchTarget::CURRENT;
+ };
+
+ auto Destroy() const -> void;
+
+ static const mozilla::jni::CallingThread callingThread =
+ mozilla::jni::CallingThread::ANY;
+
+};
+
+class GeckoHlsResourceWrapper::HlsResourceCallbacks : public mozilla::jni::ObjectBase<HlsResourceCallbacks>
+{
+public:
+ static const char name[];
+
+ explicit HlsResourceCallbacks(const Context& ctx) : ObjectBase<HlsResourceCallbacks>(ctx) {}
+
+ struct New_t {
+ typedef HlsResourceCallbacks Owner;
+ typedef HlsResourceCallbacks::LocalRef ReturnType;
+ typedef HlsResourceCallbacks::Param SetterType;
+ typedef mozilla::jni::Args<> Args;
+ static constexpr char name[] = "<init>";
+ static constexpr char signature[] =
+ "()V";
+ static const bool isStatic = false;
+ static const mozilla::jni::ExceptionMode exceptionMode =
+ mozilla::jni::ExceptionMode::ABORT;
+ static const mozilla::jni::CallingThread callingThread =
+ mozilla::jni::CallingThread::GECKO;
+ static const mozilla::jni::DispatchTarget dispatchTarget =
+ mozilla::jni::DispatchTarget::CURRENT;
+ };
+
+ static auto New() -> HlsResourceCallbacks::LocalRef;
+
+ struct OnDataArrived_t {
+ typedef HlsResourceCallbacks Owner;
+ typedef void ReturnType;
+ typedef void SetterType;
+ typedef mozilla::jni::Args<> Args;
+ static constexpr char name[] = "onDataArrived";
+ static constexpr char signature[] =
+ "()V";
+ static const bool isStatic = false;
+ static const mozilla::jni::ExceptionMode exceptionMode =
+ mozilla::jni::ExceptionMode::ABORT;
+ static const mozilla::jni::CallingThread callingThread =
+ mozilla::jni::CallingThread::ANY;
+ static const mozilla::jni::DispatchTarget dispatchTarget =
+ mozilla::jni::DispatchTarget::GECKO;
+ };
+
+ struct OnError_t {
+ typedef HlsResourceCallbacks Owner;
+ typedef void ReturnType;
+ typedef void SetterType;
+ typedef mozilla::jni::Args<
+ int32_t> Args;
+ static constexpr char name[] = "onError";
+ static constexpr char signature[] =
+ "(I)V";
+ static const bool isStatic = false;
+ static const mozilla::jni::ExceptionMode exceptionMode =
+ mozilla::jni::ExceptionMode::ABORT;
+ static const mozilla::jni::CallingThread callingThread =
+ mozilla::jni::CallingThread::ANY;
+ static const mozilla::jni::DispatchTarget dispatchTarget =
+ mozilla::jni::DispatchTarget::GECKO;
+ };
+
+ static const mozilla::jni::CallingThread callingThread =
+ mozilla::jni::CallingThread::ANY;
+
+ template<class Impl> class Natives;
+};
+
class GeckoHlsSample : public mozilla::jni::ObjectBase<GeckoHlsSample>
{
public:
static const char name[];
explicit GeckoHlsSample(const Context& ctx) : ObjectBase<GeckoHlsSample>(ctx) {}
struct IsEOS_t {