Add unique audio port IDs to AudioTrack and AudioRecord
This will allow to track activity at the track level instead of
at audio session level as only possible with current implementation.
AudioTracks and AudioRecords will receive a unique audio port ID the
first time they register to audio policy with
getOutputForAttr()/getInputForAttr() and keep this ID for their
lifetime.
This CL is the first partial change and just updates the
audio policy and audio flinger APIs used at track creation time.
Test: basic regression test of audio playback and capture use cases
Change-Id: I8d612e67738e120494f61e3f7c60bfd0b2c6a329
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index 0e70ad9..8917c26 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -547,7 +547,8 @@
pid_t tid,
audio_session_t *sessionId,
int clientUid,
- status_t *status)
+ status_t *status,
+ audio_port_handle_t portId)
{
sp<PlaybackThread::Track> track;
sp<TrackHandle> trackHandle;
@@ -640,7 +641,8 @@
ALOGV("createTrack() lSessionId: %d", lSessionId);
track = thread->createTrack_l(client, streamType, sampleRate, format,
- channelMask, frameCount, sharedBuffer, lSessionId, flags, tid, clientUid, &lStatus);
+ channelMask, frameCount, sharedBuffer, lSessionId, flags, tid,
+ clientUid, &lStatus, portId);
LOG_ALWAYS_FATAL_IF((lStatus == NO_ERROR) && (track == 0));
// we don't abort yet if lStatus != NO_ERROR; there is still work to be done regardless
@@ -1445,7 +1447,8 @@
size_t *notificationFrames,
sp<IMemory>& cblk,
sp<IMemory>& buffers,
- status_t *status)
+ status_t *status,
+ audio_port_handle_t portId)
{
sp<RecordThread::RecordTrack> recordTrack;
sp<RecordHandle> recordHandle;
@@ -1529,7 +1532,7 @@
recordTrack = thread->createRecordTrack_l(client, sampleRate, format, channelMask,
frameCount, lSessionId, notificationFrames,
- clientUid, flags, tid, &lStatus);
+ clientUid, flags, tid, &lStatus, portId);
LOG_ALWAYS_FATAL_IF((lStatus == NO_ERROR) && (recordTrack == 0));
if (lStatus == NO_ERROR) {
diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h
index c3bf1f9..b046ab5 100644
--- a/services/audioflinger/AudioFlinger.h
+++ b/services/audioflinger/AudioFlinger.h
@@ -115,7 +115,8 @@
pid_t tid,
audio_session_t *sessionId,
int clientUid,
- status_t *status /*non-NULL*/);
+ status_t *status /*non-NULL*/,
+ audio_port_handle_t portId);
virtual sp<IAudioRecord> openRecord(
audio_io_handle_t input,
@@ -132,7 +133,8 @@
size_t *notificationFrames,
sp<IMemory>& cblk,
sp<IMemory>& buffers,
- status_t *status /*non-NULL*/);
+ status_t *status /*non-NULL*/,
+ audio_port_handle_t portId);
virtual uint32_t sampleRate(audio_io_handle_t ioHandle) const;
virtual audio_format_t format(audio_io_handle_t output) const;
diff --git a/services/audioflinger/PlaybackTracks.h b/services/audioflinger/PlaybackTracks.h
index 0bcb9a0..27e4627 100644
--- a/services/audioflinger/PlaybackTracks.h
+++ b/services/audioflinger/PlaybackTracks.h
@@ -34,7 +34,8 @@
audio_session_t sessionId,
uid_t uid,
audio_output_flags_t flags,
- track_type type);
+ track_type type,
+ audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE);
virtual ~Track();
virtual status_t initCheck() const;
diff --git a/services/audioflinger/RecordTracks.h b/services/audioflinger/RecordTracks.h
index 883ff6b..848e531 100644
--- a/services/audioflinger/RecordTracks.h
+++ b/services/audioflinger/RecordTracks.h
@@ -32,7 +32,8 @@
audio_session_t sessionId,
uid_t uid,
audio_input_flags_t flags,
- track_type type);
+ track_type type,
+ audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE);
virtual ~RecordTrack();
virtual status_t initCheck() const;
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index 9966eeb..85d2335 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -1754,7 +1754,8 @@
audio_output_flags_t *flags,
pid_t tid,
uid_t uid,
- status_t *status)
+ status_t *status,
+ audio_port_handle_t portId)
{
size_t frameCount = *pFrameCount;
sp<Track> track;
@@ -1936,7 +1937,7 @@
track = new Track(this, client, streamType, sampleRate, format,
channelMask, frameCount, NULL, sharedBuffer,
- sessionId, uid, *flags, TrackBase::TYPE_DEFAULT);
+ sessionId, uid, *flags, TrackBase::TYPE_DEFAULT, portId);
lStatus = track != 0 ? track->initCheck() : (status_t) NO_MEMORY;
if (lStatus != NO_ERROR) {
@@ -6451,7 +6452,8 @@
uid_t uid,
audio_input_flags_t *flags,
pid_t tid,
- status_t *status)
+ status_t *status,
+ audio_port_handle_t portId)
{
size_t frameCount = *pFrameCount;
sp<RecordTrack> track;
@@ -6559,7 +6561,7 @@
track = new RecordTrack(this, client, sampleRate,
format, channelMask, frameCount, NULL, sessionId, uid,
- *flags, TrackBase::TYPE_DEFAULT);
+ *flags, TrackBase::TYPE_DEFAULT, portId);
lStatus = track->initCheck();
if (lStatus != NO_ERROR) {
diff --git a/services/audioflinger/Threads.h b/services/audioflinger/Threads.h
index d261ea5..4eafc38 100644
--- a/services/audioflinger/Threads.h
+++ b/services/audioflinger/Threads.h
@@ -591,7 +591,8 @@
audio_output_flags_t *flags,
pid_t tid,
uid_t uid,
- status_t *status /*non-NULL*/);
+ status_t *status /*non-NULL*/,
+ audio_port_handle_t portId);
AudioStreamOut* getOutput() const;
AudioStreamOut* clearOutput();
@@ -1363,7 +1364,8 @@
uid_t uid,
audio_input_flags_t *flags,
pid_t tid,
- status_t *status /*non-NULL*/);
+ status_t *status /*non-NULL*/,
+ audio_port_handle_t portId);
status_t start(RecordTrack* recordTrack,
AudioSystem::sync_event_t event,
diff --git a/services/audioflinger/TrackBase.h b/services/audioflinger/TrackBase.h
index 4fcb596..9ca2d63 100644
--- a/services/audioflinger/TrackBase.h
+++ b/services/audioflinger/TrackBase.h
@@ -65,7 +65,8 @@
uid_t uid,
bool isOut,
alloc_type alloc = ALLOC_CBLK,
- track_type type = TYPE_DEFAULT);
+ track_type type = TYPE_DEFAULT,
+ audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE);
virtual ~TrackBase();
virtual status_t initCheck() const;
@@ -163,6 +164,7 @@
bool mTerminated;
track_type mType; // must be one of TYPE_DEFAULT, TYPE_OUTPUT, TYPE_PATCH ...
audio_io_handle_t mThreadIoHandle; // I/O handle of the thread the track is attached to
+ audio_port_handle_t mPortId; // unique ID for this track used by audio policy
};
// PatchProxyBufferProvider interface is implemented by PatchTrack and PatchRecord.
diff --git a/services/audioflinger/Tracks.cpp b/services/audioflinger/Tracks.cpp
index e8e27e4..9746075 100644
--- a/services/audioflinger/Tracks.cpp
+++ b/services/audioflinger/Tracks.cpp
@@ -75,7 +75,8 @@
uid_t clientUid,
bool isOut,
alloc_type alloc,
- track_type type)
+ track_type type,
+ audio_port_handle_t portId)
: RefBase(),
mThread(thread),
mClient(client),
@@ -96,7 +97,8 @@
mId(android_atomic_inc(&nextTrackId)),
mTerminated(false),
mType(type),
- mThreadIoHandle(thread->id())
+ mThreadIoHandle(thread->id()),
+ mPortId(portId)
{
const uid_t callingUid = IPCThreadState::self()->getCallingUid();
if (!isTrustedCallingUid(callingUid) || clientUid == AUDIO_UID_INVALID) {
@@ -343,12 +345,13 @@
audio_session_t sessionId,
uid_t uid,
audio_output_flags_t flags,
- track_type type)
+ track_type type,
+ audio_port_handle_t portId)
: TrackBase(thread, client, sampleRate, format, channelMask, frameCount,
(sharedBuffer != 0) ? sharedBuffer->pointer() : buffer,
sessionId, uid, true /*isOut*/,
(type == TYPE_PATCH) ? ( buffer == NULL ? ALLOC_LOCAL : ALLOC_NONE) : ALLOC_CBLK,
- type),
+ type, portId),
mFillingUpStatus(FS_INVALID),
// mRetryCount initialized later when needed
mSharedBuffer(sharedBuffer),
@@ -1477,13 +1480,14 @@
audio_session_t sessionId,
uid_t uid,
audio_input_flags_t flags,
- track_type type)
+ track_type type,
+ audio_port_handle_t portId)
: TrackBase(thread, client, sampleRate, format,
channelMask, frameCount, buffer, sessionId, uid, false /*isOut*/,
(type == TYPE_DEFAULT) ?
((flags & AUDIO_INPUT_FLAG_FAST) ? ALLOC_PIPE : ALLOC_CBLK) :
((buffer == NULL) ? ALLOC_LOCAL : ALLOC_NONE),
- type),
+ type, portId),
mOverflow(false),
mFramesToDrop(0),
mResamplerBufferProvider(NULL), // initialize in case of early constructor exit