| OLD | NEW | 
|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 // | 4 // | 
| 5 // Creates a unified stream based on the cras (ChromeOS audio server) interface. | 5 // Creates a unified stream based on the cras (ChromeOS audio server) interface. | 
| 6 // | 6 // | 
| 7 // CrasUnifiedStream object is *not* thread-safe and should only be used | 7 // CrasUnifiedStream object is *not* thread-safe and should only be used | 
| 8 // from the audio thread. | 8 // from the audio thread. | 
| 9 | 9 | 
| 10 #ifndef MEDIA_AUDIO_LINUX_CRAS_UNIFIED_H_ | 10 #ifndef MEDIA_AUDIO_LINUX_CRAS_UNIFIED_H_ | 
| (...skipping 27 matching lines...) Expand all  Loading... | 
| 38   // Implementation of AudioOutputStream. | 38   // Implementation of AudioOutputStream. | 
| 39   bool Open() override; | 39   bool Open() override; | 
| 40   void Close() override; | 40   void Close() override; | 
| 41   void Start(AudioSourceCallback* callback) override; | 41   void Start(AudioSourceCallback* callback) override; | 
| 42   void Stop() override; | 42   void Stop() override; | 
| 43   void SetVolume(double volume) override; | 43   void SetVolume(double volume) override; | 
| 44   void GetVolume(double* volume) override; | 44   void GetVolume(double* volume) override; | 
| 45 | 45 | 
| 46  private: | 46  private: | 
| 47   // Convert Latency in time to bytes. | 47   // Convert Latency in time to bytes. | 
| 48   uint32 GetBytesLatency(const struct timespec& latency); | 48   uint32_t GetBytesLatency(const struct timespec& latency); | 
| 49 | 49 | 
| 50   // Handles captured audio and fills the ouput with audio to be played. | 50   // Handles captured audio and fills the ouput with audio to be played. | 
| 51   static int UnifiedCallback(cras_client* client, | 51   static int UnifiedCallback(cras_client* client, | 
| 52                              cras_stream_id_t stream_id, | 52                              cras_stream_id_t stream_id, | 
| 53                              uint8* input_samples, | 53                              uint8_t* input_samples, | 
| 54                              uint8* output_samples, | 54                              uint8_t* output_samples, | 
| 55                              unsigned int frames, | 55                              unsigned int frames, | 
| 56                              const timespec* input_ts, | 56                              const timespec* input_ts, | 
| 57                              const timespec* output_ts, | 57                              const timespec* output_ts, | 
| 58                              void* arg); | 58                              void* arg); | 
| 59 | 59 | 
| 60   // Handles notification that there was an error with the playback stream. | 60   // Handles notification that there was an error with the playback stream. | 
| 61   static int StreamError(cras_client* client, | 61   static int StreamError(cras_client* client, | 
| 62                          cras_stream_id_t stream_id, | 62                          cras_stream_id_t stream_id, | 
| 63                          int err, | 63                          int err, | 
| 64                          void* arg); | 64                          void* arg); | 
| 65 | 65 | 
| 66   // Chooses the correct audio callback based on stream direction. | 66   // Chooses the correct audio callback based on stream direction. | 
| 67   uint32 DispatchCallback(size_t frames, | 67   uint32_t DispatchCallback(size_t frames, | 
| 68                           uint8* input_samples, | 68                             uint8_t* input_samples, | 
| 69                           uint8* output_samples, | 69                             uint8_t* output_samples, | 
| 70                           const timespec* input_ts, | 70                             const timespec* input_ts, | 
| 71                           const timespec* output_ts); | 71                             const timespec* output_ts); | 
| 72 | 72 | 
| 73   // Writes audio for a playback stream. | 73   // Writes audio for a playback stream. | 
| 74   uint32 WriteAudio(size_t frames, uint8* buffer, const timespec* sample_ts); | 74   uint32_t WriteAudio(size_t frames, | 
|  | 75                       uint8_t* buffer, | 
|  | 76                       const timespec* sample_ts); | 
| 75 | 77 | 
| 76   // Deals with an error that occured in the stream.  Called from StreamError(). | 78   // Deals with an error that occured in the stream.  Called from StreamError(). | 
| 77   void NotifyStreamError(int err); | 79   void NotifyStreamError(int err); | 
| 78 | 80 | 
| 79   // The client used to communicate with the audio server. | 81   // The client used to communicate with the audio server. | 
| 80   cras_client* client_; | 82   cras_client* client_; | 
| 81 | 83 | 
| 82   // ID of the playing stream. | 84   // ID of the playing stream. | 
| 83   cras_stream_id_t stream_id_; | 85   cras_stream_id_t stream_id_; | 
| 84 | 86 | 
| 85   // PCM parameters for the stream. | 87   // PCM parameters for the stream. | 
| 86   AudioParameters params_; | 88   AudioParameters params_; | 
| 87 | 89 | 
| 88   // Size of frame in bytes. | 90   // Size of frame in bytes. | 
| 89   uint32 bytes_per_frame_; | 91   uint32_t bytes_per_frame_; | 
| 90 | 92 | 
| 91   // True if stream is playing. | 93   // True if stream is playing. | 
| 92   bool is_playing_; | 94   bool is_playing_; | 
| 93 | 95 | 
| 94   // Volume level from 0.0 to 1.0. | 96   // Volume level from 0.0 to 1.0. | 
| 95   float volume_; | 97   float volume_; | 
| 96 | 98 | 
| 97   // Audio manager that created us.  Used to report that we've been closed. | 99   // Audio manager that created us.  Used to report that we've been closed. | 
| 98   AudioManagerCras* manager_; | 100   AudioManagerCras* manager_; | 
| 99 | 101 | 
| 100   // Callback to get audio samples. | 102   // Callback to get audio samples. | 
| 101   AudioSourceCallback* source_callback_; | 103   AudioSourceCallback* source_callback_; | 
| 102 | 104 | 
| 103   // Container for exchanging data with AudioSourceCallback::OnMoreData(). | 105   // Container for exchanging data with AudioSourceCallback::OnMoreData(). | 
| 104   scoped_ptr<AudioBus> output_bus_; | 106   scoped_ptr<AudioBus> output_bus_; | 
| 105 | 107 | 
| 106   // Direciton of the stream. | 108   // Direciton of the stream. | 
| 107   CRAS_STREAM_DIRECTION stream_direction_; | 109   CRAS_STREAM_DIRECTION stream_direction_; | 
| 108 | 110 | 
| 109   DISALLOW_COPY_AND_ASSIGN(CrasUnifiedStream); | 111   DISALLOW_COPY_AND_ASSIGN(CrasUnifiedStream); | 
| 110 }; | 112 }; | 
| 111 | 113 | 
| 112 }  // namespace media | 114 }  // namespace media | 
| 113 | 115 | 
| 114 #endif  // MEDIA_AUDIO_LINUX_CRAS_UNIFIED_H_ | 116 #endif  // MEDIA_AUDIO_LINUX_CRAS_UNIFIED_H_ | 
| OLD | NEW | 
|---|