• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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_LOGGING_H_
6 #define MEDIA_AUDIO_AUDIO_LOGGING_H_
7 
8 #include <string>
9 
10 #include "base/memory/scoped_ptr.h"
11 
12 namespace media {
13 class AudioParameters;
14 
15 // AudioLog logs state information about an active audio component.  Each method
16 // takes a |component_id| along with method specific information.  Its methods
17 // are safe to call from any thread.
18 class AudioLog {
19  public:
~AudioLog()20   virtual ~AudioLog() {}
21 
22   // Called when an audio component is created.  |params| are the parameters of
23   // the created stream.  |device_id| is the id of the audio device opened by
24   // the created stream.
25   virtual void OnCreated(int component_id,
26                          const media::AudioParameters& params,
27                          const std::string& device_id) = 0;
28 
29   // Called when an audio component is started, generally this is synonymous
30   // with "playing."
31   virtual void OnStarted(int component_id) = 0;
32 
33   // Called when an audio component is stopped, generally this is synonymous
34   // with "paused."
35   virtual void OnStopped(int component_id) = 0;
36 
37   // Called when an audio component is closed, generally this is synonymous
38   // with "deleted."
39   virtual void OnClosed(int component_id) = 0;
40 
41   // Called when an audio component encounters an error.
42   virtual void OnError(int component_id) = 0;
43 
44   // Called when an audio component changes volume.  |volume| is the new volume.
45   virtual void OnSetVolume(int component_id, double volume) = 0;
46 };
47 
48 // AudioLogFactory dispenses AudioLog instances to owning classes for tracking
49 // AudioComponent behavior.  All AudioComponents have the concept of an owning
50 // class:
51 //
52 //    - AudioInputRendererHost for AudioInputController
53 //    - AudioRendererHost for AudioOutputController
54 //    - AudioOutputDispatcherImpl for AudioOutputStream
55 //
56 // Each of these owning classes may own multiple instances of each component, as
57 // such each AudioLog supports logging for multiple instances.
58 class AudioLogFactory {
59  public:
60   enum AudioComponent {
61     // Input controllers have a 1:1 mapping with streams, so there's no need to
62     // track both controllers and streams.
63     AUDIO_INPUT_CONTROLLER,
64     // Output controllers may or may not be backed by an active stream, so we
65     // need to track both controllers and streams.
66     AUDIO_OUTPUT_CONTROLLER,
67     AUDIO_OUTPUT_STREAM,
68     AUDIO_COMPONENT_MAX
69   };
70 
71   // Create a new AudioLog object for tracking the behavior for one or more
72   // instances of the given component.  Each instance of an "owning" class must
73   // create its own AudioLog.
74   virtual scoped_ptr<AudioLog> CreateAudioLog(AudioComponent component) = 0;
75 
76  protected:
~AudioLogFactory()77   virtual ~AudioLogFactory() {}
78 };
79 
80 }  // namespace media
81 
82 #endif  // MEDIA_AUDIO_AUDIO_LOGGING_H_
83