00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 #ifndef __LIDS_LIDEP_H
00099 #define __LIDS_LIDEP_H
00100
00101 #ifdef P_USE_PRAGMA
00102 #pragma interface
00103 #endif
00104
00105
00106 #include <opal/endpoint.h>
00107 #include <lids/lid.h>
00108 #include <codec/silencedetect.h>
00109
00110
00111 class OpalLineConnection;
00112
00113
00118 class OpalLIDEndPoint : public OpalEndPoint
00119 {
00120 PCLASSINFO(OpalLIDEndPoint, OpalEndPoint);
00121
00122 public:
00127 OpalLIDEndPoint(
00128 OpalManager & manager,
00129 const PString & prefix,
00130 unsigned attributes
00131 );
00132
00134 ~OpalLIDEndPoint();
00136
00168 virtual BOOL MakeConnection(
00169 OpalCall & call,
00170 const PString & party,
00171 void * userData = NULL
00172 );
00173
00183 virtual OpalMediaFormatList GetMediaFormats() const;
00185
00188 OpalLineConnection * CreateConnection(
00189 OpalCall & call,
00190 OpalLine & line,
00191 void * userData,
00192 const PString & number
00193 );
00195
00202 PSafePtr<OpalLineConnection> GetLIDConnectionWithLock(
00203 const PString & token,
00204 PSafetyMode mode = PSafeReadWrite
00205 ) { return PSafePtrCast<OpalConnection, OpalLineConnection>(GetConnectionWithLock(token, mode)); }
00206
00214 BOOL AddLine(
00215 OpalLine * line
00216 );
00217
00221 void RemoveLine(
00222 OpalLine * line
00223 );
00224
00228 void RemoveLine(
00229 const PString & token
00230 );
00231
00236 void RemoveAllLines();
00237
00247 BOOL AddLinesFromDevice(
00248 OpalLineInterfaceDevice & device
00249 );
00250
00254 void RemoveLinesFromDevice(
00255 OpalLineInterfaceDevice & device
00256 );
00257
00263 BOOL AddDeviceNames(
00264 const PStringArray & descriptors
00265 );
00266
00276 BOOL AddDeviceName(
00277 const PString & descriptor
00278 );
00279
00291 BOOL AddDevice(
00292 OpalLineInterfaceDevice * device
00293 );
00294
00298 void RemoveDevice(
00299 OpalLineInterfaceDevice * device
00300 );
00301
00309 OpalLine * GetLine(
00310 const PString & lineName,
00311 BOOL enableAudio = FALSE
00312 ) const;
00313
00317 void SetDefaultLine(
00318 const PString & lineName
00319 );
00321
00322 protected:
00323 PDECLARE_NOTIFIER(PThread, OpalLIDEndPoint, MonitorLines);
00324 virtual void MonitorLine(OpalLine & line);
00325
00326 OpalLIDList devices;
00327 OpalLineList lines;
00328 PString defaultLine;
00329 PMutex linesMutex;
00330 PThread * monitorThread;
00331 PSyncPoint exitFlag;
00332 };
00333
00334
00339 class OpalPSTNEndPoint : public OpalLIDEndPoint
00340 {
00341 PCLASSINFO(OpalLIDEndPoint, OpalLIDEndPoint);
00342
00343 public:
00348 OpalPSTNEndPoint(
00349 OpalManager & manager,
00350 const char * prefix = "pstn"
00351 ) : OpalLIDEndPoint(manager, prefix, HasLineInterface) { }
00353 };
00354
00355
00360 class OpalPOTSEndPoint : public OpalLIDEndPoint
00361 {
00362 PCLASSINFO(OpalPOTSEndPoint, OpalLIDEndPoint);
00363
00364 public:
00369 OpalPOTSEndPoint(
00370 OpalManager & manager,
00371 const char * prefix = "pots"
00372 ) : OpalLIDEndPoint(manager, prefix, CanTerminateCall) { }
00374 };
00375
00376
00379 class OpalLineConnection : public OpalConnection
00380 {
00381 PCLASSINFO(OpalLineConnection, OpalConnection);
00382
00383 public:
00388 OpalLineConnection(
00389 OpalCall & call,
00390 OpalLIDEndPoint & endpoint,
00391 OpalLine & line,
00392 const PString & number
00393 );
00395
00404 virtual BOOL SetUpConnection();
00405
00416 virtual BOOL SetAlerting(
00417 const PString & calleeName,
00418 BOOL withMedia
00419 );
00420
00425 virtual BOOL SetConnected();
00426
00445 virtual void OnReleased();
00446
00453 virtual PString GetDestinationAddress();
00454
00461 virtual OpalMediaFormatList GetMediaFormats() const;
00462
00477 virtual OpalMediaStream * CreateMediaStream(
00478 const OpalMediaFormat & mediaFormat,
00479 unsigned sessionID,
00480 BOOL isSource
00481 );
00482
00495 virtual BOOL OnOpenMediaStream(
00496 OpalMediaStream & stream
00497 );
00498
00506 virtual BOOL SendUserInputString(
00507 const PString & value
00508 );
00509
00516 virtual BOOL SendUserInputTone(
00517 char tone,
00518 int duration
00519 );
00520
00527 virtual BOOL PromptUserInput(
00528 BOOL play
00529 );
00531
00536 void StartIncoming();
00537
00540 void Monitor(
00541 BOOL offHook
00542 );
00544
00545
00546 protected:
00547 OpalLIDEndPoint & endpoint;
00548 OpalLine & line;
00549 BOOL wasOffHook;
00550 unsigned answerRingCount;
00551 BOOL requireTonesForDial;
00552
00553 PDECLARE_NOTIFIER(PThread, OpalLineConnection, HandleIncoming);
00554 PThread * handlerThread;
00555 };
00556
00557
00561 class OpalLineMediaStream : public OpalMediaStream
00562 {
00563 PCLASSINFO(OpalLineMediaStream, OpalMediaStream);
00564 public:
00569 OpalLineMediaStream(
00570 const OpalMediaFormat & mediaFormat,
00571 unsigned sessionID,
00572 BOOL isSource,
00573 OpalLine & line
00574 );
00576
00584 virtual BOOL Open();
00585
00590 virtual BOOL Close();
00591
00595 virtual BOOL ReadData(
00596 BYTE * data,
00597 PINDEX size,
00598 PINDEX & length
00599 );
00600
00604 virtual BOOL WriteData(
00605 const BYTE * data,
00606 PINDEX length,
00607 PINDEX & written
00608 );
00609
00613 virtual BOOL IsSynchronous() const;
00615
00616 protected:
00617 OpalLine & line;
00618 BOOL useDeblocking;
00619 unsigned missedCount;
00620 BYTE lastSID[4];
00621 BOOL lastFrameWasSignal;
00622 };
00623
00624
00625 class OpalLineSilenceDetector : public OpalSilenceDetector
00626 {
00627 PCLASSINFO(OpalLineSilenceDetector, OpalSilenceDetector);
00628 public:
00633 OpalLineSilenceDetector(
00634 OpalLine & line
00635 );
00637
00648 virtual unsigned GetAverageSignalLevel(
00649 const BYTE * buffer,
00650 PINDEX size
00651 );
00653
00654 protected:
00655 OpalLine & line;
00656 };
00657
00658
00659 #endif // __LIDS_LIDEP_H
00660
00661
00662