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

Commit 549a822b authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

audio: Report unknown stream positions explicitly

Instead of using 'STATUS_NO_INIT' in the case when stream
position can not be reported, use a special value for Position
fields. This streamlines processing of statuses on the client
side, by removing the need to treat 'STATUS_NO_INIT' specially.

Bug: 205884982
Test: atest VtsHalAudioCoreTargetTest
Change-Id: I13c9c8d165b632900ca76de144759ef7b9200eff
parent bd483c03
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -42,8 +42,9 @@ parcelable StreamDescriptor {
  const int LATENCY_UNKNOWN = -1;
  @FixedSize @VintfStability
  parcelable Position {
    long frames;
    long timeNs;
    long frames = -1;
    long timeNs = -1;
    const long UNKNOWN = -1;
  }
  @Backing(type="int") @VintfStability
  enum State {
+12 −9
Original line number Diff line number Diff line
@@ -116,10 +116,15 @@ parcelable StreamDescriptor {
    @VintfStability
    @FixedSize
    parcelable Position {
        /**
         * The value used when the position can not be reported by the HAL
         * module.
         */
        const long UNKNOWN = -1;
        /** Frame count. */
        long frames;
        long frames = UNKNOWN;
        /** Timestamp in nanoseconds. */
        long timeNs;
        long timeNs = UNKNOWN;
    }

    @VintfStability
@@ -295,10 +300,6 @@ parcelable StreamDescriptor {
         *  - STATUS_INVALID_OPERATION: the command is not applicable in the
         *                              current state of the stream, or to this
         *                              type of the stream;
         *  - STATUS_NO_INIT: positions can not be reported because the mix port
         *                    is not connected to any producer or consumer, or
         *                    because the HAL module does not support positions
         *                    reporting for this AudioSource (on input streams).
         *  - STATUS_NOT_ENOUGH_DATA: a read or write error has
         *                            occurred for the 'audio.fmq' queue;
         */
@@ -316,9 +317,11 @@ parcelable StreamDescriptor {
         */
        int fmqByteCount;
        /**
         * It is recommended to report the current position for any command.
         * If the position can not be reported, the 'status' field must be
         * set to 'NO_INIT'.
         * It is recommended to report the current position for any command. If
         * the position can not be reported, for example because the mix port is
         * not connected to any producer or consumer, or because the HAL module
         * does not support positions reporting for this AudioSource (on input
         * streams), the 'Position::UNKNOWN' value must be used.
         *
         * For output streams: the moment when the specified stream position
         *   was presented to an external observer (i.e. presentation position).
+3 −2
Original line number Diff line number Diff line
@@ -87,12 +87,13 @@ std::string StreamWorkerCommonLogic::init() {

void StreamWorkerCommonLogic::populateReply(StreamDescriptor::Reply* reply,
                                            bool isConnected) const {
    if (isConnected) {
    reply->status = STATUS_OK;
    if (isConnected) {
        reply->observable.frames = mFrameCount;
        reply->observable.timeNs = ::android::elapsedRealtimeNano();
    } else {
        reply->status = STATUS_NO_INIT;
        reply->observable.frames = StreamDescriptor::Position::UNKNOWN;
        reply->observable.timeNs = StreamDescriptor::Position::UNKNOWN;
    }
}

+8 −6
Original line number Diff line number Diff line
@@ -1660,6 +1660,7 @@ class StreamLogicDefaultDriver : public StreamLogicDriver {
    }
    bool interceptRawReply(const StreamDescriptor::Reply&) override { return false; }
    bool processValidReply(const StreamDescriptor::Reply& reply) override {
        if (reply.observable.frames != StreamDescriptor::Position::UNKNOWN) {
            if (mPreviousFrames.has_value()) {
                if (reply.observable.frames > mPreviousFrames.value()) {
                    mObservablePositionIncrease = true;
@@ -1668,6 +1669,7 @@ class StreamLogicDefaultDriver : public StreamLogicDriver {
                }
            }
            mPreviousFrames = reply.observable.frames;
        }

        const auto& lastCommandState = mCommands[mNextCommand - 1];
        if (lastCommandState.second != reply.state) {