Chromium Code Reviews| 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/message_loop.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
| 16 #include "content/common/media/media_stream_options.h" | 16 #include "content/common/media/media_stream_options.h" |
| 17 #include "content/public/renderer/render_view_observer.h" | 17 #include "content/public/renderer/render_view_observer.h" |
| 18 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" | 18 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" |
| 19 | 19 |
| 20 namespace base { | |
| 21 class MessageLoopProxy; | |
| 22 } // namespace | |
|
scherkus (not reviewing)
2012/08/02 00:14:19
nit: you don't need to // namespace for fwd decls
wjia(left Chromium)
2012/08/02 22:15:27
Done.
| |
| 23 | |
| 20 class RenderViewImpl; | 24 class RenderViewImpl; |
| 21 | 25 |
| 22 // MediaStreamDispatcher is a delegate for the Media Stream API messages. | 26 // MediaStreamDispatcher is a delegate for the Media Stream API messages. |
| 23 // MediaStreams are used by WebKit to open media devices such as Video Capture | 27 // MediaStreams are used by WebKit to open media devices such as Video Capture |
| 24 // and Audio input devices. | 28 // and Audio input devices. |
| 25 // It's the complement of MediaStreamDispatcherHost (owned by | 29 // It's the complement of MediaStreamDispatcherHost (owned by |
| 26 // BrowserRenderProcessHost). | 30 // BrowserRenderProcessHost). |
| 27 class CONTENT_EXPORT MediaStreamDispatcher | 31 class CONTENT_EXPORT MediaStreamDispatcher |
| 28 : public content::RenderViewObserver { | 32 : public content::RenderViewObserver { |
| 29 public: | 33 public: |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 45 // Stop a started stream. Label is the label provided in OnStreamGenerated. | 49 // Stop a started stream. Label is the label provided in OnStreamGenerated. |
| 46 virtual void StopStream(const std::string& label); | 50 virtual void StopStream(const std::string& label); |
| 47 | 51 |
| 48 // Request to enumerate devices. | 52 // Request to enumerate devices. |
| 49 void EnumerateDevices( | 53 void EnumerateDevices( |
| 50 int request_id, | 54 int request_id, |
| 51 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | 55 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, |
| 52 media_stream::MediaStreamType type, | 56 media_stream::MediaStreamType type, |
| 53 const GURL& security_origin); | 57 const GURL& security_origin); |
| 54 | 58 |
| 59 // Request to stop enumerating devices. | |
| 60 void StopEnumerateDevices( | |
| 61 int request_id, | |
| 62 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler); | |
| 63 | |
| 55 // Request to open a device. | 64 // Request to open a device. |
| 56 void OpenDevice( | 65 void OpenDevice( |
| 57 int request_id, | 66 int request_id, |
| 58 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | 67 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, |
| 59 const std::string& device_id, | 68 const std::string& device_id, |
| 60 media_stream::MediaStreamType type, | 69 media_stream::MediaStreamType type, |
| 61 const GURL& security_origin); | 70 const GURL& security_origin); |
| 62 | 71 |
| 63 // Close a started device. |label| is provided in OnDeviceOpened. | 72 // Close a started device. |label| is provided in OnDeviceOpened. |
| 64 void CloseDevice(const std::string& label); | 73 void CloseDevice(const std::string& label); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 76 FRIEND_TEST_ALL_PREFIXES(MediaStreamDispatcherTest, BasicVideoDevice); | 85 FRIEND_TEST_ALL_PREFIXES(MediaStreamDispatcherTest, BasicVideoDevice); |
| 77 FRIEND_TEST_ALL_PREFIXES(MediaStreamDispatcherTest, TestFailure); | 86 FRIEND_TEST_ALL_PREFIXES(MediaStreamDispatcherTest, TestFailure); |
| 78 FRIEND_TEST_ALL_PREFIXES(MediaStreamDispatcherTest, CancelGenerateStream); | 87 FRIEND_TEST_ALL_PREFIXES(MediaStreamDispatcherTest, CancelGenerateStream); |
| 79 | 88 |
| 80 struct Request; | 89 struct Request; |
| 81 | 90 |
| 82 // Private class for keeping track of opened devices and who have | 91 // Private class for keeping track of opened devices and who have |
| 83 // opened it. | 92 // opened it. |
| 84 struct Stream; | 93 struct Stream; |
| 85 | 94 |
| 95 struct EnumerationRequest { | |
| 96 EnumerationRequest( | |
| 97 const base::WeakPtr<MediaStreamDispatcherEventHandler>& handler, | |
| 98 int request_id); | |
| 99 ~EnumerationRequest(); | |
| 100 | |
| 101 base::WeakPtr<MediaStreamDispatcherEventHandler> handler; | |
| 102 int request_id; | |
| 103 }; | |
| 104 | |
| 105 // List of requests made to EnumerateDevices. | |
| 106 typedef std::list<EnumerationRequest> EnumerationRequestList; | |
| 107 | |
| 108 struct EnumerationState { | |
|
scherkus (not reviewing)
2012/08/02 00:14:19
instead of stuffing everything into a struct how a
wjia(left Chromium)
2012/08/02 22:15:27
Done.
| |
| 109 EnumerationState(); | |
| 110 ~EnumerationState(); | |
| 111 | |
| 112 bool started; | |
| 113 int ipc_id; | |
| 114 std::string label; | |
| 115 bool cache_valid; | |
| 116 media_stream::StreamDeviceInfoArray cached_device; | |
| 117 EnumerationRequestList requests; | |
| 118 }; | |
| 119 | |
| 86 // Messages from the browser. | 120 // Messages from the browser. |
| 87 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 121 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 88 void OnStreamGenerated( | 122 void OnStreamGenerated( |
| 89 int request_id, | 123 int request_id, |
| 90 const std::string& label, | 124 const std::string& label, |
| 91 const media_stream::StreamDeviceInfoArray& audio_array, | 125 const media_stream::StreamDeviceInfoArray& audio_array, |
| 92 const media_stream::StreamDeviceInfoArray& video_array); | 126 const media_stream::StreamDeviceInfoArray& video_array); |
| 93 void OnStreamGenerationFailed(int request_id); | 127 void OnStreamGenerationFailed(int request_id); |
| 94 void OnVideoDeviceFailed(const std::string& label, int index); | 128 void OnVideoDeviceFailed(const std::string& label, int index); |
| 95 void OnAudioDeviceFailed(const std::string& label, int index); | 129 void OnAudioDeviceFailed(const std::string& label, int index); |
| 96 void OnDevicesEnumerated( | 130 void OnDevicesEnumerated( |
| 97 int request_id, | 131 int request_id, |
| 132 const std::string& label, | |
| 98 const media_stream::StreamDeviceInfoArray& device_array); | 133 const media_stream::StreamDeviceInfoArray& device_array); |
| 99 void OnDevicesEnumerationFailed(int request_id); | 134 void OnDevicesEnumerationFailed(int request_id); |
| 100 void OnDeviceOpened( | 135 void OnDeviceOpened( |
| 101 int request_id, | 136 int request_id, |
| 102 const std::string& label, | 137 const std::string& label, |
| 103 const media_stream::StreamDeviceInfo& device_info); | 138 const media_stream::StreamDeviceInfo& device_info); |
| 104 void OnDeviceOpenFailed(int request_id); | 139 void OnDeviceOpenFailed(int request_id); |
| 105 | 140 |
| 141 bool RemoveEnumerationRequest( | |
| 142 int request_id, | |
| 143 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | |
| 144 EnumerationState* state); | |
| 145 | |
| 146 // Used for DCHECKs so methods calls won't execute in the wrong thread. | |
| 147 scoped_refptr<base::MessageLoopProxy> main_loop_; | |
| 148 | |
| 106 int next_ipc_id_; | 149 int next_ipc_id_; |
| 107 typedef std::map<std::string, Stream> LabelStreamMap; | 150 typedef std::map<std::string, Stream> LabelStreamMap; |
| 108 LabelStreamMap label_stream_map_; | 151 LabelStreamMap label_stream_map_; |
| 109 | 152 |
| 153 EnumerationState audio_enumeration_state_; | |
| 154 EnumerationState video_enumeration_state_; | |
| 155 | |
| 110 // List of calls made to GenerateStream that has not yet completed. | 156 // List of calls made to GenerateStream that has not yet completed. |
| 111 typedef std::list<Request> RequestList; | 157 typedef std::list<Request> RequestList; |
| 112 RequestList requests_; | 158 RequestList requests_; |
| 113 | 159 |
| 114 DISALLOW_COPY_AND_ASSIGN(MediaStreamDispatcher); | 160 DISALLOW_COPY_AND_ASSIGN(MediaStreamDispatcher); |
| 115 }; | 161 }; |
| 116 | 162 |
| 117 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_DISPATCHER_H_ | 163 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_DISPATCHER_H_ |
| OLD | NEW |