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

📄 vod.cpp

📁 vod vod vod vod
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	}



int GetFromID(int keycode) //数码点歌
{   
		if (strlen(str_id)>7)
			return -1;
			
    if ((keycode>=48)&&(keycode<=57))  //按esc向上
			{
          osd_disp_stat=1;
			    sprintf(str_key,"%d",(keycode-48));
					strcat(str_id,str_key);
			
					strcpy((char*)ctmpsongid,"编码:");
					strcat((char*)ctmpsongid,str_id);
					id_times=25;
			redrawtext_color(wnd,b,str_id,230,211,190,45,asc,FGColor(100,50,40));
			}
			printf("strid:%s len:%d \n",str_id,strlen(str_id));
	}



//*******************
//删除歌曲从歌曲清单*
//*******************
bool DecSong()
{
	int i;
	char tmp[256];
	char *pp[5];
	if (SelSongs.m_count<=0)
     { strcpy(curplaycode,"NULL");
       return false;
     }
	else
		{
			if (!SelSongs.getheadfield(tmp))
				return false;
			split(tmp,pp);	 
			strcpy(curplaycode,pp[2]);
			strcpy(curplaysongname,pp[0]);
			SelSongs.removehead();
			SelSongs.savelog();
		}

	if (win_name==SONGLIST)//动态刷新已点清单
		{
		if (wndsonglist)
			{//ReDrawBK(wndsonglist,SONGLIST,0);	
			 Show_select_Songs();
		  }
		}
		
	//if (win_name==RECSONG)//动态刷新已点清单
	//	{
	//	fprintf(stderr,"cursongname:%s\n",curplaysongname);
	//	show_cur_rec_song();	
	//	}
}




//*************************rua 
static void rgbtoyuv(double R,double G,double B,double *y,double *u,double *v)
{
	*y=(0.257*R + 0.504*G + 0.098*B) + 16.0;
	*u=(-0.148*R - 0.291*G + 0.439*B) + 128.0;
	*v=(0.439*R - 0.368*G - 0.071*B) + 128.0;
}


	RUA_handle h;

	png_uint_32 width, height;
	png_uint_32 ow=600, oh=150;
	
	

int initdev()
{
h=RUA_OpenDevice(0,TRUE);
	if (h==NULL)
	{printf("can't AccessDevice\n"); 
	 return -1;
	}
	else
	{printf("open device is ok\n");}

RUA_SNDMIXER_SWITCH(h,FALSE);
if (RUA_SNDMIXER_SWITCH(h,TRUE)==0) 
 printf("sndmixer is now on.\n");
else
 printf("switch sndmixer is error.\n");

	Wnd_type window;
    window.w=ow;
	window.h=oh;
	window.x=50;
	window.y=50;
	//设置osd大小区域
	RUA_DECODER_SET_PROPERTY(h,OSD_SET,eOsdDestinationWindow,sizeof(Wnd_type),&window);
	eOsdCommand_type command=eOsdOn;
	RUA_DECODER_SET_PROPERTY(h,OSD_SET,eOsdCommand,sizeof(eOsdCommand_type),&command);

	
}

//************************
//把osd图片和文字读到缓冲*
//************************
OsdPng osd;
int looposd()
{
	switch (osd_disp_stat) 
	{
	case 10://0显示流动字幕
		
		osd.MoveText(wnd,songosd,ctmp);
		break;
	case 1://1显示编码点歌
		osd.TextOut(wnd,songosd,ctmpsongid,200);
		break;
	case 2://2显示录音进度
		osd.TextOut(wnd,songosd,ctmprec,100);
		break;
	case 3://3显示wav回放进度
		
		sprintf(dispstr,"%s %d/%d",ctmpplay,playtime,toltime);
		osd.TextOut(wnd,songosd,dispstr,100);

		break;
	case 4://4显示按键图标
		osd.AddGif(icon,400);
		break;

	default:
		break;
	}
}








