This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Unable to read frame from video encoder (enc_read_frame)

Hi,

I'm using J6 EVM (REV H), which is running in QNX.

I'm trying to encode a YUV file to H.264 file.

Encoder library Initialization, Encode Instance Creation is success.

After starting the encoder, when i tried to read the frame using "enc_read_frame", i'm not able to read any frame.

I have attached my source code for your reference.

enc_test.c
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <fcntl.h>
#include <errno.h>
#include <time.h>
#include <sys/mman.h>
#include <semaphore.h>
#include <pthread.h>
#include <sched.h>

#include "libdce.h"
#include "dce_enc.h"

//#define PRINT_DEBUG
//#define PRINT_INFO

#define ERROR(FMT, ...)  printf("%s:%d:\t%s\terror: " FMT "\n", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__)
// enable below to print debug information
#ifdef PRINT_DEBUG
#define DEBUG(FMT, ...)  printf("%s:%d:\t%s\tdebug: " FMT "\n", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__)
#else
#define DEBUG(FMT, ...)
#endif
#ifdef PRINT_INFO
#define INFO(FMT, ...)  printf("%s:%d:\t%s\tinfo: " FMT "\n", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__)
#else
#define INFO(FMT, ...)
#endif

#define NUM_CHANNELS 2
#define ENC_STACK_SIZE 32768


void main()
{
	handle_t	EncHdl;			/**< Used to store the handle of an encoder instance */
	enc_props_t	NavCfg;
	char *payload;
	unsigned int len;
	payload = (char*)malloc(720*1280);
	if(payload == NULL)
	{
		printf("Unable to allocate memory\n");
	}
	int l_i32Return= 0;
	if(-1 == enc_init())
	{
		printf("Failed to initialize the encoder library" );
	}
	else
	{
		printf("Encoder library Initialization - Success\n" );

		{/*Navigation Configuration*/
			NavCfg.height				= 720;
			NavCfg.width 				= 1280;
			NavCfg.output_height		= 720;
			NavCfg.output_width		= 1280;
			NavCfg.level				= 50;
			NavCfg.framerate			= 30;
			NavCfg.enc_th_priority	= 35;
			NavCfg.scr_cap_th_priority = 35;
			strcpy(NavCfg.profile,"high");
			NavCfg.input_source = ENC_SOURCE_FILE;
			NavCfg.in_file ="/tmp/sfish_p1280x720_30fps_420pl_60fr_nv12_720p.yuv";
			NavCfg.output_sink = ENC_SINK_FILE;
			NavCfg.out_file = "/tmp/OutEnc3.h264";
		}

		if(-1 == enc_create(&EncHdl, &NavCfg))
		{
			printf("Unable to create an encoder instance\n");
		}
		else
		{
			printf("create an encoder instance - Success\n");


			if(-1 == enc_start(EncHdl))
			{
				printf("Unable to start the encoder instance\n");
			}
			else
			{
				printf("successfully started the encoder instance\n");
				while(1)
				{

					l_i32Return = enc_read_frame(EncHdl, payload, &len, 125);
					if(l_i32Return == 0 && len>0)
					{
							printf( "Read from the encoder -Success\n");
					}
					else
					{
						printf( "Unable to read from the encoder %d - %d\n",len, l_i32Return);
						break;
					}
				}
			}

		}
	}
}

Kindly let me know, whether the input parameters what i'm setting is fine or not.

While debugging the source code of video encoder, it is getting failed while reading from "get_list_head" in enc_read_frame function (File : bsp-TI-DRA74x-OMAP5-SDP6.6\bsp-TI-DRA74x-OMAP5-SDP6.6\src\utils\videolib\videnc\dce_enc.c)

