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

Side by Side Diff: webrtc/modules/media_file/media_file_impl.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 13 matching lines...) Expand all
24 24
25 void MediaFile::DestroyMediaFile(MediaFile* module) 25 void MediaFile::DestroyMediaFile(MediaFile* module)
26 { 26 {
27 delete static_cast<MediaFileImpl*>(module); 27 delete static_cast<MediaFileImpl*>(module);
28 } 28 }
29 29
30 MediaFileImpl::MediaFileImpl(const int32_t id) 30 MediaFileImpl::MediaFileImpl(const int32_t id)
31 : _id(id), 31 : _id(id),
32 _crit(CriticalSectionWrapper::CreateCriticalSection()), 32 _crit(CriticalSectionWrapper::CreateCriticalSection()),
33 _callbackCrit(CriticalSectionWrapper::CreateCriticalSection()), 33 _callbackCrit(CriticalSectionWrapper::CreateCriticalSection()),
34 _ptrFileUtilityObj(NULL), 34 _ptrFileUtilityObj(nullptr),
35 codec_info_(), 35 codec_info_(),
36 _ptrInStream(NULL), 36 _ptrInStream(nullptr),
37 _ptrOutStream(NULL), 37 _ptrOutStream(nullptr),
38 _fileFormat((FileFormats)-1), 38 _fileFormat((FileFormats)-1),
39 _recordDurationMs(0), 39 _recordDurationMs(0),
40 _playoutPositionMs(0), 40 _playoutPositionMs(0),
41 _notificationMs(0), 41 _notificationMs(0),
42 _playingActive(false), 42 _playingActive(false),
43 _recordingActive(false), 43 _recordingActive(false),
44 _isStereo(false), 44 _isStereo(false),
45 _openFile(false), 45 _openFile(false),
46 _fileName(), 46 _fileName(),
47 _ptrCallback(NULL) 47 _ptrCallback(nullptr) {
48 { 48 WEBRTC_TRACE(kTraceMemory, kTraceFile, id, "Created");
49 WEBRTC_TRACE(kTraceMemory, kTraceFile, id, "Created");
50 49
51 codec_info_.plname[0] = '\0'; 50 codec_info_.plname[0] = '\0';
52 _fileName[0] = '\0'; 51 _fileName[0] = '\0';
53 } 52 }
54 53
55 54
56 MediaFileImpl::~MediaFileImpl() 55 MediaFileImpl::~MediaFileImpl()
57 { 56 {
58 WEBRTC_TRACE(kTraceMemory, kTraceFile, _id, "~MediaFileImpl()"); 57 WEBRTC_TRACE(kTraceMemory, kTraceFile, _id, "~MediaFileImpl()");
59 { 58 {
60 CriticalSectionScoped lock(_crit); 59 CriticalSectionScoped lock(_crit);
61 60
62 if(_playingActive) 61 if(_playingActive)
63 { 62 {
64 StopPlaying(); 63 StopPlaying();
65 } 64 }
66 65
67 if(_recordingActive) 66 if(_recordingActive)
68 { 67 {
69 StopRecording(); 68 StopRecording();
70 } 69 }
71 70
72 delete _ptrFileUtilityObj; 71 delete _ptrFileUtilityObj;
73 72
74 if(_openFile) 73 if(_openFile)
75 { 74 {
76 delete _ptrInStream; 75 delete _ptrInStream;
77 _ptrInStream = NULL; 76 _ptrInStream = nullptr;
78 delete _ptrOutStream; 77 delete _ptrOutStream;
79 _ptrOutStream = NULL; 78 _ptrOutStream = nullptr;
80 } 79 }
81 } 80 }
82 81
83 delete _crit; 82 delete _crit;
84 delete _callbackCrit; 83 delete _callbackCrit;
85 } 84 }
86 85
87 int64_t MediaFileImpl::TimeUntilNextProcess() 86 int64_t MediaFileImpl::TimeUntilNextProcess()
88 { 87 {
89 WEBRTC_TRACE( 88 WEBRTC_TRACE(
(...skipping 13 matching lines...) Expand all
103 int32_t MediaFileImpl::PlayoutAudioData(int8_t* buffer, 102 int32_t MediaFileImpl::PlayoutAudioData(int8_t* buffer,
104 size_t& dataLengthInBytes) 103 size_t& dataLengthInBytes)
105 { 104 {
106 WEBRTC_TRACE(kTraceStream, kTraceFile, _id, 105 WEBRTC_TRACE(kTraceStream, kTraceFile, _id,
107 "MediaFileImpl::PlayoutData(buffer= 0x%x, bufLen= %" PRIuS ")", 106 "MediaFileImpl::PlayoutData(buffer= 0x%x, bufLen= %" PRIuS ")",
108 buffer, dataLengthInBytes); 107 buffer, dataLengthInBytes);
109 108
110 const size_t bufferLengthInBytes = dataLengthInBytes; 109 const size_t bufferLengthInBytes = dataLengthInBytes;
111 dataLengthInBytes = 0; 110 dataLengthInBytes = 0;
112 111
113 if(buffer == NULL || bufferLengthInBytes == 0) 112 if (buffer == nullptr || bufferLengthInBytes == 0) {
114 { 113 WEBRTC_TRACE(kTraceError, kTraceFile, _id,
115 WEBRTC_TRACE(kTraceError, kTraceFile, _id, 114 "Buffer pointer or length is null!");
116 "Buffer pointer or length is NULL!"); 115 return -1;
117 return -1;
118 } 116 }
119 117
120 int32_t bytesRead = 0; 118 int32_t bytesRead = 0;
121 { 119 {
122 CriticalSectionScoped lock(_crit); 120 CriticalSectionScoped lock(_crit);
123 121
124 if(!_playingActive) 122 if(!_playingActive)
125 { 123 {
126 WEBRTC_TRACE(kTraceWarning, kTraceFile, _id, 124 WEBRTC_TRACE(kTraceWarning, kTraceFile, _id,
127 "Not currently playing!"); 125 "Not currently playing!");
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 WEBRTC_TRACE(kTraceStream, kTraceFile, _id, 233 WEBRTC_TRACE(kTraceStream, kTraceFile, _id,
236 "MediaFileImpl::PlayoutStereoData(Left = 0x%x, Right = 0x%x," 234 "MediaFileImpl::PlayoutStereoData(Left = 0x%x, Right = 0x%x,"
237 " Len= %" PRIuS ")", 235 " Len= %" PRIuS ")",
238 bufferLeft, 236 bufferLeft,
239 bufferRight, 237 bufferRight,
240 dataLengthInBytes); 238 dataLengthInBytes);
241 239
242 const size_t bufferLengthInBytes = dataLengthInBytes; 240 const size_t bufferLengthInBytes = dataLengthInBytes;
243 dataLengthInBytes = 0; 241 dataLengthInBytes = 0;
244 242
245 if(bufferLeft == NULL || bufferRight == NULL || bufferLengthInBytes == 0) 243 if (bufferLeft == nullptr || bufferRight == nullptr ||
246 { 244 bufferLengthInBytes == 0) {
247 WEBRTC_TRACE(kTraceError, kTraceFile, _id, 245 WEBRTC_TRACE(kTraceError, kTraceFile, _id,
248 "A buffer pointer or the length is NULL!"); 246 "A buffer pointer or the length is null!");
249 return -1; 247 return -1;
250 } 248 }
251 249
252 bool playEnded = false; 250 bool playEnded = false;
253 uint32_t callbackNotifyMs = 0; 251 uint32_t callbackNotifyMs = 0;
254 { 252 {
255 CriticalSectionScoped lock(_crit); 253 CriticalSectionScoped lock(_crit);
256 254
257 if(!_playingActive || !_isStereo) 255 if(!_playingActive || !_isStereo)
258 { 256 {
259 WEBRTC_TRACE(kTraceWarning, kTraceFile, _id, 257 WEBRTC_TRACE(kTraceWarning, kTraceFile, _id,
260 "Not currently playing stereo!"); 258 "Not currently playing stereo!");
261 return -1; 259 return -1;
262 } 260 }
263 261
264 if(!_ptrFileUtilityObj) 262 if(!_ptrFileUtilityObj)
265 { 263 {
266 WEBRTC_TRACE( 264 WEBRTC_TRACE(kTraceError, kTraceFile, _id,
267 kTraceError, 265 "Playing stereo, but the FileUtility objects is null!");
268 kTraceFile, 266 StopPlaying();
269 _id, 267 return -1;
270 "Playing stereo, but the FileUtility objects is NULL!");
271 StopPlaying();
272 return -1;
273 } 268 }
274 269
275 // Stereo playout only supported for WAV files. 270 // Stereo playout only supported for WAV files.
276 int32_t bytesRead = 0; 271 int32_t bytesRead = 0;
277 switch(_fileFormat) 272 switch(_fileFormat)
278 { 273 {
279 case kFileFormatWavFile: 274 case kFileFormatWavFile:
280 bytesRead = _ptrFileUtilityObj->ReadWavDataAsStereo( 275 bytesRead = _ptrFileUtilityObj->ReadWavDataAsStereo(
281 *_ptrInStream, 276 *_ptrInStream,
282 bufferLeft, 277 bufferLeft,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 WEBRTC_TRACE( 352 WEBRTC_TRACE(
358 kTraceError, 353 kTraceError,
359 kTraceFile, 354 kTraceFile,
360 _id, 355 _id,
361 "specified notification time is longer than amount of ms that will\ 356 "specified notification time is longer than amount of ms that will\
362 be played"); 357 be played");
363 return -1; 358 return -1;
364 } 359 }
365 360
366 FileWrapper* inputStream = FileWrapper::Create(); 361 FileWrapper* inputStream = FileWrapper::Create();
367 if(inputStream == NULL) 362 if (inputStream == nullptr) {
368 { 363 WEBRTC_TRACE(kTraceMemory, kTraceFile, _id,
369 WEBRTC_TRACE(kTraceMemory, kTraceFile, _id, 364 "Failed to allocate input stream for file %s", fileName);
370 "Failed to allocate input stream for file %s", fileName); 365 return -1;
371 return -1;
372 } 366 }
373 367
374 if (!inputStream->OpenFile(fileName, true)) { 368 if (!inputStream->OpenFile(fileName, true)) {
375 delete inputStream; 369 delete inputStream;
376 WEBRTC_TRACE(kTraceError, kTraceFile, _id, "Could not open input file %s", 370 WEBRTC_TRACE(kTraceError, kTraceFile, _id, "Could not open input file %s",
377 fileName); 371 fileName);
378 return -1; 372 return -1;
379 } 373 }
380 374
381 if(StartPlayingStream(*inputStream, loop, notificationTimeMs, 375 if(StartPlayingStream(*inputStream, loop, notificationTimeMs,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 { 423 {
430 WEBRTC_TRACE( 424 WEBRTC_TRACE(
431 kTraceError, 425 kTraceError,
432 kTraceFile, 426 kTraceFile,
433 _id, 427 _id,
434 "StartPlaying called, but already playing or recording file %s", 428 "StartPlaying called, but already playing or recording file %s",
435 (_fileName[0] == '\0') ? "(name not set)" : _fileName); 429 (_fileName[0] == '\0') ? "(name not set)" : _fileName);
436 return -1; 430 return -1;
437 } 431 }
438 432
439 if(_ptrFileUtilityObj != NULL) 433 if (_ptrFileUtilityObj != nullptr) {
440 { 434 WEBRTC_TRACE(kTraceError, kTraceFile, _id,
441 WEBRTC_TRACE(kTraceError, 435 "StartPlaying called, but FileUtilityObj already exists!");
442 kTraceFile, 436 StopPlaying();
443 _id, 437 return -1;
444 "StartPlaying called, but FileUtilityObj already exists!");
445 StopPlaying();
446 return -1;
447 } 438 }
448 439
449 _ptrFileUtilityObj = new ModuleFileUtility(_id); 440 _ptrFileUtilityObj = new ModuleFileUtility(_id);
450 if(_ptrFileUtilityObj == NULL) 441 if (_ptrFileUtilityObj == nullptr) {
451 { 442 WEBRTC_TRACE(kTraceMemory, kTraceFile, _id,
452 WEBRTC_TRACE(kTraceMemory, kTraceFile, _id, 443 "Failed to create FileUtilityObj!");
453 "Failed to create FileUtilityObj!"); 444 return -1;
454 return -1;
455 } 445 }
456 446
457 switch(format) 447 switch(format)
458 { 448 {
459 case kFileFormatWavFile: 449 case kFileFormatWavFile:
460 { 450 {
461 if(_ptrFileUtilityObj->InitWavReading(stream, startPointMs, 451 if(_ptrFileUtilityObj->InitWavReading(stream, startPointMs,
462 stopPointMs) == -1) 452 stopPointMs) == -1)
463 { 453 {
464 WEBRTC_TRACE(kTraceError, kTraceFile, _id, 454 WEBRTC_TRACE(kTraceError, kTraceFile, _id,
(...skipping 15 matching lines...) Expand all
480 return -1; 470 return -1;
481 } 471 }
482 _fileFormat = kFileFormatCompressedFile; 472 _fileFormat = kFileFormatCompressedFile;
483 break; 473 break;
484 } 474 }
485 case kFileFormatPcm8kHzFile: 475 case kFileFormatPcm8kHzFile:
486 case kFileFormatPcm16kHzFile: 476 case kFileFormatPcm16kHzFile:
487 case kFileFormatPcm32kHzFile: 477 case kFileFormatPcm32kHzFile:
488 { 478 {
489 // ValidFileFormat() called in the beginneing of this function 479 // ValidFileFormat() called in the beginneing of this function
490 // prevents codecInst from being NULL here. 480 // prevents codecInst from being null here.
491 assert(codecInst != NULL); 481 assert(codecInst != nullptr);
492 if(!ValidFrequency(codecInst->plfreq) || 482 if(!ValidFrequency(codecInst->plfreq) ||
493 _ptrFileUtilityObj->InitPCMReading(stream, startPointMs, 483 _ptrFileUtilityObj->InitPCMReading(stream, startPointMs,
494 stopPointMs, 484 stopPointMs,
495 codecInst->plfreq) == -1) 485 codecInst->plfreq) == -1)
496 { 486 {
497 WEBRTC_TRACE(kTraceError, kTraceFile, _id, 487 WEBRTC_TRACE(kTraceError, kTraceFile, _id,
498 "Not a valid raw 8 or 16 KHz PCM file!"); 488 "Not a valid raw 8 or 16 KHz PCM file!");
499 StopPlaying(); 489 StopPlaying();
500 return -1; 490 return -1;
501 } 491 }
502 492
503 _fileFormat = format; 493 _fileFormat = format;
504 break; 494 break;
505 } 495 }
506 case kFileFormatPreencodedFile: 496 case kFileFormatPreencodedFile:
507 { 497 {
508 // ValidFileFormat() called in the beginneing of this function 498 // ValidFileFormat() called in the beginneing of this function
509 // prevents codecInst from being NULL here. 499 // prevents codecInst from being null here.
510 assert(codecInst != NULL); 500 assert(codecInst != nullptr);
511 if(_ptrFileUtilityObj->InitPreEncodedReading(stream, *codecInst) == 501 if(_ptrFileUtilityObj->InitPreEncodedReading(stream, *codecInst) ==
512 -1) 502 -1)
513 { 503 {
514 WEBRTC_TRACE(kTraceError, kTraceFile, _id, 504 WEBRTC_TRACE(kTraceError, kTraceFile, _id,
515 "Not a valid PreEncoded file!"); 505 "Not a valid PreEncoded file!");
516 StopPlaying(); 506 StopPlaying();
517 return -1; 507 return -1;
518 } 508 }
519 509
520 _fileFormat = kFileFormatPreencodedFile; 510 _fileFormat = kFileFormatPreencodedFile;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 } 543 }
554 544
555 int32_t MediaFileImpl::StopPlaying() 545 int32_t MediaFileImpl::StopPlaying()
556 { 546 {
557 547
558 CriticalSectionScoped lock(_crit); 548 CriticalSectionScoped lock(_crit);
559 _isStereo = false; 549 _isStereo = false;
560 if(_ptrFileUtilityObj) 550 if(_ptrFileUtilityObj)
561 { 551 {
562 delete _ptrFileUtilityObj; 552 delete _ptrFileUtilityObj;
563 _ptrFileUtilityObj = NULL; 553 _ptrFileUtilityObj = nullptr;
564 } 554 }
565 if(_ptrInStream) 555 if(_ptrInStream)
566 { 556 {
567 // If MediaFileImpl opened the InStream it must be reclaimed here. 557 // If MediaFileImpl opened the InStream it must be reclaimed here.
568 if(_openFile) 558 if(_openFile)
569 { 559 {
570 delete _ptrInStream; 560 delete _ptrInStream;
571 _openFile = false; 561 _openFile = false;
572 } 562 }
573 _ptrInStream = NULL; 563 _ptrInStream = nullptr;
574 } 564 }
575 565
576 codec_info_.pltype = 0; 566 codec_info_.pltype = 0;
577 codec_info_.plname[0] = '\0'; 567 codec_info_.plname[0] = '\0';
578 568
579 if(!_playingActive) 569 if(!_playingActive)
580 { 570 {
581 WEBRTC_TRACE(kTraceWarning, kTraceFile, _id, 571 WEBRTC_TRACE(kTraceWarning, kTraceFile, _id,
582 "playing is not active!"); 572 "playing is not active!");
583 return -1; 573 return -1;
(...skipping 11 matching lines...) Expand all
595 } 585 }
596 586
597 int32_t MediaFileImpl::IncomingAudioData( 587 int32_t MediaFileImpl::IncomingAudioData(
598 const int8_t* buffer, 588 const int8_t* buffer,
599 const size_t bufferLengthInBytes) 589 const size_t bufferLengthInBytes)
600 { 590 {
601 WEBRTC_TRACE(kTraceStream, kTraceFile, _id, 591 WEBRTC_TRACE(kTraceStream, kTraceFile, _id,
602 "MediaFile::IncomingData(buffer= 0x%x, bufLen= %" PRIuS, 592 "MediaFile::IncomingData(buffer= 0x%x, bufLen= %" PRIuS,
603 buffer, bufferLengthInBytes); 593 buffer, bufferLengthInBytes);
604 594
605 if(buffer == NULL || bufferLengthInBytes == 0) 595 if (buffer == nullptr || bufferLengthInBytes == 0) {
606 { 596 WEBRTC_TRACE(kTraceError, kTraceFile, _id,
607 WEBRTC_TRACE(kTraceError, kTraceFile, _id, 597 "Buffer pointer or length is null!");
608 "Buffer pointer or length is NULL!"); 598 return -1;
609 return -1;
610 } 599 }
611 600
612 bool recordingEnded = false; 601 bool recordingEnded = false;
613 uint32_t callbackNotifyMs = 0; 602 uint32_t callbackNotifyMs = 0;
614 { 603 {
615 CriticalSectionScoped lock(_crit); 604 CriticalSectionScoped lock(_crit);
616 605
617 if(!_recordingActive) 606 if(!_recordingActive)
618 { 607 {
619 WEBRTC_TRACE(kTraceWarning, kTraceFile, _id, 608 WEBRTC_TRACE(kTraceWarning, kTraceFile, _id,
620 "Not currently recording!"); 609 "Not currently recording!");
621 return -1; 610 return -1;
622 } 611 }
623 if(_ptrOutStream == NULL) 612 if (_ptrOutStream == nullptr) {
624 { 613 WEBRTC_TRACE(kTraceError, kTraceFile, _id,
625 WEBRTC_TRACE(kTraceError, kTraceFile, _id, 614 "Recording is active, but output stream is null!");
626 "Recording is active, but output stream is NULL!"); 615 assert(false);
627 assert(false); 616 return -1;
628 return -1;
629 } 617 }
630 618
631 int32_t bytesWritten = 0; 619 int32_t bytesWritten = 0;
632 uint32_t samplesWritten = codec_info_.pacsize; 620 uint32_t samplesWritten = codec_info_.pacsize;
633 if(_ptrFileUtilityObj) 621 if(_ptrFileUtilityObj)
634 { 622 {
635 switch(_fileFormat) 623 switch(_fileFormat)
636 { 624 {
637 case kFileFormatPcm8kHzFile: 625 case kFileFormatPcm8kHzFile:
638 case kFileFormatPcm16kHzFile: 626 case kFileFormatPcm16kHzFile:
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 if(!ValidFileName(fileName)) 721 if(!ValidFileName(fileName))
734 { 722 {
735 return -1; 723 return -1;
736 } 724 }
737 if(!ValidFileFormat(format,&codecInst)) 725 if(!ValidFileFormat(format,&codecInst))
738 { 726 {
739 return -1; 727 return -1;
740 } 728 }
741 729
742 FileWrapper* outputStream = FileWrapper::Create(); 730 FileWrapper* outputStream = FileWrapper::Create();
743 if(outputStream == NULL) 731 if (outputStream == nullptr) {
744 { 732 WEBRTC_TRACE(kTraceMemory, kTraceFile, _id,
745 WEBRTC_TRACE(kTraceMemory, kTraceFile, _id, 733 "Failed to allocate memory for output stream");
746 "Failed to allocate memory for output stream"); 734 return -1;
747 return -1;
748 } 735 }
749 736
750 if (!outputStream->OpenFile(fileName, false)) { 737 if (!outputStream->OpenFile(fileName, false)) {
751 delete outputStream; 738 delete outputStream;
752 WEBRTC_TRACE(kTraceError, kTraceFile, _id, 739 WEBRTC_TRACE(kTraceError, kTraceFile, _id,
753 "Could not open output file '%s' for writing!", fileName); 740 "Could not open output file '%s' for writing!", fileName);
754 return -1; 741 return -1;
755 } 742 }
756 743
757 if(maxSizeBytes) 744 if(maxSizeBytes)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 { 778 {
792 WEBRTC_TRACE( 779 WEBRTC_TRACE(
793 kTraceError, 780 kTraceError,
794 kTraceFile, 781 kTraceFile,
795 _id, 782 _id,
796 "StartRecording called, but already recording or playing file %s!", 783 "StartRecording called, but already recording or playing file %s!",
797 _fileName); 784 _fileName);
798 return -1; 785 return -1;
799 } 786 }
800 787
801 if(_ptrFileUtilityObj != NULL) 788 if (_ptrFileUtilityObj != nullptr) {
802 { 789 WEBRTC_TRACE(kTraceError, kTraceFile, _id,
803 WEBRTC_TRACE( 790 "StartRecording called, but fileUtilityObj already exists!");
804 kTraceError, 791 StopRecording();
805 kTraceFile, 792 return -1;
806 _id,
807 "StartRecording called, but fileUtilityObj already exists!");
808 StopRecording();
809 return -1;
810 } 793 }
811 794
812 _ptrFileUtilityObj = new ModuleFileUtility(_id); 795 _ptrFileUtilityObj = new ModuleFileUtility(_id);
813 if(_ptrFileUtilityObj == NULL) 796 if (_ptrFileUtilityObj == nullptr) {
814 { 797 WEBRTC_TRACE(kTraceMemory, kTraceFile, _id,
815 WEBRTC_TRACE(kTraceMemory, kTraceFile, _id, 798 "Cannot allocate fileUtilityObj!");
816 "Cannot allocate fileUtilityObj!"); 799 return -1;
817 return -1;
818 } 800 }
819 801
820 CodecInst tmpAudioCodec; 802 CodecInst tmpAudioCodec;
821 memcpy(&tmpAudioCodec, &codecInst, sizeof(CodecInst)); 803 memcpy(&tmpAudioCodec, &codecInst, sizeof(CodecInst));
822 switch(format) 804 switch(format)
823 { 805 {
824 case kFileFormatWavFile: 806 case kFileFormatWavFile:
825 { 807 {
826 if(_ptrFileUtilityObj->InitWavWriting(stream, codecInst) == -1) 808 if(_ptrFileUtilityObj->InitWavWriting(stream, codecInst) == -1)
827 { 809 {
828 WEBRTC_TRACE(kTraceError, kTraceFile, _id, 810 WEBRTC_TRACE(kTraceError, kTraceFile, _id,
829 "Failed to initialize WAV file!"); 811 "Failed to initialize WAV file!");
830 delete _ptrFileUtilityObj; 812 delete _ptrFileUtilityObj;
831 _ptrFileUtilityObj = NULL; 813 _ptrFileUtilityObj = nullptr;
832 return -1; 814 return -1;
833 } 815 }
834 _fileFormat = kFileFormatWavFile; 816 _fileFormat = kFileFormatWavFile;
835 break; 817 break;
836 } 818 }
837 case kFileFormatCompressedFile: 819 case kFileFormatCompressedFile:
838 { 820 {
839 // Write compression codec name at beginning of file 821 // Write compression codec name at beginning of file
840 if(_ptrFileUtilityObj->InitCompressedWriting(stream, codecInst) == 822 if(_ptrFileUtilityObj->InitCompressedWriting(stream, codecInst) ==
841 -1) 823 -1)
842 { 824 {
843 WEBRTC_TRACE(kTraceError, kTraceFile, _id, 825 WEBRTC_TRACE(kTraceError, kTraceFile, _id,
844 "Failed to initialize Compressed file!"); 826 "Failed to initialize Compressed file!");
845 delete _ptrFileUtilityObj; 827 delete _ptrFileUtilityObj;
846 _ptrFileUtilityObj = NULL; 828 _ptrFileUtilityObj = nullptr;
847 return -1; 829 return -1;
848 } 830 }
849 _fileFormat = kFileFormatCompressedFile; 831 _fileFormat = kFileFormatCompressedFile;
850 break; 832 break;
851 } 833 }
852 case kFileFormatPcm8kHzFile: 834 case kFileFormatPcm8kHzFile:
853 case kFileFormatPcm16kHzFile: 835 case kFileFormatPcm16kHzFile:
854 { 836 {
855 if(!ValidFrequency(codecInst.plfreq) || 837 if(!ValidFrequency(codecInst.plfreq) ||
856 _ptrFileUtilityObj->InitPCMWriting(stream, codecInst.plfreq) == 838 _ptrFileUtilityObj->InitPCMWriting(stream, codecInst.plfreq) ==
857 -1) 839 -1)
858 { 840 {
859 WEBRTC_TRACE(kTraceError, kTraceFile, _id, 841 WEBRTC_TRACE(kTraceError, kTraceFile, _id,
860 "Failed to initialize 8 or 16KHz PCM file!"); 842 "Failed to initialize 8 or 16KHz PCM file!");
861 delete _ptrFileUtilityObj; 843 delete _ptrFileUtilityObj;
862 _ptrFileUtilityObj = NULL; 844 _ptrFileUtilityObj = nullptr;
863 return -1; 845 return -1;
864 } 846 }
865 _fileFormat = format; 847 _fileFormat = format;
866 break; 848 break;
867 } 849 }
868 case kFileFormatPreencodedFile: 850 case kFileFormatPreencodedFile:
869 { 851 {
870 if(_ptrFileUtilityObj->InitPreEncodedWriting(stream, codecInst) == 852 if(_ptrFileUtilityObj->InitPreEncodedWriting(stream, codecInst) ==
871 -1) 853 -1)
872 { 854 {
873 WEBRTC_TRACE(kTraceError, kTraceFile, _id, 855 WEBRTC_TRACE(kTraceError, kTraceFile, _id,
874 "Failed to initialize Pre-Encoded file!"); 856 "Failed to initialize Pre-Encoded file!");
875 delete _ptrFileUtilityObj; 857 delete _ptrFileUtilityObj;
876 _ptrFileUtilityObj = NULL; 858 _ptrFileUtilityObj = nullptr;
877 return -1; 859 return -1;
878 } 860 }
879 861
880 _fileFormat = kFileFormatPreencodedFile; 862 _fileFormat = kFileFormatPreencodedFile;
881 break; 863 break;
882 } 864 }
883 default: 865 default:
884 { 866 {
885 WEBRTC_TRACE(kTraceError, kTraceFile, _id, 867 WEBRTC_TRACE(kTraceError, kTraceFile, _id,
886 "Invalid file format %d specified!", format); 868 "Invalid file format %d specified!", format);
887 delete _ptrFileUtilityObj; 869 delete _ptrFileUtilityObj;
888 _ptrFileUtilityObj = NULL; 870 _ptrFileUtilityObj = nullptr;
889 return -1; 871 return -1;
890 } 872 }
891 } 873 }
892 _isStereo = (tmpAudioCodec.channels == 2); 874 _isStereo = (tmpAudioCodec.channels == 2);
893 if(_isStereo) 875 if(_isStereo)
894 { 876 {
895 if(_fileFormat != kFileFormatWavFile) 877 if(_fileFormat != kFileFormatWavFile)
896 { 878 {
897 WEBRTC_TRACE(kTraceWarning, kTraceFile, _id, 879 WEBRTC_TRACE(kTraceWarning, kTraceFile, _id,
898 "Stereo is only allowed for WAV files"); 880 "Stereo is only allowed for WAV files");
(...skipping 27 matching lines...) Expand all
926 CriticalSectionScoped lock(_crit); 908 CriticalSectionScoped lock(_crit);
927 if(!_recordingActive) 909 if(!_recordingActive)
928 { 910 {
929 WEBRTC_TRACE(kTraceWarning, kTraceFile, _id, 911 WEBRTC_TRACE(kTraceWarning, kTraceFile, _id,
930 "recording is not active!"); 912 "recording is not active!");
931 return -1; 913 return -1;
932 } 914 }
933 915
934 _isStereo = false; 916 _isStereo = false;
935 917
936 if(_ptrFileUtilityObj != NULL) 918 if (_ptrFileUtilityObj != nullptr) {
937 { 919 // Both AVI and WAV header has to be updated before closing the stream
938 // Both AVI and WAV header has to be updated before closing the stream 920 // because they contain size information.
939 // because they contain size information. 921 if ((_fileFormat == kFileFormatWavFile) && (_ptrOutStream != nullptr)) {
940 if((_fileFormat == kFileFormatWavFile) && 922 _ptrFileUtilityObj->UpdateWavHeader(*_ptrOutStream);
941 (_ptrOutStream != NULL)) 923 }
942 { 924 delete _ptrFileUtilityObj;
943 _ptrFileUtilityObj->UpdateWavHeader(*_ptrOutStream); 925 _ptrFileUtilityObj = nullptr;
944 }
945 delete _ptrFileUtilityObj;
946 _ptrFileUtilityObj = NULL;
947 } 926 }
948 927
949 if(_ptrOutStream != NULL) 928 if (_ptrOutStream != nullptr) {
950 { 929 // If MediaFileImpl opened the OutStream it must be reclaimed here.
951 // If MediaFileImpl opened the OutStream it must be reclaimed here. 930 if (_openFile) {
952 if(_openFile) 931 delete _ptrOutStream;
953 { 932 _openFile = false;
954 delete _ptrOutStream; 933 }
955 _openFile = false; 934 _ptrOutStream = nullptr;
956 }
957 _ptrOutStream = NULL;
958 } 935 }
959 936
960 _recordingActive = false; 937 _recordingActive = false;
961 codec_info_.pltype = 0; 938 codec_info_.pltype = 0;
962 codec_info_.plname[0] = '\0'; 939 codec_info_.plname[0] = '\0';
963 940
964 return 0; 941 return 0;
965 } 942 }
966 943
967 bool MediaFileImpl::IsRecording() 944 bool MediaFileImpl::IsRecording()
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 if(!ValidFileName(fileName)) 986 if(!ValidFileName(fileName))
1010 { 987 {
1011 return -1; 988 return -1;
1012 } 989 }
1013 if(!ValidFrequency(freqInHz)) 990 if(!ValidFrequency(freqInHz))
1014 { 991 {
1015 return -1; 992 return -1;
1016 } 993 }
1017 994
1018 ModuleFileUtility* utilityObj = new ModuleFileUtility(_id); 995 ModuleFileUtility* utilityObj = new ModuleFileUtility(_id);
1019 if(utilityObj == NULL) 996 if (utilityObj == nullptr) {
1020 { 997 WEBRTC_TRACE(kTraceError, kTraceFile, _id,
1021 WEBRTC_TRACE(kTraceError, kTraceFile, _id, 998 "failed to allocate utility object!");
1022 "failed to allocate utility object!"); 999 return -1;
1023 return -1;
1024 } 1000 }
1025 1001
1026 const int32_t duration = utilityObj->FileDurationMs(fileName, format, 1002 const int32_t duration = utilityObj->FileDurationMs(fileName, format,
1027 freqInHz); 1003 freqInHz);
1028 delete utilityObj; 1004 delete utilityObj;
1029 if(duration == -1) 1005 if(duration == -1)
1030 { 1006 {
1031 durationMs = 0; 1007 durationMs = 0;
1032 return -1; 1008 return -1;
1033 } 1009 }
(...skipping 30 matching lines...) Expand all
1064 _playingActive ? "Playback" : "Recording"); 1040 _playingActive ? "Playback" : "Recording");
1065 return -1; 1041 return -1;
1066 } 1042 }
1067 memcpy(&codecInst,&codec_info_,sizeof(CodecInst)); 1043 memcpy(&codecInst,&codec_info_,sizeof(CodecInst));
1068 return 0; 1044 return 0;
1069 } 1045 }
1070 1046
1071 bool MediaFileImpl::ValidFileFormat(const FileFormats format, 1047 bool MediaFileImpl::ValidFileFormat(const FileFormats format,
1072 const CodecInst* codecInst) 1048 const CodecInst* codecInst)
1073 { 1049 {
1074 if(codecInst == NULL) 1050 if (codecInst == nullptr) {
1075 { 1051 if (format == kFileFormatPreencodedFile ||
1076 if(format == kFileFormatPreencodedFile || 1052 format == kFileFormatPcm8kHzFile || format == kFileFormatPcm16kHzFile ||
1077 format == kFileFormatPcm8kHzFile || 1053 format == kFileFormatPcm32kHzFile) {
1078 format == kFileFormatPcm16kHzFile || 1054 WEBRTC_TRACE(kTraceError, kTraceFile, -1,
1079 format == kFileFormatPcm32kHzFile) 1055 "Codec info required for file format specified!");
1080 { 1056 return false;
1081 WEBRTC_TRACE(kTraceError, kTraceFile, -1, 1057 }
1082 "Codec info required for file format specified!");
1083 return false;
1084 }
1085 } 1058 }
1086 return true; 1059 return true;
1087 } 1060 }
1088 1061
1089 bool MediaFileImpl::ValidFileName(const char* fileName) 1062 bool MediaFileImpl::ValidFileName(const char* fileName)
1090 { 1063 {
1091 if((fileName == NULL) ||(fileName[0] == '\0')) 1064 if ((fileName == nullptr) || (fileName[0] == '\0')) {
1092 { 1065 WEBRTC_TRACE(kTraceError, kTraceFile, -1, "FileName not specified!");
1093 WEBRTC_TRACE(kTraceError, kTraceFile, -1, "FileName not specified!"); 1066 return false;
1094 return false;
1095 } 1067 }
1096 return true; 1068 return true;
1097 } 1069 }
1098 1070
1099 1071
1100 bool MediaFileImpl::ValidFilePositions(const uint32_t startPointMs, 1072 bool MediaFileImpl::ValidFilePositions(const uint32_t startPointMs,
1101 const uint32_t stopPointMs) 1073 const uint32_t stopPointMs)
1102 { 1074 {
1103 if(startPointMs == 0 && stopPointMs == 0) // Default values 1075 if(startPointMs == 0 && stopPointMs == 0) // Default values
1104 { 1076 {
(...skipping 18 matching lines...) Expand all
1123 { 1095 {
1124 if((frequency == 8000) || (frequency == 16000)|| (frequency == 32000)) 1096 if((frequency == 8000) || (frequency == 16000)|| (frequency == 32000))
1125 { 1097 {
1126 return true; 1098 return true;
1127 } 1099 }
1128 WEBRTC_TRACE(kTraceError, kTraceFile, -1, 1100 WEBRTC_TRACE(kTraceError, kTraceFile, -1,
1129 "Frequency should be 8000, 16000 or 32000 (Hz)"); 1101 "Frequency should be 8000, 16000 or 32000 (Hz)");
1130 return false; 1102 return false;
1131 } 1103 }
1132 } // namespace webrtc 1104 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698