AmSession.h
Go to the documentation of this file.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 #ifndef _AmSession_h_
00029 #define _AmSession_h_
00030
00031 #include "AmRtpStream.h"
00032 #include "AmThread.h"
00033 #include "AmEventQueue.h"
00034 #include "AmRtpAudio.h"
00035 #include "AmDtmfDetector.h"
00036 #include "AmSipMsg.h"
00037 #include "AmSipDialog.h"
00038 #include "AmSipEvent.h"
00039 #include "AmApi.h"
00040
00041 #ifdef WITH_ZRTP
00042 #include "zrtp/zrtp.h"
00043 #endif
00044
00045 #include <string>
00046 #include <vector>
00047 #include <queue>
00048 #include <map>
00049 using std::string;
00050 using std::vector;
00051
00052 class AmSessionFactory;
00053 class AmDtmfEvent;
00054
00057
00058 #define FL_FORCE_ACTIVE 2
00059
00065 class AmSessionEventHandler
00066 : public ArgObject
00067 {
00068 public:
00069 bool destroy;
00070
00071 AmSessionEventHandler()
00072 : destroy(true) {}
00073
00074 virtual ~AmSessionEventHandler() {}
00075
00076
00077
00078
00079 virtual bool process(AmEvent*);
00080 virtual bool onSipEvent(AmSipEvent*);
00081 virtual bool onSipRequest(const AmSipRequest&);
00082 virtual bool onSipReply(const AmSipReply&);
00083
00084 virtual bool onSendRequest(const string& method,
00085 const string& content_type,
00086 const string& body,
00087 string& hdrs,
00088 int flags,
00089 unsigned int cseq);
00090
00091 virtual bool onSendReply(const AmSipRequest& req,
00092 unsigned int code,
00093 const string& reason,
00094 const string& content_type,
00095 const string& body,
00096 string& hdrs,
00097 int flags);
00098 };
00099
00100
00101
00102 #define AM_AUDIO_IN 0
00103 #define AM_AUDIO_OUT 1
00104
00110 class AmSession : public AmThread,
00111 public AmEventQueue,
00112 public AmEventHandler,
00113 public AmSipDialogEventHandler
00114 {
00115 AmMutex audio_mut;
00116
00117 AmAudio* input;
00118 AmAudio* output;
00119
00120
00121 AmAudio* local_input;
00122 AmAudio* local_output;
00123
00124 bool use_local_audio[2];
00125 protected:
00126 vector<SdpPayload *> m_payloads;
00127 bool negotiate_onreply;
00128
00129 private:
00130 AmDtmfDetector m_dtmfDetector;
00131 AmDtmfEventQueue m_dtmfEventQueue;
00132 bool m_dtmfDetectionEnabled;
00133
00134 vector<AmSessionEventHandler*> ev_handlers;
00135
00137 void run();
00138
00140 void on_stop();
00141
00142 AmCondition<bool> sess_stopped;
00143 AmCondition<bool> detached;
00144
00145 friend class AmMediaProcessor;
00146 friend class AmMediaProcessorThread;
00147 friend class AmSessionContainer;
00148 friend class AmSessionFactory;
00149
00150 protected:
00151 AmSdp sdp;
00152
00155 string callgroup;
00156
00158 bool accept_early_session;
00159
00160 public:
00161
00162 AmRtpAudio rtp_str;
00163
00164 #ifdef WITH_ZRTP
00165 zrtp_conn_ctx_t* zrtp_session;
00166 zrtp_stream_ctx_t* zrtp_audio;
00167
00169 bool enable_zrtp;
00170 #endif
00171
00172 AmSipDialog dlg;
00173
00179 struct Exception {
00180 int code;
00181 string reason;
00182 Exception(int c, string r) : code(c), reason(r) {}
00183 };
00184
00188 AmSession();
00189
00190 virtual ~AmSession();
00191
00195 virtual void process(AmEvent*);
00196
00203 void addHandler(AmSessionEventHandler*);
00204
00211 void setCallgroup(const string& cg);
00212 string getCallgroup() { return callgroup; }
00213
00217 void changeCallgroup(const string& cg);
00218
00223 int acceptAudio(const string& body,
00224 const string& hdrs = "",
00225 string* sdp_reply=0);
00226
00231 void lockAudio();
00236 void unlockAudio();
00237
00242 AmAudio* getInput() { return input; }
00247 AmAudio* getOutput(){ return output;}
00248
00253 void setInput(AmAudio* in);
00254 void setOutput(AmAudio* out);
00255 void setInOut(AmAudio* in, AmAudio* out);
00256
00257
00262 AmAudio* getLocalInput() { return local_input; }
00267 AmAudio* getLocalOutput(){ return local_output;}
00268
00273 void setLocalInput(AmAudio* in);
00274 void setLocalOutput(AmAudio* out);
00275 void setLocalInOut(AmAudio* in, AmAudio* out);
00276
00280 void setAudioLocal(unsigned int dir, bool local);
00281 bool getAudioLocal(unsigned int dir);
00282
00286 void clearAudio();
00287
00289 void setMute(bool mute) { rtp_str.mute = mute; }
00290
00292 void setReceiving(bool receive) { rtp_str.receiving = receive; }
00293
00295 const string& getCallID() const;
00296
00298 const string& getRemoteTag()const ;
00299
00301 const string& getLocalTag() const;
00302
00304 void setLocalTag();
00305
00307 void setLocalTag(const string& tag);
00308
00310 void setUri(const string& uri);
00311
00313 const vector<SdpPayload*>& getPayloads();
00314
00316 int getRPort();
00317
00319 void setNegotiateOnReply(bool n) { negotiate_onreply = n; }
00320
00322 virtual AmPayloadProviderInterface* getPayloadProvider();
00323
00325 virtual void negotiate(const string& sdp_body,
00326 bool force_symmetric_rtp,
00327 string* sdp_reply);
00328
00330 void sendUpdate();
00332 void sendReinvite(bool updateSDP = true, const string& headers = "");
00334 int sendInvite(const string& headers = "");
00335
00337 void setOnHold(bool hold);
00338
00345 void destroy();
00346
00352 void setStopped() { sess_stopped.set(true); }
00353
00357 bool getStopped() { return sess_stopped.get(); }
00358
00360 bool getDetached() { return detached.get(); }
00361
00365 static string getNewId();
00366
00370 void postDtmfEvent(AmDtmfEvent *);
00371
00372 void processDtmfEvents();
00373
00374 void setInbandDetector(Dtmf::InbandDetectorType t);
00375 bool isDtmfDetectionEnabled() { return m_dtmfDetectionEnabled; }
00376 void setDtmfDetectionEnabled(bool e) { m_dtmfDetectionEnabled = e; }
00377 void putDtmfAudio(const unsigned char *buf, int size, int user_ts);
00379 virtual void onDtmf(int event, int duration);
00380
00384 virtual void onStart(){}
00385
00390 virtual void onInvite(const AmSipRequest& req);
00391
00404 virtual void onCancel(){}
00405
00415 virtual void onSessionStart(const AmSipRequest& req){}
00416
00427 virtual void onSessionStart(const AmSipReply& reply){}
00428
00429
00435 virtual void onEarlySessionStart(const AmSipReply& reply){}
00436
00441 virtual void onRinging(const AmSipReply& reply){}
00442
00446 virtual void onBye(const AmSipRequest& req);
00447
00451 virtual void onSipEvent(AmSipEvent* sip_ev);
00452 virtual void onSipRequest(const AmSipRequest& req);
00453 virtual void onSipReply(const AmSipReply& reply);
00454
00455
00456
00457 #ifdef WITH_ZRTP
00458
00461 virtual void onZRTPEvent(zrtp_event_t event, zrtp_stream_ctx_t *stream_ctx);
00462 #endif
00463
00465 virtual void onRtpTimeout();
00466
00467
00468 virtual void onSendRequest(const string& method,
00469 const string& content_type,
00470 const string& body,
00471 string& hdrs,
00472 int flags,
00473 unsigned int cseq);
00474
00475 virtual void onSendReply(const AmSipRequest& req,
00476 unsigned int code,
00477 const string& reason,
00478 const string& content_type,
00479 const string& body,
00480 string& hdrs,
00481 int flags);
00482
00483
00484 string advertisedIP();
00485 };
00486
00487 #endif
00488
00489
00490
00491
00492
Generated on Fri May 16 12:02:05 2008 for SEMS by
1.5.1