Loading media/libmediaplayerservice/MediaPlayerFactory.cpp +2 −3 Original line number Diff line number Diff line Loading @@ -126,8 +126,7 @@ player_type MediaPlayerFactory::getPlayerType(const sp<IMediaPlayer>& client, sp<MediaPlayerBase> MediaPlayerFactory::createPlayer( player_type playerType, const wp<IMediaPlayer> &client, notify_callback_f notifyFunc, const sp<MediaPlayerBase::Listener> &listener, pid_t pid) { sp<MediaPlayerBase> p; IFactory* factory; Loading @@ -152,7 +151,7 @@ sp<MediaPlayerBase> MediaPlayerFactory::createPlayer( init_result = p->initCheck(); if (init_result == NO_ERROR) { p->setNotifyCallback(client, notifyFunc); p->setNotifyCallback(listener); } else { ALOGE("Failed to create player object of type %d, initCheck failed" " (res = %d)", playerType, init_result); Loading media/libmediaplayerservice/MediaPlayerFactory.h +1 −2 Original line number Diff line number Diff line Loading @@ -65,8 +65,7 @@ class MediaPlayerFactory { const sp<DataSource> &source); static sp<MediaPlayerBase> createPlayer(player_type playerType, const wp<IMediaPlayer> &client, notify_callback_f notifyFunc, const sp<MediaPlayerBase::Listener> &listener, pid_t pid); static void registerBuiltinFactories(); Loading media/libmediaplayerservice/MediaPlayerService.cpp +17 −22 Original line number Diff line number Diff line Loading @@ -572,10 +572,11 @@ MediaPlayerService::Client::Client( mUid = uid; mRetransmitEndpointValid = false; mAudioAttributes = NULL; mListener = new Listener(this); #if CALLBACK_ANTAGONIZER ALOGD("create Antagonizer"); mAntagonizer = new Antagonizer(notify, this); mAntagonizer = new Antagonizer(mListener); #endif } Loading Loading @@ -610,7 +611,7 @@ void MediaPlayerService::Client::disconnect() // and reset the player. We assume the player will serialize // access to itself if necessary. if (p != 0) { p->setNotifyCallback(0, 0); p->setNotifyCallback(0); #if CALLBACK_ANTAGONIZER ALOGD("kill Antagonizer"); mAntagonizer->kill(); Loading @@ -635,7 +636,7 @@ sp<MediaPlayerBase> MediaPlayerService::Client::createPlayer(player_type playerT p.clear(); } if (p == NULL) { p = MediaPlayerFactory::createPlayer(playerType, this, notify, mPid); p = MediaPlayerFactory::createPlayer(playerType, mListener, mPid); } if (p != NULL) { Loading Loading @@ -1421,25 +1422,19 @@ status_t MediaPlayerService::Client::getRetransmitEndpoint( } void MediaPlayerService::Client::notify( const wp<IMediaPlayer> &listener, int msg, int ext1, int ext2, const Parcel *obj) int msg, int ext1, int ext2, const Parcel *obj) { sp<IMediaPlayer> spListener = listener.promote(); if (spListener == NULL) { return; } Client* client = static_cast<Client*>(spListener.get()); sp<IMediaPlayerClient> c; sp<Client> nextClient; status_t errStartNext = NO_ERROR; { Mutex::Autolock l(client->mLock); c = client->mClient; if (msg == MEDIA_PLAYBACK_COMPLETE && client->mNextClient != NULL) { nextClient = client->mNextClient; Mutex::Autolock l(mLock); c = mClient; if (msg == MEDIA_PLAYBACK_COMPLETE && mNextClient != NULL) { nextClient = mNextClient; if (client->mAudioOutput != NULL) client->mAudioOutput->switchToNextOutput(); if (mAudioOutput != NULL) mAudioOutput->switchToNextOutput(); errStartNext = nextClient->start(); } Loading @@ -1465,17 +1460,17 @@ void MediaPlayerService::Client::notify( MEDIA_INFO_METADATA_UPDATE == ext1) { const media::Metadata::Type metadata_type = ext2; if(client->shouldDropMetadata(metadata_type)) { if(shouldDropMetadata(metadata_type)) { return; } // Update the list of metadata that have changed. getMetadata // also access mMetadataUpdated and clears it. client->addNewMetadataUpdate(metadata_type); addNewMetadataUpdate(metadata_type); } if (c != NULL) { ALOGV("[%d] notify (%p, %d, %d, %d)", client->mConnId, spListener.get(), msg, ext1, ext2); ALOGV("[%d] notify (%d, %d, %d)", mConnId, msg, ext1, ext2); c->notify(msg, ext1, ext2, obj); } } Loading Loading @@ -1569,8 +1564,8 @@ status_t MediaPlayerService::Client::enableAudioDeviceCallback(bool enabled) #if CALLBACK_ANTAGONIZER const int Antagonizer::interval = 10000; // 10 msecs Antagonizer::Antagonizer(notify_callback_f cb, const wp<IMediaPlayer> &client) : mExit(false), mActive(false), mClient(client), mCb(cb) Antagonizer::Antagonizer(const sp<MediaPlayerBase::Listener> &listener) : mExit(false), mActive(false), mListener(listener) { createThread(callbackThread, this); } Loading @@ -1590,7 +1585,7 @@ int Antagonizer::callbackThread(void* user) while (!p->mExit) { if (p->mActive) { ALOGV("send event"); p->mCb(p->mClient, 0, 0, 0); p->mListener->notify(0, 0, 0, 0); } usleep(interval); } Loading media/libmediaplayerservice/MediaPlayerService.h +40 −28 Original line number Diff line number Diff line Loading @@ -51,7 +51,7 @@ class MediaRecorderClient; #if CALLBACK_ANTAGONIZER class Antagonizer { public: Antagonizer(notify_callback_f cb, const wp<IMediaPlayer> &client); Antagonizer(const sp<MediaPlayerBase::Listener> &listener); void start() { mActive = true; } void stop() { mActive = false; } void kill(); Loading @@ -63,8 +63,7 @@ private: Condition mCondition; bool mExit; bool mActive; wp<IMediaPlayer> mClient; notify_callback_f mCb; sp<MediaPlayerBase::Listener> mListener; }; #endif Loading Loading @@ -228,7 +227,6 @@ class MediaPlayerService : public BnMediaPlayerService }; // AudioOutput public: static void instantiate(); Loading Loading @@ -377,8 +375,7 @@ private: status_t setDataSource_post(const sp<MediaPlayerBase>& p, status_t status); static void notify(const wp<IMediaPlayer> &cookie, int msg, int ext1, int ext2, const Parcel *obj); void notify(int msg, int ext1, int ext2, const Parcel *obj); pid_t pid() const { return mPid; } virtual status_t dump(int fd, const Vector<String16>& args); Loading Loading @@ -468,6 +465,20 @@ private: status_t setAudioAttributes_l(const Parcel &request); class Listener : public MediaPlayerBase::Listener { public: Listener(const wp<Client> &client) : mClient(client) {} virtual ~Listener() {} virtual void notify(int msg, int ext1, int ext2, const Parcel *obj) { sp<Client> client = mClient.promote(); if (client != NULL) { client->notify(msg, ext1, ext2, obj); } } private: wp<Client> mClient; }; mutable Mutex mLock; sp<MediaPlayerBase> mPlayer; sp<MediaPlayerService> mService; Loading @@ -485,6 +496,7 @@ private: struct sockaddr_in mRetransmitEndpoint; bool mRetransmitEndpointValid; sp<Client> mNextClient; sp<MediaPlayerBase::Listener> mListener; // Metadata filters. media::Metadata::Filter mMetadataAllow; // protected by mLock Loading media/libmediaplayerservice/include/MediaPlayerInterface.h +16 −14 Original line number Diff line number Diff line Loading @@ -66,14 +66,17 @@ enum player_type { // duration below which we do not allow deep audio buffering #define AUDIO_SINK_MIN_DEEP_BUFFER_DURATION_US 5000000 // callback mechanism for passing messages to MediaPlayer object typedef void (*notify_callback_f)(const wp<IMediaPlayer> &listener, int msg, int ext1, int ext2, const Parcel *obj); // abstract base class - use MediaPlayerInterface class MediaPlayerBase : public RefBase { public: // callback mechanism for passing messages to MediaPlayer object class Listener : public RefBase { public: virtual void notify(int msg, int ext1, int ext2, const Parcel *obj) = 0; virtual ~Listener() {} }; // AudioSink: abstraction layer for audio output class AudioSink : public RefBase { public: Loading Loading @@ -157,7 +160,7 @@ public: virtual status_t enableAudioDeviceCallback(bool enabled); }; MediaPlayerBase() : mClient(0), mNotify(0) {} MediaPlayerBase() {} virtual ~MediaPlayerBase() {} virtual status_t initCheck() = 0; virtual bool hardwareOutput() = 0; Loading Loading @@ -271,22 +274,22 @@ public: }; void setNotifyCallback( const wp<IMediaPlayer> &client, notify_callback_f notifyFunc) { const sp<Listener> &listener) { Mutex::Autolock autoLock(mNotifyLock); mClient = client; mNotify = notifyFunc; mListener = listener; } void sendEvent(int msg, int ext1=0, int ext2=0, const Parcel *obj=NULL) { notify_callback_f notifyCB; wp<IMediaPlayer> client; sp<Listener> listener; { Mutex::Autolock autoLock(mNotifyLock); notifyCB = mNotify; client = mClient; listener = mListener; } if (notifyCB) notifyCB(client, msg, ext1, ext2, obj); if (listener != NULL) { listener->notify(msg, ext1, ext2, obj); } } virtual status_t dump(int /* fd */, const Vector<String16>& /* args */) const { Loading @@ -305,8 +308,7 @@ private: friend class MediaPlayerService; Mutex mNotifyLock; wp<IMediaPlayer> mClient; notify_callback_f mNotify; sp<Listener> mListener; }; // Implement this class for media players that use the AudioFlinger software mixer Loading Loading
media/libmediaplayerservice/MediaPlayerFactory.cpp +2 −3 Original line number Diff line number Diff line Loading @@ -126,8 +126,7 @@ player_type MediaPlayerFactory::getPlayerType(const sp<IMediaPlayer>& client, sp<MediaPlayerBase> MediaPlayerFactory::createPlayer( player_type playerType, const wp<IMediaPlayer> &client, notify_callback_f notifyFunc, const sp<MediaPlayerBase::Listener> &listener, pid_t pid) { sp<MediaPlayerBase> p; IFactory* factory; Loading @@ -152,7 +151,7 @@ sp<MediaPlayerBase> MediaPlayerFactory::createPlayer( init_result = p->initCheck(); if (init_result == NO_ERROR) { p->setNotifyCallback(client, notifyFunc); p->setNotifyCallback(listener); } else { ALOGE("Failed to create player object of type %d, initCheck failed" " (res = %d)", playerType, init_result); Loading
media/libmediaplayerservice/MediaPlayerFactory.h +1 −2 Original line number Diff line number Diff line Loading @@ -65,8 +65,7 @@ class MediaPlayerFactory { const sp<DataSource> &source); static sp<MediaPlayerBase> createPlayer(player_type playerType, const wp<IMediaPlayer> &client, notify_callback_f notifyFunc, const sp<MediaPlayerBase::Listener> &listener, pid_t pid); static void registerBuiltinFactories(); Loading
media/libmediaplayerservice/MediaPlayerService.cpp +17 −22 Original line number Diff line number Diff line Loading @@ -572,10 +572,11 @@ MediaPlayerService::Client::Client( mUid = uid; mRetransmitEndpointValid = false; mAudioAttributes = NULL; mListener = new Listener(this); #if CALLBACK_ANTAGONIZER ALOGD("create Antagonizer"); mAntagonizer = new Antagonizer(notify, this); mAntagonizer = new Antagonizer(mListener); #endif } Loading Loading @@ -610,7 +611,7 @@ void MediaPlayerService::Client::disconnect() // and reset the player. We assume the player will serialize // access to itself if necessary. if (p != 0) { p->setNotifyCallback(0, 0); p->setNotifyCallback(0); #if CALLBACK_ANTAGONIZER ALOGD("kill Antagonizer"); mAntagonizer->kill(); Loading @@ -635,7 +636,7 @@ sp<MediaPlayerBase> MediaPlayerService::Client::createPlayer(player_type playerT p.clear(); } if (p == NULL) { p = MediaPlayerFactory::createPlayer(playerType, this, notify, mPid); p = MediaPlayerFactory::createPlayer(playerType, mListener, mPid); } if (p != NULL) { Loading Loading @@ -1421,25 +1422,19 @@ status_t MediaPlayerService::Client::getRetransmitEndpoint( } void MediaPlayerService::Client::notify( const wp<IMediaPlayer> &listener, int msg, int ext1, int ext2, const Parcel *obj) int msg, int ext1, int ext2, const Parcel *obj) { sp<IMediaPlayer> spListener = listener.promote(); if (spListener == NULL) { return; } Client* client = static_cast<Client*>(spListener.get()); sp<IMediaPlayerClient> c; sp<Client> nextClient; status_t errStartNext = NO_ERROR; { Mutex::Autolock l(client->mLock); c = client->mClient; if (msg == MEDIA_PLAYBACK_COMPLETE && client->mNextClient != NULL) { nextClient = client->mNextClient; Mutex::Autolock l(mLock); c = mClient; if (msg == MEDIA_PLAYBACK_COMPLETE && mNextClient != NULL) { nextClient = mNextClient; if (client->mAudioOutput != NULL) client->mAudioOutput->switchToNextOutput(); if (mAudioOutput != NULL) mAudioOutput->switchToNextOutput(); errStartNext = nextClient->start(); } Loading @@ -1465,17 +1460,17 @@ void MediaPlayerService::Client::notify( MEDIA_INFO_METADATA_UPDATE == ext1) { const media::Metadata::Type metadata_type = ext2; if(client->shouldDropMetadata(metadata_type)) { if(shouldDropMetadata(metadata_type)) { return; } // Update the list of metadata that have changed. getMetadata // also access mMetadataUpdated and clears it. client->addNewMetadataUpdate(metadata_type); addNewMetadataUpdate(metadata_type); } if (c != NULL) { ALOGV("[%d] notify (%p, %d, %d, %d)", client->mConnId, spListener.get(), msg, ext1, ext2); ALOGV("[%d] notify (%d, %d, %d)", mConnId, msg, ext1, ext2); c->notify(msg, ext1, ext2, obj); } } Loading Loading @@ -1569,8 +1564,8 @@ status_t MediaPlayerService::Client::enableAudioDeviceCallback(bool enabled) #if CALLBACK_ANTAGONIZER const int Antagonizer::interval = 10000; // 10 msecs Antagonizer::Antagonizer(notify_callback_f cb, const wp<IMediaPlayer> &client) : mExit(false), mActive(false), mClient(client), mCb(cb) Antagonizer::Antagonizer(const sp<MediaPlayerBase::Listener> &listener) : mExit(false), mActive(false), mListener(listener) { createThread(callbackThread, this); } Loading @@ -1590,7 +1585,7 @@ int Antagonizer::callbackThread(void* user) while (!p->mExit) { if (p->mActive) { ALOGV("send event"); p->mCb(p->mClient, 0, 0, 0); p->mListener->notify(0, 0, 0, 0); } usleep(interval); } Loading
media/libmediaplayerservice/MediaPlayerService.h +40 −28 Original line number Diff line number Diff line Loading @@ -51,7 +51,7 @@ class MediaRecorderClient; #if CALLBACK_ANTAGONIZER class Antagonizer { public: Antagonizer(notify_callback_f cb, const wp<IMediaPlayer> &client); Antagonizer(const sp<MediaPlayerBase::Listener> &listener); void start() { mActive = true; } void stop() { mActive = false; } void kill(); Loading @@ -63,8 +63,7 @@ private: Condition mCondition; bool mExit; bool mActive; wp<IMediaPlayer> mClient; notify_callback_f mCb; sp<MediaPlayerBase::Listener> mListener; }; #endif Loading Loading @@ -228,7 +227,6 @@ class MediaPlayerService : public BnMediaPlayerService }; // AudioOutput public: static void instantiate(); Loading Loading @@ -377,8 +375,7 @@ private: status_t setDataSource_post(const sp<MediaPlayerBase>& p, status_t status); static void notify(const wp<IMediaPlayer> &cookie, int msg, int ext1, int ext2, const Parcel *obj); void notify(int msg, int ext1, int ext2, const Parcel *obj); pid_t pid() const { return mPid; } virtual status_t dump(int fd, const Vector<String16>& args); Loading Loading @@ -468,6 +465,20 @@ private: status_t setAudioAttributes_l(const Parcel &request); class Listener : public MediaPlayerBase::Listener { public: Listener(const wp<Client> &client) : mClient(client) {} virtual ~Listener() {} virtual void notify(int msg, int ext1, int ext2, const Parcel *obj) { sp<Client> client = mClient.promote(); if (client != NULL) { client->notify(msg, ext1, ext2, obj); } } private: wp<Client> mClient; }; mutable Mutex mLock; sp<MediaPlayerBase> mPlayer; sp<MediaPlayerService> mService; Loading @@ -485,6 +496,7 @@ private: struct sockaddr_in mRetransmitEndpoint; bool mRetransmitEndpointValid; sp<Client> mNextClient; sp<MediaPlayerBase::Listener> mListener; // Metadata filters. media::Metadata::Filter mMetadataAllow; // protected by mLock Loading
media/libmediaplayerservice/include/MediaPlayerInterface.h +16 −14 Original line number Diff line number Diff line Loading @@ -66,14 +66,17 @@ enum player_type { // duration below which we do not allow deep audio buffering #define AUDIO_SINK_MIN_DEEP_BUFFER_DURATION_US 5000000 // callback mechanism for passing messages to MediaPlayer object typedef void (*notify_callback_f)(const wp<IMediaPlayer> &listener, int msg, int ext1, int ext2, const Parcel *obj); // abstract base class - use MediaPlayerInterface class MediaPlayerBase : public RefBase { public: // callback mechanism for passing messages to MediaPlayer object class Listener : public RefBase { public: virtual void notify(int msg, int ext1, int ext2, const Parcel *obj) = 0; virtual ~Listener() {} }; // AudioSink: abstraction layer for audio output class AudioSink : public RefBase { public: Loading Loading @@ -157,7 +160,7 @@ public: virtual status_t enableAudioDeviceCallback(bool enabled); }; MediaPlayerBase() : mClient(0), mNotify(0) {} MediaPlayerBase() {} virtual ~MediaPlayerBase() {} virtual status_t initCheck() = 0; virtual bool hardwareOutput() = 0; Loading Loading @@ -271,22 +274,22 @@ public: }; void setNotifyCallback( const wp<IMediaPlayer> &client, notify_callback_f notifyFunc) { const sp<Listener> &listener) { Mutex::Autolock autoLock(mNotifyLock); mClient = client; mNotify = notifyFunc; mListener = listener; } void sendEvent(int msg, int ext1=0, int ext2=0, const Parcel *obj=NULL) { notify_callback_f notifyCB; wp<IMediaPlayer> client; sp<Listener> listener; { Mutex::Autolock autoLock(mNotifyLock); notifyCB = mNotify; client = mClient; listener = mListener; } if (notifyCB) notifyCB(client, msg, ext1, ext2, obj); if (listener != NULL) { listener->notify(msg, ext1, ext2, obj); } } virtual status_t dump(int /* fd */, const Vector<String16>& /* args */) const { Loading @@ -305,8 +308,7 @@ private: friend class MediaPlayerService; Mutex mNotifyLock; wp<IMediaPlayer> mClient; notify_callback_f mNotify; sp<Listener> mListener; }; // Implement this class for media players that use the AudioFlinger software mixer Loading