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

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 review issues 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 // It is mainly used in the main thread. But the audio thread will use
60 // host_->frame_buffer() to read some buffer properties. It is safe
61 // because the frame_buffer()'s properties will not be changed after
62 // initialization.
63 PepperMediaStreamAudioTrackHost* host_;
64
65 // Timestamp of the next received audio frame.
66 // Access only on the audio thread.
67 base::TimeDelta timestamp_;
68
69 // Duration of one audio frame.
70 // Access only on the audio thread.
71 base::TimeDelta frame_duration_;
72
73 // The current audio parameters.
74 // Access only on the audio thread.
75 media::AudioParameters audio_params_;
76
77 // The original audio parameters which is set in the first time of
78 // OnSetFormat being called.
79 // Access only on the audio thread.
80 media::AudioParameters original_audio_params_;
81
82 // The size of a frame in bytes.
83 // Access only on the audio thread.
84 uint32_t frame_data_size_;
85
86 // A lock to protect the index queue |frames_|.
87 base::Lock lock_;
88
89 // A queue for free frame indices.
90 std::deque<int32_t> frames_;
91
92 scoped_refptr<base::MessageLoopProxy> main_message_loop_proxy_;
93
94 base::ThreadChecker audio_thread_checker_;
95
96 base::WeakPtrFactory<AudioSink> weak_factory_;
97
98 DISALLOW_COPY_AND_ASSIGN(AudioSink);
99 };
100
101 virtual ~PepperMediaStreamAudioTrackHost();
102
103 // PepperMediaStreamTrackHostBase overrides:
104 virtual void OnClose() OVERRIDE;
105
106 // MediaStreamFrameBuffer::Delegate overrides:
107 virtual void OnNewFrameEnqueued() OVERRIDE;
108
109 // ResourceHost overrides:
110 virtual void DidConnectPendingHostToResource() OVERRIDE;
111
112 blink::WebMediaStreamTrack track_;
113
114 // True if |audio_sink_| has been added to |blink::WebMediaStreamTrack|
115 // as a sink.
116 bool connected_;
117
118 AudioSink audio_sink_;
119
120 DISALLOW_COPY_AND_ASSIGN(PepperMediaStreamAudioTrackHost);
121 };
122
123 } // namespace content
124
125 #endif // CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_AUDIO_TRACK_HOST_H_
OLDNEW
« no previous file with comments | « content/content_renderer.gypi ('k') | content/renderer/pepper/pepper_media_stream_audio_track_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698