while (1) {
OMWaitForXPortSettingsChanged();
+ fprintf(stderr, "Port settings changed...\n");
+
hello_video->port_settings_changed();
hello_video->fill_buffer();
}
unsigned int num = 0;
for (unsigned int i = 0; i < size; i++)
{
-#if 0
- if (source[i] == 0x00)
- if (source[i + 1] == 0x00)
- if (source[i + 2] == 0x00)
-#else
if ((source[i] + source[i + 1] + source[i + 2]) == 0x00)
-#endif
if (source[i + 3] == 0x01)
{
// fprintf(stderr, "%s[%d]i(%d)\n", __func__, __LINE__, i);
OMX_EVENTTYPE event, OMX_U32 data1,
OMX_U32 data2, OMX_PTR eventData)
{
- fprintf(stderr, "%s[%d]\n", __func__, __LINE__);
switch(event) {
+ case OMX_EventPortSettingsChanged:
+ OMXWakeupPortSettingsChanged();
+ break;
case OMX_EventCmdComplete:
switch (data1) {
case OMX_CommandStateSet:
case OMX_EventError:
fprintf(stderr, "Err:%s[%d]%s\n.", __func__, __LINE__, hello_video2::OMX_strerror((OMX_ERRORTYPE) data1));
break;
- case OMX_EventPortSettingsChanged:
- fprintf(stderr, "Port settings changed...\n");
- OMXWakeupPortSettingsChanged();
- break;
case OMX_EventBufferFlag:
- fprintf(stderr, "%s[%d]OMX_EventBufferFlag\n", __func__, __LINE__);
+ fprintf(stderr, "%s[%d]OMX_EventBufferFlag, data1(%d), data1(%d)\n", __func__, __LINE__, data1, data2);
break;
case OMX_EventResourcesAcquired:
fprintf(stderr, "%s[%d]OMX_EventResourcesAcquired\n", __func__, __LINE__);
fprintf(stderr, "phello_video2->output_buffer_usage:0x%08x,pAppPrivate:0x%08x,nFilledLenL:%d\n", phello_video2->output_buffer_usage, *((unsigned int *)buffer->pAppPrivate), buffer->nFilledLen);
OMXWakeUpFilled();
- OMXWakeUpFilled();
-
if (buffer->nFilledLen == 0) {
phello_video2->fill_buffer();
bcm_host_init();
hello_video2::Init();
-
+
input_buffer_usage = 0;
output_buffer_usage = 0;
input_buffer_number[0] = 0;
/******************************************************************************/
-hello_video2::~hello_video2()
+hello_video2::~hello_video2()
{
}
{
OMX_SendCommand(component, OMX_CommandStateSet, nState, NULL);
OMXWaitForState(nState);
+
return OMX_ErrorNone;
-};
+}
OMX_ERRORTYPE hello_video2::block_until_port_changed(OMX_HANDLETYPE hComponent, OMX_U32 nPortIndex, OMX_BOOL bEnabled) {
OMX_ERRORTYPE r;
void * pStart = &data[nalu[i].pos];
memcpy(iBuffer->pBuffer, pStart, nalu[i].size);
iBuffer->nOffset = 0;
- iBuffer->nFlags = OMX_BUFFERFLAG_EOS;
+// iBuffer->nFlags = OMX_BUFFERFLAG_EOS;
iBuffer->nFilledLen = nalu[i].size;
input_buffer_usage ^= *((unsigned int *)iBuffer->pAppPrivate);
OMX_EmptyThisBuffer(component, iBuffer);
return OMX_ErrorNone;
}
+
OMX_ERRORTYPE hello_video2::fill_buffer()
{
OMX_BUFFERHEADERTYPE *out_buffer;
out_buffer = get_free_output_buffer();
+
OMX_FillThisBuffer(component, out_buffer);
return OMX_ErrorNone;
ErrorCode = OMX_AllocateBuffer(component, &input_buffer_header[i], 130, pPrivateData, input_port_def.nBufferSize);
if (ErrorCode == OMX_ErrorNone) {
- fprintf(stderr, "Okay:prepare_input_buffers:Output buffer %u allocated,%d.\n", i + 1, input_port_def.nBufferSize);
+ fprintf(stderr, "Okay:prepare_input_buffers:Input buffer %u allocated,%d.\n", i + 1, input_port_def.nBufferSize);
}
else {
- fprintf(stderr, "Err:prepare_input_buffers:%d. %s\n", i, OMX_strerror(ErrorCode));
+ fprintf(stderr, "Err:prepare_input_buffers:%d. %s\n", i, OMX_strerror(ErrorCode));
}
}
fprintf(stderr, "Okay:prepare_output_buffers: Port %d: Output buffer %d: allocated %d:buff %p:output_buffer_usage 0x%x\n", output_port_def.nPortIndex, i + 1, output_port_def.nBufferSize, buf, output_buffer_usage);
}
else {
- fprintf(stderr, "Err:prepare_output_buffers:%d. %s\n", i, OMX_strerror(ErrorCode));
+ fprintf(stderr, "Err:prepare_output_buffers:%d. %s\n", i, OMX_strerror(ErrorCode));
}
}
return input_buffer_header[i];
}
}
- OMXWaitForEmpty();
}
+ GetFreeOutBufferUnlock();
+
return NULL;
}
OMX_BUFFERHEADERTYPE * hello_video2::get_free_output_buffer()
{
+ GetFreeOutBufferLock();
+
if (output_buffer_usage == 0) {
for (unsigned int i = 0; i < output_port_def.nBufferCountActual; i++) {
- output_buffer_usage |= 0x1 < i;
- }
+ output_buffer_usage |= 0x1 << i;
+ }
}
while (true)
for (unsigned int i = 0; i < output_port_def.nBufferCountActual; i++) {
if ((output_buffer_usage & *((unsigned int *)output_buffer_header[i]->pAppPrivate)) != 0) {
output_buffer_usage &= ~(*((unsigned int *)output_buffer_header[i]->pAppPrivate));
- fprintf(stderr, "get_free_output_buffer:0x%08x\n", output_buffer_usage);
+ GetFreeOutBufferUnlock();
+ fprintf(stderr, "get_free_output_buffer:output_buffer_usage==0x%08x\n", output_buffer_usage);
return output_buffer_header[i];
}
}
- fprintf(stderr, "OMXWaitForFilled wait..\n");
+
OMXWaitForFilled();
- fprintf(stderr, "OMXWaitForFilled done!.\n");
}
return NULL;
////////////////////////////////////////////////////////////////////
// //
// I dont worry form now. //
-// //
+// //
////////////////////////////////////////////////////////////////////
return 0;
void** data;
} DUMP_FILE_INFO;
-pthread_mutex_t OMXMutex, OMXEmptyMutex, OMXFilledMutex, OMXPortSettingsChangedMutex;
+pthread_mutex_t OMXMutex, OMXEmptyMutex, OMXFilledMutex, OMXPortSettingsChangedMutex, OMXGetFreeOutBufferMutex;
pthread_cond_t OMXStateCond, OMXEmptyCond, OMXFilledCond, OMXPortSettingsChangedCond;
void mutex_init()
printf("Can't init port settings changed mutex.\n");
}
+ if (pthread_mutex_init(&OMXGetFreeOutBufferMutex, NULL) != 0) {
+ printf("Can't init OMXGetFreeOutBufferMutex mutex.\n");
+ }
+
OMXStateCond = PTHREAD_COND_INITIALIZER;
OMXEmptyCond = PTHREAD_COND_INITIALIZER;
OMXFilledCond = PTHREAD_COND_INITIALIZER;
/*****************************************************************************/
hello_video2 * phello_video2 = NULL;
-/**/
+
+/*****************************************************************************/
+
+void GetFreeOutBufferLock()
+{
+ pthread_mutex_lock(&OMXGetFreeOutBufferMutex);
+}
+void GetFreeOutBufferUnlock()
+{
+ pthread_mutex_unlock(&OMXGetFreeOutBufferMutex);
+}
+
+/*****************************************************************************/
+
void OMXWaitForState(OMX_STATETYPE nState)
{
pthread_mutex_lock(&OMXMutex);
unsigned int num = 0;
for (unsigned int i = 0; i < size; i++)
{
-#if 0
- if (source[i] == 0x00)
- if (source[i + 1] == 0x00)
- if (source[i + 2] == 0x00)
-#else
if ((source[i] + source[i + 1] + source[i + 2]) == 0x00)
-#endif
if (source[i + 3] == 0x01)
{
// fprintf(stderr, "%s[%d]i(%d)\n", __func__, __LINE__, i);
{
fprintf(stderr, "phello_video2->output_buffer_usage:0x%08x,pAppPrivate:0x%08x,nFilledLenL:%d\n", phello_video2->output_buffer_usage, *((unsigned int *)buffer->pAppPrivate), buffer->nFilledLen);
OMXWakeUpFilled();
-
+
fprintf(stderr, "buffer filled done:%p\n", buffer->pBuffer);
if (buffer->nFilledLen == 0) {
phello_video2->fill_buffer();
/******************************************************************************/
-hello_video2::~hello_video2()
+hello_video2::~hello_video2()
{
}
{
OMX_SendCommand(component, OMX_CommandStateSet, nState, NULL);
OMXWaitForState(nState);
+
return OMX_ErrorNone;
-};
+}
OMX_ERRORTYPE hello_video2::block_until_port_changed(OMX_HANDLETYPE hComponent, OMX_U32 nPortIndex, OMX_BOOL bEnabled) {
OMX_ERRORTYPE r;
void * pStart = &data[nalu[i].pos];
memcpy(iBuffer->pBuffer, pStart, nalu[i].size);
iBuffer->nOffset = 0;
- iBuffer->nFlags = OMX_BUFFERFLAG_EOS;
+// iBuffer->nFlags = OMX_BUFFERFLAG_EOS;
iBuffer->nFilledLen = nalu[i].size;
input_buffer_usage ^= *((unsigned int *)iBuffer->pAppPrivate);
OMX_EmptyThisBuffer(component, iBuffer);
ErrorCode = OMX_AllocateBuffer(component, &input_buffer_header[i], 130, pPrivateData, input_port_def.nBufferSize);
if (ErrorCode == OMX_ErrorNone) {
- fprintf(stderr, "Okay:prepare_input_buffers:Output buffer %u allocated,%d.\n", i + 1, input_port_def.nBufferSize);
+ fprintf(stderr, "Okay:prepare_input_buffers:Input buffer %u allocated,%d.\n", i + 1, input_port_def.nBufferSize);
}
else {
- fprintf(stderr, "Err:prepare_input_buffers:%d. %s\n", i, OMX_strerror(ErrorCode));
+ fprintf(stderr, "Err:prepare_input_buffers:%d. %s\n", i, OMX_strerror(ErrorCode));
}
}
} else {
buf = (OMX_U8*)malloc(output_port_def.nBufferSize);
}
-
+
#if 1 // Check if handle_bo.ptr is valid.
memset(handle_bo.ptr, 0x00, output_port_def.nBufferSize);
#endif // Check
- ErrorCode = OMX_UseBuffer(component, &output_buffer_header[i], output_port_def.nPortIndex, pPrivateData, output_port_def.nBufferSize, buf);
+ ErrorCode = OMX_UseBuffer(component, &output_buffer_header[i], output_port_def.nPortIndex, pPrivateData, output_port_def.nBufferSize, buf + 8);
if (ErrorCode == OMX_ErrorNone) {
fprintf(stderr, "Okay:prepare_output_buffers: Port %d: Output buffer %d: allocated %d:buff %p:output_buffer_usage 0x%x\n", output_port_def.nPortIndex, i + 1, output_port_def.nBufferSize, buf, output_buffer_usage);
}
else {
- fprintf(stderr, "Err:prepare_output_buffers:%d. %s\n", i, OMX_strerror(ErrorCode));
+ fprintf(stderr, "Err:prepare_output_buffers:%d. %s\n", i, OMX_strerror(ErrorCode));
}
}
OMX_BUFFERHEADERTYPE * hello_video2::get_free_output_buffer()
{
+ GetFreeOutBufferLock();
+
if (output_buffer_usage == 0) {
for (unsigned int i = 0; i < output_port_def.nBufferCountActual; i++) {
- output_buffer_usage |= 0x1 < i;
- }
+ output_buffer_usage |= 0x1 << i;
+ }
}
while (true)
for (unsigned int i = 0; i < output_port_def.nBufferCountActual; i++) {
if ((output_buffer_usage & *((unsigned int *)output_buffer_header[i]->pAppPrivate)) != 0) {
output_buffer_usage &= ~(*((unsigned int *)output_buffer_header[i]->pAppPrivate));
- fprintf(stderr, "get_free_output_buffer:0x%08x\n", output_buffer_usage);
+ GetFreeOutBufferUnlock();
+ fprintf(stderr, "get_free_output_buffer:output_buffer_usage==0x%08x\n", output_buffer_usage);
return output_buffer_header[i];
}
}
- fprintf(stderr, "OMXWaitForFilled wait..\n");
+
OMXWaitForFilled();
- fprintf(stderr, "OMXWaitForFilled done!.\n");
}
return NULL;
////////////////////////////////////////////////////////////////////
// //
// I dont worry form now. //
-// //
+// //
////////////////////////////////////////////////////////////////////
return 0;
void** data;
} DUMP_FILE_INFO;
-pthread_mutex_t OMXMutex, OMXEmptyMutex, OMXFilledMutex, OMXPortSettingsChangedMutex;
+pthread_mutex_t OMXMutex, OMXEmptyMutex, OMXFilledMutex, OMXPortSettingsChangedMutex, OMXGetFreeOutBufferMutex;
pthread_cond_t OMXStateCond, OMXEmptyCond, OMXFilledCond, OMXPortSettingsChangedCond;
void mutex_init()
printf("Can't init port settings changed mutex.\n");
}
+ if (pthread_mutex_init(&OMXGetFreeOutBufferMutex, NULL) != 0) {
+ printf("Can't init OMXGetFreeOutBufferMutex mutex.\n");
+ }
+
OMXStateCond = PTHREAD_COND_INITIALIZER;
OMXEmptyCond = PTHREAD_COND_INITIALIZER;
OMXFilledCond = PTHREAD_COND_INITIALIZER;
/*****************************************************************************/
hello_video2 * phello_video2 = NULL;
+
+/*****************************************************************************/
+
+void GetFreeOutBufferLock()
+{
+ pthread_mutex_lock(&OMXGetFreeOutBufferMutex);
+}
+void GetFreeOutBufferUnlock()
+{
+ pthread_mutex_unlock(&OMXGetFreeOutBufferMutex);
+}
+
+/*****************************************************************************/
+
void OMXWaitForState(OMX_STATETYPE nState)
{
pthread_mutex_lock(&OMXMutex);