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

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

Issue 2885173002: Make AudioDebugFileWriter create its own file worker thread. (Closed)
Patch Set: Make AudioDebugFileWriter create its own file thread. Created 3 years, 7 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_AUDIO_AUDIO_DEBUG_FILE_WRITER_H_ 5 #ifndef MEDIA_AUDIO_AUDIO_DEBUG_FILE_WRITER_H_
6 #define MEDIA_AUDIO_AUDIO_DEBUG_FILE_WRITER_H_ 6 #define MEDIA_AUDIO_AUDIO_DEBUG_FILE_WRITER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 11
12 #include "base/files/file.h" 12 #include "base/files/file.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/sequence_checker.h" 15 #include "base/sequence_checker.h"
16 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
17 #include "base/task_scheduler/post_task.h"
17 #include "media/base/audio_parameters.h" 18 #include "media/base/audio_parameters.h"
18 #include "media/base/media_export.h" 19 #include "media/base/media_export.h"
19 20
20 namespace media { 21 namespace media {
21 22
22 class AudioBus; 23 class AudioBus;
23 24
24 // Writes audio data to a 16 bit PCM WAVE file used for debugging purposes. All 25 // Writes audio data to a 16 bit PCM WAVE file used for debugging purposes. All
25 // operations are non-blocking. 26 // operations are non-blocking.
26 // Functions are virtual for the purpose of test mocking. 27 // Functions are virtual for the purpose of test mocking.
27 class MEDIA_EXPORT AudioDebugFileWriter { 28 class MEDIA_EXPORT AudioDebugFileWriter {
28 public: 29 public:
29 // Number of channels and sample rate are used from |params|, the other 30 // Number of channels and sample rate are used from |params|, the other
30 // parameters are ignored. The number of channels in the data passed to 31 // parameters are ignored. The number of channels in the data passed to
31 // Write() must match |params|. 32 // Write() must match |params|.
32 AudioDebugFileWriter( 33 AudioDebugFileWriter(const AudioParameters& params);
33 const AudioParameters& params,
34 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner);
35 34
36 virtual ~AudioDebugFileWriter(); 35 virtual ~AudioDebugFileWriter();
37 36
38 // Must be called before calling Write() for the first time after creation or 37 // Must be called before calling Write() for the first time after creation or
39 // Stop() call. Can be called on any sequence; Write() and Stop() must be 38 // Stop() call. Can be called on any sequence; Write() and Stop() must be
40 // called on the same sequence as Start(). 39 // called on the same sequence as Start().
41 virtual void Start(const base::FilePath& file); 40 virtual void Start(const base::FilePath& file);
42 41
43 // Must be called to finish recording. Each call to Start() requires a call to 42 // Must be called to finish recording. Each call to Start() requires a call to
44 // Stop(). Will be automatically called on destruction. 43 // Stop(). Will be automatically called on destruction.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 76 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
78 }; 77 };
79 78
80 using AudioFileWriterUniquePtr = 79 using AudioFileWriterUniquePtr =
81 std::unique_ptr<AudioFileWriter, OnThreadDeleter>; 80 std::unique_ptr<AudioFileWriter, OnThreadDeleter>;
82 81
83 AudioFileWriterUniquePtr file_writer_; 82 AudioFileWriterUniquePtr file_writer_;
84 base::SequenceChecker client_sequence_checker_; 83 base::SequenceChecker client_sequence_checker_;
85 84
86 // The task runner to do file output operations on. 85 // The task runner to do file output operations on.
87 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; 86 const scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_ =
87 base::CreateSingleThreadTaskRunnerWithTraits(
gab 2017/05/18 16:10:10 In general we don't want to create SingleThreadTas
Sébastien Marchand 2017/05/18 17:43:06 Thanks for the detailed comment! I'm addressing th
88 {base::MayBlock(), base::TaskPriority::BACKGROUND});
88 89
89 DISALLOW_COPY_AND_ASSIGN(AudioDebugFileWriter); 90 DISALLOW_COPY_AND_ASSIGN(AudioDebugFileWriter);
90 }; 91 };
91 92
92 } // namspace media 93 } // namspace media
93 94
94 #endif // MEDIA_AUDIO_AUDIO_DEBUG_FILE_WRITER_H_ 95 #endif // MEDIA_AUDIO_AUDIO_DEBUG_FILE_WRITER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698