24 #include <QElapsedTimer> 43 m_lock(QMutex::NonRecursive),
44 m_componentName(Component),
48 m_eventQueueLock(QMutex::NonRecursive),
58 if (status != OMX_ErrorNone || !
m_handle)
60 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"%1: Failed to get handle").arg(
m_componentName));
66 if ((
DisablePorts(OMX_IndexParamAudioInit) != OMX_ErrorNone) ||
67 (
DisablePorts(OMX_IndexParamImageInit) != OMX_ErrorNone) ||
68 (
DisablePorts(OMX_IndexParamVideoInit) != OMX_ErrorNone) ||
69 (
DisablePorts(OMX_IndexParamOtherInit) != OMX_ErrorNone))
84 OMX_PORT_PARAM_TYPE portparameters;
87 if (OMX_GetParameter(
m_handle, Domain, &portparameters) != OMX_ErrorNone)
89 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"%1: Failed to get port parameters").arg(
m_componentName));
98 for (OMX_U32 port = portparameters.nStartPortNumber; port < (portparameters.nStartPortNumber + portparameters.nPorts); ++port)
100 OMX_PARAM_PORTDEFINITIONTYPE portdefinition;
102 portdefinition.nPortIndex = port;
104 OMX_ERRORTYPE error = OMX_GetParameter(
m_handle, OMX_IndexParamPortDefinition, &portdefinition);
105 if (OMX_ErrorNone == error)
107 if (OMX_DirInput == portdefinition.eDir)
110 inports += QStringLiteral(
"%1 ").arg(port);
113 else if (OMX_DirOutput == portdefinition.eDir)
116 outports += QStringLiteral(
"%1 ").arg(port);
128 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"%1, %2: %3 input ports (%4), %5 output ports (%6)")
136 if (OMX_DirInput == Direction && (Index < (OMX_U32)
m_inputPorts.size()))
148 else if (OMX_DirOutput == Direction && (Index < (OMX_U32)
m_outputPorts.size()))
161 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"%1: Failed to find port (Dir: %1, Index %2, Domain %3)")
168 QMutexLocker locker(&
m_lock);
189 return component->
EventHandler(Component, Event, Data1, Data2, EventData);
191 return OMX_ErrorNone;
200 return OMX_ErrorNone;
209 return OMX_ErrorNone;
225 return OMX_ErrorUndefined;
227 QMutexLocker locker(&
m_lock);
228 OMX_ERRORTYPE error = OMX_SendCommand(
m_handle, OMX_CommandStateSet, State,
nullptr);
230 if (OMX_ErrorSameState == error)
232 return OMX_ErrorNone;
234 else if (OMX_ErrorNone == error)
238 if (OMX_ErrorSameState == error || OMX_ErrorNone == error)
241 return OMX_ErrorNone;
252 return OMX_StateInvalid;
254 QMutexLocker locker(&
m_lock);
257 OMX_ERRORTYPE error = OMX_GetState(
m_handle, &state);
258 if (OMX_ErrorNone == error)
262 return OMX_StateInvalid;
268 return OMX_ErrorUndefined;
270 QMutexLocker locker(&
m_lock);
273 return OMX_ErrorNone;
279 return OMX_ErrorUndefined;
281 QMutexLocker locker(&
m_lock);
284 return OMX_ErrorNone;
290 return OMX_ErrorUndefined;
292 QMutexLocker locker(&
m_lock);
295 return OMX_ErrorNone;
301 return OMX_ErrorUndefined;
303 QMutexLocker locker(&
m_lock);
306 return OMX_ErrorNone;
311 QMutexLocker locker(&
m_lock);
322 QMutexLocker locker(&
m_lock);
328 return OMX_ErrorUndefined;
352 return OMX_ErrorUndefined;
355 return OMX_ErrorNone;
361 return OMX_ErrorUndefined;
364 return OMX_ErrorNone;
369 QMutexLocker locker(&
m_lock);
375 return OMX_ErrorUndefined;
380 QMutexLocker locker(&
m_lock);
386 return OMX_ErrorUndefined;
400 QMutexLocker locker(&
m_lock);
406 return OMX_ErrorNone;
409 return OMX_ErrorUndefined;
416 return OMX_ErrorBadParameter;
425 return OMX_ErrorNone;
430 if (
m_handle != Component || !Buffer)
431 return OMX_ErrorBadParameter;
437 return OMX_ErrorUndefined;
443 return OMX_ErrorBadParameter;
449 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"No buffers allocated for output"));
450 return OMX_ErrorUndefined;
456 return OMX_ErrorUndefined;
458 QMutexLocker locker(&
m_lock);
461 return OMX_ErrorNone;
469 LOG(VB_GENERAL, LOG_DEBUG, QStringLiteral(
"%1: Waiting for %2 %3")
472 while (timer.elapsed() < Timeout)
481 if (event.m_type == OMX_EventCmdComplete && event.m_data1 == Command && event.m_data2 == Data2)
485 return OMX_ErrorNone;
487 else if (event.m_type == Command)
489 LOG(VB_GENERAL, LOG_DEBUG, QStringLiteral(
"1 %1 2 %2").arg(event.m_data1).arg(event.m_data2));
492 return OMX_ErrorNone;
494 else if (event.m_type == OMX_EventError)
496 OMX_ERRORTYPE omxerror = (OMX_ERRORTYPE)event.m_data1;
497 if (omxerror == OMX_ErrorSameState && event.m_data2 == 1)
501 return OMX_ErrorNone;
504 LOG(VB_GENERAL, (omxerror == OMX_ErrorPortUnpopulated) ? LOG_DEBUG : LOG_ERR, QStringLiteral(
"%1: Error event '%2' data2 %3")
506 OMX_ERRORTYPE error = (OMX_ERRORTYPE)event.m_data1;
517 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"%1: Response never received for command %2 %3")
525 return OMX_ErrorUndefined;
527 QMutexLocker locker(&
m_lock);
529 OMX_PORT_PARAM_TYPE portparameters;
534 for (OMX_U32 i = 0; i < portparameters.nPorts; ++i)
536 OMX_PARAM_PORTDEFINITIONTYPE portdefinition;
538 OMX_U32 portnumber = portparameters.nStartPortNumber + i;
539 portdefinition.nPortIndex = portnumber;
541 if (OMX_GetParameter(
m_handle, OMX_IndexParamPortDefinition, &portdefinition) == OMX_ErrorNone)
543 OMX_ERRORTYPE error = OMX_SendCommand(
m_handle, OMX_CommandPortDisable, portnumber,
nullptr);
544 if (OMX_ErrorNone == error)
547 if (OMX_ErrorNone != error)
559 portdefinition.bEnabled = OMX_FALSE;
563 return OMX_ErrorNone;
OMX_ERRORTYPE Flush(void)
QString StateToString(OMX_STATETYPE State)
OMX_U32 GetInUseBuffers(void)
OMX_ERRORTYPE FillBufferDone(OMX_HANDLETYPE Component, OMX_BUFFERHEADERTYPE *Buffer)
OMX_U32 GetInUseBuffers(OMX_DIRTYPE Direction, OMX_U32 Index, OMX_INDEXTYPE Domain)
OMX_ERRORTYPE SetState(OMX_STATETYPE State, bool Wait=true)
OMX_U32 GetPort(OMX_DIRTYPE Direction, OMX_U32 Index, OMX_INDEXTYPE Domain)
OMX_ERRORTYPE DestroyBuffers(void)
OMX_BUFFERHEADERTYPE * GetBuffer(OMX_DIRTYPE Direction, OMX_U32 Index, OMX_U32 Timeout, OMX_INDEXTYPE Domain)
QString ErrorToString(OMX_ERRORTYPE Error)
TorcOMXComponent(OMX_STRING Component)
OMX_ERRORTYPE MakeAvailable(OMX_BUFFERHEADERTYPE *Buffer)
OMX_ERRORTYPE SetConfig(OMX_INDEXTYPE Index, OMX_PTR Structure)
OMX_ERRORTYPE DestroyBuffers(OMX_DIRTYPE Direction, OMX_U32 Index, OMX_INDEXTYPE Domain)
TorcOMXEvent(OMX_EVENTTYPE Type, OMX_U32 Data1, OMX_U32 Data2)
QList< TorcOMXPort * > m_outputPorts
QString CommandToString(OMX_COMMANDTYPE Command)
QWaitCondition m_eventQueueWait
OMX_ERRORTYPE EnablePort(OMX_DIRTYPE Direction, OMX_U32 Index, bool Enable, OMX_INDEXTYPE Domain, bool Wait=true)
TorcOMXPort * FindPort(OMX_DIRTYPE Direction, OMX_U32 Index, OMX_INDEXTYPE Domain)
static OMX_ERRORTYPE EmptyBufferDoneCallback(OMX_HANDLETYPE Component, OMX_PTR OMXComponent, OMX_BUFFERHEADERTYPE *Buffer)
OMX_U32 GetAvailableBuffers(void)
OMX_ERRORTYPE CreateBuffers(QObject *Owner=nullptr)
OMX_ERRORTYPE EmptyThisBuffer(OMX_BUFFERHEADERTYPE *Buffer)
OMX_ERRORTYPE SendCommand(OMX_COMMANDTYPE Command, OMX_U32 Parameter, OMX_PTR Data)
QString DomainToString(OMX_INDEXTYPE Domain)
static OMX_ERRORTYPE FillBufferDoneCallback(OMX_HANDLETYPE Component, OMX_PTR OMXComponent, OMX_BUFFERHEADERTYPE *Buffer)
OMX_ERRORTYPE CreateBuffers(OMX_DIRTYPE Direction, OMX_U32 Index, OMX_INDEXTYPE Domain, QObject *Owner=nullptr)
OMX_ERRORTYPE EnablePort(bool Enable, bool Wait=true)
OMX_ERRORTYPE EventHandler(OMX_HANDLETYPE Component, OMX_EVENTTYPE Event, OMX_U32 Data1, OMX_U32 Data2, OMX_PTR EventData)
QList< TorcOMXEvent > m_eventQueue
OMX_HANDLETYPE GetHandle(void)
OMX_STATETYPE GetState(void)
static OMX_ERRORTYPE EventHandlerCallback(OMX_HANDLETYPE Component, OMX_PTR OMXComponent, OMX_EVENTTYPE Event, OMX_U32 Data1, OMX_U32 Data2, OMX_PTR EventData)
#define OMX_ERROR(Error, Component, Message)
#define OMX_CHECK(Error, Component, Message)
#define LOG(_MASK_, _LEVEL_, _STRING_)
OMX_U32 GetAvailableBuffers(OMX_DIRTYPE Direction, OMX_U32 Index, OMX_INDEXTYPE Domain)
OMX_ERRORTYPE GetParameter(OMX_INDEXTYPE Index, OMX_PTR Structure)
OMX_ERRORTYPE GetConfig(OMX_INDEXTYPE Index, OMX_PTR Structure)
QString EventToString(OMX_EVENTTYPE Event)
OMX_ERRORTYPE FlushBuffer(OMX_DIRTYPE Direction, OMX_U32 Index, OMX_INDEXTYPE Domain)
OMX_BUFFERHEADERTYPE * GetBuffer(OMX_S32 Timeout)
QList< TorcOMXPort * > m_inputPorts
OMX_ERRORTYPE EmptyBufferDone(OMX_HANDLETYPE Component, OMX_BUFFERHEADERTYPE *Buffer)
static OMX_CALLBACKTYPE gCallbacks
OMX_ERRORTYPE SetParameter(OMX_INDEXTYPE Index, OMX_PTR Structure)
OMX_ERRORTYPE WaitForResponse(OMX_U32 Command, OMX_U32 Data2, OMX_S32 Timeout)
void AnalysePorts(OMX_INDEXTYPE Domain)
OMX_ERRORTYPE FillThisBuffer(OMX_BUFFERHEADERTYPE *Buffer)
#define OMX_INITSTRUCTURE(Struct)
OMX_ERRORTYPE DisablePorts(OMX_INDEXTYPE Domain)