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

Side by Side Diff: media/audio/pulse/pulse_input.h

Issue 10952024: Adding pulseaudio input support to chrome (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased and ready for review. Created 7 years, 11 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 | Annotate | Revision Log
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
6 #ifndef MEDIA_AUDIO_PULSE_PULSE_INPUT_H_
7 #define MEDIA_AUDIO_PULSE_PULSE_INPUT_H_
8
9 #include <pulse/pulseaudio.h>
10
11 #include <string>
12
13 #include "media/audio/audio_device_name.h"
14 #include "media/audio/audio_input_stream_impl.h"
15 #include "media/audio/audio_io.h"
16 #include "media/audio/audio_parameters.h"
17
18 namespace media {
19
20 class AudioManagerLinux;
21 class SeekableBuffer;
22
23 class PulseAudioInputStream : public AudioInputStreamImpl {
24 public:
25 PulseAudioInputStream(AudioManagerLinux* audio_manager,
26 const std::string& device_name,
27 const AudioParameters& params,
28 pa_threaded_mainloop* mainloop,
29 pa_context* context);
30
31 virtual ~PulseAudioInputStream();
32
33 // Implementation of AudioInputStream.
34 virtual bool Open() OVERRIDE;
35 virtual void Start(AudioInputCallback* callback) OVERRIDE;
36 virtual void Stop() OVERRIDE;
37 virtual void Close() OVERRIDE;
38 virtual double GetMaxVolume() OVERRIDE;
39 virtual void SetVolume(double volume) OVERRIDE;
40 virtual double GetVolume() OVERRIDE;
41
42 private:
43 // PulseAudio Callbacks.
44 static void ContextStateCallback(pa_context* context, void* user_data);
45 static void ReadCallback(pa_stream* handle, size_t length, void* user_data);
46 static void StreamNotifyCallback(pa_stream* stream, void* user_data);
47 static void VolumeCallback(pa_context* context, const pa_source_info* info,
48 int error, void* user_data);
49
50 // Helper function to get latency in bytes.
51 int GetHardwareLatencyInBytes();
52
53 // Helper for the ReadCallback.
54 void ReadData();
55
56 // Flag indicating the state of the context has been changed.
57 bool context_state_changed_;
58
59 AudioManagerLinux* audio_manager_;
60 AudioInputCallback* callback_;
61 std::string device_name_;
62 AudioParameters params_;
63 int channels_;
64 double volume_;
65
66 // Flag indicating the code should stop reading from the data source or
67 // writing to the PulseAudio server. This is set because the device has
68 // entered an unrecoverable error state, or the Stio() has executed.
69 bool stream_started_;
70
71 // Holds the data from the OS.
72 scoped_ptr<media::SeekableBuffer> buffer_;
73
74 // Temporary storage for recorded data. It gets a packet of data from
75 // |buffer_| and deliver the data to OnData() callback.
76 scoped_array<uint8> audio_data_buffer_;
77
78 // PulseAudio API structs.
79 pa_threaded_mainloop* pa_mainloop_; // Weak.
80 pa_context* pa_context_; // Weak.
81 pa_stream* handle_;
82
83 DISALLOW_COPY_AND_ASSIGN(PulseAudioInputStream);
84 };
85
86 } // namespace media
87
88 #endif // MEDIA_AUDIO_PULSE_PULSE_OUTPUT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698