Bug 1243681 - Query port base and calculate index with it. r=alfredo
authorJohn Lin <jolin@mozilla.com>
Thu, 28 Jan 2016 17:04:54 +0800
changeset 321864 7989e73486d116c5ccbecffa8bec41ad252f53f8
parent 321863 2af0755ca43865a02976427f53d5c2835e8ccdce
child 321865 9a5f5c32373ce74b29655192a61f7c8fe5523c14
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersalfredo
bugs1243681
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1243681 - Query port base and calculate index with it. r=alfredo MozReview-Commit-ID: BTOCq8NTgp9
dom/media/platforms/omx/GonkOmxPlatformLayer.cpp
dom/media/platforms/omx/OmxDataDecoder.cpp
dom/media/platforms/omx/OmxDataDecoder.h
dom/media/platforms/omx/OmxPlatformLayer.cpp
dom/media/platforms/omx/OmxPlatformLayer.h
dom/media/platforms/omx/OmxPromiseLayer.cpp
dom/media/platforms/omx/OmxPromiseLayer.h
--- a/dom/media/platforms/omx/GonkOmxPlatformLayer.cpp
+++ b/dom/media/platforms/omx/GonkOmxPlatformLayer.cpp
@@ -355,17 +355,17 @@ nsresult
 GonkOmxPlatformLayer::AllocateOmxBuffer(OMX_DIRTYPE aType,
                                         BUFFERLIST* aBufferList)
 {
   MOZ_ASSERT(!mMemoryDealer[aType].get());
 
   // Get port definition.
   OMX_PARAM_PORTDEFINITIONTYPE def;
   nsTArray<uint32_t> portindex;
-  GetOmxPortIndex(portindex);
+  GetPortIndices(portindex);
   for (auto idx : portindex) {
     InitOmxParameter(&def);
     def.nPortIndex = idx;
 
     OMX_ERRORTYPE err = GetParameter(OMX_IndexParamPortDefinition,
                                      &def,
                                      sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
     if (err != OMX_ErrorNone) {
--- a/dom/media/platforms/omx/OmxDataDecoder.cpp
+++ b/dom/media/platforms/omx/OmxDataDecoder.cpp
@@ -911,27 +911,19 @@ void OmxDataDecoder::FlushFailure(OmxCom
 
 MediaDataHelper::MediaDataHelper(const TrackInfo* aTrackInfo,
                                  layers::ImageContainer* aImageContainer,
                                  OmxPromiseLayer* aOmxLayer)
   : mTrackInfo(aTrackInfo)
   , mAudioCompactor(mAudioQueue)
   , mImageContainer(aImageContainer)
 {
-  // Get latest port definition.
-  nsTArray<uint32_t> ports;
-  GetOmxPortIndex(ports);
-  for (auto idx : ports) {
-    InitOmxParameter(&mOutputPortDef);
-    mOutputPortDef.nPortIndex = idx;
-    aOmxLayer->GetParameter(OMX_IndexParamPortDefinition, &mOutputPortDef, sizeof(mOutputPortDef));
-    if (mOutputPortDef.eDir == OMX_DirOutput) {
-      break;
-    }
-  }
+  InitOmxParameter(&mOutputPortDef);
+  mOutputPortDef.nPortIndex = aOmxLayer->OutputPortIndex();
+  aOmxLayer->GetParameter(OMX_IndexParamPortDefinition, &mOutputPortDef, sizeof(mOutputPortDef));
 }
 
 already_AddRefed<MediaData>
 MediaDataHelper::GetMediaData(BufferData* aBufferData, bool& aPlatformDepenentData)
 {
   aPlatformDepenentData = false;
   RefPtr<MediaData> data;
 
--- a/dom/media/platforms/omx/OmxDataDecoder.h
+++ b/dom/media/platforms/omx/OmxDataDecoder.h
@@ -202,17 +202,11 @@ protected:
 template<class T>
 void InitOmxParameter(T* aParam)
 {
   PodZero(aParam);
   aParam->nSize = sizeof(T);
   aParam->nVersion.s.nVersionMajor = 1;
 }
 
-// There should be 2 ports and port number start from 0.
-void GetOmxPortIndex(nsTArray<uint32_t>& aPortIndex) {
-  aPortIndex.AppendElement(0);
-  aPortIndex.AppendElement(1);
-}
-
 }
 
 #endif /* OmxDataDecoder_h_ */
--- a/dom/media/platforms/omx/OmxPlatformLayer.cpp
+++ b/dom/media/platforms/omx/OmxPlatformLayer.cpp
@@ -49,16 +49,17 @@ class OmxAacConfig : public OmxAudioConf
 {
 public:
   OMX_ERRORTYPE Apply(OmxPlatformLayer& aOmx, const AudioInfo& aInfo) override
   {
     OMX_ERRORTYPE err;
 
     OMX_AUDIO_PARAM_AACPROFILETYPE aacProfile;
     InitOmxParameter(&aacProfile);
+    aacProfile.nPortIndex = aOmx.InputPortIndex();
     err = aOmx.GetParameter(OMX_IndexParamAudioAac, &aacProfile, sizeof(aacProfile));
     RETURN_IF_ERR(err);
 
     aacProfile.nChannels = aInfo.mChannels;
     aacProfile.nSampleRate = aInfo.mRate;
     aacProfile.eAACProfile = static_cast<OMX_AUDIO_AACPROFILETYPE>(aInfo.mProfile);
     err = aOmx.SetParameter(OMX_IndexParamAudioAac, &aacProfile, sizeof(aacProfile));
     RETURN_IF_ERR(err);
@@ -97,17 +98,17 @@ public:
 
   OMX_ERRORTYPE Apply(OmxPlatformLayer& aOmx, const VideoInfo& aInfo) override
   {
     OMX_ERRORTYPE err;
     OMX_PARAM_PORTDEFINITIONTYPE def;
 
     // Set up in/out port definition.
     nsTArray<uint32_t> ports;
-    GetOmxPortIndex(ports);
+    aOmx.GetPortIndices(ports);
     for (auto idx : ports) {
       InitOmxParameter(&def);
       def.nPortIndex = idx;
       err = aOmx.GetParameter(OMX_IndexParamPortDefinition, &def, sizeof(def));
       RETURN_IF_ERR(err);
 
       def.format.video.nFrameWidth =  aInfo.mDisplay.width;
       def.format.video.nFrameHeight = aInfo.mDisplay.height;
@@ -153,21 +154,26 @@ ConfigForMime(const nsACString& aMimeTyp
   return Move(conf);
 }
 
 OMX_ERRORTYPE
 OmxPlatformLayer::Config()
 {
   MOZ_ASSERT(mInfo);
 
+  OMX_PORT_PARAM_TYPE portParam;
+  InitOmxParameter(&portParam);
   if (mInfo->IsAudio()) {
+    GetParameter(OMX_IndexParamAudioInit, &portParam, sizeof(portParam));
+    mStartPortNumber = portParam.nStartPortNumber;
     UniquePtr<OmxAudioConfig> conf(ConfigForMime<OmxAudioConfig>(mInfo->mMimeType));
     MOZ_ASSERT(conf.get());
     return conf->Apply(*this, *(mInfo->GetAsAudioInfo()));
   } else if (mInfo->IsVideo()) {
+    GetParameter(OMX_IndexParamVideoInit, &portParam, sizeof(portParam));
     UniquePtr<OmxVideoConfig> conf(ConfigForMime<OmxVideoConfig>(mInfo->mMimeType));
     MOZ_ASSERT(conf.get());
     return conf->Apply(*this, *(mInfo->GetAsVideoInfo()));
   } else {
     MOZ_ASSERT_UNREACHABLE("non-AV data (text?) is not supported.");
     return OMX_ErrorNotImplemented;
   }
 }
--- a/dom/media/platforms/omx/OmxPlatformLayer.h
+++ b/dom/media/platforms/omx/OmxPlatformLayer.h
@@ -60,27 +60,39 @@ public:
   virtual OMX_ERRORTYPE SetParameter(OMX_INDEXTYPE nIndex,
                                      OMX_PTR aComponentParameterStructure,
                                      OMX_U32 aComponentParameterSize) = 0;
 
   virtual nsresult Shutdown() = 0;
 
   virtual ~OmxPlatformLayer() {}
 
+  // For decoders, input port index is start port number and output port is next.
+  // See OpenMAX IL spec v1.1.2 section 8.6.1 & 8.8.1.
+  OMX_U32 InputPortIndex() { return mStartPortNumber; }
+
+  OMX_U32 OutputPortIndex() { return mStartPortNumber + 1; }
+
+  void GetPortIndices(nsTArray<uint32_t>& aPortIndex) {
+    aPortIndex.AppendElement(InputPortIndex());
+    aPortIndex.AppendElement(OutputPortIndex());
+  }
+
   // 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);
 
 protected:
-  OmxPlatformLayer() : mInfo(nullptr) {}
+  OmxPlatformLayer() : mInfo(nullptr), mStartPortNumber(0) {}
 
   // The pointee is held by |OmxDataDecoder::mTrackInfo| and will outlive this pointer.
   const TrackInfo* mInfo;
+  OMX_U32 mStartPortNumber;
 };
 
 }
 
 #endif // OmxPlatformLayer_h_
--- a/dom/media/platforms/omx/OmxPromiseLayer.cpp
+++ b/dom/media/platforms/omx/OmxPromiseLayer.cpp
@@ -352,16 +352,28 @@ OmxPromiseLayer::SetParameter(OMX_INDEXT
                               OMX_PTR aComponentParameterStructure,
                               OMX_U32 aComponentParameterSize)
 {
   return mPlatformLayer->SetParameter(aParamIndex,
                                       aComponentParameterStructure,
                                       aComponentParameterSize);
 }
 
+OMX_U32
+OmxPromiseLayer::InputPortIndex()
+{
+  return mPlatformLayer->InputPortIndex();
+}
+
+OMX_U32
+OmxPromiseLayer::OutputPortIndex()
+{
+  return mPlatformLayer->OutputPortIndex();
+}
+
 nsresult
 OmxPromiseLayer::Shutdown()
 {
   LOG("");
   MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
   MOZ_ASSERT(!GetBufferHolders(OMX_DirInput)->Length());
   MOZ_ASSERT(!GetBufferHolders(OMX_DirOutput)->Length());
   return mPlatformLayer->Shutdown();
--- a/dom/media/platforms/omx/OmxPromiseLayer.h
+++ b/dom/media/platforms/omx/OmxPromiseLayer.h
@@ -105,16 +105,20 @@ public:
   OMX_ERRORTYPE GetParameter(OMX_INDEXTYPE aParamIndex,
                              OMX_PTR aComponentParameterStructure,
                              OMX_U32 aComponentParameterSize);
 
   OMX_ERRORTYPE SetParameter(OMX_INDEXTYPE nIndex,
                              OMX_PTR aComponentParameterStructure,
                              OMX_U32 aComponentParameterSize);
 
+  OMX_U32 InputPortIndex();
+
+  OMX_U32 OutputPortIndex();
+
   nsresult Shutdown();
 
   // BufferData maintains the status of OMX buffer (OMX_BUFFERHEADERTYPE).
   // mStatus tracks the buffer owner.
   // And a promise because OMX buffer working among different threads.
   class BufferData {
   protected:
     virtual ~BufferData() {}