| 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 <memory> | 10 #include <memory> |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 const url::Origin& security_origin); | 48 const url::Origin& security_origin); |
| 49 | 49 |
| 50 // Cancel the request for a new media stream to be created. | 50 // Cancel the request for a new media stream to be created. |
| 51 virtual void CancelGenerateStream( | 51 virtual void CancelGenerateStream( |
| 52 int request_id, | 52 int request_id, |
| 53 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler); | 53 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler); |
| 54 | 54 |
| 55 // Stop a started device that has been requested by calling GenerateStream. | 55 // Stop a started device that has been requested by calling GenerateStream. |
| 56 virtual void StopStreamDevice(const StreamDeviceInfo& device_info); | 56 virtual void StopStreamDevice(const StreamDeviceInfo& device_info); |
| 57 | 57 |
| 58 // Request to enumerate devices. | |
| 59 virtual void EnumerateDevices( | |
| 60 int request_id, | |
| 61 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | |
| 62 MediaStreamType type, | |
| 63 const url::Origin& security_origin); | |
| 64 | |
| 65 // Request to stop enumerating devices. | |
| 66 void StopEnumerateDevices( | |
| 67 int request_id, | |
| 68 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler); | |
| 69 | |
| 70 // Request to open a device. | 58 // Request to open a device. |
| 71 void OpenDevice( | 59 void OpenDevice( |
| 72 int request_id, | 60 int request_id, |
| 73 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | 61 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, |
| 74 const std::string& device_id, | 62 const std::string& device_id, |
| 75 MediaStreamType type, | 63 MediaStreamType type, |
| 76 const url::Origin& security_origin); | 64 const url::Origin& security_origin); |
| 77 | 65 |
| 78 // Cancel the request to open a device. | 66 // Cancel the request to open a device. |
| 79 virtual void CancelOpenDevice( | 67 virtual void CancelOpenDevice( |
| 80 int request_id, | 68 int request_id, |
| 81 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler); | 69 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler); |
| 82 | 70 |
| 83 // Close a started device. |label| is provided in OnDeviceOpened. | 71 // Close a started device. |label| is provided in OnDeviceOpened. |
| 84 void CloseDevice(const std::string& label); | 72 void CloseDevice(const std::string& label); |
| 85 | 73 |
| 86 // Register and unregister event handlers for device-change notifications. | |
| 87 // It is an error to try to subscribe a handler that is already subscribed or | |
| 88 // to cancel the subscription of a handler that is not subscribed. Also, | |
| 89 // each subscribed handler must make sure to invoke | |
| 90 // CancelDeviceChangeNotifications() before the handler is destroyed. | |
| 91 void SubscribeToDeviceChangeNotifications( | |
| 92 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | |
| 93 const url::Origin& security_origin); | |
| 94 void CancelDeviceChangeNotifications( | |
| 95 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler); | |
| 96 | |
| 97 // Check if the label is a valid stream. | 74 // Check if the label is a valid stream. |
| 98 virtual bool IsStream(const std::string& label); | 75 virtual bool IsStream(const std::string& label); |
| 99 // Get the video session_id given a label. The label identifies a stream. | 76 // Get the video session_id given a label. The label identifies a stream. |
| 100 // index is the index in the video_device_array of the stream. | 77 // index is the index in the video_device_array of the stream. |
| 101 virtual int video_session_id(const std::string& label, int index); | 78 virtual int video_session_id(const std::string& label, int index); |
| 102 // Returns an audio session_id given a label and an index. | 79 // Returns an audio session_id given a label and an index. |
| 103 virtual int audio_session_id(const std::string& label, int index); | 80 virtual int audio_session_id(const std::string& label, int index); |
| 104 | 81 |
| 105 protected: | 82 protected: |
| 106 int GetNextIpcIdForTest() { return next_ipc_id_; } | 83 int GetNextIpcIdForTest() { return next_ipc_id_; } |
| 107 size_t NumDeviceChangeSubscribers() const { | |
| 108 return device_change_subscribers_.size(); | |
| 109 } | |
| 110 | 84 |
| 111 private: | 85 private: |
| 112 FRIEND_TEST_ALL_PREFIXES(MediaStreamDispatcherTest, BasicVideoDevice); | 86 FRIEND_TEST_ALL_PREFIXES(MediaStreamDispatcherTest, BasicVideoDevice); |
| 113 FRIEND_TEST_ALL_PREFIXES(MediaStreamDispatcherTest, TestFailure); | 87 FRIEND_TEST_ALL_PREFIXES(MediaStreamDispatcherTest, TestFailure); |
| 114 FRIEND_TEST_ALL_PREFIXES(MediaStreamDispatcherTest, CancelGenerateStream); | 88 FRIEND_TEST_ALL_PREFIXES(MediaStreamDispatcherTest, CancelGenerateStream); |
| 115 | 89 |
| 116 struct Request; | 90 struct Request; |
| 117 | 91 |
| 118 // Private class for keeping track of opened devices and who have | 92 // Private class for keeping track of opened devices and who have |
| 119 // opened it. | 93 // opened it. |
| 120 struct Stream; | 94 struct Stream; |
| 121 | 95 |
| 122 // RenderFrameObserver override. | 96 // RenderFrameObserver override. |
| 123 void OnDestruct() override; | 97 void OnDestruct() override; |
| 124 bool Send(IPC::Message* message) override; | 98 bool Send(IPC::Message* message) override; |
| 125 bool OnMessageReceived(const IPC::Message& message) override; | 99 bool OnMessageReceived(const IPC::Message& message) override; |
| 126 | 100 |
| 127 // Messages from the browser. | 101 // Messages from the browser. |
| 128 void OnStreamGenerated( | 102 void OnStreamGenerated( |
| 129 int request_id, | 103 int request_id, |
| 130 const std::string& label, | 104 const std::string& label, |
| 131 const StreamDeviceInfoArray& audio_array, | 105 const StreamDeviceInfoArray& audio_array, |
| 132 const StreamDeviceInfoArray& video_array); | 106 const StreamDeviceInfoArray& video_array); |
| 133 void OnStreamGenerationFailed( | 107 void OnStreamGenerationFailed( |
| 134 int request_id, | 108 int request_id, |
| 135 content::MediaStreamRequestResult result); | 109 content::MediaStreamRequestResult result); |
| 136 void OnDeviceStopped(const std::string& label, | 110 void OnDeviceStopped(const std::string& label, |
| 137 const StreamDeviceInfo& device_info); | 111 const StreamDeviceInfo& device_info); |
| 138 void OnDevicesEnumerated( | |
| 139 int request_id, | |
| 140 const StreamDeviceInfoArray& device_array); | |
| 141 void OnDeviceOpened( | 112 void OnDeviceOpened( |
| 142 int request_id, | 113 int request_id, |
| 143 const std::string& label, | 114 const std::string& label, |
| 144 const StreamDeviceInfo& device_info); | 115 const StreamDeviceInfo& device_info); |
| 145 void OnDeviceOpenFailed(int request_id); | 116 void OnDeviceOpenFailed(int request_id); |
| 146 void OnDevicesChanged(); | |
| 147 | 117 |
| 148 // Used for DCHECKs so methods calls won't execute in the wrong thread. | 118 // Used for DCHECKs so methods calls won't execute in the wrong thread. |
| 149 base::ThreadChecker thread_checker_; | 119 base::ThreadChecker thread_checker_; |
| 150 | 120 |
| 151 int next_ipc_id_; | 121 int next_ipc_id_; |
| 152 typedef std::map<std::string, Stream> LabelStreamMap; | 122 typedef std::map<std::string, Stream> LabelStreamMap; |
| 153 LabelStreamMap label_stream_map_; | 123 LabelStreamMap label_stream_map_; |
| 154 | 124 |
| 155 // List of calls made to the browser process that have not yet completed or | 125 // List of calls made to the browser process that have not yet completed or |
| 156 // been canceled. | 126 // been canceled. |
| 157 typedef std::list<Request> RequestList; | 127 typedef std::list<Request> RequestList; |
| 158 RequestList requests_; | 128 RequestList requests_; |
| 159 | 129 |
| 160 std::vector<base::WeakPtr<MediaStreamDispatcherEventHandler>> | |
| 161 device_change_subscribers_; | |
| 162 | |
| 163 DISALLOW_COPY_AND_ASSIGN(MediaStreamDispatcher); | 130 DISALLOW_COPY_AND_ASSIGN(MediaStreamDispatcher); |
| 164 }; | 131 }; |
| 165 | 132 |
| 166 } // namespace content | 133 } // namespace content |
| 167 | 134 |
| 168 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_DISPATCHER_H_ | 135 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_DISPATCHER_H_ |
| OLD | NEW |