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

Side by Side Diff: webrtc/voice_engine/file_player_unittests.cc

Issue 2245153002: Revert of Move FilePlayer and FileRecorder to Voice Engine (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 4 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
« no previous file with comments | « webrtc/voice_engine/file_player_impl.cc ('k') | webrtc/voice_engine/file_recorder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2014 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
11 // Unit tests for FilePlayer.
12
13 #include <stdio.h>
14 #include <string>
15
16 #include "gflags/gflags.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "webrtc/base/md5digest.h"
19 #include "webrtc/base/stringencode.h"
20 #include "webrtc/test/testsupport/fileutils.h"
21 #include "webrtc/voice_engine/file_player.h"
22
23 DEFINE_bool(file_player_output, false, "Generate reference files.");
24
25 namespace webrtc {
26
27 class FilePlayerTest : public ::testing::Test {
28 protected:
29 static const uint32_t kId = 0;
30 static const FileFormats kFileFormat = kFileFormatWavFile;
31 static const int kSampleRateHz = 8000;
32
33 FilePlayerTest()
34 : player_(FilePlayer::CreateFilePlayer(kId, kFileFormat)),
35 output_file_(NULL) {}
36
37 void SetUp() override {
38 if (FLAGS_file_player_output) {
39 std::string output_file =
40 webrtc::test::OutputPath() + "file_player_unittest_out.pcm";
41 output_file_ = fopen(output_file.c_str(), "wb");
42 ASSERT_TRUE(output_file_ != NULL);
43 }
44 }
45
46 void TearDown() override {
47 if (output_file_)
48 fclose(output_file_);
49 }
50
51 ~FilePlayerTest() { FilePlayer::DestroyFilePlayer(player_); }
52
53 void PlayFileAndCheck(const std::string& input_file,
54 const std::string& ref_checksum,
55 int output_length_ms) {
56 const float kScaling = 1;
57 ASSERT_EQ(0,
58 player_->StartPlayingFile(
59 input_file.c_str(), false, 0, kScaling, 0, 0, NULL));
60 rtc::Md5Digest checksum;
61 for (int i = 0; i < output_length_ms / 10; ++i) {
62 int16_t out[10 * kSampleRateHz / 1000] = {0};
63 size_t num_samples;
64 EXPECT_EQ(0,
65 player_->Get10msAudioFromFile(out, num_samples, kSampleRateHz));
66 checksum.Update(out, num_samples * sizeof(out[0]));
67 if (FLAGS_file_player_output) {
68 ASSERT_EQ(num_samples,
69 fwrite(out, sizeof(out[0]), num_samples, output_file_));
70 }
71 }
72 char checksum_result[rtc::Md5Digest::kSize];
73 EXPECT_EQ(rtc::Md5Digest::kSize,
74 checksum.Finish(checksum_result, rtc::Md5Digest::kSize));
75 EXPECT_EQ(ref_checksum,
76 rtc::hex_encode(checksum_result, sizeof(checksum_result)));
77 }
78
79 FilePlayer* player_;
80 FILE* output_file_;
81 };
82
83 #if defined(WEBRTC_IOS)
84 #define MAYBE_PlayWavPcmuFile DISABLED_PlayWavPcmuFile
85 #else
86 #define MAYBE_PlayWavPcmuFile PlayWavPcmuFile
87 #endif
88 TEST_F(FilePlayerTest, MAYBE_PlayWavPcmuFile) {
89 const std::string kFileName =
90 test::ResourcePath("utility/encapsulated_pcmu_8khz", "wav");
91 // The file is longer than this, but keeping the output shorter limits the
92 // runtime for the test.
93 const int kOutputLengthMs = 10000;
94 const std::string kRefChecksum = "c74e7fd432d439b1311e1c16815b3e9a";
95
96 PlayFileAndCheck(kFileName, kRefChecksum, kOutputLengthMs);
97 }
98
99 #if defined(WEBRTC_IOS)
100 #define MAYBE_PlayWavPcm16File DISABLED_PlayWavPcm16File
101 #else
102 #define MAYBE_PlayWavPcm16File PlayWavPcm16File
103 #endif
104 TEST_F(FilePlayerTest, MAYBE_PlayWavPcm16File) {
105 const std::string kFileName =
106 test::ResourcePath("utility/encapsulated_pcm16b_8khz", "wav");
107 // The file is longer than this, but keeping the output shorter limits the
108 // runtime for the test.
109 const int kOutputLengthMs = 10000;
110 const std::string kRefChecksum = "e41d7e1dac8aeae9f21e8e03cd7ecd71";
111
112 PlayFileAndCheck(kFileName, kRefChecksum, kOutputLengthMs);
113 }
114
115 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/voice_engine/file_player_impl.cc ('k') | webrtc/voice_engine/file_recorder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698