summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorEric Laurent <elaurent@google.com>2010-06-21 09:27:30 -0700
committerEric Laurent <elaurent@google.com>2010-06-22 17:14:04 -0700
commita514bdb58b5de4986679f72b7204b4764f7a2778 (patch)
tree84b1ebf0c2b500bfb4995e373f8fee5b63b6c9fd /media
parent58ae9c530247668f8af36e30d228c716c226b3d4 (diff)
downloadframeworks_av-a514bdb58b5de4986679f72b7204b4764f7a2778.zip
frameworks_av-a514bdb58b5de4986679f72b7204b4764f7a2778.tar.gz
frameworks_av-a514bdb58b5de4986679f72b7204b4764f7a2778.tar.bz2
Added support for audio sessions in MediaPlayer and AudioTrack.
Audio sessions are used to associate audio effects to particular instances (or groups) of MediaPlayers or AudioTracks. Change-Id: Ib94eec43241cfcb416590f435ddce7ab39a07640
Diffstat (limited to 'media')
-rw-r--r--media/libmedia/AudioTrack.cpp6
-rw-r--r--media/libmedia/IMediaPlayerService.cpp19
-rw-r--r--media/libmedia/mediaplayer.cpp26
-rw-r--r--media/libmediaplayerservice/MediaPlayerService.cpp42
-rw-r--r--media/libmediaplayerservice/MediaPlayerService.h13
5 files changed, 78 insertions, 28 deletions
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp
index 2118f8f..0f2093a 100644
--- a/media/libmedia/AudioTrack.cpp
+++ b/media/libmedia/AudioTrack.cpp
@@ -92,7 +92,8 @@ AudioTrack::AudioTrack(
: mStatus(NO_INIT)
{
mStatus = set(streamType, sampleRate, format, channels,
- frameCount, flags, cbf, user, notificationFrames, 0);
+ frameCount, flags, cbf, user, notificationFrames,
+ 0, false, sessionId);
}
AudioTrack::AudioTrack(
@@ -109,7 +110,8 @@ AudioTrack::AudioTrack(
: mStatus(NO_INIT)
{
mStatus = set(streamType, sampleRate, format, channels,
- 0, flags, cbf, user, notificationFrames, sharedBuffer);
+ 0, flags, cbf, user, notificationFrames,
+ sharedBuffer, false, sessionId);
}
AudioTrack::~AudioTrack()
diff --git a/media/libmedia/IMediaPlayerService.cpp b/media/libmedia/IMediaPlayerService.cpp
index 71c5f86..1ae222e 100644
--- a/media/libmedia/IMediaPlayerService.cpp
+++ b/media/libmedia/IMediaPlayerService.cpp
@@ -58,7 +58,7 @@ public:
virtual sp<IMediaPlayer> create(
pid_t pid, const sp<IMediaPlayerClient>& client,
- const char* url, const KeyedVector<String8, String8> *headers) {
+ const char* url, const KeyedVector<String8, String8> *headers, int audioSessionId) {
Parcel data, reply;
data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
data.writeInt32(pid);
@@ -75,8 +75,10 @@ public:
data.writeString8(headers->valueAt(i));
}
}
+ data.writeInt32(audioSessionId);
remote()->transact(CREATE_URL, data, &reply);
+
return interface_cast<IMediaPlayer>(reply.readStrongBinder());
}
@@ -89,7 +91,8 @@ public:
return interface_cast<IMediaRecorder>(reply.readStrongBinder());
}
- virtual sp<IMediaPlayer> create(pid_t pid, const sp<IMediaPlayerClient>& client, int fd, int64_t offset, int64_t length)
+ virtual sp<IMediaPlayer> create(pid_t pid, const sp<IMediaPlayerClient>& client, int fd,
+ int64_t offset, int64_t length, int audioSessionId)
{
Parcel data, reply;
data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
@@ -98,8 +101,11 @@ public:
data.writeFileDescriptor(fd);
data.writeInt64(offset);
data.writeInt64(length);
+ data.writeInt32(audioSessionId);
+
remote()->transact(CREATE_FD, data, &reply);
- return interface_cast<IMediaPlayer>(reply.readStrongBinder());
+
+ return interface_cast<IMediaPlayer>(reply.readStrongBinder());;
}
virtual sp<IMemory> decode(const char* url, uint32_t *pSampleRate, int* pNumChannels, int* pFormat)
@@ -166,9 +172,10 @@ status_t BnMediaPlayerService::onTransact(
String8 value = data.readString8();
headers.add(key, value);
}
+ int audioSessionId = data.readInt32();
sp<IMediaPlayer> player = create(
- pid, client, url, numHeaders > 0 ? &headers : NULL);
+ pid, client, url, numHeaders > 0 ? &headers : NULL, audioSessionId);
reply->writeStrongBinder(player->asBinder());
return NO_ERROR;
@@ -180,7 +187,9 @@ status_t BnMediaPlayerService::onTransact(
int fd = dup(data.readFileDescriptor());
int64_t offset = data.readInt64();
int64_t length = data.readInt64();
- sp<IMediaPlayer> player = create(pid, client, fd, offset, length);
+ int audioSessionId = data.readInt32();
+
+ sp<IMediaPlayer> player = create(pid, client, fd, offset, length, audioSessionId);
reply->writeStrongBinder(player->asBinder());
return NO_ERROR;
} break;
diff --git a/media/libmedia/mediaplayer.cpp b/media/libmedia/mediaplayer.cpp
index c6bbbcc..d5a3c13 100644
--- a/media/libmedia/mediaplayer.cpp
+++ b/media/libmedia/mediaplayer.cpp
@@ -55,6 +55,7 @@ MediaPlayer::MediaPlayer()
mLeftVolume = mRightVolume = 1.0;
mVideoWidth = mVideoHeight = 0;
mLockThreadId = 0;
+ mAudioSessionId = AudioSystem::newAudioSessionId();
}
MediaPlayer::~MediaPlayer()
@@ -137,7 +138,7 @@ status_t MediaPlayer::setDataSource(
const sp<IMediaPlayerService>& service(getMediaPlayerService());
if (service != 0) {
sp<IMediaPlayer> player(
- service->create(getpid(), this, url, headers));
+ service->create(getpid(), this, url, headers, mAudioSessionId));
err = setDataSource(player);
}
}
@@ -150,7 +151,7 @@ status_t MediaPlayer::setDataSource(int fd, int64_t offset, int64_t length)
status_t err = UNKNOWN_ERROR;
const sp<IMediaPlayerService>& service(getMediaPlayerService());
if (service != 0) {
- sp<IMediaPlayer> player(service->create(getpid(), this, fd, offset, length));
+ sp<IMediaPlayer> player(service->create(getpid(), this, fd, offset, length, mAudioSessionId));
err = setDataSource(player);
}
return err;
@@ -501,6 +502,27 @@ status_t MediaPlayer::setVolume(float leftVolume, float rightVolume)
return OK;
}
+status_t MediaPlayer::setAudioSessionId(int sessionId)
+{
+ LOGV("MediaPlayer::setAudioSessionId(%d)", sessionId);
+ Mutex::Autolock _l(mLock);
+ if (!(mCurrentState & MEDIA_PLAYER_IDLE)) {
+ LOGE("setAudioSessionId called in state %d", mCurrentState);
+ return INVALID_OPERATION;
+ }
+ if (sessionId < 0) {
+ return BAD_VALUE;
+ }
+ mAudioSessionId = sessionId;
+ return NO_ERROR;
+}
+
+int MediaPlayer::getAudioSessionId()
+{
+ Mutex::Autolock _l(mLock);
+ return mAudioSessionId;
+}
+
void MediaPlayer::notify(int msg, int ext1, int ext2)
{
LOGV("message received msg=%d, ext1=%d, ext2=%d", msg, ext1, ext2);
diff --git a/media/libmediaplayerservice/MediaPlayerService.cpp b/media/libmediaplayerservice/MediaPlayerService.cpp
index d7ca635..d45c17b 100644
--- a/media/libmediaplayerservice/MediaPlayerService.cpp
+++ b/media/libmediaplayerservice/MediaPlayerService.cpp
@@ -252,11 +252,12 @@ sp<IMediaMetadataRetriever> MediaPlayerService::createMetadataRetriever(pid_t pi
sp<IMediaPlayer> MediaPlayerService::create(
pid_t pid, const sp<IMediaPlayerClient>& client, const char* url,
- const KeyedVector<String8, String8> *headers)
+ const KeyedVector<String8, String8> *headers, int audioSessionId)
{
int32_t connId = android_atomic_inc(&mNextConnId);
- sp<Client> c = new Client(this, pid, connId, client);
- LOGV("Create new client(%d) from pid %d, url=%s, connId=%d", connId, pid, url, connId);
+ sp<Client> c = new Client(this, pid, connId, client, audioSessionId);
+ LOGV("Create new client(%d) from pid %d, url=%s, connId=%d, audioSessionId=%d",
+ connId, pid, url, connId, audioSessionId);
if (NO_ERROR != c->setDataSource(url, headers))
{
c.clear();
@@ -269,12 +270,12 @@ sp<IMediaPlayer> MediaPlayerService::create(
}
sp<IMediaPlayer> MediaPlayerService::create(pid_t pid, const sp<IMediaPlayerClient>& client,
- int fd, int64_t offset, int64_t length)
+ int fd, int64_t offset, int64_t length, int audioSessionId)
{
int32_t connId = android_atomic_inc(&mNextConnId);
- sp<Client> c = new Client(this, pid, connId, client);
- LOGV("Create new client(%d) from pid %d, fd=%d, offset=%lld, length=%lld",
- connId, pid, fd, offset, length);
+ sp<Client> c = new Client(this, pid, connId, client, audioSessionId);
+ LOGV("Create new client(%d) from pid %d, fd=%d, offset=%lld, length=%lld, audioSessionId=%d",
+ connId, pid, fd, offset, length, audioSessionId);
if (NO_ERROR != c->setDataSource(fd, offset, length)) {
c.clear();
} else {
@@ -609,7 +610,7 @@ void MediaPlayerService::removeClient(wp<Client> client)
}
MediaPlayerService::Client::Client(const sp<MediaPlayerService>& service, pid_t pid,
- int32_t connId, const sp<IMediaPlayerClient>& client)
+ int32_t connId, const sp<IMediaPlayerClient>& client, int audioSessionId)
{
LOGV("Client(%d) constructor", connId);
mPid = pid;
@@ -618,6 +619,8 @@ MediaPlayerService::Client::Client(const sp<MediaPlayerService>& service, pid_t
mClient = client;
mLoop = false;
mStatus = NO_INIT;
+ mAudioSessionId = audioSessionId;
+
#if CALLBACK_ANTAGONIZER
LOGD("create Antagonizer");
mAntagonizer = new Antagonizer(notify, this);
@@ -871,7 +874,7 @@ status_t MediaPlayerService::Client::setDataSource(
if (p == NULL) return NO_INIT;
if (!p->hardwareOutput()) {
- mAudioOutput = new AudioOutput();
+ mAudioOutput = new AudioOutput(mAudioSessionId);
static_cast<MediaPlayerInterface*>(p.get())->setAudioSink(mAudioOutput);
}
@@ -921,7 +924,7 @@ status_t MediaPlayerService::Client::setDataSource(int fd, int64_t offset, int64
if (p == NULL) return NO_INIT;
if (!p->hardwareOutput()) {
- mAudioOutput = new AudioOutput();
+ mAudioOutput = new AudioOutput(mAudioSessionId);
static_cast<MediaPlayerInterface*>(p.get())->setAudioSink(mAudioOutput);
}
@@ -1412,9 +1415,11 @@ sp<IMemory> MediaPlayerService::snoop()
#undef LOG_TAG
#define LOG_TAG "AudioSink"
-MediaPlayerService::AudioOutput::AudioOutput()
+MediaPlayerService::AudioOutput::AudioOutput(int sessionId)
: mCallback(NULL),
- mCallbackCookie(NULL) {
+ mCallbackCookie(NULL),
+ mSessionId(sessionId) {
+ LOGV("AudioOutput(%d)", sessionId);
mTrack = 0;
mStreamType = AudioSystem::MUSIC;
mLeftVolume = 1.0;
@@ -1504,7 +1509,7 @@ status_t MediaPlayerService::AudioOutput::open(
bufferCount = mMinBufferCount;
}
- LOGV("open(%u, %d, %d, %d)", sampleRate, channelCount, format, bufferCount);
+ LOGV("open(%u, %d, %d, %d, %d)", sampleRate, channelCount, format, bufferCount,mSessionId);
if (mTrack) close();
int afSampleRate;
int afFrameCount;
@@ -1529,14 +1534,21 @@ status_t MediaPlayerService::AudioOutput::open(
frameCount,
0 /* flags */,
CallbackWrapper,
- this);
+ this,
+ 0,
+ mSessionId);
} else {
t = new AudioTrack(
mStreamType,
sampleRate,
format,
(channelCount == 2) ? AudioSystem::CHANNEL_OUT_STEREO : AudioSystem::CHANNEL_OUT_MONO,
- frameCount);
+ frameCount,
+ 0,
+ NULL,
+ NULL,
+ 0,
+ mSessionId);
}
if ((t == 0) || (t->initCheck() != NO_ERROR)) {
diff --git a/media/libmediaplayerservice/MediaPlayerService.h b/media/libmediaplayerservice/MediaPlayerService.h
index 2408c62..60b91c6 100644
--- a/media/libmediaplayerservice/MediaPlayerService.h
+++ b/media/libmediaplayerservice/MediaPlayerService.h
@@ -65,7 +65,7 @@ class MediaPlayerService : public BnMediaPlayerService
class AudioOutput : public MediaPlayerBase::AudioSink
{
public:
- AudioOutput();
+ AudioOutput(int sessionId);
virtual ~AudioOutput();
virtual bool ready() const { return mTrack != NULL; }
@@ -108,6 +108,7 @@ class MediaPlayerService : public BnMediaPlayerService
float mRightVolume;
float mMsecsPerFrame;
uint32_t mLatency;
+ int mSessionId;
static bool mIsOnEmulator;
static int mMinBufferCount; // 12 for emulator; otherwise 4
@@ -185,9 +186,9 @@ public:
// House keeping for media player clients
virtual sp<IMediaPlayer> create(
pid_t pid, const sp<IMediaPlayerClient>& client, const char* url,
- const KeyedVector<String8, String8> *headers);
+ const KeyedVector<String8, String8> *headers, int audioSessionId);
- virtual sp<IMediaPlayer> create(pid_t pid, const sp<IMediaPlayerClient>& client, int fd, int64_t offset, int64_t length);
+ virtual sp<IMediaPlayer> create(pid_t pid, const sp<IMediaPlayerClient>& client, int fd, int64_t offset, int64_t length, int audioSessionId);
virtual sp<IMemory> decode(const char* url, uint32_t *pSampleRate, int* pNumChannels, int* pFormat);
virtual sp<IMemory> decode(int fd, int64_t offset, int64_t length, uint32_t *pSampleRate, int* pNumChannels, int* pFormat);
virtual sp<IMemory> snoop();
@@ -237,12 +238,15 @@ private:
pid_t pid() const { return mPid; }
virtual status_t dump(int fd, const Vector<String16>& args) const;
+ int getAudioSessionId() { return mAudioSessionId; }
+
private:
friend class MediaPlayerService;
Client( const sp<MediaPlayerService>& service,
pid_t pid,
int32_t connId,
- const sp<IMediaPlayerClient>& client);
+ const sp<IMediaPlayerClient>& client,
+ int audioSessionId);
Client();
virtual ~Client();
@@ -271,6 +275,7 @@ private:
status_t mStatus;
bool mLoop;
int32_t mConnId;
+ int mAudioSessionId;
// Metadata filters.
media::Metadata::Filter mMetadataAllow; // protected by mLock