Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: content/renderer/media/media_stream_impl.h

Issue 8060055: Adding support for MediaStream and PeerConnection functionality (Closed) Base URL: http://git.chromium.org/chromium/chromium.git@trunk
Patch Set: Changed ID to object in WebKit interface. Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_RENDERER_MEDIA_STREAM_MEDIA_STREAM_IMPL_H_ 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_
6 #define CONTENT_RENDERER_MEDIA_STREAM_MEDIA_STREAM_IMPL_H_ 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_
7
8 #include <string>
7 9
8 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/gtest_prod_util.h"
9 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/message_loop_proxy.h"
15 #include "base/threading/thread.h"
16 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h"
17 #include "third_party/libjingle/source/talk/app/webrtc/peerconnection.h"
18 #include "third_party/libjingle/source/talk/app/webrtc/peerconnectionfactory.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamClient. h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPeerConnection.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
10 #include "webkit/glue/media/media_stream_client.h" 22 #include "webkit/glue/media/media_stream_client.h"
11 23
24 namespace base {
25 class WaitableEvent;
26 }
27
28 namespace content {
29 class IpcNetworkManager;
30 class IpcPacketSocketFactory;
31 class P2PSocketDispatcher;
32 }
33
34 namespace cricket {
35 class HttpPortAllocator;
36 class WebRtcMediaEngine;
37 }
38
39 namespace talk_base {
40 class Thread;
41 }
42
43 namespace WebKit {
44 class WebLocalMediaStream;
45 class WebMediaStreamRecorder;
46 class WebMediaStreamController;
47 class WebMediaStreamTrack;
48 class WebPeerConnection;
49 class WebSecurityOrigin;
50 }
51
52 class MediaStreamDispatcher;
12 class VideoCaptureImplManager; 53 class VideoCaptureImplManager;
13 54 class RTCVideoDecoder;
14 // A implementation of StreamClient to provide supporting functions, such as 55
15 // GetVideoDecoder. 56 // MediaStreamImpl is a delegate for the Media Stream API messages used by
16 class MediaStreamImpl 57 // WebKit.
17 : public webkit_glue::MediaStreamClient, 58 class MediaStreamImpl : public WebKit::WebMediaStreamClient,
18 public base::RefCountedThreadSafe<MediaStreamImpl> { 59 public webkit_glue::MediaStreamClient,
60 public MediaStreamDispatcherEventHandler,
61 public webrtc::PeerConnectionObserver,
62 public base::RefCountedThreadSafe<MediaStreamImpl> {
19 public: 63 public:
20 explicit MediaStreamImpl(VideoCaptureImplManager* vc_manager); 64 MediaStreamImpl(MediaStreamDispatcher* media_stream_dispatcher,
21 virtual ~MediaStreamImpl(); 65 content::P2PSocketDispatcher* p2p_socket_dispatcher,
22 66 VideoCaptureImplManager* vc_manager);
23 // Implement webkit_glue::StreamClient. 67 ~MediaStreamImpl();
68
69 // WebKit::WebMediaStreamClient implementation.
70 virtual void setController(
71 WebKit::WebMediaStreamController* controller) OVERRIDE;
72 virtual void shutdown() OVERRIDE;
73 virtual void generateStream(
74 int request_id,
75 WebKit::WebGenerateStreamOptionFlags flags,
76 const WebKit::WebSecurityOrigin& web_security_origin) OVERRIDE;
77 virtual void stopGeneratedStream(
78 const WebKit::WebLocalMediaStream& stream) OVERRIDE;
79 virtual void recordStream(
80 const WebKit::WebMediaStreamRecorder& recorder) OVERRIDE;
81 virtual void getRecordedData(const WebKit::WebMediaStreamRecorder& recorder,
82 int request_id) OVERRIDE;
tommi (sloooow) - chröme 2011/10/03 12:14:14 there are two ways of wrapping arguments used in t
Henrik Grunell 2011/10/18 19:04:05 Done.
83 virtual void disposeRecordedData(
84 const WebKit::WebMediaStreamRecorder& recorder) OVERRIDE;
85 virtual void setMediaStreamTrackEnabled(
86 const WebKit::WebMediaStreamTrack& track) OVERRIDE;
87 virtual void processSignalingMessage(
88 const WebKit::WebPeerConnection& peer_connection_web,
89 const WebKit::WebString& message) OVERRIDE;
90 virtual void message(const WebKit::WebPeerConnection& peer_connection_web,
91 const WebKit::WebString& message) OVERRIDE;
92 virtual void addStream(const WebKit::WebPeerConnection& peer_connection_web,
93 const WebKit::WebMediaStream& stream) OVERRIDE;
94 virtual void newPeerConnection(
95 const WebKit::WebPeerConnection& peer_connection_web,
96 const WebKit::WebString& configuration) OVERRIDE;
97 virtual void closePeerConnection(
98 const WebKit::WebPeerConnection& peer_connection_web) OVERRIDE;
99 virtual void startNegotiation(
100 const WebKit::WebPeerConnection& peer_connection_web) OVERRIDE;
101 virtual void removeStream(
102 const WebKit::WebPeerConnection& peer_connection_web,
103 const WebKit::WebMediaStream& stream) OVERRIDE;
104 virtual void commitStreamChanges(
105 const WebKit::WebPeerConnection& peer_connection_web) OVERRIDE;
106
107 // Implement media_stream::MediaStreamClient.
24 virtual scoped_refptr<media::VideoDecoder> GetVideoDecoder( 108 virtual scoped_refptr<media::VideoDecoder> GetVideoDecoder(
25 const GURL& url, media::MessageLoopFactory* message_loop_factory); 109 const GURL& url, media::MessageLoopFactory* message_loop_factory)
110 OVERRIDE;
111
112 // Implement MediaStreamDispatcherEventHandler.
113 virtual void OnStreamGenerated(
114 int request_id,
115 const std::string& label,
116 const media_stream::StreamDeviceInfoArray& audio_array,
117 const media_stream::StreamDeviceInfoArray& video_array) OVERRIDE;
118 virtual void OnStreamGenerationFailed(int request_id) OVERRIDE;
119 virtual void OnVideoDeviceFailed(const std::string& label,
120 int index) OVERRIDE;
121 virtual void OnAudioDeviceFailed(const std::string& label,
122 int index) OVERRIDE;
123
124 // Implement webrtc::PeerConnectionObserver
125 virtual void OnError() OVERRIDE;
126 virtual void OnSignalingMessage(const std::string& msg) OVERRIDE;
127 virtual void OnAddStream(const std::string& stream_id, bool video) OVERRIDE;
128 virtual void OnRemoveStream(const std::string& stream_id,
129 bool video) OVERRIDE;
26 130
27 private: 131 private:
132 FRIEND_TEST_ALL_PREFIXES(MediaStreamImplTest, Basic);
133 FRIEND_TEST_ALL_PREFIXES(MediaStreamImplTest, TestFailure);
134
135 // TODO(grunell): These shall be removed or changed when libjingle's
136 // PeerConnection has been updated to closer follow the specification.
137 void OnAddStreamCallback(const std::string& stream_label);
138 void OnRemoveStreamCallback(const std::string& stream_label);
139 void DeletePeerConnection();
140
141 void InitializeWorkerThread(talk_base::Thread** thread,
142 base::WaitableEvent* event);
143
144 // The controller_ is valid for the lifetime of the underlying
145 // WebCore::WebMediaStreamController. mediaStreamDestroyed() is
146 // invoked when the underlying object is destroyed. Additionally,
tommi (sloooow) - chröme 2011/10/03 12:14:14 It's not clear to me what "the underlying object"
Henrik Grunell 2011/10/18 19:04:05 Done.
147 // the dispatcher has the same life time as the controller since
tommi (sloooow) - chröme 2011/10/03 12:14:14 I'm not sure which dispatcher... assuming (media_s
Henrik Grunell 2011/10/18 19:04:05 Dispatcher was the previous name of this class, I'
148 // it is owned by RenderView.
149 scoped_ptr<WebKit::WebMediaStreamController> controller_;
150
151 MediaStreamDispatcher* media_stream_dispatcher_;
tommi (sloooow) - chröme 2011/10/03 12:14:14 would be good to document lifetime and ownership o
Henrik Grunell 2011/10/18 19:04:05 Done.
152 cricket::WebRtcMediaEngine* media_engine_;
153
154 content::P2PSocketDispatcher* p2p_socket_dispatcher_;
28 scoped_refptr<VideoCaptureImplManager> vc_manager_; 155 scoped_refptr<VideoCaptureImplManager> vc_manager_;
29 156
157 scoped_ptr<webrtc::PeerConnectionFactory> pc_factory_;
158 scoped_ptr<content::IpcNetworkManager> ipc_network_manager_;
159 scoped_ptr<content::IpcPacketSocketFactory> ipc_socket_factory_;
160 // TODO(grunell): Support several PeerConnections.
161 // peer_connection_web_ is WebKit's PeerConnection object
162 WebKit::WebPeerConnection peer_connection_web_;
163 // peer_connection_native_ is the native PeerConnection object,
164 // it handles the ICE processing and media engine.
165 scoped_ptr<webrtc::PeerConnection> peer_connection_native_;
166 scoped_refptr<RTCVideoDecoder> rtc_video_decoder_;
167 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
168
169 // PeerConnection threads. Signaling_thread is created from the
170 // "current" chrome thread.
171 // threads will be deleted when MessageLoop are destroyed.
172 talk_base::Thread* signaling_thread_;
173 talk_base::Thread* worker_thread_;
174 base::Thread chrome_worker_thread_;
175
176 // TODO(grunell): This shall be removed or changed when libjingle's
177 // PeerConnection has been updated to closer follow the specification.
178 // Currently, a stream in WebKit has audio and/or video and has one label.
179 // Local and remote streams have different labels.
180 // In libjingle, a stream has audio or video (not both), and they have
181 // separate labels. A remote stream has the same label as the corresponding
182 // local stream. Hence the workarounds in the implementation to handle this.
183 // It could look like this:
184 // WebKit: Local stream audio and video, label "foo".
185 // Remote stream audio and video, label "foo-remote".
186 // Libjingle: Local stream audio, label "foo-audio".
187 // Local stream video, label "foo".
188 // Remote stream audio, label "foo-audio".
189 // Remote stream video, label "foo".
190 std::string local_label_; // Label used in WebKit
191 std::string remote_label_; // Label used in WebKit
192
193 // Call states. Possible transitions:
194 // NOT_STARTED -> INITIATING -> SENDING_AND_RECEIVING
195 // NOT_STARTED -> RECEIVING
196 // RECEIVING -> NOT_STARTED
197 // RECEIVING -> SENDING_AND_RECEIVING
198 // RECEIVING -> TERMINATING -> NOT_STARTED
199 // SENDING_AND_RECEIVING -> TERMINATING -> NOT_STARTED
200 // SENDING_AND_RECEIVING -> NOT_STARTED
201 // Note that when in state SENDING_AND_RECEIVING, the other side may or may
202 // not send media. Thus, this state does not necessarily mean full duplex.
203 // TODO(grunell): This shall be removed or changed when libjingle's
204 // PeerConnection has been updated to closer follow the specification.
205 enum CallState {
206 NOT_STARTED,
207 INITIATING,
208 RECEIVING,
209 SENDING_AND_RECEIVING,
210 TERMINATING
211 };
212 CallState call_state_;
213
214 // Make sure we only create the video capture module once. This is also
215 // temporary and will be handled differently when several PeerConnections
216 // and/or streams is supported.
217 // TODO(grunell): This shall be removed or changed when libjingle's
218 // PeerConnection has been updated to closer follow the specification.
219 bool vcm_is_created_;
tommi (sloooow) - chröme 2011/10/03 12:14:14 nit: vcm_created_;
Henrik Grunell 2011/10/18 19:04:05 Done.
220
30 DISALLOW_COPY_AND_ASSIGN(MediaStreamImpl); 221 DISALLOW_COPY_AND_ASSIGN(MediaStreamImpl);
31 }; 222 };
32 223
33 #endif // CONTENT_RENDERER_MEDIA_STREAM_MEDIA_STREAM_IMPL_H_ 224 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_
OLDNEW
« no previous file with comments | « no previous file | content/renderer/media/media_stream_impl.cc » ('j') | content/renderer/media/media_stream_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698