Chromium Code Reviews| 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 CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_ | 5 #ifndef CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_ |
| 6 #define CONTENT_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 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
| 18 #include "content/public/browser/notification_observer.h" | |
| 19 #include "content/public/browser/notification_registrar.h" | |
| 18 #include "media/audio/audio_logging.h" | 20 #include "media/audio/audio_logging.h" |
| 21 #include "media/base/media_log.h" | |
| 19 #include "media/video/capture/video_capture_device_info.h" | 22 #include "media/video/capture/video_capture_device_info.h" |
| 20 | 23 |
| 21 namespace media { | 24 namespace media { |
| 22 class AudioParameters; | 25 class AudioParameters; |
| 23 struct MediaLogEvent; | 26 struct MediaLogEvent; |
| 24 } | 27 } |
| 25 | 28 |
| 26 namespace content { | 29 namespace content { |
| 27 | 30 |
| 28 // This class stores information about currently active media. | 31 // This class stores information about currently active media. |
| 29 class CONTENT_EXPORT MediaInternals | 32 class CONTENT_EXPORT MediaInternals |
| 30 : NON_EXPORTED_BASE(public media::AudioLogFactory) { | 33 : NON_EXPORTED_BASE(public media::AudioLogFactory), |
| 34 public NotificationObserver { | |
|
DaleCurtis
2014/11/06 23:49:08
Instead of adding this to the main MediaInternals
prabhur1
2014/11/07 23:43:23
Done.
| |
| 31 public: | 35 public: |
| 36 // NotificationObserver implementation. | |
| 37 void Observe(int type, | |
| 38 const NotificationSource& source, | |
| 39 const NotificationDetails& details) override; | |
| 40 | |
| 32 // Called with the update string. | 41 // Called with the update string. |
| 33 typedef base::Callback<void(const base::string16&)> UpdateCallback; | 42 typedef base::Callback<void(const base::string16&)> UpdateCallback; |
| 34 | 43 |
| 35 static MediaInternals* GetInstance(); | 44 static MediaInternals* GetInstance(); |
| 36 | 45 |
| 37 ~MediaInternals() override; | 46 ~MediaInternals() override; |
| 38 | 47 |
| 39 // Called when a MediaEvent occurs. | 48 // Called when a MediaEvent occurs. |
| 40 void OnMediaEvents(int render_process_id, | 49 void OnMediaEvents(int render_process_id, |
| 41 const std::vector<media::MediaLogEvent>& events); | 50 const std::vector<media::MediaLogEvent>& events); |
| 42 | 51 |
| 43 // Add/remove update callbacks (see above). Must be called on the IO thread. | 52 // Add/remove update callbacks (see above). Must be called on the IO thread. |
| 44 void AddUpdateCallback(const UpdateCallback& callback); | 53 void AddUpdateCallback(const UpdateCallback& callback); |
| 45 void RemoveUpdateCallback(const UpdateCallback& callback); | 54 void RemoveUpdateCallback(const UpdateCallback& callback); |
| 46 | 55 |
| 47 // Sends all audio cached data to each registered UpdateCallback. | 56 // Sends all audio cached data to each registered UpdateCallback. |
| 48 void SendAudioStreamData(); | 57 void SendAudioStreamData(); |
| 49 | 58 |
| 50 // Sends all video capture capabilities cached data to each registered | 59 // Sends all video capture capabilities cached data to each registered |
| 51 // UpdateCallback. | 60 // UpdateCallback. |
| 52 void SendVideoCaptureDeviceCapabilities(); | 61 void SendVideoCaptureDeviceCapabilities(); |
| 53 | 62 |
| 54 // Called to inform of the capabilities enumerated for video devices. | 63 // Called to inform of the capabilities enumerated for video devices. |
| 55 void UpdateVideoCaptureDeviceCapabilities( | 64 void UpdateVideoCaptureDeviceCapabilities( |
| 56 const media::VideoCaptureDeviceInfos& video_capture_device_infos); | 65 const media::VideoCaptureDeviceInfos& video_capture_device_infos); |
| 57 | 66 |
| 58 // AudioLogFactory implementation. Safe to call from any thread. | 67 // AudioLogFactory implementation. Safe to call from any thread. |
| 59 scoped_ptr<media::AudioLog> CreateAudioLog(AudioComponent component) override; | 68 scoped_ptr<media::AudioLog> CreateAudioLog(AudioComponent component) override; |
| 60 | 69 |
| 70 void LogAndClearPlayersInRenderer(int render_process_id); | |
| 71 | |
| 61 private: | 72 private: |
| 73 struct PipelineInfo { | |
| 74 media::PipelineStatus last_pipeline_status; | |
|
DaleCurtis
2014/11/06 23:49:08
If you take my advice above this whole thing shoul
prabhur1
2014/11/07 23:43:24
Done.
| |
| 75 bool has_audio; | |
| 76 bool has_video; | |
| 77 std::string audio_codec_name; | |
| 78 std::string video_codec_name; | |
| 79 std::string video_decoder; | |
| 80 PipelineInfo() { | |
| 81 has_audio = false; | |
| 82 has_video = false; | |
| 83 audio_codec_name = ""; | |
|
DaleCurtis
2014/11/06 23:49:08
Not necessary to initialize the strings.
prabhur1
2014/11/07 23:43:23
Done.
| |
| 84 video_codec_name = ""; | |
| 85 video_decoder = ""; | |
| 86 last_pipeline_status = media::PIPELINE_OK; | |
| 87 } | |
| 88 }; | |
| 89 | |
| 90 // Key is playerid | |
| 91 typedef std::map<int, PipelineInfo*> PlayerInfoMap; | |
|
DaleCurtis
2014/11/06 23:49:08
Don't use a pointer, no need since you're providin
prabhur1
2014/11/07 23:43:23
Done.
| |
| 92 | |
| 93 // Key is renderer id | |
| 94 typedef std::map<int, PlayerInfoMap> RendererPlayerMap; | |
| 95 | |
| 96 // Stores player information per renderer | |
| 97 RendererPlayerMap renderer_info; | |
| 98 | |
| 99 NotificationRegistrar registrar_; | |
| 100 | |
| 62 friend class AudioLogImpl; | 101 friend class AudioLogImpl; |
| 63 friend class MediaInternalsTest; | 102 friend class MediaInternalsTest; |
| 64 friend struct base::DefaultLazyInstanceTraits<MediaInternals>; | 103 friend struct base::DefaultLazyInstanceTraits<MediaInternals>; |
| 65 | 104 |
| 66 MediaInternals(); | 105 MediaInternals(); |
| 67 | 106 |
| 107 void SavePlayerState(const media::MediaLogEvent& event, | |
| 108 int render_process_id); | |
| 109 void LogUMAForPipelineStatus(const PipelineInfo& player_info); | |
|
DaleCurtis
2014/11/06 23:49:08
s/Log/Report/
prabhur1
2014/11/07 23:43:23
Done.
| |
| 110 | |
| 68 // Sends |update| to each registered UpdateCallback. Safe to call from any | 111 // Sends |update| to each registered UpdateCallback. Safe to call from any |
| 69 // thread, but will forward to the IO thread. | 112 // thread, but will forward to the IO thread. |
| 70 void SendUpdate(const base::string16& update); | 113 void SendUpdate(const base::string16& update); |
| 71 | 114 |
| 72 // Caches |value| under |cache_key| so that future SendAudioStreamData() calls | 115 // Caches |value| under |cache_key| so that future SendAudioStreamData() calls |
| 73 // will include the current data. Calls JavaScript |function|(|value|) for | 116 // will include the current data. Calls JavaScript |function|(|value|) for |
| 74 // each registered UpdateCallback. SendUpdateAndPurgeCache() is similar but | 117 // each registered UpdateCallback. SendUpdateAndPurgeCache() is similar but |
| 75 // purges the cache entry after completion instead. | 118 // purges the cache entry after completion instead. |
| 76 void SendUpdateAndCacheAudioStreamKey(const std::string& cache_key, | 119 void SendUpdateAndCacheAudioStreamKey(const std::string& cache_key, |
| 77 const std::string& function, | 120 const std::string& function, |
| 78 const base::DictionaryValue* value); | 121 const base::DictionaryValue* value); |
| 79 void SendUpdateAndPurgeAudioStreamCache(const std::string& cache_key, | 122 void SendUpdateAndPurgeAudioStreamCache(const std::string& cache_key, |
| 80 const std::string& function, | 123 const std::string& function, |
| 81 const base::DictionaryValue* value); | 124 const base::DictionaryValue* value); |
| 82 | 125 |
| 83 // Must only be accessed on the IO thread. | 126 // Must only be accessed on the IO thread. |
| 84 std::vector<UpdateCallback> update_callbacks_; | 127 std::vector<UpdateCallback> update_callbacks_; |
| 85 base::ListValue video_capture_capabilities_cached_data_; | 128 base::ListValue video_capture_capabilities_cached_data_; |
| 86 | 129 |
| 87 // All variables below must be accessed under |lock_|. | 130 // All variables below must be accessed under |lock_|. |
| 88 base::Lock lock_; | 131 base::Lock lock_; |
| 89 base::DictionaryValue audio_streams_cached_data_; | 132 base::DictionaryValue audio_streams_cached_data_; |
| 90 int owner_ids_[AUDIO_COMPONENT_MAX]; | 133 int owner_ids_[AUDIO_COMPONENT_MAX]; |
| 91 | 134 |
| 92 DISALLOW_COPY_AND_ASSIGN(MediaInternals); | 135 DISALLOW_COPY_AND_ASSIGN(MediaInternals); |
| 93 }; | 136 }; |
| 94 | 137 |
| 95 } // namespace content | 138 } // namespace content |
| 96 | 139 |
| 97 #endif // CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_ | 140 #endif // CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_ |
| OLD | NEW |