Commit 2aa78353 authored by John Lin's avatar John Lin Committed by morgan
Browse files

Bug 1924070 - modify H.264 extradata to match sample conversion code....

Bug 1924070 - modify H.264 extradata to match sample conversion code. r=media-playback-reviewers,alwu

In AVC stream, NAL unit is represented with the length of unit data
(NALUnitLength) followed by the actual unit data(NALUnit). The NALUnitLength
field can be 1-4 bytes long and the size can be derived from the
'lengthSizeMinusOne' value recorded in extradata.
H264ChangeMonitor.CheckForChange() reformats all input samples so that
NALUnitLength will always be 4 bytes long while the original extradata is
used during decoder creation earlier, so decoder won't be able to correctly
parse converted samples if extradata is not modified accordingly.

Differential Revision: https://phabricator.services.mozilla.com/D239547
parent 63d64ecc
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -42,6 +42,14 @@ class H264ChangeMonitor : public MediaChangeMonitor::CodecChangeMonitor {
      : mCurrentConfig(aInfo), mFullParsing(aFullParsing) {
    if (CanBeInstantiated()) {
      UpdateConfigFromExtraData(aInfo.mExtraData);
      auto avcc = AVCCConfig::Parse(mCurrentConfig.mExtraData);
      if (avcc.isOk() && avcc.unwrap().NALUSize() != 4) {
        // `CheckForChange()` will use `AnnexB::ConvertSampleToAVCC()` to change
        // NAL units into 4-byte.
        // `AVCDecoderConfigurationRecord.lengthSizeMinusOne` in the config
        // should be modified too.
        mCurrentConfig.mExtraData->ReplaceElementAt(4, 0xfc | 3);
      }
    }
  }