Index: content/renderer/media/audio_renderer_sink_cache_impl.h |
diff --git a/content/renderer/media/audio_renderer_sink_cache_impl.h b/content/renderer/media/audio_renderer_sink_cache_impl.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..fce4078a4fe5a4348ec13334b313b4c5e7b77728 |
--- /dev/null |
+++ b/content/renderer/media/audio_renderer_sink_cache_impl.h |
@@ -0,0 +1,103 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_SINK_CACHE_IMPL_H_ |
+#define CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_SINK_CACHE_IMPL_H_ |
+ |
+#include "content/renderer/media/audio_renderer_sink_cache.h" |
+ |
+#include <vector> |
+ |
+#include "base/single_thread_task_runner.h" |
+#include "base/synchronization/lock.h" |
+#include "base/time/time.h" |
+#include "content/common/content_export.h" |
+ |
+namespace content { |
+ |
+// AudioRendererSinkCache implementation. |
+class CONTENT_EXPORT AudioRendererSinkCacheImpl |
+ : public AudioRendererSinkCache { |
+ public: |
+ // Callback to be used for AudioRendererSink creation |
+ using CreateSinkCallback = |
+ base::Callback<scoped_refptr<media::AudioRendererSink>( |
+ int render_frame_id, |
+ int session_id, |
+ const std::string& device_id, |
+ const url::Origin& security_origin)>; |
+ |
+ AudioRendererSinkCacheImpl( |
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
+ const CreateSinkCallback& create_sink_callback, |
+ const base::TimeDelta delete_timeout); |
+ |
+ ~AudioRendererSinkCacheImpl() final; |
+ |
+ media::OutputDeviceInfo GetSinkInfo(int source_render_frame_id, |
+ int session_id, |
+ const std::string& device_id, |
+ const url::Origin& security_origin) final; |
+ |
+ scoped_refptr<media::AudioRendererSink> GetSink( |
+ int source_render_frame_id, |
+ const std::string& device_id, |
+ const url::Origin& security_origin) final; |
+ |
+ void ReleaseSink(const media::AudioRendererSink* sink_ptr) final; |
+ |
+ private: |
+ friend class AudioRendererSinkCacheTest; |
+ friend class CacheEntryFinder; |
+ |
+ struct CacheEntry; |
+ using CacheContainer = std::vector<CacheEntry>; |
+ |
+ // Schedules a sink for deletion. Deletion will be performed on the same |
+ // thread the cache is created on. |
+ void DeleteLaterIfUnused(const media::AudioRendererSink* sink_ptr); |
+ |
+ // Deletes a sink from the cache. If |force_delete_used| is set, a sink being |
+ // deleted can (and should) be in use at the moment of deletion; otherwise the |
+ // sink is deleted only if unused. |
+ void DeleteSink(const media::AudioRendererSink* sink_ptr, |
+ bool force_delete_used); |
+ |
+ CacheContainer::iterator FindCacheEntry_Locked( |
+ int source_render_frame_id, |
+ const std::string& device_id, |
+ const url::Origin& security_origin, |
+ bool unused_only); |
+ |
+ int GetCacheSizeForTesting(); |
Guido Urdaneta
2016/05/25 13:33:14
Is it possible to get rid of the ForTesting()?
If
o1ka
2016/05/25 14:52:11
For this I need to publish CacheEntry struct in th
Guido Urdaneta
2016/05/25 15:44:09
I guess it's better to leave it as it is for now t
o1ka
2016/05/26 09:00:27
Acknowledged.
|
+ |
+ // Task runner for scheduled sink garbage collection. |
+ const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
+ |
+ // Callback used for sink creation. |
+ const CreateSinkCallback create_sink_cb_; |
+ |
+ // Cached sink deletion timeout. |
+ // For example: (1) sink was created and cached in GetSinkInfo(), and then (2) |
+ // the same sink is requested in GetSink(), if time interval between (1) and |
+ // (2) is less than |kDeleteTimeoutMs|, then sink cached in (1) is reused in |
+ // (2). On the other hand, if after (1) nobody is interested in the sink |
+ // within |kDeleteTimeoutMs|, it is garbage-collected. |
+ const base::TimeDelta delete_timeout_; |
+ |
+ // Cached sinks, protected by lock. |
+ base::Lock cache_lock_; |
+ CacheContainer cache_; |
+ |
+ // A weak pointer to be used for delayed sink deletion on |task_runner_|. |
+ base::WeakPtr<AudioRendererSinkCacheImpl> weak_this_; |
+ |
+ base::WeakPtrFactory<AudioRendererSinkCacheImpl> weak_ptr_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(AudioRendererSinkCacheImpl); |
+}; |
+ |
+} // namespace content |
+ |
+#endif // CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_SINK_CACHE_IMPL_H_ |