Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b0fa4f2c authored by Andreas Huber's avatar Andreas Huber Committed by Android (Google) Code Review
Browse files

Merge "API Support for both synchronous and queued commands, optionally associated metadata."

parents 3b64772d ae9d5072
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
#include <media/IStreamSource.h>
#include <media/mediaplayer.h>
#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/foundation/AMessage.h>

#include <binder/IServiceManager.h>
#include <media/IMediaPlayerService.h>
@@ -56,7 +57,7 @@ void MyStreamSource::onBufferAvailable(size_t index) {

    ssize_t n = read(mFd, mem->pointer(), mem->size());
    if (n <= 0) {
        mListener->queueCommand(IStreamListener::EOS);
        mListener->issueCommand(IStreamListener::EOS, false /* synchronous */);
    } else {
        mListener->queueBuffer(index, n);
    }
+5 −3
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@

namespace android {

struct AMessage;
struct IMemory;
struct IStreamListener;

@@ -38,13 +39,14 @@ struct IStreamListener : public IInterface {
    DECLARE_META_INTERFACE(StreamListener);

    enum Command {
        FLUSH,
        EOS,
        DISCONTINUITY,
        EOS
    };

    virtual void queueBuffer(size_t index, size_t size) = 0;
    virtual void queueCommand(Command cmd) = 0;

    virtual void issueCommand(
            Command cmd, bool synchronous, const sp<AMessage> &msg = NULL) = 0;
};

////////////////////////////////////////////////////////////////////////////////
+4 −0
Original line number Diff line number Diff line
@@ -26,10 +26,14 @@
namespace android {

struct AString;
struct Parcel;

struct AMessage : public RefBase {
    AMessage(uint32_t what = 0, ALooper::handler_id target = 0);

    static sp<AMessage> FromParcel(const Parcel &parcel);
    void writeToParcel(Parcel *parcel) const;

    void setWhat(uint32_t what);
    uint32_t what() const;

+2 −1
Original line number Diff line number Diff line
@@ -36,7 +36,8 @@ LOCAL_SRC_FILES:= \
    fixedfft.cpp.arm

LOCAL_SHARED_LIBRARIES := \
	libui libcutils libutils libbinder libsonivox libicuuc libexpat libsurfaceflinger_client libcamera_client
	libui libcutils libutils libbinder libsonivox libicuuc libexpat \
        libsurfaceflinger_client libcamera_client libstagefright_foundation

LOCAL_MODULE:= libmedia

+23 −5
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#include <utils/Log.h>

#include <media/IStreamSource.h>
#include <media/stagefright/foundation/AMessage.h>

#include <binder/IMemory.h>
#include <binder/Parcel.h>
@@ -33,7 +34,7 @@ enum {

    // IStreamListener
    QUEUE_BUFFER,
    QUEUE_COMMAND,
    ISSUE_COMMAND,
};

struct BpStreamSource : public BpInterface<IStreamSource> {
@@ -125,12 +126,21 @@ struct BpStreamListener : public BpInterface<IStreamListener> {
        remote()->transact(QUEUE_BUFFER, data, &reply, IBinder::FLAG_ONEWAY);
    }

    virtual void queueCommand(Command cmd) {
    virtual void issueCommand(
            Command cmd, bool synchronous, const sp<AMessage> &msg) {
        Parcel data, reply;
        data.writeInterfaceToken(IStreamListener::getInterfaceDescriptor());
        data.writeInt32(static_cast<int32_t>(cmd));
        data.writeInt32(static_cast<int32_t>(synchronous));

        remote()->transact(QUEUE_COMMAND, data, &reply, IBinder::FLAG_ONEWAY);
        if (msg != NULL) {
            data.writeInt32(1);
            msg->writeToParcel(&data);
        } else {
            data.writeInt32(0);
        }

        remote()->transact(ISSUE_COMMAND, data, &reply, IBinder::FLAG_ONEWAY);
    }
};

@@ -149,12 +159,20 @@ status_t BnStreamListener::onTransact(
            break;
        }

        case QUEUE_COMMAND:
        case ISSUE_COMMAND:
        {
            CHECK_INTERFACE(IStreamListener, data, reply);
            Command cmd = static_cast<Command>(data.readInt32());

            queueCommand(cmd);
            bool synchronous = static_cast<bool>(data.readInt32());

            sp<AMessage> msg;

            if (data.readInt32()) {
                msg = AMessage::FromParcel(data);
            }

            issueCommand(cmd, synchronous, msg);
            break;
        }

Loading