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

Commit 82e1a5e9 authored by Phil Burk's avatar Phil Burk Committed by Android (Google) Code Review
Browse files

Merge "OboeAudioService: add thread to service for passing timestamps"

parents e82887b0 dec33abe
Loading
Loading
Loading
Loading
+15 −11
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include "SineGenerator.h"

#define NUM_SECONDS   10

#define SHARING_MODE  OBOE_SHARING_MODE_EXCLUSIVE
//#define SHARING_MODE  OBOE_SHARING_MODE_LEGACY

@@ -133,7 +134,9 @@ public:
    }

    oboe_result_t close() {
        if (mStream != OBOE_HANDLE_INVALID) {
            stop();
            printf("call OboeStream_close(0x%08x)\n", mStream);  fflush(stdout);
            OboeStream_close(mStream);
            mStream = OBOE_HANDLE_INVALID;
            OboeStreamBuilder_delete(mBuilder);
@@ -142,6 +145,7 @@ public:
            mOutputBuffer = nullptr;
            delete mConversionBuffer;
            mConversionBuffer = nullptr;
        }
        return OBOE_OK;
    }

@@ -274,9 +278,9 @@ int main(int argc, char **argv)
    printf("player.getFramesPerSecond() = %d\n", player.getFramesPerSecond());
    printf("player.getSamplesPerFrame() = %d\n", player.getSamplesPerFrame());
    myData.sineOsc1.setup(440.0, 48000);
    myData.sineOsc1.setSweep(300.0, 2000.0, 5.0);
    myData.sineOsc1.setSweep(300.0, 600.0, 5.0);
    myData.sineOsc2.setup(660.0, 48000);
    myData.sineOsc2.setSweep(400.0, 3000.0, 7.0);
    myData.sineOsc2.setSweep(350.0, 900.0, 7.0);
    myData.samplesPerFrame = player.getSamplesPerFrame();

    result = player.start();
