diff --git a/dom/media/platforms/agnostic/VPXDecoder.cpp b/dom/media/platforms/agnostic/VPXDecoder.cpp index 601008ca9a16..0ad5a5ccd654 100644 --- a/dom/media/platforms/agnostic/VPXDecoder.cpp +++ b/dom/media/platforms/agnostic/VPXDecoder.cpp @@ -5,6 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "VPXDecoder.h" +#include "BitReader.h" #include "TimeUnits.h" #include "gfx2DGlue.h" #include "mozilla/PodOperations.h" @@ -337,5 +338,33 @@ VPXDecoder::GetFrameSize(Span aBuffer, Codec aCodec) return gfx::IntSize(si.w, si.h); } + +/* static */ +int +VPXDecoder::GetVP9Profile(Span aBuffer) +{ + if (aBuffer.Length() < 2) { + // Can't be good. + return -1; + } + BitReader br(aBuffer.Elements(), aBuffer.Length() * 8); + + uint32_t frameMarker = br.ReadBits(2); // frame_marker + if (frameMarker != 2) { + // That's not a valid vp9 header. + return -1; + } + uint32_t profile = br.ReadBits(1); // profile_low_bit + profile |= br.ReadBits(1) << 1; // profile_high_bit + if (profile == 3) { + profile += br.ReadBits(1); // reserved_zero + if (profile > 3) { + // reserved_zero wasn't zero. + return -1; + } + } + return profile; +} + } // namespace mozilla #undef LOG diff --git a/dom/media/platforms/agnostic/VPXDecoder.h b/dom/media/platforms/agnostic/VPXDecoder.h index b9dcfaf6dc3e..7527c30d6220 100644 --- a/dom/media/platforms/agnostic/VPXDecoder.h +++ b/dom/media/platforms/agnostic/VPXDecoder.h @@ -56,6 +56,10 @@ public: // Return the frame dimensions for a sample for the specified codec. static gfx::IntSize GetFrameSize(Span aBuffer, Codec aCodec); + // Return the VP9 profile as per https://www.webmproject.org/vp9/profiles/ + // Return negative value if error. + static int GetVP9Profile(Span aBuffer); + private: ~VPXDecoder(); RefPtr ProcessDecode(MediaRawData* aSample);