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
This commit is contained in:
Mikhail Naganov
2022-11-23 18:30:07 +00:00
parent bd483c03b2
commit 549a822be2
4 changed files with 26 additions and 19 deletions

View File

@@ -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 {

View File

@@ -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).

View File

@@ -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;
}
}

View File

@@ -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) {