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/public/renderer/render_frame_observer.h" | 11 #include "content/public/renderer/render_frame_observer.h" |
12 #include "content/public/renderer/render_frame_observer_tracker.h" | 12 #include "content/public/renderer/render_frame_observer_tracker.h" |
13 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" | 13 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" |
14 #include "content/renderer/pepper/pepper_device_enumeration_host_helper.h" | 14 #include "content/renderer/pepper/pepper_device_enumeration_host_helper.h" |
15 | 15 |
16 namespace content { | 16 namespace content { |
17 class MediaStreamDispatcher; | 17 class MediaStreamDispatcher; |
18 | 18 |
19 class PepperMediaDeviceManager | 19 class PepperMediaDeviceManager |
20 : public MediaStreamDispatcherEventHandler, | 20 : public MediaStreamDispatcherEventHandler, |
21 public PepperDeviceEnumerationHostHelper::Delegate, | 21 public PepperDeviceEnumerationHostHelper::Delegate, |
22 public RenderFrameObserver, | 22 public RenderFrameObserver, |
23 public RenderFrameObserverTracker<PepperMediaDeviceManager>, | 23 public RenderFrameObserverTracker<PepperMediaDeviceManager>, |
24 public base::SupportsWeakPtr<PepperMediaDeviceManager> { | 24 public base::SupportsWeakPtr<PepperMediaDeviceManager> { |
25 public: | 25 public: |
26 static base::WeakPtr<PepperMediaDeviceManager> GetForRenderFrame( | 26 static base::WeakPtr<PepperMediaDeviceManager> GetForRenderFrame( |
27 RenderFrame* render_frame); | 27 RenderFrame* render_frame); |
28 virtual ~PepperMediaDeviceManager(); | 28 ~PepperMediaDeviceManager() override; |
29 | 29 |
30 // PepperDeviceEnumerationHostHelper::Delegate implementation: | 30 // PepperDeviceEnumerationHostHelper::Delegate implementation: |
31 virtual int EnumerateDevices(PP_DeviceType_Dev type, | 31 int EnumerateDevices(PP_DeviceType_Dev type, |
32 const GURL& document_url, | 32 const GURL& document_url, |
33 const EnumerateDevicesCallback& callback) | 33 const EnumerateDevicesCallback& callback) override; |
34 override; | 34 void StopEnumerateDevices(int request_id) override; |
35 virtual void StopEnumerateDevices(int request_id) override; | |
36 | 35 |
37 typedef base::Callback<void(int /* request_id */, | 36 typedef base::Callback<void(int /* request_id */, |
38 bool /* succeeded */, | 37 bool /* succeeded */, |
39 const std::string& /* label */)> | 38 const std::string& /* label */)> |
40 OpenDeviceCallback; | 39 OpenDeviceCallback; |
41 | 40 |
42 // 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 |
43 // 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 |
44 // 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 |
45 // CloseDevice() and GetSesssionID(). | 44 // CloseDevice() and GetSesssionID(). |
46 int OpenDevice(PP_DeviceType_Dev type, | 45 int OpenDevice(PP_DeviceType_Dev type, |
47 const std::string& device_id, | 46 const std::string& device_id, |
48 const GURL& document_url, | 47 const GURL& document_url, |
49 const OpenDeviceCallback& callback); | 48 const OpenDeviceCallback& callback); |
50 // 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 |
51 // OpenDevice(). It is guaranteed that the callback passed into OpenDevice() | 50 // OpenDevice(). It is guaranteed that the callback passed into OpenDevice() |
52 // won't be called afterwards. | 51 // won't be called afterwards. |
53 void CancelOpenDevice(int request_id); | 52 void CancelOpenDevice(int request_id); |
54 void CloseDevice(const std::string& label); | 53 void CloseDevice(const std::string& label); |
55 // Gets audio/video session ID given a label. | 54 // Gets audio/video session ID given a label. |
56 int GetSessionID(PP_DeviceType_Dev type, const std::string& label); | 55 int GetSessionID(PP_DeviceType_Dev type, const std::string& label); |
57 | 56 |
58 // MediaStreamDispatcherEventHandler implementation. | 57 // MediaStreamDispatcherEventHandler implementation. |
59 virtual void OnStreamGenerated( | 58 void OnStreamGenerated( |
60 int request_id, | 59 int request_id, |
61 const std::string& label, | 60 const std::string& label, |
62 const StreamDeviceInfoArray& audio_device_array, | 61 const StreamDeviceInfoArray& audio_device_array, |
63 const StreamDeviceInfoArray& video_device_array) override; | 62 const StreamDeviceInfoArray& video_device_array) override; |
64 virtual void OnStreamGenerationFailed( | 63 void OnStreamGenerationFailed( |
65 int request_id, | 64 int request_id, |
66 content::MediaStreamRequestResult result) override; | 65 content::MediaStreamRequestResult result) override; |
67 virtual void OnDeviceStopped(const std::string& label, | 66 void OnDeviceStopped(const std::string& label, |
68 const StreamDeviceInfo& device_info) override; | 67 const StreamDeviceInfo& device_info) override; |
69 virtual void OnDevicesEnumerated(int request_id, | 68 void OnDevicesEnumerated(int request_id, |
70 const StreamDeviceInfoArray& device_array) | 69 const StreamDeviceInfoArray& device_array) override; |
71 override; | 70 void OnDeviceOpened(int request_id, |
72 virtual void OnDeviceOpened(int request_id, | 71 const std::string& label, |
73 const std::string& label, | 72 const StreamDeviceInfo& device_info) override; |
74 const StreamDeviceInfo& device_info) override; | 73 void OnDeviceOpenFailed(int request_id) override; |
75 virtual void OnDeviceOpenFailed(int request_id) override; | |
76 | 74 |
77 // Stream type conversion. | 75 // Stream type conversion. |
78 static MediaStreamType FromPepperDeviceType(PP_DeviceType_Dev type); | 76 static MediaStreamType FromPepperDeviceType(PP_DeviceType_Dev type); |
79 static PP_DeviceType_Dev FromMediaStreamType(MediaStreamType type); | 77 static PP_DeviceType_Dev FromMediaStreamType(MediaStreamType type); |
80 | 78 |
81 private: | 79 private: |
82 explicit PepperMediaDeviceManager(RenderFrame* render_frame); | 80 explicit PepperMediaDeviceManager(RenderFrame* render_frame); |
83 | 81 |
84 // Called by StopEnumerateDevices() after returing to the event loop, to avoid | 82 // Called by StopEnumerateDevices() after returing to the event loop, to avoid |
85 // a reentrancy problem. | 83 // a reentrancy problem. |
(...skipping 13 matching lines...) Expand all Loading... |
99 | 97 |
100 typedef std::map<int, OpenDeviceCallback> OpenCallbackMap; | 98 typedef std::map<int, OpenDeviceCallback> OpenCallbackMap; |
101 OpenCallbackMap open_callbacks_; | 99 OpenCallbackMap open_callbacks_; |
102 | 100 |
103 DISALLOW_COPY_AND_ASSIGN(PepperMediaDeviceManager); | 101 DISALLOW_COPY_AND_ASSIGN(PepperMediaDeviceManager); |
104 }; | 102 }; |
105 | 103 |
106 } // namespace content | 104 } // namespace content |
107 | 105 |
108 #endif // CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_DEVICE_MANAGER_H_ | 106 #endif // CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_DEVICE_MANAGER_H_ |
OLD | NEW |