From f11902a7aaa3b45bfc9293237e9ebc6b65efd0b3 Mon Sep 17 00:00:00 2001
From: Michael Vines <mvines@codeaurora.org>
Date: Wed, 18 Mar 2015 15:05:55 -0700
Subject: [PATCH] Gecko patches for API level 22

Change-Id: I8e4b0d37f98a3f72bc90c1b64c106c0bb06ca4dc
---
 ...d-b2g-build-support-for-API-level-22.patch |  40 ++++
 ...DISCONTINUITY_TIME-as-_SEEK-is-gone-.patch |  27 +++
 .../0003-Bug-1144514-Whitelist-pread64.patch  |  35 +++
 ...5-ConsumerListener-interface-changes.patch | 209 ++++++++++++++++++
 4 files changed, 311 insertions(+)
 create mode 100644 patch/all/gecko/0001-Bug-1144512-Add-b2g-build-support-for-API-level-22.patch
 create mode 100644 patch/all/gecko/0002-Bug-1144513-Use-DISCONTINUITY_TIME-as-_SEEK-is-gone-.patch
 create mode 100644 patch/all/gecko/0003-Bug-1144514-Whitelist-pread64.patch
 create mode 100644 patch/all/gecko/0004-Bug-1144515-ConsumerListener-interface-changes.patch

