19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * libjingle 39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Copyright 2004--2005, Google Inc. 49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * 59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Redistribution and use in source and binary forms, with or without 69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * modification, are permitted provided that the following conditions are met: 79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * 89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * 1. Redistributions of source code must retain the above copyright notice, 99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * this list of conditions and the following disclaimer. 109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * 2. Redistributions in binary form must reproduce the above copyright notice, 119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * this list of conditions and the following disclaimer in the documentation 129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * and/or other materials provided with the distribution. 139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * 3. The name of the author may not be used to endorse or promote products 149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * derived from this software without specific prior written permission. 159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * 169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifndef TALK_SESSION_PHONE_CALL_H_ 299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define TALK_SESSION_PHONE_CALL_H_ 309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <string> 329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <map> 339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <vector> 349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <deque> 359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "talk/base/messagequeue.h" 369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "talk/p2p/base/session.h" 379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "talk/p2p/client/socketmonitor.h" 389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "talk/xmpp/jid.h" 399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "talk/session/phone/audiomonitor.h" 409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "talk/session/phone/voicechannel.h" 419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallnamespace cricket { 439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallclass MediaSessionClient; 459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstruct CallOptions; 469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallclass Call : public talk_base::MessageHandler, public sigslot::has_slots<> { 489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall public: 499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Call(MediaSessionClient* session_client); 509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ~Call(); 519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Session *InitiateSession(const buzz::Jid &jid, const CallOptions& options); 539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void AcceptSession(BaseSession *session, const CallOptions& options); 549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void RejectSession(BaseSession *session); 559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void TerminateSession(BaseSession *session); 569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void Terminate(); 579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void SetLocalRenderer(VideoRenderer* renderer); 589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void SetVideoRenderer(BaseSession *session, uint32 ssrc, 599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall VideoRenderer* renderer); 609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void AddStream(BaseSession *session, uint32 voice_ssrc, uint32 video_ssrc); 619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void RemoveStream(BaseSession *session, uint32 voice_ssrc, uint32 video_ssrc); 629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void StartConnectionMonitor(BaseSession *session, int cms); 639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void StopConnectionMonitor(BaseSession *session); 649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void StartAudioMonitor(BaseSession *session, int cms); 659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void StopAudioMonitor(BaseSession *session); 669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void Mute(bool mute); 679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void PressDTMF(int event); 689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall const std::vector<Session *> &sessions(); 709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall uint32 id(); 719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall bool video() const { return video_; } 729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall bool muted() const { return muted_; } 739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // Setting this to false will cause the call to have a longer timeout and 759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // for the SignalSetupToCallVoicemail to never fire. 769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void set_send_to_voicemail(bool send_to_voicemail) { 779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall send_to_voicemail_ = send_to_voicemail; 789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall bool send_to_voicemail() { return send_to_voicemail_; } 809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // Sets a flag on the chatapp that will redirect the call to voicemail once 829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // the call has been terminated 839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sigslot::signal0<> SignalSetupToCallVoicemail; 849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sigslot::signal2<Call *, Session *> SignalAddSession; 859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sigslot::signal2<Call *, Session *> SignalRemoveSession; 869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sigslot::signal3<Call *, BaseSession *, BaseSession::State> 879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SignalSessionState; 889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sigslot::signal3<Call *, BaseSession *, Session::Error> 899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SignalSessionError; 909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sigslot::signal3<Call *, Session *, const std::string &> 919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SignalReceivedTerminateReason; 929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sigslot::signal2<Call *, const std::vector<ConnectionInfo> &> 939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SignalConnectionMonitor; 949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sigslot::signal2<Call *, const VoiceMediaInfo&> SignalMediaMonitor; 959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sigslot::signal2<Call *, const AudioInfo&> SignalAudioMonitor; 969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sigslot::signal2<Call *, const std::vector<ConnectionInfo> &> 979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SignalVideoConnectionMonitor; 989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sigslot::signal2<Call *, const VideoMediaInfo&> SignalVideoMediaMonitor; 999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall private: 1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void OnMessage(talk_base::Message *message); 1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void OnSessionState(BaseSession *session, BaseSession::State state); 1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void OnSessionError(BaseSession *session, Session::Error error); 1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void OnReceivedTerminateReason(Session *session, const std::string &reason); 1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void IncomingSession(Session *session, const SessionDescription* offer); 1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // Returns true on success. 1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall bool AddSession(Session *session, const SessionDescription* offer); 1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void RemoveSession(Session *session); 1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void EnableChannels(bool enable); 1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void Join(Call *call, bool enable); 1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void OnConnectionMonitor(VoiceChannel *channel, 1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall const std::vector<ConnectionInfo> &infos); 1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void OnMediaMonitor(VoiceChannel *channel, const VoiceMediaInfo& info); 1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void OnAudioMonitor(VoiceChannel *channel, const AudioInfo& info); 1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void OnConnectionMonitor(VideoChannel *channel, 1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall const std::vector<ConnectionInfo> &infos); 1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void OnMediaMonitor(VideoChannel *channel, const VideoMediaInfo& info); 1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall VoiceChannel* GetVoiceChannel(BaseSession* session); 1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall VideoChannel* GetVideoChannel(BaseSession* session); 1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall void ContinuePlayDTMF(); 1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall uint32 id_; 1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall MediaSessionClient *session_client_; 1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall std::vector<Session *> sessions_; 1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall std::map<std::string, VoiceChannel *> voice_channel_map_; 1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall std::map<std::string, VideoChannel *> video_channel_map_; 1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall VideoRenderer* local_renderer_; 1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall bool video_; 1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall bool muted_; 1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall bool send_to_voicemail_; 1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // DTMF tones have to be queued up so that we don't flood the call. We 1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // keep a deque (doubely ended queue) of them around. While one is playing we 1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // set the playing_dtmf_ bit and schedule a message in XX msec to clear that 1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall // bit or start the next tone playing. 1369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall std::deque<int> queued_dtmf_; 1379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall bool playing_dtmf_; 1389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall friend class MediaSessionClient; 1409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}; 1419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} // namespace cricket 1439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif // TALK_SESSION_PHONE_CALL_H_ 1459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall