Loading include/media/stagefright/OMXCodec.h +3 −1 Original line number Diff line number Diff line Loading @@ -98,6 +98,7 @@ private: kDecoderLiesAboutNumberOfChannels = 256, kInputBufferSizesAreBogus = 512, kSupportsMultipleFramesPerInputBuffer = 1024, kAvoidMemcopyInputRecordingFrames = 2048, }; struct BufferInfo { Loading Loading @@ -165,7 +166,8 @@ private: OMX_COLOR_FORMATTYPE colorFormat); void setVideoInputFormat( const char *mime, OMX_U32 width, OMX_U32 height); const char *mime, OMX_U32 width, OMX_U32 height, OMX_U32 frameRate, OMX_U32 bitRate); status_t setupMPEG4EncoderParameters(); status_t setupAVCEncoderParameters(); Loading media/libstagefright/MPEG4Writer.cpp +25 −23 Original line number Diff line number Diff line Loading @@ -705,6 +705,7 @@ void MPEG4Writer::Track::threadEntry() { int64_t lastDuration = 0; // Time spacing between the previous two samples int32_t sampleCount = 1; // Sample count in the current stts table entry uint32_t previousSampleSize = 0; // Size of the previous sample sp<MetaData> meta_data; MediaBuffer *buffer; while (!mDone && mSource->read(&buffer) == OK) { Loading Loading @@ -825,35 +826,46 @@ void MPEG4Writer::Track::threadEntry() { continue; } if (is_avc) StripStartcode(buffer); // Make a deep copy of the MediaBuffer and Metadata and release // the original as soon as we can MediaBuffer *copy = new MediaBuffer(buffer->range_length()); memcpy(copy->data(), (uint8_t *)buffer->data() + buffer->range_offset(), buffer->range_length()); copy->set_range(0, buffer->range_length()); meta_data = new MetaData(*buffer->meta_data().get()); buffer->release(); buffer = NULL; if (is_avc) StripStartcode(copy); SampleInfo info; info.size = is_avc #if USE_NALLEN_FOUR ? buffer->range_length() + 4 ? copy->range_length() + 4 #else ? buffer->range_length() + 2 ? copy->range_length() + 2 #endif : buffer->range_length(); : copy->range_length(); // Max file size or duration handling mEstimatedTrackSizeBytes += info.size; if (mOwner->exceedsFileSizeLimit()) { buffer->release(); buffer = NULL; mOwner->notify(MEDIA_RECORDER_EVENT_INFO, MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED, 0); break; } if (mOwner->exceedsFileDurationLimit()) { buffer->release(); buffer = NULL; mOwner->notify(MEDIA_RECORDER_EVENT_INFO, MEDIA_RECORDER_INFO_MAX_DURATION_REACHED, 0); break; } int32_t isSync = false; meta_data->findInt32(kKeyIsSyncFrame, &isSync); int64_t timestampUs; CHECK(buffer->meta_data()->findInt64(kKeyTime, ×tampUs)); CHECK(meta_data->findInt64(kKeyTime, ×tampUs)); //////////////////////////////////////////////////////////////////////////////// if (mSampleInfos.empty()) { mOwner->setStartTimestamp(timestampUs); mStartTimestampUs = (timestampUs - mOwner->getStartTimestamp()); Loading Loading @@ -884,12 +896,10 @@ void MPEG4Writer::Track::threadEntry() { lastDuration = info.timestamp - lastTimestamp; lastTimestamp = info.timestamp; //////////////////////////////////////////////////////////////////////////////// // Make a deep copy of the MediaBuffer less Metadata MediaBuffer *copy = new MediaBuffer(buffer->range_length()); memcpy(copy->data(), (uint8_t *)buffer->data() + buffer->range_offset(), buffer->range_length()); copy->set_range(0, buffer->range_length()); if (isSync != 0) { mStssTableEntries.push_back(mSampleInfos.size()); } mChunkSamples.push_back(copy); if (interleaveDurationUs == 0) { Loading @@ -915,14 +925,6 @@ void MPEG4Writer::Track::threadEntry() { } } int32_t isSync = false; if (buffer->meta_data()->findInt32(kKeyIsSyncFrame, &isSync) && isSync != 0) { mStssTableEntries.push_back(mSampleInfos.size()); } buffer->release(); buffer = NULL; } if (mSampleInfos.empty()) { Loading media/libstagefright/OMXCodec.cpp +24 −9 Original line number Diff line number Diff line Loading @@ -347,6 +347,9 @@ uint32_t OMXCodec::getComponentQuirks(const char *componentName) { quirks |= kRequiresAllocateBufferOnInputPorts; quirks |= kRequiresAllocateBufferOnOutputPorts; if (!strncmp(componentName, "OMX.TI.video.encoder", 20)) { quirks |= kAvoidMemcopyInputRecordingFrames; } } if (!strcmp(componentName, "OMX.TI.Video.Decoder")) { Loading Loading @@ -574,7 +577,10 @@ status_t OMXCodec::configureCodec(const sp<MetaData> &meta) { CHECK(success); if (mIsEncoder) { setVideoInputFormat(mMIME, width, height); int32_t frameRate = 25; // XXX int32_t bitRate = 3000000; // bit rate //success = success && meta->findInt32(kKeySampleRate, &frameRate); setVideoInputFormat(mMIME, width, height, frameRate, bitRate); } else { status_t err = setVideoOutputFormat( mMIME, width, height); Loading Loading @@ -739,7 +745,8 @@ static size_t getFrameSize( } void OMXCodec::setVideoInputFormat( const char *mime, OMX_U32 width, OMX_U32 height) { const char *mime, OMX_U32 width, OMX_U32 height, OMX_U32 frameRate, OMX_U32 bitRate) { CODEC_LOGV("setVideoInputFormat width=%ld, height=%ld", width, height); OMX_VIDEO_CODINGTYPE compressionFormat = OMX_VIDEO_CodingUnused; Loading Loading @@ -769,6 +776,7 @@ void OMXCodec::setVideoInputFormat( CHECK_EQ(setVideoPortFormatType( kPortIndexInput, OMX_VIDEO_CodingUnused, colorFormat), OK); InitOMXParams(&def); def.nPortIndex = kPortIndexInput; Loading @@ -782,11 +790,10 @@ void OMXCodec::setVideoInputFormat( video_def->nFrameWidth = width; video_def->nFrameHeight = height; video_def->xFramerate = (frameRate << 16); // Q16 format video_def->eCompressionFormat = OMX_VIDEO_CodingUnused; video_def->eColorFormat = colorFormat; video_def->xFramerate = (24 << 16); // Q16 format err = mOMX->setParameter( mNode, OMX_IndexParamPortDefinition, &def, sizeof(def)); CHECK_EQ(err, OK); Loading @@ -806,7 +813,8 @@ void OMXCodec::setVideoInputFormat( video_def->nFrameWidth = width; video_def->nFrameHeight = height; video_def->xFramerate = (frameRate << 16); // Q16 format video_def->nBitrate = bitRate; // Q16 format video_def->eCompressionFormat = compressionFormat; video_def->eColorFormat = OMX_COLOR_FormatUnused; Loading Loading @@ -928,6 +936,7 @@ status_t OMXCodec::setupAVCEncoderParameters() { h264type.nSliceHeaderSpacing = 0; h264type.nBFrames = 0; h264type.nPFrames = 24; // XXX h264type.bUseHadamard = OMX_TRUE; h264type.nRefFrames = 1; h264type.nRefIdx10ActiveMinus1 = 0; Loading Loading @@ -960,7 +969,7 @@ status_t OMXCodec::setupAVCEncoderParameters() { CHECK_EQ(err, OK); bitrateType.eControlRate = OMX_Video_ControlRateVariable; bitrateType.nTargetBitrate = 3000000; bitrateType.nTargetBitrate = 3000000; // XXX err = mOMX->setParameter( mNode, OMX_IndexParamVideoBitrate, Loading Loading @@ -2049,9 +2058,15 @@ void OMXCodec::drainInputBuffer(BufferInfo *info) { break; } if (mIsEncoder && (mQuirks & kAvoidMemcopyInputRecordingFrames)) { CHECK(mOMXLivesLocally && offset == 0); OMX_BUFFERHEADERTYPE *header = (OMX_BUFFERHEADERTYPE *) info->mBuffer; header->pBuffer = (OMX_U8 *) srcBuffer->data() + srcBuffer->range_offset(); } else { memcpy((uint8_t *)info->mData + offset, (const uint8_t *)srcBuffer->data() + srcBuffer->range_offset(), srcBuffer->range_length()); } int64_t lastBufferTimeUs; CHECK(srcBuffer->meta_data()->findInt64(kKeyTime, &lastBufferTimeUs)); Loading Loading
include/media/stagefright/OMXCodec.h +3 −1 Original line number Diff line number Diff line Loading @@ -98,6 +98,7 @@ private: kDecoderLiesAboutNumberOfChannels = 256, kInputBufferSizesAreBogus = 512, kSupportsMultipleFramesPerInputBuffer = 1024, kAvoidMemcopyInputRecordingFrames = 2048, }; struct BufferInfo { Loading Loading @@ -165,7 +166,8 @@ private: OMX_COLOR_FORMATTYPE colorFormat); void setVideoInputFormat( const char *mime, OMX_U32 width, OMX_U32 height); const char *mime, OMX_U32 width, OMX_U32 height, OMX_U32 frameRate, OMX_U32 bitRate); status_t setupMPEG4EncoderParameters(); status_t setupAVCEncoderParameters(); Loading
media/libstagefright/MPEG4Writer.cpp +25 −23 Original line number Diff line number Diff line Loading @@ -705,6 +705,7 @@ void MPEG4Writer::Track::threadEntry() { int64_t lastDuration = 0; // Time spacing between the previous two samples int32_t sampleCount = 1; // Sample count in the current stts table entry uint32_t previousSampleSize = 0; // Size of the previous sample sp<MetaData> meta_data; MediaBuffer *buffer; while (!mDone && mSource->read(&buffer) == OK) { Loading Loading @@ -825,35 +826,46 @@ void MPEG4Writer::Track::threadEntry() { continue; } if (is_avc) StripStartcode(buffer); // Make a deep copy of the MediaBuffer and Metadata and release // the original as soon as we can MediaBuffer *copy = new MediaBuffer(buffer->range_length()); memcpy(copy->data(), (uint8_t *)buffer->data() + buffer->range_offset(), buffer->range_length()); copy->set_range(0, buffer->range_length()); meta_data = new MetaData(*buffer->meta_data().get()); buffer->release(); buffer = NULL; if (is_avc) StripStartcode(copy); SampleInfo info; info.size = is_avc #if USE_NALLEN_FOUR ? buffer->range_length() + 4 ? copy->range_length() + 4 #else ? buffer->range_length() + 2 ? copy->range_length() + 2 #endif : buffer->range_length(); : copy->range_length(); // Max file size or duration handling mEstimatedTrackSizeBytes += info.size; if (mOwner->exceedsFileSizeLimit()) { buffer->release(); buffer = NULL; mOwner->notify(MEDIA_RECORDER_EVENT_INFO, MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED, 0); break; } if (mOwner->exceedsFileDurationLimit()) { buffer->release(); buffer = NULL; mOwner->notify(MEDIA_RECORDER_EVENT_INFO, MEDIA_RECORDER_INFO_MAX_DURATION_REACHED, 0); break; } int32_t isSync = false; meta_data->findInt32(kKeyIsSyncFrame, &isSync); int64_t timestampUs; CHECK(buffer->meta_data()->findInt64(kKeyTime, ×tampUs)); CHECK(meta_data->findInt64(kKeyTime, ×tampUs)); //////////////////////////////////////////////////////////////////////////////// if (mSampleInfos.empty()) { mOwner->setStartTimestamp(timestampUs); mStartTimestampUs = (timestampUs - mOwner->getStartTimestamp()); Loading Loading @@ -884,12 +896,10 @@ void MPEG4Writer::Track::threadEntry() { lastDuration = info.timestamp - lastTimestamp; lastTimestamp = info.timestamp; //////////////////////////////////////////////////////////////////////////////// // Make a deep copy of the MediaBuffer less Metadata MediaBuffer *copy = new MediaBuffer(buffer->range_length()); memcpy(copy->data(), (uint8_t *)buffer->data() + buffer->range_offset(), buffer->range_length()); copy->set_range(0, buffer->range_length()); if (isSync != 0) { mStssTableEntries.push_back(mSampleInfos.size()); } mChunkSamples.push_back(copy); if (interleaveDurationUs == 0) { Loading @@ -915,14 +925,6 @@ void MPEG4Writer::Track::threadEntry() { } } int32_t isSync = false; if (buffer->meta_data()->findInt32(kKeyIsSyncFrame, &isSync) && isSync != 0) { mStssTableEntries.push_back(mSampleInfos.size()); } buffer->release(); buffer = NULL; } if (mSampleInfos.empty()) { Loading
media/libstagefright/OMXCodec.cpp +24 −9 Original line number Diff line number Diff line Loading @@ -347,6 +347,9 @@ uint32_t OMXCodec::getComponentQuirks(const char *componentName) { quirks |= kRequiresAllocateBufferOnInputPorts; quirks |= kRequiresAllocateBufferOnOutputPorts; if (!strncmp(componentName, "OMX.TI.video.encoder", 20)) { quirks |= kAvoidMemcopyInputRecordingFrames; } } if (!strcmp(componentName, "OMX.TI.Video.Decoder")) { Loading Loading @@ -574,7 +577,10 @@ status_t OMXCodec::configureCodec(const sp<MetaData> &meta) { CHECK(success); if (mIsEncoder) { setVideoInputFormat(mMIME, width, height); int32_t frameRate = 25; // XXX int32_t bitRate = 3000000; // bit rate //success = success && meta->findInt32(kKeySampleRate, &frameRate); setVideoInputFormat(mMIME, width, height, frameRate, bitRate); } else { status_t err = setVideoOutputFormat( mMIME, width, height); Loading Loading @@ -739,7 +745,8 @@ static size_t getFrameSize( } void OMXCodec::setVideoInputFormat( const char *mime, OMX_U32 width, OMX_U32 height) { const char *mime, OMX_U32 width, OMX_U32 height, OMX_U32 frameRate, OMX_U32 bitRate) { CODEC_LOGV("setVideoInputFormat width=%ld, height=%ld", width, height); OMX_VIDEO_CODINGTYPE compressionFormat = OMX_VIDEO_CodingUnused; Loading Loading @@ -769,6 +776,7 @@ void OMXCodec::setVideoInputFormat( CHECK_EQ(setVideoPortFormatType( kPortIndexInput, OMX_VIDEO_CodingUnused, colorFormat), OK); InitOMXParams(&def); def.nPortIndex = kPortIndexInput; Loading @@ -782,11 +790,10 @@ void OMXCodec::setVideoInputFormat( video_def->nFrameWidth = width; video_def->nFrameHeight = height; video_def->xFramerate = (frameRate << 16); // Q16 format video_def->eCompressionFormat = OMX_VIDEO_CodingUnused; video_def->eColorFormat = colorFormat; video_def->xFramerate = (24 << 16); // Q16 format err = mOMX->setParameter( mNode, OMX_IndexParamPortDefinition, &def, sizeof(def)); CHECK_EQ(err, OK); Loading @@ -806,7 +813,8 @@ void OMXCodec::setVideoInputFormat( video_def->nFrameWidth = width; video_def->nFrameHeight = height; video_def->xFramerate = (frameRate << 16); // Q16 format video_def->nBitrate = bitRate; // Q16 format video_def->eCompressionFormat = compressionFormat; video_def->eColorFormat = OMX_COLOR_FormatUnused; Loading Loading @@ -928,6 +936,7 @@ status_t OMXCodec::setupAVCEncoderParameters() { h264type.nSliceHeaderSpacing = 0; h264type.nBFrames = 0; h264type.nPFrames = 24; // XXX h264type.bUseHadamard = OMX_TRUE; h264type.nRefFrames = 1; h264type.nRefIdx10ActiveMinus1 = 0; Loading Loading @@ -960,7 +969,7 @@ status_t OMXCodec::setupAVCEncoderParameters() { CHECK_EQ(err, OK); bitrateType.eControlRate = OMX_Video_ControlRateVariable; bitrateType.nTargetBitrate = 3000000; bitrateType.nTargetBitrate = 3000000; // XXX err = mOMX->setParameter( mNode, OMX_IndexParamVideoBitrate, Loading Loading @@ -2049,9 +2058,15 @@ void OMXCodec::drainInputBuffer(BufferInfo *info) { break; } if (mIsEncoder && (mQuirks & kAvoidMemcopyInputRecordingFrames)) { CHECK(mOMXLivesLocally && offset == 0); OMX_BUFFERHEADERTYPE *header = (OMX_BUFFERHEADERTYPE *) info->mBuffer; header->pBuffer = (OMX_U8 *) srcBuffer->data() + srcBuffer->range_offset(); } else { memcpy((uint8_t *)info->mData + offset, (const uint8_t *)srcBuffer->data() + srcBuffer->range_offset(), srcBuffer->range_length()); } int64_t lastBufferTimeUs; CHECK(srcBuffer->meta_data()->findInt64(kKeyTime, &lastBufferTimeUs)); Loading