OLD | NEW |
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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 size_t samples_per_10ms = | 246 size_t samples_per_10ms = |
247 ((_wavFormatObj.formatTag == kWavFormatPcm) && | 247 ((_wavFormatObj.formatTag == kWavFormatPcm) && |
248 (_wavFormatObj.nSamplesPerSec == 44100)) ? | 248 (_wavFormatObj.nSamplesPerSec == 44100)) ? |
249 440 : static_cast<size_t>(_wavFormatObj.nSamplesPerSec / 100); | 249 440 : static_cast<size_t>(_wavFormatObj.nSamplesPerSec / 100); |
250 _readSizeBytes = samples_per_10ms * _wavFormatObj.nChannels * | 250 _readSizeBytes = samples_per_10ms * _wavFormatObj.nChannels * |
251 (_wavFormatObj.nBitsPerSample / 8); | 251 (_wavFormatObj.nBitsPerSample / 8); |
252 return 0; | 252 return 0; |
253 } | 253 } |
254 | 254 |
255 int32_t ModuleFileUtility::InitWavCodec(uint32_t samplesPerSec, | 255 int32_t ModuleFileUtility::InitWavCodec(uint32_t samplesPerSec, |
256 uint32_t channels, | 256 size_t channels, |
257 uint32_t bitsPerSample, | 257 uint32_t bitsPerSample, |
258 uint32_t formatTag) | 258 uint32_t formatTag) |
259 { | 259 { |
260 codec_info_.pltype = -1; | 260 codec_info_.pltype = -1; |
261 codec_info_.plfreq = samplesPerSec; | 261 codec_info_.plfreq = samplesPerSec; |
262 codec_info_.channels = channels; | 262 codec_info_.channels = channels; |
263 codec_info_.rate = bitsPerSample * samplesPerSec; | 263 codec_info_.rate = bitsPerSample * samplesPerSec; |
264 | 264 |
265 // Calculate the packet size for 10ms frames | 265 // Calculate the packet size for 10ms frames |
266 switch(formatTag) | 266 switch(formatTag) |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 const CodecInst& codecInst) | 656 const CodecInst& codecInst) |
657 { | 657 { |
658 | 658 |
659 if(set_codec_info(codecInst) != 0) | 659 if(set_codec_info(codecInst) != 0) |
660 { | 660 { |
661 WEBRTC_TRACE(kTraceError, kTraceFile, _id, | 661 WEBRTC_TRACE(kTraceError, kTraceFile, _id, |
662 "codecInst identifies unsupported codec!"); | 662 "codecInst identifies unsupported codec!"); |
663 return -1; | 663 return -1; |
664 } | 664 } |
665 _writing = false; | 665 _writing = false; |
666 uint32_t channels = (codecInst.channels == 0) ? | 666 size_t channels = (codecInst.channels == 0) ? 1 : codecInst.channels; |
667 1 : codecInst.channels; | |
668 | 667 |
669 if(STR_CASE_CMP(codecInst.plname, "PCMU") == 0) | 668 if(STR_CASE_CMP(codecInst.plname, "PCMU") == 0) |
670 { | 669 { |
671 _bytesPerSample = 1; | 670 _bytesPerSample = 1; |
672 if(WriteWavHeader(wav, 8000, _bytesPerSample, channels, | 671 if(WriteWavHeader(wav, 8000, _bytesPerSample, channels, |
673 kWavFormatMuLaw, 0) == -1) | 672 kWavFormatMuLaw, 0) == -1) |
674 { | 673 { |
675 return -1; | 674 return -1; |
676 } | 675 } |
677 } | 676 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 } | 724 } |
726 _bytesWritten += dataLength; | 725 _bytesWritten += dataLength; |
727 return static_cast<int32_t>(dataLength); | 726 return static_cast<int32_t>(dataLength); |
728 } | 727 } |
729 | 728 |
730 | 729 |
731 int32_t ModuleFileUtility::WriteWavHeader( | 730 int32_t ModuleFileUtility::WriteWavHeader( |
732 OutStream& wav, | 731 OutStream& wav, |
733 uint32_t freq, | 732 uint32_t freq, |
734 size_t bytesPerSample, | 733 size_t bytesPerSample, |
735 uint32_t channels, | 734 size_t channels, |
736 uint32_t format, | 735 uint32_t format, |
737 size_t lengthInBytes) | 736 size_t lengthInBytes) |
738 { | 737 { |
739 // Frame size in bytes for 10 ms of audio. | 738 // Frame size in bytes for 10 ms of audio. |
740 // TODO (hellner): 44.1 kHz has 440 samples frame size. Doesn't seem to | 739 // TODO (hellner): 44.1 kHz has 440 samples frame size. Doesn't seem to |
741 // be taken into consideration here! | 740 // be taken into consideration here! |
742 const size_t frameSize = (freq / 100) * channels; | 741 const size_t frameSize = (freq / 100) * channels; |
743 | 742 |
744 // Calculate the number of full frames that the wave file contain. | 743 // Calculate the number of full frames that the wave file contain. |
745 const size_t dataLengthInBytes = frameSize * (lengthInBytes / frameSize); | 744 const size_t dataLengthInBytes = frameSize * (lengthInBytes / frameSize); |
746 | 745 |
747 uint8_t buf[kWavHeaderSize]; | 746 uint8_t buf[kWavHeaderSize]; |
748 webrtc::WriteWavHeader(buf, channels, freq, static_cast<WavFormat>(format), | 747 webrtc::WriteWavHeader(buf, channels, freq, static_cast<WavFormat>(format), |
749 bytesPerSample, dataLengthInBytes / bytesPerSample); | 748 bytesPerSample, dataLengthInBytes / bytesPerSample); |
750 wav.Write(buf, kWavHeaderSize); | 749 wav.Write(buf, kWavHeaderSize); |
751 return 0; | 750 return 0; |
752 } | 751 } |
753 | 752 |
754 int32_t ModuleFileUtility::UpdateWavHeader(OutStream& wav) | 753 int32_t ModuleFileUtility::UpdateWavHeader(OutStream& wav) |
755 { | 754 { |
756 int32_t res = -1; | 755 int32_t res = -1; |
757 if(wav.Rewind() == -1) | 756 if(wav.Rewind() == -1) |
758 { | 757 { |
759 return -1; | 758 return -1; |
760 } | 759 } |
761 uint32_t channels = (codec_info_.channels == 0) ? 1 : codec_info_.channels; | 760 size_t channels = (codec_info_.channels == 0) ? 1 : codec_info_.channels; |
762 | 761 |
763 if(STR_CASE_CMP(codec_info_.plname, "L16") == 0) | 762 if(STR_CASE_CMP(codec_info_.plname, "L16") == 0) |
764 { | 763 { |
765 res = WriteWavHeader(wav, codec_info_.plfreq, 2, channels, | 764 res = WriteWavHeader(wav, codec_info_.plfreq, 2, channels, |
766 kWavFormatPcm, _bytesWritten); | 765 kWavFormatPcm, _bytesWritten); |
767 } else if(STR_CASE_CMP(codec_info_.plname, "PCMU") == 0) { | 766 } else if(STR_CASE_CMP(codec_info_.plname, "PCMU") == 0) { |
768 res = WriteWavHeader(wav, 8000, 1, channels, kWavFormatMuLaw, | 767 res = WriteWavHeader(wav, 8000, 1, channels, kWavFormatMuLaw, |
769 _bytesWritten); | 768 _bytesWritten); |
770 } else if(STR_CASE_CMP(codec_info_.plname, "PCMA") == 0) { | 769 } else if(STR_CASE_CMP(codec_info_.plname, "PCMA") == 0) { |
771 res = WriteWavHeader(wav, 8000, 1, channels, kWavFormatALaw, | 770 res = WriteWavHeader(wav, 8000, 1, channels, kWavFormatALaw, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 const CodecInst& codecInst) | 853 const CodecInst& codecInst) |
855 { | 854 { |
856 | 855 |
857 if(set_codec_info(codecInst) != 0) | 856 if(set_codec_info(codecInst) != 0) |
858 { | 857 { |
859 WEBRTC_TRACE(kTraceError, kTraceFile, _id, "CodecInst not recognized!"); | 858 WEBRTC_TRACE(kTraceError, kTraceFile, _id, "CodecInst not recognized!"); |
860 return -1; | 859 return -1; |
861 } | 860 } |
862 _writing = true; | 861 _writing = true; |
863 _bytesWritten = 1; | 862 _bytesWritten = 1; |
864 out.Write(&_codecId, 1); | 863 out.Write(&_codecId, 1); |
865 return 0; | 864 return 0; |
866 } | 865 } |
867 | 866 |
868 int32_t ModuleFileUtility::WritePreEncodedData( | 867 int32_t ModuleFileUtility::WritePreEncodedData( |
869 OutStream& out, | 868 OutStream& out, |
870 const int8_t* buffer, | 869 const int8_t* buffer, |
871 const size_t dataLength) | 870 const size_t dataLength) |
872 { | 871 { |
873 WEBRTC_TRACE(kTraceStream, kTraceFile, _id, | 872 WEBRTC_TRACE(kTraceStream, kTraceFile, _id, |
874 "ModuleFileUtility::WritePreEncodedData(out= 0x%x, " | 873 "ModuleFileUtility::WritePreEncodedData(out= 0x%x, " |
875 "inData= 0x%x, dataLen= %" PRIuS ")", &out, buffer, | 874 "inData= 0x%x, dataLen= %" PRIuS ")", &out, buffer, |
876 dataLength); | 875 dataLength); |
877 | 876 |
878 if(buffer == NULL) | 877 if(buffer == NULL) |
879 { | 878 { |
880 WEBRTC_TRACE(kTraceError, kTraceFile, _id,"buffer NULL"); | 879 WEBRTC_TRACE(kTraceError, kTraceFile, _id,"buffer NULL"); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1003 { | 1002 { |
1004 WEBRTC_TRACE(kTraceError, kTraceFile, _id, "not currently reading!"); | 1003 WEBRTC_TRACE(kTraceError, kTraceFile, _id, "not currently reading!"); |
1005 return -1; | 1004 return -1; |
1006 } | 1005 } |
1007 | 1006 |
1008 #ifdef WEBRTC_CODEC_ILBC | 1007 #ifdef WEBRTC_CODEC_ILBC |
1009 if((_codecId == kCodecIlbc20Ms) || | 1008 if((_codecId == kCodecIlbc20Ms) || |
1010 (_codecId == kCodecIlbc30Ms)) | 1009 (_codecId == kCodecIlbc30Ms)) |
1011 { | 1010 { |
1012 size_t byteSize = 0; | 1011 size_t byteSize = 0; |
1013 if(_codecId == kCodecIlbc30Ms) | 1012 if(_codecId == kCodecIlbc30Ms) |
1014 { | 1013 { |
1015 byteSize = 50; | 1014 byteSize = 50; |
1016 } | 1015 } |
1017 if(_codecId == kCodecIlbc20Ms) | 1016 if(_codecId == kCodecIlbc20Ms) |
1018 { | 1017 { |
1019 byteSize = 38; | 1018 byteSize = 38; |
1020 } | 1019 } |
1021 if(bufferSize < byteSize) | 1020 if(bufferSize < byteSize) |
1022 { | 1021 { |
1023 WEBRTC_TRACE(kTraceError, kTraceFile, _id, | 1022 WEBRTC_TRACE(kTraceError, kTraceFile, _id, |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1551 } | 1550 } |
1552 | 1551 |
1553 uint32_t ModuleFileUtility::PlayoutPositionMs() | 1552 uint32_t ModuleFileUtility::PlayoutPositionMs() |
1554 { | 1553 { |
1555 WEBRTC_TRACE(kTraceStream, kTraceFile, _id, | 1554 WEBRTC_TRACE(kTraceStream, kTraceFile, _id, |
1556 "ModuleFileUtility::PlayoutPosition()"); | 1555 "ModuleFileUtility::PlayoutPosition()"); |
1557 | 1556 |
1558 return _reading ? _playoutPositionMs : 0; | 1557 return _reading ? _playoutPositionMs : 0; |
1559 } | 1558 } |
1560 } // namespace webrtc | 1559 } // namespace webrtc |
OLD | NEW |