//
//  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 CPhone, a cross platform voip gui.
//
//  The Initial Developer of the Original Code is Derek Smithies.
//
//  Copyright (C) 2002 Indranet Technologies Ltd, 
//                                  http://www.indranet-technologies.com
//  All Rights Reserved.
//
//  Contributor(s): _______________


/*
 *
 *  $Log: options.cxx,v $
 *  Revision 1.9  2004/04/14 07:25:19  dereksmithies
 *  Updates, so it compiles on windows XP. Big Thanks to Francisco Huerta
 *
 *  Revision 1.8  2004/01/18 15:45:19  dereksmithies
 *  Make compatable with plugins in the openh323 CVS.
 *
 *  Revision 1.7  2004/01/02 04:06:24  dereksmithies
 *  Bring up to date with openh323 libraries. Get Plugins to work corectly.
 *
 *  Revision 1.6  2003/08/11 01:48:14  dereksmithies
 *  Fix windows compile errors
 *
 *  Revision 1.5  2003/08/10 22:18:37  dereksmithies
 *  Split a rather long line of code - improving stability.
 *
 *  Revision 1.4  2003/04/04 04:37:49  dereksmithies
 *  Major upgrade.
 *  Ixj & microtelco support added. Fix threading issues.
 *
 *  Revision 1.3  2002/11/27 23:52:48  dereksmithies
 *  Changes to make compatible with current openh323 library code.
 *
 *  Revision 1.2  2002/07/31 22:14:52  dereksmithies
 *  Minor tweaks.
 *
 *  Revision 1.1.1.1  2002/05/12 22:55:03  dereksmithies
 *  Initial release.
 *
 *
 *
 *
 */


#include <ptlib.h>

#include "main.h"
#include "keys.h"
#include "options.h"
#include "cpendpoint.h"
#include "mainwindowSub.h"
#include "qtvid.h"

AudioOptions::AudioOptions()
{
  encodingChannel = NULL;
  receiveChannel  = NULL;
}

AudioOptions::~AudioOptions()
{
}

BOOL AudioOptions::Initialise()
{
  PConfig *config = new PConfig(AUDIO_CONFIG);

  disableSilence   = config->GetBoolean(CHECKBOXDISABLESILENCEDETECTION_KEY, FALSE);
  jitterBufferSize = config->GetInteger(SLIDERJITTERBUFFERSIZE_KEY, 150);  
  volumeMicrophone = config->GetInteger(SLIDERMICROPHONE_KEY, 80);
  volumeSpeaker    = config->GetInteger(SLIDERSPEAKER_KEY, 80);
  buffers          = config->GetInteger(SPINBOXNUMBERSOUNDBUFFERS_KEY, 2);

  audioDevice      = config->GetString(COMBOBOXAUDIODEVICE_KEY, "");
  echoCancellation = config->GetString(COMBOBOXECHOCANCELLATION_KEY, CPhone::GetUi().GetAvailableEchoCancNames()[5]);

  delete config;

  return TRUE;
}

BOOL AudioOptions::SaveSettings()
{
  PConfig *config = new PConfig(AUDIO_CONFIG);

  config->SetBoolean(CHECKBOXDISABLESILENCEDETECTION_KEY, disableSilence);
  
  config->SetInteger(SLIDERJITTERBUFFERSIZE_KEY,    jitterBufferSize);  
  config->SetInteger(SLIDERMICROPHONE_KEY,          volumeMicrophone);
  config->SetInteger(SLIDERSPEAKER_KEY,             volumeSpeaker);
  config->SetInteger(SPINBOXNUMBERSOUNDBUFFERS_KEY, buffers);

  config->SetString(COMBOBOXAUDIODEVICE_KEY,        audioDevice);
  config->SetString(COMBOBOXECHOCANCELLATION_KEY,   echoCancellation);

  delete config;
  
  return TRUE;
}

