| 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 20 matching lines...) Expand all Loading... |
| 31 PP_Instance instance, | 31 PP_Instance instance, |
| 32 PP_Resource resource, | 32 PP_Resource resource, |
| 33 const blink::WebMediaStreamTrack& track); | 33 const blink::WebMediaStreamTrack& track); |
| 34 | 34 |
| 35 private: | 35 private: |
| 36 // A helper class for receiving audio samples in the audio thread. | 36 // A helper class for receiving audio samples in the audio thread. |
| 37 // This class is created and destroyed on the renderer main thread. | 37 // This class is created and destroyed on the renderer main thread. |
| 38 class AudioSink : public MediaStreamAudioSink { | 38 class AudioSink : public MediaStreamAudioSink { |
| 39 public: | 39 public: |
| 40 explicit AudioSink(PepperMediaStreamAudioTrackHost* host); | 40 explicit AudioSink(PepperMediaStreamAudioTrackHost* host); |
| 41 virtual ~AudioSink(); | 41 ~AudioSink() override; |
| 42 | 42 |
| 43 // Enqueues a free buffer index into |buffers_| which will be used for | 43 // Enqueues a free buffer index into |buffers_| which will be used for |
| 44 // sending audio samples to plugin. | 44 // sending audio samples to plugin. |
| 45 // This function is called on the main thread. | 45 // This function is called on the main thread. |
| 46 void EnqueueBuffer(int32_t index); | 46 void EnqueueBuffer(int32_t index); |
| 47 | 47 |
| 48 // This function is called on the main thread. | 48 // This function is called on the main thread. |
| 49 int32_t Configure(int32_t number_of_buffers, int32_t duration, | 49 int32_t Configure(int32_t number_of_buffers, int32_t duration, |
| 50 const ppapi::host::ReplyMessageContext& context); | 50 const ppapi::host::ReplyMessageContext& context); |
| 51 | 51 |
| 52 // Send a reply to the currently pending |Configure()| request. | 52 // Send a reply to the currently pending |Configure()| request. |
| 53 void SendConfigureReply(int32_t result); | 53 void SendConfigureReply(int32_t result); |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 // Initializes buffers on the main thread. | 56 // Initializes buffers on the main thread. |
| 57 void SetFormatOnMainThread(int bytes_per_second, int bytes_per_frame); | 57 void SetFormatOnMainThread(int bytes_per_second, int bytes_per_frame); |
| 58 | 58 |
| 59 void InitBuffers(); | 59 void InitBuffers(); |
| 60 | 60 |
| 61 // Send enqueue buffer message on the main thread. | 61 // Send enqueue buffer message on the main thread. |
| 62 void SendEnqueueBufferMessageOnMainThread(int32_t index, | 62 void SendEnqueueBufferMessageOnMainThread(int32_t index, |
| 63 int32_t buffers_generation); | 63 int32_t buffers_generation); |
| 64 | 64 |
| 65 // MediaStreamAudioSink overrides: | 65 // MediaStreamAudioSink overrides: |
| 66 // These two functions should be called on the audio thread. | 66 // These two functions should be called on the audio thread. |
| 67 virtual void OnData(const int16* audio_data, | 67 void OnData(const int16* audio_data, |
| 68 int sample_rate, | 68 int sample_rate, |
| 69 int number_of_channels, | 69 int number_of_channels, |
| 70 int number_of_frames) override; | 70 int number_of_frames) override; |
| 71 virtual void OnSetFormat(const media::AudioParameters& params) override; | 71 void OnSetFormat(const media::AudioParameters& params) override; |
| 72 | 72 |
| 73 // Unowned host which is available during the AudioSink's lifespan. | 73 // Unowned host which is available during the AudioSink's lifespan. |
| 74 // It is mainly used in the main thread. But the audio thread will use | 74 // It is mainly used in the main thread. But the audio thread will use |
| 75 // host_->buffer_manager() to read some buffer properties. It is safe | 75 // host_->buffer_manager() to read some buffer properties. It is safe |
| 76 // because the buffer_manager()'s properties will not be changed after | 76 // because the buffer_manager()'s properties will not be changed after |
| 77 // initialization. | 77 // initialization. |
| 78 PepperMediaStreamAudioTrackHost* host_; | 78 PepperMediaStreamAudioTrackHost* host_; |
| 79 | 79 |
| 80 // Timestamp of the next received audio buffer. | 80 // Timestamp of the next received audio buffer. |
| 81 // Access only on the audio thread. | 81 // Access only on the audio thread. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 int32_t user_buffer_duration_; | 141 int32_t user_buffer_duration_; |
| 142 | 142 |
| 143 // Pending |Configure()| reply context. | 143 // Pending |Configure()| reply context. |
| 144 ppapi::host::ReplyMessageContext pending_configure_reply_; | 144 ppapi::host::ReplyMessageContext pending_configure_reply_; |
| 145 | 145 |
| 146 base::WeakPtrFactory<AudioSink> weak_factory_; | 146 base::WeakPtrFactory<AudioSink> weak_factory_; |
| 147 | 147 |
| 148 DISALLOW_COPY_AND_ASSIGN(AudioSink); | 148 DISALLOW_COPY_AND_ASSIGN(AudioSink); |
| 149 }; | 149 }; |
| 150 | 150 |
| 151 virtual ~PepperMediaStreamAudioTrackHost(); | 151 ~PepperMediaStreamAudioTrackHost() override; |
| 152 | 152 |
| 153 // ResourceMessageHandler overrides: | 153 // ResourceMessageHandler overrides: |
| 154 virtual int32_t OnResourceMessageReceived( | 154 int32_t OnResourceMessageReceived( |
| 155 const IPC::Message& msg, | 155 const IPC::Message& msg, |
| 156 ppapi::host::HostMessageContext* context) override; | 156 ppapi::host::HostMessageContext* context) override; |
| 157 | 157 |
| 158 // Message handlers: | 158 // Message handlers: |
| 159 int32_t OnHostMsgConfigure( | 159 int32_t OnHostMsgConfigure( |
| 160 ppapi::host::HostMessageContext* context, | 160 ppapi::host::HostMessageContext* context, |
| 161 const ppapi::MediaStreamAudioTrackShared::Attributes& attributes); | 161 const ppapi::MediaStreamAudioTrackShared::Attributes& attributes); |
| 162 | 162 |
| 163 // PepperMediaStreamTrackHostBase overrides: | 163 // PepperMediaStreamTrackHostBase overrides: |
| 164 virtual void OnClose() override; | 164 void OnClose() override; |
| 165 | 165 |
| 166 // MediaStreamBufferManager::Delegate overrides: | 166 // MediaStreamBufferManager::Delegate overrides: |
| 167 virtual void OnNewBufferEnqueued() override; | 167 void OnNewBufferEnqueued() override; |
| 168 | 168 |
| 169 // ResourceHost overrides: | 169 // ResourceHost overrides: |
| 170 virtual void DidConnectPendingHostToResource() override; | 170 void DidConnectPendingHostToResource() override; |
| 171 | 171 |
| 172 blink::WebMediaStreamTrack track_; | 172 blink::WebMediaStreamTrack track_; |
| 173 | 173 |
| 174 // True if |audio_sink_| has been added to |blink::WebMediaStreamTrack| | 174 // True if |audio_sink_| has been added to |blink::WebMediaStreamTrack| |
| 175 // as a sink. | 175 // as a sink. |
| 176 bool connected_; | 176 bool connected_; |
| 177 | 177 |
| 178 AudioSink audio_sink_; | 178 AudioSink audio_sink_; |
| 179 | 179 |
| 180 DISALLOW_COPY_AND_ASSIGN(PepperMediaStreamAudioTrackHost); | 180 DISALLOW_COPY_AND_ASSIGN(PepperMediaStreamAudioTrackHost); |
| 181 }; | 181 }; |
| 182 | 182 |
| 183 } // namespace content | 183 } // namespace content |
| 184 | 184 |
| 185 #endif // CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_AUDIO_TRACK_HOST_H_ | 185 #endif // CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_AUDIO_TRACK_HOST_H_ |
| OLD | NEW |