void ImageOMX::init()
{
- AllocateCodecsOMX();
+ // AllocateCodecsOMX();
}
void ImageOMX::shutdown()
{
Log::getInstance()->log("ImageOMX", Log::DEBUG, "shutdown");
- DeAllocateCodecsOMX();
+ //DeAllocateCodecsOMX();
}
void ImageOMX::ReturnEmptyOMXBuffer(OMX_BUFFERHEADERTYPE* buffer){
input_bufs_omx_mutex.Lock();
- if (buffer->pBuffer) {
+ /*if (buffer->pBuffer) {
free(buffer->pBuffer);
buffer->pBuffer = NULL;
- }
+ }*/
buffer->nAllocLen= 0;
//Log::getInstance()->log("Image", Log::NOTICE, "ReturnEmptyOMXBuffer %d",input_bufs_omx_free.size());
input_bufs_omx_free.push_back(buffer);
//Log::getInstance()->log("Image", Log::NOTICE, "ReturnEmptyOMXBuffer %d",input_bufs_omx_free.size());
input_bufs_omx_mutex.Unlock();
+ VideoOMX *video=(VideoOMX*)Video::getInstance();
+ video->signalOmx();
}
OMX_ERRORTYPE ImageOMX::FillBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp, OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* buffer) {
omx_egl_filled = true;
//output_bufs_omx_full.push_back(buffer);
//input_bufs_omx_mutex.Unlock();
+ VideoOMX *video=(VideoOMX*)Video::getInstance();
+ video->signalOmx();
}
-int ImageOMX::AllocateCodecsOMX()
+int ImageOMX::AllocateCodecsOMX(unsigned char * buffer, unsigned int length)
{
OMX_ERRORTYPE error;
static OMX_CALLBACKTYPE callbacks= {&VideoOMX::EventHandler_OMX,&EmptyBufferDone_OMX,&FillBufferDone_OMX};
- if (!PrepareInputBufsOMX(true)) {
+ if (!PrepareInputBufsOMX(true, buffer, length)) {
video->UnlockClock();
Log::getInstance()->log("Image", Log::DEBUG, "prepare input bufs failed");
DeAllocateCodecsOMX();
}
- if (!video->ChangeComponentState(omx_egl_render,OMX_StateExecuting)) {
- Log::getInstance()->log("Image", Log::DEBUG, "omx_egl_rendd ChangeComponentState Execute");
- video->UnlockClock();
- DeAllocateCodecsOMX();
- return 0;
- }
+
if (!video->EnablePort(omx_imag_decode,omx_image_input_port,false)
) {
if (!pictcreat) return false;
+ int oldcancelstate;
+ int oldcanceltype;
+ pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate);
+ pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype);
+
+ if (!AllocateCodecsOMX(buffer,length)) {
+ DeAllocateCodecsOMX();
+ pthread_setcancelstate(oldcancelstate, NULL);
+ pthread_setcanceltype(oldcanceltype, NULL);
+ return false;
+ }
+ bool ret=intDecodePicture(index, buffer, length, pictcreat, video);
+ DeAllocateCodecsOMX();
+ pthread_setcancelstate(oldcancelstate, NULL);
+ pthread_setcanceltype(oldcanceltype, NULL);
+ if (ret) free(buffer);
+
+ return ret;
+}
+
+
+bool ImageOMX::intDecodePicture(LoadIndex index, unsigned char * buffer, unsigned int length, EGLPictureCreator* pictcreat, VideoOMX *video)
+{
+
// Use Buffer
OMX_BUFFERHEADERTYPE * bufhead;
}
bufhead=input_bufs_omx_free.front();
bufhead->nFilledLen=length;
- bufhead->nAllocLen= length;
+ //bufhead->nAllocLen= length;
bufhead->nOffset=0;
bufhead->nTimeStamp=VideoOMX::intToOMXTicks(0);
- bufhead->pBuffer=buffer;
+ //bufhead->pBuffer=buffer;
bufhead->pAppPrivate=this;
input_bufs_omx_free.pop_front();
input_bufs_omx_mutex.Unlock();
- bufhead->nFilledLen=bufhead->nAllocLen;
+ bufhead->nFilledLen=length;//bufhead->nAllocLen;
+ bufhead->nFlags=OMX_BUFFERFLAG_EOS;
video->ProtOMXEmptyThisBuffer(omx_imag_decode, bufhead);
- int oldcancelstate;
- int oldcanceltype;
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldcancelstate);
- pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype);
+
video->LockClock();
Log::getInstance()->log("Image", Log::DEBUG,
port_def_type.nSize=sizeof(port_def_type);
port_def_type.nVersion.nVersion=OMX_VERSION;
port_def_type.nPortIndex=omx_image_output_port;
+ Log::getInstance()->log("Image", Log::DEBUG,
+ "decodePicture 3a");
error=OMX_GetParameter(omx_imag_decode,OMX_IndexParamPortDefinition, &port_def_type);
if (error != OMX_ErrorNone) {
Log::getInstance()->log("Image", Log::DEBUG,
"OMX_IndexParamPortDefinition fix failed %x", error);
video->UnlockClock();
- pthread_setcancelstate(oldcancelstate, NULL);
- pthread_setcanceltype(oldcanceltype, NULL);
return false;
}
Log::getInstance()->log("Image", Log::DEBUG,
video->DisablePort(omx_egl_render,omx_egl_output_port,true);
- video->DisablePort(omx_egl_render,omx_egl_input_port,false);
Log::getInstance()->log("Image", Log::DEBUG,
- "decodePicture 6");
+ "decodePicture 4 a");
+
video->DisablePort(omx_imag_decode,omx_image_output_port,false);
Log::getInstance()->log("Image", Log::DEBUG,
"decodePicture 5");
+ video->DisablePort(omx_egl_render,omx_egl_input_port,false);
+ Log::getInstance()->log("Image", Log::DEBUG,
+ "decodePicture 6");
+
- if ( !video->CommandFinished(omx_egl_render,OMX_CommandPortDisable,omx_egl_input_port)) {
- video->UnlockClock();
- Log::getInstance()->log("Image", Log::DEBUG, "commandfinishes end eip");
- DeAllocateCodecsOMX();
- return 0;
- }
if ( !video->CommandFinished(omx_imag_decode,OMX_CommandPortDisable,omx_image_output_port)) {
video->UnlockClock();
Log::getInstance()->log("Image", Log::DEBUG, "commandfinishes end iop");
- DeAllocateCodecsOMX();
- return 0;
+ return false;
+ }
+
+ if ( !video->CommandFinished(omx_egl_render,OMX_CommandPortDisable,omx_egl_input_port)) {
+ video->UnlockClock();
+ Log::getInstance()->log("Image", Log::DEBUG, "commandfinishes end eip");
+ return false;
}
port_def_type.format.image.eColorFormat = OMX_COLOR_FormatYUV420PackedPlanar;
Log::getInstance()->log("Image", Log::DEBUG,
"Set OMX_IndexParamPortDefinition1 failed %x", error);
video->UnlockClock();
- pthread_setcancelstate(oldcancelstate, NULL);
- pthread_setcanceltype(oldcanceltype, NULL);
return false;
}
Log::getInstance()->log("Image", Log::DEBUG,
"OMX_IndexParamPortDefinition fix failed %x", error);
video->UnlockClock();
- pthread_setcancelstate(oldcancelstate, NULL);
- pthread_setcanceltype(oldcanceltype, NULL);
return false;
}
Log::getInstance()->log("Image", Log::DEBUG,
"getEGLPict failed");
video->UnlockClock();
- pthread_setcancelstate(oldcancelstate, NULL);
- pthread_setcanceltype(oldcanceltype, NULL);
return false;
}
+ Log::getInstance()->log("Image", Log::DEBUG,
+ "getEGLPict %x",pictInf.reference);
port_def_type.format.video.pNativeWindow = egl_display;
error = OMX_SetParameter(omx_egl_render, OMX_IndexParamPortDefinition,
Log::getInstance()->log("Image", Log::DEBUG,
"Set OMX_IndexParamPortDefinition3 failed %x", error);
video->UnlockClock();
- pthread_setcancelstate(oldcancelstate, NULL);
- pthread_setcanceltype(oldcanceltype, NULL);
return false;
}
if (error!=OMX_ErrorNone){
Log::getInstance()->log("Image", Log::DEBUG, "Use OMX_UseEGLImage failed %x", error);
video->UnlockClock();
- pthread_setcancelstate(oldcancelstate, NULL);
- pthread_setcanceltype(oldcanceltype, NULL);
return false;
}
buf_head_egl->pAppPrivate=this;
Log::getInstance()->log("Image", Log::DEBUG,
"decodePicture 8 a");
+ video->EnablePort(omx_imag_decode,omx_image_output_port,false);
+
+ if (!video->CommandFinished(omx_egl_render/*dec*/,OMX_CommandPortEnable, omx_egl_output_port /*codec*/)) {
+ video->UnlockClock();
+ return false;
+ }
Log::getInstance()->log("Image", Log::DEBUG,
"decodePicture 8 end");
- video->EnablePort(omx_imag_decode,omx_image_output_port,false);
+ if (!video->ChangeComponentState(omx_egl_render,OMX_StateExecuting)) {
+ Log::getInstance()->log("Image", Log::DEBUG, "omx_egl_rendd ChangeComponentState Execute");
+ video->UnlockClock();
+ return false;
+ }
+
+
Log::getInstance()->log("Image", Log::DEBUG,
"decodePicture 9");
//video->EnablePort(omx_egl_render,omx_egl_output_port,false);
if (error!=OMX_ErrorNone){
Log::getInstance()->log("Image", Log::DEBUG, "OMX_FillThisBuffer failed %x", error);
video->UnlockClock();
- pthread_setcancelstate(oldcancelstate, NULL);
- pthread_setcanceltype(oldcanceltype, NULL);
return false;
}
count =1;
count++;
if (count>100) {
- pthread_setcancelstate(oldcancelstate, NULL);
- pthread_setcanceltype(oldcanceltype, NULL);
Log::getInstance()->log("Image", Log::DEBUG, "No one filled my buffer");
return false;
}
error=OMX_FreeBuffer(omx_egl_render/*dec*/, omx_egl_output_port/*codec*/,buf_head_egl);
if (error!=OMX_ErrorNone){
Log::getInstance()->log("Image", Log::DEBUG, "Use OMX_FreeBuffer 2 failed %x", error);
- pthread_setcancelstate(oldcancelstate, NULL);
- pthread_setcanceltype(oldcanceltype, NULL);
return false;
}
video->UnlockClock();
- pthread_setcancelstate(oldcancelstate, NULL);
- pthread_setcanceltype(oldcanceltype, NULL);
Log::getInstance()->log("Image", Log::DEBUG,
"decodePicture left");
+ DeAllocateCodecsOMX();
pictInfValid=true;
return true;
}
-int ImageOMX::PrepareInputBufsOMX(bool setportdef) //needs to be called with locvke omx clock mutex
+int ImageOMX::PrepareInputBufsOMX(bool setportdef, unsigned char * buffer, unsigned int length) //needs to be called with locvke omx clock mutex
{
VideoOMX *video=(VideoOMX*)Video::getInstance();
OMX_ERRORTYPE error;
if (setportdef) {
- port_def_type.nBufferCountActual=10;
- port_def_type.nBufferSize=max(port_def_type.nBufferSize,1000000); // for transcoder important
+ port_def_type.nBufferCountActual=port_def_type.nBufferCountMin;
+ port_def_type.nBufferSize=max(port_def_type.nBufferSize,length); // for transcoder important
error=OMX_SetParameter(omx_imag_decode/*dec*/,OMX_IndexParamPortDefinition, &port_def_type);
input_bufs_omx_mutex.Lock();
for (unsigned int i=0; i< port_def_type.nBufferCountActual;i++) {
OMX_BUFFERHEADERTYPE *buf_head=NULL;
- error=OMX_UseBuffer(omx_imag_decode/*dec*/,&buf_head,omx_image_input_port/*codec*/,this,port_def_type.nBufferSize, NULL);
+ error=OMX_UseBuffer(omx_imag_decode/*dec*/,&buf_head,omx_image_input_port/*codec*/,this,port_def_type.nBufferSize, buffer);
if (error!=OMX_ErrorNone){
Log::getInstance()->log("Image", Log::DEBUG, "Use OMX_UseBuffer failed %x", error);
input_bufs_omx_mutex.Unlock();
input_bufs_omx_mutex.Lock();
for (int i=0; i< input_bufs_omx_all.size();i++) {
Log::getInstance()->log("Image", Log::DEBUG, "OMX_FreeBuffer mark");
- if (input_bufs_omx_all[i]->pBuffer) free(input_bufs_omx_all[i]->pBuffer);
+ //if (input_bufs_omx_all[i]->pBuffer) free(input_bufs_omx_all[i]->pBuffer);
+ input_bufs_omx_all[i]->pBuffer=NULL;
error=OMX_FreeBuffer(omx_imag_decode/*dec*/,omx_image_input_port/*codec*/,input_bufs_omx_all[i]);
if (error!=OMX_ErrorNone){
Log::getInstance()->log("Image", Log::DEBUG, "Use OMX_FreeBuffer failed %x", error);