Snap for 4657601 from 18cd9b58775e53b2ec1ffe571d165ad8fddfeff4 to oc-m4-release
Change-Id: I0c31b784dd0d395de8f9b6c0327b4b44b87f8ce3
diff --git a/media/libmedia/omx/1.0/WOmxNode.cpp b/media/libmedia/omx/1.0/WOmxNode.cpp
index 0b40e8d..2cd8b76 100644
--- a/media/libmedia/omx/1.0/WOmxNode.cpp
+++ b/media/libmedia/omx/1.0/WOmxNode.cpp
@@ -151,7 +151,8 @@
hidl_handle const& outNativeHandle) {
fnStatus = toStatusT(status);
*buffer = outBuffer;
- *native_handle = NativeHandle::create(
+ *native_handle = outNativeHandle.getNativeHandle() == nullptr ?
+ nullptr : NativeHandle::create(
native_handle_clone(outNativeHandle), true);
}));
return transStatus == NO_ERROR ? fnStatus : transStatus;
diff --git a/media/libmediaplayerservice/MediaPlayerFactory.cpp b/media/libmediaplayerservice/MediaPlayerFactory.cpp
index 686c059..cd0a003 100644
--- a/media/libmediaplayerservice/MediaPlayerFactory.cpp
+++ b/media/libmediaplayerservice/MediaPlayerFactory.cpp
@@ -126,7 +126,8 @@
sp<MediaPlayerBase> MediaPlayerFactory::createPlayer(
player_type playerType,
- const sp<MediaPlayerBase::Listener> &listener,
+ const wp<IMediaPlayer> &client,
+ notify_callback_f notifyFunc,
pid_t pid) {
sp<MediaPlayerBase> p;
IFactory* factory;
@@ -151,7 +152,7 @@
init_result = p->initCheck();
if (init_result == NO_ERROR) {
- p->setNotifyCallback(listener);
+ p->setNotifyCallback(client, notifyFunc);
} else {
ALOGE("Failed to create player object of type %d, initCheck failed"
" (res = %d)", playerType, init_result);
diff --git a/media/libmediaplayerservice/MediaPlayerFactory.h b/media/libmediaplayerservice/MediaPlayerFactory.h
index e88700c..6aedeb2 100644
--- a/media/libmediaplayerservice/MediaPlayerFactory.h
+++ b/media/libmediaplayerservice/MediaPlayerFactory.h
@@ -65,7 +65,8 @@
const sp<DataSource> &source);
static sp<MediaPlayerBase> createPlayer(player_type playerType,
- const sp<MediaPlayerBase::Listener> &listener,
+ const wp<IMediaPlayer> &client,
+ notify_callback_f notifyFunc,
pid_t pid);
static void registerBuiltinFactories();
diff --git a/media/libmediaplayerservice/MediaPlayerService.cpp b/media/libmediaplayerservice/MediaPlayerService.cpp
index 3445469..6e17b8d 100644
--- a/media/libmediaplayerservice/MediaPlayerService.cpp
+++ b/media/libmediaplayerservice/MediaPlayerService.cpp
@@ -590,11 +590,10 @@
mUid = uid;
mRetransmitEndpointValid = false;
mAudioAttributes = NULL;
- mListener = new Listener(this);
#if CALLBACK_ANTAGONIZER
ALOGD("create Antagonizer");
- mAntagonizer = new Antagonizer(mListener);
+ mAntagonizer = new Antagonizer(notify, this);
#endif
}
@@ -628,7 +627,7 @@
// and reset the player. We assume the player will serialize
// access to itself if necessary.
if (p != 0) {
- p->setNotifyCallback(0);
+ p->setNotifyCallback(0, 0);
#if CALLBACK_ANTAGONIZER
ALOGD("kill Antagonizer");
mAntagonizer->kill();
@@ -653,7 +652,7 @@
p.clear();
}
if (p == NULL) {
- p = MediaPlayerFactory::createPlayer(playerType, mListener, mPid);
+ p = MediaPlayerFactory::createPlayer(playerType, this, notify, mPid);
}
if (p != NULL) {
@@ -1431,19 +1430,25 @@
}
void MediaPlayerService::Client::notify(
- int msg, int ext1, int ext2, const Parcel *obj)
+ const wp<IMediaPlayer> &listener, 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(mLock);
- c = mClient;
- if (msg == MEDIA_PLAYBACK_COMPLETE && mNextClient != NULL) {
- nextClient = mNextClient;
+ Mutex::Autolock l(client->mLock);
+ c = client->mClient;
+ if (msg == MEDIA_PLAYBACK_COMPLETE && client->mNextClient != NULL) {
+ nextClient = client->mNextClient;
- if (mAudioOutput != NULL)
- mAudioOutput->switchToNextOutput();
+ if (client->mAudioOutput != NULL)
+ client->mAudioOutput->switchToNextOutput();
errStartNext = nextClient->start();
}
@@ -1469,17 +1474,17 @@
MEDIA_INFO_METADATA_UPDATE == ext1) {
const media::Metadata::Type metadata_type = ext2;
- if(shouldDropMetadata(metadata_type)) {
+ if(client->shouldDropMetadata(metadata_type)) {
return;
}
// Update the list of metadata that have changed. getMetadata
// also access mMetadataUpdated and clears it.
- addNewMetadataUpdate(metadata_type);
+ client->addNewMetadataUpdate(metadata_type);
}
if (c != NULL) {
- ALOGV("[%d] notify (%d, %d, %d)", mConnId, msg, ext1, ext2);
+ ALOGV("[%d] notify (%p, %d, %d, %d)", client->mConnId, spListener.get(), msg, ext1, ext2);
c->notify(msg, ext1, ext2, obj);
}
}
@@ -1537,8 +1542,8 @@
#if CALLBACK_ANTAGONIZER
const int Antagonizer::interval = 10000; // 10 msecs
-Antagonizer::Antagonizer(const sp<MediaPlayerBase::Listener> &listener) :
- mExit(false), mActive(false), mListener(listener)
+Antagonizer::Antagonizer(notify_callback_f cb, const wp<IMediaPlayer> &client) :
+ mExit(false), mActive(false), mClient(client), mCb(cb)
{
createThread(callbackThread, this);
}
@@ -1558,7 +1563,7 @@
while (!p->mExit) {
if (p->mActive) {
ALOGV("send event");
- p->mListener->notify(0, 0, 0, 0);
+ p->mCb(p->mClient, 0, 0, 0);
}
usleep(interval);
}
diff --git a/media/libmediaplayerservice/MediaPlayerService.h b/media/libmediaplayerservice/MediaPlayerService.h
index 34e5e2a..f043f32 100644
--- a/media/libmediaplayerservice/MediaPlayerService.h
+++ b/media/libmediaplayerservice/MediaPlayerService.h
@@ -51,7 +51,7 @@
#if CALLBACK_ANTAGONIZER
class Antagonizer {
public:
- Antagonizer(const sp<MediaPlayerBase::Listener> &listener);
+ Antagonizer(notify_callback_f cb, const wp<IMediaPlayer> &client);
void start() { mActive = true; }
void stop() { mActive = false; }
void kill();
@@ -59,11 +59,12 @@
static const int interval;
Antagonizer();
static int callbackThread(void* cookie);
- Mutex mLock;
- Condition mCondition;
- bool mExit;
- bool mActive;
- sp<MediaPlayerBase::Listener> mListener;
+ Mutex mLock;
+ Condition mCondition;
+ bool mExit;
+ bool mActive;
+ wp<IMediaPlayer> mClient;
+ notify_callback_f mCb;
};
#endif
@@ -214,6 +215,7 @@
}; // AudioOutput
+
public:
static void instantiate();
@@ -363,7 +365,8 @@
status_t setDataSource_post(const sp<MediaPlayerBase>& p,
status_t status);
- void notify(int msg, int ext1, int ext2, const Parcel *obj);
+ static void notify(const wp<IMediaPlayer> &cookie, 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);
@@ -434,38 +437,23 @@
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;
- sp<IMediaPlayerClient> mClient;
- sp<AudioOutput> mAudioOutput;
- pid_t mPid;
- status_t mStatus;
- bool mLoop;
- int32_t mConnId;
- audio_session_t mAudioSessionId;
- audio_attributes_t * mAudioAttributes;
- uid_t mUid;
- sp<ANativeWindow> mConnectedWindow;
- sp<IBinder> mConnectedWindowBinder;
- struct sockaddr_in mRetransmitEndpoint;
- bool mRetransmitEndpointValid;
- sp<Client> mNextClient;
- sp<MediaPlayerBase::Listener> mListener;
+ mutable Mutex mLock;
+ sp<MediaPlayerBase> mPlayer;
+ sp<MediaPlayerService> mService;
+ sp<IMediaPlayerClient> mClient;
+ sp<AudioOutput> mAudioOutput;
+ pid_t mPid;
+ status_t mStatus;
+ bool mLoop;
+ int32_t mConnId;
+ audio_session_t mAudioSessionId;
+ audio_attributes_t * mAudioAttributes;
+ uid_t mUid;
+ sp<ANativeWindow> mConnectedWindow;
+ sp<IBinder> mConnectedWindowBinder;
+ struct sockaddr_in mRetransmitEndpoint;
+ bool mRetransmitEndpointValid;
+ sp<Client> mNextClient;
// Metadata filters.
media::Metadata::Filter mMetadataAllow; // protected by mLock
@@ -480,7 +468,7 @@
sp<ServiceDeathNotifier> mExtractorDeathListener;
sp<ServiceDeathNotifier> mCodecDeathListener;
#if CALLBACK_ANTAGONIZER
- Antagonizer* mAntagonizer;
+ Antagonizer* mAntagonizer;
#endif
}; // Client
diff --git a/media/libmediaplayerservice/include/MediaPlayerInterface.h b/media/libmediaplayerservice/include/MediaPlayerInterface.h
index 6d02cce..34f1fe4 100644
--- a/media/libmediaplayerservice/include/MediaPlayerInterface.h
+++ b/media/libmediaplayerservice/include/MediaPlayerInterface.h
@@ -66,17 +66,14 @@
// 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:
@@ -155,7 +152,7 @@
virtual sp<VolumeShaper::State> getVolumeShaperState(int id);
};
- MediaPlayerBase() {}
+ MediaPlayerBase() : mClient(0), mNotify(0) {}
virtual ~MediaPlayerBase() {}
virtual status_t initCheck() = 0;
virtual bool hardwareOutput() = 0;
@@ -266,22 +263,22 @@
};
void setNotifyCallback(
- const sp<Listener> &listener) {
+ const wp<IMediaPlayer> &client, notify_callback_f notifyFunc) {
Mutex::Autolock autoLock(mNotifyLock);
- mListener = listener;
+ mClient = client; mNotify = notifyFunc;
}
void sendEvent(int msg, int ext1=0, int ext2=0,
const Parcel *obj=NULL) {
- sp<Listener> listener;
+ notify_callback_f notifyCB;
+ wp<IMediaPlayer> client;
{
Mutex::Autolock autoLock(mNotifyLock);
- listener = mListener;
+ notifyCB = mNotify;
+ client = mClient;
}
- if (listener != NULL) {
- listener->notify(msg, ext1, ext2, obj);
- }
+ if (notifyCB) notifyCB(client, msg, ext1, ext2, obj);
}
virtual status_t dump(int /* fd */, const Vector<String16>& /* args */) const {
@@ -300,7 +297,8 @@
friend class MediaPlayerService;
Mutex mNotifyLock;
- sp<Listener> mListener;
+ wp<IMediaPlayer> mClient;
+ notify_callback_f mNotify;
};
// Implement this class for media players that use the AudioFlinger software mixer
diff --git a/media/libstagefright/omx/1.0/WOmxNode.cpp b/media/libstagefright/omx/1.0/WOmxNode.cpp
index 9f82283..1dc7c7b 100644
--- a/media/libstagefright/omx/1.0/WOmxNode.cpp
+++ b/media/libstagefright/omx/1.0/WOmxNode.cpp
@@ -154,7 +154,8 @@
hidl_handle const& outNativeHandle) {
fnStatus = toStatusT(status);
*buffer = outBuffer;
- *native_handle = NativeHandle::create(
+ *native_handle = outNativeHandle.getNativeHandle() == nullptr ?
+ nullptr : NativeHandle::create(
native_handle_clone(outNativeHandle), true);
}));
return transStatus == NO_ERROR ? fnStatus : transStatus;