Commit Graph

25 Commits

Author SHA1 Message Date
Mikhail Naganov
e976625a49 audio: Do not use StreamSwitcher for StreamRemoteSubmix
Since use of StreamSwitcher causes the worker thread to be changed
during connected device change, its use must be avoided. We intend
to remove StreamSwitcher completely in future.

Bug: 300130515
Bug: 338974476
Bug: 368723297
Bug: 369272078
Bug: 369289912
Bug: 369964381
Test: atest CtsMediaAudioTestCases
Test: atest VtsHalAudioCoreTargetTest
Change-Id: I4f6fd35f69d73641a86e1102f1d30d5e8f626e8f
2024-10-04 18:51:46 -07:00
Mikhail Naganov
0413d077f7 audio: Fix stream cleanup sequence
Move the cleanup of the stream worker thread from '~StreamCommonImpl'
up to concrete stream implementations. This is because when
the worker thread is stopping, it calls 'DriverInterface::shutdown'
method of the stream. At the time when '~StreamCommonImpl' is
running, the concrete stream class has already been destroyed.

The cleanup actually only happens in the case when the client
did not close the stream properly via 'IStreamCommon.close', or
when the stream creation has failed in the middle.

Bug: 355804294
Test: atest VtsHalAudioCoreTargetTest
Change-Id: Ie86f682af202976ed48d24338b2dffcfd20d9a76
2024-08-15 14:18:51 -07:00
Mikhail Naganov
2be5078e25 audio: Prolong reading attempts from the remote submix pipe
In order to use the time interval for reading from the remote
submix pipe more efficiently, increase the deadline time
to the buffer duration minus a small amount. This should
minimize chances to have discontinuities in the remote submix
input.

Bug: 334363414
Test: atest --test-filter=".*RemoteSubmixTest#testRemoteSubmixRecordingContinuity" CtsMediaAudioTestCases
Change-Id: I02968d09afd8ecdad4d61e635393842d7280e55f
2024-07-22 16:04:23 +00:00
Mikhail Naganov
a41ff5134d audio: Implement blocking in remote submix when there is no sink
The HIDL implementation blocked for the audio buffer duration
when the output side of the remote submix pipe does not have
the sink connected. This behavior was accidentally removed
when fixing b/327220024.

Also, limit the amount of the debug messages displayed when
the sink is shutdown to avoid spamming the syslog.

Bug: 328347445
Test: repro steps from the bug
Test: atest VtsHalAudioCoreTargetTest
Test: atest --test-filter=".*AudioPlaybackCaptureTest.*" CtsMediaAudioTestCases
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:6507376fb940198e8c39ad6d5345d132b1dd7219)
Merged-In: Ia66cb7b4567d42a41bf4715b7d725d36510ac50c
Change-Id: Ia66cb7b4567d42a41bf4715b7d725d36510ac50c
2024-03-25 16:04:27 +00:00
Mikhail Naganov
55e0afa49a audio: Fix glitching of remote submix
Align behavior with the HIDL implementation. This helps
to prevent glitches in the scenarios that use remote
submix for sending audio externally: Auto and Cast.

Bug: 322247032
Bug: 327220024
Test: Repro steps in b/327220024#comment14
Change-Id: If2e4ebd7145375a268ee5f0e4ab656bb3748b2fe
Merged-In: If2e4ebd7145375a268ee5f0e4ab656bb3748b2fe
2024-03-06 10:09:16 -08:00
Mikhail Naganov
9eb3314a24 audio: Improve logging in remote submix module
Implement IModule::dump to display the current state in
the audioflinger dump.

Throttle repetitive logging when there is nothing to read.

Remove stale comment for already fixed b/307586684.

Bug: 307586684
Test: adb shell dumpsys media.audio_flinger
Change-Id: I1f1f6e1658d035d46af3a933a825b20a78c7f297
2024-01-09 14:13:15 -08:00
Mikhail Naganov
878afae8f8 audio: Fix the type used for timekeeping
On 32-bit builds, the 'long' type is 32 bit. Thus, it can not
be used to store the value returned from 'uptimeNanos'.

Bug: 318055805
Test: atest CtsMediaAudioTestCases
Change-Id: I4abf72415b7241728d3ddb1d11043dfd59a8d08a
2024-01-03 11:27:31 -08:00
Mikhail Naganov
3b732895a8 audio r_submix: Suggest configuration from the peer
When there is a pipe established for a remote submix
device, suggest the configuration of the peer when opening
the other end.

