⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 display_test.c

📁 s3c6400 video code,you play video smooth with it,it is hardware codec
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/ioctl.h>#include <fcntl.h>#include <ctype.h>#include <unistd.h>#include <sys/mman.h>#include <string.h>#include <errno.h>#include <sys/time.h>#include <signal.h>#include <linux/vt.h>#include <linux/fb.h>#include "SsbSipH264Decode.h"#include "SsbSipMpeg4Decode.h"#include "SsbSipVC1Decode.h"#include "FrameExtractor.h"#include "MPEG4Frames.h"#include "H263Frames.h"#include "H264Frames.h"#include "SsbSipLogMsg.h"#include "performance.h"#include "post.h"#include "lcd.h"#include "MfcDriver.h"#include "FileRead.h"static unsigned char delimiter_mpeg4[3] = {0x00, 0x00, 0x01};//static unsigned char delimiter_h263[3]  = {0x00, 0x00, 0x80};static unsigned char delimiter_h264[4]  = {0x00, 0x00, 0x00, 0x01};#define INPUT_BUFFER_SIZE		(204800)static void		*handle;static int		in_fd;static int		file_size;static char		*in_addr;static int		fb_size;static int		pp_fd, fb_fd;static char		*fb_addr;	static void sig_del_h264(void);static void sig_del_mpeg4(void);static void sig_del_vc1(void);int Test_Display_H264(int argc, char **argv){		void			*pStrmBuf;	int				nFrameLeng = 0;	unsigned int	pYUVBuf[2];		struct stat				s;	FRAMEX_CTX				*pFrameExCtx;	// frame extractor context	FRAMEX_STRM_PTR 		file_strm;	SSBSIP_H264_STREAM_INFO stream_info;			pp_params	pp_param;	s3c_win_info_t	osd_info_to_driver;	struct fb_fix_screeninfo	lcd_info;			#ifdef FPS	struct timeval	start, stop;	unsigned int	time = 0;	int				frame_cnt = 0;#endif	if(signal(SIGINT, sig_del_h264) == SIG_ERR) {		printf("Sinal Error\n");	}	if (argc != 2) {		printf("Usage : mfc <H.264 input filename>\n");		return -1;	}	// in file open	in_fd	= open(argv[1], O_RDONLY);	if(in_fd < 0) {		printf("Input file open failed\n");		return -1;	}	// get input file size	fstat(in_fd, &s);	file_size = s.st_size;		// mapping input file to memory	in_addr = (char *)mmap(0, file_size, PROT_READ, MAP_SHARED, in_fd, 0);	if(in_addr == NULL) {		printf("input file memory mapping failed\n");		return -1;	}		// Post processor open	pp_fd = open(PP_DEV_NAME, O_RDWR|O_NDELAY);	if(pp_fd < 0)	{		printf("Post processor open error\n");		return -1;	}	// LCD frame buffer open	fb_fd = open(FB_DEV_NAME, O_RDWR|O_NDELAY);	if(fb_fd < 0)	{		printf("LCD frame buffer open error\n");		return -1;	}	///////////////////////////////////	// FrameExtractor Initialization //	///////////////////////////////////	pFrameExCtx = FrameExtractorInit(FRAMEX_IN_TYPE_MEM, delimiter_h264, sizeof(delimiter_h264), 1);   	file_strm.p_start = file_strm.p_cur = (unsigned char *)in_addr;	file_strm.p_end = (unsigned char *)(in_addr + file_size);	FrameExtractorFirst(pFrameExCtx, &file_strm);		//////////////////////////////////////	///    1. Create new instance      ///	///      (SsbSipH264DecodeInit)    ///	//////////////////////////////////////	handle = SsbSipH264DecodeInit();	if (handle == NULL) {		printf("H264_Dec_Init Failed.\n");		return -1;	}	/////////////////////////////////////////////	///    2. Obtaining the Input Buffer      ///	///      (SsbSipH264DecodeGetInBuf)       ///	/////////////////////////////////////////////	pStrmBuf = SsbSipH264DecodeGetInBuf(handle, nFrameLeng);	if (pStrmBuf == NULL) {		printf("SsbSipH264DecodeGetInBuf Failed.\n");		SsbSipH264DecodeDeInit(handle);		return -1;	}	////////////////////////////////////	//  H264 CONFIG stream extraction //	////////////////////////////////////	nFrameLeng = ExtractConfigStreamH264(pFrameExCtx, &file_strm, pStrmBuf, INPUT_BUFFER_SIZE, NULL);	////////////////////////////////////////////////////////////////	///    3. Configuring the instance with the config stream    ///	///       (SsbSipH264DecodeExe)                             ///	////////////////////////////////////////////////////////////////	if (SsbSipH264DecodeExe(handle, nFrameLeng) != SSBSIP_H264_DEC_RET_OK) {		printf("H.264 Decoder Configuration Failed.\n");		return -1;	}	/////////////////////////////////////	///   4. Get stream information   ///	/////////////////////////////////////	SsbSipH264DecodeGetConfig(handle, H264_DEC_GETCONF_STREAMINFO, &stream_info);	printf("\t<STREAMINFO> width=%d   height=%d.\n", stream_info.width, stream_info.height);	// set post processor configuration	pp_param.SrcFullWidth	= stream_info.width;	pp_param.SrcFullHeight	= stream_info.height;	pp_param.SrcCSpace		= YC420;	pp_param.DstFullWidth	= 800;		// destination width	pp_param.DstFullHeight	= 480;		// destination height	pp_param.DstCSpace		= RGB16;#ifdef RGB24BPP	pp_param.DstCSpace		= RGB24;#endif	pp_param.OutPath		= POST_DMA;	pp_param.Mode			= ONE_SHOT;		// get LCD frame buffer address	fb_size = pp_param.DstFullWidth * pp_param.DstFullHeight * 2;	// RGB565#ifdef RGB24BPP	fb_size = pp_param.DstFullWidth * pp_param.DstFullHeight * 4;	// RGB888#endif	fb_addr = (char *)mmap(0, fb_size, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, 0);	if (fb_addr == NULL) {		printf("LCD frame buffer mmap failed\n");		return -1;	}	osd_info_to_driver.Bpp			= 16;	// RGB16#ifdef RGB24BPP	osd_info_to_driver.Bpp			= 24;	// RGB16#endif	osd_info_to_driver.LeftTop_x	= 0;		osd_info_to_driver.LeftTop_y	= 0;	osd_info_to_driver.Width		= 800;	// display width	osd_info_to_driver.Height		= 480;	// display height	// set OSD's information 	if(ioctl(fb_fd, SET_OSD_INFO, &osd_info_to_driver)) {		printf("Some problem with the ioctl SET_OSD_INFO\n");		return -1;	}	ioctl(fb_fd, SET_OSD_START);	while(1)	{	#ifdef FPS		gettimeofday(&start, NULL);	#endif			//////////////////////////////////		///       5. DECODE            ///		///    (SsbSipH264DecodeExe)   ///		//////////////////////////////////		if (SsbSipH264DecodeExe(handle, nFrameLeng) != SSBSIP_H264_DEC_RET_OK)			break;				//////////////////////////////////////////////		///    6. Obtaining the Output Buffer      ///		///      (SsbSipH264DecodeGetOutBuf)       ///		//////////////////////////////////////////////		SsbSipH264DecodeGetConfig(handle, H264_DEC_GETCONF_PHYADDR_FRAM_BUF, pYUVBuf);			/////////////////////////////		// Next H.264 VIDEO stream //		/////////////////////////////		nFrameLeng = NextFrameH264(pFrameExCtx, &file_strm, pStrmBuf, INPUT_BUFFER_SIZE, NULL);		if (nFrameLeng < 4)			break;							// Post processing		// pp_param.SrcFrmSt俊绰 MFC狼 output buffer狼 physical address啊		// pp_param.DstFrmSt俊绰 LCD frame buffer狼 physical address啊 涝仿栏肺 持绢具 茄促.		pp_param.SrcFrmSt		= pYUVBuf[0];	// MFC output buffer		ioctl(fb_fd, FBIOGET_FSCREENINFO, &lcd_info);		pp_param.DstFrmSt		= lcd_info.smem_start;			// LCD frame buffer		ioctl(pp_fd, PPROC_SET_PARAMS, &pp_param);		ioctl(pp_fd, PPROC_START);		#ifdef FPS		gettimeofday(&stop, NULL);		time += measureTime(&start, &stop);		frame_cnt++;	#endif			}#ifdef FPS	printf("Display Time : %u, Frame Count : %d, FPS : %f\n", time, frame_cnt, (float)frame_cnt*1000/time);#endif	SsbSipH264DecodeDeInit(handle);	munmap(in_addr, file_size);	munmap(fb_addr, fb_size);	close(pp_fd);	close(fb_fd);	close(in_fd);		return 0;}int Test_Display_MPEG4(int argc, char **argv){		void			*pStrmBuf;	int				nFrameLeng = 0;	unsigned int	pYUVBuf[2];	struct stat				s;	FRAMEX_CTX				*pFrameExCtx;	// frame extractor context	FRAMEX_STRM_PTR 		file_strm;	SSBSIP_H264_STREAM_INFO stream_info;			pp_params	pp_param;	s3c_win_info_t	osd_info_to_driver;	struct fb_fix_screeninfo	lcd_info;			#ifdef FPS	struct timeval	start, stop;	unsigned int	time = 0;	int				frame_cnt = 0;#endif	if(signal(SIGINT, sig_del_mpeg4) == SIG_ERR) {		printf("Sinal Error\n");	}	if (argc != 2) {		printf("Usage : mfc <MPEG-4 input filename>\n");		return -1;	}	// in file open	in_fd	= open(argv[1], O_RDONLY);	if(in_fd < 0) {		printf("Input file open failed\n");		return -1;	}	// get input file size	fstat(in_fd, &s);	file_size = s.st_size;		// mapping input file to memory	in_addr = (char *)mmap(0, file_size, PROT_READ, MAP_SHARED, in_fd, 0);	if(in_addr == NULL) {		printf("input file memory mapping failed\n");		return -1;	}		// Post processor open	pp_fd = open(PP_DEV_NAME, O_RDWR|O_NDELAY);	if(pp_fd < 0)	{		printf("Post processor open error\n");		return -1;	}	// LCD frame buffer open	fb_fd = open(FB_DEV_NAME, O_RDWR|O_NDELAY);	if(fb_fd < 0)	{		printf("LCD frame buffer open error\n");		return -1;	}	///////////////////////////////////	// FrameExtractor Initialization //	///////////////////////////////////	pFrameExCtx = FrameExtractorInit(FRAMEX_IN_TYPE_MEM, delimiter_mpeg4, sizeof(delimiter_mpeg4), 1);   	file_strm.p_start = file_strm.p_cur = (unsigned char *)in_addr;	file_strm.p_end = (unsigned char *)(in_addr + file_size);	FrameExtractorFirst(pFrameExCtx, &file_strm);		//////////////////////////////////////	///    1. Create new instance      ///	///      (SsbSipMPEG4DecodeInit)    ///	//////////////////////////////////////	handle = SsbSipMPEG4DecodeInit();	if (handle == NULL) {		printf("MPEG4_Dec_Init Failed.\n");		return -1;	}	/////////////////////////////////////////////	///    2. Obtaining the Input Buffer      ///	///      (SsbSipMPEG4DecodeGetInBuf)       ///	/////////////////////////////////////////////	pStrmBuf = SsbSipMPEG4DecodeGetInBuf(handle, nFrameLeng);	if (pStrmBuf == NULL) {		printf("SsbSipMPEG4DecodeGetInBuf Failed.\n");		SsbSipMPEG4DecodeDeInit(handle);		return -1;	}	////////////////////////////////////	//  MPEG4 CONFIG stream extraction //	////////////////////////////////////	nFrameLeng = ExtractConfigStreamMpeg4(pFrameExCtx, &file_strm, pStrmBuf, INPUT_BUFFER_SIZE, NULL);	////////////////////////////////////////////////////////////////	///    3. Configuring the instance with the config stream    ///	///       (SsbSipMPEG4DecodeExe)                             ///	////////////////////////////////////////////////////////////////	if (SsbSipMPEG4DecodeExe(handle, nFrameLeng) != SSBSIP_MPEG4_DEC_RET_OK) {		printf("MPEG-4 Decoder Configuration Failed.\n");		return -1;	}	/////////////////////////////////////	///   4. Get stream information   ///	/////////////////////////////////////	SsbSipMPEG4DecodeGetConfig(handle, MPEG4_DEC_GETCONF_STREAMINFO, &stream_info);	printf("\t<STREAMINFO> width=%d   height=%d.\n", stream_info.width, stream_info.height);	// set post processor configuration	pp_param.SrcFullWidth	= stream_info.width;	pp_param.SrcFullHeight	= stream_info.height;	pp_param.SrcCSpace		= YC420;	pp_param.DstFullWidth	= 800;		// destination width	pp_param.DstFullHeight	= 480;		// destination height	pp_param.DstCSpace		= RGB16;#ifdef RGB24BPP	pp_param.DstCSpace		= RGB24;#endif	pp_param.OutPath		= POST_DMA;	pp_param.Mode			= ONE_SHOT;		// get LCD frame buffer address	fb_size = pp_param.DstFullWidth * pp_param.DstFullHeight * 2;	// RGB565#ifdef RGB24BPP	fb_size = pp_param.DstFullWidth * pp_param.DstFullHeight * 4;	// RGB888#endif	fb_addr = (char *)mmap(0, fb_size, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, 0);	if (fb_addr == NULL) {		printf("LCD frame buffer mmap failed\n");		return -1;	}	osd_info_to_driver.Bpp			= 16;	// RGB16#ifdef RGB24BPP	osd_info_to_driver.Bpp			= 24;	// RGB24#endif	osd_info_to_driver.LeftTop_x	= 0;		osd_info_to_driver.LeftTop_y	= 0;	osd_info_to_driver.Width		= 800;	// display width	osd_info_to_driver.Height		= 480;	// display height	// set OSD's information 	if(ioctl(fb_fd, SET_OSD_INFO, &osd_info_to_driver)) {		printf("Some problem with the ioctl SET_OSD_INFO\n");		return -1;	}	ioctl(fb_fd, SET_OSD_START);	while(1)	{	#ifdef FPS		gettimeofday(&start, NULL);	#endif			//////////////////////////////////		///       5. DECODE            ///		///    (SsbSipMPEG4DecodeExe)   ///		//////////////////////////////////		if (SsbSipMPEG4DecodeExe(handle, nFrameLeng) != SSBSIP_MPEG4_DEC_RET_OK)			break;			//////////////////////////////////////////////		///    6. Obtaining the Output Buffer      ///		///      (SsbSipMPEG4DecodeGetOutBuf)       ///		//////////////////////////////////////////////		SsbSipMPEG4DecodeGetConfig(handle, MPEG4_DEC_GETCONF_PHYADDR_FRAM_BUF, pYUVBuf);			/////////////////////////////		// Next MPEG4 VIDEO stream //		/////////////////////////////		nFrameLeng = NextFrameMpeg4(pFrameExCtx, &file_strm, pStrmBuf, INPUT_BUFFER_SIZE, NULL);		if (nFrameLeng < 4)			break;							// Post processing		// pp_param.SrcFrmSt俊绰 MFC狼 output buffer狼 physical address啊		// pp_param.DstFrmSt俊绰 LCD frame buffer狼 physical address啊 涝仿栏肺 持绢具 茄促.		pp_param.SrcFrmSt		= pYUVBuf[0];	// MFC output buffer		ioctl(fb_fd, FBIOGET_FSCREENINFO, &lcd_info);		pp_param.DstFrmSt		= lcd_info.smem_start;			// LCD frame buffer		ioctl(pp_fd, PPROC_SET_PARAMS, &pp_param);		ioctl(pp_fd, PPROC_START);		#ifdef FPS		gettimeofday(&stop, NULL);		time += measureTime(&start, &stop);		frame_cnt++;	#endif		}#ifdef FPS	printf("Display Time : %u, Frame Count : %d, FPS : %f\n", time, frame_cnt, (float)frame_cnt*1000/time);#endif	SsbSipMPEG4DecodeDeInit(handle);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -