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 // MediaStreamProvider is used to capture media of the types defined in
6 // MediaStreamType. There is only one MediaStreamProvider instance per media
7 // type and a MediaStreamProvider instance can have only one registered
9 // The MediaStreamManager is expected to be called on Browser::IO thread and
10 // the listener will be called on the same thread.
12 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_PROVIDER_H_
13 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_PROVIDER_H_
18 #include "base/memory/ref_counted.h"
19 #include "content/common/content_export.h"
20 #include "content/common/media/media_stream_options.h"
23 class MessageLoopProxy
;
28 enum MediaStreamProviderError
{
30 kInvalidMediaStreamType
,
38 enum { kInvalidMediaCaptureSessionId
= 0xFFFFFFFF };
40 // Callback class used by MediaStreamProvider.
41 class CONTENT_EXPORT MediaStreamProviderListener
{
43 // Called by a MediaStreamProvider when a stream has been opened.
44 virtual void Opened(MediaStreamType stream_type
,
45 int capture_session_id
) = 0;
47 // Called by a MediaStreamProvider when a stream has been closed.
48 virtual void Closed(MediaStreamType stream_type
,
49 int capture_session_id
) = 0;
51 // Called by a MediaStreamProvider when available devices has been enumerated.
52 virtual void DevicesEnumerated(MediaStreamType stream_type
,
53 const StreamDeviceInfoArray
& devices
) = 0;
55 // Called by a MediaStreamProvider when an error has occured.
56 virtual void Error(MediaStreamType stream_type
,
57 int capture_session_id
,
58 MediaStreamProviderError error
) = 0;
61 virtual ~MediaStreamProviderListener() {}
64 // Implemented by a manager class providing captured media.
65 class CONTENT_EXPORT MediaStreamProvider
66 : public base::RefCountedThreadSafe
<MediaStreamProvider
> {
68 // Registers a listener and a device message loop.
69 virtual void Register(MediaStreamProviderListener
* listener
,
70 base::MessageLoopProxy
* device_thread_loop
) = 0;
72 // Unregisters the previously registered listener.
73 virtual void Unregister() = 0;
75 // Enumerates existing capture devices and calls |DevicesEnumerated|.
76 virtual void EnumerateDevices(MediaStreamType stream_type
) = 0;
78 // Opens the specified device. The device is not started and it is still
79 // possible for other applications to open the device before the device is
80 // started. |Opened| is called when the device is opened.
81 // kInvalidMediaCaptureSessionId is returned on error.
82 virtual int Open(const StreamDeviceInfo
& device
) = 0;
84 // Closes the specified device and calls |Closed| when done.
85 virtual void Close(int capture_session_id
) = 0;
88 friend class base::RefCountedThreadSafe
<MediaStreamProvider
>;
89 virtual ~MediaStreamProvider() {}
92 } // namespace content
94 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_PROVIDER_H_