stagefright: abstract GraphicBufferSource to interfaces
Create two interfaces from GraphicBufferSource:
a) IGraphicBufferSource for client (ACodec) to configure the graphic
buffer source. IOMX no longer routes these messages and OMX internal
options are removed.
b) IOMXBufferSource for IOMX to send OMX specific callbacks.
Added an |origTimestamp| argument to emptyGraphicBuffer, and restore
the original PTS inside OMX to avoid going back to GraphicBufferSource
to patch the output PTS. In the longer term, we should consider moving
the max PTS gap entirely into OMX (probably as an extension index).
Define newly introduced interfaces using AIDL to facilitate code
development.
bug: 31399200
Change-Id: Ibaf6ca1a0737ba6ba9f83bedc3b06ef358db36cb
diff --git a/include/media/IOMX.h b/include/media/IOMX.h
index f971ee2..c0c48c1 100644
--- a/include/media/IOMX.h
+++ b/include/media/IOMX.h
@@ -34,11 +34,10 @@
namespace android {
+class IGraphicBufferSource;
class IMemory;
class IOMXObserver;
-class IOMXRenderer;
class NativeHandle;
-class Surface;
struct omx_message;
class IOMX : public IInterface {
@@ -129,6 +128,7 @@
virtual status_t createInputSurface(
node_id node, OMX_U32 port_index, android_dataspace dataSpace,
sp<IGraphicBufferProducer> *bufferProducer,
+ sp<IGraphicBufferSource> *bufferSource,
MetadataBufferType *type = NULL) = 0;
virtual status_t createPersistentInputSurface(
@@ -140,10 +140,9 @@
virtual status_t setInputSurface(
node_id node, OMX_U32 port_index,
const sp<IGraphicBufferConsumer> &bufferConsumer,
+ sp<IGraphicBufferSource> *bufferSource,
MetadataBufferType *type) = 0;
- virtual status_t signalEndOfInputStream(node_id node) = 0;
-
// Allocate an opaque buffer as a native handle. If component supports returning native
// handles, those are returned in *native_handle. Otherwise, the allocated buffer is
// returned in *buffer_data. This clearly only makes sense if the caller lives in the
@@ -180,34 +179,23 @@
OMX_U32 range_offset, OMX_U32 range_length,
OMX_U32 flags, OMX_TICKS timestamp, int fenceFd = -1) = 0;
+ // Calls OMX_EmptyBuffer on buffer (after updating buffer header with metadata of
+ // |graphicBuffer|, |flags| and |timestamp|). Passes |fenceFd| to component if it
+ // supports fences. Otherwise, it waits on |fenceFd| before calling OMX_EmptyBuffer.
+ // Takes ownership of |fenceFd| even if this call fails. If |origTimestamp| >= 0,
+ // timestamp on the filled buffer corresponding to this frame will be modified to
+ // |origTimestamp| after it's filled.
virtual status_t emptyGraphicBuffer(
node_id node,
buffer_id buffer,
- const sp<GraphicBuffer> &graphicBuffer,
- OMX_U32 flags, OMX_TICKS timestamp, int fenceFd) = 0;
+ const sp<GraphicBuffer> &graphicBuffer, OMX_U32 flags,
+ OMX_TICKS timestamp, OMX_TICKS origTimestamp, int fenceFd) = 0;
virtual status_t getExtensionIndex(
node_id node,
const char *parameter_name,
OMX_INDEXTYPE *index) = 0;
- enum InternalOptionType {
- INTERNAL_OPTION_SUSPEND, // data is a bool
- INTERNAL_OPTION_REPEAT_PREVIOUS_FRAME_DELAY, // data is an int64_t
- INTERNAL_OPTION_MAX_TIMESTAMP_GAP, // data is int64_t
- INTERNAL_OPTION_MAX_FPS, // data is float
- INTERNAL_OPTION_START_TIME, // data is an int64_t
- INTERNAL_OPTION_TIME_LAPSE, // data is an int64_t[2]
- INTERNAL_OPTION_COLOR_ASPECTS, // data is ColorAspects
- INTERNAL_OPTION_TIME_OFFSET, // data is an int64_t
- };
- virtual status_t setInternalOption(
- node_id node,
- OMX_U32 port_index,
- InternalOptionType type,
- const void *data,
- size_t size) = 0;
-
virtual status_t dispatchMessage(const omx_message &msg) = 0;
};
diff --git a/include/media/OMXFenceParcelable.h b/include/media/OMXFenceParcelable.h
new file mode 100644
index 0000000..c9da301
--- /dev/null
+++ b/include/media/OMXFenceParcelable.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _OMX_FENCE_PARCELABLE_
+#define _OMX_FENCE_PARCELABLE_
+
+#include <binder/Parcel.h>
+
+namespace android {
+
+struct OMXFenceParcelable : public Parcelable {
+ OMXFenceParcelable() : mFenceFd(-1) {}
+ OMXFenceParcelable(int fenceFd) : mFenceFd(fenceFd) {}
+
+ int get() const { return mFenceFd; }
+
+ status_t readFromParcel(const Parcel* parcel) override;
+ status_t writeToParcel(Parcel* parcel) const override;
+
+private:
+ // Disable copy ctor and operator=
+ OMXFenceParcelable(const OMXFenceParcelable &);
+ OMXFenceParcelable &operator=(const OMXFenceParcelable &);
+
+ int mFenceFd;
+};
+
+inline status_t OMXFenceParcelable::readFromParcel(const Parcel* parcel) {
+ int32_t haveFence;
+ status_t err = parcel->readInt32(&haveFence);
+ if (err == OK && haveFence) {
+ int fd = ::dup(parcel->readFileDescriptor());
+ if (fd < 0) {
+ return fd;
+ }
+ mFenceFd = fd;
+ }
+ return err;
+}
+
+inline status_t OMXFenceParcelable::writeToParcel(Parcel* parcel) const {
+ status_t err = parcel->writeInt32(mFenceFd >= 0);
+ if (err == OK && mFenceFd >= 0) {
+ err = parcel->writeFileDescriptor(mFenceFd, true /* takeOwnership */);
+ }
+ return err;
+}
+
+} // namespace android
+
+#endif // _OMX_FENCE_PARCELABLE_
diff --git a/include/media/stagefright/ACodec.h b/include/media/stagefright/ACodec.h
index 5a0913e..faf62ad 100644
--- a/include/media/stagefright/ACodec.h
+++ b/include/media/stagefright/ACodec.h
@@ -290,13 +290,12 @@
size_t mNumUndequeuedBuffers;
sp<DataConverter> mConverter[2];
+ sp<IGraphicBufferSource> mGraphicBufferSource;
int64_t mRepeatFrameDelayUs;
int64_t mMaxPtsGapUs;
float mMaxFps;
-
int64_t mTimePerFrameUs;
int64_t mTimePerCaptureUs;
-
bool mCreateInputBuffersSuspended;
bool mTunneled;