Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / media / audio / audio_output_dispatcher.h
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 // AudioOutputDispatcher is a single-threaded base class that dispatches
6 // creation and deletion of audio output streams. AudioOutputProxy objects use
7 // this class to allocate and recycle actual audio output streams. When playback
8 // is started, the proxy calls StartStream() to get an output stream that it
9 // uses to play audio. When playback is stopped, the proxy returns the stream
10 // back to the dispatcher by calling StopStream().
11 //
12 // AudioManagerBase creates one specialization of AudioOutputDispatcher on the
13 // audio thread for each possible set of audio parameters. I.e streams with
14 // different parameters are managed independently.  The AudioOutputDispatcher
15 // instance is then deleted on the audio thread when the AudioManager shuts
16 // down.
17
18 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_
19 #define MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_
20
21 #if defined(OS_TIZEN)
22 #include <string>
23 #endif
24
25 #include "base/basictypes.h"
26 #include "base/memory/ref_counted.h"
27 #include "media/audio/audio_io.h"
28 #include "media/audio/audio_manager.h"
29 #include "media/audio/audio_parameters.h"
30
31 namespace base {
32 class SingleThreadTaskRunner;
33 }
34
35 namespace media {
36
37 class AudioOutputProxy;
38
39 class MEDIA_EXPORT AudioOutputDispatcher
40     : public base::RefCountedThreadSafe<AudioOutputDispatcher> {
41  public:
42   AudioOutputDispatcher(AudioManager* audio_manager,
43                         const AudioParameters& params,
44                         const std::string& device_id);
45
46   // Called by AudioOutputProxy to open the stream.
47   // Returns false, if it fails to open it.
48   virtual bool OpenStream() = 0;
49
50   // Called by AudioOutputProxy when the stream is started.
51   // Uses |callback| to get source data and report errors, if any.
52   // Does *not* take ownership of this callback.
53   // Returns true if started successfully, false otherwise.
54   virtual bool StartStream(AudioOutputStream::AudioSourceCallback* callback,
55                            AudioOutputProxy* stream_proxy) = 0;
56
57   // Called by AudioOutputProxy when the stream is stopped.
58   // Ownership of the |stream_proxy| is passed to the dispatcher.
59   virtual void StopStream(AudioOutputProxy* stream_proxy) = 0;
60
61   // Called by AudioOutputProxy when the volume is set.
62   virtual void StreamVolumeSet(AudioOutputProxy* stream_proxy,
63                                double volume) = 0;
64
65   // Called by AudioOutputProxy when the stream is closed.
66   virtual void CloseStream(AudioOutputProxy* stream_proxy) = 0;
67
68   // Called on the audio thread when the AudioManager is shutting down.
69   virtual void Shutdown() = 0;
70
71   const std::string& device_id() const { return device_id_; }
72
73 #if defined(OS_TIZEN)
74   virtual void SetMediaStreamProperties(const std::string& app_id,
75                                         const std::string& app_class);
76 #endif
77
78  protected:
79   friend class base::RefCountedThreadSafe<AudioOutputDispatcher>;
80   virtual ~AudioOutputDispatcher();
81
82   // A no-reference-held pointer (we don't want circular references) back to the
83   // AudioManager that owns this object.
84   AudioManager* audio_manager_;
85   const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
86   const AudioParameters params_;
87   std::string device_id_;
88
89 #if defined(OS_TIZEN)
90   std::string app_id_;
91   std::string app_class_;
92 #endif
93
94  private:
95   DISALLOW_COPY_AND_ASSIGN(AudioOutputDispatcher);
96 };
97
98 }  // namespace media
99
100 #endif  // MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_