OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 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 "content/public/renderer/media_stream_audio_sink.h" | |
15 #include "content/renderer/pepper/pepper_media_stream_track_host_base.h" | |
16 #include "media/audio/audio_parameters.h" | |
17 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | |
18 | |
19 namespace base { | |
20 class MessageLoopProxy; | |
21 } // namespace base | |
22 | |
23 namespace content { | |
24 | |
25 class PepperMediaStreamAudioTrackHost : public PepperMediaStreamTrackHostBase { | |
26 public: | |
27 PepperMediaStreamAudioTrackHost(RendererPpapiHost* host, | |
28 PP_Instance instance, | |
29 PP_Resource resource, | |
30 const blink::WebMediaStreamTrack& track); | |
31 | |
32 private: | |
33 // A helper class for receiving audio samples in the audio thread. | |
34 class AudioSink : public MediaStreamAudioSink, | |
35 public base::SupportsWeakPtr<AudioSink> { | |
36 public: | |
37 // This class is created and destroyed on the plugin main thread. | |
38 explicit AudioSink(PepperMediaStreamAudioTrackHost* host); | |
39 virtual ~AudioSink(); | |
40 | |
41 void EnqueueFrame(int32_t index); | |
42 | |
43 private: | |
44 void InitFramesOnMainThread(uint32_t number_of_frames, uint32_t frame_size); | |
45 | |
46 // MediaStreamAudioSink overrides: | |
47 // These two functions should be called on the audio thread. | |
48 virtual void OnData(const int16* audio_data, | |
49 int sample_rate, | |
50 int number_of_channels, | |
51 int number_of_frames) OVERRIDE; | |
52 virtual void OnSetFormat(const media::AudioParameters& params) OVERRIDE; | |
53 | |
54 // Unowned host which is available during the AudioSink's lifespan. | |
55 PepperMediaStreamAudioTrackHost* host_; | |
56 | |
57 // Timestamp of the next received audio frame. | |
58 // Access only on the audio thread. | |
59 base::TimeDelta timestamp_; | |
60 | |
61 // Duration of one audio frame. | |
62 // Access only on the audio thread. | |
63 base::TimeDelta frame_duration_; | |
64 | |
65 // Access only on the audio thread. | |
66 media::AudioParameters audio_params_; | |
67 | |
68 // The size of a frame in bytes. | |
69 // Access only on the audio thread. | |
70 uint32_t frame_data_size_; | |
71 | |
72 // A mutex to portect the index queue |frames_|. | |
bbudge
2014/01/31 22:13:01
s/portect/protect
Can we name this lock_ to be mo
Peng
2014/02/02 02:11:26
Done.
| |
73 base::Lock mutex_; | |
74 | |
75 // A queue for free frame indexes. | |
bbudge
2014/01/31 22:13:01
s/indexes/indices
Peng
2014/02/02 02:11:26
Done.
| |
76 std::deque<int32_t> frames_; | |
77 | |
78 scoped_refptr<base::MessageLoopProxy> main_message_loop_proxy_; | |
79 | |
80 DISALLOW_COPY_AND_ASSIGN(AudioSink); | |
81 }; | |
82 | |
83 virtual ~PepperMediaStreamAudioTrackHost(); | |
84 | |
85 // PepperMediaStreamTrackHostBase overrides: | |
86 virtual void OnClose() OVERRIDE; | |
87 | |
88 // MediaStreamFrameBuffer::Delegate overrides: | |
89 virtual void OnNewFrameEnqueued() OVERRIDE; | |
90 | |
91 // ResourceHost overrides: | |
92 virtual void DidConnectPendingHostToResource() OVERRIDE; | |
93 | |
94 blink::WebMediaStreamTrack track_; | |
95 | |
96 // True if |audio_sink_| has been added to |blink::WebMediaStreamTrack| | |
97 // as a sink. | |
98 bool connected_; | |
99 | |
100 AudioSink audio_sink_; | |
101 | |
102 DISALLOW_COPY_AND_ASSIGN(PepperMediaStreamAudioTrackHost); | |
103 }; | |
104 | |
105 } // namespace content | |
106 | |
107 #endif // CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_AUDIO_TRACK_HOST_H_ | |
OLD | NEW |