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

📄 video4dc1394.cxx

📁 安装 H323需要的pwlib库
💻 CXX
📖 第 1 页 / 共 2 页
字号:
  PTRACE(1, deviceName << " " << channelNumber);  quadlet_t supported_framerates;  if (dc1394_query_supported_framerates(handle, camera_nodes[channelNumber],					FORMAT_VGA_NONCOMPRESSED, dc1394_mode,					&supported_framerates) != DC1394_SUCCESS) {    PTRACE(1, "dc1394_query_supported_framerates() failed.");    return FALSE;  }  int framerate;  // supported_framerates seems always in the network byte order.  if (supported_framerates & (1U << (31-5)))    framerate = FRAMERATE_60;  else if (supported_framerates & (1U << (31-4)))    framerate = FRAMERATE_30;  else if (supported_framerates & (1U << (31-3)))    framerate = FRAMERATE_15;  else if (supported_framerates & (1U << (31-2)))    framerate = FRAMERATE_7_5;  else if (supported_framerates & (1U << (31-1)))    framerate = FRAMERATE_3_75;  else if (supported_framerates & (1U << (31-0)))    framerate = FRAMERATE_1_875;  else {    PTRACE(1, "No supported frame rate??!!" << supported_framerates);    return FALSE;  }    // In order to compile the following line, you need libdc1394 0.9.0 or later.  if ((UseDMA &&dc1394_dma_setup_capture(handle,camera_nodes[channelNumber],                           0, /* channel of IEEE 1394 */                            FORMAT_VGA_NONCOMPRESSED,                           dc1394_mode,                           P_DC1394_DEFAULT_SPEED,                           framerate, 4, 1, deviceName,			 &camera)!=DC1394_SUCCESS) ||      (!UseDMA && dc1394_setup_capture(handle,camera_nodes[channelNumber],                           0, /* channel of IEEE 1394 */                            FORMAT_VGA_NONCOMPRESSED,                           dc1394_mode,                           P_DC1394_DEFAULT_SPEED,                           framerate,		       &camera)!=DC1394_SUCCESS))  {    PTRACE(0,"unable to setup camera-\n"             "check " __FILE__ " to make sure\n"             "that the video mode,framerate and format are\n"             "supported by your camera\n");    return FALSE;  }  /*-----------------------------------------------------------------------   *  have the camera start sending us data   *-----------------------------------------------------------------------*/  if (dc1394_start_iso_transmission(handle,camera.node)      !=DC1394_SUCCESS)   {    PTRACE(0, "unable to start camera iso transmission\n");    if (UseDMA)      dc1394_dma_release_camera(handle,&camera);    else      dc1394_release_camera(handle,&camera);    return FALSE;  }  is_capturing = TRUE;#ifdef ESTIMATE_CAPTURE_PERFORMANCE  PTime now;  start_time = now.GetTimestamp();  num_captured = 0;#endif  return TRUE;}BOOL PVideoInput1394DcDevice::Stop(){  if (IsCapturing()) {    dc1394_stop_iso_transmission(handle,camera.node);    if (UseDMA) {    dc1394_dma_unlisten(handle, &camera);    dc1394_dma_release_camera(handle,&camera);    } else      dc1394_release_camera(handle,&camera);    is_capturing = FALSE;    return TRUE;  } else    return FALSE;}BOOL PVideoInput1394DcDevice::IsCapturing(){  return is_capturing;}PStringList PVideoInput1394DcDevice::GetInputDeviceNames(){  PStringList list;  if (PFile::Exists("/dev/raw1394"))    list.AppendString("/dev/raw1394");  if (PFile::Exists("/dev/video1394/0"))    // DEVFS naming scheme    for (int i=0; ; i++) {      PString devname = PString("/dev/video1394/") + PString(i);      if (PFile::Exists(devname))	list.AppendString(devname);      else	break;    }  else if (PFile::Exists("/dev/video1394"))    /* traditional naming */    list.AppendString("/dev/video1394");  return list;}BOOL PVideoInput1394DcDevice::SetVideoFormat(VideoFormat newFormat){  if (!PVideoDevice::SetVideoFormat(newFormat)) {    PTRACE(3,"PVideoDevice::SetVideoFormat\t failed for format "<<newFormat);    return FALSE;  }  return TRUE;}int PVideoInput1394DcDevice::GetBrightness(){  return -1;}BOOL PVideoInput1394DcDevice::SetBrightness(unsigned newBrightness){  return FALSE;}int PVideoInput1394DcDevice::GetHue(){  return -1;}BOOL PVideoInput1394DcDevice::SetHue(unsigned newHue){  return FALSE;}int PVideoInput1394DcDevice::GetContrast(){  return -1;}BOOL PVideoInput1394DcDevice::SetContrast(unsigned newContrast){  return FALSE;}BOOL PVideoInput1394DcDevice::SetColour(unsigned newColour) {  return -1;}int PVideoInput1394DcDevice::GetColour(){  return -1;}BOOL PVideoInput1394DcDevice::SetWhiteness(unsigned newWhiteness) {  return FALSE;}int PVideoInput1394DcDevice::GetWhiteness(){  return -1;}BOOL PVideoInput1394DcDevice::GetParameters (int *whiteness, int *brightness,                                       int *colour, int *contrast, int *hue){  *whiteness = -1;  *brightness = -1;  *colour = -1;  *hue = -1;  return FALSE;}int PVideoInput1394DcDevice::GetNumChannels() {  return numCameras;}BOOL PVideoInput1394DcDevice::SetChannel(int newChannel){  if (PVideoDevice::SetChannel(newChannel) == FALSE)    return FALSE;  if(IsCapturing()) {    Stop();    Start();  }  return TRUE;}BOOL PVideoInput1394DcDevice::SetFrameRate(unsigned rate){  return PVideoDevice::SetFrameRate(rate);}BOOL PVideoInput1394DcDevice::GetFrameSizeLimits(unsigned & minWidth,                                           unsigned & minHeight,                                           unsigned & maxWidth,                                           unsigned & maxHeight) {  minWidth = 160;  maxWidth = 320;  minHeight = 120;  maxHeight = 240;  return TRUE;}PINDEX PVideoInput1394DcDevice::GetMaxFrameBytes(){  if (converter != NULL) {    PINDEX bytes = converter->GetMaxDstFrameBytes();    if (bytes > frameBytes)      return bytes;  }  return frameBytes;}BOOL PVideoInput1394DcDevice::GetFrameDataNoDelay(BYTE * buffer, PINDEX * bytesReturned){  if (!IsCapturing()) return FALSE;  PTRACE(3, "We are going to single capture.\n");  if ((UseDMA && dc1394_dma_single_capture(&camera)!=DC1394_SUCCESS) ||      (!UseDMA && dc1394_single_capture(handle,&camera)!=DC1394_SUCCESS)){    PTRACE(1, "dc1394_single_capture() failed.");    return FALSE;  }    PTRACE(3, "single captured, try to convert\n");  // If converting on the fly do it from frame store to output buffer, otherwise do  // straight copy.  if (converter != NULL)    converter->Convert((const BYTE *)camera.capture_buffer, buffer, bytesReturned);  else {    PTRACE(1, "Converter must exist. Something goes wrong.");    return FALSE;  }#ifdef ESTIMATE_CAPTURE_PERFORMANCE  ++num_captured;  PTime now;  double capturing_time = (double)((now.GetTimestamp()-start_time))/1000000;  ::fprintf(stderr, "time %f, num_captured=%d, fps=%f\n",	    capturing_time, num_captured, num_captured/capturing_time);#endif  if (UseDMA)    dc1394_dma_done_with_buffer(&camera);  return TRUE;}BOOL PVideoInput1394DcDevice::GetFrameData(BYTE * buffer, PINDEX * bytesReturned){  if(frameRate>0) {    if (msBetweenFrames > capturing_duration)      PThread::Current()->Sleep(msBetweenFrames - capturing_duration);    PTime start;    if ( !GetFrameDataNoDelay(buffer, bytesReturned))      return FALSE;    PTime end;    capturing_duration = (int)((end-start).GetMilliSeconds());    return TRUE;  }  return GetFrameDataNoDelay(buffer,bytesReturned);}void PVideoInput1394DcDevice::ClearMapping(){}BOOL PVideoInput1394DcDevice::TestAllFormats(){  return TRUE;}BOOL PVideoInput1394DcDevice::SetColourFormat(const PString & newFormat){  if (newFormat != colourFormat) {    return FALSE;  }  return TRUE;}BOOL PVideoInput1394DcDevice::SetFrameSize(unsigned width, unsigned height){  if ((!(width == 320 && height == 240)) &&      (!(width == 160 && height == 120)))    return FALSE;  frameWidth = width;  frameHeight = height;  if (frameWidth == 320 && frameHeight == 240)    colourFormat = "UYVY422";  else if (frameWidth == 160 && frameHeight == 120)    colourFormat = "UYV444";  frameBytes = PVideoDevice::CalculateFrameBytes(frameWidth, frameHeight, colourFormat);    if (IsCapturing()) {    Stop(); Start();  }  return TRUE;}BOOL PVideoInput1394DcDevice::SetFrameSizeConverter(unsigned width, unsigned height,					 BOOL bScaleNotCrop){  if (width == CIFWidth && height == CIFHeight)    SetFrameSize(320, 240);  else if (width == QCIFWidth && height == QCIFHeight)    SetFrameSize(160, 120);  else {    PTRACE(1, width << "x" << height << " is not supported.");    return FALSE;  }  if (converter != NULL)     delete converter;    desiredFrameWidth = width;  desiredFrameHeight = height;  converter = PColourConverter::Create(colourFormat, desiredColourFormat, width, height);  if (converter == NULL) {    PTRACE(1, "Failed to make a converter.");    return FALSE;  }  if (converter->SetSrcFrameSize(frameWidth, frameHeight) == FALSE) {    PTRACE(1, "Failed to set source frame size of a converter.");    return FALSE;  }  return TRUE;}BOOL PVideoInput1394DcDevice::SetColourFormatConverter(const PString & colourFmt){  if (colourFmt != "YUV420P") {    PTRACE(1, colourFmt << " is unsupported.");    return FALSE;  }  desiredColourFormat = colourFmt;  return SetFrameSizeConverter(desiredFrameWidth, desiredFrameHeight, FALSE);}    // End Of File ///////////////////////////////////////////////////////////////

⌨️ 快捷键说明

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