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

📄 vblasterlid.cxx

📁 sloedgy open sip stack source code
💻 CXX
📖 第 1 页 / 共 3 页
字号:
        PTRACE(3, "vBlaster\tFirst time serial number " << str);
      }
      firstTime = TRUE;
      break;

    case VoipBlasterInterface::Status_VOUT_DONE:   // Voice output done
      PTRACE(1, "VB\tVOUT done");
      break;

    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
    case 'A':
    case 'B':
    case 'C':
    case 'D':
    case '*':
    case '#':
      PTRACE(1, "VB\tDTMF digit " << (char )status);
      dtmfQueue.Enqueue((BYTE)status);
      break;

    default:
      PTRACE(1, "VB\tUnknown status value " << status);
  }
}


BOOL OpalVoipBlasterDevice::IsLineOffHook(unsigned line)
{
  PWaitAndSignal m(vbMutex);

  if (!IsOpen())
    return FALSE;

  if (line > 0)
    return FALSE;

  return hookState;
}


BOOL OpalVoipBlasterDevice::SetLineOffHook(unsigned /*line*/, BOOL /* newState*/)
{
  return FALSE;
}


BOOL OpalVoipBlasterDevice::HasHookFlash(unsigned /* line */)
{
  return FALSE;
}


BOOL OpalVoipBlasterDevice::IsLineRinging(unsigned /*line*/, DWORD * /*cadence*/)
{
  return FALSE;
}


BOOL OpalVoipBlasterDevice::RingLine(unsigned line, DWORD cadence)
{
  PWaitAndSignal m(vbMutex);

  if (!IsOpen())
    return FALSE;

  if (line > 0)
    return FALSE;

  // %%%%%% this really needs to use a timer to implement cadences.
  if (cadence == 0)
    vBlaster.WriteCommand(VoipBlasterInterface::Command_RING_OFF);
  else
    vBlaster.WriteCommand(VoipBlasterInterface::Command_RING_ON); 

  return TRUE;
}


BOOL OpalVoipBlasterDevice::IsLineDisconnected(unsigned /*line*/, BOOL /*checkForWink*/)
{
  return FALSE;
}


BOOL OpalVoipBlasterDevice::SetLineToLineDirect(unsigned /*line1 */, unsigned /*line2*/, BOOL /*connect*/)
{
  return FALSE;
}


BOOL OpalVoipBlasterDevice::IsLineToLineDirect(unsigned /*line1*/, unsigned /*line2*/)
{
  return FALSE;
}


static const struct {
  const char * mediaFormat;
  PINDEX frameSize;
} CodecInfo[] = {
  { OPAL_G7231_6k3,  24 },
  { OPAL_G7231_5k3,  20 },
};


OpalMediaFormatList OpalVoipBlasterDevice::GetMediaFormats() const
{
  OpalMediaFormatList codecs;

  codecs += CodecInfo[0].mediaFormat;

  return codecs;
}


static PINDEX FindCodec(const OpalMediaFormat & mediaFormat)
{
  for (PINDEX codecType = 0; codecType < PARRAYSIZE(CodecInfo); codecType++) {
    if (mediaFormat == CodecInfo[codecType].mediaFormat)
      return codecType;
  }

  return P_MAX_INDEX;
}


BOOL OpalVoipBlasterDevice::SetReadFormat(unsigned line, const OpalMediaFormat & mediaFormat)
{
  StopReadCodec(line);

  PWaitAndSignal m(vbMutex);
  PWaitAndSignal mutex(readMutex);

  readCodecType = FindCodec(mediaFormat);
  if (readCodecType == P_MAX_INDEX) {
    PTRACE(1, "vBlaster\tUnsupported read codec requested: " << mediaFormat);
    return FALSE;
  }

  if (!writeStopped && readCodecType != writeCodecType) {
    PTRACE(1, "vBlaster\tAsymmetric codecs requested: "
              "read=" << CodecInfo[readCodecType].mediaFormat
           << " write=" << CodecInfo[writeCodecType].mediaFormat);
    return FALSE;
  }

  PTRACE(3, "vBlaster\tSetReadFormat(" << CodecInfo[readCodecType].mediaFormat << ')');

  readFrameSize = CodecInfo[readCodecType].frameSize;

  if (writeStopped)
    vBlaster.OpenData();

  vBlaster.WriteCommand(VoipBlasterInterface::Command_VINP_START);

  readDelay.Restart();

  readStopped = FALSE;

  return TRUE;
}


