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

📄 lfplayer.cxx

📁 很不错的播放代玛
💻 CXX
📖 第 1 页 / 共 2 页
字号:
/***********************************************************************************************************************
Author name		   : Jack
Title			   : Main routine
Working environment: Linux or Windows platform . 
Copyright (C) LiFan Technology 2006. 
***********************************************************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <fltk/run.h>
#include <fltk/events.h>
#include <fltk/Widget.h>
#include <fltk/Window.h>
#include <FL/Fl_Menu_Item.H>
#include <fltk/MenuBar.h>
#include <fltk/ask.h>
#include <fltk/SharedImage.h>
#include <fltk/xbmImage.h>
#include <fltk/Button.h>
#include <fltk/Monitor.h>
#include <fltk/x.h>

#include <include/LFPlayer.h>
void WV_ConstructWorkSpace(void)
{
	int ws_pos = 0;
	int ws_height = 0;
	int x,y,w,h;
//	WV_LoadStartImage();
	pWorkSpace = new Window(WEINVIEWWIDTH,WEINVIEWHEIGHT);
	pWorkSpace->box(DOWN_BOX);
	pWorkSpace->color(GRAY15);
	pWorkSpace->clear_border();

	w = pWorkSpace->w(); h = pWorkSpace->h();
#ifdef WIN32
		x = (pWeinWin->w() -  WEINVIEWWIDTH)/2;

		y = (pWeinWin->h() -  WEINVIEWHEIGHT)/2;
		
//		if(WV_EobGetWorkMode() == NORMAL_WS)
//		{
			x += pWeinWin->x();
			y += pWeinWin->y();
//		}
//		else
//		pWeinWin->insert(*pWorkSpace, 0);			
#else
	const Monitor& monitor = Monitor::find(pWorkSpace->x()+pWorkSpace->w()/2, pWorkSpace->y()+pWorkSpace->h()/2);
	x = (monitor.w() - w)/2;
	y = (monitor.h() - h)/2;
#endif
	pWorkSpace->resize(x,y,w,h);
}          
///////////////////////////////////////////////////////////////
void WV_ConstructMainWindow(void)
{
	int x,y,w,h;

#ifdef WIN32
	W_BYTE VirtualName[200];
	
	memset(VirtualName,0,200);
	GetCurrentDirectory(100,VirtualName);
	strcat(VirtualName,"\\MT800.bmp");

	bmpImage* pImage =(bmpImage*) bmpImage::get(VirtualName);
	pImage->measure(w,h);
	pWeinWin = new Weinview_Window(NO_BOX,w,h);
	pWeinWin->clear_border();	
	pWeinWin->image(pImage);
		
	const Monitor& monitor = Monitor::find(pWeinWin->x()+pWeinWin->w()/2, pWeinWin->y()+pWeinWin->h()/2);
	x = (monitor.w() - w)/2;
	y = (monitor.h() - h)/2;
	pWeinWin->resize(x,y,w,h);
#endif
	WV_ConstructWorkSpace(); 
}
LF_VOID LIFAN_ConstructPlayerWindow(LF_DWORD product_id)
{// draw the interface of lf;
}
////////////////////////////////////////////////////////////////////////////////////////////////
//
void  LIFAN_OpenVOBSub(void)
{
	char *buf;
	char *psub;

 ////////////////////////////////
 // init global sub numbers
	global_sub_size = 0;
	for (i = 0; i < SUB_SOURCES; i++) 
		global_sub_indices[i] = -1; 
////////////////////////////////

    if (vobsub_name)
	{
		vo_vobsub=vobsub_open(vobsub_name,spudec_ifo,1,&vo_spudec);
		if(vo_vobsub==NULL)
		{
			message("Can't load subtitle file !")
//			mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadSub,vobsub_name);
		}
    }
	else if(sub_auto && filename && (strlen(filename)>=5))
	{
      /* try to autodetect vobsub from movie filename ::atmos */
		char *buf = malloc((strlen(filename)-3) * sizeof(char)),*psub;
		memset(buf,0,strlen(filename)-3); // make sure string is terminated
		strncpy(buf, filename, strlen(filename)-4); 
		vo_vobsub=vobsub_open(buf,spudec_ifo,0,&vo_spudec);
      /* try from ~/.mplayer/sub */
		if(!vo_vobsub && (psub = get_path( "sub/" ))) 
		{
			char *bname;
			int l;
			
			bname = strrchr(buf,'/');
#ifdef WIN32
			if(!bname) 
				bname = strrchr(buf,'\\');
#endif
			if(bname) 
				bname++;
			else 
				bname = buf;
          
			l = strlen(psub) + strlen(bname) + 1;
			psub = realloc(psub,l);
			strcat(psub,bname);
			vo_vobsub=vobsub_open(psub,spudec_ifo,0,&vo_spudec);
			free(psub);          
		}
		free(buf);
	}
    if(vo_vobsub)
	{
		inited_flags|=INITED_VOBSUB;
		vobsub_set_from_lang(vo_vobsub, dvdsub_lang);
      // check if vobsub requested only to display forced subtitles
		forced_subs_only=vobsub_get_forced_subs_flag(vo_vobsub);

      // setup global sub numbering
		global_sub_indices[SUB_SOURCE_VOBSUB] = global_sub_size; // the global # of the first vobsub.
		global_sub_size += vobsub_get_indexes_count(vo_vobsub);
    }
}
////////////////////////////////////////////////////////////////////////////////////////////////
//
LF_BYTE LIFAN_OpenStream(void)
{
	FILE* pStreamDump;
	LF_UBYTE DumpBuffer[4096];
	LF_DWORD DumpLen;

	stream  = NULL;
	demuxer = NULL;
	d_audio = NULL;
	d_video = NULL;
	sh_audio=NULL;
	sh_video=NULL;

	stream=open_stream(filename,0,&file_format);
	if(!stream) 
	{ // error...
		message("stream is null");
		eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY);
		return LF_FAIL;
	//	goto goto_next_file;
	}
	
	inited_flags|=INITED_STREAM;

