Bug 1358662 - Store VPXDecoder codec as an enum. r=jya draft
authorRalph Giles <giles@mozilla.com>
Mon, 24 Apr 2017 15:02:54 -0700
changeset 571593 7876422fb86708fb0f60ec09b2c37ff3478fe784
parent 571592 e8ed144c5ba95540037a78b2cdfcd7a70a821c89
child 571594 ba5d8f6c328c6c2039e69851c32aafd000d87b4c
push id56862
push userbmo:giles@thaumas.net
push dateWed, 03 May 2017 00:23:00 +0000
reviewersjya
bugs1358662
milestone55.0a1
Bug 1358662 - Store VPXDecoder codec as an enum. r=jya Use the enum we already have here instead of converting to an int when we pass it around, giving us better type checking. MozReview-Commit-ID: Gj4xmtQnzw2
dom/media/platforms/agnostic/VPXDecoder.cpp
dom/media/platforms/agnostic/VPXDecoder.h
--- a/dom/media/platforms/agnostic/VPXDecoder.cpp
+++ b/dom/media/platforms/agnostic/VPXDecoder.cpp
@@ -17,32 +17,32 @@
 #undef LOG
 #define LOG(arg, ...) MOZ_LOG(sPDMLog, mozilla::LogLevel::Debug, ("VPXDecoder(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
 
 namespace mozilla {
 
 using namespace gfx;
 using namespace layers;
 
-static int MimeTypeToCodec(const nsACString& aMimeType)
+static VPXDecoder::Codec MimeTypeToCodec(const nsACString& aMimeType)
 {
   if (aMimeType.EqualsLiteral("video/webm; codecs=vp8")) {
     return VPXDecoder::Codec::VP8;
   } else if (aMimeType.EqualsLiteral("video/webm; codecs=vp9")) {
     return VPXDecoder::Codec::VP9;
   } else if (aMimeType.EqualsLiteral("video/vp9")) {
     return VPXDecoder::Codec::VP9;
   }
-  return -1;
+  return VPXDecoder::Codec::Unknown;
 }
 
 static nsresult
 InitContext(vpx_codec_ctx_t* aCtx,
             const VideoInfo& aInfo,
-            const int aCodec)
+            const VPXDecoder::Codec aCodec)
 {
   int decode_threads = 2;
 
   vpx_codec_iface_t* dx = nullptr;
   if (aCodec == VPXDecoder::Codec::VP8) {
     dx = vpx_codec_vp8_dx();
   }
   else if (aCodec == VPXDecoder::Codec::VP9) {
--- a/dom/media/platforms/agnostic/VPXDecoder.h
+++ b/dom/media/platforms/agnostic/VPXDecoder.h
@@ -29,17 +29,18 @@ public:
   const char* GetDescriptionName() const override
   {
     return "libvpx video decoder";
   }
 
   enum Codec: uint8_t
   {
     VP8 = 1 << 0,
-    VP9 = 1 << 1
+    VP9 = 1 << 1,
+    Unknown = 1 << 7,
   };
 
   // Return true if aMimeType is a one of the strings used by our demuxers to
   // identify VPX of the specified type. Does not parse general content type
   // strings, i.e. white space matters.
   static bool IsVPX(const nsACString& aMimeType, uint8_t aCodecMask=VP8|VP9);
   static bool IsVP8(const nsACString& aMimeType);
   static bool IsVP9(const nsACString& aMimeType);
@@ -55,14 +56,14 @@ private:
   // VPx decoder state
   vpx_codec_ctx_t mVPX;
 
   // VPx alpha decoder state
   vpx_codec_ctx_t mVPXAlpha;
 
   const VideoInfo& mInfo;
 
-  const int mCodec;
+  const Codec mCodec;
 };
 
 } // namespace mozilla
 
 #endif