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

Commit 43f77e93 authored by Mikhail Naganov's avatar Mikhail Naganov Committed by Automerger Merge Worker
Browse files

audio: Implementation of audio I/O, part II am: 4f5d3f12 am: 4af7cb62

parents 231ca12c 4af7cb62
Loading
Loading
Loading
Loading
+1 −5
Original line number Original line Diff line number Diff line
@@ -38,11 +38,7 @@ parcelable StreamDescriptor {
  android.hardware.common.fmq.MQDescriptor<android.hardware.audio.core.StreamDescriptor.Reply,android.hardware.common.fmq.SynchronizedReadWrite> reply;
  android.hardware.common.fmq.MQDescriptor<android.hardware.audio.core.StreamDescriptor.Reply,android.hardware.common.fmq.SynchronizedReadWrite> reply;
  long bufferSizeFrames;
  long bufferSizeFrames;
  android.hardware.audio.core.StreamDescriptor.AudioBuffer audio;
  android.hardware.audio.core.StreamDescriptor.AudioBuffer audio;
  const int COMMAND_EXIT = 0;
  const int COMMAND_BURST = 1;
  const int COMMAND_BURST = 1;
  const int STATUS_OK = 0;
  const int STATUS_ILLEGAL_ARGUMENT = 1;
  const int STATUS_ILLEGAL_STATE = 2;
  @FixedSize @VintfStability
  @FixedSize @VintfStability
  parcelable Position {
  parcelable Position {
    long frames;
    long frames;
@@ -63,7 +59,7 @@ parcelable StreamDescriptor {
  }
  }
  @VintfStability
  @VintfStability
  union AudioBuffer {
  union AudioBuffer {
    android.hardware.common.fmq.MQDescriptor<byte,android.hardware.common.fmq.UnsynchronizedWrite> fmq;
    android.hardware.common.fmq.MQDescriptor<byte,android.hardware.common.fmq.SynchronizedReadWrite> fmq;
    android.hardware.audio.core.MmapBufferDescriptor mmap;
    android.hardware.audio.core.MmapBufferDescriptor mmap;
  }
  }
}
}
+18 −8
Original line number Original line Diff line number Diff line
@@ -255,12 +255,16 @@ interface IModule {
     *
     *
     * Note that although it's not prohibited to open a stream on a mix port
     * Note that although it's not prohibited to open a stream on a mix port
     * configuration which is not connected (using a patch) to any device port,
     * configuration which is not connected (using a patch) to any device port,
     * and set up a patch afterwards, this is not the recommended sequence of
     * and set up a patch afterwards, this sequence of calls is not recommended,
     * calls, because setting up of a patch might fail due to an insufficient
     * because setting up of a patch might fail due to an insufficient stream
     * stream buffer size.
     * buffer size. Another consequence of having a stream on an unconnected mix
     * port is that capture positions can not be determined because there is no
     * "external observer," thus read operations done via StreamDescriptor will
     * be completing with an error, although data (zero filled) will still be
     * provided.
     *
     *
     * @return An opened input stream and the associated descriptor.
     * @return An opened input stream and the associated descriptor.
     * @param args Input arguments, see 'OpenInputStreamArguments' parcelable.
     * @param args The pack of arguments, see 'OpenInputStreamArguments' parcelable.
     * @throws EX_ILLEGAL_ARGUMENT In the following cases:
     * @throws EX_ILLEGAL_ARGUMENT In the following cases:
     *                             - If the port config can not be found by the ID.
     *                             - If the port config can not be found by the ID.
     *                             - If the port config is not of an input mix port.
     *                             - If the port config is not of an input mix port.
@@ -269,6 +273,7 @@ interface IModule {
     *                          - If the port config already has a stream opened on it.
     *                          - If the port config already has a stream opened on it.
     *                          - If the limit on the open stream count for the port has
     *                          - If the limit on the open stream count for the port has
     *                            been reached.
     *                            been reached.
     *                          - If the HAL module failed to initialize the stream.
     */
     */
    @VintfStability
    @VintfStability
    parcelable OpenInputStreamArguments {
    parcelable OpenInputStreamArguments {
@@ -312,12 +317,16 @@ interface IModule {
     *
     *
     * Note that although it's not prohibited to open a stream on a mix port
     * Note that although it's not prohibited to open a stream on a mix port
     * configuration which is not connected (using a patch) to any device port,
     * configuration which is not connected (using a patch) to any device port,
     * and set up a patch afterwards, this is not the recommended sequence of
     * and set up a patch afterwards, this sequence of calls is not recommended,
     * calls, because setting up of a patch might fail due to an insufficient
     * because setting up of a patch might fail due to an insufficient stream
     * stream buffer size.
     * buffer size. Another consequence of having a stream on an unconnected mix
     * port is that presentation positions can not be determined because there
     * is no "external observer," thus write operations done via
     * StreamDescriptor will be completing with an error, although the data
     * will still be accepted and immediately discarded.
     *
     *
     * @return An opened output stream and the associated descriptor.
     * @return An opened output stream and the associated descriptor.
     * @param args Input arguments, see 'OpenOutputStreamArguments' parcelable.
     * @param args The pack of arguments, see 'OpenOutputStreamArguments' parcelable.
     * @throws EX_ILLEGAL_ARGUMENT In the following cases:
     * @throws EX_ILLEGAL_ARGUMENT In the following cases:
     *                             - If the port config can not be found by the ID.
     *                             - If the port config can not be found by the ID.
     *                             - If the port config is not of an output mix port.
     *                             - If the port config is not of an output mix port.
@@ -330,6 +339,7 @@ interface IModule {
     *                            been reached.
     *                            been reached.
     *                          - If another opened stream already exists for the 'PRIMARY'
     *                          - If another opened stream already exists for the 'PRIMARY'
     *                            output port.
     *                            output port.
     *                          - If the HAL module failed to initialize the stream.
     */
     */
    @VintfStability
    @VintfStability
    parcelable OpenOutputStreamArguments {
    parcelable OpenOutputStreamArguments {
+5 −3
Original line number Original line Diff line number Diff line
@@ -27,10 +27,12 @@ interface IStreamIn {
     * Close the stream.
     * Close the stream.
     *
     *
     * Releases any resources allocated for this stream on the HAL module side.
     * Releases any resources allocated for this stream on the HAL module side.
     * The stream can not be operated after it has been closed. Methods of this
     * This includes the fast message queues and shared memories returned via
     * interface throw EX_ILLEGAL_STATE for a closed stream.
     * the StreamDescriptor. Thus, the stream can not be operated anymore after
     * it has been closed. The client needs to release the audio data I/O
     * objects after the call to this method returns.
     *
     *
     * The associated stream descriptor can be released once this method returns.
     * Methods of this interface throw EX_ILLEGAL_STATE for a closed stream.
     *
     *
     * @throws EX_ILLEGAL_STATE If the stream has already been closed.
     * @throws EX_ILLEGAL_STATE If the stream has already been closed.
     */
     */
+5 −3
Original line number Original line Diff line number Diff line
@@ -27,10 +27,12 @@ interface IStreamOut {
     * Close the stream.
     * Close the stream.
     *
     *
     * Releases any resources allocated for this stream on the HAL module side.
     * Releases any resources allocated for this stream on the HAL module side.
     * The stream can not be operated after it has been closed. Methods of this
     * This includes the fast message queues and shared memories returned via
     * interface throw EX_ILLEGAL_STATE for a closed stream.
     * the StreamDescriptor. Thus, the stream can not be operated anymore after
     * it has been closed. The client needs to release the audio data I/O
     * objects after the call to this method returns.
     *
     *
     * The associated stream descriptor can be released once this method returns.
     * Methods of this interface throw EX_ILLEGAL_STATE for a closed stream.
     *
     *
     * @throws EX_ILLEGAL_STATE If the stream has already been closed.
     * @throws EX_ILLEGAL_STATE If the stream has already been closed.
     */
     */
+37 −33
Original line number Original line Diff line number Diff line
@@ -19,7 +19,6 @@ package android.hardware.audio.core;
import android.hardware.audio.core.MmapBufferDescriptor;
import android.hardware.audio.core.MmapBufferDescriptor;
import android.hardware.common.fmq.MQDescriptor;
import android.hardware.common.fmq.MQDescriptor;
import android.hardware.common.fmq.SynchronizedReadWrite;
import android.hardware.common.fmq.SynchronizedReadWrite;
import android.hardware.common.fmq.UnsynchronizedWrite;


/**
/**
 * Stream descriptor contains fast message queues and buffers used for sending
 * Stream descriptor contains fast message queues and buffers used for sending
@@ -56,13 +55,6 @@ parcelable StreamDescriptor {
        long timeNs;
        long timeNs;
    }
    }


    /**
     * The exit command is used to unblock the HAL thread and ask it to exit.
     * This is the last command that the client sends via the StreamDescriptor.
     * The HAL module must reply to this command in order to unblock the client,
     * and cease waiting on the command queue.
     */
    const int COMMAND_EXIT = 0;
    /**
    /**
     * The command used for audio I/O, see 'AudioBuffer'. For MMap No IRQ mode
     * The command used for audio I/O, see 'AudioBuffer'. For MMap No IRQ mode
     * this command only provides updated positions and latency because actual
     * this command only provides updated positions and latency because actual
@@ -83,29 +75,26 @@ parcelable StreamDescriptor {
         */
         */
        int code;
        int code;
        /**
        /**
         * For output streams: the amount of bytes provided by the client in the
         * For output streams: the amount of bytes that the client requests the
         *   'audio.fmq' queue.
         *   HAL module to read from the 'audio.fmq' queue.
         * For input streams: the amount of bytes requested by the client to read
         * For input streams: the amount of bytes requested by the client to
         *   from the hardware into the 'audio.fmq' queue.
         *   read from the hardware into the 'audio.fmq' queue.
         *
         * In both cases it is allowed for this field to contain any
         * non-negative number. The value 0 can be used if the client only needs
         * to retrieve current positions and latency. Any sufficiently big value
         * which exceeds the size of the queue's area which is currently
         * available for reading or writing by the HAL module must be trimmed by
         * the HAL module to the available size. Note that the HAL module is
         * allowed to consume or provide less data than requested, and it must
         * return the amount of actually read or written data via the
         * 'Reply.fmqByteCount' field. Thus, only attempts to pass a negative
         * number must be constituted as a client's error.
         */
         */
        int fmqByteCount;
        int fmqByteCount;
    }
    }
    MQDescriptor<Command, SynchronizedReadWrite> command;
    MQDescriptor<Command, SynchronizedReadWrite> command;


    /**
     * No error, the command completed successfully.
     */
    const int STATUS_OK = 0;
    /**
     * Invalid data provided in the command, e.g. unknown command code or
     * negative 'fmqByteCount' value.
     */
    const int STATUS_ILLEGAL_ARGUMENT = 1;
    /**
     * The HAL module is not in the state when it can complete the command.
     */
    const int STATUS_ILLEGAL_STATE = 2;

    /**
    /**
     * Used for providing replies to commands. The HAL module writes into
     * Used for providing replies to commands. The HAL module writes into
     * the queue, the client reads. The queue can only contain a single reply,
     * the queue, the client reads. The queue can only contain a single reply,
@@ -115,7 +104,15 @@ parcelable StreamDescriptor {
    @FixedSize
    @FixedSize
    parcelable Reply {
    parcelable Reply {
        /**
        /**
         * One of STATUS_* statuses.
         * One of Binder STATUS_* statuses:
         *  - STATUS_OK: the command has completed successfully;
         *  - STATUS_BAD_VALUE: invalid value in the 'Command' structure;
         *  - STATUS_INVALID_OPERATION: the mix port is not connected
         *                              to any producer or consumer, thus
         *                              positions can not be reported;
         *  - STATUS_NOT_ENOUGH_DATA: a read or write error has
         *                            occurred for the 'audio.fmq' queue;
         *
         */
         */
        int status;
        int status;
        /**
        /**
@@ -123,6 +120,9 @@ parcelable StreamDescriptor {
         *   module from the 'audio.fmq' queue.
         *   module from the 'audio.fmq' queue.
         * For input streams: the amount of bytes actually provided by the HAL
         * For input streams: the amount of bytes actually provided by the HAL
         *   in the 'audio.fmq' queue.
         *   in the 'audio.fmq' queue.
         *
         * The returned value must not exceed the value passed in the
         * 'fmqByteCount' field of the corresponding command or be negative.
         */
         */
        int fmqByteCount;
        int fmqByteCount;
        /**
        /**
@@ -162,12 +162,15 @@ parcelable StreamDescriptor {
    @VintfStability
    @VintfStability
    union AudioBuffer {
    union AudioBuffer {
        /**
        /**
         * The fast message queue used for all modes except MMap No IRQ. Access
         * The fast message queue used for all modes except MMap No IRQ.  Both
         * to this queue is synchronized via the 'command' and 'reply' queues
         * reads and writes into this queue are non-blocking because access to
         * as described below.
         * this queue is synchronized via the 'command' and 'reply' queues as
         * described below. The queue nevertheless uses 'SynchronizedReadWrite'
         * because there is only one reader, and the reading position must be
         * shared.
         *
         *
         * For output streams the following sequence of operations is used:
         * For output streams the following sequence of operations is used:
         *  1. The client puts audio data into the 'audio.fmq' queue.
         *  1. The client writes audio data into the 'audio.fmq' queue.
         *  2. The client writes the 'BURST' command into the 'command' queue,
         *  2. The client writes the 'BURST' command into the 'command' queue,
         *     and hangs on waiting on a read from the 'reply' queue.
         *     and hangs on waiting on a read from the 'reply' queue.
         *  3. The high priority thread in the HAL module wakes up due to 2.
         *  3. The high priority thread in the HAL module wakes up due to 2.
@@ -175,19 +178,20 @@ parcelable StreamDescriptor {
         *  5. The HAL module writes the command status and current positions
         *  5. The HAL module writes the command status and current positions
         *     into 'reply' queue, and hangs on waiting on a read from
         *     into 'reply' queue, and hangs on waiting on a read from
         *     the 'command' queue.
         *     the 'command' queue.
         *  6. The client wakes up due to 5. and reads the reply.
         *
         *
         * For input streams the following sequence of operations is used:
         * For input streams the following sequence of operations is used:
         *  1. The client writes the 'BURST' command into the 'command' queue,
         *  1. The client writes the 'BURST' command into the 'command' queue,
         *     and hangs on waiting on a read from the 'reply' queue.
         *     and hangs on waiting on a read from the 'reply' queue.
         *  2. The high priority thread in the HAL module wakes up due to 1.
         *  2. The high priority thread in the HAL module wakes up due to 1.
         *  3. The HAL module puts audio data into the 'audio.fmq' queue.
         *  3. The HAL module writes audio data into the 'audio.fmq' queue.
         *  4. The HAL module writes the command status and current positions
         *  4. The HAL module writes the command status and current positions
         *     into 'reply' queue, and hangs on waiting on a read from
         *     into 'reply' queue, and hangs on waiting on a read from
         *     the 'command' queue.
         *     the 'command' queue.
         *  5. The client wakes up due to 4.
         *  5. The client wakes up due to 4.
         *  6. The client reads the reply and audio data.
         *  6. The client reads the reply and audio data.
         */
         */
        MQDescriptor<byte, UnsynchronizedWrite> fmq;
        MQDescriptor<byte, SynchronizedReadWrite> fmq;
        /**
        /**
         * MMap buffers are shared directly with the DSP, which operates
         * MMap buffers are shared directly with the DSP, which operates
         * independently from the CPU. Writes and reads into these buffers
         * independently from the CPU. Writes and reads into these buffers
Loading