Bug 1233410 - Refactor: let component decide which compression format to use. r=alfredo
authorJohn Lin <jolin@mozilla.com>
Tue, 23 Feb 2016 13:17:47 +0800
changeset 285546 06f762ea5c7ffaf01ea1299ffc148f87a26b0264
parent 285545 12e56cb35dc57123fb43bc38a44e09207cd68414
child 285547 f523d47054813ad85464c6dc898c24908f978b46
push id17822
push usercbook@mozilla.com
push dateThu, 25 Feb 2016 11:00:09 +0000
treeherderfx-team@1c779b0b8969 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersalfredo
bugs1233410
milestone47.0a1
Bug 1233410 - Refactor: let component decide which compression format to use. r=alfredo MozReview-Commit-ID: EVBTwua5BFL
dom/media/platforms/omx/OmxPlatformLayer.cpp
dom/media/platforms/omx/OmxPlatformLayer.h
--- a/dom/media/platforms/omx/OmxPlatformLayer.cpp
+++ b/dom/media/platforms/omx/OmxPlatformLayer.cpp
@@ -1,16 +1,18 @@
 /* -*- 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/. */
 
 #include "OmxPlatformLayer.h"
 
+#include "OMX_VideoExt.h" // For VP8.
+
 #if defined(MOZ_WIDGET_GONK) && (ANDROID_VERSION == 20 || ANDROID_VERSION == 19)
 #define OMX_PLATFORM_GONK
 #include "GonkOmxPlatformLayer.h"
 #endif
 
 extern mozilla::LogModule* GetPDMLog();
 
 #ifdef LOG
@@ -184,19 +186,18 @@ ConfigForMime(const nsACString& aMimeTyp
 }
 
 // There should be a better way to calculate it.
 #define MIN_VIDEO_INPUT_BUFFER_SIZE 64 * 1024
 
 class OmxCommonVideoConfig : public OmxVideoConfig
 {
 public:
-  explicit OmxCommonVideoConfig(OMX_VIDEO_CODINGTYPE aCodec)
+  explicit OmxCommonVideoConfig()
     : OmxVideoConfig()
-    , mCodec(aCodec)
   {}
 
   OMX_ERRORTYPE Apply(OmxPlatformLayer& aOmx, const VideoInfo& aInfo) override
   {
     OMX_ERRORTYPE err;
     OMX_PARAM_PORTDEFINITIONTYPE def;
 
     // Set up in/out port definition.
@@ -209,50 +210,40 @@ public:
       RETURN_IF_ERR(err);
 
       def.format.video.nFrameWidth =  aInfo.mDisplay.width;
       def.format.video.nFrameHeight = aInfo.mDisplay.height;
       def.format.video.nStride = aInfo.mImage.width;
       def.format.video.nSliceHeight = aInfo.mImage.height;
 
       if (def.eDir == OMX_DirInput) {
-        def.format.video.eCompressionFormat = mCodec;
+        def.format.video.eCompressionFormat = aOmx.CompressionFormat();
         def.format.video.eColorFormat = OMX_COLOR_FormatUnused;
         if (def.nBufferSize < MIN_VIDEO_INPUT_BUFFER_SIZE) {
           def.nBufferSize = aInfo.mImage.width * aInfo.mImage.height;
           LOG("Change input buffer size to %d", def.nBufferSize);
         }
       } else {
         def.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused;
       }
 
       err = aOmx.SetParameter(OMX_IndexParamPortDefinition, &def, sizeof(def));
     }
     return err;
   }
-
-private:
-  const OMX_VIDEO_CODINGTYPE mCodec;
 };
 
 template<>
 UniquePtr<OmxVideoConfig>
 ConfigForMime(const nsACString& aMimeType)
 {
   UniquePtr<OmxVideoConfig> conf;
 
   if (OmxPlatformLayer::SupportsMimeType(aMimeType)) {
-    if (aMimeType.EqualsLiteral("video/avc")) {
-      conf.reset(new OmxCommonVideoConfig(OMX_VIDEO_CodingAVC));
-    } else if (aMimeType.EqualsLiteral("video/mp4v-es") ||
-         aMimeType.EqualsLiteral("video/mp4")) {
-      conf.reset(new OmxCommonVideoConfig(OMX_VIDEO_CodingMPEG4));
-    } else if (aMimeType.EqualsLiteral("video/3gpp")) {
-      conf.reset(new OmxCommonVideoConfig(OMX_VIDEO_CodingH263));
-    }
+    conf.reset(new OmxCommonVideoConfig());
   }
   return Move(conf);
 }
 
 OMX_ERRORTYPE
 OmxPlatformLayer::Config()
 {
   MOZ_ASSERT(mInfo);
@@ -271,16 +262,36 @@ OmxPlatformLayer::Config()
     MOZ_ASSERT(conf.get());
     return conf->Apply(*this, *(mInfo->GetAsVideoInfo()));
   } else {
     MOZ_ASSERT_UNREACHABLE("non-AV data (text?) is not supported.");
     return OMX_ErrorNotImplemented;
   }
 }
 
+OMX_VIDEO_CODINGTYPE
+OmxPlatformLayer::CompressionFormat()
+{
+  MOZ_ASSERT(mInfo);
+
+  if (mInfo->mMimeType.EqualsLiteral("video/avc")) {
+    return OMX_VIDEO_CodingAVC;
+  } else if (mInfo->mMimeType.EqualsLiteral("video/mp4v-es") ||
+       mInfo->mMimeType.EqualsLiteral("video/mp4")) {
+    return OMX_VIDEO_CodingMPEG4;
+  } else if (mInfo->mMimeType.EqualsLiteral("video/3gpp")) {
+    return OMX_VIDEO_CodingH263;
+  } else if (mInfo->mMimeType.EqualsLiteral("video/webm; codecs=vp8")) {
+    return static_cast<OMX_VIDEO_CODINGTYPE>(OMX_VIDEO_CodingVP8);
+  } else {
+    MOZ_ASSERT_UNREACHABLE("Unsupported compression format");
+    return OMX_VIDEO_CodingUnused;
+  }
+}
+
 // Implementations for different platforms will be defined in their own files.
 #ifdef OMX_PLATFORM_GONK
 
 bool
 OmxPlatformLayer::SupportsMimeType(const nsACString& aMimeType)
 {
   return GonkOmxPlatformLayer::FindComponents(aMimeType);
 }
--- a/dom/media/platforms/omx/OmxPlatformLayer.h
+++ b/dom/media/platforms/omx/OmxPlatformLayer.h
@@ -71,16 +71,18 @@ public:
 
   OMX_U32 OutputPortIndex() { return mStartPortNumber + 1; }
 
   void GetPortIndices(nsTArray<uint32_t>& aPortIndex) {
     aPortIndex.AppendElement(InputPortIndex());
     aPortIndex.AppendElement(OutputPortIndex());
   }
 
+  virtual OMX_VIDEO_CODINGTYPE CompressionFormat();
+
   // Check if the platform implementation supports given MIME type.
   static bool SupportsMimeType(const nsACString& aMimeType);
 
   // Hide the details of creating implementation objects for different platforms.
   static OmxPlatformLayer* Create(OmxDataDecoder* aDataDecoder,
                                   OmxPromiseLayer* aPromiseLayer,
                                   TaskQueue* aTaskQueue,
                                   layers::ImageContainer* aImageContainer);