Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: content/browser/media/media_internals.h

Issue 68173025: Introduce new interface for MediaInternals updates. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add impl. Maintain sanity? Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/memory/ref_counted.h" 11 #include "base/callback_forward.h"
12 #include "base/memory/singleton.h" 12 #include "base/lazy_instance.h"
13 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
14 #include "base/synchronization/lock.h"
14 #include "base/values.h" 15 #include "base/values.h"
15 #include "content/common/content_export.h" 16 #include "content/common/content_export.h"
16 #include "content/public/common/media_stream_request.h" 17 #include "media/audio/audio_logging.h"
17 18
18 namespace media { 19 namespace media {
19 class AudioParameters; 20 class AudioParameters;
20 struct MediaLogEvent; 21 struct MediaLogEvent;
21 } 22 }
22 23
23 namespace content { 24 namespace content {
24 25
25 // This class stores information about currently active media. 26 // This class stores information about currently active media.
26 // It's constructed on the UI thread but all of its methods are called on the IO 27 class CONTENT_EXPORT MediaInternals : public media::AudioLogFactory {
acolwell GONE FROM CHROMIUM 2013/11/22 21:01:21 Since this is the only object that derives from Au
DaleCurtis 2013/11/22 21:16:03 Most of the audio code lives in media/ not content
27 // thread.
28 class CONTENT_EXPORT MediaInternals {
29 public: 28 public:
29 static MediaInternals* GetInstance();
30
30 virtual ~MediaInternals(); 31 virtual ~MediaInternals();
31 32
32 static MediaInternals* GetInstance();
33
34 // The following methods are virtual for gmock.
35
36 // Called when an audio stream is deleted.
37 virtual void OnDeleteAudioStream(void* host, int stream_id);
38
39 // Called when an audio stream is set to playing or paused.
40 virtual void OnSetAudioStreamPlaying(void* host, int stream_id, bool playing);
41
42 // Called when an audio stream is created with the parameters that
43 // it attempts to use to make the stream.
44 virtual void OnAudioStreamCreated(void* host,
45 int stream_id,
46 const media::AudioParameters& params,
47 const std::string& input_device_id);
48
49 // Called when the status of an audio stream is set to "created", "closed", or
50 // "error".
51 virtual void OnSetAudioStreamStatus(void* host, int stream_id,
52 const std::string& status);
53
54 // Called when the volume of an audio stream is set.
55 virtual void OnSetAudioStreamVolume(void* host, int stream_id,
56 double volume);
57
58 // Called when a MediaEvent occurs. 33 // Called when a MediaEvent occurs.
59 virtual void OnMediaEvents(int render_process_id, 34 void OnMediaEvents(int render_process_id,
60 const std::vector<media::MediaLogEvent>& events); 35 const std::vector<media::MediaLogEvent>& events);
61 36
62 // Called with the update string. 37 // Called with the update string.
63 typedef base::Callback<void(const string16&)> UpdateCallback; 38 typedef base::Callback<void(const string16&)> UpdateCallback;
64 39
65 // Add/remove update callbacks (see above). 40 // Add/remove update callbacks (see above). Must be called on the IO thread.
66 void AddUpdateCallback(const UpdateCallback& callback); 41 void AddUpdateCallback(const UpdateCallback& callback);
67 void RemoveUpdateCallback(const UpdateCallback& callback); 42 void RemoveUpdateCallback(const UpdateCallback& callback);
43
44 // Sends all cached data to each registered UpdateCallback.
68 void SendEverything(); 45 void SendEverything();
69 46
47 // AudioLogFactory implementation. Safe to call from any thread.
48 virtual scoped_ptr<media::AudioLog> CreateAudioLog(
49 AudioComponent component) OVERRIDE;
50
70 private: 51 private:
71 friend class MockMediaInternals; 52 friend class AudioLogImpl;
72 friend class MediaInternalsTest; 53 friend class MediaInternalsTest;
73 friend struct DefaultSingletonTraits<MediaInternals>; 54 friend struct base::DefaultLazyInstanceTraits<MediaInternals>;
74 55
75 MediaInternals(); 56 MediaInternals();
76 57
77 // Sets |property| of an audio stream to |value| and notifies observers. 58 // Sends |update| to each registered UpdateCallback. Safe to call from any
78 // (host, stream_id) is a unique id for the audio stream. 59 // thread, but will forward to the IO thread.
79 // |host| will never be dereferenced. 60 void SendUpdate(const string16& update);
80 void UpdateAudioStream(void* host, int stream_id,
81 const std::string& property, base::Value* value);
82 61
83 // See UpdateAudioStream. The difference is that StoreAudioStream does not 62 // Caches |value| under |cache_key| so that future SendEverything() calls will
84 // immediately send the data to the client, instead it waits until 63 // include the current data. Calls JavaScript |function|(|value|) for each
85 // SendEverything is called. 64 // registered UpdateCallback. SendUpdateAndPurgeCache() is similar but purges
86 void StoreAudioStream(void* host, 65 // the cache entry after completion instead.
87 int stream_id, 66 void SendUpdateAndCache(const std::string& cache_key,
88 const std::string& property, 67 const std::string& function,
89 base::Value* value); 68 const base::DictionaryValue* value);
69 void SendUpdateAndPurgeCache(const std::string& cache_key,
70 const std::string& function,
71 const base::DictionaryValue* value);
72 // Must only be accessed on the IO thread.
73 std::vector<UpdateCallback> update_callbacks_;
90 74
91 // Removes |item| from |data_|. 75 base::Lock cache_lock_;
92 void DeleteItem(const std::string& item); 76 base::DictionaryValue cached_data_;
93 77 int owner_ids_[AUDIO_COMPONENT_MAX];
94 base::DictionaryValue* StoreItem(const std::string& id,
95 const std::string& property,
96 base::Value* value);
97
98 // Sets data_.id.property = value and notifies attached UIs using update_fn.
99 // id may be any depth, e.g. "video.decoders.1.2.3"
100 void UpdateItem(const std::string& update_fn, const std::string& id,
101 const std::string& property, base::Value* value);
102
103 // Calls javascript |function|(|value|) on each attached UI.
104 void SendUpdate(const std::string& function, base::Value* value);
105
106 base::DictionaryValue data_;
107
108 std::vector<UpdateCallback> update_callbacks_;
109 78
110 DISALLOW_COPY_AND_ASSIGN(MediaInternals); 79 DISALLOW_COPY_AND_ASSIGN(MediaInternals);
111 }; 80 };
112 81
113 } // namespace content 82 } // namespace content
114 83
115 #endif // CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_ 84 #endif // CONTENT_BROWSER_MEDIA_MEDIA_INTERNALS_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/media/media_internals.cc » ('j') | content/browser/media/media_internals.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698