1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #if !defined(OmxPlatformLayer_h_)
8 #define OmxPlatformLayer_h_
9 
10 #include "OMX_Core.h"
11 #include "OMX_Types.h"
12 
13 #include "OmxPromiseLayer.h"
14 
15 class nsACString;
16 
17 namespace mozilla {
18 
19 class TaskQueue;
20 class TrackInfo;
21 
22 /*
23  * This class the the abstract layer of the platform OpenMax IL implementation.
24  *
25  * For some platform like andoird, it exposures its OpenMax IL via IOMX which
26  * is definitions are different comparing to standard.
27  * For other platforms like Raspberry Pi, it will be easy to implement this layer
28  * with the standard OpenMax IL api.
29  */
30 class OmxPlatformLayer {
31 public:
32   typedef OmxPromiseLayer::BUFFERLIST BUFFERLIST;
33   typedef OmxPromiseLayer::BufferData BufferData;
34 
35   virtual OMX_ERRORTYPE InitOmxToStateLoaded(const TrackInfo* aInfo) = 0;
36 
37   OMX_ERRORTYPE Config();
38 
39   virtual OMX_ERRORTYPE EmptyThisBuffer(BufferData* aData) = 0;
40 
41   virtual OMX_ERRORTYPE FillThisBuffer(BufferData* aData) = 0;
42 
43   virtual OMX_ERRORTYPE SendCommand(OMX_COMMANDTYPE aCmd,
44                                     OMX_U32 aParam1,
45                                     OMX_PTR aCmdData) = 0;
46 
47   // Buffer could be platform dependent; for example, video decoding needs gralloc
48   // on Gonk. Therefore, derived class needs to implement its owned buffer
49   // allocate/release API according to its platform type.
50   virtual nsresult AllocateOmxBuffer(OMX_DIRTYPE aType, BUFFERLIST* aBufferList) = 0;
51 
52   virtual nsresult ReleaseOmxBuffer(OMX_DIRTYPE aType, BUFFERLIST* aBufferList) = 0;
53 
54   virtual OMX_ERRORTYPE GetState(OMX_STATETYPE* aType) = 0;
55 
56   virtual OMX_ERRORTYPE GetParameter(OMX_INDEXTYPE aParamIndex,
57                                      OMX_PTR aComponentParameterStructure,
58                                      OMX_U32 aComponentParameterSize) = 0;
59 
60   virtual OMX_ERRORTYPE SetParameter(OMX_INDEXTYPE nIndex,
61                                      OMX_PTR aComponentParameterStructure,
62                                      OMX_U32 aComponentParameterSize) = 0;
63 
64   virtual nsresult Shutdown() = 0;
65 
~OmxPlatformLayer()66   virtual ~OmxPlatformLayer() {}
67 
68   // For decoders, input port index is start port number and output port is next.
69   // See OpenMAX IL spec v1.1.2 section 8.6.1 & 8.8.1.
InputPortIndex()70   OMX_U32 InputPortIndex() { return mStartPortNumber; }
71 
OutputPortIndex()72   OMX_U32 OutputPortIndex() { return mStartPortNumber + 1; }
73 
GetPortIndices(nsTArray<uint32_t> & aPortIndex)74   void GetPortIndices(nsTArray<uint32_t>& aPortIndex) {
75     aPortIndex.AppendElement(InputPortIndex());
76     aPortIndex.AppendElement(OutputPortIndex());
77   }
78 
79   virtual OMX_VIDEO_CODINGTYPE CompressionFormat();
80 
81   // Check if the platform implementation supports given MIME type.
82   static bool SupportsMimeType(const nsACString& aMimeType);
83 
84   // Hide the details of creating implementation objects for different platforms.
85   static OmxPlatformLayer* Create(OmxDataDecoder* aDataDecoder,
86                                   OmxPromiseLayer* aPromiseLayer,
87                                   TaskQueue* aTaskQueue,
88                                   layers::ImageContainer* aImageContainer);
89 
90 protected:
OmxPlatformLayer()91   OmxPlatformLayer() : mInfo(nullptr), mStartPortNumber(0) {}
92 
93   // The pointee is held by |OmxDataDecoder::mTrackInfo| and will outlive this pointer.
94   const TrackInfo* mInfo;
95   OMX_U32 mStartPortNumber;
96 };
97 
98 }
99 
100 #endif // OmxPlatformLayer_h_
101