Merge changes I71f5b0fc,I92c7accb
* changes:
Moving decision to use still camera to CameraSourceTimeLapse
pass auxiliary video parameters.
diff --git a/cmds/stagefright/record.cpp b/cmds/stagefright/record.cpp
index 5a87f4c..c424281 100644
--- a/cmds/stagefright/record.cpp
+++ b/cmds/stagefright/record.cpp
@@ -32,9 +32,15 @@
using namespace android;
+static const int32_t kFramerate = 24; // fps
+static const int32_t kIFramesIntervalSec = 1;
+static const int32_t kVideoBitRate = 512 * 1024;
+static const int32_t kAudioBitRate = 12200;
+static const int32_t kColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
+static const int64_t kDurationUs = 10000000LL; // 10 seconds
+
#if 1
class DummySource : public MediaSource {
- static const int32_t kFramerate = 24; // fps
public:
DummySource(int width, int height)
@@ -176,6 +182,12 @@
enc_meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_AVC);
enc_meta->setInt32(kKeyWidth, width);
enc_meta->setInt32(kKeyHeight, height);
+ enc_meta->setInt32(kKeySampleRate, kFramerate);
+ enc_meta->setInt32(kKeyBitRate, kVideoBitRate);
+ enc_meta->setInt32(kKeyStride, width);
+ enc_meta->setInt32(kKeySliceHeight, height);
+ enc_meta->setInt32(kKeyIFramesInterval, kIFramesIntervalSec);
+ enc_meta->setInt32(kKeyColorFormat, kColorFormat);
sp<MediaSource> encoder =
OMXCodec::Create(
@@ -184,8 +196,10 @@
#if 1
sp<MPEG4Writer> writer = new MPEG4Writer("/sdcard/output.mp4");
writer->addSource(encoder);
+ writer->setMaxFileDuration(kDurationUs);
writer->start();
while (!writer->reachedEOS()) {
+ fprintf(stderr, ".");
usleep(100000);
}
writer->stop();
@@ -194,6 +208,8 @@
MediaBuffer *buffer;
while (encoder->read(&buffer) == OK) {
+ printf(".");
+ fflush(stdout);
int32_t isSync;
if (!buffer->meta_data()->findInt32(kKeyIsSyncFrame, &isSync)) {
isSync = false;
@@ -209,6 +225,7 @@
encoder->stop();
#endif
+ printf("$\n");
client.disconnect();
#endif
@@ -267,6 +284,7 @@
encMeta->setInt32(kKeySampleRate, kSampleRate);
encMeta->setInt32(kKeyChannelCount, kNumChannels);
encMeta->setInt32(kKeyMaxInputSize, 8192);
+ encMeta->setInt32(kKeyBitRate, kAudioBitRate);
sp<MediaSource> encoder =
OMXCodec::Create(client.interface(), encMeta, true, audioSource);
diff --git a/include/media/IOMX.h b/include/media/IOMX.h
index 2f61cbe..1f8ce71 100644
--- a/include/media/IOMX.h
+++ b/include/media/IOMX.h
@@ -19,6 +19,7 @@
#define ANDROID_IOMX_H_
#include <binder/IInterface.h>
+#include <ui/GraphicBuffer.h>
#include <utils/List.h>
#include <utils/String8.h>
@@ -78,10 +79,17 @@
node_id node, OMX_INDEXTYPE index,
const void *params, size_t size) = 0;
+ virtual status_t enableGraphicBuffers(
+ node_id node, OMX_U32 port_index, OMX_BOOL enable) = 0;
+
virtual status_t useBuffer(
node_id node, OMX_U32 port_index, const sp<IMemory> ¶ms,
buffer_id *buffer) = 0;
+ virtual status_t useGraphicBuffer(
+ node_id node, OMX_U32 port_index,
+ const sp<GraphicBuffer> &graphicBuffer, buffer_id *buffer) = 0;
+
// This API clearly only makes sense if the caller lives in the
// same process as the callee, i.e. is the media_server, as the
// returned "buffer_data" pointer is just that, a pointer into local
diff --git a/include/media/stagefright/AudioSource.h b/include/media/stagefright/AudioSource.h
index 1af4254..a5cec78 100644
--- a/include/media/stagefright/AudioSource.h
+++ b/include/media/stagefright/AudioSource.h
@@ -72,6 +72,7 @@
int64_t mPrevSampleTimeUs;
int64_t mTotalLostFrames;
int64_t mPrevLostBytes;
+ int64_t mInitialReadTimeUs;
MediaBufferGroup *mGroup;
diff --git a/include/media/stagefright/HardwareAPI.h b/include/media/stagefright/HardwareAPI.h
index 221c679..4ded5e8 100644
--- a/include/media/stagefright/HardwareAPI.h
+++ b/include/media/stagefright/HardwareAPI.h
@@ -21,10 +21,60 @@
#include <media/stagefright/OMXPluginBase.h>
#include <media/stagefright/VideoRenderer.h>
#include <surfaceflinger/ISurface.h>
+#include <ui/android_native_buffer.h>
#include <utils/RefBase.h>
#include <OMX_Component.h>
+namespace android {
+
+// A pointer to this struct is passed to the OMX_SetParameter when the extension
+// index for the 'OMX.google.android.index.enableAndroidNativeBuffers' extension
+// is given.
+//
+// When Android native buffer use is disabled for a port (the default state),
+// the OMX node should operate as normal, and expect UseBuffer calls to set its
+// buffers. This is the mode that will be used when CPU access to the buffer is
+// required.
+//
+// When Android native buffer use has been enabled, the OMX node must support
+// only color formats in the range [OMX_COLOR_FormatAndroidPrivateStart,
+// OMX_COLOR_FormatAndroidPrivateEnd). The node should then expect to receive
+// UseAndroidNativeBuffer calls (via OMX_SetParameter) rather than UseBuffer
+// calls.
+struct EnableAndroidNativeBuffersParams {
+ OMX_U32 nSize;
+ OMX_VERSIONTYPE nVersion;
+ OMX_U32 nPortIndex;
+ OMX_BOOL enable;
+};
+
+// Color formats in the range [OMX_COLOR_FormatAndroidPrivateStart,
+// OMX_COLOR_FormatAndroidPrivateEnd) will be converted to a gralloc pixel
+// format when used to allocate Android native buffers via gralloc. The
+// conversion is done by subtracting OMX_COLOR_FormatAndroidPrivateStart from
+// the color format reported by the codec.
+enum {
+ OMX_COLOR_FormatAndroidPrivateStart = 0xA0000000,
+ OMX_COLOR_FormatAndroidPrivateEnd = 0xB0000000,
+};
+
+// A pointer to this struct is passed to OMX_SetParameter when the extension
+// index for the 'OMX.google.android.index.useAndroidNativeBuffer' extension is
+// given. This call will only be performed if a prior call was made with the
+// 'OMX.google.android.index.enableAndroidNativeBuffers' extension index,
+// enabling use of Android native buffers.
+struct UseAndroidNativeBufferParams {
+ OMX_U32 nSize;
+ OMX_VERSIONTYPE nVersion;
+ OMX_U32 nPortIndex;
+ OMX_PTR pAppPrivate;
+ OMX_BUFFERHEADERTYPE **bufferHeader;
+ const sp<android_native_buffer_t>& nativeBuffer;
+};
+
+} // namespace android
+
extern android::VideoRenderer *createRenderer(
const android::sp<android::ISurface> &surface,
const char *componentName,
@@ -35,4 +85,3 @@
extern android::OMXPluginBase *createOMXPlugin();
#endif // HARDWARE_API_H_
-
diff --git a/include/media/stagefright/MPEG4Writer.h b/include/media/stagefright/MPEG4Writer.h
index 2412f6a..70bd8e8 100644
--- a/include/media/stagefright/MPEG4Writer.h
+++ b/include/media/stagefright/MPEG4Writer.h
@@ -62,6 +62,7 @@
class Track;
FILE *mFile;
+ bool mUse4ByteNalLength;
bool mUse32BitOffset;
bool mPaused;
bool mStarted;
@@ -132,9 +133,13 @@
// Adjust other track media clock (presumably wall clock)
// based on audio track media clock with the drift time.
int64_t mDriftTimeUs;
- void addDriftTimeUs(int64_t driftTimeUs);
+ void setDriftTimeUs(int64_t driftTimeUs);
int64_t getDriftTimeUs();
+ // Return whether the nal length is 4 bytes or 2 bytes
+ // Only makes sense for H.264/AVC
+ bool useNalLengthFour();
+
void lock();
void unlock();
@@ -144,6 +149,7 @@
inline size_t write(const void *ptr, size_t size, size_t nmemb, FILE* stream);
bool exceedsFileSizeLimit();
+ bool use32BitFileOffset() const;
bool exceedsFileDurationLimit();
void trackProgressStatus(const Track* track, int64_t timeUs, status_t err = OK);
diff --git a/include/media/stagefright/MetaData.h b/include/media/stagefright/MetaData.h
index 43354c2..1e447f1 100644
--- a/include/media/stagefright/MetaData.h
+++ b/include/media/stagefright/MetaData.h
@@ -48,6 +48,7 @@
kKeyTime = 'time', // int64_t (usecs)
kKeyNTPTime = 'ntpT', // uint64_t (ntp-timestamp)
kKeyTargetTime = 'tarT', // int64_t (usecs)
+ kKeyDriftTime = 'dftT', // int64_t (usecs)
kKeyDuration = 'dura', // int64_t (usecs)
kKeyColorFormat = 'colf',
kKeyPlatformPrivate = 'priv', // pointer
@@ -78,6 +79,7 @@
// Set this key to enable authoring files in 64-bit offset
kKey64BitFileOffset = 'fobt', // int32_t (bool)
+ kKey2ByteNalLength = '2NAL', // int32_t (bool)
// Identify the file output format for authoring
// Please see <media/mediarecorder.h> for the supported
@@ -90,6 +92,8 @@
kKeyNotRealTime = 'ntrt', // bool (int32_t)
+ // Ogg files can be tagged to be automatically looping...
+ kKeyAutoLoop = 'autL', // bool (int32_t)
};
enum {
diff --git a/media/libeffects/lvm/lib/Reverb/src/LVREV_ApplyNewSettings.c b/media/libeffects/lvm/lib/Reverb/src/LVREV_ApplyNewSettings.c
index 6a8b39b..9a40f68 100644
--- a/media/libeffects/lvm/lib/Reverb/src/LVREV_ApplyNewSettings.c
+++ b/media/libeffects/lvm/lib/Reverb/src/LVREV_ApplyNewSettings.c
@@ -526,7 +526,7 @@
(pPrivate->NewParams.OperatingMode == LVM_MODE_ON))
{
pPrivate->BypassMixer.Target2 = ((LVM_INT32)(pPrivate->NewParams.Level * 32767)/100)<<16;
- pPrivate->BypassMixer.Target1 = LVREV_HEADROOM << 16;
+ pPrivate->BypassMixer.Target1 = 0x00000000;
if ((pPrivate->NewParams.Level == 0) && (pPrivate->bFirstControl == LVM_FALSE))
{
pPrivate->BypassMixer.CallbackSet2 = LVM_TRUE;
@@ -542,7 +542,7 @@
if(pPrivate->NewParams.OperatingMode == LVM_MODE_ON)
{
pPrivate->BypassMixer.Target2 = ((LVM_INT32)(pPrivate->NewParams.Level * 32767)/100)<<16;
- pPrivate->BypassMixer.Target1 = LVREV_HEADROOM << 16;
+ pPrivate->BypassMixer.Target1 = 0x00000000;
pPrivate->BypassMixer.CallbackSet2 = LVM_FALSE;
OperatingMode = LVM_MODE_ON;
@@ -558,7 +558,7 @@
else if (pPrivate->bFirstControl == LVM_FALSE)
{
pPrivate->BypassMixer.Target2 = 0x00000000;
- pPrivate->BypassMixer.Target1 = 0x7FFFFFFF;
+ pPrivate->BypassMixer.Target1 = 0x00000000;
pPrivate->BypassMixer.CallbackSet2 = LVM_TRUE;
pPrivate->GainMixer.Target = 0x03FFFFFF;
OperatingMode = LVM_MODE_ON;
diff --git a/media/libeffects/lvm/lib/Reverb/src/LVREV_GetInstanceHandle.c b/media/libeffects/lvm/lib/Reverb/src/LVREV_GetInstanceHandle.c
index c2b266a..ffa5138 100644
--- a/media/libeffects/lvm/lib/Reverb/src/LVREV_GetInstanceHandle.c
+++ b/media/libeffects/lvm/lib/Reverb/src/LVREV_GetInstanceHandle.c
@@ -238,8 +238,8 @@
pLVREV_Private->BypassMixer.pGeneralPurpose1 = LVM_NULL;
pLVREV_Private->BypassMixer.pCallBack1 = LVM_NULL;
pLVREV_Private->BypassMixer.CallbackSet1 = LVM_FALSE;
- pLVREV_Private->BypassMixer.Current1 = 0x7fffffff;
- pLVREV_Private->BypassMixer.Target1 = 0x7fffffff;
+ pLVREV_Private->BypassMixer.Current1 = 0x00000000;
+ pLVREV_Private->BypassMixer.Target1 = 0x00000000;
pLVREV_Private->RoomSizeInms = 100; // 100 msec
diff --git a/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Control.c b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Control.c
index a3ba42b..ce6d410 100644
--- a/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Control.c
+++ b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Control.c
@@ -202,7 +202,9 @@
/* Set the reverb delay timeout */
if(pInstance->bInOperatingModeTransition != LVM_TRUE){
pInstance->bTimerDone = LVM_FALSE;
- pInstance->TimerParams.TimeInMs = (LVM_INT16)(((pInstance->Reverberation.DelaySize << 2)/pInstance->TimerParams.SamplingRate) + 1);
+ pInstance->TimerParams.TimeInMs =
+ (LVM_INT16)(((pInstance->Reverberation.DelaySize << 2)
+ /pInstance->TimerParams.SamplingRate) + 1);
LVM_Timer_Init ( &pInstance->TimerInstance,
&pInstance->TimerParams);
}
diff --git a/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp b/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp
index d3bb96e..e86ed99 100644
--- a/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp
+++ b/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp
@@ -258,14 +258,21 @@
pContext->pBundledContext->firstVolume = LVM_TRUE;
#ifdef LVM_PCM
- pContext->pBundledContext->PcmInPtr = NULL;
- pContext->pBundledContext->PcmOutPtr = NULL;
- pContext->pBundledContext->PcmInPtr = fopen("/data/tmp/bundle_pcm_in.pcm", "w");
- pContext->pBundledContext->PcmOutPtr = fopen("/data/tmp/bundle_pcm_out.pcm", "w");
+ char fileName[256];
+ snprintf(fileName, 256, "/data/tmp/bundle_%p_pcm_in.pcm", pContext->pBundledContext);
+ pContext->pBundledContext->PcmInPtr = fopen(fileName, "w");
+ if (pContext->pBundledContext->PcmInPtr == NULL) {
+ LOGV("cannot open %s", fileName);
+ return -EINVAL;
+ }
- if((pContext->pBundledContext->PcmInPtr == NULL)||
- (pContext->pBundledContext->PcmOutPtr == NULL)){
+ snprintf(fileName, 256, "/data/tmp/bundle_%p_pcm_out.pcm", pContext->pBundledContext);
+ pContext->pBundledContext->PcmOutPtr = fopen(fileName, "w");
+ if (pContext->pBundledContext->PcmOutPtr == NULL) {
+ LOGV("cannot open %s", fileName);
+ fclose(pContext->pBundledContext->PcmInPtr);
+ pContext->pBundledContext->PcmInPtr = NULL;
return -EINVAL;
}
#endif
@@ -375,8 +382,14 @@
(GlobalSessionMemory[pContext->pBundledContext->SessionNo].bVirtualizerInstantiated==LVM_FALSE))
{
#ifdef LVM_PCM
- fclose(pContext->pBundledContext->PcmInPtr);
- fclose(pContext->pBundledContext->PcmOutPtr);
+ if (pContext->pBundledContext->PcmInPtr != NULL) {
+ fclose(pContext->pBundledContext->PcmInPtr);
+ pContext->pBundledContext->PcmInPtr = NULL;
+ }
+ if (pContext->pBundledContext->PcmOutPtr != NULL) {
+ fclose(pContext->pBundledContext->PcmOutPtr);
+ pContext->pBundledContext->PcmOutPtr = NULL;
+ }
#endif
LvmSessionsActive--;
@@ -551,9 +564,6 @@
params.SpeakerType = LVM_HEADPHONES;
pContext->pBundledContext->SampleRate = LVM_FS_44100;
- pContext->pBundledContext->SamplesToExitCountEq = 44100*2*2; // 2 secs Stereo
- pContext->pBundledContext->SamplesToExitCountBb = 44100*2*2; // 2 secs Stereo
- pContext->pBundledContext->SamplesToExitCountVirt = 44100*2*2; // 2 secs Stereo
/* Concert Sound parameters */
params.VirtualizerOperatingMode = LVM_MODE_OFF;
@@ -2417,7 +2427,7 @@
if(pContext->pBundledContext->SamplesToExitCountBb > 0){
status2Sec = -ENODATA;
pContext->pBundledContext->SamplesToExitCountBb -= outBuffer->frameCount * 2; // STEREO
- //LOGV("\tEffect_process: Waiting for 2 secs to turn off BASS_BOOST, %d samples left",
+ //LOGV("\tEffect_process: Waiting to turn off BASS_BOOST, %d samples left",
// pContext->pBundledContext->SamplesToExitCountBb);
} else {
status = -ENODATA;
@@ -2883,11 +2893,11 @@
pContext->pBundledContext->NumberEffectsEnabled++;
android::LvmEffect_enable(pContext);
pContext->pBundledContext->SamplesToExitCountEq =
- (LVM_INT32)(pContext->pBundledContext->SamplesPerSecond*1); // 0.1 secs Stereo
+ (LVM_INT32)(pContext->pBundledContext->SamplesPerSecond*0.1); // 0.1 secs Stereo
pContext->pBundledContext->SamplesToExitCountBb =
- (LVM_INT32)(pContext->pBundledContext->SamplesPerSecond*6); // 2 secs Stereo
+ (LVM_INT32)(pContext->pBundledContext->SamplesPerSecond*0.1); // 0.1 secs Stereo
pContext->pBundledContext->SamplesToExitCountVirt =
- (LVM_INT32)(pContext->pBundledContext->SamplesPerSecond*1); // 2 secs Stereo
+ (LVM_INT32)(pContext->pBundledContext->SamplesPerSecond*0.1); // 0.1 secs Stereo
LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE Samples to Exit = %d",
pContext->pBundledContext->SamplesToExitCountBb);
//LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE NumberEffectsEnabled = %d",
diff --git a/media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp b/media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp
index 10c3e92..45ef416 100755
--- a/media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp
+++ b/media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp
@@ -152,6 +152,7 @@
bool preset;
uint16_t curPreset;
uint16_t nextPreset;
+ int SamplesToExitCount;
};
#define REVERB_DEFAULT_PRESET REVERB_PRESET_MEDIUMROOM
@@ -212,6 +213,7 @@
desc = gDescriptors[i];
if (memcmp(uuid, &desc->uuid, sizeof(effect_uuid_t))
== 0) {
+ LOGV("\tEffectCreate - UUID matched Reverb type %d, UUID = %x", i, desc->uuid.timeLow);
break;
}
}
@@ -228,6 +230,9 @@
pContext->auxiliary = false;
if ((desc->flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_AUXILIARY){
pContext->auxiliary = true;
+ LOGV("\tEffectCreate - AUX");
+ }else{
+ LOGV("\tEffectCreate - INS");
}
pContext->preset = false;
@@ -236,6 +241,9 @@
// force reloading preset at first call to process()
pContext->curPreset = REVERB_PRESET_LAST + 1;
pContext->nextPreset = REVERB_DEFAULT_PRESET;
+ LOGV("\tEffectCreate - PRESET");
+ }else{
+ LOGV("\tEffectCreate - ENVIRONMENTAL");
}
LOGV("\tEffectCreate - Calling Reverb_init");
@@ -389,22 +397,19 @@
int frameCount,
ReverbContext *pContext){
- LVM_INT16 samplesPerFrame = 0;
+ LVM_INT16 samplesPerFrame = 1;
LVREV_ReturnStatus_en LvmStatus = LVREV_SUCCESS; /* Function call status */
LVM_INT16 *OutFrames16;
// Check that the input is either mono or stereo
- if(pContext->config.inputCfg.channels == CHANNEL_STEREO){
+ if (pContext->config.inputCfg.channels == CHANNEL_STEREO) {
samplesPerFrame = 2;
- } else if (pContext->config.inputCfg.channels == CHANNEL_MONO){
- samplesPerFrame = 1;
- } else {
+ } else if (pContext->config.inputCfg.channels != CHANNEL_MONO) {
LOGV("\tLVREV_ERROR : process invalid PCM format");
return -EINVAL;
}
-
OutFrames16 = (LVM_INT16 *)pContext->OutFrames32;
// Check for NULL pointers
@@ -437,43 +442,49 @@
//pContext->config.outputCfg.channels, CHANNEL_STEREO);
if (pContext->preset && pContext->curPreset == REVERB_PRESET_NONE) {
- memset(pContext->OutFrames32, 0, frameCount * sizeof(LVM_INT32) * 2);
+ memset(pContext->OutFrames32, 0, frameCount * sizeof(LVM_INT32) * 2); //always stereo here
} else {
- /* Process the samples */
- LvmStatus = LVREV_Process(pContext->hInstance, /* Instance handle */
- pContext->InFrames32, /* Input buffer */
- pContext->OutFrames32, /* Output buffer */
- frameCount); /* Number of samples to read */
- }
-
- if (!pContext->auxiliary) {
- for (int i=0; i<frameCount*2; i++){
- pContext->OutFrames32[i] += pContext->InFrames32[i];
+ if(pContext->bEnabled == LVM_FALSE && pContext->SamplesToExitCount > 0) {
+ memset(pContext->InFrames32,
+ 0,
+ frameCount * sizeof(LVM_INT32) * 2); //always stereo here
}
+
+ /* Process the samples */
+ LvmStatus = LVREV_Process(pContext->hInstance, /* Instance handle */
+ pContext->InFrames32, /* Input buffer */
+ pContext->OutFrames32, /* Output buffer */
+ frameCount); /* Number of samples to read */
}
LVM_ERROR_CHECK(LvmStatus, "LVREV_Process", "process")
if(LvmStatus != LVREV_SUCCESS) return -EINVAL;
// Convert to 16 bits
- for(int i=0; i<frameCount*2; i++){ // Always stereo
- OutFrames16[i] = clamp16(pContext->OutFrames32[i]>>8);
+ if (pContext->auxiliary) {
+ for (int i=0; i < frameCount*2; i++) { //always stereo here
+ OutFrames16[i] = clamp16(pContext->OutFrames32[i]>>8);
+ }
+ } else {
+ for (int i=0; i < frameCount*2; i++) { //always stereo here
+ OutFrames16[i] = clamp16((pContext->OutFrames32[i]>>8) + (LVM_INT32)pIn[i]);
+ }
}
#ifdef LVM_PCM
- fwrite(OutFrames16, frameCount*sizeof(LVM_INT16)*samplesPerFrame, 1, pContext->PcmOutPtr);
+ fwrite(OutFrames16, frameCount*sizeof(LVM_INT16)*2, 1, pContext->PcmOutPtr);
fflush(pContext->PcmOutPtr);
#endif
// Accumulate if required
if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE){
//LOGV("\tBuffer access is ACCUMULATE");
- for (int i=0; i<frameCount*2; i++){
+ for (int i=0; i<frameCount*2; i++){ //always stereo here
pOut[i] = clamp16((int32_t)pOut[i] + (int32_t)OutFrames16[i]);
}
}else{
//LOGV("\tBuffer access is WRITE");
- memcpy(pOut, OutFrames16, frameCount*sizeof(LVM_INT16)*2); // 2 is for stereo output
+ memcpy(pOut, OutFrames16, frameCount*sizeof(LVM_INT16)*2);
}
return 0;
@@ -560,6 +571,7 @@
//LOGV("\tReverb_configure calling memcpy");
memcpy(&pContext->config, pConfig, sizeof(effect_config_t));
+
switch (pConfig->inputCfg.samplingRate) {
case 8000:
SampleRate = LVM_FS_8000;
@@ -741,6 +753,8 @@
params.Damping = 21;
params.RoomSize = 100;
+ pContext->SamplesToExitCount = (params.T60 * pContext->config.inputCfg.samplingRate)/1000;
+
/* Saved strength is used to return the exact strength that was used in the set to the get
* because we map the original strength range of 0:1000 to 1:15, and this will avoid
* quantisation like effect when returning
@@ -1082,7 +1096,8 @@
//LOGV("\tReverbGetRoomLevel, Level = %d, pContext->SavedRoomLevel = %d, "
// "pContext->SavedReverbLevel = %d, CombinedLevel = %d, level = %d",
- //ActiveParams.Level, pContext->SavedRoomLevel, pContext->SavedReverbLevel, CombinedLevel, level);
+ // ActiveParams.Level, pContext->SavedRoomLevel,
+ // pContext->SavedReverbLevel, CombinedLevel, level);
if(ActiveParams.Level != level){
LOGV("\tLVM_ERROR : (ignore at start up) ReverbGetRoomLevel() has wrong level -> %d %d\n",
@@ -1129,6 +1144,8 @@
LVM_ERROR_CHECK(LvmStatus, "LVREV_SetControlParameters", "ReverbSetDecayTime")
//LOGV("\tReverbSetDecayTime() just Set -> %d\n", ActiveParams.T60);
+ pContext->SamplesToExitCount = (ActiveParams.T60 * pContext->config.inputCfg.samplingRate)/1000;
+ //LOGV("\tReverbSetDecayTime() just Set SamplesToExitCount-> %d\n",pContext->SamplesToExitCount);
pContext->SavedDecayTime = time;
//LOGV("\tReverbSetDecayTime end");
return;
@@ -1769,8 +1786,12 @@
return -EINVAL;
}
if (pContext->bEnabled == LVM_FALSE){
- LOGV("\tReverb_process() ERROR Effect is not enabled");
- return -ENODATA;
+ if( pContext->SamplesToExitCount > 0){
+ pContext->SamplesToExitCount -= outBuffer->frameCount;
+ }else{
+ LOGV("\tReverb_process() ERROR Effect is not enabled %d", pContext->SamplesToExitCount);
+ return -ENODATA;
+ }
}
//LOGV("\tReverb_process() Calling process with %d frames", outBuffer->frameCount);
/* Process all the available frames, block processing is handled internalLY by the LVM bundle */
@@ -1791,6 +1812,9 @@
void *pReplyData){
android::ReverbContext * pContext = (android::ReverbContext *) self;
int retsize;
+ LVREV_ControlParams_st ActiveParams; /* Current control Parameters */
+ LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */
+
if (pContext == NULL){
LOGV("\tLVM_ERROR : Reverb_command ERROR pContext == NULL");
@@ -1917,6 +1941,12 @@
}
*(int *)pReplyData = 0;
pContext->bEnabled = LVM_TRUE;
+ /* Get the current settings */
+ LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams);
+ LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "EFFECT_CMD_ENABLE")
+ pContext->SamplesToExitCount =
+ (ActiveParams.T60 * pContext->config.inputCfg.samplingRate)/1000;
+ //LOGV("\tEFFECT_CMD_ENABLE SamplesToExitCount = %d", pContext->SamplesToExitCount);
break;
case EFFECT_CMD_DISABLE:
//LOGV("\tReverb_command cmdCode Case: "
@@ -1939,8 +1969,8 @@
case EFFECT_CMD_SET_DEVICE:
case EFFECT_CMD_SET_VOLUME:
case EFFECT_CMD_SET_AUDIO_MODE:
- //LOGV("\tReverb_command cmdCode Case: "
- // "EFFECT_CMD_SET_DEVICE/EFFECT_CMD_SET_VOLUME/EFFECT_CMD_SET_AUDIO_MODE start");
+ //LOGV("\tReverb_command cmdCode Case: "
+ // "EFFECT_CMD_SET_DEVICE/EFFECT_CMD_SET_VOLUME/EFFECT_CMD_SET_AUDIO_MODE start");
break;
default:
diff --git a/media/libmedia/IOMX.cpp b/media/libmedia/IOMX.cpp
index f3804b8..40801a2 100644
--- a/media/libmedia/IOMX.cpp
+++ b/media/libmedia/IOMX.cpp
@@ -21,7 +21,9 @@
SET_PARAMETER,
GET_CONFIG,
SET_CONFIG,
+ ENABLE_GRAPHIC_BUFFERS,
USE_BUFFER,
+ USE_GRAPHIC_BUFFER,
ALLOC_BUFFER,
ALLOC_BUFFER_WITH_BACKUP,
FREE_BUFFER,
@@ -216,6 +218,19 @@
return reply.readInt32();
}
+ virtual status_t enableGraphicBuffers(
+ node_id node, OMX_U32 port_index, OMX_BOOL enable) {
+ Parcel data, reply;
+ data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
+ data.writeIntPtr((intptr_t)node);
+ data.writeInt32(port_index);
+ data.writeInt32((uint32_t)enable);
+ remote()->transact(ENABLE_GRAPHIC_BUFFERS, data, &reply);
+
+ status_t err = reply.readInt32();
+ return err;
+ }
+
virtual status_t useBuffer(
node_id node, OMX_U32 port_index, const sp<IMemory> ¶ms,
buffer_id *buffer) {
@@ -238,6 +253,29 @@
return err;
}
+
+ virtual status_t useGraphicBuffer(
+ node_id node, OMX_U32 port_index,
+ const sp<GraphicBuffer> &graphicBuffer, buffer_id *buffer) {
+ Parcel data, reply;
+ data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
+ data.writeIntPtr((intptr_t)node);
+ data.writeInt32(port_index);
+ data.write(*graphicBuffer);
+ remote()->transact(USE_GRAPHIC_BUFFER, data, &reply);
+
+ status_t err = reply.readInt32();
+ if (err != OK) {
+ *buffer = 0;
+
+ return err;
+ }
+
+ *buffer = (void*)reply.readIntPtr();
+
+ return err;
+ }
+
virtual status_t allocateBuffer(
node_id node, OMX_U32 port_index, size_t size,
buffer_id *buffer, void **buffer_data) {
@@ -541,6 +579,20 @@
return NO_ERROR;
}
+ case ENABLE_GRAPHIC_BUFFERS:
+ {
+ CHECK_INTERFACE(IOMX, data, reply);
+
+ node_id node = (void*)data.readIntPtr();
+ OMX_U32 port_index = data.readInt32();
+ OMX_BOOL enable = (OMX_BOOL)data.readInt32();
+
+ status_t err = enableGraphicBuffers(node, port_index, enable);
+ reply->writeInt32(err);
+
+ return NO_ERROR;
+ }
+
case USE_BUFFER:
{
CHECK_INTERFACE(IOMX, data, reply);
@@ -561,6 +613,27 @@
return NO_ERROR;
}
+ case USE_GRAPHIC_BUFFER:
+ {
+ CHECK_INTERFACE(IOMX, data, reply);
+
+ node_id node = (void*)data.readIntPtr();
+ OMX_U32 port_index = data.readInt32();
+ sp<GraphicBuffer> graphicBuffer = new GraphicBuffer();
+ data.read(*graphicBuffer);
+
+ buffer_id buffer;
+ status_t err = useGraphicBuffer(
+ node, port_index, graphicBuffer, &buffer);
+ reply->writeInt32(err);
+
+ if (err == OK) {
+ reply->writeIntPtr((intptr_t)buffer);
+ }
+
+ return NO_ERROR;
+ }
+
case ALLOC_BUFFER:
{
CHECK_INTERFACE(IOMX, data, reply);
diff --git a/media/libstagefright/AudioSource.cpp b/media/libstagefright/AudioSource.cpp
index 4c729e4..c2f79e8 100644
--- a/media/libstagefright/AudioSource.cpp
+++ b/media/libstagefright/AudioSource.cpp
@@ -72,6 +72,10 @@
return UNKNOWN_ERROR;
}
+ if (mInitCheck != OK) {
+ return NO_INIT;
+ }
+
char value[PROPERTY_VALUE_MAX];
if (property_get("media.stagefright.record-stats", value, NULL)
&& (!strcmp(value, "1") || !strcasecmp(value, "true"))) {
@@ -80,6 +84,7 @@
mTrackMaxAmplitude = false;
mMaxAmplitude = 0;
+ mInitialReadTimeUs = 0;
mStartTimeUs = 0;
int64_t startTimeUs;
if (params && params->findInt64(kKeyTime, &startTimeUs)) {
@@ -102,6 +107,10 @@
return UNKNOWN_ERROR;
}
+ if (mInitCheck != OK) {
+ return NO_INIT;
+ }
+
mRecord->stop();
delete mGroup;
@@ -118,6 +127,10 @@
}
sp<MetaData> AudioSource::getFormat() {
+ if (mInitCheck != OK) {
+ return 0;
+ }
+
sp<MetaData> meta = new MetaData;
meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_RAW);
meta->setInt32(kKeySampleRate, mRecord->getSampleRate());
@@ -193,6 +206,12 @@
status_t AudioSource::read(
MediaBuffer **out, const ReadOptions *options) {
+
+ if (mInitCheck != OK) {
+ return NO_INIT;
+ }
+
+ int64_t readTimeUs = systemTime() / 1000;
*out = NULL;
MediaBuffer *buffer;
@@ -206,9 +225,10 @@
if (numFramesRecorded == 0 && mPrevSampleTimeUs == 0) {
+ mInitialReadTimeUs = readTimeUs;
// Initial delay
if (mStartTimeUs > 0) {
- mStartTimeUs = systemTime() / 1000 - mStartTimeUs;
+ mStartTimeUs = readTimeUs - mStartTimeUs;
} else {
// Assume latency is constant.
mStartTimeUs += mRecord->latency() * 1000;
@@ -254,7 +274,10 @@
}
memset(buffer->data(), 0, numLostBytes);
buffer->set_range(0, numLostBytes);
- buffer->meta_data()->setInt64(kKeyTime, mPrevSampleTimeUs);
+ if (numFramesRecorded == 0) {
+ buffer->meta_data()->setInt64(kKeyTime, mStartTimeUs);
+ }
+ buffer->meta_data()->setInt64(kKeyDriftTime, readTimeUs - mInitialReadTimeUs);
mPrevSampleTimeUs = timestampUs;
*out = buffer;
return OK;
@@ -292,12 +315,11 @@
trackMaxAmplitude((int16_t *) buffer->data(), n >> 1);
}
- buffer->meta_data()->setInt64(kKeyTime, mPrevSampleTimeUs);
- CHECK(timestampUs > mPrevSampleTimeUs);
- if (mTotalLostFrames == 0) {
- CHECK_EQ(mPrevSampleTimeUs,
- mStartTimeUs + (1000000LL * numFramesRecorded) / sampleRate);
+ if (numFramesRecorded == 0) {
+ buffer->meta_data()->setInt64(kKeyTime, mStartTimeUs);
}
+ buffer->meta_data()->setInt64(kKeyDriftTime, readTimeUs - mInitialReadTimeUs);
+ CHECK(timestampUs > mPrevSampleTimeUs);
mPrevSampleTimeUs = timestampUs;
LOGV("initial delay: %lld, sample rate: %d, timestamp: %lld",
mStartTimeUs, sampleRate, timestampUs);
diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp
index 085e92d..fd5f30b 100644
--- a/media/libstagefright/AwesomePlayer.cpp
+++ b/media/libstagefright/AwesomePlayer.cpp
@@ -50,6 +50,9 @@
namespace android {
+static int64_t kLowWaterMarkUs = 2000000ll; // 2secs
+static int64_t kHighWaterMarkUs = 10000000ll; // 10secs
+
struct AwesomeEvent : public TimedEventQueue::Event {
AwesomeEvent(
AwesomePlayer *player,
@@ -274,9 +277,13 @@
status_t AwesomePlayer::setDataSource(
int fd, int64_t offset, int64_t length) {
#if 0
+ // return setDataSource("httplive://qthttp.apple.com.edgesuite.net/1009qpeijrfn/sl.m3u8");
+ return setDataSource("httplive://qthttp.apple.com.edgesuite.net/1009qpeijrfn/0440.m3u8");
+ // return setDataSource("httplive://qthttp.apple.com.edgesuite.net/1009qpeijrfn/0640.m3u8");
+ // return setDataSource("httplive://qthttp.apple.com.edgesuite.net/1009qpeijrfn/1240_vod.m3u8");
// return setDataSource("httplive://iphoned5.akamai.com.edgesuite.net/mhbarron/nasatv/nasatv_96.m3u8");
// return setDataSource("httplive://iphoned5.akamai.com.edgesuite.net/mhbarron/nasatv/nasatv_1500.m3u8");
- return setDataSource("httplive://iphone.video.hsn.com/iPhone_high.m3u8");
+ // return setDataSource("httplive://iphone.video.hsn.com/iPhone_high.m3u8");
// return setDataSource("httplive://iphoned5.akamai.com.edgesuite.net/mhbarron/iphonewebcast/webcast090209_all/webcast090209_all.m3u8");
// return setDataSource("httplive://qthttp.akamai.com.edgesuite.net/iphone_demo/Video_Content/usat/tt_062209_iphone/hi/prog_index.m3u8");
// return setDataSource("httplive://qthttp.akamai.com.edgesuite.net/iphone_demo/Video_Content/usat/tt_googmaps/hi/prog_index.m3u8");
@@ -326,6 +333,13 @@
} else if (!haveAudio && !strncasecmp(mime, "audio/", 6)) {
setAudioSource(extractor->getTrack(i));
haveAudio = true;
+
+ sp<MetaData> fileMeta = extractor->getMetaData();
+ int32_t loop;
+ if (fileMeta != NULL
+ && fileMeta->findInt32(kKeyAutoLoop, &loop) && loop != 0) {
+ mFlags |= AUTO_LOOPING;
+ }
}
if (haveAudio && haveVideo) {
@@ -449,6 +463,25 @@
}
}
+// Returns true iff cached duration is available/applicable.
+bool AwesomePlayer::getCachedDuration_l(int64_t *durationUs, bool *eos) {
+ off_t totalSize;
+
+ if (mRTSPController != NULL) {
+ *durationUs = mRTSPController->getQueueDurationUs(eos);
+ return true;
+ } else if (mCachedSource != NULL && mDurationUs >= 0
+ && mCachedSource->getSize(&totalSize) == OK) {
+ int64_t bitrate = totalSize * 8000000ll / mDurationUs; // in bits/sec
+
+ size_t cachedDataRemaining = mCachedSource->approxDataRemaining(eos);
+ *durationUs = cachedDataRemaining * 8000000ll / bitrate;
+ return true;
+ }
+
+ return false;
+}
+
void AwesomePlayer::onBufferingUpdate() {
Mutex::Autolock autoLock(mLock);
if (!mBufferingEventPending) {
@@ -456,49 +489,80 @@
}
mBufferingEventPending = false;
- if (mCachedSource == NULL) {
- return;
- }
+ if (mCachedSource != NULL) {
+ bool eos;
+ size_t cachedDataRemaining = mCachedSource->approxDataRemaining(&eos);
- bool eos;
- size_t cachedDataRemaining = mCachedSource->approxDataRemaining(&eos);
+ if (eos) {
+ notifyListener_l(MEDIA_BUFFERING_UPDATE, 100);
+ } else {
+ off_t size;
+ if (mDurationUs >= 0 && mCachedSource->getSize(&size) == OK) {
+ int64_t bitrate = size * 8000000ll / mDurationUs; // in bits/sec
- size_t lowWatermark = 400000;
- size_t highWatermark = 1000000;
+ size_t cachedSize = mCachedSource->cachedSize();
+ int64_t cachedDurationUs = cachedSize * 8000000ll / bitrate;
- if (eos) {
- notifyListener_l(MEDIA_BUFFERING_UPDATE, 100);
- } else {
- off_t size;
- if (mDurationUs >= 0 && mCachedSource->getSize(&size) == OK) {
- int64_t bitrate = size * 8000000ll / mDurationUs; // in bits/sec
+ int percentage = 100.0 * (double)cachedDurationUs / mDurationUs;
+ if (percentage > 100) {
+ percentage = 100;
+ }
- size_t cachedSize = mCachedSource->cachedSize();
- int64_t cachedDurationUs = cachedSize * 8000000ll / bitrate;
+ notifyListener_l(MEDIA_BUFFERING_UPDATE, percentage);
+ } else {
+ // We don't know the bitrate of the stream, use absolute size
+ // limits to maintain the cache.
- int percentage = 100.0 * (double)cachedDurationUs / mDurationUs;
- if (percentage > 100) {
- percentage = 100;
+ const size_t kLowWaterMarkBytes = 400000;
+ const size_t kHighWaterMarkBytes = 1000000;
+
+ if ((mFlags & PLAYING) && !eos
+ && (cachedDataRemaining < kLowWaterMarkBytes)) {
+ LOGI("cache is running low (< %d) , pausing.",
+ kLowWaterMarkBytes);
+ mFlags |= CACHE_UNDERRUN;
+ pause_l();
+ notifyListener_l(MEDIA_INFO, MEDIA_INFO_BUFFERING_START);
+ } else if (eos || cachedDataRemaining > kHighWaterMarkBytes) {
+ if (mFlags & CACHE_UNDERRUN) {
+ LOGI("cache has filled up (> %d), resuming.",
+ kHighWaterMarkBytes);
+ mFlags &= ~CACHE_UNDERRUN;
+ play_l();
+ notifyListener_l(MEDIA_INFO, MEDIA_INFO_BUFFERING_END);
+ } else if (mFlags & PREPARING) {
+ LOGV("cache has filled up (> %d), prepare is done",
+ kHighWaterMarkBytes);
+ finishAsyncPrepare_l();
+ }
+ }
}
-
- notifyListener_l(MEDIA_BUFFERING_UPDATE, percentage);
-
- lowWatermark = 2 * bitrate / 8; // 2 secs
- highWatermark = 10 * bitrate / 8; // 10 secs
}
}
- if ((mFlags & PLAYING) && !eos && (cachedDataRemaining < lowWatermark)) {
- LOGI("cache is running low (< %d) , pausing.", lowWatermark);
- mFlags |= CACHE_UNDERRUN;
- pause_l();
- notifyListener_l(MEDIA_INFO, MEDIA_INFO_BUFFERING_START);
- } else if ((mFlags & CACHE_UNDERRUN)
- && (eos || cachedDataRemaining > highWatermark)) {
- LOGI("cache has filled up (> %d), resuming.", highWatermark);
- mFlags &= ~CACHE_UNDERRUN;
- play_l();
- notifyListener_l(MEDIA_INFO, MEDIA_INFO_BUFFERING_END);
+ int64_t cachedDurationUs;
+ bool eos;
+ if (getCachedDuration_l(&cachedDurationUs, &eos)) {
+ if ((mFlags & PLAYING) && !eos
+ && (cachedDurationUs < kLowWaterMarkUs)) {
+ LOGI("cache is running low (%.2f secs) , pausing.",
+ cachedDurationUs / 1E6);
+ mFlags |= CACHE_UNDERRUN;
+ pause_l();
+ notifyListener_l(MEDIA_INFO, MEDIA_INFO_BUFFERING_START);
+ } else if (eos || cachedDurationUs > kHighWaterMarkUs) {
+ if (mFlags & CACHE_UNDERRUN) {
+ LOGI("cache has filled up (%.2f secs), resuming.",
+ cachedDurationUs / 1E6);
+ mFlags &= ~CACHE_UNDERRUN;
+ play_l();
+ notifyListener_l(MEDIA_INFO, MEDIA_INFO_BUFFERING_END);
+ } else if (mFlags & PREPARING) {
+ LOGV("cache has filled up (%.2f secs), prepare is done",
+ cachedDurationUs / 1E6);
+ finishAsyncPrepare_l();
+ }
+ }
}
postBufferingEvent_l();
@@ -533,7 +597,7 @@
return;
}
- if (mFlags & LOOPING) {
+ if (mFlags & (LOOPING | AUTO_LOOPING)) {
seekTo_l(0);
if (mVideoSource != NULL) {
@@ -1428,45 +1492,49 @@
}
void AwesomePlayer::onPrepareAsyncEvent() {
- {
- Mutex::Autolock autoLock(mLock);
+ Mutex::Autolock autoLock(mLock);
- if (mFlags & PREPARE_CANCELLED) {
- LOGI("prepare was cancelled before doing anything");
- abortPrepare(UNKNOWN_ERROR);
+ if (mFlags & PREPARE_CANCELLED) {
+ LOGI("prepare was cancelled before doing anything");
+ abortPrepare(UNKNOWN_ERROR);
+ return;
+ }
+
+ if (mUri.size() > 0) {
+ status_t err = finishSetDataSource_l();
+
+ if (err != OK) {
+ abortPrepare(err);
return;
}
-
- if (mUri.size() > 0) {
- status_t err = finishSetDataSource_l();
-
- if (err != OK) {
- abortPrepare(err);
- return;
- }
- }
-
- if (mVideoTrack != NULL && mVideoSource == NULL) {
- status_t err = initVideoDecoder();
-
- if (err != OK) {
- abortPrepare(err);
- return;
- }
- }
-
- if (mAudioTrack != NULL && mAudioSource == NULL) {
- status_t err = initAudioDecoder();
-
- if (err != OK) {
- abortPrepare(err);
- return;
- }
- }
}
- Mutex::Autolock autoLock(mLock);
+ if (mVideoTrack != NULL && mVideoSource == NULL) {
+ status_t err = initVideoDecoder();
+ if (err != OK) {
+ abortPrepare(err);
+ return;
+ }
+ }
+
+ if (mAudioTrack != NULL && mAudioSource == NULL) {
+ status_t err = initAudioDecoder();
+
+ if (err != OK) {
+ abortPrepare(err);
+ return;
+ }
+ }
+
+ if (mCachedSource != NULL || mRTSPController != NULL) {
+ postBufferingEvent_l();
+ } else {
+ finishAsyncPrepare_l();
+ }
+}
+
+void AwesomePlayer::finishAsyncPrepare_l() {
if (mIsAsyncPrepare) {
if (mVideoSource == NULL) {
notifyListener_l(MEDIA_SET_VIDEO_SIZE, 0, 0);
@@ -1482,8 +1550,6 @@
mFlags |= PREPARED;
mAsyncPrepareEvent = NULL;
mPreparedCondition.broadcast();
-
- postBufferingEvent_l();
}
status_t AwesomePlayer::suspend() {
@@ -1523,7 +1589,7 @@
state->mUriHeaders = mUriHeaders;
state->mFileSource = mFileSource;
- state->mFlags = mFlags & (PLAYING | LOOPING | AT_EOS);
+ state->mFlags = mFlags & (PLAYING | AUTO_LOOPING | LOOPING | AT_EOS);
getPosition(&state->mPositionUs);
if (mLastVideoBuffer) {
@@ -1584,7 +1650,7 @@
seekTo_l(state->mPositionUs);
- mFlags = state->mFlags & (LOOPING | AT_EOS);
+ mFlags = state->mFlags & (AUTO_LOOPING | LOOPING | AT_EOS);
if (state->mLastVideoFrame && (mSurface != NULL || mISurface != NULL)) {
mVideoRenderer =
diff --git a/media/libstagefright/MPEG4Writer.cpp b/media/libstagefright/MPEG4Writer.cpp
index a15b84e..806836d 100644
--- a/media/libstagefright/MPEG4Writer.cpp
+++ b/media/libstagefright/MPEG4Writer.cpp
@@ -32,12 +32,12 @@
#include <media/stagefright/MediaSource.h>
#include <media/stagefright/Utils.h>
#include <media/mediarecorder.h>
-#include <cutils/properties.h>
#include "include/ESDS.h"
namespace android {
+static const int64_t kMax32BitFileSize = 0x007fffffffLL;
static const uint8_t kNalUnitTypeSeqParamSet = 0x07;
static const uint8_t kNalUnitTypePicParamSet = 0x08;
@@ -59,7 +59,7 @@
bool isAvc() const { return mIsAvc; }
bool isAudio() const { return mIsAudio; }
bool isMPEG4() const { return mIsMPEG4; }
- void addChunkOffset(off_t offset) { mChunkOffsets.push_back(offset); }
+ void addChunkOffset(off_t offset);
status_t dump(int fd, const Vector<String16>& args) const;
private:
@@ -79,7 +79,7 @@
bool mIsRealTimeRecording;
int64_t mMaxTimeStampUs;
int64_t mEstimatedTrackSizeBytes;
- int64_t mMaxWriteTimeUs;
+ int64_t mMdatSizeBytes;
int32_t mTimeScale;
pthread_t mThread;
@@ -92,8 +92,11 @@
bool mSamplesHaveSameSize;
List<MediaBuffer *> mChunkSamples;
+
+ size_t mNumStcoTableEntries;
List<off_t> mChunkOffsets;
+ size_t mNumStscTableEntries;
struct StscTableEntry {
StscTableEntry(uint32_t chunk, uint32_t samples, uint32_t id)
@@ -107,9 +110,10 @@
};
List<StscTableEntry> mStscTableEntries;
+ size_t mNumStssTableEntries;
List<int32_t> mStssTableEntries;
- List<int64_t> mChunkDurations;
+ size_t mNumSttsTableEntries;
struct SttsTableEntry {
SttsTableEntry(uint32_t count, uint32_t durationUs)
@@ -161,12 +165,6 @@
void trackProgressStatus(int64_t timeUs, status_t err = OK);
void initTrackingProgressStatus(MetaData *params);
- // Utilities for collecting statistical data
- void logStatisticalData(bool isAudio);
- void findMinAvgMaxSampleDurationMs(
- int32_t *min, int32_t *avg, int32_t *max);
- void findMinMaxChunkDurations(int64_t *min, int64_t *max);
-
void getCodecSpecificDataFromInputFormatIfPossible();
// Determine the track time scale
@@ -178,14 +176,18 @@
// Simple validation on the codec specific data
status_t checkCodecSpecificData() const;
+ void updateTrackSizeEstimate();
+ void addOneStscTableEntry(size_t chunkId, size_t sampleId);
+ void addOneStssTableEntry(size_t sampleId);
+ void addOneSttsTableEntry(size_t sampleCount, int64_t durationUs);
+
Track(const Track &);
Track &operator=(const Track &);
};
-#define USE_NALLEN_FOUR 1
-
MPEG4Writer::MPEG4Writer(const char *filename)
: mFile(fopen(filename, "wb")),
+ mUse4ByteNalLength(true),
mUse32BitOffset(true),
mPaused(false),
mStarted(false),
@@ -198,6 +200,7 @@
MPEG4Writer::MPEG4Writer(int fd)
: mFile(fdopen(fd, "wb")),
+ mUse4ByteNalLength(true),
mUse32BitOffset(true),
mPaused(false),
mStarted(false),
@@ -211,9 +214,11 @@
MPEG4Writer::~MPEG4Writer() {
stop();
- for (List<Track *>::iterator it = mTracks.begin();
- it != mTracks.end(); ++it) {
+ while (!mTracks.empty()) {
+ List<Track *>::iterator it = mTracks.begin();
delete *it;
+ (*it) = NULL;
+ mTracks.erase(it);
}
mTracks.clear();
}
@@ -332,11 +337,26 @@
mUse32BitOffset = false;
}
- // System property can overwrite the file offset bits parameter
- char value[PROPERTY_VALUE_MAX];
- if (property_get("media.stagefright.record-64bits", value, NULL)
- && (!strcmp(value, "1") || !strcasecmp(value, "true"))) {
- mUse32BitOffset = false;
+ if (mUse32BitOffset) {
+ // Implicit 32 bit file size limit
+ if (mMaxFileSizeLimitBytes == 0) {
+ mMaxFileSizeLimitBytes = kMax32BitFileSize;
+ }
+
+ // If file size is set to be larger than the 32 bit file
+ // size limit, treat it as an error.
+ if (mMaxFileSizeLimitBytes > kMax32BitFileSize) {
+ LOGE("32-bit file size limit too big: %lld bytes",
+ mMaxFileSizeLimitBytes);
+ return UNKNOWN_ERROR;
+ }
+ }
+
+ int32_t use2ByteNalLength;
+ if (param &&
+ param->findInt32(kKey2ByteNalLength, &use2ByteNalLength) &&
+ use2ByteNalLength) {
+ mUse4ByteNalLength = false;
}
mStartTimestampUs = -1;
@@ -413,6 +433,10 @@
return OK;
}
+bool MPEG4Writer::use32BitFileOffset() const {
+ return mUse32BitOffset;
+}
+
status_t MPEG4Writer::pause() {
if (mFile == NULL) {
return OK;
@@ -607,32 +631,30 @@
size_t length = buffer->range_length();
-#if USE_NALLEN_FOUR
- uint8_t x = length >> 24;
- fwrite(&x, 1, 1, mFile);
- x = (length >> 16) & 0xff;
- fwrite(&x, 1, 1, mFile);
- x = (length >> 8) & 0xff;
- fwrite(&x, 1, 1, mFile);
- x = length & 0xff;
- fwrite(&x, 1, 1, mFile);
-#else
- CHECK(length < 65536);
+ if (mUse4ByteNalLength) {
+ uint8_t x = length >> 24;
+ fwrite(&x, 1, 1, mFile);
+ x = (length >> 16) & 0xff;
+ fwrite(&x, 1, 1, mFile);
+ x = (length >> 8) & 0xff;
+ fwrite(&x, 1, 1, mFile);
+ x = length & 0xff;
+ fwrite(&x, 1, 1, mFile);
- uint8_t x = length >> 8;
- fwrite(&x, 1, 1, mFile);
- x = length & 0xff;
- fwrite(&x, 1, 1, mFile);
-#endif
+ fwrite((const uint8_t *)buffer->data() + buffer->range_offset(),
+ 1, length, mFile);
+ mOffset += length + 4;
+ } else {
+ CHECK(length < 65536);
- fwrite((const uint8_t *)buffer->data() + buffer->range_offset(),
- 1, length, mFile);
-
-#if USE_NALLEN_FOUR
- mOffset += length + 4;
-#else
- mOffset += length + 2;
-#endif
+ uint8_t x = length >> 8;
+ fwrite(&x, 1, 1, mFile);
+ x = length & 0xff;
+ fwrite(&x, 1, 1, mFile);
+ fwrite((const uint8_t *)buffer->data() + buffer->range_offset(),
+ 1, length, mFile);
+ mOffset += length + 2;
+ }
return old_offset;
}
@@ -739,7 +761,8 @@
it != mTracks.end(); ++it) {
nTotalBytesEstimate += (*it)->getEstimatedTrackSizeBytes();
}
- return (nTotalBytesEstimate >= mMaxFileSizeLimitBytes);
+
+ return (nTotalBytesEstimate + 1024 >= mMaxFileSizeLimitBytes);
}
bool MPEG4Writer::exceedsFileDurationLimit() {
@@ -819,6 +842,48 @@
setTimeScale();
}
+void MPEG4Writer::Track::updateTrackSizeEstimate() {
+
+ int64_t stcoBoxSizeBytes = mOwner->use32BitFileOffset()
+ ? mNumStcoTableEntries * 4
+ : mNumStcoTableEntries * 8;
+
+ int64_t stszBoxSizeBytes = mSamplesHaveSameSize? 4: (mNumSamples * 4);
+
+ mEstimatedTrackSizeBytes = mMdatSizeBytes + // media data size
+ mNumStscTableEntries * 12 + // stsc box size
+ mNumStssTableEntries * 4 + // stss box size
+ mNumSttsTableEntries * 8 + // stts box size
+ stcoBoxSizeBytes + // stco box size
+ stszBoxSizeBytes; // stsz box size
+}
+
+void MPEG4Writer::Track::addOneStscTableEntry(
+ size_t chunkId, size_t sampleId) {
+
+ StscTableEntry stscEntry(chunkId, sampleId, 1);
+ mStscTableEntries.push_back(stscEntry);
+ ++mNumStscTableEntries;
+}
+
+void MPEG4Writer::Track::addOneStssTableEntry(size_t sampleId) {
+ mStssTableEntries.push_back(sampleId);
+ ++mNumStssTableEntries;
+}
+
+void MPEG4Writer::Track::addOneSttsTableEntry(
+ size_t sampleCount, int64_t durationUs) {
+
+ SttsTableEntry sttsEntry(sampleCount, durationUs);
+ mSttsTableEntries.push_back(sttsEntry);
+ ++mNumSttsTableEntries;
+}
+
+void MPEG4Writer::Track::addChunkOffset(off_t offset) {
+ ++mNumStcoTableEntries;
+ mChunkOffsets.push_back(offset);
+}
+
void MPEG4Writer::Track::setTimeScale() {
LOGV("setTimeScale");
// Default time scale
@@ -1039,6 +1104,7 @@
return OK;
}
+
status_t MPEG4Writer::Track::start(MetaData *params) {
if (!mDone && mPaused) {
mPaused = false;
@@ -1077,6 +1143,11 @@
mTrackDurationUs = 0;
mReachedEOS = false;
mEstimatedTrackSizeBytes = 0;
+ mNumStcoTableEntries = 0;
+ mNumStssTableEntries = 0;
+ mNumStscTableEntries = 0;
+ mNumSttsTableEntries = 0;
+ mMdatSizeBytes = 0;
pthread_create(&mThread, &attr, ThreadWrapper, this);
pthread_attr_destroy(&attr);
@@ -1123,46 +1194,6 @@
return (void *) err;
}
-#include <ctype.h>
-static void hexdump(const void *_data, size_t size) {
- const uint8_t *data = (const uint8_t *)_data;
- size_t offset = 0;
- while (offset < size) {
- printf("0x%04x ", offset);
-
- size_t n = size - offset;
- if (n > 16) {
- n = 16;
- }
-
- for (size_t i = 0; i < 16; ++i) {
- if (i == 8) {
- printf(" ");
- }
-
- if (offset + i < size) {
- printf("%02x ", data[offset + i]);
- } else {
- printf(" ");
- }
- }
-
- printf(" ");
-
- for (size_t i = 0; i < n; ++i) {
- if (isprint(data[offset + i])) {
- printf("%c", data[offset + i]);
- } else {
- printf(".");
- }
- }
-
- printf("\n");
-
- offset += 16;
- }
-}
-
static void getNalUnitType(uint8_t byte, uint8_t* type) {
LOGV("getNalUnitType: %d", byte);
@@ -1334,7 +1365,6 @@
status_t MPEG4Writer::Track::makeAVCCodecSpecificData(
const uint8_t *data, size_t size) {
- // hexdump(data, size);
if (mCodecSpecificData != NULL) {
LOGE("Already have codec specific data");
@@ -1365,11 +1395,11 @@
header[3] = mLevelIdc;
// 6-bit '111111' followed by 2-bit to lengthSizeMinuusOne
-#if USE_NALLEN_FOUR
- header[4] = 0xfc | 3; // length size == 4 bytes
-#else
- header[4] = 0xfc | 1; // length size == 2 bytes
-#endif
+ if (mOwner->useNalLengthFour()) {
+ header[4] = 0xfc | 3; // length size == 4 bytes
+ } else {
+ header[4] = 0xfc | 1; // length size == 2 bytes
+ }
// 3-bit '111' followed by 5-bit numSequenceParameterSets
int nSequenceParamSets = mSeqParamSets.size();
@@ -1406,15 +1436,6 @@
return OK;
}
-static bool collectStatisticalData() {
- char value[PROPERTY_VALUE_MAX];
- if (property_get("media.stagefright.record-stats", value, NULL)
- && (!strcmp(value, "1") || !strcasecmp(value, "true"))) {
- return true;
- }
- return false;
-}
-
status_t MPEG4Writer::Track::threadEntry() {
int32_t count = 0;
const int64_t interleaveDurationUs = mOwner->interleaveDuration();
@@ -1430,14 +1451,9 @@
int64_t previousPausedDurationUs = 0;
int64_t timestampUs;
- int64_t wallClockTimeUs = 0;
- int64_t lastWallClockTimeUs = 0;
-
sp<MetaData> meta_data;
- bool collectStats = collectStatisticalData();
mNumSamples = 0;
- mMaxWriteTimeUs = 0;
status_t err = OK;
MediaBuffer *buffer;
while (!mDone && (err = mSource->read(&buffer)) == OK) {
@@ -1498,17 +1514,19 @@
if (mIsAvc) StripStartcode(copy);
- size_t sampleSize;
- sampleSize = mIsAvc
-#if USE_NALLEN_FOUR
- ? copy->range_length() + 4
-#else
- ? copy->range_length() + 2
-#endif
- : copy->range_length();
+ size_t sampleSize = copy->range_length();
+ if (mIsAvc) {
+ if (mOwner->useNalLengthFour()) {
+ sampleSize += 4;
+ } else {
+ sampleSize += 2;
+ }
+ }
// Max file size or duration handling
- mEstimatedTrackSizeBytes += sampleSize;
+ mMdatSizeBytes += sampleSize;
+ updateTrackSizeEstimate();
+
if (mOwner->exceedsFileSizeLimit()) {
mOwner->notify(MEDIA_RECORDER_EVENT_INFO, MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED, 0);
break;
@@ -1542,14 +1560,15 @@
// of neighboring samples. This in turn helps reduce the track header size,
// especially, the number of entries in the "stts" box.
if (mNumSamples > 1) {
- int64_t durationUs = timestampUs + mOwner->getDriftTimeUs() - lastTimestampUs;
+ int64_t currDriftTimeUs = mOwner->getDriftTimeUs();
+ int64_t durationUs = timestampUs + currDriftTimeUs - lastTimestampUs;
int64_t diffUs = (durationUs > lastDurationUs)
? durationUs - lastDurationUs
: lastDurationUs - durationUs;
if (diffUs <= 5000) { // XXX: Magic number 5ms
timestampUs = lastTimestampUs + lastDurationUs;
} else {
- timestampUs += mOwner->getDriftTimeUs();
+ timestampUs += currDriftTimeUs;
}
}
}
@@ -1557,12 +1576,6 @@
if (mNumSamples > 1) {
if (timestampUs <= lastTimestampUs) {
LOGW("Frame arrives too late!");
-#if 0
- // Drop the late frame.
- copy->release();
- copy = NULL;
- continue;
-#else
// Don't drop the late frame, since dropping a frame may cause
// problems later during playback
@@ -1573,7 +1586,6 @@
} else {
timestampUs = lastTimestampUs + (1000000LL + (mTimeScale >> 1)) / mTimeScale;
}
-#endif
}
}
@@ -1596,8 +1608,7 @@
(lastTimestampUs * mTimeScale + 500000LL) / 1000000LL);
if (currDurationTicks != lastDurationTicks) {
- SttsTableEntry sttsEntry(sampleCount, lastDurationUs);
- mSttsTableEntries.push_back(sttsEntry);
+ addOneSttsTableEntry(sampleCount, lastDurationUs);
sampleCount = 1;
} else {
++sampleCount;
@@ -1613,16 +1624,14 @@
lastDurationTicks = currDurationTicks;
lastTimestampUs = timestampUs;
if (mIsRealTimeRecording && mIsAudio) {
- wallClockTimeUs = systemTime() / 1000;
- int64_t wallClockDurationUs = wallClockTimeUs - lastWallClockTimeUs;
- if (mNumSamples > 2) {
- mOwner->addDriftTimeUs(lastDurationUs - wallClockDurationUs);
+ int64_t driftTimeUs = 0;
+ if (meta_data->findInt64(kKeyDriftTime, &driftTimeUs)) {
+ mOwner->setDriftTimeUs(driftTimeUs);
}
- lastWallClockTimeUs = wallClockTimeUs;
}
if (isSync != 0) {
- mStssTableEntries.push_back(mNumSamples);
+ addOneStssTableEntry(mNumSamples);
}
if (mTrackingProgressStatus) {
@@ -1635,7 +1644,7 @@
off_t offset = mIsAvc? mOwner->addLengthPrefixedSample_l(copy)
: mOwner->addSample_l(copy);
if (mChunkOffsets.empty()) {
- mChunkOffsets.push_back(offset);
+ addChunkOffset(offset);
}
copy->release();
copy = NULL;
@@ -1644,8 +1653,7 @@
mChunkSamples.push_back(copy);
if (interleaveDurationUs == 0) {
- StscTableEntry stscEntry(++nChunks, 1, 1);
- mStscTableEntries.push_back(stscEntry);
+ addOneStscTableEntry(++nChunks, 1);
bufferChunk(timestampUs);
} else {
if (chunkTimestampUs == 0) {
@@ -1653,15 +1661,10 @@
} else {
if (timestampUs - chunkTimestampUs > interleaveDurationUs) {
++nChunks;
- if (collectStats) {
- mChunkDurations.push_back(timestampUs - chunkTimestampUs);
- }
if (nChunks == 1 || // First chunk
(--(mStscTableEntries.end()))->samplesPerChunk !=
mChunkSamples.size()) {
- StscTableEntry stscEntry(nChunks,
- mChunkSamples.size(), 1);
- mStscTableEntries.push_back(stscEntry);
+ addOneStscTableEntry(nChunks, mChunkSamples.size());
}
bufferChunk(timestampUs);
chunkTimestampUs = timestampUs;
@@ -1680,12 +1683,9 @@
// Last chunk
if (mOwner->numTracks() == 1) {
- StscTableEntry stscEntry(1, mNumSamples, 1);
- mStscTableEntries.push_back(stscEntry);
+ addOneStscTableEntry(1, mNumSamples);
} else if (!mChunkSamples.empty()) {
- ++nChunks;
- StscTableEntry stscEntry(nChunks, mChunkSamples.size(), 1);
- mStscTableEntries.push_back(stscEntry);
+ addOneStscTableEntry(++nChunks, mChunkSamples.size());
bufferChunk(timestampUs);
}
@@ -1697,14 +1697,12 @@
} else {
++sampleCount; // Count for the last sample
}
- SttsTableEntry sttsEntry(sampleCount, lastDurationUs);
- mSttsTableEntries.push_back(sttsEntry);
+ addOneSttsTableEntry(sampleCount, lastDurationUs);
mTrackDurationUs += lastDurationUs;
mReachedEOS = true;
- LOGI("Received total/0-length (%d/%d) buffers and encoded %d frames. Max write time: %lld us - %s",
- count, nZeroLengthFrames, mNumSamples, mMaxWriteTimeUs, mIsAudio? "audio": "video");
+ LOGI("Received total/0-length (%d/%d) buffers and encoded %d frames. - %s",
+ count, nZeroLengthFrames, mNumSamples, mIsAudio? "audio": "video");
- logStatisticalData(mIsAudio);
if (err == ERROR_END_OF_STREAM) {
return OK;
}
@@ -1729,17 +1727,6 @@
CHECK(nTracks < 64); // Arbitrary number
int32_t trackNum = 0;
-#if 0
- // In the worst case, we can put the trackNum
- // along with MEDIA_RECORDER_INFO_COMPLETION_STATUS
- // to report the progress.
- for (List<Track *>::iterator it = mTracks.begin();
- it != mTracks.end(); ++it, ++trackNum) {
- if (track == (*it)) {
- break;
- }
- }
-#endif
CHECK(trackNum < nTracks);
trackNum <<= 16;
@@ -1766,95 +1753,10 @@
}
}
-void MPEG4Writer::Track::findMinAvgMaxSampleDurationMs(
- int32_t *min, int32_t *avg, int32_t *max) {
- CHECK(!mSampleSizes.empty());
- int32_t avgSampleDurationMs = mTrackDurationUs / 1000 / mNumSamples;
- int32_t minSampleDurationMs = 0x7FFFFFFF;
- int32_t maxSampleDurationMs = 0;
- for (List<SttsTableEntry>::iterator it = mSttsTableEntries.begin();
- it != mSttsTableEntries.end(); ++it) {
- int32_t sampleDurationMs =
- (static_cast<int32_t>(it->sampleDurationUs) + 500) / 1000;
- if (sampleDurationMs > maxSampleDurationMs) {
- maxSampleDurationMs = sampleDurationMs;
- } else if (sampleDurationMs < minSampleDurationMs) {
- minSampleDurationMs = sampleDurationMs;
- }
- LOGI("sample duration: %d ms", sampleDurationMs);
- }
- CHECK(minSampleDurationMs != 0);
- CHECK(avgSampleDurationMs != 0);
- CHECK(maxSampleDurationMs != 0);
- *min = minSampleDurationMs;
- *avg = avgSampleDurationMs;
- *max = maxSampleDurationMs;
-}
-
-// Don't count the last duration
-void MPEG4Writer::Track::findMinMaxChunkDurations(int64_t *min, int64_t *max) {
- int64_t duration = mOwner->interleaveDuration();
- int64_t minChunkDuration = duration;
- int64_t maxChunkDuration = duration;
- if (mChunkDurations.size() > 1) {
- for (List<int64_t>::iterator it = mChunkDurations.begin();
- it != --mChunkDurations.end(); ++it) {
- if (minChunkDuration > (*it)) {
- minChunkDuration = (*it);
- } else if (maxChunkDuration < (*it)) {
- maxChunkDuration = (*it);
- }
- }
- }
- *min = minChunkDuration;
- *max = maxChunkDuration;
-}
-
-void MPEG4Writer::Track::logStatisticalData(bool isAudio) {
- if (mTrackDurationUs <= 0 || mSampleSizes.empty()) {
- LOGI("nothing is recorded");
- return;
- }
-
- bool collectStats = collectStatisticalData();
-
- if (collectStats) {
- LOGI("%s track - duration %lld us, total %d frames",
- isAudio? "audio": "video", mTrackDurationUs,
- mNumSamples);
- int32_t min, avg, max;
- findMinAvgMaxSampleDurationMs(&min, &avg, &max);
- LOGI("min/avg/max sample duration (ms): %d/%d/%d", min, avg, max);
- if (!isAudio) {
- float avgFps = 1000.0 / avg;
- float minFps = 1000.0 / max;
- float maxFps = 1000.0 / min;
- LOGI("min/avg/max frame rate (fps): %.2f/%.2f/%.2f",
- minFps, avgFps, maxFps);
- }
-
- int64_t totalBytes = 0;
- for (List<size_t>::iterator it = mSampleSizes.begin();
- it != mSampleSizes.end(); ++it) {
- totalBytes += (*it);
- }
- float bitRate = (totalBytes * 8000000.0) / mTrackDurationUs;
- LOGI("avg bit rate (bps): %.2f", bitRate);
-
- int64_t duration = mOwner->interleaveDuration();
- if (duration != 0) { // If interleaving is enabled
- int64_t minChunk, maxChunk;
- findMinMaxChunkDurations(&minChunk, &maxChunk);
- LOGI("min/avg/max chunk duration (ms): %lld/%lld/%lld",
- minChunk, duration, maxChunk);
- }
- }
-}
-
-void MPEG4Writer::addDriftTimeUs(int64_t driftTimeUs) {
- LOGV("addDriftTimeUs: %lld us", driftTimeUs);
+void MPEG4Writer::setDriftTimeUs(int64_t driftTimeUs) {
+ LOGV("setDriftTimeUs: %lld us", driftTimeUs);
Mutex::Autolock autolock(mLock);
- mDriftTimeUs += driftTimeUs;
+ mDriftTimeUs = driftTimeUs;
}
int64_t MPEG4Writer::getDriftTimeUs() {
@@ -1863,17 +1765,16 @@
return mDriftTimeUs;
}
+bool MPEG4Writer::useNalLengthFour() {
+ return mUse4ByteNalLength;
+}
+
void MPEG4Writer::Track::bufferChunk(int64_t timestampUs) {
LOGV("bufferChunk");
- int64_t startTimeUs = systemTime() / 1000;
Chunk chunk(this, timestampUs, mChunkSamples);
mOwner->bufferChunk(chunk);
mChunkSamples.clear();
- int64_t endTimeUs = systemTime() / 1000;
- if (mMaxWriteTimeUs < endTimeUs - startTimeUs) {
- mMaxWriteTimeUs = endTimeUs - startTimeUs;
- }
}
int64_t MPEG4Writer::Track::getDurationUs() const {
@@ -2226,7 +2127,7 @@
mOwner->beginBox("stts");
mOwner->writeInt32(0); // version=0, flags=0
- mOwner->writeInt32(mSttsTableEntries.size());
+ mOwner->writeInt32(mNumSttsTableEntries);
int64_t prevTimestampUs = 0;
for (List<SttsTableEntry>::iterator it = mSttsTableEntries.begin();
it != mSttsTableEntries.end(); ++it) {
@@ -2246,7 +2147,7 @@
if (!mIsAudio) {
mOwner->beginBox("stss");
mOwner->writeInt32(0); // version=0, flags=0
- mOwner->writeInt32(mStssTableEntries.size()); // number of sync frames
+ mOwner->writeInt32(mNumStssTableEntries); // number of sync frames
for (List<int32_t>::iterator it = mStssTableEntries.begin();
it != mStssTableEntries.end(); ++it) {
mOwner->writeInt32(*it);
@@ -2273,7 +2174,7 @@
mOwner->beginBox("stsc");
mOwner->writeInt32(0); // version=0, flags=0
- mOwner->writeInt32(mStscTableEntries.size());
+ mOwner->writeInt32(mNumStscTableEntries);
for (List<StscTableEntry>::iterator it = mStscTableEntries.begin();
it != mStscTableEntries.end(); ++it) {
mOwner->writeInt32(it->firstChunk);
@@ -2283,7 +2184,7 @@
mOwner->endBox(); // stsc
mOwner->beginBox(use32BitOffset? "stco": "co64");
mOwner->writeInt32(0); // version=0, flags=0
- mOwner->writeInt32(mChunkOffsets.size());
+ mOwner->writeInt32(mNumStcoTableEntries);
for (List<off_t>::iterator it = mChunkOffsets.begin();
it != mChunkOffsets.end(); ++it) {
if (use32BitOffset) {
diff --git a/media/libstagefright/OggExtractor.cpp b/media/libstagefright/OggExtractor.cpp
index 2c1311a..7a8cf32 100644
--- a/media/libstagefright/OggExtractor.cpp
+++ b/media/libstagefright/OggExtractor.cpp
@@ -592,6 +592,7 @@
{ "DATE", kKeyDate },
{ "LYRICIST", kKeyWriter },
{ "METADATA_BLOCK_PICTURE", kKeyAlbumArt },
+ { "ANDROID_LOOP", kKeyAutoLoop },
};
for (int i = 0; i < mVc.comments; ++i) {
@@ -605,12 +606,15 @@
extractAlbumArt(
&comment[tagLen + 1],
mVc.comment_lengths[i] - tagLen - 1);
+ } else if (kMap[j].mKey == kKeyAutoLoop) {
+ if (!strcasecmp(&comment[tagLen + 1], "true")) {
+ mFileMeta->setInt32(kKeyAutoLoop, true);
+ }
} else {
mFileMeta->setCString(kMap[j].mKey, &comment[tagLen + 1]);
}
}
}
-
}
#if 0
diff --git a/media/libstagefright/codecs/aacenc/AACEncoder.cpp b/media/libstagefright/codecs/aacenc/AACEncoder.cpp
index 052c354..e391c72 100644
--- a/media/libstagefright/codecs/aacenc/AACEncoder.cpp
+++ b/media/libstagefright/codecs/aacenc/AACEncoder.cpp
@@ -208,6 +208,8 @@
MediaBuffer *buffer;
CHECK_EQ(mBufferGroup->acquire_buffer(&buffer), OK);
uint8_t *outPtr = (uint8_t *)buffer->data();
+ bool readFromSource = false;
+ int64_t wallClockTimeUs = -1;
if (mFrameCount == 0) {
memcpy(outPtr, mAudioSpecificConfigData, 2);
@@ -238,9 +240,15 @@
CHECK_EQ(align, 0);
int64_t timeUs;
+ if (mInputBuffer->meta_data()->findInt64(kKeyDriftTime, &timeUs)) {
+ wallClockTimeUs = timeUs;
+ }
if (mInputBuffer->meta_data()->findInt64(kKeyTime, &timeUs)) {
mAnchorTimeUs = timeUs;
}
+ readFromSource = true;
+ } else {
+ readFromSource = false;
}
size_t copy =
(kNumSamplesPerFrame - mNumInputSamples) * sizeof(int16_t);
@@ -288,9 +296,13 @@
CHECK(outputData.Length != 0);
buffer->set_range(0, outputData.Length);
- int64_t timestampUs = ((mFrameCount - 1) * 1000000LL * kNumSamplesPerFrame) / mSampleRate;
+ int64_t mediaTimeUs =
+ ((mFrameCount - 1) * 1000000LL * kNumSamplesPerFrame) / mSampleRate;
+ buffer->meta_data()->setInt64(kKeyTime, mAnchorTimeUs + mediaTimeUs);
+ if (readFromSource && wallClockTimeUs != -1) {
+ buffer->meta_data()->setInt64(kKeyDriftTime, mediaTimeUs - wallClockTimeUs);
+ }
++mFrameCount;
- buffer->meta_data()->setInt64(kKeyTime, timestampUs);
*out = buffer;
return OK;
diff --git a/media/libstagefright/codecs/amrnb/enc/AMRNBEncoder.cpp b/media/libstagefright/codecs/amrnb/enc/AMRNBEncoder.cpp
index c875426..858e6d0 100644
--- a/media/libstagefright/codecs/amrnb/enc/AMRNBEncoder.cpp
+++ b/media/libstagefright/codecs/amrnb/enc/AMRNBEncoder.cpp
@@ -147,6 +147,8 @@
int64_t seekTimeUs;
ReadOptions::SeekMode mode;
CHECK(options == NULL || !options->getSeekTo(&seekTimeUs, &mode));
+ bool readFromSource = false;
+ int64_t wallClockTimeUs = -1;
while (mNumInputSamples < kNumSamplesPerFrame) {
if (mInputBuffer == NULL) {
@@ -166,12 +168,17 @@
size_t align = mInputBuffer->range_length() % sizeof(int16_t);
CHECK_EQ(align, 0);
+ readFromSource = true;
int64_t timeUs;
+ if (mInputBuffer->meta_data()->findInt64(kKeyDriftTime, &timeUs)) {
+ wallClockTimeUs = timeUs;
+ }
if (mInputBuffer->meta_data()->findInt64(kKeyTime, &timeUs)) {
mAnchorTimeUs = timeUs;
- mNumFramesOutput = 0;
}
+ } else {
+ readFromSource = false;
}
size_t copy =
@@ -217,8 +224,14 @@
buffer->set_range(0, res);
// Each frame of 160 samples is 20ms long.
+ int64_t mediaTimeUs = mNumFramesOutput * 20000LL;
buffer->meta_data()->setInt64(
- kKeyTime, mAnchorTimeUs + mNumFramesOutput * 20000);
+ kKeyTime, mAnchorTimeUs + mediaTimeUs);
+
+ if (readFromSource && wallClockTimeUs != -1) {
+ buffer->meta_data()->setInt64(kKeyDriftTime,
+ mediaTimeUs - wallClockTimeUs);
+ }
++mNumFramesOutput;
diff --git a/media/libstagefright/codecs/amrwbenc/AMRWBEncoder.cpp b/media/libstagefright/codecs/amrwbenc/AMRWBEncoder.cpp
index 93304d0..cd28413 100644
--- a/media/libstagefright/codecs/amrwbenc/AMRWBEncoder.cpp
+++ b/media/libstagefright/codecs/amrwbenc/AMRWBEncoder.cpp
@@ -198,6 +198,8 @@
int64_t seekTimeUs;
ReadOptions::SeekMode mode;
CHECK(options == NULL || !options->getSeekTo(&seekTimeUs, &mode));
+ bool readFromSource = false;
+ int64_t wallClockTimeUs = -1;
while (mNumInputSamples < kNumSamplesPerFrame) {
if (mInputBuffer == NULL) {
@@ -219,9 +221,15 @@
CHECK_EQ(align, 0);
int64_t timeUs;
+ if (mInputBuffer->meta_data()->findInt64(kKeyDriftTime, &timeUs)) {
+ wallClockTimeUs = timeUs;
+ }
if (mInputBuffer->meta_data()->findInt64(kKeyTime, &timeUs)) {
mAnchorTimeUs = timeUs;
}
+ readFromSource = true;
+ } else {
+ readFromSource = false;
}
size_t copy =
@@ -276,10 +284,11 @@
buffer->set_range(0, outputData.Length);
++mNumFramesOutput;
- // XXX: fix timestamp calculation
- int64_t timestampUs = mNumFramesOutput * 20000LL;
-
- buffer->meta_data()->setInt64(kKeyTime, timestampUs);
+ int64_t mediaTimeUs = mNumFramesOutput * 20000LL;
+ buffer->meta_data()->setInt64(kKeyTime, mAnchorTimeUs + mediaTimeUs);
+ if (readFromSource && wallClockTimeUs != -1) {
+ buffer->meta_data()->setInt64(kKeyDriftTime, mediaTimeUs - wallClockTimeUs);
+ }
*out = buffer;
return OK;
diff --git a/media/libstagefright/include/ARTSPController.h b/media/libstagefright/include/ARTSPController.h
index 7016880..300d8f7 100644
--- a/media/libstagefright/include/ARTSPController.h
+++ b/media/libstagefright/include/ARTSPController.h
@@ -42,6 +42,7 @@
size_t index, uint32_t flags);
int64_t getNormalPlayTimeUs();
+ int64_t getQueueDurationUs(bool *eos);
void onMessageReceived(const sp<AMessage> &msg);
diff --git a/media/libstagefright/include/AwesomePlayer.h b/media/libstagefright/include/AwesomePlayer.h
index f34eb45..ea2f7d5 100644
--- a/media/libstagefright/include/AwesomePlayer.h
+++ b/media/libstagefright/include/AwesomePlayer.h
@@ -107,6 +107,7 @@
CACHE_UNDERRUN = 128,
AUDIO_AT_EOS = 256,
VIDEO_AT_EOS = 512,
+ AUTO_LOOPING = 1024,
};
mutable Mutex mLock;
@@ -241,6 +242,9 @@
void onCheckAudioStatus();
void onPrepareAsyncEvent();
void abortPrepare(status_t err);
+ void finishAsyncPrepare_l();
+
+ bool getCachedDuration_l(int64_t *durationUs, bool *eos);
status_t finishSetDataSource_l();
diff --git a/media/libstagefright/include/OMX.h b/media/libstagefright/include/OMX.h
index c99da59..83b75ad 100644
--- a/media/libstagefright/include/OMX.h
+++ b/media/libstagefright/include/OMX.h
@@ -59,10 +59,17 @@
node_id node, OMX_INDEXTYPE index,
const void *params, size_t size);
+ virtual status_t enableGraphicBuffers(
+ node_id node, OMX_U32 port_index, OMX_BOOL enable);
+
virtual status_t useBuffer(
node_id node, OMX_U32 port_index, const sp<IMemory> ¶ms,
buffer_id *buffer);
+ virtual status_t useGraphicBuffer(
+ node_id node, OMX_U32 port_index,
+ const sp<GraphicBuffer> &graphicBuffer, buffer_id *buffer);
+
virtual status_t allocateBuffer(
node_id node, OMX_U32 port_index, size_t size,
buffer_id *buffer, void **buffer_data);
diff --git a/media/libstagefright/include/OMXNodeInstance.h b/media/libstagefright/include/OMXNodeInstance.h
index b5b31ac..8c7c562 100644
--- a/media/libstagefright/include/OMXNodeInstance.h
+++ b/media/libstagefright/include/OMXNodeInstance.h
@@ -49,10 +49,16 @@
status_t getConfig(OMX_INDEXTYPE index, void *params, size_t size);
status_t setConfig(OMX_INDEXTYPE index, const void *params, size_t size);
+ status_t enableGraphicBuffers(OMX_U32 portIndex, OMX_BOOL enable);
+
status_t useBuffer(
OMX_U32 portIndex, const sp<IMemory> ¶ms,
OMX::buffer_id *buffer);
+ status_t useGraphicBuffer(
+ OMX_U32 portIndex, const sp<GraphicBuffer> &graphicBuffer,
+ OMX::buffer_id *buffer);
+
status_t allocateBuffer(
OMX_U32 portIndex, size_t size, OMX::buffer_id *buffer,
void **buffer_data);
@@ -125,4 +131,3 @@
} // namespace android
#endif // OMX_NODE_INSTANCE_H_
-
diff --git a/media/libstagefright/mpeg2ts/ATSParser.cpp b/media/libstagefright/mpeg2ts/ATSParser.cpp
index 26a0fb3..72de8d7 100644
--- a/media/libstagefright/mpeg2ts/ATSParser.cpp
+++ b/media/libstagefright/mpeg2ts/ATSParser.cpp
@@ -78,6 +78,8 @@
unsigned PTS_DTS_flags, uint64_t PTS, uint64_t DTS,
const uint8_t *data, size_t size);
+ void extractAACFrames(const sp<ABuffer> &buffer);
+
DISALLOW_EVIL_CONSTRUCTORS(Stream);
};
@@ -226,7 +228,7 @@
ATSParser::Stream::Stream(unsigned elementaryPID, unsigned streamType)
: mElementaryPID(elementaryPID),
mStreamType(streamType),
- mBuffer(new ABuffer(65536)),
+ mBuffer(new ABuffer(128 * 1024)),
mPayloadStarted(false) {
mBuffer->setRange(0, 0);
}
@@ -662,7 +664,7 @@
csd->data()[sizeof(kStaticESDS) + 1] =
((sampling_freq_index << 7) & 0x80) | (channel_configuration << 3);
- hexdump(csd->data(), csd->size());
+ // hexdump(csd->data(), csd->size());
return csd;
}
@@ -727,13 +729,76 @@
buffer->meta()->setInt64("time", (PTS * 100) / 9);
if (mStreamType == 0x0f) {
- // WHY???
- buffer->setRange(7, buffer->size() - 7);
+ extractAACFrames(buffer);
}
mSource->queueAccessUnit(buffer);
}
+// Disassemble one or more ADTS frames into their constituent parts and
+// leave only the concatenated raw_data_blocks in the buffer.
+void ATSParser::Stream::extractAACFrames(const sp<ABuffer> &buffer) {
+ size_t dstOffset = 0;
+
+ size_t offset = 0;
+ while (offset < buffer->size()) {
+ CHECK_LE(offset + 7, buffer->size());
+
+ ABitReader bits(buffer->data() + offset, buffer->size() - offset);
+
+ // adts_fixed_header
+
+ CHECK_EQ(bits.getBits(12), 0xfffu);
+ bits.skipBits(3); // ID, layer
+ bool protection_absent = bits.getBits(1) != 0;
+
+ // profile_ObjectType, sampling_frequency_index, private_bits,
+ // channel_configuration, original_copy, home
+ bits.skipBits(12);
+
+ // adts_variable_header
+
+ // copyright_identification_bit, copyright_identification_start
+ bits.skipBits(2);
+
+ unsigned aac_frame_length = bits.getBits(13);
+
+ bits.skipBits(11); // adts_buffer_fullness
+
+ unsigned number_of_raw_data_blocks_in_frame = bits.getBits(2);
+
+ if (number_of_raw_data_blocks_in_frame == 0) {
+ size_t scan = offset + aac_frame_length;
+
+ offset += 7;
+ if (!protection_absent) {
+ offset += 2;
+ }
+
+ CHECK_LE(scan, buffer->size());
+
+ LOG(VERBOSE)
+ << "found aac raw data block at ["
+ << StringPrintf("0x%08x", offset)
+ << " ; "
+ << StringPrintf("0x%08x", scan)
+ << ")";
+
+ memmove(&buffer->data()[dstOffset], &buffer->data()[offset],
+ scan - offset);
+
+ dstOffset += scan - offset;
+ offset = scan;
+ } else {
+ // To be implemented.
+ TRESPASS();
+ }
+ }
+ CHECK_EQ(offset, buffer->size());
+
+ buffer->setRange(buffer->offset(), dstOffset);
+}
+
sp<MediaSource> ATSParser::Stream::getSource(SourceType type) {
if ((type == AVC_VIDEO && mStreamType == 0x1b)
|| (type == MPEG2ADTS_AUDIO && mStreamType == 0x0f)) {
diff --git a/media/libstagefright/omx/OMX.cpp b/media/libstagefright/omx/OMX.cpp
index 88b9605..37243ad 100644
--- a/media/libstagefright/omx/OMX.cpp
+++ b/media/libstagefright/omx/OMX.cpp
@@ -287,6 +287,11 @@
index, params, size);
}
+status_t OMX::enableGraphicBuffers(
+ node_id node, OMX_U32 port_index, OMX_BOOL enable) {
+ return findInstance(node)->enableGraphicBuffers(port_index, enable);
+}
+
status_t OMX::useBuffer(
node_id node, OMX_U32 port_index, const sp<IMemory> ¶ms,
buffer_id *buffer) {
@@ -294,6 +299,13 @@
port_index, params, buffer);
}
+status_t OMX::useGraphicBuffer(
+ node_id node, OMX_U32 port_index,
+ const sp<GraphicBuffer> &graphicBuffer, buffer_id *buffer) {
+ return findInstance(node)->useGraphicBuffer(
+ port_index, graphicBuffer, buffer);
+}
+
status_t OMX::allocateBuffer(
node_id node, OMX_U32 port_index, size_t size,
buffer_id *buffer, void **buffer_data) {
@@ -530,4 +542,3 @@
}
} // namespace android
-
diff --git a/media/libstagefright/omx/OMXNodeInstance.cpp b/media/libstagefright/omx/OMXNodeInstance.cpp
index 5db516e..ba4d765 100644
--- a/media/libstagefright/omx/OMXNodeInstance.cpp
+++ b/media/libstagefright/omx/OMXNodeInstance.cpp
@@ -24,6 +24,7 @@
#include <OMX_Component.h>
#include <binder/IMemory.h>
+#include <media/stagefright/HardwareAPI.h>
#include <media/stagefright/MediaDebug.h>
#include <media/stagefright/MediaErrors.h>
@@ -40,6 +41,11 @@
mIsBackup(false) {
}
+ BufferMeta(const sp<GraphicBuffer> &graphicBuffer)
+ : mGraphicBuffer(graphicBuffer),
+ mIsBackup(false) {
+ }
+
void CopyFromOMX(const OMX_BUFFERHEADERTYPE *header) {
if (!mIsBackup) {
return;
@@ -61,6 +67,7 @@
}
private:
+ sp<GraphicBuffer> mGraphicBuffer;
sp<IMemory> mMem;
size_t mSize;
bool mIsBackup;
@@ -240,6 +247,43 @@
return StatusFromOMXError(err);
}
+status_t OMXNodeInstance::enableGraphicBuffers(
+ OMX_U32 portIndex, OMX_BOOL enable) {
+ Mutex::Autolock autoLock(mLock);
+
+ OMX_INDEXTYPE index;
+ OMX_ERRORTYPE err = OMX_GetExtensionIndex(
+ mHandle,
+ const_cast<OMX_STRING>("OMX.google.android.index.enableAndroidNativeBuffers"),
+ &index);
+
+ if (err != OMX_ErrorNone) {
+ LOGE("OMX_GetExtensionIndex failed");
+
+ return StatusFromOMXError(err);
+ }
+
+ OMX_VERSIONTYPE ver;
+ ver.s.nVersionMajor = 1;
+ ver.s.nVersionMinor = 0;
+ ver.s.nRevision = 0;
+ ver.s.nStep = 0;
+ EnableAndroidNativeBuffersParams params = {
+ sizeof(EnableAndroidNativeBuffersParams), ver, portIndex, enable,
+ };
+
+ err = OMX_SetParameter(mHandle, index, ¶ms);
+
+ if (err != OMX_ErrorNone) {
+ LOGE("OMX_EnableAndroidNativeBuffers failed with error %d (0x%08x)",
+ err, err);
+
+ return UNKNOWN_ERROR;
+ }
+
+ return OK;
+}
+
status_t OMXNodeInstance::useBuffer(
OMX_U32 portIndex, const sp<IMemory> ¶ms,
OMX::buffer_id *buffer) {
@@ -273,6 +317,60 @@
return OK;
}
+status_t OMXNodeInstance::useGraphicBuffer(
+ OMX_U32 portIndex, const sp<GraphicBuffer>& graphicBuffer,
+ OMX::buffer_id *buffer) {
+ Mutex::Autolock autoLock(mLock);
+
+ OMX_INDEXTYPE index;
+ OMX_ERRORTYPE err = OMX_GetExtensionIndex(
+ mHandle,
+ const_cast<OMX_STRING>("OMX.google.android.index.useAndroidNativeBuffer"),
+ &index);
+
+ if (err != OMX_ErrorNone) {
+ LOGE("OMX_GetExtensionIndex failed");
+
+ return StatusFromOMXError(err);
+ }
+
+ BufferMeta *bufferMeta = new BufferMeta(graphicBuffer);
+
+ OMX_BUFFERHEADERTYPE *header;
+
+ OMX_VERSIONTYPE ver;
+ ver.s.nVersionMajor = 1;
+ ver.s.nVersionMinor = 0;
+ ver.s.nRevision = 0;
+ ver.s.nStep = 0;
+ UseAndroidNativeBufferParams params = {
+ sizeof(UseAndroidNativeBufferParams), ver, portIndex, bufferMeta,
+ &header, graphicBuffer,
+ };
+
+ err = OMX_SetParameter(mHandle, index, ¶ms);
+
+ if (err != OMX_ErrorNone) {
+ LOGE("OMX_UseAndroidNativeBuffer failed with error %d (0x%08x)", err,
+ err);
+
+ delete bufferMeta;
+ bufferMeta = NULL;
+
+ *buffer = 0;
+
+ return UNKNOWN_ERROR;
+ }
+
+ CHECK_EQ(header->pAppPrivate, bufferMeta);
+
+ *buffer = header;
+
+ addActiveBuffer(portIndex, *buffer);
+
+ return OK;
+}
+
status_t OMXNodeInstance::allocateBuffer(
OMX_U32 portIndex, size_t size, OMX::buffer_id *buffer,
void **buffer_data) {
@@ -498,4 +596,3 @@
}
} // namespace android
-
diff --git a/media/libstagefright/rtsp/AMPEG4ElementaryAssembler.cpp b/media/libstagefright/rtsp/AMPEG4ElementaryAssembler.cpp
index 7dd3e3f..f68a35b 100644
--- a/media/libstagefright/rtsp/AMPEG4ElementaryAssembler.cpp
+++ b/media/libstagefright/rtsp/AMPEG4ElementaryAssembler.cpp
@@ -18,29 +18,160 @@
#include "ARTPSource.h"
+#include <media/stagefright/foundation/ABitReader.h>
#include <media/stagefright/foundation/ABuffer.h>
#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/foundation/AMessage.h>
#include <media/stagefright/foundation/hexdump.h>
+#include <media/stagefright/Utils.h>
+#include <ctype.h>
#include <stdint.h>
#define BE_VERBOSE 0
namespace android {
+static bool GetAttribute(const char *s, const char *key, AString *value) {
+ value->clear();
+
+ size_t keyLen = strlen(key);
+
+ for (;;) {
+ while (isspace(*s)) {
+ ++s;
+ }
+
+ const char *colonPos = strchr(s, ';');
+
+ size_t len =
+ (colonPos == NULL) ? strlen(s) : colonPos - s;
+
+ if (len >= keyLen + 1 && s[keyLen] == '='
+ && !strncasecmp(s, key, keyLen)) {
+ value->setTo(&s[keyLen + 1], len - keyLen - 1);
+ return true;
+ }
+
+ if (colonPos == NULL) {
+ return false;
+ }
+
+ s = colonPos + 1;
+ }
+}
+
+static bool GetIntegerAttribute(
+ const char *s, const char *key, unsigned *x) {
+ *x = 0;
+
+ AString val;
+ if (!GetAttribute(s, key, &val)) {
+ return false;
+ }
+
+ s = val.c_str();
+ char *end;
+ unsigned y = strtoul(s, &end, 10);
+
+ if (end == s || *end != '\0') {
+ return false;
+ }
+
+ *x = y;
+
+ return true;
+}
+
// static
-AMPEG4ElementaryAssembler::AMPEG4ElementaryAssembler(const sp<AMessage> ¬ify)
+AMPEG4ElementaryAssembler::AMPEG4ElementaryAssembler(
+ const sp<AMessage> ¬ify, const AString &desc, const AString ¶ms)
: mNotifyMsg(notify),
+ mIsGeneric(false),
+ mParams(params),
+ mSizeLength(0),
+ mIndexLength(0),
+ mIndexDeltaLength(0),
+ mCTSDeltaLength(0),
+ mDTSDeltaLength(0),
+ mRandomAccessIndication(false),
+ mStreamStateIndication(0),
+ mAuxiliaryDataSizeLength(0),
+ mHasAUHeader(false),
mAccessUnitRTPTime(0),
mNextExpectedSeqNoValid(false),
mNextExpectedSeqNo(0),
mAccessUnitDamaged(false) {
+ mIsGeneric = desc.startsWith("mpeg4-generic/");
+
+ if (mIsGeneric) {
+ AString value;
+ CHECK(GetAttribute(params.c_str(), "mode", &value));
+
+ if (!GetIntegerAttribute(params.c_str(), "sizeLength", &mSizeLength)) {
+ mSizeLength = 0;
+ }
+
+ if (!GetIntegerAttribute(
+ params.c_str(), "indexLength", &mIndexLength)) {
+ mIndexLength = 0;
+ }
+
+ if (!GetIntegerAttribute(
+ params.c_str(), "indexDeltaLength", &mIndexDeltaLength)) {
+ mIndexDeltaLength = 0;
+ }
+
+ if (!GetIntegerAttribute(
+ params.c_str(), "CTSDeltaLength", &mCTSDeltaLength)) {
+ mCTSDeltaLength = 0;
+ }
+
+ if (!GetIntegerAttribute(
+ params.c_str(), "DTSDeltaLength", &mDTSDeltaLength)) {
+ mDTSDeltaLength = 0;
+ }
+
+ unsigned x;
+ if (!GetIntegerAttribute(
+ params.c_str(), "randomAccessIndication", &x)) {
+ mRandomAccessIndication = false;
+ } else {
+ CHECK(x == 0 || x == 1);
+ mRandomAccessIndication = (x != 0);
+ }
+
+ if (!GetIntegerAttribute(
+ params.c_str(), "streamStateIndication",
+ &mStreamStateIndication)) {
+ mStreamStateIndication = 0;
+ }
+
+ if (!GetIntegerAttribute(
+ params.c_str(), "auxiliaryDataSizeLength",
+ &mAuxiliaryDataSizeLength)) {
+ mAuxiliaryDataSizeLength = 0;
+ }
+
+ mHasAUHeader =
+ mSizeLength > 0
+ || mIndexLength > 0
+ || mIndexDeltaLength > 0
+ || mCTSDeltaLength > 0
+ || mDTSDeltaLength > 0
+ || mRandomAccessIndication
+ || mStreamStateIndication > 0;
+ }
}
AMPEG4ElementaryAssembler::~AMPEG4ElementaryAssembler() {
}
+struct AUHeader {
+ unsigned mSize;
+ unsigned mSerial;
+};
+
ARTPAssembler::AssemblyStatus AMPEG4ElementaryAssembler::addPacket(
const sp<ARTPSource> &source) {
List<sp<ABuffer> > *queue = source->queue();
@@ -85,8 +216,116 @@
}
mAccessUnitRTPTime = rtpTime;
- mPackets.push_back(buffer);
- // hexdump(buffer->data(), buffer->size());
+ if (!mIsGeneric) {
+ mPackets.push_back(buffer);
+ } else {
+ // hexdump(buffer->data(), buffer->size());
+
+ CHECK_GE(buffer->size(), 2u);
+ unsigned AU_headers_length = U16_AT(buffer->data()); // in bits
+
+ CHECK_GE(buffer->size(), 2 + (AU_headers_length + 7) / 8);
+
+ List<AUHeader> headers;
+
+ ABitReader bits(buffer->data() + 2, buffer->size() - 2);
+ unsigned numBitsLeft = AU_headers_length;
+
+ unsigned AU_serial = 0;
+ for (;;) {
+ if (numBitsLeft < mSizeLength) { break; }
+
+ unsigned AU_size = bits.getBits(mSizeLength);
+ numBitsLeft -= mSizeLength;
+
+ size_t n = headers.empty() ? mIndexLength : mIndexDeltaLength;
+ if (numBitsLeft < n) { break; }
+
+ unsigned AU_index = bits.getBits(n);
+ numBitsLeft -= n;
+
+ if (headers.empty()) {
+ AU_serial = AU_index;
+ } else {
+ AU_serial += 1 + AU_index;
+ }
+
+ if (mCTSDeltaLength > 0) {
+ if (numBitsLeft < 1) {
+ break;
+ }
+ --numBitsLeft;
+ if (bits.getBits(1)) {
+ if (numBitsLeft < mCTSDeltaLength) {
+ break;
+ }
+ bits.skipBits(mCTSDeltaLength);
+ numBitsLeft -= mCTSDeltaLength;
+ }
+ }
+
+ if (mDTSDeltaLength > 0) {
+ if (numBitsLeft < 1) {
+ break;
+ }
+ --numBitsLeft;
+ if (bits.getBits(1)) {
+ if (numBitsLeft < mDTSDeltaLength) {
+ break;
+ }
+ bits.skipBits(mDTSDeltaLength);
+ numBitsLeft -= mDTSDeltaLength;
+ }
+ }
+
+ if (mRandomAccessIndication) {
+ if (numBitsLeft < 1) {
+ break;
+ }
+ bits.skipBits(1);
+ --numBitsLeft;
+ }
+
+ if (mStreamStateIndication > 0) {
+ if (numBitsLeft < mStreamStateIndication) {
+ break;
+ }
+ bits.skipBits(mStreamStateIndication);
+ }
+
+ AUHeader header;
+ header.mSize = AU_size;
+ header.mSerial = AU_serial;
+ headers.push_back(header);
+ }
+
+ size_t offset = 2 + (AU_headers_length + 7) / 8;
+
+ if (mAuxiliaryDataSizeLength > 0) {
+ ABitReader bits(buffer->data() + offset, buffer->size() - offset);
+
+ unsigned auxSize = bits.getBits(mAuxiliaryDataSizeLength);
+
+ offset += (mAuxiliaryDataSizeLength + auxSize + 7) / 8;
+ }
+
+ for (List<AUHeader>::iterator it = headers.begin();
+ it != headers.end(); ++it) {
+ const AUHeader &header = *it;
+
+ CHECK_LE(offset + header.mSize, buffer->size());
+
+ sp<ABuffer> accessUnit = new ABuffer(header.mSize);
+ memcpy(accessUnit->data(), buffer->data() + offset, header.mSize);
+
+ offset += header.mSize;
+
+ CopyTimes(accessUnit, buffer);
+ mPackets.push_back(accessUnit);
+ }
+
+ CHECK_EQ(offset, buffer->size());
+ }
queue->erase(queue->begin());
++mNextExpectedSeqNo;
diff --git a/media/libstagefright/rtsp/AMPEG4ElementaryAssembler.h b/media/libstagefright/rtsp/AMPEG4ElementaryAssembler.h
index 1566d00..794bbcc 100644
--- a/media/libstagefright/rtsp/AMPEG4ElementaryAssembler.h
+++ b/media/libstagefright/rtsp/AMPEG4ElementaryAssembler.h
@@ -20,6 +20,8 @@
#include "ARTPAssembler.h"
+#include <media/stagefright/foundation/AString.h>
+
#include <utils/List.h>
#include <utils/RefBase.h>
@@ -29,7 +31,9 @@
struct AMessage;
struct AMPEG4ElementaryAssembler : public ARTPAssembler {
- AMPEG4ElementaryAssembler(const sp<AMessage> ¬ify);
+ AMPEG4ElementaryAssembler(
+ const sp<AMessage> ¬ify, const AString &desc,
+ const AString ¶ms);
protected:
virtual ~AMPEG4ElementaryAssembler();
@@ -40,6 +44,18 @@
private:
sp<AMessage> mNotifyMsg;
+ bool mIsGeneric;
+ AString mParams;
+
+ unsigned mSizeLength;
+ unsigned mIndexLength;
+ unsigned mIndexDeltaLength;
+ unsigned mCTSDeltaLength;
+ unsigned mDTSDeltaLength;
+ bool mRandomAccessIndication;
+ unsigned mStreamStateIndication;
+ unsigned mAuxiliaryDataSizeLength;
+ bool mHasAUHeader;
uint32_t mAccessUnitRTPTime;
bool mNextExpectedSeqNoValid;
diff --git a/media/libstagefright/rtsp/APacketSource.cpp b/media/libstagefright/rtsp/APacketSource.cpp
index 2d7738b..b63798f 100644
--- a/media/libstagefright/rtsp/APacketSource.cpp
+++ b/media/libstagefright/rtsp/APacketSource.cpp
@@ -247,6 +247,65 @@
return csd;
}
+// From mpeg4-generic configuration data.
+sp<ABuffer> MakeAACCodecSpecificData2(const char *params) {
+ AString val;
+ unsigned long objectType;
+ if (GetAttribute(params, "objectType", &val)) {
+ const char *s = val.c_str();
+ char *end;
+ objectType = strtoul(s, &end, 10);
+ CHECK(end > s && *end == '\0');
+ } else {
+ objectType = 0x40; // Audio ISO/IEC 14496-3
+ }
+
+ CHECK(GetAttribute(params, "config", &val));
+
+ sp<ABuffer> config = decodeHex(val);
+ CHECK(config != NULL);
+
+ // Make sure size fits into a single byte and doesn't have to
+ // be encoded.
+ CHECK_LT(20 + config->size(), 128u);
+
+ const uint8_t *data = config->data();
+
+ static const uint8_t kStaticESDS[] = {
+ 0x03, 22,
+ 0x00, 0x00, // ES_ID
+ 0x00, // streamDependenceFlag, URL_Flag, OCRstreamFlag
+
+ 0x04, 17,
+ 0x40, // Audio ISO/IEC 14496-3
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+
+ 0x05, 2,
+ // AudioSpecificInfo follows
+ };
+
+ sp<ABuffer> csd = new ABuffer(sizeof(kStaticESDS) + config->size());
+ uint8_t *dst = csd->data();
+ *dst++ = 0x03;
+ *dst++ = 20 + config->size();
+ *dst++ = 0x00; // ES_ID
+ *dst++ = 0x00;
+ *dst++ = 0x00; // streamDependenceFlag, URL_Flag, OCRstreamFlag
+ *dst++ = 0x04;
+ *dst++ = 15 + config->size();
+ *dst++ = objectType;
+ for (int i = 0; i < 12; ++i) { *dst++ = 0x00; }
+ *dst++ = 0x05;
+ *dst++ = config->size();
+ memcpy(dst, config->data(), config->size());
+
+ // hexdump(csd->data(), csd->size());
+
+ return csd;
+}
+
static size_t GetSizeWidth(size_t x) {
size_t n = 1;
while (x > 127) {
@@ -560,6 +619,30 @@
mFormat->setInt32(kKeyWidth, width);
mFormat->setInt32(kKeyHeight, height);
+ } else if (!strncmp(desc.c_str(), "mpeg4-generic/", 14)) {
+ AString val;
+ if (!GetAttribute(params.c_str(), "mode", &val)
+ || (strcasecmp(val.c_str(), "AAC-lbr")
+ && strcasecmp(val.c_str(), "AAC-hbr"))) {
+ mInitCheck = ERROR_UNSUPPORTED;
+ return;
+ }
+
+ mFormat->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_AAC);
+
+ int32_t sampleRate, numChannels;
+ ASessionDescription::ParseFormatDesc(
+ desc.c_str(), &sampleRate, &numChannels);
+
+ mFormat->setInt32(kKeySampleRate, sampleRate);
+ mFormat->setInt32(kKeyChannelCount, numChannels);
+
+ sp<ABuffer> codecSpecificData =
+ MakeAACCodecSpecificData2(params.c_str());
+
+ mFormat->setData(
+ kKeyESDS, 0,
+ codecSpecificData->data(), codecSpecificData->size());
} else {
mInitCheck = ERROR_UNSUPPORTED;
}
@@ -663,4 +746,27 @@
mNormalPlayTimeBaseUs = normalPlayTimeUs;
}
+int64_t APacketSource::getQueueDurationUs(bool *eos) {
+ Mutex::Autolock autoLock(mLock);
+
+ *eos = (mEOSResult != OK);
+
+ if (mBuffers.size() < 2) {
+ return 0;
+ }
+
+ const sp<ABuffer> first = *mBuffers.begin();
+ const sp<ABuffer> last = *--mBuffers.end();
+
+ int64_t firstTimeUs;
+ CHECK(first->meta()->findInt64("timeUs", &firstTimeUs));
+
+ int64_t lastTimeUs;
+ CHECK(last->meta()->findInt64("timeUs", &lastTimeUs));
+
+ CHECK_GE(lastTimeUs, firstTimeUs);
+
+ return lastTimeUs - firstTimeUs;
+}
+
} // namespace android
diff --git a/media/libstagefright/rtsp/APacketSource.h b/media/libstagefright/rtsp/APacketSource.h
index 3833ab1..076ddc4 100644
--- a/media/libstagefright/rtsp/APacketSource.h
+++ b/media/libstagefright/rtsp/APacketSource.h
@@ -50,6 +50,8 @@
void setNormalPlayTimeMapping(
uint32_t rtpTime, int64_t normalPlayTimeUs);
+ int64_t getQueueDurationUs(bool *eos);
+
protected:
virtual ~APacketSource();
diff --git a/media/libstagefright/rtsp/ARTPConnection.cpp b/media/libstagefright/rtsp/ARTPConnection.cpp
index 12f8f32..10c9e02 100644
--- a/media/libstagefright/rtsp/ARTPConnection.cpp
+++ b/media/libstagefright/rtsp/ARTPConnection.cpp
@@ -362,7 +362,6 @@
if (receiveRTP) {
err = parseRTP(s, buffer);
} else {
- ++s->mNumRTCPPacketsReceived;
err = parseRTCP(s, buffer);
}
@@ -456,6 +455,12 @@
}
status_t ARTPConnection::parseRTCP(StreamInfo *s, const sp<ABuffer> &buffer) {
+ if (s->mNumRTCPPacketsReceived++ == 0) {
+ sp<AMessage> notify = s->mNotifyMsg->dup();
+ notify->setInt32("first-rtcp", true);
+ notify->post();
+ }
+
const uint8_t *data = buffer->data();
size_t size = buffer->size();
@@ -626,7 +631,6 @@
if (it->mRTPSocket == index) {
err = parseRTP(s, buffer);
} else {
- ++s->mNumRTCPPacketsReceived;
err = parseRTCP(s, buffer);
}
}
diff --git a/media/libstagefright/rtsp/ARTPSession.cpp b/media/libstagefright/rtsp/ARTPSession.cpp
index f60c1a9..8ce93b7 100644
--- a/media/libstagefright/rtsp/ARTPSession.cpp
+++ b/media/libstagefright/rtsp/ARTPSession.cpp
@@ -125,6 +125,14 @@
switch (msg->what()) {
case kWhatAccessUnitComplete:
{
+ int32_t firstRTCP;
+ if (msg->findInt32("first-rtcp", &firstRTCP)) {
+ // There won't be an access unit here, it's just a notification
+ // that the data communication worked since we got the first
+ // rtcp packet.
+ break;
+ }
+
size_t trackIndex;
CHECK(msg->findSize("track-index", &trackIndex));
diff --git a/media/libstagefright/rtsp/ARTPSource.cpp b/media/libstagefright/rtsp/ARTPSource.cpp
index 775c4ee..9656ba2 100644
--- a/media/libstagefright/rtsp/ARTPSource.cpp
+++ b/media/libstagefright/rtsp/ARTPSource.cpp
@@ -64,8 +64,9 @@
mAssembler = new AAMRAssembler(notify, false /* isWide */, params);
} else if (!strncmp(desc.c_str(), "AMR-WB/", 7)) {
mAssembler = new AAMRAssembler(notify, true /* isWide */, params);
- } else if (!strncmp(desc.c_str(), "MP4V-ES/", 8)) {
- mAssembler = new AMPEG4ElementaryAssembler(notify);
+ } else if (!strncmp(desc.c_str(), "MP4V-ES/", 8)
+ || !strncmp(desc.c_str(), "mpeg4-generic/", 14)) {
+ mAssembler = new AMPEG4ElementaryAssembler(notify, desc, params);
mIssueFIRRequests = true;
} else {
TRESPASS();
diff --git a/media/libstagefright/rtsp/ARTSPController.cpp b/media/libstagefright/rtsp/ARTSPController.cpp
index a89946b..4c53639 100644
--- a/media/libstagefright/rtsp/ARTSPController.cpp
+++ b/media/libstagefright/rtsp/ARTSPController.cpp
@@ -143,4 +143,26 @@
return mHandler->getNormalPlayTimeUs();
}
+int64_t ARTSPController::getQueueDurationUs(bool *eos) {
+ *eos = true;
+
+ int64_t minQueuedDurationUs = 0;
+ for (size_t i = 0; i < mHandler->countTracks(); ++i) {
+ sp<APacketSource> source = mHandler->getPacketSource(i);
+
+ bool newEOS;
+ int64_t queuedDurationUs = source->getQueueDurationUs(&newEOS);
+
+ if (!newEOS) {
+ *eos = false;
+ }
+
+ if (i == 0 || queuedDurationUs < minQueuedDurationUs) {
+ minQueuedDurationUs = queuedDurationUs;
+ }
+ }
+
+ return minQueuedDurationUs;
+}
+
} // namespace android
diff --git a/media/libstagefright/rtsp/MyHandler.h b/media/libstagefright/rtsp/MyHandler.h
index 3d8d86b..0aefd58 100644
--- a/media/libstagefright/rtsp/MyHandler.h
+++ b/media/libstagefright/rtsp/MyHandler.h
@@ -82,7 +82,8 @@
mFirstAccessUnitNTP(0),
mNumAccessUnitsReceived(0),
mCheckPending(false),
- mTryTCPInterleaving(false) {
+ mTryTCPInterleaving(false),
+ mReceivedFirstRTCPPacket(false) {
mNetLooper->setName("rtsp net");
mNetLooper->start(false /* runOnCallingThread */,
false /* canCallJava */,
@@ -199,31 +200,35 @@
break;
}
- CHECK_EQ(response->mStatusCode, 200u);
-
- mSessionDesc = new ASessionDescription;
-
- mSessionDesc->setTo(
- response->mContent->data(),
- response->mContent->size());
-
- CHECK(mSessionDesc->isValid());
-
- ssize_t i = response->mHeaders.indexOfKey("content-base");
- if (i >= 0) {
- mBaseURL = response->mHeaders.valueAt(i);
+ if (response->mStatusCode != 200) {
+ result = UNKNOWN_ERROR;
} else {
- i = response->mHeaders.indexOfKey("content-location");
+ mSessionDesc = new ASessionDescription;
+
+ mSessionDesc->setTo(
+ response->mContent->data(),
+ response->mContent->size());
+
+ CHECK(mSessionDesc->isValid());
+
+ ssize_t i = response->mHeaders.indexOfKey("content-base");
if (i >= 0) {
mBaseURL = response->mHeaders.valueAt(i);
} else {
- mBaseURL = mSessionURL;
+ i = response->mHeaders.indexOfKey("content-location");
+ if (i >= 0) {
+ mBaseURL = response->mHeaders.valueAt(i);
+ } else {
+ mBaseURL = mSessionURL;
+ }
}
- }
- CHECK_GT(mSessionDesc->countTracks(), 1u);
- setupTrack(1);
- } else {
+ CHECK_GT(mSessionDesc->countTracks(), 1u);
+ setupTrack(1);
+ }
+ }
+
+ if (result != OK) {
sp<AMessage> reply = new AMessage('disc', id());
mConn->disconnect(reply);
}
@@ -247,6 +252,39 @@
LOG(INFO) << "SETUP(" << index << ") completed with result "
<< result << " (" << strerror(-result) << ")";
+ if (result == OK) {
+ CHECK(track != NULL);
+
+ sp<RefBase> obj;
+ CHECK(msg->findObject("response", &obj));
+ sp<ARTSPResponse> response =
+ static_cast<ARTSPResponse *>(obj.get());
+
+ if (response->mStatusCode != 200) {
+ result = UNKNOWN_ERROR;
+ } else {
+ ssize_t i = response->mHeaders.indexOfKey("session");
+ CHECK_GE(i, 0);
+
+ mSessionID = response->mHeaders.valueAt(i);
+ i = mSessionID.find(";");
+ if (i >= 0) {
+ // Remove options, i.e. ";timeout=90"
+ mSessionID.erase(i, mSessionID.size() - i);
+ }
+
+ sp<AMessage> notify = new AMessage('accu', id());
+ notify->setSize("track-index", trackIndex);
+
+ mRTPConn->addStream(
+ track->mRTPSocket, track->mRTCPSocket,
+ mSessionDesc, index,
+ notify, track->mUsingInterleavedTCP);
+
+ mSetupTracksSuccessful = true;
+ }
+ }
+
if (result != OK) {
if (track) {
if (!track->mUsingInterleavedTCP) {
@@ -256,37 +294,6 @@
mTracks.removeItemsAt(trackIndex);
}
- } else {
- CHECK(track != NULL);
-
- sp<RefBase> obj;
- CHECK(msg->findObject("response", &obj));
- sp<ARTSPResponse> response =
- static_cast<ARTSPResponse *>(obj.get());
-
- CHECK_EQ(response->mStatusCode, 200u);
-
- ssize_t i = response->mHeaders.indexOfKey("session");
- CHECK_GE(i, 0);
-
- if (index == 1) {
- mSessionID = response->mHeaders.valueAt(i);
- i = mSessionID.find(";");
- if (i >= 0) {
- // Remove options, i.e. ";timeout=90"
- mSessionID.erase(i, mSessionID.size() - i);
- }
- }
-
- sp<AMessage> notify = new AMessage('accu', id());
- notify->setSize("track-index", trackIndex);
-
- mRTPConn->addStream(
- track->mRTPSocket, track->mRTCPSocket,
- mSessionDesc, index,
- notify, track->mUsingInterleavedTCP);
-
- mSetupTracksSuccessful = true;
}
++index;
@@ -355,6 +362,12 @@
}
}
mTracks.clear();
+ mSetupTracksSuccessful = false;
+ mSeekPending = false;
+ mFirstAccessUnit = true;
+ mFirstAccessUnitNTP = 0;
+ mNumAccessUnitsReceived = 0;
+ mReceivedFirstRTCPPacket = false;
sp<AMessage> reply = new AMessage('tear', id());
@@ -424,6 +437,12 @@
case 'accu':
{
+ int32_t firstRTCP;
+ if (msg->findInt32("first-rtcp", &firstRTCP)) {
+ mReceivedFirstRTCPPacket = true;
+ break;
+ }
+
++mNumAccessUnitsReceived;
if (!mCheckPending) {
@@ -612,7 +631,7 @@
case 'tiou':
{
- if (mFirstAccessUnit) {
+ if (!mReceivedFirstRTCPPacket) {
if (mTryTCPInterleaving) {
LOG(WARNING) << "Never received any data, disconnecting.";
(new AMessage('abor', id()))->post();
@@ -747,6 +766,7 @@
int64_t mNumAccessUnitsReceived;
bool mCheckPending;
bool mTryTCPInterleaving;
+ bool mReceivedFirstRTCPPacket;
struct TrackInfo {
AString mURL;
diff --git a/media/mtp/MtpDatabase.h b/media/mtp/MtpDatabase.h
index 899b34a..c8cb016 100644
--- a/media/mtp/MtpDatabase.h
+++ b/media/mtp/MtpDatabase.h
@@ -93,6 +93,10 @@
MtpObjectFormat format) = 0;
virtual MtpProperty* getDevicePropertyDesc(MtpDeviceProperty property) = 0;
+
+ virtual void sessionStarted() = 0;
+
+ virtual void sessionEnded() = 0;
};
}; // namespace android
diff --git a/media/mtp/MtpDevice.cpp b/media/mtp/MtpDevice.cpp
index bd68f75..fca0142 100644
--- a/media/mtp/MtpDevice.cpp
+++ b/media/mtp/MtpDevice.cpp
@@ -342,7 +342,7 @@
MtpResponseCode ret = readResponse();
if (ret == MTP_RESPONSE_OK) {
MtpProperty* property = new MtpProperty;
- property->read(mData, true);
+ property->read(mData);
return property;
}
return NULL;
diff --git a/media/mtp/MtpProperty.cpp b/media/mtp/MtpProperty.cpp
index 932ad6a..c7a91d6 100644
--- a/media/mtp/MtpProperty.cpp
+++ b/media/mtp/MtpProperty.cpp
@@ -120,7 +120,7 @@
delete[] mEnumValues;
}
-void MtpProperty::read(MtpDataPacket& packet, bool deviceProp) {
+void MtpProperty::read(MtpDataPacket& packet) {
mCode = packet.getUInt16();
mType = packet.getUInt16();
@@ -141,7 +141,7 @@
break;
default:
readValue(packet, mDefaultValue);
- if (deviceProp)
+ if (isDeviceProperty())
readValue(packet, mCurrentValue);
}
mGroupCode = packet.getUInt32();
@@ -159,7 +159,6 @@
}
}
-// FIXME - only works for object properties
void MtpProperty::write(MtpDataPacket& packet) {
packet.putUInt16(mCode);
packet.putUInt16(mType);
diff --git a/media/mtp/MtpProperty.h b/media/mtp/MtpProperty.h
index c5b4e28..64cfb93 100644
--- a/media/mtp/MtpProperty.h
+++ b/media/mtp/MtpProperty.h
@@ -65,16 +65,22 @@
inline MtpPropertyCode getPropertyCode() const { return mCode; }
- void read(MtpDataPacket& packet, bool deviceProp);
+ void read(MtpDataPacket& packet);
void write(MtpDataPacket& packet);
void print();
+ inline bool isDeviceProperty() const {
+ return ( ((mCode & 0xF000) == 0x5000)
+ || ((mCode & 0xF800) == 0xD000));
+ }
+
private:
void readValue(MtpDataPacket& packet, MtpPropertyValue& value);
void writeValue(MtpDataPacket& packet, MtpPropertyValue& value);
MtpPropertyValue* readArrayValues(MtpDataPacket& packet, int& length);
- void writeArrayValues(MtpDataPacket& packet, MtpPropertyValue* values, int length);
+ void writeArrayValues(MtpDataPacket& packet,
+ MtpPropertyValue* values, int length);
};
}; // namespace android
diff --git a/media/mtp/MtpServer.cpp b/media/mtp/MtpServer.cpp
index 1e64e4f..3d3bd62 100644
--- a/media/mtp/MtpServer.cpp
+++ b/media/mtp/MtpServer.cpp
@@ -55,7 +55,7 @@
// MTP_OPERATION_SELF_TEST,
// MTP_OPERATION_SET_OBJECT_PROTECTION,
// MTP_OPERATION_POWER_DOWN,
-// MTP_OPERATION_GET_DEVICE_PROP_DESC,
+ MTP_OPERATION_GET_DEVICE_PROP_DESC,
MTP_OPERATION_GET_DEVICE_PROP_VALUE,
MTP_OPERATION_SET_DEVICE_PROP_VALUE,
MTP_OPERATION_RESET_DEVICE_PROP_VALUE,
@@ -185,6 +185,9 @@
LOGV("skipping response\n");
}
}
+
+ if (mSessionOpen)
+ mDatabase->sessionEnded();
}
void MtpServer::sendObjectAdded(MtpObjectHandle handle) {
@@ -285,6 +288,9 @@
case MTP_OPERATION_GET_OBJECT_PROP_DESC:
response = doGetObjectPropDesc();
break;
+ case MTP_OPERATION_GET_DEVICE_PROP_DESC:
+ response = doGetDevicePropDesc();
+ break;
default:
response = MTP_RESPONSE_OPERATION_NOT_SUPPORTED;
break;
@@ -346,6 +352,9 @@
}
mSessionID = mRequest.getParameter(1);
mSessionOpen = true;
+
+ mDatabase->sessionStarted();
+
return MTP_RESPONSE_OK;
}
@@ -354,6 +363,7 @@
return MTP_RESPONSE_SESSION_NOT_OPEN;
mSessionID = 0;
mSessionOpen = false;
+ mDatabase->sessionEnded();
return MTP_RESPONSE_OK;
}
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index ff31470..3770b55 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -1781,6 +1781,14 @@
if (chain != 0 && chain->setVolume_l(&vl, &vr)) {
// Do not ramp volume is volume is controlled by effect
param = AudioMixer::VOLUME;
+ track->mHasVolumeController = true;
+ } else {
+ // force no volume ramp when volume controller was just disabled or removed
+ // from effect chain to avoid volume spike
+ if (track->mHasVolumeController) {
+ param = AudioMixer::VOLUME;
+ }
+ track->mHasVolumeController = false;
}
// Convert volumes from 8.24 to 4.12 format
@@ -2901,7 +2909,8 @@
const sp<IMemory>& sharedBuffer,
int sessionId)
: TrackBase(thread, client, sampleRate, format, channelCount, frameCount, 0, sharedBuffer, sessionId),
- mMute(false), mSharedBuffer(sharedBuffer), mName(-1), mMainBuffer(NULL), mAuxBuffer(NULL), mAuxEffectId(0)
+ mMute(false), mSharedBuffer(sharedBuffer), mName(-1), mMainBuffer(NULL), mAuxBuffer(NULL),
+ mAuxEffectId(0), mHasVolumeController(false)
{
if (mCblk != NULL) {
sp<ThreadBase> baseThread = thread.promote();
@@ -5371,7 +5380,7 @@
return;
}
- if (mState == ACTIVE || mState == STOPPING || mState == STOPPED || mState == RESTART) {
+ if (isProcessEnabled()) {
// do 32 bit to 16 bit conversion for auxiliary effect input buffer
if ((mDescriptor.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_AUXILIARY) {
AudioMixer::ditherAndClamp(mConfig.inputCfg.buffer.s32,
@@ -5600,6 +5609,8 @@
// going from enabled to disabled
case RESTART:
+ mState = STOPPED;
+ break;
case STARTING:
mState = IDLE;
break;
@@ -5632,6 +5643,21 @@
}
}
+bool AudioFlinger::EffectModule::isProcessEnabled()
+{
+ switch (mState) {
+ case RESTART:
+ case ACTIVE:
+ case STOPPING:
+ case STOPPED:
+ return true;
+ case IDLE:
+ case STARTING:
+ default:
+ return false;
+ }
+}
+
status_t AudioFlinger::EffectModule::setVolume(uint32_t *left, uint32_t *right, bool controller)
{
Mutex::Autolock _l(mLock);
@@ -5639,7 +5665,7 @@
// Send volume indication if EFFECT_FLAG_VOLUME_IND is set and read back altered volume
// if controller flag is set (Note that controller == TRUE => EFFECT_FLAG_VOLUME_CTRL set)
- if ((mState >= ACTIVE) &&
+ if (isProcessEnabled() &&
((mDescriptor.flags & EFFECT_FLAG_VOLUME_MASK) == EFFECT_FLAG_VOLUME_CTRL ||
(mDescriptor.flags & EFFECT_FLAG_VOLUME_MASK) == EFFECT_FLAG_VOLUME_IND)) {
status_t cmdStatus;
@@ -5966,12 +5992,14 @@
p,
&rsize,
&reply);
- if (ret == NO_ERROR) {
- if (reply != NO_ERROR) {
- status = reply;
- }
- } else {
+ // stop at first error encountered
+ if (ret != NO_ERROR) {
status = ret;
+ *(int *)pReplyData = reply;
+ break;
+ } else if (reply != NO_ERROR) {
+ *(int *)pReplyData = reply;
+ break;
}
mCblk->serverIndex += size;
}
@@ -5979,8 +6007,10 @@
mCblk->clientIndex = 0;
return status;
} else if (cmdCode == EFFECT_CMD_ENABLE) {
+ *(int *)pReplyData = NO_ERROR;
return enable();
} else if (cmdCode == EFFECT_CMD_DISABLE) {
+ *(int *)pReplyData = NO_ERROR;
return disable();
}
@@ -6288,7 +6318,7 @@
// first update volume controller
for (size_t i = size; i > 0; i--) {
- if ((mEffects[i - 1]->state() >= EffectModule::ACTIVE) &&
+ if (mEffects[i - 1]->isProcessEnabled() &&
(mEffects[i - 1]->desc().flags & EFFECT_FLAG_VOLUME_MASK) == EFFECT_FLAG_VOLUME_CTRL) {
ctrlIdx = i - 1;
hasControl = true;
@@ -6304,9 +6334,6 @@
return hasControl;
}
- if (mVolumeCtrlIdx != -1) {
- hasControl = true;
- }
mVolumeCtrlIdx = ctrlIdx;
mLeftVolume = newLeft;
mRightVolume = newRight;
diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h
index 51881f0..5917632 100644
--- a/services/audioflinger/AudioFlinger.h
+++ b/services/audioflinger/AudioFlinger.h
@@ -514,6 +514,7 @@
int16_t *mMainBuffer;
int32_t *mAuxBuffer;
int mAuxEffectId;
+ bool mHasVolumeController;
}; // end of Track
@@ -965,6 +966,7 @@
}
status_t setEnabled(bool enabled);
bool isEnabled();
+ bool isProcessEnabled();
void setInBuffer(int16_t *buffer) { mConfig.inputCfg.buffer.s16 = buffer; }
int16_t *inBuffer() { return mConfig.inputCfg.buffer.s16; }
diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp
index c6a9909..d1fbf17 100644
--- a/services/camera/libcameraservice/CameraService.cpp
+++ b/services/camera/libcameraservice/CameraService.cpp
@@ -336,11 +336,6 @@
int callingPid = getCallingPid();
LOG1("Client::~Client E (pid %d, this %p)", callingPid, this);
- // Clean up the ANativeWindow
- if (mSurface != 0) {
- setPreviewDisplay(0);
- }
-
// set mClientPid to let disconnet() tear down the hardware
mClientPid = callingPid;
disconnect();