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

Side by Side Diff: webrtc/test/file_audio_device.h

Issue 2717623003: Add the ability to read/write to WAV files in FakeAudioDevice (Closed)
Patch Set: Created 3 years, 9 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
(Empty)
1 /*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10 #ifndef WEBRTC_TEST_FILE_AUDIO_DEVICE_H_
11 #define WEBRTC_TEST_FILE_AUDIO_DEVICE_H_
12
13 #include <memory>
14 #include <string>
15 #include <vector>
16
17 #include "webrtc/base/criticalsection.h"
18 #include "webrtc/base/event.h"
19 #include "webrtc/base/platform_thread.h"
20 #include "webrtc/common_audio/wav_file.h"
21 #include "webrtc/modules/audio_device/include/fake_audio_device.h"
22 #include "webrtc/typedefs.h"
23
24 namespace webrtc {
25
26 class EventTimerWrapper;
27
28 namespace test {
29
30 // FileAudioDevice implements an AudioDevice module that can act as a capturer
31 // (read audio from a WAV file and send it) or a renderer (receive audio and
32 // write it to a WAV file). It will use 10ms audio frames.
33 class FileAudioDevice : public FakeAudioDeviceModule {
kwiberg-webrtc 2017/02/28 13:43:47 final? Or do you anticipate subclasses?
oprypin_webrtc 2017/03/06 16:45:01 It's hard to predict what people might want to do.
34 public:
35 // Creates a new FileAudioDevice. When capturing or playing, 10 ms audio
36 // frames will be processed every 100ms / |speed|.
kwiberg-webrtc 2017/02/28 13:43:47 Umm... so a speed of 1 gives one frame every 100ms
oprypin_webrtc 2017/03/06 16:45:01 Again this is just something I copied from FakeAud
37 // |sampling_frequency_in_hz| can be 8, 16, 32, 44.1 or 48kHz.
kwiberg-webrtc 2017/02/28 13:43:47 For consistency with other audio code (and for bre
oprypin_webrtc 2017/03/06 16:45:01 Done.
38 FileAudioDevice(const std::string& filename,
39 float speed, int sampling_frequency_in_hz);
40 ~FileAudioDevice() override;
41
42 // Block until the input audio file ends.
kwiberg-webrtc 2017/02/28 13:43:47 Document the argument? And that it only works if y
oprypin_webrtc 2017/03/06 16:45:01 Named it `timeout_ms`. And this should stay in onl
43 bool WaitForFileEnd(int milliseconds = rtc::Event::kForever);
44
45 private:
46 int32_t Init() override;
47 int32_t RegisterAudioCallback(AudioTransport* callback) override;
48
49 // Start receiving audio data and writing it to the file.
50 int32_t StartPlayout() override;
51 int32_t StopPlayout() override;
52 // Start reading audio data from the file and sending it.
53 int32_t StartRecording() override;
54 int32_t StopRecording() override;
55
56 bool Playing() const override;
57 bool Recording() const override;
58
59 static bool Run(void* obj);
60 void ProcessAudio();
61
62 const std::string filename_;
63 const int sampling_frequency_in_hz_;
64 const size_t num_samples_per_frame_;
65 const float speed_;
66
67 rtc::CriticalSection lock_;
68 AudioTransport* audio_callback_ GUARDED_BY(lock_);
69 std::unique_ptr<WavReader> wav_reader_ GUARDED_BY(lock_);
70 std::unique_ptr<WavWriter> wav_writer_ GUARDED_BY(lock_);
71
72 std::vector<int16_t> playout_buffer_ GUARDED_BY(lock_);
kwiberg-webrtc 2017/02/28 13:43:47 Good use of const and GUARDED_BY!
oprypin_webrtc 2017/03/06 16:45:01 Not sure what you mean.
73
74 std::unique_ptr<EventTimerWrapper> tick_;
75 rtc::PlatformThread thread_;
76 rtc::Event done_reading_;
kwiberg-webrtc 2017/02/28 13:43:47 Document what this one does?
oprypin_webrtc 2017/03/06 16:45:01 Done.
77 };
78 } // namespace test
79 } // namespace webrtc
80
81 #endif // WEBRTC_TEST_FILE_AUDIO_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698