Skip to content

Commit

Permalink
libstagefright: Add changes to handle multiple slices in writer
Browse files Browse the repository at this point in the history
Few codecs encodes frame into multiple slices and
mpeg4 writer cannot support bitstream with multiple
slices. Hence add changes to configure the encoder
to return the bitstream in nal length format and
to avoid start code search if skip start code search
flag is set which will be enable for nal length bitstream

CRs-Fixed: 2781652

Change-Id: I5ca5d9e51c1d38d39f7a7941073d0d3bb9b6b21c
  • Loading branch information
Uma Mehta committed Mar 19, 2021
1 parent 292078a commit e8eb9e9
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ enum {
kKeyFeatureNalLengthBitstream = 'nlbs', // int32_t key to check nal length bistream
// AC-4 AudioPresentationInfo
kKeyAudioPresentationInfo = 'audP', // raw data

kKeyVendorFeatureNalLength = 'vfnl',
};

enum {
Expand Down
3 changes: 3 additions & 0 deletions media/libmediaplayerservice/StagefrightRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2108,6 +2108,9 @@ status_t StagefrightRecorder::setupVideoEncoder(
if (mOutputFormat == OUTPUT_FORMAT_MPEG_4) {
format->setInt32("feature-nal-length-bitstream", 1);
format->setInt32("nal-length-in-bytes", 4);
if (mVideoEncoder == VIDEO_ENCODER_HEVC) {
format->setInt32("vendor.qti-ext-enc-nal-length-bs.num-bytes", 4);
}
}

// Will send this info to encoder component for custom optimizations
Expand Down
4 changes: 3 additions & 1 deletion media/libstagefright/MPEG4Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2160,7 +2160,9 @@ MPEG4Writer::Track::Track(
!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AAC);
mIsMPEGH = !strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_MHAS);

mMeta->findInt32(kKeyFeatureNalLengthBitstream, &mNalLengthBitstream);
if (!mMeta->findInt32(kKeyFeatureNalLengthBitstream, &mNalLengthBitstream)) {
mMeta->findInt32(kKeyVendorFeatureNalLength, &mNalLengthBitstream);
}
// store temporal layer count
if (mIsVideo) {
int32_t count;
Expand Down
5 changes: 4 additions & 1 deletion media/libstagefright/MediaCodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4398,7 +4398,10 @@ status_t MediaCodec::amendOutputFormatWithCodecSpecificData(
CHECK(mOutputFormat->findString("mime", &mime));

int32_t nalLengthBistream = 0;
mOutputFormat->findInt32("feature-nal-length-bitstream", &nalLengthBistream);
if (!mOutputFormat->findInt32("feature-nal-length-bitstream", &nalLengthBistream)) {
mOutputFormat->findInt32(
"vendor.qti-ext-enc-nal-length-bs.num-bytes", &nalLengthBistream);
}

if (!strcasecmp(mime.c_str(), MEDIA_MIMETYPE_VIDEO_AVC)) {
// Codec specific data should be SPS and PPS in a single buffer,
Expand Down
5 changes: 4 additions & 1 deletion media/libstagefright/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ static std::vector<std::pair<const char *, uint32_t>> int32Mappings {
{ "thumbnail-height", kKeyThumbnailHeight },
{ "track-id", kKeyTrackID },
{ "valid-samples", kKeyValidSamples },
{ "vendor.qti-ext-enc-nal-length-bs.num-bytes", kKeyVendorFeatureNalLength },
}
};

Expand Down Expand Up @@ -1892,7 +1893,9 @@ status_t convertMessageToMetaData(const sp<AMessage> &msg, sp<MetaData> &meta) {

// reassemble the csd data into its original form
int32_t nalLengthBitstream = 0;
msg->findInt32("feature-nal-length-bitstream", &nalLengthBitstream);
if (! msg->findInt32("feature-nal-length-bitstream", &nalLengthBitstream)) {
msg->findInt32("vendor.qti-ext-enc-nal-length-bs.num-bytes", &nalLengthBitstream);
}
sp<ABuffer> csd0, csd1, csd2;
if (msg->findBuffer("csd-0", &csd0)) {
uint8_t* data = csd0->data();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ enum {
// Slow-motion markers
kKeySlowMotionMarkers = 'slmo', // raw data, byte array following spec for
// MediaFormat#KEY_SLOW_MOTION_MARKERS
kKeyVendorFeatureNalLength = 'vfnl', // int32_t key to check nal length enable
};

enum {
Expand Down

0 comments on commit e8eb9e9

Please sign in to comment.