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

📄 mpeg2ply.c

📁 MPEG2视频编解码程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/* patched version from July 13, 1994 *//* mpeg2dec.c, main(), initialization, option processing                    *//* Copyright (C) 1994, MPEG Software Simulation Group. All Rights Reserved. *//* * Disclaimer of Warranty * * These software programs are available to the user without any license fee or * royalty on an "as is" basis.  The MPEG Software Simulation Group disclaims * any and all warranties, whether express, implied, or statuary, including any * implied warranties or merchantability or of fitness for a particular * purpose.  In no event shall the copyright-holder be liable for any * incidental, punitive, or consequential damages of any kind whatsoever * arising from the use of these programs. * * This disclaimer of warranty extends to the user of these programs and user's * customers, employees, agents, transferees, successors, and assigns. * * The MPEG Software Simulation Group does not represent or warrant that the * programs furnished hereunder are free of infringement of any third-party * patents. * * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware, * are subject to royalty fees to patent holders.  Many of these patents are * general enough such that they are unavoidable regardless of implementation * design. * */// MS Windows includes#include <windows.h>#include <commdlg.h>#include <assert.h>#include <io.h>#include "gui.h"#define	APPNAME         "Mpeg2Play"   /* The name of this application */#define BASEWINDOWTITLE "mpeg2play" /* The title bar text */#define MAXFILENAME     256  /* maximum length of file pathname */#define MAXCUSTFILTER   40   /* maximum size of custom filter buffer */// display related variables#define START	0#define READY   1#define PLAYING 2#define PAUSED  3#define FINISH  4#define STOP    5#include <stdio.h>#include <stdlib.h>#include <ctype.h>#include <fcntl.h>#define GLOBAL#include "config.h"#include "global.h"#include "mpeg2dec.h"// MS Windows related variablesLRESULT CALLBACK WndProc(             HWND   hWnd,       // window handle			 UINT   message,    // type of message			 WPARAM uParam,     // additional information			 LPARAM lParam);    // additional informationstatic HINSTANCE   hInst;          // current instancestatic HWND        ghWnd   =NULL;  // handle to main windowstatic char       *image   =NULL;static char        szFileName[MAXFILENAME]="";static unsigned short gusState = START;static int         nDitherType;static HDC         hDC;static HPALETTE    hpal,hPalPrev=NULL;static PBITMAPINFO pbmi    =NULL;int play_movie(void);extern int         __argc;extern char      **__argv;/* private prototypes */static void initdecoder _ANSI_ARGS_((void));static void options     _ANSI_ARGS_((int *argcp, char **argvp[]));static int  getval      _ANSI_ARGS_((char *argv[]));/* loop flag not implemented yet */static int loopflag;// MS Windows related functions//////////////////////////////////////////////////////////////////////////////* ********************************************************************************* * * WinMain: * **********************************************************************************///// yield function to simulate multitasking on MS Windows//static void myYield(void){    MSG         msg;    if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))    {	    TranslateMessage(&msg);// Translates virtual key codes	    DispatchMessage(&msg); // Dispatches message to window	}}//// initializations//static BOOL InitApplication(HINSTANCE hInstance){   WNDCLASS  wc;   // Fill in window class structure with parameters that describe the   // main window.   wc.style         = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;// Class style(s).   wc.lpfnWndProc   = (WNDPROC)WndProc;           // Window Procedure   wc.cbClsExtra    = 0;                          // No per-class extra data.   wc.cbWndExtra    = 0;                          // No per-window extra data.   wc.hInstance     = hInstance;                  // Owner of this class   wc.hIcon         = LoadIcon (hInstance, APPNAME); // Icon name from .RC   wc.hCursor       = LoadCursor(NULL, IDC_ARROW);// Cursor   wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);   // Default color   wc.lpszMenuName  = APPNAME;                    // Menu name from .RC   wc.lpszClassName = APPNAME;                    // Name to register as   // Register the window class and return success/failure code.   return (RegisterClass(&wc));}static BOOL InitInstance(HINSTANCE hInstance,int       nCmdShow){    // Save the instance handle in static variable, which will be used in    // many subsequence calls from this application to Windows.    hInst = hInstance; // Store instance handle in our global variable    // Create a main window for this application instance.    ghWnd = CreateWindow(             APPNAME,            // See RegisterClass() call.			 BASEWINDOWTITLE,    // Text for window title bar.			 WS_OVERLAPPEDWINDOW &			 ~WS_THICKFRAME &			 ~WS_MAXIMIZEBOX,    // Window style.			 CW_USEDEFAULT,			 0,			 CW_USEDEFAULT,			 0,                  // Use default positioning			 NULL,               // Overlapped windows have no parent.			 NULL,               // Use the window class menu.			 hInstance,          // This instance owns this window.			 NULL                // We don't use any data in our WM_CREATE	);    // If window could not be created, return "failure"    if (!ghWnd)       return (FALSE);    // Make the window visible; update its client area; and return "success"    ShowWindow(ghWnd, nCmdShow); // Show the window    UpdateWindow(ghWnd);         // Sends WM_PAINT message    return (TRUE);              // We succeeded...}//// prompts the user for the efile name//static BOOL AskUserFileName(char szFileName[],char szFileTitle[]){   /* new variables for common dialogs */   static char         szFilterSpec[]="MPEG Files\0*.MPG\0MPEG2 Video Files\0*.M2V\0MPEG1 Video Files\0*.M1V\0All Files (*.*)\0*.*\0";   static char         szInitialDirectory[MAXFILENAME]="";	  OPENFILENAME ofn;   memset(&ofn,0,sizeof(ofn));   /* fill in non-variant fields of OPENFILENAME struct. */   ofn.lStructSize       = sizeof(OPENFILENAME);   ofn.hwndOwner         = ghWnd;   ofn.lpstrFilter       = szFilterSpec;   ofn.lpstrCustomFilter = NULL;   ofn.nMaxCustFilter    = 0;   ofn.nFilterIndex      = 0;   ofn.lpstrFile         = szFileName;   ofn.nMaxFile          = MAXFILENAME;   if (!szInitialDirectory[0])      GetModuleFileName(hInst, szInitialDirectory, MAXFILENAME);   // strip the file name   *(LPSTR)strrchr(szInitialDirectory,'\\')=0;   ofn.lpstrInitialDir     = szInitialDirectory;   ofn.lpstrFileTitle      = szFileTitle;   ofn.nMaxFileTitle       = MAXFILENAME;   ofn.lpstrTitle          = NULL;   ofn.lpstrDefExt         = "MPG";   ofn.Flags               = 0;/* changed GetOpenFileName to GetFileName --Chad */   if (!GetOpenFileName((LPOPENFILENAME)&ofn))      return FALSE;   // save the current directory   lstrcpy(szInitialDirectory,szFileName);   return TRUE;}/********************************************************************************* * * About box ***********************************************************************************/BOOL CALLBACK About(HWND   hDlg,         // window handle of the dialog box		    UINT   message,      // type of message		    WPARAM uParam,       // message-specific information		    LPARAM lParam){   switch (message)   {      case WM_COMMAND:                     // message: received a command	 if (LOWORD(uParam) == IDOK || LOWORD(uParam) == IDCANCEL)	 {	    EndDialog(hDlg, TRUE);        // Exit the dialog	    return (TRUE);	 }	 break;   }   return (FALSE); // Didn't process the message   lParam; // This will prevent 'unused formal parameter' warnings}//// Main window procedure//LRESULT CALLBACK WndProc(HWND   hWnd,       // window handle			 UINT   message,    // type of message			 WPARAM uParam,     // additional information			 LPARAM lParam)     // additional information{   switch (message)   {      case WM_CLOSE:	    gusState = STOP;	    myYield();      return (DefWindowProc(hWnd, message, uParam, lParam));	    break;      case WM_DESTROY:  // message: window being destroyed	    gusState = STOP;	    myYield();      PostQuitMessage(0);      break;      case WM_COMMAND:  // message: command from application menu      {	int wmId, wmEvent;	wmId    = LOWORD(uParam);	wmEvent = HIWORD(uParam);	switch (wmId)	{       case IDM_OPEN:	   {	      char szWindowTitle[80];	      char szFileTitle[MAXFILENAME];	       // if something was playing, give a chance to stop.	      if (gusState > READY)	      {		    gusState = STOP;		    myYield();	      }	      EnableMenuItem(GetMenu(hWnd), IDM_PLAY, MF_GRAYED | MF_DISABLED);	      szFileName[0]=0;	      if (!AskUserFileName (szFileName,szFileTitle))		    return FALSE;	      lstrcpy(szWindowTitle, BASEWINDOWTITLE);	      lstrcat(szWindowTitle, " - ");	      lstrcat(szWindowTitle, szFileTitle);	      SetWindowText(hWnd, szFileTitle);	      // enable play menu	      EnableMenuItem(GetMenu(hWnd), IDM_PLAY, MF_ENABLED);	      gusState = READY;          break;	   }	   case IDM_PLAY:	      // disable play menu while playing	      EnableMenuItem(GetMenu(hWnd), IDM_STOP, MF_ENABLED);	      EnableMenuItem(GetMenu(hWnd), IDM_PLAY, MF_GRAYED | MF_DISABLED);	      // play the movie. It returns after the playing ended	      if (play_movie()<0)	      	error("error. Movie does not play.");	      // disable stop menu	      EnableMenuItem(GetMenu(hWnd), IDM_STOP, MF_GRAYED | MF_DISABLED);	      EnableMenuItem(GetMenu(hWnd), IDM_PLAY, MF_ENABLED);	      break;	   case IDM_STOP:	      gusState=STOP;	      // force a task switch to allow the decoder to see the stop command	      myYield();	      break;	   case IDM_EXIT:	      SendMessage(hWnd, WM_CLOSE, 0, 0l);	      break;	   case IDM_ABOUT:	   {	      FARPROC lpProcAbout;  // pointer to the "About" function	      lpProcAbout = MakeProcInstance((FARPROC)About, hInst);	      DialogBox(hInst,                 // current instance			"AboutBox",            // dlg resource to use			hWnd,                  // parent handle			(DLGPROC)lpProcAbout); // About() instance address	      FreeProcInstance(lpProcAbout);	      break;	   }	   case IDM_DISPLAY8:	   case IDM_DISPLAY24:	      // reset the display.	      // It will be reinitialized the first time it will be called	      switch (outtype)	      {		 case T_X11:		   if (nDitherType==8)		      CheckMenuItem(GetMenu(hWnd), IDM_DISPLAY8, MF_UNCHECKED);		   else		      CheckMenuItem(GetMenu(hWnd), IDM_DISPLAY24, MF_UNCHECKED);		   break;	      }	      switch (wmId)	      {		 case IDM_DISPLAY8:		    CheckMenuItem(GetMenu(hWnd), IDM_DISPLAY8, MF_CHECKED);		    outtype=T_X11;		    nDitherType=8;		    break;		 case IDM_DISPLAY24:		    CheckMenuItem(GetMenu(hWnd), IDM_DISPLAY24, MF_CHECKED);		    outtype=T_X11;		    nDitherType=24;		    break;	      }	}	break;      }      default:          // Passes it on if unproccessed	return (DefWindowProc(hWnd, message, uParam, lParam));   }   return (0);}//// program entry point//int APIENTRY WinMain(HINSTANCE   hInstance,		     HINSTANCE   hPrevInstance,		     LPSTR       lpCmdLine,		     int         nCmdShow){    MSG msg;    if (!hPrevInstance)       // Other instances of app running?	if (!InitApplication(hInstance))	   // Initialize shared things	   return (FALSE);     // Exits if unable to initialize    /* Perform initializations that apply to a specific instance */    if (!InitInstance(hInstance, nCmdShow))       return (FALSE);    // start-up initialization    verbose = 0;    outtype = T_X11;    hDC     = GetDC(ghWnd);    nDitherType=8;    sflag = 0;    ld = &base; /* select base layer context *//*    options(&__argc,&__argv);  */    /* Acquire and dispatch messages until a WM_QUIT message is received. */    while (GetMessage(&msg, // message structure		      NULL,   // handle of window receiving the message		      0,      // lowest message to examine		      0))     // highest message to examine    {	TranslateMessage(&msg);// Translates virtual key codes	DispatchMessage(&msg); // Dispatches message to window    }    return (msg.wParam); // Returns the value from PostQuitMessage

⌨️ 快捷键说明

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