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" |
| 16 #include "content/public/browser/browser_thread.h" | |
| 17 #include "media/audio/audio_input_writer.h" | 17 #include "media/audio/audio_input_writer.h" |
| 18 #include "media/base/audio_parameters.h" | 18 #include "media/base/audio_parameters.h" |
| 19 | 19 |
| 20 namespace media { | 20 namespace media { |
| 21 | 21 |
| 22 class AudioBus; | 22 class AudioBus; |
| 23 class AudioBusRefCounted; | |
| 24 | 23 |
| 25 } // namespace media | 24 } // namespace media |
| 26 | 25 |
| 27 namespace content { | 26 namespace content { |
| 28 | 27 |
| 29 // Writes audio input data used for debugging purposes. Can be created on any | 28 // Writes audio input data used for debugging purposes. All operations are |
| 30 // thread. Must be destroyed on the FILE thread. Write call can be made on any | 29 // non-blocking |
|
Henrik Grunell
2016/10/13 07:26:11
Nit: end sentence with .
| |
| 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 | 30 class CONTENT_EXPORT AudioInputDebugWriter |
| 34 : public NON_EXPORTED_BASE(media::AudioInputWriter) { | 31 : public NON_EXPORTED_BASE(media::AudioInputWriter) { |
| 35 public: | 32 public: |
| 36 AudioInputDebugWriter(base::File file, const media::AudioParameters& params); | 33 explicit AudioInputDebugWriter(const media::AudioParameters& params); |
| 37 | |
| 38 ~AudioInputDebugWriter() override; | 34 ~AudioInputDebugWriter() override; |
| 39 | 35 |
| 40 // Write data from |data| to file. | 36 void Start(const base::FilePath& file) override; |
| 37 void Stop() override; | |
| 41 void Write(std::unique_ptr<media::AudioBus> data) override; | 38 void Write(std::unique_ptr<media::AudioBus> data) override; |
| 39 bool WillWrite() override; | |
| 42 | 40 |
| 43 private: | 41 private: |
| 44 // Write data from |data| to file. Called on the FILE thread. | 42 class AudioFileWriter; |
| 45 void DoWrite(std::unique_ptr<media::AudioBus> data); | 43 using AudioFileWriterUniquePtr = |
| 46 | 44 std::unique_ptr<AudioFileWriter, BrowserThread::DeleteOnFileThread>; |
| 47 // Write wave header to file. Called on the FILE thread twice: on construction | 45 AudioFileWriterUniquePtr file_writer_; |
| 48 // of AudioInputDebugWriter size of the wave data is unknown, so the header is | 46 const media::AudioParameters params_; |
| 49 // written with zero sizes; then on destruction it is re-written with the | 47 base::SequenceChecker client_sequence_checker_; |
| 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 }; | 48 }; |
| 68 | 49 |
| 69 } // namspace content | 50 } // namspace content |
| 70 | 51 |
| 71 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEBUG_WRITER_H_ | 52 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEBUG_WRITER_H_ |
| OLD | NEW |