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

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

Issue 10832285: Switch OnMoreData() to use AudioBus. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Comments. Created 8 years, 3 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
« no previous file with comments | « media/audio/mac/audio_output_mac_unittest.cc ('k') | media/audio/pulse/pulse_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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // Creates an audio output stream based on the PulseAudio asynchronous API. 5 // Creates an audio output stream based on the PulseAudio asynchronous API.
6 // 6 //
7 // If the stream is successfully opened, Close() must be called before the 7 // If the stream is successfully opened, Close() must be called before the
8 // stream is deleted as Close() is responsible for ensuring resource cleanup 8 // stream is deleted as Close() is responsible for ensuring resource cleanup
9 // occurs. 9 // occurs.
10 // 10 //
(...skipping 10 matching lines...) Expand all
21 21
22 #include <pulse/pulseaudio.h> 22 #include <pulse/pulseaudio.h>
23 23
24 #include "base/memory/scoped_ptr.h" 24 #include "base/memory/scoped_ptr.h"
25 #include "base/memory/weak_ptr.h" 25 #include "base/memory/weak_ptr.h"
26 #include "media/audio/audio_io.h" 26 #include "media/audio/audio_io.h"
27 #include "media/base/channel_layout.h" 27 #include "media/base/channel_layout.h"
28 28
29 namespace media { 29 namespace media {
30 30
31 class SeekableBuffer;
32
33 #if defined(OS_LINUX) 31 #if defined(OS_LINUX)
34 class AudioManagerLinux; 32 class AudioManagerLinux;
35 typedef AudioManagerLinux AudioManagerPulse; 33 typedef AudioManagerLinux AudioManagerPulse;
36 #elif defined(OS_OPENBSD) 34 #elif defined(OS_OPENBSD)
37 class AudioManagerOpenBSD; 35 class AudioManagerOpenBSD;
38 typedef AudioManagerOpenBSD AudioManagerPulse; 36 typedef AudioManagerOpenBSD AudioManagerPulse;
39 #else 37 #else
40 #error Unsupported platform 38 #error Unsupported platform
41 #endif 39 #endif
42 40
43 class AudioParameters; 41 class AudioParameters;
42 class SeekableBuffer;
44 43
45 class PulseAudioOutputStream : public AudioOutputStream { 44 class PulseAudioOutputStream : public AudioOutputStream {
46 public: 45 public:
47 PulseAudioOutputStream(const AudioParameters& params, 46 PulseAudioOutputStream(const AudioParameters& params,
48 AudioManagerPulse* manager); 47 AudioManagerPulse* manager);
49 48
50 virtual ~PulseAudioOutputStream(); 49 virtual ~PulseAudioOutputStream();
51 50
52 // Implementation of AudioOutputStream. 51 // Implementation of AudioOutputStream.
53 virtual bool Open(); 52 virtual bool Open() OVERRIDE;
54 virtual void Close(); 53 virtual void Close() OVERRIDE;
55 virtual void Start(AudioSourceCallback* callback); 54 virtual void Start(AudioSourceCallback* callback) OVERRIDE;
56 virtual void Stop(); 55 virtual void Stop() OVERRIDE;
57 virtual void SetVolume(double volume); 56 virtual void SetVolume(double volume) OVERRIDE;
58 virtual void GetVolume(double* volume); 57 virtual void GetVolume(double* volume) OVERRIDE;
59 58
60 private: 59 private:
61 // PulseAudio Callbacks. 60 // PulseAudio Callbacks.
62 static void ContextStateCallback(pa_context* context, void* state_addr); 61 static void ContextStateCallback(pa_context* context, void* state_addr);
63 static void WriteRequestCallback(pa_stream* playback_handle, size_t length, 62 static void WriteRequestCallback(pa_stream* playback_handle, size_t length,
64 void* stream_addr); 63 void* stream_addr);
65 64
66 // Iterate the PulseAudio mainloop to get write requests. 65 // Iterate the PulseAudio mainloop to get write requests.
67 void WaitForWriteRequest(); 66 void WaitForWriteRequest();
68 67
69 // Get another packet from the data source and write it to the client buffer. 68 // Get another packet from the data source and write it to the client buffer.
70 bool BufferPacketFromSource(); 69 bool BufferPacketFromSource();
71 70
72 // Fulfill a write request from the write request callback. If the write 71 // Fulfill a write request from the write request callback. If the write
73 // can't be finished a first, post a new attempt to the message loop. 72 // can't be finished a first, post a new attempt to the message loop.
74 void FulfillWriteRequest(size_t requested_bytes); 73 void FulfillWriteRequest(size_t requested_bytes);
75 74
76 // Write data from the client buffer to the PulseAudio stream. 75 // Write data from the client buffer to the PulseAudio stream.
77 void WriteToStream(size_t bytes_to_write, size_t* bytes_written); 76 void WriteToStream(size_t bytes_to_write, size_t* bytes_written);
78 77
79 // API for Proxying calls to the AudioSourceCallback provided during Start(). 78 // API for Proxying calls to the AudioSourceCallback provided during Start().
80 uint32 RunDataCallback(uint8* dest, uint32 max_size, 79 int RunDataCallback(AudioBus* audio_bus, AudioBuffersState buffers_state);
81 AudioBuffersState buffers_state);
82 80
83 // Close() helper function to free internal structs. 81 // Close() helper function to free internal structs.
84 void Reset(); 82 void Reset();
85 83
86 // Configuration constants from the constructor. Referencable by all threads 84 // Configuration constants from the constructor. Referencable by all threads
87 // since they are constants. 85 // since they are constants.
88 const ChannelLayout channel_layout_; 86 const ChannelLayout channel_layout_;
89 const uint32 channel_count_; 87 const uint32 channel_count_;
90 const pa_sample_format_t sample_format_; 88 const pa_sample_format_t sample_format_;
91 const uint32 sample_rate_; 89 const uint32 sample_rate_;
(...skipping 28 matching lines...) Expand all
120 // set of pa_mainloop iterations. 118 // set of pa_mainloop iterations.
121 bool write_callback_handled_; 119 bool write_callback_handled_;
122 120
123 // Allows us to run tasks on the PulseAudioOutputStream instance which are 121 // Allows us to run tasks on the PulseAudioOutputStream instance which are
124 // bound by its lifetime. 122 // bound by its lifetime.
125 base::WeakPtrFactory<PulseAudioOutputStream> weak_factory_; 123 base::WeakPtrFactory<PulseAudioOutputStream> weak_factory_;
126 124
127 // Callback to audio data source. 125 // Callback to audio data source.
128 AudioSourceCallback* source_callback_; 126 AudioSourceCallback* source_callback_;
129 127
128 // Container for retrieving data from AudioSourceCallback::OnMoreData().
129 scoped_ptr<AudioBus> audio_bus_;
130
130 DISALLOW_COPY_AND_ASSIGN(PulseAudioOutputStream); 131 DISALLOW_COPY_AND_ASSIGN(PulseAudioOutputStream);
131 }; 132 };
132 133
133 } // namespace media 134 } // namespace media
134 135
135 #endif // MEDIA_AUDIO_PULSE_PULSE_OUTPUT_H_ 136 #endif // MEDIA_AUDIO_PULSE_PULSE_OUTPUT_H_
OLDNEW
« no previous file with comments | « media/audio/mac/audio_output_mac_unittest.cc ('k') | media/audio/pulse/pulse_output.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698