vd_realvid.c

来自「君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图」· C语言 代码 · 共 550 行 · 第 1/2 页

C
550
字号
struct rv_init_t {	short unk1;	short w;	short h;	short unk3;	int unk2;	int subformat;	int unk5;	int format;} rv_init_t;// init driverstatic int init(sh_video_t *sh){	//unsigned int out_fmt;	//char *path;	int result;	// we export codec id and sub-id from demuxer in bitmapinfohdr:	unsigned char* extrahdr=(unsigned char*)(sh->bih+1);	unsigned int extrahdr_size = sh->bih->biSize - sizeof(BITMAPINFOHEADER);	struct rv_init_t init_data;	if(extrahdr_size < 8) {	    mp_msg(MSGT_DECVIDEO,MSGL_ERR,"realvideo: extradata too small (%u)\n", sh->bih->biSize - sizeof(BITMAPINFOHEADER));	    return 0;	}	init_data = (struct rv_init_t){11, sh->disp_w, sh->disp_h, 0, 0, be2me_32(((unsigned int*)extrahdr)[0]), 1, be2me_32(((unsigned int*)extrahdr)[1])}; // rv30	mp_msg(MSGT_DECVIDEO,MSGL_V,"realvideo codec id: 0x%08X  sub-id: 0x%08X\n",be2me_32(((unsigned int*)extrahdr)[1]),be2me_32(((unsigned int*)extrahdr)[0]));	//path = malloc(strlen(REALCODEC_PATH)+strlen(sh->codec->dll)+2);	//if (!path) return 0;	//sprintf(path, REALCODEC_PATH "/%s", sh->codec->dll);	/* first try to load linux dlls, if failed and we're supporting win32 dlls,	   then try to load the windows ones */#ifdef HAVE_LIBDL       	if(!load_syms_linux(NULL))	//if(strstr(sh->codec->dll,".dll") || !load_syms_linux(path))#endif#ifdef USE_WIN32DLL	    if (!load_syms_windows(sh->codec->dll))#endif	{		//mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MissingDLLcodec,sh->codec->dll);		mp_msg(MSGT_DECVIDEO,MSGL_HINT,"Read the RealVideo section of the DOCS!\n");		//free(path);		return 0;	}	//free(path);	// only I420 supported//	if((sh->format!=0x30335652) && !mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_I420)) return 0;	// init codec:	sh->context=NULL;#ifdef USE_WIN32DLL	if (dll_type == 1)	    result=(*wrvyuv_init)(&init_data, &sh->context);	else#endif	result=(*rvyuv_init)(&init_data, &sh->context);	if (result){	    mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Couldn't open RealVideo codec, error code: 0x%X  \n",result);	    return 0;	}	// setup rv30 codec (codec sub-type and image dimensions):	if((sh->format<=0x30335652) && (be2me_32(((unsigned int*)extrahdr)[1])>=0x20200002)){	    int i, cmsg_cnt;	    uint32_t cmsg24[16]={sh->disp_w,sh->disp_h};	    cmsg_data_t cmsg_data={0x24,1+(extrahdr[1]&7), &cmsg24[0]};	    mp_msg(MSGT_DECVIDEO,MSGL_V,"realvideo: using cmsg24 with %u elements.\n",extrahdr[1]&7);	    cmsg_cnt = (extrahdr[1]&7)*2;	    if (extrahdr_size-8 < cmsg_cnt) {	        mp_msg(MSGT_DECVIDEO,MSGL_WARN,"realvideo: not enough extradata (%u) to make %u cmsg24 elements.\n",extrahdr_size-8,extrahdr[1]&7);	        cmsg_cnt = extrahdr_size-8;	    }	    for (i = 0; i < cmsg_cnt; i++)	        cmsg24[2+i] = extrahdr[8+i]*4;	    if (extrahdr_size-8 > cmsg_cnt)	        mp_msg(MSGT_DECVIDEO,MSGL_WARN,"realvideo: %u bytes of unknown extradata remaining.\n",extrahdr_size-8-cmsg_cnt);#ifdef USE_WIN32DLL	    if (dll_type == 1)		(*wrvyuv_custom_message)(&cmsg_data,sh->context);	    else#endif	    (*rvyuv_custom_message)(&cmsg_data,sh->context);	}	mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: RealVideo codec init OK!\n");	return 1;}// uninit driverstatic void uninit(sh_video_t *sh){#ifdef USE_WIN32DLL	if (dll_type == 1)	{	    if (wrvyuv_free) wrvyuv_free(sh->context);	} else#endif	if(rvyuv_free) rvyuv_free(sh->context);#ifdef USE_WIN32DLL	if (dll_type == 1)	{	    if (rv_handle) FreeLibrary(rv_handle);	} else#endif#ifdef HAVE_LIBDL	//if(rv_handle) dlclose(rv_handle);#endif	rv_handle=NULL;	inited = 0;	if (buffer)	    free(buffer);	buffer = NULL;	//bufsz = 0;}// copypaste from demux_real.c - it should match to get it working!typedef struct dp_hdr_s {    uint32_t chunks;	// number of chunks    uint32_t timestamp; // timestamp from packet header    uint32_t len;	// length of actual data    uint32_t chunktab;	// offset to chunk offset array} dp_hdr_t;// decode a framestatic mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){	mp_image_t* mpi;	unsigned long result;	dp_hdr_t* dp_hdr=(dp_hdr_t*)data;	unsigned char* dp_data=((unsigned char*)data)+sizeof(dp_hdr_t);	uint32_t* extra=(uint32_t*)(((char*)data)+dp_hdr->chunktab);	unsigned int transform_out[5];	transform_in_t transform_in;	if(flags==1)	{	transform_in=(transform_in_t){		dp_hdr->len,	// length of the packet (sub-packets appended)		0,		// unknown, seems to be unused		dp_hdr->chunks,	// number of sub-packets - 1		extra,		// table of sub-packet offsets		0x206,		// unknown, seems to be unused		dp_hdr->timestamp,// timestamp (the integer value from the stream)	};	 }else { 	transform_in=(transform_in_t){		dp_hdr->len,	// length of the packet (sub-packets appended)		0,		// unknown, seems to be unused		dp_hdr->chunks,	// number of sub-packets - 1		extra,		// table of sub-packet offsets		0,		// unknown, seems to be unused		dp_hdr->timestamp,// timestamp (the integer value from the stream)	}; }	 	//F("flags = %x\n",flags);	if(len<=0 || flags&2) return NULL; // skipped frame || hardframedrop/*	if (bufsz < sh->disp_w*sh->disp_h*3/2) {	    if (buffer) free(buffer);	    bufsz = sh->disp_w*sh->disp_h*3/2;	    buffer=malloc(bufsz);	    if (!buffer) return 0;	}	*/	if(buffer == NULL)	{			 buffer = malloc(sizeof(unsigned int) * 8);			 //return 0;	}#ifdef USE_WIN32DLL	if (dll_type == 1)	    result=(*wrvyuv_transform)(dp_data, buffer, &transform_in,		transform_out, sh->context);	else#endif  // F("%x\n",buffer);	result=(*rvyuv_transform)(dp_data, buffer, &transform_in,		transform_out, sh->context);				#if 0	ULONG32 numFrames;	ULONG32 notes;        /* 'notes' is assigned by the transform function during each call to */        /* decompress a frame.  If upon return the notes parameter contains */        /* the indication RV_DECODE_MORE_FRAMES, then the front-end */        /* should invoke the decoder again to decompress the same image. */        /* For this additional invocation, the front-end should first set */        /* the RV_DECODE_MORE_FRAMES bit in the 'H263DecoderInParams.flags' */        /* member, to indicate to the decoder that it is being invoked to */        /* extract the next frame. */        /* The front-end should continue invoking the decoder until the */        /* RV_DECODE_MORE_FRAMES bit is not set in the 'notes' member. */        /* For each invocation to decompress a frame in the same "MORE_FRAMES" */        /* loop, the front-end should send in the same input image. */        /* */        /* If the decoder has no frames to return for display, 'numFrames' will */        /* be set to zero.  To avoid redundancy, the decoder does *not* set */        /* the RV_DECODE_DONT_DRAW bit in 'notes' in this case. */	ULONG32 timestamp;        /* The 'temporal_offset' parameter is used in conjunction with the */        /* RV_DECODE_MORE_FRAMES note, to assist the front-end in */        /* determining when to display each returned frame. */        /* If the decoder sets this to T upon return, the front-end should */        /* attempt to display the returned image T milliseconds relative to */        /* the front-end's idea of the presentation time corresponding to */        /* the input image. */        /* Be aware that this is a signed value, and will typically be */        /* negative. */	ULONG32 width;	ULONG32 height;		/* Width and height of the returned frame. */		/* This is the width and the height as signalled in the bitstream. */#endif	if(transform_out[0] == 0)      	return NULL;	//if(flags == 1)	//	return NULL;	if(!inited){  // rv30 width/height now known	    sh->aspect=(float)sh->disp_w /(float)sh->disp_h;	    sh->disp_w=transform_out[3];	    sh->disp_h=transform_out[4];	    if (!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_I420)) return 0;	    //if (!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YV12)) return 0;	    inited=1;	} 	    mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, 0 /*MP_IMGFLAG_ACCEPT_STRIDE*/,		    sh->disp_w, sh->disp_h);		  if(!mpi) 		  {		  		return NULL;	    }	    /*	    mpi->planes[0] = buffer;	    mpi->stride[0] = sh->disp_w;	    mpi->planes[1] = buffer + sh->disp_w*sh->disp_h;	    mpi->stride[1] = sh->disp_w / 2;	    mpi->planes[2] = buffer + sh->disp_w*sh->disp_h*5/4;	    mpi->stride[2] = sh->disp_w / 2;     */          	//F("======== %x %x\n",transform_out[0],buffer);      mpi->planes[0] = *(buffer + 2);	    mpi->stride[0] = *(buffer + 3);	    mpi->planes[1] = *(buffer + 4);	    mpi->stride[1] = *(buffer + 5);	    mpi->planes[2] = *(buffer + 6);	    mpi->stride[2] = *(buffer + 7);	    //F("%x %x %x\n",mpi->planes[0],mpi->planes[1],mpi->planes[2]);	    	    /*     		*out++ = 0 (unsigned long)dst->format.rectangle.width;				*out++ = 1 (unsigned long)dst->format.rectangle.height;				*out++ = 2 (unsigned long)pDisplayBuffer->m_pYPlane;				*out++ = 3 (unsigned long)pDisplayBuffer->m_pitch;				*out++ = 4 (unsigned long)pDisplayBuffer->m_pUPlane;				*out++ = 5 (unsigned long)pDisplayBuffer->m_pitch;				*out++ = 6 (unsigned long)pDisplayBuffer->m_pVPlane;				*out++ = 7 (unsigned long)pDisplayBuffer->m_pitch;		   */	if(transform_out[0] &&	   (sh->disp_w != transform_out[3] || sh->disp_h != transform_out[4]))	{    	    inited = 0;	}		return (result?NULL:mpi);}

⌨️ 快捷键说明

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