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 "base/atomicops.h" | |
9 #include "base/compiler_specific.h" | |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/memory/weak_ptr.h" | |
12 #include "content/public/renderer/media_stream_audio_sink.h" | |
13 #include "content/renderer/pepper/pepper_media_stream_track_host_base.h" | |
14 #include "media/audio/audio_parameters.h" | |
15 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | |
16 | |
17 namespace base { | |
18 class MessageLoopProxy; | |
19 } // namespace base | |
20 | |
21 namespace content { | |
22 | |
23 class PepperMediaStreamAudioTrackHost : public PepperMediaStreamTrackHostBase { | |
24 public: | |
25 PepperMediaStreamAudioTrackHost(RendererPpapiHost* host, | |
26 PP_Instance instance, | |
27 PP_Resource resource, | |
28 const blink::WebMediaStreamTrack& track); | |
29 | |
30 private: | |
31 // A helper class for receiving audio samples in the audio thread. | |
32 class AudioSink : public MediaStreamAudioSink, | |
33 public base::SupportsWeakPtr<AudioSink> { | |
34 public: | |
35 // This class is created and destroyed in the plugin main thread. | |
bbudge
2014/01/31 20:29:35
s/in/on
Peng
2014/01/31 21:09:25
Done.
| |
36 explicit AudioSink(PepperMediaStreamAudioTrackHost* host); | |
37 virtual ~AudioSink(); | |
38 | |
39 // Enquque a frame in the main thread. | |
bbudge
2014/01/31 20:29:35
s/Enquque/Enqueue
s/in/on
Peng
2014/01/31 21:09:25
Removed 'in the main thread', because I added a lo
| |
40 void EnqueueFrame(int32_t index); | |
41 | |
42 private: | |
43 void InitFramesOnMainThread(uint32_t number_of_frames, uint32_t frame_size); | |
44 | |
45 // MediaStreamAudioSink overrides: | |
46 // Those functions are called from the audio thread. | |
bbudge
2014/01/31 20:29:35
// These functions should be called on the audio t
Peng
2014/01/31 21:09:25
Done.
| |
47 virtual void OnData(const int16* audio_data, | |
48 int sample_rate, | |
49 int number_of_channels, | |
50 int number_of_frames) OVERRIDE; | |
51 virtual void OnSetFormat(const media::AudioParameters& params) OVERRIDE; | |
52 | |
53 // Unowned host which is available during the AudioSink's lifespan. | |
54 PepperMediaStreamAudioTrackHost* host_; | |
55 | |
56 // Timestamp of the next received audio frame. | |
57 // It is accessed in the audio thread. | |
bbudge
2014/01/31 20:29:35
// Access only on the audio thread.
and below.
Peng
2014/01/31 21:09:25
Done.
| |
58 base::TimeDelta timestamp_; | |
59 | |
60 // Duration of one audio frame. | |
61 // It is accessed in the audio thread. | |
62 base::TimeDelta frame_duration_; | |
63 | |
64 // It is accessed in the audio thread. | |
65 media::AudioParameters audio_params_; | |
66 | |
67 // The size of a frame in bytes. | |
68 // It is accessed in the audio thread. | |
69 uint32_t frame_data_size_; | |
70 | |
71 // Free frames can be used for sending audio samples. | |
72 // Each bit of |frames_| represents a frame index. | |
73 base::subtle::Atomic64 frames_; | |
74 | |
75 scoped_refptr<base::MessageLoopProxy> main_message_loop_proxy_; | |
76 | |
77 DISALLOW_COPY_AND_ASSIGN(AudioSink); | |
78 }; | |
79 | |
80 virtual ~PepperMediaStreamAudioTrackHost(); | |
81 | |
82 // PepperMediaStreamTrackHostBase overrides: | |
83 virtual void OnClose() OVERRIDE; | |
84 | |
85 // MediaStreamFrameBuffer::Delegate overrides: | |
86 virtual void OnNewFrameEnqueued() OVERRIDE; | |
87 | |
88 // ResourceHost overrides: | |
89 virtual void DidConnectPendingHostToResource() OVERRIDE; | |
90 | |
91 blink::WebMediaStreamTrack track_; | |
92 | |
93 // True if it has been added to |blink::WebMediaStreamTrack| as a sink. | |
bbudge
2014/01/31 20:29:35
it is a ambiguous here. Is it the host or the Audi
Peng
2014/01/31 21:09:25
Done.
| |
94 bool connected_; | |
95 | |
96 AudioSink audio_sink_; | |
97 | |
98 DISALLOW_COPY_AND_ASSIGN(PepperMediaStreamAudioTrackHost); | |
99 }; | |
100 | |
101 } // namespace content | |
102 | |
103 #endif // CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_AUDIO_TRACK_HOST_H_ | |
OLD | NEW |