From c0ac48ee0cc6e48c31325770db19c0c866cc4085 Mon Sep 17 00:00:00 2001 From: Jean-Yves Avenard Date: Thu, 4 Oct 2018 09:43:57 +0000 Subject: [PATCH] Bug 1322234 - P3. Add method to read a VP9 profile from a VP9 bitstream r=TD-Linux Depends on D7616 Differential Revision: https://phabricator.services.mozilla.com/D7647 --HG-- extra : moz-landing-system : lando --- dom/media/platforms/agnostic/VPXDecoder.cpp | 29 +++++++++++++++++++++ dom/media/platforms/agnostic/VPXDecoder.h | 4 +++ 2 files changed, 33 insertions(+) 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);