summaryrefslogtreecommitdiff
path: root/include/media
diff options
context:
space:
mode:
Diffstat (limited to 'include/media')
-rw-r--r--include/media/AudioBufferProvider.h65
-rw-r--r--include/media/AudioRecord.h133
-rw-r--r--include/media/AudioSystem.h22
-rw-r--r--include/media/AudioTrack.h18
-rw-r--r--include/media/ExtendedAudioBufferProvider.h31
-rw-r--r--include/media/IAudioFlinger.h19
-rw-r--r--include/media/IAudioPolicyService.h10
-rw-r--r--include/media/IAudioRecord.h2
-rw-r--r--include/media/ICrypto.h2
-rw-r--r--include/media/IHDCP.h78
-rw-r--r--include/media/IMediaPlayer.h1
-rw-r--r--include/media/IMediaPlayerService.h14
-rw-r--r--include/media/IRemoteDisplay.h63
-rw-r--r--include/media/IRemoteDisplayClient.h79
-rw-r--r--include/media/IStreamSource.h11
-rw-r--r--include/media/MediaPlayerInterface.h14
-rw-r--r--include/media/Visualizer.h2
-rw-r--r--include/media/mediametadataretriever.h1
-rw-r--r--include/media/mediaplayer.h3
-rw-r--r--include/media/nbaio/AudioBufferProviderSource.h57
-rw-r--r--include/media/nbaio/AudioStreamInSource.h65
-rw-r--r--include/media/nbaio/AudioStreamOutSink.h68
-rw-r--r--include/media/nbaio/LibsndfileSink.h54
-rw-r--r--include/media/nbaio/LibsndfileSource.h58
-rw-r--r--include/media/nbaio/MonoPipe.h134
-rw-r--r--include/media/nbaio/MonoPipeReader.h64
-rw-r--r--include/media/nbaio/NBAIO.h315
-rw-r--r--include/media/nbaio/Pipe.h64
-rw-r--r--include/media/nbaio/PipeReader.h65
-rw-r--r--include/media/nbaio/SourceAudioBufferProvider.h52
-rw-r--r--include/media/nbaio/roundup.h31
-rw-r--r--include/media/stagefright/ACodec.h22
-rw-r--r--include/media/stagefright/AudioSource.h11
-rw-r--r--include/media/stagefright/CameraSource.h1
-rw-r--r--include/media/stagefright/MediaCodec.h47
-rw-r--r--include/media/stagefright/MediaExtractor.h2
-rw-r--r--include/media/stagefright/MetaData.h1
-rw-r--r--include/media/stagefright/NuMediaExtractor.h2
-rw-r--r--include/media/stagefright/OMXCodec.h19
-rw-r--r--include/media/stagefright/SurfaceMediaSource.h31
-rw-r--r--include/media/stagefright/TimeSource.h2
-rw-r--r--include/media/stagefright/Utils.h2
-rw-r--r--include/media/stagefright/foundation/hexdump.h6
-rw-r--r--include/media/stagefright/timedtext/TimedTextDriver.h1
44 files changed, 1591 insertions, 151 deletions
diff --git a/include/media/AudioBufferProvider.h b/include/media/AudioBufferProvider.h
new file mode 100644
index 00000000..865ed7e2
--- /dev/null
+++ b/include/media/AudioBufferProvider.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_AUDIO_BUFFER_PROVIDER_H
+#define ANDROID_AUDIO_BUFFER_PROVIDER_H
+
+#include <utils/Errors.h>
+
+namespace android {
+// ----------------------------------------------------------------------------
+
+class AudioBufferProvider
+{
+public:
+
+ struct Buffer {
+ Buffer() : raw(NULL), frameCount(0) { }
+ union {
+ void* raw;
+ short* i16;
+ int8_t* i8;
+ };
+ size_t frameCount;
+ };
+
+protected:
+ AudioBufferProvider() : mValid(kValid) { }
+ virtual ~AudioBufferProvider() { mValid = kDead; }
+
+public:
+ // value representing an invalid presentation timestamp
+ static const int64_t kInvalidPTS = 0x7FFFFFFFFFFFFFFFLL; // <stdint.h> is too painful
+
+ // pts is the local time when the next sample yielded by getNextBuffer
+ // will be rendered.
+ // Pass kInvalidPTS if the PTS is unknown or not applicable.
+ virtual status_t getNextBuffer(Buffer* buffer, int64_t pts = kInvalidPTS) = 0;
+
+ virtual void releaseBuffer(Buffer* buffer) = 0;
+
+ int getValid() const { return mValid; }
+ static const int kValid = 'GOOD';
+ static const int kDead = 'DEAD';
+
+private:
+ int mValid;
+};
+
+// ----------------------------------------------------------------------------
+}; // namespace android
+
+#endif // ANDROID_AUDIO_BUFFER_PROVIDER_H
diff --git a/include/media/AudioRecord.h b/include/media/AudioRecord.h
index ef77692b..156c5924 100644
--- a/include/media/AudioRecord.h
+++ b/include/media/AudioRecord.h
@@ -17,22 +17,15 @@
#ifndef AUDIORECORD_H_
#define AUDIORECORD_H_
-#include <stdint.h>
-#include <sys/types.h>
-
-#include <media/IAudioFlinger.h>
+#include <binder/IMemory.h>
+#include <cutils/sched_policy.h>
+#include <media/AudioSystem.h>
#include <media/IAudioRecord.h>
-
+#include <system/audio.h>
#include <utils/RefBase.h>
#include <utils/Errors.h>
-#include <binder/IInterface.h>
-#include <binder/IMemory.h>
-#include <cutils/sched_policy.h>
#include <utils/threads.h>
-#include <system/audio.h>
-#include <media/AudioSystem.h>
-
namespace android {
class audio_track_cblk_t;
@@ -46,11 +39,10 @@ public:
static const int DEFAULT_SAMPLE_RATE = 8000;
/* Events used by AudioRecord callback function (callback_t).
- *
- * to keep in sync with frameworks/base/media/java/android/media/AudioRecord.java
+ * Keep in sync with frameworks/base/media/java/android/media/AudioRecord.java NATIVE_EVENT_*.
*/
enum event_type {
- EVENT_MORE_DATA = 0, // Request to reqd more data from PCM buffer.
+ EVENT_MORE_DATA = 0, // Request to read more data from PCM buffer.
EVENT_OVERRUN = 1, // PCM buffer overrun occured.
EVENT_MARKER = 2, // Record head is at the specified marker position
// (See setMarkerPosition()).
@@ -72,7 +64,7 @@ public:
int channelCount;
audio_format_t format;
size_t frameCount;
- size_t size;
+ size_t size; // total size in bytes == frameCount * frameSize
union {
void* raw;
short* i16;
@@ -80,12 +72,6 @@ public:
};
};
- /* These are static methods to control the system-wide AudioFlinger
- * only privileged processes can have access to them
- */
-
-// static status_t setMasterMute(bool mute);
-
/* As a convenience, if a callback is supplied, a handler thread
* is automatically created with the appropriate priority. This thread
* invokes the callback when a new buffer becomes ready or an overrun condition occurs.
@@ -98,8 +84,8 @@ public:
* more bytes than indicated by 'size' field and update 'size' if less bytes are
* read.
* - EVENT_OVERRUN: unused.
- * - EVENT_MARKER: pointer to an uin32_t containing the marker position in frames.
- * - EVENT_NEW_POS: pointer to an uin32_t containing the new position in frames.
+ * - EVENT_MARKER: pointer to const uint32_t containing the marker position in frames.
+ * - EVENT_NEW_POS: pointer to const uint32_t containing the new position in frames.
*/
typedef void (*callback_t)(int event, void* user, void *info);
@@ -115,7 +101,7 @@ public:
static status_t getMinFrameCount(int* frameCount,
uint32_t sampleRate,
audio_format_t format,
- int channelCount);
+ audio_channel_mask_t channelMask);
/* Constructs an uninitialized AudioRecord. No connection with
* AudioFlinger takes place.
@@ -133,32 +119,22 @@ public:
* sampleRate: Track sampling rate in Hz.
* format: Audio format (e.g AUDIO_FORMAT_PCM_16_BIT for signed
* 16 bits per sample).
- * channelMask: Channel mask: see audio_channels_t.
+ * channelMask: Channel mask.
* frameCount: Total size of track PCM buffer in frames. This defines the
* latency of the track.
- * flags: A bitmask of acoustic values from enum record_flags. It enables
- * AGC, NS, and IIR.
* cbf: Callback function. If not null, this function is called periodically
* to provide new PCM data.
+ * user: Context for use by the callback receiver.
* notificationFrames: The callback function is called each time notificationFrames PCM
* frames are ready in record track output buffer.
- * user Context for use by the callback receiver.
+ * sessionId: Not yet supported.
*/
- // FIXME consider removing this alias and replacing it by audio_in_acoustics_t
- // or removing the parameter entirely if it is unused
- enum record_flags {
- RECORD_AGC_ENABLE = AUDIO_IN_ACOUSTICS_AGC_ENABLE,
- RECORD_NS_ENABLE = AUDIO_IN_ACOUSTICS_NS_ENABLE,
- RECORD_IIR_ENABLE = AUDIO_IN_ACOUSTICS_TX_IIR_ENABLE,
- };
-
AudioRecord(audio_source_t inputSource,
uint32_t sampleRate = 0,
audio_format_t format = AUDIO_FORMAT_DEFAULT,
- uint32_t channelMask = AUDIO_CHANNEL_IN_MONO,
+ audio_channel_mask_t channelMask = AUDIO_CHANNEL_IN_MONO,
int frameCount = 0,
- record_flags flags = (record_flags) 0,
callback_t cbf = NULL,
void* user = NULL,
int notificationFrames = 0,
@@ -166,7 +142,7 @@ public:
/* Terminates the AudioRecord and unregisters it from AudioFlinger.
- * Also destroys all resources assotiated with the AudioRecord.
+ * Also destroys all resources associated with the AudioRecord.
*/
~AudioRecord();
@@ -182,9 +158,8 @@ public:
status_t set(audio_source_t inputSource = AUDIO_SOURCE_DEFAULT,
uint32_t sampleRate = 0,
audio_format_t format = AUDIO_FORMAT_DEFAULT,
- uint32_t channelMask = AUDIO_CHANNEL_IN_MONO,
+ audio_channel_mask_t channelMask = AUDIO_CHANNEL_IN_MONO,
int frameCount = 0,
- record_flags flags = (record_flags) 0,
callback_t cbf = NULL,
void* user = NULL,
int notificationFrames = 0,
@@ -205,11 +180,10 @@ public:
*/
uint32_t latency() const;
- /* getters, see constructor */
+ /* getters, see constructor and set() */
audio_format_t format() const;
int channelCount() const;
- int channels() const;
uint32_t frameCount() const;
size_t frameSize() const;
audio_source_t inputSource() const;
@@ -227,7 +201,7 @@ public:
* obtainBuffer returns STOPPED. Note that obtainBuffer() still works
* and will fill up buffers until the pool is exhausted.
*/
- status_t stop();
+ void stop();
bool stopped() const;
/* get sample rate for this record track
@@ -271,7 +245,7 @@ public:
status_t getPositionUpdatePeriod(uint32_t *updatePeriod) const;
- /* Gets record head position. The position is the total number of frames
+ /* Gets record head position. The position is the total number of frames
* recorded since record start.
*
* Parameters:
@@ -294,7 +268,7 @@ public:
*/
audio_io_handle_t getInput() const;
- /* returns the audio session ID associated to this AudioRecord.
+ /* returns the audio session ID associated with this AudioRecord.
*
* Parameters:
* none.
@@ -342,57 +316,72 @@ private:
AudioRecord& operator = (const AudioRecord& other);
/* a small internal class to handle the callback */
- class ClientRecordThread : public Thread
+ class AudioRecordThread : public Thread
{
public:
- ClientRecordThread(AudioRecord& receiver, bool bCanCallJava = false);
+ AudioRecordThread(AudioRecord& receiver, bool bCanCallJava = false);
+
+ // Do not call Thread::requestExitAndWait() without first calling requestExit().
+ // Thread::requestExitAndWait() is not virtual, and the implementation doesn't do enough.
+ virtual void requestExit();
+
+ void pause(); // suspend thread from execution at next loop boundary
+ void resume(); // allow thread to execute, if not requested to exit
+
private:
friend class AudioRecord;
virtual bool threadLoop();
- virtual status_t readyToRun();
- virtual void onFirstRef() {}
AudioRecord& mReceiver;
+ virtual ~AudioRecordThread();
+ Mutex mMyLock; // Thread::mLock is private
+ Condition mMyCond; // Thread::mThreadExitedCondition is private
+ bool mPaused; // whether thread is currently paused
};
- bool processAudioBuffer(const sp<ClientRecordThread>& thread);
+ // body of AudioRecordThread::threadLoop()
+ bool processAudioBuffer(const sp<AudioRecordThread>& thread);
+
status_t openRecord_l(uint32_t sampleRate,
audio_format_t format,
- uint32_t channelMask,
+ audio_channel_mask_t channelMask,
int frameCount,
audio_io_handle_t input);
audio_io_handle_t getInput_l();
status_t restoreRecord_l(audio_track_cblk_t*& cblk);
- sp<IAudioRecord> mAudioRecord;
- sp<IMemory> mCblkMemory;
- sp<ClientRecordThread> mClientRecordThread;
- status_t mReadyToRun;
+ sp<AudioRecordThread> mAudioRecordThread;
mutable Mutex mLock;
- Condition mCondition;
- uint32_t mFrameCount;
+ bool mActive; // protected by mLock
- audio_track_cblk_t* mCblk;
+ // for client callback handler
+ callback_t mCbf;
+ void* mUserData;
+
+ // for notification APIs
+ uint32_t mNotificationFrames;
+ uint32_t mRemainingFrames;
+ uint32_t mMarkerPosition; // in frames
+ bool mMarkerReached;
+ uint32_t mNewPosition; // in frames
+ uint32_t mUpdatePeriod; // in ms
+
+ // constant after constructor or set()
+ uint32_t mFrameCount;
audio_format_t mFormat;
uint8_t mChannelCount;
audio_source_t mInputSource;
status_t mStatus;
uint32_t mLatency;
+ audio_channel_mask_t mChannelMask;
+ audio_io_handle_t mInput; // returned by AudioSystem::getInput()
+ int mSessionId;
- volatile int32_t mActive;
+ // may be changed if IAudioRecord object is re-created
+ sp<IAudioRecord> mAudioRecord;
+ sp<IMemory> mCblkMemory;
+ audio_track_cblk_t* mCblk;
- callback_t mCbf;
- void* mUserData;
- uint32_t mNotificationFrames;
- uint32_t mRemainingFrames;
- uint32_t mMarkerPosition;
- bool mMarkerReached;
- uint32_t mNewPosition;
- uint32_t mUpdatePeriod;
- record_flags mFlags;
- uint32_t mChannelMask;
- audio_io_handle_t mInput;
- int mSessionId;
int mPreviousPriority; // before start()
SchedPolicy mPreviousSchedulingGroup;
};
diff --git a/include/media/AudioSystem.h b/include/media/AudioSystem.h
index e2662f27..49e1afcb 100644
--- a/include/media/AudioSystem.h
+++ b/include/media/AudioSystem.h
@@ -70,6 +70,8 @@ public:
// returns true in *state if tracks are active on the specified stream or has been active
// in the past inPastMs milliseconds
static status_t isStreamActive(audio_stream_type_t stream, bool *state, uint32_t inPastMs = 0);
+ // returns true in *state if a recorder is currently recording with the specified source
+ static status_t isSourceActive(audio_source_t source, bool *state);
// set/get audio hardware parameters. The function accepts a list of parameters
// key value pairs in the form: key1=value1;key2=value2;...
@@ -110,8 +112,8 @@ public:
static bool routedToA2dpOutput(audio_stream_type_t streamType);
- static status_t getInputBufferSize(uint32_t sampleRate, audio_format_t format, int channelCount,
- size_t* buffSize);
+ static status_t getInputBufferSize(uint32_t sampleRate, audio_format_t format,
+ audio_channel_mask_t channelMask, size_t* buffSize);
static status_t setVoiceVolume(float volume);
@@ -126,6 +128,7 @@ public:
// necessary to check returned status before using the returned values.
static status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames, audio_stream_type_t stream = AUDIO_STREAM_DEFAULT);
+ // return the number of input frames lost by HAL implementation, or 0 if the handle is invalid
static unsigned int getInputFramesLost(audio_io_handle_t ioHandle);
static int newAudioSessionId();
@@ -188,7 +191,7 @@ public:
static audio_io_handle_t getOutput(audio_stream_type_t stream,
uint32_t samplingRate = 0,
audio_format_t format = AUDIO_FORMAT_DEFAULT,
- uint32_t channels = AUDIO_CHANNEL_OUT_STEREO,
+ audio_channel_mask_t channelMask = AUDIO_CHANNEL_OUT_STEREO,
audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE);
static status_t startOutput(audio_io_handle_t output,
audio_stream_type_t stream,
@@ -200,8 +203,7 @@ public:
static audio_io_handle_t getInput(audio_source_t inputSource,
uint32_t samplingRate = 0,
audio_format_t format = AUDIO_FORMAT_DEFAULT,
- uint32_t channels = AUDIO_CHANNEL_IN_MONO,
- audio_in_acoustics_t acoustics = (audio_in_acoustics_t)0,
+ audio_channel_mask_t channelMask = AUDIO_CHANNEL_IN_MONO,
int sessionId = 0);
static status_t startInput(audio_io_handle_t input);
static status_t stopInput(audio_io_handle_t input);
@@ -219,8 +221,8 @@ public:
static uint32_t getStrategyForStream(audio_stream_type_t stream);
static audio_devices_t getDevicesForStream(audio_stream_type_t stream);
- static audio_io_handle_t getOutputForEffect(effect_descriptor_t *desc);
- static status_t registerEffect(effect_descriptor_t *desc,
+ static audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc);
+ static status_t registerEffect(const effect_descriptor_t *desc,
audio_io_handle_t io,
uint32_t strategy,
int session,
@@ -234,6 +236,10 @@ public:
static const sp<IAudioPolicyService>& get_audio_policy_service();
+ // helpers for android.media.AudioManager.getProperty(), see description there for meaning
+ static int32_t getPrimaryOutputSamplingRate();
+ static int32_t getPrimaryOutputFrameCount();
+
// ----------------------------------------------------------------------------
private:
@@ -277,7 +283,7 @@ private:
// previous parameters for recording buffer size queries
static uint32_t gPrevInSamplingRate;
static audio_format_t gPrevInFormat;
- static int gPrevInChannelCount;
+ static audio_channel_mask_t gPrevInChannelMask;
static sp<IAudioPolicyService> gAudioPolicyService;
diff --git a/include/media/AudioTrack.h b/include/media/AudioTrack.h
index 639d6d22..34108b38 100644
--- a/include/media/AudioTrack.h
+++ b/include/media/AudioTrack.h
@@ -135,7 +135,7 @@ public:
* sampleRate: Track sampling rate in Hz.
* format: Audio format (e.g AUDIO_FORMAT_PCM_16_BIT for signed
* 16 bits per sample).
- * channelMask: Channel mask: see audio_channels_t.
+ * channelMask: Channel mask.
* frameCount: Minimum size of track PCM buffer in frames. This defines the
* latency of the track. The actual size selected by the AudioTrack could be
* larger if the requested size is not compatible with current audio HAL
@@ -154,7 +154,7 @@ public:
AudioTrack( audio_stream_type_t streamType,
uint32_t sampleRate = 0,
audio_format_t format = AUDIO_FORMAT_DEFAULT,
- int channelMask = 0,
+ audio_channel_mask_t channelMask = 0,
int frameCount = 0,
audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE,
callback_t cbf = NULL,
@@ -186,7 +186,7 @@ public:
AudioTrack( audio_stream_type_t streamType,
uint32_t sampleRate = 0,
audio_format_t format = AUDIO_FORMAT_DEFAULT,
- int channelMask = 0,
+ audio_channel_mask_t channelMask = 0,
const sp<IMemory>& sharedBuffer = 0,
audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE,
callback_t cbf = NULL,
@@ -204,13 +204,13 @@ public:
* Returned status (from utils/Errors.h) can be:
* - NO_ERROR: successful initialization
* - INVALID_OPERATION: AudioTrack is already initialized
- * - BAD_VALUE: invalid parameter (channels, format, sampleRate...)
+ * - BAD_VALUE: invalid parameter (channelMask, format, sampleRate...)
* - NO_INIT: audio server or audio hardware not initialized
* */
status_t set(audio_stream_type_t streamType = AUDIO_STREAM_DEFAULT,
uint32_t sampleRate = 0,
audio_format_t format = AUDIO_FORMAT_DEFAULT,
- int channelMask = 0,
+ audio_channel_mask_t channelMask = 0,
int frameCount = 0,
audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE,
callback_t cbf = NULL,
@@ -472,8 +472,6 @@ protected:
private:
friend class AudioTrack;
virtual bool threadLoop();
- virtual status_t readyToRun();
- virtual void onFirstRef();
AudioTrack& mReceiver;
~AudioTrackThread();
Mutex mMyLock; // Thread::mLock is private
@@ -487,7 +485,7 @@ protected:
status_t createTrack_l(audio_stream_type_t streamType,
uint32_t sampleRate,
audio_format_t format,
- uint32_t channelMask,
+ audio_channel_mask_t channelMask,
int frameCount,
audio_output_flags_t flags,
const sp<IMemory>& sharedBuffer,
@@ -512,7 +510,7 @@ protected:
uint8_t mChannelCount;
uint8_t mMuted;
uint8_t mReserved;
- uint32_t mChannelMask;
+ audio_channel_mask_t mChannelMask;
status_t mStatus;
uint32_t mLatency;
@@ -549,7 +547,7 @@ public:
status_t allocateTimedBuffer(size_t size, sp<IMemory>* buffer);
/* queue a buffer obtained via allocateTimedBuffer for playback at the
- given timestamp. PTS units a microseconds on the media time timeline.
+ given timestamp. PTS units are microseconds on the media time timeline.
The media time transform (set with setMediaTimeTransform) set by the
audio producer will handle converting from media time to local time
(perhaps going through the common time timeline in the case of
diff --git a/include/media/ExtendedAudioBufferProvider.h b/include/media/ExtendedAudioBufferProvider.h
new file mode 100644
index 00000000..00c4444f
--- /dev/null
+++ b/include/media/ExtendedAudioBufferProvider.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_EXTENDED_AUDIO_BUFFER_PROVIDER_H
+#define ANDROID_EXTENDED_AUDIO_BUFFER_PROVIDER_H
+
+#include <media/AudioBufferProvider.h>
+
+namespace android {
+
+class ExtendedAudioBufferProvider : public AudioBufferProvider {
+public:
+ virtual size_t framesReady() const = 0; // see description at AudioFlinger.h
+};
+
+} // namespace android
+
+#endif // ANDROID_EXTENDED_AUDIO_BUFFER_PROVIDER_H
diff --git a/include/media/IAudioFlinger.h b/include/media/IAudioFlinger.h
index 86e228bf..5170a87e 100644
--- a/include/media/IAudioFlinger.h
+++ b/include/media/IAudioFlinger.h
@@ -48,7 +48,7 @@ public:
enum {
TRACK_DEFAULT = 0, // client requests a default AudioTrack
TRACK_TIMED = 1, // client requests a TimedAudioTrack
- TRACK_FAST = 2, // client requests a fast AudioTrack
+ TRACK_FAST = 2, // client requests a fast AudioTrack or AudioRecord
};
typedef uint32_t track_flags_t;
@@ -60,7 +60,7 @@ public:
audio_stream_type_t streamType,
uint32_t sampleRate,
audio_format_t format,
- uint32_t channelMask,
+ audio_channel_mask_t channelMask,
int frameCount,
track_flags_t flags,
const sp<IMemory>& sharedBuffer,
@@ -74,9 +74,10 @@ public:
audio_io_handle_t input,
uint32_t sampleRate,
audio_format_t format,
- uint32_t channelMask,
+ audio_channel_mask_t channelMask,
int frameCount,
track_flags_t flags,
+ pid_t tid, // -1 means unused, otherwise must be valid non-0
int *sessionId,
status_t *status) = 0;
@@ -84,7 +85,9 @@ public:
* and therefore can be cached.
*/
virtual uint32_t sampleRate(audio_io_handle_t output) const = 0;
+#if 0
virtual int channelCount(audio_io_handle_t output) const = 0;
+#endif
virtual audio_format_t format(audio_io_handle_t output) const = 0;
virtual size_t frameCount(audio_io_handle_t output) const = 0;
@@ -126,7 +129,8 @@ public:
virtual void registerClient(const sp<IAudioFlingerClient>& client) = 0;
// retrieve the audio recording buffer size
- virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format, int channelCount) const = 0;
+ virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format,
+ audio_channel_mask_t channelMask) const = 0;
virtual audio_io_handle_t openOutput(audio_module_handle_t module,
audio_devices_t *pDevices,
@@ -183,6 +187,13 @@ public:
audio_io_handle_t dstOutput) = 0;
virtual audio_module_handle_t loadHwModule(const char *name) = 0;
+
+ // helpers for android.media.AudioManager.getProperty(), see description there for meaning
+ // FIXME move these APIs to AudioPolicy to permit a more accurate implementation
+ // that looks on primary device for a stream with fast flag, primary flag, or first one.
+ virtual int32_t getPrimaryOutputSamplingRate() = 0;
+ virtual int32_t getPrimaryOutputFrameCount() = 0;
+
};
diff --git a/include/media/IAudioPolicyService.h b/include/media/IAudioPolicyService.h
index e160d70e..cc2e0692 100644
--- a/include/media/IAudioPolicyService.h
+++ b/include/media/IAudioPolicyService.h
@@ -51,7 +51,7 @@ public:
virtual audio_io_handle_t getOutput(audio_stream_type_t stream,
uint32_t samplingRate = 0,
audio_format_t format = AUDIO_FORMAT_DEFAULT,
- uint32_t channels = 0,
+ audio_channel_mask_t channelMask = 0,
audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE) = 0;
virtual status_t startOutput(audio_io_handle_t output,
audio_stream_type_t stream,
@@ -63,8 +63,7 @@ public:
virtual audio_io_handle_t getInput(audio_source_t inputSource,
uint32_t samplingRate = 0,
audio_format_t format = AUDIO_FORMAT_DEFAULT,
- uint32_t channels = 0,
- audio_in_acoustics_t acoustics = (audio_in_acoustics_t)0,
+ audio_channel_mask_t channelMask = 0,
int audioSession = 0) = 0;
virtual status_t startInput(audio_io_handle_t input) = 0;
virtual status_t stopInput(audio_io_handle_t input) = 0;
@@ -80,8 +79,8 @@ public:
audio_devices_t device) = 0;
virtual uint32_t getStrategyForStream(audio_stream_type_t stream) = 0;
virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream) = 0;
- virtual audio_io_handle_t getOutputForEffect(effect_descriptor_t *desc) = 0;
- virtual status_t registerEffect(effect_descriptor_t *desc,
+ virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc) = 0;
+ virtual status_t registerEffect(const effect_descriptor_t *desc,
audio_io_handle_t io,
uint32_t strategy,
int session,
@@ -89,6 +88,7 @@ public:
virtual status_t unregisterEffect(int id) = 0;
virtual status_t setEffectEnabled(int id, bool enabled) = 0;
virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs = 0) const = 0;
+ virtual bool isSourceActive(audio_source_t source) const = 0;
virtual status_t queryDefaultPreProcessing(int audioSession,
effect_descriptor_t *descriptors,
uint32_t *count) = 0;
diff --git a/include/media/IAudioRecord.h b/include/media/IAudioRecord.h
index ebc03eaa..d6e3141c 100644
--- a/include/media/IAudioRecord.h
+++ b/include/media/IAudioRecord.h
@@ -37,7 +37,7 @@ public:
/* After it's created the track is not active. Call start() to
* make it active.
*/
- virtual status_t start(int event, int triggerSession) = 0;
+ virtual status_t start(int /*AudioSystem::sync_event_t*/ event, int triggerSession) = 0;
/* Stop a track. If set, the callback will cease being called and
* obtainBuffer will return an error. Buffers that are already released
diff --git a/include/media/ICrypto.h b/include/media/ICrypto.h
index 32a2cf77..61059bde 100644
--- a/include/media/ICrypto.h
+++ b/include/media/ICrypto.h
@@ -41,7 +41,7 @@ struct ICrypto : public IInterface {
virtual bool requiresSecureDecoderComponent(
const char *mime) const = 0;
- virtual status_t decrypt(
+ virtual ssize_t decrypt(
bool secure,
const uint8_t key[16],
const uint8_t iv[16],
diff --git a/include/media/IHDCP.h b/include/media/IHDCP.h
new file mode 100644
index 00000000..a0613c7a
--- /dev/null
+++ b/include/media/IHDCP.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <binder/IInterface.h>
+#include <media/hardware/HDCPAPI.h>
+#include <media/stagefright/foundation/ABase.h>
+
+namespace android {
+
+struct IHDCPObserver : public IInterface {
+ DECLARE_META_INTERFACE(HDCPObserver);
+
+ virtual void notify(
+ int msg, int ext1, int ext2, const Parcel *obj) = 0;
+
+private:
+ DISALLOW_EVIL_CONSTRUCTORS(IHDCPObserver);
+};
+
+struct IHDCP : public IInterface {
+ DECLARE_META_INTERFACE(HDCP);
+
+ // Called to specify the observer that receives asynchronous notifications
+ // from the HDCP implementation to signal completion/failure of asynchronous
+ // operations (such as initialization) or out of band events.
+ virtual status_t setObserver(const sp<IHDCPObserver> &observer) = 0;
+
+ // Request to setup an HDCP session with the specified host listening
+ // on the specified port.
+ virtual status_t initAsync(const char *host, unsigned port) = 0;
+
+ // Request to shutdown the active HDCP session.
+ virtual status_t shutdownAsync() = 0;
+
+ // Encrypt a data according to the HDCP spec. The data is to be
+ // encrypted in-place, only size bytes of data should be read/write,
+ // even if the size is not a multiple of 128 bit (16 bytes).
+ // This operation is to be synchronous, i.e. this call does not return
+ // until outData contains size bytes of encrypted data.
+ // streamCTR will be assigned by the caller (to 0 for the first PES stream,
+ // 1 for the second and so on)
+ // inputCTR will be maintained by the callee for each PES stream.
+ virtual status_t encrypt(
+ const void *inData, size_t size, uint32_t streamCTR,
+ uint64_t *outInputCTR, void *outData) = 0;
+
+private:
+ DISALLOW_EVIL_CONSTRUCTORS(IHDCP);
+};
+
+struct BnHDCPObserver : public BnInterface<IHDCPObserver> {
+ virtual status_t onTransact(
+ uint32_t code, const Parcel &data, Parcel *reply,
+ uint32_t flags = 0);
+};
+
+struct BnHDCP : public BnInterface<IHDCP> {
+ virtual status_t onTransact(
+ uint32_t code, const Parcel &data, Parcel *reply,
+ uint32_t flags = 0);
+};
+
+} // namespace android
+
+
diff --git a/include/media/IMediaPlayer.h b/include/media/IMediaPlayer.h
index 00facc5a..4ed18634 100644
--- a/include/media/IMediaPlayer.h
+++ b/include/media/IMediaPlayer.h
@@ -64,6 +64,7 @@ public:
virtual status_t setParameter(int key, const Parcel& request) = 0;
virtual status_t getParameter(int key, Parcel* reply) = 0;
virtual status_t setRetransmitEndpoint(const struct sockaddr_in* endpoint) = 0;
+ virtual status_t getRetransmitEndpoint(struct sockaddr_in* endpoint) = 0;
virtual status_t setNextPlayer(const sp<IMediaPlayer>& next) = 0;
// Invoke a generic method on the player by using opaque parcels
diff --git a/include/media/IMediaPlayerService.h b/include/media/IMediaPlayerService.h
index 76c45a02..7a89135c 100644
--- a/include/media/IMediaPlayerService.h
+++ b/include/media/IMediaPlayerService.h
@@ -32,8 +32,11 @@
namespace android {
struct ICrypto;
+struct IHDCP;
class IMediaRecorder;
class IOMX;
+class IRemoteDisplay;
+class IRemoteDisplayClient;
struct IStreamSource;
class IMediaPlayerService: public IInterface
@@ -49,6 +52,17 @@ public:
virtual sp<IMemory> decode(int fd, int64_t offset, int64_t length, uint32_t *pSampleRate, int* pNumChannels, audio_format_t* pFormat) = 0;
virtual sp<IOMX> getOMX() = 0;
virtual sp<ICrypto> makeCrypto() = 0;
+ virtual sp<IHDCP> makeHDCP() = 0;
+
+ // Connects to a remote display.
+ // 'iface' specifies the address of the local interface on which to listen for
+ // a connection from the remote display as an ip address and port number
+ // of the form "x.x.x.x:y". The media server should call back into the provided remote
+ // display client when display connection, disconnection or errors occur.
+ // The assumption is that at most one remote display will be connected to the
+ // provided interface at a time.
+ virtual sp<IRemoteDisplay> listenForRemoteDisplay(const sp<IRemoteDisplayClient>& client,
+ const String8& iface) = 0;
// codecs and audio devices usage tracking for the battery app
enum BatteryDataBits {
diff --git a/include/media/IRemoteDisplay.h b/include/media/IRemoteDisplay.h
new file mode 100644
index 00000000..c8baae9d
--- /dev/null
+++ b/include/media/IRemoteDisplay.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_IREMOTEDISPLAY_H
+#define ANDROID_IREMOTEDISPLAY_H
+
+#include <stdint.h>
+#include <sys/types.h>
+
+#include <utils/RefBase.h>
+#include <binder/IInterface.h>
+#include <binder/Parcel.h>
+
+namespace android {
+
+/*
+ * Represents a remote display, such as a Wifi display.
+ *
+ * When the remote display is created, it may not yet be connected to the
+ * display. The remote display asynchronously reports events such as successful
+ * connection, disconnection and errors to an IRemoteDisplayClient interface provided by
+ * the client.
+ */
+class IRemoteDisplay : public IInterface
+{
+public:
+ DECLARE_META_INTERFACE(RemoteDisplay);
+
+ virtual status_t pause() = 0;
+ virtual status_t resume() = 0;
+
+ // Disconnects the remote display and stops listening for new connections.
+ virtual status_t dispose() = 0;
+};
+
+
+// ----------------------------------------------------------------------------
+
+class BnRemoteDisplay : public BnInterface<IRemoteDisplay>
+{
+public:
+ virtual status_t onTransact( uint32_t code,
+ const Parcel& data,
+ Parcel* reply,
+ uint32_t flags = 0);
+};
+
+}; // namespace android
+
+#endif // ANDROID_IREMOTEDISPLAY_H
diff --git a/include/media/IRemoteDisplayClient.h b/include/media/IRemoteDisplayClient.h
new file mode 100644
index 00000000..252b401d
--- /dev/null
+++ b/include/media/IRemoteDisplayClient.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_IREMOTEDISPLAYCLIENT_H
+#define ANDROID_IREMOTEDISPLAYCLIENT_H
+
+#include <stdint.h>
+#include <sys/types.h>
+
+#include <utils/RefBase.h>
+#include <binder/IInterface.h>
+#include <binder/Parcel.h>
+
+namespace android {
+
+class ISurfaceTexture;
+
+class IRemoteDisplayClient : public IInterface
+{
+public:
+ DECLARE_META_INTERFACE(RemoteDisplayClient);
+
+ enum {
+ // Flag: The remote display is using a secure transport protocol such as HDCP.
+ kDisplayFlagSecure = 1 << 0,
+ };
+
+ enum {
+ // Error: An unknown / generic error occurred.
+ kDisplayErrorUnknown = 1,
+ // Error: The connection was dropped unexpectedly.
+ kDisplayErrorConnectionDropped = 2,
+ };
+
+ // Indicates that the remote display has been connected successfully.
+ // Provides a surface texture that the client should use to stream buffers to
+ // the remote display.
+ virtual void onDisplayConnected(const sp<ISurfaceTexture>& surfaceTexture,
+ uint32_t width, uint32_t height, uint32_t flags) = 0; // one-way
+
+ // Indicates that the remote display has been disconnected normally.
+ // This method should only be called once the client has called 'dispose()'
+ // on the IRemoteDisplay.
+ // It is currently an error for the display to disconnect for any other reason.
+ virtual void onDisplayDisconnected() = 0; // one-way
+
+ // Indicates that a connection could not be established to the remote display
+ // or an unrecoverable error occurred and the connection was severed.
+ virtual void onDisplayError(int32_t error) = 0; // one-way
+};
+
+
+// ----------------------------------------------------------------------------
+
+class BnRemoteDisplayClient : public BnInterface<IRemoteDisplayClient>
+{
+public:
+ virtual status_t onTransact( uint32_t code,
+ const Parcel& data,
+ Parcel* reply,
+ uint32_t flags = 0);
+};
+
+}; // namespace android
+
+#endif // ANDROID_IREMOTEDISPLAYCLIENT_H
diff --git a/include/media/IStreamSource.h b/include/media/IStreamSource.h
index 19646b0c..39e0a9ed 100644
--- a/include/media/IStreamSource.h
+++ b/include/media/IStreamSource.h
@@ -33,6 +33,12 @@ struct IStreamSource : public IInterface {
virtual void setBuffers(const Vector<sp<IMemory> > &buffers) = 0;
virtual void onBufferAvailable(size_t index) = 0;
+
+ enum {
+ // Video PES packets contain exactly one (aligned) access unit.
+ kFlagAlignedVideoData = 1,
+ };
+ virtual uint32_t flags() const { return 0; }
};
struct IStreamListener : public IInterface {
@@ -67,6 +73,11 @@ struct IStreamListener : public IInterface {
// ATSParser::DiscontinuityType.
static const char *const kKeyDiscontinuityMask;
+ // Optionally signalled as part of a discontinuity that includes
+ // DISCONTINUITY_TIME. It indicates the media time (in us) to be associated
+ // with the next PTS occuring in the stream. The value is of type int64_t.
+ static const char *const kKeyMediaTimeUs;
+
virtual void issueCommand(
Command cmd, bool synchronous, const sp<AMessage> &msg = NULL) = 0;
};
diff --git a/include/media/MediaPlayerInterface.h b/include/media/MediaPlayerInterface.h
index a70fe8c7..b7bee3f8 100644
--- a/include/media/MediaPlayerInterface.h
+++ b/include/media/MediaPlayerInterface.h
@@ -50,9 +50,6 @@ enum player_type {
// The shared library with the test player is passed passed as an
// argument to the 'test:' url in the setDataSource call.
TEST_PLAYER = 5,
-
- AAH_RX_PLAYER = 100,
- AAH_TX_PLAYER = 101,
};
@@ -153,13 +150,16 @@ public:
virtual status_t setParameter(int key, const Parcel &request) = 0;
virtual status_t getParameter(int key, Parcel *reply) = 0;
- // Right now, only the AAX TX player supports this functionality. For now,
- // provide a default implementation which indicates a lack of support for
- // this functionality to make life easier for all of the other media player
- // maintainers out there.
+ // default no-op implementation of optional extensions
virtual status_t setRetransmitEndpoint(const struct sockaddr_in* endpoint) {
return INVALID_OPERATION;
}
+ virtual status_t getRetransmitEndpoint(struct sockaddr_in* endpoint) {
+ return INVALID_OPERATION;
+ }
+ virtual status_t setNextPlayer(const sp<MediaPlayerBase>& next) {
+ return OK;
+ }
// Invoke a generic method on the player by using opaque parcels
// for the request and reply.
diff --git a/include/media/Visualizer.h b/include/media/Visualizer.h
index fdec5eee..aa589057 100644
--- a/include/media/Visualizer.h
+++ b/include/media/Visualizer.h
@@ -142,8 +142,6 @@ private:
private:
friend class Visualizer;
virtual bool threadLoop();
- virtual status_t readyToRun();
- virtual void onFirstRef();
Visualizer& mReceiver;
Mutex mLock;
uint32_t mSleepTimeUs;
diff --git a/include/media/mediametadataretriever.h b/include/media/mediametadataretriever.h
index 534afce4..0df77c1f 100644
--- a/include/media/mediametadataretriever.h
+++ b/include/media/mediametadataretriever.h
@@ -55,6 +55,7 @@ enum {
METADATA_KEY_TIMED_TEXT_LANGUAGES = 21,
METADATA_KEY_IS_DRM = 22,
METADATA_KEY_LOCATION = 23,
+ METADATA_KEY_VIDEO_ROTATION = 24,
// Add more here...
};
diff --git a/include/media/mediaplayer.h b/include/media/mediaplayer.h
index 1fad3833..d753ebaa 100644
--- a/include/media/mediaplayer.h
+++ b/include/media/mediaplayer.h
@@ -99,6 +99,8 @@ enum media_info_type {
// The player was started because it was used as the next player for another
// player, which just completed playback
MEDIA_INFO_STARTED_AS_NEXT = 2,
+ // The player just pushed the very first video frame for rendering
+ MEDIA_INFO_RENDERING_START = 3,
// 7xx
// The video is too complex for the decoder: it can't decode frames fast
// enough. Possibly only the audio plays fine at this stage.
@@ -247,7 +249,6 @@ private:
sp<MediaPlayerListener> mListener;
void* mCookie;
media_player_states mCurrentState;
- int mDuration;
int mCurrentPosition;
int mSeekPosition;
bool mPrepareSync;
diff --git a/include/media/nbaio/AudioBufferProviderSource.h b/include/media/nbaio/AudioBufferProviderSource.h
new file mode 100644
index 00000000..2c4aaffb
--- /dev/null
+++ b/include/media/nbaio/AudioBufferProviderSource.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Implementation of NBAIO_Source that wraps an AudioBufferProvider
+
+#ifndef ANDROID_AUDIO_BUFFER_PROVIDER_SOURCE_H
+#define ANDROID_AUDIO_BUFFER_PROVIDER_SOURCE_H
+
+#include "NBAIO.h"
+#include <media/AudioBufferProvider.h>
+
+namespace android {
+
+class AudioBufferProviderSource : public NBAIO_Source {
+
+public:
+ AudioBufferProviderSource(AudioBufferProvider *provider, NBAIO_Format format);
+ virtual ~AudioBufferProviderSource();
+
+ // NBAIO_Port interface
+
+ //virtual ssize_t negotiate(const NBAIO_Format offers[], size_t numOffers,
+ // NBAIO_Format counterOffers[], size_t& numCounterOffers);
+ //virtual NBAIO_Format format();
+
+ // NBAIO_Source interface
+
+ //virtual size_t framesRead() const;
+ //virtual size_t framesOverrun();
+ //virtual size_t overruns();
+ virtual ssize_t availableToRead();
+ virtual ssize_t read(void *buffer, size_t count, int64_t readPTS);
+ virtual ssize_t readVia(readVia_t via, size_t total, void *user,
+ int64_t readPTS, size_t block);
+
+private:
+ AudioBufferProvider * const mProvider;
+ AudioBufferProvider::Buffer mBuffer; // current buffer
+ size_t mConsumed; // number of frames consumed so far from current buffer
+};
+
+} // namespace android
+
+#endif // ANDROID_AUDIO_BUFFER_PROVIDER_SOURCE_H
diff --git a/include/media/nbaio/AudioStreamInSource.h b/include/media/nbaio/AudioStreamInSource.h
new file mode 100644
index 00000000..07d8c89e
--- /dev/null
+++ b/include/media/nbaio/AudioStreamInSource.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_AUDIO_STREAM_IN_SOURCE_H
+#define ANDROID_AUDIO_STREAM_IN_SOURCE_H
+
+#include <hardware/audio.h>
+#include "NBAIO.h"
+
+namespace android {
+
+// not multi-thread safe
+class AudioStreamInSource : public NBAIO_Source {
+
+public:
+ AudioStreamInSource(audio_stream_in *stream);
+ virtual ~AudioStreamInSource();
+
+ // NBAIO_Port interface
+
+ virtual ssize_t negotiate(const NBAIO_Format offers[], size_t numOffers,
+ NBAIO_Format counterOffers[], size_t& numCounterOffers);
+ //virtual NBAIO_Format format() const;
+
+ // NBAIO_Sink interface
+
+ //virtual size_t framesRead() const;
+ virtual size_t framesOverrun();
+ virtual size_t overruns() { (void) framesOverrun(); return mOverruns; }
+
+ // This is an over-estimate, and could dupe the caller into making a blocking read()
+ // FIXME Use an audio HAL API to query the buffer filling status when it's available.
+ virtual ssize_t availableToRead() { return mStreamBufferSizeBytes >> mBitShift; }
+
+ virtual ssize_t read(void *buffer, size_t count);
+
+ // NBAIO_Sink end
+
+#if 0 // until necessary
+ audio_stream_in *stream() const { return mStream; }
+#endif
+
+private:
+ audio_stream_in * const mStream;
+ size_t mStreamBufferSizeBytes; // as reported by get_buffer_size()
+ size_t mFramesOverrun;
+ size_t mOverruns;
+};
+
+} // namespace android
+
+#endif // ANDROID_AUDIO_STREAM_IN_SOURCE_H
diff --git a/include/media/nbaio/AudioStreamOutSink.h b/include/media/nbaio/AudioStreamOutSink.h
new file mode 100644
index 00000000..5976b186
--- /dev/null
+++ b/include/media/nbaio/AudioStreamOutSink.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_AUDIO_STREAM_OUT_SINK_H
+#define ANDROID_AUDIO_STREAM_OUT_SINK_H
+
+#include <hardware/audio.h>
+#include "NBAIO.h"
+
+namespace android {
+
+// not multi-thread safe
+class AudioStreamOutSink : public NBAIO_Sink {
+
+public:
+ AudioStreamOutSink(audio_stream_out *stream);
+ virtual ~AudioStreamOutSink();
+
+ // NBAIO_Port interface
+
+ virtual ssize_t negotiate(const NBAIO_Format offers[], size_t numOffers,
+ NBAIO_Format counterOffers[], size_t& numCounterOffers);
+ //virtual NBAIO_Format format();
+
+ // NBAIO_Sink interface
+
+ //virtual size_t framesWritten() const;
+ //virtual size_t framesUnderrun() const;
+ //virtual size_t underruns() const;
+
+ // This is an over-estimate, and could dupe the caller into making a blocking write()
+ // FIXME Use an audio HAL API to query the buffer emptying status when it's available.
+ virtual ssize_t availableToWrite() const { return mStreamBufferSizeBytes >> mBitShift; }
+
+ virtual ssize_t write(const void *buffer, size_t count);
+
+ // AudioStreamOutSink wraps a HAL's output stream. Its
+ // getNextWriteTimestamp method is simply a passthru to the HAL's underlying
+ // implementation of GNWT (if any)
+ virtual status_t getNextWriteTimestamp(int64_t *timestamp);
+
+ // NBAIO_Sink end
+
+#if 0 // until necessary
+ audio_stream_out *stream() const { return mStream; }
+#endif
+
+private:
+ audio_stream_out * const mStream;
+ size_t mStreamBufferSizeBytes; // as reported by get_buffer_size()
+};
+
+} // namespace android
+
+#endif // ANDROID_AUDIO_STREAM_OUT_SINK_H
diff --git a/include/media/nbaio/LibsndfileSink.h b/include/media/nbaio/LibsndfileSink.h
new file mode 100644
index 00000000..f5d53d51
--- /dev/null
+++ b/include/media/nbaio/LibsndfileSink.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_AUDIO_LIBSNDFILE_SINK_H
+#define ANDROID_AUDIO_LIBSNDFILE_SINK_H
+
+#include "NBAIO.h"
+#include "sndfile.h"
+
+// Implementation of NBAIO_Sink that wraps a libsndfile opened in SFM_WRITE mode
+
+namespace android {
+
+class LibsndfileSink : public NBAIO_Sink {
+
+public:
+ LibsndfileSink(SNDFILE *sndfile, const SF_INFO &sfinfo);
+ virtual ~LibsndfileSink();
+
+ // NBAIO_Port interface
+
+ //virtual ssize_t negotiate(const NBAIO_Format offers[], size_t numOffers,
+ // NBAIO_Format counterOffers[], size_t& numCounterOffers);
+ //virtual NBAIO_Format format() const;
+
+ // NBAIO_Sink interface
+
+ //virtual size_t framesWritten() const;
+ //virtual size_t framesUnderrun() const;
+ //virtual size_t underruns() const;
+ //virtual ssize_t availableToWrite() const;
+ virtual ssize_t write(const void *buffer, size_t count);
+ //virtual ssize_t writeVia(writeVia_t via, size_t total, void *user, size_t block);
+
+private:
+ SNDFILE * mSndfile;
+};
+
+} // namespace android
+
+#endif // ANDROID_AUDIO_LIBSNDFILE_SINK_H
diff --git a/include/media/nbaio/LibsndfileSource.h b/include/media/nbaio/LibsndfileSource.h
new file mode 100644
index 00000000..4fbdb4b7
--- /dev/null
+++ b/include/media/nbaio/LibsndfileSource.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_AUDIO_LIBSNDFILE_SOURCE_H
+#define ANDROID_AUDIO_LIBSNDFILE_SOURCE_H
+
+#include "NBAIO.h"
+#include "sndfile.h"
+
+// Implementation of NBAIO_Source that wraps a libsndfile opened in SFM_READ mode
+
+namespace android {
+
+class LibsndfileSource : public NBAIO_Source {
+
+public:
+ // If 'loop' is true and it permits seeking, then we'll act as an infinite source
+ LibsndfileSource(SNDFILE *sndfile, const SF_INFO &sfinfo, bool loop = false);
+ virtual ~LibsndfileSource();
+
+ // NBAIO_Port interface
+
+ //virtual ssize_t negotiate(const NBAIO_Format offers[], size_t numOffers,
+ // NBAIO_Format counterOffers[], size_t& numCounterOffers);
+ //virtual NBAIO_Format format() const;
+
+ // NBAIO_Source interface
+
+ //virtual size_t framesRead() const;
+ //virtual size_t framesOverrun();
+ //virtual size_t overruns();
+ virtual ssize_t availableToRead();
+ virtual ssize_t read(void *buffer, size_t count);
+ //virtual ssize_t readVia(readVia_t via, size_t total, void *user, size_t block);
+
+private:
+ SNDFILE * mSndfile;
+ sf_count_t mEstimatedFramesUntilEOF;
+ bool mLooping;
+ bool mReadAnyFramesThisLoopCycle;
+};
+
+} // namespace android
+
+#endif // ANDROID_AUDIO_LIBSNDFILE_SOURCE_H
diff --git a/include/media/nbaio/MonoPipe.h b/include/media/nbaio/MonoPipe.h
new file mode 100644
index 00000000..5fcfe9ee
--- /dev/null
+++ b/include/media/nbaio/MonoPipe.h
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_AUDIO_MONO_PIPE_H
+#define ANDROID_AUDIO_MONO_PIPE_H
+
+#include <time.h>
+#include <utils/LinearTransform.h>
+#include "NBAIO.h"
+
+namespace android {
+
+// MonoPipe is similar to Pipe except:
+// - supports only a single reader, called MonoPipeReader
+// - write() cannot overrun; instead it will return a short actual count if insufficient space
+// - write() can optionally block if the pipe is full
+// Like Pipe, it is not multi-thread safe for either writer or reader
+// but writer and reader can be different threads.
+class MonoPipe : public NBAIO_Sink {
+
+ friend class MonoPipeReader;
+
+public:
+ // reqFrames will be rounded up to a power of 2, and all slots are available. Must be >= 2.
+ // Note: whatever shares this object with another thread needs to do so in an SMP-safe way (like
+ // creating it the object before creating the other thread, or storing the object with a
+ // release_store). Otherwise the other thread could see a partially-constructed object.
+ MonoPipe(size_t reqFrames, NBAIO_Format format, bool writeCanBlock = false);
+ virtual ~MonoPipe();
+
+ // NBAIO_Port interface
+
+ //virtual ssize_t negotiate(const NBAIO_Format offers[], size_t numOffers,
+ // NBAIO_Format counterOffers[], size_t& numCounterOffers);
+ //virtual NBAIO_Format format() const;
+
+ // NBAIO_Sink interface
+
+ //virtual size_t framesWritten() const;
+ //virtual size_t framesUnderrun() const;
+ //virtual size_t underruns() const;
+
+ virtual ssize_t availableToWrite() const;
+ virtual ssize_t write(const void *buffer, size_t count);
+ //virtual ssize_t writeVia(writeVia_t via, size_t total, void *user, size_t block);
+
+ // MonoPipe's implementation of getNextWriteTimestamp works in conjunction
+ // with MonoPipeReader. Every time a MonoPipeReader reads from the pipe, it
+ // receives a "readPTS" indicating the point in time for which the reader
+ // would like to read data. This "last read PTS" is offset by the amt of
+ // data the reader is currently mixing and then cached cached along with the
+ // updated read pointer. This cached value is the local time for which the
+ // reader is going to request data next time it reads data (assuming we are
+ // in steady state and operating with no underflows). Writers to the
+ // MonoPipe who would like to know when their next write operation will hit
+ // the speakers can call getNextWriteTimestamp which will return the value
+ // of the last read PTS plus the duration of the amt of data waiting to be
+ // read in the MonoPipe.
+ virtual status_t getNextWriteTimestamp(int64_t *timestamp);
+
+ // average number of frames present in the pipe under normal conditions.
+ // See throttling mechanism in MonoPipe::write()
+ size_t getAvgFrames() const { return mSetpoint; }
+ void setAvgFrames(size_t setpoint);
+ size_t maxFrames() const { return mMaxFrames; }
+
+ // Set the shutdown state for the write side of a pipe.
+ // This may be called by an unrelated thread. When shutdown state is 'true',
+ // a write that would otherwise block instead returns a short transfer count.
+ // There is no guarantee how long it will take for the shutdown to be recognized,
+ // but it will not be an unbounded amount of time.
+ // The state can be restored to normal by calling shutdown(false).
+ void shutdown(bool newState = true);
+
+ // Return true if the write side of a pipe is currently shutdown.
+ bool isShutdown();
+
+private:
+ // A pair of methods and a helper variable which allows the reader and the
+ // writer to update and observe the values of mFront and mNextRdPTS in an
+ // atomic lock-less fashion.
+ //
+ // :: Important ::
+ // Two assumptions must be true in order for this lock-less approach to
+ // function properly on all systems. First, there may only be one updater
+ // thread in the system. Second, the updater thread must be running at a
+ // strictly higher priority than the observer threads. Currently, both of
+ // these assumptions are true. The only updater is always a single
+ // FastMixer thread (which runs with SCHED_FIFO/RT priority while the only
+ // observer is always an AudioFlinger::PlaybackThread running with
+ // traditional (non-RT) audio priority.
+ void updateFrontAndNRPTS(int32_t newFront, int64_t newNextRdPTS);
+ void observeFrontAndNRPTS(int32_t *outFront, int64_t *outNextRdPTS);
+ volatile int32_t mUpdateSeq;
+
+ const size_t mReqFrames; // as requested in constructor, unrounded
+ const size_t mMaxFrames; // always a power of 2
+ void * const mBuffer;
+ // mFront and mRear will never be separated by more than mMaxFrames.
+ // 32-bit overflow is possible if the pipe is active for a long time, but if that happens it's
+ // safe because we "&" with (mMaxFrames-1) at end of computations to calculate a buffer index.
+ volatile int32_t mFront; // written by the reader with updateFrontAndNRPTS, observed by
+ // the writer with observeFrontAndNRPTS
+ volatile int32_t mRear; // written by writer with android_atomic_release_store,
+ // read by reader with android_atomic_acquire_load
+ volatile int64_t mNextRdPTS; // written by the reader with updateFrontAndNRPTS, observed by
+ // the writer with observeFrontAndNRPTS
+ bool mWriteTsValid; // whether mWriteTs is valid
+ struct timespec mWriteTs; // time that the previous write() completed
+ size_t mSetpoint; // target value for pipe fill depth
+ const bool mWriteCanBlock; // whether write() should block if the pipe is full
+
+ int64_t offsetTimestampByAudioFrames(int64_t ts, size_t audFrames);
+ LinearTransform mSamplesToLocalTime;
+
+ bool mIsShutdown; // whether shutdown(true) was called, no barriers are needed
+};
+
+} // namespace android
+
+#endif // ANDROID_AUDIO_MONO_PIPE_H
diff --git a/include/media/nbaio/MonoPipeReader.h b/include/media/nbaio/MonoPipeReader.h
new file mode 100644
index 00000000..0e1c9927
--- /dev/null
+++ b/include/media/nbaio/MonoPipeReader.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_AUDIO_MONO_PIPE_READER_H
+#define ANDROID_AUDIO_MONO_PIPE_READER_H
+
+#include "MonoPipe.h"
+
+namespace android {
+
+// MonoPipeReader is safe for only a single reader thread
+class MonoPipeReader : public NBAIO_Source {
+
+public:
+
+ // Construct a MonoPipeReader and associate it with a MonoPipe;
+ // any data already in the pipe is visible to this PipeReader.
+ // There can be only a single MonoPipeReader per MonoPipe.
+ // FIXME make this constructor a factory method of MonoPipe.
+ MonoPipeReader(MonoPipe* pipe);
+ virtual ~MonoPipeReader();
+
+ // NBAIO_Port interface
+
+ //virtual ssize_t negotiate(const NBAIO_Format offers[], size_t numOffers,
+ // NBAIO_Format counterOffers[], size_t& numCounterOffers);
+ //virtual NBAIO_Format format() const;
+
+ // NBAIO_Source interface
+
+ //virtual size_t framesRead() const;
+ //virtual size_t framesOverrun();
+ //virtual size_t overruns();
+
+ virtual ssize_t availableToRead();
+
+ virtual ssize_t read(void *buffer, size_t count, int64_t readPTS);
+
+ // NBAIO_Source end
+
+#if 0 // until necessary
+ MonoPipe* pipe() const { return mPipe; }
+#endif
+
+private:
+ MonoPipe * const mPipe;
+};
+
+} // namespace android
+
+#endif // ANDROID_AUDIO_MONO_PIPE_READER_H
diff --git a/include/media/nbaio/NBAIO.h b/include/media/nbaio/NBAIO.h
new file mode 100644
index 00000000..81f42ed4
--- /dev/null
+++ b/include/media/nbaio/NBAIO.h
@@ -0,0 +1,315 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_AUDIO_NBAIO_H
+#define ANDROID_AUDIO_NBAIO_H
+
+// Non-blocking audio I/O interface
+//
+// This header file has the abstract interfaces only. Concrete implementation classes are declared
+// elsewhere. Implementations _should_ be non-blocking for all methods, especially read() and
+// write(), but this is not enforced. In general, implementations do not need to be multi-thread
+// safe, and any exceptions are noted in the particular implementation.
+
+#include <limits.h>
+#include <stdlib.h>
+#include <utils/Errors.h>
+#include <utils/RefBase.h>
+
+namespace android {
+
+// In addition to the usual status_t
+enum {
+ NEGOTIATE = 0x80000010, // Must (re-)negotiate format. For negotiate() only, the offeree
+ // doesn't accept offers, and proposes counter-offers
+ OVERRUN = 0x80000011, // availableToRead(), read(), or readVia() detected lost input due
+ // to overrun; an event is counted and the caller should re-try
+ UNDERRUN = 0x80000012, // availableToWrite(), write(), or writeVia() detected a gap in
+ // output due to underrun (not being called often enough, or with
+ // enough data); an event is counted and the caller should re-try
+};
+
+// Negotiation of format is based on the data provider and data sink, or the data consumer and
+// data source, exchanging prioritized arrays of offers and counter-offers until a single offer is
+// mutually agreed upon. Each offer is an NBAIO_Format. For simplicity and performance,
+// NBAIO_Format is an enum that ties together the most important combinations of the various
+// attributes, rather than a struct with separate fields for format, sample rate, channel count,
+// interleave, packing, alignment, etc. The reason is that NBAIO_Format tries to abstract out only
+// the combinations that are actually needed within AudioFligner. If the list of combinations grows
+// too large, then this decision should be re-visited.
+enum NBAIO_Format {
+ Format_Invalid,
+ Format_SR44_1_C2_I16, // 44.1 kHz PCM stereo interleaved 16-bit signed
+ Format_SR48_C2_I16, // 48 kHz PCM stereo interleaved 16-bit signed
+ Format_SR44_1_C1_I16, // 44.1 kHz PCM mono interleaved 16-bit signed
+ Format_SR48_C1_I16, // 48 kHz PCM mono interleaved 16-bit signed
+};
+
+// Return the frame size of an NBAIO_Format in bytes
+size_t Format_frameSize(NBAIO_Format format);
+
+// Return the frame size of an NBAIO_Format as a bit shift
+size_t Format_frameBitShift(NBAIO_Format format);
+
+// Convert a sample rate in Hz and channel count to an NBAIO_Format
+NBAIO_Format Format_from_SR_C(unsigned sampleRate, unsigned channelCount);
+
+// Return the sample rate in Hz of an NBAIO_Format
+unsigned Format_sampleRate(NBAIO_Format format);
+
+// Return the channel count of an NBAIO_Format
+unsigned Format_channelCount(NBAIO_Format format);
+
+// Callbacks used by NBAIO_Sink::writeVia() and NBAIO_Source::readVia() below.
+typedef ssize_t (*writeVia_t)(void *user, void *buffer, size_t count);
+typedef ssize_t (*readVia_t)(void *user, const void *buffer,
+ size_t count, int64_t readPTS);
+
+// Abstract class (interface) representing a data port.
+class NBAIO_Port : public RefBase {
+
+public:
+
+ // negotiate() must called first. The purpose of negotiate() is to check compatibility of
+ // formats, not to automatically adapt if they are incompatible. It's the responsibility of
+ // whoever sets up the graph connections to make sure formats are compatible, and this method
+ // just verifies that. The edges are "dumb" and don't attempt to adapt to bad connections.
+ // How it works: offerer proposes an array of formats, in descending order of preference from
+ // offers[0] to offers[numOffers - 1]. If offeree accepts one of these formats, it returns
+ // the index of that offer. Otherwise, offeree sets numCounterOffers to the number of
+ // counter-offers (up to a maximumum of the entry value of numCounterOffers), fills in the
+ // provided array counterOffers[] with its counter-offers, in descending order of preference
+ // from counterOffers[0] to counterOffers[numCounterOffers - 1], and returns NEGOTIATE.
+ // Note that since the offerer allocates space for counter-offers, but only the offeree knows
+ // how many counter-offers it has, there may be insufficient space for all counter-offers.
+ // In that case, the offeree sets numCounterOffers to the requested number of counter-offers
+ // (which is greater than the entry value of numCounterOffers), fills in as many of the most
+ // important counterOffers as will fit, and returns NEGOTIATE. As this implies a re-allocation,
+ // it should be used as a last resort. It is preferable for the offerer to simply allocate a
+ // larger space to begin with, and/or for the offeree to tolerate a smaller space than desired.
+ // Alternatively, the offerer can pass NULL for offers and counterOffers, and zero for
+ // numOffers. This indicates that it has not allocated space for any counter-offers yet.
+ // In this case, the offerree should set numCounterOffers appropriately and return NEGOTIATE.
+ // Then the offerer will allocate the correct amount of memory and retry.
+ // Format_Invalid is not allowed as either an offer or counter-offer.
+ // Returns:
+ // >= 0 Offer accepted.
+ // NEGOTIATE No offer accepted, and counter-offer(s) optionally made. See above for details.
+ virtual ssize_t negotiate(const NBAIO_Format offers[], size_t numOffers,
+ NBAIO_Format counterOffers[], size_t& numCounterOffers);
+
+ // Return the current negotiated format, or Format_Invalid if negotiation has not been done,
+ // or if re-negotiation is required.
+ virtual NBAIO_Format format() const { return mNegotiated ? mFormat : Format_Invalid; }
+
+protected:
+ NBAIO_Port(NBAIO_Format format) : mNegotiated(false), mFormat(format),
+ mBitShift(Format_frameBitShift(format)) { }
+ virtual ~NBAIO_Port() { }
+
+ // Implementations are free to ignore these if they don't need them
+
+ bool mNegotiated; // mNegotiated implies (mFormat != Format_Invalid)
+ NBAIO_Format mFormat; // (mFormat != Format_Invalid) does not imply mNegotiated
+ size_t mBitShift; // assign in parallel with any assignment to mFormat
+};
+
+// Abstract class (interface) representing a non-blocking data sink, for use by a data provider.
+class NBAIO_Sink : public NBAIO_Port {
+
+public:
+
+ // For the next two APIs:
+ // 32 bits rolls over after 27 hours at 44.1 kHz; if that concerns you then poll periodically.
+
+ // Return the number of frames written successfully since construction.
+ virtual size_t framesWritten() const { return mFramesWritten; }
+
+ // Number of frames lost due to underrun since construction.
+ virtual size_t framesUnderrun() const { return 0; }
+
+ // Number of underruns since construction, where a set of contiguous lost frames is one event.
+ virtual size_t underruns() const { return 0; }
+
+ // Estimate of number of frames that could be written successfully now without blocking.
+ // When a write() is actually attempted, the implementation is permitted to return a smaller or
+ // larger transfer count, however it will make a good faith effort to give an accurate estimate.
+ // Errors:
+ // NEGOTIATE (Re-)negotiation is needed.
+ // UNDERRUN write() has not been called frequently enough, or with enough frames to keep up.
+ // An underrun event is counted, and the caller should re-try this operation.
+ // WOULD_BLOCK Determining how many frames can be written without blocking would itself block.
+ virtual ssize_t availableToWrite() const { return SSIZE_MAX; }
+
+ // Transfer data to sink from single input buffer. Implies a copy.
+ // Inputs:
+ // buffer Non-NULL buffer owned by provider.
+ // count Maximum number of frames to transfer.
+ // Return value:
+ // > 0 Number of frames successfully transferred prior to first error.
+ // = 0 Count was zero.
+ // < 0 status_t error occurred prior to the first frame transfer.
+ // Errors:
+ // NEGOTIATE (Re-)negotiation is needed.
+ // WOULD_BLOCK No frames can be transferred without blocking.
+ // UNDERRUN write() has not been called frequently enough, or with enough frames to keep up.
+ // An underrun event is counted, and the caller should re-try this operation.
+ virtual ssize_t write(const void *buffer, size_t count) = 0;
+
+ // Transfer data to sink using a series of callbacks. More suitable for zero-fill, synthesis,
+ // and non-contiguous transfers (e.g. circular buffer or writev).
+ // Inputs:
+ // via Callback function that the sink will call as many times as needed to consume data.
+ // total Estimate of the number of frames the provider has available. This is an estimate,
+ // and it can provide a different number of frames during the series of callbacks.
+ // user Arbitrary void * reserved for data provider.
+ // block Number of frames per block, that is a suggested value for 'count' in each callback.
+ // Zero means no preference. This parameter is a hint only, and may be ignored.
+ // Return value:
+ // > 0 Total number of frames successfully transferred prior to first error.
+ // = 0 Count was zero.
+ // < 0 status_t error occurred prior to the first frame transfer.
+ // Errors:
+ // NEGOTIATE (Re-)negotiation is needed.
+ // WOULD_BLOCK No frames can be transferred without blocking.
+ // UNDERRUN write() has not been called frequently enough, or with enough frames to keep up.
+ // An underrun event is counted, and the caller should re-try this operation.
+ //
+ // The 'via' callback is called by the data sink as follows:
+ // Inputs:
+ // user Arbitrary void * reserved for data provider.
+ // buffer Non-NULL buffer owned by sink that callback should fill in with data,
+ // up to a maximum of 'count' frames.
+ // count Maximum number of frames to transfer during this callback.
+ // Return value:
+ // > 0 Number of frames successfully transferred during this callback prior to first error.
+ // = 0 Count was zero.
+ // < 0 status_t error occurred prior to the first frame transfer during this callback.
+ virtual ssize_t writeVia(writeVia_t via, size_t total, void *user, size_t block = 0);
+
+ // Get the time (on the LocalTime timeline) at which the first frame of audio of the next write
+ // operation to this sink will be eventually rendered by the HAL.
+ // Inputs:
+ // ts A pointer pointing to the int64_t which will hold the result.
+ // Return value:
+ // OK Everything went well, *ts holds the time at which the first audio frame of the next
+ // write operation will be rendered, or AudioBufferProvider::kInvalidPTS if this sink
+ // does not know the answer for some reason. Sinks which eventually lead to a HAL
+ // which implements get_next_write_timestamp may return Invalid temporarily if the DMA
+ // output of the audio driver has not started yet. Sinks which lead to a HAL which
+ // does not implement get_next_write_timestamp, or which don't lead to a HAL at all,
+ // will always return kInvalidPTS.
+ // <other> Something unexpected happened internally. Check the logs and start debugging.
+ virtual status_t getNextWriteTimestamp(int64_t *ts) { return INVALID_OPERATION; }
+
+protected:
+ NBAIO_Sink(NBAIO_Format format = Format_Invalid) : NBAIO_Port(format), mFramesWritten(0) { }
+ virtual ~NBAIO_Sink() { }
+
+ // Implementations are free to ignore these if they don't need them
+ size_t mFramesWritten;
+};
+
+// Abstract class (interface) representing a non-blocking data source, for use by a data consumer.
+class NBAIO_Source : public NBAIO_Port {
+
+public:
+
+ // For the next two APIs:
+ // 32 bits rolls over after 27 hours at 44.1 kHz; if that concerns you then poll periodically.
+
+ // Number of frames read successfully since construction.
+ virtual size_t framesRead() const { return mFramesRead; }
+
+ // Number of frames lost due to overrun since construction.
+ // Not const because implementations may need to do I/O.
+ virtual size_t framesOverrun() /*const*/ { return 0; }
+
+ // Number of overruns since construction, where a set of contiguous lost frames is one event.
+ // Not const because implementations may need to do I/O.
+ virtual size_t overruns() /*const*/ { return 0; }
+
+ // Estimate of number of frames that could be read successfully now.
+ // When a read() is actually attempted, the implementation is permitted to return a smaller or
+ // larger transfer count, however it will make a good faith effort to give an accurate estimate.
+ // Errors:
+ // NEGOTIATE (Re-)negotiation is needed.
+ // OVERRUN One or more frames were lost due to overrun, try again to read more recent data.
+ // WOULD_BLOCK Determining how many frames can be read without blocking would itself block.
+ virtual ssize_t availableToRead() { return SSIZE_MAX; }
+
+ // Transfer data from source into single destination buffer. Implies a copy.
+ // Inputs:
+ // buffer Non-NULL destination buffer owned by consumer.
+ // count Maximum number of frames to transfer.
+ // readPTS The presentation time (on the LocalTime timeline) for which data
+ // is being requested, or kInvalidPTS if not known.
+ // Return value:
+ // > 0 Number of frames successfully transferred prior to first error.
+ // = 0 Count was zero.
+ // < 0 status_t error occurred prior to the first frame transfer.
+ // Errors:
+ // NEGOTIATE (Re-)negotiation is needed.
+ // WOULD_BLOCK No frames can be transferred without blocking.
+ // OVERRUN read() has not been called frequently enough, or with enough frames to keep up.
+ // One or more frames were lost due to overrun, try again to read more recent data.
+ virtual ssize_t read(void *buffer, size_t count, int64_t readPTS) = 0;
+
+ // Transfer data from source using a series of callbacks. More suitable for zero-fill,
+ // synthesis, and non-contiguous transfers (e.g. circular buffer or readv).
+ // Inputs:
+ // via Callback function that the source will call as many times as needed to provide data.
+ // total Estimate of the number of frames the consumer desires. This is an estimate,
+ // and it can consume a different number of frames during the series of callbacks.
+ // user Arbitrary void * reserved for data consumer.
+ // readPTS The presentation time (on the LocalTime timeline) for which data
+ // is being requested, or kInvalidPTS if not known.
+ // block Number of frames per block, that is a suggested value for 'count' in each callback.
+ // Zero means no preference. This parameter is a hint only, and may be ignored.
+ // Return value:
+ // > 0 Total number of frames successfully transferred prior to first error.
+ // = 0 Count was zero.
+ // < 0 status_t error occurred prior to the first frame transfer.
+ // Errors:
+ // NEGOTIATE (Re-)negotiation is needed.
+ // WOULD_BLOCK No frames can be transferred without blocking.
+ // OVERRUN read() has not been called frequently enough, or with enough frames to keep up.
+ // One or more frames were lost due to overrun, try again to read more recent data.
+ //
+ // The 'via' callback is called by the data source as follows:
+ // Inputs:
+ // user Arbitrary void * reserved for data consumer.
+ // dest Non-NULL buffer owned by source that callback should consume data from,
+ // up to a maximum of 'count' frames.
+ // count Maximum number of frames to transfer during this callback.
+ // Return value:
+ // > 0 Number of frames successfully transferred during this callback prior to first error.
+ // = 0 Count was zero.
+ // < 0 status_t error occurred prior to the first frame transfer during this callback.
+ virtual ssize_t readVia(readVia_t via, size_t total, void *user,
+ int64_t readPTS, size_t block = 0);
+
+protected:
+ NBAIO_Source(NBAIO_Format format = Format_Invalid) : NBAIO_Port(format), mFramesRead(0) { }
+ virtual ~NBAIO_Source() { }
+
+ // Implementations are free to ignore these if they don't need them
+ size_t mFramesRead;
+};
+
+} // namespace android
+
+#endif // ANDROID_AUDIO_NBAIO_H
diff --git a/include/media/nbaio/Pipe.h b/include/media/nbaio/Pipe.h
new file mode 100644
index 00000000..79a4eee3
--- /dev/null
+++ b/include/media/nbaio/Pipe.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_AUDIO_PIPE_H
+#define ANDROID_AUDIO_PIPE_H
+
+#include "NBAIO.h"
+
+namespace android {
+
+// Pipe is multi-thread safe for readers (see PipeReader), but safe for only a single writer thread.
+// It cannot UNDERRUN on write, unless we allow designation of a master reader that provides the
+// time-base. Readers can be added and removed dynamically, and it's OK to have no readers.
+class Pipe : public NBAIO_Sink {
+
+ friend class PipeReader;
+
+public:
+ // maxFrames will be rounded up to a power of 2, and all slots are available. Must be >= 2.
+ Pipe(size_t maxFrames, NBAIO_Format format);
+ virtual ~Pipe();
+
+ // NBAIO_Port interface
+
+ //virtual ssize_t negotiate(const NBAIO_Format offers[], size_t numOffers,
+ // NBAIO_Format counterOffers[], size_t& numCounterOffers);
+ //virtual NBAIO_Format format() const;
+
+ // NBAIO_Sink interface
+
+ //virtual size_t framesWritten() const;
+ //virtual size_t framesUnderrun() const;
+ //virtual size_t underruns() const;
+
+ // The write side of a pipe permits overruns; flow control is the caller's responsibility.
+ // It doesn't return +infinity because that would guarantee an overrun.
+ virtual ssize_t availableToWrite() const { return mMaxFrames; }
+
+ virtual ssize_t write(const void *buffer, size_t count);
+ //virtual ssize_t writeVia(writeVia_t via, size_t total, void *user, size_t block);
+
+private:
+ const size_t mMaxFrames; // always a power of 2
+ void * const mBuffer;
+ volatile int32_t mRear; // written by android_atomic_release_store
+ volatile int32_t mReaders; // number of PipeReader clients currently attached to this Pipe
+};
+
+} // namespace android
+
+#endif // ANDROID_AUDIO_PIPE_H
diff --git a/include/media/nbaio/PipeReader.h b/include/media/nbaio/PipeReader.h
new file mode 100644
index 00000000..350e6ab8
--- /dev/null
+++ b/include/media/nbaio/PipeReader.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_AUDIO_PIPE_READER_H
+#define ANDROID_AUDIO_PIPE_READER_H
+
+#include "Pipe.h"
+
+namespace android {
+
+// PipeReader is safe for only a single thread
+class PipeReader : public NBAIO_Source {
+
+public:
+
+ // Construct a PipeReader and associate it with a Pipe
+ // FIXME make this constructor a factory method of Pipe.
+ PipeReader(Pipe& pipe);
+ virtual ~PipeReader();
+
+ // NBAIO_Port interface
+
+ //virtual ssize_t negotiate(const NBAIO_Format offers[], size_t numOffers,
+ // NBAIO_Format counterOffers[], size_t& numCounterOffers);
+ //virtual NBAIO_Format format() const;
+
+ // NBAIO_Source interface
+
+ //virtual size_t framesRead() const;
+ virtual size_t framesOverrun() { return mFramesOverrun; }
+ virtual size_t overruns() { return mOverruns; }
+
+ virtual ssize_t availableToRead();
+
+ virtual ssize_t read(void *buffer, size_t count, int64_t readPTS);
+
+ // NBAIO_Source end
+
+#if 0 // until necessary
+ Pipe& pipe() const { return mPipe; }
+#endif
+
+private:
+ Pipe& mPipe;
+ int32_t mFront; // follows behind mPipe.mRear
+ size_t mFramesOverrun;
+ size_t mOverruns;
+};
+
+} // namespace android
+
+#endif // ANDROID_AUDIO_PIPE_READER_H
diff --git a/include/media/nbaio/SourceAudioBufferProvider.h b/include/media/nbaio/SourceAudioBufferProvider.h
new file mode 100644
index 00000000..c08331bf
--- /dev/null
+++ b/include/media/nbaio/SourceAudioBufferProvider.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Implementation of AudioBufferProvider that wraps an NBAIO_Source
+
+#ifndef ANDROID_SOURCE_AUDIO_BUFFER_PROVIDER_H
+#define ANDROID_SOURCE_AUDIO_BUFFER_PROVIDER_H
+
+#include "NBAIO.h"
+#include <media/ExtendedAudioBufferProvider.h>
+
+namespace android {
+
+class SourceAudioBufferProvider : public ExtendedAudioBufferProvider {
+
+public:
+ SourceAudioBufferProvider(const sp<NBAIO_Source>& source);
+ virtual ~SourceAudioBufferProvider();
+
+ // AudioBufferProvider interface
+ virtual status_t getNextBuffer(Buffer *buffer, int64_t pts);
+ virtual void releaseBuffer(Buffer *buffer);
+
+ // ExtendedAudioBufferProvider interface
+ virtual size_t framesReady() const;
+
+private:
+ const sp<NBAIO_Source> mSource; // the wrapped source
+ /*const*/ size_t mFrameBitShift; // log2(frame size in bytes)
+ void* mAllocated; // pointer to base of allocated memory
+ size_t mSize; // size of mAllocated in frames
+ size_t mOffset; // frame offset within mAllocated of valid data
+ size_t mRemaining; // frame count within mAllocated of valid data
+ size_t mGetCount; // buffer.frameCount of the most recent getNextBuffer
+};
+
+} // namespace android
+
+#endif // ANDROID_SOURCE_AUDIO_BUFFER_PROVIDER_H
diff --git a/include/media/nbaio/roundup.h b/include/media/nbaio/roundup.h
new file mode 100644
index 00000000..4c3cc257
--- /dev/null
+++ b/include/media/nbaio/roundup.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ROUNDUP_H
+#define ROUNDUP_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// Round up to the next highest power of 2
+unsigned roundup(unsigned v);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // ROUNDUP_H
diff --git a/include/media/stagefright/ACodec.h b/include/media/stagefright/ACodec.h
index 2371619b..df1c46b3 100644
--- a/include/media/stagefright/ACodec.h
+++ b/include/media/stagefright/ACodec.h
@@ -25,6 +25,8 @@
#include <media/stagefright/SkipCutBuffer.h>
#include <OMX_Audio.h>
+#define TRACK_BUFFER_TIMING 0
+
namespace android {
struct ABuffer;
@@ -56,6 +58,8 @@ struct ACodec : public AHierarchicalStateMachine {
void initiateConfigureComponent(const sp<AMessage> &msg);
void initiateStart();
+ void signalRequestIDRFrame();
+
struct PortDescription : public RefBase {
size_t countBuffers();
IOMX::buffer_id bufferIDAt(size_t index) const;
@@ -100,6 +104,7 @@ private:
kWhatAllocateComponent = 'allo',
kWhatConfigureComponent = 'conf',
kWhatStart = 'star',
+ kWhatRequestIDRFrame = 'ridr',
};
enum {
@@ -127,6 +132,15 @@ private:
sp<GraphicBuffer> mGraphicBuffer;
};
+#if TRACK_BUFFER_TIMING
+ struct BufferStats {
+ int64_t mEmptyBufferTimeUs;
+ int64_t mFillBufferDoneTimeUs;
+ };
+
+ KeyedVector<int64_t, BufferStats> mBufferStats;
+#endif
+
sp<AMessage> mNotify;
sp<UninitializedState> mUninitializedState;
@@ -170,6 +184,7 @@ private:
bool mChannelMaskPresent;
int32_t mChannelMask;
+ status_t setCyclicIntraMacroblockRefresh(const sp<AMessage> &msg, int32_t mode);
status_t allocateBuffersOnPort(OMX_U32 portIndex);
status_t freeBuffersOnPort(OMX_U32 portIndex);
status_t freeBuffer(OMX_U32 portIndex, size_t i);
@@ -228,7 +243,10 @@ private:
status_t setupAVCEncoderParameters(const sp<AMessage> &msg);
status_t verifySupportForProfileAndLevel(int32_t profile, int32_t level);
- status_t configureBitrate(int32_t bitrate);
+
+ status_t configureBitrate(
+ int32_t bitrate, OMX_VIDEO_CONTROLRATETYPE bitrateMode);
+
status_t setupErrorCorrectionParameters();
status_t initNativeWindow();
@@ -251,6 +269,8 @@ private:
OMX_ERRORTYPE error = OMX_ErrorUndefined,
status_t internalError = UNKNOWN_ERROR);
+ status_t requestIDRFrame();
+
DISALLOW_EVIL_CONSTRUCTORS(ACodec);
};
diff --git a/include/media/stagefright/AudioSource.h b/include/media/stagefright/AudioSource.h
index f5466e80..99f3c3bb 100644
--- a/include/media/stagefright/AudioSource.h
+++ b/include/media/stagefright/AudioSource.h
@@ -31,11 +31,12 @@ namespace android {
class AudioRecord;
struct AudioSource : public MediaSource, public MediaBufferObserver {
- // Note that the "channels" parameter is _not_ the number of channels,
- // but a bitmask of audio_channels_t constants.
+ // Note that the "channels" parameter _is_ the number of channels,
+ // _not_ a bitmask of audio_channels_t constants.
AudioSource(
- audio_source_t inputSource, uint32_t sampleRate,
- uint32_t channels = AUDIO_CHANNEL_IN_MONO);
+ audio_source_t inputSource,
+ uint32_t sampleRate,
+ uint32_t channels = 1);
status_t initCheck() const;
@@ -49,7 +50,7 @@ struct AudioSource : public MediaSource, public MediaBufferObserver {
virtual status_t read(
MediaBuffer **buffer, const ReadOptions *options = NULL);
- status_t dataCallbackTimestamp(const AudioRecord::Buffer& buffer, int64_t timeUs);
+ status_t dataCallback(const AudioRecord::Buffer& buffer);
virtual void signalBufferReturned(MediaBuffer *buffer);
protected:
diff --git a/include/media/stagefright/CameraSource.h b/include/media/stagefright/CameraSource.h
index 5a35358d..6d6b8a96 100644
--- a/include/media/stagefright/CameraSource.h
+++ b/include/media/stagefright/CameraSource.h
@@ -137,6 +137,7 @@ protected:
int32_t mCameraFlags;
Size mVideoSize;
+ int32_t mNumInputBuffers;
int32_t mVideoFrameRate;
int32_t mColorFormat;
status_t mInitCheck;
diff --git a/include/media/stagefright/MediaCodec.h b/include/media/stagefright/MediaCodec.h
index e46e8e95..b1e57cf5 100644
--- a/include/media/stagefright/MediaCodec.h
+++ b/include/media/stagefright/MediaCodec.h
@@ -106,6 +106,15 @@ struct MediaCodec : public AHandler {
status_t getInputBuffers(Vector<sp<ABuffer> > *buffers) const;
status_t getOutputBuffers(Vector<sp<ABuffer> > *buffers) const;
+ status_t requestIDRFrame();
+
+ // Notification will be posted once there "is something to do", i.e.
+ // an input/output buffer has become available, a format change is
+ // pending, an error is pending.
+ void requestActivityNotification(const sp<AMessage> &notify);
+
+ status_t getName(AString *componentName) const;
+
protected:
virtual ~MediaCodec();
virtual void onMessageReceived(const sp<AMessage> &msg);
@@ -130,21 +139,24 @@ private:
};
enum {
- kWhatInit = 'init',
- kWhatConfigure = 'conf',
- kWhatStart = 'strt',
- kWhatStop = 'stop',
- kWhatRelease = 'rele',
- kWhatDequeueInputBuffer = 'deqI',
- kWhatQueueInputBuffer = 'queI',
- kWhatDequeueOutputBuffer = 'deqO',
- kWhatReleaseOutputBuffer = 'relO',
- kWhatGetBuffers = 'getB',
- kWhatFlush = 'flus',
- kWhatGetOutputFormat = 'getO',
- kWhatDequeueInputTimedOut = 'dITO',
- kWhatDequeueOutputTimedOut = 'dOTO',
- kWhatCodecNotify = 'codc',
+ kWhatInit = 'init',
+ kWhatConfigure = 'conf',
+ kWhatStart = 'strt',
+ kWhatStop = 'stop',
+ kWhatRelease = 'rele',
+ kWhatDequeueInputBuffer = 'deqI',
+ kWhatQueueInputBuffer = 'queI',
+ kWhatDequeueOutputBuffer = 'deqO',
+ kWhatReleaseOutputBuffer = 'relO',
+ kWhatGetBuffers = 'getB',
+ kWhatFlush = 'flus',
+ kWhatGetOutputFormat = 'getO',
+ kWhatDequeueInputTimedOut = 'dITO',
+ kWhatDequeueOutputTimedOut = 'dOTO',
+ kWhatCodecNotify = 'codc',
+ kWhatRequestIDRFrame = 'ridr',
+ kWhatRequestActivityNotification = 'racN',
+ kWhatGetName = 'getN',
};
enum {
@@ -169,6 +181,7 @@ private:
sp<ALooper> mLooper;
sp<ALooper> mCodecLooper;
sp<ACodec> mCodec;
+ AString mComponentName;
uint32_t mReplyID;
uint32_t mFlags;
sp<SurfaceTextureClient> mNativeWindow;
@@ -188,6 +201,8 @@ private:
List<sp<ABuffer> > mCSD;
+ sp<AMessage> mActivityNotify;
+
MediaCodec(const sp<ALooper> &looper);
static status_t PostAndAwaitResponse(
@@ -213,6 +228,8 @@ private:
status_t setNativeWindow(
const sp<SurfaceTextureClient> &surfaceTextureClient);
+ void postActivityNotificationIfPossible();
+
DISALLOW_EVIL_CONSTRUCTORS(MediaCodec);
};
diff --git a/include/media/stagefright/MediaExtractor.h b/include/media/stagefright/MediaExtractor.h
index 94090eef..3076a96c 100644
--- a/include/media/stagefright/MediaExtractor.h
+++ b/include/media/stagefright/MediaExtractor.h
@@ -67,7 +67,7 @@ public:
}
protected:
- MediaExtractor() {}
+ MediaExtractor() : mIsDrm(false) {}
virtual ~MediaExtractor() {}
private:
diff --git a/include/media/stagefright/MetaData.h b/include/media/stagefright/MetaData.h
index 3c25a14d..e91904c9 100644
--- a/include/media/stagefright/MetaData.h
+++ b/include/media/stagefright/MetaData.h
@@ -111,6 +111,7 @@ enum {
kKeyTrackTimeStatus = 'tktm', // int64_t
kKeyNotRealTime = 'ntrt', // bool (int32_t)
+ kKeyNumBuffers = 'nbbf', // int32_t
// Ogg files can be tagged to be automatically looping...
kKeyAutoLoop = 'autL', // bool (int32_t)
diff --git a/include/media/stagefright/NuMediaExtractor.h b/include/media/stagefright/NuMediaExtractor.h
index c9c709cc..0833110b 100644
--- a/include/media/stagefright/NuMediaExtractor.h
+++ b/include/media/stagefright/NuMediaExtractor.h
@@ -50,6 +50,8 @@ struct NuMediaExtractor : public RefBase {
status_t setDataSource(int fd, off64_t offset, off64_t size);
+ status_t setDataSource(const sp<DataSource> &datasource);
+
size_t countTracks() const;
status_t getTrackFormat(size_t index, sp<AMessage> *format) const;
diff --git a/include/media/stagefright/OMXCodec.h b/include/media/stagefright/OMXCodec.h
index 81350ca3..583c3b3a 100644
--- a/include/media/stagefright/OMXCodec.h
+++ b/include/media/stagefright/OMXCodec.h
@@ -98,9 +98,13 @@ struct OMXCodec : public MediaSource,
kDecoderLiesAboutNumberOfChannels = 256,
kInputBufferSizesAreBogus = 512,
kSupportsMultipleFramesPerInputBuffer = 1024,
- kAvoidMemcopyInputRecordingFrames = 2048,
- kRequiresLargerEncoderOutputBuffer = 4096,
- kOutputBuffersAreUnreadable = 8192,
+ kRequiresLargerEncoderOutputBuffer = 2048,
+ kOutputBuffersAreUnreadable = 4096,
+ };
+
+ struct CodecNameAndQuirks {
+ String8 mName;
+ uint32_t mQuirks;
};
// for use by ACodec
@@ -108,8 +112,7 @@ struct OMXCodec : public MediaSource,
const char *mime,
bool createEncoder, const char *matchComponentName,
uint32_t flags,
- Vector<String8> *matchingCodecs,
- Vector<uint32_t> *matchingCodecQuirks = NULL);
+ Vector<CodecNameAndQuirks> *matchingCodecNamesAndQuirks);
static uint32_t getComponentQuirks(
const MediaCodecList *list, size_t index);
@@ -273,7 +276,7 @@ private:
CodecProfileLevel& profileLevel);
status_t setVideoOutputFormat(
- const char *mime, OMX_U32 width, OMX_U32 height);
+ const char *mime, const sp<MetaData>& meta);
void setImageOutputFormat(
OMX_COLOR_FORMATTYPE format, OMX_U32 width, OMX_U32 height);
@@ -342,8 +345,6 @@ private:
status_t configureCodec(const sp<MetaData> &meta);
- void restorePatchedDataPointer(BufferInfo *info);
-
status_t applyRotation();
status_t waitForBufferFilled_l();
@@ -353,6 +354,8 @@ private:
const void *data, size_t size,
unsigned *profile, unsigned *level);
+ status_t stopOmxComponent_l();
+
OMXCodec(const OMXCodec &);
OMXCodec &operator=(const OMXCodec &);
};
diff --git a/include/media/stagefright/SurfaceMediaSource.h b/include/media/stagefright/SurfaceMediaSource.h
index 4a8e2217..e56527d6 100644
--- a/include/media/stagefright/SurfaceMediaSource.h
+++ b/include/media/stagefright/SurfaceMediaSource.h
@@ -52,6 +52,8 @@ class GraphicBuffer;
// may be dropped. It is possible to wait for the buffers to be
// returned (but not implemented)
+#define DEBUG_PENDING_BUFFERS 0
+
class SurfaceMediaSource : public MediaSource,
public MediaBufferObserver,
protected BufferQueue::ConsumerListener {
@@ -73,10 +75,9 @@ public:
// For the MediaSource interface for use by StageFrightRecorder:
virtual status_t start(MetaData *params = NULL);
-
- virtual status_t stop() { return reset(); }
- virtual status_t read(
- MediaBuffer **buffer, const ReadOptions *options = NULL);
+ virtual status_t stop();
+ virtual status_t read(MediaBuffer **buffer,
+ const ReadOptions *options = NULL);
virtual sp<MetaData> getFormat();
// Get / Set the frame rate used for encoding. Default fps = 30
@@ -112,6 +113,12 @@ public:
sp<BufferQueue> getBufferQueue() const { return mBufferQueue; }
+ // To be called before start()
+ status_t setMaxAcquiredBufferCount(size_t count);
+
+ // To be called before start()
+ status_t setUseAbsoluteTimestamps();
+
protected:
// Implementation of the BufferQueue::ConsumerListener interface. These
@@ -165,6 +172,12 @@ private:
// this list in signalBufferReturned
Vector<sp<GraphicBuffer> > mCurrentBuffers;
+ size_t mNumPendingBuffers;
+
+#if DEBUG_PENDING_BUFFERS
+ Vector<MediaBuffer *> mPendingBuffers;
+#endif
+
// mCurrentTimestamp is the timestamp for the current texture. It
// gets set to mLastQueuedTimestamp each time updateTexImage is called.
int64_t mCurrentTimestamp;
@@ -183,8 +196,8 @@ private:
// Set to a default of 30 fps if not specified by the client side
int32_t mFrameRate;
- // mStopped is a flag to check if the recording is going on
- bool mStopped;
+ // mStarted is a flag to check if the recording is going on
+ bool mStarted;
// mNumFramesReceived indicates the number of frames recieved from
// the client side
@@ -200,11 +213,15 @@ private:
// offset timestamps.
int64_t mStartTimeNs;
+ size_t mMaxAcquiredBufferCount;
+
+ bool mUseAbsoluteTimestamps;
+
// mFrameAvailableCondition condition used to indicate whether there
// is a frame available for dequeuing
Condition mFrameAvailableCondition;
- status_t reset();
+ Condition mMediaBuffersAvailableCondition;
// Avoid copying and equating and default constructor
DISALLOW_IMPLICIT_CONSTRUCTORS(SurfaceMediaSource);
diff --git a/include/media/stagefright/TimeSource.h b/include/media/stagefright/TimeSource.h
index 443673de..8f11e14c 100644
--- a/include/media/stagefright/TimeSource.h
+++ b/include/media/stagefright/TimeSource.h
@@ -41,8 +41,6 @@ public:
virtual int64_t getRealTimeUs();
private:
- static int64_t GetSystemTimeUs();
-
int64_t mStartTimeUs;
};
diff --git a/include/media/stagefright/Utils.h b/include/media/stagefright/Utils.h
index d87902e7..8213af96 100644
--- a/include/media/stagefright/Utils.h
+++ b/include/media/stagefright/Utils.h
@@ -42,6 +42,8 @@ struct MetaData;
struct AMessage;
status_t convertMetaDataToMessage(
const sp<MetaData> &meta, sp<AMessage> *format);
+void convertMessageToMetaData(
+ const sp<AMessage> &format, sp<MetaData> &meta);
} // namespace android
diff --git a/include/media/stagefright/foundation/hexdump.h b/include/media/stagefright/foundation/hexdump.h
index f6083a93..8360c5a3 100644
--- a/include/media/stagefright/foundation/hexdump.h
+++ b/include/media/stagefright/foundation/hexdump.h
@@ -22,7 +22,11 @@
namespace android {
-void hexdump(const void *_data, size_t size);
+struct AString;
+
+void hexdump(
+ const void *_data, size_t size,
+ size_t indent = 0, AString *appendTo = NULL);
} // namespace android
diff --git a/include/media/stagefright/timedtext/TimedTextDriver.h b/include/media/stagefright/timedtext/TimedTextDriver.h
index cde551b7..f23c3375 100644
--- a/include/media/stagefright/timedtext/TimedTextDriver.h
+++ b/include/media/stagefright/timedtext/TimedTextDriver.h
@@ -64,6 +64,7 @@ private:
enum State {
UNINITIALIZED,
+ PREPARED,
PLAYING,
PAUSED,
};