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

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

Issue 1579693006: MediaRecorder: support sampling rate adaption in AudioTrackRecorder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: miu@s nit Created 4 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
« no previous file with comments | « no previous file | 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_RENDERER_MEDIA_AUDIO_TRACK_RECORDER_H_ 5 #ifndef CONTENT_RENDERER_MEDIA_AUDIO_TRACK_RECORDER_H_
6 #define CONTENT_RENDERER_MEDIA_AUDIO_TRACK_RECORDER_H_ 6 #define CONTENT_RENDERER_MEDIA_AUDIO_TRACK_RECORDER_H_
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/threading/thread.h" 12 #include "base/threading/thread.h"
13 #include "base/threading/thread_checker.h" 13 #include "base/threading/thread_checker.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "content/public/renderer/media_stream_audio_sink.h" 15 #include "content/public/renderer/media_stream_audio_sink.h"
16 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" 16 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
17 17
18 namespace media { 18 namespace media {
19 class AudioBus; 19 class AudioBus;
20 class AudioParameters;
20 } // namespace media 21 } // namespace media
21 22
22 namespace content { 23 namespace content {
23 24
24 // AudioTrackRecorder is a MediaStreamAudioSink that encodes the audio buses 25 // AudioTrackRecorder is a MediaStreamAudioSink that encodes the audio buses
25 // received from a Stream Audio Track. The class is constructed on a 26 // received from a Stream Audio Track. The class is constructed on a
26 // single thread (the main Render thread) but can recieve MediaStreamAudioSink- 27 // single thread (the main Render thread) but can recieve MediaStreamAudioSink-
27 // related calls on a different "live audio" thread (referred to internally as 28 // 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 // 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 // which lives an AudioEncoder (a private nested class of ATR) with its own
(...skipping 10 matching lines...) Expand all
40 const OnEncodedAudioCB& on_encoded_audio_cb, 41 const OnEncodedAudioCB& on_encoded_audio_cb,
41 int32_t bits_per_second); 42 int32_t bits_per_second);
42 ~AudioTrackRecorder() override; 43 ~AudioTrackRecorder() override;
43 44
44 // Implement MediaStreamAudioSink. 45 // Implement MediaStreamAudioSink.
45 void OnSetFormat(const media::AudioParameters& params) override; 46 void OnSetFormat(const media::AudioParameters& params) override;
46 void OnData(const media::AudioBus& audio_bus, 47 void OnData(const media::AudioBus& audio_bus,
47 base::TimeTicks capture_time) override; 48 base::TimeTicks capture_time) override;
48 49
49 private: 50 private:
50 friend class AudioTrackRecorderTest;
51 class AudioParameters;
52
53 // Forward declaration of nested class for handling encoding. 51 // Forward declaration of nested class for handling encoding.
54 // See the implementation file for details. 52 // See the implementation file for details.
55 class AudioEncoder; 53 class AudioEncoder;
56 54
57 // Returns the Opus buffer duration in milliseconds, or zero if none will work
58 // for the given |sample_rate|.
59 static int GetOpusBufferDuration(int sample_rate);
60
61 // Used to check that we are destroyed on the same thread we were created on. 55 // Used to check that we are destroyed on the same thread we were created on.
62 base::ThreadChecker main_render_thread_checker_; 56 base::ThreadChecker main_render_thread_checker_;
63 57
64 // Used to check that MediaStreamAudioSink's methods are called on the 58 // Used to check that MediaStreamAudioSink's methods are called on the
65 // capture audio thread. 59 // capture audio thread.
66 base::ThreadChecker capture_thread_checker_; 60 base::ThreadChecker capture_thread_checker_;
67 61
68 // We need to hold on to the Blink track to remove ourselves on destruction. 62 // We need to hold on to the Blink track to remove ourselves on destruction.
69 const blink::WebMediaStreamTrack track_; 63 const blink::WebMediaStreamTrack track_;
70 64
71 // Thin wrapper around OpusEncoder. 65 // Thin wrapper around OpusEncoder.
72 // |encoder_| should be initialized before |encoder_thread_| such that 66 // |encoder_| should be initialized before |encoder_thread_| such that
73 // |encoder_thread_| is destructed first. This, combined with all 67 // |encoder_thread_| is destructed first. This, combined with all
74 // AudioEncoder work (aside from construction and destruction) happening on 68 // AudioEncoder work (aside from construction and destruction) happening on
75 // |encoder_thread_|, should allow us to be sure that all AudioEncoder work is 69 // |encoder_thread_|, should allow us to be sure that all AudioEncoder work is
76 // done by the time we destroy it on ATR's thread. 70 // done by the time we destroy it on ATR's thread.
77 const scoped_refptr<AudioEncoder> encoder_; 71 const scoped_refptr<AudioEncoder> encoder_;
78 // The thread on which |encoder_| works. 72 // The thread on which |encoder_| works.
79 base::Thread encoder_thread_; 73 base::Thread encoder_thread_;
80 74
81 DISALLOW_COPY_AND_ASSIGN(AudioTrackRecorder); 75 DISALLOW_COPY_AND_ASSIGN(AudioTrackRecorder);
82 }; 76 };
83 77
84 } // namespace content 78 } // namespace content
85 79
86 #endif // CONTENT_RENDERER_MEDIA_AUDIO_TRACK_RECORDER_H_ 80 #endif // CONTENT_RENDERER_MEDIA_AUDIO_TRACK_RECORDER_H_
OLDNEW
« no previous file with comments | « no previous file | content/renderer/media/audio_track_recorder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698