Chromium Code Reviews| 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 CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEBUG_WRITER_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEBUG_WRITER_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEBUG_WRITER_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEBUG_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/sequence_checker.h" |
| 15 #include "base/memory/weak_ptr.h" | |
| 16 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
| 17 #include "media/audio/audio_input_writer.h" | 16 #include "media/audio/audio_input_writer.h" |
| 18 #include "media/base/audio_parameters.h" | 17 #include "media/base/audio_parameters.h" |
| 19 | 18 |
| 20 namespace media { | 19 namespace media { |
| 21 | 20 |
| 22 class AudioBus; | 21 class AudioBus; |
| 23 class AudioBusRefCounted; | |
| 24 | 22 |
| 25 } // namespace media | 23 } // namespace media |
| 26 | 24 |
| 27 namespace content { | 25 namespace content { |
| 28 | 26 |
| 29 // Writes audio input data used for debugging purposes. Can be created on any | 27 // Writes audio input data used for debugging purposes. The only blocking |
| 30 // thread. Must be destroyed on the FILE thread. Write call can be made on any | 28 // operation is IsRecording(), with a very small scope (1 flag update). |
| 31 // thread. This object must be unregistered in Write caller before destroyed. | |
| 32 // When created, it takes ownership of |file|. | |
| 33 class CONTENT_EXPORT AudioInputDebugWriter | 29 class CONTENT_EXPORT AudioInputDebugWriter |
| 34 : public NON_EXPORTED_BASE(media::AudioInputWriter) { | 30 : public NON_EXPORTED_BASE(media::AudioInputWriter) { |
| 35 public: | 31 public: |
| 36 AudioInputDebugWriter(base::File file, const media::AudioParameters& params); | 32 explicit AudioInputDebugWriter(const media::AudioParameters& params); |
| 37 | |
| 38 ~AudioInputDebugWriter() override; | 33 ~AudioInputDebugWriter() override; |
| 39 | 34 |
| 40 // Write data from |data| to file. | 35 void Start(const base::FilePath& file) override; |
| 36 void Stop() override; | |
| 41 void Write(std::unique_ptr<media::AudioBus> data) override; | 37 void Write(std::unique_ptr<media::AudioBus> data) override; |
| 38 bool WillWrite() override; | |
|
Henrik Grunell
2016/10/11 13:07:24
Comment on this - not clear what it does.
o1ka
2016/10/11 14:04:37
See base class
Henrik Grunell
2016/10/13 07:26:11
Acknowledged.
| |
| 42 | 39 |
| 43 private: | 40 private: |
| 44 // Write data from |data| to file. Called on the FILE thread. | 41 class AudioFileWriter; |
| 45 void DoWrite(std::unique_ptr<media::AudioBus> data); | 42 std::unique_ptr<AudioFileWriter> file_writer_; |
| 46 | 43 const media::AudioParameters params_; |
| 47 // Write wave header to file. Called on the FILE thread twice: on construction | 44 base::SequenceChecker client_sequence_checker_; |
| 48 // of AudioInputDebugWriter size of the wave data is unknown, so the header is | |
| 49 // written with zero sizes; then on destruction it is re-written with the | |
| 50 // actual size info accumulated throughout the object lifetime. | |
| 51 void WriteHeader(); | |
| 52 | |
| 53 // The file to write to. | |
| 54 base::File file_; | |
| 55 | |
| 56 // Number of written samples. | |
| 57 uint64_t samples_; | |
| 58 | |
| 59 // Input audio parameters required to build wave header. | |
| 60 media::AudioParameters params_; | |
| 61 | |
| 62 // Intermediate buffer to be written to file. Interleaved 16 bit audio data. | |
| 63 std::unique_ptr<int16_t[]> interleaved_data_; | |
| 64 int interleaved_data_size_; | |
| 65 | |
| 66 base::WeakPtrFactory<AudioInputDebugWriter> weak_factory_; | |
| 67 }; | 45 }; |
| 68 | 46 |
| 69 } // namspace content | 47 } // namspace content |
| 70 | 48 |
| 71 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEBUG_WRITER_H_ | 49 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEBUG_WRITER_H_ |
| OLD | NEW |