Configure policy of mediaserver threads
Change-Id: Ifd825590ba36996064a458f64453a94b84722cb0
diff --git a/services/audioflinger/Android.mk b/services/audioflinger/Android.mk
index 4667649..7202b8b 100644
--- a/services/audioflinger/Android.mk
+++ b/services/audioflinger/Android.mk
@@ -68,4 +68,6 @@
LOCAL_CFLAGS += -DSTATE_QUEUE_INSTANTIATIONS='"StateQueueInstantiations.cpp"'
+LOCAL_CFLAGS += -UHAVE_REQUEST_PRIORITY
+
include $(BUILD_SHARED_LIBRARY)
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index bce30d7..865051f 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -401,6 +401,7 @@
IAudioFlinger::track_flags_t flags,
const sp<IMemory>& sharedBuffer,
audio_io_handle_t output,
+ pid_t tid,
int *sessionId,
status_t *status)
{
@@ -458,9 +459,8 @@
}
ALOGV("createTrack() lSessionId: %d", lSessionId);
- bool isTimed = (flags & IAudioFlinger::TRACK_TIMED) != 0;
track = thread->createTrack_l(client, streamType, sampleRate, format,
- channelMask, frameCount, sharedBuffer, lSessionId, flags, &lStatus);
+ channelMask, frameCount, sharedBuffer, lSessionId, flags, tid, &lStatus);
// move effect chain to this output thread if an effect on same session was waiting
// for a track to be created
@@ -1569,6 +1569,7 @@
const sp<IMemory>& sharedBuffer,
int sessionId,
IAudioFlinger::track_flags_t flags,
+ pid_t tid,
status_t *status)
{
sp<Track> track;
@@ -1589,7 +1590,7 @@
) ||
// use case 2: callback handler and small power-of-2 frame count
(
- // unfortunately we can't verify that there's a callback until start()
+ (tid != -1) &&
// FIXME supported frame counts should not be hard-coded
(
(frameCount == 128) ||
@@ -1678,6 +1679,20 @@
chain->incTrackCnt();
}
}
+
+#ifdef HAVE_REQUEST_PRIORITY
+ if ((flags & IAudioFlinger::TRACK_FAST) && (tid != -1)) {
+ pid_t callingPid = IPCThreadState::self()->getCallingPid();
+ // we don't have CAP_SYS_NICE, nor do we want to have it as it's too powerful,
+ // so ask activity manager to do this on our behalf
+ int err = requestPriority(callingPid, tid, 1);
+ if (err != 0) {
+ ALOGW("Policy SCHED_FIFO priority %d is unavailable for pid %d tid %d; error %d",
+ 1, callingPid, tid, err);
+ }
+ }
+#endif
+
lStatus = NO_ERROR;
Exit:
@@ -3681,20 +3696,11 @@
return false;
}
-status_t AudioFlinger::PlaybackThread::Track::start(pid_t tid,
- AudioSystem::sync_event_t event,
+status_t AudioFlinger::PlaybackThread::Track::start(AudioSystem::sync_event_t event,
int triggerSession)
{
status_t status = NO_ERROR;
- ALOGV("start(%d), calling pid %d session %d tid %d",
- mName, IPCThreadState::self()->getCallingPid(), mSessionId, tid);
- // check for use case 2 with missing callback
- if (isFastTrack() && (mSharedBuffer == 0) && (tid == 0)) {
- ALOGW("AUDIO_OUTPUT_FLAG_FAST denied");
- mFlags &= ~IAudioFlinger::TRACK_FAST;
- // FIXME the track must be invalidated and moved to another thread or
- // attached directly to the normal mixer now
- }
+
sp<ThreadBase> thread = mThread.promote();
if (thread != 0) {
Mutex::Autolock _l(thread->mLock);
@@ -4467,14 +4473,13 @@
return NOT_ENOUGH_DATA;
}
-status_t AudioFlinger::RecordThread::RecordTrack::start(pid_t tid,
- AudioSystem::sync_event_t event,
+status_t AudioFlinger::RecordThread::RecordTrack::start(AudioSystem::sync_event_t event,
int triggerSession)
{
sp<ThreadBase> thread = mThread.promote();
if (thread != 0) {
RecordThread *recordThread = (RecordThread *)thread.get();
- return recordThread->start(this, tid, event, triggerSession);
+ return recordThread->start(this, event, triggerSession);
} else {
return BAD_VALUE;
}
@@ -4541,11 +4546,10 @@
clearBufferQueue();
}
-status_t AudioFlinger::PlaybackThread::OutputTrack::start(pid_t tid,
- AudioSystem::sync_event_t event,
+status_t AudioFlinger::PlaybackThread::OutputTrack::start(AudioSystem::sync_event_t event,
int triggerSession)
{
- status_t status = Track::start(tid, event, triggerSession);
+ status_t status = Track::start(event, triggerSession);
if (status != NO_ERROR) {
return status;
}
@@ -4575,7 +4579,7 @@
uint32_t waitTimeLeftMs = mSourceThread->waitTimeMs();
if (!mActive && frames != 0) {
- start(0);
+ start();
sp<ThreadBase> thread = mThread.promote();
if (thread != 0) {
MixerThread *mixerThread = (MixerThread *)thread.get();
@@ -4834,8 +4838,8 @@
return mTrack->getCblk();
}
-status_t AudioFlinger::TrackHandle::start(pid_t tid) {
- return mTrack->start(tid);
+status_t AudioFlinger::TrackHandle::start() {
+ return mTrack->start();
}
void AudioFlinger::TrackHandle::stop() {
@@ -4988,9 +4992,9 @@
return mRecordTrack->getCblk();
}
-status_t AudioFlinger::RecordHandle::start(pid_t tid, int event, int triggerSession) {
+status_t AudioFlinger::RecordHandle::start(int event, int triggerSession) {
ALOGV("RecordHandle::start()");
- return mRecordTrack->start(tid, (AudioSystem::sync_event_t)event, triggerSession);
+ return mRecordTrack->start((AudioSystem::sync_event_t)event, triggerSession);
}
void AudioFlinger::RecordHandle::stop() {
@@ -5291,9 +5295,10 @@
}
status_t AudioFlinger::RecordThread::start(RecordThread::RecordTrack* recordTrack,
- pid_t tid, AudioSystem::sync_event_t event,
+ AudioSystem::sync_event_t event,
int triggerSession)
{
+ // FIXME use tid here
ALOGV("RecordThread::start tid=%d, event %d, triggerSession %d", tid, event, triggerSession);
sp<ThreadBase> strongMe = this;
status_t status = NO_ERROR;
diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h
index b1c5554..6b18945 100644
--- a/services/audioflinger/AudioFlinger.h
+++ b/services/audioflinger/AudioFlinger.h
@@ -91,6 +91,7 @@
IAudioFlinger::track_flags_t flags,
const sp<IMemory>& sharedBuffer,
audio_io_handle_t output,
+ pid_t tid,
int *sessionId,
status_t *status);
@@ -376,8 +377,7 @@
int sessionId);
virtual ~TrackBase();
- virtual status_t start(pid_t tid,
- AudioSystem::sync_event_t event = AudioSystem::SYNC_EVENT_NONE,
+ virtual status_t start(AudioSystem::sync_event_t event = AudioSystem::SYNC_EVENT_NONE,
int triggerSession = 0) = 0;
virtual void stop() = 0;
sp<IMemory> getCblk() const { return mCblkMemory; }
@@ -669,8 +669,7 @@
virtual ~Track();
void dump(char* buffer, size_t size);
- virtual status_t start(pid_t tid,
- AudioSystem::sync_event_t event = AudioSystem::SYNC_EVENT_NONE,
+ virtual status_t start(AudioSystem::sync_event_t event = AudioSystem::SYNC_EVENT_NONE,
int triggerSession = 0);
virtual void stop();
void pause();
@@ -855,8 +854,7 @@
int frameCount);
virtual ~OutputTrack();
- virtual status_t start(pid_t tid,
- AudioSystem::sync_event_t event = AudioSystem::SYNC_EVENT_NONE,
+ virtual status_t start(AudioSystem::sync_event_t event = AudioSystem::SYNC_EVENT_NONE,
int triggerSession = 0);
virtual void stop();
bool write(int16_t* data, uint32_t frames);
@@ -933,6 +931,7 @@
const sp<IMemory>& sharedBuffer,
int sessionId,
IAudioFlinger::track_flags_t flags,
+ pid_t tid,
status_t *status);
AudioStreamOut* getOutput() const;
@@ -1188,7 +1187,7 @@
TrackHandle(const sp<PlaybackThread::Track>& track);
virtual ~TrackHandle();
virtual sp<IMemory> getCblk() const;
- virtual status_t start(pid_t tid);
+ virtual status_t start();
virtual void stop();
virtual void flush();
virtual void mute(bool);
@@ -1227,8 +1226,7 @@
int sessionId);
virtual ~RecordTrack();
- virtual status_t start(pid_t tid,
- AudioSystem::sync_event_t event = AudioSystem::SYNC_EVENT_NONE,
+ virtual status_t start(AudioSystem::sync_event_t event = AudioSystem::SYNC_EVENT_NONE,
int triggerSession = 0);
virtual void stop();
@@ -1276,7 +1274,7 @@
int sessionId,
status_t *status);
- status_t start(RecordTrack* recordTrack, pid_t tid,
+ status_t start(RecordTrack* recordTrack,
AudioSystem::sync_event_t event,
int triggerSession);
void stop(RecordTrack* recordTrack);
@@ -1335,7 +1333,7 @@
RecordHandle(const sp<RecordThread::RecordTrack>& recordTrack);
virtual ~RecordHandle();
virtual sp<IMemory> getCblk() const;
- virtual status_t start(pid_t tid, int event, int triggerSession);
+ virtual status_t start(int event, int triggerSession);
virtual void stop();
virtual status_t onTransact(
uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags);