OLD | NEW |
---|---|
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 "media/base/audio_parameters.h" | 17 #include "media/base/audio_parameters.h" |
18 #include "media/base/media_export.h" | 18 #include "media/base/media_export.h" |
19 | 19 |
20 namespace media { | 20 namespace media { |
21 | 21 |
22 class AudioBus; | 22 class AudioBus; |
23 | 23 |
24 // Writes audio data used for debugging purposes. All operations are | 24 // Writes audio data to a 16 bit PCM WAVE file used for debugging purposes. All |
25 // non-blocking. | 25 // operations are non-blocking. |
26 class MEDIA_EXPORT AudioDebugFileWriter { | 26 class MEDIA_EXPORT AudioDebugFileWriter { |
27 public: | 27 public: |
28 // Number of channels and sample rate are used from |params|, the other | |
29 // parameters are ignored. The number of channels in the data passed to | |
30 // Write() must match |params|. | |
28 AudioDebugFileWriter( | 31 AudioDebugFileWriter( |
29 const AudioParameters& params, | 32 const AudioParameters& params, |
30 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner); | 33 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner); |
31 ~AudioDebugFileWriter(); | 34 |
35 virtual ~AudioDebugFileWriter(); | |
o1ka
2017/03/01 18:36:23
It's inheritable for mocking only, right?
Having i
Henrik Grunell
2017/03/01 19:52:54
Yes. Added a comment.
| |
32 | 36 |
33 // 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 |
34 // 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 |
35 // called on the same sequence as Start(). | 39 // called on the same sequence as Start(). |
36 void Start(const base::FilePath& file); | 40 virtual void Start(const base::FilePath& file); |
37 | 41 |
38 // 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 |
39 // Stop(). Will be automatically called on destruction. | 43 // Stop(). Will be automatically called on destruction. |
40 void Stop(); | 44 virtual void Stop(); |
41 | 45 |
42 // Write |data| to file. | 46 // Write |data| to file. |
43 void Write(std::unique_ptr<AudioBus> data); | 47 virtual void Write(std::unique_ptr<AudioBus> data); |
44 | 48 |
45 // Returns true if Write() call scheduled at this point will most likely write | 49 // Returns true if Write() call scheduled at this point will most likely write |
46 // data to the file, and false if it most likely will be a no-op. The result | 50 // data to the file, and false if it most likely will be a no-op. The result |
47 // may be ambigulous if Start() or Stop() is executed at the moment. Can be | 51 // may be ambigulous if Start() or Stop() is executed at the moment. Can be |
48 // called from any sequence. | 52 // called from any sequence. |
49 bool WillWrite(); | 53 virtual bool WillWrite(); |
54 | |
55 // Gets the extension for the file type the as a string, for example "wav". | |
56 // Can be called before calling Start() to add the appropriate extension to | |
57 // the filename. | |
58 virtual const base::FilePath::CharType* GetFileNameExtension(); | |
59 | |
60 protected: | |
61 const AudioParameters params_; | |
50 | 62 |
51 private: | 63 private: |
52 class AudioFileWriter; | 64 class AudioFileWriter; |
53 | 65 |
54 // Deleter for AudioFileWriter. | 66 // Deleter for AudioFileWriter. |
55 struct OnThreadDeleter { | 67 struct OnThreadDeleter { |
56 public: | 68 public: |
57 OnThreadDeleter(); | 69 OnThreadDeleter(); |
58 OnThreadDeleter(const OnThreadDeleter& other); | 70 OnThreadDeleter(const OnThreadDeleter& other); |
59 OnThreadDeleter(scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 71 OnThreadDeleter(scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
60 ~OnThreadDeleter(); | 72 ~OnThreadDeleter(); |
61 void operator()(AudioFileWriter* ptr) const; | 73 void operator()(AudioFileWriter* ptr) const; |
62 | 74 |
63 private: | 75 private: |
64 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 76 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
65 }; | 77 }; |
66 | 78 |
67 using AudioFileWriterUniquePtr = | 79 using AudioFileWriterUniquePtr = |
68 std::unique_ptr<AudioFileWriter, OnThreadDeleter>; | 80 std::unique_ptr<AudioFileWriter, OnThreadDeleter>; |
69 | 81 |
70 AudioFileWriterUniquePtr file_writer_; | 82 AudioFileWriterUniquePtr file_writer_; |
71 const AudioParameters params_; | |
72 base::SequenceChecker client_sequence_checker_; | 83 base::SequenceChecker client_sequence_checker_; |
73 | 84 |
74 // The task runner to do file output operations on. | 85 // The task runner to do file output operations on. |
75 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; | 86 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; |
76 | 87 |
77 DISALLOW_COPY_AND_ASSIGN(AudioDebugFileWriter); | 88 DISALLOW_COPY_AND_ASSIGN(AudioDebugFileWriter); |
78 }; | 89 }; |
79 | 90 |
80 } // namspace media | 91 } // namspace media |
81 | 92 |
82 #endif // MEDIA_AUDIO_AUDIO_DEBUG_FILE_WRITER_H_ | 93 #endif // MEDIA_AUDIO_AUDIO_DEBUG_FILE_WRITER_H_ |
OLD | NEW |