Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: content/renderer/pepper/pepper_media_stream_audio_track_host.h

Issue 140783004: [PPAPI] Pepper MediaStream API audio track implementation and example. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build error Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 // This class is created and destroyed on the renderer main thread.
36 class AudioSink : public MediaStreamAudioSink {
37 public:
38 explicit AudioSink(PepperMediaStreamAudioTrackHost* host);
39 virtual ~AudioSink();
40
41 // Enqueues a free frame index into |frames_| which will be used for
42 // sending audio samples to plugin.
43 // This function is called on the renderer main thread.
44 void EnqueueFrame(int32_t index);
45
46 private:
47 void InitFramesOnMainThread(int32_t number_of_frames, int32_t frame_size);
48 void SendEnqueueFrameMessageOnMainThread(int32_t index);
49
50 // MediaStreamAudioSink overrides:
51 // These two functions should be called on the audio thread.
52 virtual void OnData(const int16* audio_data,
53 int sample_rate,
54 int number_of_channels,
55 int number_of_frames) OVERRIDE;
56 virtual void OnSetFormat(const media::AudioParameters& params) OVERRIDE;
57
58 // Unowned host which is available during the AudioSink's lifespan.
59 PepperMediaStreamAudioTrackHost* host_;
60
61 // Timestamp of the next received audio frame.
62 // Access only on the audio thread.
63 base::TimeDelta timestamp_;
64
65 // Duration of one audio frame.
66 // Access only on the audio thread.
67 base::TimeDelta frame_duration_;
68
69 // The current audio parameters.
70 // Access only on the audio thread.
71 media::AudioParameters audio_params_;
72
73 // The original audio parameters which is set in the first time of
74 // OnSetFormat being called.
75 // Access only on the audio thread.
76 media::AudioParameters original_audio_params_;
77
78 // The size of a frame in bytes.
79 // Access only on the audio thread.
80 uint32_t frame_data_size_;
81
82 // A lock to protect the index queue |frames_|.
83 base::Lock lock_;
84
85 // A queue for free frame indices.
86 std::deque<int32_t> frames_;
87
88 scoped_refptr<base::MessageLoopProxy> main_message_loop_proxy_;
89
90 base::WeakPtrFactory<AudioSink> weak_factory_;
yzshen1 2014/02/04 18:26:13 nit: it is better to place |weak_factory_| as the
Peng 2014/02/04 19:57:31 Done.
91
92 base::ThreadChecker audio_thread_checker_;
93
94 DISALLOW_COPY_AND_ASSIGN(AudioSink);
95 };
96
97 virtual ~PepperMediaStreamAudioTrackHost();
98
99 // PepperMediaStreamTrackHostBase overrides:
100 virtual void OnClose() OVERRIDE;
101
102 // MediaStreamFrameBuffer::Delegate overrides:
103 virtual void OnNewFrameEnqueued() OVERRIDE;
104
105 // ResourceHost overrides:
106 virtual void DidConnectPendingHostToResource() OVERRIDE;
107
108 blink::WebMediaStreamTrack track_;
109
110 // True if |audio_sink_| has been added to |blink::WebMediaStreamTrack|
111 // as a sink.
112 bool connected_;
113
114 AudioSink audio_sink_;
115
116 DISALLOW_COPY_AND_ASSIGN(PepperMediaStreamAudioTrackHost);
117 };
118
119 } // namespace content
120
121 #endif // CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_AUDIO_TRACK_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698