Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / libjingle / source / talk / app / webrtc / test / fakemediastreamsignaling.h
1 /*
2  * libjingle
3  * Copyright 2013, Google Inc.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  *  1. Redistributions of source code must retain the above copyright notice,
9  *     this list of conditions and the following disclaimer.
10  *  2. Redistributions in binary form must reproduce the above copyright notice,
11  *     this list of conditions and the following disclaimer in the documentation
12  *     and/or other materials provided with the distribution.
13  *  3. The name of the author may not be used to endorse or promote products
14  *     derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  */
28
29 #ifndef TALK_APP_WEBRTC_TEST_FAKEMEDIASTREAMSIGNALING_H_
30 #define TALK_APP_WEBRTC_TEST_FAKEMEDIASTREAMSIGNALING_H_
31
32 #include "talk/app/webrtc/audiotrack.h"
33 #include "talk/app/webrtc/mediastreamsignaling.h"
34 #include "talk/app/webrtc/videotrack.h"
35
36 static const char kStream1[] = "stream1";
37 static const char kVideoTrack1[] = "video1";
38 static const char kAudioTrack1[] = "audio1";
39
40 static const char kStream2[] = "stream2";
41 static const char kVideoTrack2[] = "video2";
42 static const char kAudioTrack2[] = "audio2";
43
44 class FakeMediaStreamSignaling : public webrtc::MediaStreamSignaling,
45                                  public webrtc::MediaStreamSignalingObserver {
46  public:
47   explicit FakeMediaStreamSignaling(cricket::ChannelManager* channel_manager) :
48     webrtc::MediaStreamSignaling(rtc::Thread::Current(), this,
49                                  channel_manager) {
50   }
51
52   void SendAudioVideoStream1() {
53     ClearLocalStreams();
54     AddLocalStream(CreateStream(kStream1, kAudioTrack1, kVideoTrack1));
55   }
56
57   void SendAudioVideoStream2() {
58     ClearLocalStreams();
59     AddLocalStream(CreateStream(kStream2, kAudioTrack2, kVideoTrack2));
60   }
61
62   void SendAudioVideoStream1And2() {
63     ClearLocalStreams();
64     AddLocalStream(CreateStream(kStream1, kAudioTrack1, kVideoTrack1));
65     AddLocalStream(CreateStream(kStream2, kAudioTrack2, kVideoTrack2));
66   }
67
68   void SendNothing() {
69     ClearLocalStreams();
70   }
71
72   void UseOptionsAudioOnly() {
73     ClearLocalStreams();
74     AddLocalStream(CreateStream(kStream2, kAudioTrack2, ""));
75   }
76
77   void UseOptionsVideoOnly() {
78     ClearLocalStreams();
79     AddLocalStream(CreateStream(kStream2, "", kVideoTrack2));
80   }
81
82   void ClearLocalStreams() {
83     while (local_streams()->count() != 0) {
84       RemoveLocalStream(local_streams()->at(0));
85     }
86   }
87
88   // Implements MediaStreamSignalingObserver.
89   virtual void OnAddRemoteStream(webrtc::MediaStreamInterface* stream) {
90   }
91   virtual void OnRemoveRemoteStream(webrtc::MediaStreamInterface* stream) {
92   }
93   virtual void OnAddDataChannel(webrtc::DataChannelInterface* data_channel) {
94   }
95   virtual void OnAddLocalAudioTrack(webrtc::MediaStreamInterface* stream,
96                                     webrtc::AudioTrackInterface* audio_track,
97                                     uint32 ssrc) {
98   }
99   virtual void OnAddLocalVideoTrack(webrtc::MediaStreamInterface* stream,
100                                     webrtc::VideoTrackInterface* video_track,
101                                     uint32 ssrc) {
102   }
103   virtual void OnAddRemoteAudioTrack(webrtc::MediaStreamInterface* stream,
104                                      webrtc::AudioTrackInterface* audio_track,
105                                      uint32 ssrc) {
106   }
107
108   virtual void OnAddRemoteVideoTrack(webrtc::MediaStreamInterface* stream,
109                                      webrtc::VideoTrackInterface* video_track,
110                                      uint32 ssrc) {
111   }
112
113   virtual void OnRemoveRemoteAudioTrack(
114       webrtc::MediaStreamInterface* stream,
115       webrtc::AudioTrackInterface* audio_track) {
116   }
117
118   virtual void OnRemoveRemoteVideoTrack(
119       webrtc::MediaStreamInterface* stream,
120       webrtc::VideoTrackInterface* video_track) {
121   }
122
123   virtual void OnRemoveLocalAudioTrack(
124       webrtc::MediaStreamInterface* stream,
125       webrtc::AudioTrackInterface* audio_track,
126       uint32 ssrc) {
127   }
128   virtual void OnRemoveLocalVideoTrack(
129       webrtc::MediaStreamInterface* stream,
130       webrtc::VideoTrackInterface* video_track) {
131   }
132   virtual void OnRemoveLocalStream(webrtc::MediaStreamInterface* stream) {
133   }
134
135  private:
136   rtc::scoped_refptr<webrtc::MediaStreamInterface> CreateStream(
137       const std::string& stream_label,
138       const std::string& audio_track_id,
139       const std::string& video_track_id) {
140     rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
141         webrtc::MediaStream::Create(stream_label));
142
143     if (!audio_track_id.empty()) {
144       rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
145           webrtc::AudioTrack::Create(audio_track_id, NULL));
146       stream->AddTrack(audio_track);
147     }
148
149     if (!video_track_id.empty()) {
150       rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
151           webrtc::VideoTrack::Create(video_track_id, NULL));
152       stream->AddTrack(video_track);
153     }
154     return stream;
155   }
156 };
157
158 #endif  // TALK_APP_WEBRTC_TEST_FAKEMEDIASTREAMSIGNALING_H_