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

Side by Side Diff: media/audio/simple_sources.h

Issue 7601002: Revert r95841 due to failing media_unittests on linux_shared bot. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 4 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/linux/audio_manager_linux.h ('k') | media/base/async_filter_factory_base.h » ('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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #ifndef MEDIA_AUDIO_SIMPLE_SOURCES_H_ 5 #ifndef MEDIA_AUDIO_SIMPLE_SOURCES_H_
6 #define MEDIA_AUDIO_SIMPLE_SOURCES_H_ 6 #define MEDIA_AUDIO_SIMPLE_SOURCES_H_
7 7
8 #include <list> 8 #include <list>
9 9
10 #include "media/audio/audio_io.h" 10 #include "media/audio/audio_io.h"
11 #include "media/base/seekable_buffer.h" 11 #include "media/base/seekable_buffer.h"
12 12
13 // An audio source that produces a pure sinusoidal tone. 13 // An audio source that produces a pure sinusoidal tone.
14 class MEDIA_EXPORT SineWaveAudioSource 14 class SineWaveAudioSource : public AudioOutputStream::AudioSourceCallback {
15 : public AudioOutputStream::AudioSourceCallback {
16 public: 15 public:
17 enum Format { 16 enum Format {
18 FORMAT_8BIT_LINEAR_PCM, 17 FORMAT_8BIT_LINEAR_PCM,
19 FORMAT_16BIT_LINEAR_PCM, 18 FORMAT_16BIT_LINEAR_PCM,
20 }; 19 };
21 // |channels| is the number of audio channels, |freq| is the frequency in 20 // |channels| is the number of audio channels, |freq| is the frequency in
22 // hertz and it has to be less than half of the sampling frequency 21 // hertz and it has to be less than half of the sampling frequency
23 // |sample_freq| or else you will get aliasing. 22 // |sample_freq| or else you will get aliasing.
24 SineWaveAudioSource(Format format, int channels, 23 SineWaveAudioSource(Format format, int channels,
25 double freq, double sample_freq); 24 double freq, double sample_freq);
26 virtual ~SineWaveAudioSource() {} 25 virtual ~SineWaveAudioSource() {}
27 26
28 // Implementation of AudioSourceCallback. 27 // Implementation of AudioSourceCallback.
29 virtual uint32 OnMoreData( 28 virtual uint32 OnMoreData(
30 AudioOutputStream* stream, uint8* dest, uint32 max_size, 29 AudioOutputStream* stream, uint8* dest, uint32 max_size,
31 AudioBuffersState audio_buffers); 30 AudioBuffersState audio_buffers);
32 virtual void OnError(AudioOutputStream* stream, int code); 31 virtual void OnError(AudioOutputStream* stream, int code);
33 32
34 protected: 33 protected:
35 Format format_; 34 Format format_;
36 int channels_; 35 int channels_;
37 double freq_; 36 double freq_;
38 double sample_freq_; 37 double sample_freq_;
39 }; 38 };
40 39
41 // Defines an interface for pushing audio output. In contrast, the interfaces 40 // Defines an interface for pushing audio output. In contrast, the interfaces
42 // defined by AudioSourceCallback are pull model only. 41 // defined by AudioSourceCallback are pull model only.
43 class MEDIA_EXPORT PushAudioOutput { 42 class PushAudioOutput {
44 public: 43 public:
45 virtual ~PushAudioOutput() {} 44 virtual ~PushAudioOutput() {}
46 45
47 // Write audio data to the audio device. It will be played eventually. 46 // Write audio data to the audio device. It will be played eventually.
48 // Returns false on failure. 47 // Returns false on failure.
49 virtual bool Write(const void* data, uint32 len) = 0; 48 virtual bool Write(const void* data, uint32 len) = 0;
50 49
51 // Returns the number of bytes that have been buffered but not yet given 50 // Returns the number of bytes that have been buffered but not yet given
52 // to the audio device. 51 // to the audio device.
53 virtual uint32 UnProcessedBytes() = 0; 52 virtual uint32 UnProcessedBytes() = 0;
54 }; 53 };
55 54
56 // A fairly basic class to connect a push model provider PushAudioOutput to 55 // A fairly basic class to connect a push model provider PushAudioOutput to
57 // a pull model provider AudioSourceCallback. Fundamentally it manages a series 56 // a pull model provider AudioSourceCallback. Fundamentally it manages a series
58 // of audio buffers and is unaware of the actual audio format. 57 // of audio buffers and is unaware of the actual audio format.
59 // Note that the PushSource is not thread safe and user need to provide locking. 58 // Note that the PushSource is not thread safe and user need to provide locking.
60 class MEDIA_EXPORT PushSource 59 class PushSource
61 : public AudioOutputStream::AudioSourceCallback, 60 : public AudioOutputStream::AudioSourceCallback,
62 public PushAudioOutput { 61 public PushAudioOutput {
63 public: 62 public:
64 PushSource(); 63 PushSource();
65 virtual ~PushSource(); 64 virtual ~PushSource();
66 65
67 // Write one buffer. 66 // Write one buffer.
68 virtual bool Write(const void* data, uint32 len); 67 virtual bool Write(const void* data, uint32 len);
69 68
70 // Return the total number of bytes not given to the audio device yet. 69 // Return the total number of bytes not given to the audio device yet.
71 virtual uint32 UnProcessedBytes(); 70 virtual uint32 UnProcessedBytes();
72 71
73 // Implementation of AudioSourceCallback. 72 // Implementation of AudioSourceCallback.
74 virtual uint32 OnMoreData(AudioOutputStream* stream, uint8* dest, 73 virtual uint32 OnMoreData(AudioOutputStream* stream, uint8* dest,
75 uint32 max_size, AudioBuffersState buffers_state); 74 uint32 max_size, AudioBuffersState buffers_state);
76 virtual void OnError(AudioOutputStream* stream, int code); 75 virtual void OnError(AudioOutputStream* stream, int code);
77 76
78 // Discard all buffered data and reset to initial state. 77 // Discard all buffered data and reset to initial state.
79 void ClearAll(); 78 void ClearAll();
80 79
81 private: 80 private:
82 // Free acquired resources. 81 // Free acquired resources.
83 void CleanUp(); 82 void CleanUp();
84 83
85 media::SeekableBuffer buffer_; 84 media::SeekableBuffer buffer_;
86 }; 85 };
87 86
88 #endif // MEDIA_AUDIO_SIMPLE_SOURCES_H_ 87 #endif // MEDIA_AUDIO_SIMPLE_SOURCES_H_
OLDNEW
« no previous file with comments | « media/audio/linux/audio_manager_linux.h ('k') | media/base/async_filter_factory_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698