void showosd(char *image_buf,int bufcount)
{
	#define CHUNKSIZE 8000
	int i;
	char buf[CHUNKSIZE];
	int read_buf_num;
	int read_count=0;

	if (bufcount%CHUNKSIZE>0)
       read_buf_num=(ow*oh+1032)/CHUNKSIZE+1;
	else
	   read_buf_num=(ow*oh+1032)/CHUNKSIZE;

		for(i=0;i<read_buf_num;i++)
	{
		my_MPEG_WRITE_DATA Q={0,};
			for (read_count=0;read_count<CHUNKSIZE;read_count++)
			{   if ((i*CHUNKSIZE+read_count)<(ow*oh+1032))
				{buf[read_count]=image_buf[i*CHUNKSIZE+read_count];}
				else
				break;

			}
	
       if (i==(read_buf_num-1))
	   {Q.pData=(RMuint8*)buf;
		Q.DataLeft=read_count;
	   }
	   else
	   {Q.pData=(RMuint8*)buf;
		Q.DataLeft=CHUNKSIZE;
	   }
		#define COPYANDQUEUEDATA_TIMEOUT_MICROSEC 200000
		while (RUA_DECODER_FEEDME(h,REALMAGICHWL_OSD,0,&Q)!=0) 
		{
			RMuint32 X=REALMAGICHWL_HAPPENING_DECODER_OSDDMA_HALF;
			RUA_DECODER_WAIT(h,COPYANDQUEUEDATA_TIMEOUT_MICROSEC,&X);

			if ((X&REALMAGICHWL_HAPPENING_DECODER_OSDDMA_HALF)==0)
				printf("REALMAGICHWL_HAPPENING_DECODER_OSDDMA_HALF timeout...\n");
		}
	} 
}

//*************************ruaend






//**************************************dvd
static void apidemopaniccallback(RMuint32 reason)
{
	longjmp(g_env,(int)reason);
}

//static RMbool g_trickmode;
static int writeOSD;
static int finishTimeThread = 0;

static void signalCatch(int arg)
	{printf("received sig pipe\n");}



int cleanDVDup()
{ 
	finishTimeThread = 1; 
	RMFCloseControlInterface(ctrl);
	printf("interface closed\n");
	if (ExitCaribbean(&memoryPeakUsage)==RM_OK) 
	{
       printf("Memory peak usage=%ld/%d bytes (%ld%%)\n",
	   memoryPeakUsage,
	   TOTAL_MEMORY_NEEDED_PER_BOARD*1,
	   100*memoryPeakUsage/(TOTAL_MEMORY_NEEDED_PER_BOARD*1));
       free(pStart);
	}
}

int initDVD()
{
	int rc;
	RMuint32 width = 0;
	RMuint32 height = 0;
	
	struct sigaction sa;
	sa.sa_handler = &signalCatch;
	sa.sa_flags = 0;
	sigemptyset( &sa.sa_mask );
	sigaction(SIGPIPE, &sa, 0 );
	pStart=(RMuint8 *)malloc(TOTAL_MEMORY_NEEDED_PER_BOARD*1);	/* 建立区,进入驱动Creates the zone and enter Caribbean driver */
	if (pStart==NULL) 
	{	printf("Cannot allocate %d bytes.\n",TOTAL_MEMORY_NEEDED_PER_BOARD*1);
		return -1;
	}
	rc=setjmp(g_env);
	if (rc==0)
		{printf("Saved context for panic situation OK\n");}
	else
		{
		fprintf(stderr,"CARIBBEAN called RMPanic with RMstatus %d. Exiting\n",rc);
		if (rc==RM_ERRORGRAPHMISSINGNODEORMODULE) 
			fprintf(stderr,"you are missing a required shared library\n");
		return -1;
		}
	EnterCaribbean(pStart,TOTAL_MEMORY_NEEDED_PER_BOARD*1,RM_MACHINEALIGNMENT,apidemopaniccallback);

}	

static void convertToTime(RMuint32 totalSeconds, char tmp[20])
{
	RMuint32 hours;
	RMuint32 minutes;
	RMuint32 seconds;
	
	seconds = (RMuint32) (totalSeconds % 60);
	minutes = (RMuint32) (totalSeconds/60);
	hours = (RMuint32) (minutes/60);
	minutes = (RMuint32) (minutes%60);
	sprintf(tmp,"%02lu:%02lu:%02lu",hours,minutes,seconds);
	printf("%02lu %02lu %02lu",hours,minutes,seconds);
}

