OLD | NEW |
---|---|
(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 "content/common/content_export.h" | |
15 | |
16 namespace content { | |
17 | |
18 // AudioRendererSinkCache implementation. | |
19 class CONTENT_EXPORT AudioRendererSinkCacheImpl | |
20 : public AudioRendererSinkCache { | |
21 public: | |
22 // Callback to be used for AudioRendererSink creation | |
23 using CreateSinkCallback = | |
24 base::Callback<scoped_refptr<media::AudioRendererSink>( | |
25 int render_frame_id, | |
26 int session_id, | |
27 const std::string& device_id, | |
28 const url::Origin& security_origin)>; | |
29 | |
30 AudioRendererSinkCacheImpl( | |
31 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
32 const CreateSinkCallback& create_sink_callback, | |
33 int delete_timeout_ms); | |
34 | |
35 ~AudioRendererSinkCacheImpl() final; | |
36 | |
37 media::OutputDeviceInfo GetSinkInfo(int source_render_frame_id, | |
38 int session_id, | |
39 const std::string& device_id, | |
40 const url::Origin& security_origin) final; | |
41 | |
42 scoped_refptr<media::AudioRendererSink> GetSink( | |
43 int source_render_frame_id, | |
44 const std::string& device_id, | |
45 const url::Origin& security_origin) final; | |
46 | |
47 void ReleaseSink(const media::AudioRendererSink* sink_ptr) final; | |
48 | |
49 private: | |
50 friend class AudioRendererSinkCacheTest; | |
51 friend class CacheEntryFinder; | |
52 | |
53 struct CacheEntry; | |
54 | |
55 // Schedules a sink for deletion. Deletion will be performed on the same | |
56 // thread the cache is created on. | |
57 void DeleteLaterIfUnused(const media::AudioRendererSink* sink_ptr); | |
58 | |
59 // Deletes a sink from the cache. If |force_delete_used| is set, a sink being | |
60 // deleted can (and should) be in use at the moment of deletion; otherwise the | |
61 // sink is deleted only if unused. | |
62 void DeleteSink(const media::AudioRendererSink* sink_ptr, | |
63 bool force_delete_used); | |
64 | |
65 int GetCacheSizeForTesting(); | |
66 | |
67 // Task runner for scheduled sink garbage collection. | |
68 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
69 | |
70 // Callback used for sink creation. | |
71 const CreateSinkCallback create_sink_cb_; | |
72 | |
73 // Cached sink deletion timeout. | |
74 // For example: (1) sink was created and cached in GetSinkInfo(), and then (2) | |
75 // the same sink is requested in GetSink(), if time interval between (1) and | |
76 // (2) is less than |kDeleteTimeoutMs|, then sink cached in (1) is reused in | |
77 // (2). On the other hand, if after (1) nobody is interested in the sink | |
78 // within |kDeleteTimeoutMs|, it is garbage-collected. | |
79 const int delete_timeout_ms_; | |
DaleCurtis
2016/05/23 18:29:08
Just use a TimeDelta?
o1ka
2016/05/24 15:00:41
Done.
| |
80 | |
81 // Cached sinks, protected by lock. | |
82 base::Lock cache_lock_; | |
83 std::vector<CacheEntry> cache_; | |
84 | |
85 base::WeakPtrFactory<AudioRendererSinkCacheImpl> weak_ptr_factory_; | |
86 | |
87 DISALLOW_COPY_AND_ASSIGN(AudioRendererSinkCacheImpl); | |
88 }; | |
89 | |
90 } // namespace content | |
91 | |
92 #endif // CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_SINK_CACHE_IMPL_H_ | |
OLD | NEW |