audio_logging.h revision f2477e01787aa58f445919b809d89e252beef54f
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 12namespace media { 13class 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. 18class AudioLog { 19 public: 20 virtual ~AudioLog() {} 21 22 // Called when an audio component is created. |params| are the parameters of 23 // the created stream. |input_device_id| and |output_device_id| are the 24 // respective device ids for input and output. Either one or both may be 25 // specified. 26 virtual void OnCreated(int component_id, 27 const media::AudioParameters& params, 28 const std::string& input_device_id, 29 const std::string& output_device_id) = 0; 30 31 // Called when an audio component is started, generally this is synonymous 32 // with "playing." 33 virtual void OnStarted(int component_id) = 0; 34 35 // Called when an audio component is stopped, generally this is synonymous 36 // with "paused." 37 virtual void OnStopped(int component_id) = 0; 38 39 // Called when an audio component is closed, generally this is synonymous 40 // with "deleted." 41 virtual void OnClosed(int component_id) = 0; 42 43 // Called when an audio component encounters an error. 44 virtual void OnError(int component_id) = 0; 45 46 // Called when an audio component changes volume. |volume| is the new volume. 47 virtual void OnSetVolume(int component_id, double volume) = 0; 48}; 49 50// AudioLogFactory dispenses AudioLog instances to owning classes for tracking 51// AudioComponent behavior. All AudioComponents have the concept of an owning 52// class: 53// 54// - AudioInputRendererHost for AudioInputController 55// - AudioRendererHost for AudioOutputController 56// - AudioOutputDispatcherImpl for AudioOutputStream 57// 58// Each of these owning classes may own multiple instances of each component, as 59// such each AudioLog supports logging for multiple instances. 60class AudioLogFactory { 61 public: 62 enum AudioComponent { 63 // Input controllers have a 1:1 mapping with streams, so there's no need to 64 // track both controllers and streams. 65 AUDIO_INPUT_CONTROLLER, 66 // Output controllers may or may not be backed by an active stream, so we 67 // need to track both controllers and streams. 68 AUDIO_OUTPUT_CONTROLLER, 69 AUDIO_OUTPUT_STREAM, 70 AUDIO_COMPONENT_MAX 71 }; 72 73 // Create a new AudioLog object for tracking the behavior for one or more 74 // instances of the given component. Each instance of an "owning" class must 75 // create its own AudioLog. 76 virtual scoped_ptr<AudioLog> CreateAudioLog(AudioComponent component) = 0; 77 78 protected: 79 virtual ~AudioLogFactory() {} 80}; 81 82} // namespace media 83 84#endif // MEDIA_AUDIO_AUDIO_LOGGING_H_ 85