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_FILE_WRITER_H_ | 5 #ifndef MEDIA_AUDIO_AUDIO_DEBUG_FILE_WRITER_H_ |
6 #define MEDIA_AUDIO_AUDIO_FILE_WRITER_H_ | 6 #define MEDIA_AUDIO_AUDIO_DEBUG_FILE_WRITER_H_ |
| 7 |
| 8 #include <stdint.h> |
7 | 9 |
8 #include <memory> | 10 #include <memory> |
9 | 11 |
10 namespace base { | 12 #include "base/files/file.h" |
11 class FilePath; | 13 #include "base/macros.h" |
12 } | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/sequence_checker.h" |
| 16 #include "base/single_thread_task_runner.h" |
| 17 #include "media/base/audio_parameters.h" |
| 18 #include "media/base/media_export.h" |
13 | 19 |
14 namespace media { | 20 namespace media { |
15 | 21 |
16 class AudioBus; | 22 class AudioBus; |
17 | 23 |
18 // A writer interface used for writing audio data to file for debugging | 24 // Writes audio data used for debugging purposes. All operations are |
19 // purposes. | 25 // non-blocking. |
20 class AudioFileWriter { | 26 class MEDIA_EXPORT AudioDebugFileWriter { |
21 public: | 27 public: |
22 virtual ~AudioFileWriter() {} | 28 AudioDebugFileWriter( |
| 29 const AudioParameters& params, |
| 30 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner); |
| 31 ~AudioDebugFileWriter(); |
23 | 32 |
24 // Must be called before calling Write() for the first time after creation or | 33 // Must be called before calling Write() for the first time after creation or |
25 // Stop() call. Can be called on any sequence; Write() and Stop() must be | 34 // Stop() call. Can be called on any sequence; Write() and Stop() must be |
26 // called on the same sequence as Start(). | 35 // called on the same sequence as Start(). |
27 virtual void Start(const base::FilePath& file) = 0; | 36 void Start(const base::FilePath& file); |
28 | 37 |
29 // Must be called to finish recording. Each call to Start() requires a call to | 38 // Must be called to finish recording. Each call to Start() requires a call to |
30 // Stop(). Will be automatically called on destruction. | 39 // Stop(). Will be automatically called on destruction. |
31 virtual void Stop() = 0; | 40 void Stop(); |
32 | 41 |
33 // Write |data| to file. | 42 // Write |data| to file. |
34 virtual void Write(std::unique_ptr<AudioBus> data) = 0; | 43 void Write(std::unique_ptr<AudioBus> data); |
35 | 44 |
36 // Returns true if Write() call scheduled at this point will most likely write | 45 // Returns true if Write() call scheduled at this point will most likely write |
37 // data to the file, and false if it most likely will be a no-op. The result | 46 // data to the file, and false if it most likely will be a no-op. The result |
38 // may be ambigulous if Start() or Stop() is executed at the moment. Can be | 47 // may be ambigulous if Start() or Stop() is executed at the moment. Can be |
39 // called from any sequence. | 48 // called from any sequence. |
40 virtual bool WillWrite() = 0; | 49 bool WillWrite(); |
| 50 |
| 51 private: |
| 52 class AudioFileWriter; |
| 53 |
| 54 // Deleter for AudioFileWriter. |
| 55 struct OnThreadDeleter { |
| 56 public: |
| 57 OnThreadDeleter(); |
| 58 OnThreadDeleter(const OnThreadDeleter& other); |
| 59 OnThreadDeleter(scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 60 ~OnThreadDeleter(); |
| 61 void operator()(AudioFileWriter* ptr) const; |
| 62 |
| 63 private: |
| 64 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 65 }; |
| 66 |
| 67 using AudioFileWriterUniquePtr = |
| 68 std::unique_ptr<AudioFileWriter, OnThreadDeleter>; |
| 69 |
| 70 AudioFileWriterUniquePtr file_writer_; |
| 71 const AudioParameters params_; |
| 72 base::SequenceChecker client_sequence_checker_; |
| 73 |
| 74 // The task runner to do file output operations on. |
| 75 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(AudioDebugFileWriter); |
41 }; | 78 }; |
42 | 79 |
43 } // namespace media | 80 } // namspace media |
44 | 81 |
45 #endif // MEDIA_AUDIO_AUDIO_FILE_WRITER_H_ | 82 #endif // MEDIA_AUDIO_AUDIO_DEBUG_FILE_WRITER_H_ |
OLD | NEW |