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

📄 main.c

📁 MPEG2 PLAYER in linux
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * main.c -- * *      Main procedure * *//* * Copyright (c) 1995 The Regents of the University of California. * All rights reserved. *  * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without written agreement is * hereby granted, provided that the above copyright notice and the following * two paragraphs appear in all copies of this software. *  * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *  * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. *//* * Portions of this software Copyright (c) 1995 Brown University. * All rights reserved. *  * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without written agreement * is hereby granted, provided that the above copyright notice and the * following two paragraphs appear in all copies of this software. *  * IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF BROWN * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *  * BROWN UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" * BASIS, AND BROWN UNIVERSITY HAS NO OBLIGATION TO PROVIDE MAINTENANCE, * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. */#include "video.h"#include "proto.h"#ifndef NOCONTROLS#include "ctrlbar.h"#endif#include <math.h>#include <sys/types.h>#include <signal.h>#include <netinet/in.h>#include <string.h> /* strtok */#include "util.h"#include "dither.h"/*   Changes to make the code reentrant:     Got rid of setjmp, longjmp     deglobalized: EOF_flag, FilmState, curVidStream, bitOffset, bitLength,     bitBuffer, sys_layer, input, seekValue, window, X Windows globals (to     xinfo), curBits, ditherType, matched_depth, totNumFrames, realTimeStart   Additional changes:     Ability to play >1 movie (w/out CONTROLS)     Make sure we do a full frame for each movie     DISABLE_DITHER #ifdef to avoid compiling dithering code     Changes to deal with non-MPEG streams     Now deals with NO_DITHER, PPM_DITHER and noDisplayFlag==1     CONTROLS version now can deal with >1 movie   -lsh@cs.brown.edu (Loring Holden) *//* Make Ordered be the default dither */#define DEFAULT_ORDERED_DITHER/* Define buffer length. */#define BUF_LENGTH 80000/* Function return type declarations */void usage();/* Forward declaration of functions in this file. */#ifndef P# ifdef __STDC__#   define        P(s) s# else#   define P(s) ()# endif#endif #ifndef SIG_ONE_PARAMvoid int_handler P((void ));void bad_handler P((void ));#elsevoid int_handler P((int signum));void bad_handler P((int signum));#endifvoid usage P((char *s ));#ifdef DCPREC/* Declaration of global variable to hold DC precision */int dcprec = 0;#endif/* Global file pointer to incoming data. */FILE **input;char **inputName;/* Loop flag. */int loopFlag = 0;/* Shared memory flag. */int shmemFlag = 0;/* Quiet flag. */#ifdef QUIETint quietFlag = 1;#elseint quietFlag = 0;#endif/* "Press return" flag, requires return for each new frame */int requireKeypressFlag = 0;/* Display image on screen? */int noDisplayFlag = 0;/* Seek Value.    0 means do not seek.   N (N>0) means seek to N after the header is parsed   N (N<0) means the seek has beeen done to offset N*//* Framerate, -1: specified in stream (default)               0: as fast as possible               N (N>0): N frames/sec                 */int framerate = -1;/* Flags/values to control Arbitrary start/stop frames. */int partialFlag = 0, startFrame = -1, endFrame = -1;/* Flag for gamma correction */int gammaCorrectFlag = 0;double gammaCorrect = 1.0;/* Flag for chroma correction */int chromaCorrectFlag = 0;double chromaCorrect = 1.0;/* Flag for high quality at the expense of speed */#ifdef QUALITYint qualityFlag = 1;#elseint qualityFlag = 0;#endif/* no further error messages */static BOOLEAN exiting=FALSE;/* global variable for interrupt handlers */VidStream **curVidStream;/* Brown - put X specific variables in xinfo struct */#define NUMMOVIES 15XInfo xinfo[NUMMOVIES];int numInput=0;/* #define Color16DitherImage ColorDitherImage #define Color32DitherImage ColorDitherImage*//* *-------------------------------------------------------------- * * int_handler -- * *        Handles Cntl-C interupts.. *      (two different ones for different OSes) * Results:    None. * Side effects:   None. *-------------------------------------------------------------- */#ifndef SIG_ONE_PARAMvoidint_handler()#elsevoidint_handler(signum)int signum;#endif{  int i,displayClosed=0;  if (!quietFlag && !exiting) {    fprintf(stderr, "Interrupted!\n");  }  exiting = TRUE;  for (i = 0;  i < numInput;  i++) {    if (curVidStream[i] != NULL)      DestroyVidStream(curVidStream[i], &xinfo[i]);    if ((xinfo[i].display != NULL) && !displayClosed) {      XCloseDisplay(xinfo[i].display);      displayClosed=1;    }  }  exit(1);}/* *-------------------------------------------------------------- * * bad_handler -- * *        Handles Seg faults/bus errors... *      (two different ones for different OSes) * Results:    None. * Side effects:   None. * *-------------------------------------------------------------- */#ifndef SIG_ONE_PARAMvoid  bad_handler()#elsevoid  bad_handler(signum)int signum;#endif{  if (!exiting) {    fprintf(stderr, "Bad MPEG?  Giving up.\ntry 'mpeg_stat -verify' to see if the stream is valid.\n");  }  exit(0);}/* *-------------------------------------------------------------- * * getposition -- * *-------------------------------------------------------------- */void getposition(arg, xpos, ypos)char *arg;int *xpos, *ypos;{  char *pos;  if ((pos = strtok(arg, "+-")) != NULL) {    *xpos = atoi(pos);    if ((pos = strtok(NULL, "+-")) != NULL) {      *ypos = atoi(pos);      return;    }  }  if (!quietFlag) {    fprintf(stderr, "Illegal position... Warning: argument ignored! (-position +x+y)\n");  }  return;}/* *-------------------------------------------------------------- * * main -- * *        Parses command line, starts decoding and displaying. * * Results: *        None. * * Side effects: *        None. * *-------------------------------------------------------------- */#ifndef __STDC__void#endifmain(argc, argv)     int argc;     char **argv;{  char *name;  static VidStream **theStream;  int mark;  int i, mult, largy, y, lastStream, firstStream=-1, workToDo=TRUE;  int doDisplay=0; /* Current movie is displaying on screen */   long seekValue=0;/* holds value before it is put in vid_stream */  int  owncmFlag=0;   /* holds value before it is put in xinfo  */  BOOLEAN firstRead=FALSE;  int ppm_width = -1,  ppm_height = -1, ppm_modulus = -1;  mark = 1;  argc--;  input = (FILE **) malloc(NUMMOVIES*sizeof(FILE *));  inputName = (char **) malloc(NUMMOVIES *sizeof(char *));  theStream = (VidStream **) malloc(NUMMOVIES *sizeof(VidStream *));  curVidStream = (VidStream **) malloc(NUMMOVIES *sizeof(VidStream *));  for (i = 0; i < NUMMOVIES; i++) {     input[i] = NULL;     inputName[i] = "stdin";     theStream[i] = NULL;     curVidStream[i] = NULL;     xinfo[i].hints.x = -1;     xinfo[i].hints.y = -1;     xinfo[i].ExistingWindow = 0;  }  name = (char *) "";#ifndef DISABLE_DITHER#ifndef DEFAULT_ORDERED_DITHER  xinfo[0].ditherType = FULL_COLOR_DITHER;#else  xinfo[0].ditherType = ORDERED_DITHER;#endif#endif  LUM_RANGE = 8;  CR_RANGE = CB_RANGE = 4;  noDisplayFlag = 0;#ifdef SH_MEM  shmemFlag = 1;#endif  while (argc) {    if (strcmp(argv[mark], "-nop") == 0) {      SetPFlag(TRUE);      SetBFlag(TRUE);      argc--; mark++;    } else if (strcmp(argv[mark], "-nob") == 0) {      SetBFlag(TRUE);      argc--; mark++;    } else if (strcmp(argv[mark], "-display") == 0) {      name = argv[++mark];      argc -= 2; mark++;    } else if (strcmp(argv[mark], "-position") == 0) {      argc--; mark++;      getposition(argv[mark], &xinfo[numInput].hints.x, &xinfo[numInput].hints.y);      argc--; mark++;    } else if (strcmp(argv[mark], "-xid") == 0) {      xinfo[numInput].ExistingWindow = atoi(argv[++mark]);      argc -= 2; mark++;    } else if (strcmp(argv[mark], "-start") == 0) {      if (argc < 2) usage(argv[0]);      partialFlag = TRUE;      if (seekValue != 0) {	fprintf(stderr, "Cannot use -start with -seek (ignored)\n");      } else {	startFrame = atoi(argv[++mark]);      }      argc -= 2; mark++;    } else if (strcmp(argv[mark], "-seek") == 0) {      if (argc < 2) usage(argv[0]);      seekValue = atoi(argv[++mark]);      if (startFrame != -1) startFrame = 0;      argc -= 2; mark++;    } else if (strcmp(argv[mark], "-end") == 0) {      if (argc < 2) usage(argv[0]);      endFrame = atoi(argv[++mark]);      partialFlag = TRUE;      argc -= 2; mark++;    } else if (strcmp(argv[mark], "-gamma") == 0) {      if (argc < 2) usage(argv[0]);      gammaCorrectFlag = 1;      sscanf(argv[++mark], "%lf", &gammaCorrect);      if (gammaCorrect <= 0.0) {        fprintf(stderr, "ERROR: Gamma correction must be greater than 0.\n");        gammaCorrect = 1.0;      }      if (!quietFlag) {        printf("Gamma Correction set to %4.2f.\n", gammaCorrect);      }      argc -= 2; mark++;    } else if (strcmp(argv[mark], "-chroma") == 0) {      if (argc < 2) usage(argv[0]);      chromaCorrectFlag = 1;      sscanf(argv[++mark], "%lf", &chromaCorrect);      if (chromaCorrect <= 0.0) {        fprintf(stderr, "ERROR: Chroma correction must be greater than 0.\n");        chromaCorrect = 1.0;      }      if (!quietFlag) {        printf("Chroma Correction set to %4.2f.\n",chromaCorrect);      }

⌨️ 快捷键说明

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