Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_AUDIO_TRACK_HOST_H_ | |
| 6 #define CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_AUDIO_TRACK_HOST_H_ | |
| 7 | |
| 8 #include <deque> | |
| 9 | |
| 10 #include "base/compiler_specific.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/memory/weak_ptr.h" | |
| 13 #include "base/synchronization/lock.h" | |
| 14 #include "base/threading/thread_checker.h" | |
| 15 #include "content/public/renderer/media_stream_audio_sink.h" | |
| 16 #include "content/renderer/pepper/pepper_media_stream_track_host_base.h" | |
| 17 #include "media/audio/audio_parameters.h" | |
| 18 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | |
| 19 | |
| 20 namespace base { | |
| 21 class MessageLoopProxy; | |
| 22 } // namespace base | |
| 23 | |
| 24 namespace content { | |
| 25 | |
| 26 class PepperMediaStreamAudioTrackHost : public PepperMediaStreamTrackHostBase { | |
| 27 public: | |
| 28 PepperMediaStreamAudioTrackHost(RendererPpapiHost* host, | |
| 29 PP_Instance instance, | |
| 30 PP_Resource resource, | |
| 31 const blink::WebMediaStreamTrack& track); | |
| 32 | |
| 33 private: | |
| 34 // A helper class for receiving audio samples in the audio thread. | |
| 35 class AudioSink : public MediaStreamAudioSink, | |
| 36 public base::SupportsWeakPtr<AudioSink> { | |
| 37 public: | |
| 38 // This class is created and destroyed on the plugin main thread. | |
| 39 explicit AudioSink(PepperMediaStreamAudioTrackHost* host); | |
| 40 virtual ~AudioSink(); | |
| 41 | |
| 42 // Enqueue a free frame index into |frames_| which will be used for | |
|
yzshen1
2014/02/03 18:14:36
Enqueue*s*
Peng
2014/02/03 19:21:08
Done.
| |
| 43 // sending audio samples to plugin. | |
| 44 void EnqueueFrame(int32_t index); | |
| 45 | |
| 46 private: | |
| 47 void InitFramesOnMainThread(int32_t number_of_frames, int32_t frame_size); | |
| 48 | |
| 49 // MediaStreamAudioSink overrides: | |
| 50 // These two functions should be called on the audio thread. | |
| 51 virtual void OnData(const int16* audio_data, | |
| 52 int sample_rate, | |
| 53 int number_of_channels, | |
| 54 int number_of_frames) OVERRIDE; | |
| 55 virtual void OnSetFormat(const media::AudioParameters& params) OVERRIDE; | |
| 56 | |
| 57 // Unowned host which is available during the AudioSink's lifespan. | |
| 58 PepperMediaStreamAudioTrackHost* host_; | |
|
yzshen1
2014/02/03 18:14:36
This should only be accessed from the main thread,
Peng
2014/02/03 19:21:08
Except for reading frame_buffer(), to get frame_si
yzshen1
2014/02/04 18:26:13
Please explicitly talk about it here and at the de
Peng
2014/02/04 19:57:31
Done.
| |
| 59 | |
| 60 // Timestamp of the next received audio frame. | |
| 61 // Access only on the audio thread. | |
| 62 base::TimeDelta timestamp_; | |
| 63 | |
| 64 // Duration of one audio frame. | |
| 65 // Access only on the audio thread. | |
| 66 base::TimeDelta frame_duration_; | |
| 67 | |
| 68 // Access only on the audio thread. | |
| 69 media::AudioParameters audio_params_; | |
| 70 | |
| 71 // The size of a frame in bytes. | |
| 72 // Access only on the audio thread. | |
| 73 uint32_t frame_data_size_; | |
| 74 | |
| 75 // A lock to protect the index queue |frames_|. | |
| 76 base::Lock lock_; | |
| 77 | |
| 78 // A queue for free frame indices. | |
| 79 std::deque<int32_t> frames_; | |
| 80 | |
| 81 scoped_refptr<base::MessageLoopProxy> main_message_loop_proxy_; | |
| 82 | |
| 83 base::ThreadChecker capture_thread_checker_; | |
|
yzshen1
2014/02/03 18:14:36
Is capture_thread == audio thread mentioned above?
Peng
2014/02/03 19:21:08
Done.
| |
| 84 | |
| 85 DISALLOW_COPY_AND_ASSIGN(AudioSink); | |
| 86 }; | |
| 87 | |
| 88 virtual ~PepperMediaStreamAudioTrackHost(); | |
| 89 | |
| 90 // PepperMediaStreamTrackHostBase overrides: | |
| 91 virtual void OnClose() OVERRIDE; | |
| 92 | |
| 93 // MediaStreamFrameBuffer::Delegate overrides: | |
| 94 virtual void OnNewFrameEnqueued() OVERRIDE; | |
| 95 | |
| 96 // ResourceHost overrides: | |
| 97 virtual void DidConnectPendingHostToResource() OVERRIDE; | |
| 98 | |
| 99 blink::WebMediaStreamTrack track_; | |
| 100 | |
| 101 // True if |audio_sink_| has been added to |blink::WebMediaStreamTrack| | |
| 102 // as a sink. | |
| 103 bool connected_; | |
| 104 | |
| 105 AudioSink audio_sink_; | |
| 106 | |
| 107 DISALLOW_COPY_AND_ASSIGN(PepperMediaStreamAudioTrackHost); | |
| 108 }; | |
| 109 | |
| 110 } // namespace content | |
| 111 | |
| 112 #endif // CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_AUDIO_TRACK_HOST_H_ | |
| OLD | NEW |