void AudioOptions::PrintOn(ostream & strm) const
{
  strm 
  <<  "-------------------------------------------------------"    << endl
  <<  "Disable Silence detection is " << disableSilence            << endl
  <<  "Echo cancellation is         " << echoCancellation          << endl
  <<  "Buffers is                   " << buffers                   << endl
  <<  "Jitter buffer size is        " << jitterBufferSize << " ms" << endl
  <<  "Microphone volume is         " << volumeMicrophone          << endl
  <<  "Speaker volume is            " << volumeSpeaker             << endl
  <<  "Audio device is              " << audioDevice               << endl
  <<  "-------------------------------------------------------"    << endl;
}

void AudioOptions::AttachAudioChannel(BOOL isEncoding, PChannel *newChannel)
{
  if (isEncoding) {
    encodingChannel = (PSoundChannel *)newChannel;
    EchoCancellationChange();
    VolumeMicrophoneChange();
  } else {
    receiveChannel = (PSoundChannel *)newChannel;
    VolumeSpeakerChange();
  }
}

BOOL AudioOptions::DisableSilenceChange()
{
  return CPhone::GetUi().SetDisableSilenceDetection(disableSilence);
}

BOOL AudioOptions::DisableSilenceChange(BOOL newDisableSilence)
{
  disableSilence = newDisableSilence;
  return DisableSilenceChange();
}

BOOL AudioOptions::EchoCancellationChange()
{
  return CPhone::GetUi().SetEchoCancellation((const char *)echoCancellation);
}
  
BOOL AudioOptions::EchoCancellationChange(QString newEchoCancellation)
{
  echoCancellation = newEchoCancellation;
  return EchoCancellationChange();
}


BOOL AudioOptions::BuffersChange()
{
  CPhone::GetUi().SetSoundChannelBufferDepth(buffers);
  return TRUE;
}

BOOL AudioOptions::BuffersChange(int newBuffers)
{
  buffers = newBuffers;
  return BuffersChange();
}

BOOL AudioOptions::JitterBufferSizeChange()
{
  CPhone::GetUi().SetAudioJitterDelay(0, (unsigned) jitterBufferSize);
  return TRUE;
}

BOOL AudioOptions::JitterBufferSizeChange(int newJitterBufferSize)
{
  jitterBufferSize = newJitterBufferSize;
  return JitterBufferSizeChange();
}


BOOL AudioOptions::VolumeMicrophoneChange()
{
  if (encodingChannel != NULL)
    if (encodingChannel->IsClass("PSoundChannel")) {
      int newVol = volumeMicrophone | (volumeMicrophone << 8);
      return encodingChannel->SetVolume(newVol);    
    }
#ifdef HAS_IXJ  
  return CPhone::GetUi().lidThread.SetRecordVolume(volumeMicrophone);
#endif
  return FALSE;
}

BOOL AudioOptions::VolumeMicrophoneChange(int newVolumeMicrophone)
{
  volumeMicrophone = newVolumeMicrophone;
  return VolumeMicrophoneChange();
}


BOOL AudioOptions::VolumeSpeakerChange()
{
  if (receiveChannel != NULL)
    if (receiveChannel->IsClass("PSoundChannel")) {
      int newVol = volumeSpeaker | (volumeSpeaker << 8);
      return receiveChannel->SetVolume(newVol);
    }
#ifdef HAS_IXJ
  return CPhone::GetUi().lidThread.SetPlayVolume(volumeSpeaker);
#endif
  return FALSE;
}

BOOL AudioOptions::VolumeSpeakerChange(int newVolumeSpeaker)
{
  volumeSpeaker = newVolumeSpeaker;
  return VolumeSpeakerChange();
}

BOOL AudioOptions::AudioDeviceChange()
{
  BOOL success = FALSE;
#ifdef HAS_IXJ
  PStringArray names = CPhone::GetUi().GetAvailableIxjDeviceNames();
  if (names.GetStringsIndex(audioDevice) != P_MAX_INDEX){
    success = CPhone::GetUi().lidThread.SetPhoneDevice(audioDevice);
    if (success)
      goto end_AudioDeviceChange;
  }
#endif

  success = CPhone::GetUi().SetSoundChannelRecordDevice(audioDevice);
  if (success)
    success = CPhone::GetUi().SetSoundChannelPlayDevice(audioDevice);

#ifdef HAS_IXJ
  end_AudioDeviceChange:
#endif
  CPhone::GetUi().RebuildCapabilityTable();

  return success;
}

BOOL AudioOptions::AudioDeviceChange(PString newAudioDevice)
{
  audioDevice = newAudioDevice;
  return AudioDeviceChange();
}

///////////////////

BOOL AudioOptions::GetDisableSilence()
{
  return disableSilence;
}

PString AudioOptions::GetEchoCancellation()
{
  return echoCancellation;
}

int  AudioOptions::GetBuffers()
{
  return buffers;
}

int  AudioOptions::GetJitterBufferSize()
{
  return jitterBufferSize;
}

int  AudioOptions::GetVolumeMicrophone()
{
  return volumeMicrophone;
}

int  AudioOptions::GetVolumeSpeaker()
{
  return volumeSpeaker;
}

PString AudioOptions::GetAudioDevice()
{
  return audioDevice;
}
/////////////////////////////////////////////////////////

VideoOptions::VideoOptions()
{
  codec  = NULL;

  txChannel        = NULL;
  rxChannel        = NULL;
}

VideoOptions::~VideoOptions()
{
}

BOOL VideoOptions::Initialise()
{
  PConfig *config = new PConfig(VIDEO_CONFIG);

  // get default display options
  brightness = config->GetInteger(SLIDERBRIGHTNESS_KEY, 50);
  colour     = config->GetInteger(SLIDERCOLOUR_KEY, 50);
  contrast   = config->GetInteger(SLIDERCONTRAST_KEY, 50);
  hue        = config->GetInteger(SLIDERHUE_KEY, 50);
  whiteness  = config->GetInteger(SLIDERWHITENESS_KEY, 50);
 
  inputChannel   = config->GetInteger(SPINBOXVIDEOINPUTCHANNEL_KEY, -1);
  receiveQuality = config->GetInteger(SPINBOXVIDEORECEIVEQUALITY_KEY, -1);

  palFormat  = config->GetBoolean(RADIOBUTTONPALVIDEOFORMAT_KEY, TRUE);
  ntscFormat = config->GetBoolean(RADIOBUTTONNTSCVIDEOFORMAT_KEY, FALSE);
  transmitQuality= config->GetInteger(SPINBOXVIDEOTRANSMITQUALITY_KEY, -1);

  useLargeSize = config->GetBoolean(CHECKBOXLARGESIZE_KEY, FALSE);

  displayLocal = config->GetBoolean(CHECKBOXDISPLAYLOCALVIDEO_KEY, TRUE);
  flipLocal    = config->GetBoolean(CHECKBOXFLIPLOCALVIDEO_KEY, FALSE);
  flipReceived = config->GetBoolean(CHECKBOXFLIPRECEIVEDVIDEO_KEY, FALSE);

  receiveQuality  = config->GetInteger(SPINBOXVIDEORECEIVEQUALITY_KEY,  10);
  transmitQuality = config->GetInteger(SPINBOXVIDEOTRANSMITQUALITY_KEY, 10);

  videoDevice  = config->GetString(COMBOBOXVIDEOINPUTDEVICE_KEY, "fake");   

  delete config;

  return TRUE;
}

BOOL VideoOptions::SaveSettings()
{
  PConfig *config = new PConfig(VIDEO_CONFIG);

  config->SetInteger(SLIDERBRIGHTNESS_KEY, brightness);
  config->SetInteger(SLIDERCOLOUR_KEY, colour);
  config->SetInteger(SLIDERCONTRAST_KEY, contrast);
  config->SetInteger(SLIDERHUE_KEY, hue);
  config->SetInteger(SLIDERWHITENESS_KEY, whiteness);

  config->SetInteger(SPINBOXVIDEOINPUTCHANNEL_KEY,   inputChannel);
  config->SetInteger(SPINBOXVIDEORECEIVEQUALITY_KEY, receiveQuality);
  config->SetInteger(SPINBOXVIDEOTRANSMITQUALITY_KEY,transmitQuality);

  config->SetBoolean(RADIOBUTTONPALVIDEOFORMAT_KEY,  palFormat);
  config->SetBoolean(RADIOBUTTONNTSCVIDEOFORMAT_KEY, ntscFormat);

  config->SetBoolean(CHECKBOXLARGESIZE_KEY, useLargeSize);

  config->SetBoolean(CHECKBOXDISPLAYLOCALVIDEO_KEY, displayLocal);
  config->SetBoolean(CHECKBOXFLIPLOCALVIDEO_KEY,    flipLocal);
  config->SetBoolean(CHECKBOXFLIPRECEIVEDVIDEO_KEY, flipReceived);

  config->SetInteger(SPINBOXVIDEORECEIVEQUALITY_KEY,  receiveQuality);
  config->SetInteger(SPINBOXVIDEOTRANSMITQUALITY_KEY, transmitQuality);

  config->SetString(COMBOBOXVIDEOINPUTDEVICE_KEY, videoDevice);

  delete config;

  return TRUE;
}

void VideoOptions::GetVideoFrameSizeSetting(unsigned &newFrameWidth, unsigned &newFrameHeight)
{
  if (useLargeSize ) {    
    newFrameWidth  = 352;
    newFrameHeight = 288;
  } else {
    newFrameWidth  = 176;
    newFrameHeight = 144;
  }
}

void VideoOptions::AttachVideoChannels(CpVideoChannel *newRxChannel, CpVideoChannel *newTxChannel)
{
  rxChannel = newRxChannel;
  txChannel = newTxChannel;
}

BOOL VideoOptions::DeviceChange(PString newDevice)
{
  videoDevice = newDevice;
  return DeviceChange();
}

BOOL VideoOptions::DeviceChange()
{
  int returnVal = TRUE;

  txChannel->RestrictAccess();

  txChannel->AttachVideoReader(NULL, FALSE); //delete attached grabber.
   
  txChannel->AttachVideoReader(GetNewVideoGrabber(), FALSE);
 
  txChannel->EnableAccess();

  BrightnessChange();
  ColourChange();
  ContrastChange();
  HueChange();
  WhitenessChange();
  TransmitQualityChange();
  DisplayLocalChange();

  return returnVal;
}

BOOL VideoOptions::FormatChange(BOOL usePalFormat)
{
  palFormat = usePalFormat;
  ntscFormat = !usePalFormat;
  return FormatChange();
}

BOOL VideoOptions::FormatChange()
{
  int returnVal = TRUE;
  txChannel->RestrictAccess();

  PVideoInputDevice  * grabber = txChannel->GetVideoReader();
  if (grabber == NULL) {
    txChannel->EnableAccess();
    return FALSE;
  }
  
  returnVal = grabber->SetVideoFormat(palFormat ? 
				      PVideoDevice::PAL : PVideoDevice::NTSC);
  txChannel->EnableAccess();
  return returnVal;
}

BOOL VideoOptions::ChannelChange(int  newChannel)
{
  inputChannel = newChannel;
  return DeviceChange();          //A channel change requires complete
                                  //reinitialization of the device.
}

BOOL VideoOptions::ChannelChange()
{
  int returnVal = TRUE;
  txChannel->RestrictAccess();

  PVideoInputDevice  * grabber = txChannel->GetVideoReader();
  if (grabber == NULL) {
    txChannel->EnableAccess();
    return FALSE;
  }
 
  returnVal = grabber->SetChannel(inputChannel);
  txChannel->EnableAccess();

  return returnVal;
}

BOOL VideoOptions::ColourFormatChange(PString newColourFormat)
{
  ColourFormatChange();
  return TRUE;
}


BOOL VideoOptions::ColourFormatChange()
{
  int returnVal = TRUE;
  txChannel->RestrictAccess();

  PVideoInputDevice  * grabber = txChannel->GetVideoReader();
  if (grabber == NULL) {
    txChannel->EnableAccess();
    return FALSE;
  }
  
  returnVal = grabber->SetColourFormatConverter("YUV420P"); 
  txChannel->EnableAccess();

  return returnVal;
}

BOOL VideoOptions::FrameRateChange(int newFrameRate)
{
  return FrameRateChange();
}


BOOL VideoOptions::FrameRateChange()
{
  int returnVal = TRUE;
  txChannel->RestrictAccess();

  PVideoInputDevice  * grabber = txChannel->GetVideoReader();
  if (grabber == NULL) {
    txChannel->EnableAccess();
    return FALSE;
  }
  
  returnVal = grabber->SetFrameRate(0);
  txChannel->EnableAccess();

  return returnVal;
}

BOOL VideoOptions::FrameSizeChange(BOOL newUseLargeSize)
{
  useLargeSize = newUseLargeSize;
  return FrameSizeChange();
}

BOOL VideoOptions::FrameSizeChange()
{
  int returnVal = TRUE;
  txChannel->RestrictAccess();

  PVideoInputDevice  * grabber = txChannel->GetVideoReader();
  if (grabber == NULL) {
    txChannel->EnableAccess();
    return FALSE;
  }

  unsigned newFrameWidth,newFrameHeight;              
  GetVideoFrameSizeSetting(newFrameWidth, newFrameHeight);

  returnVal = grabber->SetFrameSizeConverter(newFrameWidth,
					     newFrameHeight, FALSE);  
  txChannel->EnableAccess();

  return returnVal;
}

BOOL VideoOptions::LocalVideoOrientationChange(BOOL  newFlipLocal)
{
  flipLocal = newFlipLocal;
  return LocalVideoOrientationChange();
}

BOOL VideoOptions::LocalVideoOrientationChange()
{
  int returnVal = TRUE;
  txChannel->RestrictAccess();

  PVideoOutputDevice  * player = txChannel->GetVideoPlayer();
  if (player == NULL) {
    txChannel->EnableAccess();
    return FALSE;
  }
  
  returnVal = player->SetVFlipState(flipLocal);
  
  txChannel->EnableAccess();

  return returnVal;
}

BOOL VideoOptions::ReceivedVideoOrientationChange(BOOL newFlipReceived)
{
  flipReceived = newFlipReceived;
  return ReceivedVideoOrientationChange();
}

BOOL VideoOptions::ReceivedVideoOrientationChange()
{
  int returnVal = TRUE;
  rxChannel->RestrictAccess();

  PVideoOutputDevice  * player = rxChannel->GetVideoPlayer();
  if (player == NULL) {
    rxChannel->EnableAccess();
    return FALSE;
  }
  
  returnVal = player->SetVFlipState(flipReceived);
  
  rxChannel->EnableAccess();

  return returnVal;
}


BOOL VideoOptions::BrightnessChange(int newBrightness)
{
  brightness = newBrightness;
  return BrightnessChange();
}

BOOL VideoOptions::BrightnessChange()
{
  int returnVal = TRUE;
  txChannel->RestrictAccess();

  PVideoInputDevice  * grabber = txChannel->GetVideoReader();
  if (grabber == NULL) {
    txChannel->EnableAccess();
    return FALSE;
  }
  
  returnVal = grabber->SetBrightness(brightness);
  txChannel->EnableAccess();

  return returnVal;
}

BOOL VideoOptions::ColourChange(int newColour)
{
  colour = newColour;
  return ColourChange();
}

BOOL VideoOptions::ColourChange()
{
  int returnVal = TRUE;
  txChannel->RestrictAccess();

  PVideoInputDevice  * grabber = txChannel->GetVideoReader();
  if (grabber == NULL) {
    txChannel->EnableAccess();
    return FALSE;
  }
  
  returnVal = grabber->SetColour(colour);  
  txChannel->EnableAccess();

  return returnVal;
}

BOOL VideoOptions::ContrastChange(int newContrast)
{
  contrast = newContrast;
  return ContrastChange();
}

BOOL VideoOptions::ContrastChange()
{
  int returnVal = TRUE;
  txChannel->RestrictAccess();

  PVideoInputDevice  * grabber = txChannel->GetVideoReader();
  if (grabber == NULL) {
    txChannel->EnableAccess();
    return FALSE;
  }
  
  returnVal = grabber->SetContrast(contrast);  
  txChannel->EnableAccess();

  return returnVal;
}

BOOL VideoOptions::HueChange(int newHue)
{
  hue = newHue;
  return HueChange();
}

BOOL VideoOptions::HueChange()
{
  int returnVal = TRUE;
  txChannel->RestrictAccess();

  PVideoInputDevice  * grabber = txChannel->GetVideoReader();
  if (grabber == NULL) {
    txChannel->EnableAccess();
    return FALSE;
  }
  
  returnVal = grabber->SetHue(hue);  
  txChannel->EnableAccess();

  return returnVal;
}

BOOL VideoOptions::WhitenessChange(int newWhiteness)
{
  whiteness = newWhiteness;
  return WhitenessChange();
}

BOOL VideoOptions::WhitenessChange()
{
  int returnVal = TRUE;
  txChannel->RestrictAccess();

  PVideoInputDevice  * grabber = txChannel->GetVideoReader();
  if (grabber == NULL) {
    txChannel->EnableAccess();
    return FALSE;
  }
  
  returnVal = grabber->SetWhiteness(whiteness);  
  txChannel->EnableAccess();

  return returnVal;
}

BOOL VideoOptions::DisplayLocalChange(BOOL newDisplayLocal)
{
  displayLocal = newDisplayLocal;
  return DisplayLocalChange();
}

BOOL VideoOptions::DisplayLocalChange()
{
  return CPhone::GetUi().DisplayLocalIsNow(displayLocal);
}

BOOL VideoOptions::TransmitQualityChange(int newTxQuality)
{
  transmitQuality = newTxQuality;
  return TransmitQualityChange();
}

BOOL VideoOptions::TransmitQualityChange()
{
  if (codec != NULL)
    codec->SetTxQualityLevel(transmitQuality);

  return TRUE;
}

BOOL VideoOptions::ReceivedQualityChange(int newRxQuality)
{
  receiveQuality = newRxQuality;

  return ReceivedQualityChange();
}

BOOL VideoOptions::ReceivedQualityChange()
{
  int returnVal = TRUE;

  return returnVal;
}

BOOL VideoOptions::AttachPlayerReaderToVideoChannel(BOOL isEncoding)
{
  return CPhone::GetUi().AttachPlayerReaderToVideoChannel(isEncoding);
}

PVideoInputDevice *VideoOptions::GetNewVideoGrabber()
{
  PVideoInputDevice  * grabber  = NULL;
  PString            errMessage = "";
  unsigned newFrameWidth,newFrameHeight;              
  GetVideoFrameSizeSetting(newFrameWidth, newFrameHeight);

  grabber = PVideoInputDevice::CreateDeviceByName(videoDevice);
      
  if (grabber == NULL) {
    errMessage = "No grabber available for " + videoDevice;
    goto errVideo;
  }

  if (!grabber->Open(videoDevice, FALSE)) {
    errMessage = "Failed to open the camera device " + videoDevice;
    goto errVideo;
  }

  if (!grabber->SetVideoFormat(palFormat ? PVideoDevice::PAL : PVideoDevice::NTSC)) {
    errMessage = PString("Failed to set format to ") +  PString(palFormat ? "PAL" : "NTSC" );
    goto errVideo;
  }

  if (!grabber->SetChannel(inputChannel)) {
    errMessage = PString("Failed to set channel to ") + PString(inputChannel);
    goto errVideo;
  }

  if (!grabber->SetColourFormatConverter("YUV420P") ) {
    errMessage = PString("Failed to set format to yuv420P");
    goto errVideo;
  }

  if (!grabber->SetFrameRate(0)) {
    errMessage = PString("Failed to set framerate to default");
    goto errVideo;
  }

  if (!grabber->SetFrameSizeConverter(newFrameWidth, newFrameHeight, FALSE) ) {
    errMessage = PString("Failed to set framesize to ") + 
                         PString(newFrameWidth) + PString("x") + PString(newFrameHeight);
    goto errVideo;
  }

  goto exitVideo;
  
  errVideo:
    delete grabber;
    grabber = new PTextVideoInputDevice("No Video");
    grabber->SetColourFormatConverter("YUV420P");
    CPhone::GetUi().DisplayMessage(errMessage);

 exitVideo:
    grabber->Start();
    
    return grabber;
}

int  VideoOptions::GetBrightness()
{
  return brightness;
}

int  VideoOptions::GetColour()
{
  return colour;
}

int  VideoOptions::GetContrast()
{
  return contrast;
}

int  VideoOptions::GetHue()
{
  return hue;
}

int  VideoOptions::GetWhiteness()
{
  return whiteness;
}
  
int  VideoOptions::GetInputChannel()
{
  return inputChannel;
}

int  VideoOptions::GetReceiveQuality()
{
  return receiveQuality;
}

int  VideoOptions::GetTransmitQuality()
{
  return transmitQuality;
}

BOOL VideoOptions::GetPalFormat()
{
  return palFormat;
}

BOOL VideoOptions::GetNtscFormat()
{
  return ntscFormat;
}
  
BOOL VideoOptions::GetUseLargeSize()
{
  return useLargeSize;
}
  
BOOL VideoOptions::GetDisplayLocal()
{
  return displayLocal;
}

BOOL VideoOptions::GetFlipLocal()
{
  return flipLocal;
}

BOOL VideoOptions::GetFlipReceived()
{
  return flipReceived;
}

PString VideoOptions::GetVideoDevice()
{
  return videoDevice;
}

void VideoOptions::AttachVideoCodec(H323VideoCodec *newCodec)
{
  codec = newCodec; 
}

PStringList VideoOptions::GetAllVideoDevices()
{
    PStringList drivers = PVideoInputDevice::GetDriverNames();
    PStringList result;

    for (int i = 0; i < drivers.GetSize(); i++) {
      PStringList devices = PVideoInputDevice::GetDriversDeviceNames(drivers[i]);
      for (int j = 0; j < devices.GetSize(); j++) 
        result += devices[j];
    }

 return result;
}

void VideoOptions::PrintOn(ostream & strm) const
{
  strm 
  <<  "-------------------------------------------------------"   << endl
  <<  "Brightness is   "      <<  brightness   << endl
  <<  "Colour is       "      <<  colour                 << endl
  <<  "Contrast is     "      <<  contrast             << endl
  <<  "Hue is          "      <<  hue             << endl
  <<  "Whiteness is    "      <<  whiteness               << endl
  << endl 
  <<  "Input Channel is        "      <<  inputChannel        << endl 
  <<  "Receive Quality is      "      <<  receiveQuality           << endl
  <<  "Transmit Quality is     "      <<  transmitQuality               << endl
  << endl
  << "pal format is  " << palFormat <<endl
  << "ntsc format is " << ntscFormat<<endl
  << endl
  <<  "Use Large Size is       "      <<  useLargeSize              << endl
  <<  "display Local image is  "      <<  displayLocal              << endl
  << endl 
  <<  "flip Local image is    " <<  flipLocal     << endl
  <<  "Flip Received image is " <<  flipReceived  << endl
  <<  "Video Grab device is   " <<  videoDevice   << endl
  <<  "-------------------------------------------------------"   << endl;
}


////////////////////////////////////////////////////////////////////
LocalVideoDisplayThread::LocalVideoDisplayThread(CpVideoChannel *vChannel)
      : PThread(1000, NoAutoDeleteThread)
{ 
  localVideoChannel = vChannel;
  Resume();
}

void LocalVideoDisplayThread::InitiateTermination()
{
  exitFlag.Signal();
}

void LocalVideoDisplayThread::Main()
{
  Q_UINT8  *videoBuffer = new Q_UINT8[352 * 288 * 4];
  
  while (exitFlag.WillBlock()) {
    PThread::Current()->Sleep(50);
    localVideoChannel->DisplayRawData(videoBuffer);
  }

  delete videoBuffer;
}    


// End of File ///////////////////////



syntax highlighted by Code2HTML, v. 0.9.1