BOOL OpalVoipBlasterDevice::SetWriteFormat(unsigned line, const OpalMediaFormat & mediaFormat)
{
  StopWriteCodec(line);

  PWaitAndSignal m(vbMutex);
  PWaitAndSignal mutex(writeMutex);

  writeCodecType = FindCodec(mediaFormat);
  if (writeCodecType == P_MAX_INDEX) {
    PTRACE(1, "vBlaster\tUnsupported write codec requested: " << mediaFormat);
    return FALSE;
  }

  if (!readStopped && writeCodecType != readCodecType) {
    PTRACE(1, "vBlaster\tAsymmetric codecs requested: "
              "read=" << CodecInfo[readCodecType].mediaFormat
           << " write=" << CodecInfo[writeCodecType].mediaFormat);
    return FALSE;
  }

  PTRACE(3, "vBlaster\tSetWriteFormat(" << CodecInfo[writeCodecType].mediaFormat << ')');

  writeFrameSize = CodecInfo[writeCodecType].frameSize;

  if (readStopped)
    vBlaster.OpenData();

  vBlaster.WriteCommand(VoipBlasterInterface::Command_VOUT_START);
  vBlaster.WriteCommand(VoipBlasterInterface::Command_VOL_3);
  vBlaster.WriteCommand(VoipBlasterInterface::Command_MUTE_OFF);

  writeDelay.Restart();

  writeStopped = FALSE;
  return TRUE;
}


OpalMediaFormat OpalVoipBlasterDevice::GetReadFormat(unsigned)
{
  if (readCodecType == P_MAX_INDEX)
    return "";
  return CodecInfo[readCodecType].mediaFormat;
}


OpalMediaFormat OpalVoipBlasterDevice::GetWriteFormat(unsigned)
{
  if (writeCodecType == P_MAX_INDEX)
    return "";
  return CodecInfo[writeCodecType].mediaFormat;
}


BOOL OpalVoipBlasterDevice::SetRawCodec(unsigned)
{
  return FALSE;
}

BOOL OpalVoipBlasterDevice::StopReadCodec(unsigned line)
{
  PTRACE(3, "vBlaster\tStopping read codec");

  PWaitAndSignal m(vbMutex);
  readMutex.Wait();
  if (!readStopped) {
    readStopped = TRUE;
    vBlaster.WriteCommand(VoipBlasterInterface::Command_VINP_STOP);
  }

  if (writeStopped)
    vBlaster.CloseData();

  readMutex.Signal();

  return OpalLineInterfaceDevice::StopReadCodec(line);
}


BOOL OpalVoipBlasterDevice::StopWriteCodec(unsigned line)
{
  PTRACE(3, "vBlaster\tStopping write codec");

  PWaitAndSignal m(vbMutex);
  writeMutex.Wait();
  if (!writeStopped) {
    writeStopped = TRUE;
    vBlaster.WriteCommand(VoipBlasterInterface::Command_VOUT_STOP);
  }

  if (readStopped)
    vBlaster.CloseData();

  writeMutex.Signal();

  return OpalLineInterfaceDevice::StopWriteCodec(line);
}


BOOL OpalVoipBlasterDevice::StopRawCodec(unsigned /*line*/)
{
  return FALSE;
}


PINDEX OpalVoipBlasterDevice::GetReadFrameSize(unsigned)
{
  return readFrameSize;
}


BOOL OpalVoipBlasterDevice::SetReadFrameSize(unsigned, PINDEX size)
{
  readFrameSize = size;
  return TRUE;
}


PINDEX OpalVoipBlasterDevice::GetWriteFrameSize(unsigned)
{
  return writeFrameSize;
}


BOOL OpalVoipBlasterDevice::SetWriteFrameSize(unsigned, PINDEX size)
{
  writeFrameSize = size;
  return TRUE;
}


