author Jean-Yves Avenard <>
Wed, 31 May 2017 16:15:45 +0200
changeset 361781 18c7e0ab522082c69fe0b3e7b0fe1feb3f84c833
parent 361779 3ad1b460540d2a6eda0011805457d9701d113f26
child 365887 0d953ca28addebf90833bc6ddb1df4abbee4d754
permissions -rw-r--r--
Bug 1313398: P2. Always check for SPS/PPS inband. r=gerald Ignore the known out of band extradata. MozReview-Commit-ID: 8ARjrTtxhwY

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at */


template <class T> struct already_AddRefed;

namespace mozilla {
class MediaRawData;
class MediaByteBuffer;
namespace mp4_demuxer
class ByteReader;

class AnnexB
  // All conversions assume size of NAL length field is 4 bytes.
  // Convert a sample from AVCC format to Annex B.
  static bool ConvertSampleToAnnexB(mozilla::MediaRawData* aSample, bool aAddSPS = true);
  // Convert a sample from Annex B to AVCC.
  // an AVCC extradata must not be set.
  static bool ConvertSampleToAVCC(mozilla::MediaRawData* aSample);
  static bool ConvertSampleTo4BytesAVCC(mozilla::MediaRawData* aSample);

  // Parse an AVCC extradata and construct the Annex B sample header.
  static already_AddRefed<mozilla::MediaByteBuffer> ConvertExtraDataToAnnexB(
    const mozilla::MediaByteBuffer* aExtraData);
  // Extract SPS and PPS NALs from aSample by looking into each NALs.
  // aSample must be in AVCC format.
  static already_AddRefed<mozilla::MediaByteBuffer> ExtractExtraData(
    const mozilla::MediaRawData* aSample);
  static bool HasSPS(const mozilla::MediaRawData* aSample);
  static bool HasSPS(const mozilla::MediaByteBuffer* aExtraData);
  // Returns true if format is AVCC and sample has valid extradata.
  static bool IsAVCC(const mozilla::MediaRawData* aSample);
  // Returns true if format is AnnexB.
  static bool IsAnnexB(const mozilla::MediaRawData* aSample);
  // Return true if both extradata are equal.
  static bool CompareExtraData(const mozilla::MediaByteBuffer* aExtraData1,
                               const mozilla::MediaByteBuffer* aExtraData2);

  // AVCC box parser helper.
  static void ConvertSPSOrPPS(ByteReader& aReader, uint8_t aCount,
                              mozilla::MediaByteBuffer* aAnnexB);

} // namespace mp4_demuxer

#endif // MP4_DEMUXER_ANNEX_B_H_