📄 vesavcd.c
字号:
int Len;
int i;
Len=lstrlen(FileName);
if(*(FileName+Len-4)!='.') return 0; //FALSE
for(i=0;i<3;i++) ExtName[i]=(*(FileName+Len-3+i)|0x20);//To Lower
ExtName[3]=0;
if(ExtName[0]=='v' && ExtName[1]=='c' && ExtName[2]=='d' ) return 4;//VCD
if(ExtName[0]=='d' && ExtName[1]=='a' && ExtName[2]=='t' ) return 3;//VCD
if(ExtName[0]=='m' && ExtName[1]=='p' && ExtName[2]=='g' ) return 2;//MPG
if(ExtName[0]=='m' && ExtName[1]=='p' && ExtName[2]=='v' ) return 2;//MPV
if(ExtName[0]=='v' && ExtName[1]=='b' && ExtName[2]=='s' ) return 2;//VBS
return CheckExtName(ExtName,VideoDriver);
}
static int OnlyCheckExtName(char *ExtName,char *VideoDriver)
{
int Ret;
char Buffer[80];
GetProfileString("mci extensions",ExtName,"NOT",Buffer,sizeof(Buffer));
if(Buffer[0]=='N' && Buffer[1]=='O' && Buffer[2]=='T') return 0;//FALSE
Ret=lstrcmpi(Buffer,VideoDriver);
if(Ret==0) Ret=1;
else Ret=0;
return Ret;
}
static int OnlyCheckFileForDriver(char *FileName,char *VideoDriver)
{
char ExtName[4];
int Len;
int i;
Len=lstrlen(FileName);
if(*(FileName+Len-4)!='.') return 0; //FALSE
for(i=0;i<3;i++) ExtName[i]=(*(FileName+Len-3+i)|0x20);//To Lower
ExtName[3]=0;
return OnlyCheckExtName(ExtName,VideoDriver);
}
//////////////////////////////////////
LONG Length=0;
int CurVideoType=0;
HWND VideoWindow; //Video output Window.
static void ResetPalette(void)
{
if(VESAColor!=8) return;
if(CurVideoType)SetAllDAC();
}
//////////////////////////////////////
char VideoDriver[40];
int PASCAL FAR OpenVideo(HWND hwnd,int VideoNumber)
{
DWORD Ret;
if(videoID!=-1) return 1;
Ret=CheckFileForDriver(VideoName[VideoNumber],VideoDriver);
if(Ret==0) return 0; //Not MCI Type.
if(Ret==3||Ret==2||Ret==4)
{
if(OtherDecoder)
{//Check if the driver valid
int Val;
char StateBuffer[16];
Val=GetPrivateProfileString("mci",OtherDecoderName,"",StateBuffer,sizeof(StateBuffer),"system.ini");
if(Val==0)
{//The driver invalid,can not use.
MessageBox(NULL,"The Driver your selected is not present on [MCI].","No driver",MB_OK);
OtherDecoder=0;
}
else {//Check if the driver can play this file.
//Val=OnlyCheckFileForDriver(VideoName[VideoNumber],OtherDecoderName);
//if(Val==0)
// {
// MessageBox(NULL,"The Driver your selected can't play MPEG format.","Not Match",MB_OK);
// OtherDecoder=0;
// }
}
}
if(OtherDecoder)
{//Use the Other driver
Ret=VideoOpen(VideoName[VideoNumber],OtherDecoderName);//Open MCI
CurVideoType=0;
}
else {//Use internal driver
AddSTHMPEGTypeMCI(); //Install MCI Interface
TurnOffEscape(); //Off Old Escape on my Escape
Ret=VideoOpen(VideoName[VideoNumber],"STHMPEG");//Open STHMPEG
TurnOnEscape(); //Restore Old Escape after video open.
DeleteSTHMPEGTypeMCI(); //Delete MCI Interface
CurVideoType=1;
}
}
else {
Ret=VideoOpen(VideoName[VideoNumber],VideoDriver);//Open MCI
CurVideoType=0;
}
SetVideoTimeFormat(videoID,hwnd,MCI_FORMAT_MILLISECONDS);
if(HIWORD(Ret)) //Error
{
DisplayErrorMessage(Ret,hwnd);
Length=VideoNumber=0; //No Disk on it
videoID=-1;
return 0;
}
////////////
videoID=Ret; //Video Handle ID;
/////////////
return 1;
}
/////////////////////////////////////
int PlayType=0;
int CurFileNum=0;
long FAR PASCAL WndProc(HWND hwnd,WORD message,WORD wParam,LONG lParam);
HWND MainWindow; //Main Windows
HWND ShowVideo=0;
HBITMAP VCDFACE;
HANDLE hInst;
static DWORD ByteToTimeLength(int No)
{
DWORD Size;
DWORD Time;
int T,M,S;
HFILE hFile;
hFile=_lopen(VideoName[No],READ);
Size=_llseek(hFile,0,2);
_lclose(hFile);
Size/=2048;
T=Size/270000L;
M=(Size-T*270000L)/4500L;
S=(Size-T*270000L-M*4500L)/75;
Time=T*3600000L;
Time+=M*60000L;
Time+=S*1000L;
return Time;
}
static DWORD VCDByteToTimeLength(int No)
{ //*.VCD file
DWORD Size;
DWORD Time;
int T,M,S;
HFILE hFile;
hFile=_lopen(VideoName[No],READ);
Size=_llseek(hFile,0,2);
_lclose(hFile);
Size/=2324;
T=Size/270000L;
M=(Size-T*270000L)/4500L;
S=(Size-T*270000L-M*4500L)/75;
Time=T*3600000L;
Time+=M*60000L;
Time+=S*1000L;
return Time;
}
void PASCAL FAR InitVideoState(void)
{// Get All length;
int i;
int Type;
Length=0;
for(i=(VideoNumber-1);i>=0;i--)
{// Fram End to Start open
Type=CheckFileForDriver(VideoName[i],VideoDriver);
if(Type==1)//Not VCD File,other MCI File.
{
if(CurFileNum!=i || videoID==-1)
{
if(videoID!=-1)
{
CloseVideo(videoID,MainWindow);
videoID=-1;
}
OpenVideo(MainWindow,i);
CurFileNum=i;
}
VideoLength[i]=GetVideoLength(videoID,MainWindow);
}
else {//VCD type files.
if(Type==4) VideoLength[i]=VCDByteToTimeLength(i);
else VideoLength[i]=ByteToTimeLength(i);
}
Length+=VideoLength[i];
}
// had open the first.
if(videoID!=-1 && CurFileNum!=0)
{
CloseVideo(videoID,MainWindow);
videoID=-1;
OpenVideo(MainWindow,0);
CurFileNum=0;
}
}
static void SeekAllVideoTo(DWORD Pos)
{
int i;
int SeekNum=0;
DWORD LocalPos=Pos;
for(i=0;i<VideoNumber;i++)
{
if( LocalPos<=VideoLength[i] )
{
SeekNum=i;
break;
}
LocalPos-=VideoLength[i];
}
if(videoID!=-1 && CurFileNum!=SeekNum)
{ //May Close Current & ReOpen.
CloseVideo(videoID,MainWindow);
videoID=-1;
CurFileNum=SeekNum;
OpenVideo(MainWindow,SeekNum);
}
if(LocalPos==0)
{
SeekVideoToStart(videoID,MainWindow);
return;
}
if(LocalPos==VideoLength[SeekNum])
{
SeekVideoToEnd(videoID,MainWindow);
return;
}
SeekVideoTo(videoID,MainWindow,LocalPos);
}
DWORD PASCAL FAR GetAllVideoPosition(void)
{
int i;
DWORD CurrentPos;
CurrentPos=GetVideoCurrentPosition(videoID,MainWindow);
for(i=0;i<CurFileNum;i++) // Counting Pos
CurrentPos+=VideoLength[i];
return CurrentPos;
}
////////////////// Test frames / sec //////////
void PASCAL FAR SetProfileRate(int V)
{
GetCWD(Buffer,sizeof(Buffer));
lstrcat(Buffer,"\\STHMPEG.INI");
WritePrivateProfileString("STHVIDEO","Skip",V?"1":"0",Buffer);
}
int Line240Port;
static void SetDoubleLine(void)
{
int Port;
//Set 640x240 mode
outportb(0x3D4,9);
Line240Port=Port=inportb(0x3D5);
if((Port&1)) Port|=0x80;
else Port|=1;
outportb(0x3D5,Port);
}
static void RestoreLine(void)
{
outportb(0x3D4,9);
outportb(0x3D5,Line240Port);
InvalidateRect(NULL,NULL,0);
}
int UseDCI=0;
int DCIPlay=0;
extern DCIOFFSCREEN DCISurfaceScreen; //Offscreen or primary
extern RECT VideoRc;
RGNDATA RgnData;
RECT SrcRect={0,0,352,288};
///////////////////////////////////////
static void StartPlayScreen(void)
{
if(!Start)
{
Start=1;
if(DCIPlay)
{
if(DCIType==1 && (VESAColor==64||VESAColor==32))
SetDoubleLine();
if(DCIType==2) //YUV -> RGB
{
////////// Set Cliplist //////////
RgnData.rdh.dwSize=0x20;
RgnData.rdh.rcBound.left=VideoRc.left;
RgnData.rdh.rcBound.top=VideoRc.top;
RgnData.rdh.rcBound.right=VideoRc.right;
RgnData.rdh.rcBound.bottom=VideoRc.bottom;
}
}
else {
Set320x20064KC();
_AX=0x4000; //OS/2 call about display
geninterrupt(0x2F);
}
}
}
static void EndPlayScreen(void)
{
if(Start)
{
Start=0;
if(DCIPlay)
{
if(DCIType==1 && (VESAColor==64||VESAColor==32))
RestoreLine();
if(DCIType==2) //YUV -> RGB
{//Repaint windows
InvalidateRect(NULL,NULL,0);
}
}
else {
_AX=0x4007; //OS/2 call about display
geninterrupt(0x2F);
NormalWindow(); //Restore video mode
}
}
}
static DWORD TestVideoSpeed(void)
{
DWORD StartTime=1,EndTime=0;
DWORD Ret=1;
MCI_ANIM_PLAY_PARMS mciplay;
MemSet((LPSTR)&mciplay,0,sizeof(mciplay));
mciplay.dwCallback=(DWORD)MainWindow;
mciplay.dwFrom=0;
mciplay.dwTo=120;
if(VideoNumber!=0)
{
// SetProfileRate(0);
// if(videoID!=-1) CloseVideo(videoID,MainWindow);
// videoID=-1;
// OpenVideo(MainWindow,CurFileNum);
if(videoID==-1) OpenVideo(MainWindow,CurFileNum);
SetVideoTimeFormat(videoID,MainWindow,MCI_FORMAT_FRAMES);
SeekVideoToStart(videoID,MainWindow); //Ready to test
if(CurVideoType)
{
SetVideoWindow(videoID,VideoWindow,MainWindow);
ShowWindow(VideoWindow,SW_SHOW);
}
Ret=ByteToTimeLength(CurFileNum);
if(Ret<120) mciplay.dwTo=Ret;
if(CurVideoType)
{
SetVideoWindow(videoID,VideoWindow,MainWindow);
ShowWindow(VideoWindow,SW_SHOW);
StartPlayScreen();
}
DisplayVideo=1;
if(VESAColor==8) ResetPalette();
StartTime=timeGetTime();
Ret=mciSendCommand(videoID,MCI_PLAY,MCI_WAIT|
MCI_FROM|MCI_TO,(DWORD)(LPVOID)&mciplay);
EndTime=timeGetTime();
DisplayVideo=0;
EndPlayScreen();
ShowWindow(VideoWindow,SW_HIDE);
// SetProfileRate(1);
// CloseVideo(videoID,MainWindow);
// videoID=-1;
// OpenVideo(MainWindow,CurFileNum);
if(CurVideoType)SetVideoWindow(videoID,ShowVideo,MainWindow);
SetVideoTimeFormat(videoID,MainWindow,MCI_FORMAT_MILLISECONDS);
}
if(Ret!=0)
{
return (-1); //FALSE HIWORD Not Zero
}
EndTime-=StartTime;if(EndTime==0) EndTime=1;
Ret=(mciplay.dwTo==120?120:mciplay.dwTo);
Ret*=10000;
Ret/=EndTime;
return Ret+26; //Always is +16;
}
//////////////// AVI Profile ///////////////
char AVIBuffer[30];
int AVIZoom;
void PASCAL FAR SetAVITypeZoomBy2AndWindow(void)
{
/* AVIZoom=GetProfileInt("MCIAVI","ZoomBy2",1);
GetProfileString("MCIAVI","DefaultVideo","Window",AVIBuffer,sizeof(AVIBuffer));
/////// Set AVI Play method /////////
WriteProfileString("MCIAVI","DefaultVideo","Window");
*/// WriteProfileString("MCIAVI","ZoomBy2","1");
}
void PASCAL FAR RestoreAVIZoomBy2AndWindow(void)
{
/* WriteProfileString("MCIAVI","DefaultVideo",AVIBuffer);
*/// WriteProfileString("MCIAVI","ZoomBy2",AVIZoom?"1":"0");
}
////////////////////////////////////////////
HINSTANCE AcceleratorInst=0;
int PASCAL FAR LoadDriverVideoAndAudio(void)
{
HFILE hFile;
FFBLK FindBlk;
int done;
done=FindFirst("SthAccel.DLL",&FindBlk,0);
if(done!=0) return 0;
AcceleratorInst=LoadLibrary("SthAccel.DLL");
if(AcceleratorInst<HINSTANCE_ERROR)
{
if(Chinese) MessageBox(NULL,"软 VCD 系统不完整 !","错误",MB_OK);
else MessageBox(NULL,"Soft VCD System not complete !","Error",MB_OK);
return 0;
}
return 1;
}
void PASCAL FAR FreeDriverVideoAndAudio(void)
{
if(AcceleratorInst>HINSTANCE_ERROR)
{
FreeLibrary(AcceleratorInst);
}
AcceleratorInst=0;
}
///////////////////////////////////////////
int ListAllFile=0;
extern int SampleRate; //Rate 0=44.1K 1=22.05K 2=11.025K
extern int DecodeMode; //above 486-66 all had FPU,So use Float
extern int CheckTime;
//////////////Create INI File///////////////
void PASCAL FAR CreateINIFile(void)
{
char StateBuffer[8];
GetCWD(Buffer,sizeof(Buffer));
lstrcat(Buffer,"\\STHMPEG.INI");
////////////// Driver INI ////////
WritePrivateProfileString("STHVIDEO","Skip","1",Buffer);
WritePrivateProfileString("STHVIDEO","Sizes","1",Buffer);
WritePrivateProfileString("STHVIDEO","SthAudio","0",Buffer);
WritePrivateProfileString("STHVIDEO","DCI","1",Buffer);
WritePrivateProfileString("STHVIDEO","Full","1",Buffer);
WritePrivateProfileString("STHVIDEO","AudioKHz","2",Buffer);
WritePrivateProfileString("STHVIDEO","Stereo","1",Buffer);
///////////////// My Profile ///////////
SampleRate=GetPrivateProfileString("SthAV","AudioSamples","",StateBuffer,sizeof(StateBuffer),Buffer);
if(SampleRate==0)//Save Supper VESA State
{
if(GetCPUType()>486)
{//Pentium and later
WritePrivateProfileString("SthAV","AudioSamples","22050Hz",Buffer);
StateBuffer[0]='2';
}
else {//586
WritePrivateProfileString("SthAV","AudioSamples","11205Hz",Buffer);
StateBuffer[0]='1';
}
}
switch(StateBuffer[0])
{
case '4': SampleRate=0;break;//0:44100Hz Audio sample rate used with different CPU
case '2': SampleRate=1;break;//1:22050Hz
case '1':
default : SampleRate=2;break;//2:11025Hz
}
////////////////////
SupperVESAState=GetPrivateProfileString("SthAV","SthAudio","",StateBuffer,sizeof(StateBuffer),Buffer);
if(SupperVESAState==0||(StateBuffer[0]|0x20)=='s')//Save Supper VESA State
{
if(GetCPUType()>486)
{//Pentium and later
WritePrivateProfileString("SthAV","SthAudio","FloatPoint",Buffer);
StateBuffer[0]='F';
}
else {//486
WritePrivateProfileString("SthAV","SthAudio","QuickDecode",Buffer);
StateBuffer[0]='Q';
}
}
StateBuffer[0]|=0x20;
if(StateBuffer[0]=='f') DecodeMode=1; //Float
if(StateBuffer[0]=='i') DecodeMode=0; //Intgeter
if(StateBuffer[0]=='m') DecodeMode=2; //Mix
if(StateBuffer[0]=='q') DecodeMode=3; //Quick
SupperVESAState=GetPrivateProfileString("SthAV","SupperVESAStateSave","",StateBuffer,sizeof(StateBuffer),Buffer);
if(SupperVESAState==0)//Save Supper VESA State
WritePrivateProfileString("SthAV","SupperVESAStateSave","1",Buffer);
SupperVESAState=GetPrivateProfileInt("SthAV","SupperVESAStateSave",1,Buffer);
SupperVESAState<<=3; // Bit 3
///////////////////////////////////
ListAllFile=GetPrivateProfileString("SthAV","ListAllFile","",StateBuffer,sizeof(StateBuffer),Buffer);
if(ListAllFile==0)//Open Dialog list all file
WritePrivateProfileString("SthAV","ListAllFile","0",Buffer);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -