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

Side by Side Diff: media/audio/cras/cras_output.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: Save params, other cleanups suggested by Dale 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
« no previous file with comments | « media/audio/cras/cras_input.cc ('k') | media/audio/cras/cras_output.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 // Creates an output stream based on the cras (ChromeOS audio server) interface.
6 //
7 // CrasOutputStream object is *not* thread-safe and should only be used
8 // from the audio thread.
9
10 #ifndef MEDIA_AUDIO_CRAS_CRAS_OUTPUT_H_
11 #define MEDIA_AUDIO_CRAS_CRAS_OUTPUT_H_
12
13 #include <alsa/asoundlib.h>
14 #include <cras_client.h>
15 #include <ostream>
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 CrasOutputStream : 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 CrasOutputStream(const AudioParameters& params, AudioManagerCras* manager);
33
34 // The dtor is typically called by the AudioManager only and it is usually
35 // triggered by calling AudioOutputStream::Close().
36 virtual ~CrasOutputStream();
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 // Flags indicating the state of the stream.
47 enum InternalState {
48 kInError = 0,
49 kCreated,
50 kIsOpened,
51 kIsPlaying,
52 kIsStopped,
53 kIsClosed
54 };
55 friend std::ostream& operator<<(std::ostream& os, InternalState);
56 // Reports the current state for unit testing.
57 InternalState state();
58
59 private:
60 // Handles requests to put samples in the provided buffer. This will be
61 // called by the audio server when it needs more data.
62 static int PutSamples(cras_client* client,
63 cras_stream_id_t stream_id,
64 uint8* samples,
65 size_t frames,
66 const timespec* sample_ts,
67 void* arg);
68
69 // Handles notificaiton that there was an error with the playback stream.
70 static int StreamError(cras_client* client,
71 cras_stream_id_t stream_id,
72 int err,
73 void* arg);
74
75 // Actually fills buffer with audio data. Called from PutSamples().
76 uint32 Render(size_t frames, uint8* buffer, const timespec* sample_ts);
77
78 // Deals with an error that occured in the stream. Called from StreamError().
79 void NotifyStreamError(int err);
80
81 // Functions to safeguard state transitions. All changes to the object state
82 // should go through these functions.
83 bool CanTransitionTo(InternalState to);
84 InternalState TransitionTo(InternalState to);
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 num_channels_;
103
104 // PCM format for Alsa.
105 const snd_pcm_format_t pcm_format_;
106
107 // Current state.
108 InternalState state_;
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 retrieving data from AudioSourceCallback::OnMoreData().
120 scoped_ptr<AudioBus> audio_bus_;
121
122 DISALLOW_COPY_AND_ASSIGN(CrasOutputStream);
123 };
124
125 } // namespace media
126
127 #endif // MEDIA_AUDIO_CRAS_CRAS_OUTPUT_H_
OLDNEW
« no previous file with comments | « media/audio/cras/cras_input.cc ('k') | media/audio/cras/cras_output.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698