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

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
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 class MEDIA_EXPORT AudioOutputMixer
26 : public AudioOutputDispatcher,
27 public AudioOutputStream::AudioSourceCallback {
28 public:
29 AudioOutputMixer(AudioManager* audio_manager,
30 const AudioParameters& params,
31 const base::TimeDelta& close_delay);
32
33 // AudioOutputDispatcher interface.
34 virtual bool OpenStream() OVERRIDE;
35 virtual bool StartStream(AudioOutputStream::AudioSourceCallback* callback,
36 AudioOutputProxy* stream_proxy) OVERRIDE;
37 virtual void StopStream(AudioOutputProxy* stream_proxy) OVERRIDE;
38 virtual void StreamVolumeSet(AudioOutputProxy* stream_proxy,
39 double volume) OVERRIDE;
40 virtual void CloseStream(AudioOutputProxy* stream_proxy) OVERRIDE;
41 virtual void Shutdown() OVERRIDE;
42
43 // AudioSourceCallback interface.
44 virtual uint32 OnMoreData(AudioOutputStream* stream,
45 uint8* dest,
46 uint32 max_size,
47 AudioBuffersState buffers_state) OVERRIDE;
48 virtual void OnError(AudioOutputStream* stream, int code) OVERRIDE;
49 virtual void WaitTillDataReady() OVERRIDE;
50
51 private:
52 friend class base::RefCountedThreadSafe<AudioOutputMixer>;
53 virtual ~AudioOutputMixer();
54
55 // Called by |close_timer_|. Closes physical stream.
56 void ClosePhysicalStream();
57
58 // The |lock_| must be acquired whenever we modify |proxies_| in the audio
59 // manager thread or accessing it in the hardware audio thread. Read in the
60 // audio manager thread is safe.
61 base::Lock lock_;
62
63 // List of audio output proxies.
64 // For every proxy we store aux structure containing data necessary for
65 // mixing.
66 struct ProxyData {
67 int pending_bytes;
68 };
69 typedef std::map<AudioOutputProxy*, ProxyData> ProxyMap;
vrk (LEFT CHROMIUM) 2012/04/06 23:37:05 This is closer to what I was thinking, but now tha
enal1 2012/04/16 22:01:35 Done.
70 ProxyMap proxies_;
71
72 // Physical stream for this mixer.
73 scoped_ptr<AudioOutputStream> physical_stream_;
74
75 // Temporary buffer used when mixing. Allocated in the constructor
76 // to avoid constant allocation/deallocation in the callback.
77 scoped_array<uint8> mixer_data_;
78
79 // Used to post delayed tasks to ourselves that we cancel inside Shutdown().
80 base::WeakPtrFactory<AudioOutputMixer> weak_this_;
81 base::DelayTimer<AudioOutputMixer> close_timer_;
82
83 DISALLOW_COPY_AND_ASSIGN(AudioOutputMixer);
84 };
85
86 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_MIXER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698