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

Side by Side Diff: media/audio/cras/cras_unified.h

Issue 11959018: Add a unified audio I/O backend for ChromeOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed unittest too Created 7 years, 9 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
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
no longer working on chromium 2013/03/21 15:38:27 nit, remove the (c), and change 2012 to 2013
dgreid 2013/03/21 17:18:44 Done.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 // Creates a unified stream based on the cras (ChromeOS audio server) interface.
6 //
7 // CrasUnifiedStream object is *not* thread-safe and should only be used
8 // from the audio thread.
9
10 #ifndef MEDIA_AUDIO_LINUX_CRAS_UNIFIED_H_
11 #define MEDIA_AUDIO_LINUX_CRAS_UNIFIED_H_
12
13 #include <alsa/asoundlib.h>
14 #include <cras_client.h>
15 #include <ostream>
no longer working on chromium 2013/03/21 15:38:27 may I ask where ostream is used?
dgreid 2013/03/21 17:18:44 It isn't, removed.
16
17 #include "base/compiler_specific.h"
18 #include "base/gtest_prod_util.h"
19 #include "media/audio/audio_io.h"
20
21 namespace media {
22
23 class AudioManagerCras;
24 class AudioParameters;
25
26 // Implementation of AudioOuputStream for Chrome OS using the Chrome OS audio
27 // server.
28 class MEDIA_EXPORT CrasUnifiedStream : public AudioOutputStream {
29 public:
30 // The ctor takes all the usual parameters, plus |manager| which is the
31 // audio manager who is creating this object.
32 CrasUnifiedStream(const AudioParameters& params, AudioManagerCras* manager);
33
34 // The dtor is typically called by the AudioManager only and it is usually
35 // triggered by calling AudioUnifiedStream::Close().
36 virtual ~CrasUnifiedStream();
37
38 // Implementation of AudioOutputStream.
39 virtual bool Open() OVERRIDE;
40 virtual void Close() OVERRIDE;
41 virtual void Start(AudioSourceCallback* callback) OVERRIDE;
42 virtual void Stop() OVERRIDE;
43 virtual void SetVolume(double volume) OVERRIDE;
44 virtual void GetVolume(double* volume) OVERRIDE;
45
46 private:
47 // Convert Latency in time to bytes.
48 unsigned int GetBytesLatency(const struct timespec& latency);
49
50 // Handles captured audio and fills the ouput with audio to be played.
51 static int UnifiedCallback(cras_client* client,
52 cras_stream_id_t stream_id,
53 uint8* input_samples,
54 uint8* output_samples,
55 unsigned int frames,
56 const timespec* input_ts,
57 const timespec* output_ts,
58 void* arg);
59
60 // Handles notificaiton that there was an error with the playback stream.
61 static int StreamError(cras_client* client,
62 cras_stream_id_t stream_id,
63 int err,
64 void* arg);
65
66 // Chooses the correct audio callback based on stream direction.
67 uint32 DispatchCalback(size_t frames,
68 uint8* input_samples,
69 uint8* output_samples,
70 const timespec* input_ts,
71 const timespec* output_ts);
72
73 // Receives input samples and write output samples for a unified I/O stream.
74 uint32 ReadWriteAudio(size_t frames,
75 uint8* input_samples,
76 uint8* output_samples,
77 const timespec* input_ts,
78 const timespec* output_ts);
79
80 // Writes audio for a playback stream.
81 uint32 WriteAudio(size_t frames, uint8* buffer, const timespec* sample_ts);
82
83 // Deals with an error that occured in the stream. Called from StreamError().
84 void NotifyStreamError(int err);
85
86 // The client used to communicate with the audio server.
87 cras_client* client_;
88
89 // ID of the playing stream.
90 cras_stream_id_t stream_id_;
91
92 // Packet size in samples.
93 uint32 samples_per_packet_;
94
95 // Size of frame in bytes.
96 uint32 bytes_per_frame_;
97
98 // Rate in Hz.
99 size_t frame_rate_;
100
101 // Number of channels.
102 size_t output_channels_;
103
104 // PCM format for Alsa.
105 const snd_pcm_format_t pcm_format_;
106
107 // True if stream is playing.
108 bool is_playing_;
109
110 // Volume level from 0.0 to 1.0.
111 float volume_;
112
113 // Audio manager that created us. Used to report that we've been closed.
114 AudioManagerCras* manager_;
115
116 // Callback to get audio samples.
117 AudioSourceCallback* source_callback_;
118
119 // Container for exchanging data with AudioSourceCallback::OnMoreIOData().
120 scoped_ptr<AudioBus> input_bus_;
121 scoped_ptr<AudioBus> output_bus_;
122
123 // Direciton of the stream.
124 CRAS_STREAM_DIRECTION stream_direction_;
125
126 DISALLOW_COPY_AND_ASSIGN(CrasUnifiedStream);
127 };
128
129 } // namespace media
130
131 #endif // MEDIA_AUDIO_LINUX_CRAS_UNIFIED_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698