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

📄 xlibvid.cxx

📁 openh323_1.1.2.2.zip; 2. 把pwlib_1.52.zip 、openh323_1.1.2.2.zip分别展开到目录e:h323sourcepwlib及e:h323sourc
💻 CXX
📖 第 1 页 / 共 3 页
字号:
           *(d1+1)=*d1;                          \
           *(d2++)=*d1;                          \
           *(d2++)=*d1;                          \
           d1+=2;                                \
           if(sw==1)                             \
             RGBPIXEL(yplane2,dtype,d3)          \
            else                                 \
             GRAYPIXEL(yplane2,dtype,d3)         \
           *(d3+1)=*d3;                          \
           *(d4++)=*d3;                          \
           *(d4++)=*d3;                          \
           d3+=2;                                \
           if(sw==1)                             \
             RGBPIXEL(yplane2,dtype,d3)          \
            else                                 \
             GRAYPIXEL(yplane2,dtype,d3)         \
           *(d3+1)=*d3;                          \
           *(d4++)=*d3;                          \
           *(d4++)=*d3;                          \
           d3+=2;                                \
          }                                      \
       d1+=width*6;                              \
       d2+=width*6;                              \
       d3+=width*6;                              \
       d4+=width*6;                              \
       yplane+=width;                            \
       yplane2+=width;                           \
     }                                           \
 } else if(videoPIP&&isEncoding) {               \
          d1= (dtype *)d;                        \
          for(y=0;y<height;y+=2) {               \
             for(x=0;x<width;x+=2) {             \
               CALCULATE ;                       \
               if(sw==1)                         \
                  RGBPIXEL(yplane,dtype,d1)      \
                else                             \
                  GRAYPIXEL(yplane,dtype,d1)     \
               d1++;                             \
               yplane++;                         \
              }                                  \
           yplane+=width;                        \
           }                                     \
       } else {                                  \
         d1= (dtype *)d;                         \
         d2= d1+width;                           \
         for(y=0;y<height;y+=2) {                \
           for(x=0;x<width;x+=2) {               \
             CALCULATE ;                         \
             if(sw==1)                           \
                RGBPIXEL(yplane,dtype,d1)        \
              else                               \
                GRAYPIXEL(yplane,dtype,d1)       \
             d1++;                               \
             if(sw==1)                           \
                RGBPIXEL(yplane,dtype,d1)        \
              else                               \
                GRAYPIXEL(yplane,dtype,d1)       \
             d1++;                               \
             if(sw==1)                           \
                RGBPIXEL(yplane2,dtype,d2)       \
              else                               \
                GRAYPIXEL(yplane2,dtype,d2)      \
             d2++;                               \
             if(sw==1)                           \
                RGBPIXEL(yplane2,dtype,d2)       \
              else                               \
                GRAYPIXEL(yplane2,dtype,d2)      \
             d2++;                               \
            }                                    \
         d1+=width;                              \
         d2+=width;                              \
         yplane+=width;                          \
         yplane2+=width;                         \
        }                                        \
      }                                          \
   }

  if(byteDepth==4) {
     u_int32_t *dest1, *dest2, *dest3, *dest4;
      if(useGrayScale)
       YUVCONVERT(0,u_int32_t,dest1,dest2,dest3,dest4)
      else
       YUVCONVERT(1,u_int32_t,dest1,dest2,dest3,dest4)
  } 
  if(byteDepth==2) {
     u_int16_t *dest1, *dest2, *dest3, *dest4;
     if(useGrayScale)
       YUVCONVERT(0,u_int16_t,dest1,dest2,dest3,dest4)
      else
       YUVCONVERT(1,u_int16_t,dest1,dest2,dest3,dest4)
  }
  if(byteDepth==1) {
     u_int8_t *dest1, *dest2, *dest3, *dest4;
     if(useGrayScale)
       YUVCONVERT(0,u_int8_t,dest1,dest2,dest3,dest4)
      else
       YUVCONVERT(1,u_int8_t,dest1,dest2,dest3,dest4)
  }

#ifdef REPORT_TIMES
  int diffrence;
  static int total_diff_enc=0;
  static int total_diff_dec=0;
  static int framesdone_enc=0;
  static int framesdone_dec=0;
  gettimeofday(&t2,NULL);
  if(t1.tv_sec<t2.tv_sec)
    diffrence=1000000;
   else
    diffrence=0;
  diffrence+= t2.tv_usec-t1.tv_usec;
  if(isEncoding) {
     total_diff_enc+=diffrence;
     framesdone_enc++;
   } else {
      total_diff_dec+=diffrence;
      framesdone_dec++;
  }
  if(framesdone_enc>100){
        cerr<<getpid()<< "average 100 frames enc"<<
              total_diff_enc/framesdone_enc<<endl;
    framesdone_enc=0;
    total_diff_enc=0;
   }
  if(framesdone_dec>100){
      cerr<<getpid()<< "average 100 frames dec"<<
               total_diff_dec/framesdone_dec<<endl;
    framesdone_dec=0;
    total_diff_dec=0;
   }
#endif
  return;
}

