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

Side by Side Diff: media/audio/audio_debug_recording_helper.h

Issue 2582703003: Audio output debug recording. (Closed)
Patch Set: Using callbacks instead. Created 3 years, 11 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
OLDNEW
(Empty)
1 // Copyright 2017 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 MEDIA_AUDIO_AUDIO_DEBUG_RECORDING_HELPER_H_
6 #define MEDIA_AUDIO_AUDIO_DEBUG_RECORDING_HELPER_H_
7
8 #include <memory>
9
10 #include "base/callback.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/threading/thread_checker.h"
13 #include "media/audio/audio_file_writer.h"
14 #include "media/base/audio_parameters.h"
15
16 namespace base {
17 class FilePath;
18 class SingleThreadTaskRunner;
19 }
20
21 namespace media {
22
23 class AudioBus;
24
25 // A helper class for those who want to use AudioFileWriter. It handles
26 // copying AudioBus data, thread jump (MaybeWrite() can be called on any
27 // thread), and creating and deleting the AudioFileWriter at enable and disable.
28 class AudioDebugRecordingHelper {
29 public:
30 AudioDebugRecordingHelper(
31 const AudioParameters& params,
32 const CreateAudioFileWriterCallback& create_audio_file_writer_callback,
33 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
34 ~AudioDebugRecordingHelper();
35
36 // Enable and disable debug recording. When enabled, |audio_manager_| is asked
37 // to create a DebugWriter. Extension "wav" will be added to |file_name|.
38 void EnableDebugRecording(const base::FilePath& file_name);
39 void DisableDebugRecording();
40
41 // If debug recording is enabled, copies audio data and posts DoWrite() on
42 // |task_runner_|. Can be called on any thread.
43 void MaybeWrite(const AudioBus* source);
44
45 // Pass-through to AudioFileWriter::WillWrite(). Can be called on any thread.
46 bool WillWrite();
47
48 private:
49 // Writes debug data to |debug_writer_|.
50 void DoWrite(std::unique_ptr<media::AudioBus> data);
51
52 const AudioParameters params_;
53 CreateAudioFileWriterCallback create_audio_file_writer_callback_;
54 std::unique_ptr<AudioFileWriter> debug_writer_;
55 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
56
57 base::WeakPtrFactory<AudioDebugRecordingHelper> weak_factory_;
58 DISALLOW_COPY_AND_ASSIGN(AudioDebugRecordingHelper);
59 };
60
61 } // namspace media
62
63 #endif // MEDIA_AUDIO_AUDIO_DEBUG_RECORDING_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698