Battery Status API: add UMA logging for Linux.
[chromium-blink-merge.git] / content / browser / renderer_host / media / media_stream_provider.h
blob3413a99bd343c99116ad44c6ebcc1bd8d909bd1d
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
8 // listener.
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_
15 #include <list>
16 #include <string>
18 #include "base/memory/ref_counted.h"
19 #include "content/common/content_export.h"
20 #include "content/common/media/media_stream_options.h"
22 namespace base {
23 class SingleThreadTaskRunner;
26 namespace content {
28 enum MediaStreamProviderError {
29 kMediaStreamOk = 0,
30 kInvalidMediaStreamType,
31 kInvalidSession,
32 kUnknownSession,
33 kDeviceNotAvailable,
34 kDeviceAlreadyInUse,
35 kUnknownError
38 enum { kInvalidMediaCaptureSessionId = 0xFFFFFFFF };
40 // Callback class used by MediaStreamProvider.
41 class CONTENT_EXPORT MediaStreamProviderListener {
42 public:
43 // Called by a MediaStreamProvider when a stream has been opened.
44 virtual void Opened(MediaStreamType stream_type, int capture_session_id) = 0;
46 // Called by a MediaStreamProvider when a stream has been closed.
47 virtual void Closed(MediaStreamType stream_type, int capture_session_id) = 0;
49 // Called by a MediaStreamProvider when available devices has been enumerated.
50 virtual void DevicesEnumerated(MediaStreamType stream_type,
51 const StreamDeviceInfoArray& devices) = 0;
53 // Called by a MediaStreamProvider when the device has been aborted due to
54 // device error.
55 virtual void Aborted(MediaStreamType stream_type, int capture_session_id) = 0;
57 protected:
58 virtual ~MediaStreamProviderListener() {}
61 // Implemented by a manager class providing captured media.
62 class CONTENT_EXPORT MediaStreamProvider
63 : public base::RefCountedThreadSafe<MediaStreamProvider> {
64 public:
65 // Registers a listener and a device message loop.
66 virtual void Register(MediaStreamProviderListener* listener,
67 const scoped_refptr<base::SingleThreadTaskRunner>&
68 device_task_runner) = 0;
70 // Unregisters the previously registered listener.
71 virtual void Unregister() = 0;
73 // Enumerates existing capture devices and calls |DevicesEnumerated|.
74 virtual void EnumerateDevices(MediaStreamType stream_type) = 0;
76 // Opens the specified device. The device is not started and it is still
77 // possible for other applications to open the device before the device is
78 // started. |Opened| is called when the device is opened.
79 // kInvalidMediaCaptureSessionId is returned on error.
80 virtual int Open(const StreamDeviceInfo& device) = 0;
82 // Closes the specified device and calls |Closed| when done.
83 virtual void Close(int capture_session_id) = 0;
85 protected:
86 friend class base::RefCountedThreadSafe<MediaStreamProvider>;
87 virtual ~MediaStreamProvider() {}
90 } // namespace content
92 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_PROVIDER_H_