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

📄 lid.cxx

📁 sloedgy open sip stack source code
💻 CXX
📖 第 1 页 / 共 4 页
字号:
 * Added hacks so G.728 works with (I think) broken cisco gateways.
 *
 * Revision 1.10  2000/03/29 21:01:52  robertj
 * Changed codec to use number of frames rather than number of bytes.
 * Added function on LID to get available codecs.
 * Fixed codec table for G.729 codec
 *
 * Revision 1.9  2000/03/28 05:22:05  robertj
 * Fixed translation of text country code to numeric code.
 *
 * Revision 1.8  2000/03/23 23:36:49  robertj
 * Added more calling tone detection functionality.
 *
 * Revision 1.7  2000/03/21 03:06:50  robertj
 * Changes to make RTP TX of exact numbers of frames in some codecs.
 *
 * Revision 1.6  2000/01/13 12:39:29  robertj
 * Added string based country codes to LID.
 *
 * Revision 1.5  2000/01/13 04:03:46  robertj
 * Added video transmission
 *
 * Revision 1.4  2000/01/07 10:01:26  robertj
 * GCC/Linux compatibility
 *
 * Revision 1.3  2000/01/07 08:28:09  robertj
 * Additions and changes to line interface device base class.
 *
 * Revision 1.2  1999/12/29 01:18:07  craigs
 * Fixed problem with codecs other than G.711 not working after reorganisation
 *
 * Revision 1.1  1999/12/23 23:02:36  robertj
 * File reorganision for separating RTP from H.323 and creation of LID for VPB support.
 *
 */

#include <ptlib.h>

#ifdef __GNUC__
#pragma implementation "lid.cxx"
#endif

#include <lids/lid.h>


#define new PNEW


static OpalLIDRegistration * RegisteredLIDsListHead;


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

#if PTRACING
static const char * const CallProgressTonesNames[] = {
  "DialTone", "RingTone", "BusyTone", "ClearTone", "CNGTone"
};

ostream & operator<<(ostream & o, OpalLineInterfaceDevice::CallProgressTones t)
{
  PINDEX i = 0;    
  while ((1 << i) != t)
    i++;

  if (i < PARRAYSIZE(CallProgressTonesNames))
    return o << CallProgressTonesNames[i];
  else
    return o << "Unknown";
}

#endif


OpalLineInterfaceDevice::OpalLineInterfaceDevice()
{
  os_handle = -1;
  osError = 0;
  countryCode = UnknownCountry;
  readDeblockingOffset = P_MAX_INDEX;
  writeDeblockingOffset = 0;
}


BOOL OpalLineInterfaceDevice::IsOpen() const
{
  return os_handle >= 0;
}


BOOL OpalLineInterfaceDevice::Close()
{
  if (os_handle < 0)
    return FALSE;

  os_handle = -1;
  return TRUE;
}


BOOL OpalLineInterfaceDevice::IsLineTerminal(unsigned)
{
  return FALSE;
}


BOOL OpalLineInterfaceDevice::IsLinePresent(unsigned, BOOL)
{
  return TRUE;
}


BOOL OpalLineInterfaceDevice::HookFlash(unsigned line, unsigned flashTime)
{
  if (!IsLineOffHook(line))
    return FALSE;

  if (!SetLineOnHook(line))
    return FALSE;

  PThread::Current()->Sleep(flashTime);

  return SetLineOffHook(line);
}


BOOL OpalLineInterfaceDevice::HasHookFlash(unsigned)
{
  return FALSE;
}


BOOL OpalLineInterfaceDevice::IsLineRinging(unsigned, DWORD *)
{
  return FALSE;
}


BOOL OpalLineInterfaceDevice::RingLine(unsigned, DWORD)
{
  return FALSE;
}


BOOL OpalLineInterfaceDevice::RingLine(unsigned, PINDEX, unsigned *)
{
  return FALSE;
}


BOOL OpalLineInterfaceDevice::IsLineDisconnected(unsigned line, BOOL)
{
  if (IsLineTerminal(line))
    return !IsLineOffHook(line);

  return IsToneDetected(line) == BusyTone;
}


BOOL OpalLineInterfaceDevice::SetLineToLineDirect(unsigned, unsigned, BOOL)
{
  return FALSE;
}


BOOL OpalLineInterfaceDevice::IsLineToLineDirect(unsigned, unsigned)
{
  return FALSE;
}


BOOL OpalLineInterfaceDevice::SetReadCodec(unsigned line,
                                           RTP_DataFrame::PayloadTypes codec)
{
  return SetReadFormat(line, OpalMediaFormat(codec));
}


BOOL OpalLineInterfaceDevice::SetWriteCodec(unsigned line,
                                            RTP_DataFrame::PayloadTypes codec)
{
  return SetWriteFormat(line, OpalMediaFormat(codec));
}


BOOL OpalLineInterfaceDevice::SetRawCodec(unsigned line)
{
  if (!SetReadFormat(line, OpalPCM16))
    return FALSE;

  if (SetWriteFormat(line, OpalPCM16))
    return TRUE;

  StopReadCodec(line);
  return FALSE;
}


