| OLD | NEW |
| 1 // Copyright (c) 2012 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_MEDIA_STREAM_DISPATCHER_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_DISPATCHER_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_DISPATCHER_H_ | 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_DISPATCHER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/threading/thread_checker.h" |
| 16 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
| 17 #include "content/common/media/media_stream_options.h" | 18 #include "content/common/media/media_stream_options.h" |
| 18 #include "content/public/renderer/render_view_observer.h" | 19 #include "content/public/renderer/render_frame_observer.h" |
| 19 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" | 20 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" |
| 20 | 21 |
| 21 namespace base { | 22 namespace base { |
| 22 class MessageLoopProxy; | 23 class MessageLoopProxy; |
| 23 } | 24 } |
| 24 | 25 |
| 25 namespace content { | 26 namespace content { |
| 26 | 27 |
| 27 class RenderViewImpl; | |
| 28 | |
| 29 // MediaStreamDispatcher is a delegate for the Media Stream API messages. | 28 // MediaStreamDispatcher is a delegate for the Media Stream API messages. |
| 30 // MediaStreams are used by WebKit to open media devices such as Video Capture | 29 // MediaStreams are used by WebKit to open media devices such as Video Capture |
| 31 // and Audio input devices. | 30 // and Audio input devices. |
| 32 // It's the complement of MediaStreamDispatcherHost (owned by | 31 // It's the complement of MediaStreamDispatcherHost (owned by |
| 33 // BrowserRenderProcessHost). | 32 // BrowserRenderProcessHost). |
| 34 class CONTENT_EXPORT MediaStreamDispatcher | 33 class CONTENT_EXPORT MediaStreamDispatcher |
| 35 : public RenderViewObserver, | 34 : public RenderFrameObserver, |
| 36 public base::SupportsWeakPtr<MediaStreamDispatcher> { | 35 public base::SupportsWeakPtr<MediaStreamDispatcher> { |
| 37 public: | 36 public: |
| 38 explicit MediaStreamDispatcher(RenderViewImpl* render_view); | 37 explicit MediaStreamDispatcher(RenderFrame* render_frame); |
| 39 virtual ~MediaStreamDispatcher(); | 38 virtual ~MediaStreamDispatcher(); |
| 40 | 39 |
| 41 // Request a new media stream to be created. | 40 // Request a new media stream to be created. |
| 42 // This can be used either by WebKit or a plugin. | 41 // This can be used either by WebKit or a plugin. |
| 43 // Note: The event_handler must be valid for as long as the stream exists. | 42 // Note: The event_handler must be valid for as long as the stream exists. |
| 44 virtual void GenerateStream( | 43 virtual void GenerateStream( |
| 45 int request_id, | 44 int request_id, |
| 46 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | 45 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, |
| 47 const StreamOptions& components, | 46 const StreamOptions& components, |
| 48 const GURL& security_origin); | 47 const GURL& security_origin); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 FRIEND_TEST_ALL_PREFIXES(MediaStreamDispatcherTest, TestFailure); | 107 FRIEND_TEST_ALL_PREFIXES(MediaStreamDispatcherTest, TestFailure); |
| 109 FRIEND_TEST_ALL_PREFIXES(MediaStreamDispatcherTest, CancelGenerateStream); | 108 FRIEND_TEST_ALL_PREFIXES(MediaStreamDispatcherTest, CancelGenerateStream); |
| 110 FRIEND_TEST_ALL_PREFIXES(MediaStreamDispatcherTest, CheckDuckingState); | 109 FRIEND_TEST_ALL_PREFIXES(MediaStreamDispatcherTest, CheckDuckingState); |
| 111 | 110 |
| 112 struct Request; | 111 struct Request; |
| 113 | 112 |
| 114 // Private class for keeping track of opened devices and who have | 113 // Private class for keeping track of opened devices and who have |
| 115 // opened it. | 114 // opened it. |
| 116 struct Stream; | 115 struct Stream; |
| 117 | 116 |
| 118 // RenderViewObserver OVERRIDE. | 117 // RenderFrameObserver OVERRIDE. |
| 118 virtual void OnDestruct() OVERRIDE; |
| 119 virtual bool Send(IPC::Message* message) OVERRIDE; | 119 virtual bool Send(IPC::Message* message) OVERRIDE; |
| 120 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 120 | 121 |
| 121 // Messages from the browser. | 122 // Messages from the browser. |
| 122 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
| 123 void OnStreamGenerated( | 123 void OnStreamGenerated( |
| 124 int request_id, | 124 int request_id, |
| 125 const std::string& label, | 125 const std::string& label, |
| 126 const StreamDeviceInfoArray& audio_array, | 126 const StreamDeviceInfoArray& audio_array, |
| 127 const StreamDeviceInfoArray& video_array); | 127 const StreamDeviceInfoArray& video_array); |
| 128 void OnStreamGenerationFailed( | 128 void OnStreamGenerationFailed( |
| 129 int request_id, | 129 int request_id, |
| 130 content::MediaStreamRequestResult result); | 130 content::MediaStreamRequestResult result); |
| 131 void OnDeviceStopped(const std::string& label, | 131 void OnDeviceStopped(const std::string& label, |
| 132 const StreamDeviceInfo& device_info); | 132 const StreamDeviceInfo& device_info); |
| 133 void OnDevicesEnumerated( | 133 void OnDevicesEnumerated( |
| 134 int request_id, | 134 int request_id, |
| 135 const StreamDeviceInfoArray& device_array); | 135 const StreamDeviceInfoArray& device_array); |
| 136 void OnDeviceOpened( | 136 void OnDeviceOpened( |
| 137 int request_id, | 137 int request_id, |
| 138 const std::string& label, | 138 const std::string& label, |
| 139 const StreamDeviceInfo& device_info); | 139 const StreamDeviceInfo& device_info); |
| 140 void OnDeviceOpenFailed(int request_id); | 140 void OnDeviceOpenFailed(int request_id); |
| 141 | 141 |
| 142 // Used for DCHECKs so methods calls won't execute in the wrong thread. | 142 // Used for DCHECKs so methods calls won't execute in the wrong thread. |
| 143 scoped_refptr<base::MessageLoopProxy> main_loop_; | 143 base::ThreadChecker thread_checker_; |
| 144 | 144 |
| 145 int next_ipc_id_; | 145 int next_ipc_id_; |
| 146 typedef std::map<std::string, Stream> LabelStreamMap; | 146 typedef std::map<std::string, Stream> LabelStreamMap; |
| 147 LabelStreamMap label_stream_map_; | 147 LabelStreamMap label_stream_map_; |
| 148 | 148 |
| 149 // List of calls made to the browser process that have not yet completed or | 149 // List of calls made to the browser process that have not yet completed or |
| 150 // been canceled. | 150 // been canceled. |
| 151 typedef std::list<Request> RequestList; | 151 typedef std::list<Request> RequestList; |
| 152 RequestList requests_; | 152 RequestList requests_; |
| 153 | 153 |
| 154 DISALLOW_COPY_AND_ASSIGN(MediaStreamDispatcher); | 154 DISALLOW_COPY_AND_ASSIGN(MediaStreamDispatcher); |
| 155 }; | 155 }; |
| 156 | 156 |
| 157 } // namespace content | 157 } // namespace content |
| 158 | 158 |
| 159 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_DISPATCHER_H_ | 159 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_DISPATCHER_H_ |
| OLD | NEW |