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
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_DEVICE_MANAGER_H_
6 #define CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_DEVICE_MANAGER_H_
10 #include "base/memory/weak_ptr.h"
11 #include "content/public/renderer/render_frame_observer.h"
12 #include "content/public/renderer/render_frame_observer_tracker.h"
13 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h"
14 #include "content/renderer/pepper/pepper_device_enumeration_host_helper.h"
17 class MediaStreamDispatcher
;
19 class PepperMediaDeviceManager
20 : public MediaStreamDispatcherEventHandler
,
21 public PepperDeviceEnumerationHostHelper::Delegate
,
22 public RenderFrameObserver
,
23 public RenderFrameObserverTracker
<PepperMediaDeviceManager
>,
24 public base::SupportsWeakPtr
<PepperMediaDeviceManager
> {
26 static base::WeakPtr
<PepperMediaDeviceManager
> GetForRenderFrame(
27 RenderFrame
* render_frame
);
28 ~PepperMediaDeviceManager() override
;
30 // PepperDeviceEnumerationHostHelper::Delegate implementation:
31 int EnumerateDevices(PP_DeviceType_Dev type
,
32 const GURL
& document_url
,
33 const EnumerateDevicesCallback
& callback
) override
;
34 void StopEnumerateDevices(int request_id
) override
;
36 typedef base::Callback
<void(int /* request_id */,
38 const std::string
& /* label */)>
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
43 // callback identifies a audio/video steam, which can be used to call
44 // CloseDevice() and GetSesssionID().
45 int OpenDevice(PP_DeviceType_Dev type
,
46 const std::string
& device_id
,
47 const GURL
& document_url
,
48 const OpenDeviceCallback
& callback
);
49 // Cancels an request to open device, using the request ID returned by
50 // OpenDevice(). It is guaranteed that the callback passed into OpenDevice()
51 // won't be called afterwards.
52 void CancelOpenDevice(int request_id
);
53 void CloseDevice(const std::string
& label
);
54 // Gets audio/video session ID given a label.
55 int GetSessionID(PP_DeviceType_Dev type
, const std::string
& label
);
57 // MediaStreamDispatcherEventHandler implementation.
58 void OnStreamGenerated(
60 const std::string
& label
,
61 const StreamDeviceInfoArray
& audio_device_array
,
62 const StreamDeviceInfoArray
& video_device_array
) override
;
63 void OnStreamGenerationFailed(
65 content::MediaStreamRequestResult result
) override
;
66 void OnDeviceStopped(const std::string
& label
,
67 const StreamDeviceInfo
& device_info
) override
;
68 void OnDevicesEnumerated(int request_id
,
69 const StreamDeviceInfoArray
& device_array
) override
;
70 void OnDeviceOpened(int request_id
,
71 const std::string
& label
,
72 const StreamDeviceInfo
& device_info
) override
;
73 void OnDeviceOpenFailed(int request_id
) override
;
75 // Stream type conversion.
76 static MediaStreamType
FromPepperDeviceType(PP_DeviceType_Dev type
);
77 static PP_DeviceType_Dev
FromMediaStreamType(MediaStreamType type
);
80 explicit PepperMediaDeviceManager(RenderFrame
* render_frame
);
82 // Called by StopEnumerateDevices() after returing to the event loop, to avoid
83 // a reentrancy problem.
84 void StopEnumerateDevicesDelayed(int request_id
);
86 void NotifyDeviceOpened(int request_id
,
88 const std::string
& label
);
91 MediaStreamDispatcher
* GetMediaStreamDispatcher() const;
95 typedef std::map
<int, EnumerateDevicesCallback
> EnumerateCallbackMap
;
96 EnumerateCallbackMap enumerate_callbacks_
;
98 typedef std::map
<int, OpenDeviceCallback
> OpenCallbackMap
;
99 OpenCallbackMap open_callbacks_
;
101 DISALLOW_COPY_AND_ASSIGN(PepperMediaDeviceManager
);
104 } // namespace content
106 #endif // CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_DEVICE_MANAGER_H_