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

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

Issue 9691001: Audio software mixer. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 8 years, 8 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/audio_output_dispatcher_impl.cc ('k') | media/audio/audio_output_mixer.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 // AudioOutputMixer is a class that implements browser-side audio mixer.
6 // AudioOutputMixer implements both AudioOutputDispatcher and
7 // AudioSourceCallback interfaces.
8
9 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_MIXER_H_
10 #define MEDIA_AUDIO_AUDIO_OUTPUT_MIXER_H_
11
12 #include <map>
13
14 #include "base/basictypes.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/weak_ptr.h"
18 #include "base/synchronization/lock.h"
19 #include "base/timer.h"
20 #include "media/audio/audio_io.h"
21 #include "media/audio/audio_manager.h"
22 #include "media/audio/audio_output_dispatcher.h"
23 #include "media/audio/audio_parameters.h"
24
25 namespace media {
26
27 class MEDIA_EXPORT AudioOutputMixer
28 : public AudioOutputDispatcher,
29 public AudioOutputStream::AudioSourceCallback {
30 public:
31 AudioOutputMixer(AudioManager* audio_manager,
32 const AudioParameters& params,
33 const base::TimeDelta& close_delay);
34
35 // AudioOutputDispatcher interface.
36 virtual bool OpenStream() OVERRIDE;
37 virtual bool StartStream(AudioOutputStream::AudioSourceCallback* callback,
38 AudioOutputProxy* stream_proxy) OVERRIDE;
39 virtual void StopStream(AudioOutputProxy* stream_proxy) OVERRIDE;
40 virtual void StreamVolumeSet(AudioOutputProxy* stream_proxy,
41 double volume) OVERRIDE;
42 virtual void CloseStream(AudioOutputProxy* stream_proxy) OVERRIDE;
43 virtual void Shutdown() OVERRIDE;
44
45 // AudioSourceCallback interface.
46 virtual uint32 OnMoreData(AudioOutputStream* stream,
47 uint8* dest,
48 uint32 max_size,
49 AudioBuffersState buffers_state) OVERRIDE;
50 virtual void OnError(AudioOutputStream* stream, int code) OVERRIDE;
51 virtual void WaitTillDataReady() OVERRIDE;
52
53 private:
54 friend class base::RefCountedThreadSafe<AudioOutputMixer>;
55 virtual ~AudioOutputMixer();
56
57 // Called by |close_timer_|. Closes physical stream.
58 void ClosePhysicalStream();
59
60 // The |lock_| must be acquired whenever we modify |proxies_| in the audio
61 // manager thread or accessing it in the hardware audio thread. Read in the
62 // audio manager thread is safe.
63 base::Lock lock_;
64
65 // List of audio output proxies currently being played.
66 // For every proxy we store aux structure containing data necessary for
67 // mixing.
68 struct ProxyData {
69 AudioOutputStream::AudioSourceCallback* audio_source_callback;
70 double volume;
71 int pending_bytes;
72 };
73 typedef std::map<AudioOutputProxy*, ProxyData> ProxyMap;
74 ProxyMap proxies_;
75
76 // Physical stream for this mixer.
77 scoped_ptr<AudioOutputStream> physical_stream_;
78
79 // Temporary buffer used when mixing. Allocated in the constructor
80 // to avoid constant allocation/deallocation in the callback.
81 scoped_array<uint8> mixer_data_;
82
83 // Used to post delayed tasks to ourselves that we cancel inside Shutdown().
84 base::WeakPtrFactory<AudioOutputMixer> weak_this_;
85 base::DelayTimer<AudioOutputMixer> close_timer_;
86
87 DISALLOW_COPY_AND_ASSIGN(AudioOutputMixer);
88 };
89
90 } // namespace media
91
92 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_MIXER_H_
OLDNEW
« no previous file with comments | « media/audio/audio_output_dispatcher_impl.cc ('k') | media/audio/audio_output_mixer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698