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/tuple.h" | |
|
perkj_chrome
2014/10/08 11:49:59
not used?
mcasas
2014/10/08 14:05:18
Done.
| |
| 16 #include "base/values.h" | 17 #include "base/values.h" |
| 17 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
| 18 #include "media/audio/audio_logging.h" | 19 #include "media/audio/audio_logging.h" |
| 20 #include "media/video/capture/video_capture_device.h" | |
| 21 #include "media/video/capture/video_capture_types.h" | |
| 19 | 22 |
| 20 namespace media { | 23 namespace media { |
| 21 class AudioParameters; | 24 class AudioParameters; |
| 22 struct MediaLogEvent; | 25 struct MediaLogEvent; |
| 23 } | 26 } |
| 24 | 27 |
| 25 namespace content { | 28 namespace content { |
| 26 | 29 |
| 27 // This class stores information about currently active media. | 30 // This class stores information about currently active media. |
| 28 class CONTENT_EXPORT MediaInternals | 31 class CONTENT_EXPORT MediaInternals |
| 29 : NON_EXPORTED_BASE(public media::AudioLogFactory) { | 32 : NON_EXPORTED_BASE(public media::AudioLogFactory) { |
| 30 public: | 33 public: |
| 34 // Called with the update string. | |
| 35 typedef base::Callback<void(const base::string16&)> UpdateCallback; | |
| 36 | |
| 31 static MediaInternals* GetInstance(); | 37 static MediaInternals* GetInstance(); |
| 32 | 38 |
| 33 virtual ~MediaInternals(); | 39 virtual ~MediaInternals(); |
| 34 | 40 |
| 35 // Called when a MediaEvent occurs. | 41 // Called when a MediaEvent occurs. |
| 36 void OnMediaEvents(int render_process_id, | 42 void OnMediaEvents(int render_process_id, |
| 37 const std::vector<media::MediaLogEvent>& events); | 43 const std::vector<media::MediaLogEvent>& events); |
| 38 | 44 |
| 39 // Called with the update string. | |
| 40 typedef base::Callback<void(const base::string16&)> UpdateCallback; | |
| 41 | |
| 42 // Add/remove update callbacks (see above). Must be called on the IO thread. | 45 // Add/remove update callbacks (see above). Must be called on the IO thread. |
| 43 void AddUpdateCallback(const UpdateCallback& callback); | 46 void AddUpdateCallback(const UpdateCallback& callback); |
| 44 void RemoveUpdateCallback(const UpdateCallback& callback); | 47 void RemoveUpdateCallback(const UpdateCallback& callback); |
| 45 | 48 |
| 46 // Sends all cached data to each registered UpdateCallback. | 49 // Sends all audio cached data to each registered UpdateCallback. |
| 47 void SendEverything(); | 50 void SendAudioStreamData(); |
| 51 | |
| 52 // Called to inform of the capabilities enumerated for a video device. | |
| 53 void UpdateVideoCaptureDeviceCapabilities( | |
| 54 const media::VideoCaptureDevice::DeviceInfos& name_and_formats); | |
| 48 | 55 |
| 49 // AudioLogFactory implementation. Safe to call from any thread. | 56 // AudioLogFactory implementation. Safe to call from any thread. |
| 50 virtual scoped_ptr<media::AudioLog> CreateAudioLog( | 57 virtual scoped_ptr<media::AudioLog> CreateAudioLog( |
| 51 AudioComponent component) override; | 58 AudioComponent component) override; |
| 52 | 59 |
| 53 private: | 60 private: |
| 54 friend class AudioLogImpl; | 61 friend class AudioLogImpl; |
| 55 friend class MediaInternalsTest; | 62 friend class MediaInternalsTest; |
| 56 friend struct base::DefaultLazyInstanceTraits<MediaInternals>; | 63 friend struct base::DefaultLazyInstanceTraits<MediaInternals>; |
| 57 | 64 |
| 58 MediaInternals(); | 65 MediaInternals(); |
| 59 | 66 |
| 60 // Sends |update| to each registered UpdateCallback. Safe to call from any | 67 // Sends |update| to each registered UpdateCallback. Safe to call from any |
| 61 // thread, but will forward to the IO thread. | 68 // thread, but will forward to the IO thread. |
| 62 void SendUpdate(const base::string16& update); | 69 void SendUpdate(const base::string16& update); |
| 63 | 70 |
| 64 // Caches |value| under |cache_key| so that future SendEverything() calls will | 71 // Caches |value| under |cache_key| so that future SendAudioStreamData() calls |
| 65 // include the current data. Calls JavaScript |function|(|value|) for each | 72 // will include the current data. Calls JavaScript |function|(|value|) for |
| 66 // registered UpdateCallback. SendUpdateAndPurgeCache() is similar but purges | 73 // each registered UpdateCallback. SendUpdateAndPurgeCache() is similar but |
| 67 // the cache entry after completion instead. | 74 // purges the cache entry after completion instead. |
| 68 void SendUpdateAndCache(const std::string& cache_key, | 75 void SendUpdateAndCacheAudioStreamKey(const std::string& cache_key, |
| 69 const std::string& function, | 76 const std::string& function, |
| 70 const base::DictionaryValue* value); | 77 const base::DictionaryValue* value); |
| 71 void SendUpdateAndPurgeCache(const std::string& cache_key, | 78 void SendUpdateAndPurgeAudioStreamCache(const std::string& cache_key, |
| 72 const std::string& function, | 79 const std::string& function, |
| 73 const base::DictionaryValue* value); | 80 const base::DictionaryValue* value); |
| 81 | |
| 74 // Must only be accessed on the IO thread. | 82 // Must only be accessed on the IO thread. |
| 75 std::vector<UpdateCallback> update_callbacks_; | 83 std::vector<UpdateCallback> update_callbacks_; |
| 76 | 84 |
| 77 // All variables below must be accessed under |lock_|. | 85 // All variables below must be accessed under |lock_|. |
| 78 base::Lock lock_; | 86 base::Lock lock_; |
| 79 base::DictionaryValue cached_data_; | 87 base::DictionaryValue audio_streams_cached_data_; |
| 80 int owner_ids_[AUDIO_COMPONENT_MAX]; | 88 int owner_ids_[AUDIO_COMPONENT_MAX]; |
| 81 | 89 |
| 82 DISALLOW_COPY_AND_ASSIGN(MediaInternals); | 90 DISALLOW_COPY_AND_ASSIGN(MediaInternals); |
| 83 }; | 91 }; |
| 84 | 92 |
| 85 } // namespace content | 93 } // namespace content |
| 86 | 94 |
| 87 #endif // CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_ | 95 #endif // CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_ |
| OLD | NEW |