summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-03-19 23:08:54 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-19 23:08:54 -0700
commit87e445b4bed2931b9033aff68878cd4b392e1fab (patch)
tree2a6b28c0a3b73ccb81dba2d78681a63b482c5542
parent1179bc9b0e3d17c984e8f4ad38561c049dd102fa (diff)
downloadframeworks_av-87e445b4bed2931b9033aff68878cd4b392e1fab.zip
frameworks_av-87e445b4bed2931b9033aff68878cd4b392e1fab.tar.gz
frameworks_av-87e445b4bed2931b9033aff68878cd4b392e1fab.tar.bz2
auto import from //branches/cupcake_rel/...@141571
-rw-r--r--include/media/AudioRecord.h1
-rw-r--r--include/media/AudioTrack.h1
-rw-r--r--include/media/mediaplayer.h1
-rw-r--r--media/libmedia/AudioRecord.cpp9
-rw-r--r--media/libmedia/AudioTrack.cpp15
-rw-r--r--media/libmedia/JetPlayer.cpp2
-rw-r--r--media/libmedia/mediaplayer.cpp28
7 files changed, 47 insertions, 10 deletions
diff --git a/include/media/AudioRecord.h b/include/media/AudioRecord.h
index ff64855..7164b78 100644
--- a/include/media/AudioRecord.h
+++ b/include/media/AudioRecord.h
@@ -335,6 +335,7 @@ private:
uint32_t mNotificationFrames;
uint32_t mRemainingFrames;
uint32_t mMarkerPosition;
+ bool mMarkerReached;
uint32_t mNewPosition;
uint32_t mUpdatePeriod;
};
diff --git a/include/media/AudioTrack.h b/include/media/AudioTrack.h
index 659f5f8..7645978 100644
--- a/include/media/AudioTrack.h
+++ b/include/media/AudioTrack.h
@@ -409,6 +409,7 @@ private:
int mLoopCount;
uint32_t mRemainingFrames;
uint32_t mMarkerPosition;
+ bool mMarkerReached;
uint32_t mNewPosition;
uint32_t mUpdatePeriod;
};
diff --git a/include/media/mediaplayer.h b/include/media/mediaplayer.h
index 58906d1..255a67b 100644
--- a/include/media/mediaplayer.h
+++ b/include/media/mediaplayer.h
@@ -173,6 +173,7 @@ private:
};
sp<IMediaPlayer> mPlayer;
+ thread_id_t mLockThreadId;
Mutex mLock;
Mutex mNotifyLock;
Condition mSignal;
diff --git a/media/libmedia/AudioRecord.cpp b/media/libmedia/AudioRecord.cpp
index 7594ff0..5c800c3 100644
--- a/media/libmedia/AudioRecord.cpp
+++ b/media/libmedia/AudioRecord.cpp
@@ -200,6 +200,7 @@ status_t AudioRecord::set(
// TODO: add audio hardware input latency here
mLatency = (1000*mFrameCount) / mSampleRate;
mMarkerPosition = 0;
+ mMarkerReached = false;
mNewPosition = 0;
mUpdatePeriod = 0;
@@ -293,6 +294,9 @@ status_t AudioRecord::stop()
if (android_atomic_and(~1, &mActive) == 1) {
mAudioRecord->stop();
+ // the record head position will reset to 0, so if a marker is set, we need
+ // to activate it again
+ mMarkerReached = false;
if (t != 0) {
t->requestExit();
} else {
@@ -317,6 +321,7 @@ status_t AudioRecord::setMarkerPosition(uint32_t marker)
if (mCbf == 0) return INVALID_OPERATION;
mMarkerPosition = marker;
+ mMarkerReached = false;
return NO_ERROR;
}
@@ -492,10 +497,10 @@ bool AudioRecord::processAudioBuffer(const sp<ClientRecordThread>& thread)
size_t readSize;
// Manage marker callback
- if (mMarkerPosition > 0) {
+ if (!mMarkerReached && (mMarkerPosition > 0)) {
if (mCblk->user >= mMarkerPosition) {
mCbf(EVENT_MARKER, mUserData, (void *)&mMarkerPosition);
- mMarkerPosition = 0;
+ mMarkerReached = true;
}
}
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp
index 7537ddf..24f7281 100644
--- a/media/libmedia/AudioTrack.cpp
+++ b/media/libmedia/AudioTrack.cpp
@@ -259,6 +259,7 @@ status_t AudioTrack::set(
mLatency = afLatency + (1000*mFrameCount) / mSampleRate;
mLoopCount = 0;
mMarkerPosition = 0;
+ mMarkerReached = false;
mNewPosition = 0;
mUpdatePeriod = 0;
@@ -360,6 +361,9 @@ void AudioTrack::stop()
// Cancel loops (If we are in the middle of a loop, playback
// would not stop until loopCount reaches 0).
setLoop(0, 0, 0);
+ // the playback head position will reset to 0, so if a marker is set, we need
+ // to activate it again
+ mMarkerReached = false;
// Force flush if a shared buffer is used otherwise audioflinger
// will not stop before end of buffer is reached.
if (mSharedBuffer != 0) {
@@ -385,6 +389,12 @@ bool AudioTrack::stopped() const
void AudioTrack::flush()
{
LOGV("flush");
+
+ // clear playback marker and periodic update counter
+ mMarkerPosition = 0;
+ mMarkerReached = false;
+ mUpdatePeriod = 0;
+
if (!mActive) {
mAudioTrack->flush();
@@ -508,6 +518,7 @@ status_t AudioTrack::setMarkerPosition(uint32_t marker)
if (mCbf == 0) return INVALID_OPERATION;
mMarkerPosition = marker;
+ mMarkerReached = false;
return NO_ERROR;
}
@@ -755,10 +766,10 @@ bool AudioTrack::processAudioBuffer(const sp<AudioTrackThread>& thread)
}
// Manage marker callback
- if(mMarkerPosition > 0) {
+ if (!mMarkerReached && (mMarkerPosition > 0)) {
if (mCblk->server >= mMarkerPosition) {
mCbf(EVENT_MARKER, mUserData, (void *)&mMarkerPosition);
- mMarkerPosition = 0;
+ mMarkerReached = true;
}
}
diff --git a/media/libmedia/JetPlayer.cpp b/media/libmedia/JetPlayer.cpp
index 77a9013..586aacb 100644
--- a/media/libmedia/JetPlayer.cpp
+++ b/media/libmedia/JetPlayer.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#define LOG_NDEBUG 0
+//#define LOG_NDEBUG 0
#define LOG_TAG "JetPlayer-C"
#include <utils/Log.h>
diff --git a/media/libmedia/mediaplayer.cpp b/media/libmedia/mediaplayer.cpp
index 6b40412..5841922 100644
--- a/media/libmedia/mediaplayer.cpp
+++ b/media/libmedia/mediaplayer.cpp
@@ -91,6 +91,7 @@ MediaPlayer::MediaPlayer()
mLoop = false;
mLeftVolume = mRightVolume = 1.0;
mVideoWidth = mVideoHeight = 0;
+ mLockThreadId = 0;
}
void MediaPlayer::onFirstRef()
@@ -223,16 +224,24 @@ status_t MediaPlayer::prepare()
{
LOGV("prepare");
Mutex::Autolock _l(mLock);
- if (mPrepareSync) return -EALREADY;
+ mLockThreadId = getThreadId();
+ if (mPrepareSync) {
+ mLockThreadId = 0;
+ return -EALREADY;
+ }
mPrepareSync = true;
status_t ret = prepareAsync_l();
- if (ret != NO_ERROR) return ret;
+ if (ret != NO_ERROR) {
+ mLockThreadId = 0;
+ return ret;
+ }
if (mPrepareSync) {
mSignal.wait(mLock); // wait for prepare done
mPrepareSync = false;
}
LOGV("prepare complete - status=%d", mPrepareStatus);
+ mLockThreadId = 0;
return mPrepareStatus;
}
@@ -485,14 +494,23 @@ void MediaPlayer::notify(int msg, int ext1, int ext2)
{
LOGV("message received msg=%d, ext1=%d, ext2=%d", msg, ext1, ext2);
bool send = true;
+ bool locked = false;
// TODO: In the future, we might be on the same thread if the app is
// running in the same process as the media server. In that case,
// this will deadlock.
- mLock.lock();
+ //
+ // The threadId hack below works around this for the care of prepare
+ // within the same process.
+
+ if (mLockThreadId != getThreadId()) {
+ mLock.lock();
+ locked = true;
+ }
+
if (mPlayer == 0) {
LOGV("notify(%d, %d, %d) callback on disconnected mediaplayer", msg, ext1, ext2);
- mLock.unlock(); // release the lock when done.
+ if (locked) mLock.unlock(); // release the lock when done.
return;
}
@@ -561,7 +579,7 @@ void MediaPlayer::notify(int msg, int ext1, int ext2)
}
sp<MediaPlayerListener> listener = mListener;
- mLock.unlock();
+ if (locked) mLock.unlock();
// this prevents re-entrant calls into client code
if ((listener != 0) && send) {