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 CHROME_BROWSER_MEDIA_MEDIA_INTERNALS_H_ | 5 #ifndef CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_ |
6 #define CHROME_BROWSER_MEDIA_MEDIA_INTERNALS_H_ | 6 #define CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
| 9 #include <vector> |
9 | 10 |
10 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
11 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
12 #include "base/observer_list.h" | 13 #include "base/string16.h" |
13 #include "base/values.h" | 14 #include "base/values.h" |
14 #include "content/public/browser/media_observer.h" | 15 #include "content/common/content_export.h" |
15 #include "content/public/common/media_stream_request.h" | 16 #include "content/public/common/media_stream_request.h" |
16 | 17 |
17 class MediaCaptureDevicesDispatcher; | 18 namespace media { |
18 class MediaInternalsObserver; | 19 struct MediaLogEvent; |
19 class MediaStreamCaptureIndicator; | 20 } |
20 class Profile; | |
21 | 21 |
22 namespace media { | 22 namespace content { |
23 | |
24 struct MediaLogEvent; | |
25 | |
26 // Helper to get the default devices which can be used by the media request, | |
27 // if the return list is empty, it means there is no available device on the OS. | |
28 // Called on the UI thread. | |
29 void GetDefaultDevicesForProfile(Profile* profile, | |
30 bool audio, | |
31 bool video, | |
32 content::MediaStreamDevices* devices); | |
33 | |
34 // Helper for picking the device that was requested for an OpenDevice request. | |
35 // If the device requested is not available it will revert to using the first | |
36 // available one instead or will return an empty list if no devices of the | |
37 // requested kind are present. | |
38 void GetRequestedDevice(const std::string& requested_device_id, | |
39 bool audio, | |
40 bool video, | |
41 content::MediaStreamDevices* devices); | |
42 } | |
43 | 23 |
44 // This class stores information about currently active media. | 24 // This class stores information about currently active media. |
45 // It's constructed on the UI thread but all of its methods are called on the IO | 25 // It's constructed on the UI thread but all of its methods are called on the IO |
46 // thread. | 26 // thread. |
47 class MediaInternals : public content::MediaObserver { | 27 class CONTENT_EXPORT MediaInternals { |
48 public: | 28 public: |
49 virtual ~MediaInternals(); | 29 virtual ~MediaInternals(); |
50 | 30 |
51 static MediaInternals* GetInstance(); | 31 static MediaInternals* GetInstance(); |
52 | 32 |
53 // Overridden from content::MediaObserver: | 33 // The following methods are virtual for gmock. |
54 virtual void OnDeleteAudioStream(void* host, int stream_id) OVERRIDE; | 34 |
55 virtual void OnSetAudioStreamPlaying(void* host, | 35 // Called when an audio stream is deleted. |
56 int stream_id, | 36 virtual void OnDeleteAudioStream(void* host, int stream_id); |
57 bool playing) OVERRIDE; | 37 |
58 virtual void OnSetAudioStreamStatus(void* host, | 38 // Called when an audio stream is set to playing or paused. |
59 int stream_id, | 39 virtual void OnSetAudioStreamPlaying(void* host, int stream_id, |
60 const std::string& status) OVERRIDE; | 40 bool playing); |
61 virtual void OnSetAudioStreamVolume(void* host, | 41 |
62 int stream_id, | 42 // Called when the status of an audio stream is set to "created", "flushed", |
63 double volume) OVERRIDE; | 43 // "closed", or "error". |
| 44 virtual void OnSetAudioStreamStatus(void* host, int stream_id, |
| 45 const std::string& status); |
| 46 |
| 47 // Called when the volume of an audio stream is set. |
| 48 virtual void OnSetAudioStreamVolume(void* host, int stream_id, |
| 49 double volume); |
| 50 |
| 51 // Called when a MediaEvent occurs. |
64 virtual void OnMediaEvent(int render_process_id, | 52 virtual void OnMediaEvent(int render_process_id, |
65 const media::MediaLogEvent& event) OVERRIDE; | 53 const media::MediaLogEvent& event); |
66 virtual void OnCaptureDevicesOpened( | |
67 int render_process_id, | |
68 int render_view_id, | |
69 const content::MediaStreamDevices& devices) OVERRIDE; | |
70 virtual void OnCaptureDevicesClosed( | |
71 int render_process_id, | |
72 int render_view_id, | |
73 const content::MediaStreamDevices& devices) OVERRIDE; | |
74 virtual void OnAudioCaptureDevicesChanged( | |
75 const content::MediaStreamDevices& devices) OVERRIDE; | |
76 virtual void OnVideoCaptureDevicesChanged( | |
77 const content::MediaStreamDevices& devices) OVERRIDE; | |
78 virtual void OnMediaRequestStateChanged( | |
79 int render_process_id, | |
80 int render_view_id, | |
81 const content::MediaStreamDevice& device, | |
82 content::MediaRequestState state) OVERRIDE; | |
83 | 54 |
84 // Methods for observers. | 55 // Called with the update string. |
85 // Observers should add themselves on construction and remove themselves | 56 typedef base::Callback<void(const string16&)> UpdateCallback; |
86 // on destruction. | 57 |
87 void AddObserver(MediaInternalsObserver* observer); | 58 // Add/remove update callbacks (see above). |
88 void RemoveObserver(MediaInternalsObserver* observer); | 59 void AddUpdateCallback(const UpdateCallback& callback); |
| 60 void RemoveUpdateCallback(const UpdateCallback& callback); |
89 void SendEverything(); | 61 void SendEverything(); |
90 | 62 |
91 scoped_refptr<MediaStreamCaptureIndicator> GetMediaStreamCaptureIndicator(); | |
92 scoped_refptr<MediaCaptureDevicesDispatcher> | |
93 GetMediaCaptureDevicesDispatcher(); | |
94 | |
95 private: | 63 private: |
| 64 friend class MockMediaInternals; |
96 friend class MediaInternalsTest; | 65 friend class MediaInternalsTest; |
97 friend struct DefaultSingletonTraits<MediaInternals>; | 66 friend struct DefaultSingletonTraits<MediaInternals>; |
98 | 67 |
99 MediaInternals(); | 68 MediaInternals(); |
100 | 69 |
101 // Sets |property| of an audio stream to |value| and notifies observers. | 70 // Sets |property| of an audio stream to |value| and notifies observers. |
102 // (host, stream_id) is a unique id for the audio stream. | 71 // (host, stream_id) is a unique id for the audio stream. |
103 // |host| will never be dereferenced. | 72 // |host| will never be dereferenced. |
104 void UpdateAudioStream(void* host, int stream_id, | 73 void UpdateAudioStream(void* host, int stream_id, |
105 const std::string& property, Value* value); | 74 const std::string& property, Value* value); |
106 | 75 |
107 // Removes |item| from |data_|. | 76 // Removes |item| from |data_|. |
108 void DeleteItem(const std::string& item); | 77 void DeleteItem(const std::string& item); |
109 | 78 |
110 // Sets data_.id.property = value and notifies attached UIs using update_fn. | 79 // Sets data_.id.property = value and notifies attached UIs using update_fn. |
111 // id may be any depth, e.g. "video.decoders.1.2.3" | 80 // id may be any depth, e.g. "video.decoders.1.2.3" |
112 void UpdateItem(const std::string& update_fn, const std::string& id, | 81 void UpdateItem(const std::string& update_fn, const std::string& id, |
113 const std::string& property, Value* value); | 82 const std::string& property, Value* value); |
114 | 83 |
115 // Calls javascript |function|(|value|) on each attached UI. | 84 // Calls javascript |function|(|value|) on each attached UI. |
116 void SendUpdate(const std::string& function, Value* value); | 85 void SendUpdate(const std::string& function, Value* value); |
117 | 86 |
118 DictionaryValue data_; | 87 DictionaryValue data_; |
119 ObserverList<MediaInternalsObserver> observers_; | 88 |
120 scoped_refptr<MediaStreamCaptureIndicator> media_stream_capture_indicator_; | 89 std::vector<UpdateCallback> update_callbacks_; |
121 scoped_refptr<MediaCaptureDevicesDispatcher> media_devices_dispatcher_; | |
122 | 90 |
123 DISALLOW_COPY_AND_ASSIGN(MediaInternals); | 91 DISALLOW_COPY_AND_ASSIGN(MediaInternals); |
124 }; | 92 }; |
125 | 93 |
126 #endif // CHROME_BROWSER_MEDIA_MEDIA_INTERNALS_H_ | 94 } // namespace content |
| 95 |
| 96 #endif // CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_ |
OLD | NEW |