2 changes: 2 additions & 0 deletions drm/mediadrm/plugins/mock/MockDrmCryptoPlugin.h
Expand Up @@ -88,7 +88,9 @@ namespace android {
status_t unprovisionDevice();

status_t getSecureStops(List<Vector<uint8_t> > &secureStops);
status_t getSecureStop(Vector<uint8_t> const &ssid, Vector<uint8_t> &secureStop);
status_t releaseSecureStops(Vector<uint8_t> const &ssRelease);
status_t releaseAllSecureStops();

status_t getPropertyString(String8 const &name, String8 &value ) const;
status_t getPropertyByteArray(String8 const &name,
Expand Down
5 changes: 5 additions & 0 deletions include/camera/CameraParameters.h
Expand Up @@ -19,6 +19,7 @@

#include <utils/KeyedVector.h>
#include <utils/String8.h>
#include <camera/CameraParametersExtra.h>

namespace android {

Expand Down Expand Up @@ -683,6 +684,10 @@ class CameraParameters
// High-dynamic range mode
static const char LIGHTFX_HDR[];

#ifdef CAMERA_PARAMETERS_EXTRA_H
CAMERA_PARAMETERS_EXTRA_H
#endif

/**
* Returns the the supported preview formats as an enum given in graphics.h
* corrsponding to the format given in the input string or -1 if no such
Expand Down
35 changes: 35 additions & 0 deletions include/camera/CameraParametersExtra.h
@@ -0,0 +1,35 @@
// Overload this file in your device specific config if you need
// to add extra camera parameters.
// A typical file would look like this:
/*
* Copyright (C) 2014 The CyanogenMod 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.
*/
/*
#define CAMERA_PARAMETERS_EXTRA_C \
const char CameraParameters::KEY_SUPPORTED_BURST_NUM[] = "supported-burst-num"; \
const char CameraParameters::KEY_BURST_NUM[] = "burst-num"; \
const char CameraParameters::KEY_SUPPORTED_HDR_MODES[] = "supported-hdr-modes"; \
const char CameraParameters::KEY_HDR_MODE[] = "hdr-mode"; \
const char CameraParameters::HDR_MODE_OFF[] = "hdr-mode-off"; \
const char CameraParameters::HDR_MODE_HDR[] = "hdr-mode-hdr";
#define CAMERA_PARAMETERS_EXTRA_H \
static const char KEY_SUPPORTED_BURST_NUM[]; \
static const char KEY_BURST_NUM[]; \
static const char KEY_SUPPORTED_HDR_MODES[]; \
static const char KEY_HDR_MODE[]; \
static const char HDR_MODE_OFF[]; \
static const char HDR_MODE_HDR[];
*/
6 changes: 6 additions & 0 deletions include/camera/ICameraRecordingProxy.h
Expand Up @@ -83,6 +83,12 @@ class ICameraRecordingProxy: public IInterface
virtual status_t startRecording(const sp<ICameraRecordingProxyListener>& listener) = 0;
virtual void stopRecording() = 0;
virtual void releaseRecordingFrame(const sp<IMemory>& mem) = 0;

// b/28466701
static size_t getCommonBaseAddress();
private:

static uint8_t baseObject;
};

// ----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion include/camera/ProCamera.h
Expand Up @@ -265,7 +265,7 @@ class ProCamera :
}

protected:
virtual void onFrameAvailable() {
virtual void onFrameAvailable(const BufferItem& /* item */) {
sp<ProCamera> c = mCamera.promote();
if (c.get() != NULL) {
c->onFrameAvailable(mStreamId);
Expand Down
9 changes: 7 additions & 2 deletions include/media/AudioEffect.h
Expand Up @@ -133,10 +133,11 @@ class AudioEffect : public RefBase
*
* Returned value
* *descriptor updated with descriptors of pre processings enabled by default
* *count number of descriptors returned if returned status is N_ERROR.
* *count number of descriptors returned if returned status is NO_ERROR.
* total number of pre processing enabled by default if returned status is
* NO_MEMORY. This happens if the count passed as input is less than the number
* of descriptors to return
* of descriptors to return.
* *count is limited to kMaxPreProcessing on return.
*/
static status_t queryDefaultPreProcessing(int audioSession,
effect_descriptor_t *descriptors,
Expand Down Expand Up @@ -391,6 +392,10 @@ class AudioEffect : public RefBase
*/
static status_t guidToString(const effect_uuid_t *guid, char *str, size_t maxLen);

// kMaxPreProcessing is a reasonable value for the maximum number of preprocessing effects
// that can be applied simultaneously.
static const uint32_t kMaxPreProcessing = 10;

protected:
bool mEnabled; // enable state
int32_t mSessionId; // audio session ID
Expand Down
5 changes: 5 additions & 0 deletions include/media/AudioParameter.h
@@ -1,4 +1,7 @@
/*
* Copyright (c) 2013, The Linux Foundation. All rights reserved.
* Not a Contribution.
*
* Copyright (C) 2008-2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -48,6 +51,8 @@ class AudioParameter {
static const char * const keyFrameCount;
static const char * const keyInputSource;
static const char * const keyScreenState;
static const char * const keySSR;
static const char * const keyADSPStatus;

String8 toString();

Expand Down
82 changes: 82 additions & 0 deletions include/media/AudioPolicy.h
@@ -0,0 +1,82 @@
/*
* Copyright (C) 2014 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_POLICY_H
#define ANDROID_AUDIO_POLICY_H

#include <system/audio.h>
#include <system/audio_policy.h>
#include <binder/Parcel.h>
#include <utils/String8.h>
#include <utils/Vector.h>

namespace android {

// Keep in sync with AudioMix.java, AudioMixingRule.java, AudioPolicyConfig.java
#define RULE_EXCLUSION_MASK 0x8000
#define RULE_MATCH_ATTRIBUTE_USAGE 0x1
#define RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET (0x1 << 1)
#define RULE_EXCLUDE_ATTRIBUTE_USAGE (RULE_EXCLUSION_MASK|RULE_MATCH_ATTRIBUTE_USAGE)
#define RULE_EXCLUDE_ATTRIBUTE_CAPTURE_PRESET \
(RULE_EXCLUSION_MASK|RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET)

#define MIX_TYPE_INVALID -1
#define MIX_TYPE_PLAYERS 0
#define MIX_TYPE_RECORDERS 1

#define ROUTE_FLAG_RENDER 0x1
#define ROUTE_FLAG_LOOP_BACK (0x1 << 1)

#define MAX_MIXES_PER_POLICY 10
#define MAX_CRITERIA_PER_MIX 20

class AttributeMatchCriterion {
public:
AttributeMatchCriterion() {}
AttributeMatchCriterion(audio_usage_t usage, audio_source_t source, uint32_t rule);

status_t readFromParcel(Parcel *parcel);
status_t writeToParcel(Parcel *parcel) const;

union {
audio_usage_t mUsage;
audio_source_t mSource;
} mAttr;
uint32_t mRule;
};

class AudioMix {
public:
AudioMix() {}
AudioMix(Vector<AttributeMatchCriterion> criteria, uint32_t mixType, audio_config_t format,
uint32_t routeFlags, String8 registrationId) :
mCriteria(criteria), mMixType(mixType), mFormat(format),
mRouteFlags(routeFlags), mRegistrationId(registrationId) {}

status_t readFromParcel(Parcel *parcel);
status_t writeToParcel(Parcel *parcel) const;

Vector<AttributeMatchCriterion> mCriteria;
uint32_t mMixType;
audio_config_t mFormat;
uint32_t mRouteFlags;
String8 mRegistrationId;
};

}; // namespace android

#endif // ANDROID_AUDIO_POLICY_H
53 changes: 52 additions & 1 deletion include/media/AudioPolicyHelper.h
Expand Up @@ -18,7 +18,7 @@

#include <system/audio.h>

audio_stream_type_t audio_attributes_to_stream_type(const audio_attributes_t *attr)
static audio_stream_type_t audio_attributes_to_stream_type(const audio_attributes_t *attr)
{
// flags to stream type mapping
if ((attr->flags & AUDIO_FLAG_AUDIBILITY_ENFORCED) == AUDIO_FLAG_AUDIBILITY_ENFORCED) {
Expand Down Expand Up @@ -61,4 +61,55 @@ audio_stream_type_t audio_attributes_to_stream_type(const audio_attributes_t *at
}
}

static void stream_type_to_audio_attributes(audio_stream_type_t streamType,
audio_attributes_t *attr) {
memset(attr, 0, sizeof(audio_attributes_t));

switch (streamType) {
case AUDIO_STREAM_DEFAULT:
case AUDIO_STREAM_MUSIC:
attr->content_type = AUDIO_CONTENT_TYPE_MUSIC;
attr->usage = AUDIO_USAGE_MEDIA;
break;
case AUDIO_STREAM_VOICE_CALL:
attr->content_type = AUDIO_CONTENT_TYPE_SPEECH;
attr->usage = AUDIO_USAGE_VOICE_COMMUNICATION;
break;
case AUDIO_STREAM_ENFORCED_AUDIBLE:
attr->flags |= AUDIO_FLAG_AUDIBILITY_ENFORCED;
// intended fall through, attributes in common with STREAM_SYSTEM
case AUDIO_STREAM_SYSTEM:
attr->content_type = AUDIO_CONTENT_TYPE_SONIFICATION;
attr->usage = AUDIO_USAGE_ASSISTANCE_SONIFICATION;
break;
case AUDIO_STREAM_RING:
attr->content_type = AUDIO_CONTENT_TYPE_SONIFICATION;
attr->usage = AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE;
break;
case AUDIO_STREAM_ALARM:
attr->content_type = AUDIO_CONTENT_TYPE_SONIFICATION;
attr->usage = AUDIO_USAGE_ALARM;
break;
case AUDIO_STREAM_NOTIFICATION:
attr->content_type = AUDIO_CONTENT_TYPE_SONIFICATION;
attr->usage = AUDIO_USAGE_NOTIFICATION;
break;
case AUDIO_STREAM_BLUETOOTH_SCO:
attr->content_type = AUDIO_CONTENT_TYPE_SPEECH;
attr->usage = AUDIO_USAGE_VOICE_COMMUNICATION;
attr->flags |= AUDIO_FLAG_SCO;
break;
case AUDIO_STREAM_DTMF:
attr->content_type = AUDIO_CONTENT_TYPE_SONIFICATION;
attr->usage = AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING;
break;
case AUDIO_STREAM_TTS:
attr->content_type = AUDIO_CONTENT_TYPE_SPEECH;
attr->usage = AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY;
break;
default:
ALOGE("invalid stream type %d when converting to attributes", streamType);
}
}

#endif //AUDIO_POLICY_HELPER_H_
11 changes: 7 additions & 4 deletions include/media/AudioRecord.h
Expand Up @@ -152,6 +152,7 @@ class AudioRecord : public RefBase
* transferType: How data is transferred from AudioRecord.
* flags: See comments on audio_input_flags_t in <system/audio.h>
* threadCanCallJava: Not present in parameter list, and so is fixed at false.
* pAttributes: if not NULL, supersedes inputSource for use case selection
*/

AudioRecord(audio_source_t inputSource,
Expand All @@ -164,7 +165,8 @@ class AudioRecord : public RefBase
uint32_t notificationFrames = 0,
int sessionId = AUDIO_SESSION_ALLOCATE,
transfer_type transferType = TRANSFER_DEFAULT,
audio_input_flags_t flags = AUDIO_INPUT_FLAG_NONE);
audio_input_flags_t flags = AUDIO_INPUT_FLAG_NONE,
const audio_attributes_t* pAttributes = NULL);

/* Terminates the AudioRecord and unregisters it from AudioFlinger.
* Also destroys all resources associated with the AudioRecord.
Expand Down Expand Up @@ -198,7 +200,8 @@ class AudioRecord : public RefBase
bool threadCanCallJava = false,
int sessionId = AUDIO_SESSION_ALLOCATE,
transfer_type transferType = TRANSFER_DEFAULT,
audio_input_flags_t flags = AUDIO_INPUT_FLAG_NONE);
audio_input_flags_t flags = AUDIO_INPUT_FLAG_NONE,
const audio_attributes_t* pAttributes = NULL);

/* Result of constructing the AudioRecord. This must be checked for successful initialization
* before using any AudioRecord API (except for set()), because using
Expand All @@ -219,7 +222,7 @@ class AudioRecord : public RefBase
uint32_t channelCount() const { return mChannelCount; }
size_t frameCount() const { return mFrameCount; }
size_t frameSize() const { return mFrameSize; }
audio_source_t inputSource() const { return mInputSource; }
audio_source_t inputSource() const { return mAttributes.source; }

/* After it's created the track is not active. Call start() to
* make it active. If set, the callback will start being called.
Expand Down Expand Up @@ -489,7 +492,6 @@ class AudioRecord : public RefBase
audio_format_t mFormat;
uint32_t mChannelCount;
size_t mFrameSize; // app-level frame size == AudioFlinger frame size
audio_source_t mInputSource;
uint32_t mLatency; // in ms
audio_channel_mask_t mChannelMask;
audio_input_flags_t mFlags;
Expand Down Expand Up @@ -529,6 +531,7 @@ class AudioRecord : public RefBase

sp<DeathNotifier> mDeathNotifier;
uint32_t mSequence; // incremented for each new IAudioRecord attempt
audio_attributes_t mAttributes;
};

}; // namespace android
Expand Down
42 changes: 28 additions & 14 deletions include/media/AudioSystem.h
@@ -1,4 +1,6 @@
/*
* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
* Not a Contribution.
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -18,6 +20,7 @@
#define ANDROID_AUDIOSYSTEM_H_

#include <hardware/audio_effect.h>
#include <media/AudioPolicy.h>
#include <media/IAudioFlingerClient.h>
#include <media/IAudioPolicyServiceClient.h>
#include <system/audio.h>
Expand Down Expand Up @@ -90,7 +93,7 @@ class AudioSystem
static void setErrorCallback(audio_error_callback cb);

// helper function to obtain AudioFlinger service handle
static const sp<IAudioFlinger>& get_audio_flinger();
static const sp<IAudioFlinger> get_audio_flinger();

static float linearToLog(int volume);
static int logToLinear(float volume);
Expand All @@ -99,8 +102,6 @@ class AudioSystem
// to be non-zero if status == NO_ERROR
static status_t getOutputSamplingRate(uint32_t* samplingRate,
audio_stream_type_t stream);
static status_t getOutputSamplingRateForAttr(uint32_t* samplingRate,
const audio_attributes_t *attr);
static status_t getOutputFrameCount(size_t* frameCount,
audio_stream_type_t stream);
static status_t getOutputLatency(uint32_t* latency,
Expand All @@ -116,8 +117,6 @@ class AudioSystem
static status_t getLatency(audio_io_handle_t output,
uint32_t* latency);

static bool routedToA2dpOutput(audio_stream_type_t streamType);

// return status NO_ERROR implies *buffSize > 0
static status_t getInputBufferSize(uint32_t sampleRate, audio_format_t format,
audio_channel_mask_t channelMask, size_t* buffSize);
Expand Down Expand Up @@ -163,6 +162,9 @@ class AudioSystem
INPUT_CLOSED,
INPUT_CONFIG_CHANGED,
STREAM_CONFIG_CHANGED,
#ifdef QCOM_DIRECTTRACK
EFFECT_CONFIG_CHANGED,
#endif
NUM_CONFIG_EVENTS
};

Expand Down Expand Up @@ -219,28 +221,34 @@ class AudioSystem
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);
static audio_io_handle_t getOutputForAttr(const audio_attributes_t *attr,
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);
static status_t startOutput(audio_io_handle_t output,
audio_stream_type_t stream,
int session);
audio_session_t session);
static status_t stopOutput(audio_io_handle_t output,
audio_stream_type_t stream,
int session);
static void releaseOutput(audio_io_handle_t output);
audio_session_t session);
static void releaseOutput(audio_io_handle_t output,
audio_stream_type_t stream,
audio_session_t session);

// Client must successfully hand off the handle reference to AudioFlinger via openRecord(),
// or release it with releaseInput().
static audio_io_handle_t getInput(audio_source_t inputSource,
static status_t getInputForAttr(const audio_attributes_t *attr,
audio_io_handle_t *input,
audio_session_t session,
uint32_t samplingRate,
audio_format_t format,
audio_channel_mask_t channelMask,
int sessionId,
audio_input_flags_t);
audio_input_flags_t flags);

static status_t startInput(audio_io_handle_t input,
audio_session_t session);
Expand Down Expand Up @@ -274,7 +282,7 @@ class AudioSystem
// and output configuration cache (gOutputs)
static void clearAudioConfigCache();

static const sp<IAudioPolicyService>& get_audio_policy_service();
static const sp<IAudioPolicyService> get_audio_policy_service();

// helpers for android.media.AudioManager.getProperty(), see description there for meaning
static uint32_t getPrimaryOutputSamplingRate();
Expand Down Expand Up @@ -322,6 +330,8 @@ class AudioSystem

static audio_mode_t getPhoneState();

static status_t registerPolicyMixes(Vector<AudioMix> mixes, bool registration);

// ----------------------------------------------------------------------------

class AudioPortCallback : public RefBase
Expand Down Expand Up @@ -377,7 +387,11 @@ class AudioSystem
friend class AudioFlingerClient;
friend class AudioPolicyServiceClient;

static Mutex gLock;
static Mutex gLock; // protects gAudioFlinger and gAudioErrorCallback,
static Mutex gLockCache; // protects gOutputs, gPrevInSamplingRate, gPrevInFormat,
// gPrevInChannelMask and gInBuffSize
static Mutex gLockAPS; // protects gAudioPolicyService and gAudioPolicyServiceClient
static Mutex gLockAPC; // protects gAudioPortCallback
static sp<IAudioFlinger> gAudioFlinger;
static audio_error_callback gAudioErrorCallback;

Expand Down
82 changes: 73 additions & 9 deletions include/media/AudioTrack.h
@@ -1,4 +1,6 @@
/*
* Copyright (c) 2013, The Linux Foundation. All rights reserved.
* Not a Contribution.
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -22,7 +24,10 @@
#include <media/AudioTimestamp.h>
#include <media/IAudioTrack.h>
#include <utils/threads.h>

#ifdef QCOM_DIRECTTRACK
#include <media/IDirectTrack.h>
#include <media/IDirectTrackClient.h>
#endif
namespace android {

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -61,6 +66,9 @@ class AudioTrack : public RefBase
EVENT_NEW_TIMESTAMP = 8, // Delivered periodically and when there's a significant change
// in the mapping from frame position to presentation time.
// See AudioTimestamp for the information included with event.
#ifdef QCOM_DIRECTTRACK
EVENT_HW_FAIL = 9, // ADSP failure.
#endif
};

/* Client should declare Buffer on the stack and pass address to obtainBuffer()
Expand Down Expand Up @@ -221,9 +229,8 @@ class AudioTrack : public RefBase
/* Terminates the AudioTrack and unregisters it from AudioFlinger.
* Also destroys all resources associated with the AudioTrack.
*/
protected:

virtual ~AudioTrack();
public:

/* Initialize an AudioTrack that was created using the AudioTrack() constructor.
* Don't call set() more than once, or after the AudioTrack() constructors that take parameters.
Expand All @@ -239,6 +246,9 @@ class AudioTrack : public RefBase
* Parameters not listed in the AudioTrack constructors above:
*
* threadCanCallJava: Whether callbacks are made from an attached thread and thus can call JNI.
*
* Internal state post condition:
* (mStreamType == AUDIO_STREAM_DEFAULT) implies this AudioTrack has valid attributes
*/
status_t set(audio_stream_type_t streamType,
uint32_t sampleRate,
Expand Down Expand Up @@ -273,7 +283,7 @@ class AudioTrack : public RefBase

/* getters, see constructors and set() */

audio_stream_type_t streamType() const { return mStreamType; }
audio_stream_type_t streamType() const;
audio_format_t format() const { return mFormat; }

/* Return frame size in bytes, which for linear PCM is
Expand Down Expand Up @@ -532,6 +542,12 @@ class AudioTrack : public RefBase
*/
status_t obtainBuffer(Buffer* audioBuffer, const struct timespec *requested,
struct timespec *elapsed = NULL, size_t *nonContig = NULL);
// To decide whether or not to offload the pcm track thats being created
bool canOffloadTrack(audio_stream_type_t streamType, audio_format_t format,
audio_channel_mask_t channelMask, audio_output_flags_t flags,
transfer_type transferType,
audio_attributes_t *attributes,
const audio_offload_info_t *offloadInfo);
public:

/* Release a filled buffer of "audioBuffer->frameCount" frames for AudioFlinger to process. */
Expand Down Expand Up @@ -590,17 +606,18 @@ class AudioTrack : public RefBase
*
* The timestamp parameter is undefined on return, if status is not NO_ERROR.
*/
status_t getTimestamp(AudioTimestamp& timestamp);
virtual status_t getTimestamp(AudioTimestamp& timestamp);
#ifdef QCOM_DIRECTTRACK
virtual void notify(int msg);
virtual status_t getTimeStamp(uint64_t *tstamp);
#endif

protected:
/* copying audio tracks is not allowed */
AudioTrack(const AudioTrack& other);
AudioTrack& operator = (const AudioTrack& other);

void setAttributesFromStreamType(audio_stream_type_t streamType);
void setStreamTypeFromAttributes(audio_attributes_t& aa);
/* paa is guaranteed non-NULL */
bool isValidAttributes(const audio_attributes_t *paa);

/* a small internal class to handle the callback */
class AudioTrackThread : public Thread
Expand Down Expand Up @@ -670,13 +687,29 @@ class AudioTrack : public RefBase
// increment mPosition by the delta of mServer, and return new value of mPosition
uint32_t updateAndGetPosition_l();

static bool decideTrackOffloadFromStreamType(const audio_stream_type_t sType);

static bool decideTrackOffloadfromAttributes(const audio_attributes_t *pAttributes);

void initializeTrackOffloadParams();

void setTrackOffloadParams(audio_output_flags_t flags);

void resetTrackOffloadParams();

// Next 4 fields may be changed if IAudioTrack is re-created, but always != 0
#ifdef QCOM_DIRECTTRACK
sp<IDirectTrack> mDirectTrack;
#endif
sp<IAudioTrack> mAudioTrack;
sp<IMemory> mCblkMemory;
audio_track_cblk_t* mCblk; // re-load after mLock.unlock()
audio_io_handle_t mOutput; // returned by AudioSystem::getOutput()

sp<AudioTrackThread> mAudioTrackThread;
#ifdef QCOM_DIRECTTRACK
sp<IAudioFlinger> mAudioFlinger;
#endif

float mVolume[2];
float mSendLevel;
Expand All @@ -688,19 +721,25 @@ class AudioTrack : public RefBase

// constant after constructor or set()
audio_format_t mFormat; // as requested by client, not forced to 16-bit
audio_stream_type_t mStreamType;
audio_format_t mOriginalFormat;
audio_stream_type_t mStreamType; // mStreamType == AUDIO_STREAM_DEFAULT implies
// this AudioTrack has valid attributes
bool mValidStreamType;
uint32_t mChannelCount;
audio_channel_mask_t mChannelMask;
sp<IMemory> mSharedBuffer;
transfer_type mTransfer;
audio_offload_info_t mOffloadInfoCopy;
const audio_offload_info_t* mOffloadInfo;
audio_attributes_t mAttributes;
bool mValidAttributes;

// mFrameSize is equal to mFrameSizeAF for non-PCM or 16-bit PCM data. For 8-bit PCM data, it's
// twice as large as mFrameSize because data is expanded to 16-bit before it's stored in buffer.
size_t mFrameSize; // app-level frame size
size_t mOriginalFrameSize;
size_t mFrameSizeAF; // AudioFlinger frame size
size_t mOriginalFrameSizeAF;

status_t mStatus;

Expand Down Expand Up @@ -758,6 +797,13 @@ class AudioTrack : public RefBase
// only used for offloaded and direct tracks.

audio_output_flags_t mFlags;
#ifdef QCOM_DIRECTTRACK
audio_io_handle_t mAudioDirectOutput;
void* mObserver;
#endif

audio_output_flags_t mOriginalFlags;
bool mSavedParams;
// const after set(), except for bits AUDIO_OUTPUT_FLAG_FAST and AUDIO_OUTPUT_FLAG_OFFLOAD.
// mLock must be held to read or write those bits reliably.

Expand All @@ -770,6 +816,8 @@ class AudioTrack : public RefBase
int mPreviousPriority; // before start()
SchedPolicy mPreviousSchedulingGroup;
bool mAwaitBoost; // thread should wait for priority boost before running
bool mUseSmallBuf; // to indicate that hal has to use small buffers for
// offload in pcm offload use case

// The proxy should only be referenced while a lock is held because the proxy isn't
// multi-thread safe, especially the SingleStateQueue part of the proxy.
Expand All @@ -782,6 +830,11 @@ class AudioTrack : public RefBase
bool mInUnderrun; // whether track is currently in underrun state
uint32_t mPausedPosition;

//the following structures are used for tracks with PCM data that are offloaded
audio_offload_info_t mPcmTrackOffloadInfo; //offload info structure for pcm tracks
bool mIsPcmTrackOffloaded; //whether the track is offloaded or not
bool mCanOffloadPcmTrack; //whether or not an offload profile exists

private:
class DeathNotifier : public IBinder::DeathRecipient {
public:
Expand All @@ -796,6 +849,17 @@ class AudioTrack : public RefBase
uint32_t mSequence; // incremented for each new IAudioTrack attempt
int mClientUid;
pid_t mClientPid;

#ifdef QCOM_DIRECTTRACK
class DirectClient : public BnDirectTrackClient {
public:
DirectClient(AudioTrack * audioTrack) : mAudioTrack(audioTrack) { }
virtual void notify(int msg);
private:
const wp<AudioTrack> mAudioTrack;
};
sp<DirectClient> mDirectClient;
#endif
};

class TimedAudioTrack : public AudioTrack
Expand Down
23 changes: 22 additions & 1 deletion include/media/IAudioFlinger.h
@@ -1,5 +1,7 @@
/*
* Copyright (C) 2007 The Android Open Source Project
* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
* Not a contribution.
* 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.
Expand All @@ -24,6 +26,10 @@
#include <utils/RefBase.h>
#include <utils/Errors.h>
#include <binder/IInterface.h>
#ifdef QCOM_DIRECTTRACK
#include <media/IDirectTrack.h>
#include <media/IDirectTrackClient.h>
#endif
#include <media/IAudioTrack.h>
#include <media/IAudioRecord.h>
#include <media/IAudioFlingerClient.h>
Expand Down Expand Up @@ -77,6 +83,21 @@ class IAudioFlinger : public IInterface
int clientUid,
status_t *status) = 0;

#ifdef QCOM_DIRECTTRACK
/* create a direct audio track and registers it with AudioFlinger.
* return null if the track cannot be created.
*/
virtual sp<IDirectTrack> createDirectTrack(
pid_t pid,
uint32_t sampleRate,
audio_channel_mask_t channelMask,
audio_io_handle_t output,
int *sessionId,
IDirectTrackClient* client,
audio_stream_type_t streamType,
status_t *status) = 0;
#endif

virtual sp<IAudioRecord> openRecord(
// On successful return, AudioFlinger takes over the handle
// reference and will release it when the track is destroyed.
Expand Down
39 changes: 24 additions & 15 deletions include/media/IAudioPolicyService.h
Expand Up @@ -25,6 +25,7 @@
#include <utils/Errors.h>
#include <binder/IInterface.h>
#include <media/AudioSystem.h>
#include <media/AudioPolicy.h>
#include <media/IAudioPolicyServiceClient.h>

#include <system/audio_policy.h>
Expand Down Expand Up @@ -56,25 +57,31 @@ class IAudioPolicyService : public IInterface
audio_channel_mask_t channelMask = 0,
audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE,
const audio_offload_info_t *offloadInfo = NULL) = 0;
virtual audio_io_handle_t getOutputForAttr(const audio_attributes_t *attr,
uint32_t samplingRate = 0,
audio_format_t format = AUDIO_FORMAT_DEFAULT,
audio_channel_mask_t channelMask = 0,
audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE,
const audio_offload_info_t *offloadInfo = NULL) = 0;
virtual 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 = 0,
audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE,
const audio_offload_info_t *offloadInfo = NULL) = 0;
virtual status_t startOutput(audio_io_handle_t output,
audio_stream_type_t stream,
int session = 0) = 0;
audio_session_t session) = 0;
virtual status_t stopOutput(audio_io_handle_t output,
audio_stream_type_t stream,
int session = 0) = 0;
virtual void releaseOutput(audio_io_handle_t output) = 0;
virtual audio_io_handle_t getInput(audio_source_t inputSource,
uint32_t samplingRate,
audio_format_t format,
audio_channel_mask_t channelMask,
int audioSession,
audio_input_flags_t flags) = 0;
audio_session_t session) = 0;
virtual void releaseOutput(audio_io_handle_t output,
audio_stream_type_t stream,
audio_session_t session) = 0;
virtual status_t getInputForAttr(const audio_attributes_t *attr,
audio_io_handle_t *input,
audio_session_t session,
uint32_t samplingRate,
audio_format_t format,
audio_channel_mask_t channelMask,
audio_input_flags_t flags) = 0;
virtual status_t startInput(audio_io_handle_t input,
audio_session_t session) = 0;
virtual status_t stopInput(audio_io_handle_t input,
Expand Down Expand Up @@ -144,6 +151,8 @@ class IAudioPolicyService : public IInterface
virtual status_t releaseSoundTriggerSession(audio_session_t session) = 0;

virtual audio_mode_t getPhoneState() = 0;

virtual status_t registerPolicyMixes(Vector<AudioMix> mixes, bool registration) = 0;
};


Expand Down
3 changes: 2 additions & 1 deletion include/media/ICrypto.h
Expand Up @@ -41,6 +41,8 @@ struct ICrypto : public IInterface {
virtual bool requiresSecureDecoderComponent(
const char *mime) const = 0;

virtual void notifyResolution(uint32_t width, uint32_t height) = 0;

virtual ssize_t decrypt(
bool secure,
const uint8_t key[16],
Expand All @@ -64,4 +66,3 @@ struct BnCrypto : public BnInterface<ICrypto> {
} // namespace android

#endif // ANDROID_ICRYPTO_H_

92 changes: 92 additions & 0 deletions include/media/IDirectTrack.h
@@ -0,0 +1,92 @@
/*
* Copyright (c) 2012, The Linux Foundation. All rights reserved.
* Not a Contribution.
*
* 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_IDIRECTTRACK_H
#define ANDROID_IDIRECTTRACK_H

#include <stdint.h>
#include <sys/types.h>

#include <utils/RefBase.h>
#include <utils/Errors.h>
#include <binder/IInterface.h>
#include <binder/IMemory.h>


namespace android {

// ----------------------------------------------------------------------------

class IDirectTrack : public IInterface
{
public:
DECLARE_META_INTERFACE(DirectTrack);

/* After it's created the track is not active. Call start() to
* make it active. If set, the callback will start being called.
*/
virtual status_t start() = 0;

/* Stop a track. If set, the callback will cease being called and
* obtainBuffer will return an error. Buffers that are already released
* will be processed, unless flush() is called.
*/
virtual void stop() = 0;

/* flush a stopped track. All pending buffers are discarded.
* This function has no effect if the track is not stoped.
*/
virtual void flush() = 0;

/* mute or unmutes this track.
* While mutted, the callback, if set, is still called.
*/
virtual void mute(bool) = 0;

/* Pause a track. If set, the callback will cease being called and
* obtainBuffer will return an error. Buffers that are already released
* will be processed, unless flush() is called.
*/
virtual void pause() = 0;

/* set volume for both left and right channels.
*/
virtual void setVolume(float l, float r) = 0;

virtual ssize_t write(const void*, size_t) = 0;

virtual int64_t getTimeStamp() = 0;
};

// ----------------------------------------------------------------------------

class BnDirectTrack : public BnInterface<IDirectTrack>
{
public:
virtual status_t onTransact( uint32_t code,
const Parcel& data,
Parcel* reply,
uint32_t flags = 0);
};

// ----------------------------------------------------------------------------

}; // namespace android

#endif // ANDROID_IAUDIOTRACK_H
50 changes: 50 additions & 0 deletions include/media/IDirectTrackClient.h
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2012, The Linux Foundation. All rights reserved.
* Not a Contribution.
*
* 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_IDIRECTTRACKCLIENT_H
#define ANDROID_IDIRECTTRACKCLIENT_H

#include <utils/RefBase.h>
#include <binder/IInterface.h>
#include <binder/Parcel.h>

namespace android {

class IDirectTrackClient: public IInterface
{
public:
DECLARE_META_INTERFACE(DirectTrackClient);

virtual void notify(int msg) = 0;
};

// ----------------------------------------------------------------------------

class BnDirectTrackClient: public BnInterface<IDirectTrackClient>
{
public:
virtual status_t onTransact( uint32_t code,
const Parcel& data,
Parcel* reply,
uint32_t flags = 0);
};

}; // namespace android

#endif // ANDROID_IDIRECTTRACKCLIENT_H
3 changes: 2 additions & 1 deletion include/media/IDrm.h
Expand Up @@ -73,8 +73,10 @@ struct IDrm : public IInterface {
virtual status_t unprovisionDevice() = 0;

virtual status_t getSecureStops(List<Vector<uint8_t> > &secureStops) = 0;
virtual status_t getSecureStop(Vector<uint8_t> const &ssid, Vector<uint8_t> &secureStop) = 0;

virtual status_t releaseSecureStops(Vector<uint8_t> const &ssRelease) = 0;
virtual status_t releaseAllSecureStops() = 0;

virtual status_t getPropertyString(String8 const &name, String8 &value) const = 0;
virtual status_t getPropertyByteArray(String8 const &name,
Expand Down Expand Up @@ -137,4 +139,3 @@ struct BnDrm : public BnInterface<IDrm> {
} // namespace android

#endif // ANDROID_IDRM_H_

2 changes: 1 addition & 1 deletion include/media/IMediaDeathNotifier.h
Expand Up @@ -30,7 +30,7 @@ class IMediaDeathNotifier: virtual public RefBase
virtual ~IMediaDeathNotifier() { removeObitRecipient(this); }

virtual void died() = 0;
static const sp<IMediaPlayerService>& getMediaPlayerService();
static const sp<IMediaPlayerService> getMediaPlayerService();

private:
IMediaDeathNotifier &operator=(const IMediaDeathNotifier &);
Expand Down
10 changes: 8 additions & 2 deletions include/media/IOMX.h
Expand Up @@ -99,7 +99,7 @@ class IOMX : public IInterface {

virtual status_t useBuffer(
node_id node, OMX_U32 port_index, const sp<IMemory> &params,
buffer_id *buffer) = 0;
buffer_id *buffer, OMX_BOOL crossProcess = OMX_FALSE) = 0;

virtual status_t useGraphicBuffer(
node_id node, OMX_U32 port_index,
Expand All @@ -125,7 +125,7 @@ class IOMX : public IInterface {

virtual status_t allocateBufferWithBackup(
node_id node, OMX_U32 port_index, const sp<IMemory> &params,
buffer_id *buffer) = 0;
buffer_id *buffer, OMX_BOOL crossProcess = OMX_FALSE) = 0;

virtual status_t freeBuffer(
node_id node, OMX_U32 port_index, buffer_id buffer) = 0;
Expand Down Expand Up @@ -207,6 +207,12 @@ class BnOMX : public BnInterface<IOMX> {
virtual status_t onTransact(
uint32_t code, const Parcel &data, Parcel *reply,
uint32_t flags = 0);

protected:
// check if the codec is secure.
virtual bool isSecure(IOMX::node_id node) {
return false;
}
};

class BnOMXObserver : public BnInterface<IOMXObserver> {
Expand Down
28 changes: 24 additions & 4 deletions include/media/MediaPlayerInterface.h
@@ -1,4 +1,6 @@
/*
* Copyright (c) 2013, The Linux Foundation. All rights reserved.
* Not a Contribution.
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -80,8 +82,12 @@ class MediaPlayerBase : public RefBase
CB_EVENT_FILL_BUFFER, // Request to write more data to buffer.
CB_EVENT_STREAM_END, // Sent after all the buffers queued in AF and HW are played
// back (after stop is called)
CB_EVENT_TEAR_DOWN // The AudioTrack was invalidated due to use case change:
CB_EVENT_TEAR_DOWN, // The AudioTrack was invalidated due to use case change:
// Need to re-evaluate offloading options
#ifdef QCOM_DIRECTTRACK
CB_EVENT_UNDERRUN,
CB_EVENT_HW_FAIL
#endif
};

// Callback returns the number of bytes actually written to the buffer.
Expand All @@ -97,6 +103,9 @@ class MediaPlayerBase : public RefBase
virtual ssize_t channelCount() const = 0;
virtual ssize_t frameSize() const = 0;
virtual uint32_t latency() const = 0;
#ifdef QCOM_DIRECTTRACK
virtual audio_stream_type_t streamType() const {return AUDIO_STREAM_DEFAULT;}
#endif
virtual float msecsPerFrame() const = 0;
virtual status_t getPosition(uint32_t *position) const = 0;
virtual status_t getTimestamp(AudioTimestamp &ts) const = 0;
Expand Down Expand Up @@ -125,9 +134,13 @@ class MediaPlayerBase : public RefBase

virtual status_t setPlaybackRatePermille(int32_t rate) { return INVALID_OPERATION; }
virtual bool needsTrailingPadding() { return true; }

virtual status_t setParameters(const String8& keyValuePairs) { return NO_ERROR; };
virtual String8 getParameters(const String8& keys) { return String8::empty(); };

#ifdef QCOM_DIRECTTRACK
virtual ssize_t sampleRate() const {return 0;};
virtual status_t getTimeStamp(uint64_t *tstamp) {return 0;};
#endif
};

MediaPlayerBase() : mCookie(0), mNotify(0) {}
Expand Down Expand Up @@ -209,8 +222,15 @@ class MediaPlayerBase : public RefBase

void sendEvent(int msg, int ext1=0, int ext2=0,
const Parcel *obj=NULL) {
Mutex::Autolock autoLock(mNotifyLock);
if (mNotify) mNotify(mCookie, msg, ext1, ext2, obj);
notify_callback_f notifyCB;
void* cookie;
{
Mutex::Autolock autoLock(mNotifyLock);
notifyCB = mNotify;
cookie = mCookie;
}

if (notifyCB) notifyCB(cookie, msg, ext1, ext2, obj);
}

virtual status_t dump(int fd, const Vector<String16> &args) const {
Expand Down
33 changes: 17 additions & 16 deletions include/media/MediaProfiles.h
Expand Up @@ -34,16 +34,17 @@ enum camcorder_quality {
CAMCORDER_QUALITY_1080P = 6,
CAMCORDER_QUALITY_QVGA = 7,
CAMCORDER_QUALITY_2160P = 8, // a.k.a 4K-UHD
CAMCORDER_QUALITY_WVGA = 9,
CAMCORDER_QUALITY_VGA = 10,
CAMCORDER_QUALITY_WQVGA = 11,
CAMCORDER_QUALITY_FWVGA = 12,
CAMCORDER_QUALITY_4kDCI = 13,
CAMCORDER_QUALITY_HEVC720P = 14,
CAMCORDER_QUALITY_HEVC1080P = 15,
CAMCORDER_QUALITY_HEVC4kUHD = 16,
CAMCORDER_QUALITY_HEVC4kDCI = 17,
CAMCORDER_QUALITY_LIST_END = 17,
CAMCORDER_QUALITY_WVGA = 10,
CAMCORDER_QUALITY_VGA = 11,
CAMCORDER_QUALITY_WQVGA = 12,
CAMCORDER_QUALITY_FWVGA = 13,
CAMCORDER_QUALITY_4kDCI = 14,
CAMCORDER_QUALITY_HEVC720P = 15,
CAMCORDER_QUALITY_HEVC1080P = 16,
CAMCORDER_QUALITY_HEVC4kUHD = 17,
CAMCORDER_QUALITY_HEVC4kDCI = 18,
CAMCORDER_QUALITY_HVGA = 19,
CAMCORDER_QUALITY_LIST_END = 19,

CAMCORDER_QUALITY_TIME_LAPSE_LIST_START = 1000,
CAMCORDER_QUALITY_TIME_LAPSE_LOW = 1000,
Expand All @@ -55,12 +56,12 @@ enum camcorder_quality {
CAMCORDER_QUALITY_TIME_LAPSE_1080P = 1006,
CAMCORDER_QUALITY_TIME_LAPSE_QVGA = 1007,
CAMCORDER_QUALITY_TIME_LAPSE_2160P = 1008,
CAMCORDER_QUALITY_TIME_LAPSE_WVGA = 1009,
CAMCORDER_QUALITY_TIME_LAPSE_VGA = 1010,
CAMCORDER_QUALITY_TIME_LAPSE_WQVGA = 1011,
CAMCORDER_QUALITY_TIME_LAPSE_FWVGA = 1012,
CAMCORDER_QUALITY_TIME_LAPSE_4kDCI = 1013,
CAMCORDER_QUALITY_TIME_LAPSE_LIST_END = 1013,
CAMCORDER_QUALITY_TIME_LAPSE_WVGA = 1010,
CAMCORDER_QUALITY_TIME_LAPSE_VGA = 1011,
CAMCORDER_QUALITY_TIME_LAPSE_WQVGA = 1012,
CAMCORDER_QUALITY_TIME_LAPSE_FWVGA = 1013,
CAMCORDER_QUALITY_TIME_LAPSE_4kDCI = 1014,
CAMCORDER_QUALITY_TIME_LAPSE_LIST_END = 1014,

CAMCORDER_QUALITY_HIGH_SPEED_LIST_START = 2000,
CAMCORDER_QUALITY_HIGH_SPEED_LOW = 2000,
Expand Down
2 changes: 2 additions & 0 deletions include/media/Metadata.h
Expand Up @@ -92,6 +92,8 @@ class Metadata {
static const Type kNumTracks = 30; // Integer
static const Type kDrmCrippled = 31; // Boolean

static const Type kServerTimeout = 8801; // Integer, ms, RTSP server timeout

// @param p[inout] The parcel to append the metadata records
// to. The global metadata header should have been set already.
explicit Metadata(Parcel *p);
Expand Down
8 changes: 5 additions & 3 deletions include/media/SoundPool.h
Expand Up @@ -144,6 +144,7 @@ class SoundChannel : public SoundEvent {
void nextEvent();
int nextChannelID() { return mNextEvent.channelID(); }
void dump();
int getPrevSampleID(void) { return mPrevSampleID; }

private:
static void callback(int event, void* user, void *info);
Expand All @@ -160,6 +161,7 @@ class SoundChannel : public SoundEvent {
int mAudioBufferSize;
unsigned long mToggle;
bool mAutoPaused;
int mPrevSampleID;
};

// application object for managing a pool of sounds
Expand Down Expand Up @@ -187,6 +189,7 @@ class SoundPool {

// called from SoundPoolThread
void sampleLoaded(int sampleID);
sp<Sample> findSample(int sampleID);

// called from AudioTrack thread
void done_l(SoundChannel* channel);
Expand All @@ -198,11 +201,10 @@ class SoundPool {
private:
SoundPool() {} // no default constructor
bool startThreads();
void doLoad(sp<Sample>& sample);
sp<Sample> findSample(int sampleID) { return mSamples.valueFor(sampleID); }
sp<Sample> findSample_l(int sampleID);
SoundChannel* findChannel (int channelID);
SoundChannel* findNextChannel (int channelID);
SoundChannel* allocateChannel_l(int priority);
SoundChannel* allocateChannel_l(int priority, int sampleID);
void moveToFront_l(SoundChannel* channel);
void notify(SoundPoolEvent event);
void dump();
Expand Down
2 changes: 1 addition & 1 deletion include/media/ToneGenerator.h
Expand Up @@ -211,7 +211,7 @@ class ToneGenerator {
static const unsigned int TONEGEN_MAX_WAVES = 3; // Maximun number of sine waves in a tone segment
static const unsigned int TONEGEN_MAX_SEGMENTS = 12; // Maximun number of segments in a tone descriptor
static const unsigned int TONEGEN_INF = 0xFFFFFFFF; // Represents infinite time duration
static const float TONEGEN_GAIN = 0.9; // Default gain passed to WaveGenerator().
#define TONEGEN_GAIN 0.9 // Default gain passed to WaveGenerator().

// ToneDescriptor class contains all parameters needed to generate a tone:
// - The array waveFreq[]:
Expand Down
1 change: 1 addition & 0 deletions include/media/Visualizer.h
Expand Up @@ -95,6 +95,7 @@ class Visualizer: public AudioEffect {
// install a callback to receive periodic captures. The capture rate is specified in milliHertz
// and the capture format is according to flags (see callback_flags).
status_t setCaptureCallBack(capture_cbk_t cbk, void* user, uint32_t flags, uint32_t rate);
void cancelCaptureCallBack();

// set the capture size capture size must be a power of two in the range
// [VISUALIZER_CAPTURE_SIZE_MAX. VISUALIZER_CAPTURE_SIZE_MIN]
Expand Down
2 changes: 1 addition & 1 deletion include/media/mediametadataretriever.h
Expand Up @@ -79,7 +79,7 @@ class MediaMetadataRetriever: public RefBase
const char* extractMetadata(int keyCode);

private:
static const sp<IMediaPlayerService>& getService();
static const sp<IMediaPlayerService> getService();

class DeathNotifier: public IBinder::DeathRecipient
{
Expand Down
17 changes: 17 additions & 0 deletions include/media/mediaplayer.h
Expand Up @@ -206,6 +206,12 @@ class MediaPlayer : public BnMediaPlayerClient,
void died();
void disconnect();

#ifdef SAMSUNG_CAMERA_LEGACY
status_t setDataSource(
const char *url,
const KeyedVector<String8, String8> *headers);
#endif

status_t setDataSource(
const sp<IMediaHTTPService> &httpService,
const char *url,
Expand Down Expand Up @@ -234,6 +240,17 @@ class MediaPlayer : public BnMediaPlayerClient,
bool isLooping();
status_t setVolume(float leftVolume, float rightVolume);
void notify(int msg, int ext1, int ext2, const Parcel *obj = NULL);

#ifdef SAMSUNG_CAMERA_LEGACY
static status_t decode(
const char* url,
uint32_t *pSampleRate,
int* pNumChannels,
audio_format_t* pFormat,
const sp<IMemoryHeap>& heap,
size_t *pSize);
#endif

static status_t decode(
const sp<IMediaHTTPService> &httpService,
const char* url,
Expand Down
2 changes: 2 additions & 0 deletions include/media/nbaio/AudioStreamOutSink.h
Expand Up @@ -52,7 +52,9 @@ class AudioStreamOutSink : public NBAIO_Sink {
// implementation of GNWT (if any)
virtual status_t getNextWriteTimestamp(int64_t *timestamp);

#ifndef HAVE_PRE_KITKAT_AUDIO_BLOB
virtual status_t getTimestamp(AudioTimestamp& timestamp);
#endif

// NBAIO_Sink end

Expand Down
43 changes: 33 additions & 10 deletions include/media/stagefright/ACodec.h
Expand Up @@ -23,11 +23,21 @@
#include <media/IOMX.h>
#include <media/stagefright/foundation/AHierarchicalStateMachine.h>
#include <media/stagefright/CodecBase.h>
#include <media/stagefright/ExtendedStats.h>
#include <media/stagefright/SkipCutBuffer.h>
#include <OMX_Audio.h>

#include <system/audio.h>

#define TRACK_BUFFER_TIMING 0

#define CODEC_PLAYER_STATS(func, ...) \
do { \
if(mCodec != NULL && mCodec->mMediaExtendedStats != NULL) { \
mCodec->mMediaExtendedStats->func(__VA_ARGS__);} \
} \
while(0)

namespace android {

struct ABuffer;
Expand Down Expand Up @@ -78,7 +88,7 @@ struct ACodec : public AHierarchicalStateMachine, public CodecBase {

static bool isFlexibleColorFormat(
const sp<IOMX> &omx, IOMX::node_id node,
uint32_t colorFormat, OMX_U32 *flexibleEquivalent);
uint32_t colorFormat, bool usingNativeBuffers, OMX_U32 *flexibleEquivalent);

// Returns 0 if configuration is not supported. NOTE: this is treated by
// some OMX components as auto level, and by others as invalid level.
Expand Down Expand Up @@ -131,8 +141,7 @@ struct ACodec : public AHierarchicalStateMachine, public CodecBase {
enum {
kFlagIsSecure = 1,
kFlagPushBlankBuffersToNativeWindowOnShutdown = 2,
// protection against screen capture of non-secure drm content
kFlagIsContentDrmProtected = 3,
kFlagIsGrallocUsageProtected = 4,
};

struct BufferInfo {
Expand Down Expand Up @@ -173,6 +182,7 @@ struct ACodec : public AHierarchicalStateMachine, public CodecBase {
sp<IdleToLoadedState> mIdleToLoadedState;
sp<FlushingState> mFlushingState;
sp<SkipCutBuffer> mSkipCutBuffer;
sp<MediaExtendedStats> mMediaExtendedStats;

AString mComponentName;
uint32_t mFlags;
Expand All @@ -184,6 +194,7 @@ struct ACodec : public AHierarchicalStateMachine, public CodecBase {
sp<ANativeWindow> mNativeWindow;
sp<AMessage> mInputFormat;
sp<AMessage> mOutputFormat;
sp<AMessage> mBaseOutputFormat;

Vector<BufferInfo> mBuffers[2];
bool mPortEOS[2];
Expand All @@ -194,6 +205,9 @@ struct ACodec : public AHierarchicalStateMachine, public CodecBase {
bool mSentFormat;
bool mIsEncoder;
bool mUseMetadataOnEncoderOutput;
bool mFatalError;
bool mEncoderComponent;
bool mComponentAllocByName;
bool mShutdownInProgress;
bool mExplicitShutdown;

Expand Down Expand Up @@ -222,6 +236,8 @@ struct ACodec : public AHierarchicalStateMachine, public CodecBase {

bool mTunneled;

bool mIsVideoRenderingDisabled;

status_t setCyclicIntraMacroblockRefresh(const sp<AMessage> &msg, int32_t mode);
status_t allocateBuffersOnPort(OMX_U32 portIndex);
status_t freeBuffersOnPort(OMX_U32 portIndex);
Expand All @@ -234,6 +250,9 @@ struct ACodec : public AHierarchicalStateMachine, public CodecBase {
status_t submitOutputMetaDataBuffer();
void signalSubmitOutputMetaDataBufferIfEOS_workaround();
status_t allocateOutputBuffersFromNativeWindow();
#ifdef USE_SAMSUNG_COLORFORMAT
void setNativeWindowColorFormat(OMX_COLOR_FORMATTYPE &eNativeColorFormat);
#endif
status_t cancelBufferToNativeWindow(BufferInfo *info);
status_t freeOutputBuffersNotOwnedByComponent();
BufferInfo *dequeueBufferFromNativeWindow();
Expand All @@ -251,20 +270,21 @@ struct ACodec : public AHierarchicalStateMachine, public CodecBase {
status_t setVideoPortFormatType(
OMX_U32 portIndex,
OMX_VIDEO_CODINGTYPE compressionFormat,
OMX_COLOR_FORMATTYPE colorFormat);
OMX_COLOR_FORMATTYPE colorFormat,
bool usingNativeBuffers = false);

status_t setSupportedOutputFormat();
status_t setSupportedOutputFormat(bool getLegacyFlexibleFormat);

status_t setupVideoDecoder(
const char *mime, const sp<AMessage> &msg);
const char *mime, const sp<AMessage> &msg, bool usingNativeBuffers);

status_t setupVideoEncoder(
const char *mime, const sp<AMessage> &msg);

status_t setVideoFormatOnPort(
OMX_U32 portIndex,
int32_t width, int32_t height,
OMX_VIDEO_CODINGTYPE compressionFormat);
OMX_VIDEO_CODINGTYPE compressionFormat, float frameRate = -1.0);

typedef struct drcParams {
int32_t drcCut;
Expand All @@ -281,7 +301,9 @@ struct ACodec : public AHierarchicalStateMachine, public CodecBase {
int32_t maxOutputChannelCount, const drcParams_t& drc,
int32_t pcmLimiterEnable);

status_t setupAC3Codec(bool encoder, int32_t numChannels, int32_t sampleRate);
status_t setupAC3Codec(bool encoder, int32_t numChannels, int32_t sampleRate, int32_t bitsPerSample);

status_t setupEAC3Codec(bool encoder, int32_t numChannels, int32_t sampleRate, int32_t bitsPerSample);

status_t selectAudioPortFormat(
OMX_U32 portIndex, OMX_AUDIO_CODINGTYPE desiredFormat);
Expand All @@ -290,10 +312,11 @@ struct ACodec : public AHierarchicalStateMachine, public CodecBase {
status_t setupG711Codec(bool encoder, int32_t numChannels);

status_t setupFlacCodec(
bool encoder, int32_t numChannels, int32_t sampleRate, int32_t compressionLevel);
bool encoder, int32_t numChannels, int32_t sampleRate, int32_t compressionLevel, int32_t bitsPerSample);

status_t setupRawAudioFormat(
OMX_U32 portIndex, int32_t sampleRate, int32_t numChannels);
OMX_U32 portIndex, int32_t sampleRate, int32_t numChannels,
int32_t bitsPerSample);

status_t setMinBufferSize(OMX_U32 portIndex, size_t size);

Expand Down
49 changes: 40 additions & 9 deletions include/media/stagefright/AudioPlayer.h
@@ -1,4 +1,6 @@
/*
* Copyright (c) 2013, The Linux Foundation. All rights reserved.
* Not a Contribution.
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,6 +14,25 @@
* 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.
*
* This file was modified by Dolby Laboratories, Inc. The portions of the
* code that are surrounded by "DOLBY..." are copyrighted and
* licensed separately, as follows:
*
* (C) 2014 Dolby Laboratories, Inc.
*
* 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 AUDIO_PLAYER_H_
Expand Down Expand Up @@ -51,27 +72,27 @@ class AudioPlayer : public TimeSource {
virtual ~AudioPlayer();

// Caller retains ownership of "source".
void setSource(const sp<MediaSource> &source);
virtual void setSource(const sp<MediaSource> &source);

// Return time in us.
virtual int64_t getRealTimeUs();

status_t start(bool sourceAlreadyStarted = false);
virtual status_t start(bool sourceAlreadyStarted = false);

void pause(bool playPendingSamples = false);
status_t resume();
virtual void pause(bool playPendingSamples = false);
virtual status_t resume();

// Returns the timestamp of the last buffer played (in us).
int64_t getMediaTimeUs();
virtual int64_t getMediaTimeUs();

// Returns true iff a mapping is established, i.e. the AudioPlayer
// has played at least one frame of audio.
bool getMediaTimeMapping(int64_t *realtime_us, int64_t *mediatime_us);
virtual bool getMediaTimeMapping(int64_t *realtime_us, int64_t *mediatime_us);

status_t seekTo(int64_t time_us);
virtual status_t seekTo(int64_t time_us);

bool isSeeking();
bool reachedEOS(status_t *finalStatus);
virtual bool isSeeking();
virtual bool reachedEOS(status_t *finalStatus);

status_t setPlaybackRatePermille(int32_t ratePermille);

Expand Down Expand Up @@ -114,9 +135,15 @@ class AudioPlayer : public TimeSource {

bool mPlaying;
int64_t mStartPosUs;
#ifdef DOLBY_UDC
bool mDolbyProcessedAudio;
void updateDolbyProcessedAudioState();
void setDolbyProcessedAudioState(bool processed);
#endif // DOLBY_END
const uint32_t mCreateFlags;
bool mPauseRequired;

bool mUseSmallBufs;
static void AudioCallback(int event, void *user, void *info);
void AudioCallback(int event, void *info);

Expand All @@ -139,6 +166,10 @@ class AudioPlayer : public TimeSource {

AudioPlayer(const AudioPlayer &);
AudioPlayer &operator=(const AudioPlayer &);

#ifdef USE_ALP_AUDIO
bool mIsALPAudio;
#endif
};

} // namespace android
Expand Down
11 changes: 9 additions & 2 deletions include/media/stagefright/AudioSource.h
Expand Up @@ -53,14 +53,17 @@ struct AudioSource : public MediaSource, public MediaBufferObserver {
MediaBuffer **buffer, const ReadOptions *options = NULL);

status_t dataCallback(const AudioRecord::Buffer& buffer);
virtual void onEvent(int event, void* info);
virtual void signalBufferReturned(MediaBuffer *buffer);

protected:
virtual ~AudioSource();

private:
enum {
kMaxBufferSize = 2048,
//This max buffer size is derived from aggregation of audio
//buffers for max duration 80 msec with 48K sampling rate.
kMaxBufferSize = 30720,

// After the initial mute, we raise the volume linearly
// over kAutoRampDurationUs.
Expand All @@ -75,6 +78,11 @@ struct AudioSource : public MediaSource, public MediaBufferObserver {
Condition mFrameAvailableCondition;
Condition mFrameEncodingCompletionCondition;

AudioRecord::Buffer mTempBuf;
uint32_t mPrevPosition;
uint32_t mAllocBytes;
int32_t mAudioSessionId;
AudioRecord::transfer_type mTransferMode;
sp<AudioRecord> mRecord;
status_t mInitCheck;
bool mStarted;
Expand All @@ -91,7 +99,6 @@ struct AudioSource : public MediaSource, public MediaBufferObserver {
int64_t mAutoRampStartUs;

List<MediaBuffer * > mBuffersReceived;

void trackMaxAmplitude(int16_t *data, int nSamples);

// This is used to raise the volume from mute to the
Expand Down
12 changes: 12 additions & 0 deletions include/media/stagefright/CameraSource.h
Expand Up @@ -27,6 +27,14 @@
#include <utils/RefBase.h>
#include <utils/String16.h>

#include <media/stagefright/ExtendedStats.h>
#define RECORDER_STATS(func, ...) \
do { \
if(mRecorderExtendedStats != NULL) { \
mRecorderExtendedStats->func(__VA_ARGS__);} \
} \
while(0)

namespace android {

class IMemory;
Expand Down Expand Up @@ -202,6 +210,7 @@ class CameraSource : public MediaSource, public MediaBufferObserver {
List<sp<IMemory> > mFramesReceived;
List<sp<IMemory> > mFramesBeingEncoded;
List<int64_t> mFrameTimes;
sp<RecorderExtendedStats> mRecorderExtendedStats;

int64_t mFirstFrameTimeUs;
int32_t mNumFramesDropped;
Expand Down Expand Up @@ -240,6 +249,9 @@ class CameraSource : public MediaSource, public MediaBufferObserver {
status_t checkFrameRate(const CameraParameters& params,
int32_t frameRate);

static void adjustIncomingANWBuffer(IMemory* data);
static void adjustOutgoingANWBuffer(IMemory* data);

void stopCameraRecording();
status_t reset();

Expand Down
3 changes: 3 additions & 0 deletions include/media/stagefright/CameraSourceTimeLapse.h
Expand Up @@ -66,6 +66,9 @@ class CameraSourceTimeLapse : public CameraSource {

// Real timestamp of the last encoded time lapse frame
int64_t mLastTimeLapseFrameRealTimestampUs;
// Adjusted continuous timestamp based on recording fps
// of the last encoded time lapse frame
int64_t mLastTimeLapseFrameTimeStampUs;

// Variable set in dataCallbackTimestamp() to help skipCurrentFrame()
// to know if current frame needs to be skipped.
Expand Down
103 changes: 97 additions & 6 deletions include/media/stagefright/DataSource.h
Expand Up @@ -19,7 +19,7 @@
#define DATA_SOURCE_H_

#include <sys/types.h>

#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/MediaErrors.h>
#include <utils/Errors.h>
#include <utils/KeyedVector.h>
Expand All @@ -35,6 +35,40 @@ struct AString;
struct IMediaHTTPService;
class String8;
struct HTTPBase;
class DataSource;

class Sniffer : public RefBase {
public:
Sniffer();

////////////////////////////////////////////////////////////////////////////

bool sniff(DataSource *source, String8 *mimeType, float *confidence, sp<AMessage> *meta);

// The sniffer can optionally fill in "meta" with an AMessage containing
// a dictionary of values that helps the corresponding extractor initialize
// its state without duplicating effort already exerted by the sniffer.
typedef bool (*SnifferFunc)(
const sp<DataSource> &source, String8 *mimeType,
float *confidence, sp<AMessage> *meta);

//if isExtendedExtractor = true, store the location of the sniffer to register
void registerSniffer_l(SnifferFunc func);
void registerDefaultSniffers();

virtual ~Sniffer() {}

private:
Mutex mSnifferMutex;
List<SnifferFunc> mSniffers;
List<SnifferFunc> mExtraSniffers;
List<SnifferFunc>::iterator extendedSnifferPosition;

void registerSnifferPlugin();

Sniffer(const Sniffer &);
Sniffer &operator=(const Sniffer &);
};

class DataSource : public RefBase {
public:
Expand All @@ -54,7 +88,7 @@ class DataSource : public RefBase {

static sp<DataSource> CreateMediaHTTP(const sp<IMediaHTTPService> &httpService);

DataSource() {}
DataSource() : mSniffer(new Sniffer()) {}

virtual status_t initCheck() const = 0;

Expand All @@ -66,6 +100,20 @@ class DataSource : public RefBase {
bool getUInt32(off64_t offset, uint32_t *x);
bool getUInt64(off64_t offset, uint64_t *x);

// Reads in "count" entries of type T into vector *x.
// Returns true if "count" entries can be read.
// If fewer than "count" entries can be read, return false. In this case,
// the output vector *x will still have those entries that were read. Call
// x->size() to obtain the number of entries read.
// The optional parameter chunkSize specifies how many entries should be
// read from the data source at one time into a temporary buffer. Increasing
// chunkSize can improve the performance at the cost of extra memory usage.
// The default value for chunkSize is set to read at least 4k bytes at a
// time, depending on sizeof(T).
template <typename T>
bool getVector(off64_t offset, Vector<T>* x, size_t count,
size_t chunkSize = (4095 / sizeof(T)) + 1);

// May return ERROR_UNSUPPORTED.
virtual status_t getSize(off64_t *size);

Expand Down Expand Up @@ -105,17 +153,60 @@ class DataSource : public RefBase {
protected:
virtual ~DataSource() {}

private:
static Mutex gSnifferMutex;
static List<SnifferFunc> gSniffers;
static bool gSniffersRegistered;
sp<Sniffer> mSniffer;

static void RegisterSniffer_l(SnifferFunc func);
static void RegisterSnifferPlugin();

DataSource(const DataSource &);
DataSource &operator=(const DataSource &);
};

template <typename T>
bool DataSource::getVector(off64_t offset, Vector<T>* x, size_t count,
size_t chunkSize)
{
x->clear();
if (chunkSize == 0) {
return false;
}
if (count == 0) {
return true;
}

T tmp[chunkSize];
ssize_t numBytesRead;
size_t numBytesPerChunk = chunkSize * sizeof(T);
size_t i;

for (i = 0; i + chunkSize < count; i += chunkSize) {
// This loops is executed when more than chunkSize records need to be
// read.
numBytesRead = this->readAt(offset, (void*)&tmp, numBytesPerChunk);
if (numBytesRead == -1) { // If readAt() returns -1, there is an error.
return false;
}
if (numBytesRead < numBytesPerChunk) {
// This case is triggered when the stream ends before the whole
// chunk is read.
x->appendArray(tmp, (size_t)numBytesRead / sizeof(T));
return false;
}
x->appendArray(tmp, chunkSize);
offset += numBytesPerChunk;
}

// There are (count - i) more records to read.
// Right now, (count - i) <= chunkSize.
// We do the same thing as above, but with chunkSize replaced by count - i.
numBytesRead = this->readAt(offset, (void*)&tmp, (count - i) * sizeof(T));
if (numBytesRead == -1) {
return false;
}
x->appendArray(tmp, (size_t)numBytesRead / sizeof(T));
return x->size() == count;
}

} // namespace android

#endif // DATA_SOURCE_H_
13 changes: 11 additions & 2 deletions include/media/stagefright/ExtendedCodec.h
Expand Up @@ -74,7 +74,11 @@ struct ExtendedCodec {
bool isEncoder);

static status_t setVideoFormat(
const char *mime,
const sp<MetaData> &meta, const char *mime,
OMX_VIDEO_CODINGTYPE *compressionFormat);

static status_t setVideoFormat(
const sp<AMessage> &msg, const char *mime,
OMX_VIDEO_CODINGTYPE *compressionFormat);

static status_t getSupportedAudioFormatInfo(
Expand Down Expand Up @@ -152,11 +156,14 @@ struct ExtendedCodec {
const sp<IOMX> &omx, IOMX::node_id nodeID, bool* isEnabled,
const char* componentName);

static bool useHWAACDecoder(const char *mime);

static bool isSourcePauseRequired(const char *componentName);

private:
static const char* getMsgKey(int key );

private:

static status_t setWMAFormat(
const sp<MetaData> &meta, sp<IOMX> OMXhandle,
IOMX::node_id nodeID, bool isEncoder );
Expand All @@ -175,9 +182,11 @@ struct ExtendedCodec {
sp<IOMX> OMXhandle, IOMX::node_id nodeID,
bool isEncoder );

#ifdef QCOM_ADDITIONAL_CODECS
static void setAC3Format(
int32_t numChannels, int32_t sampleRate,
sp<IOMX> OMXhandle, IOMX::node_id nodeID);
#endif

static status_t setDIVXFormat(
const sp<AMessage> &msg, const char* mime,
Expand Down
292 changes: 292 additions & 0 deletions include/media/stagefright/ExtendedStats.h
@@ -0,0 +1,292 @@
/* Copyright (c) 2013 - 2014, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef EXTENDED_STATS_H_
#define EXTENDED_STATS_H_

#include <inttypes.h>
#include <media/stagefright/foundation/AString.h>
#include <utils/KeyedVector.h>
#include <utils/Mutex.h>
#include <utils/RefBase.h>
#include <utils/StrongPointer.h>

#define MEDIA_EXTENDED_STATS "MediaExtendedStats"

#define STATS_PROFILE_START_LATENCY "Total startup latency"
#define STATS_PROFILE_ALLOCATE_NODE(isVideo) (isVideo != 0 ? "\tAllocate node (video)" : "\tAllocate node (audio)")
#define STATS_PROFILE_ALLOCATE_INPUT(isVideo) (isVideo != 0 ? "\tAllocate input buffer (video)" : "\tAllocate input buffer (audio)")
#define STATS_PROFILE_ALLOCATE_OUTPUT(isVideo) (isVideo != 0 ? "\tAllocate output buffer (video)" : "\tAllocate output buffer (audio)")
#define STATS_PROFILE_CONFIGURE_CODEC(isVideo) (isVideo != 0 ? "\tConfigure codec (video)" : "\tConfigure codec (audio)")
#define STATS_PROFILE_FIRST_BUFFER(isVideo) (isVideo != 0 ? "Time to process first buffer (video)" : "Time to process first buffer (audio)")
#define STATS_PROFILE_PREPARE "Prepare"
#define STATS_PROFILE_SET_DATA_SOURCE "Set data source"
#define STATS_PROFILE_PAUSE "Pause"
#define STATS_PROFILE_SEEK "Seek"
#define STATS_PROFILE_RESUME "Resume"

#define STATS_PROFILE_SET_CAMERA_SOURCE "Set camera source"
#define STATS_PROFILE_SET_ENCODER(isVideo) (isVideo != 0 ? "Set video encoder" : "Set audio encoder")
#define STATS_PROFILE_STOP "Stop"
#define STATS_BITRATE "Video Bitrate"
#define STATS_PROFILE_SF_RECORDER_START_LATENCY "\tStagefrightRecorder start latency"
#define STATS_PROFILE_CAMERA_SOURCE_START_LATENCY "\tCamera source start latency"
#define STATS_PROFILE_RECONFIGURE "\tReconfigure latency"

namespace android {

/*
* This class provides support for profiling events and dumping aggregate
* statistics. It may be used to profile latencies at startup, seek, resume
* and to report dropped frames etc.
*/
typedef int64_t statsDataType;
class MediaExtendedStats;

class ExtendedStats : public RefBase {

public:

enum {
MEDIA_STATS_FLAG = 'MeSt',
};

explicit ExtendedStats(const char* id, pid_t tid);

// Evaluative item; associated with an operation
struct LogEntry : public RefBase {
LogEntry();
virtual ~LogEntry() { mData = 0;}
virtual void insert(statsDataType) { }
virtual void dump(const char* label) const;
virtual void reset() {mData = 0;}
inline statsDataType data() const { return mData; }
protected:
statsDataType mData;
};

// Supported type of MediaExtendedStats
enum StatsType {
PLAYER,
RECORDER,
};

// Supported evaluations (and hence possible variants of 'LogEntry's)
enum LogType {
AVERAGE = 1 << 0,
MOVING_AVERAGE = 1 << 1,
PROFILE = 1 << 2,
};

enum {
PROFILE_START = 1,
PROFILE_START_ONCE,
PROFILE_STOP,
};

static const size_t kMaxStringLength = 1024;
static const int32_t kMaxWindowSize = 120;

struct AutoProfile {
AutoProfile(const char* eventName, sp<MediaExtendedStats> mediaExtendedStats = NULL,
bool condition = true, bool profileOnce = false);
~AutoProfile();

private:
AString mEventName;
sp<ExtendedStats::LogEntry> mLog;
sp<ExtendedStats> mStats;
bool mCondition;
};

~ExtendedStats();
void log(LogType type, const char* key, statsDataType value, bool condition = true);
virtual void dump(const char* key = NULL);
virtual void reset(const char* key);
virtual void clear();

static int64_t getSystemTime() {
struct timeval tv;
gettimeofday(&tv, NULL);
return (int64_t)tv.tv_sec * 1E6 + tv.tv_usec;
}

static sp<LogEntry> createLogEntry(LogType type, int32_t windowSize);

//only profile once, as opposed to up to kMaxOccurrences
inline void profileStartOnce(const char* name, bool condition = true) {
log(PROFILE, name, PROFILE_START_ONCE, condition);
}

//wrapper function to start profiling latency
inline void profileStart(const char* name, bool condition = true) {
log(PROFILE, name, PROFILE_START, condition);
}

//wrapper function to stop profiling. Name must match the name from profileStart
inline void profileStop(const char* name) {
log(PROFILE, name, PROFILE_STOP);
}

static MediaExtendedStats* Create(enum StatsType statsType, const char* name, pid_t tid);

//wrapper function to set window size.
inline void setWindowSize(int32_t windowSize) {
mWindowSize = windowSize;
}

private:
sp<LogEntry> getLogEntry(const char *key, LogType type);

protected:
KeyedVector<AString, sp<LogEntry> > mLogEntry;
Mutex mLock;

ExtendedStats(const ExtendedStats&) {}
AString mName;
pid_t mTid;

int32_t mWindowSize;
};

inline ExtendedStats::LogType operator| (ExtendedStats::LogType a, ExtendedStats::LogType b) {
return static_cast<ExtendedStats::LogType>(static_cast<int>(a) | static_cast<int>(b));
}

/**************************** MediaExtendedStats *********************/

class MediaExtendedStats : public RefBase {
public:
explicit MediaExtendedStats(const char* name, pid_t tid);

void logFrameDropped();
void logDimensions(int32_t width, int32_t height);
void logBitRate(int64_t frameSize, int64_t timestamp);

//only profile once, as opposed to up to kMaxOccurrences
inline void profileStartOnce(const char* name, bool condition = true) {
mProfileTimes->profileStartOnce(name, condition);
}

//wrapper function to start profiling latency
inline void profileStart(const char* name, bool condition = true) {
mProfileTimes->profileStart(name, condition);
}

//wrapper function to stop profiling. Name must match the name from profileStart
inline void profileStop(const char* name) {
mProfileTimes->profileStop(name);
}

sp<ExtendedStats> getProfileTimes() {
return mProfileTimes;
}
virtual void reset();

virtual void notifyPause(int64_t pauseTimeUs) = 0;
virtual void dump() = 0;

int32_t setFrameRate(int32_t frameRate) {
mFrameRate = frameRate;
mProfileTimes->setWindowSize(mFrameRate);
}

protected:
AString mName;
pid_t mTid;

int64_t mCurrentConsecutiveFramesDropped;
int64_t mMaxConsecutiveFramesDropped;
int64_t mNumChainedDrops;
int64_t mFramesDropped;

int64_t mLastPauseTime;

Vector<int32_t> mWidthDimensions;
Vector<int32_t> mHeightDimensions;

sp<ExtendedStats> mProfileTimes;
int32_t mFrameRate;
Mutex mLock;

/* helper functions */
void resetConsecutiveFramesDropped();

virtual ~MediaExtendedStats();
};

/************************* PlayerExtendedStats *************************/

class PlayerExtendedStats : public MediaExtendedStats {

public:
explicit PlayerExtendedStats(const char* name, pid_t tid);

void logFrameRendered();

//functions to alert the logger of discontinuities in playback
void notifyPlaying(bool isPlaying);
void notifySeek(int64_t seekTimeUs);
void notifySeekDone();
void notifyEOS();

virtual void reset();
virtual void dump();
virtual void notifyPause(int64_t pauseTimeUs);

private:
int64_t mFramesRendered;

int64_t mTotalPlayingTime;
int64_t mStartPlayingTime;
int64_t mLastSeekTime;

bool mEOS;
bool mPlaying;
bool mPaused; //used as a flag for seeking while paused

void updateTotalPlayingTime(bool wasPlaying);
};

class RecorderExtendedStats : public MediaExtendedStats {
public:
explicit RecorderExtendedStats(const char* name, pid_t tid);

void logFrameEncoded();
void logRecordingDuration(int64_t duration);

virtual void reset();
virtual void dump();
virtual void notifyPause(int64_t pauseTimeUs);

private:
int64_t mFramesEncoded;
int64_t mTotalRecordingTime;
};

}
#endif //EXTENDED_STATS_H_
141 changes: 141 additions & 0 deletions include/media/stagefright/FFMPEGSoftCodec.h
@@ -0,0 +1,141 @@
/*
* Copyright (C) 2014 The CyanogenMod 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 FFMPEG_SOFT_CODEC_H_
#define FFMPEG_SOFT_CODEC_H_

#include <media/IOMX.h>
#include <media/MediaCodecInfo.h>

#include <media/stagefright/foundation/AMessage.h>
#include <media/stagefright/foundation/AString.h>

#include <media/stagefright/MetaData.h>

#include <OMX_Audio.h>
#include <OMX_Video.h>

namespace android {

struct MediaCodecList;
struct OMXCodec;

struct FFMPEGSoftCodec {

enum {
kPortIndexInput = 0,
kPortIndexOutput = 1
};
static void convertMessageToMetaData(
const sp<AMessage> &msg, sp<MetaData> &meta);

static const char* overrideComponentName(
uint32_t quirks, const sp<MetaData> &meta,
const char *mime, bool isEncoder);

static void overrideComponentName(
uint32_t quirks, const sp<AMessage> &msg,
AString* componentName, AString* mime,
int32_t isEncoder);

static status_t setSupportedRole(
const sp<IOMX> &omx, IOMX::node_id node,
bool isEncoder, const char *mime);

static status_t setAudioFormat(
const sp<MetaData> &meta, const char* mime,
sp<IOMX> OMXhandle, IOMX::node_id nodeID,
bool isEncoder);

static status_t setAudioFormat(
const sp<AMessage> &msg, const char* mime,
sp<IOMX> OMXhandle, IOMX::node_id nodeID,
bool isEncoder);

static status_t setVideoFormat(
const sp<MetaData> &meta, const char* mime,
sp<IOMX> OMXhandle,IOMX::node_id nodeID,
bool isEncoder, OMX_VIDEO_CODINGTYPE *compressionFormat);

static status_t setVideoFormat(
const sp<AMessage> &msg, const char* mime,
sp<IOMX> OMXhandle,IOMX::node_id nodeID,
bool isEncoder, OMX_VIDEO_CODINGTYPE *compressionFormat);

static status_t handleSupportedAudioFormats(
int format, AString* mime);

static status_t handleSupportedVideoFormats(
int format, AString* mime);

private:
static const char* getMsgKey(int key);

static status_t setWMVFormat(
const sp<AMessage> &msg, sp<IOMX> OMXhandle,
IOMX::node_id nodeID);

static status_t setRVFormat(
const sp<AMessage> &msg, sp<IOMX> OMXhandle,
IOMX::node_id nodeID);

static status_t setFFmpegVideoFormat(
const sp<AMessage> &msg, sp<IOMX> OMXhandle,
IOMX::node_id nodeID);

static status_t setRawAudioFormat(
const sp<AMessage> &msg, sp<IOMX> OMXhandle,
IOMX::node_id nodeID);

static status_t setWMAFormat(
const sp<AMessage> &msg, sp<IOMX> OMXhandle,
IOMX::node_id nodeID);

static status_t setVORBISFormat(
const sp<AMessage> &msg, sp<IOMX> OMXhandle,
IOMX::node_id nodeID);

static status_t setRAFormat(
const sp<AMessage> &msg, sp<IOMX> OMXhandle,
IOMX::node_id nodeID);

static status_t setFLACFormat(
const sp<AMessage> &msg, sp<IOMX> OMXhandle,
IOMX::node_id nodeID);

static status_t setMP2Format(
const sp<AMessage> &msg, sp<IOMX> OMXhandle,
IOMX::node_id nodeID);

static status_t setAC3Format(
const sp<AMessage> &msg, sp<IOMX> OMXhandle,
IOMX::node_id nodeID);

static status_t setAPEFormat(
const sp<AMessage> &msg, sp<IOMX> OMXhandle,
IOMX::node_id nodeID);

static status_t setDTSFormat(
const sp<AMessage> &msg, sp<IOMX> OMXhandle,
IOMX::node_id nodeID);

static status_t setFFmpegAudioFormat(
const sp<AMessage> &msg, sp<IOMX> OMXhandle,
IOMX::node_id nodeID);

};

}
#endif
6 changes: 6 additions & 0 deletions include/media/stagefright/FileSource.h
Expand Up @@ -39,6 +39,10 @@ class FileSource : public DataSource {

virtual status_t getSize(off64_t *size);

virtual String8 getUri() {
return mUri;
}

virtual sp<DecryptHandle> DrmInitialization(const char *mime);

virtual void getDrmInfo(sp<DecryptHandle> &handle, DrmManagerClient **client);
Expand All @@ -48,6 +52,7 @@ class FileSource : public DataSource {

private:
int mFd;
String8 mUri;
int64_t mOffset;
int64_t mLength;
Mutex mLock;
Expand All @@ -60,6 +65,7 @@ class FileSource : public DataSource {
unsigned char *mDrmBuf;

ssize_t readAtDRM(off64_t offset, void *data, size_t size);
void fetchUriFromFd(int fd);

FileSource(const FileSource &);
FileSource &operator=(const FileSource &);
Expand Down
198 changes: 198 additions & 0 deletions include/media/stagefright/LPAPlayer.h
@@ -0,0 +1,198 @@
/*
* Copyright (c) 2009-2012, The Linux Foundation. All rights reserved.
* Not a Contribution.
* Copyright (C) 2009 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 LPA_PLAYER_H_

#define LPA_PLAYER_H_

#include "AudioPlayer.h"
#include <utils/threads.h>
#include <utils/List.h>
#include <utils/Vector.h>
#include <fcntl.h>
#include <pthread.h>
#include <include/TimedEventQueue.h>

// Pause timeout = 3sec
#define LPA_PAUSE_TIMEOUT_USEC 3000000

namespace android {

class LPAPlayer : public AudioPlayer {
public:
enum {
REACHED_EOS,
SEEK_COMPLETE
};

enum {
TRACK_DIRECT,
TRACK_REGULAR,
TRACK_NONE
};

LPAPlayer(const sp<MediaPlayerBase::AudioSink> &audioSink, bool &initCheck,
AwesomePlayer *audioObserver = NULL);

virtual ~LPAPlayer();

// Caller retains ownership of "source".
virtual void setSource(const sp<MediaSource> &source);

// Return time in us.
virtual int64_t getRealTimeUs();

virtual status_t start(bool sourceAlreadyStarted = false);

virtual void pause(bool playPendingSamples = false);
virtual status_t resume();

// Returns the timestamp of the last buffer played (in us).
virtual int64_t getMediaTimeUs();

// Returns true iff a mapping is established, i.e. the LPAPlayer
// has played at least one frame of audio.
virtual bool getMediaTimeMapping(int64_t *realtime_us, int64_t *mediatime_us);

virtual status_t seekTo(int64_t time_us);

virtual bool isSeeking();
virtual bool reachedEOS(status_t *finalStatus);

static int mObjectsAlive;
private:
int64_t mPositionTimeMediaUs;
int64_t mPositionTimeRealUs;
bool mInternalSeeking;
bool mIsAudioRouted;
bool mStarted;
bool mPaused;
int32_t mChannelMask;
int32_t mNumOutputChannels;
int32_t mNumInputChannels;
int32_t mSampleRate;
int64_t mLatencyUs;
size_t mFrameSize;
int64_t mTimeStarted;
int64_t mTimePlayed;
int64_t mNumFramesPlayed;
int64_t mNumFramesPlayedSysTimeUs;

pthread_t mDecoderThread;

//Kill Thread boolean
bool mKillDecoderThread;

//Thread alive boolean
bool mDecoderThreadAlive;

//Declare the condition Variables and Mutex

Mutex mDecoderMutex;

Condition mDecoderCv;

// make sure Decoder thread has exited
void requestAndWaitForDecoderThreadExit_l();

static void *decoderThreadWrapper(void *me);
void decoderThreadEntry();

void createThreads();

void onPauseTimeOut();

sp<MediaSource> mSource;

MediaBuffer *mInputBuffer;

Mutex mLock;

bool mSeeking;
bool mReachedEOS;
bool mReachedOutputEOS;
status_t mFinalStatus;
int64_t mSeekTimeUs;
int64_t mPauseTime;


bool mIsFirstBuffer;
status_t mFirstBufferResult;
MediaBuffer *mFirstBuffer;
TimedEventQueue mQueue;
bool mQueueStarted;
sp<TimedEventQueue::Event> mPauseEvent;
bool mPauseEventPending;

sp<MediaPlayerBase::AudioSink> mAudioSink;
AwesomePlayer *mObserver;
int mTrackType;

static size_t AudioSinkCallback(
MediaPlayerBase::AudioSink *audioSink,
void *data, size_t size, void *me,
MediaPlayerBase::AudioSink::cb_event_t event);

int64_t getTimeStamp();

size_t fillBuffer(void *data, size_t size);

int64_t getRealTimeUsLocked();

void reset();

status_t setupAudioSink();
static size_t AudioCallback(
MediaPlayerBase::AudioSink *audioSink,
void *buffer, size_t size, void *cookie);
size_t AudioCallback(void *cookie, void *data, size_t size);
int64_t getMediaTimeUs_l();
bool seekTooClose(int64_t);

void convertMonoToStereo(int16_t *data, size_t size);

LPAPlayer(const LPAPlayer &);
LPAPlayer &operator=(const LPAPlayer &);
};

struct TimedEvent : public TimedEventQueue::Event {
TimedEvent(LPAPlayer *player,
void (LPAPlayer::*method)())
: mPlayer(player),
mMethod(method) {
}

protected:
virtual ~TimedEvent() {}

virtual void fire(TimedEventQueue *queue, int64_t /* now_us */) {
(mPlayer->*mMethod)();
}

private:
LPAPlayer *mPlayer;
void (LPAPlayer::*mMethod)();

TimedEvent(const TimedEvent &);
TimedEvent &operator=(const TimedEvent &);
};

} // namespace android

#endif // LPA_PLAYER_H_

3 changes: 2 additions & 1 deletion include/media/stagefright/MPEG4Writer.h
Expand Up @@ -23,6 +23,7 @@
#include <media/stagefright/MediaWriter.h>
#include <utils/List.h>
#include <utils/threads.h>
#include <media/stagefright/ExtendedStats.h>

namespace android {

Expand Down Expand Up @@ -60,7 +61,7 @@ class MPEG4Writer : public MediaWriter {
void endBox();
uint32_t interleaveDuration() const { return mInterleaveDurationUs; }
status_t setInterleaveDuration(uint32_t duration);
int32_t getTimeScale() const { return mTimeScale; }
int32_t getTimeScale() const { return (mTimeScale / mHFRRatio); }

status_t setGeoData(int latitudex10000, int longitudex10000);
virtual void setStartTimeOffsetMs(int ms) { mStartTimeOffsetMs = ms; }
Expand Down
4 changes: 4 additions & 0 deletions include/media/stagefright/MediaAdapter.h
Expand Up @@ -56,6 +56,8 @@ struct MediaAdapter : public MediaSource, public MediaBufferObserver {
// deep copy, such that after pushBuffer return, the buffer can be re-used.
status_t pushBuffer(MediaBuffer *buffer);

virtual void notifyError(status_t err);

private:
Mutex mAdapterLock;
// Make sure the read() wait for the incoming buffer.
Expand All @@ -68,6 +70,8 @@ struct MediaAdapter : public MediaSource, public MediaBufferObserver {
bool mStarted;
sp<MetaData> mOutputFormat;

status_t mStatus;

DISALLOW_EVIL_CONSTRUCTORS(MediaAdapter);
};

Expand Down
1 change: 1 addition & 0 deletions include/media/stagefright/MediaBuffer.h
Expand Up @@ -93,6 +93,7 @@ class MediaBuffer : public MediaBufferBase {
private:
friend class MediaBufferGroup;
friend class OMXDecoder;
friend class MediaAdapter;

// For use by OMXDecoder, reference count must be 1, drop reference
// count to 0 without signalling the observer.
Expand Down
2 changes: 1 addition & 1 deletion include/media/stagefright/MediaCodec.h
Expand Up @@ -195,7 +195,7 @@ struct MediaCodec : public AHandler {
};

enum {
kFlagIsSoftwareCodec = 1,
kFlagUsesSoftwareRenderer = 1,
kFlagOutputFormatChanged = 2,
kFlagOutputBuffersChanged = 4,
kFlagStickyError = 8,
Expand Down
10 changes: 10 additions & 0 deletions include/media/stagefright/MediaCodecList.h
Expand Up @@ -45,13 +45,23 @@ struct MediaCodecList : public BnMediaCodecList {
virtual size_t countCodecs() const;

virtual sp<MediaCodecInfo> getCodecInfo(size_t index) const {
if (index >= mCodecInfos.size()) {
ALOGE("b/24445127");
return NULL;
}
return mCodecInfos.itemAt(index);
}

// to be used by MediaPlayerService alone
static sp<IMediaCodecList> getLocalInstance();

private:
class BinderDeathObserver : public IBinder::DeathRecipient {
void binderDied(const wp<IBinder> &the_late_who __unused);
};

static sp<BinderDeathObserver> sBinderDeathObserver;

enum Section {
SECTION_TOPLEVEL,
SECTION_DECODERS,
Expand Down
13 changes: 9 additions & 4 deletions include/media/stagefright/MediaCodecSource.h
Expand Up @@ -21,6 +21,14 @@
#include <media/stagefright/foundation/AHandlerReflector.h>
#include <media/stagefright/MediaSource.h>

#include <media/stagefright/ExtendedStats.h>
#define RECORDER_STATS(func, ...) \
do { \
if(mRecorderExtendedStats != NULL) { \
mRecorderExtendedStats->func(__VA_ARGS__);} \
} \
while(0)

namespace android {

class ALooper;
Expand Down Expand Up @@ -85,14 +93,13 @@ struct MediaCodecSource : public MediaSource,
status_t initEncoder();
void releaseEncoder();
status_t feedEncoderInputBuffers();
void scheduleDoMoreWork();
status_t doMoreWork(int32_t numInput, int32_t numOutput);
void suspend();
void resume(int64_t skipFramesBeforeUs = -1ll);
void signalEOS(status_t err = ERROR_END_OF_STREAM);
bool reachedEOS();
status_t postSynchronouslyAndReturnError(const sp<AMessage> &msg);

sp<RecorderExtendedStats> mRecorderExtendedStats;
sp<ALooper> mLooper;
sp<ALooper> mCodecLooper;
sp<AHandlerReflector<MediaCodecSource> > mReflector;
Expand All @@ -108,8 +115,6 @@ struct MediaCodecSource : public MediaSource,
bool mDoMoreWorkPending;
sp<AMessage> mEncoderActivityNotify;
sp<IGraphicBufferProducer> mGraphicBufferProducer;
Vector<sp<ABuffer> > mEncoderInputBuffers;
Vector<sp<ABuffer> > mEncoderOutputBuffers;
List<MediaBuffer *> mInputBufferQueue;
List<size_t> mAvailEncoderInputIndices;
List<int64_t> mDecodingTimeQueue; // decoding time (us) for video
Expand Down
63 changes: 63 additions & 0 deletions include/media/stagefright/MediaDefs.h
Expand Up @@ -12,6 +12,25 @@
* 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.
*
* This file was modified by Dolby Laboratories, Inc. The portions of the
* code that are surrounded by "DOLBY..." are copyrighted and
* licensed separately, as follows:
*
* (C) 2011-2014 Dolby Laboratories, Inc.
*
* 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 MEDIA_DEFS_H_
Expand Down Expand Up @@ -48,6 +67,7 @@ extern const char *MEDIA_MIMETYPE_AUDIO_FLAC;
extern const char *MEDIA_MIMETYPE_AUDIO_AAC_ADTS;
extern const char *MEDIA_MIMETYPE_AUDIO_MSGSM;
extern const char *MEDIA_MIMETYPE_AUDIO_AC3;
extern const char *MEDIA_MIMETYPE_AUDIO_EAC3;

extern const char *MEDIA_MIMETYPE_CONTAINER_MPEG4;
extern const char *MEDIA_MIMETYPE_CONTAINER_WAV;
Expand All @@ -64,6 +84,49 @@ extern const char *MEDIA_MIMETYPE_TEXT_SUBRIP;
extern const char *MEDIA_MIMETYPE_TEXT_VTT;
extern const char *MEDIA_MIMETYPE_TEXT_CEA_608;

#ifdef DOLBY_UDC
extern const char *MEDIA_MIMETYPE_AUDIO_EAC3_JOC;
extern const char *MEDIA_MIMETYPE_AUDIO_EAC3;
#endif // DOLBY_END

extern const char *MEDIA_MIMETYPE_VIDEO_DIVX;
extern const char *MEDIA_MIMETYPE_VIDEO_DIVX311;
extern const char *MEDIA_MIMETYPE_VIDEO_DIVX4;
extern const char *MEDIA_MIMETYPE_VIDEO_FLV1;
extern const char *MEDIA_MIMETYPE_VIDEO_MJPEG;
extern const char *MEDIA_MIMETYPE_VIDEO_RV;
extern const char *MEDIA_MIMETYPE_VIDEO_VC1;
extern const char *MEDIA_MIMETYPE_VIDEO_WMV;
extern const char *MEDIA_MIMETYPE_VIDEO_HEVC;
extern const char *MEDIA_MIMETYPE_VIDEO_FFMPEG;

extern const char *MEDIA_MIMETYPE_AUDIO_AC3;
extern const char *MEDIA_MIMETYPE_AUDIO_APE;
extern const char *MEDIA_MIMETYPE_AUDIO_DTS;
extern const char *MEDIA_MIMETYPE_AUDIO_PCM;
extern const char *MEDIA_MIMETYPE_AUDIO_RA;
extern const char *MEDIA_MIMETYPE_AUDIO_WMA;
extern const char *MEDIA_MIMETYPE_AUDIO_FFMPEG;

extern const char *MEDIA_MIMETYPE_CONTAINER_APE;
extern const char *MEDIA_MIMETYPE_CONTAINER_ASF;
extern const char *MEDIA_MIMETYPE_CONTAINER_DIVX;
extern const char *MEDIA_MIMETYPE_CONTAINER_DTS;
extern const char *MEDIA_MIMETYPE_CONTAINER_FLAC;
extern const char *MEDIA_MIMETYPE_CONTAINER_FLV;
extern const char *MEDIA_MIMETYPE_CONTAINER_MOV;
extern const char *MEDIA_MIMETYPE_CONTAINER_MP2;
extern const char *MEDIA_MIMETYPE_CONTAINER_MPG;
extern const char *MEDIA_MIMETYPE_CONTAINER_RA;
extern const char *MEDIA_MIMETYPE_CONTAINER_RM;
extern const char *MEDIA_MIMETYPE_CONTAINER_TS;
extern const char *MEDIA_MIMETYPE_CONTAINER_WEBM;
extern const char *MEDIA_MIMETYPE_CONTAINER_WMA;
extern const char *MEDIA_MIMETYPE_CONTAINER_WMV;
extern const char *MEDIA_MIMETYPE_CONTAINER_VC1;
extern const char *MEDIA_MIMETYPE_CONTAINER_HEVC;
extern const char *MEDIA_MIMETYPE_CONTAINER_FFMPEG;

} // namespace android

#endif // MEDIA_DEFS_H_
23 changes: 23 additions & 0 deletions include/media/stagefright/MediaErrors.h
Expand Up @@ -12,6 +12,25 @@
* 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.
*
* This file was modified by Dolby Laboratories, Inc. The portions of the
* code that are surrounded by "DOLBY..." are copyrighted and
* licensed separately, as follows:
*
* (C) 2014 Dolby Laboratories, Inc.
*
* 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 MEDIA_ERRORS_H_
Expand Down Expand Up @@ -53,6 +72,10 @@ enum {
INFO_FORMAT_CHANGED = MEDIA_ERROR_BASE - 12,
INFO_DISCONTINUITY = MEDIA_ERROR_BASE - 13,
INFO_OUTPUT_BUFFERS_CHANGED = MEDIA_ERROR_BASE - 14,
#ifdef DOLBY_UDC
INFO_DOLBY_PROCESSED_AUDIO_START = MEDIA_ERROR_BASE - 15,
INFO_DOLBY_PROCESSED_AUDIO_STOP = MEDIA_ERROR_BASE - 16,
#endif // DOLBY_END

// The following constant values should be in sync with
// drm/drm_framework_common.h
Expand Down
15 changes: 14 additions & 1 deletion include/media/stagefright/MediaExtractor.h
Expand Up @@ -19,15 +19,27 @@
#define MEDIA_EXTRACTOR_H_

#include <utils/RefBase.h>
#include <media/stagefright/DataSource.h>

namespace android {

class DataSource;
class MediaSource;
class MetaData;

class MediaExtractor : public RefBase {
public:
typedef MediaExtractor *(*CreateFunc)(const sp<DataSource> &source,
const char *mime, const sp<AMessage> &meta);

struct Plugin {
DataSource::SnifferFunc sniff;
CreateFunc create;
};

static Plugin *getPlugin() {
return &sPlugin;
}

static sp<MediaExtractor> Create(
const sp<DataSource> &source, const char *mime = NULL);

Expand Down Expand Up @@ -74,6 +86,7 @@ class MediaExtractor : public RefBase {

private:
bool mIsDrm;
static Plugin sPlugin;

MediaExtractor(const MediaExtractor &);
MediaExtractor &operator=(const MediaExtractor &);
Expand Down
1 change: 1 addition & 0 deletions include/media/stagefright/MediaSource.h
Expand Up @@ -59,6 +59,7 @@ struct MediaSource : public virtual RefBase {
virtual status_t read(
MediaBuffer **buffer, const ReadOptions *options = NULL) = 0;

virtual void notifyError(status_t) {}
// Options that modify read() behaviour. The default is to
// a) not request a seek
// b) not be late, i.e. lateness_us = 0
Expand Down