//#ifdef HAVE_NEW_GUI
//	if ( use_gui ) 
//		guiGetEvent( guiSetStream,(char *)stream );
//#endif

	if(file_format == DEMUXER_TYPE_PLAYLIST) 
	{
//		play_tree_t* entry;
    // Handle playlist
//		current_module="handle_playlist";
//		mp_msg(MSGT_CPLAYER,MSGL_V,"Parsing playlist %s...\n",filename);
//		entry = parse_playtree(stream,0);
//		eof=playtree_add_playlist(entry);
//		goto goto_next_file;
	}
	
	stream->start_pos+=seek_to_byte;
	if(stream_dump_type==5)
	{
//		unsigned char buf[4096];
//		int len;
//		FILE *f;
		
//current_module="dumpstream";
		if(stream->type==STREAMTYPE_STREAM && stream->fd<0)
		{
			message("Unavailable for dumping stream ");
			//exit(0);
//			mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_DumpstreamFdUnavailable);
//			exit_player(MSGTR_Exit_error);
		}
		stream_reset(stream);
		stream_seek(stream,stream->start_pos);
		pStreamDump=fopen(stream_dump_name,"wb");
		if(!pStreamDump)
		{
			message("Can't open the specified dumping file ");
			// exit()
//			mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile);
//			exit_player(MSGTR_Exit_error);
		}
		while(!stream->eof)
		{
			DumpLen=stream_read(stream,DumpBuffer,4096);
			if(DumpLen>0) 
			{
				if(fwrite(DumpBuffer,len,1,pStreamDump) != 1) 
				{
					message("Error for writing dumping file");
					//exit();
//					mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile,stream_dump_name);
//					exit_player(MSGTR_Exit_error);
				}
			}
		}
		if(fclose(pStreamDump)) 
		{
			message("Error for writing dumping file");
			//exit();
			//mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile,stream_dump_name);
			//exit_player(MSGTR_Exit_error);
		}
		message("Core dumped ");
	//		mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CoreDumped);
		exit_player_with_rc(MSGTR_Exit_eof, 0);
	}

#ifdef USE_DVDREAD
	if(stream->type==STREAMTYPE_DVD)
	{

//current_module="dvd lang->id";
		if(audio_id==-1) 
			audio_id=dvd_aid_from_lang(stream,audio_lang);
		if(dvdsub_lang && dvdsub_id==-2) 
			dvdsub_id=-1;
		if(dvdsub_lang && dvdsub_id==-1) 
			dvdsub_id=dvd_sid_from_lang(stream,dvdsub_lang);
  // setup global sub numbering
		global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
		global_sub_size += dvd_number_of_subs(stream);
//current_module=NULL;

	}
#endif

#ifdef USE_DVDNAV
	if (stream->type==STREAMTYPE_DVDNAV) 
		stream_cache_size=0;	// must disable caching...
#endif

// CACHE2: initial prefill: 20%  later: 5%  (should be set by -cacheopts)
#ifdef HAS_DVBIN_SUPPORT
	goto_enable_cache:
#endif

	if(stream_cache_size>0)
	{
// current_module="enable_cache";
		if(!stream_enable_cache(stream,stream_cache_size*1024,stream_cache_size*1024*(stream_cache_min_percent / 100.0),stream_cache_size*1024*(stream_cache_seek_min_percent / 100.0)))
			if((eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY))) 
			goto goto_next_file;
	}

	return LF_TRUE;
}
//============ Open DEMUXERS --- DETECT file type =======================
LF_BYTE LIFAN_OpenDemux(void)
{
	FILE* pStreamDump;
	play_tree_t* list;
	play_tree_t* entry;
	demux_stream_t *ds;
	LF_UBYTE* playlist_entry;
	LF_UBYTE* start;
	LF_BYTE* temp;
	LF_BYTE* bname;
	LF_DWORD in_size;



//current_module="demux_open";
//printf("jack for checking file type \r\n");
	
	demuxer=demux_open(stream,file_format,audio_id,video_id,dvdsub_id,filename);

// HACK to get MOV Reference Files working

	if (demuxer && demuxer->type==DEMUXER_TYPE_PLAYLIST)
	{ 
//		unsigned char* playlist_entry;
//		play_tree_t *list = NULL, *entry = NULL;
		list = NULL;
		entry = NULL;

		current_module="handle_demux_playlist";
		while (ds_get_packet(demuxer->video,&playlist_entry)>0)
		{	 
			char *temp, *bname;
    
			mp_msg(MSGT_CPLAYER,MSGL_V,"Adding file %s to element entry.\n",playlist_entry);

			bname=mp_basename(playlist_entry);
			if ((strlen(bname)>10) && !strncmp(bname,"qt",2) && !strncmp(bname+3,"gateQT",6))
				continue;

			if (!strncmp(bname,mp_basename(filename),strlen(bname))) // ignoring self-reference
				continue;

			entry = play_tree_new();
    
			if (filename && !strcmp(mp_basename(playlist_entry),playlist_entry)) // add reference path of current file
			{
				temp=malloc((strlen(filename)-strlen(mp_basename(filename))+strlen(playlist_entry)+1)*sizeof(char));
				if (temp)
				{
					strncpy(temp, filename, strlen(filename)-strlen(mp_basename(filename)));
					temp[strlen(filename)-strlen(mp_basename(filename))]='\0';
					strcat(temp, playlist_entry);
					play_tree_add_file(entry,temp);
					mp_msg(MSGT_CPLAYER,MSGL_V,"Resolving reference to %s.\n",temp);
					free(temp);
				}
			}
			else
				play_tree_add_file(entry,playlist_entry);
    
			if(!list)
				list = entry;
			else
				play_tree_append_entry(list,entry);
		}	
		free_demuxer(demuxer);
		demuxer = NULL;

		if (list)
		{
			entry = play_tree_new();
			play_tree_set_child(entry,list);
			eof=playtree_add_playlist(entry);
			goto goto_next_file;
		}
	}

	if(!demuxer) 
		goto goto_next_file;
	
	inited_flags|=INITED_DEMUXER;
	if (demuxer->type==DEMUXER_TYPE_MATROSKA) 
	{
  // setup global sub numbering
		global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
		global_sub_size += demux_mkv_num_subs(demuxer);
	}
#ifdef HAVE_OGGVORBIS
	if (demuxer->type==DEMUXER_TYPE_OGG) 
	{
  // setup global sub numbering
		global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
		global_sub_size += demux_ogg_num_subs(demuxer);
	}
#endif

//current_module="demux_open2";
//
//file_format=demuxer->file_format;
//
	d_audio=demuxer->audio;
	d_video=demuxer->video;
	d_dvdsub=demuxer->sub;

// DUMP STREAMS:
	if((stream_dump_type)&&(stream_dump_type<4))
	{
		
//		demux_stream_t *ds=NULL;
		ds = NULL;

//current_module="dump";
  // select stream to dump
		switch(stream_dump_type)
		{
			case 1: 
				ds=d_audio;
				break;
			case 2: 
				ds=d_video;
				break;
			case 3: 
				ds=d_dvdsub;
				break;
			default:
				break;
		}
		if(!ds)
		{        
			message("Dump selected stream missing \r\n");
			// exit();
//			mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_DumpSelectedStreamMissing);
//			exit_player(MSGTR_Exit_error);
		}
  // disable other streams:
		if(d_audio && d_audio!=ds) 
		{
			ds_free_packs(d_audio); 
			d_audio->id=-2; 
		}
		if(d_video && d_video!=ds) 
		{
			ds_free_packs(d_video); 
			d_video->id=-2; 
		}
		if(d_dvdsub && d_dvdsub!=ds) 
		{
			ds_free_packs(d_dvdsub); 
			d_dvdsub->id=-2; 
		}
  // let's dump it!
		pDumpStream=fopen(stream_dump_name,"wb");
		if(!pDumpStream)
		{
			message("Can't open the specified dumping file");
			// exit();
//	mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile);
//	exit_player(MSGTR_Exit_error);
		}
  
		while(!ds->eof)
		{
		//	unsigned char* start;
			in_size=ds_get_packet(ds,&start);
			if( (demuxer->file_format==DEMUXER_TYPE_AVI || demuxer->file_format==DEMUXER_TYPE_ASF || demuxer->file_format==DEMUXER_TYPE_MOV)
				&& stream_dump_type==2) 
					fwrite(&in_size,1,4,pDumpStream);
			if(in_size>0) 

⌨️ 快捷键说明

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