//************
//DVD回调函数*
//************
long LAST_TRAME_INDEX=0;
static void callback(RMTcontrolInterface ctrl, void *userData, RMmessage message, RMuint32 val)
{
	RMTpropertyControl ctrl_prop;
	char text[20];
	bool playerror;
	playerror=false;
	switch (message) 
	{
	
//	case RM_MESSAGE_FRAME_INDEX:
			//printf( "lase Frame Idx: %3lu\n", LAST_TRAME_INDEX);
			//printf( "Frame Idx: %3lu\n", val);
			//if (LAST_TRAME_INDEX<val)
			//	printf( "lll\n");
			//else
			//{
			//	printf( "file play error\n");
				//playerror=true;
			//	if (LAST_TRAME_INDEX!=0)
			//	{	LAST_TRAME_INDEX=0;
			//	keyplay();
			//}
		//	}
			//if (playerror)
			//	LAST_TRAME_INDEX=0;
			//else	
	//			LAST_TRAME_INDEX=val;
	//	break;
		
	case RM_MESSAGE_ERROR:
			printf("callback Message recevie error\n");
		break;
	case RM_MESSAGE_EOS:
			dvd_play_stats=STOPPING;
			
		break;
	case RM_MESSAGE_DISPLAY_TIME:
		    RMFGetControlHandle((void **) &ctrl_prop, RM_CONTROL_PROPERTY, ctrl);
		    RMFGetGenericProperty(ctrl_prop, RM_PROPERTY_EXTERNAL, "VIDEO", "DURATION", &duration, sizeof(RMuint32));
		
			if (wav_recording==1)
			{
				tolsec=(RMuint32)val;
				convertToTime(val,text);
				sprintf(ctmprec,"录制时间 %s",text);
				printf( "tolsec:%02lu  duration:%02lu\n",tolsec,duration);
			}
			else
			{
				strcpy(ctmprec,"录制时间结束");
			}
 		break;
	default:
		break;
	}
}


void openDVDfile(char *songpath)
{
	RMuint32  nurl, val;
	Wnd_type hwnd;
	RMTpropertyControl ctrl_prop;
    evInAspectRatio_type ratio = evInAspectRatio_4x3;
	evOutDisplayOption_type display = evOutDisplayOption_Normal;
	ebiCommand_type black = ebiCommand_VideoHwBlackFrame;

	//if (RMFOpenUrlControlInterface("FILE@DIVX_PCM:///song/divx_pcm.avi", &(ctrl), &callback, NULL) != RM_OK)              /*鎵撳紑鏂囦欢*/
//printf(";;;;;;;;;;;;;;;;;;;\n");
//printf("%s\n",songpath);
	if (RMFOpenUrlControlInterface((const RMascii*)songpath, &(ctrl), &callback, NULL) != RM_OK)              /*鎵撳紑鏂囦欢*/

	{	printf("\nCannot open the specified url :%s\n",songpath);
		cleanDVDup();
	}
	else
	{
	dvd_play_stats=PLAYING;
  }
	RMFGetControlHandle((void **) &ctrl_prop, RM_CONTROL_PROPERTY, ctrl);

	// reinit aspectratio to default value
	RMFSetGenericProperty(ctrl_prop, RM_PROPERTY_HWLIB, "BOARDINFO_SET","ebiCommand", &black, sizeof(ebiCommand_type));
	RMFSetGenericProperty(ctrl_prop, RM_PROPERTY_HWLIB, "VIDEO_SET","evInAspectRatio", &ratio, sizeof(evInAspectRatio_type));
	RMFSetGenericProperty(ctrl_prop, RM_PROPERTY_HWLIB, "VIDEO_SET","evOutDisplayOption", &display, sizeof(evOutDisplayOption_type));
	width = 0;
	height = 0;
		RMFGetPropertyValue(ctrl_prop, RM_PROPERTY_HWLIB, "VIDEO_SET", "evTvStandard", &val);
			hwnd.x=0;
			hwnd.y=0;
		if (val == evTvStandard_PAL) {
			printf("TV type = PAL\n");
			hwnd.h = PAL_SCREEN_HEIGHT;
			hwnd.w = PAL_SCREEN_WIDTH;
		}
		else if (val == evTvStandard_NTSC) {
			printf("TV type = NTSC\n");
			hwnd.h = NTSC_SCREEN_HEIGHT;
			hwnd.w = NTSC_SCREEN_WIDTH;
		}
		// Apply the settings
		RMFSetGenericProperty(ctrl_prop, RM_PROPERTY_HWLIB, "VIDEO_SET","evDestinationWindow", &hwnd, sizeof(Wnd_type));
		// This is optional. This is just to keep the PIDs active after a stop (or else they are reset to 0).
		RMFSetPropertyState(ctrl_prop, RM_PROPERTY_EXTERNAL, "DEMUX", "KeepPIDAfterStop", TRUE);
}

void closeDVDfile()
{
RMFCloseControlInterface(ctrl);
printf("interface closed\n");
}


bool pth_end;
bool findsong;
pthread_t pid;
char access_song_path[20];

void* mythread(void*)
{
	if (access(access_song_path,F_OK)==0) 
		{printf("%s is exise\n",access_song_path);
			
			findsong=true;
		}
	else
		printf("%s is not find\n",access_song_path);

		pth_end=true;
}

