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/renderer/media/media_stream_dispatcher_eventhandler.h"
12 #include "content/renderer/pepper/pepper_device_enumeration_host_helper.h"
13 #include "content/public/renderer/render_view_observer_tracker.h"
14 #include "content/public/renderer/render_view_observer.h"
19 class PepperMediaDeviceManager
20 : public MediaStreamDispatcherEventHandler
,
21 public PepperDeviceEnumerationHostHelper::Delegate
,
22 public RenderViewObserver
,
23 public RenderViewObserverTracker
<PepperMediaDeviceManager
>,
24 public base::SupportsWeakPtr
<PepperMediaDeviceManager
> {
26 static PepperMediaDeviceManager
* GetForRenderView(RenderView
* render_view
);
27 virtual ~PepperMediaDeviceManager();
29 // PepperDeviceEnumerationHostHelper::Delegate implementation:
30 virtual int EnumerateDevices(
31 PP_DeviceType_Dev type
,
32 const EnumerateDevicesCallback
& callback
) OVERRIDE
;
33 virtual void StopEnumerateDevices(int request_id
) OVERRIDE
;
35 typedef base::Callback
<void (int /* request_id */,
37 const std::string
& /* label */)>
40 // Opens the specified device. The request ID passed into the callback will be
41 // the same as the return value. If successful, the label passed into the
42 // callback identifies a audio/video steam, which can be used to call
43 // CloseDevice() and GetSesssionID().
44 int OpenDevice(PP_DeviceType_Dev type
,
45 const std::string
& device_id
,
46 const GURL
& document_url
,
47 const OpenDeviceCallback
& callback
);
48 // Cancels an request to open device, using the request ID returned by
49 // OpenDevice(). It is guaranteed that the callback passed into OpenDevice()
50 // won't be called afterwards.
51 void CancelOpenDevice(int request_id
);
52 void CloseDevice(const std::string
& label
);
53 // Gets audio/video session ID given a label.
54 int GetSessionID(PP_DeviceType_Dev type
, const std::string
& label
);
56 // MediaStreamDispatcherEventHandler implementation.
57 virtual void OnStreamGenerated(
59 const std::string
& label
,
60 const StreamDeviceInfoArray
& audio_device_array
,
61 const StreamDeviceInfoArray
& video_device_array
) OVERRIDE
;
62 virtual void OnStreamGenerationFailed(int request_id
) OVERRIDE
;
63 virtual void OnStopGeneratedStream(const std::string
& label
) OVERRIDE
;
64 virtual void OnDevicesEnumerated(
66 const StreamDeviceInfoArray
& device_array
) OVERRIDE
;
67 virtual void OnDevicesEnumerationFailed(int request_id
) OVERRIDE
;
68 virtual void OnDeviceOpened(
70 const std::string
& label
,
71 const StreamDeviceInfo
& device_info
) OVERRIDE
;
72 virtual void OnDeviceOpenFailed(int request_id
) OVERRIDE
;
74 // Stream type conversion.
75 static MediaStreamType
FromPepperDeviceType(PP_DeviceType_Dev type
);
76 static PP_DeviceType_Dev
FromMediaStreamType(MediaStreamType type
);
79 PepperMediaDeviceManager(RenderView
* render_view
);
81 void NotifyDevicesEnumerated(
84 const StreamDeviceInfoArray
& device_array
);
86 void NotifyDeviceOpened(int request_id
,
88 const std::string
& label
);
90 RenderViewImpl
* GetRenderViewImpl();
94 typedef std::map
<int, EnumerateDevicesCallback
> EnumerateCallbackMap
;
95 EnumerateCallbackMap enumerate_callbacks_
;
97 typedef std::map
<int, OpenDeviceCallback
> OpenCallbackMap
;
98 OpenCallbackMap open_callbacks_
;
100 DISALLOW_COPY_AND_ASSIGN(PepperMediaDeviceManager
);
103 } // namespace content
105 #endif // CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_DEVICE_MANAGER_H_