Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(462)

Side by Side Diff: media/audio/linux/cras_input.h

Issue 10592014: media/audio/linux: Add CrasInputStream. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebase before trying cq Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/audio/linux/audio_manager_linux.cc ('k') | media/audio/linux/cras_input.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 MEDIA_AUDIO_LINUX_CRAS_INPUT_H_
6 #define MEDIA_AUDIO_LINUX_CRAS_INPUT_H_
7
8 #include <cras_client.h>
9
10 #include <string>
11
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/time.h"
16 #include "media/audio/audio_input_stream_impl.h"
17 #include "media/audio/audio_io.h"
18 #include "media/audio/audio_parameters.h"
19
20 namespace media {
21
22 class AudioManagerLinux;
23
24 // Provides an input stream for audio capture based on CRAS, the ChromeOS Audio
25 // Server. This object is not thread safe and all methods should be invoked in
26 // the thread that created the object.
27 class CrasInputStream : public AudioInputStreamImpl {
28 public:
29 // The ctor takes all the usual parameters, plus |manager| which is the
30 // audio manager who is creating this object.
31 CrasInputStream(const AudioParameters& params, AudioManagerLinux* manager);
32
33 // The dtor is typically called by the AudioManager only and it is usually
34 // triggered by calling AudioOutputStream::Close().
35 virtual ~CrasInputStream();
36
37 // Implementation of AudioInputStream.
38 virtual bool Open() OVERRIDE;
39 virtual void Start(AudioInputCallback* callback) OVERRIDE;
40 virtual void Stop() OVERRIDE;
41 virtual void Close() OVERRIDE;
42 virtual double GetMaxVolume() OVERRIDE;
43 virtual void SetVolume(double volume) OVERRIDE;
44 virtual double GetVolume() OVERRIDE;
45
46 private:
47 // Handles requests to get samples from the provided buffer. This will be
48 // called by the audio server when it has samples ready.
49 static int SamplesReady(cras_client* client,
50 cras_stream_id_t stream_id,
51 uint8* samples,
52 size_t frames,
53 const timespec* sample_ts,
54 void* arg);
55
56 // Handles notificaiton that there was an error with the playback stream.
57 static int StreamError(cras_client* client,
58 cras_stream_id_t stream_id,
59 int err,
60 void* arg);
61
62 // Reads one or more buffers of audio from the device, passes on to the
63 // registered callback. Called from SamplesReady().
64 void ReadAudio(size_t frames, uint8* buffer, const timespec* sample_ts);
65
66 // Deals with an error that occured in the stream. Called from StreamError().
67 void NotifyStreamError(int err);
68
69 // Convert from dB * 100 to a volume ratio.
70 double GetVolumeRatioFromDecibels(double dB) const;
71
72 // Convert from a volume ratio to dB.
73 double GetDecibelsFromVolumeRatio(double volume_ratio) const;
74
75 // Non-refcounted pointer back to the audio manager.
76 // The AudioManager indirectly holds on to stream objects, so we don't
77 // want circular references. Additionally, stream objects live on the audio
78 // thread, which is owned by the audio manager and we don't want to addref
79 // the manager from that thread.
80 AudioManagerLinux* audio_manager_;
81
82 // Size of frame in bytes.
83 uint32 bytes_per_frame_;
84
85 // Callback to pass audio samples too, valid while recording.
86 AudioInputCallback* callback_;
87
88 // The client used to communicate with the audio server.
89 cras_client* client_;
90
91 // PCM parameters for the stream.
92 AudioParameters params_;
93
94 // True if the stream has been started.
95 bool started_;
96
97 // ID of the playing stream.
98 cras_stream_id_t stream_id_;
99
100 DISALLOW_COPY_AND_ASSIGN(CrasInputStream);
101 };
102
103 } // namespace media
104
105 #endif // MEDIA_AUDIO_LINUX_ALSA_INPUT_H_
OLDNEW
« no previous file with comments | « media/audio/linux/audio_manager_linux.cc ('k') | media/audio/linux/cras_input.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698