void Draw(int)
{
    printf("timeout  \n");
    if (!pth_end)
    {pthread_cancel(pid);
    pth_end=true;
  }
}




bool get_url_from_code(char *path,char *code)
{   char tmpstr[50];
		char search_path[20][20];
		char file_type[3][4];
		char url_type[3][4];
		int i,j;
		
		pthread_attr_t attr;
		int ret;

  strcpy(search_path[0],"song0");
	strcpy(search_path[1],"song1");
	strcpy(search_path[2],"song2");
	strcpy(search_path[3],"song3");
	strcpy(search_path[4],"song4");
	strcpy(search_path[5],"song5");
	strcpy(search_path[6],"song6");
	strcpy(search_path[7],"song7");
	strcpy(search_path[8],"song8");
	strcpy(search_path[9],"song9");
	strcpy(search_path[10],"song10");
	strcpy(search_path[11],"song11");
	strcpy(search_path[12],"song12");
	strcpy(search_path[13],"song13");
	strcpy(search_path[14],"song14");
	strcpy(search_path[15],"song15");
	strcpy(search_path[16],"song16");
	strcpy(search_path[17],"song17");
	strcpy(search_path[18],"song18");
	strcpy(search_path[19],"song19");
	
	
	strcpy(file_type[0],"mpg"); //mpeg2
	strcpy(file_type[1],"m2p"); //mpeg1
	strcpy(file_type[2],"avi"); //divx
	
	strcpy(url_type[0],"M1S"); //mpeg2
	strcpy(url_type[1],"VOB"); //mpeg1
	strcpy(url_type[2],"DIVX"); //divx
		
		findsong=false;
	for (i=0;i<20;i++)
	{
			for(j=0;j<2;j++)
			{
				sprintf(access_song_path,"/%s/%s.%s",search_path[i],code,file_type[j]);
				
       // printf("path:%s\n",access_song_path);
       
		    if (access(access_song_path,F_OK)==0)  
					{		sprintf(path,"FILE@%s://%s",url_type[j],access_song_path);
					    return true;
					}	
			}
			
	}
	    return false;
}

int setsound(int val)
{
	RMTpropertyControl ctrl_prop;	 	
  RMFGetControlHandle((void **) &ctrl_prop, RM_CONTROL_PROPERTY, ctrl);
  
RMFSetPropertyValue(ctrl_prop, RM_PROPERTY_HWLIB, "AUDIO_SET", "eaVolumeRight", val);	
RMFSetPropertyValue(ctrl_prop, RM_PROPERTY_HWLIB, "AUDIO_SET", "eaVolumeLeft", val);


}

int keyplay()
{
IFFastPlay=false;
IFPause=false;
//IFMute=false;

if (IFMute)
	{
	IFMute=false;
	setsound(50);  
	}



		DecSong();
		while(!get_url_from_code(curplaypath,curplaycode)&&(strcmp(curplaycode,"NULL")!=0))
		{DecSong();}
		
  	if (strcmp(curplaycode,"NULL")!=0)  
  	{	
			
			//printf("curplaypath:%s\n",curplaypath);
			
			RMFStopFile(ctrl_file);
			printf("this is ok\n");
			LAST_TRAME_INDEX=0;
			
			
			
			RMFCloseControlInterface(ctrl);
			
			openDVDfile(curplaypath);
			
			RMFGetControlHandle((void **) &ctrl_file, RM_CONTROL_FILE, ctrl);
			RMFPlayFile(ctrl_file);
			karaok=true;
			keyLR();
		}
		else
		{
	
			RMFStopFile(ctrl_file);
			LAST_TRAME_INDEX=0;
			RMFCloseControlInterface(ctrl);
	
			strcpy(curplaypath,"FILE@M1S:///song/nosong.mpg");
			
			openDVDfile(curplaypath);
			
			RMFGetControlHandle((void **) &ctrl_file, RM_CONTROL_FILE, ctrl);
			
			RMFPlayFile(ctrl_file);
			
			keyLR();
			//LR(atoi(LR_val));
    }
   printf("play:%s\n",curplaypath); 
//   wnd->printf(10, 10, curplaypath);

}



int volup()
{	RMTpropertyControl ctrl_prop;
	  	 if (RMFGetControlHandle((void **) &ctrl_prop, RM_CONTROL_PROPERTY, ctrl)!=RM_OK)
		    {	fprintf(stderr, "get handle is error\n");
    		  return -1;
    		}      

⌨️ 快捷键说明

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