| 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_PEPPER_PEPPER_MEDIA_DEVICE_MANAGER_H_ | 5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_DEVICE_MANAGER_H_ |
| 6 #define CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_DEVICE_MANAGER_H_ | 6 #define CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_DEVICE_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" | 11 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" |
| 12 #include "content/renderer/pepper/pepper_device_enumeration_host_helper.h" | 12 #include "content/renderer/pepper/pepper_device_enumeration_host_helper.h" |
| 13 #include "content/public/renderer/render_view_observer_tracker.h" | 13 #include "content/public/renderer/render_view_observer_tracker.h" |
| 14 #include "content/public/renderer/render_view_observer.h" | 14 #include "content/public/renderer/render_view_observer.h" |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 class RenderViewImpl; | 17 class RenderViewImpl; |
| 18 | 18 |
| 19 class PepperMediaDeviceManager | 19 class PepperMediaDeviceManager |
| 20 : public MediaStreamDispatcherEventHandler, | 20 : public MediaStreamDispatcherEventHandler, |
| 21 public PepperDeviceEnumerationHostHelper::Delegate, | 21 public PepperDeviceEnumerationHostHelper::Delegate, |
| 22 public RenderViewObserver, | 22 public RenderViewObserver, |
| 23 public RenderViewObserverTracker<PepperMediaDeviceManager>, | 23 public RenderViewObserverTracker<PepperMediaDeviceManager>, |
| 24 public base::SupportsWeakPtr<PepperMediaDeviceManager> { | 24 public base::SupportsWeakPtr<PepperMediaDeviceManager> { |
| 25 public: | 25 public: |
| 26 static PepperMediaDeviceManager* GetForRenderView(RenderView* render_view); | 26 static PepperMediaDeviceManager* GetForRenderView(RenderView* render_view); |
| 27 virtual ~PepperMediaDeviceManager(); | 27 virtual ~PepperMediaDeviceManager(); |
| 28 | 28 |
| 29 // PepperDeviceEnumerationHostHelper::Delegate implementation: | 29 // PepperDeviceEnumerationHostHelper::Delegate implementation: |
| 30 virtual int EnumerateDevices( | 30 virtual int EnumerateDevices(PP_DeviceType_Dev type, |
| 31 PP_DeviceType_Dev type, | 31 const GURL& document_url, |
| 32 const GURL& document_url, | 32 const EnumerateDevicesCallback& callback) |
| 33 const EnumerateDevicesCallback& callback) OVERRIDE; | 33 OVERRIDE; |
| 34 virtual void StopEnumerateDevices(int request_id) OVERRIDE; | 34 virtual void StopEnumerateDevices(int request_id) OVERRIDE; |
| 35 | 35 |
| 36 typedef base::Callback<void (int /* request_id */, | 36 typedef base::Callback<void(int /* request_id */, |
| 37 bool /* succeeded */, | 37 bool /* succeeded */, |
| 38 const std::string& /* label */)> | 38 const std::string& /* label */)> |
| 39 OpenDeviceCallback; | 39 OpenDeviceCallback; |
| 40 | 40 |
| 41 // Opens the specified device. The request ID passed into the callback will be | 41 // Opens the specified device. The request ID passed into the callback will be |
| 42 // the same as the return value. If successful, the label passed into the | 42 // the same as the return value. If successful, the label passed into the |
| 43 // callback identifies a audio/video steam, which can be used to call | 43 // callback identifies a audio/video steam, which can be used to call |
| 44 // CloseDevice() and GetSesssionID(). | 44 // CloseDevice() and GetSesssionID(). |
| 45 int OpenDevice(PP_DeviceType_Dev type, | 45 int OpenDevice(PP_DeviceType_Dev type, |
| 46 const std::string& device_id, | 46 const std::string& device_id, |
| 47 const GURL& document_url, | 47 const GURL& document_url, |
| 48 const OpenDeviceCallback& callback); | 48 const OpenDeviceCallback& callback); |
| 49 // Cancels an request to open device, using the request ID returned by | 49 // Cancels an request to open device, using the request ID returned by |
| 50 // OpenDevice(). It is guaranteed that the callback passed into OpenDevice() | 50 // OpenDevice(). It is guaranteed that the callback passed into OpenDevice() |
| 51 // won't be called afterwards. | 51 // won't be called afterwards. |
| 52 void CancelOpenDevice(int request_id); | 52 void CancelOpenDevice(int request_id); |
| 53 void CloseDevice(const std::string& label); | 53 void CloseDevice(const std::string& label); |
| 54 // Gets audio/video session ID given a label. | 54 // Gets audio/video session ID given a label. |
| 55 int GetSessionID(PP_DeviceType_Dev type, const std::string& label); | 55 int GetSessionID(PP_DeviceType_Dev type, const std::string& label); |
| 56 | 56 |
| 57 // MediaStreamDispatcherEventHandler implementation. | 57 // MediaStreamDispatcherEventHandler implementation. |
| 58 virtual void OnStreamGenerated( | 58 virtual void OnStreamGenerated( |
| 59 int request_id, | 59 int request_id, |
| 60 const std::string& label, | 60 const std::string& label, |
| 61 const StreamDeviceInfoArray& audio_device_array, | 61 const StreamDeviceInfoArray& audio_device_array, |
| 62 const StreamDeviceInfoArray& video_device_array) OVERRIDE; | 62 const StreamDeviceInfoArray& video_device_array) OVERRIDE; |
| 63 virtual void OnStreamGenerationFailed( | 63 virtual void OnStreamGenerationFailed( |
| 64 int request_id, | 64 int request_id, |
| 65 content::MediaStreamRequestResult result) OVERRIDE; | 65 content::MediaStreamRequestResult result) OVERRIDE; |
| 66 virtual void OnDeviceStopped(const std::string& label, | 66 virtual void OnDeviceStopped(const std::string& label, |
| 67 const StreamDeviceInfo& device_info) OVERRIDE; | 67 const StreamDeviceInfo& device_info) OVERRIDE; |
| 68 virtual void OnDevicesEnumerated( | 68 virtual void OnDevicesEnumerated(int request_id, |
| 69 int request_id, | 69 const StreamDeviceInfoArray& device_array) |
| 70 const StreamDeviceInfoArray& device_array) OVERRIDE; | 70 OVERRIDE; |
| 71 virtual void OnDeviceOpened( | 71 virtual void OnDeviceOpened(int request_id, |
| 72 int request_id, | 72 const std::string& label, |
| 73 const std::string& label, | 73 const StreamDeviceInfo& device_info) OVERRIDE; |
| 74 const StreamDeviceInfo& device_info) OVERRIDE; | |
| 75 virtual void OnDeviceOpenFailed(int request_id) OVERRIDE; | 74 virtual void OnDeviceOpenFailed(int request_id) OVERRIDE; |
| 76 | 75 |
| 77 // Stream type conversion. | 76 // Stream type conversion. |
| 78 static MediaStreamType FromPepperDeviceType(PP_DeviceType_Dev type); | 77 static MediaStreamType FromPepperDeviceType(PP_DeviceType_Dev type); |
| 79 static PP_DeviceType_Dev FromMediaStreamType(MediaStreamType type); | 78 static PP_DeviceType_Dev FromMediaStreamType(MediaStreamType type); |
| 80 | 79 |
| 81 private: | 80 private: |
| 82 PepperMediaDeviceManager(RenderView* render_view); | 81 PepperMediaDeviceManager(RenderView* render_view); |
| 83 | 82 |
| 84 void NotifyDeviceOpened(int request_id, | 83 void NotifyDeviceOpened(int request_id, |
| 85 bool succeeded, | 84 bool succeeded, |
| 86 const std::string& label); | 85 const std::string& label); |
| 87 | 86 |
| 88 RenderViewImpl* GetRenderViewImpl(); | 87 RenderViewImpl* GetRenderViewImpl(); |
| 89 | 88 |
| 90 int next_id_; | 89 int next_id_; |
| 91 | 90 |
| 92 typedef std::map<int, EnumerateDevicesCallback> EnumerateCallbackMap; | 91 typedef std::map<int, EnumerateDevicesCallback> EnumerateCallbackMap; |
| 93 EnumerateCallbackMap enumerate_callbacks_; | 92 EnumerateCallbackMap enumerate_callbacks_; |
| 94 | 93 |
| 95 typedef std::map<int, OpenDeviceCallback> OpenCallbackMap; | 94 typedef std::map<int, OpenDeviceCallback> OpenCallbackMap; |
| 96 OpenCallbackMap open_callbacks_; | 95 OpenCallbackMap open_callbacks_; |
| 97 | 96 |
| 98 DISALLOW_COPY_AND_ASSIGN(PepperMediaDeviceManager); | 97 DISALLOW_COPY_AND_ASSIGN(PepperMediaDeviceManager); |
| 99 }; | 98 }; |
| 100 | 99 |
| 101 } // namespace content | 100 } // namespace content |
| 102 | 101 |
| 103 #endif // CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_DEVICE_MANAGER_H_ | 102 #endif // CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_DEVICE_MANAGER_H_ |
| OLD | NEW |