From 2799d743ee2ae5a25fe869a7f9c052acc029559f Mon Sep 17 00:00:00 2001 From: Glenn Kasten Date: Thu, 30 May 2013 14:33:29 -0700 Subject: Use sp instead of raw AudioTrack * This change prepares for the new implementation of AudioTrack client, which will require clients to use only sp, 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 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 --- libvideoeditor/lvpp/VideoEditorAudioPlayer.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'libvideoeditor/lvpp/VideoEditorAudioPlayer.cpp') 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 &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(); -- cgit v1.1 From ad3af3305f024bcbbd55c894a4995e449498e1ba Mon Sep 17 00:00:00 2001 From: Richard Fitzgerald Date: Mon, 25 Mar 2013 16:54:37 +0000 Subject: Public API changes for audio offload support. NOTE: this does _not_ include all private member variables added to classes as part of offload support. Only public/protected functions and stubs functions/variables needed to make the changes buildable. - isOffloadSupported() added to audio policy service A stub implementation is required to build, this always returns false - setParameters() added to IAudioTrack A stub implementation is required to build, this always returns INVALID_OPERATION - CBlk flag for stream end - Change AudioSystem::getRenderPosition() to take an audio_output_t so caller can specify which output to query - Add AudioSystem::isOffloadSupported() This is fully implemented down to the AudioFlinger function AudioPolicyServer::isOffloadSupported() which is just a stub that always returns false. - Add EVENT_STREAM_END to AudioTrack interface. STREAM_END is used to signal when the hardware has actually finished playing all the data it was sent. - Add event type enumeration to media player interface AudioSink callbacks so that the same callback can be used to handle multiple types of event. For offloaded tracks we also have to handle STREAM_END and TEAR_DOWN events - Pass audio_offload_info_t to various functions used for opening outputs, tracks and audio players. This passes additional information about the compressed stream down to the HAL when using offload. For publicly-available APIs this is an optional parameter (for some of the internal and low-level APIs around the HAL interface it is mandatory) - Add getParameters() and setParameters() API to AudioTrack Currently dummy implementations. - Change AudioPlayer contructor so that it takes a set of bitflags defining what options are required. This replaces the original bool which only specified whether to use deep buffering. - Changes to StageFright class definition related to handling tearing-down of an offloaded track when we need to switch back to software decode - Define new StageFright utility functions used for offloaded tracks Currently dummy implementations. - AudioFlinger changes to use extended audio_config_t. Fills in audio_offload_info_t member if this info is passed in when opening an output. - libvideoeditor changes required to add the new event type parameter to AudioSink callback functions - libmediaplayerservice changes required to add the new event type parameter to AudioSink callback functions Change-Id: I3ab41138aa1083d81fe83b886a9b1021ec7320f1 Signed-off-by: Richard Fitzgerald Signed-off-by: Eric Laurent --- libvideoeditor/lvpp/VideoEditorAudioPlayer.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'libvideoeditor/lvpp/VideoEditorAudioPlayer.cpp') diff --git a/libvideoeditor/lvpp/VideoEditorAudioPlayer.cpp b/libvideoeditor/lvpp/VideoEditorAudioPlayer.cpp index 3fa8b87..dc360a5 100755 --- a/libvideoeditor/lvpp/VideoEditorAudioPlayer.cpp +++ b/libvideoeditor/lvpp/VideoEditorAudioPlayer.cpp @@ -575,10 +575,15 @@ void VideoEditorAudioPlayer::reset() { size_t VideoEditorAudioPlayer::AudioSinkCallback( MediaPlayerBase::AudioSink *audioSink, - void *buffer, size_t size, void *cookie) { + void *buffer, size_t size, void *cookie, + MediaPlayerBase::AudioSink::cb_event_t event) { VideoEditorAudioPlayer *me = (VideoEditorAudioPlayer *)cookie; - return me->fillBuffer(buffer, size); + if (event == MediaPlayerBase::AudioSink::CB_EVENT_FILL_BUFFER ) { + return me->fillBuffer(buffer, size); + } else { + return 0; + } } -- cgit v1.1 From 94ea60f975c3eb7ce6d2a4430538a42a5fc3babd Mon Sep 17 00:00:00 2001 From: Richard Fitzgerald Date: Tue, 14 May 2013 15:52:03 +0100 Subject: stagefright: offload playback support Offloading of compressed audio decoding to audio DSP is implemented for audio only, non streamed content. when the datasource is AudioPlayer: - Create an offloaded sink when playing a compressed source - Send metadata to audio HAL - Return sink start error to AwesomePlayer so that a new player for PCM audio can be created in case of problem. - Forward stream end and tear down callback events to AwesomePlayer - Stop the sink and wait for stream end callback when EOS is reached. - Pause and restart the sink if needed before flushing when seeking (otherwise flush is a no op). - For current media time, directly query the render position from the sink and offset by the start position (seek to time) AwesomePlayer: - When initializing the audio decoder, check with audio policy manager if offloading is supported. If yes, create the software decoder in case a reconfiguration is needed but connect the audio track directly to the AudioPlayer. - In case of error when starting the AudioPlayer, reconnect the software decoder (OMXSource) and recreate a PCM AudioPlayer. - Handle AudioPlayer tear down event by detroying and recreating the AudioPlayer to allow transitions between situations were offloading is supported or not. - Force tear down of offloaded AudioPlayer when paused for a certain time: This will close the sink and allow the DSP to power down. Utils: - Added helper methods: - send meta data to audio ia sink setParameters - query audio policy manager if offloading is supported for a given audio content Change-Id: I115842ce424f947b966d45e253a74d3fd5df9aae Signed-off-by: Eric Laurent --- libvideoeditor/lvpp/VideoEditorAudioPlayer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'libvideoeditor/lvpp/VideoEditorAudioPlayer.cpp') diff --git a/libvideoeditor/lvpp/VideoEditorAudioPlayer.cpp b/libvideoeditor/lvpp/VideoEditorAudioPlayer.cpp index dc360a5..176f8e9 100755 --- a/libvideoeditor/lvpp/VideoEditorAudioPlayer.cpp +++ b/libvideoeditor/lvpp/VideoEditorAudioPlayer.cpp @@ -149,7 +149,7 @@ void VideoEditorAudioPlayer::clear() { mStarted = false; } -void VideoEditorAudioPlayer::resume() { +status_t VideoEditorAudioPlayer::resume() { ALOGV("resume"); AudioMixSettings audioMixSettings; @@ -180,6 +180,7 @@ void VideoEditorAudioPlayer::resume() { } else { mAudioTrack->start(); } + return OK; } status_t VideoEditorAudioPlayer::seekTo(int64_t time_us) { -- cgit v1.1