Chromium Code Reviews| 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 const blink::WebMediaStreamTrack& track); | 31 const blink::WebMediaStreamTrack& track); |
| 32 | 32 |
| 33 private: | 33 private: |
| 34 // A helper class for receiving audio samples in the audio thread. | 34 // A helper class for receiving audio samples in the audio thread. |
| 35 // This class is created and destroyed on the renderer main thread. | 35 // This class is created and destroyed on the renderer main thread. |
| 36 class AudioSink : public MediaStreamAudioSink { | 36 class AudioSink : public MediaStreamAudioSink { |
| 37 public: | 37 public: |
| 38 explicit AudioSink(PepperMediaStreamAudioTrackHost* host); | 38 explicit AudioSink(PepperMediaStreamAudioTrackHost* host); |
| 39 virtual ~AudioSink(); | 39 virtual ~AudioSink(); |
| 40 | 40 |
| 41 // Enqueues a free frame index into |frames_| which will be used for | 41 // Enqueues a free buffer index into |buffers_| which will be used for |
| 42 // sending audio samples to plugin. | 42 // sending audio samples to plugin. |
| 43 // This function is called on the renderer main thread. | 43 // This function is called on the main thread. |
| 44 void EnqueueFrame(int32_t index); | 44 void EnqueueBuffer(int32_t index); |
| 45 | 45 |
| 46 private: | 46 private: |
| 47 void InitFramesOnMainThread(int32_t number_of_frames, int32_t frame_size); | 47 // Init buffers on the main thread. |
|
yzshen1
2014/02/07 20:09:52
Please use "Initializes"
Peng
2014/02/07 20:30:01
Done.
| |
| 48 void SendEnqueueFrameMessageOnMainThread(int32_t index); | 48 void InitBuffersOnMT(int32_t number_of_buffers, |
|
yzshen1
2014/02/07 20:09:52
Please keep 'MainThread' (here and below). :)
Peng
2014/02/07 20:30:01
Done.
| |
| 49 int32_t buffer_size); | |
| 50 | |
| 51 // Send enqueue buffer message on the main thread. | |
| 52 void SendEnqueueBufferMessageOnMT(int32_t index); | |
| 49 | 53 |
| 50 // MediaStreamAudioSink overrides: | 54 // MediaStreamAudioSink overrides: |
| 51 // These two functions should be called on the audio thread. | 55 // These two functions should be called on the audio thread. |
| 52 virtual void OnData(const int16* audio_data, | 56 virtual void OnData(const int16* audio_data, |
| 53 int sample_rate, | 57 int sample_rate, |
| 54 int number_of_channels, | 58 int number_of_channels, |
| 55 int number_of_frames) OVERRIDE; | 59 int number_of_frames) OVERRIDE; |
| 56 virtual void OnSetFormat(const media::AudioParameters& params) OVERRIDE; | 60 virtual void OnSetFormat(const media::AudioParameters& params) OVERRIDE; |
| 57 | 61 |
| 58 // Unowned host which is available during the AudioSink's lifespan. | 62 // Unowned host which is available during the AudioSink's lifespan. |
| 59 // It is mainly used in the main thread. But the audio thread will use | 63 // It is mainly used in the main thread. But the audio thread will use |
| 60 // host_->frame_buffer() to read some buffer properties. It is safe | 64 // host_->buffer_manager() to read some buffer properties. It is safe |
| 61 // because the frame_buffer()'s properties will not be changed after | 65 // because the buffer_manager()'s properties will not be changed after |
| 62 // initialization. | 66 // initialization. |
| 63 PepperMediaStreamAudioTrackHost* host_; | 67 PepperMediaStreamAudioTrackHost* host_; |
| 64 | 68 |
| 65 // Timestamp of the next received audio frame. | 69 // Timestamp of the next received audio buffer. |
| 66 // Access only on the audio thread. | 70 // Access only on the audio thread. |
| 67 base::TimeDelta timestamp_; | 71 base::TimeDelta timestamp_; |
| 68 | 72 |
| 69 // Duration of one audio frame. | 73 // Duration of one audio buffer. |
| 70 // Access only on the audio thread. | 74 // Access only on the audio thread. |
| 71 base::TimeDelta frame_duration_; | 75 base::TimeDelta buffer_duration_; |
| 72 | 76 |
| 73 // The current audio parameters. | 77 // The current audio parameters. |
| 74 // Access only on the audio thread. | 78 // Access only on the audio thread. |
| 75 media::AudioParameters audio_params_; | 79 media::AudioParameters audio_params_; |
| 76 | 80 |
| 77 // The original audio parameters which is set in the first time of | 81 // The original audio parameters which is set in the first time of |
| 78 // OnSetFormat being called. | 82 // OnSetFormat being called. |
| 79 // Access only on the audio thread. | 83 // Access only on the audio thread. |
| 80 media::AudioParameters original_audio_params_; | 84 media::AudioParameters original_audio_params_; |
| 81 | 85 |
| 82 // The size of a frame in bytes. | 86 // The audio data size of one audio buffer in bytes. |
| 83 // Access only on the audio thread. | 87 // Access only on the audio thread. |
| 84 uint32_t frame_data_size_; | 88 uint32_t buffer_data_size_; |
| 85 | 89 |
| 86 // A lock to protect the index queue |frames_|. | 90 // A lock to protect the index queue |buffers_|. |
| 87 base::Lock lock_; | 91 base::Lock lock_; |
| 88 | 92 |
| 89 // A queue for free frame indices. | 93 // A queue for free buffer indices. |
| 90 std::deque<int32_t> frames_; | 94 std::deque<int32_t> buffers_; |
| 91 | 95 |
| 92 scoped_refptr<base::MessageLoopProxy> main_message_loop_proxy_; | 96 scoped_refptr<base::MessageLoopProxy> main_message_loop_proxy_; |
| 93 | 97 |
| 94 base::ThreadChecker audio_thread_checker_; | 98 base::ThreadChecker audio_thread_checker_; |
| 95 | 99 |
| 96 base::WeakPtrFactory<AudioSink> weak_factory_; | 100 base::WeakPtrFactory<AudioSink> weak_factory_; |
| 97 | 101 |
| 98 DISALLOW_COPY_AND_ASSIGN(AudioSink); | 102 DISALLOW_COPY_AND_ASSIGN(AudioSink); |
| 99 }; | 103 }; |
| 100 | 104 |
| 101 virtual ~PepperMediaStreamAudioTrackHost(); | 105 virtual ~PepperMediaStreamAudioTrackHost(); |
| 102 | 106 |
| 103 // PepperMediaStreamTrackHostBase overrides: | 107 // PepperMediaStreamTrackHostBase overrides: |
| 104 virtual void OnClose() OVERRIDE; | 108 virtual void OnClose() OVERRIDE; |
| 105 | 109 |
| 106 // MediaStreamFrameBuffer::Delegate overrides: | 110 // MediaStreamBufferManager::Delegate overrides: |
| 107 virtual void OnNewFrameEnqueued() OVERRIDE; | 111 virtual void OnNewBufferEnqueued() OVERRIDE; |
| 108 | 112 |
| 109 // ResourceHost overrides: | 113 // ResourceHost overrides: |
| 110 virtual void DidConnectPendingHostToResource() OVERRIDE; | 114 virtual void DidConnectPendingHostToResource() OVERRIDE; |
| 111 | 115 |
| 112 blink::WebMediaStreamTrack track_; | 116 blink::WebMediaStreamTrack track_; |
| 113 | 117 |
| 114 // True if |audio_sink_| has been added to |blink::WebMediaStreamTrack| | 118 // True if |audio_sink_| has been added to |blink::WebMediaStreamTrack| |
| 115 // as a sink. | 119 // as a sink. |
| 116 bool connected_; | 120 bool connected_; |
| 117 | 121 |
| 118 AudioSink audio_sink_; | 122 AudioSink audio_sink_; |
| 119 | 123 |
| 120 DISALLOW_COPY_AND_ASSIGN(PepperMediaStreamAudioTrackHost); | 124 DISALLOW_COPY_AND_ASSIGN(PepperMediaStreamAudioTrackHost); |
| 121 }; | 125 }; |
| 122 | 126 |
| 123 } // namespace content | 127 } // namespace content |
| 124 | 128 |
| 125 #endif // CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_AUDIO_TRACK_HOST_H_ | 129 #endif // CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_AUDIO_TRACK_HOST_H_ |
| OLD | NEW |