main.h
上传用户:wzkunzhan
上传日期:2022-04-23
资源大小:2618k
文件大小:9k
- /*
- * main.h
- *
- * PWLib application header file for Voxilla
- *
- * A H.323 Beacon Server 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.
- *
- * Portions are Copyright (C) 2002 ITEC-Ohio.
- */
- #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 H323BeaconServer : public PProcess
- {
- PCLASSINFO(H323BeaconServer, PProcess)
- public:
- PString getLocalhostIPAddress();
- H323BeaconServer();
- ~H323BeaconServer();
- void Main();
- void RecordFile(PArgList & args);
- void PlayFile(PArgList & args);
- protected:
- long GetCodec(const PString & codecname);
- OpalLineInterfaceDevice * GetDevice(const PString & device);
- };
- class MyH323EndPoint : public H323EndPoint
- {
- PCLASSINFO(MyH323EndPoint, H323EndPoint);
- public:
- 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 &);
- //void OnConnectionEstablished( H323Connection & , 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;
- BOOL recordWav;
- };
- class PCM_RecordFile;
- class MyH323Connection;
- PQUEUE(PStringQueue, PString);
- class PCM_OGMChannel : public PIndirectChannel
- {
- PCLASSINFO(PCM_OGMChannel, PIndirectChannel);
- public:
- PCM_OGMChannel(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;
- MyH323Connection & conn;
- PMutex chanMutex;
- int silentCount;
- int totalData;
- BOOL recordTrigger, hangupTrigger;
- BOOL closed;
- BOOL playOnce;
- PAdaptiveDelay ogm_delay;
- PBYTEArray frameBuffer;
- PINDEX frameLen, frameOffs;
- };
- class G7231_OGMChannel : public PCM_OGMChannel
- {
- PCLASSINFO(G7231_OGMChannel, PCM_OGMChannel);
- public:
- G7231_OGMChannel(MyH323Connection & conn);
- protected:
- BOOL ReadFrame(PINDEX amount);
- void CreateSilenceFrame(PINDEX amount);
- void Synchronise(PINDEX amount);
- BOOL IsWAVFileValid(PWAVFile *chan);
- };
- class MyH323Connection : public H323Connection
- {
- PCLASSINFO(MyH323Connection, H323Connection);
- public:
- MyH323Connection(MyH323EndPoint &, unsigned);
- ~MyH323Connection();
- // overrides from H323Connection
- BOOL OpenAudioChannel(BOOL, unsigned, H323AudioCodec & codec);
- AnswerCallResponse OnAnswerCall(const PString &, const H323SignalPDU &, H323SignalPDU &);
- void OnUserInputString(const PString & value);
- BOOL OnStartLogicalChannel(H323Channel & channel);
- //int SendTraceRtToClient(PString clientIP, PString *message);
- // new functions
- void StartRecording();
- void Hangup();
- int log_server();
- 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 MyH323EndPoint & ep;
- PString product;
- PTime callStartTime;
- PTime recordStartTime;
- PString basename;
- PFilePath recordFn;
- PString transmitCodecName, receiveCodecName;
- BOOL recordTrigger;
- PMutex connMutex;
- //PCM_RecordFile * recordFile;
- PCM_OGMChannel * ogmChannel;
- PString digits, lastDigits;
- int currentMenu;
- PStringList menuNames;
- PString securityToken, e164Number;
- };
- class PCM_RecordFile : public PIndirectChannel
- {
- PCLASSINFO(PCM_RecordFile, PIndirectChannel)
- public:
- PCM_RecordFile(MyH323Connection & conn, const PFilePath & fn, unsigned callLimit);
- ~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:
- 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 G7231_RecordFile : public PCM_RecordFile
- {
- PCLASSINFO(G7231_RecordFile, PCM_RecordFile);
- public:
- G7231_RecordFile(MyH323Connection & conn, const PFilePath & fn, unsigned callLimit);
- void DelayFrame(PINDEX len);
- BOOL WriteFrame(const void * buf, PINDEX len);
- };
- /*class G7231_File_Codec : public H323AudioCodec
- {
- PCLASSINFO(G7231_File_Codec, H323AudioCodec);
- public:
- G7231_File_Codec(Direction dir);
- unsigned GetBandwidth() const;
- static int GetFrameLen(int val);
-
- BOOL Read(BYTE * buffer, unsigned & length, RTP_DataFrame &);
- BOOL Write(const BYTE * buffer, unsigned length, const RTP_DataFrame & rtp, unsigned & frames);
- };
- class G7231_File_Capability : public H323AudioCapability
- {
- PCLASSINFO(G7231_File_Capability, H323AudioCapability)
- public:
- G7231_File_Capability();
- unsigned GetSubType() const { return H245_AudioCapability::e_g7231; }
- PString GetFormatName() const { return "G.723.1"; }
- H323Codec * CreateCodec(H323Codec::Direction direction) const;
- BOOL OnSendingPDU(H245_AudioCapability & cap, unsigned packetSize) const;
- BOOL OnReceivedPDU(const H245_AudioCapability & pdu, unsigned & packetSize);
- PObject * Clone() const;
- };
- */
- #endif // _Voxilla_MAIN_H
- // End of File ///////////////////////////////////////////////////////////////