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

📄 video.cxx

📁 这是一个OPENH323中的MCU程序
💻 CXX
📖 第 1 页 / 共 3 页
字号:
/*
 * video.cxx
 *
 * Video conferencing functions for a simple MCU
 *
 * Copyright (c) 2000 Equivalence Pty. Ltd.
 * Copyright (c) 2004 Post Increment
 *
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 * the License for the specific language governing rights and limitations
 * under the License.
 *
 * The Original Code is Portable Windows Library.
 *
 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
 *
 * Portions of ths code were written by by Post Increment (http://www.postincrement.com) 
 * with the assistance of funding from Stonevoice, slc. http://www.stonevoice.com
 *
 * Portions of this code were written by Post Increment (http://www.postincrement.com) 
 * with the assistance of funding from Citron Networks (http://www.citron.com.tw)
 *
 * Contributor(s): Derek J Smithies (derek@indranet.co.nz)
 *                 Craig Southeren (craig@postincrement.com)
 *
 * $Log: video.cxx,v $
 * Revision 1.2  2007/10/20 12:04:57  shorne
 * Fix small compile error with ptlib v1.12
 *
 * Revision 1.1  2007/10/17 19:44:37  shorne
 * Initial Commit
 *
 * Revision 2.6  2006/07/21 08:01:40  csoutheren
 * Fixed conference member detect
 * Re-factored video mixer code slightly
 *
 * Revision 1.10  2006/07/21 06:07:08  craigs
 * Backports from open source version
 *
 * Revision 2.5  2006/07/21 05:08:03  csoutheren
 * Stability fixes and more inline documentation
 * Thanks to Paolo Amadini of Stonevoice
 *
 * Revision 2.4  2006/06/21 06:11:36  csoutheren
 * Fixes for latest pwlib
 *
 * Revision 2.3  2006/06/09 04:39:59  csoutheren
 * Migrated VideoBranch to main trunk
 *
 * Revision 2.2.2.16  2006/06/06 08:24:16  csoutheren
 * Added support for echo test room
 * Fix problem with using high frame rates
 *
 * Revision 2.2.2.15  2006/04/18 03:05:09  csoutheren
 * Fix video mix problem with > 3 members
 * Add test room
 *
 * Revision 2.2.2.14  2006/04/12 04:54:18  csoutheren
 * Fix more problems with audio-only members
 *
 * Revision 2.2.2.13  2006/04/12 01:46:13  csoutheren
 * Added defaut image when audio-only member enters video conference
 * Added image to Web gui
 *
 * Revision 2.2.2.12  2006/04/06 08:20:29  csoutheren
 * Retyped conference member identifier to epxlicit type
 * Added support for H.245 terminal added and terminal left
 *
 * Revision 2.2.2.11  2006/04/06 01:11:16  csoutheren
 * Latest sources include
 *   - premedia blanking and optional image display
 *   - ablity to defer conference join for authentication if required
 *   - more bulletproofing on conference join
 *   - new video copy/fill functions
 *
 * Revision 2.2.2.10  2006/04/06 00:50:30  csoutheren
 * Latest changes (more to come)
 *
 * Revision 2.2.2.8  2006/03/28 05:13:38  csoutheren
 * Normalised file headers
 * Fixed problem with QCIF video
 * Seperated H.323 and MCU process functions into seperate files
 *
 * Revision 2.2.2.7  2006/03/27 12:53:14  csoutheren
 * More fixes for QCIF video (not yet verified)
 *
 * Revision 2.2.2.6  2006/03/27 09:14:15  csoutheren
 * Fixed Unix compile warnings and errors
 * Added VideoTxQuality value
 *
 * Revision 2.2.2.5  2006/03/24 22:49:24  csoutheren
 * Video now working
 *
 * Revision 2.2.2.4  2006/03/21 14:02:49  csoutheren
 * More video mixiing.
 * Still some crashes in video mixer code when members exit conference
 *
 * Revision 2.2.2.3  2006/03/17 07:00:24  csoutheren
 * More video implementation
 * Video mixing now working except copying subimage UV components causes overrun
 * Y is OK, which is why the images are grey. Also need to work out flipping requirements
 *
 * Revision 2.2.2.2  2006/03/14 08:02:50  csoutheren
 * More implemenrtation of video
 * Video mixing infrastructure implemented but not fully working
 *
 * Revision 2.2.2.1  2006/03/06 05:45:30  csoutheren
 * Start of implementation for video. Still in progress
 *
 * Revision 2.2  2004/03/23 11:40:06  csoutheren
 * Fixed problem where deleting map element in-place causes crash at end of call
 * Fixed problem where referencing map by iterator rather than ID
 * Fixed code formatting problems
 *
 * Revision 2.1  2004/03/11 20:49:44  csoutheren
 * Removed warnings
 *
 * Revision 2.0  2004/03/08 02:06:24  csoutheren
 * Totally rewritten to use new connection locking mecahnism
 * Added ability to monitor conferences
 * Added initial support for H.323 MCU messages
 * Thanks to Citron Networks for supporting this work
 *
 */