Refactor SubmixRoute management to move it out from
StreamRemoteSubmix so that ModuleRemoteSubmix could also
use it.

Bug: 294962274
Test: atest audiorouting_tests
Change-Id: Ib31a662e7b65b92c614dc441a01160cae3485f3a
2023-12-26 10:31:43 -08:00
Mikhail Naganov
7b234d483f audio: Fix remote submix behavior with multiple inputs
Align the behavior of the new implementation with the legacy
implementation in the case when the client opens multiple
input streams on the same remote submix device.

Reduce the HAL buffer size to match legacy behavior.

Bug: 264712385
Test: atest CtsVirtualDevicesTestCases --test-filter=".*VirtualAudioTest.*"
(cherry picked from commit a83c8a5518)
Change-Id: I6f5e6a2c133059c66269b1bdd8a30392db282c4d
2023-12-12 15:55:22 -08:00
Shunkai Yao
0347f0eff0 Revert "audio: Fix remote submix behavior with multiple inputs"
Revert submission 2862771-cuttlefish_aidl_audio-2

Reason for revert: b/316027906

Reverted changes: /q/submissionid:2862771-cuttlefish_aidl_audio-2

Change-Id: I68932be8dad4b4fd4214d0ae6fc01202727f1658
2023-12-12 22:55:59 +00:00
Mikhail Naganov
a83c8a5518 audio: Fix remote submix behavior with multiple inputs
Align the behavior of the new implementation with the legacy
implementation in the case when the client opens multiple
input streams on the same remote submix device.

Reduce the HAL buffer size to match legacy behavior.

Bug: 264712385
Test: atest CtsVirtualDevicesTestCases --test-filter=".*VirtualAudioTest.*"
Change-Id: Ia86a8480495693595dbb501ec58e5d1d238abab2
2023-12-08 09:37:41 -08:00
Mikhail Naganov
0608545377 audio: Fix remote submix module I/O timing and atomicity
Similar to the primary module implementation, align the time
spent in the transfer operation with the duration of audio.

Change the read operation to ingest as much data as possible
during the audio burst duration.

Ensure that checking the existence of a SubmixRoute and adding
a new one is an atomic operation.

Minor improvements to avoid extra synchronization.

In the configuration, change the limit of max open streams to 10
to match the legacy implementation.

Bug: 302132812
Test: atest CtsMediaAudioTestCases --test-filter=".*AudioPlaybackCaptureTest#testPlaybackCaptureDoS"
Change-Id: Iccb6aaac46c039551c3d5f7760b1459168d9cfe5
2023-12-01 16:39:52 -08:00
Mikhail Naganov
2ebe3906ad audio: Fix remote submix configuration and 'prepareToClose'
In the configuration, remove "mono" channel masks.
The legacy implementation always used stereo, the framework
handles channel conversion. Otherwise, the input may
be opened with a different channel mask from the output.

In 'prepareToClose', close the output side of the route.
The framework may close the "old" output stream after
it has opened a new one. A call to 'prepareToClose' means
that the framework thread is already shutting down, thus
it is safe to shut down the route.

Bug: 302036943
Test: atest audioeffect_analysis
Change-Id: I95b57807f2559ef681da822b3cab4ea6b4340143
2023-11-09 14:33:37 -08:00
Mikhail Naganov
2aab766d05 audio: Fix default remote submix HAL implementation and VTS
The implementation had duplicated code in 'transfer', which already
present in 'outWrite'.

Cleaned up delay calculations and logging.

Fixed the VTS to send 'prepareToClose' before attempting to join
the worker. Otherwise, the worker could be stuck on a blocking
operation due to inactivity of the other party and join would never
happen.

Bug: 302132812
Test: atest VtsHalAudioCoreTargetTest --test-filter="*AudioModuleRemoteSubmix*"
Change-Id: Id8455eb12d1d2999dc0bc7b64f0d70a61a177598
2023-11-03 13:49:59 -07:00
Shraddha Basantwani
95f9232923 r_submix : Fix minor issues in AIDL implementation
1. Update refinePosition for output stream
2. Add missing exitStandby on transfer
3. Add check for availableToRead in read functionality

Bug: 286914845
Test: atest VtsHalAudioCoreTargetTest
Change-Id: Ibab914e5e09474c2b55a6c64cc004ebc1bb6cb47
2023-09-12 05:43:18 +00:00
Shunkai Yao
7816f26afa r_submix: keep the signed value for offset calculation in AIDL implementation
otherwise a negative offset will result in long sleep