BOOL GenericXlibVideoDevice::SetFrameData(unsigned x, unsigned y,
			                  unsigned w, unsigned h,
					  const BYTE * data,
					  BOOL endFrame)
{
  videoMutex.Wait();
  PTRACE(6,"XDisplay\t Redraw START "<<DirectionStr()<<" window.");
  if(win[xIndex()]) {
    XEvent event;
    if(XEventsQueued(display,QueuedAfterFlush)) {
      XNextEvent(display,&event);
      switch (event.type) {
        case ClientMessage:
          PTRACE(3,"XDisplay\t ClientMessage: Cross in X window selected.");
          CloseWindow();
        default:
          PTRACE(4,"XDisplay\t Message " << event.type);
      }
    }
  }
  if(videoPIP&&isEncoding&&width&&height&&(!win[xIndex()])&& display) 
       OpenWindow(width,height); 
      //The display is open. doing PIP, but there is no local window.
      //There should be a local window, so open it.

  if(width&&height&&win[xIndex()]) {
     PTRACE(6,"XDisplay\t  Window all ready for "<<DirectionStr()<< " display");
     Translate420PInput(pixels[xIndex(useImage0)], data);
     XImage * xi = images[xIndex(useImage0)];
     DisplayImage(xi);
     useImage0 = 1 - useImage0;
  } 

  PTRACE(6,"XDisplay\t Redraw FINISH "<<DirectionStr()<<" window.");
  videoMutex.Signal();
  return TRUE;
}


BOOL GenericXlibVideoDevice::EndFrame()
{
  return TRUE;
}


BOOL  GenericXlibVideoDevice::IsOpen()
{
  return nWindowsOpen > 0 ;
}

 

//////////////////////////////////////////////////////////////////////////
//
//  Shared memory Xlib functions
//

void ShmXlibVideoDevice::OpenRender(void)
{
  PTRACE(3,"XDisplayShm\t Open Render, label "<<DirectionStr());
  for(int i=0;i<2;i++) {
     CreateShmXImage(&images[ xIndex(i) ], &shminfo[xIndex(i)]);
     pixels[xIndex(i)] = (BYTE *)shminfo[xIndex(i)].shmaddr;
  }
}

void ShmXlibVideoDevice::CloseRender()
{   
   PTRACE(3,"XDisplayShm\t Close Render, label "<<DirectionStr());
   for(int i=0;i<2;i++) 
     DestroyShmXImage(&images[ xIndex(i) ], &shminfo[xIndex(i)]);
}

void ShmXlibVideoDevice::CreateShmXImage(XImage **image, XShmSegmentInfo *xsi)
{

  int w1,h1;

  w1=displayWidth[xIndex()];
  h1=displayHeight[xIndex()];

  *image = XShmCreateImage(display,
                           visual,
                           pixelDepth,
                           ZPixmap,
                           NULL,
                           xsi,
                           w1,h1);

    if ((*image) == NULL) {
       cerr << "Failed to create shared memory image" << endl; 
       return;
    }
    //   XInitImage(*image);

   xsi->shmid = shmget(IPC_PRIVATE,
                      w1 * h1 * byteDepth,
                      IPC_CREAT | 0777 );
  if(xsi->shmid<0) {
    PTRACE(0,"XDisplayShm\t Failed to create shared memory area" );
    return;
  }

  xsi->shmaddr = (*image)->data = (char *)shmat(xsi->shmid,0 ,0);
  if (xsi->shmaddr == (char *) -1) {
    PTRACE(0,"XDisplayShm\t Failed to assign shared memory area to image->data");
    return;
  }
  xsi->readOnly = False;
  if(!XShmAttach(display, xsi)) {
    PTRACE(0,"XDisplayShm\t Failed to attach shared memory area to X server");
    return;
  }
}

void ShmXlibVideoDevice::DestroyShmXImage(XImage **image, XShmSegmentInfo *xsi)
{
  struct shmid_ds shared_ds;
  if ((*image) != NULL) {
    XShmDetach(display,xsi);
    XDestroyImage(*image);
    shmdt(xsi->shmaddr);
    shmctl(xsi->shmid,IPC_RMID,&shared_ds);          
    *image=NULL;
    }
}
 
void ShmXlibVideoDevice::DisplayImage(XImage *xi)
{ 
  XShmPutImage(display,win[xIndex()],gc,xi,0,0,0,0, xi->width,xi->height,False);
}

//////////////////////////////////////////////////////////////////////////
//
//  Non-shared memory Xlib functions
//

void XlibVideoDevice::OpenRender(void)
{
  PTRACE(3,"XDisplayNonShm\t Open Render, label "<<DirectionStr());
  for(int i=0;i<2;i++)
    CreateXImage(&images[ xIndex(i) ], &pixels[ xIndex(i) ]);
}

void XlibVideoDevice::CloseRender()
{
  PTRACE(3,"XDisplayNonShm\t Close Render, label "<<DirectionStr());

  for(int i=0;i<2;i++)
    if(images[ xIndex(i) ]) {  
      XDestroyImage(images[ xIndex(i) ]);
      images[ xIndex(i) ]=NULL;
    }
}

void XlibVideoDevice::CreateXImage(XImage **image, BYTE ** pixelData)
{
  int w1,h1;

  w1=displayWidth[xIndex()];
  h1=displayHeight[xIndex()];

  *pixelData = (BYTE *)runtime_malloc(w1 * h1 * byteDepth);

  if ((*pixelData) == NULL) {
    PTRACE(0,"XDisplayNonShm\t Failed to allocate storage for pixel data");
    cerr << "Failed to allocate storage for pixel data" << endl;
    return;
  }
  *image = XCreateImage(display,
                        visual,
                        pixelDepth,
                        ZPixmap,
                        0,
                        (char *)*pixelData,
                        w1, h1,
                        8, 0);
  if ((*image) == NULL) {
    cerr << "Failed to create X image" << endl;
    return;
  }

  XInitImage(*image);
}

void XlibVideoDevice::DestroyXImage(XImage **image)
{
  if (*image != NULL)
    XDestroyImage(*image);
}

void XlibVideoDevice::DisplayImage(XImage *xi)
{
  XPutImage(display,win[xIndex()],gc,xi,0,0,0,0, xi->width,xi->height);
}   



#endif

// HAS_X11

⌨️ 快捷键说明

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