Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / media / audio / audio_output_proxy.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 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_PROXY_H_
6 #define MEDIA_AUDIO_AUDIO_OUTPUT_PROXY_H_
7
8 #if defined(OS_TIZEN)
9 #include <string>
10 #endif
11
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/threading/non_thread_safe.h"
16 #include "media/audio/audio_io.h"
17 #include "media/audio/audio_parameters.h"
18
19 namespace media {
20
21 class AudioOutputDispatcher;
22
23 // AudioOutputProxy is an audio otput stream that uses resources more
24 // efficiently than a regular audio output stream: it opens audio
25 // device only when sound is playing, i.e. between Start() and Stop()
26 // (there is still one physical stream per each audio output proxy in
27 // playing state).
28 //
29 // AudioOutputProxy uses AudioOutputDispatcher to open and close
30 // physical output streams.
31 class MEDIA_EXPORT AudioOutputProxy
32   : public AudioOutputStream,
33     public NON_EXPORTED_BASE(base::NonThreadSafe) {
34  public:
35   // Caller keeps ownership of |dispatcher|.
36   explicit AudioOutputProxy(AudioOutputDispatcher* dispatcher);
37
38   // AudioOutputStream interface.
39   bool Open() override;
40   void Start(AudioSourceCallback* callback) override;
41   void Stop() override;
42   void SetVolume(double volume) override;
43   void GetVolume(double* volume) override;
44   void Close() override;
45
46 #if defined(OS_TIZEN)
47   void SetMediaStreamProperties(const std::string& app_id,
48                                 const std::string& app_class) override;
49 #endif
50
51  private:
52   enum State {
53     kCreated,
54     kOpened,
55     kPlaying,
56     kClosed,
57     kOpenError,
58     kStartError,
59   };
60
61   ~AudioOutputProxy() override;
62
63   scoped_refptr<AudioOutputDispatcher> dispatcher_;
64   State state_;
65
66   // Need to save volume here, so that we can restore it in case the stream
67   // is stopped, and then started again.
68   double volume_;
69
70   DISALLOW_COPY_AND_ASSIGN(AudioOutputProxy);
71 };
72
73 }  // namespace media
74
75 #endif  // MEDIA_AUDIO_AUDIO_OUTPUT_PROXY_H_