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 write the data(Input source as ENC_SOURCE_SCREEN) from Video encoder -QNX

Hi,

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

Initially, I was tried to encode a YUV file(ENC_SOURCE_FILE as input source) to H.264 file.In this case i didn't faced any issue and it's working fine with play the video content(H.264 file)

But when I'm trying with ENC_SOURCE_SCREEN as input source i.e. getting the data from screen. In this case I'm not getting the proper data(H.264 video file).

I have attached my source code for your reference.

#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 "dce_enc.h"
#include "Nav_intf.h"
//#include "libdce.h"

#if 0
#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
#endif

int FileId;

typedef struct thread_props_s {
    int 	 tid; //Encoding process thread id.
    unsigned int state;
    unsigned int priority;
} thread_props_t;

typedef struct input_struct_s {

	int width;
	int height;
	enc_source_t source;
	const char *input;
	enc_sink_t sink;
	const char *output;
	const char *profile;
	int level;
	char *buffertype;
	handle_t handle;
	int fd;
	thread_props_t	thread_props;

} input_struct_t;

#define DUMPING_LEN

//void *read_thread (void *data)
void read_thread (void *data)
{
	printf("read_thread called\n");
	char *payload;
	unsigned int len;
	//input_struct_t *tmp;
	Nav_Tx_st *tmp;
	int ret;

	payload = malloc(300000);
	tmp = (Nav_Tx_st *)data;

	while(1) {
		usleep(20000);
		//DEBUG("Reading frames", len);
		//printf("Reading frames %d\n", len);
		ret = enc_read_frame ( tmp->EncHdl, payload, &len, 10000);
		if((ret == 0) && (len > 0)) {
			write(FileId, payload, len);

			//printf("Got frame len  = %d \n", len);
		}
		else
		{
			//break;
		}

	}
	free(payload);
}


int main(int argc, char **argv)
{
//    enc_props_t props;
    input_struct_t *tmp;
    Nav_Tx_st *lp_Nav_Tx_st;
    int ret;

    tmp = malloc(sizeof(input_struct_t));
    lp_Nav_Tx_st = malloc(sizeof(Nav_Tx_st));
    tmp->thread_props.priority = 75;


		//DEBUG("Selected buffer: %s\n", tilerbuffer);

		lp_Nav_Tx_st->NavCfg.framerate = 30;
		lp_Nav_Tx_st->NavCfg.scr_cap_th_priority = 70; //10;
		lp_Nav_Tx_st->NavCfg.enc_th_priority = 10;
		lp_Nav_Tx_st->NavCfg.width = 720;
		lp_Nav_Tx_st->NavCfg.height = 480;
		lp_Nav_Tx_st->NavCfg.output_width	= 720;
		lp_Nav_Tx_st->NavCfg.output_height	= 480;
		lp_Nav_Tx_st->NavCfg.input_source = ENC_SOURCE_SCREEN;
	//	lp_Nav_Tx_st->NavCfg.input_source = ENC_SOURCE_FILE;
	//	lp_Nav_Tx_st->NavCfg.in_file = "/tmp/HP_p720x480_30fps_420pl_152fr_nv12_480p.yuv";
		lp_Nav_Tx_st->NavCfg.output_sink = ENC_SINK_FILE;
	//	lp_Nav_Tx_st->NavCfg.output_sink = ENC_SINK_EAVB;
		lp_Nav_Tx_st->NavCfg.out_file = "/usr/EncoderOutFile.h264";
		strcpy(lp_Nav_Tx_st->NavCfg.profile,"high");
		lp_Nav_Tx_st->NavCfg.level = 51;
		lp_Nav_Tx_st->NavCfg.tiler = 1;


#if 0
	    props.framerate = 30;
	    props.scr_cap_th_priority = 10;
	    props.enc_th_priority = 10;
	    props.width = 720;
	    props.height = 480;
	    props.output_width		= 720;
	    props.output_height		= 480;
	    props.input_source = ENC_SOURCE_FILE;
	    props.in_file = "/tmp/HP_p720x480_30fps_420pl_152fr_nv12_480p.yuv";
	    //props.output_sink = ENC_SINK_FILE;
	    props.output_sink = ENC_SINK_EAVB;
	  	props.out_file = "/tmp/EncOutput.h264";
	  	strcpy(props.profile,"high");
	    props.level =51;
		props.tiler = 1;
#endif
		//tmp->fd = open("/tmp/EncOutput.h264", (O_CREAT|O_WRONLY), (S_IRUSR|S_IRGRP|S_IROTH));
		FileId =open("/tmp/EncOutput_VP4.h264", (O_CREAT|O_WRONLY), (S_IRUSR|S_IRGRP|S_IROTH));

		ret = enc_init();
		//ret = enc_create(&tmp->handle, &props);
		ret = enc_create(&lp_Nav_Tx_st->EncHdl, &lp_Nav_Tx_st->NavCfg);
	    if (ret == -1) {
	    	ERROR("Encoder creation failed\n");
	    	return 0;
	    }
	    else
	    {
	    	printf("Encoder Creation sucess\n");
	    }

	    //enc_start(tmp->handle);
	   ret = enc_start(lp_Nav_Tx_st->EncHdl);
	   if (ret == -1) {
			ERROR("Encoder enc_start failed\n");
			return 0;
		}
		else
		{
			printf("enc_start - sucess\n");
		}
	    read_thread(lp_Nav_Tx_st);

   // while(1);
    printf("Done!!!!\n");
    return 0;
}

The input parameters are working fine for ENC_SOURCE_FILE as input source.

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

Kindly do the needful to resolve the issue.