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

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

Issue 290993005: Support configuring number of audio buffers in MediaStream Pepper API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 6 years, 6 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_AUDIO_TRACK_HOST_H_ 5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_AUDIO_TRACK_HOST_H_
6 #define CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_AUDIO_TRACK_HOST_H_ 6 #define CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_AUDIO_TRACK_HOST_H_
7 7
8 #include <deque> 8 #include <deque>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
14 #include "base/threading/thread_checker.h" 14 #include "base/threading/thread_checker.h"
15 #include "content/public/renderer/media_stream_audio_sink.h" 15 #include "content/public/renderer/media_stream_audio_sink.h"
16 #include "content/renderer/pepper/pepper_media_stream_track_host_base.h" 16 #include "content/renderer/pepper/pepper_media_stream_track_host_base.h"
17 #include "media/audio/audio_parameters.h" 17 #include "media/audio/audio_parameters.h"
18 #include "ppapi/shared_impl/media_stream_audio_track_shared.h"
18 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" 19 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
19 20
20 namespace base { 21 namespace base {
21 class MessageLoopProxy; 22 class MessageLoopProxy;
22 } // namespace base 23 } // namespace base
23 24
24 namespace content { 25 namespace content {
25 26
26 class PepperMediaStreamAudioTrackHost : public PepperMediaStreamTrackHostBase { 27 class PepperMediaStreamAudioTrackHost : public PepperMediaStreamTrackHostBase {
27 public: 28 public:
28 PepperMediaStreamAudioTrackHost(RendererPpapiHost* host, 29 PepperMediaStreamAudioTrackHost(RendererPpapiHost* host,
29 PP_Instance instance, 30 PP_Instance instance,
30 PP_Resource resource, 31 PP_Resource resource,
31 const blink::WebMediaStreamTrack& track); 32 const blink::WebMediaStreamTrack& track);
32 33
33 private: 34 private:
34 // A helper class for receiving audio samples in the audio thread. 35 // A helper class for receiving audio samples in the audio thread.
35 // This class is created and destroyed on the renderer main thread. 36 // This class is created and destroyed on the renderer main thread.
36 class AudioSink : public MediaStreamAudioSink { 37 class AudioSink : public MediaStreamAudioSink {
37 public: 38 public:
38 explicit AudioSink(PepperMediaStreamAudioTrackHost* host); 39 explicit AudioSink(PepperMediaStreamAudioTrackHost* host);
39 virtual ~AudioSink(); 40 virtual ~AudioSink();
40 41
41 // Enqueues a free buffer index into |buffers_| which will be used for 42 // Enqueues a free buffer index into |buffers_| which will be used for
42 // sending audio samples to plugin. 43 // sending audio samples to plugin.
43 // This function is called on the main thread. 44 // This function is called on the main thread.
44 void EnqueueBuffer(int32_t index); 45 void EnqueueBuffer(int32_t index);
45 46
47 // This function is called on the main thread.
48 void Configure(int number_of_buffers);
dcheng 2014/05/28 15:55:44 Nit: this should be explicitly sized to int32_t li
thembrown 2014/05/28 17:13:11 Done.
49
46 private: 50 private:
47 // Initializes buffers on the main thread. 51 // Initializes buffers on the main thread.
48 void InitBuffersOnMainThread(int32_t number_of_buffers, 52 void SetFormatOnMainThread(int bytes_per_second);
49 int32_t buffer_size); 53
54 void InitBuffers();
50 55
51 // Send enqueue buffer message on the main thread. 56 // Send enqueue buffer message on the main thread.
52 void SendEnqueueBufferMessageOnMainThread(int32_t index); 57 void SendEnqueueBufferMessageOnMainThread(int32_t index);
53 58
54 // MediaStreamAudioSink overrides: 59 // MediaStreamAudioSink overrides:
55 // These two functions should be called on the audio thread. 60 // These two functions should be called on the audio thread.
56 virtual void OnData(const int16* audio_data, 61 virtual void OnData(const int16* audio_data,
57 int sample_rate, 62 int sample_rate,
58 int number_of_channels, 63 int number_of_channels,
59 int number_of_frames) OVERRIDE; 64 int number_of_frames) OVERRIDE;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 97
93 // A queue for free buffer indices. 98 // A queue for free buffer indices.
94 std::deque<int32_t> buffers_; 99 std::deque<int32_t> buffers_;
95 100
96 scoped_refptr<base::MessageLoopProxy> main_message_loop_proxy_; 101 scoped_refptr<base::MessageLoopProxy> main_message_loop_proxy_;
97 102
98 base::ThreadChecker audio_thread_checker_; 103 base::ThreadChecker audio_thread_checker_;
99 104
100 base::WeakPtrFactory<AudioSink> weak_factory_; 105 base::WeakPtrFactory<AudioSink> weak_factory_;
101 106
107 // Number of buffers.
108 int32_t number_of_buffers_;
109
110 // Number of bytes per second.
111 int bytes_per_second_;
112
102 DISALLOW_COPY_AND_ASSIGN(AudioSink); 113 DISALLOW_COPY_AND_ASSIGN(AudioSink);
103 }; 114 };
104 115
105 virtual ~PepperMediaStreamAudioTrackHost(); 116 virtual ~PepperMediaStreamAudioTrackHost();
106 117
118 // ResourceMessageHandler overrides:
119 virtual int32_t OnResourceMessageReceived(
120 const IPC::Message& msg,
121 ppapi::host::HostMessageContext* context) OVERRIDE;
122
123 // Message handlers:
124 int32_t OnHostMsgConfigure(
125 ppapi::host::HostMessageContext* context,
126 const ppapi::MediaStreamAudioTrackShared::Attributes& attributes);
127
107 // PepperMediaStreamTrackHostBase overrides: 128 // PepperMediaStreamTrackHostBase overrides:
108 virtual void OnClose() OVERRIDE; 129 virtual void OnClose() OVERRIDE;
109 130
110 // MediaStreamBufferManager::Delegate overrides: 131 // MediaStreamBufferManager::Delegate overrides:
111 virtual void OnNewBufferEnqueued() OVERRIDE; 132 virtual void OnNewBufferEnqueued() OVERRIDE;
112 133
113 // ResourceHost overrides: 134 // ResourceHost overrides:
114 virtual void DidConnectPendingHostToResource() OVERRIDE; 135 virtual void DidConnectPendingHostToResource() OVERRIDE;
115 136
116 blink::WebMediaStreamTrack track_; 137 blink::WebMediaStreamTrack track_;
117 138
118 // True if |audio_sink_| has been added to |blink::WebMediaStreamTrack| 139 // True if |audio_sink_| has been added to |blink::WebMediaStreamTrack|
119 // as a sink. 140 // as a sink.
120 bool connected_; 141 bool connected_;
121 142
122 AudioSink audio_sink_; 143 AudioSink audio_sink_;
123 144
124 DISALLOW_COPY_AND_ASSIGN(PepperMediaStreamAudioTrackHost); 145 DISALLOW_COPY_AND_ASSIGN(PepperMediaStreamAudioTrackHost);
125 }; 146 };
126 147
127 } // namespace content 148 } // namespace content
128 149
129 #endif // CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_AUDIO_TRACK_HOST_H_ 150 #endif // CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_AUDIO_TRACK_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698