summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/media/cast_receiver_audio_valve.h
blob: 4ac8a93b433a726fdf86d19e50277085fbce171e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2015 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 CHROME_RENDERER_MEDIA_CAST_RECEIVER_AUDIO_VALVE_H_
#define CHROME_RENDERER_MEDIA_CAST_RECEIVER_AUDIO_VALVE_H_

#include "base/synchronization/lock.h"
#include "media/base/audio_capturer_source.h"

namespace media {
class AudioBus;
}

// Forwards calls to |cb| until Stop is called.
// Thread-safe.
// All functions may block depending on contention.
class CastReceiverAudioValve :
    public media::AudioCapturerSource::CaptureCallback,
    public base::RefCountedThreadSafe<CastReceiverAudioValve> {
 public:
  explicit CastReceiverAudioValve(
      media::AudioCapturerSource::CaptureCallback* cb);

  // AudioCapturerSource::CaptureCallback implementation.
  void Capture(const media::AudioBus* audio_source,
               int audio_delay_milliseconds,
               double volume,
               bool key_pressed) override;
  void OnCaptureError() override;

  // When this returns, no more calls will be forwarded to |cb|.
  void Stop();

 private:
  friend class base::RefCountedThreadSafe<CastReceiverAudioValve>;
  ~CastReceiverAudioValve() override;
  media::AudioCapturerSource::CaptureCallback* cb_;
  base::Lock lock_;
};

#endif  // CHROME_RENDERER_MEDIA_CAST_RECEIVER_AUDIO_VALVE_H_