diff options
author | Eric Laurent <elaurent@google.com> | 2010-06-21 09:27:30 -0700 |
---|---|---|
committer | Eric Laurent <elaurent@google.com> | 2010-06-22 17:14:04 -0700 |
commit | a514bdb58b5de4986679f72b7204b4764f7a2778 (patch) | |
tree | 84b1ebf0c2b500bfb4995e373f8fee5b63b6c9fd /media/libmedia | |
parent | 58ae9c530247668f8af36e30d228c716c226b3d4 (diff) | |
download | frameworks_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/libmedia')
-rw-r--r-- | media/libmedia/AudioTrack.cpp | 6 | ||||
-rw-r--r-- | media/libmedia/IMediaPlayerService.cpp | 19 | ||||
-rw-r--r-- | media/libmedia/mediaplayer.cpp | 26 |
3 files changed, 42 insertions, 9 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); |