Bug 1314147 - Recognize AV1 in WebMDemuxer. r=jya draft
authorRalph Giles <giles@mozilla.com>
Wed, 19 Apr 2017 14:41:37 -0700
changeset 573367 9b534330eff32fa49eda23dca2354a016211bfc3
parent 573366 33128df83181a8d372731cf95f50171d1d1df05d
child 627278 29bd8db859e4dc2c65474221910ff64c0e13e8a5
push id57365
push userbmo:giles@thaumas.net
push dateFri, 05 May 2017 16:49:55 +0000
reviewersjya
bugs1314147
milestone55.0a1
Bug 1314147 - Recognize AV1 in WebMDemuxer. r=jya Call AOMDecoder to handle AV1 video tracks from the WebM container. The new decoder is very similar to VPXDecoder so we can use parallel calls. This codec is still build-time conditional. MozReview-Commit-ID: 5cexCZiNBqo
dom/media/webm/WebMDemuxer.cpp
--- a/dom/media/webm/WebMDemuxer.cpp
+++ b/dom/media/webm/WebMDemuxer.cpp
@@ -3,16 +3,19 @@
 /* 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 http://mozilla.org/MPL/2.0/. */
 
 #include "nsError.h"
 #include "MediaDecoderStateMachine.h"
 #include "AbstractMediaDecoder.h"
 #include "MediaResource.h"
+#ifdef MOZ_AV1
+#include "AOMDecoder.h"
+#endif
 #include "OpusDecoder.h"
 #include "VPXDecoder.h"
 #include "WebMDemuxer.h"
 #include "WebMBufferedParser.h"
 #include "gfx2DGlue.h"
 #include "mozilla/Atomics.h"
 #include "mozilla/EndianUtils.h"
 #include "mozilla/SharedThreadPool.h"
@@ -322,16 +325,19 @@ WebMDemuxer::ReadMetadata()
       mVideoCodec = nestegg_track_codec_id(context, track);
       switch(mVideoCodec) {
         case NESTEGG_CODEC_VP8:
           mInfo.mVideo.mMimeType = "video/webm; codecs=vp8";
           break;
         case NESTEGG_CODEC_VP9:
           mInfo.mVideo.mMimeType = "video/webm; codecs=vp9";
           break;
+        case NESTEGG_CODEC_AV1:
+          mInfo.mVideo.mMimeType = "video/webm; codecs=av1";
+          break;
         default:
           NS_WARNING("Unknown WebM video codec");
           return NS_ERROR_FAILURE;
       }
       // Picture region, taking into account cropping, before scaling
       // to the display size.
       unsigned int cropH = params.crop_right + params.crop_left;
       unsigned int cropV = params.crop_bottom + params.crop_top;
@@ -677,27 +683,42 @@ WebMDemuxer::GetNextPacket(TrackInfo::Tr
         auto sample = MakeSpan(data, length);
         switch (mVideoCodec) {
         case NESTEGG_CODEC_VP8:
           isKeyframe = VPXDecoder::IsKeyframe(sample, VPXDecoder::Codec::VP8);
           break;
         case NESTEGG_CODEC_VP9:
           isKeyframe = VPXDecoder::IsKeyframe(sample, VPXDecoder::Codec::VP9);
           break;
+#ifdef MOZ_AV1
+        case NESTEGG_CODEC_AV1:
+          isKeyframe = AOMDecoder::IsKeyframe(sample);
+          break;
+#endif
         default:
           NS_WARNING("Cannot detect keyframes in unknown WebM video codec");
           return NS_ERROR_FAILURE;
         }
         if (isKeyframe) {
           // For both VP8 and VP9, we only look for resolution changes
           // on keyframes. Other resolution changes are invalid.
-          auto codec = mVideoCodec == NESTEGG_CODEC_VP8
-                       ? VPXDecoder::Codec::VP8
-                       : VPXDecoder::Codec::VP9;
-          auto dimensions = VPXDecoder::GetFrameSize(sample, codec);
+          auto dimensions = nsIntSize(0, 0);
+          switch (mVideoCodec) {
+          case NESTEGG_CODEC_VP8:
+            dimensions = VPXDecoder::GetFrameSize(sample, VPXDecoder::Codec::VP8);
+            break;
+          case NESTEGG_CODEC_VP9:
+            dimensions = VPXDecoder::GetFrameSize(sample, VPXDecoder::Codec::VP9);
+            break;
+#ifdef MOZ_AV1
+          case NESTEGG_CODEC_AV1:
+            dimensions = AOMDecoder::GetFrameSize(sample);
+            break;
+#endif
+          }
           if (mLastSeenFrameSize.isSome()
               && (dimensions != mLastSeenFrameSize.value())) {
             mInfo.mVideo.mDisplay = dimensions;
             mSharedVideoTrackInfo =
               new TrackInfoSharedPtr(mInfo.mVideo, ++sStreamSourceID);
           }
           mLastSeenFrameSize = Some(dimensions);
         }