BOOL OpalVoipBlasterDevice::ReadFrame(unsigned, void * buffer, PINDEX & wasRead)
{
  PWaitAndSignal mutex(readMutex);
  if (readStopped)
    return FALSE;

  readDelay.Delay(30);

  if (!hookState)
    return FALSE;

  int stat;
  if ((stat = vBlaster.ReadData(buffer, 20)) != 20) {
    PTRACE(1, "Error reading frame - " << stat);
    return FALSE;
  }

  wasRead = 20;

  return TRUE;
}


BOOL OpalVoipBlasterDevice::WriteFrame(unsigned, const void * buffer, PINDEX /*count*/, PINDEX & written)
{
  PWaitAndSignal m(writeMutex);
  if (writeStopped)
    return FALSE;

  writeDelay.Delay(30);

  const BYTE * p = (const BYTE *)buffer;

  PINDEX toWrite = 0;
  switch (*p & 3) {
    case 0:
      toWrite = 24;
      vBlaster.WriteData(buffer, 24);
      break;
    case 1:
      toWrite = 20;
      vBlaster.WriteData(buffer, 20);
      break;
    case 2:
      toWrite = 4;
      break;
    default:
      // Check for frame erasure command
      if (memcmp(buffer, "\xff\xff\xff\xff", 4) == 0)
        toWrite = 24;
      else
        toWrite = 1;
      break;
  }

  written = toWrite;

  return TRUE;
}


unsigned OpalVoipBlasterDevice::GetAverageSignalLevel(unsigned, BOOL /*playback*/)
{
  return UINT_MAX;
}


BOOL OpalVoipBlasterDevice::EnableAudio(unsigned /*line*/, BOOL /*enable*/)
{
  return TRUE;
}


BOOL OpalVoipBlasterDevice::SetRecordVolume(unsigned /*line*/, unsigned /*volume*/)
{
  return TRUE;
}


BOOL OpalVoipBlasterDevice::SetPlayVolume(unsigned /*line*/, unsigned /*volume*/)
{
  return TRUE;
}


BOOL OpalVoipBlasterDevice::GetRecordVolume(unsigned, unsigned & /*volume*/)
{
  return TRUE;
}


BOOL OpalVoipBlasterDevice::GetPlayVolume(unsigned, unsigned & volume)
{
  volume = 50;
  return TRUE;
}


OpalLineInterfaceDevice::AECLevels OpalVoipBlasterDevice::GetAEC(unsigned)
{
  return AECOff;
}


BOOL OpalVoipBlasterDevice::SetAEC(unsigned, AECLevels /*level*/)
{
  return FALSE;
}


BOOL OpalVoipBlasterDevice::GetVAD(unsigned)
{
  return FALSE;
}


BOOL OpalVoipBlasterDevice::SetVAD(unsigned, BOOL /*enable*/)
{
  return FALSE;
}


BOOL OpalVoipBlasterDevice::GetCallerID(unsigned, PString & /*idString*/, BOOL /*full*/)
{
  return FALSE;
}


BOOL OpalVoipBlasterDevice::SetCallerID(unsigned, const PString & /*idString*/)
{
  return FALSE;
}


BOOL OpalVoipBlasterDevice::SendCallerIDOnCallWaiting(unsigned, const PString & /*idString*/)
{
  return FALSE;
}


BOOL OpalVoipBlasterDevice::SendVisualMessageWaitingIndicator(unsigned /*line*/, BOOL /*isOn*/)
{
  return FALSE;
}


BOOL OpalVoipBlasterDevice::PlayDTMF(unsigned /*line*/,
                                     const char * digits,
                             DWORD /*onTime*/, DWORD /*offTime*/)
{
  PINDEX i;
  for (i = 0; digits[i] != '\0'; i++) {
    PWaitAndSignal m(vbMutex);
    vBlaster.WriteCommand((VoipBlasterInterface::Command)digits[i]);
  }

  return TRUE;
}


char OpalVoipBlasterDevice::ReadDTMF(unsigned)
{
  int v = dtmfQueue.Dequeue();
  return (v < 0) ? (char)0 : (char)v;
}

⌨️ 快捷键说明

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