OLD | NEW |
---|---|
1 /* | 1 /* |
hlundin-webrtc
2016/04/13 07:05:24
I'm truly sorry that you have to deal with this re
ossu
2016/04/13 11:57:07
Aww. It's alright. I've seen worse. :)
| |
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 // TODO(hlundin): Reformat file to meet style guide. | 11 // TODO(hlundin): Reformat file to meet style guide. |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
258 ISACFIX_MainStruct* ISAC_inst[2]; | 258 ISACFIX_MainStruct* ISAC_inst[2]; |
259 #endif | 259 #endif |
260 #ifdef CODEC_ISAC_SWB | 260 #ifdef CODEC_ISAC_SWB |
261 ISACStruct* ISACSWB_inst[2]; | 261 ISACStruct* ISACSWB_inst[2]; |
262 #endif | 262 #endif |
263 #ifdef CODEC_GSMFR | 263 #ifdef CODEC_GSMFR |
264 GSMFR_encinst_t* GSMFRenc_inst[2]; | 264 GSMFR_encinst_t* GSMFRenc_inst[2]; |
265 #endif | 265 #endif |
266 #if (defined(CODEC_CNGCODEC8) || defined(CODEC_CNGCODEC16) || \ | 266 #if (defined(CODEC_CNGCODEC8) || defined(CODEC_CNGCODEC16) || \ |
267 defined(CODEC_CNGCODEC32) || defined(CODEC_CNGCODEC48)) | 267 defined(CODEC_CNGCODEC32) || defined(CODEC_CNGCODEC48)) |
268 CNG_enc_inst* CNGenc_inst[2]; | 268 std::unique_ptr<webrtc::ComfortNoiseEncoder> CNG_encoder[2]; |
269 #endif | 269 #endif |
270 #ifdef CODEC_SPEEX_8 | 270 #ifdef CODEC_SPEEX_8 |
271 SPEEX_encinst_t* SPEEX8enc_inst[2]; | 271 SPEEX_encinst_t* SPEEX8enc_inst[2]; |
272 #endif | 272 #endif |
273 #ifdef CODEC_SPEEX_16 | 273 #ifdef CODEC_SPEEX_16 |
274 SPEEX_encinst_t* SPEEX16enc_inst[2]; | 274 SPEEX_encinst_t* SPEEX16enc_inst[2]; |
275 #endif | 275 #endif |
276 #ifdef CODEC_OPUS | 276 #ifdef CODEC_OPUS |
277 OpusEncInst* opus_inst[2]; | 277 OpusEncInst* opus_inst[2]; |
278 #endif | 278 #endif |
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
921 exit(0); | 921 exit(0); |
922 } | 922 } |
923 ok = WebRtcVad_Init(VAD_inst[k]); | 923 ok = WebRtcVad_Init(VAD_inst[k]); |
924 if (ok == -1) { | 924 if (ok == -1) { |
925 printf("Error: Initialization of VAD struct failed\n"); | 925 printf("Error: Initialization of VAD struct failed\n"); |
926 exit(0); | 926 exit(0); |
927 } | 927 } |
928 | 928 |
929 #if (defined(CODEC_CNGCODEC8) || defined(CODEC_CNGCODEC16) || \ | 929 #if (defined(CODEC_CNGCODEC8) || defined(CODEC_CNGCODEC16) || \ |
930 defined(CODEC_CNGCODEC32) || defined(CODEC_CNGCODEC48)) | 930 defined(CODEC_CNGCODEC32) || defined(CODEC_CNGCODEC48)) |
931 ok = WebRtcCng_CreateEnc(&CNGenc_inst[k]); | 931 // TODO(ossu): Why <= 16000? |
932 if (ok != 0) { | |
933 printf("Error: Couldn't allocate memory for CNG encoding instance\n"); | |
934 exit(0); | |
935 } | |
936 if (sampfreq <= 16000) { | 932 if (sampfreq <= 16000) { |
937 ok = WebRtcCng_InitEnc(CNGenc_inst[k], sampfreq, 200, 5); | 933 CNG_encoder[k].reset(new webrtc::ComfortNoiseEncoder(sampfreq, 200, 5)); |
kwiberg-webrtc
2016/04/12 13:35:31
The old code created but didn't initialize a CNG e
ossu
2016/04/12 13:54:50
I ... don't know. I put a TODO comment about that
hlundin-webrtc
2016/04/13 07:05:24
I think we've always said that we only support CNG
ossu
2016/04/13 11:57:07
Acknowledged.
| |
938 if (ok == -1) { | |
939 printf("Error: Initialization of CNG struct failed. Error code %d\n", | |
940 WebRtcCng_GetErrorCodeEnc(CNGenc_inst[k])); | |
941 exit(0); | |
942 } | |
943 } | 934 } |
944 #endif | 935 #endif |
945 | 936 |
946 switch (coder) { | 937 switch (coder) { |
947 #ifdef CODEC_PCM16B | 938 #ifdef CODEC_PCM16B |
948 case webrtc::NetEqDecoder::kDecoderPCM16B: | 939 case webrtc::NetEqDecoder::kDecoderPCM16B: |
949 #endif | 940 #endif |
950 #ifdef CODEC_PCM16B_WB | 941 #ifdef CODEC_PCM16B_WB |
951 case webrtc::NetEqDecoder::kDecoderPCM16Bwb: | 942 case webrtc::NetEqDecoder::kDecoderPCM16Bwb: |
952 #endif | 943 #endif |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1454 } // end for | 1445 } // end for |
1455 | 1446 |
1456 return (0); | 1447 return (0); |
1457 } | 1448 } |
1458 | 1449 |
1459 int NetEQTest_free_coders(webrtc::NetEqDecoder coder, size_t numChannels) { | 1450 int NetEQTest_free_coders(webrtc::NetEqDecoder coder, size_t numChannels) { |
1460 for (size_t k = 0; k < numChannels; k++) { | 1451 for (size_t k = 0; k < numChannels; k++) { |
1461 WebRtcVad_Free(VAD_inst[k]); | 1452 WebRtcVad_Free(VAD_inst[k]); |
1462 #if (defined(CODEC_CNGCODEC8) || defined(CODEC_CNGCODEC16) || \ | 1453 #if (defined(CODEC_CNGCODEC8) || defined(CODEC_CNGCODEC16) || \ |
1463 defined(CODEC_CNGCODEC32) || defined(CODEC_CNGCODEC48)) | 1454 defined(CODEC_CNGCODEC32) || defined(CODEC_CNGCODEC48)) |
1464 WebRtcCng_FreeEnc(CNGenc_inst[k]); | 1455 CNG_encoder[k].reset(); |
1465 #endif | 1456 #endif |
1466 | 1457 |
1467 switch (coder) { | 1458 switch (coder) { |
1468 #ifdef CODEC_PCM16B | 1459 #ifdef CODEC_PCM16B |
1469 case webrtc::NetEqDecoder::kDecoderPCM16B: | 1460 case webrtc::NetEqDecoder::kDecoderPCM16B: |
1470 #endif | 1461 #endif |
1471 #ifdef CODEC_PCM16B_WB | 1462 #ifdef CODEC_PCM16B_WB |
1472 case webrtc::NetEqDecoder::kDecoderPCM16Bwb: | 1463 case webrtc::NetEqDecoder::kDecoderPCM16Bwb: |
1473 #endif | 1464 #endif |
1474 #ifdef CODEC_PCM16B_32KHZ | 1465 #ifdef CODEC_PCM16B_32KHZ |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1594 size_t frameLen, | 1585 size_t frameLen, |
1595 unsigned char* encoded, | 1586 unsigned char* encoded, |
1596 int sampleRate, | 1587 int sampleRate, |
1597 int* vad, | 1588 int* vad, |
1598 int useVAD, | 1589 int useVAD, |
1599 int bitrate, | 1590 int bitrate, |
1600 size_t numChannels) { | 1591 size_t numChannels) { |
1601 size_t cdlen = 0; | 1592 size_t cdlen = 0; |
1602 int16_t* tempdata; | 1593 int16_t* tempdata; |
1603 static int first_cng = 1; | 1594 static int first_cng = 1; |
1604 size_t tempLen; | 1595 int tempLen; |
hlundin-webrtc
2016/04/13 07:05:24
Why change this?
ossu
2016/04/13 11:57:07
Because ComfortNoiseEncoder->Encode returns an int
| |
1605 *vad = 1; | 1596 *vad = 1; |
1606 | 1597 |
1607 // check VAD first | 1598 // check VAD first |
1608 if (useVAD) { | 1599 if (useVAD) { |
1609 *vad = 0; | 1600 *vad = 0; |
1610 | 1601 |
1611 size_t sampleRate_10 = static_cast<size_t>(10 * sampleRate / 1000); | 1602 const int sampleRate_10 = 10 * sampleRate / 1000; |
hlundin-webrtc
2016/04/13 07:05:24
And these?
ossu
2016/04/13 11:57:07
Because changing tempLen to int caused a warning a
| |
1612 size_t sampleRate_20 = static_cast<size_t>(20 * sampleRate / 1000); | 1603 const int sampleRate_20 = 20 * sampleRate / 1000; |
1613 size_t sampleRate_30 = static_cast<size_t>(30 * sampleRate / 1000); | 1604 const int sampleRate_30 = 30 * sampleRate / 1000; |
1614 for (size_t k = 0; k < numChannels; k++) { | 1605 for (size_t k = 0; k < numChannels; k++) { |
1615 tempLen = frameLen; | 1606 tempLen = frameLen; |
1616 tempdata = &indata[k * frameLen]; | 1607 tempdata = &indata[k * frameLen]; |
1617 int localVad = 0; | 1608 int localVad = 0; |
1618 /* Partition the signal and test each chunk for VAD. | 1609 /* Partition the signal and test each chunk for VAD. |
1619 All chunks must be VAD=0 to produce a total VAD=0. */ | 1610 All chunks must be VAD=0 to produce a total VAD=0. */ |
1620 while (tempLen >= sampleRate_10) { | 1611 while (tempLen >= sampleRate_10) { |
1621 if ((tempLen % sampleRate_30) == 0) { // tempLen is multiple of 30ms | 1612 if ((tempLen % sampleRate_30) == 0) { // tempLen is multiple of 30ms |
1622 localVad |= WebRtcVad_Process(VAD_inst[k], sampleRate, tempdata, | 1613 localVad |= WebRtcVad_Process(VAD_inst[k], sampleRate, tempdata, |
1623 sampleRate_30); | 1614 sampleRate_30); |
(...skipping 13 matching lines...) Expand all Loading... | |
1637 } | 1628 } |
1638 | 1629 |
1639 // aggregate all VAD decisions over all channels | 1630 // aggregate all VAD decisions over all channels |
1640 *vad |= localVad; | 1631 *vad |= localVad; |
1641 } | 1632 } |
1642 | 1633 |
1643 if (!*vad) { | 1634 if (!*vad) { |
1644 // all channels are silent | 1635 // all channels are silent |
1645 cdlen = 0; | 1636 cdlen = 0; |
1646 for (size_t k = 0; k < numChannels; k++) { | 1637 for (size_t k = 0; k < numChannels; k++) { |
1647 WebRtcCng_Encode(CNGenc_inst[k], &indata[k * frameLen], | 1638 tempLen = CNG_encoder[k]->Encode( |
1648 (frameLen <= 640 ? frameLen : 640) /* max 640 */, | 1639 rtc::ArrayView<const int16_t>( |
1649 encoded, &tempLen, first_cng); | 1640 &indata[k * frameLen], |
1641 (frameLen <= 640 ? frameLen : 640) /* max 640 */), | |
1642 // TODO(ossu): kRtpDataSize is wrong to use here, but we should be | |
1643 // fine. | |
1644 rtc::ArrayView<uint8_t>(encoded, kRtpDataSize), | |
1645 first_cng); | |
1646 RTC_CHECK_GE(tempLen, 0); | |
1650 encoded += tempLen; | 1647 encoded += tempLen; |
1651 cdlen += tempLen; | 1648 cdlen += tempLen; |
1652 } | 1649 } |
1653 *vad = 0; | 1650 *vad = 0; |
1654 first_cng = 0; | 1651 first_cng = 0; |
1655 return (cdlen); | 1652 return (cdlen); |
1656 } | 1653 } |
1657 } | 1654 } |
1658 | 1655 |
1659 // loop over all channels | 1656 // loop over all channels |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1878 memmove(ptrL + stride, ptrL, ptrR - ptrL); | 1875 memmove(ptrL + stride, ptrL, ptrR - ptrL); |
1879 | 1876 |
1880 // copy from temp to left pointer | 1877 // copy from temp to left pointer |
1881 memcpy(ptrL, temp, stride); | 1878 memcpy(ptrL, temp, stride); |
1882 | 1879 |
1883 // advance pointers | 1880 // advance pointers |
1884 ptrL += stride * 2; | 1881 ptrL += stride * 2; |
1885 ptrR += stride; | 1882 ptrR += stride; |
1886 } | 1883 } |
1887 } | 1884 } |
OLD | NEW |