+1 −1
Original line number Diff line number Diff line
@@ -154,7 +154,7 @@ OBOE_API oboe_result_t OboeStreamBuilder_getSamplesPerFrame(OboeStreamBuilder bu


/**
 * Request a sample data format, for example OBOE_AUDIO_FORMAT_PCM16.
 * Request a sample data format, for example OBOE_AUDIO_FORMAT_PCM_I16.
 * The application should query for the actual format after the stream is opened.
 *
 * @return OBOE_OK or a negative error.
+10 −4
Original line number Diff line number Diff line
@@ -67,12 +67,17 @@ enum oboe_direction_t {
enum oboe_audio_format_t {
    OBOE_AUDIO_FORMAT_INVALID = -1,
    OBOE_AUDIO_FORMAT_UNSPECIFIED = 0,
    OBOE_AUDIO_FORMAT_PCM16, // TODO rename to _PCM_I16
    OBOE_AUDIO_FORMAT_PCM_I16,
    OBOE_AUDIO_FORMAT_PCM_FLOAT,
    OBOE_AUDIO_FORMAT_PCM824, // TODO rename to _PCM_I8_24
    OBOE_AUDIO_FORMAT_PCM32  // TODO rename to _PCM_I32
    OBOE_AUDIO_FORMAT_PCM_I8_24,
    OBOE_AUDIO_FORMAT_PCM_I32
};

// TODO These are deprecated. Remove these aliases once all references are replaced.
#define OBOE_AUDIO_FORMAT_PCM16    OBOE_AUDIO_FORMAT_PCM_I16
#define OBOE_AUDIO_FORMAT_PCM824   OBOE_AUDIO_FORMAT_PCM_I8_24
#define OBOE_AUDIO_FORMAT_PCM32    OBOE_AUDIO_FORMAT_PCM_I32

enum {
    OBOE_OK,
    OBOE_ERROR_BASE = -900, // TODO review
@@ -93,7 +98,8 @@ enum {
    OBOE_ERROR_TIMEOUT,
    OBOE_ERROR_WOULD_BLOCK,
    OBOE_ERROR_INVALID_ORDER,
    OBOE_ERROR_OUT_OF_RANGE
    OBOE_ERROR_OUT_OF_RANGE,
    OBOE_ERROR_NO_SERVICE
};

typedef enum {
+16 −28
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include "binding/OboeStreamRequest.h"
#include "binding/OboeStreamConfiguration.h"
#include "binding/IOboeAudioService.h"
#include "utility/OboeUtilities.h"

namespace android {

@@ -44,7 +45,7 @@ public:
        request.writeToParcel(&data);
        status_t err = remote()->transact(OPEN_STREAM, data, &reply);
        if (err != NO_ERROR) {
            return OBOE_ERROR_INTERNAL; // TODO consider another error
            return OboeConvert_androidToOboeResult(err);
        }
        // parse reply
        oboe_handle_t stream;
@@ -53,14 +54,14 @@ public:
        return stream;
    }

    virtual oboe_result_t closeStream(int32_t streamHandle) override {
    virtual oboe_result_t closeStream(oboe_handle_t streamHandle) override {
        Parcel data, reply;
        // send command
        data.writeInterfaceToken(IOboeAudioService::getInterfaceDescriptor());
        data.writeInt32(streamHandle);
        status_t err = remote()->transact(CLOSE_STREAM, data, &reply);
        if (err != NO_ERROR) {
            return OBOE_ERROR_INTERNAL; // TODO consider another error
            return OboeConvert_androidToOboeResult(err);
        }
        // parse reply
        oboe_result_t res;
@@ -69,14 +70,14 @@ public:
    }

    virtual oboe_result_t getStreamDescription(oboe_handle_t streamHandle,
                                               AudioEndpointParcelable &parcelable)   {
                                               oboe::AudioEndpointParcelable &parcelable)   {
        Parcel data, reply;
        // send command
        data.writeInterfaceToken(IOboeAudioService::getInterfaceDescriptor());
        data.writeInt32(streamHandle);
        status_t err = remote()->transact(GET_STREAM_DESCRIPTION, data, &reply);
        if (err != NO_ERROR) {
            return OBOE_ERROR_INTERNAL; // TODO consider another error
            return OboeConvert_androidToOboeResult(err);
        }
        // parse reply
        parcelable.readFromParcel(&reply);
@@ -97,7 +98,7 @@ public:
        data.writeInt32(streamHandle);
        status_t err = remote()->transact(START_STREAM, data, &reply);
        if (err != NO_ERROR) {
            return OBOE_ERROR_INTERNAL; // TODO consider another error
            return OboeConvert_androidToOboeResult(err);
        }
        // parse reply
        oboe_result_t res;
@@ -112,7 +113,7 @@ public:
        data.writeInt32(streamHandle);
        status_t err = remote()->transact(PAUSE_STREAM, data, &reply);
        if (err != NO_ERROR) {
            return OBOE_ERROR_INTERNAL; // TODO consider another error
            return OboeConvert_androidToOboeResult(err);
        }
        // parse reply
        oboe_result_t res;
@@ -127,7 +128,7 @@ public:
        data.writeInt32(streamHandle);
        status_t err = remote()->transact(FLUSH_STREAM, data, &reply);
        if (err != NO_ERROR) {
            return OBOE_ERROR_INTERNAL; // TODO consider another error
            return OboeConvert_androidToOboeResult(err);
        }
        // parse reply
        oboe_result_t res;
@@ -135,13 +136,6 @@ public:
        return res;
    }

    virtual void tickle() override { // TODO remove after service thread implemented
        Parcel data;
        // send command
        data.writeInterfaceToken(IOboeAudioService::getInterfaceDescriptor());
        remote()->transact(TICKLE, data, nullptr);
    }

    virtual oboe_result_t registerAudioThread(oboe_handle_t streamHandle, pid_t clientThreadId,
                                              oboe_nanoseconds_t periodNanoseconds)
    override {
@@ -153,7 +147,7 @@ public:
        data.writeInt64(periodNanoseconds);
        status_t err = remote()->transact(REGISTER_AUDIO_THREAD, data, &reply);
        if (err != NO_ERROR) {
            return OBOE_ERROR_INTERNAL; // TODO consider another error
            return OboeConvert_androidToOboeResult(err);
        }
        // parse reply
        oboe_result_t res;
@@ -170,7 +164,7 @@ public:
        data.writeInt32((int32_t) clientThreadId);
        status_t err = remote()->transact(UNREGISTER_AUDIO_THREAD, data, &reply);
        if (err != NO_ERROR) {
            return OBOE_ERROR_INTERNAL; // TODO consider another error
            return OboeConvert_androidToOboeResult(err);
        }
        // parse reply
        oboe_result_t res;
@@ -189,8 +183,8 @@ IMPLEMENT_META_INTERFACE(OboeAudioService, "IOboeAudioService");
status_t BnOboeAudioService::onTransact(uint32_t code, const Parcel& data,
                                        Parcel* reply, uint32_t flags) {
    OboeStream stream;
    OboeStreamRequest request;
    OboeStreamConfiguration configuration;
    oboe::OboeStreamRequest request;
    oboe::OboeStreamConfiguration configuration;
    pid_t pid;
    oboe_nanoseconds_t nanoseconds;
    oboe_result_t result;
@@ -201,7 +195,7 @@ status_t BnOboeAudioService::onTransact(uint32_t code, const Parcel& data,
        case OPEN_STREAM: {
            request.readFromParcel(&data);
            stream = openStream(request, configuration);
            ALOGD("BnOboeAudioService::onTransact OPEN_STREAM 0x%08X", stream);
            ALOGD("BnOboeAudioService::onTransact OPEN_STREAM server handle = 0x%08X", stream);
            reply->writeInt32(stream);
            configuration.writeToParcel(reply);
            return NO_ERROR;
@@ -221,12 +215,12 @@ status_t BnOboeAudioService::onTransact(uint32_t code, const Parcel& data,
            oboe::AudioEndpointParcelable parcelable;
            result = getStreamDescription(stream, parcelable);
            if (result != OBOE_OK) {
                return -1; // FIXME
                return OboeConvert_oboeToAndroidStatus(result);
            }
            parcelable.dump();
            result = parcelable.validate();
            if (result != OBOE_OK) {
                return -1; // FIXME
                return OboeConvert_oboeToAndroidStatus(result);
            }
            parcelable.writeToParcel(reply);
            reply->writeInt32(result);
@@ -281,12 +275,6 @@ status_t BnOboeAudioService::onTransact(uint32_t code, const Parcel& data,
            return NO_ERROR;
        } break;

        case TICKLE: {
            ALOGV("BnOboeAudioService::onTransact TICKLE");
            tickle();
            return NO_ERROR;
        } break;

        default:
            // ALOGW("BnOboeAudioService::onTransact not handled %u", code);
            return BBinder::onTransact(code, data, reply, flags);
+4 −19
Original line number Diff line number Diff line
@@ -29,13 +29,6 @@
#include "binding/OboeStreamRequest.h"
#include "binding/OboeStreamConfiguration.h"

//using android::status_t;
//using android::IInterface;
//using android::BnInterface;

using oboe::AudioEndpointParcelable;
using oboe::OboeStreamRequest;
using oboe::OboeStreamConfiguration;

namespace android {

@@ -45,16 +38,16 @@ public:

    DECLARE_META_INTERFACE(OboeAudioService);

    virtual oboe_handle_t openStream(OboeStreamRequest &request,
                                     OboeStreamConfiguration &configuration) = 0;
    virtual oboe_handle_t openStream(oboe::OboeStreamRequest &request,
                                     oboe::OboeStreamConfiguration &configuration) = 0;

    virtual oboe_result_t closeStream(int32_t streamHandle) = 0;
    virtual oboe_result_t closeStream(oboe_handle_t streamHandle) = 0;

    /* Get an immutable description of the in-memory queues
    * used to communicate with the underlying HAL or Service.
    */
    virtual oboe_result_t getStreamDescription(oboe_handle_t streamHandle,
                                               AudioEndpointParcelable &parcelable) = 0;
                                               oboe::AudioEndpointParcelable &parcelable) = 0;

    /**
     * Start the flow of data.
@@ -79,14 +72,6 @@ public:

    virtual oboe_result_t unregisterAudioThread(oboe_handle_t streamHandle,
                                                pid_t clientThreadId) = 0;

    /**
     * Poke server instead of running a background thread.
     * Cooperative multi-tasking for early development only.
     * TODO remove tickle() when service has its own thread.
     */
    virtual void tickle() { };

};

class BnOboeAudioService : public BnInterface<IOboeAudioService> {
Loading