summaryrefslogtreecommitdiffstats
path: root/content/renderer/media/mock_peer_connection_impl.h
blob: 626786b9ef15a89eb418e1283fc450eb40f8a27c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_RENDERER_MEDIA_MOCK_PEER_CONNECTION_IMPL_H_
#define CONTENT_RENDERER_MEDIA_MOCK_PEER_CONNECTION_IMPL_H_

#include <string>

#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h"

namespace content {

class MockMediaStreamDependencyFactory;
class MockStreamCollection;

class MockPeerConnectionImpl : public webrtc::PeerConnectionInterface {
 public:
  explicit MockPeerConnectionImpl(MockMediaStreamDependencyFactory* factory);

  // PeerConnectionInterface implementation.
  virtual talk_base::scoped_refptr<webrtc::StreamCollectionInterface>
      local_streams() OVERRIDE;
  virtual talk_base::scoped_refptr<webrtc::StreamCollectionInterface>
      remote_streams() OVERRIDE;
  virtual bool AddStream(
      webrtc::MediaStreamInterface* local_stream,
      const webrtc::MediaConstraintsInterface* constraints) OVERRIDE;
  virtual void RemoveStream(
      webrtc::MediaStreamInterface* local_stream) OVERRIDE;
  virtual bool CanSendDtmf(const webrtc::AudioTrackInterface* track) OVERRIDE;
  virtual bool SendDtmf(const webrtc::AudioTrackInterface* send_track,
                        const std::string& tones, int duration,
                        const webrtc::AudioTrackInterface* play_track) OVERRIDE;
  virtual talk_base::scoped_refptr<webrtc::DataChannelInterface>
      CreateDataChannel(const std::string& label,
                        const webrtc::DataChannelInit* config) OVERRIDE;

  virtual bool GetStats(webrtc::StatsObserver* observer,
                        webrtc::MediaStreamTrackInterface* track) OVERRIDE;
  virtual ReadyState ready_state() OVERRIDE;
  virtual bool StartIce(IceOptions options) OVERRIDE;

  virtual webrtc::SessionDescriptionInterface* CreateOffer(
      const webrtc::MediaHints& hints) OVERRIDE;
  virtual webrtc::SessionDescriptionInterface* CreateAnswer(
      const webrtc::MediaHints& hints,
      const webrtc::SessionDescriptionInterface* offer) OVERRIDE;
  virtual bool SetLocalDescription(
      Action action,
      webrtc::SessionDescriptionInterface* desc) OVERRIDE;
  virtual bool SetRemoteDescription(
      Action action,
      webrtc::SessionDescriptionInterface* desc) OVERRIDE;
  virtual bool ProcessIceMessage(
      const webrtc::IceCandidateInterface* ice_candidate) OVERRIDE;
  virtual const webrtc::SessionDescriptionInterface* local_description()
      const OVERRIDE;
  virtual const webrtc::SessionDescriptionInterface* remote_description()
      const OVERRIDE;

  // JSEP01 APIs
  virtual void CreateOffer(
      webrtc::CreateSessionDescriptionObserver* observer,
      const webrtc::MediaConstraintsInterface* constraints) OVERRIDE;
  virtual void CreateAnswer(
      webrtc::CreateSessionDescriptionObserver* observer,
      const webrtc::MediaConstraintsInterface* constraints) OVERRIDE;
  virtual void SetLocalDescription(
      webrtc::SetSessionDescriptionObserver* observer,
      webrtc::SessionDescriptionInterface* desc) OVERRIDE;
  virtual void SetRemoteDescription(
      webrtc::SetSessionDescriptionObserver* observer,
      webrtc::SessionDescriptionInterface* desc) OVERRIDE;
  virtual bool UpdateIce(
      const IceServers& configuration,
      const webrtc::MediaConstraintsInterface* constraints) OVERRIDE;
  virtual bool AddIceCandidate(
      const webrtc::IceCandidateInterface* candidate) OVERRIDE;
  virtual IceState ice_state() OVERRIDE;

  void AddRemoteStream(webrtc::MediaStreamInterface* stream);
  void SetReadyState(ReadyState state) { ready_state_ = state; }
  void SetIceState(IceState state) { ice_state_ = state; }

  const std::string& stream_label() const { return stream_label_; }
  bool hint_audio() const { return hint_audio_; }
  bool hint_video() const { return hint_video_; }
  Action action() const { return action_; }
  const std::string& description_sdp() const { return description_sdp_; }
  IceOptions ice_options() const { return ice_options_; }
  const std::string& sdp_mid() const { return sdp_mid_; }
  int sdp_mline_index() const { return sdp_mline_index_; }
  const std::string& ice_sdp() const { return ice_sdp_; }
  webrtc::SessionDescriptionInterface* created_session_description() const {
    return created_sessiondescription_.get();
  }
  static const char kDummyOffer[];
  static const char kDummyAnswer[];

 protected:
  virtual ~MockPeerConnectionImpl();

 private:
  // Used for creating MockSessionDescription.
  MockMediaStreamDependencyFactory* dependency_factory_;

  std::string stream_label_;
  talk_base::scoped_refptr<MockStreamCollection> local_streams_;
  talk_base::scoped_refptr<MockStreamCollection> remote_streams_;
  scoped_ptr<webrtc::SessionDescriptionInterface> local_desc_;
  scoped_ptr<webrtc::SessionDescriptionInterface> remote_desc_;
  scoped_ptr<webrtc::SessionDescriptionInterface> created_sessiondescription_;
  bool hint_audio_;
  bool hint_video_;
  Action action_;
  std::string description_sdp_;
  IceOptions ice_options_;
  std::string sdp_mid_;
  int sdp_mline_index_;
  std::string ice_sdp_;
  ReadyState ready_state_;
  IceState ice_state_;

  DISALLOW_COPY_AND_ASSIGN(MockPeerConnectionImpl);
};

}  // namespace content

#endif  // CONTENT_RENDERER_MEDIA_MOCK_PEER_CONNECTION_IMPL_H_