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

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

Powered by Google App Engine
This is Rietveld 408576698