BOOL OpalLineInterfaceDevice::StopReadCodec(unsigned)
{
  readDeblockingOffset = P_MAX_INDEX;
  return TRUE;
}


BOOL OpalLineInterfaceDevice::StopWriteCodec(unsigned)
{
  writeDeblockingOffset = 0;
  return TRUE;
}


BOOL OpalLineInterfaceDevice::StopRawCodec(unsigned line)
{
  BOOL ok = StopReadCodec(line);
  return StopWriteCodec(line) && ok;
}


BOOL OpalLineInterfaceDevice::SetReadFrameSize(unsigned, PINDEX)
{
  return FALSE;
}


BOOL OpalLineInterfaceDevice::SetWriteFrameSize(unsigned, PINDEX)
{
  return FALSE;
}


BOOL OpalLineInterfaceDevice::ReadBlock(unsigned line, void * buffer, PINDEX length)
{
  // Are reblocking the hardware frame sizes to those expected by the RTP packets.
  PINDEX frameSize = GetReadFrameSize(line);

  BYTE * bufferPtr = (BYTE *)buffer;

  PINDEX readBytes;
  while (length > 0) {
    if (readDeblockingOffset < frameSize) {
      PINDEX left = frameSize - readDeblockingOffset;
      if (left > length)
        left = length;
      memcpy(bufferPtr, &readDeblockingBuffer[readDeblockingOffset], left);
      readDeblockingOffset += left;
      bufferPtr += left;
      length -= left;
    }
    else if (length < frameSize) {
      BYTE * deblockPtr = readDeblockingBuffer.GetPointer(frameSize);
      if (!ReadFrame(line, deblockPtr, readBytes))
        return FALSE;
      readDeblockingOffset = 0;
    }
    else {
      if (!ReadFrame(line, bufferPtr, readBytes))
        return FALSE;
      bufferPtr += readBytes;
      length -= readBytes;
    }
  }

  return TRUE;
}


BOOL OpalLineInterfaceDevice::WriteBlock(unsigned line, const void * buffer, PINDEX length)
{
  PINDEX frameSize = GetWriteFrameSize(line);
  PINDEX written;

  // If zero length then flush any remaining data
  if (length == 0 && writeDeblockingOffset != 0) {
    SetWriteFrameSize(line, writeDeblockingOffset);
    BOOL ok = WriteFrame(line,
                         writeDeblockingBuffer.GetPointer(),
                         GetWriteFrameSize(line),
                         written);
    SetWriteFrameSize(line, frameSize);
    writeDeblockingOffset = 0;
    return ok;
  }

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

  while (length > 0) {
    // If have enough data and nothing in the reblocking buffer, just send it
    // straight on to the device.
    if (writeDeblockingOffset == 0 && length >= frameSize) {
      if (!WriteFrame(line, bufferPtr, frameSize, written))
        return FALSE;
      bufferPtr += written;
      length -= written;
    }
    else {
      BYTE * savedFramePtr = writeDeblockingBuffer.GetPointer(frameSize);

      // See if new chunk gives us enough for one frames worth
      if ((writeDeblockingOffset + length) < frameSize) {
        // Nope, just copy bytes into buffer and return
        memcpy(savedFramePtr + writeDeblockingOffset, bufferPtr, length);
        writeDeblockingOffset += length;
        return TRUE;
      }

      /* Calculate bytes we want from the passed in buffer to fill a frame by
         subtracting from full frame width the amount we have so far. This also
         means the lastWriteCount is set to the correct amount of buffer we are
         grabbing this time around.
       */
      PINDEX left = frameSize - writeDeblockingOffset;
      memcpy(savedFramePtr + writeDeblockingOffset, bufferPtr, left);
      writeDeblockingOffset = 0;

      // Write the saved frame out
      if (!WriteFrame(line, savedFramePtr, frameSize, written))
        return FALSE;

      bufferPtr += left;
      length -= left;
    }
  }

  return TRUE;
}


unsigned OpalLineInterfaceDevice::GetAverageSignalLevel(unsigned, BOOL)
{
  return UINT_MAX;
}


BOOL OpalLineInterfaceDevice::EnableAudio(unsigned line, BOOL enabled)
{
  return line < GetLineCount() && enabled;
}


BOOL OpalLineInterfaceDevice::IsAudioEnabled(unsigned line)
{
  return line < GetLineCount();
}


BOOL OpalLineInterfaceDevice::SetRecordVolume(unsigned, unsigned)
{
  return FALSE;
}

BOOL OpalLineInterfaceDevice::GetRecordVolume(unsigned, unsigned &)
{
  return FALSE;
}


BOOL OpalLineInterfaceDevice::SetPlayVolume(unsigned, unsigned)
{
  return FALSE;
}

BOOL OpalLineInterfaceDevice::GetPlayVolume(unsigned, unsigned &)

⌨️ 快捷键说明

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