Kindly do the needful to resolve the issue.

  • Hi Karikalan,

    I have forwarded your question to QNX video expert.

    Regards,
    Yordan
  • Hi Karikalan,

    I pulled the latest QNX BSP "BSP_ti-j6-dra74x_vayu-evm_br-660_be-660_SVN817036_JBN156.zip" from QNX website and I don't see bsp\src\utils\videolib\videnc\dce_enc.c
    Is it an add-on package? I don't have access to bsp-TI-DRA74x-OMAP5-SDP6.6\bsp-TI-DRA74x-OMAP5-SDP6.6\src\utils\videolib\videnc\dce_enc.c. So, I cannot really see enc_read_frame().
    Why can you try with our test code "dce_enc_test.c" as reference to see on why your enc_read_frame() doesn't work?

    You can see our QNX test code from: git.omapzoom.org/
    I think the similar reference for enc_read_frame() should be the read_input()

    From the enc_test.c, you are trying to encode 720p resolution. Once you have the dce_enc_test binary you can run:
    dce_enc_test 1280 720 0 <yuv_input_file_in_NV12_format.yuv> <output_file_location.h264> h264 high 51 nontiler full

    Thanks.
    //Buddy
  • H Buddy,

    When I run the dce_enc_test.c(enc_test.c in my project), I'm getting the below output.

    Actually I'm getting error in alloc shmem buffer.

    I'm already running "shmemallocator" in stratup.sh. Any more library I have to add?

     ./enc_test 1280 720 0 sfish_p1280x720_30fps_420pl_60fr_nv12_720p.yuv output.h264 h264 high 51 nontiler full
    Selected codec: h264
    Selected buffer: nontiler
    Encode mode: full
    Acceptable H.264 level value = 51
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:851:    main    debug: width=1280, height=720
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:868:    main    debug: After alignment width=1280, height=720, num_buffers=2
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:880:    main    debug: Engine_open successful engine=8010a510
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:941:    main    debug: dce_alloc VIDENC2_Params successful params=80aa020 inputDataMode(2=IVIDEO_NUMROWS) 3
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:945:    main    debug: H.264 Encoding with profile_value 100 level 51
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:1108:   main    debug: dce_alloc VIDENC2_Params successful h264enc_params=80aa020
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:1188:   main    debug: VIDENC2_create successful codec=8010a550
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:1197:   main    debug: dce_alloc dynParams successful dynParams=80ab020 size=240
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:1247:   main    debug: dce_alloc IH264ENC_DynamicParams successful size 240 dynParams=80ab020
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:1335:   main    debug: dce_alloc IH264ENC_Status successful status=80ad020
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:1342:   main    debug: IH264ENC_Status successful h264enc_status=80ad020
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:1344:   main    debug: VIDENC2_control IH264ENC_Status XDM_GETVERSION h264enc_status->data.buf = H264ENC_TI DEV.500.V.H264AVC.E.IVAHD.02.00.08.01
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:1348:   main    debug: dce_alloc IH264ENC_Status successful h264enc_status=80ad020
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:1396:   main    debug: VIDENC2_control XDM_SETPARAMS successful
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:1407:   main    debug: VIDENC2_control - XDM_GETBUFINFO err 0 status numInBuf 2 minInBufSize[0] 1280 minInBufSize[1] 1280
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:1413:   main    debug: input buffer configuration width 1280 height 720
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:1416:   main    debug: Input inBufs 0x80ac020 allocate through dce_alloc
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:1446:   main    debug: Input allocate through NON-TILER
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:338:    input_allocate_nonTiler debug:  ----------------- create NON INPUT TILER buf 0x809b050 --------------------
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:216:    allocate_nonTiler       debug:  ----------------- create nonTILER size 1382400 --------------------
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:230:    allocate_nonTiler       debug: nonTILER shmBuf->vir_addr =28000000, shmBuf->phy_addr =ba300000
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:243:    allocate_nonTiler       debug: shmBuf 809b068
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:352:    input_allocate_nonTiler debug: INPUT NON TILER buf=809b050, buf->buf=28000000 y=28000000, uv=280e1000
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:338:    input_allocate_nonTiler debug:  ----------------- create NON INPUT TILER buf 0x809b088 --------------------
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:216:    allocate_nonTiler       debug:  ----------------- create nonTILER size 1382400 --------------------
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:225:    allocate_nonTiler       error: Failed to alloc shmem buffer

    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:342:    input_allocate_nonTiler error: DCE_ENCODE_TEST_FAIL: NON-TILER ALLOCATION FAILED
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:1460:   main    debug: input buffer configuration num_buffers 2 width 1280 height 720
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:1480:   main    debug: Output allocate through NON-TILER
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:216:    allocate_nonTiler       debug:  ----------------- create nonTILER size 1382400 --------------------
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:225:    allocate_nonTiler       error: Failed to alloc shmem buffer

    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:1483:   main    error: DCE_ENCODE_TEST_FAIL: NON_TILER ALLOCATION FAILED -12

    Deleting encoder codec 0x8010a550...

    Freeing output 0... output_mvbuf 0...

    Freeing input...
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:258:    input_free      debug: input_free: 809b050
    DCE ENC test completed...

    Regards,

    Karikalan

  • Hi Karikalan,

    It is odd that you are getting -12 (ENOMEM) when trying to allocate another the 2nd input buffer.
    From the trace several buffers were allocated through shmemallocator:
    * VIDENC2_Params - allocated using dce_alloc which by default using MEM_SHARED (shmemallocator)
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:941: main debug: dce_alloc VIDENC2_Params successful params=80aa020 inputDataMode(2=IVIDEO_NUMROWS) 3

    * IH264ENC_DynamicParams - through dce_alloc
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:1247: main debug: dce_alloc IH264ENC_DynamicParams successful size 240 dynParams=80ab020

    * IH264ENC_Status - through dce_alloc
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:1348: main debug: dce_alloc IH264ENC_Status successful h264enc_status=80ad020

    * 1st input buffer:
    D:/QNX_WorkSpace/Navigation/enc_test/enc_test.c:243: allocate_nonTiler debug: shmBuf 809b068

    Can you run: use -i shmemallocator
    J6EVM@QNX # use -i shmemallocator
    QNX_BUILDID=(GNU)f5445ea52b890ba5f05dd8858db52a8b
    NAME=shmemallocator
    DESCRIPTION=Shared Memory Allocator driver
    DATE=2017/03/22-10:16:44-CDT
    STATE=Experimental
    HOST=magpie
    USER=a0389345

    To see what version of shmemallocator it is. Are you building the shmemallocator?
    Do you have access to TI QNX DCE 4.x Release (TI NDA only)?

    As far as other binaries or libraries, the component of interest should be:
    shmemallocator
    ipc
    libdce
    m4 firmware (ipumm)

    Can you also change the QNX BSP startup build: QNX_BSP\src\hardware\startup\boards\dra74x\vayu-evm\build
    from:
    startup-dra74x-vayu-evm -v -n852,668 -W -G
    to:
    startup-dra74x-vayu-evm -v -n852,668 -W -G -r0xBA300000,0x5A00000,1 -r0x60000000,0x20000000,1

    This is to carveout the memory of 90MB for shmemallocator (0xBA300000 - 0xBFD00000)

    Thanks.
    //Buddy
  • Hi Buddy,

    I missed to include the library "libsharedmemallocator.a" in my Project, after adding the same.

    Its working fine. Thanks a lot for your support.