callermain.h
上传用户:wzkunzhan
上传日期:2022-04-23
资源大小:2618k
文件大小:8k
- /*
- * main.h
- *
- * PWLib application header file for Voxilla
- *
- * A H.323 "net telephone" application.
- *
- * Copyright (c) 1993-2001 Equivalence Pty. Ltd.
- *
- * 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 this code were written with the assisance of funding from
- * Vovida Networks, Inc. http://www.vovida.com.
- *
- * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
- * All Rights Reserved.
- *
- * Contributor(s): ______________________________________.
- *
- *
- *
- */
- //#ifndef _Voxilla_MAIN_H
- //#define _Voxilla_MAIN_H
- #include <h323.h>
- #include <h323pdu.h>
- #include <h245.h>
- #include <gsmcodec.h>
- #include <lid.h>
- #include <ptclib/pwavfile.h>
- #include <ptclib/delaychan.h>
- //class Caller : public PProcess
- class Caller : public PObject
- {
- PCLASSINFO(Caller, PObject)
- public:
- Caller();
- ~Caller();
- void CallerMain(PString Cargs);
- void RecordFile(PArgList & args);
- void PlayFile(PArgList & args);
- protected:
- long GetCodec(const PString & codecname);
- OpalLineInterfaceDevice * GetDevice(const PString & device);
- };
- //Caller * caller;
- class C_MyH323EndPoint : public H323EndPoint
- {
- PCLASSINFO(C_MyH323EndPoint, H323EndPoint);
- public:
- C_MyH323EndPoint(unsigned callLimit,
- const PString & runCmd,
- const PDirectory & dir,
- int flags);
- // overrides from H323EndPoint
- virtual H323Connection * CreateConnection(unsigned callReference);
- BOOL OnIncomingCall(H323Connection &, const H323SignalPDU &, H323SignalPDU &);
- // Alteracoes para o Caller
- BOOL OnAlerting( H323Connection & , const H323SignalPDU & , const PString &
- );
- void OnConnectionEstablished( H323Connection & , const PString & );
- void OnConnectionCleared( H323Connection & , const PString & );
- void AwaitTermination();
- BOOL MakeOutgoingCall(const PString &);
- // new functions
- BOOL Initialise(PConfigArgs & args);
- PString GetGSMOGM() const { return gsmOgm; }
- void SetGSMOGM(const PString & s) { gsmOgm = s; }
- PString GetG711OGM() const { return g711Ogm; }
- void SetG711OGM(const PString & s) { g711Ogm = s; }
- PString GetLPC10OGM() const { return lpc10Ogm; }
- void SetLPC10OGM(const PString & s) { lpc10Ogm = s; }
- PString GetSPEEXOGM() const { return speexOgm; }
- void SetSPEEXOGM(const PString & s) { speexOgm = s; }
- PString GetG7231OGM() const { return g7231Ogm; }
- void SetG7231OGM(const PString & s) { g7231Ogm = s; }
- unsigned GetCallLimit() const { return callLimit; }
- PString GetRunCmd() const { return runCmd; }
- PDirectory GetDirectory() const { return dir; }
- void SetRecordWav(const BOOL rec){ recordWav = rec; }
- BOOL GetRecordWav() const { return recordWav; }
- enum {
- DeleteAfterRecord = 0x01,
- NoRecordG7231 = 0x02,
- HangupAfterPlay = 0x04
- };
- BOOL GetDeleteAfterRecord() const { return flags & DeleteAfterRecord; }
- BOOL GetNoRecordG7231() const { return flags & NoRecordG7231; }
- BOOL GetHangupAfterPlay() const { return flags & HangupAfterPlay; }
- protected:
- unsigned callLimit;
- PString pcmOgm, g711Ogm, gsmOgm, lpc10Ogm, g7231Ogm, runCmd;
- PString speexOgm;
- PDirectory dir;
- int flags;
- // Variaveis usadas pelo caller
- PString currentCallToken;
- enum {
- InCall = 0x00,
- CallClosed=0x01,
- CallInit=0x02
- } StateFlag ;
- BOOL recordWav;
- };
- class C_PCM_RecordFile;
- class C_MyH323Connection;
- PQUEUE(PStringQueue, PString);
- class C_PCM_OGMChannel : public PIndirectChannel
- {
- PCLASSINFO(C_PCM_OGMChannel, PIndirectChannel);
- public:
- C_PCM_OGMChannel(C_MyH323Connection & conn);
- BOOL Read(void * buffer, PINDEX amount);
- void PlayFile(PFile * chan);
- BOOL Close();
- void QueueFile(const PString & cmd);
- void FlushQueue();
- void SetRecordTrigger();
- void SetHangupTrigger();
- void SetPlayOnce() { playOnce = TRUE; }
- protected:
- virtual BOOL ReadFrame(PINDEX amount);
- virtual void CreateSilenceFrame(PINDEX amount);
- virtual void Synchronise(PINDEX amount);
- virtual BOOL IsWAVFileValid(PWAVFile *chan);
- BOOL AdjustFrame(void * buffer, PINDEX amount);
- PStringQueue playQueue;
- C_MyH323Connection & conn;
- PMutex chanMutex;
- int silentCount;
- int totalData;
- BOOL recordTrigger, hangupTrigger;
- BOOL closed;
- BOOL playOnce;
- PAdaptiveDelay ogm_delay;
- PBYTEArray frameBuffer;
- PINDEX frameLen, frameOffs;
- };
- class C_G7231_OGMChannel : public C_PCM_OGMChannel
- {
- PCLASSINFO(C_G7231_OGMChannel, C_PCM_OGMChannel);
- public:
- C_G7231_OGMChannel(C_MyH323Connection & conn);
- protected:
- BOOL ReadFrame(PINDEX amount);
- void CreateSilenceFrame(PINDEX amount);
- void Synchronise(PINDEX amount);
- BOOL IsWAVFileValid(PWAVFile *chan);
- };
- class C_MyH323Connection : public H323Connection
- {
- PCLASSINFO(C_MyH323Connection, H323Connection);
- public:
- C_MyH323Connection(C_MyH323EndPoint &, unsigned);
- ~C_MyH323Connection();
- // overrides from H323Connection
- BOOL OpenAudioChannel(BOOL, unsigned, H323AudioCodec & codec);
- AnswerCallResponse OnAnswerCall(const PString &, const H323SignalPDU &, H323SignalPDU &);
- BOOL OnStartLogicalChannel(H323Channel & channel);
- void OnUserInputString(const PString & value);
- // new functions
- void StartRecording();
- void Hangup();
- void SetE164Number(const PString & _num)
- { e164Number = _num; }
- PString GetE164Number() const
- { return e164Number; }
- protected:
- void OnUserInputChar(char ch);
- BOOL StartMenu(int menuNumber);
- BOOL ProcessMenuCmd(const PString & cmdStr);
- const C_MyH323EndPoint & ep;
- PString product;
- PTime callStartTime;
- PTime recordStartTime;
- PString basename;
- PFilePath recordFn;
- PString transmitCodecName, receiveCodecName;
- BOOL recordTrigger;
- PMutex connMutex;
- C_PCM_RecordFile * recordFile;
- C_PCM_OGMChannel * ogmChannel;
- PString digits, lastDigits;
- int currentMenu;
- PStringList menuNames;
- PString securityToken, e164Number;
- };
- class C_PCM_RecordFile : public PIndirectChannel
- {
- PCLASSINFO(C_PCM_RecordFile, PIndirectChannel)
- public:
- C_PCM_RecordFile(C_MyH323Connection & conn, const PFilePath & fn, unsigned callLimit);
- ~C_PCM_RecordFile();
- BOOL Write(const void * buf, PINDEX len);
- BOOL Close();
- void StartRecording();
- virtual void DelayFrame(PINDEX len);
- virtual BOOL WriteFrame(const void * buf, PINDEX len);
- BOOL WasRecordStarted() const { return recordStarted; }
- protected:
- C_MyH323Connection & conn;
- PTime finishTime;
- PFilePath fn;
- unsigned callLimit;
- BOOL recordStarted;
- BOOL timeLimitExceeded;
- BOOL closed;
- BOOL isPCM;
- BOOL dataWritten;
- PAdaptiveDelay delay;
- PMutex pcmrecordMutex;
- PFile *fileclass; // will point to a PWAVFile or PFile class
- };
- class C_G7231_RecordFile : public C_PCM_RecordFile
- {
- PCLASSINFO(C_G7231_RecordFile, C_PCM_RecordFile);
- public:
- C_G7231_RecordFile(C_MyH323Connection & conn, const PFilePath & fn, unsigned callLimit);
- void DelayFrame(PINDEX len);
- BOOL WriteFrame(const void * buf, PINDEX len);
- };
- //#endif // _Voxilla_MAIN_H
- // End of File ///////////////////////////////////////////////////////////////