Bug 1330284 - Use MediaContentType in AndroidMediaPluginHost::CreateDecoder, AndroidMediaDecoder, AndroidMediaReader - r?jya draft
authorGerald Squelart <gsquelart@mozilla.com>
Wed, 28 Dec 2016 15:07:45 +1100
changeset 460041 ed188eb7d4c55825f4e7c8abaa43b651531f7124
parent 460040 71de6d8abf6e69e5724bf1267856eb9b5a150999
child 460042 f4819fa9c01f6cdb870e868511b201b8af0621c0
push id41348
push usergsquelart@mozilla.com
push dateThu, 12 Jan 2017 20:50:49 +0000
reviewersjya
bugs1330284
milestone53.0a1
Bug 1330284 - Use MediaContentType in AndroidMediaPluginHost::CreateDecoder, AndroidMediaDecoder, AndroidMediaReader - r?jya MozReview-Commit-ID: JvdBe8I9A2K
dom/media/DecoderTraits.cpp
dom/media/android/AndroidMediaDecoder.cpp
dom/media/android/AndroidMediaDecoder.h
dom/media/android/AndroidMediaPluginHost.cpp
dom/media/android/AndroidMediaPluginHost.h
dom/media/android/AndroidMediaReader.cpp
dom/media/android/AndroidMediaReader.h
--- a/dom/media/DecoderTraits.cpp
+++ b/dom/media/DecoderTraits.cpp
@@ -334,17 +334,17 @@ InstantiateDecoder(const MediaContentTyp
   }
   if (FlacDecoder::IsSupportedType(aType)) {
     decoder = new FlacDecoder(aOwner);
     return decoder.forget();
   }
 #ifdef MOZ_ANDROID_OMX
   if (MediaDecoder::IsAndroidMediaPluginEnabled() &&
       EnsureAndroidMediaPluginHost()->FindDecoder(aType, nullptr)) {
-    decoder = new AndroidMediaDecoder(aOwner, aType.Type().AsString());
+    decoder = new AndroidMediaDecoder(aOwner, aType);
     return decoder.forget();
   }
 #endif
 
   if (WebMDecoder::IsSupportedType(aType)) {
     decoder = new WebMDecoder(aOwner);
     return decoder.forget();
   }
@@ -413,17 +413,17 @@ MediaDecoderReader* DecoderTraits::Creat
     decoderReader = new MediaFormatReader(aDecoder, new FlacDemuxer(aDecoder->GetResource()));
   } else
   if (OggDecoder::IsSupportedType(*type)) {
     decoderReader = new MediaFormatReader(aDecoder, new OggDemuxer(aDecoder->GetResource()));
   } else
 #ifdef MOZ_ANDROID_OMX
   if (MediaDecoder::IsAndroidMediaPluginEnabled() &&
       EnsureAndroidMediaPluginHost()->FindDecoder(aType, nullptr)) {
-    decoderReader = new AndroidMediaReader(aDecoder, aType);
+    decoderReader = new AndroidMediaReader(aDecoder, *type);
   } else
 #endif
   if (WebMDecoder::IsSupportedType(*type)) {
     decoderReader =
       new MediaFormatReader(aDecoder, new WebMDemuxer(aDecoder->GetResource()));
   } else
 #ifdef MOZ_DIRECTSHOW
   if (DirectShowDecoder::GetSupportedCodecs(*type, nullptr)) {
--- a/dom/media/android/AndroidMediaDecoder.cpp
+++ b/dom/media/android/AndroidMediaDecoder.cpp
@@ -6,17 +6,17 @@
 
 #include "MediaDecoderStateMachine.h"
 #include "AndroidMediaDecoder.h"
 #include "AndroidMediaReader.h"
 
 namespace mozilla {
 
 AndroidMediaDecoder::AndroidMediaDecoder(MediaDecoderOwner* aOwner,
-                                         const nsACString& aType)
+                                         const MediaContentType& aType)
   : MediaDecoder(aOwner), mType(aType)
 {
 }
 
 MediaDecoderStateMachine* AndroidMediaDecoder::CreateStateMachine()
 {
   return new MediaDecoderStateMachine(this, new AndroidMediaReader(this, mType));
 }
--- a/dom/media/android/AndroidMediaDecoder.h
+++ b/dom/media/android/AndroidMediaDecoder.h
@@ -3,24 +3,25 @@
 /* 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/. */
 #if !defined(AndroidMediaDecoder_h_)
 #define AndroidMediaDecoder_h_
 
 #include "MediaDecoder.h"
 #include "AndroidMediaDecoder.h"
+#include "MediaContentType.h"
 
 namespace mozilla {
 
 class AndroidMediaDecoder : public MediaDecoder
 {
-  nsCString mType;
+  MediaContentType mType;
 public:
-  AndroidMediaDecoder(MediaDecoderOwner* aOwner, const nsACString& aType);
+  AndroidMediaDecoder(MediaDecoderOwner* aOwner, const MediaContentType& aType);
 
   MediaDecoder* Clone(MediaDecoderOwner* aOwner) override {
     return new AndroidMediaDecoder(aOwner, mType);
   }
   MediaDecoderStateMachine* CreateStateMachine() override;
 };
 
 } // namespace mozilla
--- a/dom/media/android/AndroidMediaPluginHost.cpp
+++ b/dom/media/android/AndroidMediaPluginHost.cpp
@@ -239,27 +239,28 @@ bool AndroidMediaPluginHost::FindDecoder
       if (aCodecs)
         *aCodecs = codecs;
       return true;
     }
   }
   return false;
 }
 
