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

Side by Side Diff: content/renderer/media/audio_track_recorder.h

Issue 1406113002: Add AudioTrackRecorder for audio component of MediaStream recording. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: forward declaration Created 5 years, 1 month 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 2015 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_MEDIA_AUDIO_TRACK_RECORDER_H_
6 #define CONTENT_RENDERER_MEDIA_AUDIO_TRACK_RECORDER_H_
7
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/threading/thread_checker.h"
12 #include "base/time/time.h"
13 #include "content/public/renderer/media_stream_audio_sink.h"
14 #include "media/base/audio_bus.h"
15 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
16
17 namespace base {
18 class Thread;
19 } // namespace base
20
21 namespace content {
22
23 // AudioTrackRecorder is a MediaStreamAudioSink that encodes the audio buses
24 // received from a Stream Audio Track. The class is constructed on a
25 // single thread (the main Render thread) but can recieve MediaStreamAudioSink-
26 // related calls on a different "live audio" thread (referred to internally as
27 // the "capture thread"). It owns an internal thread to use for encoding, on
28 // which lives an AudioEncoder (a private nested class of ATR) with its own
29 // threading subtleties, see the implementation file.
30 class CONTENT_EXPORT AudioTrackRecorder
31 : NON_EXPORTED_BASE(public MediaStreamAudioSink) {
32 public:
33 using OnEncodedAudioCB =
34 base::Callback<void(const media::AudioParameters& params,
35 scoped_ptr<std::string> encoded_data,
36 base::TimeTicks capture_time)>;
37
38 AudioTrackRecorder(const blink::WebMediaStreamTrack& track,
39 const OnEncodedAudioCB& on_encoded_audio_cb);
40 ~AudioTrackRecorder() override;
41
42 // Implement MediaStreamAudioSink.
43 void OnSetFormat(const media::AudioParameters& params) override;
44 void OnData(const media::AudioBus& audio_bus,
45 base::TimeTicks capture_time) override;
46
47 private:
48 friend class AudioTrackRecorderTest;
49 class AudioParameters;
50
51 // Forward declaration of nested class for handling encoding.
52 // See the implementation file for details.
53 class AudioEncoder;
54
55 // Used to check that we are destroyed on the same thread we were created on.
56 base::ThreadChecker main_render_thread_checker_;
57
58 // Used to check that MediaStreamAudioSink's methods are called on the
59 // capture audio thread.
60 base::ThreadChecker capture_thread_checker_;
61
62 // We need to hold on to the Blink track to remove ourselves on destruction.
63 const blink::WebMediaStreamTrack track_;
64
65 // Thin wrapper around OpusEncoder.
66 // |encoder_| should be initialized before |encoder_thread_| such that
67 // |encoder_thread_| is destructed first. This, combined with all
68 // AudioEncoder work (aside from construction and destruction) happening on
69 // |encoder_thread_|, should allow us to be sure that all AudioEncoder work is
70 // done by the time we destroy it on ATR's thread.
71 const scoped_refptr<AudioEncoder> encoder_;
72 // The thread on which |encoder_| works.
73 const scoped_ptr<base::Thread> encoder_thread_;
miu 2015/10/26 22:41:04 nit: No need for separate heap allocation (scoped_
ajose 2015/10/27 18:41:28 Done.
74
75 DISALLOW_COPY_AND_ASSIGN(AudioTrackRecorder);
76 };
77
78 } // namespace content
79
80 #endif // CONTENT_RENDERER_MEDIA_AUDIO_TRACK_RECORDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698