#include <ptlib.h>

#ifdef _WIN32
#pragma warning(disable:4786)
#endif

#include "config.h"

#if OPENMCU_VIDEO

#include "mcu.h"
#include "h323.h"
#include <ptlib/vconvert.h>

#define Q3CIF_WIDTH   (CIF_WIDTH / 3)
#define Q3CIF_HEIGHT  (CIF_HEIGHT / 3)
#define Q3CIF_SIZE    (Q3CIF_WIDTH*Q3CIF_HEIGHT*3/2)

#define Q3CIFCHAIR_WIDTH   (2*CIF_WIDTH / 3)
#define Q3CIFCHAIR_HEIGHT  (2*CIF_HEIGHT / 3)
#define Q3CIFCHAIR_SIZE    (Q3CIFCHAIR_WIDTH*Q3CIFCHAIR_HEIGHT*3/2)

#define Q4CIF_WIDTH   (CIF_WIDTH / 4)
#define Q4CIF_HEIGHT  (CIF_HEIGHT / 4)
#define Q4CIF_SIZE    (Q4CIF_WIDTH*Q4CIF_HEIGHT*3/2)

#define Q4CIFCHAIR_WIDTH   (3*CIF_WIDTH / 4)
#define Q4CIFCHAIR_HEIGHT  (3*CIF_HEIGHT / 4)
#define Q4CIFCHAIR_SIZE    (Q4CIFCHAIR_WIDTH*Q4CIFCHAIR_HEIGHT*3/2)

#define MAX_SUBFRAMES   16

///////////////////////////////////////////////////////////////////////////////////////
//
//  declare a video capture (input) device for use with OpenMCU
//

PVideoInputDevice_OpenMCU::PVideoInputDevice_OpenMCU(OpenMCUH323Connection & _mcuConnection)
  : mcuConnection(_mcuConnection)
{
  SetColourFormat("YUV420P");
  channelNumber = 0; 
  grabCount = 0;
  SetFrameRate(25);
}


BOOL PVideoInputDevice_OpenMCU::Open(const PString & devName, BOOL /*startImmediate*/)
{
  //file.SetWidth(frameWidth);
  //file.SetHeight(frameHeight);

  deviceName = devName;

  return TRUE;    
}


BOOL PVideoInputDevice_OpenMCU::IsOpen() 
{
  return TRUE;
}


BOOL PVideoInputDevice_OpenMCU::Close()
{
  return TRUE;
}


BOOL PVideoInputDevice_OpenMCU::Start()
{
  return TRUE;
}


BOOL PVideoInputDevice_OpenMCU::Stop()
{
  return TRUE;
}


BOOL PVideoInputDevice_OpenMCU::IsCapturing()
{
  return IsOpen();
}


PStringList PVideoInputDevice_OpenMCU::GetInputDeviceNames()
{
  PStringList list;
  list.AppendString("openmcu");
  return list;
}


