Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
|
no longer working on chromium
2014/02/03 09:50:44
nit, %s/Copyright (c) 2014/Copyright 2014/g
Peng
2014/02/03 14:38:54
Done.
| |
| 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 void EnqueueFrame(int32_t index); | |
|
no longer working on chromium
2014/02/03 09:50:44
please add comment to explain how this method is u
Peng
2014/02/03 14:38:54
Done.
| |
| 43 | |
| 44 private: | |
| 45 void InitFramesOnMainThread(int32_t number_of_frames, int32_t frame_size); | |
| 46 | |
| 47 // MediaStreamAudioSink overrides: | |
| 48 // These two functions should be called on the audio thread. | |
| 49 virtual void OnData(const int16* audio_data, | |
| 50 int sample_rate, | |
| 51 int number_of_channels, | |
| 52 int number_of_frames) OVERRIDE; | |
| 53 virtual void OnSetFormat(const media::AudioParameters& params) OVERRIDE; | |
| 54 | |
| 55 // Unowned host which is available during the AudioSink's lifespan. | |
| 56 PepperMediaStreamAudioTrackHost* host_; | |
| 57 | |
| 58 // Timestamp of the next received audio frame. | |
| 59 // Access only on the audio thread. | |
| 60 base::TimeDelta timestamp_; | |
| 61 | |
| 62 // Duration of one audio frame. | |
| 63 // Access only on the audio thread. | |
| 64 base::TimeDelta frame_duration_; | |
| 65 | |
| 66 // Access only on the audio thread. | |
| 67 media::AudioParameters audio_params_; | |
| 68 | |
| 69 // The size of a frame in bytes. | |
| 70 // Access only on the audio thread. | |
| 71 uint32_t frame_data_size_; | |
| 72 | |
| 73 // A lock to protect the index queue |frames_|. | |
| 74 base::Lock lock_; | |
| 75 | |
| 76 // A queue for free frame indices. | |
| 77 std::deque<int32_t> frames_; | |
| 78 | |
| 79 scoped_refptr<base::MessageLoopProxy> main_message_loop_proxy_; | |
| 80 | |
| 81 base::ThreadChecker capture_thread_checker_; | |
| 82 | |
| 83 DISALLOW_COPY_AND_ASSIGN(AudioSink); | |
| 84 }; | |
| 85 | |
| 86 virtual ~PepperMediaStreamAudioTrackHost(); | |
| 87 | |
| 88 // PepperMediaStreamTrackHostBase overrides: | |
| 89 virtual void OnClose() OVERRIDE; | |
| 90 | |
| 91 // MediaStreamFrameBuffer::Delegate overrides: | |
| 92 virtual void OnNewFrameEnqueued() OVERRIDE; | |
| 93 | |
| 94 // ResourceHost overrides: | |
| 95 virtual void DidConnectPendingHostToResource() OVERRIDE; | |
| 96 | |
| 97 blink::WebMediaStreamTrack track_; | |
| 98 | |
| 99 // True if |audio_sink_| has been added to |blink::WebMediaStreamTrack| | |
| 100 // as a sink. | |
| 101 bool connected_; | |
| 102 | |
| 103 AudioSink audio_sink_; | |
| 104 | |
| 105 DISALLOW_COPY_AND_ASSIGN(PepperMediaStreamAudioTrackHost); | |
| 106 }; | |
| 107 | |
| 108 } // namespace content | |
| 109 | |
| 110 #endif // CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_AUDIO_TRACK_HOST_H_ | |
| OLD | NEW |