summaryrefslogtreecommitdiffstats
path: root/media/base/audio_capturer_source.h
blob: fd79db3dfcd7f4ccfe3c9e711b51863dd97b133d (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (c) 2012 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 MEDIA_BASE_AUDIO_CAPTURER_SOURCE_H_
#define MEDIA_BASE_AUDIO_CAPTURER_SOURCE_H_

#include <string>
#include <vector>
#include "base/memory/ref_counted.h"
#include "media/audio/audio_parameters.h"
#include "media/base/audio_bus.h"
#include "media/base/media_export.h"

namespace media {

// AudioCapturerSource is an interface representing the source for
// captured audio.  An implementation will periodically call Capture() on a
// callback object.
class AudioCapturerSource
    : public base::RefCountedThreadSafe<media::AudioCapturerSource> {
 public:
  class CaptureCallback {
   public:
    // Callback to deliver the captured data from the OS.
    // TODO(chcunningham): Update delay argument to use frames instead of
    // milliseconds to prevent loss of precision. See http://crbug.com/587291.
    virtual void Capture(const AudioBus* audio_source,
                         int audio_delay_milliseconds,
                         double volume,
                         bool key_pressed) = 0;

    // Signals an error has occurred.
    virtual void OnCaptureError(const std::string& message) = 0;

   protected:
    virtual ~CaptureCallback() {}
  };

  // Sets information about the audio stream format and the device
  // to be used. It must be called before any of the other methods.
  // The |session_id| is used by the browser to identify which input device to
  // be used. For clients who do not care about device permission and device
  // selection, pass |session_id| using
  // AudioInputDeviceManager::kFakeOpenSessionId.
  virtual void Initialize(const AudioParameters& params,
                          CaptureCallback* callback,
                          int session_id) = 0;

  // Starts the audio recording.
  virtual void Start() = 0;

  // Stops the audio recording. This API is synchronous, and no more data
  // callback will be passed to the client after it is being called.
  virtual void Stop() = 0;

  // Sets the capture volume, with range [0.0, 1.0] inclusive.
  virtual void SetVolume(double volume) = 0;

  // Enables or disables the WebRtc AGC control.
  virtual void SetAutomaticGainControl(bool enable) = 0;

 protected:
  friend class base::RefCountedThreadSafe<AudioCapturerSource>;
  virtual ~AudioCapturerSource() {}
};

}  // namespace media

#endif  // MEDIA_BASE_AUDIO_CAPTURER_SOURCE_H_