| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_AUDIO_TRACK_HOST_H_ | 5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_AUDIO_TRACK_HOST_H_ |
| 6 #define CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_AUDIO_TRACK_HOST_H_ | 6 #define CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_AUDIO_TRACK_HOST_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 public: | 38 public: |
| 39 explicit AudioSink(PepperMediaStreamAudioTrackHost* host); | 39 explicit AudioSink(PepperMediaStreamAudioTrackHost* host); |
| 40 virtual ~AudioSink(); | 40 virtual ~AudioSink(); |
| 41 | 41 |
| 42 // Enqueues a free buffer index into |buffers_| which will be used for | 42 // Enqueues a free buffer index into |buffers_| which will be used for |
| 43 // sending audio samples to plugin. | 43 // sending audio samples to plugin. |
| 44 // This function is called on the main thread. | 44 // This function is called on the main thread. |
| 45 void EnqueueBuffer(int32_t index); | 45 void EnqueueBuffer(int32_t index); |
| 46 | 46 |
| 47 // This function is called on the main thread. | 47 // This function is called on the main thread. |
| 48 void Configure(int32_t number_of_buffers); | 48 void Configure(int32_t number_of_buffers, int32_t duration); |
| 49 | 49 |
| 50 private: | 50 private: |
| 51 // Initializes buffers on the main thread. | 51 // Initializes buffers on the main thread. |
| 52 void SetFormatOnMainThread(int bytes_per_second); | 52 void SetFormatOnMainThread(int bytes_per_second, int bytes_per_frame); |
| 53 | 53 |
| 54 void InitBuffers(); | 54 void InitBuffers(); |
| 55 | 55 |
| 56 // Send enqueue buffer message on the main thread. | 56 // Send enqueue buffer message on the main thread. |
| 57 void SendEnqueueBufferMessageOnMainThread(int32_t index); | 57 void SendEnqueueBufferMessageOnMainThread(int32_t index, |
| 58 int32_t buffers_init_count); |
| 58 | 59 |
| 59 // MediaStreamAudioSink overrides: | 60 // MediaStreamAudioSink overrides: |
| 60 // These two functions should be called on the audio thread. | 61 // These two functions should be called on the audio thread. |
| 61 virtual void OnData(const int16* audio_data, | 62 virtual void OnData(const int16* audio_data, |
| 62 int sample_rate, | 63 int sample_rate, |
| 63 int number_of_channels, | 64 int number_of_channels, |
| 64 int number_of_frames) OVERRIDE; | 65 int number_of_frames) OVERRIDE; |
| 65 virtual void OnSetFormat(const media::AudioParameters& params) OVERRIDE; | 66 virtual void OnSetFormat(const media::AudioParameters& params) OVERRIDE; |
| 66 | 67 |
| 67 // Unowned host which is available during the AudioSink's lifespan. | 68 // Unowned host which is available during the AudioSink's lifespan. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 85 | 86 |
| 86 // The original audio parameters which is set in the first time of | 87 // The original audio parameters which is set in the first time of |
| 87 // OnSetFormat being called. | 88 // OnSetFormat being called. |
| 88 // Access only on the audio thread. | 89 // Access only on the audio thread. |
| 89 media::AudioParameters original_audio_params_; | 90 media::AudioParameters original_audio_params_; |
| 90 | 91 |
| 91 // The audio data size of one audio buffer in bytes. | 92 // The audio data size of one audio buffer in bytes. |
| 92 // Access only on the audio thread. | 93 // Access only on the audio thread. |
| 93 uint32_t buffer_data_size_; | 94 uint32_t buffer_data_size_; |
| 94 | 95 |
| 95 // A lock to protect the index queue |buffers_|. | 96 // Index of the currently active buffer. |
| 97 // Access only on the audio thread. |
| 98 int active_buffer_index_; |
| 99 |
| 100 // The count of |InitBuffers()| calls corresponding to the currently active |
| 101 // buffer. Used to make sure the active buffer is still valid. |
| 102 // Access only on the audio thread. |
| 103 int32_t active_init_buffers_count_; |
| 104 |
| 105 // Current offset, in bytes, within the currently active buffer. |
| 106 // Access only on the audio thread. |
| 107 uint32_t active_buffer_offset_; |
| 108 |
| 109 // A lock to protect the index queue |buffers_|, |init_buffers_count_|, |
| 110 // buffers in |host_->buffer_manager()|, and |output_buffer_size_|. |
| 96 base::Lock lock_; | 111 base::Lock lock_; |
| 97 | 112 |
| 98 // A queue for free buffer indices. | 113 // A queue for free buffer indices. |
| 99 std::deque<int32_t> buffers_; | 114 std::deque<int32_t> buffers_; |
| 100 | 115 |
| 116 // Count of |InitBuffers()| calls. |
| 117 int32_t init_buffers_count_; |
| 118 |
| 119 // Intended size of each output buffer. |
| 120 int32_t output_buffer_size_; |
| 121 |
| 101 scoped_refptr<base::MessageLoopProxy> main_message_loop_proxy_; | 122 scoped_refptr<base::MessageLoopProxy> main_message_loop_proxy_; |
| 102 | 123 |
| 103 base::ThreadChecker audio_thread_checker_; | 124 base::ThreadChecker audio_thread_checker_; |
| 104 | 125 |
| 105 base::WeakPtrFactory<AudioSink> weak_factory_; | 126 base::WeakPtrFactory<AudioSink> weak_factory_; |
| 106 | 127 |
| 107 // Number of buffers. | 128 // Number of buffers. |
| 108 int32_t number_of_buffers_; | 129 int32_t number_of_buffers_; |
| 109 | 130 |
| 110 // Number of bytes per second. | 131 // Number of bytes per second. |
| 111 int bytes_per_second_; | 132 int bytes_per_second_; |
| 112 | 133 |
| 134 // Number of bytes per frame = channels * bytes per sample. |
| 135 int bytes_per_frame_; |
| 136 |
| 137 // User-configured buffer duration, in milliseconds. |
| 138 int32_t user_buffer_duration_; |
| 139 |
| 113 DISALLOW_COPY_AND_ASSIGN(AudioSink); | 140 DISALLOW_COPY_AND_ASSIGN(AudioSink); |
| 114 }; | 141 }; |
| 115 | 142 |
| 116 virtual ~PepperMediaStreamAudioTrackHost(); | 143 virtual ~PepperMediaStreamAudioTrackHost(); |
| 117 | 144 |
| 118 // ResourceMessageHandler overrides: | 145 // ResourceMessageHandler overrides: |
| 119 virtual int32_t OnResourceMessageReceived( | 146 virtual int32_t OnResourceMessageReceived( |
| 120 const IPC::Message& msg, | 147 const IPC::Message& msg, |
| 121 ppapi::host::HostMessageContext* context) OVERRIDE; | 148 ppapi::host::HostMessageContext* context) OVERRIDE; |
| 122 | 149 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 141 bool connected_; | 168 bool connected_; |
| 142 | 169 |
| 143 AudioSink audio_sink_; | 170 AudioSink audio_sink_; |
| 144 | 171 |
| 145 DISALLOW_COPY_AND_ASSIGN(PepperMediaStreamAudioTrackHost); | 172 DISALLOW_COPY_AND_ASSIGN(PepperMediaStreamAudioTrackHost); |
| 146 }; | 173 }; |
| 147 | 174 |
| 148 } // namespace content | 175 } // namespace content |
| 149 | 176 |
| 150 #endif // CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_AUDIO_TRACK_HOST_H_ | 177 #endif // CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_AUDIO_TRACK_HOST_H_ |
| OLD | NEW |