Merge "MPEG2TSWriter: Write a proper CRC in PAT and PMT"
diff --git a/include/media/stagefright/MPEG4Writer.h b/include/media/stagefright/MPEG4Writer.h
index cd4e129..3596b38 100644
--- a/include/media/stagefright/MPEG4Writer.h
+++ b/include/media/stagefright/MPEG4Writer.h
@@ -186,6 +186,8 @@
void release();
status_t reset();
+ static uint32_t getMpeg4Time();
+
MPEG4Writer(const MPEG4Writer &);
MPEG4Writer &operator=(const MPEG4Writer &);
};
diff --git a/libvideoeditor/vss/stagefrightshells/src/VideoEditorBuffer.c b/libvideoeditor/vss/stagefrightshells/src/VideoEditorBuffer.c
index 98919d2..f4cfa7c 100755
--- a/libvideoeditor/vss/stagefrightshells/src/VideoEditorBuffer.c
+++ b/libvideoeditor/vss/stagefrightshells/src/VideoEditorBuffer.c
@@ -53,6 +53,7 @@
{
M4OSA_ERR lerr = M4NO_ERROR;
VIDEOEDITOR_BUFFER_Pool* pool;
+ M4OSA_UInt32 index;
ALOGV("VIDEOEDITOR_BUFFER_allocatePool : ppool = 0x%x nbBuffers = %d ",
ppool, nbBuffers);
@@ -79,6 +80,11 @@
goto VIDEOEDITOR_BUFFER_allocatePool_Cleanup;
}
+ for (index = 0; index < nbBuffers; index++)
+ {
+ pool->pNXPBuffer[index].pData = M4OSA_NULL;
+ }
+
ALOGV("VIDEOEDITOR_BUFFER_allocatePool : Allocating Pool name buffer");
pool->poolName = M4OSA_NULL;
pool->poolName = (M4OSA_Char*)M4OSA_32bitAlignedMalloc(
diff --git a/media/libstagefright/MPEG4Writer.cpp b/media/libstagefright/MPEG4Writer.cpp
index 755b502..6108298 100755
--- a/media/libstagefright/MPEG4Writer.cpp
+++ b/media/libstagefright/MPEG4Writer.cpp
@@ -236,11 +236,11 @@
void writeDrefBox();
void writeDinfBox();
void writeDamrBox();
- void writeMdhdBox(time_t now);
+ void writeMdhdBox(uint32_t now);
void writeSmhdBox();
void writeVmhdBox();
void writeHdlrBox();
- void writeTkhdBox(time_t now);
+ void writeTkhdBox(uint32_t now);
void writeMp4aEsdsBox();
void writeMp4vEsdsBox();
void writeAudioFourCCBox();
@@ -723,8 +723,17 @@
return err;
}
-void MPEG4Writer::writeMvhdBox(int64_t durationUs) {
+uint32_t MPEG4Writer::getMpeg4Time() {
time_t now = time(NULL);
+ // MP4 file uses time counting seconds since midnight, Jan. 1, 1904
+ // while time function returns Unix epoch values which starts
+ // at 1970-01-01. Lets add the number of seconds between them
+ uint32_t mpeg4Time = now + (66 * 365 + 17) * (24 * 60 * 60);
+ return mpeg4Time;
+}
+
+void MPEG4Writer::writeMvhdBox(int64_t durationUs) {
+ uint32_t now = getMpeg4Time();
beginBox("mvhd");
writeInt32(0); // version=0, flags=0
writeInt32(now); // creation time
@@ -2357,7 +2366,7 @@
ALOGV("%s track time scale: %d",
mIsAudio? "Audio": "Video", mTimeScale);
- time_t now = time(NULL);
+ uint32_t now = getMpeg4Time();
mOwner->beginBox("trak");
writeTkhdBox(now);
mOwner->beginBox("mdia");
@@ -2570,7 +2579,7 @@
mOwner->endBox(); // esds
}
-void MPEG4Writer::Track::writeTkhdBox(time_t now) {
+void MPEG4Writer::Track::writeTkhdBox(uint32_t now) {
mOwner->beginBox("tkhd");
// Flags = 7 to indicate that the track is enabled, and
// part of the presentation
@@ -2639,7 +2648,7 @@
mOwner->endBox();
}
-void MPEG4Writer::Track::writeMdhdBox(time_t now) {
+void MPEG4Writer::Track::writeMdhdBox(uint32_t now) {
int64_t trakDurationUs = getDurationUs();
mOwner->beginBox("mdhd");
mOwner->writeInt32(0); // version=0, flags=0
diff --git a/media/libstagefright/MediaCodec.cpp b/media/libstagefright/MediaCodec.cpp
index ff71170..d28322f 100644
--- a/media/libstagefright/MediaCodec.cpp
+++ b/media/libstagefright/MediaCodec.cpp
@@ -1118,7 +1118,8 @@
CHECK(msg->senderAwaitsResponse(&replyID));
if ((mState != STARTED && mState != FLUSHING)
- || (mFlags & kFlagStickyError)) {
+ || (mFlags & kFlagStickyError)
+ || mOutputFormat == NULL) {
sp<AMessage> response = new AMessage;
response->setInt32("err", INVALID_OPERATION);
diff --git a/media/libstagefright/codecs/avc/common/include/avcapi_common.h b/media/libstagefright/codecs/avc/common/include/avcapi_common.h
index 3331689..abffe6e 100644
--- a/media/libstagefright/codecs/avc/common/include/avcapi_common.h
+++ b/media/libstagefright/codecs/avc/common/include/avcapi_common.h
@@ -213,15 +213,15 @@
memory usage.
\param "size" "Size of requested memory in bytes."
\param "attribute" "Some value specifying types, priority, etc. of the memory."
-\return "The address of the allocated memory casted to int"
+\return "The address of the allocated, zero-initialized memory"
*/
-typedef int (*FunctionType_Malloc)(void *userData, int32 size, int attribute);
+typedef void* (*FunctionType_Malloc)(void *userData, int32 size, int attribute);
/** Function pointer to free
-\param "mem" "Pointer to the memory to be freed casted to int"
+\param "mem" "Pointer to the memory to be freed"
\return "void"
*/
-typedef void (*FunctionType_Free)(void *userData, int mem);
+typedef void (*FunctionType_Free)(void *userData, void *mem);
/** Debug logging information is returned to the application thru this function.
\param "type" "Type of logging message, see definition of AVCLogType."
diff --git a/media/libstagefright/codecs/avc/common/src/dpb.cpp b/media/libstagefright/codecs/avc/common/src/dpb.cpp
index 2c4c7da..b5d0dfe 100644
--- a/media/libstagefright/codecs/avc/common/src/dpb.cpp
+++ b/media/libstagefright/codecs/avc/common/src/dpb.cpp
@@ -152,7 +152,7 @@
framesize = (FrameHeightInMbs * PicWidthInMbs);
if (video->mblock)
{
- avcHandle->CBAVC_Free(userData, (uint32)video->mblock);
+ avcHandle->CBAVC_Free(userData, video->mblock);
video->mblock = NULL;
}
video->mblock = (AVCMacroblock*) avcHandle->CBAVC_Malloc(userData, sizeof(AVCMacroblock) * framesize, DEFAULT_ATTR);
@@ -187,7 +187,7 @@
if (video->MbToSliceGroupMap)
{
- avcHandle->CBAVC_Free(userData, (uint32)video->MbToSliceGroupMap);
+ avcHandle->CBAVC_Free(userData, video->MbToSliceGroupMap);
video->MbToSliceGroupMap = NULL;
}
video->MbToSliceGroupMap = (int*) avcHandle->CBAVC_Malloc(userData, sizeof(uint) * PicSizeInMapUnits * 2, 7/*DEFAULT_ATTR*/);
@@ -212,14 +212,14 @@
{
if (dpb->fs[ii] != NULL)
{
- avcHandle->CBAVC_Free(userData, (int)dpb->fs[ii]);
+ avcHandle->CBAVC_Free(userData, dpb->fs[ii]);
dpb->fs[ii] = NULL;
}
}
#ifndef PV_MEMORY_POOL
if (dpb->decoded_picture_buffer)
{
- avcHandle->CBAVC_Free(userData, (int)dpb->decoded_picture_buffer);
+ avcHandle->CBAVC_Free(userData, dpb->decoded_picture_buffer);
dpb->decoded_picture_buffer = NULL;
}
#endif
diff --git a/media/libstagefright/codecs/avc/enc/SoftAVCEncoder.cpp b/media/libstagefright/codecs/avc/enc/SoftAVCEncoder.cpp
index c6f658d..259562b 100644
--- a/media/libstagefright/codecs/avc/enc/SoftAVCEncoder.cpp
+++ b/media/libstagefright/codecs/avc/enc/SoftAVCEncoder.cpp
@@ -131,13 +131,16 @@
}
}
-static int32_t MallocWrapper(
+static void* MallocWrapper(
void *userData, int32_t size, int32_t attrs) {
- return reinterpret_cast<int32_t>(malloc(size));
+ void *ptr = malloc(size);
+ if (ptr)
+ memset(ptr, 0, size);
+ return ptr;
}
-static void FreeWrapper(void *userData, int32_t ptr) {
- free(reinterpret_cast<void *>(ptr));
+static void FreeWrapper(void *userData, void* ptr) {
+ free(ptr);
}
static int32_t DpbAllocWrapper(void *userData,
diff --git a/media/libstagefright/codecs/avc/enc/src/avcenc_api.cpp b/media/libstagefright/codecs/avc/enc/src/avcenc_api.cpp
index 6d43142..cf14e10 100644
--- a/media/libstagefright/codecs/avc/enc/src/avcenc_api.cpp
+++ b/media/libstagefright/codecs/avc/enc/src/avcenc_api.cpp
@@ -77,7 +77,6 @@
}
encvid = (AVCEncObject*) avcHandle->AVCObject;
- memset(encvid, 0, sizeof(AVCEncObject)); /* reset everything */
encvid->enc_state = AVCEnc_Initializing;
@@ -90,7 +89,6 @@
}
video = encvid->common;
- memset(video, 0, sizeof(AVCCommonObj));
/* allocate bitstream structure */
encvid->bitstream = (AVCEncBitstream*) avcHandle->CBAVC_Malloc(userData, sizeof(AVCEncBitstream), DEFAULT_ATTR);
@@ -106,7 +104,6 @@
{
return AVCENC_MEMORY_FAIL;
}
- memset(video->currSeqParams, 0, sizeof(AVCSeqParamSet));
/* allocate picture parameter set structure */
video->currPicParams = (AVCPicParamSet*) avcHandle->CBAVC_Malloc(userData, sizeof(AVCPicParamSet), DEFAULT_ATTR);
@@ -114,7 +111,6 @@
{
return AVCENC_MEMORY_FAIL;
}
- memset(video->currPicParams, 0, sizeof(AVCPicParamSet));
/* allocate slice header structure */
video->sliceHdr = (AVCSliceHeader*) avcHandle->CBAVC_Malloc(userData, sizeof(AVCSliceHeader), DEFAULT_ATTR);
@@ -122,7 +118,6 @@
{
return AVCENC_MEMORY_FAIL;
}
- memset(video->sliceHdr, 0, sizeof(AVCSliceHeader));
/* allocate encoded picture buffer structure*/
video->decPicBuf = (AVCDecPicBuffer*) avcHandle->CBAVC_Malloc(userData, sizeof(AVCDecPicBuffer), DEFAULT_ATTR);
@@ -130,7 +125,6 @@
{
return AVCENC_MEMORY_FAIL;
}
- memset(video->decPicBuf, 0, sizeof(AVCDecPicBuffer));
/* allocate rate control structure */
encvid->rateCtrl = (AVCRateControl*) avcHandle->CBAVC_Malloc(userData, sizeof(AVCRateControl), DEFAULT_ATTR);
@@ -138,7 +132,6 @@
{
return AVCENC_MEMORY_FAIL;
}
- memset(encvid->rateCtrl, 0, sizeof(AVCRateControl));
/* reset frame list, not really needed */
video->currPic = NULL;
@@ -194,7 +187,6 @@
{
return AVCENC_MEMORY_FAIL;
}
- memset(encvid->mot16x16, 0, sizeof(AVCMV)*framesize);
encvid->intraSearch = (uint8*) avcHandle->CBAVC_Malloc(userData, sizeof(uint8) * framesize, DEFAULT_ATTR);
if (encvid->intraSearch == NULL)
@@ -610,32 +602,32 @@
if (encvid->functionPointer != NULL)
{
- avcHandle->CBAVC_Free(userData, (int)encvid->functionPointer);
+ avcHandle->CBAVC_Free(userData, encvid->functionPointer);
}
if (encvid->min_cost)
{
- avcHandle->CBAVC_Free(userData, (int)encvid->min_cost);
+ avcHandle->CBAVC_Free(userData, encvid->min_cost);
}
if (encvid->intraSearch)
{
- avcHandle->CBAVC_Free(userData, (int)encvid->intraSearch);
+ avcHandle->CBAVC_Free(userData, encvid->intraSearch);
}
if (encvid->mot16x16)
{
- avcHandle->CBAVC_Free(userData, (int)encvid->mot16x16);
+ avcHandle->CBAVC_Free(userData, encvid->mot16x16);
}
if (encvid->rateCtrl)
{
- avcHandle->CBAVC_Free(userData, (int)encvid->rateCtrl);
+ avcHandle->CBAVC_Free(userData, encvid->rateCtrl);
}
if (encvid->overrunBuffer)
{
- avcHandle->CBAVC_Free(userData, (int)encvid->overrunBuffer);
+ avcHandle->CBAVC_Free(userData, encvid->overrunBuffer);
}
video = encvid->common;
@@ -643,45 +635,45 @@
{
if (video->MbToSliceGroupMap)
{
- avcHandle->CBAVC_Free(userData, (int)video->MbToSliceGroupMap);
+ avcHandle->CBAVC_Free(userData, video->MbToSliceGroupMap);
}
if (video->mblock != NULL)
{
- avcHandle->CBAVC_Free(userData, (int)video->mblock);
+ avcHandle->CBAVC_Free(userData, video->mblock);
}
if (video->decPicBuf != NULL)
{
CleanUpDPB(avcHandle, video);
- avcHandle->CBAVC_Free(userData, (int)video->decPicBuf);
+ avcHandle->CBAVC_Free(userData, video->decPicBuf);
}
if (video->sliceHdr != NULL)
{
- avcHandle->CBAVC_Free(userData, (int)video->sliceHdr);
+ avcHandle->CBAVC_Free(userData, video->sliceHdr);
}
if (video->currPicParams != NULL)
{
if (video->currPicParams->slice_group_id)
{
- avcHandle->CBAVC_Free(userData, (int)video->currPicParams->slice_group_id);
+ avcHandle->CBAVC_Free(userData, video->currPicParams->slice_group_id);
}
- avcHandle->CBAVC_Free(userData, (int)video->currPicParams);
+ avcHandle->CBAVC_Free(userData, video->currPicParams);
}
if (video->currSeqParams != NULL)
{
- avcHandle->CBAVC_Free(userData, (int)video->currSeqParams);
+ avcHandle->CBAVC_Free(userData, video->currSeqParams);
}
if (encvid->bitstream != NULL)
{
- avcHandle->CBAVC_Free(userData, (int)encvid->bitstream);
+ avcHandle->CBAVC_Free(userData, encvid->bitstream);
}
if (video != NULL)
{
- avcHandle->CBAVC_Free(userData, (int)video);
+ avcHandle->CBAVC_Free(userData, video);
}
}
- avcHandle->CBAVC_Free(userData, (int)encvid);
+ avcHandle->CBAVC_Free(userData, encvid);
avcHandle->AVCObject = NULL;
}
diff --git a/media/libstagefright/codecs/avc/enc/src/bitstream_io.cpp b/media/libstagefright/codecs/avc/enc/src/bitstream_io.cpp
index 75ab514..0e3037f 100644
--- a/media/libstagefright/codecs/avc/enc/src/bitstream_io.cpp
+++ b/media/libstagefright/codecs/avc/enc/src/bitstream_io.cpp
@@ -275,8 +275,8 @@
// allocate new overrun Buffer
if (encvid->overrunBuffer)
{
- encvid->avcHandle->CBAVC_Free((uint32*)encvid->avcHandle->userData,
- (int)encvid->overrunBuffer);
+ encvid->avcHandle->CBAVC_Free(encvid->avcHandle->userData,
+ encvid->overrunBuffer);
}
encvid->oBSize = stream->oBSize;
@@ -314,8 +314,8 @@
// copy from the old buffer to new buffer
memcpy(encvid->overrunBuffer, stream->overrunBuffer, stream->write_pos);
// free old buffer
- encvid->avcHandle->CBAVC_Free((uint32*)encvid->avcHandle->userData,
- (int)stream->overrunBuffer);
+ encvid->avcHandle->CBAVC_Free(encvid->avcHandle->userData,
+ stream->overrunBuffer);
// assign pointer to new buffer
stream->overrunBuffer = encvid->overrunBuffer;
diff --git a/media/libstagefright/codecs/avc/enc/src/motion_est.cpp b/media/libstagefright/codecs/avc/enc/src/motion_est.cpp
index f650ef9..00c56c8 100644
--- a/media/libstagefright/codecs/avc/enc/src/motion_est.cpp
+++ b/media/libstagefright/codecs/avc/enc/src/motion_est.cpp
@@ -176,7 +176,7 @@
if (encvid->mvbits_array)
{
- avcHandle->CBAVC_Free(avcHandle->userData, (int)(encvid->mvbits_array));
+ avcHandle->CBAVC_Free(avcHandle->userData, encvid->mvbits_array);
encvid->mvbits = NULL;
}
diff --git a/media/libstagefright/codecs/avc/enc/src/rate_control.cpp b/media/libstagefright/codecs/avc/enc/src/rate_control.cpp
index 15b55fb..aa13873 100644
--- a/media/libstagefright/codecs/avc/enc/src/rate_control.cpp
+++ b/media/libstagefright/codecs/avc/enc/src/rate_control.cpp
@@ -190,7 +190,6 @@
{
goto CLEANUP_RC;
}
- memset(rateCtrl->pMP, 0, sizeof(MultiPass));
rateCtrl->pMP->encoded_frames = -1; /* forget about the very first I frame */
/* RDInfo **pRDSamples */
@@ -207,7 +206,6 @@
{
goto CLEANUP_RC;
}
- for (j = 0; j < 32; j++) memset(&(rateCtrl->pMP->pRDSamples[i][j]), 0, sizeof(RDInfo));
}
rateCtrl->pMP->frameRange = (int)(rateCtrl->frame_rate * 1.0); /* 1.0s time frame*/
rateCtrl->pMP->frameRange = AVC_MAX(rateCtrl->pMP->frameRange, 5);
@@ -300,7 +298,7 @@
if (rateCtrl->MADofMB)
{
- avcHandle->CBAVC_Free(avcHandle->userData, (int)(rateCtrl->MADofMB));
+ avcHandle->CBAVC_Free(avcHandle->userData, rateCtrl->MADofMB);
}
if (rateCtrl->pMP)
@@ -311,12 +309,12 @@
{
if (rateCtrl->pMP->pRDSamples[i])
{
- avcHandle->CBAVC_Free(avcHandle->userData, (int)rateCtrl->pMP->pRDSamples[i]);
+ avcHandle->CBAVC_Free(avcHandle->userData, rateCtrl->pMP->pRDSamples[i]);
}
}
- avcHandle->CBAVC_Free(avcHandle->userData, (int)rateCtrl->pMP->pRDSamples);
+ avcHandle->CBAVC_Free(avcHandle->userData, rateCtrl->pMP->pRDSamples);
}
- avcHandle->CBAVC_Free(avcHandle->userData, (int)(rateCtrl->pMP));
+ avcHandle->CBAVC_Free(avcHandle->userData, rateCtrl->pMP);
}
return ;
diff --git a/media/libstagefright/codecs/avc/enc/src/sad_mb_offset.h b/media/libstagefright/codecs/avc/enc/src/sad_mb_offset.h
index d5d4a42..5bc5c86 100644
--- a/media/libstagefright/codecs/avc/enc/src/sad_mb_offset.h
+++ b/media/libstagefright/codecs/avc/enc/src/sad_mb_offset.h
@@ -296,9 +296,9 @@
#if (NUMBER==3)
goto LOOP_SAD3;
#elif (NUMBER==2)
-goto LOOP_SAD2;
+ goto LOOP_SAD2;
#elif (NUMBER==1)
-goto LOOP_SAD1;
+ goto LOOP_SAD1;
#endif
}
diff --git a/media/libstagefright/id3/ID3.cpp b/media/libstagefright/id3/ID3.cpp
index ca14054..69274ca 100644
--- a/media/libstagefright/id3/ID3.cpp
+++ b/media/libstagefright/id3/ID3.cpp
@@ -743,7 +743,8 @@
n += 2;
}
- return n;
+ // Add size of null termination.
+ return n + 2;
}
const void *
diff --git a/services/audioflinger/AudioMixer.cpp b/services/audioflinger/AudioMixer.cpp
index 0c8b3ce..3e4c55e 100644
--- a/services/audioflinger/AudioMixer.cpp
+++ b/services/audioflinger/AudioMixer.cpp
@@ -93,8 +93,12 @@
effect_descriptor_t AudioMixer::dwnmFxDesc;
+// Ensure mConfiguredNames bitmask is initialized properly on all architectures.
+// The value of 1 << x is undefined in C when x >= 32.
+
AudioMixer::AudioMixer(size_t frameCount, uint32_t sampleRate, uint32_t maxNumTracks)
- : mTrackNames(0), mConfiguredNames((1 << maxNumTracks) - 1), mSampleRate(sampleRate)
+ : mTrackNames(0), mConfiguredNames((maxNumTracks >= 32 ? 0 : 1 << maxNumTracks) - 1),
+ mSampleRate(sampleRate)
{
// AudioMixer is not yet capable of multi-channel beyond stereo
COMPILE_TIME_ASSERT_FUNCTION_SCOPE(2 == MAX_NUM_CHANNELS);
diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp
index bf07f8b..385be50 100644
--- a/services/camera/libcameraservice/CameraService.cpp
+++ b/services/camera/libcameraservice/CameraService.cpp
@@ -721,9 +721,9 @@
Mutex::Autolock lock(mLock);
if (checkPidAndHardware() != NO_ERROR) return;
- mCameraService->playSound(SOUND_RECORDING);
disableMsgType(CAMERA_MSG_VIDEO_FRAME);
mHardware->stopRecording();
+ mCameraService->playSound(SOUND_RECORDING);
mPreviewBuffer.clear();
}