-MPAPI::Decoder *AndroidMediaPluginHost::CreateDecoder(MediaResource *aResource, const nsACString& aMimeType)
+MPAPI::Decoder *AndroidMediaPluginHost::CreateDecoder(MediaResource *aResource,
+                                                      const MediaContentType& aMimeType)
 {
   NS_ENSURE_TRUE(aResource, nullptr);
 
   nsAutoPtr<Decoder> decoder(new Decoder());
   if (!decoder) {
     return nullptr;
   }
 
   const char *chars;
-  size_t len = NS_CStringGetData(aMimeType, &chars, nullptr);
+  size_t len = NS_CStringGetData(aMimeType.Type().AsString(), &chars, nullptr);
   for (size_t n = 0; n < mPlugins.Length(); ++n) {
     Manifest *plugin = mPlugins[n];
     const char* const *codecs;
     if (!plugin->CanDecode(chars, len, &codecs)) {
       continue;
     }
 
     nsCString url;
--- a/dom/media/android/AndroidMediaPluginHost.h
+++ b/dom/media/android/AndroidMediaPluginHost.h
@@ -22,17 +22,17 @@ class AndroidMediaPluginHost {
   MPAPI::Manifest *FindPlugin(const nsACString& aMimeType);
 public:
   AndroidMediaPluginHost();
   ~AndroidMediaPluginHost();
 
   static void Shutdown();
 
   bool FindDecoder(const MediaContentType& aMimeType, const char* const** aCodecs);
-  MPAPI::Decoder *CreateDecoder(mozilla::MediaResource *aResource, const nsACString& aMimeType);
+  MPAPI::Decoder *CreateDecoder(mozilla::MediaResource *aResource, const MediaContentType& aMimeType);
   void DestroyDecoder(MPAPI::Decoder *aDecoder);
 };
 
 // Must be called on the main thread. Creates the plugin host if it doesn't
 // already exist.
 AndroidMediaPluginHost *EnsureAndroidMediaPluginHost();
 
 // May be called on any thread after EnsureAndroidMediaPluginHost has been called.
--- a/dom/media/android/AndroidMediaReader.cpp
+++ b/dom/media/android/AndroidMediaReader.cpp
@@ -20,17 +20,17 @@ namespace mozilla {
 
 using namespace mozilla::gfx;
 using namespace mozilla::media;
 
 typedef mozilla::layers::Image Image;
 typedef mozilla::layers::PlanarYCbCrImage PlanarYCbCrImage;
 
 AndroidMediaReader::AndroidMediaReader(AbstractMediaDecoder *aDecoder,
-                                       const nsACString& aContentType) :
+                                       const MediaContentType& aContentType) :
   MediaDecoderReader(aDecoder),
   mType(aContentType),
   mPlugin(nullptr),
   mHasAudio(false),
   mHasVideo(false),
   mVideoSeekTimeUs(-1),
   mAudioSeekTimeUs(-1)
 {
--- a/dom/media/android/AndroidMediaReader.h
+++ b/dom/media/android/AndroidMediaReader.h
@@ -1,50 +1,49 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* 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/. */
 #if !defined(AndroidMediaReader_h_)
 #define AndroidMediaReader_h_
 
-#include "mozilla/Attributes.h"
+#include "ImageContainer.h"
+#include "MediaContentType.h"
+#include "MediaDecoderReader.h"
 #include "MediaResource.h"
-#include "MediaDecoderReader.h"
-#include "ImageContainer.h"
+#include "mozilla/Attributes.h"
 #include "mozilla/layers/SharedRGBImage.h"
 
 #include "MPAPI.h"
 
-class nsACString;
-
 namespace mozilla {
 
 class AbstractMediaDecoder;
 
 namespace layers {
 class ImageContainer;
 }
 
 class AndroidMediaReader : public MediaDecoderReader
 {
-  nsCString mType;
+  MediaContentType mType;
   MPAPI::Decoder *mPlugin;
   bool mHasAudio;
   bool mHasVideo;
   nsIntRect mPicture;
   nsIntSize mInitialFrame;
   int64_t mVideoSeekTimeUs;
   int64_t mAudioSeekTimeUs;
   RefPtr<VideoData> mLastVideoFrame;
   MozPromiseHolder<MediaDecoderReader::SeekPromise> mSeekPromise;
   MozPromiseRequestHolder<MediaDecoderReader::MediaDataPromise> mSeekRequest;
 public:
   AndroidMediaReader(AbstractMediaDecoder* aDecoder,
-                     const nsACString& aContentType);
+                     const MediaContentType& aContentType);
 
   nsresult ResetDecode(TrackSet aTracks = TrackSet(TrackInfo::kAudioTrack,
                                                    TrackInfo::kVideoTrack)) override;
 
   bool DecodeAudioData() override;
   bool DecodeVideoFrame(bool &aKeyframeSkip, int64_t aTimeThreshold) override;
 
   nsresult ReadMetadata(MediaInfo* aInfo, MetadataTags** aTags) override;