24 #include <QElapsedTimer> 36 m_lock(QMutex::NonRecursive),
61 if (!m_handle || !m_parent)
62 return OMX_ErrorUndefined;
64 OMX_PARAM_PORTDEFINITIONTYPE portdefinition;
66 portdefinition.nPortIndex = m_port;
68 OMX_ERRORTYPE error = OMX_GetParameter(m_handle, OMX_IndexParamPortDefinition, &portdefinition);
69 OMX_CHECK(error, m_parent->
GetName(), QStringLiteral(
"Failed to get port definition"));
71 if (portdefinition.bEnabled == OMX_FALSE && Enable)
73 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"%1: Enabling port %2").arg(m_parent->
GetName()).arg(m_port));
74 error = OMX_SendCommand(m_handle, OMX_CommandPortEnable, m_port,
nullptr);
75 OMX_CHECK(error, m_parent->
GetName(), QStringLiteral(
"Failed to send command"));
81 else if (portdefinition.bEnabled == OMX_TRUE && !Enable)
83 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"%1: Disabling port %2").arg(m_parent->
GetName()).arg(m_port));
84 error = OMX_SendCommand(m_handle, OMX_CommandPortDisable, m_port,
nullptr);
85 OMX_CHECK(error, m_parent->
GetName(), QStringLiteral(
"Failed to send command"));
98 OMX_U32 result = m_availableBuffers.size();
106 OMX_U32 result = m_buffers.size() - m_availableBuffers.size();
114 return OMX_ErrorUndefined;
116 QMutexLocker locker(&m_lock);
120 connect(
this, SIGNAL(
BufferReady(OMX_BUFFERHEADERTYPE*, quint64)), m_owner, SLOT(
BufferReady(OMX_BUFFERHEADERTYPE*, quint64)), Qt::QueuedConnection);
122 OMX_PARAM_PORTDEFINITIONTYPE portdefinition;
124 portdefinition.nPortIndex = m_port;
126 OMX_ERRORTYPE error = OMX_GetParameter(m_handle, OMX_IndexParamPortDefinition, &portdefinition);
127 OMX_CHECK(error, m_parent->
GetName(), QStringLiteral(
"Failed to get port definition"));
129 m_alignment = portdefinition.nBufferAlignment;
131 for (OMX_U32 i = 0; i < portdefinition.nBufferCountActual; ++i)
133 OMX_BUFFERHEADERTYPE *buffer =
nullptr;
134 error = OMX_AllocateBuffer(m_handle, &buffer, m_port,
nullptr, portdefinition.nBufferSize);
135 if (OMX_ErrorNone != error)
137 OMX_ERROR(error, m_parent->
GetName(), QStringLiteral(
"Failed to allocate buffer"));
141 buffer->pAppPrivate = (
void*)
this;
142 buffer->nFilledLen = 0;
144 buffer->nInputPortIndex = m_port;
146 m_buffers.append(buffer);
147 m_availableBuffers.enqueue(buffer);
150 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"%1: Created %2 %3byte buffers")
151 .arg(m_parent->
GetName()).arg(portdefinition.nBufferCountActual).arg(portdefinition.nBufferSize));
153 return OMX_ErrorNone;
158 if (!m_handle || !m_parent)
159 return OMX_ErrorUndefined;
163 disconnect(
this, SIGNAL(
BufferReady(OMX_BUFFERHEADERTYPE*, quint64)), m_owner, SLOT(
BufferReady(OMX_BUFFERHEADERTYPE*, quint64)));
170 QMutexLocker locker(&m_lock);
171 for (
int i = 0; i < m_buffers.size(); ++i)
173 OMX_ERRORTYPE error = OMX_FreeBuffer(m_handle, m_port, m_buffers.at(i));
178 m_availableBuffers.clear();
182 return OMX_ErrorNone;
187 if (!m_handle || !m_parent)
188 return OMX_ErrorUndefined;
190 QMutexLocker locker(&m_lock);
192 OMX_ERRORTYPE error = OMX_SendCommand(m_handle, OMX_CommandFlush, m_port,
nullptr);
193 OMX_CHECK(error, m_parent->
GetName(), QStringLiteral(
"Failed to send command"));
195 return OMX_ErrorNone;
201 if (!m_buffers.contains(Buffer))
202 LOG(VB_GENERAL, LOG_WARNING, QStringLiteral(
"%1: Unknown buffer").arg(m_parent->
GetName()));
203 m_availableBuffers.enqueue(Buffer);
208 return OMX_ErrorNone;
213 OMX_BUFFERHEADERTYPE* result =
nullptr;
220 while (timer.elapsed() < Timeout)
222 if (!m_availableBuffers.isEmpty())
224 result = m_availableBuffers.dequeue();
229 m_wait.wait(&m_lock, 10);
233 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"%1: Timed out waiting for available buffer").arg(m_parent->
GetName()));
OMX_ERRORTYPE Flush(void)
OMX_U32 GetInUseBuffers(void)
OMX_ERRORTYPE DestroyBuffers(void)
OMX_ERRORTYPE MakeAvailable(OMX_BUFFERHEADERTYPE *Buffer)
TorcOMXPort(TorcOMXComponent *Parent, OMX_HANDLETYPE Handle, OMX_U32 Port, OMX_INDEXTYPE Domain)
OMX_U32 GetAvailableBuffers(void)
OMX_ERRORTYPE CreateBuffers(QObject *Owner=nullptr)
OMX_ERRORTYPE EnablePort(bool Enable, bool Wait=true)
#define OMX_CHECKX(Error, Component, Message)
#define OMX_ERROR(Error, Component, Message)
OMX_INDEXTYPE GetDomain(void)
#define OMX_CHECK(Error, Component, Message)
#define LOG(_MASK_, _LEVEL_, _STRING_)
void BufferReady(OMX_BUFFERHEADERTYPE *Buffer, quint64 Type)
OMX_BUFFERHEADERTYPE * GetBuffer(OMX_S32 Timeout)
OMX_ERRORTYPE WaitForResponse(OMX_U32 Command, OMX_U32 Data2, OMX_S32 Timeout)
#define OMX_INITSTRUCTURE(Struct)