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

📄 main.c

📁 MPEG2 PLAYER in linux
💻 C
📖 第 1 页 / 共 3 页
字号:
    InitDisplay(name, &xinfo[0]);    InitOrdered2Dither();    break;  case MBORDERED_DITHER:    InitColor();    InitDisplay(name, &xinfo[0]);    InitMBOrderedDither();    break;  }#endif#ifdef SH_MEM    if (shmemFlag && (xinfo[0].display != NULL)) {      if (!XShmQueryExtension(xinfo[0].display)) {        shmemFlag = 0;        if (!quietFlag) {          fprintf(stderr, "Shared memory not supported\n");          fprintf(stderr, "Reverting to normal Xlib.\n");        }      }    }#endif  InitCrop();  y=300;  largy=0;  for (i=0;i<numInput;i++) {    doDisplay=!noDisplayFlag;#ifndef DISABLE_DITHER    if ((xinfo[i].ditherType == NO_DITHER) ||        (xinfo[i].ditherType == PPM_DITHER))       doDisplay = FALSE;#endif    lastStream = i-1;    while ((lastStream>=0) && (theStream[lastStream]==NULL)) {       lastStream--;    }    if ((i != 0) && doDisplay) {       if (lastStream > -1) {         xinfo[i].hints.x =            xinfo[lastStream].hints.x+10 + theStream[lastStream]->h_size;         if (theStream[lastStream]->v_size>largy)	   largy = theStream[lastStream]->v_size;         if (xinfo[i].hints.x > DisplayWidth(xinfo[firstStream].display,			       XDefaultScreen(xinfo[firstStream].display)) -80) {		y += largy + 30;		largy = 0;		xinfo[i].hints.x = 0;         }         xinfo[i].hints.y = y;         xinfo[i].visual = xinfo[firstStream].visual;         xinfo[i].cmap = xinfo[firstStream].cmap;         xinfo[i].gc = xinfo[firstStream].gc;       }       xinfo[i].display = xinfo[0].display;       xinfo[i].depth = xinfo[0].depth;       xinfo[i].ditherType = xinfo[0].ditherType;       InitColorDisplay(name, &xinfo[i]);    }    curVidStream[i] = theStream[i] = NewVidStream((unsigned int) BUF_LENGTH);    theStream[i]->ppm_width = ppm_width;    theStream[i]->ppm_height = ppm_height;    theStream[i]->ppm_modulus = ppm_modulus;    theStream[i]->input = input[i];    theStream[i]->seekValue = seekValue;    theStream[i]->filename = inputName[i];    theStream[i]->ditherType = xinfo[i].ditherType;    theStream[i]->matched_depth = xinfo[i].depth;    mark = quietFlag;    quietFlag=1;    if (mpegVidRsrc(0, theStream[i], 1, &xinfo[i])==NULL) {       if (doDisplay) {         XDestroyWindow(xinfo[i].display, xinfo[i].window);       }	        /* stream has already been destroyed */       curVidStream[i] = theStream[i]=NULL;       fprintf(stderr, "Skipping movie %d, \"%s\" - not an MPEG stream\n",	  i, inputName[i]);       fclose(input[i]);       if (i+1 == numInput) numInput--;    } else if (firstStream == -1) firstStream=i;    quietFlag = mark;#ifndef DISABLE_DITHER    if (IS_2x2_DITHER(xinfo[i].ditherType)) {      mult = 2;    }    else {      mult = 1;      }#else    mult = 1;#endif    if (doDisplay && (theStream[i]!=NULL)) {      ResizeDisplay((unsigned int) theStream[i]->h_size* mult,                    (unsigned int) theStream[i]->v_size* mult,		  &xinfo[i]);    }  }  if (numInput > 1) {    loopFlag = TRUE;    framerate = 0;  }#ifndef NOCONTROLS  if (xinfo[0].display == NULL) {    ControlShow = CTRLBAR_NONE;  /* no display => no controls */  }  if (ControlShow != CTRLBAR_NONE) {    MakeControlBar(&xinfo[0]);    ControlBar(theStream, xinfo, numInput);  }  for (i = 0; i < numInput; i++) {     if (theStream[i] != NULL) theStream[i]->realTimeStart = ReadSysClock();  }#else  /* Start time for each movie - do after windows are mapped */  for (i = 0; i < numInput; i++) {     if (theStream[i] != NULL) theStream[i]->realTimeStart = ReadSysClock();  }#endif#ifndef NOCONTROLS  if (ControlShow == CTRLBAR_NONE) {    while (TRUE) {      for (i=0;i < numInput; i++) {        while (theStream[i]->film_has_ended != TRUE) {          mpegVidRsrc(0, theStream[i], 0, &xinfo[i]);        }        if (loopFlag) {          rewind(theStream[i]->input);           ResetVidStream(theStream[i]); /* Reinitialize vid_stream pointers */          if (theStream[i]->seekValue < 0) {            theStream[i]->seekValue = 0 - theStream[i]->seekValue;          }          mpegVidRsrc(0, theStream[i], 1, &xinfo[i]); /* Process start codes */        } else if (doDisplay) break;        else goto done;      }     }   }  else {    ControlLoop(theStream, xinfo, numInput);  }done:  mark=0;  for (i=0;i < numInput; i++) {     DestroyVidStream(theStream[i], &xinfo[i]);    if ((xinfo[i].display != NULL) && !mark) {      XCloseDisplay(xinfo[i].display);      mark=1;    }  }  exit(0);#else /* !NOCONTROLS */  if (!numInput) {     fprintf(stderr, "Must enter MPEG file to play\n");     usage(argv[0]);  }  while (workToDo) {     workToDo = FALSE;     for (i = 0; i < numInput; i++) {       if (theStream[i] != NULL) {         mark = theStream[i]->totNumFrames;         /* make sure we do a whole frame */         while (mark == theStream[i]->totNumFrames) {             mpegVidRsrc(0, theStream[i], 0, &xinfo[i]);         }         if (theStream[i]->film_has_ended) {           if (loopFlag) {             clear_data_stream(theStream[i]);             /* Reinitialize vid_stream pointers */             ResetVidStream(theStream[i]);             rewind(theStream[i]->input);             if (theStream[i]->seekValue < 0) {               theStream[i]->seekValue = 0 - theStream[i]->seekValue;             }#ifdef ANALYSIS              init_stats();#endif             /* Process start codes */             if (mpegVidRsrc(0, theStream[i], 1, &xinfo[i])==NULL) {	       /* print something sensible here,		  but we only get here if the file is changed while we		  are decoding, right?		*/	     }           } /* loopFlag */	 }   /* film_has_ended */         workToDo = workToDo || (!theStream[i]->film_has_ended);       } /* theStream[i]!=NULL */     }   /* for (i.. */  }      /* while workToDo */  sleep(1000);    /* freeze on the last frame */#endif /* NOCONTROLS */} /* *-------------------------------------------------------------- * * usage -- * *        Print mpeg_play usage * * Results: *        None. * * Side effects: *        exits with a return value -1 * *-------------------------------------------------------------- */voidusage(s)char *s;        /* program name */{    fprintf(stderr, "Usage:\n");#ifndef NOCONTROLS    fprintf(stderr, "mpeg_play [options] [filename]\n");#else    fprintf(stderr, "mpeg_play [[options] [filename]]  [[options] [filename]]  [..]\n");#endif    fprintf(stderr, "Options :\n");   fprintf(stderr, "      [-display X_display]\t[-no_display]\n");#ifndef DISABLE_DITHER    fprintf(stderr, "      [-dither {ordered|ordered2|mbordered|fs4|fs2|fs2fast|hybrid|\n");    fprintf(stderr, "                hybrid2|2x2|gray|gray256|color|color2|none|mono|threshold|ppm|\n");    fprintf(stderr, "                gray2|gray256x2}]\n");#endif    fprintf(stderr, "      [-loop]\n");    fprintf(stderr, "      [-start frame_num]\t[-end frame_num]\t[-seek file_offset]\n");    fprintf(stderr, "      [-gamma gamma_correction_value]\t[-chroma chroma_correction_value]\n");    fprintf(stderr, "      [-framerate num_frames_per_sec]  (0 means as fast as possible)\n");    fprintf(stderr, "      [-position +x+y]\t[-quality {on|off}] (compiled default is ");#ifdef QUALITY    fprintf(stderr, "ON)\n");#else    fprintf(stderr, "OFF)\n");#endif#ifdef QUIET    fprintf(stderr, "      [-noisy] (turns on all program output)\n");#else    fprintf(stderr, "      [-quiet] (turns off all program output)\n");#endif#ifndef NOCONTROLS    fprintf(stderr, "      [-controls {on|off|none}] (default is on)\n");#endif    fprintf(stderr, "      [-?]\t[-help] for help (this message)\n");    fprintf(stderr, "Rare options:\n");    fprintf(stderr, "      [-nob]\t[-nop]\n");#ifdef ANALYSIS    fprintf(stderr, "      [-eachstat]\t[-owncm]\t[-shmem_off]\n");#else    fprintf(stderr, "      [-owncm]\t[-shmem_off]\n");#endif    fprintf(stderr, "      [-l_range num]\t[-cr_range num]\t[-cb_range num]\n");/*    fprintf(stderr, "      [-xid xid]\n"); */#ifdef DCPREC    fprintf(stderr, "      [-dc {8|9|10|11}] (defaults to 8)\n");#endif    fprintf(stderr, "      with -dither ppm:\n");    fprintf(stderr, "          [-ppmwidth num]\t[-ppmheight num]\t[-ppmskip num]\n");    exit (-1);}/* *-------------------------------------------------------------- * * DoDitherImage -- * *      Called when image needs to be dithered. Selects correct *      dither routine based on info in xinfo[0].ditherType. * * Results: *        None. * * Side effects: *        None. * *-------------------------------------------------------------- */voidDoDitherImage(vid_stream)VidStream *vid_stream;{ unsigned char *l=vid_stream->current->luminance,               *Cr=vid_stream->current->Cr,               *Cb=vid_stream->current->Cb,               *disp=vid_stream->current->display; int h=(int) vid_stream->mb_height * 16; int w=(int) vid_stream->mb_width * 16; int ditherType=vid_stream->ditherType; int matched_depth=vid_stream->matched_depth;#ifndef DISABLE_DITHER  switch(ditherType) {  case HYBRID_DITHER:    HybridDitherImage(l, Cr, Cb, disp, h, w);    break;  case HYBRID2_DITHER:    HybridErrorDitherImage(l, Cr, Cb, disp, h, w);    break;  case FS2FAST_DITHER:    FS2FastDitherImage(l, Cr, Cb, disp, h, w);    break;  case FS2_DITHER:    FS2DitherImage(l, Cr, Cb, disp, h, w);    break;  case FS4_DITHER:    FS4DitherImage(l, Cr, Cb, disp, h, w);    break;  case Twox2_DITHER:    Twox2DitherImage(l, Cr, Cb, disp, h, w);    break;  case FULL_COLOR2_DITHER:    if (matched_depth >= 24)      Twox2Color32DitherImage(l, Cr, Cb, disp, h, w);    else      Twox2Color16DitherImage(l, Cr, Cb, disp, h, w);    break;  case FULL_COLOR_DITHER:    if (matched_depth >= 24)#endif      Color32DitherImage(l, Cr, Cb, disp, h, w);#ifndef DISABLE_DITHER    else      Color16DitherImage(l, Cr, Cb, disp, h, w);    break;  case GRAY_DITHER:  case GRAY256_DITHER:    if (matched_depth == 8)       GrayDitherImage(l, Cr, Cb, disp, h, w);    else if (matched_depth == 16)       Gray16DitherImage(l, Cr, Cb, disp, h, w);    else if (matched_depth == 32 || matched_depth == 24)      Gray32DitherImage(l, Cr, Cb, disp, h, w);    break;  case GRAY2_DITHER:  case GRAY2562_DITHER:    if (matched_depth == 8)       Gray2DitherImage(l, Cr, Cb, disp, h, w);    else if (matched_depth == 16)       Gray216DitherImage(l, Cr, Cb, disp, h, w);    else if (matched_depth == 32 || matched_depth == 24)      Gray232DitherImage(l, Cr, Cb, disp, h, w);    break;  case NO_DITHER:    break;  case PPM_DITHER:    Color32DitherImage(l, Cr, Cb, disp, h, w);    break;  case ORDERED_DITHER:    OrderedDitherImage(l, Cr, Cb, disp, h, w);    break;  case MONO_DITHER:    MonoDitherImage(l, Cr, Cb, disp, h, w);    break;  case MONO_THRESHOLD:    MonoThresholdImage(l, Cr, Cb, disp, h, w);    break;  case ORDERED2_DITHER:    Ordered2DitherImage(l, Cr, Cb, disp, h, w);    break;  case MBORDERED_DITHER:    MBOrderedDitherImage(l, Cr, Cb, disp, h, w, vid_stream->ditherFlags);    break;  }#endif}

⌨️ 快捷键说明

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