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