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
;
62 // If possible, i.e. a WebContents exists for the given RenderFrameHostID,
63 // tells an existing AudioLogEntry the WebContents title for easier
64 // differentiation on the UI.
65 void SetWebContentsTitleForAudioLogEntry(int component_id
,
66 int render_process_id
,
68 media::AudioLog
* audio_log
);
71 // Inner class to handle reporting pipelinestatus to UMA
72 class MediaInternalsUMAHandler
;
74 friend class AudioLogImpl
;
75 friend class MediaInternalsTest
;
76 friend struct base::DefaultLazyInstanceTraits
<MediaInternals
>;
80 // Sends |update| to each registered UpdateCallback. Safe to call from any
81 // thread, but will forward to the IO thread.
82 void SendUpdate(const base::string16
& update
);
84 // Caches |value| under |cache_key| so that future SendAudioLogUpdate() calls
85 // will include the current data. Calls JavaScript |function|(|value|) for
86 // each registered UpdateCallback.
87 enum AudioLogUpdateType
{
88 CREATE
, // Creates a new AudioLog cache entry.
89 UPDATE_IF_EXISTS
, // Updates an existing AudioLog cache entry, does
90 // nothing if it doesn't exist.
91 UPDATE_AND_DELETE
, // Deletes an existing AudioLog cache entry.
93 void SendAudioLogUpdate(AudioLogUpdateType type
,
94 const std::string
& cache_key
,
95 const std::string
& function
,
96 const base::DictionaryValue
* value
);
98 // Must only be accessed on the IO thread.
99 std::vector
<UpdateCallback
> update_callbacks_
;
100 base::ListValue video_capture_capabilities_cached_data_
;
102 // All variables below must be accessed under |lock_|.
104 base::DictionaryValue audio_streams_cached_data_
;
105 int owner_ids_
[AUDIO_COMPONENT_MAX
];
106 scoped_ptr
<MediaInternalsUMAHandler
> uma_handler_
;
108 DISALLOW_COPY_AND_ASSIGN(MediaInternals
);
111 } // namespace content
113 #endif // CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_