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

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: Update Created 6 years, 11 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 (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.
32 // This class is created, destroyed and added into |WebMediaStreamTrack| in
33 // the main thread. But audio samples are received in the audio thread.
34 class AudioSink : public MediaStreamAudioSink,
35 public base::SupportsWeakPtr<AudioSink> {
36 public:
37 explicit AudioSink(PepperMediaStreamAudioTrackHost* host);
38 virtual ~AudioSink();
39
40 // Enqueue a free frame. This function uses atomic operation, so it is
41 // thread safe.
42 void EnqueueFrame(int32_t index);
43
44 private:
45 void InitFramesOnMainThread(uint32_t number_of_frames, uint32_t frame_size);
46
47 // MediaStreamAudioSink overrides:
48 // Those functions are called from the audio thread.
49 virtual void OnData(const int16* audio_data,
50 int sample_rate,
51 int number_of_channels,
52 int number_of_frames) OVERRIDE;
53 virtual void OnSetFormat(const media::AudioParameters& params) OVERRIDE;
54
55 // Unowned host which is available during the AudioSink's lifespan.
56 PepperMediaStreamAudioTrackHost* host_;
57
58 // Timestamp of the next received audio frame.
59 base::TimeDelta timestamp_;
60
61 // Duration of one audio frame.
62 base::TimeDelta frame_duration_;
63
64 media::AudioParameters audio_params_;
65
66 // The size of frame pixels in bytes.
67 uint32_t frame_data_size_;
68
69 // Free frames can be used for sending audio samples.
70 // Each bit of |frames_| represents a frame index.
71 base::subtle::Atomic32 frames_;
72
73 scoped_refptr<base::MessageLoopProxy> main_message_loop_proxy_;
74
75 DISALLOW_COPY_AND_ASSIGN(AudioSink);
76 };
77
78 virtual ~PepperMediaStreamAudioTrackHost();
79
80 // PepperMediaStreamTrackHostBase overrides:
81 virtual void OnClose() OVERRIDE;
82
83 // MediaStreamFrameBuffer::Delegate overrides:
84 virtual bool OnNewFramePreEnqueued(int32_t index) OVERRIDE;
85
86 // ResourceHost overrides:
87 virtual void DidConnectPendingHostToResource() OVERRIDE;
88
89 blink::WebMediaStreamTrack track_;
90
91 // True if it has been added to |blink::WebMediaStreamTrack| as a sink.
92 bool connected_;
93
94 AudioSink audio_sink_;
95
96 DISALLOW_COPY_AND_ASSIGN(PepperMediaStreamAudioTrackHost);
97 };
98
99 } // namespace content
100
101 #endif // CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_AUDIO_TRACK_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698