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

Side by Side Diff: webrtc/modules/audio_coding/test/PCMFile.cc

Issue 2685783014: Replace NULL with nullptr in all C++ files. (Closed)
Patch Set: Fixing android. Created 3 years, 10 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
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/modules/audio_coding/test/PCMFile.h" 11 #include "webrtc/modules/audio_coding/test/PCMFile.h"
12 12
13 #include <ctype.h> 13 #include <ctype.h>
14 #include <stdio.h> 14 #include <stdio.h>
15 #include <string.h> 15 #include <string.h>
16 16
17 #include "webrtc/modules/include/module_common_types.h" 17 #include "webrtc/modules/include/module_common_types.h"
18 #include "webrtc/test/gtest.h" 18 #include "webrtc/test/gtest.h"
19 19
20 namespace webrtc { 20 namespace webrtc {
21 21
22 #define MAX_FILE_NAME_LENGTH_BYTE 500 22 #define MAX_FILE_NAME_LENGTH_BYTE 500
23 23
24 PCMFile::PCMFile() 24 PCMFile::PCMFile()
25 : pcm_file_(NULL), 25 : pcm_file_(nullptr),
26 samples_10ms_(160), 26 samples_10ms_(160),
27 frequency_(16000), 27 frequency_(16000),
28 end_of_file_(false), 28 end_of_file_(false),
29 auto_rewind_(false), 29 auto_rewind_(false),
30 rewinded_(false), 30 rewinded_(false),
31 read_stereo_(false), 31 read_stereo_(false),
32 save_stereo_(false) { 32 save_stereo_(false) {
33 timestamp_ = (((uint32_t) rand() & 0x0000FFFF) << 16) | 33 timestamp_ = (((uint32_t) rand() & 0x0000FFFF) << 16) |
34 ((uint32_t) rand() & 0x0000FFFF); 34 ((uint32_t) rand() & 0x0000FFFF);
35 } 35 }
36 36
37 PCMFile::PCMFile(uint32_t timestamp) 37 PCMFile::PCMFile(uint32_t timestamp)
38 : pcm_file_(NULL), 38 : pcm_file_(nullptr),
39 samples_10ms_(160), 39 samples_10ms_(160),
40 frequency_(16000), 40 frequency_(16000),
41 end_of_file_(false), 41 end_of_file_(false),
42 auto_rewind_(false), 42 auto_rewind_(false),
43 rewinded_(false), 43 rewinded_(false),
44 read_stereo_(false), 44 read_stereo_(false),
45 save_stereo_(false) { 45 save_stereo_(false) {
46 timestamp_ = timestamp; 46 timestamp_ = timestamp;
47 } 47 }
48 48
49 PCMFile::~PCMFile() { 49 PCMFile::~PCMFile() {
50 if (pcm_file_) { 50 if (pcm_file_) {
51 fclose(pcm_file_); 51 fclose(pcm_file_);
52 } 52 }
53 } 53 }
54 54
55 int16_t PCMFile::ChooseFile(std::string* file_name, int16_t max_len, 55 int16_t PCMFile::ChooseFile(std::string* file_name, int16_t max_len,
56 uint16_t* frequency_hz) { 56 uint16_t* frequency_hz) {
57 char tmp_name[MAX_FILE_NAME_LENGTH_BYTE]; 57 char tmp_name[MAX_FILE_NAME_LENGTH_BYTE];
58 58
59 EXPECT_TRUE(fgets(tmp_name, MAX_FILE_NAME_LENGTH_BYTE, stdin) != NULL); 59 EXPECT_TRUE(fgets(tmp_name, MAX_FILE_NAME_LENGTH_BYTE, stdin) != nullptr);
60 tmp_name[MAX_FILE_NAME_LENGTH_BYTE - 1] = '\0'; 60 tmp_name[MAX_FILE_NAME_LENGTH_BYTE - 1] = '\0';
61 int16_t n = 0; 61 int16_t n = 0;
62 62
63 // Removing trailing spaces. 63 // Removing trailing spaces.
64 while ((isspace(tmp_name[n]) || iscntrl(tmp_name[n])) && (tmp_name[n] != 0) 64 while ((isspace(tmp_name[n]) || iscntrl(tmp_name[n])) && (tmp_name[n] != 0)
65 && (n < MAX_FILE_NAME_LENGTH_BYTE)) { 65 && (n < MAX_FILE_NAME_LENGTH_BYTE)) {
66 n++; 66 n++;
67 } 67 }
68 if (n > 0) { 68 if (n > 0) {
69 memmove(tmp_name, &tmp_name[n], MAX_FILE_NAME_LENGTH_BYTE - n); 69 memmove(tmp_name, &tmp_name[n], MAX_FILE_NAME_LENGTH_BYTE - n);
(...skipping 13 matching lines...) Expand all
83 int16_t len = (int16_t) strlen(tmp_name); 83 int16_t len = (int16_t) strlen(tmp_name);
84 if (len > max_len) { 84 if (len > max_len) {
85 return -1; 85 return -1;
86 } 86 }
87 if (len > 0) { 87 if (len > 0) {
88 std::string tmp_string(tmp_name, len + 1); 88 std::string tmp_string(tmp_name, len + 1);
89 *file_name = tmp_string; 89 *file_name = tmp_string;
90 } 90 }
91 printf("Enter the sampling frequency (in Hz) of the above file [%u]: ", 91 printf("Enter the sampling frequency (in Hz) of the above file [%u]: ",
92 *frequency_hz); 92 *frequency_hz);
93 EXPECT_TRUE(fgets(tmp_name, 10, stdin) != NULL); 93 EXPECT_TRUE(fgets(tmp_name, 10, stdin) != nullptr);
94 uint16_t tmp_frequency = (uint16_t) atoi(tmp_name); 94 uint16_t tmp_frequency = (uint16_t) atoi(tmp_name);
95 if (tmp_frequency > 0) { 95 if (tmp_frequency > 0) {
96 *frequency_hz = tmp_frequency; 96 *frequency_hz = tmp_frequency;
97 } 97 }
98 return 0; 98 return 0;
99 } 99 }
100 100
101 void PCMFile::Open(const std::string& file_name, uint16_t frequency, 101 void PCMFile::Open(const std::string& file_name, uint16_t frequency,
102 const char* mode, bool auto_rewind) { 102 const char* mode, bool auto_rewind) {
103 if ((pcm_file_ = fopen(file_name.c_str(), mode)) == NULL) { 103 if ((pcm_file_ = fopen(file_name.c_str(), mode)) == nullptr) {
104 printf("Cannot open file %s.\n", file_name.c_str()); 104 printf("Cannot open file %s.\n", file_name.c_str());
105 ADD_FAILURE() << "Unable to read file"; 105 ADD_FAILURE() << "Unable to read file";
106 } 106 }
107 frequency_ = frequency; 107 frequency_ = frequency;
108 samples_10ms_ = (uint16_t)(frequency_ / 100); 108 samples_10ms_ = (uint16_t)(frequency_ / 100);
109 auto_rewind_ = auto_rewind; 109 auto_rewind_ = auto_rewind;
110 end_of_file_ = false; 110 end_of_file_ = false;
111 rewinded_ = false; 111 rewinded_ = false;
112 } 112 }
113 113
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 183
184 void PCMFile::Write10MsData(int16_t* playout_buffer, size_t length_smpls) { 184 void PCMFile::Write10MsData(int16_t* playout_buffer, size_t length_smpls) {
185 if (fwrite(playout_buffer, sizeof(uint16_t), length_smpls, pcm_file_) != 185 if (fwrite(playout_buffer, sizeof(uint16_t), length_smpls, pcm_file_) !=
186 length_smpls) { 186 length_smpls) {
187 return; 187 return;
188 } 188 }
189 } 189 }
190 190
191 void PCMFile::Close() { 191 void PCMFile::Close() {
192 fclose(pcm_file_); 192 fclose(pcm_file_);
193 pcm_file_ = NULL; 193 pcm_file_ = nullptr;
194 blocks_read_ = 0; 194 blocks_read_ = 0;
195 } 195 }
196 196
197 void PCMFile::FastForward(int num_10ms_blocks) { 197 void PCMFile::FastForward(int num_10ms_blocks) {
198 const int channels = read_stereo_ ? 2 : 1; 198 const int channels = read_stereo_ ? 2 : 1;
199 long num_bytes_to_move = 199 long num_bytes_to_move =
200 num_10ms_blocks * sizeof(int16_t) * samples_10ms_ * channels; 200 num_10ms_blocks * sizeof(int16_t) * samples_10ms_ * channels;
201 int error = fseek(pcm_file_, num_bytes_to_move, SEEK_CUR); 201 int error = fseek(pcm_file_, num_bytes_to_move, SEEK_CUR);
202 RTC_DCHECK_EQ(error, 0); 202 RTC_DCHECK_EQ(error, 0);
203 } 203 }
(...skipping 14 matching lines...) Expand all
218 218
219 void PCMFile::ReadStereo(bool is_stereo) { 219 void PCMFile::ReadStereo(bool is_stereo) {
220 read_stereo_ = is_stereo; 220 read_stereo_ = is_stereo;
221 } 221 }
222 222
223 void PCMFile::SetNum10MsBlocksToRead(int value) { 223 void PCMFile::SetNum10MsBlocksToRead(int value) {
224 num_10ms_blocks_to_read_ = rtc::Optional<int>(value); 224 num_10ms_blocks_to_read_ = rtc::Optional<int>(value);
225 } 225 }
226 226
227 } // namespace webrtc 227 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698