lorddoskias
Posts: 15
Joined: Tue Jun 18, 2013 10:01 pm

image_fx -> video_encode - encoder doesn't start executing

Wed Jun 26, 2013 11:34 am

In the main loop of my openmax thread i have the following piece of code:

Code: Select all

if(ctx->pipeline.image_fx.port_settings_changed == 1) {
                ctx->pipeline.image_fx.port_settings_changed = 0;
                 
                //configure encoder output format
                OMX_INIT_STRUCTURE(encoder_format_config);
                encoder_format_config.nPortIndex = 201; //encoder output port
                encoder_format_config.eCompressionFormat = OMX_VIDEO_CodingAVC;
                OERR(OMX_SetParameter(ctx->pipeline.video_encode.h, OMX_IndexParamVideoPortFormat, &encoder_format_config));
                
                //configure encoder output bitrate
                OMX_INIT_STRUCTURE(encoder_bitrate_config);
                encoder_bitrate_config.nPortIndex = 201;
                encoder_bitrate_config.eControlRate = OMX_Video_ControlRateVariable; //var bitrate
                encoder_bitrate_config.nTargetBitrate = ENCODED_BITRATE; //1 mbit 
                OERR(OMX_SetParameter(ctx->pipeline.video_encode.h, OMX_IndexParamVideoBitrate, &encoder_bitrate_config));
                
                //setup tunnel from decoder to encoder
                OERR(OMX_SetupTunnel(ctx->pipeline.image_fx.h, 191, ctx->pipeline.video_encode.h, 200));
                
                //set encoder to idle after we have finished configuring it
                omx_send_command_and_wait0(&ctx->pipeline.video_encode, OMX_CommandStateSet, OMX_StateIdle, NULL);
                
                //allocate buffers for output of the encoder
                //send the enable command, which won't complete until the bufs are alloc'ed
                omx_send_command_and_wait0(&ctx->pipeline.video_encode, OMX_CommandPortEnable, 201, NULL);
                omx_alloc_buffers(&ctx->pipeline.video_encode, 201); //allocate output buffers
                //block until the port is fully enabled
                omx_send_command_and_wait1(&ctx->pipeline.video_encode, OMX_CommandPortEnable, 201, NULL);

                omx_send_command_and_wait1(&ctx->pipeline.video_encode, OMX_CommandStateSet, OMX_StateIdle, NULL);
                OMX_SendCommand(ctx->pipeline.image_fx.h, OMX_CommandPortEnable, 191, NULL);
                OMX_SendCommand(ctx->pipeline.video_encode.h, OMX_CommandPortEnable, 200, NULL);
                OMX_SendCommand(ctx->pipeline.video_encode.h, OMX_CommandStateSet, OMX_StateExecuting, NULL);
                
                fprintf(stderr, "finished configuring encoder\n");
            }
The problem is that I never get OMX_EventCmdComplete for the last command - putting the encoder into state executing. Everything else completes successfully. Here is a debug log from my console:

Code: Select all

[EVENT] OMX.broadcom.video_encode 0xc83760 has completed the last command (0).
[EVENT] OMX.broadcom.video_encode 0xc83760 has completed the last command (3).
[DEBUG] Allocating buffers for OMX.broadcom.video_encode done
[EVENT] OMX.broadcom.video_encode 0xc83760 has completed the last command (3).
[EVENT] OMX.broadcom.image_fx 0xc83620 has completed the last command (3).
line 1 coresponds to the encoder going into state idle. The next line means port 201 is enabled and the last two means that the image_fx output port is enabled and video_encode input port is enabled. However I do not get a callback that the encode has transitioned into executing state thus my whole program blocks. I observe this when running my code under the debugger on netbeans ( it uses the raspberrypi toolchain so it is running on the RPI). However when I run the code directly from the console sometimes it completes, sometimes it doesn't. Which points me to a possible race condition, which I have no idea where it might come from. Furthermore if I hook up the decoder directly to the encoder (without image_fx) I never get this issue.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23947
Joined: Sat Jul 30, 2011 7:41 pm

Re: image_fx -> video_encode - encoder doesn't start executi

Wed Jun 26, 2013 2:28 pm

I posed the questions to one of our openMAX experts. Can you try the following:

We think you need to wait for the result from the OMX_CommandPortEnable before sending the OMX_CommandStateSet. Also you are not checking the return code from the OMX_SendCommand call, and that may be indicating a failure, so please add that.

It may also be running out of memory - can you try it with a smaller frame size to see if it makes any difference?
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I think it’s wrong that only one company makes the game Monopoly.” – Steven Wright

lorddoskias
Posts: 15
Joined: Tue Jun 18, 2013 10:01 pm

Re: image_fx -> video_encode - encoder doesn't start executi

Wed Jun 26, 2013 4:30 pm

Hello and thanks for replying. I did not realize that OMX_SendCommand returns error information. After checking for this I can confirm that the encoder returns the following: Error state executing encoder : 80001000 - where the error code signifies OMX_ErrorInsufficientResources. Having this in mind could you please tell me what do you meant by trying with a smaller frame size? I'm guessing the alternative would be to allocate more memory for the video core. Currently I have (which is the default):

Code: Select all

sudo vcdbg reloc

Relocatable heap version 4 found at 0x1c000000
total space allocated is 44M, with 40M relocatable, 0 legacy and 4.5M offline
0 legacy blocks of size 2359296

free list at 0x1c379c60
41M free memory in 1 free block(s)
largest free block is 41M bytes

[   1] 0x1c000000: used 4.0K (refcount 1 lock count 0, size        0, align 4096, data 0x1c001000, d1rual) 'camera fast alloc arena'
[   2] 0x1c001000: used  16K (refcount 1 lock count 0, size    16384, align   32, data 0x1c001020, d0ruAl) 'audioplus_tmp_buf'
[   3] 0x1c005020: used 3.5M (refcount 1 lock count 8, size  3618816, align 4096, data 0x1c006000, d3rual) 'ARM FB'
[   4] 0x1c379820: used  544 (refcount 1 lock count 0, size      512, align    4, data 0x1c379840, d0rual) 'ILCS VC buffer pool'
0x1c379a40: free 41M
small allocs not requested

PS: What is the state of the CMA option (dynamic memory split) since it might be prudent to use it in this case?

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23947
Joined: Sat Jul 30, 2011 7:41 pm

Re: image_fx -> video_encode - encoder doesn't start executi

Wed Jun 26, 2013 4:45 pm

By smaller frame size I mean resolution of the imagery you are pushing through. So if you are using 1080p, try 720p, or even smaller.

I'll need to check with the team to see what can be done about memory. May require a bigger pool allocation in the code. Not sure how to do that without a firmware change. As far as I know CMA is too unsafe to use at the moment.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I think it’s wrong that only one company makes the game Monopoly.” – Steven Wright

lorddoskias
Posts: 15
Joined: Tue Jun 18, 2013 10:01 pm

Re: image_fx -> video_encode - encoder doesn't start executi

Wed Jun 26, 2013 4:50 pm

Thanks. I allocate 128mb for the videocore through boot.txt gpu_mem option but I still get this error changing state of the encoder.

lorddoskias
Posts: 15
Joined: Tue Jun 18, 2013 10:01 pm

Re: image_fx -> video_encode - encoder doesn't start executi

Wed Jun 26, 2013 5:19 pm

In the end it turned out it was due to the port enablement no happening at the correct time. Now after I have wrapped both calls into a synchronous wrapper I can confirm that the encoder is enabled without a problem. Even with 64mb (the default) of video memory.

Return to “OpenMAX”