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

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 plugin main thread.
36 class AudioSink : public MediaStreamAudioSink,
37 public base::SupportsWeakPtr<AudioSink> {
dmichael (off chromium) 2014/02/03 22:18:34 It looks like you're only getting AudioSink WeakPt
Peng 2014/02/03 22:50:31 Done.
38 public:
39 explicit AudioSink(PepperMediaStreamAudioTrackHost* host);
40 virtual ~AudioSink();
41
42 // Enqueues a free frame index into |frames_| which will be used for
43 // sending audio samples to plugin.
44 void EnqueueFrame(int32_t index);
dmichael (off chromium) 2014/02/03 22:18:34 please note what thread(s) this is callable on
Peng 2014/02/03 22:50:31 Done.
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 // Access only on the audio thread.
70 media::AudioParameters audio_params_;
71
72 // The size of a frame in bytes.
73 // Access only on the audio thread.
74 uint32_t frame_data_size_;
75
76 // A lock to protect the index queue |frames_|.
77 base::Lock lock_;
78
79 // A queue for free frame indices.
80 std::deque<int32_t> frames_;
81
82 scoped_refptr<base::MessageLoopProxy> main_message_loop_proxy_;
83
84 base::ThreadChecker audio_thread_checker_;
85
86 DISALLOW_COPY_AND_ASSIGN(AudioSink);
87 };
88
89 virtual ~PepperMediaStreamAudioTrackHost();
90
91 // PepperMediaStreamTrackHostBase overrides:
92 virtual void OnClose() OVERRIDE;
93
94 // MediaStreamFrameBuffer::Delegate overrides:
95 virtual void OnNewFrameEnqueued() OVERRIDE;
96
97 // ResourceHost overrides:
98 virtual void DidConnectPendingHostToResource() OVERRIDE;
99
100 blink::WebMediaStreamTrack track_;
101
102 // True if |audio_sink_| has been added to |blink::WebMediaStreamTrack|
103 // as a sink.
104 bool connected_;
105
106 AudioSink audio_sink_;
107
108 DISALLOW_COPY_AND_ASSIGN(PepperMediaStreamAudioTrackHost);
109 };
110
111 } // namespace content
112
113 #endif // CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_AUDIO_TRACK_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698