cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / media / audio / pulse / pulse_unified.h
bloba800d099a109ff0d2941a32b9865930ff76ebaf5
1 // Copyright 2013 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.
5 #ifndef MEDIA_AUDIO_PULSE_PULSE_UNIFIED_H_
6 #define MEDIA_AUDIO_PULSE_PULSE_UNIFIED_H_
8 #include <pulse/pulseaudio.h>
9 #include <string>
11 #include "base/memory/scoped_ptr.h"
12 #include "media/audio/audio_io.h"
13 #include "media/audio/audio_parameters.h"
14 #include "media/base/audio_fifo.h"
16 namespace media {
18 class AudioManagerBase;
19 class SeekableBuffer;
21 class PulseAudioUnifiedStream : public AudioOutputStream {
22 public:
23 PulseAudioUnifiedStream(const AudioParameters& params,
24 const std::string& input_device_id,
25 AudioManagerBase* manager);
27 virtual ~PulseAudioUnifiedStream();
29 // Implementation of PulseAudioUnifiedStream.
30 virtual bool Open() OVERRIDE;
31 virtual void Close() OVERRIDE;
32 virtual void Start(AudioSourceCallback* callback) OVERRIDE;
33 virtual void Stop() OVERRIDE;
34 virtual void SetVolume(double volume) OVERRIDE;
35 virtual void GetVolume(double* volume) OVERRIDE;
37 private:
38 // Called by PulseAudio when |pa_stream_| change state. If an unexpected
39 // failure state change happens and |source_callback_| is set
40 // this method will forward the error via OnError().
41 static void StreamNotifyCallback(pa_stream* s, void* user_data);
43 // Called by PulseAudio recording stream when it has data.
44 static void ReadCallback(pa_stream* s, size_t length, void* user_data);
46 // Helpers for ReadCallback() to read and write data.
47 void WriteData(size_t requested_bytes);
48 void ReadData();
50 // Close() helper function to free internal structs.
51 void Reset();
53 // AudioParameters from the constructor.
54 const AudioParameters params_;
56 // Device unique ID of the input device.
57 const std::string input_device_id_;
59 // Audio manager that created us. Used to report that we've closed.
60 AudioManagerBase* manager_;
62 // PulseAudio API structs.
63 pa_context* pa_context_;
64 pa_threaded_mainloop* pa_mainloop_;
65 pa_stream* input_stream_;
66 pa_stream* output_stream_;
68 // Float representation of volume from 0.0 to 1.0.
69 float volume_;
71 // Callback to audio data source. Must only be modified while holding a lock
72 // on |pa_mainloop_| via pa_threaded_mainloop_lock().
73 AudioSourceCallback* source_callback_;
75 scoped_ptr<AudioBus> input_bus_;
76 scoped_ptr<AudioBus> output_bus_;
78 // Used for input to output buffering.
79 scoped_ptr<media::SeekableBuffer> fifo_;
81 // Temporary storage for recorded data. It gets a packet of data from
82 // |fifo_| and deliver the data to OnMoreIOData() callback.
83 scoped_ptr<uint8[]> input_data_buffer_;
85 DISALLOW_COPY_AND_ASSIGN(PulseAudioUnifiedStream);
88 } // namespace media
90 #endif // MEDIA_AUDIO_PULSE_PULSE_UNIFIED_H_