Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/media/platforms/omx/OmxDataDecoder.h
Line
Count
Source (jump to first uncovered line)
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(OmxDataDecoder_h_)
8
#define OmxDataDecoder_h_
9
10
#include "mozilla/Monitor.h"
11
#include "mozilla/StateWatching.h"
12
13
#include "AudioCompactor.h"
14
#include "ImageContainer.h"
15
#include "MediaInfo.h"
16
#include "PlatformDecoderModule.h"
17
18
#include "OMX_Component.h"
19
20
#include "OmxPromiseLayer.h"
21
22
namespace mozilla {
23
24
class MediaDataHelper;
25
26
typedef OmxPromiseLayer::OmxCommandPromise OmxCommandPromise;
27
typedef OmxPromiseLayer::OmxBufferPromise OmxBufferPromise;
28
typedef OmxPromiseLayer::OmxBufferFailureHolder OmxBufferFailureHolder;
29
typedef OmxPromiseLayer::OmxCommandFailureHolder OmxCommandFailureHolder;
30
typedef OmxPromiseLayer::BufferData BufferData;
31
typedef OmxPromiseLayer::BUFFERLIST BUFFERLIST;
32
33
DDLoggedTypeDeclNameAndBase(OmxDataDecoder, MediaDataDecoder);
34
35
/* OmxDataDecoder is the major class which performs followings:
36
 *   1. Translate PDM function into OMX commands.
37
 *   2. Keeping the buffers between client and component.
38
 *   3. Manage the OMX state.
39
 *
40
 * From the definition in OpenMax spec. "2.2.1", there are 3 major roles in
41
 * OpenMax IL.
42
 *
43
 * IL client:
44
 *   "The IL client may be a layer below the GUI application, such as GStreamer,
45
 *   or may be several layers below the GUI layer."
46
 *
47
 *   OmxDataDecoder acts as the IL client.
48
 *
49
 * OpenMAX IL component:
50
 *   "A component that is intended to wrap functionality that is required in the
51
 *   target system."
52
 *
53
 *   OmxPromiseLayer acts as the OpenMAX IL component.
54
 *
55
 * OpenMAX IL core:
56
 *   "Platform-specific code that has the functionality necessary to locate and
57
 *   then load an OpenMAX IL component into main memory."
58
 *
59
 *   OmxPlatformLayer acts as the OpenMAX IL core.
60
 */
61
class OmxDataDecoder
62
  : public MediaDataDecoder
63
  , public DecoderDoctorLifeLogger<OmxDataDecoder>
64
{
65
protected:
66
  virtual ~OmxDataDecoder();
67
68
public:
69
  OmxDataDecoder(const TrackInfo& aTrackInfo,
70
                 TaskQueue* aTaskQueue,
71
                 layers::ImageContainer* aImageContainer);
72
73
  RefPtr<InitPromise> Init() override;
74
  RefPtr<DecodePromise> Decode(MediaRawData* aSample) override;
75
  RefPtr<DecodePromise> Drain() override;
76
  RefPtr<FlushPromise> Flush() override;
77
  RefPtr<ShutdownPromise> Shutdown() override;
78
79
  nsCString GetDescriptionName() const override
80
0
  {
81
0
    return NS_LITERAL_CSTRING("omx decoder");
82
0
  }
83
84
  ConversionRequired NeedsConversion() const override
85
0
  {
86
0
    return ConversionRequired::kNeedAnnexB;
87
0
  }
88
89
  // Return true if event is handled.
90
  bool Event(OMX_EVENTTYPE aEvent, OMX_U32 aData1, OMX_U32 aData2);
91
92
protected:
93
  void InitializationTask();
94
95
  void ResolveInitPromise(const char* aMethodName);
96
97
  void RejectInitPromise(MediaResult aError, const char* aMethodName);
98
99
  void OmxStateRunner();
100
101
  void FillAndEmptyBuffers();
102
103
  void FillBufferDone(BufferData* aData);
104
105
  void FillBufferFailure(OmxBufferFailureHolder aFailureHolder);
106
107
  void EmptyBufferDone(BufferData* aData);
108
109
  void EmptyBufferFailure(OmxBufferFailureHolder aFailureHolder);
110
111
  void NotifyError(OMX_ERRORTYPE aOmxError,
112
                   const char* aLine,
113
                   const MediaResult& aError = MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR));
114
115
  // Configure audio/video codec.
116
  // Some codec may just ignore this and rely on codec specific data in
117
  // FillCodecConfigDataToOmx().
118
  void ConfigCodec();
119
120
  // Sending codec specific data to OMX component. OMX component could send a
121
  // OMX_EventPortSettingsChanged back to client. And then client needs to
122
  // disable port and reallocate buffer.
123
  void FillCodecConfigDataToOmx();
124
125
  void SendEosBuffer();
126
127
  void EndOfStream();
128
129
  // It could be called after codec specific data is sent and component found
130
  // the port format is changed due to different codec specific.
131
  void PortSettingsChanged();
132
133
  void Output(BufferData* aData);
134
135
  // Buffer can be released if its status is not OMX_COMPONENT or
136
  // OMX_CLIENT_OUTPUT.
137
  bool BuffersCanBeReleased(OMX_DIRTYPE aType);
138
139
  OMX_DIRTYPE GetPortDirection(uint32_t aPortIndex);
140
141
  RefPtr<ShutdownPromise> DoAsyncShutdown();
142
143
  RefPtr<FlushPromise> DoFlush();
144
145
  void FlushComplete(OMX_COMMANDTYPE aCommandType);
146
147
  void FlushFailure(OmxCommandFailureHolder aFailureHolder);
148
149
  BUFFERLIST* GetBuffers(OMX_DIRTYPE aType);
150
151
  nsresult AllocateBuffers(OMX_DIRTYPE aType);
152
153
  nsresult ReleaseBuffers(OMX_DIRTYPE aType);
154
155
  BufferData* FindAvailableBuffer(OMX_DIRTYPE aType);
156
157
  // aType could be OMX_DirMax for all types.
158
  RefPtr<OmxPromiseLayer::OmxBufferPromise::AllPromiseType>
159
  CollectBufferPromises(OMX_DIRTYPE aType);
160
161
  // The Omx TaskQueue.
162
  RefPtr<TaskQueue> mOmxTaskQueue;
163
164
  RefPtr<TaskQueue> mTaskQueue;
165
166
  RefPtr<layers::ImageContainer> mImageContainer;
167
168
  WatchManager<OmxDataDecoder> mWatchManager;
169
170
  // It is accessed in omx TaskQueue.
171
  Watchable<OMX_STATETYPE> mOmxState;
172
173
  RefPtr<OmxPromiseLayer> mOmxLayer;
174
175
  UniquePtr<TrackInfo> mTrackInfo;
176
177
  // It is accessed in both omx and reader TaskQueue.
178
  Atomic<bool> mFlushing;
179
180
  // It is accessed in Omx/reader TaskQueue.
181
  Atomic<bool> mShuttingDown;
182
183
  // It is accessed in Omx TaskQeueu.
184
  bool mCheckingInputExhausted;
185
186
  // It is accessed in OMX TaskQueue.
187
  MozPromiseHolder<InitPromise> mInitPromise;
188
  MozPromiseHolder<DecodePromise> mDecodePromise;
189
  MozPromiseHolder<DecodePromise> mDrainPromise;
190
  MozPromiseHolder<FlushPromise> mFlushPromise;
191
  MozPromiseHolder<ShutdownPromise> mShutdownPromise;
192
  // Where decoded samples will be stored until the decode promise is resolved.
193
  DecodedData mDecodedData;
194
195
  void CompleteDrain();
196
197
  // It is written in Omx TaskQueue. Read in Omx TaskQueue.
198
  // It value means the port index which port settings is changed.
199
  // -1 means no port setting changed.
200
  //
201
  // Note: when port setting changed, there should be no buffer operations
202
  //       via EmptyBuffer or FillBuffer.
203
  Watchable<int32_t> mPortSettingsChanged;
204
205
  // It is access in Omx TaskQueue.
206
  nsTArray<RefPtr<MediaRawData>> mMediaRawDatas;
207
208
  BUFFERLIST mInPortBuffers;
209
210
  BUFFERLIST mOutPortBuffers;
211
212
  RefPtr<MediaDataHelper> mMediaDataHelper;
213
};
214
215
template<class T>
216
void InitOmxParameter(T* aParam)
217
0
{
218
0
  PodZero(aParam);
219
0
  aParam->nSize = sizeof(T);
220
0
  aParam->nVersion.s.nVersionMajor = 1;
221
0
}
Unexecuted instantiation: void mozilla::InitOmxParameter<OMX_AUDIO_PARAM_AACPROFILETYPE>(OMX_AUDIO_PARAM_AACPROFILETYPE*)
Unexecuted instantiation: void mozilla::InitOmxParameter<OMX_AUDIO_PARAM_PCMMODETYPE>(OMX_AUDIO_PARAM_PCMMODETYPE*)
Unexecuted instantiation: void mozilla::InitOmxParameter<OMX_AUDIO_PARAM_MP3TYPE>(OMX_AUDIO_PARAM_MP3TYPE*)
Unexecuted instantiation: void mozilla::InitOmxParameter<OMX_AUDIO_PARAM_AMRTYPE>(OMX_AUDIO_PARAM_AMRTYPE*)
Unexecuted instantiation: void mozilla::InitOmxParameter<OMX_PARAM_PORTDEFINITIONTYPE>(OMX_PARAM_PORTDEFINITIONTYPE*)
Unexecuted instantiation: void mozilla::InitOmxParameter<OMX_PORT_PARAM_TYPE>(OMX_PORT_PARAM_TYPE*)
222
223
}
224
225
#endif /* OmxDataDecoder_h_ */