summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/codecs/avc
diff options
context:
space:
mode:
authorJames Dong <jdong@google.com>2010-08-08 08:56:48 -0700
committerJames Dong <jdong@google.com>2010-08-10 10:20:15 -0700
commitf3b7859fc9b63dded08d470b1c0de3ddc681d9c7 (patch)
treedfe86f9cc1e7d430ce02d908558744dd06f0f7eb /media/libstagefright/codecs/avc
parent259b4c860212dd528b25d1cce6e74be01afed85c (diff)
downloadframeworks_base-f3b7859fc9b63dded08d470b1c0de3ddc681d9c7.zip
frameworks_base-f3b7859fc9b63dded08d470b1c0de3ddc681d9c7.tar.gz
frameworks_base-f3b7859fc9b63dded08d470b1c0de3ddc681d9c7.tar.bz2
Only check the codec specific data when the output buffer contains kKeyIsCodecConfig in MP4 writer
o Assume there is only a single output buffer containing such information. This simplifies the logic in MP4 file writer o Output SPS and PPS in the very first buffer for software AVC encoder This is to make AVC encoder work with the MP4 file writer o Add timestamp value for codec config data Change-Id: Iad27a04579e6028332429cd0bebd30976041e997
Diffstat (limited to 'media/libstagefright/codecs/avc')
-rw-r--r--media/libstagefright/codecs/avc/enc/AVCEncoder.cpp29
1 files changed, 22 insertions, 7 deletions
diff --git a/media/libstagefright/codecs/avc/enc/AVCEncoder.cpp b/media/libstagefright/codecs/avc/enc/AVCEncoder.cpp
index d5eb156..18320cf 100644
--- a/media/libstagefright/codecs/avc/enc/AVCEncoder.cpp
+++ b/media/libstagefright/codecs/avc/enc/AVCEncoder.cpp
@@ -337,14 +337,18 @@ status_t AVCEncoder::read(
MediaBuffer *outputBuffer;
CHECK_EQ(OK, mGroup->acquire_buffer(&outputBuffer));
- uint8_t *outPtr = (uint8_t *) outputBuffer->data();
- uint32_t dataLength = outputBuffer->size();
+
+ // Add 4 bytes for the start code 0x00000001
+ uint8_t *outPtr = (uint8_t *) outputBuffer->data() + 4;
+ uint32_t dataLength = outputBuffer->size() - 4;
int32_t type;
AVCEnc_Status encoderStatus = AVCENC_SUCCESS;
- // Return SPS and PPS for the first two buffers
- if (!mSpsPpsHeaderReceived) {
+ // Combine SPS and PPS and place them in the very first output buffer
+ // SPS and PPS are separated by start code 0x00000001
+ // Assume that we have exactly one SPS and exactly one PPS.
+ while (!mSpsPpsHeaderReceived && mNumInputFrames <= 0) {
encoderStatus = PVAVCEncodeNAL(mHandle, outPtr, &dataLength, &type);
if (encoderStatus == AVCENC_WRONG_STATE) {
mSpsPpsHeaderReceived = true;
@@ -352,11 +356,22 @@ status_t AVCEncoder::read(
} else {
switch (type) {
case AVC_NALTYPE_SPS:
+ ++mNumInputFrames;
+ memcpy(outputBuffer->data(), "\x00\x00\x00\x01", 4);
+ outputBuffer->set_range(0, dataLength + 4);
+ outPtr += (dataLength + 4); // 4 bytes for next start code
+ dataLength = outputBuffer->size() -
+ (outputBuffer->range_length() + 4);
+ break;
case AVC_NALTYPE_PPS:
- LOGV("%s received",
- (type == AVC_NALTYPE_SPS)? "SPS": "PPS");
++mNumInputFrames;
- outputBuffer->set_range(0, dataLength);
+ memcpy(((uint8_t *) outputBuffer->data()) +
+ outputBuffer->range_length(),
+ "\x00\x00\x00\x01", 4);
+ outputBuffer->set_range(0,
+ dataLength + outputBuffer->range_length() + 4);
+ outputBuffer->meta_data()->setInt32(kKeyIsCodecConfig, 1);
+ outputBuffer->meta_data()->setInt64(kKeyTime, 0);
*out = outputBuffer;
return OK;
default: