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

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: Merge Created 8 years, 11 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) 2012 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 <list>
9 #include <map>
10 #include <string>
7 11
8 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "base/gtest_prod_util.h"
9 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/message_loop_proxy.h"
18 #include "base/threading/non_thread_safe.h"
19 #include "base/threading/thread.h"
20 #include "content/common/content_export.h"
21 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h"
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h"
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaRequest.h "
10 #include "webkit/media/media_stream_client.h" 24 #include "webkit/media/media_stream_client.h"
11 25
26 namespace base {
27 class WaitableEvent;
28 }
29
30 namespace content {
31 class IpcNetworkManager;
32 class IpcPacketSocketFactory;
33 class P2PSocketDispatcher;
34 }
35
36 namespace cricket {
37 class WebRtcMediaEngine;
38 }
39
40 namespace talk_base {
41 class Thread;
42 }
43
44 namespace WebKit {
45 class WebPeerConnectionHandler;
46 class WebPeerConnectionHandlerClient;
47 }
48
49 class MediaStreamDispatcher;
50 class MediaStreamDependencyFactory;
51 class PeerConnectionHandler;
12 class VideoCaptureImplManager; 52 class VideoCaptureImplManager;
53 class RTCVideoDecoder;
13 54
14 // A implementation of StreamClient to provide supporting functions, such as 55 // MediaStreamImpl is a delegate for the Media Stream API messages used by
15 // GetVideoDecoder. 56 // WebKit. It ties together WebKit, native PeerConnection in libjingle and
16 class MediaStreamImpl 57 // MediaStreamManager (via MediaStreamDispatcher and MediaStreamDispatcherHost)
17 : public webkit_media::MediaStreamClient, 58 // in the browser process. It must be created, called and destroyed on the
59 // render thread.
60 class CONTENT_EXPORT MediaStreamImpl
61 : NON_EXPORTED_BASE(public WebKit::WebUserMediaClient),
62 NON_EXPORTED_BASE(public webkit_media::MediaStreamClient),
63 public MediaStreamDispatcherEventHandler,
64 NON_EXPORTED_BASE(public base::NonThreadSafe),
18 public base::RefCountedThreadSafe<MediaStreamImpl> { 65 public base::RefCountedThreadSafe<MediaStreamImpl> {
19 public: 66 public:
20 explicit MediaStreamImpl(VideoCaptureImplManager* vc_manager); 67 MediaStreamImpl(
68 MediaStreamDispatcher* media_stream_dispatcher,
69 content::P2PSocketDispatcher* p2p_socket_dispatcher,
70 VideoCaptureImplManager* vc_manager,
71 MediaStreamDependencyFactory* dependency_factory);
21 virtual ~MediaStreamImpl(); 72 virtual ~MediaStreamImpl();
22 73
23 // Implement webkit_media::StreamClient. 74 virtual WebKit::WebPeerConnectionHandler* CreatePeerConnectionHandler(
75 WebKit::WebPeerConnectionHandlerClient* client);
76 virtual void ClosePeerConnection();
77
78 // Returns true if created successfully or already exists, false otherwise.
79 virtual bool SetVideoCaptureModule(const std::string& label);
80
81 // WebKit::WebUserMediaClient implementation
82 virtual void requestUserMedia(
83 const WebKit::WebUserMediaRequest& user_media_request,
84 const WebKit::WebVector<WebKit::WebMediaStreamSource>&
85 media_stream_source_vector) OVERRIDE;
86 virtual void cancelUserMediaRequest(
87 const WebKit::WebUserMediaRequest& user_media_request) OVERRIDE;
88
89 // webkit_media::MediaStreamClient implementation.
24 virtual scoped_refptr<media::VideoDecoder> GetVideoDecoder( 90 virtual scoped_refptr<media::VideoDecoder> GetVideoDecoder(
25 const GURL& url, 91 const GURL& url,
26 media::MessageLoopFactory* message_loop_factory) OVERRIDE; 92 media::MessageLoopFactory* message_loop_factory) OVERRIDE;
27 93
94 // MediaStreamDispatcherEventHandler implementation.
95 virtual void OnStreamGenerated(
96 int request_id,
97 const std::string& label,
98 const media_stream::StreamDeviceInfoArray& audio_array,
99 const media_stream::StreamDeviceInfoArray& video_array) OVERRIDE;
100 virtual void OnStreamGenerationFailed(int request_id) OVERRIDE;
101 virtual void OnVideoDeviceFailed(
102 const std::string& label,
103 int index) OVERRIDE;
104 virtual void OnAudioDeviceFailed(
105 const std::string& label,
106 int index) OVERRIDE;
107
28 private: 108 private:
109 FRIEND_TEST_ALL_PREFIXES(MediaStreamImplTest, Basic);
110
111 void InitializeWorkerThread(
112 talk_base::Thread** thread,
113 base::WaitableEvent* event);
114 void DeleteIpcNetworkManager();
115
116 scoped_ptr<MediaStreamDependencyFactory> dependency_factory_;
117
118 // media_stream_dispatcher_ is a weak reference, owned by RenderView. It's
119 // valid for the lifetime of RenderView.
120 MediaStreamDispatcher* media_stream_dispatcher_;
121
122 // media_engine_ is owned by PeerConnectionFactory (which is owned by
123 // dependency_factory_) and is valid for the lifetime of
124 // PeerConnectionFactory.
125 cricket::WebRtcMediaEngine* media_engine_;
126
127 // p2p_socket_dispatcher_ is a weak reference, owned by RenderView. It's valid
128 // for the lifetime of RenderView.
129 content::P2PSocketDispatcher* p2p_socket_dispatcher_;
130
131 // We own network_manager_, must be deleted on the worker thread.
132 content::IpcNetworkManager* network_manager_;
133
134 scoped_ptr<content::IpcPacketSocketFactory> socket_factory_;
135
29 scoped_refptr<VideoCaptureImplManager> vc_manager_; 136 scoped_refptr<VideoCaptureImplManager> vc_manager_;
30 137
138 // peer_connection_handler_ is a weak reference, owned by WebKit. It's valid
139 // until stop is called on it (which will call ClosePeerConnection on us).
140 // TODO(grunell): Support several PeerConnectionsHandlers.
141 PeerConnectionHandler* peer_connection_handler_;
142
143 scoped_refptr<RTCVideoDecoder> rtc_video_decoder_;
144 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
145
146 // PeerConnection threads. signaling_thread_ is created from the
147 // "current" chrome thread.
148 talk_base::Thread* signaling_thread_;
149 talk_base::Thread* worker_thread_;
150 base::Thread chrome_worker_thread_;
151
152 static int next_request_id_;
153 typedef std::map<int, WebKit::WebUserMediaRequest> MediaRequestMap;
154 MediaRequestMap user_media_requests_;
155
156 std::list<std::string> stream_labels_;
157
158 // Make sure we only create the video capture module once. This is also
159 // temporary and will be handled differently when several PeerConnections
160 // and/or streams is supported.
161 // TODO(grunell): This shall be removed or changed when native PeerConnection
162 // has been updated to closer follow the specification.
163 bool vcm_created_;
164
31 DISALLOW_COPY_AND_ASSIGN(MediaStreamImpl); 165 DISALLOW_COPY_AND_ASSIGN(MediaStreamImpl);
32 }; 166 };
33 167
34 #endif // CONTENT_RENDERER_MEDIA_STREAM_MEDIA_STREAM_IMPL_H_ 168 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_
OLDNEW
« no previous file with comments | « content/renderer/media/media_stream_dispatcher.h ('k') | content/renderer/media/media_stream_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698