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 <memory>
9 #include <string>
10 
11 
12 namespace media {
13 
14 class AudioParameters;
15 
16 // AudioLog logs state information about an active audio component.
17 class AudioLog {
18  public:
~AudioLog()19   virtual ~AudioLog() {}
20 
21   // Called when an audio component is created.  |params| are the parameters of
22   // the created stream.  |device_id| is the id of the audio device opened by
23   // the created stream.
24   virtual void OnCreated(const media::AudioParameters& params,
25                          const std::string& device_id) = 0;
26 
27   // Called when an audio component is started, generally this is synonymous
28   // with "playing."
29   virtual void OnStarted() = 0;
30 
31   // Called when an audio component is stopped, generally this is synonymous
32   // with "paused."
33   virtual void OnStopped() = 0;
34 
35   // Called when an audio component is closed, generally this is synonymous
36   // with "deleted."
37   virtual void OnClosed() = 0;
38 
39   // Called when an audio component encounters an error.
40   virtual void OnError() = 0;
41 
42   // Called when an audio component changes volume.  |volume| is the new volume.
43   virtual void OnSetVolume(double volume) = 0;
44 
45   // Called with information about audio processing set-up for an audio
46   // component.
47   virtual void OnProcessingStateChanged(const std::string& message) = 0;
48 
49   // Called when an audio component wants to forward a log message.
50   virtual void OnLogMessage(const std::string& message) = 0;
51 };
52 
53 // AudioLogFactory dispenses AudioLog instances for tracking AudioComponent
54 // behavior.
55 class AudioLogFactory {
56  public:
57   enum AudioComponent {
58     // Input controllers have a 1:1 mapping with streams, so there's no need to
59     // track both controllers and streams.
60     AUDIO_INPUT_CONTROLLER,
61     // Output controllers may or may not be backed by an active stream, so we
62     // need to track both controllers and streams.
63     AUDIO_OUTPUT_CONTROLLER,
64     AUDIO_OUTPUT_STREAM,
65     AUDIO_COMPONENT_MAX
66   };
67 
68   // Create a new AudioLog object for tracking the behavior for one instance of
69   // the given component.  Each instance of an "owning" class must create its
70   // own AudioLog.
71   virtual std::unique_ptr<AudioLog> CreateAudioLog(AudioComponent component,
72                                                    int component_id) = 0;
73 
74  protected:
~AudioLogFactory()75   virtual ~AudioLogFactory() {}
76 };
77 
78 }  // namespace media
79 
80 #endif  // MEDIA_AUDIO_AUDIO_LOGGING_H_
81