Loading media/libmediaplayerservice/MediaPlayerService.cpp +34 −8 Original line number Original line Diff line number Diff line Loading @@ -84,6 +84,9 @@ #include "HTTPBase.h" #include "HTTPBase.h" #include "RemoteDisplay.h" #include "RemoteDisplay.h" static const int kDumpLockRetries = 50; static const int kDumpLockSleepUs = 20000; namespace { namespace { using android::media::Metadata; using android::media::Metadata; using android::status_t; using android::status_t; Loading Loading @@ -417,12 +420,32 @@ status_t MediaPlayerService::Client::dump(int fd, const Vector<String16>& args) snprintf(buffer, 255, " pid(%d), connId(%d), status(%d), looping(%s)\n", snprintf(buffer, 255, " pid(%d), connId(%d), status(%d), looping(%s)\n", mPid, mConnId, mStatus, mLoop?"true": "false"); mPid, mConnId, mStatus, mLoop?"true": "false"); result.append(buffer); result.append(buffer); sp<MediaPlayerBase> p; sp<AudioOutput> audioOutput; bool locked = false; for (int i = 0; i < kDumpLockRetries; ++i) { if (mLock.tryLock() == NO_ERROR) { locked = true; break; } usleep(kDumpLockSleepUs); } if (locked) { p = mPlayer; audioOutput = mAudioOutput; mLock.unlock(); } else { result.append(" lock is taken, no dump from player and audio output\n"); } write(fd, result.string(), result.size()); write(fd, result.string(), result.size()); if (mPlayer != NULL) { mPlayer->dump(fd, args); if (p != NULL) { p->dump(fd, args); } } if (mAudioOutput != 0) { if (audioOutput != 0) { mAudioOutput->dump(fd, args); audioOutput->dump(fd, args); } } write(fd, "\n", 1); write(fd, "\n", 1); return NO_ERROR; return NO_ERROR; Loading Loading @@ -591,7 +614,10 @@ MediaPlayerService::Client::Client( MediaPlayerService::Client::~Client() MediaPlayerService::Client::~Client() { { ALOGV("Client(%d) destructor pid = %d", mConnId, mPid); ALOGV("Client(%d) destructor pid = %d", mConnId, mPid); { Mutex::Autolock l(mLock); mAudioOutput.clear(); mAudioOutput.clear(); } wp<Client> client(this); wp<Client> client(this); disconnect(); disconnect(); mService->removeClient(client); mService->removeClient(client); Loading @@ -610,9 +636,8 @@ void MediaPlayerService::Client::disconnect() Mutex::Autolock l(mLock); Mutex::Autolock l(mLock); p = mPlayer; p = mPlayer; mClient.clear(); mClient.clear(); } mPlayer.clear(); mPlayer.clear(); } // clear the notification to prevent callbacks to dead client // clear the notification to prevent callbacks to dead client // and reset the player. We assume the player will serialize // and reset the player. We assume the player will serialize Loading @@ -634,7 +659,7 @@ void MediaPlayerService::Client::disconnect() sp<MediaPlayerBase> MediaPlayerService::Client::createPlayer(player_type playerType) sp<MediaPlayerBase> MediaPlayerService::Client::createPlayer(player_type playerType) { { // determine if we have the right player type // determine if we have the right player type sp<MediaPlayerBase> p = mPlayer; sp<MediaPlayerBase> p = getPlayer(); if ((p != NULL) && (p->playerType() != playerType)) { if ((p != NULL) && (p->playerType() != playerType)) { ALOGV("delete player"); ALOGV("delete player"); p.clear(); p.clear(); Loading Loading @@ -691,6 +716,7 @@ void MediaPlayerService::Client::setDataSource_post( } } if (mStatus == OK) { if (mStatus == OK) { Mutex::Autolock l(mLock); mPlayer = p; mPlayer = p; } } } } Loading Loading
media/libmediaplayerservice/MediaPlayerService.cpp +34 −8 Original line number Original line Diff line number Diff line Loading @@ -84,6 +84,9 @@ #include "HTTPBase.h" #include "HTTPBase.h" #include "RemoteDisplay.h" #include "RemoteDisplay.h" static const int kDumpLockRetries = 50; static const int kDumpLockSleepUs = 20000; namespace { namespace { using android::media::Metadata; using android::media::Metadata; using android::status_t; using android::status_t; Loading Loading @@ -417,12 +420,32 @@ status_t MediaPlayerService::Client::dump(int fd, const Vector<String16>& args) snprintf(buffer, 255, " pid(%d), connId(%d), status(%d), looping(%s)\n", snprintf(buffer, 255, " pid(%d), connId(%d), status(%d), looping(%s)\n", mPid, mConnId, mStatus, mLoop?"true": "false"); mPid, mConnId, mStatus, mLoop?"true": "false"); result.append(buffer); result.append(buffer); sp<MediaPlayerBase> p; sp<AudioOutput> audioOutput; bool locked = false; for (int i = 0; i < kDumpLockRetries; ++i) { if (mLock.tryLock() == NO_ERROR) { locked = true; break; } usleep(kDumpLockSleepUs); } if (locked) { p = mPlayer; audioOutput = mAudioOutput; mLock.unlock(); } else { result.append(" lock is taken, no dump from player and audio output\n"); } write(fd, result.string(), result.size()); write(fd, result.string(), result.size()); if (mPlayer != NULL) { mPlayer->dump(fd, args); if (p != NULL) { p->dump(fd, args); } } if (mAudioOutput != 0) { if (audioOutput != 0) { mAudioOutput->dump(fd, args); audioOutput->dump(fd, args); } } write(fd, "\n", 1); write(fd, "\n", 1); return NO_ERROR; return NO_ERROR; Loading Loading @@ -591,7 +614,10 @@ MediaPlayerService::Client::Client( MediaPlayerService::Client::~Client() MediaPlayerService::Client::~Client() { { ALOGV("Client(%d) destructor pid = %d", mConnId, mPid); ALOGV("Client(%d) destructor pid = %d", mConnId, mPid); { Mutex::Autolock l(mLock); mAudioOutput.clear(); mAudioOutput.clear(); } wp<Client> client(this); wp<Client> client(this); disconnect(); disconnect(); mService->removeClient(client); mService->removeClient(client); Loading @@ -610,9 +636,8 @@ void MediaPlayerService::Client::disconnect() Mutex::Autolock l(mLock); Mutex::Autolock l(mLock); p = mPlayer; p = mPlayer; mClient.clear(); mClient.clear(); } mPlayer.clear(); mPlayer.clear(); } // clear the notification to prevent callbacks to dead client // clear the notification to prevent callbacks to dead client // and reset the player. We assume the player will serialize // and reset the player. We assume the player will serialize Loading @@ -634,7 +659,7 @@ void MediaPlayerService::Client::disconnect() sp<MediaPlayerBase> MediaPlayerService::Client::createPlayer(player_type playerType) sp<MediaPlayerBase> MediaPlayerService::Client::createPlayer(player_type playerType) { { // determine if we have the right player type // determine if we have the right player type sp<MediaPlayerBase> p = mPlayer; sp<MediaPlayerBase> p = getPlayer(); if ((p != NULL) && (p->playerType() != playerType)) { if ((p != NULL) && (p->playerType() != playerType)) { ALOGV("delete player"); ALOGV("delete player"); p.clear(); p.clear(); Loading Loading @@ -691,6 +716,7 @@ void MediaPlayerService::Client::setDataSource_post( } } if (mStatus == OK) { if (mStatus == OK) { Mutex::Autolock l(mLock); mPlayer = p; mPlayer = p; } } } } Loading