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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/audio_track_recorder.h
diff --git a/content/renderer/media/audio_track_recorder.h b/content/renderer/media/audio_track_recorder.h
new file mode 100644
index 0000000000000000000000000000000000000000..6bf2e2f552c877828d43dbe7bcf04ec98f108cf6
--- /dev/null
+++ b/content/renderer/media/audio_track_recorder.h
@@ -0,0 +1,77 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_RENDERER_MEDIA_AUDIO_TRACK_RECORDER_H_
+#define CONTENT_RENDERER_MEDIA_AUDIO_TRACK_RECORDER_H_
+
+#include "base/callback.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/threading/thread.h"
+#include "base/threading/thread_checker.h"
+#include "base/time/time.h"
+#include "content/public/renderer/media_stream_audio_sink.h"
+#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
+#include "media/base/audio_bus.h"
+#include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
+
+namespace content {
+
+// AudioTrackRecorder is a MediaStreamAudioSink that encodes the audio buses
+// received from a Stream Audio Track. The class is constructed on a
+// single thread (the main Render thread) but can recieve MediaStreamAudioSink-
+// related calls on a different "live audio" thread (referred to internally as
+// the "capture thread"). It owns an internal thread to use for encoding, on
+// which lives an AudioEncoder (a private nested class of ATR) with its own
+// threading subtleties, see the implementation file.
+class CONTENT_EXPORT AudioTrackRecorder
+ : NON_EXPORTED_BASE(public MediaStreamAudioSink) {
+ public:
+ using OnEncodedAudioCB =
+ base::Callback<void(const media::AudioParameters& params,
+ scoped_ptr<std::string> encoded_data,
+ base::TimeTicks capture_time)>;
+
+ AudioTrackRecorder(const blink::WebMediaStreamTrack& track,
+ const OnEncodedAudioCB& on_encoded_audio_cb);
+ ~AudioTrackRecorder() override;
+
+ // Implement MediaStreamAudioSink.
+ void OnSetFormat(const media::AudioParameters& params) override;
+ void OnData(const media::AudioBus& audio_bus,
+ base::TimeTicks capture_time) override;
+
+ private:
+ friend class AudioTrackRecorderTest;
+
+ // Forward declaration of nested class for handling encoding.
+ // See the implementation file for details.
+ class AudioEncoder;
+
+ // Used to check that we are destroyed on the same thread we were created on.
+ base::ThreadChecker main_render_thread_checker_;
+
+ // Used to check that MediaStreamAudioSink's methods are called on the
+ // capture audio thread.
+ base::ThreadChecker capture_thread_checker_;
+
+ // We need to hold on to the Blink track to remove ourselves on destruction.
+ blink::WebMediaStreamTrack track_;
+
+ // Thin wrapper around OpusEncoder.
+ // |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
+ // |encoder_thread_| is destructed first. This, combined with all
+ // AudioEncoder work (aside from construction and destruction) happening on
+ // |encoder_thread_|, should allow us to be sure that all AudioEncoder work is
+ // done by the time we destroy it on ATR's thread.
+ const scoped_refptr<AudioEncoder> encoder_;
+ // The thread on which |encoder_| works.
+ const scoped_ptr<base::Thread> encoder_thread_;
+
+ DISALLOW_COPY_AND_ASSIGN(AudioTrackRecorder);
+};
+
+} // namespace content
+
+#endif // CONTENT_RENDERER_MEDIA_AUDIO_TRACK_RECORDER_H_

Powered by Google App Engine
This is Rietveld 408576698