Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…orks_av into marshmallow
  • Loading branch information
Flyhalf205 committed May 26, 2017
2 parents 02d1eff + 54b384f commit 52d6a4d
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 27 deletions.
2 changes: 1 addition & 1 deletion media/libstagefright/AMRExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ status_t AMRSource::read(

int64_t seekTimeUs;
ReadOptions::SeekMode mode;
if (options && options->getSeekTo(&seekTimeUs, &mode)) {
if (mOffsetTableLength > 0 && options && options->getSeekTo(&seekTimeUs, &mode)) {
size_t size;
int64_t seekFrame = seekTimeUs / 20000ll; // 20ms per frame.
mCurrentTimeUs = seekFrame * 20000ll;
Expand Down
2 changes: 1 addition & 1 deletion media/libstagefright/NuMediaExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ bool NuMediaExtractor::getTotalBitrate(int64_t *bitrate) const {
}

off64_t size;
if (mDurationUs >= 0 && mDataSource->getSize(&size) == OK) {
if (mDurationUs > 0 && mDataSource->getSize(&size) == OK) {
*bitrate = size * 8000000ll / mDurationUs; // in bits/sec
return true;
}
Expand Down
14 changes: 12 additions & 2 deletions media/libstagefright/codecs/aacenc/SoftAACEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ SoftAACEncoder::SoftAACEncoder(
}

SoftAACEncoder::~SoftAACEncoder() {
delete[] mInputFrame;
mInputFrame = NULL;
onReset();

if (mEncoderHandle) {
CHECK_EQ(VO_ERR_NONE, mApiHandle->Uninit(mEncoderHandle));
Expand Down Expand Up @@ -579,6 +578,17 @@ void SoftAACEncoder::onQueueFilled(OMX_U32 portIndex) {
}
}

void SoftAACEncoder::onReset() {
delete[] mInputFrame;
mInputFrame = NULL;
mInputSize = 0;

mSentCodecSpecificData = false;
mInputTimeUs = -1ll;
mSawInputEOS = false;
mSignalledError = false;
}

} // namespace android

android::SoftOMXComponent *createSoftOMXComponent(
Expand Down
2 changes: 2 additions & 0 deletions media/libstagefright/codecs/aacenc/SoftAACEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ struct SoftAACEncoder : public SimpleSoftOMXComponent {

virtual void onQueueFilled(OMX_U32 portIndex);

virtual void onReset();

private:
enum {
kNumBuffers = 4,
Expand Down
23 changes: 21 additions & 2 deletions media/libstagefright/codecs/aacenc/SoftAACEncoder2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ SoftAACEncoder2::SoftAACEncoder2(
SoftAACEncoder2::~SoftAACEncoder2() {
aacEncClose(&mAACEncoder);

delete[] mInputFrame;
mInputFrame = NULL;
onReset();
}

void SoftAACEncoder2::initPorts() {
Expand Down Expand Up @@ -478,6 +477,15 @@ void SoftAACEncoder2::onQueueFilled(OMX_U32 /* portIndex */) {

BufferInfo *outInfo = *outQueue.begin();
OMX_BUFFERHEADERTYPE *outHeader = outInfo->mHeader;

if (outHeader->nOffset + encInfo.confSize > outHeader->nAllocLen) {
ALOGE("b/34617444");
android_errorWriteLog(0x534e4554,"34617444");
notify(OMX_EventError, OMX_ErrorUndefined, 0, NULL);
mSignalledError = true;
return;
}

outHeader->nFilledLen = encInfo.confSize;
outHeader->nFlags = OMX_BUFFERFLAG_CODECCONFIG;

Expand Down Expand Up @@ -670,6 +678,17 @@ void SoftAACEncoder2::onQueueFilled(OMX_U32 /* portIndex */) {
}
}

void SoftAACEncoder2::onReset() {
delete[] mInputFrame;
mInputFrame = NULL;
mInputSize = 0;

mSentCodecSpecificData = false;
mInputTimeUs = -1ll;
mSawInputEOS = false;
mSignalledError = false;
}

} // namespace android

android::SoftOMXComponent *createSoftOMXComponent(
Expand Down
2 changes: 2 additions & 0 deletions media/libstagefright/codecs/aacenc/SoftAACEncoder2.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ struct SoftAACEncoder2 : public SimpleSoftOMXComponent {

virtual void onQueueFilled(OMX_U32 portIndex);

virtual void onReset();

private:
enum {
kNumBuffers = 4,
Expand Down
18 changes: 17 additions & 1 deletion media/libstagefright/codecs/m4v_h263/dec/src/mb_motion_comp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
* and limitations under the License.
* -------------------------------------------------------------------
*/

#define LOG_TAG "m4v_h263"
#include <log/log.h>

/*
------------------------------------------------------------------------------
INPUT AND OUTPUT DEFINITIONS
Expand Down Expand Up @@ -236,6 +240,11 @@ void MBMotionComp(

/* Pointer to previous luminance frame */
c_prev = prev->yChan;
if (!c_prev) {
ALOGE("b/35269635");
android_errorWriteLog(0x534e4554, "35269635");
return;
}

pred_block = video->mblock->pred_block;

Expand Down Expand Up @@ -574,7 +583,14 @@ void SkippedMBMotionComp(

/* zero motion compensation for previous frame */
/*mby*width + mbx;*/
c_prev = prev->yChan + offset;
c_prev = prev->yChan;
if (!c_prev) {
ALOGE("b/35269635");
android_errorWriteLog(0x534e4554, "35269635");
return;
}
c_prev += offset;

/*by*width_uv + bx;*/
cu_prev = prev->uChan + (offset >> 2) + (xpos >> 2);
/*by*width_uv + bx;*/
Expand Down
7 changes: 7 additions & 0 deletions media/libstagefright/codecs/m4v_h263/dec/src/pvdec_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* and limitations under the License.
* -------------------------------------------------------------------
*/
#define LOG_TAG "pvdec_api"
#include <log/log.h>
#include "mp4dec_lib.h"
#include "vlc_decode.h"
#include "bitstream.h"
Expand Down Expand Up @@ -1335,6 +1337,11 @@ Bool PVDecodeVopBody(VideoDecControls *decCtrl, int32 buffer_size[])
}
}

if (!video->prevVop->yChan) {
ALOGE("b/35269635");
android_errorWriteLog(0x534e4554, "35269635");
return PV_FALSE;
}
oscl_memcpy(currVop->yChan, video->prevVop->yChan, (decCtrl->size*3) / 2);

video->prevVop = prevVop;
Expand Down
35 changes: 21 additions & 14 deletions media/libstagefright/codecs/m4v_h263/enc/SoftMPEG4Encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ SoftMPEG4Encoder::SoftMPEG4Encoder(

SoftMPEG4Encoder::~SoftMPEG4Encoder() {
ALOGV("Destruct SoftMPEG4Encoder");
onReset();
releaseEncoder();
List<BufferInfo *> &outQueue = getPortQueue(1);
List<BufferInfo *> &inQueue = getPortQueue(0);
Expand Down Expand Up @@ -208,22 +209,15 @@ OMX_ERRORTYPE SoftMPEG4Encoder::initEncoder() {
}

OMX_ERRORTYPE SoftMPEG4Encoder::releaseEncoder() {
if (!mStarted) {
return OMX_ErrorNone;
if (mEncParams) {
delete mEncParams;
mEncParams = NULL;
}

PVCleanUpVideoEncoder(mHandle);

free(mInputFrameData);
mInputFrameData = NULL;

delete mEncParams;
mEncParams = NULL;

delete mHandle;
mHandle = NULL;

mStarted = false;
if (mHandle) {
delete mHandle;
mHandle = NULL;
}

return OMX_ErrorNone;
}
Expand Down Expand Up @@ -519,6 +513,19 @@ void SoftMPEG4Encoder::onQueueFilled(OMX_U32 /* portIndex */) {
}
}

void SoftMPEG4Encoder::onReset() {
if (!mStarted) {
return;
}

PVCleanUpVideoEncoder(mHandle);

free(mInputFrameData);
mInputFrameData = NULL;

mStarted = false;
}

} // namespace android

android::SoftOMXComponent *createSoftOMXComponent(
Expand Down
2 changes: 2 additions & 0 deletions media/libstagefright/codecs/m4v_h263/enc/SoftMPEG4Encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ struct SoftMPEG4Encoder : public SoftVideoEncoderOMXComponent {

virtual void onQueueFilled(OMX_U32 portIndex);

virtual void onReset();

protected:
virtual ~SoftMPEG4Encoder();

Expand Down
9 changes: 8 additions & 1 deletion media/libstagefright/codecs/on2/enc/SoftVPXEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,9 @@ void SoftVPXEncoder::onQueueFilled(OMX_U32 /* portIndex */) {
if (inputBufferHeader->nTimeStamp > mLastTimestamp) {
frameDuration = (uint32_t)(inputBufferHeader->nTimeStamp - mLastTimestamp);
} else {
frameDuration = (uint32_t)(((uint64_t)1000000 << 16) / mFramerate);
// Use default of 30 fps in case of 0 frame rate.
uint32_t framerate = mFramerate ?: (30 << 16);
frameDuration = (uint32_t)(((uint64_t)1000000 << 16) / framerate);
}
mLastTimestamp = inputBufferHeader->nTimeStamp;
codec_return = vpx_codec_encode(
Expand Down Expand Up @@ -842,6 +844,11 @@ void SoftVPXEncoder::onQueueFilled(OMX_U32 /* portIndex */) {
}
}

void SoftVPXEncoder::onReset() {
releaseEncoder();
mLastTimestamp = 0x7FFFFFFFFFFFFFFFLL;
}

} // namespace android


Expand Down
2 changes: 2 additions & 0 deletions media/libstagefright/codecs/on2/enc/SoftVPXEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ struct SoftVPXEncoder : public SoftVideoEncoderOMXComponent {
// encoding of the frame
virtual void onQueueFilled(OMX_U32 portIndex);

virtual void onReset();

private:
enum TemporalReferences {
// For 1 layer case: reference all (last, golden, and alt ref), but only
Expand Down
12 changes: 8 additions & 4 deletions media/libstagefright/id3/ID3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ bool ID3::removeUnsynchronizationV2_4(bool iTunesHack) {
flags &= ~1;
}

if (flags & 2) {
if ((flags & 2) && (dataSize >= 2)) {
// This file has "unsynchronization", so we have to replace occurrences
// of 0xff 0x00 with just 0xff in order to get the real data.

Expand All @@ -395,11 +395,15 @@ bool ID3::removeUnsynchronizationV2_4(bool iTunesHack) {
mData[writeOffset++] = mData[readOffset++];
}
// move the remaining data following this frame
memmove(&mData[writeOffset], &mData[readOffset], oldSize - readOffset);
if (readOffset <= oldSize) {
memmove(&mData[writeOffset], &mData[readOffset], oldSize - readOffset);
} else {
ALOGE("b/34618607 (%zu %zu %zu %zu)", readOffset, writeOffset, oldSize, mSize);
android_errorWriteLog(0x534e4554, "34618607");
}

flags &= ~2;
}

flags &= ~2;
if (flags != prevFlags || iTunesHack) {
WriteSyncsafeInteger(&mData[offset + 4], dataSize);
mData[offset + 8] = flags >> 8;
Expand Down
17 changes: 16 additions & 1 deletion services/audioflinger/Tracks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,24 @@ AudioFlinger::ThreadBase::TrackBase::TrackBase(
mUid = clientUid;

// ALOGD("Creating track with %d buffers @ %d bytes", bufferCount, bufferSize);

size_t bufferSize = buffer == NULL ? roundup(frameCount) : frameCount;
// check overflow when computing bufferSize due to multiplication by mFrameSize.
if (bufferSize < frameCount // roundup rounds down for values above UINT_MAX / 2
|| mFrameSize == 0 // format needs to be correct
|| bufferSize > SIZE_MAX / mFrameSize) {
android_errorWriteLog(0x534e4554, "34749571");
return;
}
bufferSize *= mFrameSize;

size_t size = sizeof(audio_track_cblk_t);
size_t bufferSize = (buffer == NULL ? roundup(frameCount) : frameCount) * mFrameSize;
if (buffer == NULL && alloc == ALLOC_CBLK) {
// check overflow when computing allocation size for streaming tracks.
if (size > SIZE_MAX - bufferSize) {
android_errorWriteLog(0x534e4554, "34749571");
return;
}
size += bufferSize;
}

Expand Down

0 comments on commit 52d6a4d

Please sign in to comment.