Merge "Revert "Make build warnings be errors"" into nyc-dev
diff --git a/include/media/stagefright/ACodec.h b/include/media/stagefright/ACodec.h
index 2365323..fab92bd 100644
--- a/include/media/stagefright/ACodec.h
+++ b/include/media/stagefright/ACodec.h
@@ -25,6 +25,7 @@
#include <media/stagefright/foundation/AHierarchicalStateMachine.h>
#include <media/stagefright/CodecBase.h>
#include <media/stagefright/FrameRenderTracker.h>
+#include <media/stagefright/MediaDefs.h>
#include <media/stagefright/SkipCutBuffer.h>
#include <utils/NativeHandle.h>
#include <OMX_Audio.h>
@@ -36,6 +37,7 @@
struct ABuffer;
struct MemoryDealer;
struct DescribeColorFormat2Params;
+struct DataConverter;
struct ACodec : public AHierarchicalStateMachine, public CodecBase {
ACodec();
@@ -188,8 +190,11 @@
Status mStatus;
unsigned mDequeuedAt;
- sp<ABuffer> mData;
- sp<RefBase> mMemRef;
+ sp<ABuffer> mData; // the client's buffer; if not using data conversion, this is the
+ // codec buffer; otherwise, it is allocated separately
+ sp<RefBase> mMemRef; // and a reference to the IMemory, so it does not go away
+ sp<ABuffer> mCodecData; // the codec's buffer
+ sp<RefBase> mCodecRef; // and a reference to the IMemory
sp<GraphicBuffer> mGraphicBuffer;
sp<NativeHandle> mNativeHandle;
int mFenceFd;
@@ -248,6 +253,9 @@
sp<AMessage> mConfigFormat;
sp<AMessage> mInputFormat;
sp<AMessage> mOutputFormat;
+
+ // Initial output format + configuration params that is reused as the base for all subsequent
+ // format updates. This will equal to mOutputFormat until the first actual frame is received.
sp<AMessage> mBaseOutputFormat;
FrameRenderTracker mRenderTracker; // render information for buffers rendered by ACodec
@@ -280,6 +288,7 @@
bool mLegacyAdaptiveExperiment;
int32_t mMetadataBuffersToSubmit;
size_t mNumUndequeuedBuffers;
+ sp<DataConverter> mConverter[2];
int64_t mRepeatFrameDelayUs;
int64_t mMaxPtsGapUs;
@@ -441,7 +450,8 @@
bool encoder, int32_t numChannels, int32_t sampleRate, int32_t compressionLevel);
status_t setupRawAudioFormat(
- OMX_U32 portIndex, int32_t sampleRate, int32_t numChannels);
+ OMX_U32 portIndex, int32_t sampleRate, int32_t numChannels,
+ AudioEncoding encoding = kAudioEncodingPcm16bit);
status_t setPriority(int32_t priority);
status_t setOperatingRate(float rateFloat, bool isVideo);
@@ -496,7 +506,10 @@
void notifyOfRenderedFrames(
bool dropIncomplete = false, FrameRenderTracker::Info *until = NULL);
- void onOutputFormatChanged();
+ // Pass |expectedFormat| to print a warning if the format differs from it.
+ // Using sp<> instead of const sp<>& because expectedFormat is likely the current mOutputFormat
+ // which will get updated inside.
+ void onOutputFormatChanged(sp<const AMessage> expectedFormat = NULL);
void addKeyFormatChangesToRenderBufferNotification(sp<AMessage> ¬ify);
void sendFormatChange();
diff --git a/include/media/stagefright/MediaCodecSource.h b/include/media/stagefright/MediaCodecSource.h
index 5f10487..035e8ae 100644
--- a/include/media/stagefright/MediaCodecSource.h
+++ b/include/media/stagefright/MediaCodecSource.h
@@ -56,7 +56,7 @@
virtual status_t start(MetaData *params = NULL);
virtual status_t stop();
virtual status_t pause();
- virtual sp<MetaData> getFormat() { return mMeta; }
+ virtual sp<MetaData> getFormat();
virtual status_t read(
MediaBuffer **buffer,
const ReadOptions *options = NULL);
@@ -105,7 +105,7 @@
sp<ALooper> mCodecLooper;
sp<AHandlerReflector<MediaCodecSource> > mReflector;
sp<AMessage> mOutputFormat;
- sp<MetaData> mMeta;
+ Mutexed<sp<MetaData>> mMeta;
sp<Puller> mPuller;
sp<MediaCodec> mEncoder;
uint32_t mFlags;
diff --git a/include/media/stagefright/NuMediaExtractor.h b/include/media/stagefright/NuMediaExtractor.h
index b8bb824..6606c58 100644
--- a/include/media/stagefright/NuMediaExtractor.h
+++ b/include/media/stagefright/NuMediaExtractor.h
@@ -84,6 +84,10 @@
kIsVorbis = 1,
};
+ enum {
+ kMaxTrackCount = 16384,
+ };
+
struct TrackInfo {
sp<IMediaSource> mSource;
size_t mTrackIndex;
@@ -113,7 +117,7 @@
void releaseTrackSamples();
bool getTotalBitrate(int64_t *bitRate) const;
- void updateDurationAndBitrate();
+ status_t updateDurationAndBitrate();
status_t appendVorbisNumPageSamples(TrackInfo *info, const sp<ABuffer> &buffer);
DISALLOW_EVIL_CONSTRUCTORS(NuMediaExtractor);
diff --git a/include/media/stagefright/foundation/AMessage.h b/include/media/stagefright/foundation/AMessage.h
index 83b9444..09d2ad8 100644
--- a/include/media/stagefright/foundation/AMessage.h
+++ b/include/media/stagefright/foundation/AMessage.h
@@ -127,6 +127,15 @@
// their refcount incremented.
sp<AMessage> dup() const;
+ // Performs a shallow or deep comparison of |this| and |other| and returns
+ // an AMessage with the differences.
+ // Warning: RefBase items, i.e. "objects" are _not_ copied but only have
+ // their refcount incremented.
+ // This is true for AMessages that have no corresponding AMessage equivalent in |other|.
+ // (E.g. there is no such key or the type is different.) On the other hand, changes in
+ // the AMessage (or AMessages if deep is |false|) are returned in new objects.
+ sp<AMessage> changesFrom(const sp<const AMessage> &other, bool deep = false) const;
+
AString debugString(int32_t indent = 0) const;
enum Type {
diff --git a/include/media/stagefright/foundation/Mutexed.h b/include/media/stagefright/foundation/Mutexed.h
index d4fd905..e905d86 100644
--- a/include/media/stagefright/foundation/Mutexed.h
+++ b/include/media/stagefright/foundation/Mutexed.h
@@ -110,6 +110,11 @@
inline T* operator->() const { return mLocked ? &mTreasure : nullptr; }
inline T& operator*() const { return mLocked ? mTreasure : *(T*)nullptr; }
+ // same as *
+ inline T& get() const { return mLocked ? mTreasure : *(T*)nullptr; }
+ // sets structure. this will abort if mLocked is false.
+ inline void set(T& o) const { get() = o; }
+
// Wait on the condition variable using lock. Must be locked.
inline status_t waitForCondition(Condition &cond) { return cond.wait(mLock); }
diff --git a/include/ndk/NdkMediaCodec.h b/include/ndk/NdkMediaCodec.h
index c6035bd..fcb3a99 100644
--- a/include/ndk/NdkMediaCodec.h
+++ b/include/ndk/NdkMediaCodec.h
@@ -178,7 +178,9 @@
typedef enum {
AMEDIACODECRYPTOINFO_MODE_CLEAR = 0,
- AMEDIACODECRYPTOINFO_MODE_AES_CTR = 1
+ AMEDIACODECRYPTOINFO_MODE_AES_CTR = 1,
+ AMEDIACODECRYPTOINFO_MODE_AES_WV = 2,
+ AMEDIACODECRYPTOINFO_MODE_AES_CBC = 3
} cryptoinfo_mode_t;
typedef struct {
diff --git a/media/audioserver/main_audioserver.cpp b/media/audioserver/main_audioserver.cpp
index 698da1f..4a7a988 100644
--- a/media/audioserver/main_audioserver.cpp
+++ b/media/audioserver/main_audioserver.cpp
@@ -56,6 +56,7 @@
sp<ProcessState> proc(ProcessState::self());
MediaLogService::instantiate();
ProcessState::self()->startThreadPool();
+ IPCThreadState::self()->joinThreadPool();
for (;;) {
siginfo_t info;
int ret = waitid(P_PID, childPid, &info, WEXITED | WSTOPPED | WCONTINUED);
diff --git a/media/libeffects/downmix/EffectDownmix.c b/media/libeffects/downmix/EffectDownmix.c
index 4a41037..9823c55 100644
--- a/media/libeffects/downmix/EffectDownmix.c
+++ b/media/libeffects/downmix/EffectDownmix.c
@@ -141,6 +141,37 @@
}
#endif
+static bool Downmix_validChannelMask(uint32_t mask)
+{
+ if (!mask) {
+ return false;
+ }
+ // check against unsupported channels
+ if (mask & kUnsupported) {
+ ALOGE("Unsupported channels (top or front left/right of center)");
+ return false;
+ }
+ // verify has FL/FR
+ if ((mask & AUDIO_CHANNEL_OUT_STEREO) != AUDIO_CHANNEL_OUT_STEREO) {
+ ALOGE("Front channels must be present");
+ return false;
+ }
+ // verify uses SIDE as a pair (ok if not using SIDE at all)
+ if ((mask & kSides) != 0) {
+ if ((mask & kSides) != kSides) {
+ ALOGE("Side channels must be used as a pair");
+ return false;
+ }
+ }
+ // verify uses BACK as a pair (ok if not using BACK at all)
+ if ((mask & kBacks) != 0) {
+ if ((mask & kBacks) != kBacks) {
+ ALOGE("Back channels must be used as a pair");
+ return false;
+ }
+ }
+ return true;
+}
/*----------------------------------------------------------------------------
* Effect API implementation
@@ -624,9 +655,10 @@
pDownmixer->apply_volume_correction = false;
pDownmixer->input_channel_count = 8; // matches default input of AUDIO_CHANNEL_OUT_7POINT1
} else {
- // when configuring the effect, do not allow a blank channel mask
- if (pConfig->inputCfg.channels == 0) {
- ALOGE("Downmix_Configure error: input channel mask can't be 0");
+ // when configuring the effect, do not allow a blank or unsupported channel mask
+ if (!Downmix_validChannelMask(pConfig->inputCfg.channels)) {
+ ALOGE("Downmix_Configure error: input channel mask(0x%x) not supported",
+ pConfig->inputCfg.channels);
return -EINVAL;
}
pDownmixer->input_channel_count =
@@ -969,34 +1001,13 @@
*/
bool Downmix_foldGeneric(
uint32_t mask, int16_t *pSrc, int16_t*pDst, size_t numFrames, bool accumulate) {
- // check against unsupported channels
- if (mask & kUnsupported) {
- ALOGE("Unsupported channels (top or front left/right of center)");
+
+ if (!Downmix_validChannelMask(mask)) {
return false;
}
- // verify has FL/FR
- if ((mask & AUDIO_CHANNEL_OUT_STEREO) != AUDIO_CHANNEL_OUT_STEREO) {
- ALOGE("Front channels must be present");
- return false;
- }
- // verify uses SIDE as a pair (ok if not using SIDE at all)
- bool hasSides = false;
- if ((mask & kSides) != 0) {
- if ((mask & kSides) != kSides) {
- ALOGE("Side channels must be used as a pair");
- return false;
- }
- hasSides = true;
- }
- // verify uses BACK as a pair (ok if not using BACK at all)
- bool hasBacks = false;
- if ((mask & kBacks) != 0) {
- if ((mask & kBacks) != kBacks) {
- ALOGE("Back channels must be used as a pair");
- return false;
- }
- hasBacks = true;
- }
+
+ const bool hasSides = (mask & kSides) != 0;
+ const bool hasBacks = (mask & kBacks) != 0;
const int numChan = audio_channel_count_from_out_mask(mask);
const bool hasFC = ((mask & AUDIO_CHANNEL_OUT_FRONT_CENTER) == AUDIO_CHANNEL_OUT_FRONT_CENTER);
diff --git a/media/libmedia/AudioRecord.cpp b/media/libmedia/AudioRecord.cpp
index 79ce75e..2976a5c 100644
--- a/media/libmedia/AudioRecord.cpp
+++ b/media/libmedia/AudioRecord.cpp
@@ -66,7 +66,7 @@
// ---------------------------------------------------------------------------
AudioRecord::AudioRecord(const String16 &opPackageName)
- : mStatus(NO_INIT), mOpPackageName(opPackageName), mSessionId(AUDIO_SESSION_ALLOCATE),
+ : mActive(false), mStatus(NO_INIT), mOpPackageName(opPackageName), mSessionId(AUDIO_SESSION_ALLOCATE),
mPreviousPriority(ANDROID_PRIORITY_NORMAL), mPreviousSchedulingGroup(SP_DEFAULT),
mSelectedDeviceId(AUDIO_PORT_HANDLE_NONE)
{
@@ -88,7 +88,8 @@
int uid,
pid_t pid,
const audio_attributes_t* pAttributes)
- : mStatus(NO_INIT),
+ : mActive(false),
+ mStatus(NO_INIT),
mOpPackageName(opPackageName),
mSessionId(AUDIO_SESSION_ALLOCATE),
mPreviousPriority(ANDROID_PRIORITY_NORMAL),
@@ -268,10 +269,9 @@
}
mStatus = NO_ERROR;
- mActive = false;
mUserData = user;
// TODO: add audio hardware input latency here
- mLatency = (1000*mFrameCount) / sampleRate;
+ mLatency = (1000 * mFrameCount) / mSampleRate;
mMarkerPosition = 0;
mMarkerReached = false;
mNewPosition = 0;
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp
index ef0ccc2..a731354 100644
--- a/media/libmedia/AudioTrack.cpp
+++ b/media/libmedia/AudioTrack.cpp
@@ -163,6 +163,7 @@
AudioTrack::AudioTrack()
: mStatus(NO_INIT),
+ mState(STATE_STOPPED),
mPreviousPriority(ANDROID_PRIORITY_NORMAL),
mPreviousSchedulingGroup(SP_DEFAULT),
mPausedPosition(0),
@@ -192,6 +193,7 @@
const audio_attributes_t* pAttributes,
bool doNotReconnect)
: mStatus(NO_INIT),
+ mState(STATE_STOPPED),
mPreviousPriority(ANDROID_PRIORITY_NORMAL),
mPreviousSchedulingGroup(SP_DEFAULT),
mPausedPosition(0),
@@ -221,6 +223,7 @@
const audio_attributes_t* pAttributes,
bool doNotReconnect)
: mStatus(NO_INIT),
+ mState(STATE_STOPPED),
mPreviousPriority(ANDROID_PRIORITY_NORMAL),
mPreviousSchedulingGroup(SP_DEFAULT),
mPausedPosition(0),
@@ -477,7 +480,6 @@
}
mStatus = NO_ERROR;
- mState = STATE_STOPPED;
mUserData = user;
mLoopCount = 0;
mLoopStart = 0;
@@ -552,19 +554,6 @@
mNewPosition = mPosition + mUpdatePeriod;
int32_t flags = android_atomic_and(~CBLK_DISABLED, &mCblk->mFlags);
- sp<AudioTrackThread> t = mAudioTrackThread;
- if (t != 0) {
- if (previousState == STATE_STOPPING) {
- mProxy->interrupt();
- } else {
- t->resume();
- }
- } else {
- mPreviousPriority = getpriority(PRIO_PROCESS, 0);
- get_sched_policy(0, &mPreviousSchedulingGroup);
- androidSetThreadPriority(0, ANDROID_PRIORITY_AUDIO);
- }
-
status_t status = NO_ERROR;
if (!(flags & CBLK_INVALID)) {
status = mAudioTrack->start();
@@ -576,7 +565,21 @@
status = restoreTrack_l("start");
}
- if (status != NO_ERROR) {
+ // resume or pause the callback thread as needed.
+ sp<AudioTrackThread> t = mAudioTrackThread;
+ if (status == NO_ERROR) {
+ if (t != 0) {
+ if (previousState == STATE_STOPPING) {
+ mProxy->interrupt();
+ } else {
+ t->resume();
+ }
+ } else {
+ mPreviousPriority = getpriority(PRIO_PROCESS, 0);
+ get_sched_policy(0, &mPreviousSchedulingGroup);
+ androidSetThreadPriority(0, ANDROID_PRIORITY_AUDIO);
+ }
+ } else {
ALOGE("start() status %d", status);
mState = previousState;
if (t != 0) {
diff --git a/media/libmedia/mediaplayer.cpp b/media/libmedia/mediaplayer.cpp
index 53b6df6..2795101 100644
--- a/media/libmedia/mediaplayer.cpp
+++ b/media/libmedia/mediaplayer.cpp
@@ -207,7 +207,7 @@
ALOGV("invoke %zu", request.dataSize());
return mPlayer->invoke(request, reply);
}
- ALOGE("invoke failed: wrong state %X", mCurrentState);
+ ALOGE("invoke failed: wrong state %X, mPlayer(%p)", mCurrentState, mPlayer.get());
return INVALID_OPERATION;
}
@@ -252,7 +252,7 @@
mCurrentState = MEDIA_PLAYER_PREPARING;
return mPlayer->prepareAsync();
}
- ALOGE("prepareAsync called in state %d", mCurrentState);
+ ALOGE("prepareAsync called in state %d, mPlayer(%p)", mCurrentState, mPlayer.get());
return INVALID_OPERATION;
}
@@ -318,7 +318,7 @@
}
}
} else {
- ALOGE("start called in state %d", mCurrentState);
+ ALOGE("start called in state %d, mPlayer(%p)", mCurrentState, mPlayer.get());
ret = INVALID_OPERATION;
}
@@ -342,7 +342,7 @@
}
return ret;
}
- ALOGE("stop called in state %d", mCurrentState);
+ ALOGE("stop called in state %d, mPlayer(%p)", mCurrentState, mPlayer.get());
return INVALID_OPERATION;
}
@@ -361,7 +361,7 @@
}
return ret;
}
- ALOGE("pause called in state %d", mCurrentState);
+ ALOGE("pause called in state %d, mPlayer(%p)", mCurrentState, mPlayer.get());
return INVALID_OPERATION;
}
@@ -484,7 +484,8 @@
}
return ret;
}
- ALOGE("Attempt to call getDuration without a valid mediaplayer");
+ ALOGE("Attempt to call getDuration in wrong state: mPlayer=%p, mCurrentState=%u",
+ mPlayer.get(), mCurrentState);
return INVALID_OPERATION;
}
@@ -691,7 +692,7 @@
if (mPlayer == 0 ||
(mCurrentState & MEDIA_PLAYER_IDLE) ||
(mCurrentState == MEDIA_PLAYER_STATE_ERROR )) {
- ALOGE("attachAuxEffect called in state %d", mCurrentState);
+ ALOGE("attachAuxEffect called in state %d, mPlayer(%p)", mCurrentState, mPlayer.get());
return INVALID_OPERATION;
}
@@ -906,6 +907,7 @@
}
status_t MediaPlayer::setNextMediaPlayer(const sp<MediaPlayer>& next) {
+ Mutex::Autolock _l(mLock);
if (mPlayer == NULL) {
return NO_INIT;
}
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp b/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp
index edd0aad..06bb53d 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp
+++ b/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp
@@ -315,6 +315,7 @@
}
status_t NuPlayerDriver::pause() {
+ ALOGD("pause(%p)", this);
// The NuPlayerRenderer may get flushed if pause for long enough, e.g. the pause timeout tear
// down for audio offload mode. If that happens, the NuPlayerRenderer will no longer know the
// current position. So similar to seekTo, update |mPositionUs| to the pause position by calling
diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp
index e8f75a4..d6a9f53 100644
--- a/media/libstagefright/ACodec.cpp
+++ b/media/libstagefright/ACodec.cpp
@@ -52,6 +52,7 @@
#include <OMX_AsString.h>
#include "include/avc_utils.h"
+#include "include/DataConverter.h"
#include "omx/OMXUtils.h"
namespace android {
@@ -114,6 +115,13 @@
DISALLOW_EVIL_CONSTRUCTORS(MessageList);
};
+static sp<DataConverter> getCopyConverter() {
+ static pthread_once_t once = PTHREAD_ONCE_INIT; // const-inited
+ static sp<DataConverter> sCopyConverter; // zero-inited
+ pthread_once(&once, [](){ sCopyConverter = new DataConverter(); });
+ return sCopyConverter;
+}
+
struct CodecObserver : public BnOMXObserver {
CodecObserver() {}
@@ -505,6 +513,7 @@
mOutputMetadataType(kMetadataBufferTypeInvalid),
mLegacyAdaptiveExperiment(false),
mMetadataBuffersToSubmit(0),
+ mNumUndequeuedBuffers(0),
mRepeatFrameDelayUs(-1ll),
mMaxPtsGapUs(-1ll),
mMaxFps(-1),
@@ -781,7 +790,7 @@
if (err == OK) {
MetadataBufferType type =
portIndex == kPortIndexOutput ? mOutputMetadataType : mInputMetadataType;
- int32_t bufSize = def.nBufferSize;
+ size_t bufSize = def.nBufferSize;
if (type == kMetadataBufferTypeGrallocSource) {
bufSize = sizeof(VideoGrallocMetadata);
} else if (type == kMetadataBufferTypeANWBuffer) {
@@ -792,33 +801,47 @@
// metadata size as we prefer to generate native source metadata, but component
// may require gralloc source. For camera source, allocate at least enough
// size for native metadata buffers.
- int32_t allottedSize = bufSize;
+ size_t allottedSize = bufSize;
if (portIndex == kPortIndexInput && type >= kMetadataBufferTypeGrallocSource) {
bufSize = max(sizeof(VideoGrallocMetadata), sizeof(VideoNativeMetadata));
} else if (portIndex == kPortIndexInput && type == kMetadataBufferTypeCameraSource) {
- bufSize = max(bufSize, (int32_t)sizeof(VideoNativeMetadata));
+ bufSize = max(bufSize, sizeof(VideoNativeMetadata));
+ }
+
+ size_t conversionBufferSize = 0;
+
+ sp<DataConverter> converter = mConverter[portIndex];
+ if (converter != NULL) {
+ // here we assume sane conversions of max 4:1, so result fits in int32
+ if (portIndex == kPortIndexInput) {
+ conversionBufferSize = converter->sourceSize(bufSize);
+ } else {
+ conversionBufferSize = converter->targetSize(bufSize);
+ }
}
size_t alignment = MemoryDealer::getAllocationAlignment();
- ALOGV("[%s] Allocating %u buffers of size %d/%d (from %u using %s) on %s port",
+ ALOGV("[%s] Allocating %u buffers of size %zu/%zu (from %u using %s) on %s port",
mComponentName.c_str(),
def.nBufferCountActual, bufSize, allottedSize, def.nBufferSize, asString(type),
portIndex == kPortIndexInput ? "input" : "output");
- if (bufSize == 0 || bufSize > kMaxCodecBufferSize) {
+ // verify buffer sizes to avoid overflow in align()
+ if (bufSize == 0 || max(bufSize, conversionBufferSize) > kMaxCodecBufferSize) {
ALOGE("b/22885421");
return NO_MEMORY;
}
// don't modify bufSize as OMX may not expect it to increase after negotiation
size_t alignedSize = align(bufSize, alignment);
- if (def.nBufferCountActual > SIZE_MAX / alignedSize) {
+ size_t alignedConvSize = align(conversionBufferSize, alignment);
+ if (def.nBufferCountActual > SIZE_MAX / (alignedSize + alignedConvSize)) {
ALOGE("b/22885421");
return NO_MEMORY;
}
- size_t totalSize = def.nBufferCountActual * alignedSize;
+ size_t totalSize = def.nBufferCountActual * (alignedSize + alignedConvSize);
mDealer[portIndex] = new MemoryDealer(totalSize, "ACodec");
for (OMX_U32 i = 0; i < def.nBufferCountActual && err == OK; ++i) {
@@ -857,6 +880,7 @@
// because Widevine source only receives these base addresses.
info.mData = new ABuffer(ptr != NULL ? ptr : (void *)native_handle, bufSize);
info.mNativeHandle = NativeHandle::create(native_handle, true /* ownsHandle */);
+ info.mCodecData = info.mData;
} else if (mQuirks & requiresAllocateBufferBit) {
err = mOMX->allocateBufferWithBackup(
mNode, portIndex, mem, &info.mBufferID, allottedSize);
@@ -865,11 +889,27 @@
}
if (mem != NULL) {
- info.mData = new ABuffer(mem->pointer(), bufSize);
+ info.mCodecData = new ABuffer(mem->pointer(), bufSize);
+ info.mCodecRef = mem;
+
if (type == kMetadataBufferTypeANWBuffer) {
((VideoNativeMetadata *)mem->pointer())->nFenceFd = -1;
}
- info.mMemRef = mem;
+
+ // if we require conversion, allocate conversion buffer for client use;
+ // otherwise, reuse codec buffer
+ if (mConverter[portIndex] != NULL) {
+ CHECK_GT(conversionBufferSize, (size_t)0);
+ mem = mDealer[portIndex]->allocate(conversionBufferSize);
+ if (mem == NULL|| mem->pointer() == NULL) {
+ return NO_MEMORY;
+ }
+ info.mData = new ABuffer(mem->pointer(), conversionBufferSize);
+ info.mMemRef = mem;
+ } else {
+ info.mData = info.mCodecData;
+ info.mMemRef = info.mCodecRef;
+ }
}
mBuffers[portIndex].push(info);
@@ -1062,6 +1102,7 @@
info.mIsReadFence = false;
info.mRenderInfo = NULL;
info.mData = new ABuffer(NULL /* data */, bufferSize /* capacity */);
+ info.mCodecData = info.mData;
info.mGraphicBuffer = graphicBuffer;
mBuffers[kPortIndexOutput].push(info);
@@ -1146,11 +1187,13 @@
((VideoNativeMetadata *)mem->pointer())->nFenceFd = -1;
}
info.mData = new ABuffer(mem->pointer(), mem->size());
+ info.mMemRef = mem;
+ info.mCodecData = info.mData;
+ info.mCodecRef = mem;
// we use useBuffer for metadata regardless of quirks
err = mOMX->useBuffer(
mNode, kPortIndexOutput, mem, &info.mBufferID, mem->size());
- info.mMemRef = mem;
mBuffers[kPortIndexOutput].push(info);
ALOGV("[%s] allocated meta buffer with ID %u (pointer = %p)",
@@ -1944,6 +1987,10 @@
}
}
+ AudioEncoding pcmEncoding = kAudioEncodingPcm16bit;
+ (void)msg->findInt32("pcm-encoding", (int32_t*)&pcmEncoding);
+ // invalid encodings will default to PCM-16bit in setupRawAudioFormat.
+
if (video) {
// determine need for software renderer
bool usingSwRenderer = false;
@@ -2148,7 +2195,7 @@
|| !msg->findInt32("sample-rate", &sampleRate)) {
err = INVALID_OPERATION;
} else {
- err = setupRawAudioFormat(kPortIndexInput, sampleRate, numChannels);
+ err = setupRawAudioFormat(kPortIndexInput, sampleRate, numChannels, pcmEncoding);
}
} else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AC3)) {
int32_t numChannels;
@@ -2210,6 +2257,7 @@
err = setOperatingRate(rateFloat, video);
}
+ // NOTE: both mBaseOutputFormat and mOutputFormat are outputFormat to signal first frame.
mBaseOutputFormat = outputFormat;
// trigger a kWhatOutputFormatChanged msg on first buffer
mLastOutputFormat.clear();
@@ -2222,6 +2270,25 @@
mOutputFormat = outputFormat;
}
}
+
+ // create data converters if needed
+ if (!video && err == OK) {
+ AudioEncoding codecPcmEncoding = kAudioEncodingPcm16bit;
+ if (encoder) {
+ (void)mInputFormat->findInt32("pcm-encoding", (int32_t*)&codecPcmEncoding);
+ mConverter[kPortIndexInput] = AudioConverter::Create(pcmEncoding, codecPcmEncoding);
+ if (mConverter[kPortIndexInput] != NULL) {
+ mInputFormat->setInt32("pcm-encoding", pcmEncoding);
+ }
+ } else {
+ (void)mOutputFormat->findInt32("pcm-encoding", (int32_t*)&codecPcmEncoding);
+ mConverter[kPortIndexOutput] = AudioConverter::Create(codecPcmEncoding, pcmEncoding);
+ if (mConverter[kPortIndexOutput] != NULL) {
+ mOutputFormat->setInt32("pcm-encoding", pcmEncoding);
+ }
+ }
+ }
+
return err;
}
@@ -2772,7 +2839,7 @@
}
status_t ACodec::setupRawAudioFormat(
- OMX_U32 portIndex, int32_t sampleRate, int32_t numChannels) {
+ OMX_U32 portIndex, int32_t sampleRate, int32_t numChannels, AudioEncoding encoding) {
OMX_PARAM_PORTDEFINITIONTYPE def;
InitOMXParams(&def);
def.nPortIndex = portIndex;
@@ -2805,9 +2872,23 @@
}
pcmParams.nChannels = numChannels;
- pcmParams.eNumData = OMX_NumericalDataSigned;
+ switch (encoding) {
+ case kAudioEncodingPcm8bit:
+ pcmParams.eNumData = OMX_NumericalDataUnsigned;
+ pcmParams.nBitPerSample = 8;
+ break;
+ case kAudioEncodingPcmFloat:
+ pcmParams.eNumData = OMX_NumericalDataFloat;
+ pcmParams.nBitPerSample = 32;
+ break;
+ case kAudioEncodingPcm16bit:
+ pcmParams.eNumData = OMX_NumericalDataSigned;
+ pcmParams.nBitPerSample = 16;
+ break;
+ default:
+ return BAD_VALUE;
+ }
pcmParams.bInterleaved = OMX_TRUE;
- pcmParams.nBitPerSample = 16;
pcmParams.nSamplingRate = sampleRate;
pcmParams.ePCMMode = OMX_AUDIO_PCMModeLinear;
@@ -2815,8 +2896,17 @@
return OMX_ErrorNone;
}
- return mOMX->setParameter(
+ err = mOMX->setParameter(
mNode, OMX_IndexParamAudioPcm, &pcmParams, sizeof(pcmParams));
+ // if we could not set up raw format to non-16-bit, try with 16-bit
+ // NOTE: we will also verify this via readback, in case codec ignores these fields
+ if (err != OK && encoding != kAudioEncodingPcm16bit) {
+ pcmParams.eNumData = OMX_NumericalDataSigned;
+ pcmParams.nBitPerSample = 16;
+ err = mOMX->setParameter(
+ mNode, OMX_IndexParamAudioPcm, &pcmParams, sizeof(pcmParams));
+ }
+ return err;
}
status_t ACodec::configureTunneledVideoPlayback(
@@ -3857,6 +3947,13 @@
h264type.eLevel = static_cast<OMX_VIDEO_AVCLEVELTYPE>(level);
}
+ // XXX
+ if (h264type.eProfile != OMX_VIDEO_AVCProfileBaseline) {
+ ALOGW("Use baseline profile instead of %d for AVC recording",
+ h264type.eProfile);
+ h264type.eProfile = OMX_VIDEO_AVCProfileBaseline;
+ }
+
if (h264type.eProfile == OMX_VIDEO_AVCProfileBaseline) {
h264type.nSliceHeaderSpacing = 0;
h264type.bUseHadamard = OMX_TRUE;
@@ -3874,23 +3971,6 @@
h264type.bDirect8x8Inference = OMX_FALSE;
h264type.bDirectSpatialTemporal = OMX_FALSE;
h264type.nCabacInitIdc = 0;
- } else if (h264type.eProfile == OMX_VIDEO_AVCProfileMain ||
- h264type.eProfile == OMX_VIDEO_AVCProfileHigh) {
- h264type.nSliceHeaderSpacing = 0;
- h264type.bUseHadamard = OMX_TRUE;
- h264type.nRefFrames = 2;
- h264type.nBFrames = 1;
- h264type.nPFrames = setPFramesSpacing(iFrameInterval, frameRate);
- h264type.nAllowedPictureTypes =
- OMX_VIDEO_PictureTypeI | OMX_VIDEO_PictureTypeP | OMX_VIDEO_PictureTypeB;
- h264type.nRefIdx10ActiveMinus1 = 0;
- h264type.nRefIdx11ActiveMinus1 = 0;
- h264type.bEntropyCodingCABAC = OMX_TRUE;
- h264type.bWeightedPPrediction = OMX_TRUE;
- h264type.bconstIpred = OMX_TRUE;
- h264type.bDirect8x8Inference = OMX_TRUE;
- h264type.bDirectSpatialTemporal = OMX_TRUE;
- h264type.nCabacInitIdc = 1;
}
if (h264type.nBFrames != 0) {
@@ -4653,22 +4733,33 @@
if (params.nChannels <= 0
|| (params.nChannels != 1 && !params.bInterleaved)
- || params.nBitPerSample != 16u
- || params.eNumData != OMX_NumericalDataSigned
|| params.ePCMMode != OMX_AUDIO_PCMModeLinear) {
- ALOGE("unsupported PCM port: %u channels%s, %u-bit, %s(%d), %s(%d) mode ",
+ ALOGE("unsupported PCM port: %u channels%s, %u-bit",
params.nChannels,
params.bInterleaved ? " interleaved" : "",
- params.nBitPerSample,
- asString(params.eNumData), params.eNumData,
- asString(params.ePCMMode), params.ePCMMode);
+ params.nBitPerSample);
return FAILED_TRANSACTION;
}
notify->setString("mime", MEDIA_MIMETYPE_AUDIO_RAW);
notify->setInt32("channel-count", params.nChannels);
notify->setInt32("sample-rate", params.nSamplingRate);
- notify->setInt32("pcm-encoding", kAudioEncodingPcm16bit);
+
+ AudioEncoding encoding = kAudioEncodingPcm16bit;
+ if (params.eNumData == OMX_NumericalDataUnsigned
+ && params.nBitPerSample == 8u) {
+ encoding = kAudioEncodingPcm8bit;
+ } else if (params.eNumData == OMX_NumericalDataFloat
+ && params.nBitPerSample == 32u) {
+ encoding = kAudioEncodingPcmFloat;
+ } else if (params.nBitPerSample != 16u
+ || params.eNumData != OMX_NumericalDataSigned) {
+ ALOGE("unsupported PCM port: %s(%d), %s(%d) mode ",
+ asString(params.eNumData), params.eNumData,
+ asString(params.ePCMMode), params.ePCMMode);
+ return FAILED_TRANSACTION;
+ }
+ notify->setInt32("pcm-encoding", encoding);
if (mChannelMaskPresent) {
notify->setInt32("channel-mask", mChannelMask);
@@ -4928,8 +5019,8 @@
transfer, asString((ColorTransfer)transfer));
}
-void ACodec::onOutputFormatChanged() {
- // store new output format
+void ACodec::onOutputFormatChanged(sp<const AMessage> expectedFormat) {
+ // store new output format, at the same time mark that this is no longer the first frame
mOutputFormat = mBaseOutputFormat->dup();
if (getPortFormat(kPortIndexOutput, mOutputFormat) != OK) {
@@ -4937,6 +5028,28 @@
return;
}
+ if (expectedFormat != NULL) {
+ sp<const AMessage> changes = expectedFormat->changesFrom(mOutputFormat);
+ sp<const AMessage> to = mOutputFormat->changesFrom(expectedFormat);
+ if (changes->countEntries() != 0 || to->countEntries() != 0) {
+ ALOGW("[%s] BAD CODEC: Output format changed unexpectedly from (diff) %s to (diff) %s",
+ mComponentName.c_str(),
+ changes->debugString(4).c_str(), to->debugString(4).c_str());
+ }
+ }
+
+ if (!mIsVideo && !mIsEncoder) {
+ AudioEncoding pcmEncoding = kAudioEncodingPcm16bit;
+ (void)mConfigFormat->findInt32("pcm-encoding", (int32_t*)&pcmEncoding);
+ AudioEncoding codecPcmEncoding = kAudioEncodingPcm16bit;
+ (void)mOutputFormat->findInt32("pcm-encoding", (int32_t*)&pcmEncoding);
+
+ mConverter[kPortIndexOutput] = AudioConverter::Create(codecPcmEncoding, pcmEncoding);
+ if (mConverter[kPortIndexOutput] != NULL) {
+ mOutputFormat->setInt32("pcm-encoding", pcmEncoding);
+ }
+ }
+
if (mTunneled) {
sendFormatChange();
}
@@ -5464,20 +5577,21 @@
flags |= OMX_BUFFERFLAG_EOS;
}
- if (buffer != info->mData) {
+ if (buffer != info->mCodecData) {
ALOGV("[%s] Needs to copy input data for buffer %u. (%p != %p)",
mCodec->mComponentName.c_str(),
bufferID,
- buffer.get(), info->mData.get());
+ buffer.get(), info->mCodecData.get());
- if (buffer->size() > info->mData->capacity()) {
- ALOGE("data size (%zu) is greated than buffer capacity (%zu)",
- buffer->size(), // this is the data received
- info->mData->capacity()); // this is out buffer size
- mCodec->signalError(OMX_ErrorUndefined, FAILED_TRANSACTION);
+ sp<DataConverter> converter = mCodec->mConverter[kPortIndexInput];
+ if (converter == NULL) {
+ converter = getCopyConverter();
+ }
+ status_t err = converter->convert(buffer, info->mCodecData);
+ if (err != OK) {
+ mCodec->signalError(OMX_ErrorUndefined, err);
return;
}
- memcpy(info->mData->data(), buffer->data(), buffer->size());
}
if (flags & OMX_BUFFERFLAG_CODECCONFIG) {
@@ -5520,7 +5634,7 @@
mCodec->mNode,
bufferID,
0,
- buffer->size(),
+ info->mCodecData->size(),
flags,
timeUs,
info->mFenceFd);
@@ -5699,6 +5813,10 @@
new AMessage(kWhatOutputBufferDrained, mCodec);
if (mCodec->mOutputFormat != mCodec->mLastOutputFormat && rangeLength > 0) {
+ // pretend that output format has changed on the first frame (we used to do this)
+ if (mCodec->mBaseOutputFormat == mCodec->mOutputFormat) {
+ mCodec->onOutputFormatChanged(mCodec->mOutputFormat);
+ }
mCodec->addKeyFormatChangesToRenderBufferNotification(reply);
mCodec->sendFormatChange();
}
@@ -5722,8 +5840,17 @@
info->mData->meta()->setPointer("handle", handle);
info->mData->meta()->setInt32("rangeOffset", rangeOffset);
info->mData->meta()->setInt32("rangeLength", rangeLength);
- } else {
+ } else if (info->mData == info->mCodecData) {
info->mData->setRange(rangeOffset, rangeLength);
+ } else {
+ info->mCodecData->setRange(rangeOffset, rangeLength);
+ // in this case we know that mConverter is not null
+ status_t err = mCodec->mConverter[kPortIndexOutput]->convert(
+ info->mCodecData, info->mData);
+ if (err != OK) {
+ mCodec->signalError(OMX_ErrorUndefined, makeNoSideEffectStatus(err));
+ return true;
+ }
}
#if 0
if (mCodec->mNativeWindow == NULL) {
@@ -5939,6 +6066,8 @@
mCodec->mFlags = 0;
mCodec->mInputMetadataType = kMetadataBufferTypeInvalid;
mCodec->mOutputMetadataType = kMetadataBufferTypeInvalid;
+ mCodec->mConverter[0].clear();
+ mCodec->mConverter[1].clear();
mCodec->mComponentName.clear();
}
diff --git a/media/libstagefright/Android.mk b/media/libstagefright/Android.mk
index 557971d..2445842 100644
--- a/media/libstagefright/Android.mk
+++ b/media/libstagefright/Android.mk
@@ -14,6 +14,7 @@
CameraSource.cpp \
CameraSourceTimeLapse.cpp \
CodecBase.cpp \
+ DataConverter.cpp \
DataSource.cpp \
DataURISource.cpp \
DRMExtractor.cpp \
diff --git a/media/libstagefright/DataConverter.cpp b/media/libstagefright/DataConverter.cpp
new file mode 100644
index 0000000..aea47f3
--- /dev/null
+++ b/media/libstagefright/DataConverter.cpp
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//#define LOG_NDEBUG 0
+#define LOG_TAG "DataConverter"
+
+#include "include/DataConverter.h"
+
+#include <audio_utils/primitives.h>
+
+#include <media/stagefright/foundation/ABuffer.h>
+#include <media/stagefright/foundation/ADebug.h>
+#include <media/stagefright/foundation/AUtils.h>
+
+namespace android {
+
+status_t DataConverter::convert(const sp<ABuffer> &source, sp<ABuffer> &target) {
+ CHECK(source->base() != target->base());
+ size_t size = targetSize(source->size());
+ status_t err = OK;
+ if (size > target->capacity()) {
+ ALOGE("data size (%zu) is greater than buffer capacity (%zu)",
+ size, // this is the data received/to be converted
+ target->capacity()); // this is out buffer size
+ err = FAILED_TRANSACTION;
+ } else {
+ err = safeConvert(source, target);
+ }
+ target->setRange(0, err == OK ? size : 0);
+ return err;
+}
+
+status_t DataConverter::safeConvert(const sp<ABuffer> &source, sp<ABuffer> &target) {
+ memcpy(target->base(), source->data(), source->size());
+ return OK;
+}
+
+size_t DataConverter::sourceSize(size_t targetSize) {
+ return targetSize;
+}
+
+size_t DataConverter::targetSize(size_t sourceSize) {
+ return sourceSize;
+}
+
+DataConverter::~DataConverter() { }
+
+
+size_t SampleConverterBase::sourceSize(size_t targetSize) {
+ size_t numSamples = targetSize / mTargetSampleSize;
+ if (numSamples > SIZE_MAX / mSourceSampleSize) {
+ ALOGW("limiting source size due to overflow (%zu*%zu/%zu)",
+ targetSize, mSourceSampleSize, mTargetSampleSize);
+ return SIZE_MAX;
+ }
+ return numSamples * mSourceSampleSize;
+}
+
+size_t SampleConverterBase::targetSize(size_t sourceSize) {
+ // we round up on conversion
+ size_t numSamples = divUp(sourceSize, (size_t)mSourceSampleSize);
+ if (numSamples > SIZE_MAX / mTargetSampleSize) {
+ ALOGW("limiting target size due to overflow (%zu*%zu/%zu)",
+ sourceSize, mTargetSampleSize, mSourceSampleSize);
+ return SIZE_MAX;
+ }
+ return numSamples * mTargetSampleSize;
+}
+
+
+static size_t getAudioSampleSize(AudioEncoding e) {
+ switch (e) {
+ case kAudioEncodingPcm16bit: return 2;
+ case kAudioEncodingPcm8bit: return 1;
+ case kAudioEncodingPcmFloat: return 4;
+ default: return 0;
+ }
+}
+
+
+// static
+AudioConverter* AudioConverter::Create(AudioEncoding source, AudioEncoding target) {
+ uint32_t sourceSampleSize = getAudioSampleSize(source);
+ uint32_t targetSampleSize = getAudioSampleSize(target);
+ if (sourceSampleSize && targetSampleSize && sourceSampleSize != targetSampleSize) {
+ return new AudioConverter(source, sourceSampleSize, target, targetSampleSize);
+ }
+ return NULL;
+}
+
+status_t AudioConverter::safeConvert(const sp<ABuffer> &src, sp<ABuffer> &tgt) {
+ if (mTo == kAudioEncodingPcm8bit && mFrom == kAudioEncodingPcm16bit) {
+ memcpy_to_u8_from_i16((uint8_t*)tgt->base(), (const int16_t*)src->data(), src->size() / 2);
+ } else if (mTo == kAudioEncodingPcm8bit && mFrom == kAudioEncodingPcmFloat) {
+ memcpy_to_u8_from_float((uint8_t*)tgt->base(), (const float*)src->data(), src->size() / 4);
+ } else if (mTo == kAudioEncodingPcm16bit && mFrom == kAudioEncodingPcm8bit) {
+ memcpy_to_i16_from_u8((int16_t*)tgt->base(), (const uint8_t*)src->data(), src->size());
+ } else if (mTo == kAudioEncodingPcm16bit && mFrom == kAudioEncodingPcmFloat) {
+ memcpy_to_i16_from_float((int16_t*)tgt->base(), (const float*)src->data(), src->size() / 4);
+ } else if (mTo == kAudioEncodingPcmFloat && mFrom == kAudioEncodingPcm8bit) {
+ memcpy_to_float_from_u8((float*)tgt->base(), (const uint8_t*)src->data(), src->size());
+ } else if (mTo == kAudioEncodingPcmFloat && mFrom == kAudioEncodingPcm16bit) {
+ memcpy_to_float_from_i16((float*)tgt->base(), (const int16_t*)src->data(), src->size() / 2);
+ } else {
+ return INVALID_OPERATION;
+ }
+ return OK;
+}
+
+} // namespace android
diff --git a/media/libstagefright/MediaCodecSource.cpp b/media/libstagefright/MediaCodecSource.cpp
index 0a052d2..1acfca0 100644
--- a/media/libstagefright/MediaCodecSource.cpp
+++ b/media/libstagefright/MediaCodecSource.cpp
@@ -358,6 +358,11 @@
return OK;
}
+sp<MetaData> MediaCodecSource::getFormat() {
+ Mutexed<sp<MetaData>>::Locked meta(mMeta);
+ return *meta;
+}
+
sp<IGraphicBufferProducer> MediaCodecSource::getGraphicBufferProducer() {
CHECK(mFlags & FLAG_USE_SURFACE_INPUT);
return mGraphicBufferProducer;
@@ -493,7 +498,9 @@
}
mEncoder->getOutputFormat(&mOutputFormat);
- convertMessageToMetaData(mOutputFormat, mMeta);
+ sp<MetaData> meta = new MetaData;
+ convertMessageToMetaData(mOutputFormat, meta);
+ mMeta.lock().set(meta);
if (mFlags & FLAG_USE_SURFACE_INPUT) {
CHECK(mIsVideo);
@@ -787,7 +794,9 @@
signalEOS(err);
break;
}
- convertMessageToMetaData(mOutputFormat, mMeta);
+ sp<MetaData> meta = new MetaData;
+ convertMessageToMetaData(mOutputFormat, meta);
+ mMeta.lock().set(meta);
} else if (cbID == MediaCodec::CB_OUTPUT_AVAILABLE) {
int32_t index;
size_t offset;
diff --git a/media/libstagefright/NuMediaExtractor.cpp b/media/libstagefright/NuMediaExtractor.cpp
index dd7f6b9..6d1a460 100644
--- a/media/libstagefright/NuMediaExtractor.cpp
+++ b/media/libstagefright/NuMediaExtractor.cpp
@@ -121,9 +121,10 @@
return ERROR_UNSUPPORTED;
}
- mDataSource = dataSource;
-
- updateDurationAndBitrate();
+ status_t err = updateDurationAndBitrate();
+ if (err == OK) {
+ mDataSource = dataSource;
+ }
return OK;
}
@@ -152,9 +153,10 @@
return ERROR_UNSUPPORTED;
}
- mDataSource = fileSource;
-
- updateDurationAndBitrate();
+ err = updateDurationAndBitrate();
+ if (err == OK) {
+ mDataSource = fileSource;
+ }
return OK;
}
@@ -177,14 +179,19 @@
return ERROR_UNSUPPORTED;
}
- mDataSource = source;
+ err = updateDurationAndBitrate();
+ if (err == OK) {
+ mDataSource = source;
+ }
- updateDurationAndBitrate();
-
- return OK;
+ return err;
}
-void NuMediaExtractor::updateDurationAndBitrate() {
+status_t NuMediaExtractor::updateDurationAndBitrate() {
+ if (mImpl->countTracks() > kMaxTrackCount) {
+ return ERROR_UNSUPPORTED;
+ }
+
mTotalBitrate = 0ll;
mDurationUs = -1ll;
@@ -212,6 +219,7 @@
mDurationUs = durationUs;
}
}
+ return OK;
}
size_t NuMediaExtractor::countTracks() const {
@@ -235,6 +243,12 @@
}
sp<MetaData> meta = mImpl->getTrackMetaData(index);
+ // Extractors either support trackID-s or not, so either all tracks have trackIDs or none.
+ // Generate trackID if missing.
+ int32_t trackID;
+ if (meta != NULL && !meta->findInt32(kKeyTrackID, &trackID)) {
+ meta->setInt32(kKeyTrackID, (int32_t)index + 1);
+ }
return convertMetaDataToMessage(meta, format);
}
diff --git a/media/libstagefright/SampleTable.cpp b/media/libstagefright/SampleTable.cpp
index f5d9ec7..1bdd812 100644
--- a/media/libstagefright/SampleTable.cpp
+++ b/media/libstagefright/SampleTable.cpp
@@ -298,6 +298,7 @@
mDefaultSampleSize = U32_AT(&header[4]);
mNumSampleSizes = U32_AT(&header[8]);
if (mNumSampleSizes > (UINT32_MAX - 12) / 16) {
+ ALOGE("b/23247055, mNumSampleSizes(%u)", mNumSampleSizes);
return ERROR_MALFORMED;
}
@@ -532,6 +533,9 @@
Mutex::Autolock autoLock(mLock);
if (mSampleTimeEntries != NULL || mNumSampleSizes == 0) {
+ if (mNumSampleSizes == 0) {
+ ALOGE("b/23247055, mNumSampleSizes(%u)", mNumSampleSizes);
+ }
return;
}
diff --git a/media/libstagefright/Utils.cpp b/media/libstagefright/Utils.cpp
index dc4acda..7daae20 100644
--- a/media/libstagefright/Utils.cpp
+++ b/media/libstagefright/Utils.cpp
@@ -167,6 +167,12 @@
msg->setInt32("is-sync-frame", 1);
}
+ // this only needs to be translated from meta to message as it is an extractor key
+ int32_t trackID;
+ if (meta->findInt32(kKeyTrackID, &trackID)) {
+ msg->setInt32("track-id", trackID);
+ }
+
if (!strncasecmp("video/", mime, 6)) {
int32_t width, height;
if (!meta->findInt32(kKeyWidth, &width)
diff --git a/media/libstagefright/VideoFrameScheduler.cpp b/media/libstagefright/VideoFrameScheduler.cpp
index 5564926..03226c7 100644
--- a/media/libstagefright/VideoFrameScheduler.cpp
+++ b/media/libstagefright/VideoFrameScheduler.cpp
@@ -156,12 +156,12 @@
lastTime = time;
}
- int64_t div = numSamplesToUse * sumXX - sumX * sumX;
+ int64_t div = (int64_t)numSamplesToUse * sumXX - sumX * sumX;
if (div == 0) {
return false;
}
- int64_t a_nom = numSamplesToUse * sumXY - sumX * sumY;
+ int64_t a_nom = (int64_t)numSamplesToUse * sumXY - sumX * sumY;
int64_t b_nom = sumXX * sumY - sumX * sumXY;
*a = divRound(a_nom, div);
*b = divRound(b_nom, div);
@@ -437,10 +437,10 @@
(renderTime + mTimeCorrection + videoPeriod * i - mVsyncTime) % mVsyncPeriod;
edgeRemainder += (videoPeriod * i) % mVsyncPeriod;
}
- mTimeCorrection += mVsyncPeriod / 2 - offset / N;
+ mTimeCorrection += mVsyncPeriod / 2 - offset / (nsecs_t)N;
renderTime += mTimeCorrection;
nsecs_t correctionLimit = mVsyncPeriod * 3 / 5;
- edgeRemainder = abs(edgeRemainder / N - mVsyncPeriod / 2);
+ edgeRemainder = abs(edgeRemainder / (nsecs_t)N - mVsyncPeriod / 2);
if (edgeRemainder <= mVsyncPeriod / 3) {
correctionLimit /= 2;
}
diff --git a/media/libstagefright/codecs/amrnb/dec/SoftAMR.cpp b/media/libstagefright/codecs/amrnb/dec/SoftAMR.cpp
index be22098..edf648d 100644
--- a/media/libstagefright/codecs/amrnb/dec/SoftAMR.cpp
+++ b/media/libstagefright/codecs/amrnb/dec/SoftAMR.cpp
@@ -306,13 +306,6 @@
BufferInfo *inInfo = *inQueue.begin();
OMX_BUFFERHEADERTYPE *inHeader = inInfo->mHeader;
- if (inHeader->nFilledLen == 0) {
- inInfo->mOwnedByUs = false;
- inQueue.erase(inQueue.begin());
- notifyEmptyBufferDone(inHeader);
- continue;
- }
-
BufferInfo *outInfo = *outQueue.begin();
OMX_BUFFERHEADERTYPE *outHeader = outInfo->mHeader;
@@ -330,6 +323,13 @@
return;
}
+ if (inHeader->nFilledLen == 0) {
+ inInfo->mOwnedByUs = false;
+ inQueue.erase(inQueue.begin());
+ notifyEmptyBufferDone(inHeader);
+ continue;
+ }
+
if (inHeader->nOffset == 0) {
mAnchorTimeUs = inHeader->nTimeStamp;
mNumSamplesOutput = 0;
diff --git a/media/libstagefright/codecs/on2/enc/SoftVPXEncoder.cpp b/media/libstagefright/codecs/on2/enc/SoftVPXEncoder.cpp
index a354690..5edfbb5 100644
--- a/media/libstagefright/codecs/on2/enc/SoftVPXEncoder.cpp
+++ b/media/libstagefright/codecs/on2/enc/SoftVPXEncoder.cpp
@@ -734,9 +734,10 @@
const uint8_t *source =
inputBufferHeader->pBuffer + inputBufferHeader->nOffset;
+ size_t frameSize = mWidth * mHeight * 3 / 2;
if (mInputDataIsMeta) {
source = extractGraphicBuffer(
- mConversionBuffer, mWidth * mHeight * 3 / 2,
+ mConversionBuffer, frameSize,
source, inputBufferHeader->nFilledLen,
mWidth, mHeight);
if (source == NULL) {
@@ -744,11 +745,21 @@
notify(OMX_EventError, OMX_ErrorUndefined, 0, 0);
return;
}
- } else if (mColorFormat == OMX_COLOR_FormatYUV420SemiPlanar) {
- ConvertYUV420SemiPlanarToYUV420Planar(
- source, mConversionBuffer, mWidth, mHeight);
+ } else {
+ if (inputBufferHeader->nFilledLen < frameSize) {
+ android_errorWriteLog(0x534e4554, "27569635");
+ notify(OMX_EventError, OMX_ErrorUndefined, 0, 0);
+ return;
+ } else if (inputBufferHeader->nFilledLen > frameSize) {
+ ALOGW("Input buffer contains too many pixels");
+ }
- source = mConversionBuffer;
+ if (mColorFormat == OMX_COLOR_FormatYUV420SemiPlanar) {
+ ConvertYUV420SemiPlanarToYUV420Planar(
+ source, mConversionBuffer, mWidth, mHeight);
+
+ source = mConversionBuffer;
+ }
}
vpx_image_t raw_frame;
vpx_img_wrap(&raw_frame, VPX_IMG_FMT_I420, mWidth, mHeight,
@@ -810,9 +821,14 @@
outputBufferHeader->nTimeStamp = encoded_packet->data.frame.pts;
outputBufferHeader->nFlags = 0;
if (encoded_packet->data.frame.flags & VPX_FRAME_IS_KEY)
- outputBufferHeader->nFlags |= OMX_BUFFERFLAG_SYNCFRAME;
+ outputBufferHeader->nFlags |= OMX_BUFFERFLAG_SYNCFRAME;
outputBufferHeader->nOffset = 0;
outputBufferHeader->nFilledLen = encoded_packet->data.frame.sz;
+ if (outputBufferHeader->nFilledLen > outputBufferHeader->nAllocLen) {
+ android_errorWriteLog(0x534e4554, "27569635");
+ notify(OMX_EventError, OMX_ErrorUndefined, 0, 0);
+ return;
+ }
memcpy(outputBufferHeader->pBuffer,
encoded_packet->data.frame.buf,
encoded_packet->data.frame.sz);
diff --git a/media/libstagefright/codecs/raw/SoftRaw.cpp b/media/libstagefright/codecs/raw/SoftRaw.cpp
index c4e0659..acb2b37 100644
--- a/media/libstagefright/codecs/raw/SoftRaw.cpp
+++ b/media/libstagefright/codecs/raw/SoftRaw.cpp
@@ -42,7 +42,9 @@
: SimpleSoftOMXComponent(name, callbacks, appData, component),
mSignalledError(false),
mChannelCount(2),
- mSampleRate(44100) {
+ mSampleRate(44100),
+ mNumericalData(OMX_NumericalDataSigned),
+ mBitsPerSample(16) {
initPorts();
CHECK_EQ(initDecoder(), (status_t)OK);
}
@@ -111,10 +113,10 @@
return OMX_ErrorUndefined;
}
- pcmParams->eNumData = OMX_NumericalDataSigned;
+ pcmParams->eNumData = (OMX_NUMERICALDATATYPE)mNumericalData;
pcmParams->eEndian = OMX_EndianBig;
pcmParams->bInterleaved = OMX_TRUE;
- pcmParams->nBitPerSample = 16;
+ pcmParams->nBitPerSample = mBitsPerSample;
pcmParams->ePCMMode = OMX_AUDIO_PCMModeLinear;
pcmParams->eChannelMapping[0] = OMX_AUDIO_ChannelLF;
pcmParams->eChannelMapping[1] = OMX_AUDIO_ChannelRF;
@@ -166,6 +168,8 @@
mChannelCount = pcmParams->nChannels;
mSampleRate = pcmParams->nSamplingRate;
+ mNumericalData = pcmParams->eNumData;
+ mBitsPerSample = pcmParams->nBitPerSample;
return OMX_ErrorNone;
}
diff --git a/media/libstagefright/codecs/raw/SoftRaw.h b/media/libstagefright/codecs/raw/SoftRaw.h
index 015c4a3..80906b4 100644
--- a/media/libstagefright/codecs/raw/SoftRaw.h
+++ b/media/libstagefright/codecs/raw/SoftRaw.h
@@ -50,6 +50,8 @@
int32_t mChannelCount;
int32_t mSampleRate;
+ int32_t mNumericalData;
+ int32_t mBitsPerSample;
void initPorts();
status_t initDecoder();
diff --git a/media/libstagefright/codecs/vorbis/dec/SoftVorbis.cpp b/media/libstagefright/codecs/vorbis/dec/SoftVorbis.cpp
index 41d9d55..6a689c4 100644
--- a/media/libstagefright/codecs/vorbis/dec/SoftVorbis.cpp
+++ b/media/libstagefright/codecs/vorbis/dec/SoftVorbis.cpp
@@ -338,7 +338,13 @@
}
if (inHeader->nFilledLen || !mSawInputEos) {
- CHECK_GE(inHeader->nFilledLen, sizeof(numPageSamples));
+ if (inHeader->nFilledLen < sizeof(numPageSamples)) {
+ notify(OMX_EventError, OMX_ErrorBadParameter, 0, NULL);
+ mSignalledError = true;
+ ALOGE("onQueueFilled, input header has nFilledLen %u, expected %zu",
+ inHeader->nFilledLen, sizeof(numPageSamples));
+ return;
+ }
memcpy(&numPageSamples,
inHeader->pBuffer
+ inHeader->nOffset + inHeader->nFilledLen - 4,
diff --git a/media/libstagefright/foundation/AMessage.cpp b/media/libstagefright/foundation/AMessage.cpp
index 725a574..855ac95 100644
--- a/media/libstagefright/foundation/AMessage.cpp
+++ b/media/libstagefright/foundation/AMessage.cpp
@@ -749,6 +749,126 @@
}
}
+sp<AMessage> AMessage::changesFrom(const sp<const AMessage> &other, bool deep) const {
+ if (other == NULL) {
+ return const_cast<AMessage*>(this);
+ }
+
+ sp<AMessage> diff = new AMessage;
+ if (mWhat != other->mWhat) {
+ diff->setWhat(mWhat);
+ }
+ if (mHandler != other->mHandler) {
+ diff->setTarget(mHandler.promote());
+ }
+
+ for (size_t i = 0; i < mNumItems; ++i) {
+ const Item &item = mItems[i];
+ const Item *oitem = other->findItem(item.mName, item.mType);
+ switch (item.mType) {
+ case kTypeInt32:
+ if (oitem == NULL || item.u.int32Value != oitem->u.int32Value) {
+ diff->setInt32(item.mName, item.u.int32Value);
+ }
+ break;
+
+ case kTypeInt64:
+ if (oitem == NULL || item.u.int64Value != oitem->u.int64Value) {
+ diff->setInt64(item.mName, item.u.int64Value);
+ }
+ break;
+
+ case kTypeSize:
+ if (oitem == NULL || item.u.sizeValue != oitem->u.sizeValue) {
+ diff->setSize(item.mName, item.u.sizeValue);
+ }
+ break;
+
+ case kTypeFloat:
+ if (oitem == NULL || item.u.floatValue != oitem->u.floatValue) {
+ diff->setFloat(item.mName, item.u.sizeValue);
+ }
+ break;
+
+ case kTypeDouble:
+ if (oitem == NULL || item.u.doubleValue != oitem->u.doubleValue) {
+ diff->setDouble(item.mName, item.u.sizeValue);
+ }
+ break;
+
+ case kTypeString:
+ if (oitem == NULL || *item.u.stringValue != *oitem->u.stringValue) {
+ diff->setString(item.mName, *item.u.stringValue);
+ }
+ break;
+
+ case kTypeRect:
+ if (oitem == NULL || memcmp(&item.u.rectValue, &oitem->u.rectValue, sizeof(Rect))) {
+ diff->setRect(
+ item.mName, item.u.rectValue.mLeft, item.u.rectValue.mTop,
+ item.u.rectValue.mRight, item.u.rectValue.mBottom);
+ }
+ break;
+
+ case kTypePointer:
+ if (oitem == NULL || item.u.ptrValue != oitem->u.ptrValue) {
+ diff->setPointer(item.mName, item.u.ptrValue);
+ }
+ break;
+
+ case kTypeBuffer:
+ {
+ sp<ABuffer> myBuf = static_cast<ABuffer *>(item.u.refValue);
+ if (myBuf == NULL) {
+ if (oitem == NULL || oitem->u.refValue != NULL) {
+ diff->setBuffer(item.mName, NULL);
+ }
+ break;
+ }
+ sp<ABuffer> oBuf = oitem == NULL ? NULL : static_cast<ABuffer *>(oitem->u.refValue);
+ if (oBuf == NULL
+ || myBuf->size() != oBuf->size()
+ || (!myBuf->data() ^ !oBuf->data()) // data nullness differs
+ || (myBuf->data() && memcmp(myBuf->data(), oBuf->data(), myBuf->size()))) {
+ diff->setBuffer(item.mName, myBuf);
+ }
+ break;
+ }
+
+ case kTypeMessage:
+ {
+ sp<AMessage> myMsg = static_cast<AMessage *>(item.u.refValue);
+ if (myMsg == NULL) {
+ if (oitem == NULL || oitem->u.refValue != NULL) {
+ diff->setMessage(item.mName, NULL);
+ }
+ break;
+ }
+ sp<AMessage> oMsg =
+ oitem == NULL ? NULL : static_cast<AMessage *>(oitem->u.refValue);
+ sp<AMessage> changes = myMsg->changesFrom(oMsg, deep);
+ if (changes->countEntries()) {
+ diff->setMessage(item.mName, deep ? changes : myMsg);
+ }
+ break;
+ }
+
+ case kTypeObject:
+ if (oitem == NULL || item.u.refValue != oitem->u.refValue) {
+ diff->setObject(item.mName, item.u.refValue);
+ }
+ break;
+
+ default:
+ {
+ ALOGE("Unknown type %d", item.mType);
+ TRESPASS();
+ }
+ }
+ }
+ return diff;
+}
+
size_t AMessage::countEntries() const {
return mNumItems;
}
diff --git a/media/libstagefright/include/DataConverter.h b/media/libstagefright/include/DataConverter.h
new file mode 100644
index 0000000..8d67921
--- /dev/null
+++ b/media/libstagefright/include/DataConverter.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef STAGEFRIGHT_DATACONVERTER_H_
+#define STAGEFRIGHT_DATACONVERTER_H_
+
+#include <utils/Errors.h>
+#include <utils/RefBase.h>
+
+#include <media/stagefright/MediaDefs.h>
+
+namespace android {
+
+struct ABuffer;
+
+// DataConverter base class, defaults to memcpy
+struct DataConverter : public RefBase {
+ virtual size_t sourceSize(size_t targetSize); // will clamp to SIZE_MAX
+ virtual size_t targetSize(size_t sourceSize); // will clamp to SIZE_MAX
+
+ status_t convert(const sp<ABuffer> &source, sp<ABuffer> &target);
+ virtual ~DataConverter();
+
+protected:
+ virtual status_t safeConvert(const sp<ABuffer> &source, sp<ABuffer> &target);
+};
+
+// SampleConverterBase uses a ratio to calculate the source and target sizes
+// based on source and target sample sizes.
+struct SampleConverterBase : public DataConverter {
+ virtual size_t sourceSize(size_t targetSize);
+ virtual size_t targetSize(size_t sourceSize);
+
+protected:
+ virtual status_t safeConvert(const sp<ABuffer> &source, sp<ABuffer> &target) = 0;
+
+ // sourceSize = sourceSampleSize / targetSampleSize * targetSize
+ SampleConverterBase(uint32_t sourceSampleSize, uint32_t targetSampleSize)
+ : mSourceSampleSize(sourceSampleSize),
+ mTargetSampleSize(targetSampleSize) { }
+ size_t mSourceSampleSize;
+ size_t mTargetSampleSize;
+};
+
+// AudioConverter converts between audio PCM formats
+struct AudioConverter : public SampleConverterBase {
+ // return nullptr if conversion is not needed or not supported
+ static AudioConverter *Create(AudioEncoding source, AudioEncoding target);
+
+protected:
+ virtual status_t safeConvert(const sp<ABuffer> &src, sp<ABuffer> &tgt);
+
+private:
+ AudioConverter(
+ AudioEncoding source, size_t sourceSample,
+ AudioEncoding target, size_t targetSample)
+ : SampleConverterBase(sourceSample, targetSample),
+ mFrom(source),
+ mTo(target) { }
+ AudioEncoding mFrom;
+ AudioEncoding mTo;
+};
+
+} // namespace android
+
+#endif
diff --git a/media/libstagefright/include/MPEG2TSExtractor.h b/media/libstagefright/include/MPEG2TSExtractor.h
index e5c24ca..34b9606 100644
--- a/media/libstagefright/include/MPEG2TSExtractor.h
+++ b/media/libstagefright/include/MPEG2TSExtractor.h
@@ -25,6 +25,8 @@
#include <utils/KeyedVector.h>
#include <utils/Vector.h>
+#include "mpeg2ts/ATSParser.h"
+
namespace android {
struct AMessage;
@@ -55,6 +57,10 @@
sp<ATSParser> mParser;
+ // Used to remember SyncEvent occurred in feedMore() when called from init(),
+ // because init() needs to update |mSourceImpls| before adding SyncPoint.
+ ATSParser::SyncEvent mLastSyncEvent;
+
Vector<sp<AnotherPacketSource> > mSourceImpls;
Vector<KeyedVector<int64_t, off64_t> > mSyncPoints;
@@ -65,7 +71,14 @@
off64_t mOffset;
void init();
- status_t feedMore();
+ // Try to feed more data from source to parser.
+ // |isInit| means this function is called inside init(). This is a signal to
+ // save SyncEvent so that init() can add SyncPoint after it updates |mSourceImpls|.
+ // This function returns OK if expected amount of data is fed from DataSource to
+ // parser and is successfully parsed. Otherwise, various error codes could be
+ // returned, e.g., ERROR_END_OF_STREAM, or no data availalbe from DataSource, or
+ // the data has syntax error during parsing, etc.
+ status_t feedMore(bool isInit = false);
status_t seek(int64_t seekTimeUs,
const MediaSource::ReadOptions::SeekMode& seekMode);
status_t queueDiscontinuityForSeek(int64_t actualSeekTimeUs);
@@ -73,6 +86,9 @@
status_t feedUntilBufferAvailable(const sp<AnotherPacketSource> &impl);
+ // Add a SynPoint derived from |event|.
+ void addSyncPoint_l(const ATSParser::SyncEvent &event);
+
DISALLOW_EVIL_CONSTRUCTORS(MPEG2TSExtractor);
};
diff --git a/media/libstagefright/mpeg2ts/ATSParser.cpp b/media/libstagefright/mpeg2ts/ATSParser.cpp
index 2790a0e..fb43a38 100644
--- a/media/libstagefright/mpeg2ts/ATSParser.cpp
+++ b/media/libstagefright/mpeg2ts/ATSParser.cpp
@@ -122,7 +122,7 @@
void setPID(unsigned pid) { mElementaryPID = pid; }
// Parse the payload and set event when PES with a sync frame is detected.
- // This method knows when a PES starts; so record mPesStartOffset in that
+ // This method knows when a PES starts; so record mPesStartOffsets in that
// case.
status_t parse(
unsigned continuity_counter,
@@ -157,7 +157,7 @@
bool mEOSReached;
uint64_t mPrevPTS;
- off64_t mPesStartOffset;
+ List<off64_t> mPesStartOffsets;
ElementaryStreamQueue *mQueue;
@@ -205,16 +205,19 @@
};
ATSParser::SyncEvent::SyncEvent(off64_t offset)
- : mInit(false), mOffset(offset), mTimeUs(0) {}
+ : mHasReturnedData(false), mOffset(offset), mTimeUs(0) {}
void ATSParser::SyncEvent::init(off64_t offset, const sp<MediaSource> &source,
int64_t timeUs) {
- mInit = true;
+ mHasReturnedData = true;
mOffset = offset;
mMediaSource = source;
mTimeUs = timeUs;
}
+void ATSParser::SyncEvent::reset() {
+ mHasReturnedData = false;
+}
////////////////////////////////////////////////////////////////////////////////
ATSParser::Program::Program(
@@ -661,6 +664,7 @@
ALOGI("discontinuity on stream pid 0x%04x", mElementaryPID);
mPayloadStarted = false;
+ mPesStartOffsets.clear();
mBuffer->setRange(0, 0);
mExpectedContinuityCounter = -1;
@@ -697,7 +701,7 @@
}
mPayloadStarted = true;
- mPesStartOffset = offset;
+ mPesStartOffsets.push_back(offset);
}
if (!mPayloadStarted) {
@@ -772,6 +776,7 @@
}
mPayloadStarted = false;
+ mPesStartOffsets.clear();
mEOSReached = false;
mBuffer->setRange(0, 0);
@@ -1105,7 +1110,9 @@
int64_t timeUs;
if (accessUnit->meta()->findInt64("timeUs", &timeUs)) {
found = true;
- event->init(mPesStartOffset, mSource, timeUs);
+ off64_t pesStartOffset = *mPesStartOffsets.begin();
+ event->init(pesStartOffset, mSource, timeUs);
+ mPesStartOffsets.erase(mPesStartOffsets.begin());
}
}
}
diff --git a/media/libstagefright/mpeg2ts/ATSParser.h b/media/libstagefright/mpeg2ts/ATSParser.h
index 430a8d5..fb03cd6 100644
--- a/media/libstagefright/mpeg2ts/ATSParser.h
+++ b/media/libstagefright/mpeg2ts/ATSParser.h
@@ -69,16 +69,18 @@
void init(off64_t offset, const sp<MediaSource> &source,
int64_t timeUs);
- bool isInit() { return mInit; }
- off64_t getOffset() { return mOffset; }
- const sp<MediaSource> &getMediaSource() { return mMediaSource; }
- int64_t getTimeUs() { return mTimeUs; }
+ bool hasReturnedData() const { return mHasReturnedData; }
+ void reset();
+ off64_t getOffset() const { return mOffset; }
+ const sp<MediaSource> &getMediaSource() const { return mMediaSource; }
+ int64_t getTimeUs() const { return mTimeUs; }
private:
- bool mInit;
+ bool mHasReturnedData;
/*
- * mInit == false: the current offset
- * mInit == true: the start offset of sync payload
+ * mHasReturnedData == false: the current offset (or undefined if the returned data
+ has been invalidated via reset())
+ * mHasReturnedData == true: the start offset of sync payload
*/
off64_t mOffset;
/* The media source object for this event. */
diff --git a/media/libstagefright/mpeg2ts/MPEG2TSExtractor.cpp b/media/libstagefright/mpeg2ts/MPEG2TSExtractor.cpp
index 0b456c3..fb5e079 100644
--- a/media/libstagefright/mpeg2ts/MPEG2TSExtractor.cpp
+++ b/media/libstagefright/mpeg2ts/MPEG2TSExtractor.cpp
@@ -112,6 +112,7 @@
MPEG2TSExtractor::MPEG2TSExtractor(const sp<DataSource> &source)
: mDataSource(source),
mParser(new ATSParser),
+ mLastSyncEvent(0),
mOffset(0) {
init();
}
@@ -149,8 +150,10 @@
bool haveVideo = false;
int64_t startTime = ALooper::GetNowUs();
- while (feedMore() == OK) {
+ while (feedMore(true /* isInit */) == OK) {
if (haveAudio && haveVideo) {
+ addSyncPoint_l(mLastSyncEvent);
+ mLastSyncEvent.reset();
break;
}
if (!haveVideo) {
@@ -181,6 +184,9 @@
}
}
+ addSyncPoint_l(mLastSyncEvent);
+ mLastSyncEvent.reset();
+
// Wait only for 2 seconds to detect audio/video streams.
if (ALooper::GetNowUs() - startTime > 2000000ll) {
break;
@@ -245,7 +251,7 @@
haveAudio, haveVideo, ALooper::GetNowUs() - startTime);
}
-status_t MPEG2TSExtractor::feedMore() {
+status_t MPEG2TSExtractor::feedMore(bool isInit) {
Mutex::Autolock autoLock(mLock);
uint8_t packet[kTSPacketSize];
@@ -261,29 +267,41 @@
ATSParser::SyncEvent event(mOffset);
mOffset += n;
status_t err = mParser->feedTSPacket(packet, kTSPacketSize, &event);
- if (event.isInit()) {
- for (size_t i = 0; i < mSourceImpls.size(); ++i) {
- if (mSourceImpls[i].get() == event.getMediaSource().get()) {
- KeyedVector<int64_t, off64_t> *syncPoints = &mSyncPoints.editItemAt(i);
- syncPoints->add(event.getTimeUs(), event.getOffset());
- // We're keeping the size of the sync points at most 5mb per a track.
- size_t size = syncPoints->size();
- if (size >= 327680) {
- int64_t firstTimeUs = syncPoints->keyAt(0);
- int64_t lastTimeUs = syncPoints->keyAt(size - 1);
- if (event.getTimeUs() - firstTimeUs > lastTimeUs - event.getTimeUs()) {
- syncPoints->removeItemsAt(0, 4096);
- } else {
- syncPoints->removeItemsAt(size - 4096, 4096);
- }
- }
- break;
- }
+ if (event.hasReturnedData()) {
+ if (isInit) {
+ mLastSyncEvent = event;
+ } else {
+ addSyncPoint_l(event);
}
}
return err;
}
+void MPEG2TSExtractor::addSyncPoint_l(const ATSParser::SyncEvent &event) {
+ if (!event.hasReturnedData()) {
+ return;
+ }
+
+ for (size_t i = 0; i < mSourceImpls.size(); ++i) {
+ if (mSourceImpls[i].get() == event.getMediaSource().get()) {
+ KeyedVector<int64_t, off64_t> *syncPoints = &mSyncPoints.editItemAt(i);
+ syncPoints->add(event.getTimeUs(), event.getOffset());
+ // We're keeping the size of the sync points at most 5mb per a track.
+ size_t size = syncPoints->size();
+ if (size >= 327680) {
+ int64_t firstTimeUs = syncPoints->keyAt(0);
+ int64_t lastTimeUs = syncPoints->keyAt(size - 1);
+ if (event.getTimeUs() - firstTimeUs > lastTimeUs - event.getTimeUs()) {
+ syncPoints->removeItemsAt(0, 4096);
+ } else {
+ syncPoints->removeItemsAt(size - 4096, 4096);
+ }
+ }
+ break;
+ }
+ }
+}
+
uint32_t MPEG2TSExtractor::flags() const {
return CAN_PAUSE | CAN_SEEK_BACKWARD | CAN_SEEK_FORWARD;
}
diff --git a/media/mtp/MtpDevice.cpp b/media/mtp/MtpDevice.cpp
index a398aca..bd89a51 100644
--- a/media/mtp/MtpDevice.cpp
+++ b/media/mtp/MtpDevice.cpp
@@ -611,7 +611,7 @@
return NULL;
if (!readData())
return NULL;
- MtpResponseCode ret = readResponse();
+ const MtpResponseCode ret = readResponse();
if (ret == MTP_RESPONSE_OK) {
MtpProperty* property = new MtpProperty;
if (property->read(mData))
@@ -622,6 +622,25 @@
return NULL;
}
+bool MtpDevice::getObjectPropValue(MtpObjectHandle handle, MtpProperty* property) {
+ if (property == nullptr)
+ return false;
+
+ Mutex::Autolock autoLock(mMutex);
+
+ mRequest.reset();
+ mRequest.setParameter(1, handle);
+ mRequest.setParameter(2, property->getPropertyCode());
+ if (!sendRequest(MTP_OPERATION_GET_OBJECT_PROP_VALUE))
+ return false;
+ if (!readData())
+ return false;
+ if (readResponse() != MTP_RESPONSE_OK)
+ return false;
+ property->setCurrentValue(mData);
+ return true;
+}
+
bool MtpDevice::readObject(MtpObjectHandle handle,
ReadObjectCallback callback,
uint32_t expectedLength,
@@ -679,11 +698,6 @@
return false;
}
- if (mData.getContainerType() == MTP_CONTAINER_TYPE_RESPONSE) {
- mResponse.copyFrom(mData);
- return mResponse.getResponseCode() == MTP_RESPONSE_OK ? 0 : -1;
- }
-
// If object size 0 byte, the remote device can reply response packet
// without sending any data packets.
if (mData.getContainerType() == MTP_CONTAINER_TYPE_RESPONSE) {
diff --git a/media/mtp/MtpDevice.h b/media/mtp/MtpDevice.h
index ce60811..4be44cf 100644
--- a/media/mtp/MtpDevice.h
+++ b/media/mtp/MtpDevice.h
@@ -107,6 +107,9 @@
MtpProperty* getDevicePropDesc(MtpDeviceProperty code);
MtpProperty* getObjectPropDesc(MtpObjectProperty code, MtpObjectFormat format);
+ // Reads value of |property| for |handle|. Returns true on success.
+ bool getObjectPropValue(MtpObjectHandle handle, MtpProperty* property);
+
bool readObject(MtpObjectHandle handle, ReadObjectCallback callback,
uint32_t objectSize, void* clientData);
bool readObject(MtpObjectHandle handle, const char* destPath, int group,
diff --git a/media/mtp/MtpProperty.cpp b/media/mtp/MtpProperty.cpp
index 2be2d79..039e4f5 100644
--- a/media/mtp/MtpProperty.cpp
+++ b/media/mtp/MtpProperty.cpp
@@ -236,6 +236,12 @@
mCurrentValue.str = NULL;
}
+void MtpProperty::setCurrentValue(MtpDataPacket& packet) {
+ free(mCurrentValue.str);
+ mCurrentValue.str = NULL;
+ readValue(packet, mCurrentValue);
+}
+
void MtpProperty::setFormRange(int min, int max, int step) {
mFormFlag = kFormRange;
switch (mType) {
diff --git a/media/mtp/MtpProperty.h b/media/mtp/MtpProperty.h
index 2e2ead1..03c08e1 100644
--- a/media/mtp/MtpProperty.h
+++ b/media/mtp/MtpProperty.h
@@ -81,13 +81,16 @@
int defaultValue = 0);
virtual ~MtpProperty();
- inline MtpPropertyCode getPropertyCode() const { return mCode; }
+ MtpPropertyCode getPropertyCode() const { return mCode; }
+ MtpDataType getDataType() const { return mType; }
bool read(MtpDataPacket& packet);
void write(MtpDataPacket& packet);
void setDefaultValue(const uint16_t* string);
void setCurrentValue(const uint16_t* string);
+ void setCurrentValue(MtpDataPacket& packet);
+ const MtpPropertyValue& getCurrentValue() { return mCurrentValue; }
void setFormRange(int min, int max, int step);
void setFormEnum(const int* values, int count);
diff --git a/services/audioflinger/AutoPark.h b/services/audioflinger/AutoPark.h
new file mode 100644
index 0000000..e539e47
--- /dev/null
+++ b/services/audioflinger/AutoPark.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace android {
+
+// T is FastMixer or FastCapture
+template<typename T> class AutoPark {
+public:
+
+ // Park the specific FastThread, which can be nullptr, in hot idle if not currently idling
+ AutoPark(const sp<T>& fastThread) : mFastThread(fastThread)
+ {
+ mPreviousCommand = FastThreadState::HOT_IDLE;
+ if (fastThread != nullptr) {
+ auto sq = mFastThread->sq();
+ FastThreadState *state = sq->begin();
+ if (!(state->mCommand & FastThreadState::IDLE)) {
+ mPreviousCommand = state->mCommand;
+ state->mCommand = FastThreadState::HOT_IDLE;
+ sq->end();
+ sq->push(sq->BLOCK_UNTIL_ACKED);
+ } else {
+ sq->end(false /*didModify*/);
+ }
+ }
+ }
+
+ // Remove the FastThread from hot idle if necessary
+ ~AutoPark()
+ {
+ if (!(mPreviousCommand & FastThreadState::IDLE)) {
+ ALOG_ASSERT(mFastThread != nullptr);
+ auto sq = mFastThread->sq();
+ FastThreadState *state = sq->begin();
+ ALOG_ASSERT(state->mCommand == FastThreadState::HOT_IDLE);
+ state->mCommand = mPreviousCommand;
+ sq->end();
+ sq->push(sq->BLOCK_UNTIL_PUSHED);
+ }
+ }
+
+private:
+ const sp<T> mFastThread;
+ // if !&IDLE, holds the FastThread state to restore after new parameters processed
+ FastThreadState::Command mPreviousCommand;
+}; // class AutoPark
+
+} // namespace
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index 973c983..04cd91f 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -71,6 +71,8 @@
#include <cpustats/ThreadCpuUsage.h>
#endif
+#include "AutoPark.h"
+
// ----------------------------------------------------------------------------
// Note: the following macro is used for extremely verbose logging message. In
@@ -3283,31 +3285,9 @@
status_t AudioFlinger::MixerThread::createAudioPatch_l(const struct audio_patch *patch,
audio_patch_handle_t *handle)
{
- // if !&IDLE, holds the FastMixer state to restore after new parameters processed
- FastMixerState::Command previousCommand = FastMixerState::HOT_IDLE;
- if (mFastMixer != 0) {
- FastMixerStateQueue *sq = mFastMixer->sq();
- FastMixerState *state = sq->begin();
- if (!(state->mCommand & FastMixerState::IDLE)) {
- previousCommand = state->mCommand;
- state->mCommand = FastMixerState::HOT_IDLE;
- sq->end();
- sq->push(FastMixerStateQueue::BLOCK_UNTIL_ACKED);
- } else {
- sq->end(false /*didModify*/);
- }
- }
- status_t status = PlaybackThread::createAudioPatch_l(patch, handle);
+ AutoPark<FastMixer> park(mFastMixer);
- if (!(previousCommand & FastMixerState::IDLE)) {
- ALOG_ASSERT(mFastMixer != 0);
- FastMixerStateQueue *sq = mFastMixer->sq();
- FastMixerState *state = sq->begin();
- ALOG_ASSERT(state->mCommand == FastMixerState::HOT_IDLE);
- state->mCommand = previousCommand;
- sq->end();
- sq->push(FastMixerStateQueue::BLOCK_UNTIL_PUSHED);
- }
+ status_t status = PlaybackThread::createAudioPatch_l(patch, handle);
return status;
}
@@ -3390,33 +3370,10 @@
status_t AudioFlinger::MixerThread::releaseAudioPatch_l(const audio_patch_handle_t handle)
{
- // if !&IDLE, holds the FastMixer state to restore after new parameters processed
- FastMixerState::Command previousCommand = FastMixerState::HOT_IDLE;
- if (mFastMixer != 0) {
- FastMixerStateQueue *sq = mFastMixer->sq();
- FastMixerState *state = sq->begin();
- if (!(state->mCommand & FastMixerState::IDLE)) {
- previousCommand = state->mCommand;
- state->mCommand = FastMixerState::HOT_IDLE;
- sq->end();
- sq->push(FastMixerStateQueue::BLOCK_UNTIL_ACKED);
- } else {
- sq->end(false /*didModify*/);
- }
- }
+ AutoPark<FastMixer> park(mFastMixer);
status_t status = PlaybackThread::releaseAudioPatch_l(handle);
- if (!(previousCommand & FastMixerState::IDLE)) {
- ALOG_ASSERT(mFastMixer != 0);
- FastMixerStateQueue *sq = mFastMixer->sq();
- FastMixerState *state = sq->begin();
- ALOG_ASSERT(state->mCommand == FastMixerState::HOT_IDLE);
- state->mCommand = previousCommand;
- sq->end();
- sq->push(FastMixerStateQueue::BLOCK_UNTIL_PUSHED);
- }
-
return status;
}
@@ -4464,20 +4421,7 @@
status = NO_ERROR;
- // if !&IDLE, holds the FastMixer state to restore after new parameters processed
- FastMixerState::Command previousCommand = FastMixerState::HOT_IDLE;
- if (mFastMixer != 0) {
- FastMixerStateQueue *sq = mFastMixer->sq();
- FastMixerState *state = sq->begin();
- if (!(state->mCommand & FastMixerState::IDLE)) {
- previousCommand = state->mCommand;
- state->mCommand = FastMixerState::HOT_IDLE;
- sq->end();
- sq->push(FastMixerStateQueue::BLOCK_UNTIL_ACKED);
- } else {
- sq->end(false /*didModify*/);
- }
- }
+ AutoPark<FastMixer> park(mFastMixer);
AudioParameter param = AudioParameter(keyValuePair);
int value;
@@ -4572,16 +4516,6 @@
}
}
- if (!(previousCommand & FastMixerState::IDLE)) {
- ALOG_ASSERT(mFastMixer != 0);
- FastMixerStateQueue *sq = mFastMixer->sq();
- FastMixerState *state = sq->begin();
- ALOG_ASSERT(state->mCommand == FastMixerState::HOT_IDLE);
- state->mCommand = previousCommand;
- sq->end();
- sq->push(FastMixerStateQueue::BLOCK_UNTIL_PUSHED);
- }
-
return reconfig || a2dpDeviceChanged;
}
@@ -7057,6 +6991,10 @@
AudioParameter param = AudioParameter(keyValuePair);
int value;
+
+ // scope for AutoPark extends to end of method
+ AutoPark<FastCapture> park(mFastCapture);
+
// TODO Investigate when this code runs. Check with audio policy when a sample rate and
// channel count change can be requested. Do we mandate the first client defines the
// HAL sampling rate and channel count or do we allow changes on the fly?
diff --git a/services/audiopolicy/common/managerdefinitions/src/AudioPolicyMix.cpp b/services/audiopolicy/common/managerdefinitions/src/AudioPolicyMix.cpp
index 4af3d54..7ee98b6 100644
--- a/services/audiopolicy/common/managerdefinitions/src/AudioPolicyMix.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/AudioPolicyMix.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#define LOG_TAG "APM::AudioPolicyMix"
+#define LOG_TAG "APM_AudioPolicyMix"
//#define LOG_NDEBUG 0
#include "AudioPolicyMix.h"
@@ -107,6 +107,7 @@
status_t AudioPolicyMixCollection::getOutputForAttr(audio_attributes_t attributes, uid_t uid,
sp<SwAudioOutputDescriptor> &desc)
{
+ ALOGV("getOutputForAttr() querying %zu mixes:", size());
desc = 0;
for (size_t i = 0; i < size(); i++) {
sp<AudioPolicyMix> policyMix = valueAt(i);
@@ -129,7 +130,8 @@
// iterate over all mix criteria to list what rules this mix contains
for (size_t j = 0; j < mix->mCriteria.size(); j++) {
- ALOGV("getOutputForAttr: inspecting mix %zu of %zu", i, mix->mCriteria.size());
+ ALOGV(" getOutputForAttr: mix %zu: inspecting mix criteria %zu of %zu",
+ i, j, mix->mCriteria.size());
// if there is an address match, prioritize that match
if (strncmp(attributes.tags, "addr=", strlen("addr=")) == 0 &&
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index 6f52e35..ae8cf15 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#define LOG_TAG "AudioPolicyManager"
+#define LOG_TAG "APM_AudioPolicyManager"
//#define LOG_NDEBUG 0
//#define VERY_VERBOSE_LOGGING
@@ -2051,7 +2051,7 @@
String8 address = mixes[i].mDeviceAddress;
if (mPolicyMixes.registerMix(address, mixes[i], 0 /*output desc*/) != NO_ERROR) {
- ALOGE(" Error regisering mix %zu for address %s", i, address.string());
+ ALOGE(" Error registering mix %zu for address %s", i, address.string());
res = INVALID_OPERATION;
break;
}
@@ -2076,21 +2076,25 @@
address.string(), "remote-submix");
}
} else if ((mixes[i].mRouteFlags & MIX_ROUTE_FLAG_RENDER) == MIX_ROUTE_FLAG_RENDER) {
- ALOGV("registerPolicyMixes() mix %zu of %zu is RENDER", i, mixes.size());
String8 address = mixes[i].mDeviceAddress;
-
audio_devices_t device = mixes[i].mDeviceType;
+ ALOGV(" registerPolicyMixes() mix %zu of %zu is RENDER, dev=0x%X addr=%s",
+ i, mixes.size(), device, address.string());
+ bool foundOutput = false;
for (size_t j = 0 ; j < mOutputs.size() ; j++) {
sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(j);
sp<AudioPatch> patch = mAudioPatches.valueFor(desc->getPatchHandle());
if ((patch != 0) && (patch->mPatch.num_sinks != 0)
&& (patch->mPatch.sinks[0].type == AUDIO_PORT_TYPE_DEVICE)
&& (patch->mPatch.sinks[0].ext.device.type == device)
- && (patch->mPatch.sinks[0].ext.device.address == address)) {
+ && (strncmp(patch->mPatch.sinks[0].ext.device.address, address.string(),
+ AUDIO_DEVICE_MAX_ADDRESS_LEN) == 0)) {
if (mPolicyMixes.registerMix(address, mixes[i], desc) != NO_ERROR) {
res = INVALID_OPERATION;
+ } else {
+ foundOutput = true;
}
break;
}
@@ -2098,7 +2102,12 @@
if (res != NO_ERROR) {
ALOGE(" Error registering mix %zu for device 0x%X addr %s",
- i,device, address.string());
+ i, device, address.string());
+ res = INVALID_OPERATION;
+ break;
+ } else if (!foundOutput) {
+ ALOGE(" Output not found for mix %zu for device 0x%X addr %s",
+ i, device, address.string());
res = INVALID_OPERATION;
break;
}
@@ -5202,23 +5211,30 @@
// Modify the list of surround sound formats supported.
void AudioPolicyManager::filterSurroundFormats(FormatVector &formats) {
+ // TODO Change the ALOGIs to ALOGVs in this function after the feature is verified.
+
+ // TODO Set this based on Config properties.
+ const bool alwaysForceAC3 = true;
audio_policy_forced_cfg_t forceUse = mEngine->getForceUse(
AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND);
ALOGI("%s: forced use = %d", __FUNCTION__, forceUse);
// Analyze original support for various formats.
- bool supportsRawSurround = false;
+ bool supportsAC3 = false;
+ bool supportsOtherSurround = false;
bool supportsIEC61937 = false;
for (size_t formatIndex = 0; formatIndex < formats.size(); formatIndex++) {
audio_format_t format = formats[formatIndex];
- ALOGI("%s: original formats: %#x", __FUNCTION__, format);
+ ALOGI("%s: original formats: 0x%08x", __FUNCTION__, format);
switch (format) {
case AUDIO_FORMAT_AC3:
+ supportsAC3 = true;
+ break;
case AUDIO_FORMAT_E_AC3:
case AUDIO_FORMAT_DTS:
case AUDIO_FORMAT_DTS_HD:
- supportsRawSurround = true;
+ supportsOtherSurround = true;
break;
case AUDIO_FORMAT_IEC61937:
supportsIEC61937 = true;
@@ -5227,55 +5243,67 @@
break;
}
}
- ALOGI("%s: supportsRawSurround = %d, supportsIEC61937 = %d",
- __FUNCTION__, supportsRawSurround, supportsIEC61937);
+ ALOGI("%s: original, supportsAC3 = %d, supportsOtherSurround = %d, supportsIEC61937 = %d",
+ __FUNCTION__, supportsAC3, supportsOtherSurround, supportsIEC61937);
// Modify formats based on surround preferences.
// If NEVER, remove support for surround formats.
- if ((forceUse == AUDIO_POLICY_FORCE_ENCODED_SURROUND_NEVER)
- && (supportsRawSurround || supportsIEC61937)) {
- // Remove surround sound related formats.
- for (size_t formatIndex = 0; formatIndex < formats.size(); ) {
- audio_format_t format = formats[formatIndex];
- switch(format) {
- case AUDIO_FORMAT_AC3:
- case AUDIO_FORMAT_E_AC3:
- case AUDIO_FORMAT_DTS:
- case AUDIO_FORMAT_DTS_HD:
- case AUDIO_FORMAT_IEC61937:
- ALOGI("%s: remove %#x", __FUNCTION__, format);
- formats.removeAt(formatIndex);
- break;
- default:
- formatIndex++; // keep it
- break;
+ if (forceUse == AUDIO_POLICY_FORCE_ENCODED_SURROUND_NEVER) {
+ if (supportsAC3 || supportsOtherSurround || supportsIEC61937) {
+ // Remove surround sound related formats.
+ for (size_t formatIndex = 0; formatIndex < formats.size(); ) {
+ audio_format_t format = formats[formatIndex];
+ switch(format) {
+ case AUDIO_FORMAT_AC3:
+ case AUDIO_FORMAT_E_AC3:
+ case AUDIO_FORMAT_DTS:
+ case AUDIO_FORMAT_DTS_HD:
+ case AUDIO_FORMAT_IEC61937:
+ ALOGI("%s: remove format 0x%08x", __FUNCTION__, format);
+ formats.removeAt(formatIndex);
+ break;
+ default:
+ formatIndex++; // keep it
+ break;
+ }
}
+ supportsAC3 = false;
+ supportsOtherSurround = false;
+ supportsIEC61937 = false;
}
- supportsRawSurround = false;
- supportsIEC61937 = false;
- }
- // If ALWAYS, add support for raw surround formats if all are missing.
- // This assumes that if any of these formats are reported by the HAL
- // then the report is valid and should not be modified.
- if ((forceUse == AUDIO_POLICY_FORCE_ENCODED_SURROUND_ALWAYS)
- && !supportsRawSurround) {
- formats.add(AUDIO_FORMAT_AC3);
- formats.add(AUDIO_FORMAT_E_AC3);
- formats.add(AUDIO_FORMAT_DTS);
- formats.add(AUDIO_FORMAT_DTS_HD);
- supportsRawSurround = true;
- }
- // Add support for IEC61937 if raw surround supported.
- // The HAL could do this but add it here, just in case.
- if (supportsRawSurround && !supportsIEC61937) {
- formats.add(AUDIO_FORMAT_IEC61937);
- // supportsIEC61937 = true;
+ } else { // AUTO or ALWAYS
+ // Most TVs support AC3 even if they do not report it in the EDID.
+ if ((alwaysForceAC3 || (forceUse == AUDIO_POLICY_FORCE_ENCODED_SURROUND_ALWAYS))
+ && !supportsAC3) {
+ formats.add(AUDIO_FORMAT_AC3);
+ supportsAC3 = true;
+ }
+
+ // If ALWAYS, add support for raw surround formats if all are missing.
+ // This assumes that if any of these formats are reported by the HAL
+ // then the report is valid and should not be modified.
+ if ((forceUse == AUDIO_POLICY_FORCE_ENCODED_SURROUND_ALWAYS)
+ && !supportsOtherSurround) {
+ formats.add(AUDIO_FORMAT_E_AC3);
+ formats.add(AUDIO_FORMAT_DTS);
+ formats.add(AUDIO_FORMAT_DTS_HD);
+ supportsOtherSurround = true;
+ }
+
+ // Add support for IEC61937 if any raw surround supported.
+ // The HAL could do this but add it here, just in case.
+ if ((supportsAC3 || supportsOtherSurround) && !supportsIEC61937) {
+ formats.add(AUDIO_FORMAT_IEC61937);
+ supportsIEC61937 = true;
+ }
}
// Just for debugging.
for (size_t formatIndex = 0; formatIndex < formats.size(); formatIndex++) {
audio_format_t format = formats[formatIndex];
- ALOGI("%s: final formats: %#x", __FUNCTION__, format);
+ ALOGI("%s: final formats: 0x%08x", __FUNCTION__, format);
}
+ ALOGI("%s: final, supportsAC3 = %d, supportsOtherSurround = %d, supportsIEC61937 = %d",
+ __FUNCTION__, supportsAC3, supportsOtherSurround, supportsIEC61937);
}
void AudioPolicyManager::updateAudioProfiles(audio_io_handle_t ioHandle,
diff --git a/services/camera/libcameraservice/api1/client2/CaptureSequencer.cpp b/services/camera/libcameraservice/api1/client2/CaptureSequencer.cpp
index 61e1442..e3d6906 100644
--- a/services/camera/libcameraservice/api1/client2/CaptureSequencer.cpp
+++ b/services/camera/libcameraservice/api1/client2/CaptureSequencer.cpp
@@ -41,6 +41,7 @@
mNewAEState(false),
mNewFrameReceived(false),
mNewCaptureReceived(false),
+ mNewCaptureErrorCnt(0),
mShutterNotified(false),
mHalNotifiedShutter(false),
mShutterCaptureId(-1),
@@ -131,7 +132,7 @@
}
void CaptureSequencer::onCaptureAvailable(nsecs_t timestamp,
- sp<MemoryBase> captureBuffer) {
+ sp<MemoryBase> captureBuffer, bool captureError) {
ATRACE_CALL();
ALOGV("%s", __FUNCTION__);
Mutex::Autolock l(mInputMutex);
@@ -139,6 +140,11 @@
mCaptureBuffer = captureBuffer;
if (!mNewCaptureReceived) {
mNewCaptureReceived = true;
+ if (captureError) {
+ mNewCaptureErrorCnt++;
+ } else {
+ mNewCaptureErrorCnt = 0;
+ }
mNewCaptureSignal.signal();
}
}
@@ -623,6 +629,17 @@
break;
}
}
+ if (mNewCaptureReceived) {
+ if (mNewCaptureErrorCnt > kMaxRetryCount) {
+ ALOGW("Exceeding multiple retry limit of %d due to buffer drop", kMaxRetryCount);
+ return DONE;
+ } else if (mNewCaptureErrorCnt > 0) {
+ ALOGW("Capture error happened, retry %d...", mNewCaptureErrorCnt);
+ mNewCaptureReceived = false;
+ return STANDARD_CAPTURE;
+ }
+ }
+
if (mTimeoutCount <= 0) {
ALOGW("Timed out waiting for capture to complete");
return DONE;
diff --git a/services/camera/libcameraservice/api1/client2/CaptureSequencer.h b/services/camera/libcameraservice/api1/client2/CaptureSequencer.h
index b05207e..a7c61d2 100644
--- a/services/camera/libcameraservice/api1/client2/CaptureSequencer.h
+++ b/services/camera/libcameraservice/api1/client2/CaptureSequencer.h
@@ -69,7 +69,7 @@
virtual void onResultAvailable(const CaptureResult &result);
// Notifications from the JPEG processor
- void onCaptureAvailable(nsecs_t timestamp, sp<MemoryBase> captureBuffer);
+ void onCaptureAvailable(nsecs_t timestamp, sp<MemoryBase> captureBuffer, bool captureError);
void dump(int fd, const Vector<String16>& args);
@@ -94,6 +94,7 @@
Condition mNewFrameSignal;
bool mNewCaptureReceived;
+ int32_t mNewCaptureErrorCnt;
nsecs_t mCaptureTimestamp;
sp<MemoryBase> mCaptureBuffer;
Condition mNewCaptureSignal;
@@ -110,6 +111,7 @@
static const int kMaxTimeoutsForPrecaptureStart = 10; // 1 sec
static const int kMaxTimeoutsForPrecaptureEnd = 20; // 2 sec
static const int kMaxTimeoutsForCaptureEnd = 40; // 4 sec
+ static const int kMaxRetryCount = 3; // 3 retries in case of buffer drop
wp<Camera2Client> mClient;
wp<ZslProcessor> mZslProcessor;
diff --git a/services/camera/libcameraservice/api1/client2/JpegProcessor.cpp b/services/camera/libcameraservice/api1/client2/JpegProcessor.cpp
index e97618c..ffe96fc 100644
--- a/services/camera/libcameraservice/api1/client2/JpegProcessor.cpp
+++ b/services/camera/libcameraservice/api1/client2/JpegProcessor.cpp
@@ -42,7 +42,8 @@
mDevice(client->getCameraDevice()),
mSequencer(sequencer),
mId(client->getCameraId()),
- mCaptureAvailable(false),
+ mCaptureDone(false),
+ mCaptureSuccess(false),
mCaptureStreamId(NO_STREAM) {
}
@@ -53,9 +54,26 @@
void JpegProcessor::onFrameAvailable(const BufferItem& /*item*/) {
Mutex::Autolock l(mInputMutex);
- if (!mCaptureAvailable) {
- mCaptureAvailable = true;
- mCaptureAvailableSignal.signal();
+ ALOGV("%s", __FUNCTION__);
+ if (!mCaptureDone) {
+ mCaptureDone = true;
+ mCaptureSuccess = true;
+ mCaptureDoneSignal.signal();
+ }
+}
+
+void JpegProcessor::onBufferAcquired(const BufferInfo& /*bufferInfo*/) {
+ // Intentionally left empty
+}
+
+void JpegProcessor::onBufferReleased(const BufferInfo& bufferInfo) {
+ Mutex::Autolock l(mInputMutex);
+ ALOGV("%s", __FUNCTION__);
+
+ if (bufferInfo.mError) {
+ mCaptureDone = true;
+ mCaptureSuccess = false;
+ mCaptureDoneSignal.signal();
}
}
@@ -154,6 +172,12 @@
return res;
}
+ res = device->addBufferListenerForStream(mCaptureStreamId, this);
+ if (res != OK) {
+ ALOGE("%s: Camera %d: Can't add buffer listeneri: %s (%d)",
+ __FUNCTION__, mId, strerror(-res), res);
+ return res;
+ }
}
return OK;
}
@@ -192,24 +216,26 @@
bool JpegProcessor::threadLoop() {
status_t res;
+ bool captureSuccess = false;
{
Mutex::Autolock l(mInputMutex);
- while (!mCaptureAvailable) {
- res = mCaptureAvailableSignal.waitRelative(mInputMutex,
+
+ while (!mCaptureDone) {
+ res = mCaptureDoneSignal.waitRelative(mInputMutex,
kWaitDuration);
if (res == TIMED_OUT) return true;
}
- mCaptureAvailable = false;
+
+ captureSuccess = mCaptureSuccess;
+ mCaptureDone = false;
}
- do {
- res = processNewCapture();
- } while (res == OK);
+ res = processNewCapture(captureSuccess);
return true;
}
-status_t JpegProcessor::processNewCapture() {
+status_t JpegProcessor::processNewCapture(bool captureSuccess) {
ATRACE_CALL();
status_t res;
sp<Camera2Heap> captureHeap;
@@ -217,7 +243,7 @@
CpuConsumer::LockedBuffer imgBuffer;
- {
+ if (captureSuccess) {
Mutex::Autolock l(mInputMutex);
if (mCaptureStreamId == NO_STREAM) {
ALOGW("%s: Camera %d: No stream is available", __FUNCTION__, mId);
@@ -269,7 +295,7 @@
sp<CaptureSequencer> sequencer = mSequencer.promote();
if (sequencer != 0) {
- sequencer->onCaptureAvailable(imgBuffer.timestamp, captureBuffer);
+ sequencer->onCaptureAvailable(imgBuffer.timestamp, captureBuffer, !captureSuccess);
}
return OK;
diff --git a/services/camera/libcameraservice/api1/client2/JpegProcessor.h b/services/camera/libcameraservice/api1/client2/JpegProcessor.h
index ac6f5c7..7187ad9 100644
--- a/services/camera/libcameraservice/api1/client2/JpegProcessor.h
+++ b/services/camera/libcameraservice/api1/client2/JpegProcessor.h
@@ -41,7 +41,8 @@
* Still image capture output image processing
*/
class JpegProcessor:
- public Thread, public CpuConsumer::FrameAvailableListener {
+ public Thread, public CpuConsumer::FrameAvailableListener,
+ public camera3::Camera3StreamBufferListener {
public:
JpegProcessor(sp<Camera2Client> client, wp<CaptureSequencer> sequencer);
~JpegProcessor();
@@ -49,6 +50,10 @@
// CpuConsumer listener implementation
void onFrameAvailable(const BufferItem& item);
+ // Camera3StreamBufferListener implementation
+ void onBufferAcquired(const BufferInfo& bufferInfo) override;
+ void onBufferReleased(const BufferInfo& bufferInfo) override;
+
status_t updateStream(const Parameters ¶ms);
status_t deleteStream();
int getStreamId() const;
@@ -61,8 +66,9 @@
int mId;
mutable Mutex mInputMutex;
- bool mCaptureAvailable;
- Condition mCaptureAvailableSignal;
+ bool mCaptureDone;
+ bool mCaptureSuccess;
+ Condition mCaptureDoneSignal;
enum {
NO_STREAM = -1
@@ -75,7 +81,7 @@
virtual bool threadLoop();
- status_t processNewCapture();
+ status_t processNewCapture(bool captureSuccess);
size_t findJpegSize(uint8_t* jpegBuffer, size_t maxSize);
};
diff --git a/services/camera/libcameraservice/common/CameraDeviceBase.h b/services/camera/libcameraservice/common/CameraDeviceBase.h
index ccb3bc8..d570d4b 100644
--- a/services/camera/libcameraservice/common/CameraDeviceBase.h
+++ b/services/camera/libcameraservice/common/CameraDeviceBase.h
@@ -296,6 +296,12 @@
virtual status_t tearDown(int streamId) = 0;
/**
+ * Add buffer listener for a particular stream in the device.
+ */
+ virtual status_t addBufferListenerForStream(int streamId,
+ wp<camera3::Camera3StreamBufferListener> listener) = 0;
+
+ /**
* Prepare stream by preallocating up to maxCount buffers for it asynchronously.
* Calls notifyPrepared() once allocation is complete.
*/
diff --git a/services/camera/libcameraservice/device3/Camera3Device.cpp b/services/camera/libcameraservice/device3/Camera3Device.cpp
index 331f10d..1caf157 100644
--- a/services/camera/libcameraservice/device3/Camera3Device.cpp
+++ b/services/camera/libcameraservice/device3/Camera3Device.cpp
@@ -1652,6 +1652,26 @@
return stream->tearDown();
}
+status_t Camera3Device::addBufferListenerForStream(int streamId,
+ wp<Camera3StreamBufferListener> listener) {
+ ATRACE_CALL();
+ ALOGV("%s: Camera %d: Adding buffer listener for stream %d", __FUNCTION__, mId, streamId);
+ Mutex::Autolock il(mInterfaceLock);
+ Mutex::Autolock l(mLock);
+
+ sp<Camera3StreamInterface> stream;
+ ssize_t outputStreamIdx = mOutputStreams.indexOfKey(streamId);
+ if (outputStreamIdx == NAME_NOT_FOUND) {
+ CLOGE("Stream %d does not exist", streamId);
+ return BAD_VALUE;
+ }
+
+ stream = mOutputStreams.editValueAt(outputStreamIdx);
+ stream->addBufferListener(listener);
+
+ return OK;
+}
+
uint32_t Camera3Device::getDeviceVersion() {
ATRACE_CALL();
Mutex::Autolock il(mInterfaceLock);
diff --git a/services/camera/libcameraservice/device3/Camera3Device.h b/services/camera/libcameraservice/device3/Camera3Device.h
index ba092d0..96ca7b7 100644
--- a/services/camera/libcameraservice/device3/Camera3Device.h
+++ b/services/camera/libcameraservice/device3/Camera3Device.h
@@ -146,6 +146,9 @@
virtual status_t tearDown(int streamId);
+ virtual status_t addBufferListenerForStream(int streamId,
+ wp<camera3::Camera3StreamBufferListener> listener);
+
virtual status_t prepare(int maxCount, int streamId);
virtual uint32_t getDeviceVersion();
diff --git a/services/camera/libcameraservice/device3/Camera3Stream.cpp b/services/camera/libcameraservice/device3/Camera3Stream.cpp
index 50f7a91..a4714a7 100644
--- a/services/camera/libcameraservice/device3/Camera3Stream.cpp
+++ b/services/camera/libcameraservice/device3/Camera3Stream.cpp
@@ -560,7 +560,7 @@
}
void Camera3Stream::fireBufferListenersLocked(
- const camera3_stream_buffer& /*buffer*/, bool acquired, bool output) {
+ const camera3_stream_buffer& buffer, bool acquired, bool output) {
List<wp<Camera3StreamBufferListener> >::iterator it, end;
// TODO: finish implementing
@@ -568,6 +568,7 @@
Camera3StreamBufferListener::BufferInfo info =
Camera3StreamBufferListener::BufferInfo();
info.mOutput = output;
+ info.mError = (buffer.status == CAMERA3_BUFFER_STATUS_ERROR);
// TODO: rest of fields
for (it = mBufferListenerList.begin(), end = mBufferListenerList.end();
diff --git a/services/camera/libcameraservice/device3/Camera3StreamBufferListener.h b/services/camera/libcameraservice/device3/Camera3StreamBufferListener.h
index 62ea6c0..2db333d 100644
--- a/services/camera/libcameraservice/device3/Camera3StreamBufferListener.h
+++ b/services/camera/libcameraservice/device3/Camera3StreamBufferListener.h
@@ -34,6 +34,7 @@
uint32_t mScalingMode;
int64_t mTimestamp;
uint64_t mFrameNumber;
+ bool mError;
};
// Buffer was acquired by the HAL
diff --git a/services/mediacodec/minijail/seccomp_policy/mediacodec-seccomp-arm.policy b/services/mediacodec/minijail/seccomp_policy/mediacodec-seccomp-arm.policy
index 4be96d5..0afaa15 100644
--- a/services/mediacodec/minijail/seccomp_policy/mediacodec-seccomp-arm.policy
+++ b/services/mediacodec/minijail/seccomp_policy/mediacodec-seccomp-arm.policy
@@ -40,6 +40,7 @@
statfs64: 1
sched_setscheduler: 1
fstatat64: 1
+ugetrlimit: 1
# for attaching to debuggerd on process crash
sigaction: 1
@@ -47,3 +48,4 @@
socket: 1
connect: 1
fcntl64: 1
+rt_tgsigqueueinfo: 1
diff --git a/services/mediaextractor/minijail/seccomp_policy/mediaextractor-seccomp-arm.policy b/services/mediaextractor/minijail/seccomp_policy/mediaextractor-seccomp-arm.policy
index 5bbd4e3..cc9a580 100644
--- a/services/mediaextractor/minijail/seccomp_policy/mediaextractor-seccomp-arm.policy
+++ b/services/mediaextractor/minijail/seccomp_policy/mediaextractor-seccomp-arm.policy
@@ -32,6 +32,7 @@
gettid: 1
rt_sigprocmask: 1
sched_yield: 1
+ugetrlimit: 1
# for attaching to debuggerd on process crash
sigaction: 1
@@ -39,3 +40,4 @@
socket: 1
connect: 1
fcntl64: 1
+rt_tgsigqueueinfo: 1
diff --git a/services/mediaextractor/minijail/seccomp_policy/mediaextractor-seccomp-x86.policy b/services/mediaextractor/minijail/seccomp_policy/mediaextractor-seccomp-x86.policy
index 3d258c7..516ca60 100644
--- a/services/mediaextractor/minijail/seccomp_policy/mediaextractor-seccomp-x86.policy
+++ b/services/mediaextractor/minijail/seccomp_policy/mediaextractor-seccomp-x86.policy
@@ -29,6 +29,8 @@
rt_sigreturn: 1
faccessat: 1
sched_setscheduler: 1
+ugetrlimit: 1
+getrlimit: 1
# for attaching to debuggerd on process crash
socketcall: 1
@@ -36,3 +38,4 @@
tgkill: 1
rt_sigprocmask: 1
fcntl64: 1
+rt_tgsigqueueinfo: 1
diff --git a/services/mediaresourcemanager/ResourceManagerService.cpp b/services/mediaresourcemanager/ResourceManagerService.cpp
index e1235b8..64534bf 100644
--- a/services/mediaresourcemanager/ResourceManagerService.cpp
+++ b/services/mediaresourcemanager/ResourceManagerService.cpp
@@ -96,8 +96,11 @@
if (binder != NULL) {
sp<IMediaResourceMonitor> service = interface_cast<IMediaResourceMonitor>(binder);
for (size_t i = 0; i < resources.size(); ++i) {
- service->notifyResourceGranted(pid, String16(asString(resources[i].mType)),
- String16(asString(resources[i].mSubType)), resources[i].mValue);
+ if (resources[i].mSubType == MediaResource::kAudioCodec) {
+ service->notifyResourceGranted(pid, IMediaResourceMonitor::TYPE_AUDIO_CODEC);
+ } else if (resources[i].mSubType == MediaResource::kVideoCodec) {
+ service->notifyResourceGranted(pid, IMediaResourceMonitor::TYPE_VIDEO_CODEC);
+ }
}
}
}