diff --git a/audio/aidl/aidl_api/android.hardware.audio.core/current/android/hardware/audio/core/StreamDescriptor.aidl b/audio/aidl/aidl_api/android.hardware.audio.core/current/android/hardware/audio/core/StreamDescriptor.aidl index 84a1fe7bad..45040e4609 100644 --- a/audio/aidl/aidl_api/android.hardware.audio.core/current/android/hardware/audio/core/StreamDescriptor.aidl +++ b/audio/aidl/aidl_api/android.hardware.audio.core/current/android/hardware/audio/core/StreamDescriptor.aidl @@ -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 { diff --git a/audio/aidl/android/hardware/audio/core/StreamDescriptor.aidl b/audio/aidl/android/hardware/audio/core/StreamDescriptor.aidl index 92d131a8ad..cab0fda4a1 100644 --- a/audio/aidl/android/hardware/audio/core/StreamDescriptor.aidl +++ b/audio/aidl/android/hardware/audio/core/StreamDescriptor.aidl @@ -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). diff --git a/audio/aidl/default/Stream.cpp b/audio/aidl/default/Stream.cpp index c5d00a2517..d1efb02a12 100644 --- a/audio/aidl/default/Stream.cpp +++ b/audio/aidl/default/Stream.cpp @@ -87,12 +87,13 @@ std::string StreamWorkerCommonLogic::init() { void StreamWorkerCommonLogic::populateReply(StreamDescriptor::Reply* reply, bool isConnected) const { + reply->status = STATUS_OK; if (isConnected) { - reply->status = STATUS_OK; 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; } } diff --git a/audio/aidl/vts/VtsHalAudioCoreTargetTest.cpp b/audio/aidl/vts/VtsHalAudioCoreTargetTest.cpp index a0580697ab..2d7eaff37d 100644 --- a/audio/aidl/vts/VtsHalAudioCoreTargetTest.cpp +++ b/audio/aidl/vts/VtsHalAudioCoreTargetTest.cpp @@ -1660,14 +1660,16 @@ class StreamLogicDefaultDriver : public StreamLogicDriver { } bool interceptRawReply(const StreamDescriptor::Reply&) override { return false; } bool processValidReply(const StreamDescriptor::Reply& reply) override { - if (mPreviousFrames.has_value()) { - if (reply.observable.frames > mPreviousFrames.value()) { - mObservablePositionIncrease = true; - } else if (reply.observable.frames < mPreviousFrames.value()) { - mRetrogradeObservablePosition = true; + if (reply.observable.frames != StreamDescriptor::Position::UNKNOWN) { + if (mPreviousFrames.has_value()) { + if (reply.observable.frames > mPreviousFrames.value()) { + mObservablePositionIncrease = true; + } else if (reply.observable.frames < mPreviousFrames.value()) { + mRetrogradeObservablePosition = true; + } } + mPreviousFrames = reply.observable.frames; } - mPreviousFrames = reply.observable.frames; const auto& lastCommandState = mCommands[mNextCommand - 1]; if (lastCommandState.second != reply.state) {