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

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: miu's comment 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
« no previous file with comments | « content/renderer/media/DEPS ('k') | content/renderer/media/audio_track_recorder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/macros.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/threading/thread.h"
13 #include "base/threading/thread_checker.h"
14 #include "base/time/time.h"
15 #include "content/public/renderer/media_stream_audio_sink.h"
16 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
17
18 namespace media {
19 class AudioBus;
20 } // namespace media
21
22 namespace content {
23
24 // AudioTrackRecorder is a MediaStreamAudioSink that encodes the audio buses
25 // received from a Stream Audio Track. The class is constructed on a
26 // single thread (the main Render thread) but can recieve MediaStreamAudioSink-
27 // related calls on a different "live audio" thread (referred to internally as
28 // the "capture thread"). It owns an internal thread to use for encoding, on
29 // which lives an AudioEncoder (a private nested class of ATR) with its own
30 // threading subtleties, see the implementation file.
31 class CONTENT_EXPORT AudioTrackRecorder
32 : NON_EXPORTED_BASE(public MediaStreamAudioSink) {
33 public:
34 using OnEncodedAudioCB =
35 base::Callback<void(const media::AudioParameters& params,
36 scoped_ptr<std::string> encoded_data,
37 base::TimeTicks capture_time)>;
38
39 AudioTrackRecorder(const blink::WebMediaStreamTrack& track,
40 const OnEncodedAudioCB& on_encoded_audio_cb);
41 ~AudioTrackRecorder() override;
42
43 // Implement MediaStreamAudioSink.
44 void OnSetFormat(const media::AudioParameters& params) override;
45 void OnData(const media::AudioBus& audio_bus,
46 base::TimeTicks capture_time) override;
47
48 private:
49 friend class AudioTrackRecorderTest;
50 class AudioParameters;
51
52 // Forward declaration of nested class for handling encoding.
53 // See the implementation file for details.
54 class AudioEncoder;
55
56 // Returns the Opus buffer duration in milliseconds, or zero if none will work
57 // for the given |sample_rate|.
58 static int GetOpusBufferDuration(int sample_rate);
59
60 // Used to check that we are destroyed on the same thread we were created on.
61 base::ThreadChecker main_render_thread_checker_;
62
63 // Used to check that MediaStreamAudioSink's methods are called on the
64 // capture audio thread.
65 base::ThreadChecker capture_thread_checker_;
66
67 // We need to hold on to the Blink track to remove ourselves on destruction.
68 const blink::WebMediaStreamTrack track_;
69
70 // Thin wrapper around OpusEncoder.
71 // |encoder_| should be initialized before |encoder_thread_| such that
72 // |encoder_thread_| is destructed first. This, combined with all
73 // AudioEncoder work (aside from construction and destruction) happening on
74 // |encoder_thread_|, should allow us to be sure that all AudioEncoder work is
75 // done by the time we destroy it on ATR's thread.
76 const scoped_refptr<AudioEncoder> encoder_;
77 // The thread on which |encoder_| works.
78 base::Thread encoder_thread_;
79
80 DISALLOW_COPY_AND_ASSIGN(AudioTrackRecorder);
81 };
82
83 } // namespace content
84
85 #endif // CONTENT_RENDERER_MEDIA_AUDIO_TRACK_RECORDER_H_
OLDNEW
« no previous file with comments | « content/renderer/media/DEPS ('k') | content/renderer/media/audio_track_recorder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698