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

📄 play_jpeg.c

📁 Sample code for use on smp 863x processor.
💻 C
📖 第 1 页 / 共 2 页
字号:
	err = apply_playback_options(&dcc_info, &play_opt);	if (RMFAILED(err)) {		fprintf(stderr, "Cannot set playback options %d\n", err);		return NULL;	}		set_default_out_window(&(dcc_info.out_window));	set_default_out_window(&(dcc_info.osd_window));	dcc_info.active_window = &(dcc_info.osd_window);     	err = apply_display_options(&dcc_info, &disp_opt);	if (RMFAILED(err)) {		fprintf(stderr, "Cannot set display options %d\n", err);		return NULL;	}		fd = load_jpg_file(&cinfo, &jerr, filename, &osd_profile);	if (fd == NULL) {		fprintf(stderr, "Cannot load JPEG file\n");		return NULL;	}	err = DCCOpenOSDVideoSource(pDCC, &osd_profile, &pOSDSource);	if (RMFAILED(err)) {		fprintf(stderr, "Cannot open OSD decoder %d\n", err);		return NULL;	}#if (EM86XX_MODE == EM86XX_MODEID_WITHHOST)	bitmapLumaSize = (osd_profile.Width)*(osd_profile.Height);	bitmapChromaSize = (bitmapLumaSize/2); // only true for YUV 420 !!!	pLuma = (RMuint8 *)RMMalloc(bitmapLumaSize*sizeof(RMuint8));	if(pLuma == (RMuint8 *)NULL) {		fprintf(stderr, "Cannot RMMalloc() LUMA buffer !!\n");		return NULL;	}		pChroma = (RMuint8 *)RMMalloc(bitmapChromaSize*sizeof(RMuint8));	if(pChroma == (RMuint8 *)NULL) {		fprintf(stderr, "Cannot RMMalloc() CHROMA buffer !!\n");		return NULL;	}	decompress_jpg_file(&cinfo, fd, pLuma, pChroma);	err = DCCSetOSDVideoSource(pOSDSource, pLuma, pChroma);	if (RMFAILED(err)) {		fprintf(stderr, "Cannot load image to RUA buffer %d\n", err);		return NULL;	}#else	{		RMuint32 LumaAddr=0,ChromaAddr=0;		err = DCCGetOSDVideoSourceInfo(pOSDSource, &LumaAddr, &bitmapLumaSize, &ChromaAddr, &bitmapChromaSize);		if (RMFAILED(err)) {			fprintf(stderr, "Cannot get osd buffer info %d\n", err);			return NULL;		}				pLuma = (RMuint8 *)LumaAddr;		pChroma = (RMuint8 *)ChromaAddr;	}		decompress_jpg_file(&cinfo, fd, pLuma, pChroma);#endif	err = DCCGetScalerModuleID(pDCC, dcc_info.route, DCCSurface_OSD, 2, &surfaceID);	if (RMFAILED(err)) {		fprintf(stderr, "Cannot get surface to display video source %d\n", err);		return NULL;	}	err = DCCEnableSPUSurface(pDCC, dcc_info.route, 0, (struct DCCVideoSource *) NULL, FALSE);		dcc_info.pOSDSource = pOSDSource;	dcc_info.osd_scaler = surfaceID;	dcc_info.osd_enable = TRUE;	{		RMbool set_surface_once = FALSE;		while(surface_is_ready != -1) {			if(surface_is_ready == 1) {				if(!set_surface_once) {					DCCSetSurfaceSource(pDCC, surfaceID, pOSDSource);					set_surface_once = TRUE;				}			} else {				set_surface_once = FALSE;			}			usleep(WAIT_SURFACE_READY);		}	}       #if (EM86XX_MODE == EM86XX_MODEID_WITHHOST)	RMFree(pLuma);	RMFree(pChroma);#endif	clear_display_options(&dcc_info, &disp_opt);		err = DCCClose(pDCC);	if (RMFAILED(err)) {		fprintf(stderr, "Cannot close DCC %d\n", err);		return NULL;	}	err = RUADestroyInstance(pRUA);	if (RMFAILED(err)) {		fprintf(stderr, "Cannot destroy RUA instance %d\n", err);		return NULL;	}	return thread_arg;}int main(int argc, char *argv[]){	pthread_t pth = {0,};	int rc = -1;	void *rc_pth = NULL;		struct DCC *pDCC = NULL;	struct DCCVideoSource *pOSDSource = NULL;	struct DCCOSDProfile osd_profile = {0,};	struct RUA *pRUA = NULL;	struct jpeg_decompress_struct cinfo;	struct jpeg_error_mgr jerr;	FILE *fd = (FILE*)NULL;	RMstatus err;	RMuint32 surfaceID;	static struct dcc_context dcc_info = {0,};	RMuint32 bitmapLumaSize = 0;	RMuint32 bitmapChromaSize = 0;	RMuint8 * pLuma = (RMuint8 *)NULL;	RMuint8 * pChroma = (RMuint8 *)NULL;	init_display_options(&disp_opt);	init_video_options(&video_opt);	init_playback_options(&play_opt);	parse_cmdline(argc, argv);	err = RUACreateInstance(&pRUA, play_opt.chip_num);	if (RMFAILED(err)) {		fprintf(stderr, "Error creating RUA instance! %d\n", err);		return -1;	}		err = DCCOpen(pRUA, &pDCC);	if (RMFAILED(err)) {		fprintf(stderr, "Error Opening DCC! %d\n", err);		return -1;	}	err = DCCInitChainEx(pDCC, disp_opt.init_mode);	if (RMFAILED(err)) {		fprintf(stderr, "Cannot initialize microcode %d\n", err);		return -1;	}		dcc_info.pRUA = pRUA;	dcc_info.pDCC = pDCC;	dcc_info.pDH = NULL;	dcc_info.route = DCCRoute_Main;	err = apply_playback_options(&dcc_info, &play_opt);	if (RMFAILED(err)) {		fprintf(stderr, "Cannot set playback options %d\n", err);		return -1;	}	set_default_out_window(&(dcc_info.out_window));	set_default_out_window(&(dcc_info.osd_window));	dcc_info.active_window = &(dcc_info.osd_window);     	err = apply_display_options(&dcc_info, &disp_opt);	if (RMFAILED(err)) {		fprintf(stderr, "Cannot set display options %d\n", err);		return -1;	}		if (grey_w && grey_h) {		osd_profile.ColorSpace = EMhwlibColorSpace_YUV_601;		osd_profile.SamplingMode = EMhwlibSamplingMode_420;		osd_profile.ColorMode = EMhwlibColorMode_VideoNonInterleaved;		osd_profile.ColorFormat = EMhwlibColorFormat_32BPP;		osd_profile.PixelAspectRatio.X = 1;		osd_profile.PixelAspectRatio.Y = 1;		osd_profile.Width = grey_w;		osd_profile.Height = grey_h;	} else {		fd = load_jpg_file(&cinfo, &jerr, filename, &osd_profile);		if (fd == NULL) {			fprintf(stderr, "Cannot load JPEG file\n");			return -1;		}	}	err = DCCOpenOSDVideoSource(pDCC, &osd_profile, &pOSDSource);	if (RMFAILED(err)) {		fprintf(stderr, "Cannot open OSD decoder %d\n", err);		return -1;	}	// use main video scaler for large JPEG pictures (more than 2047 pixels per line)	err = DCCGetScalerModuleID(pDCC, dcc_info.route, DCCSurface_OSD, 2, &surfaceID);	if (RMFAILED(err)) {		fprintf(stderr, "Cannot get surface to display video source %d\n", err);		return -1;	}	err = DCCEnableSPUSurface(pDCC, dcc_info.route, 0, (struct DCCVideoSource *) NULL, FALSE);	#if (EM86XX_MODE == EM86XX_MODEID_WITHHOST)	bitmapLumaSize = (osd_profile.Width)*(osd_profile.Height);	bitmapChromaSize = (bitmapLumaSize/2); // only true for YUV 420 !!!	pLuma = (RMuint8 *)RMMalloc(bitmapLumaSize*sizeof(RMuint8));	if(pLuma == (RMuint8 *)NULL) {		fprintf(stderr, "Cannot RMMalloc() LUMA buffer !!\n");		return -1;	}		pChroma = (RMuint8 *)RMMalloc(bitmapChromaSize*sizeof(RMuint8));	if(pChroma == (RMuint8 *)NULL) {		fprintf(stderr, "Cannot RMMalloc() CHROMA buffer !!\n");		return -1;	}	if (grey_w && grey_h) {		create_grey_420(osd_profile.Width, osd_profile.Height, pLuma, pChroma);	} else {		decompress_jpg_file(&cinfo, fd, pLuma, pChroma);	}	err = DCCSetOSDVideoSource(pOSDSource, pLuma, pChroma);	if (RMFAILED(err)) {		fprintf(stderr, "Cannot load image to RUA buffer %d\n", err);		return -1;	}#else	{		RMuint32 LumaAddr=0,ChromaAddr=0;		err = DCCGetOSDVideoSourceInfo(pOSDSource, &LumaAddr, &bitmapLumaSize, &ChromaAddr, &bitmapChromaSize);		if (RMFAILED(err)) {			fprintf(stderr, "Cannot get osd buffer info %d\n", err);			return -1;		}				pLuma = (RMuint8 *)LumaAddr;		pChroma = (RMuint8 *)ChromaAddr;	}		if (grey_w && grey_h) {		create_grey_420(osd_profile.Width, osd_profile.Height, pLuma, pChroma);	} else {		decompress_jpg_file(&cinfo, fd, pLuma, pChroma);	}#endif	if(filename2) {		// spawning thread		rc = pthread_create(&pth,(pthread_attr_t *)NULL, main2, filename2);		if(rc != 0) fprintf(stderr, "Cannot spawn thread %d\n", rc);	}	err = DCCSetSurfaceSource(pDCC, surfaceID, pOSDSource);	if (RMFAILED(err)) {			fprintf(stderr, "Cannot set the surface source %d\n", err);			return -1;	}		dcc_info.pOSDSource = pOSDSource;	dcc_info.osd_scaler = surfaceID;	dcc_info.osd_enable = TRUE;	display_key_usage(KEYFLAGS);	// specific key usage for play_jpeg	fprintf(stdout,"\nSpecific commands  for %s :\n",argv[0]);	fprintf(stdout,"\tS - Display second picture (if second picture on command line)\n");	fprintf(stdout,"\tP - Display first picture\n");	RMTermInit(TRUE);    // don't allow ctrl-C and the like ...	RMSignalInit(NULL, NULL);  // ... but catch other termination signals to call RMTermExit()	do {		RMuint32 cmd;		err = process_key(&dcc_info, &cmd, KEYFLAGS);		if (RMFAILED(err)) {			fprintf(stderr, "Error while processing key %d\n", err);			break;		}		switch(cmd) {		case RM_STOP:			DCCSetSurfaceSource(pDCC, surfaceID, (struct DCCVideoSource *)NULL);			surface_is_ready = 1;			break;		case RM_PLAY:			surface_is_ready = 0;			DCCSetSurfaceSource(pDCC, surfaceID, (struct DCCVideoSource *)NULL);			while(RMFAILED( DCCSetSurfaceSource(pDCC, surfaceID, pOSDSource))) {				fprintf(stderr,"Waiting for surface to be ready ...\n");				usleep(WAIT_SURFACE_READY);			}			break;		case RM_SEEK: 			fprintf(stderr, "Unsuported command\n");			cmd = RM_PLAY;			break;		case RM_QUIT:			surface_is_ready = -1;			goto cleanup;			break;		default:			usleep(50*1000);			break;		}		update_hdmi(&dcc_info, &disp_opt, NULL);	} while(1);cleanup:	RMTermExit();#if (EM86XX_MODE == EM86XX_MODEID_WITHHOST)	RMFree(pLuma);	RMFree(pChroma);#endif	// clear_display_options() calls DCCCloseVideoSource()	clear_display_options(&dcc_info, &disp_opt);		err = DCCClose(pDCC);	if (RMFAILED(err)) {		fprintf(stderr, "Cannot close DCC %d\n", err);		return -1;	}	err = RUADestroyInstance(pRUA);	if (RMFAILED(err)) {		fprintf(stderr, "Cannot destroy RUA instance %d\n", err);		return -1;	}	if(filename2) {		rc = pthread_join(pth,&rc_pth);		if(rc != 0) fprintf(stderr, "Can't wait for thread to terminate %d\n", rc);		if(rc_pth == NULL) fprintf(stderr, "Something went wrong with the other thread !!!\n");	}		return 0;}#elseint main(int argc, char *argv[]){	return 0;}#endif

⌨️ 快捷键说明

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