Chromium Code Reviews| 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..836b5711668a1a725dcba5b94c7cbdb0b1825645 |
| --- /dev/null |
| +++ b/content/renderer/media/audio_renderer_sink_cache_impl.h |
| @@ -0,0 +1,92 @@ |
| +// 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 "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, |
| + int delete_timeout_ms); |
| + |
| + ~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; |
| + |
| + // 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); |
| + |
| + int GetCacheSizeForTesting(); |
| + |
| + // 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 int delete_timeout_ms_; |
|
DaleCurtis
2016/05/23 18:29:08
Just use a TimeDelta?
o1ka
2016/05/24 15:00:41
Done.
|
| + |
| + // Cached sinks, protected by lock. |
| + base::Lock cache_lock_; |
| + std::vector<CacheEntry> cache_; |
| + |
| + base::WeakPtrFactory<AudioRendererSinkCacheImpl> weak_ptr_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(AudioRendererSinkCacheImpl); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_SINK_CACHE_IMPL_H_ |