diff --git a/patch/all/gecko/0001-Bug-1144512-Add-b2g-build-support-for-API-level-22.patch b/patch/all/gecko/0001-Bug-1144512-Add-b2g-build-support-for-API-level-22.patch
new file mode 100644
index 0000000..fff83a4
--- /dev/null
+++ b/patch/all/gecko/0001-Bug-1144512-Add-b2g-build-support-for-API-level-22.patch
@@ -0,0 +1,40 @@
+From a49c14cf336031e9a69f07a422cf19b906e61e58 Mon Sep 17 00:00:00 2001
+From: Michael Vines <mvines@codeaurora.org>
+Date: Wed, 18 Mar 2015 14:34:48 -0700
+Subject: [PATCH 1/4] Bug 1144512 - Add b2g build support for API level 22
+
+Change-Id: Ibd833ee7d74716d86d23a5b664a7e414211d18b7
+---
+ b2g/app/moz.build | 2 +-
+ configure.in      | 2 +-
+ 2 files changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/b2g/app/moz.build b/b2g/app/moz.build
+index c6736b3..1f95405 100644
+--- a/b2g/app/moz.build
++++ b/b2g/app/moz.build
+@@ -58,7 +58,7 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
+         'cutils',
+     ]
+     OS_LIBS += CONFIG['MOZ_ZLIB_LIBS']
+-    if CONFIG['ANDROID_VERSION'] in ('17', '18', '19', '21'):
++    if CONFIG['ANDROID_VERSION'] in ('17', '18', '19', '21', '22'):
+         OS_LIBS += [
+             'gui',
+             'suspend',
+diff --git a/configure.in b/configure.in
+index 72bff25..2250f4b 100644
+--- a/configure.in
++++ b/configure.in
+@@ -286,7 +286,7 @@ if test -n "$gonkdir" ; then
+         AC_DEFINE(MOZ_AUDIO_OFFLOAD)
+         MOZ_FMP4=1
+         ;;
+-    21)
++    21|22)
+         GONK_INCLUDES="-I$gonkdir/frameworks/native/include -I$gonkdir/frameworks/av/include -I$gonkdir/frameworks/av/include/media -I$gonkdir/frameworks/av/include/camera -I$gonkdir/frameworks/native/include/media/openmax -I$gonkdir/frameworks/av/media/libstagefright/include"
+         MOZ_AUDIO_OFFLOAD=1
+         MOZ_OMX_DECODER=1
+-- 
+1.8.2.1
+
diff --git a/patch/all/gecko/0002-Bug-1144513-Use-DISCONTINUITY_TIME-as-_SEEK-is-gone-.patch b/patch/all/gecko/0002-Bug-1144513-Use-DISCONTINUITY_TIME-as-_SEEK-is-gone-.patch
new file mode 100644
index 0000000..f58050d
--- /dev/null
+++ b/patch/all/gecko/0002-Bug-1144513-Use-DISCONTINUITY_TIME-as-_SEEK-is-gone-.patch
@@ -0,0 +1,27 @@
+From f2957b0235cdc626a5984e7d1b9881c0ddde9d2d Mon Sep 17 00:00:00 2001
+From: Michael Vines <mvines@codeaurora.org>
+Date: Wed, 18 Mar 2015 14:41:11 -0700
+Subject: [PATCH 2/4] Bug 1144513 - Use DISCONTINUITY_TIME as _SEEK is gone
+ from API level 22
+
+Change-Id: I10619bfdae49766e3dedd16f8e179f8d41f2fb19
+---
+ netwerk/protocol/rtsp/rtsp/RTSPSource.cpp | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/netwerk/protocol/rtsp/rtsp/RTSPSource.cpp b/netwerk/protocol/rtsp/rtsp/RTSPSource.cpp
+index 315aec9..0649f58 100644
+--- a/netwerk/protocol/rtsp/rtsp/RTSPSource.cpp
++++ b/netwerk/protocol/rtsp/rtsp/RTSPSource.cpp
+@@ -494,7 +494,7 @@ void RTSPSource::onMessageReceived(const sp<AMessage> &msg) {
+             sp<AnotherPacketSource> source = info->mSource;
+             if (source != NULL) {
+ #if ANDROID_VERSION >= 21
+-                source->queueDiscontinuity(ATSParser::DISCONTINUITY_SEEK, NULL,
++                source->queueDiscontinuity(ATSParser::DISCONTINUITY_TIME, NULL,
+                                            true /* discard */);
+ #else
+                 source->queueDiscontinuity(ATSParser::DISCONTINUITY_SEEK, NULL);
+-- 
+1.8.2.1
+
diff --git a/patch/all/gecko/0003-Bug-1144514-Whitelist-pread64.patch b/patch/all/gecko/0003-Bug-1144514-Whitelist-pread64.patch
new file mode 100644
index 0000000..7faa46f
--- /dev/null
+++ b/patch/all/gecko/0003-Bug-1144514-Whitelist-pread64.patch
@@ -0,0 +1,35 @@
+From a5dc50e9229ea93a692f146a112fa5c717d8f077 Mon Sep 17 00:00:00 2001
+From: Michael Vines <mvines@codeaurora.org>
+Date: Wed, 18 Mar 2015 15:02:19 -0700
+Subject: [PATCH 3/4] Bug 1144514 - Whitelist pread64
+
+Change-Id: I445e6988981ead54f34d4c44322954b49662aafe
+---
+ security/sandbox/linux/SandboxFilter.cpp | 4 +++-
+ 1 file changed, 3 insertions(+), 1 deletion(-)
+
+diff --git a/security/sandbox/linux/SandboxFilter.cpp b/security/sandbox/linux/SandboxFilter.cpp
+index db4fa75..39d24e3 100644
+--- a/security/sandbox/linux/SandboxFilter.cpp
++++ b/security/sandbox/linux/SandboxFilter.cpp
+@@ -145,6 +145,9 @@ SandboxFilterImplContent::Build() {
+ #if SYSCALL_EXISTS(ftruncate64)
+   Allow(SYSCALL(ftruncate64));
+ #endif
++#if SYSCALL_EXISTS(pread64)
++  Allow(SYSCALL(pread64));
++#endif
+ 
+   /* ioctl() is for GL. Remove when GL proxy is implemented.
+    * Additionally ioctl() might be a place where we want to have
+@@ -286,7 +289,6 @@ SandboxFilterImplContent::Build() {
+   Allow(SYSCALL(mkdir));
+   Allow(SYSCALL(getcwd));
+   Allow(SYSCALL(readahead));
+-  Allow(SYSCALL(pread64));
+   Allow(SYSCALL(statfs));
+ #if SYSCALL_EXISTS(ugetrlimit)
+   Allow(SYSCALL(ugetrlimit));
+-- 
+1.8.2.1
+
diff --git a/patch/all/gecko/0004-Bug-1144515-ConsumerListener-interface-changes.patch b/patch/all/gecko/0004-Bug-1144515-ConsumerListener-interface-changes.patch
new file mode 100644
index 0000000..4e45dff
--- /dev/null
+++ b/patch/all/gecko/0004-Bug-1144515-ConsumerListener-interface-changes.patch
@@ -0,0 +1,209 @@
+From ae4139a7b5dfb0b0326c84070e52fa58e43a54fe Mon Sep 17 00:00:00 2001
+From: Michael Vines <mvines@codeaurora.org>
+Date: Wed, 18 Mar 2015 15:03:15 -0700
+Subject: [PATCH] Bug 1144515 - ConsumerListener interface changes
+
+Change-Id: I3a3e4d6f58a42576197356ba4b7301c670298c74
+---
+ widget/gonk/libdisplay/FramebufferSurface.cpp            |  4 ++++
+ widget/gonk/libdisplay/FramebufferSurface.h              |  4 ++++
+ .../nativewindow/GonkBufferQueueLL/GonkBufferQueueLL.cpp | 16 ++++++++++++++++
+ .../nativewindow/GonkBufferQueueLL/GonkBufferQueueLL.h   |  5 +++++
+ .../GonkBufferQueueLL/GonkBufferQueueProducer.cpp        |  9 ++++++++-
+ widget/gonk/nativewindow/GonkConsumerBaseLL.cpp          |  4 ++++
+ widget/gonk/nativewindow/GonkConsumerBaseLL.h            |  5 +++++
+ widget/gonk/nativewindow/GonkNativeWindowLL.cpp          |  5 +++++
+ widget/gonk/nativewindow/GonkNativeWindowLL.h            |  4 ++++
+ 9 files changed, 55 insertions(+), 1 deletion(-)
+
+diff --git a/widget/gonk/libdisplay/FramebufferSurface.cpp b/widget/gonk/libdisplay/FramebufferSurface.cpp
+index 32d0907..3282448 100644
+--- a/widget/gonk/libdisplay/FramebufferSurface.cpp
++++ b/widget/gonk/libdisplay/FramebufferSurface.cpp
+@@ -129,7 +129,11 @@ status_t FramebufferSurface::nextBuffer(sp<GraphicBuffer>& outBuffer, sp<Fence>&
+ }
+ 
+ // Overrides ConsumerBase::onFrameAvailable(), does not call base class impl.
++#if ANDROID_VERSION >= 22
++void FramebufferSurface::onFrameAvailable(const ::android::BufferItem &item) {
++#else
+ void FramebufferSurface::onFrameAvailable() {
++#endif
+     sp<GraphicBuffer> buf;
+     sp<Fence> acquireFence;
+     status_t err = nextBuffer(buf, acquireFence);
+diff --git a/widget/gonk/libdisplay/FramebufferSurface.h b/widget/gonk/libdisplay/FramebufferSurface.h
+index 1528c6e..0e4c2aa 100644
+--- a/widget/gonk/libdisplay/FramebufferSurface.h
++++ b/widget/gonk/libdisplay/FramebufferSurface.h
+@@ -63,7 +63,11 @@ public:
+ private:
+     virtual ~FramebufferSurface() { }; // this class cannot be overloaded
+ 
++#if ANDROID_VERSION >= 22
++    virtual void onFrameAvailable(const ::android::BufferItem &item);
++#else
+     virtual void onFrameAvailable();
++#endif
+     virtual void freeBufferLocked(int slotIndex);
+ 
+     // nextBuffer waits for and then latches the next buffer from the
+diff --git a/widget/gonk/nativewindow/GonkBufferQueueLL/GonkBufferQueueLL.cpp b/widget/gonk/nativewindow/GonkBufferQueueLL/GonkBufferQueueLL.cpp
+index 1056c3b..649d06b 100644
+--- a/widget/gonk/nativewindow/GonkBufferQueueLL/GonkBufferQueueLL.cpp
++++ b/widget/gonk/nativewindow/GonkBufferQueueLL/GonkBufferQueueLL.cpp
+@@ -32,12 +32,28 @@ GonkBufferQueue::ProxyConsumerListener::ProxyConsumerListener(
+ 
+ GonkBufferQueue::ProxyConsumerListener::~ProxyConsumerListener() {}
+ 
++#if ANDROID_VERSION == 21
+ void GonkBufferQueue::ProxyConsumerListener::onFrameAvailable() {
+     sp<ConsumerListener> listener(mConsumerListener.promote());
+     if (listener != NULL) {
+         listener->onFrameAvailable();
+     }
+ }
++#else
++void GonkBufferQueue::ProxyConsumerListener::onFrameAvailable(const ::android::BufferItem& item) {
++    sp<ConsumerListener> listener(mConsumerListener.promote());
++    if (listener != NULL) {
++        listener->onFrameAvailable(item);
++    }
++}
++
++void GonkBufferQueue::ProxyConsumerListener::onFrameReplaced(const ::android::BufferItem& item) {
++    sp<ConsumerListener> listener(mConsumerListener.promote());
++    if (listener != NULL) {
++        listener->onFrameReplaced(item);
++    }
++}
++#endif
+ 
+ void GonkBufferQueue::ProxyConsumerListener::onBuffersReleased() {
+     sp<ConsumerListener> listener(mConsumerListener.promote());
+diff --git a/widget/gonk/nativewindow/GonkBufferQueueLL/GonkBufferQueueLL.h b/widget/gonk/nativewindow/GonkBufferQueueLL/GonkBufferQueueLL.h
+index 9fb740a..b1b4e06 100644
+--- a/widget/gonk/nativewindow/GonkBufferQueueLL/GonkBufferQueueLL.h
++++ b/widget/gonk/nativewindow/GonkBufferQueueLL/GonkBufferQueueLL.h
+@@ -63,7 +63,12 @@ public:
+     public:
+         ProxyConsumerListener(const wp<ConsumerListener>& consumerListener);
+         virtual ~ProxyConsumerListener();
++#if ANDROID_VERSION == 21
+         virtual void onFrameAvailable();
++#else
++        virtual void onFrameAvailable(const ::android::BufferItem& item);
++        virtual void onFrameReplaced(const ::android::BufferItem& item);
++#endif
+         virtual void onBuffersReleased();
+         virtual void onSidebandStreamChanged();
+     private:
+diff --git a/widget/gonk/nativewindow/GonkBufferQueueLL/GonkBufferQueueProducer.cpp b/widget/gonk/nativewindow/GonkBufferQueueLL/GonkBufferQueueProducer.cpp
+index 5d3bbed..3340c97 100644
+--- a/widget/gonk/nativewindow/GonkBufferQueueLL/GonkBufferQueueProducer.cpp
++++ b/widget/gonk/nativewindow/GonkBufferQueueLL/GonkBufferQueueProducer.cpp
+@@ -537,6 +537,7 @@ status_t GonkBufferQueueProducer::queueBuffer(int slot,
+             return BAD_VALUE;
+     }
+ 
++    GonkBufferItem item;
+     sp<IConsumerListener> listener;
+     { // Autolock scope
+         Mutex::Autolock lock(mCore->mMutex);
+@@ -593,7 +594,6 @@ status_t GonkBufferQueueProducer::queueBuffer(int slot,
+         ++mCore->mFrameCounter;
+         mSlots[slot].mFrameNumber = mCore->mFrameCounter;
+ 
+-        GonkBufferItem item;
+         item.mAcquireCalled = mSlots[slot].mAcquireCalled;
+         item.mGraphicBuffer = mSlots[slot].mGraphicBuffer;
+         item.mCrop = crop;
+@@ -641,11 +641,18 @@ status_t GonkBufferQueueProducer::queueBuffer(int slot,
+ 
+         output->inflate(mCore->mDefaultWidth, mCore->mDefaultHeight,
+                 mCore->mTransformHint, mCore->mQueue.size());
++
++        item.mGraphicBuffer.clear();
++        item.mSlot = GonkBufferItem::INVALID_BUFFER_SLOT;
+     } // Autolock scope
+ 
+     // Call back without lock held
+     if (listener != NULL) {
++#if ANDROID_VERSION == 21
+         listener->onFrameAvailable();
++#else
++        listener->onFrameAvailable(reinterpret_cast<::android::BufferItem&>(item));
++#endif
+     }
+ 
+     return NO_ERROR;
+diff --git a/widget/gonk/nativewindow/GonkConsumerBaseLL.cpp b/widget/gonk/nativewindow/GonkConsumerBaseLL.cpp
+index 8444665..36e4a83 100644
+--- a/widget/gonk/nativewindow/GonkConsumerBaseLL.cpp
++++ b/widget/gonk/nativewindow/GonkConsumerBaseLL.cpp
+@@ -85,7 +85,11 @@ void GonkConsumerBase::freeBufferLocked(int slotIndex) {
+     mSlots[slotIndex].mFrameNumber = 0;
+ }
+ 
++#if ANDROID_VERSION == 21
+ void GonkConsumerBase::onFrameAvailable() {
++#else
++void GonkConsumerBase::onFrameAvailable(const ::android::BufferItem& item) {
++#endif
+     ALOGV("onFrameAvailable");
+ 
+     sp<FrameAvailableListener> listener;
+diff --git a/widget/gonk/nativewindow/GonkConsumerBaseLL.h b/widget/gonk/nativewindow/GonkConsumerBaseLL.h
+index ba7b6c3..0b2c2d1 100644
+--- a/widget/gonk/nativewindow/GonkConsumerBaseLL.h
++++ b/widget/gonk/nativewindow/GonkConsumerBaseLL.h
+@@ -107,7 +107,12 @@ protected:
+     // the GonkConsumerBase implementation must be called from the derived class.
+     // The GonkConsumerBase version of onSidebandStreamChanged does nothing and can
+     // be overriden by derived classes if they want the notification.
++#if ANDROID_VERSION == 21
+     virtual void onFrameAvailable();
++#else
++    virtual void onFrameAvailable(const ::android::BufferItem& item);
++    virtual void onFrameReplaced(const ::android::BufferItem& item) {};
++#endif
+     virtual void onBuffersReleased();
+     virtual void onSidebandStreamChanged();
+ 
+diff --git a/widget/gonk/nativewindow/GonkNativeWindowLL.cpp b/widget/gonk/nativewindow/GonkNativeWindowLL.cpp
+index ee939ce..0cccc9d 100644
+--- a/widget/gonk/nativewindow/GonkNativeWindowLL.cpp
++++ b/widget/gonk/nativewindow/GonkNativeWindowLL.cpp
+@@ -188,8 +188,13 @@ void GonkNativeWindow::setNewFrameCallback(
+     mNewFrameCallback = callback;
+ }
+ 
++#if ANDROID_VERSION == 21
+ void GonkNativeWindow::onFrameAvailable() {
+     GonkConsumerBase::onFrameAvailable();
++#else
++void GonkNativeWindow::onFrameAvailable(const ::android::BufferItem &item) {
++    GonkConsumerBase::onFrameAvailable(item);
++#endif
+ 
+     if (mNewFrameCallback) {
+         mNewFrameCallback->OnNewFrame();
+diff --git a/widget/gonk/nativewindow/GonkNativeWindowLL.h b/widget/gonk/nativewindow/GonkNativeWindowLL.h
+index a257cc5..1a9b210 100644
+--- a/widget/gonk/nativewindow/GonkNativeWindowLL.h
++++ b/widget/gonk/nativewindow/GonkNativeWindowLL.h
+@@ -118,7 +118,11 @@ class GonkNativeWindow: public GonkConsumerBase
+     static void RecycleCallback(TextureClient* client, void* closure);
+ 
+ protected:
++#if ANDROID_VERSION == 21
+     virtual void onFrameAvailable();
++#else
++    virtual void onFrameAvailable(const ::android::BufferItem &item);
++#endif
+ 
+ private:
+     GonkNativeWindowNewFrameCallback* mNewFrameCallback;
+-- 
+1.8.2.1
+
-- 
GitLab