Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 int BufferDurationForTesting(int sample_rate); | |
|
minyue
2015/11/16 11:57:32
You probably don't need this function.
here can b
ajose
2015/11/16 22:29:47
Done.
| |
| 49 | |
| 50 private: | |
| 51 friend class AudioTrackRecorderTest; | |
| 52 class AudioParameters; | |
| 53 | |
| 54 // Forward declaration of nested class for handling encoding. | |
| 55 // See the implementation file for details. | |
| 56 class AudioEncoder; | |
| 57 | |
| 58 // Used to check that we are destroyed on the same thread we were created on. | |
| 59 base::ThreadChecker main_render_thread_checker_; | |
| 60 | |
| 61 // Used to check that MediaStreamAudioSink's methods are called on the | |
| 62 // capture audio thread. | |
| 63 base::ThreadChecker capture_thread_checker_; | |
| 64 | |
| 65 // We need to hold on to the Blink track to remove ourselves on destruction. | |
| 66 const blink::WebMediaStreamTrack track_; | |
| 67 | |
| 68 // Thin wrapper around OpusEncoder. | |
| 69 // |encoder_| should be initialized before |encoder_thread_| such that | |
| 70 // |encoder_thread_| is destructed first. This, combined with all | |
| 71 // AudioEncoder work (aside from construction and destruction) happening on | |
| 72 // |encoder_thread_|, should allow us to be sure that all AudioEncoder work is | |
| 73 // done by the time we destroy it on ATR's thread. | |
| 74 const scoped_refptr<AudioEncoder> encoder_; | |
| 75 // The thread on which |encoder_| works. | |
| 76 base::Thread encoder_thread_; | |
| 77 | |
| 78 DISALLOW_COPY_AND_ASSIGN(AudioTrackRecorder); | |
| 79 }; | |
| 80 | |
| 81 } // namespace content | |
| 82 | |
| 83 #endif // CONTENT_RENDERER_MEDIA_AUDIO_TRACK_RECORDER_H_ | |
| OLD | NEW |