15976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org/*
25976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * libjingle
35976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * Copyright 2004 Google Inc.
45976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *
55976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * Redistribution and use in source and binary forms, with or without
65976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * modification, are permitted provided that the following conditions are met:
75976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *
85976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *  1. Redistributions of source code must retain the above copyright notice,
95976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *     this list of conditions and the following disclaimer.
105976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *  2. Redistributions in binary form must reproduce the above copyright notice,
115976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *     this list of conditions and the following disclaimer in the documentation
125976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *     and/or other materials provided with the distribution.
135976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *  3. The name of the author may not be used to endorse or promote products
145976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *     derived from this software without specific prior written permission.
155976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *
165976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
175976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
185976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
195976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
205976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
215976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
225976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
235976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
245976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
255976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
265976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org */
275976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
285976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#ifndef TALK_SESSION_MEDIA_MEDIASESSIONCLIENT_H_
295976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#define TALK_SESSION_MEDIA_MEDIASESSIONCLIENT_H_
305976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
315976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include <string>
325976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include <vector>
335976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include <map>
345976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include <algorithm>
355976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/base/messagequeue.h"
365976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/base/sigslot.h"
375976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/base/sigslotrepeater.h"
385976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/base/thread.h"
395976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/media/base/cryptoparams.h"
405976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/p2p/base/session.h"
415976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/p2p/base/sessionclient.h"
425976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/p2p/base/sessiondescription.h"
435976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/p2p/base/sessionmanager.h"
445976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/session/media/call.h"
455976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/session/media/channelmanager.h"
465976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/session/media/mediasession.h"
475976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
485976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgnamespace cricket {
495976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
505976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgclass Call;
515976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
525976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgclass MediaSessionClient : public SessionClient, public sigslot::has_slots<> {
535976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org public:
545976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#if !defined(DISABLE_MEDIA_ENGINE_FACTORY)
555976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  MediaSessionClient(const buzz::Jid& jid, SessionManager *manager);
565976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#endif
575976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // Alternative constructor, allowing injection of media_engine
585976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // and device_manager.
595976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  MediaSessionClient(const buzz::Jid& jid, SessionManager *manager,
605976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                     MediaEngineInterface* media_engine,
615976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                     DataEngineInterface* data_media_engine,
625976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                     DeviceManagerInterface* device_manager);
635976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  ~MediaSessionClient();
645976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
655976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  const buzz::Jid &jid() const { return jid_; }
665976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  SessionManager* session_manager() const { return session_manager_; }
675976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  ChannelManager* channel_manager() const { return channel_manager_; }
685976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
695976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // Return mapping of call ids to Calls.
705976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  const std::map<uint32, Call *>& calls() const { return calls_; }
715976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
725976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // The settings below combine with the settings on SessionManager to choose
735976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
745976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // whether SDES-SRTP, DTLS-SRTP, or no security should be used. The possible
755976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // combinations are shown in the following table. Note that where either DTLS
765976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // or SDES is possible, DTLS is preferred. Thus to require either SDES or
775976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // DTLS, but not mandate DTLS, set SDES to require and DTLS to enable.
785976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  //
795976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  //              | SDES:Disable   | SDES:Enable    | SDES:Require   |
805976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // ----------------------------------------------------------------|
815976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // DTLS:Disable | No SRTP        | SDES Optional  | SDES Mandatory |
825976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // DTLS:Enable  | DTLS Optional  | DTLS/SDES Opt  | DTLS/SDES Mand |
835976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // DTLS:Require | DTLS Mandatory | DTLS Mandatory | DTLS Mandatory |
845976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
855976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // Control use of SDES-SRTP.
865976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  SecurePolicy secure() const { return desc_factory_.secure(); }
875976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  void set_secure(SecurePolicy s) { desc_factory_.set_secure(s); }
885976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
895976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // Control use of multiple sessions in a call.
905976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  void set_multisession_enabled(bool multisession_enabled) {
915976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    multisession_enabled_ = multisession_enabled;
925976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
935976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
945976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  int GetCapabilities() { return channel_manager_->GetCapabilities(); }
955976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
965976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  Call *CreateCall();
975976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  void DestroyCall(Call *call);
985976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
995976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  Call *GetFocus();
1005976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  void SetFocus(Call *call);
1015976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
1025976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  void JoinCalls(Call *call_to_join, Call *call);
1035976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
1045976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  bool GetAudioInputDevices(std::vector<std::string>* names) {
1055976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    return channel_manager_->GetAudioInputDevices(names);
1065976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
1075976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  bool GetAudioOutputDevices(std::vector<std::string>* names) {
1085976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    return channel_manager_->GetAudioOutputDevices(names);
1095976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
1105976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  bool GetVideoCaptureDevices(std::vector<std::string>* names) {
1115976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    return channel_manager_->GetVideoCaptureDevices(names);
1125976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
1135976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
1145976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  bool SetAudioOptions(const std::string& in_name, const std::string& out_name,
115e73fa366a56d0c3c46860c534db19fffe110f167mallinath@webrtc.org                       const AudioOptions& options) {
116e73fa366a56d0c3c46860c534db19fffe110f167mallinath@webrtc.org    return channel_manager_->SetAudioOptions(in_name, out_name, options);
1175976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
1185976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  bool SetOutputVolume(int level) {
1195976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    return channel_manager_->SetOutputVolume(level);
1205976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
1215976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  bool SetCaptureDevice(const std::string& cam_device) {
1225976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    return channel_manager_->SetCaptureDevice(cam_device);
1235976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
1245976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
1255976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  SessionDescription* CreateOffer(const CallOptions& options) {
1265976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    return desc_factory_.CreateOffer(options, NULL);
1275976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
1285976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  SessionDescription* CreateAnswer(const SessionDescription* offer,
1295976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                                   const CallOptions& options) {
1305976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    return desc_factory_.CreateAnswer(offer, options, NULL);
1315976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
1325976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
1335976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  sigslot::signal2<Call *, Call *> SignalFocus;
1345976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  sigslot::signal1<Call *> SignalCallCreate;
1355976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  sigslot::signal1<Call *> SignalCallDestroy;
1365976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  sigslot::repeater0<> SignalDevicesChange;
1375976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
1385976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool ParseContent(SignalingProtocol protocol,
1395976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                            const buzz::XmlElement* elem,
1405976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                            ContentDescription** content,
1415976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                            ParseError* error);
1425976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool IsWritable(SignalingProtocol protocol,
1435976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                          const ContentDescription* content);
1445976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool WriteContent(SignalingProtocol protocol,
1455976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                            const ContentDescription* content,
1465976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                            buzz::XmlElement** elem,
1475976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                            WriteError* error);
1485976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
1495976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org private:
1505976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  void Construct();
1515976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  void OnSessionCreate(Session *session, bool received_initiate);
1525976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  void OnSessionState(BaseSession *session, BaseSession::State state);
1535976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  void OnSessionDestroy(Session *session);
1545976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  Session *CreateSession(Call *call);
155c237f0ad875cde990bf9d89f41424b18809cc345henrike@webrtc.org  Session *CreateSession(const std::string& id, Call* call);
1565976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  Call *FindCallByRemoteName(const std::string &remote_name);
1575976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
1585976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  buzz::Jid jid_;
1595976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  SessionManager* session_manager_;
1605976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  Call *focus_call_;
1615976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  ChannelManager *channel_manager_;
1625976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  MediaSessionDescriptionFactory desc_factory_;
1635976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  bool multisession_enabled_;
1645976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  std::map<uint32, Call *> calls_;
1655976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
1665976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // Maintain a mapping of session id to call.
1675976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  typedef std::map<std::string, Call *> SessionMap;
1685976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  SessionMap session_map_;
1695976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
1705976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  friend class Call;
1715976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org};
1725976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
1735976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org}  // namespace cricket
1745976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
1755976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#endif  // TALK_SESSION_MEDIA_MEDIASESSIONCLIENT_H_
176