diff options
Diffstat (limited to 'include/media/MediaPlayerInterface.h')
-rw-r--r-- | include/media/MediaPlayerInterface.h | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/include/media/MediaPlayerInterface.h b/include/media/MediaPlayerInterface.h index 4810b7eef4..875c6b685c 100644 --- a/include/media/MediaPlayerInterface.h +++ b/include/media/MediaPlayerInterface.h @@ -65,14 +65,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)(void* cookie, - 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: @@ -144,7 +147,7 @@ public: virtual String8 getParameters(const String8& /* keys */) { return String8::empty(); } }; - MediaPlayerBase() : mCookie(0), mNotify(0) {} + MediaPlayerBase() {} virtual ~MediaPlayerBase() {} virtual status_t initCheck() = 0; virtual bool hardwareOutput() = 0; @@ -245,22 +248,22 @@ public: }; void setNotifyCallback( - void* cookie, notify_callback_f notifyFunc) { + const sp<Listener> &listener) { Mutex::Autolock autoLock(mNotifyLock); - mCookie = cookie; mNotify = notifyFunc; + mListener = listener; } void sendEvent(int msg, int ext1=0, int ext2=0, const Parcel *obj=NULL) { - notify_callback_f notifyCB; - void* cookie; + sp<Listener> listener; { Mutex::Autolock autoLock(mNotifyLock); - notifyCB = mNotify; - cookie = mCookie; + listener = mListener; } - if (notifyCB) notifyCB(cookie, msg, ext1, ext2, obj); + if (listener != NULL) { + listener->notify(msg, ext1, ext2, obj); + } } virtual status_t dump(int /* fd */, const Vector<String16>& /* args */) const { @@ -279,8 +282,7 @@ private: friend class MediaPlayerService; Mutex mNotifyLock; - void* mCookie; - notify_callback_f mNotify; + sp<Listener> mListener; }; // Implement this class for media players that use the AudioFlinger software mixer |