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_
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/base/media_log.h"
20 #include "media/video/capture/video_capture_device_info.h"
23 class AudioParameters
;
29 // This class stores information about currently active media.
30 class CONTENT_EXPORT MediaInternals
31 : NON_EXPORTED_BASE(public media::AudioLogFactory
) {
33 // Called with the update string.
34 typedef base::Callback
<void(const base::string16
&)> UpdateCallback
;
36 static MediaInternals
* GetInstance();
38 ~MediaInternals() override
;
40 // Called when a MediaEvent occurs.
41 void OnMediaEvents(int render_process_id
,
42 const std::vector
<media::MediaLogEvent
>& events
);
44 // Add/remove update callbacks (see above). Must be called on the IO thread.
45 void AddUpdateCallback(const UpdateCallback
& callback
);
46 void RemoveUpdateCallback(const UpdateCallback
& callback
);
48 // Sends all audio cached data to each registered UpdateCallback.
49 void SendAudioStreamData();
51 // Sends all video capture capabilities cached data to each registered
53 void SendVideoCaptureDeviceCapabilities();
55 // Called to inform of the capabilities enumerated for video devices.
56 void UpdateVideoCaptureDeviceCapabilities(
57 const media::VideoCaptureDeviceInfos
& video_capture_device_infos
);
59 // AudioLogFactory implementation. Safe to call from any thread.
60 scoped_ptr
<media::AudioLog
> CreateAudioLog(AudioComponent component
) override
;
63 // Inner class to handle reporting pipelinestatus to UMA
64 class MediaInternalsUMAHandler
;
66 friend class AudioLogImpl
;
67 friend class MediaInternalsTest
;
68 friend struct base::DefaultLazyInstanceTraits
<MediaInternals
>;
72 // Sends |update| to each registered UpdateCallback. Safe to call from any
73 // thread, but will forward to the IO thread.
74 void SendUpdate(const base::string16
& update
);
76 // Caches |value| under |cache_key| so that future SendAudioStreamData() calls
77 // will include the current data. Calls JavaScript |function|(|value|) for
78 // each registered UpdateCallback. SendUpdateAndPurgeCache() is similar but
79 // purges the cache entry after completion instead.
80 void SendUpdateAndCacheAudioStreamKey(const std::string
& cache_key
,
81 const std::string
& function
,
82 const base::DictionaryValue
* value
);
83 void SendUpdateAndPurgeAudioStreamCache(const std::string
& cache_key
,
84 const std::string
& function
,
85 const base::DictionaryValue
* value
);
87 // Must only be accessed on the IO thread.
88 std::vector
<UpdateCallback
> update_callbacks_
;
89 base::ListValue video_capture_capabilities_cached_data_
;
91 // All variables below must be accessed under |lock_|.
93 base::DictionaryValue audio_streams_cached_data_
;
94 int owner_ids_
[AUDIO_COMPONENT_MAX
];
95 scoped_ptr
<MediaInternalsUMAHandler
> uma_handler_
;
97 DISALLOW_COPY_AND_ASSIGN(MediaInternals
);
100 } // namespace content
102 #endif // CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_