summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/media/AudioResamplerPublic.h38
-rw-r--r--include/media/AudioSystem.h17
-rw-r--r--include/media/AudioTrack.h44
-rw-r--r--include/media/IAudioPolicyService.h1
-rw-r--r--include/media/ICrypto.h8
-rw-r--r--include/media/IMediaCodecList.h4
-rw-r--r--include/media/MediaCodecInfo.h4
-rw-r--r--include/media/stagefright/ACodec.h1
-rw-r--r--include/media/stagefright/MediaClock.h1
-rw-r--r--include/media/stagefright/MediaCodec.h15
-rw-r--r--include/media/stagefright/MediaCodecList.h15
-rw-r--r--include/private/media/AudioTrackShared.h36
12 files changed, 171 insertions, 13 deletions
diff --git a/include/media/AudioResamplerPublic.h b/include/media/AudioResamplerPublic.h
index b705efa..07d946d 100644
--- a/include/media/AudioResamplerPublic.h
+++ b/include/media/AudioResamplerPublic.h
@@ -17,6 +17,8 @@
#ifndef ANDROID_AUDIO_RESAMPLER_PUBLIC_H
#define ANDROID_AUDIO_RESAMPLER_PUBLIC_H
+#include <stdint.h>
+
// AUDIO_RESAMPLER_DOWN_RATIO_MAX is the maximum ratio between the original
// audio sample rate and the target rate when downsampling,
// as permitted in the audio framework, e.g. AudioTrack and AudioFlinger.
@@ -26,6 +28,22 @@
// TODO: replace with an API
#define AUDIO_RESAMPLER_DOWN_RATIO_MAX 256
+// AUDIO_RESAMPLER_UP_RATIO_MAX is the maximum suggested ratio between the original
+// audio sample rate and the target rate when upsampling. It is loosely enforced by
+// the system. One issue with large upsampling ratios is the approximation by
+// an int32_t of the phase increments, making the resulting sample rate inexact.
+#define AUDIO_RESAMPLER_UP_RATIO_MAX 65536
+
+#define AUDIO_TIMESTRETCH_SPEED_MIN 0.5f
+#define AUDIO_TIMESTRETCH_SPEED_MAX 2.0f
+#define AUDIO_TIMESTRETCH_SPEED_NORMAL 1.0f
+
+#define AUDIO_TIMESTRETCH_PITCH_MIN 0.5f
+#define AUDIO_TIMESTRETCH_PITCH_MAX 2.0f
+#define AUDIO_TIMESTRETCH_PITCH_NORMAL 1.0f
+
+// TODO: Consider putting these inlines into a class scope
+
// Returns the source frames needed to resample to destination frames. This is not a precise
// value and depends on the resampler (and possibly how it handles rounding internally).
// Nevertheless, this should be an upper bound on the requirements of the resampler.
@@ -39,4 +57,24 @@ static inline size_t sourceFramesNeeded(
size_t((uint64_t)dstFramesRequired * srcSampleRate / dstSampleRate + 1 + 1);
}
+// An upper bound for the number of destination frames possible from srcFrames
+// after sample rate conversion. This may be used for buffer sizing.
+static inline size_t destinationFramesPossible(size_t srcFrames, uint32_t srcSampleRate,
+ uint32_t dstSampleRate) {
+ if (srcSampleRate == dstSampleRate) {
+ return srcFrames;
+ }
+ uint64_t dstFrames = (uint64_t)srcFrames * dstSampleRate / srcSampleRate;
+ return dstFrames > 2 ? dstFrames - 2 : 0;
+}
+
+static inline size_t sourceFramesNeededWithTimestretch(
+ uint32_t srcSampleRate, size_t dstFramesRequired, uint32_t dstSampleRate,
+ float speed) {
+ // required is the number of input frames the resampler needs
+ size_t required = sourceFramesNeeded(srcSampleRate, dstFramesRequired, dstSampleRate);
+ // to deliver this, the time stretcher requires:
+ return required * (double)speed + 1 + 1; // accounting for rounding dependencies
+}
+
#endif // ANDROID_AUDIO_RESAMPLER_PUBLIC_H
diff --git a/include/media/AudioSystem.h b/include/media/AudioSystem.h
index f5db1bb..3b6db8c 100644
--- a/include/media/AudioSystem.h
+++ b/include/media/AudioSystem.h
@@ -221,14 +221,15 @@ public:
audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE,
const audio_offload_info_t *offloadInfo = NULL);
static status_t getOutputForAttr(const audio_attributes_t *attr,
- audio_io_handle_t *output,
- audio_session_t session,
- audio_stream_type_t *stream,
- uint32_t samplingRate = 0,
- audio_format_t format = AUDIO_FORMAT_DEFAULT,
- audio_channel_mask_t channelMask = AUDIO_CHANNEL_OUT_STEREO,
- audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE,
- const audio_offload_info_t *offloadInfo = NULL);
+ audio_io_handle_t *output,
+ audio_session_t session,
+ audio_stream_type_t *stream,
+ uint32_t samplingRate = 0,
+ audio_format_t format = AUDIO_FORMAT_DEFAULT,
+ audio_channel_mask_t channelMask = AUDIO_CHANNEL_OUT_STEREO,
+ audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE,
+ audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE,
+ const audio_offload_info_t *offloadInfo = NULL);
static status_t startOutput(audio_io_handle_t output,
audio_stream_type_t stream,
audio_session_t session);
diff --git a/include/media/AudioTrack.h b/include/media/AudioTrack.h
index d9b7057..a06197f 100644
--- a/include/media/AudioTrack.h
+++ b/include/media/AudioTrack.h
@@ -359,6 +359,21 @@ public:
/* Return current source sample rate in Hz */
uint32_t getSampleRate() const;
+ /* Set source playback rate for timestretch
+ * 1.0 is normal speed: < 1.0 is slower, > 1.0 is faster
+ * 1.0 is normal pitch: < 1.0 is lower pitch, > 1.0 is higher pitch
+ *
+ * AUDIO_TIMESTRETCH_SPEED_MIN <= speed <= AUDIO_TIMESTRETCH_SPEED_MAX
+ * AUDIO_TIMESTRETCH_PITCH_MIN <= pitch <= AUDIO_TIMESTRETCH_PITCH_MAX
+ *
+ * Speed increases the playback rate of media, but does not alter pitch.
+ * Pitch increases the "tonal frequency" of media, but does not affect the playback rate.
+ */
+ status_t setPlaybackRate(float speed, float pitch);
+
+ /* Return current playback rate */
+ void getPlaybackRate(float *speed, float *pitch) const;
+
/* Enables looping and sets the start and end points of looping.
* Only supported for static buffer mode.
*
@@ -477,6 +492,26 @@ private:
audio_io_handle_t getOutput() const;
public:
+ /* Selects the audio device to use for output of this AudioTrack. A value of
+ * AUDIO_PORT_HANDLE_NONE indicates default (AudioPolicyManager) routing.
+ *
+ * Parameters:
+ * The device ID of the selected device (as returned by the AudioDevicesManager API).
+ *
+ * Returned value:
+ * - NO_ERROR: successful operation
+ * TODO: what else can happen here?
+ */
+ status_t setOutputDevice(audio_port_handle_t deviceId);
+
+ /* Returns the ID of the audio device used for output of this AudioTrack.
+ * A value of AUDIO_PORT_HANDLE_NONE indicates default (AudioPolicyManager) routing.
+ *
+ * Parameters:
+ * none.
+ */
+ audio_port_handle_t getOutputDevice();
+
/* Returns the unique session ID associated with this track.
*
* Parameters:
@@ -699,6 +734,9 @@ protected:
// increment mPosition by the delta of mServer, and return new value of mPosition
uint32_t updateAndGetPosition_l();
+ // check sample rate and speed is compatible with AudioTrack
+ bool isSampleRateSpeedAllowed_l(uint32_t sampleRate, float speed) const;
+
// Next 4 fields may be changed if IAudioTrack is re-created, but always != 0
sp<IAudioTrack> mAudioTrack;
sp<IMemory> mCblkMemory;
@@ -710,6 +748,8 @@ protected:
float mVolume[2];
float mSendLevel;
mutable uint32_t mSampleRate; // mutable because getSampleRate() can update it
+ float mSpeed; // timestretch: 1.0f for normal speed.
+ float mPitch; // timestretch: 1.0f for normal pitch.
size_t mFrameCount; // corresponds to current IAudioTrack, value is
// reported back by AudioFlinger to the client
size_t mReqFrameCount; // frame count to request the first or next time
@@ -817,6 +857,10 @@ protected:
bool mInUnderrun; // whether track is currently in underrun state
uint32_t mPausedPosition;
+ // For Device Selection API
+ // a value of AUDIO_PORT_HANDLE_NONE indicated default (AudioPolicyManager) routing.
+ int mSelectedDeviceId;
+
private:
class DeathNotifier : public IBinder::DeathRecipient {
public:
diff --git a/include/media/IAudioPolicyService.h b/include/media/IAudioPolicyService.h
index fecc6f1..7506153 100644
--- a/include/media/IAudioPolicyService.h
+++ b/include/media/IAudioPolicyService.h
@@ -66,6 +66,7 @@ public:
audio_format_t format = AUDIO_FORMAT_DEFAULT,
audio_channel_mask_t channelMask = 0,
audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE,
+ audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE,
const audio_offload_info_t *offloadInfo = NULL) = 0;
virtual status_t startOutput(audio_io_handle_t output,
audio_stream_type_t stream,
diff --git a/include/media/ICrypto.h b/include/media/ICrypto.h
index 07742ca..aa04dbe 100644
--- a/include/media/ICrypto.h
+++ b/include/media/ICrypto.h
@@ -25,6 +25,7 @@
namespace android {
struct AString;
+struct IMemory;
struct ICrypto : public IInterface {
DECLARE_META_INTERFACE(Crypto);
@@ -43,12 +44,14 @@ struct ICrypto : public IInterface {
virtual void notifyResolution(uint32_t width, uint32_t height) = 0;
+ virtual status_t setMediaDrmSession(const Vector<uint8_t> &sessionId) = 0;
+
virtual ssize_t decrypt(
bool secure,
const uint8_t key[16],
const uint8_t iv[16],
CryptoPlugin::Mode mode,
- const void *srcPtr,
+ const sp<IMemory> &sharedBuffer, size_t offset,
const CryptoPlugin::SubSample *subSamples, size_t numSubSamples,
void *dstPtr,
AString *errorDetailMsg) = 0;
@@ -61,6 +64,9 @@ struct BnCrypto : public BnInterface<ICrypto> {
virtual status_t onTransact(
uint32_t code, const Parcel &data, Parcel *reply,
uint32_t flags = 0);
+private:
+ void readVector(const Parcel &data, Vector<uint8_t> &vector) const;
+ void writeVector(Parcel *reply, Vector<uint8_t> const &vector) const;
};
} // namespace android
diff --git a/include/media/IMediaCodecList.h b/include/media/IMediaCodecList.h
index e93ea8b..12b52d7 100644
--- a/include/media/IMediaCodecList.h
+++ b/include/media/IMediaCodecList.h
@@ -21,6 +21,8 @@
#include <binder/IInterface.h>
#include <binder/Parcel.h>
+#include <media/stagefright/foundation/AMessage.h>
+
namespace android {
struct MediaCodecInfo;
@@ -33,6 +35,8 @@ public:
virtual size_t countCodecs() const = 0;
virtual sp<MediaCodecInfo> getCodecInfo(size_t index) const = 0;
+ virtual const sp<AMessage> getGlobalSettings() const = 0;
+
virtual ssize_t findCodecByType(
const char *type, bool encoder, size_t startIndex = 0) const = 0;
diff --git a/include/media/MediaCodecInfo.h b/include/media/MediaCodecInfo.h
index cd56adb..895a13a 100644
--- a/include/media/MediaCodecInfo.h
+++ b/include/media/MediaCodecInfo.h
@@ -35,6 +35,8 @@ struct AMessage;
struct Parcel;
struct CodecCapabilities;
+typedef KeyedVector<AString, AString> CodecSettings;
+
struct MediaCodecInfo : public RefBase {
struct ProfileLevel {
uint32_t mProfile;
@@ -104,6 +106,7 @@ private:
MediaCodecInfo(AString name, bool encoder, const char *mime);
void addQuirk(const char *name);
status_t addMime(const char *mime);
+ status_t updateMime(const char *mime);
status_t initializeCapabilities(const CodecCapabilities &caps);
void addDetail(const AString &key, const AString &value);
void addFeature(const AString &key, int32_t value);
@@ -114,6 +117,7 @@ private:
DISALLOW_EVIL_CONSTRUCTORS(MediaCodecInfo);
friend class MediaCodecList;
+ friend class MediaCodecListOverridesTest;
};
} // namespace android
diff --git a/include/media/stagefright/ACodec.h b/include/media/stagefright/ACodec.h
index c1483f3..a8d0fcb 100644
--- a/include/media/stagefright/ACodec.h
+++ b/include/media/stagefright/ACodec.h
@@ -300,6 +300,7 @@ private:
OMX_U32 portIndex, int32_t sampleRate, int32_t numChannels);
status_t setPriority(int32_t priority);
+ status_t setOperatingRate(float rateFloat, bool isVideo);
status_t setMinBufferSize(OMX_U32 portIndex, size_t size);
diff --git a/include/media/stagefright/MediaClock.h b/include/media/stagefright/MediaClock.h
index e9c09a1..dd1a809 100644
--- a/include/media/stagefright/MediaClock.h
+++ b/include/media/stagefright/MediaClock.h
@@ -42,6 +42,7 @@ struct MediaClock : public RefBase {
void updateMaxTimeMedia(int64_t maxTimeMediaUs);
void setPlaybackRate(float rate);
+ float getPlaybackRate() const;
// query media time corresponding to real time |realUs|, and save the
// result in |outMediaUs|.
diff --git a/include/media/stagefright/MediaCodec.h b/include/media/stagefright/MediaCodec.h
index 8241e19..3e3c276 100644
--- a/include/media/stagefright/MediaCodec.h
+++ b/include/media/stagefright/MediaCodec.h
@@ -30,8 +30,10 @@ struct AMessage;
struct AReplyToken;
struct AString;
struct CodecBase;
-struct ICrypto;
struct IBatteryStats;
+struct ICrypto;
+struct IMemory;
+struct MemoryDealer;
struct SoftwareRenderer;
struct Surface;
@@ -51,6 +53,13 @@ struct MediaCodec : public AHandler {
CB_OUTPUT_AVAILABLE = 2,
CB_ERROR = 3,
CB_OUTPUT_FORMAT_CHANGED = 4,
+ CB_CODEC_RELEASED = 5,
+ };
+
+ // used by CB_CODEC_RELEASED to tell the upper layer the cause of the release.
+ enum ReleaseReason {
+ REASON_UNKNOWN = 0,
+ REASON_RECLAIMED, // resources reclaimed by resource manager
};
struct BatteryNotifier;
@@ -126,6 +135,8 @@ struct MediaCodec : public AHandler {
status_t getOutputFormat(sp<AMessage> *format) const;
status_t getInputFormat(sp<AMessage> *format) const;
+ status_t getWidevineLegacyBuffers(Vector<sp<ABuffer> > *buffers) const;
+
status_t getInputBuffers(Vector<sp<ABuffer> > *buffers) const;
status_t getOutputBuffers(Vector<sp<ABuffer> > *buffers) const;
@@ -213,6 +224,7 @@ private:
uint32_t mBufferID;
sp<ABuffer> mData;
sp<ABuffer> mEncryptedData;
+ sp<IMemory> mSharedEncryptedBuffer;
sp<AMessage> mNotify;
sp<AMessage> mFormat;
bool mOwnedByClient;
@@ -231,6 +243,7 @@ private:
sp<AMessage> mOutputFormat;
sp<AMessage> mInputFormat;
sp<AMessage> mCallback;
+ sp<MemoryDealer> mDealer;
bool mBatteryStatNotified;
bool mIsVideo;
diff --git a/include/media/stagefright/MediaCodecList.h b/include/media/stagefright/MediaCodecList.h
index c2bbe4d..9d1d675 100644
--- a/include/media/stagefright/MediaCodecList.h
+++ b/include/media/stagefright/MediaCodecList.h
@@ -48,9 +48,14 @@ struct MediaCodecList : public BnMediaCodecList {
return mCodecInfos.itemAt(index);
}
+ virtual const sp<AMessage> getGlobalSettings() const;
+
// to be used by MediaPlayerService alone
static sp<IMediaCodecList> getLocalInstance();
+ // only to be used in getLocalInstance
+ void updateDetailsForMultipleCodecs(const KeyedVector<AString, CodecSettings>& updates);
+
private:
class BinderDeathObserver : public IBinder::DeathRecipient {
void binderDied(const wp<IBinder> &the_late_who __unused);
@@ -60,6 +65,7 @@ private:
enum Section {
SECTION_TOPLEVEL,
+ SECTION_SETTINGS,
SECTION_DECODERS,
SECTION_DECODER,
SECTION_DECODER_TYPE,
@@ -74,10 +80,14 @@ private:
status_t mInitCheck;
Section mCurrentSection;
+ bool mUpdate;
Vector<Section> mPastSections;
int32_t mDepth;
AString mHrefBase;
+ sp<AMessage> mGlobalSettings;
+ KeyedVector<AString, CodecSettings> mOverrides;
+
Vector<sp<MediaCodecInfo> > mCodecInfos;
sp<MediaCodecInfo> mCurrentInfo;
sp<IOMX> mOMX;
@@ -87,7 +97,7 @@ private:
status_t initCheck() const;
void parseXMLFile(const char *path);
- void parseTopLevelXMLFile(const char *path);
+ void parseTopLevelXMLFile(const char *path, bool ignore_errors = false);
static void StartElementHandlerWrapper(
void *me, const char *name, const char **attrs);
@@ -98,9 +108,12 @@ private:
void endElementHandler(const char *name);
status_t includeXMLFile(const char **attrs);
+ status_t addSettingFromAttributes(const char **attrs);
status_t addMediaCodecFromAttributes(bool encoder, const char **attrs);
void addMediaCodec(bool encoder, const char *name, const char *type = NULL);
+ void setCurrentCodecInfo(bool encoder, const char *name, const char *type);
+
status_t addQuirk(const char **attrs);
status_t addTypeFromAttributes(const char **attrs);
status_t addLimit(const char **attrs);
diff --git a/include/private/media/AudioTrackShared.h b/include/private/media/AudioTrackShared.h
index 5644428..6cc2e2b 100644
--- a/include/private/media/AudioTrackShared.h
+++ b/include/private/media/AudioTrackShared.h
@@ -25,6 +25,7 @@
#include <utils/Log.h>
#include <utils/RefBase.h>
#include <audio_utils/roundup.h>
+#include <media/AudioResamplerPublic.h>
#include <media/SingleStateQueue.h>
namespace android {
@@ -113,6 +114,14 @@ struct AudioTrackSharedStatic {
mPosLoopQueue;
};
+
+struct AudioTrackPlaybackRate {
+ float mSpeed;
+ float mPitch;
+};
+
+typedef SingleStateQueue<AudioTrackPlaybackRate> AudioTrackPlaybackRateQueue;
+
// ----------------------------------------------------------------------------
// Important: do not add any virtual methods, including ~
@@ -159,6 +168,8 @@ private:
uint32_t mSampleRate; // AudioTrack only: client's requested sample rate in Hz
// or 0 == default. Write-only client, read-only server.
+ AudioTrackPlaybackRateQueue::Shared mPlaybackRateQueue;
+
// client write-only, server read-only
uint16_t mSendLevel; // Fixed point U4.12 so 0x1000 means 1.0
@@ -313,7 +324,8 @@ public:
AudioTrackClientProxy(audio_track_cblk_t* cblk, void *buffers, size_t frameCount,
size_t frameSize, bool clientInServer = false)
: ClientProxy(cblk, buffers, frameCount, frameSize, true /*isOut*/,
- clientInServer) { }
+ clientInServer),
+ mPlaybackRateMutator(&cblk->mPlaybackRateQueue) { }
virtual ~AudioTrackClientProxy() { }
// No barriers on the following operations, so the ordering of loads/stores
@@ -333,6 +345,13 @@ public:
mCblk->mSampleRate = sampleRate;
}
+ void setPlaybackRate(float speed, float pitch) {
+ AudioTrackPlaybackRate playbackRate;
+ playbackRate.mSpeed = speed;
+ playbackRate.mPitch = pitch;
+ mPlaybackRateMutator.push(playbackRate);
+ }
+
virtual void flush();
virtual uint32_t getUnderrunFrames() const {
@@ -344,6 +363,9 @@ public:
bool getStreamEndDone() const;
status_t waitStreamEndDone(const struct timespec *requested);
+
+private:
+ AudioTrackPlaybackRateQueue::Mutator mPlaybackRateMutator;
};
class StaticAudioTrackClientProxy : public AudioTrackClientProxy {
@@ -458,8 +480,11 @@ class AudioTrackServerProxy : public ServerProxy {
public:
AudioTrackServerProxy(audio_track_cblk_t* cblk, void *buffers, size_t frameCount,
size_t frameSize, bool clientInServer = false, uint32_t sampleRate = 0)
- : ServerProxy(cblk, buffers, frameCount, frameSize, true /*isOut*/, clientInServer) {
+ : ServerProxy(cblk, buffers, frameCount, frameSize, true /*isOut*/, clientInServer),
+ mPlaybackRateObserver(&cblk->mPlaybackRateQueue) {
mCblk->mSampleRate = sampleRate;
+ mPlaybackRate.mSpeed = AUDIO_TIMESTRETCH_SPEED_NORMAL;
+ mPlaybackRate.mPitch = AUDIO_TIMESTRETCH_PITCH_NORMAL;
}
protected:
virtual ~AudioTrackServerProxy() { }
@@ -493,6 +518,13 @@ public:
// Return the total number of frames that AudioFlinger has obtained and released
virtual size_t framesReleased() const { return mCblk->mServer; }
+
+ // Return the playback speed and pitch read atomically. Not multi-thread safe on server side.
+ void getPlaybackRate(float *speed, float *pitch);
+
+private:
+ AudioTrackPlaybackRate mPlaybackRate; // last observed playback rate
+ AudioTrackPlaybackRateQueue::Observer mPlaybackRateObserver;
};
class StaticAudioTrackServerProxy : public AudioTrackServerProxy {