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

Side by Side Diff: webrtc/modules/audio_processing/utility/delay_estimator.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
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 // iii) With one exception, i.e., the histogram based algorithm can overrule 251 // iii) With one exception, i.e., the histogram based algorithm can overrule
252 // the instantaneous one if |is_histogram_valid| = 1 and the histogram 252 // the instantaneous one if |is_histogram_valid| = 1 and the histogram
253 // is significantly strong. 253 // is significantly strong.
254 is_robust |= is_histogram_valid && 254 is_robust |= is_histogram_valid &&
255 (self->histogram[candidate_delay] > self->last_delay_histogram); 255 (self->histogram[candidate_delay] > self->last_delay_histogram);
256 256
257 return is_robust; 257 return is_robust;
258 } 258 }
259 259
260 void WebRtc_FreeBinaryDelayEstimatorFarend(BinaryDelayEstimatorFarend* self) { 260 void WebRtc_FreeBinaryDelayEstimatorFarend(BinaryDelayEstimatorFarend* self) {
261 261 if (self == nullptr) {
262 if (self == NULL) {
263 return; 262 return;
264 } 263 }
265 264
266 free(self->binary_far_history); 265 free(self->binary_far_history);
267 self->binary_far_history = NULL; 266 self->binary_far_history = nullptr;
268 267
269 free(self->far_bit_counts); 268 free(self->far_bit_counts);
270 self->far_bit_counts = NULL; 269 self->far_bit_counts = nullptr;
271 270
272 free(self); 271 free(self);
273 } 272 }
274 273
275 BinaryDelayEstimatorFarend* WebRtc_CreateBinaryDelayEstimatorFarend( 274 BinaryDelayEstimatorFarend* WebRtc_CreateBinaryDelayEstimatorFarend(
276 int history_size) { 275 int history_size) {
277 BinaryDelayEstimatorFarend* self = NULL; 276 BinaryDelayEstimatorFarend* self = nullptr;
278 277
279 if (history_size > 1) { 278 if (history_size > 1) {
280 // Sanity conditions fulfilled. 279 // Sanity conditions fulfilled.
281 self = static_cast<BinaryDelayEstimatorFarend*>( 280 self = static_cast<BinaryDelayEstimatorFarend*>(
282 malloc(sizeof(BinaryDelayEstimatorFarend))); 281 malloc(sizeof(BinaryDelayEstimatorFarend)));
283 } 282 }
284 if (self == NULL) { 283 if (self == nullptr) {
285 return NULL; 284 return nullptr;
286 } 285 }
287 286
288 self->history_size = 0; 287 self->history_size = 0;
289 self->binary_far_history = NULL; 288 self->binary_far_history = nullptr;
290 self->far_bit_counts = NULL; 289 self->far_bit_counts = nullptr;
291 if (WebRtc_AllocateFarendBufferMemory(self, history_size) == 0) { 290 if (WebRtc_AllocateFarendBufferMemory(self, history_size) == 0) {
292 WebRtc_FreeBinaryDelayEstimatorFarend(self); 291 WebRtc_FreeBinaryDelayEstimatorFarend(self);
293 self = NULL; 292 self = nullptr;
294 } 293 }
295 return self; 294 return self;
296 } 295 }
297 296
298 int WebRtc_AllocateFarendBufferMemory(BinaryDelayEstimatorFarend* self, 297 int WebRtc_AllocateFarendBufferMemory(BinaryDelayEstimatorFarend* self,
299 int history_size) { 298 int history_size) {
300 RTC_DCHECK(self); 299 RTC_DCHECK(self);
301 // (Re-)Allocate memory for history buffers. 300 // (Re-)Allocate memory for history buffers.
302 self->binary_far_history = static_cast<uint32_t*>( 301 self->binary_far_history = static_cast<uint32_t*>(
303 realloc(self->binary_far_history, 302 realloc(self->binary_far_history,
304 history_size * sizeof(*self->binary_far_history))); 303 history_size * sizeof(*self->binary_far_history)));
305 self->far_bit_counts = static_cast<int*>( 304 self->far_bit_counts = static_cast<int*>(
306 realloc(self->far_bit_counts, 305 realloc(self->far_bit_counts,
307 history_size * sizeof(*self->far_bit_counts))); 306 history_size * sizeof(*self->far_bit_counts)));
308 if ((self->binary_far_history == NULL) || (self->far_bit_counts == NULL)) { 307 if ((self->binary_far_history == nullptr) ||
308 (self->far_bit_counts == nullptr)) {
309 history_size = 0; 309 history_size = 0;
310 } 310 }
311 // Fill with zeros if we have expanded the buffers. 311 // Fill with zeros if we have expanded the buffers.
312 if (history_size > self->history_size) { 312 if (history_size > self->history_size) {
313 int size_diff = history_size - self->history_size; 313 int size_diff = history_size - self->history_size;
314 memset(&self->binary_far_history[self->history_size], 314 memset(&self->binary_far_history[self->history_size],
315 0, 315 0,
316 sizeof(*self->binary_far_history) * size_diff); 316 sizeof(*self->binary_far_history) * size_diff);
317 memset(&self->far_bit_counts[self->history_size], 317 memset(&self->far_bit_counts[self->history_size],
318 0, 318 0,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 handle->binary_far_history[0] = binary_far_spectrum; 371 handle->binary_far_history[0] = binary_far_spectrum;
372 372
373 // Shift history of far-end binary spectrum bit counts and insert bit count 373 // Shift history of far-end binary spectrum bit counts and insert bit count
374 // of current |binary_far_spectrum|. 374 // of current |binary_far_spectrum|.
375 memmove(&(handle->far_bit_counts[1]), &(handle->far_bit_counts[0]), 375 memmove(&(handle->far_bit_counts[1]), &(handle->far_bit_counts[0]),
376 (handle->history_size - 1) * sizeof(int)); 376 (handle->history_size - 1) * sizeof(int));
377 handle->far_bit_counts[0] = BitCount(binary_far_spectrum); 377 handle->far_bit_counts[0] = BitCount(binary_far_spectrum);
378 } 378 }
379 379
380 void WebRtc_FreeBinaryDelayEstimator(BinaryDelayEstimator* self) { 380 void WebRtc_FreeBinaryDelayEstimator(BinaryDelayEstimator* self) {
381 381 if (self == nullptr) {
382 if (self == NULL) {
383 return; 382 return;
384 } 383 }
385 384
386 free(self->mean_bit_counts); 385 free(self->mean_bit_counts);
387 self->mean_bit_counts = NULL; 386 self->mean_bit_counts = nullptr;
388 387
389 free(self->bit_counts); 388 free(self->bit_counts);
390 self->bit_counts = NULL; 389 self->bit_counts = nullptr;
391 390
392 free(self->binary_near_history); 391 free(self->binary_near_history);
393 self->binary_near_history = NULL; 392 self->binary_near_history = nullptr;
394 393
395 free(self->histogram); 394 free(self->histogram);
396 self->histogram = NULL; 395 self->histogram = nullptr;
397 396
398 // BinaryDelayEstimator does not have ownership of |farend|, hence we do not 397 // BinaryDelayEstimator does not have ownership of |farend|, hence we do not
399 // free the memory here. That should be handled separately by the user. 398 // free the memory here. That should be handled separately by the user.
400 self->farend = NULL; 399 self->farend = nullptr;
401 400
402 free(self); 401 free(self);
403 } 402 }
404 403
405 BinaryDelayEstimator* WebRtc_CreateBinaryDelayEstimator( 404 BinaryDelayEstimator* WebRtc_CreateBinaryDelayEstimator(
406 BinaryDelayEstimatorFarend* farend, int max_lookahead) { 405 BinaryDelayEstimatorFarend* farend, int max_lookahead) {
407 BinaryDelayEstimator* self = NULL; 406 BinaryDelayEstimator* self = nullptr;
408 407
409 if ((farend != NULL) && (max_lookahead >= 0)) { 408 if ((farend != nullptr) && (max_lookahead >= 0)) {
410 // Sanity conditions fulfilled. 409 // Sanity conditions fulfilled.
411 self = static_cast<BinaryDelayEstimator*>( 410 self = static_cast<BinaryDelayEstimator*>(
412 malloc(sizeof(BinaryDelayEstimator))); 411 malloc(sizeof(BinaryDelayEstimator)));
413 } 412 }
414 if (self == NULL) { 413 if (self == nullptr) {
415 return NULL; 414 return nullptr;
416 } 415 }
417 416
418 self->farend = farend; 417 self->farend = farend;
419 self->near_history_size = max_lookahead + 1; 418 self->near_history_size = max_lookahead + 1;
420 self->history_size = 0; 419 self->history_size = 0;
421 self->robust_validation_enabled = 0; // Disabled by default. 420 self->robust_validation_enabled = 0; // Disabled by default.
422 self->allowed_offset = 0; 421 self->allowed_offset = 0;
423 422
424 self->lookahead = max_lookahead; 423 self->lookahead = max_lookahead;
425 424
426 // Allocate memory for spectrum and history buffers. 425 // Allocate memory for spectrum and history buffers.
427 self->mean_bit_counts = NULL; 426 self->mean_bit_counts = nullptr;
428 self->bit_counts = NULL; 427 self->bit_counts = nullptr;
429 self->histogram = NULL; 428 self->histogram = nullptr;
430 self->binary_near_history = static_cast<uint32_t*>( 429 self->binary_near_history = static_cast<uint32_t*>(
431 malloc((max_lookahead + 1) * sizeof(*self->binary_near_history))); 430 malloc((max_lookahead + 1) * sizeof(*self->binary_near_history)));
432 if (self->binary_near_history == NULL || 431 if (self->binary_near_history == nullptr ||
433 WebRtc_AllocateHistoryBufferMemory(self, farend->history_size) == 0) { 432 WebRtc_AllocateHistoryBufferMemory(self, farend->history_size) == 0) {
434 WebRtc_FreeBinaryDelayEstimator(self); 433 WebRtc_FreeBinaryDelayEstimator(self);
435 self = NULL; 434 self = nullptr;
436 } 435 }
437 436
438 return self; 437 return self;
439 } 438 }
440 439
441 int WebRtc_AllocateHistoryBufferMemory(BinaryDelayEstimator* self, 440 int WebRtc_AllocateHistoryBufferMemory(BinaryDelayEstimator* self,
442 int history_size) { 441 int history_size) {
443 BinaryDelayEstimatorFarend* far = self->farend; 442 BinaryDelayEstimatorFarend* far = self->farend;
444 // (Re-)Allocate memory for spectrum and history buffers. 443 // (Re-)Allocate memory for spectrum and history buffers.
445 if (history_size != far->history_size) { 444 if (history_size != far->history_size) {
446 // Only update far-end buffers if we need. 445 // Only update far-end buffers if we need.
447 history_size = WebRtc_AllocateFarendBufferMemory(far, history_size); 446 history_size = WebRtc_AllocateFarendBufferMemory(far, history_size);
448 } 447 }
449 // The extra array element in |mean_bit_counts| and |histogram| is a dummy 448 // The extra array element in |mean_bit_counts| and |histogram| is a dummy
450 // element only used while |last_delay| == -2, i.e., before we have a valid 449 // element only used while |last_delay| == -2, i.e., before we have a valid
451 // estimate. 450 // estimate.
452 self->mean_bit_counts = static_cast<int32_t*>( 451 self->mean_bit_counts = static_cast<int32_t*>(
453 realloc(self->mean_bit_counts, 452 realloc(self->mean_bit_counts,
454 (history_size + 1) * sizeof(*self->mean_bit_counts))); 453 (history_size + 1) * sizeof(*self->mean_bit_counts)));
455 self->bit_counts = static_cast<int32_t*>( 454 self->bit_counts = static_cast<int32_t*>(
456 realloc(self->bit_counts, history_size * sizeof(*self->bit_counts))); 455 realloc(self->bit_counts, history_size * sizeof(*self->bit_counts)));
457 self->histogram = static_cast<float*>( 456 self->histogram = static_cast<float*>(
458 realloc(self->histogram, (history_size + 1) * sizeof(*self->histogram))); 457 realloc(self->histogram, (history_size + 1) * sizeof(*self->histogram)));
459 458
460 if ((self->mean_bit_counts == NULL) || 459 if ((self->mean_bit_counts == nullptr) || (self->bit_counts == nullptr) ||
461 (self->bit_counts == NULL) || 460 (self->histogram == nullptr)) {
462 (self->histogram == NULL)) {
463 history_size = 0; 461 history_size = 0;
464 } 462 }
465 // Fill with zeros if we have expanded the buffers. 463 // Fill with zeros if we have expanded the buffers.
466 if (history_size > self->history_size) { 464 if (history_size > self->history_size) {
467 int size_diff = history_size - self->history_size; 465 int size_diff = history_size - self->history_size;
468 memset(&self->mean_bit_counts[self->history_size], 466 memset(&self->mean_bit_counts[self->history_size],
469 0, 467 0,
470 sizeof(*self->mean_bit_counts) * size_diff); 468 sizeof(*self->mean_bit_counts) * size_diff);
471 memset(&self->bit_counts[self->history_size], 469 memset(&self->bit_counts[self->history_size],
472 0, 470 0,
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 int32_t diff = new_value - *mean_value; 692 int32_t diff = new_value - *mean_value;
695 693
696 // mean_new = mean_value + ((new_value - mean_value) >> factor); 694 // mean_new = mean_value + ((new_value - mean_value) >> factor);
697 if (diff < 0) { 695 if (diff < 0) {
698 diff = -((-diff) >> factor); 696 diff = -((-diff) >> factor);
699 } else { 697 } else {
700 diff = (diff >> factor); 698 diff = (diff >> factor);
701 } 699 }
702 *mean_value += diff; 700 *mean_value += diff;
703 } 701 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698