Bug: 295055755
Test: atest android.media.audio.cts.AudioPlaybackCaptureTest
Change-Id: Ie941cc2525e3ea42b53106ae3a65242794b1dd1b
2023-08-22 20:50:31 +00:00
Mikhail Naganov
459b7331e9 audio: Make renamings suggested by reviewers
Rename DriverInterface::getPosition -> refinePosition. This reflects
the fact that the driver may provide more precise position, however
this is an optional operation.

Rename StreamIn/Out::mContext -> mContextInstance. This is
to emphasize that StreamIn/Out actually own the context and they
hold the real context instance, not just a reference/pointer
to it, like other classes involved in the inheritance chain.

Bug: 286914845
Test: atest VtsHalAudioCoreTargetTest
Change-Id: Id7159f9bf3ee020dc7cf594ec35f5d59d23d7e31
2023-08-03 10:31:12 -07:00
Treehugger Robot
0bc307a5dd Merge "Audio r_submix : Handle the usecase when no data is available to read." into main 2023-08-02 18:51:53 +00:00
Shraddha Basantwani
675cce24d6 Audio r_submix : Handle the usecase when no data is available to read.
Bug: 290116295
Test: atest VtsHalAudioCoreTargetTest
Change-Id: Ifd6706d593f890dd8ae148523a37177774c8ffd4
2023-08-02 05:19:24 +00:00
Shraddha Basantwani
2e460345a2 Audio r_submix : Replace usage of portId by device address
Use stream switcher to obtain device address for creation
of a remote submix stream.

Bug: 286914845
Test: atest VtsHalAudioCoreTargetTest
Change-Id: I8dde3d59e488c9621dce78ffd5249254ecfc0b1a
2023-08-01 12:06:38 +00:00
Mikhail Naganov
1eedc130e8 audio: Move frame counter to StreamContext
Moving frame counter to the StreamContext class enables
switching stream drivers on the fly while keeping the frame
count monotonically increasing.

StreamWorkerCommonLogic now holds a pointer to StreamContext,
which makes redundant storing copies of the fields of the latter.

Bug: 264712385
Test: atest VtsHalAudioCoreTargetTest
Change-Id: If6716f4051c484b52927cbfe4032df7c907eb3a5
2023-07-24 16:37:18 -07:00
Mikhail Naganov
6ddefdbcdf audio: Move StreamContext ownership out from StreamCommonImpl
Upcoming implementations of the streams of the primary module
will need to change the underlying stream type depending on
the current connected device. The stream context must persist,
thus its life time must be bound to the IStreamIn/Out implementation.
Move the StreamContext instance under ownership of StreamIn/Out.

Add StreamCommonImpl::onClose so that the owner of the context
may know when it is safe to reset it.

Re-arrange the order of the arguments when creating a stream
so that the context always comes first.

Bug: 264712385
Test: atest VtsHalAudioCoreTargetTest
Change-Id: Iaf13d4bc3a53cbfc27264d3abd1f6c417ece3941
2023-07-19 17:49:28 -07:00
Mikhail Naganov
704aec434e audio: Add optional 'DriverInterface::getPosition' method.
This is a method which can be optionally implemented
by a stream in case it can provide more exact position,
for example by taking into account data in intermediate
buffers.

Implemented this method for StreamAlsa and StreamRemoteSubmix.

Bug: 264712385
Test: atest VtsHalAudioCoreTargetTest
Change-Id: I392933f8f6b22d784726925199db00dcb0313648
2023-07-13 11:25:47 -07:00
Mikhail Naganov
49712b56d8 audio: Add DriverInterface::start method
This method is used to bring out the hardware from standby.
It replaces the ad hoc 'exitStandby' method in StreamUsb.

Streamlined StreamUsb code to avoid locking during transfers.

Updated StreamRemoteSubmix to use 'start'.

Added extra checks to StreamStub to ensure that 'init/shutdown'
and 'standby/start' methods are called as expected. This allows
removing extra checks from non-stub stream implementations.

Bug: 205884982
Test: atest VtsHalAudioCoreTargetTest
Change-Id: I3615a7ca99cb4f1e149dcbfbc912f2ed58fb033f
2023-06-30 13:41:55 -07:00
Shraddha Basantwani
6bb696370b Audio : Add remote submix stream implementation
Bug: 286914845
Test: atest VtsHalAudioCoreTargetTest
Change-Id: Ia477458193ade9068eaf56e953ab670fee53cc7d
2023-06-30 09:05:50 +00:00