summaryrefslogtreecommitdiffstats
path: root/libvideoeditor
diff options
context:
space:
mode:
authorGlenn Kasten <gkasten@google.com>2013-05-30 14:33:29 -0700
committerGlenn Kasten <gkasten@google.com>2013-06-03 11:28:36 -0700
commit2799d743ee2ae5a25fe869a7f9c052acc029559f (patch)
tree5cab5ff06f7cae0025b93fdcd549cfb2ec72b755 /libvideoeditor
parent7c684c622110af460025eff85082030947278430 (diff)
downloadframeworks_av-2799d743ee2ae5a25fe869a7f9c052acc029559f.zip
frameworks_av-2799d743ee2ae5a25fe869a7f9c052acc029559f.tar.gz
frameworks_av-2799d743ee2ae5a25fe869a7f9c052acc029559f.tar.bz2
Use sp<AudioTrack> instead of raw AudioTrack *
This change prepares for the new implementation of AudioTrack client, which will require clients to use only sp<AudioTrack>, not raw AudioTrack *. A raw delete will cause a race condition during AudioTrack destruction. AudioTrack was made a RefBase by commit b68a91a70bc8d0d18e7404e14443d4e4020b3635 on 2011/11/15, when it was needed by OpenSL ES (for the callback protector). At that time, the only other client that was also converted from AudioTrack * to sp<AudioTrack> was android.media.AudioTrack JNI in project frameworks/base (file android_media_AudioTrack.cpp). Details: * Use .clear() instead of delete followed by = NULL. * ALOG %p need .get(). * sp<> don't need to be listed in constructor initializer, if initially 0. * Use == 0 for sp<> vs == NULL for raw pointers. * Use if (sp != 0) instead of if (raw). Change-Id: Ic7cad25795d6e862e112abdc227b6d33afdfce17
Diffstat (limited to 'libvideoeditor')
-rwxr-xr-xlibvideoeditor/lvpp/VideoEditorAudioPlayer.cpp9
-rwxr-xr-xlibvideoeditor/lvpp/VideoEditorAudioPlayer.h2
-rwxr-xr-xlibvideoeditor/lvpp/VideoEditorPlayer.cpp21
-rwxr-xr-xlibvideoeditor/lvpp/VideoEditorPlayer.h2
4 files changed, 14 insertions, 20 deletions
diff --git a/libvideoeditor/lvpp/VideoEditorAudioPlayer.cpp b/libvideoeditor/lvpp/VideoEditorAudioPlayer.cpp
index c111ba8..3fa8b87 100755
--- a/libvideoeditor/lvpp/VideoEditorAudioPlayer.cpp
+++ b/libvideoeditor/lvpp/VideoEditorAudioPlayer.cpp
@@ -35,8 +35,7 @@ namespace android {
VideoEditorAudioPlayer::VideoEditorAudioPlayer(
const sp<MediaPlayerBase::AudioSink> &audioSink,
PreviewPlayer *observer)
- : mAudioTrack(NULL),
- mInputBuffer(NULL),
+ : mInputBuffer(NULL),
mSampleRate(0),
mLatencyUs(0),
mFrameSize(0),
@@ -111,8 +110,7 @@ void VideoEditorAudioPlayer::clear() {
} else {
mAudioTrack->stop();
- delete mAudioTrack;
- mAudioTrack = NULL;
+ mAudioTrack.clear();
}
// Make sure to release any buffer we hold onto so that the
@@ -538,8 +536,7 @@ status_t VideoEditorAudioPlayer::start(bool sourceAlreadyStarted) {
0, AUDIO_OUTPUT_FLAG_NONE, &AudioCallback, this, 0);
if ((err = mAudioTrack->initCheck()) != OK) {
- delete mAudioTrack;
- mAudioTrack = NULL;
+ mAudioTrack.clear();
if (mFirstBuffer != NULL) {
mFirstBuffer->release();
diff --git a/libvideoeditor/lvpp/VideoEditorAudioPlayer.h b/libvideoeditor/lvpp/VideoEditorAudioPlayer.h
index 626df39..a5616c1 100755
--- a/libvideoeditor/lvpp/VideoEditorAudioPlayer.h
+++ b/libvideoeditor/lvpp/VideoEditorAudioPlayer.h
@@ -91,7 +91,7 @@ private:
int64_t mBGAudioStoryBoardCurrentMediaVolumeVal;
sp<MediaSource> mSource;
- AudioTrack *mAudioTrack;
+ sp<AudioTrack> mAudioTrack;
MediaBuffer *mInputBuffer;
diff --git a/libvideoeditor/lvpp/VideoEditorPlayer.cpp b/libvideoeditor/lvpp/VideoEditorPlayer.cpp
index 91a4415..4a14b40 100755
--- a/libvideoeditor/lvpp/VideoEditorPlayer.cpp
+++ b/libvideoeditor/lvpp/VideoEditorPlayer.cpp
@@ -310,7 +310,6 @@ bool VideoEditorPlayer::VeAudioOutput::mIsOnEmulator = false;
VideoEditorPlayer::VeAudioOutput::VeAudioOutput()
: mCallback(NULL),
mCallbackCookie(NULL) {
- mTrack = 0;
mStreamType = AUDIO_STREAM_MUSIC;
mLeftVolume = 1.0;
mRightVolume = 1.0;
@@ -405,7 +404,7 @@ status_t VideoEditorPlayer::VeAudioOutput::open(
}
ALOGV("open(%u, %d, %d, %d)", sampleRate, channelCount, format, bufferCount);
- if (mTrack) close();
+ if (mTrack != 0) close();
uint32_t afSampleRate;
size_t afFrameCount;
int frameCount;
@@ -434,7 +433,7 @@ status_t VideoEditorPlayer::VeAudioOutput::open(
}
}
- AudioTrack *t;
+ sp<AudioTrack> t;
if (mCallback != NULL) {
t = new AudioTrack(
mStreamType,
@@ -457,7 +456,6 @@ status_t VideoEditorPlayer::VeAudioOutput::open(
if ((t == 0) || (t->initCheck() != NO_ERROR)) {
ALOGE("Unable to create audio track");
- delete t;
return NO_INIT;
}
@@ -472,7 +470,7 @@ status_t VideoEditorPlayer::VeAudioOutput::open(
void VideoEditorPlayer::VeAudioOutput::start() {
ALOGV("start");
- if (mTrack) {
+ if (mTrack != 0) {
mTrack->setVolume(mLeftVolume, mRightVolume);
mTrack->start();
mTrack->getPosition(&mNumFramesWritten);
@@ -492,7 +490,7 @@ ssize_t VideoEditorPlayer::VeAudioOutput::write(
LOG_FATAL_IF(mCallback != NULL, "Don't call write if supplying a callback.");
//ALOGV("write(%p, %u)", buffer, size);
- if (mTrack) {
+ if (mTrack != 0) {
snoopWrite(buffer, size);
ssize_t ret = mTrack->write(buffer, size);
mNumFramesWritten += ret / 4; // assume 16 bit stereo
@@ -504,26 +502,25 @@ ssize_t VideoEditorPlayer::VeAudioOutput::write(
void VideoEditorPlayer::VeAudioOutput::stop() {
ALOGV("stop");
- if (mTrack) mTrack->stop();
+ if (mTrack != 0) mTrack->stop();
}
void VideoEditorPlayer::VeAudioOutput::flush() {
ALOGV("flush");
- if (mTrack) mTrack->flush();
+ if (mTrack != 0) mTrack->flush();
}
void VideoEditorPlayer::VeAudioOutput::pause() {
ALOGV("VeAudioOutput::pause");
- if (mTrack) mTrack->pause();
+ if (mTrack != 0) mTrack->pause();
}
void VideoEditorPlayer::VeAudioOutput::close() {
ALOGV("close");
- delete mTrack;
- mTrack = 0;
+ mTrack.clear();
}
void VideoEditorPlayer::VeAudioOutput::setVolume(float left, float right) {
@@ -531,7 +528,7 @@ void VideoEditorPlayer::VeAudioOutput::setVolume(float left, float right) {
ALOGV("setVolume(%f, %f)", left, right);
mLeftVolume = left;
mRightVolume = right;
- if (mTrack) {
+ if (mTrack != 0) {
mTrack->setVolume(left, right);
}
}
diff --git a/libvideoeditor/lvpp/VideoEditorPlayer.h b/libvideoeditor/lvpp/VideoEditorPlayer.h
index 77194ab..defc90d 100755
--- a/libvideoeditor/lvpp/VideoEditorPlayer.h
+++ b/libvideoeditor/lvpp/VideoEditorPlayer.h
@@ -71,7 +71,7 @@ class VideoEditorPlayer : public MediaPlayerInterface {
static void CallbackWrapper(
int event, void *me, void *info);
- AudioTrack* mTrack;
+ sp<AudioTrack> mTrack;
AudioCallback mCallback;
void * mCallbackCookie;
audio_stream_type_t mStreamType;