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/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 "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | |
| 16 | |
| 17 namespace content { | |
| 18 | |
| 19 // AudioTrackRecorder is a MediaStreamAudioSink that encodes the audio buses | |
| 20 // received from a Stream Audio Track. The class is constructed on a | |
| 21 // single thread (the main Render thread) but can recieve MediaStreamAudioSink- | |
| 22 // related calls on a different "live audio" thread (referred to internally as | |
| 23 // the "capture thread"). It owns an internal thread to use for encoding, on | |
| 24 // which lives an AudioEncoder (a private nested class of ATR) with its own | |
| 25 // threading subtleties, see the implementation file. | |
| 26 class CONTENT_EXPORT AudioTrackRecorder | |
| 27 : NON_EXPORTED_BASE(public MediaStreamAudioSink) { | |
| 28 public: | |
| 29 using OnEncodedAudioCB = | |
| 30 base::Callback<void(const media::AudioParameters& params, | |
| 31 scoped_ptr<std::string> encoded_data, | |
| 32 base::TimeTicks capture_time)>; | |
| 33 | |
| 34 AudioTrackRecorder(const blink::WebMediaStreamTrack& track, | |
| 35 const OnEncodedAudioCB& on_encoded_audio_cb); | |
| 36 ~AudioTrackRecorder() override; | |
| 37 | |
| 38 // Implement MediaStreamAudioSink. | |
| 39 void OnSetFormat(const media::AudioParameters& params) override; | |
| 40 void OnData(const media::AudioBus& audio_bus, | |
| 41 base::TimeTicks capture_time) override; | |
| 42 | |
| 43 private: | |
| 44 friend class AudioTrackRecorderTest; | |
| 45 class AudioBus; | |
|
mcasas
2015/10/28 20:03:00
move to l.16:
namespace media {
class AudioBus;
}
ajose
2015/10/28 21:54:06
Done.
| |
| 46 class AudioParameters; | |
| 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 const blink::WebMediaStreamTrack track_; | |
| 61 | |
| 62 // Thin wrapper around OpusEncoder. | |
| 63 // |encoder_| should be initialized before |encoder_thread_| such that | |
| 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 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_ | |
| OLD | NEW |