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

Side by Side Diff: content/renderer/media/audio_renderer_sink_cache_impl.h

Issue 1942803002: Caching AudioOutputDevice instances in mixer manager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more review comments addressed Created 4 years, 7 months 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
OLDNEW
(Empty)
1 // Copyright 2016 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.
4
5 #ifndef CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_SINK_CACHE_IMPL_H_
6 #define CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_SINK_CACHE_IMPL_H_
7
8 #include "content/renderer/media/audio_renderer_sink_cache.h"
9
10 #include <vector>
11
12 #include "base/single_thread_task_runner.h"
13 #include "base/synchronization/lock.h"
14 #include "base/time/time.h"
15 #include "content/common/content_export.h"
16
17 namespace content {
18
19 // AudioRendererSinkCache implementation.
20 class CONTENT_EXPORT AudioRendererSinkCacheImpl
21 : public AudioRendererSinkCache {
22 public:
23 // Callback to be used for AudioRendererSink creation
24 using CreateSinkCallback =
25 base::Callback<scoped_refptr<media::AudioRendererSink>(
26 int render_frame_id,
27 int session_id,
28 const std::string& device_id,
29 const url::Origin& security_origin)>;
30
31 AudioRendererSinkCacheImpl(
32 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
33 const CreateSinkCallback& create_sink_callback,
34 const base::TimeDelta& delete_timeout);
35
36 ~AudioRendererSinkCacheImpl() final;
37
38 media::OutputDeviceInfo GetSinkInfo(int source_render_frame_id,
39 int session_id,
40 const std::string& device_id,
41 const url::Origin& security_origin) final;
42
43 scoped_refptr<media::AudioRendererSink> GetSink(
44 int source_render_frame_id,
45 const std::string& device_id,
46 const url::Origin& security_origin) final;
47
48 void ReleaseSink(const media::AudioRendererSink* sink_ptr) final;
49
50 private:
51 friend class AudioRendererSinkCacheTest;
52 friend class CacheEntryFinder;
53
54 struct CacheEntry;
55
56 // Schedules a sink for deletion. Deletion will be performed on the same
57 // thread the cache is created on.
58 void DeleteLaterIfUnused(const media::AudioRendererSink* sink_ptr);
59
60 // Deletes a sink from the cache. If |force_delete_used| is set, a sink being
61 // deleted can (and should) be in use at the moment of deletion; otherwise the
62 // sink is deleted only if unused.
63 void DeleteSink(const media::AudioRendererSink* sink_ptr,
64 bool force_delete_used);
65
66 int GetCacheSizeForTesting();
67
68 // Task runner for scheduled sink garbage collection.
69 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
70
71 // Callback used for sink creation.
72 const CreateSinkCallback create_sink_cb_;
73
74 // Cached sink deletion timeout.
75 // For example: (1) sink was created and cached in GetSinkInfo(), and then (2)
76 // the same sink is requested in GetSink(), if time interval between (1) and
77 // (2) is less than |kDeleteTimeoutMs|, then sink cached in (1) is reused in
78 // (2). On the other hand, if after (1) nobody is interested in the sink
79 // within |kDeleteTimeoutMs|, it is garbage-collected.
80 const base::TimeDelta delete_timeout_;
81
82 // Cached sinks, protected by lock.
83 base::Lock cache_lock_;
84 std::vector<CacheEntry> cache_;
85
86 base::WeakPtrFactory<AudioRendererSinkCacheImpl> weak_ptr_factory_;
87
88 DISALLOW_COPY_AND_ASSIGN(AudioRendererSinkCacheImpl);
89 };
90
91 } // namespace content
92
93 #endif // CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_SINK_CACHE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698