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, | |
|
minyue
2015/11/11 13:40:10
Em.. why using a std::string for encoded_data?
ajose
2015/11/12 00:10:41
I believe this choice was made to simplify data mo
minyue
2015/11/12 16:52:31
Yes, indeed, it is quite often used in VPx. Good,
| |
| 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 // Used to check that we are destroyed on the same thread we were created on. | |
| 57 base::ThreadChecker main_render_thread_checker_; | |
| 58 | |
| 59 // Used to check that MediaStreamAudioSink's methods are called on the | |
| 60 // capture audio thread. | |
| 61 base::ThreadChecker capture_thread_checker_; | |
| 62 | |
| 63 // We need to hold on to the Blink track to remove ourselves on destruction. | |
| 64 const blink::WebMediaStreamTrack track_; | |
| 65 | |
| 66 // Thin wrapper around OpusEncoder. | |
| 67 // |encoder_| should be initialized before |encoder_thread_| such that | |
| 68 // |encoder_thread_| is destructed first. This, combined with all | |
| 69 // AudioEncoder work (aside from construction and destruction) happening on | |
| 70 // |encoder_thread_|, should allow us to be sure that all AudioEncoder work is | |
| 71 // done by the time we destroy it on ATR's thread. | |
| 72 const scoped_refptr<AudioEncoder> encoder_; | |
| 73 // The thread on which |encoder_| works. | |
| 74 base::Thread encoder_thread_; | |
| 75 | |
| 76 DISALLOW_COPY_AND_ASSIGN(AudioTrackRecorder); | |
| 77 }; | |
| 78 | |
| 79 } // namespace content | |
| 80 | |
| 81 #endif // CONTENT_RENDERER_MEDIA_AUDIO_TRACK_RECORDER_H_ | |
| OLD | NEW |