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

📄 display.cc.openptc

📁 ac3的解码程序
💻 OPENPTC
📖 第 1 页 / 共 3 页
字号:
/*   File: display.cc   By: Alex de Jong (original by MSSG)   Created: March 1996      Description:   Multi-Threaded display class. Displays class is able to    synchronize frames with a synchronoization object, which   in turn is updates by a decoder timer.*/#define USE_PTC 1#ifdef __GNUG__#pragma implementation#endif#include "athread.hh"#include <stdio.h>#include <fstream.h>#include <sys/time.h>#ifdef USE_PTC#include <ptc/ptc.h>#endif#include "error.hh"#include "debug.hh"#include "util.hh"#include "videoconst.hh"#include "sync.hh"#include "display.hh"extern int quiet;extern int coded_picture_width;extern int coded_picture_height;extern int prog_seq;extern int chroma_format;extern int chrom_width;extern int pict_struct, topfirst;extern int convmat[8][4];extern int matrix_coefficients;extern int playedlastframe;// #define USE_DGA 1               /* enable this to use DGA extention */#ifdef SH_MEM// Dummies to get rid of warningsextern "C" {int XShmQueryExtension(Display*);int XShmGetEventBase(Display*);}#ifdef USE_DGA#include <X11/extensions/xf86dga.h>#include <X11/extensions/xf86vmode.h>#endif#endifDisplayX11::DisplayX11(const char* title, Synchronization* s){  TRACER("DisplayX11::DisplayX11(const char* title, Synchronization* s)");  int crv, cbu, cgu, cgv;  int y, u, v, r, g, b;  int i, j;  Colormap cmap;  XColor xcolor;  unsigned int fg, bg;  XSizeHints hint;  unsigned long tmp_pixel;  XWindowAttributes xwa;  int screen;  static Console console;  con = &console;    // init to avoid invalid destroy in destructor  ximage=0;  ximage2=0;  // Synchronization with decoder clock  sync=s;  // Init display lock/condition to prevent threads to pass eachother  source=0;#ifdef SH_MEM  CompletionType = -1;#endif  // create clipping table  clp=new unsigned char[1024];  // clip table  clp += 384;  for (i=-384; i<640; i++)     clp[i] = (i<0) ? 0 : ((i>255) ? 255 : i);  if (!(display=XOpenDisplay(0))){    error("Can not open display\n");    athr_exit(0);  }#ifdef TRACE  XSynchronize(display, 1);#endif      screen = DefaultScreen(display);  // find  display  if (XMatchVisualInfo(display, screen, 16, TrueColor, &vinfo)){  } else   error("requires 16 bit display\n");  // Make the window  hint.x = 200;  hint.y = 200;  hint.width = 100;  hint.height= 100;  hint.flags = PPosition | PSize;  bpp = vinfo.depth;  if (vinfo.red_mask == 0x7c00)    rgb_mode = 1;		// RGB555    for more modes see yuv12-rgb.s  else    rgb_mode = 0;		// RGB565//  if (rgb_mode == 0) //    Format format(16,0xf800,0x7e0,0x1f);//  else//    Format format(16,0x7c00,0x3e0,0x1f);//  form = &format;#if 0  // Get some colors  bg = WhitePixel(display, screen);  fg = BlackPixel(display, screen);  window=XCreateSimpleWindow(display, DefaultRootWindow (display),                               hint.x, hint.y, hint.width, hint.height, 4, fg, bg);  // Tell other applications about this window  XSetStandardProperties(display, window, title, title, None, NULL, 0, &hint);  XSelectInput(display, window, StructureNotifyMask);  // Map window  XMapWindow(display, window);  // Wait for map.  do {    XNextEvent(display, &event);  }  while (event.type != MapNotify || event.xmap.event != window);  XSelectInput(display, window, NoEventMask);  gc = DefaultGC(display, screen);/*   Init dither   4x4 ordered dither   threshold pattern:    0  8  2 10   12  4 14  6    3 11  1  9   15  7 13  5*/  unsigned char ctab[256+32];    for (i=0; i<256+16; i++){    v = (i-8)>>4;    if (v<2) v=2;    else if (v>14) v=14;    for (j=0; j<16; j++)       ytab[16*i+j] = pixel[(v<<4)+j];  }  for (i=0; i<256+32; i++){    v = (i+48-128)>>5;    if (v<0) v=0;    else if (v>3) v=3;    ctab[i]=v;  }  for (i=0; i<255+15; i++)    for (j=0; j<255+15; j++)      uvtab[256*i+j]=(ctab[i+16]<<6)|(ctab[j+16]<<4)|(ctab[i]<<2)|ctab[j];#endif}DisplayX11::~DisplayX11(){   TRACER("DisplayX11::~DisplayX11()");  display_lock.lock();  if (!terminated) athr_join(thread_id);  exit_display();  delete clp; // delete clipping table  display_lock.unlock();}void* DisplayX11::dither_thread(DisplayX11* d){  d->display_lock.lock();  d->terminated=0;  d->dither_image(d->source);  d->display_image(d->ximage, d->dithered_image);   d->source=0;  d->display_cond.signal();  d->terminated=1;  d->display_lock.unlock(); #if !defined(IRIX) && !defined(SOLARIS_SDK_XIL) && !defined(LINUX)  athr_exit(0);#endif  return 0;}void* DisplayX11::display_thread(DisplayX11* d){#ifndef LINUX  d->display_lock.lock();  d->terminated=0;  d->display_image(d->ximage2, d->dithered_image2);   d->terminated=1;  d->display_lock.unlock();#if !defined(IRIX) && !defined(SOLARIS_SDK_XIL) && !defined(LINUX)  athr_exit(0);#endif#endif  return 0;}int DisplayX11::init(int h_size, int v_size){  TRACER("void DisplayX11::init(int h_size, int v_size)");  display_lock.lock();  // lock the display from others access for now  // resize window  horizontal_size=h_size;  vertical_size=v_size;  Format format(16,0x7c00,0x3e0,0x1f);  con->option("dga pedantic init");  con->open("MPEG2 Player",h_size,v_size,format,0);  if (con->format() != format) message("Unable to get  format");#if 0  XResizeWindow(display, window, horizontal_size, vertical_size);#ifdef SH_MEM  char dummy;  shmem_flag = 0;#ifdef USE_DGA             /* enable this if you want to have DGA support */  int EventBase, ErrorBase, flags,vp_width,vp_height,bank,ram;  if (XF86DGAQueryExtension (display, &EventBase, &ErrorBase)) {      XF86DGAQueryDirectVideo (display, XDefaultScreen (display), &flags);      if ((flags & XF86DGADirectPresent) == 0) {          if (!quiet) message ("dga: no direct present");      }      else {          shmem_flag = 2;          if (!quiet) message ("using DGA ");      }      XF86DGAGetVideo (display, XDefaultScreen (display), (char **) &dithered_image,                        &xwidth, &bank, &ram);      dithered_image2 = dithered_image;      XF86DGAGetViewPortSize (display, XDefaultScreen (display),                        &vp_width, &vp_height);      if (vp_height < v_size || vp_width < h_size) {        if (!quiet) message("View Port too small for DGA");        shmem_flag = 0;      }      else {        XF86DGASetViewPort (display, XDefaultScreen (display), 0, 0);        XF86DGADirectVideo (display, XDefaultScreen (display),XF86DGADirectGraphics );      }  }#endif  if (!shmem_flag)     if (XShmQueryExtension(display)) shmem_flag = 1;    else {      shmem_flag = 0;      if (!quiet){        message("Shared memory not supported");        message("Reverting to normal Xlib");      }    }  if (shmem_flag==1) CompletionType = XShmGetEventBase(display) + ShmCompletion;  InstallXErrorHandler();  if (shmem_flag==1){    ximage = XShmCreateImage(display, None, bpp, ZPixmap, NULL,                             &shminfo1,                             coded_picture_width, coded_picture_height);    if (!prog_seq)      ximage2 = XShmCreateImage(display, None, bpp, ZPixmap, NULL,                                &shminfo2,                                coded_picture_width, coded_picture_height);    /* If no go, then revert to normal Xlib calls. */    if (ximage==NULL || (!prog_seq && ximage2==NULL)){      if (ximage!=NULL) XDestroyImage(ximage);      if (!prog_seq && ximage2!=NULL) XDestroyImage(ximage2);      if (!quiet)        fprintf(stderr, "Shared memory error, disabling (Ximage error)\n");      goto shmemerror;    }    /* Success here, continue. */    shminfo1.shmid = shmget(IPC_PRIVATE,                             ximage->bytes_per_line * ximage->height,                            IPC_CREAT | 0777);    if (!prog_seq)      shminfo2.shmid = shmget(IPC_PRIVATE,                               ximage2->bytes_per_line * ximage2->height,                              IPC_CREAT | 0777);    if (shminfo1.shmid<0 || (!prog_seq && shminfo2.shmid<0)){      XDestroyImage(ximage);      if (!prog_seq) XDestroyImage(ximage2);      if (!quiet)        fprintf(stderr, "Shared memory error, disabling (seg id error)\n");      goto shmemerror;    }    shminfo1.shmaddr = (char *) shmat(shminfo1.shmid, 0, 0);    shminfo2.shmaddr = (char *) shmat(shminfo2.shmid, 0, 0);    if (shminfo1.shmaddr==((char *) -1) ||        (!prog_seq && shminfo2.shmaddr==((char *) -1))){      XDestroyImage(ximage);      if (shminfo1.shmaddr!=((char *) -1)) shmdt(shminfo1.shmaddr);      if (!prog_seq){        XDestroyImage(ximage2);        if (shminfo2.shmaddr!=((char *) -1))          shmdt(shminfo2.shmaddr);      }      if (!quiet)      {        fprintf(stderr, "Shared memory error, disabling (address error)\n");      }      goto shmemerror;    }    ximage->data = shminfo1.shmaddr;    dithered_image = (unsigned char *)ximage->data;    shminfo1.readOnly = False;    XShmAttach(display, &shminfo1);    if (!prog_seq){      ximage2->data = shminfo2.shmaddr;      dithered_image2 = (unsigned char *)ximage2->data;      shminfo2.readOnly = False;      XShmAttach(display, &shminfo2);    }    XSync(display, False);    if (gXErrorFlag){      /* Ultimate failure here. */      XDestroyImage(ximage);      shmdt(shminfo1.shmaddr);      if (!prog_seq){        XDestroyImage(ximage2);        shmdt(shminfo2.shmaddr);      }      if (!quiet)

⌨️ 快捷键说明

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