BOOL PVideoInputDevice_OpenMCU::SetVideoFormat(VideoFormat newFormat)
{
  return PVideoDevice::SetVideoFormat(newFormat);
}


int PVideoInputDevice_OpenMCU::GetNumChannels() 
{
  return 0;
}


BOOL PVideoInputDevice_OpenMCU::SetChannel(int newChannel)
{
  return PVideoDevice::SetChannel(newChannel);
}

BOOL PVideoInputDevice_OpenMCU::SetColourFormat(const PString & newFormat)
{
  if (!(newFormat *= "YUV420P"))
    return FALSE;

  if (!PVideoDevice::SetColourFormat(newFormat))
    return FALSE;

  return SetFrameSize(frameWidth, frameHeight);
}


BOOL PVideoInputDevice_OpenMCU::SetFrameRate(unsigned rate)
{
  if (rate < 1)
    rate = 1;
  else if (rate > 50)
    rate = 50;

  return PVideoDevice::SetFrameRate(rate);
}


BOOL PVideoInputDevice_OpenMCU::GetFrameSizeLimits(unsigned & minWidth,
                                           unsigned & minHeight,
                                           unsigned & maxWidth,
                                           unsigned & maxHeight) 
{
  maxWidth  = CIF_WIDTH;
  maxHeight = CIF_HEIGHT;
  minWidth  = QCIF_WIDTH;
  minHeight = QCIF_HEIGHT;

  return TRUE;
}


BOOL PVideoInputDevice_OpenMCU::SetFrameSize(unsigned width, unsigned height)
{
  if (!PVideoDevice::SetFrameSize(width, height))
    return FALSE;

  videoFrameSize = CalculateFrameBytes(frameWidth, frameHeight, colourFormat);
  scanLineWidth = videoFrameSize/frameHeight;
  return videoFrameSize > 0;
}


PINDEX PVideoInputDevice_OpenMCU::GetMaxFrameBytes()
{
  return GetMaxFrameBytesConverted(videoFrameSize);
}


BOOL PVideoInputDevice_OpenMCU::GetFrameData(BYTE * buffer, PINDEX * bytesReturned)
{    
  grabDelay.Delay(1000/GetFrameRate());

  return GetFrameDataNoDelay(buffer, bytesReturned);
}

 
BOOL PVideoInputDevice_OpenMCU::GetFrameDataNoDelay(BYTE *destFrame, PINDEX * bytesReturned)
{
  grabCount++;

  if (!mcuConnection.OnOutgoingVideo(destFrame, frameWidth, frameHeight, *bytesReturned))
    return FALSE;

  if (converter != NULL) {
    if (!converter->Convert(destFrame, destFrame, bytesReturned))
      return FALSE;
  }

  if (bytesReturned != NULL)
    *bytesReturned = videoFrameSize;

  return TRUE;
}

///////////////////////////////////////////////////////////////////////////////////////
//
//  declare a video display (output) device for use with OpenMCU
//

PVideoOutputDevice_OpenMCU::PVideoOutputDevice_OpenMCU(OpenMCUH323Connection & _mcuConnection)
  : mcuConnection(_mcuConnection)
{
}


BOOL PVideoOutputDevice_OpenMCU::Open(const PString & _deviceName, BOOL /*startImmediate*/)
{
  deviceName = _deviceName;
  return TRUE;
}

BOOL PVideoOutputDevice_OpenMCU::Close()
{
  return TRUE;
}

BOOL PVideoOutputDevice_OpenMCU::Start()
{
  return TRUE;
}

BOOL PVideoOutputDevice_OpenMCU::Stop()
{
  return TRUE;
}

BOOL PVideoOutputDevice_OpenMCU::IsOpen()
{
  return TRUE;
}


PStringList PVideoOutputDevice_OpenMCU::GetOutputDeviceNames()
{
  PStringList list;
  return list;
}


⌨️ 快捷键说明

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