Bug 1265755 - separate JavaCallbacksSupport class declaration to a different header file; r?jolin
MozReview-Commit-ID: 7Vj3G47n2bu
new file mode 100644
--- /dev/null
+++ b/dom/media/platforms/android/JavaCallbacksSupport.h
@@ -0,0 +1,76 @@
+/* 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/. */
+
+#ifndef JavaCallbacksSupport_h_
+#define JavaCallbacksSupport_h_
+
+#include "FennecJNINatives.h"
+#include "MediaResult.h"
+#include "MediaCodec.h"
+
+namespace mozilla {
+
+class JavaCallbacksSupport
+ : public java::CodecProxy::NativeCallbacks::Natives<JavaCallbacksSupport>
+{
+public:
+ typedef java::CodecProxy::NativeCallbacks::Natives<JavaCallbacksSupport> Base;
+ using Base::AttachNative;
+ using Base::DisposeNative;
+
+ JavaCallbacksSupport() : mCanceled(false) { }
+
+ virtual ~JavaCallbacksSupport() { }
+
+ virtual void HandleInputExhausted() = 0;
+
+ void OnInputExhausted()
+ {
+ if (!mCanceled) {
+ HandleInputExhausted();
+ }
+ }
+
+ virtual void HandleOutput(java::Sample::Param aSample) = 0;
+
+ void OnOutput(jni::Object::Param aSample)
+ {
+ if (!mCanceled) {
+ HandleOutput(java::Sample::Ref::From(aSample));
+ }
+ }
+
+ virtual void HandleOutputFormatChanged(java::sdk::MediaFormat::Param aFormat) { };
+
+ void OnOutputFormatChanged(jni::Object::Param aFormat)
+ {
+ if (!mCanceled) {
+ HandleOutputFormatChanged(java::sdk::MediaFormat::Ref::From(aFormat));
+ }
+ }
+
+ virtual void HandleError(const MediaResult& aError) = 0;
+
+ void OnError(bool aIsFatal)
+ {
+ if (!mCanceled) {
+ HandleError(
+ aIsFatal
+ ? MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR, __func__)
+ : MediaResult(NS_ERROR_DOM_MEDIA_DECODE_ERR, __func__));
+ }
+ }
+
+ void Cancel()
+ {
+ mCanceled = true;
+ }
+
+private:
+ Atomic<bool> mCanceled;
+};
+
+} // namespace mozilla
+
+#endif
--- a/dom/media/platforms/android/RemoteDataDecoder.cpp
+++ b/dom/media/platforms/android/RemoteDataDecoder.cpp
@@ -1,17 +1,17 @@
/* 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/. */
#include "AndroidBridge.h"
#include "AndroidDecoderModule.h"
#include "AndroidSurfaceTexture.h"
+#include "JavaCallbacksSupport.h"
#include "SimpleMap.h"
-#include "FennecJNINatives.h"
#include "GLImages.h"
#include "MediaData.h"
#include "MediaInfo.h"
#include "VideoUtils.h"
#include "VPXDecoder.h"
#include "nsIGfxInfo.h"
#include "nsPromiseFlatString.h"
@@ -28,80 +28,16 @@
using namespace mozilla;
using namespace mozilla::gl;
using namespace mozilla::java;
using namespace mozilla::java::sdk;
using media::TimeUnit;
namespace mozilla {
-class JavaCallbacksSupport
- : public CodecProxy::NativeCallbacks::Natives<JavaCallbacksSupport>
-{
-public:
- typedef CodecProxy::NativeCallbacks::Natives<JavaCallbacksSupport> Base;
- using Base::AttachNative;
-
- JavaCallbacksSupport() : mCanceled(false) { }
-
- virtual ~JavaCallbacksSupport() { }
-
- virtual void HandleInputExhausted() = 0;
-
- void OnInputExhausted()
- {
- if (!mCanceled) {
- HandleInputExhausted();
- }
- }
-
- virtual void HandleOutput(Sample::Param aSample) = 0;
-
- void OnOutput(jni::Object::Param aSample)
- {
- if (!mCanceled) {
- HandleOutput(Sample::Ref::From(aSample));
- }
- }
-
- virtual void HandleOutputFormatChanged(MediaFormat::Param aFormat) { };
-
- void OnOutputFormatChanged(jni::Object::Param aFormat)
- {
- if (!mCanceled) {
- HandleOutputFormatChanged(MediaFormat::Ref::From(aFormat));
- }
- }
-
- virtual void HandleError(const MediaResult& aError) = 0;
-
- void OnError(bool aIsFatal)
- {
- if (!mCanceled) {
- HandleError(
- aIsFatal
- ? MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR, __func__)
- : MediaResult(NS_ERROR_DOM_MEDIA_DECODE_ERR, __func__));
- }
- }
-
- void DisposeNative()
- {
- // TODO
- }
-
- void Cancel()
- {
- mCanceled = true;
- }
-
-private:
- Atomic<bool> mCanceled;
-};
-
class RemoteVideoDecoder : public RemoteDataDecoder
{
public:
// Hold an output buffer and render it to the surface when the frame is sent
// to compositor, or release it if not presented.
class RenderOrReleaseOutput : public VideoData::Listener
{
public:
@@ -563,16 +499,17 @@ RemoteDataDecoder::ProcessShutdown()
mShutdown = true;
if (mJavaDecoder) {
mJavaDecoder->Release();
mJavaDecoder = nullptr;
}
if (mJavaCallbacks) {
JavaCallbacksSupport::GetNative(mJavaCallbacks)->Cancel();
+ JavaCallbacksSupport::DisposeNative(mJavaCallbacks);
mJavaCallbacks = nullptr;
}
mFormat = nullptr;
return ShutdownPromise::CreateAndResolve(true, __func__);
}
--- a/dom/media/platforms/moz.build
+++ b/dom/media/platforms/moz.build
@@ -75,16 +75,17 @@ if CONFIG['MOZ_APPLEMEDIA']:
'-framework AudioToolbox',
]
include('/ipc/chromium/chromium-config.mozbuild')
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
EXPORTS += [
'android/AndroidDecoderModule.h',
+ 'android/JavaCallbacksSupport.h',
]
UNIFIED_SOURCES += [
'android/AndroidDecoderModule.cpp',
'android/RemoteDataDecoder.cpp',
]
FINAL_LIBRARY = 'xul'
--- a/mobile/android/base/java/org/mozilla/gecko/media/CodecProxy.java
+++ b/mobile/android/base/java/org/mozilla/gecko/media/CodecProxy.java
@@ -43,17 +43,19 @@ public final class CodecProxy {
@WrapForJNI
public static class NativeCallbacks extends JNIObject implements Callbacks {
public native void onInputExhausted();
public native void onOutputFormatChanged(MediaFormat format);
public native void onOutput(Sample output);
public native void onError(boolean fatal);
@Override // JNIObject
- protected native void disposeNative();
+ protected void disposeNative() {
+ throw new UnsupportedOperationException();
+ }
}
private class CallbacksForwarder extends ICodecCallbacks.Stub {
private final Callbacks mCallbacks;
private boolean mEndOfInput;
CallbacksForwarder(Callbacks callbacks) {
mCallbacks = callbacks;
--- a/widget/android/fennec/FennecJNINatives.h
+++ b/widget/android/fennec/FennecJNINatives.h
@@ -149,26 +149,22 @@ const JNINativeMethod ZoomedView::Native
mozilla::jni::NativeStub<ZoomedView::RequestZoomedViewData_t, Impl>
::template Wrap<&Impl::RequestZoomedViewData>)
};
template<class Impl>
class CodecProxy::NativeCallbacks::Natives : public mozilla::jni::NativeImpl<NativeCallbacks, Impl>
{
public:
- static const JNINativeMethod methods[5];
+ static const JNINativeMethod methods[4];
};
template<class Impl>
const JNINativeMethod CodecProxy::NativeCallbacks::Natives<Impl>::methods[] = {
- mozilla::jni::MakeNativeMethod<CodecProxy::NativeCallbacks::DisposeNative_t>(
- mozilla::jni::NativeStub<CodecProxy::NativeCallbacks::DisposeNative_t, Impl>
- ::template Wrap<&Impl::DisposeNative>),
-
mozilla::jni::MakeNativeMethod<CodecProxy::NativeCallbacks::OnError_t>(
mozilla::jni::NativeStub<CodecProxy::NativeCallbacks::OnError_t, Impl>
::template Wrap<&Impl::OnError>),
mozilla::jni::MakeNativeMethod<CodecProxy::NativeCallbacks::OnInputExhausted_t>(
mozilla::jni::NativeStub<CodecProxy::NativeCallbacks::OnInputExhausted_t, Impl>
::template Wrap<&Impl::OnInputExhausted>),
--- a/widget/android/fennec/FennecJNIWrappers.cpp
+++ b/widget/android/fennec/FennecJNIWrappers.cpp
@@ -238,16 +238,21 @@ constexpr char CodecProxy::NativeCallbac
auto CodecProxy::NativeCallbacks::New() -> NativeCallbacks::LocalRef
{
return mozilla::jni::Constructor<New_t>::Call(NativeCallbacks::Context(), nullptr);
}
constexpr char CodecProxy::NativeCallbacks::DisposeNative_t::name[];
constexpr char CodecProxy::NativeCallbacks::DisposeNative_t::signature[];
+auto CodecProxy::NativeCallbacks::DisposeNative() const -> void
+{
+ return mozilla::jni::Method<DisposeNative_t>::Call(NativeCallbacks::mCtx, nullptr);
+}
+
constexpr char CodecProxy::NativeCallbacks::OnError_t::name[];
constexpr char CodecProxy::NativeCallbacks::OnError_t::signature[];
constexpr char CodecProxy::NativeCallbacks::OnInputExhausted_t::name[];
constexpr char CodecProxy::NativeCallbacks::OnInputExhausted_t::signature[];
constexpr char CodecProxy::NativeCallbacks::OnOutput_t::name[];
constexpr char CodecProxy::NativeCallbacks::OnOutput_t::signature[];
--- a/widget/android/fennec/FennecJNIWrappers.h
+++ b/widget/android/fennec/FennecJNIWrappers.h
@@ -829,16 +829,18 @@ public:
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 DisposeNative() const -> void;
+
struct OnError_t {
typedef NativeCallbacks Owner;
typedef void ReturnType;
typedef void SetterType;
typedef mozilla::jni::Args<
bool> Args;
static constexpr char name[] = "onError";
static constexpr char signature[] =