diff --git a/media/libstagefright/binding/H264.cpp b/media/libstagefright/binding/H264.cpp index f9e8b0d8c6c9..6e070ebcbb64 100644 --- a/media/libstagefright/binding/H264.cpp +++ b/media/libstagefright/binding/H264.cpp @@ -919,28 +919,51 @@ H264::ExtractExtraData(const mozilla::MediaRawData* aSample) /* static */ bool H264::HasSPS(const mozilla::MediaByteBuffer* aExtraData) +{ + return NumSPS(aExtraData) > 0; +} + +/* static */ uint8_t +H264::NumSPS(const mozilla::MediaByteBuffer* aExtraData) { if (!aExtraData) { - return false; + return 0; } ByteReader reader(aExtraData); const uint8_t* ptr = reader.Read(5); if (!ptr || !reader.CanRead8()) { - return false; + return 0; } - uint8_t numSps = reader.ReadU8() & 0x1f; - - return numSps > 0; + return reader.ReadU8() & 0x1f; } - /* static */ bool H264::CompareExtraData(const mozilla::MediaByteBuffer* aExtraData1, const mozilla::MediaByteBuffer* aExtraData2) { - // Very crude comparison. - return aExtraData1 == aExtraData2 || *aExtraData1 == *aExtraData2; + if (aExtraData1 == aExtraData2) { + return true; + } + uint8_t numSPS = NumSPS(aExtraData1); + if (numSPS == 0 || numSPS != NumSPS(aExtraData2)) { + return false; + } + + // We only compare if the SPS are the same as the various H264 decoders can + // deal with in-band change of PPS. + + SPSNALIterator it1(aExtraData1); + SPSNALIterator it2(aExtraData2); + + while (it1 && it2) { + if (*it1 != *it2) { + return false; + } + ++it1; + ++it2; + } + return true; } #undef READUE diff --git a/media/libstagefright/binding/include/mp4_demuxer/H264.h b/media/libstagefright/binding/include/mp4_demuxer/H264.h index 792d5d314b1a..c35f82d15b9f 100644 --- a/media/libstagefright/binding/include/mp4_demuxer/H264.h +++ b/media/libstagefright/binding/include/mp4_demuxer/H264.h @@ -457,6 +457,7 @@ private: static bool vui_parameters(BitReader& aBr, SPSData& aDest); // Read HRD parameters, all data is ignored. static void hrd_parameters(BitReader& aBr); + static uint8_t NumSPS(const mozilla::MediaByteBuffer* aExtraData); }; } // namespace mp4_demuxer