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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 size_t samples_per_10ms = | 257 size_t samples_per_10ms = |
258 ((_wavFormatObj.formatTag == kWavFormatPcm) && | 258 ((_wavFormatObj.formatTag == kWavFormatPcm) && |
259 (_wavFormatObj.nSamplesPerSec == 44100)) ? | 259 (_wavFormatObj.nSamplesPerSec == 44100)) ? |
260 440 : static_cast<size_t>(_wavFormatObj.nSamplesPerSec / 100); | 260 440 : static_cast<size_t>(_wavFormatObj.nSamplesPerSec / 100); |
261 _readSizeBytes = samples_per_10ms * _wavFormatObj.nChannels * | 261 _readSizeBytes = samples_per_10ms * _wavFormatObj.nChannels * |
262 (_wavFormatObj.nBitsPerSample / 8); | 262 (_wavFormatObj.nBitsPerSample / 8); |
263 return 0; | 263 return 0; |
264 } | 264 } |
265 | 265 |
266 int32_t ModuleFileUtility::InitWavCodec(uint32_t samplesPerSec, | 266 int32_t ModuleFileUtility::InitWavCodec(uint32_t samplesPerSec, |
267 uint32_t channels, | 267 size_t channels, |
268 uint32_t bitsPerSample, | 268 uint32_t bitsPerSample, |
269 uint32_t formatTag) | 269 uint32_t formatTag) |
270 { | 270 { |
271 codec_info_.pltype = -1; | 271 codec_info_.pltype = -1; |
272 codec_info_.plfreq = samplesPerSec; | 272 codec_info_.plfreq = samplesPerSec; |
273 codec_info_.channels = channels; | 273 codec_info_.channels = channels; |
274 codec_info_.rate = bitsPerSample * samplesPerSec; | 274 codec_info_.rate = bitsPerSample * samplesPerSec; |
275 | 275 |
276 // Calculate the packet size for 10ms frames | 276 // Calculate the packet size for 10ms frames |
277 switch(formatTag) | 277 switch(formatTag) |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 const CodecInst& codecInst) | 667 const CodecInst& codecInst) |
668 { | 668 { |
669 | 669 |
670 if(set_codec_info(codecInst) != 0) | 670 if(set_codec_info(codecInst) != 0) |
671 { | 671 { |
672 WEBRTC_TRACE(kTraceError, kTraceFile, _id, | 672 WEBRTC_TRACE(kTraceError, kTraceFile, _id, |
673 "codecInst identifies unsupported codec!"); | 673 "codecInst identifies unsupported codec!"); |
674 return -1; | 674 return -1; |
675 } | 675 } |
676 _writing = false; | 676 _writing = false; |
677 uint32_t channels = (codecInst.channels == 0) ? | 677 size_t channels = (codecInst.channels == 0) ? 1 : codecInst.channels; |
678 1 : codecInst.channels; | |
679 | 678 |
680 if(STR_CASE_CMP(codecInst.plname, "PCMU") == 0) | 679 if(STR_CASE_CMP(codecInst.plname, "PCMU") == 0) |
681 { | 680 { |
682 _bytesPerSample = 1; | 681 _bytesPerSample = 1; |
683 if(WriteWavHeader(wav, 8000, _bytesPerSample, channels, | 682 if(WriteWavHeader(wav, 8000, _bytesPerSample, channels, |
684 kWavFormatMuLaw, 0) == -1) | 683 kWavFormatMuLaw, 0) == -1) |
685 { | 684 { |
686 return -1; | 685 return -1; |
687 } | 686 } |
688 } | 687 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 } | 735 } |
737 _bytesWritten += dataLength; | 736 _bytesWritten += dataLength; |
738 return static_cast<int32_t>(dataLength); | 737 return static_cast<int32_t>(dataLength); |
739 } | 738 } |
740 | 739 |
741 | 740 |
742 int32_t ModuleFileUtility::WriteWavHeader( | 741 int32_t ModuleFileUtility::WriteWavHeader( |
743 OutStream& wav, | 742 OutStream& wav, |
744 uint32_t freq, | 743 uint32_t freq, |
745 size_t bytesPerSample, | 744 size_t bytesPerSample, |
746 uint32_t channels, | 745 size_t channels, |
747 uint32_t format, | 746 uint32_t format, |
748 size_t lengthInBytes) | 747 size_t lengthInBytes) |
749 { | 748 { |
750 // Frame size in bytes for 10 ms of audio. | 749 // Frame size in bytes for 10 ms of audio. |
751 // TODO (hellner): 44.1 kHz has 440 samples frame size. Doesn't seem to | 750 // TODO (hellner): 44.1 kHz has 440 samples frame size. Doesn't seem to |
752 // be taken into consideration here! | 751 // be taken into consideration here! |
753 const size_t frameSize = (freq / 100) * channels; | 752 const size_t frameSize = (freq / 100) * channels; |
754 | 753 |
755 // Calculate the number of full frames that the wave file contain. | 754 // Calculate the number of full frames that the wave file contain. |
756 const size_t dataLengthInBytes = frameSize * (lengthInBytes / frameSize); | 755 const size_t dataLengthInBytes = frameSize * (lengthInBytes / frameSize); |
757 | 756 |
758 uint8_t buf[kWavHeaderSize]; | 757 uint8_t buf[kWavHeaderSize]; |
759 webrtc::WriteWavHeader(buf, channels, freq, static_cast<WavFormat>(format), | 758 webrtc::WriteWavHeader(buf, channels, freq, static_cast<WavFormat>(format), |
760 bytesPerSample, dataLengthInBytes / bytesPerSample); | 759 bytesPerSample, dataLengthInBytes / bytesPerSample); |
761 wav.Write(buf, kWavHeaderSize); | 760 wav.Write(buf, kWavHeaderSize); |
762 return 0; | 761 return 0; |
763 } | 762 } |
764 | 763 |
765 int32_t ModuleFileUtility::UpdateWavHeader(OutStream& wav) | 764 int32_t ModuleFileUtility::UpdateWavHeader(OutStream& wav) |
766 { | 765 { |
767 int32_t res = -1; | 766 int32_t res = -1; |
768 if(wav.Rewind() == -1) | 767 if(wav.Rewind() == -1) |
769 { | 768 { |
770 return -1; | 769 return -1; |
771 } | 770 } |
772 uint32_t channels = (codec_info_.channels == 0) ? 1 : codec_info_.channels; | 771 size_t channels = (codec_info_.channels == 0) ? 1 : codec_info_.channels; |
773 | 772 |
774 if(STR_CASE_CMP(codec_info_.plname, "L16") == 0) | 773 if(STR_CASE_CMP(codec_info_.plname, "L16") == 0) |
775 { | 774 { |
776 res = WriteWavHeader(wav, codec_info_.plfreq, 2, channels, | 775 res = WriteWavHeader(wav, codec_info_.plfreq, 2, channels, |
777 kWavFormatPcm, _bytesWritten); | 776 kWavFormatPcm, _bytesWritten); |
778 } else if(STR_CASE_CMP(codec_info_.plname, "PCMU") == 0) { | 777 } else if(STR_CASE_CMP(codec_info_.plname, "PCMU") == 0) { |
779 res = WriteWavHeader(wav, 8000, 1, channels, kWavFormatMuLaw, | 778 res = WriteWavHeader(wav, 8000, 1, channels, kWavFormatMuLaw, |
780 _bytesWritten); | 779 _bytesWritten); |
781 } else if(STR_CASE_CMP(codec_info_.plname, "PCMA") == 0) { | 780 } else if(STR_CASE_CMP(codec_info_.plname, "PCMA") == 0) { |
782 res = WriteWavHeader(wav, 8000, 1, channels, kWavFormatALaw, | 781 res = WriteWavHeader(wav, 8000, 1, channels, kWavFormatALaw, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 const CodecInst& codecInst) | 864 const CodecInst& codecInst) |
866 { | 865 { |
867 | 866 |
868 if(set_codec_info(codecInst) != 0) | 867 if(set_codec_info(codecInst) != 0) |
869 { | 868 { |
870 WEBRTC_TRACE(kTraceError, kTraceFile, _id, "CodecInst not recognized!"); | 869 WEBRTC_TRACE(kTraceError, kTraceFile, _id, "CodecInst not recognized!"); |
871 return -1; | 870 return -1; |
872 } | 871 } |
873 _writing = true; | 872 _writing = true; |
874 _bytesWritten = 1; | 873 _bytesWritten = 1; |
875 out.Write(&_codecId, 1); | 874 out.Write(&_codecId, 1); |
876 return 0; | 875 return 0; |
877 } | 876 } |
878 | 877 |
879 int32_t ModuleFileUtility::WritePreEncodedData( | 878 int32_t ModuleFileUtility::WritePreEncodedData( |
880 OutStream& out, | 879 OutStream& out, |
881 const int8_t* buffer, | 880 const int8_t* buffer, |
882 const size_t dataLength) | 881 const size_t dataLength) |
883 { | 882 { |
884 WEBRTC_TRACE(kTraceStream, kTraceFile, _id, | 883 WEBRTC_TRACE(kTraceStream, kTraceFile, _id, |
885 "ModuleFileUtility::WritePreEncodedData(out= 0x%x, " | 884 "ModuleFileUtility::WritePreEncodedData(out= 0x%x, " |
886 "inData= 0x%x, dataLen= %" PRIuS ")", &out, buffer, | 885 "inData= 0x%x, dataLen= %" PRIuS ")", &out, buffer, |
887 dataLength); | 886 dataLength); |
888 | 887 |
889 if(buffer == NULL) | 888 if(buffer == NULL) |
890 { | 889 { |
891 WEBRTC_TRACE(kTraceError, kTraceFile, _id,"buffer NULL"); | 890 WEBRTC_TRACE(kTraceError, kTraceFile, _id,"buffer NULL"); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1014 { | 1013 { |
1015 WEBRTC_TRACE(kTraceError, kTraceFile, _id, "not currently reading!"); | 1014 WEBRTC_TRACE(kTraceError, kTraceFile, _id, "not currently reading!"); |
1016 return -1; | 1015 return -1; |
1017 } | 1016 } |
1018 | 1017 |
1019 #ifdef WEBRTC_CODEC_ILBC | 1018 #ifdef WEBRTC_CODEC_ILBC |
1020 if((_codecId == kCodecIlbc20Ms) || | 1019 if((_codecId == kCodecIlbc20Ms) || |
1021 (_codecId == kCodecIlbc30Ms)) | 1020 (_codecId == kCodecIlbc30Ms)) |
1022 { | 1021 { |
1023 size_t byteSize = 0; | 1022 size_t byteSize = 0; |
1024 if(_codecId == kCodecIlbc30Ms) | 1023 if(_codecId == kCodecIlbc30Ms) |
1025 { | 1024 { |
1026 byteSize = 50; | 1025 byteSize = 50; |
1027 } | 1026 } |
1028 if(_codecId == kCodecIlbc20Ms) | 1027 if(_codecId == kCodecIlbc20Ms) |
1029 { | 1028 { |
1030 byteSize = 38; | 1029 byteSize = 38; |
1031 } | 1030 } |
1032 if(bufferSize < byteSize) | 1031 if(bufferSize < byteSize) |
1033 { | 1032 { |
1034 WEBRTC_TRACE(kTraceError, kTraceFile, _id, | 1033 WEBRTC_TRACE(kTraceError, kTraceFile, _id, |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1562 } | 1561 } |
1563 | 1562 |
1564 uint32_t ModuleFileUtility::PlayoutPositionMs() | 1563 uint32_t ModuleFileUtility::PlayoutPositionMs() |
1565 { | 1564 { |
1566 WEBRTC_TRACE(kTraceStream, kTraceFile, _id, | 1565 WEBRTC_TRACE(kTraceStream, kTraceFile, _id, |
1567 "ModuleFileUtility::PlayoutPosition()"); | 1566 "ModuleFileUtility::PlayoutPosition()"); |
1568 | 1567 |
1569 return _reading ? _playoutPositionMs : 0; | 1568 return _reading ? _playoutPositionMs : 0; |
1570 } | 1569 } |
1571 } // namespace webrtc | 1570 } // namespace webrtc |
OLD | NEW |