Apply _RELATIVE relocations ahead of others.
[chromium-blink-merge.git] / content / browser / media / media_internals.h
blob4c1b2ed2ed6452e3554a12c3fc94d08c66a0ddc9
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_BROWSER_MEDIA_MEDIA_INTERNALS_H_
6 #define CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_
8 #include <string>
9 #include <vector>
11 #include "base/callback_forward.h"
12 #include "base/compiler_specific.h"
13 #include "base/lazy_instance.h"
14 #include "base/strings/string16.h"
15 #include "base/synchronization/lock.h"
16 #include "base/values.h"
17 #include "content/common/content_export.h"
18 #include "media/audio/audio_logging.h"
19 #include "media/video/capture/video_capture_device_info.h"
21 namespace media {
22 class AudioParameters;
23 struct MediaLogEvent;
26 namespace content {
28 // This class stores information about currently active media.
29 class CONTENT_EXPORT MediaInternals
30 : NON_EXPORTED_BASE(public media::AudioLogFactory) {
31 public:
32 // Called with the update string.
33 typedef base::Callback<void(const base::string16&)> UpdateCallback;
35 static MediaInternals* GetInstance();
37 ~MediaInternals() override;
39 // Called when a MediaEvent occurs.
40 void OnMediaEvents(int render_process_id,
41 const std::vector<media::MediaLogEvent>& events);
43 // Add/remove update callbacks (see above). Must be called on the IO thread.
44 void AddUpdateCallback(const UpdateCallback& callback);
45 void RemoveUpdateCallback(const UpdateCallback& callback);
47 // Sends all audio cached data to each registered UpdateCallback.
48 void SendAudioStreamData();
50 // Sends all video capture capabilities cached data to each registered
51 // UpdateCallback.
52 void SendVideoCaptureDeviceCapabilities();
54 // Called to inform of the capabilities enumerated for video devices.
55 void UpdateVideoCaptureDeviceCapabilities(
56 const media::VideoCaptureDeviceInfos& video_capture_device_infos);
58 // AudioLogFactory implementation. Safe to call from any thread.
59 scoped_ptr<media::AudioLog> CreateAudioLog(AudioComponent component) override;
61 private:
62 friend class AudioLogImpl;
63 friend class MediaInternalsTest;
64 friend struct base::DefaultLazyInstanceTraits<MediaInternals>;
66 MediaInternals();
68 // Sends |update| to each registered UpdateCallback. Safe to call from any
69 // thread, but will forward to the IO thread.
70 void SendUpdate(const base::string16& update);
72 // Caches |value| under |cache_key| so that future SendAudioStreamData() calls
73 // will include the current data. Calls JavaScript |function|(|value|) for
74 // each registered UpdateCallback. SendUpdateAndPurgeCache() is similar but
75 // purges the cache entry after completion instead.
76 void SendUpdateAndCacheAudioStreamKey(const std::string& cache_key,
77 const std::string& function,
78 const base::DictionaryValue* value);
79 void SendUpdateAndPurgeAudioStreamCache(const std::string& cache_key,
80 const std::string& function,
81 const base::DictionaryValue* value);
83 // Must only be accessed on the IO thread.
84 std::vector<UpdateCallback> update_callbacks_;
85 base::ListValue video_capture_capabilities_cached_data_;
87 // All variables below must be accessed under |lock_|.
88 base::Lock lock_;
89 base::DictionaryValue audio_streams_cached_data_;
90 int owner_ids_[AUDIO_COMPONENT_MAX];
92 DISALLOW_COPY_AND_ASSIGN(MediaInternals);
95 } // namespace content
97 #endif // CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_