使用openh323开发(8)

2019-01-18 22:26

#ifdef SPEEX_CODEC

if (!speexOgm.IsEmpty())

SetCapability(0, 0, new SpeexNarrow3AudioCapability()); #endif

capabilities.Remove(args.GetOptionString(D).Lines()); capabilities.Reorder(args.GetOptionString(P).Lines()); cout << \capabilities < < endl; return TRUE; }

/////////////////////////////////////////////////////////////// //录音通道, 解码对象所附着的通道 //写文件

PCM_RecordFile::PCM_RecordFile(MyH323Connection & _conn, const PFilePath & _fn

, unsigned _callLimit)

: conn(_conn), fn(_fn), callLimit(_callLimit) {

recordStarted = FALSE; timeLimitExceeded = FALSE; closed = FALSE;

dataWritten = FALSE;

// If the file name ends in .wav then open the output as a WAV file. // Otherwise open it as a raw file. if ((_fn.Right(4)).ToLower() == \

fileclass = new PWAVFile(_fn, PFile::WriteOnly, PFile::ModeDefault,PWAVFile::PCM_WavFile); else

fileclass = new PFile(_fn, PFile::WriteOnly); }

void PCM_RecordFile::StartRecording() {

PWaitAndSignal mutex(pcmrecordMutex); if (recordStarted) return;

PTRACE(1, \PTime now;

recordStarted = TRUE;

finishTime = now + (callLimit * 1000); }

BOOL PCM_RecordFile::Close() {

PWaitAndSignal mutex(pcmrecordMutex); closed = TRUE;

return fileclass->Close(); }

BOOL PCM_RecordFile::Write(const void * buf, PINDEX len) {

// Wait for the mutex, and Signal it at the end of this function PWaitAndSignal mutex(pcmrecordMutex);

// If the record file has been closed, or if the time limit has // been exceeded, then return immediatly. if (closed || timeLimitExceeded) return FALSE; if (!recordStarted) { DelayFrame(len); return TRUE; }

PTime now;

if ((callLimit != 0) && (now >= finishTime)) { PTRACE(1, \conn.ClearCall();

timeLimitExceeded = TRUE; return TRUE; }

DelayFrame(len); dataWritten = TRUE;

return WriteFrame(buf, len); }

BOOL PCM_RecordFile::WriteFrame(const void * buf, PINDEX len) {

//cerr << \return fileclass->Write(buf, len); }

void PCM_RecordFile::DelayFrame(PINDEX len) {

delay.Delay(len/16); }

PCM_RecordFile::~PCM_RecordFile() {

PWaitAndSignal mutex(pcmrecordMutex);

if (!dataWritten) {

PTRACE(1, \fileclass->Remove(fn); }

delete fileclass; }

/////////////////////////////////////////////////////////////// // Override some of the PCM_RecordFile functions to write // G723.1 data instead of PCM data.

G7231_RecordFile::G7231_RecordFile(MyH323Connection & _conn, const PFilePath &

_fn, unsigned _callLimit)

: PCM_RecordFile(_conn, _fn, _callLimit) {

// If the record file is a .wav file, we need to close the file

// that PCM_RecordFile will have opened, and reopen it as a G.723.1 Wav file.

if ((_fn.Right(4)).ToLower() == \fileclass->Remove(_fn); delete fileclass;

fileclass = new PWAVFile(_fn, PFile::WriteOnly, PFile::ModeDefault,PWAVFile::G7231_WavFile); } }

BOOL G7231_RecordFile::WriteFrame(const void * buf, PINDEX /*len*/) {

int frameLen = G7231_File_Codec::GetFrameLen(*(BYTE *)buf); // cerr << \return fileclass->Write(buf, frameLen); }

void G7231_RecordFile::DelayFrame(PINDEX /*len*/) {

// Ignore the len parameter as that is the compressed size. // We must delay by the actual sample time. delay.Delay((G7231_SAMPLES_PER_BLOCK*2)/16); }

/////////////////////////////////////////////////////////////// static BOOL MatchString(const PString & str1, const PString str2) {

if (str1.GetLength() != str2.GetLength()) return FALSE;

PINDEX len = str1.GetLength();

PINDEX i;

for (i = 0; i < len; i++)

if ((str1[i] != ?) && (str2[i] != ?) && (str1[i] != str2[i])) return FALSE; return TRUE; }

static PINDEX FindMatch(const PStringList & list, const PString & key) {

PINDEX maxKeyLen = 0; PINDEX i;

PINDEX keyLen = key.GetLength(); PINDEX listLen = list.GetSize();

for (i = 0; i < listLen; i++)

maxKeyLen = PMAX(maxKeyLen, list[i].GetLength()); if (keyLen == 0 || maxKeyLen == 0) return P_MAX_INDEX;

if (keyLen > maxKeyLen) return P_MAX_INDEX;

PINDEX len = 1;

while (len <= keyLen) {

PString subStr = key.Left(len); PINDEX matches = 0;

PINDEX lastMatch = P_MAX_INDEX; PINDEX i;

// look for a match to the substring for (i = 0; i < list.GetSize(); i++) {

if ((list[i].GetLength() >= keyLen) && MatchString(list[i].Left(len), subStr)) {

matches++;

lastMatch = i; } }

// if we got ONE match, we have a winner if (matches == 1) return lastMatch+1;

// if we have no matches, then there is no point continuing if (matches == 0) return P_MAX_INDEX;

// if we have more than one match, try the next char len++; }

// too many matches return 0; }

MyH323Connection::MyH323Connection(MyH323EndPoint & _ep, unsigned callReferenc e)

: H323Connection(_ep, callReference), ep(_ep) {

basename = psprintf(\callStartTime.GetYear(), call


使用openh323开发(8).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:(2018年秋)人教版小学六年级语文上册第一单元1.山中访友 教案

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: