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

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

Issue 7990004: Adding support for MediaStream and PeerConnection functionality. (Closed) Base URL: http://git.chromium.org/chromium/chromium.git@trunk
Patch Set: Created 9 years, 3 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/WebURL.h"
10 #include "webkit/glue/media/media_stream_client.h" 21 #include "webkit/glue/media/media_stream_client.h"
11 22
23 namespace base {
24 class WaitableEvent;
25 }
26
27 namespace content {
28 class IpcNetworkManager;
29 class IpcPacketSocketFactory;
30 class P2PSocketDispatcher;
31 }
32
33 namespace cricket {
34 class HttpPortAllocator;
35 class WebRtcMediaEngine;
36 }
37
38 namespace talk_base {
39 class Thread;
40 }
41
42 namespace WebKit {
43 class WebMediaStreamController;
44 class WebSecurityOrigin;
45 }
46
47 class MediaStreamDispatcher;
12 class VideoCaptureImplManager; 48 class VideoCaptureImplManager;
49 class RTCVideoDecoder;
13 50
14 // A implementation of StreamClient to provide supporting functions, such as 51 // MediaStreamImpl is a delegate for the Media Stream API messages used by
15 // GetVideoDecoder. 52 // WebKit.
16 class MediaStreamImpl 53 class MediaStreamImpl : public WebKit::WebMediaStreamClient,
17 : public webkit_glue::MediaStreamClient, 54 public webkit_glue::MediaStreamClient,
18 public base::RefCountedThreadSafe<MediaStreamImpl> { 55 public MediaStreamDispatcherEventHandler,
56 public webrtc::PeerConnectionObserver,
57 public base::RefCountedThreadSafe<MediaStreamImpl> {
19 public: 58 public:
20 explicit MediaStreamImpl(VideoCaptureImplManager* vc_manager); 59 MediaStreamImpl(MediaStreamDispatcher* media_stream_dispatcher,
21 virtual ~MediaStreamImpl(); 60 content::P2PSocketDispatcher* p2p_socket_dispatcher,
61 VideoCaptureImplManager* vc_manager);
62 ~MediaStreamImpl();
22 63
23 // Implement webkit_glue::StreamClient. 64 // WebKit::WebMediaStreamClient implementation.
65 virtual void setController(WebKit::WebMediaStreamController*);
tommi (sloooow) - chröme 2011/09/23 13:02:42 Missing parameter names in a few methods. Also, I
grunell (dont use) 2011/09/29 13:38:17 Both done.
66 virtual void mediaStreamDestroyed();
67
68 virtual void generateStream(int requestId,
69 WebKit::WebGenerateStreamOptionFlags,
70 const WebKit::WebSecurityOrigin&);
71 virtual void recordStream(const WebKit::WebString& streamLabel,
72 int recorderId);
73 virtual void getRecordedData(const WebKit::WebString& streamLabel,
74 int recorderId, int requestId);
75 virtual void disposeRecordedData(const WebKit::WebString& streamLabel,
76 int recorderId);
77 virtual void stopGeneratedStream(const WebKit::WebString& streamLabel);
78 virtual void setMediaStreamTrackEnabled(const WebKit::WebString& trackId,
79 bool enabled);
80 virtual void processSignalingMessage(int peerConnectionId,
81 const WebKit::WebString& message);
82 virtual void message(int peerConnectionId,
83 const WebKit::WebString& message);
84 virtual void addStream(int peerConnectionId,
85 const WebKit::WebString& streamLabel);
86 virtual void newPeerConnection(int peerConnectionId,
87 const WebKit::WebString& configuration);
88 virtual void closePeerConnection(int peerConnectionId);
89 virtual void startNegotiation(int peerConnectionId);
90 virtual void removeStream(int peerConnectionId,
91 const WebKit::WebString& streamLabel);
92 virtual void commitStreamChanges(int peerConnectionId);
93
94 // Implement media_stream::MediaStreamClient.
24 virtual scoped_refptr<media::VideoDecoder> GetVideoDecoder( 95 virtual scoped_refptr<media::VideoDecoder> GetVideoDecoder(
25 const GURL& url, media::MessageLoopFactory* message_loop_factory); 96 const GURL& url, media::MessageLoopFactory* message_loop_factory);
26 97
98 // Implement MediaStreamDispatcherEventHandler.
99 virtual void OnStreamGenerated(
100 int requestId,
101 const std::string& label,
102 const media_stream::StreamDeviceInfoArray& audio_array,
103 const media_stream::StreamDeviceInfoArray& video_array);
104 virtual void OnStreamGenerationFailed(int requestId);
105 virtual void OnVideoDeviceFailed(const std::string& label, int index);
106 virtual void OnAudioDeviceFailed(const std::string& label, int index);
107
108 // Implement webrtc::PeerConnectionObserver
109 virtual void OnError();
110 virtual void OnSignalingMessage(const std::string& msg);
111 virtual void OnAddStream(const std::string& stream_id, bool video);
112 virtual void OnRemoveStream(const std::string& stream_id, bool video);
113
27 private: 114 private:
115 FRIEND_TEST_ALL_PREFIXES(MediaStreamImplTest, Basic);
116 FRIEND_TEST_ALL_PREFIXES(MediaStreamImplTest, TestFailure);
117
118 // TODO(grunell): These shall be removed or changed when libjingle's
119 // PeerConnection has been updated to closer follow the specification.
120 void OnAddStreamCallback(std::string streamLabel);
tommi (sloooow) - chröme 2011/09/23 13:02:42 const &
grunell (dont use) 2011/09/29 13:38:17 Done.
121 void OnRemoveStreamCallback(std::string streamLabel);
tommi (sloooow) - chröme 2011/09/23 13:02:42 const &
grunell (dont use) 2011/09/29 13:38:17 Done.
122 void DeletePeerConnection();
123
124 void initializeWorkerThread(talk_base::Thread** thread,
tommi (sloooow) - chröme 2011/09/23 13:02:42 InitializeWorkerThread
grunell (dont use) 2011/09/29 13:38:17 Done.
125 base::WaitableEvent* event);
126
127 // The controller_ is valid for the lifetime of the underlying
128 // WebCore::WebMediaStreamController. mediaStreamDestroyed() is
129 // invoked when the underlying object is destroyed. Additionally,
130 // the dispatcher has the same life time as the controller since
131 // it is owned by RenderView.
132 scoped_ptr<WebKit::WebMediaStreamController> controller_;
133
134 MediaStreamDispatcher* media_stream_dispatcher_;
135 cricket::WebRtcMediaEngine* media_engine_;
136
137 content::P2PSocketDispatcher* p2p_socket_dispatcher_;
28 scoped_refptr<VideoCaptureImplManager> vc_manager_; 138 scoped_refptr<VideoCaptureImplManager> vc_manager_;
29 139
140 scoped_ptr<webrtc::PeerConnectionFactory> pc_factory_;
141 scoped_ptr<content::IpcNetworkManager> ipc_network_manager_;
142 scoped_ptr<content::IpcPacketSocketFactory> ipc_socket_factory_;
143 // PeerConnectionFactory owns port_allocator_;
144 cricket::HttpPortAllocator* port_allocator_;
tommi (sloooow) - chröme 2011/09/23 13:02:42 do you need to hang on to all these in the MediaSt
grunell (dont use) 2011/09/29 13:38:17 Not port_allocator_, removed this. The other, yes.
145 // TODO(grunell): Support several PeerConnections.
146 int peer_connection_id_;
tommi (sloooow) - chröme 2011/09/23 13:02:42 document the purpose of peer_connection_id_ and pe
grunell (dont use) 2011/09/29 13:38:17 Done.
147 scoped_ptr<webrtc::PeerConnection> peer_connection_;
148 scoped_refptr<RTCVideoDecoder> rtc_video_decoder_;
149 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
150
151 // PeerConnection threads. Signaling_thread is created from the
152 // "current" chrome thread.
153 // threads will be deleted when MessageLoop are destroyed.
154 talk_base::Thread* signaling_thread_;
155 talk_base::Thread* worker_thread_;
156 base::Thread chrome_worker_thread_;
157
158 // TODO(grunell): All of this shall be removed or changed when libjingle's
159 // PeerConnection has been updated to closer follow the specification.
160 // Currently, a stream in WebKit has audio and/or video and has one label.
161 // Local and remote streams have different labels.
162 // In libjingle, a stream has audio or video (not both), and they have
163 // separate labels. A remote stream has the same label as the corresponding
164 // local stream. Hence the workarounds in the implementation to handle this.
165 // It could look like this:
166 // WebKit: Local stream audio and video, label "foo".
167 // Remote stream audio and video, label "foo-remote".
168 // Libjingle: Local stream audio, label "foo-audio".
169 // Local stream video, label "foo".
170 // Remote stream audio, label "foo-audio".
171 // Remote stream video, label "foo".
172 std::string local_label_; // Label used in WebKit
173 std::string remote_label_; // Label used in WebKit
174 // Call states. Possible transitions:
tommi (sloooow) - chröme 2011/09/23 13:02:42 empty line before this one as above
grunell (dont use) 2011/09/29 13:38:17 Done.
175 // NOT_STARTED -> INITIATING -> SENDING_AND_RECEIVING
176 // NOT_STARTED -> RECEIVING
177 // RECEIVING -> NOT_STARTED
178 // RECEIVING -> SENDING_AND_RECEIVING
179 // RECEIVING -> TERMINATING -> NOT_STARTED
180 // SENDING_AND_RECEIVING -> TERMINATING -> NOT_STARTED
181 // SENDING_AND_RECEIVING -> NOT_STARTED
182 // Note that when in state SENDING_AND_RECEIVING, the other side may or may
183 // not send media. Thus, this state does not necessarily mean full duplex.
184 enum CallState {
185 NOT_STARTED,
186 INITIATING,
187 RECEIVING,
188 SENDING_AND_RECEIVING,
189 TERMINATING
190 };
191 CallState call_state_;
192 // Make sure we only create the video capture module once. This is also
193 // temporary and will be handled differently when several PeerConnections
194 // and/or streams is supported.
195 bool vcm_is_created_;
196
30 DISALLOW_COPY_AND_ASSIGN(MediaStreamImpl); 197 DISALLOW_COPY_AND_ASSIGN(MediaStreamImpl);
31 }; 198 };
32 199
33 #endif // CONTENT_RENDERER_MEDIA_STREAM_MEDIA_STREAM_IMPL_H_ 200 #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