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 247 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 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]); | |
932 if (ok != 0) { | |
933 printf("Error: Couldn't allocate memory for CNG encoding instance\n"); | |
934 exit(0); | |
935 } | |
936 if (sampfreq <= 16000) { | 931 if (sampfreq <= 16000) { |
937 ok = WebRtcCng_InitEnc(CNGenc_inst[k], sampfreq, 200, 5); | 932 CNG_encoder[k] = new webrtc::ComfortNoiseEncoder(sampfreq, 200, 5); |
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 } | 933 } |
944 #endif | 934 #endif |
945 | 935 |
946 switch (coder) { | 936 switch (coder) { |
947 #ifdef CODEC_PCM16B | 937 #ifdef CODEC_PCM16B |
948 case webrtc::NetEqDecoder::kDecoderPCM16B: | 938 case webrtc::NetEqDecoder::kDecoderPCM16B: |
949 #endif | 939 #endif |
950 #ifdef CODEC_PCM16B_WB | 940 #ifdef CODEC_PCM16B_WB |
951 case webrtc::NetEqDecoder::kDecoderPCM16Bwb: | 941 case webrtc::NetEqDecoder::kDecoderPCM16Bwb: |
952 #endif | 942 #endif |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1454 } // end for | 1444 } // end for |
1455 | 1445 |
1456 return (0); | 1446 return (0); |
1457 } | 1447 } |
1458 | 1448 |
1459 int NetEQTest_free_coders(webrtc::NetEqDecoder coder, size_t numChannels) { | 1449 int NetEQTest_free_coders(webrtc::NetEqDecoder coder, size_t numChannels) { |
1460 for (size_t k = 0; k < numChannels; k++) { | 1450 for (size_t k = 0; k < numChannels; k++) { |
1461 WebRtcVad_Free(VAD_inst[k]); | 1451 WebRtcVad_Free(VAD_inst[k]); |
1462 #if (defined(CODEC_CNGCODEC8) || defined(CODEC_CNGCODEC16) || \ | 1452 #if (defined(CODEC_CNGCODEC8) || defined(CODEC_CNGCODEC16) || \ |
1463 defined(CODEC_CNGCODEC32) || defined(CODEC_CNGCODEC48)) | 1453 defined(CODEC_CNGCODEC32) || defined(CODEC_CNGCODEC48)) |
1464 WebRtcCng_FreeEnc(CNGenc_inst[k]); | 1454 delete CNG_encoder[k]; |
ossu
2016/04/19 09:50:26
I should probably null CNG_encoder[k] here as well
| |
1465 #endif | 1455 #endif |
1466 | 1456 |
1467 switch (coder) { | 1457 switch (coder) { |
1468 #ifdef CODEC_PCM16B | 1458 #ifdef CODEC_PCM16B |
1469 case webrtc::NetEqDecoder::kDecoderPCM16B: | 1459 case webrtc::NetEqDecoder::kDecoderPCM16B: |
1470 #endif | 1460 #endif |
1471 #ifdef CODEC_PCM16B_WB | 1461 #ifdef CODEC_PCM16B_WB |
1472 case webrtc::NetEqDecoder::kDecoderPCM16Bwb: | 1462 case webrtc::NetEqDecoder::kDecoderPCM16Bwb: |
1473 #endif | 1463 #endif |
1474 #ifdef CODEC_PCM16B_32KHZ | 1464 #ifdef CODEC_PCM16B_32KHZ |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1593 int16_t* indata, | 1583 int16_t* indata, |
1594 size_t frameLen, | 1584 size_t frameLen, |
1595 unsigned char* encoded, | 1585 unsigned char* encoded, |
1596 int sampleRate, | 1586 int sampleRate, |
1597 int* vad, | 1587 int* vad, |
1598 int useVAD, | 1588 int useVAD, |
1599 int bitrate, | 1589 int bitrate, |
1600 size_t numChannels) { | 1590 size_t numChannels) { |
1601 size_t cdlen = 0; | 1591 size_t cdlen = 0; |
1602 int16_t* tempdata; | 1592 int16_t* tempdata; |
1603 static int first_cng = 1; | 1593 static bool first_cng = true; |
1604 size_t tempLen; | 1594 size_t tempLen; |
1605 *vad = 1; | 1595 *vad = 1; |
1606 | 1596 |
1607 // check VAD first | 1597 // check VAD first |
1608 if (useVAD) { | 1598 if (useVAD) { |
1609 *vad = 0; | 1599 *vad = 0; |
1610 | 1600 |
1611 size_t sampleRate_10 = static_cast<size_t>(10 * sampleRate / 1000); | 1601 const size_t sampleRate_10 = static_cast<size_t>(10 * sampleRate / 1000); |
1612 size_t sampleRate_20 = static_cast<size_t>(20 * sampleRate / 1000); | 1602 const size_t sampleRate_20 = static_cast<size_t>(20 * sampleRate / 1000); |
1613 size_t sampleRate_30 = static_cast<size_t>(30 * sampleRate / 1000); | 1603 const size_t sampleRate_30 = static_cast<size_t>(30 * sampleRate / 1000); |
1614 for (size_t k = 0; k < numChannels; k++) { | 1604 for (size_t k = 0; k < numChannels; k++) { |
1615 tempLen = frameLen; | 1605 tempLen = frameLen; |
1616 tempdata = &indata[k * frameLen]; | 1606 tempdata = &indata[k * frameLen]; |
1617 int localVad = 0; | 1607 int localVad = 0; |
1618 /* Partition the signal and test each chunk for VAD. | 1608 /* Partition the signal and test each chunk for VAD. |
1619 All chunks must be VAD=0 to produce a total VAD=0. */ | 1609 All chunks must be VAD=0 to produce a total VAD=0. */ |
1620 while (tempLen >= sampleRate_10) { | 1610 while (tempLen >= sampleRate_10) { |
1621 if ((tempLen % sampleRate_30) == 0) { // tempLen is multiple of 30ms | 1611 if ((tempLen % sampleRate_30) == 0) { // tempLen is multiple of 30ms |
1622 localVad |= WebRtcVad_Process(VAD_inst[k], sampleRate, tempdata, | 1612 localVad |= WebRtcVad_Process(VAD_inst[k], sampleRate, tempdata, |
1623 sampleRate_30); | 1613 sampleRate_30); |
(...skipping 11 matching lines...) Expand all Loading... | |
1635 tempLen -= sampleRate_10; | 1625 tempLen -= sampleRate_10; |
1636 } | 1626 } |
1637 } | 1627 } |
1638 | 1628 |
1639 // aggregate all VAD decisions over all channels | 1629 // aggregate all VAD decisions over all channels |
1640 *vad |= localVad; | 1630 *vad |= localVad; |
1641 } | 1631 } |
1642 | 1632 |
1643 if (!*vad) { | 1633 if (!*vad) { |
1644 // all channels are silent | 1634 // all channels are silent |
1635 rtc::Buffer workaround; | |
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 workaround.Clear(); |
1648 (frameLen <= 640 ? frameLen : 640) /* max 640 */, | 1639 tempLen = CNG_encoder[k]->Encode( |
1649 encoded, &tempLen, first_cng); | 1640 rtc::ArrayView<const int16_t>( |
1641 &indata[k * frameLen], | |
1642 (frameLen <= 640 ? frameLen : 640) /* max 640 */), | |
1643 first_cng, | |
1644 &workaround); | |
1645 memcpy(encoded, workaround.data(), tempLen); | |
1650 encoded += tempLen; | 1646 encoded += tempLen; |
1651 cdlen += tempLen; | 1647 cdlen += tempLen; |
1652 } | 1648 } |
1653 *vad = 0; | 1649 *vad = 0; |
1654 first_cng = 0; | 1650 first_cng = false; |
1655 return (cdlen); | 1651 return (cdlen); |
1656 } | 1652 } |
1657 } | 1653 } |
1658 | 1654 |
1659 // loop over all channels | 1655 // loop over all channels |
1660 size_t totalLen = 0; | 1656 size_t totalLen = 0; |
1661 | 1657 |
1662 for (size_t k = 0; k < numChannels; k++) { | 1658 for (size_t k = 0; k < numChannels; k++) { |
1663 /* Encode with the selected coder type */ | 1659 /* Encode with the selected coder type */ |
1664 if (coder == webrtc::NetEqDecoder::kDecoderPCMu) { /*g711 u-law */ | 1660 if (coder == webrtc::NetEqDecoder::kDecoderPCMu) { /*g711 u-law */ |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1727 cdlen = WebRtcOpus_Encode(opus_inst[k], indata, frameLen, kRtpDataSize - 12, | 1723 cdlen = WebRtcOpus_Encode(opus_inst[k], indata, frameLen, kRtpDataSize - 12, |
1728 encoded); | 1724 encoded); |
1729 RTC_CHECK_GT(cdlen, 0u); | 1725 RTC_CHECK_GT(cdlen, 0u); |
1730 #endif | 1726 #endif |
1731 indata += frameLen; | 1727 indata += frameLen; |
1732 encoded += cdlen; | 1728 encoded += cdlen; |
1733 totalLen += cdlen; | 1729 totalLen += cdlen; |
1734 | 1730 |
1735 } // end for | 1731 } // end for |
1736 | 1732 |
1737 first_cng = 1; | 1733 first_cng = true; |
1738 return (totalLen); | 1734 return (totalLen); |
1739 } | 1735 } |
1740 | 1736 |
1741 void makeRTPheader(unsigned char* rtp_data, | 1737 void makeRTPheader(unsigned char* rtp_data, |
1742 int payloadType, | 1738 int payloadType, |
1743 int seqNo, | 1739 int seqNo, |
1744 uint32_t timestamp, | 1740 uint32_t timestamp, |
1745 uint32_t ssrc) { | 1741 uint32_t ssrc) { |
1746 rtp_data[0] = 0x80; | 1742 rtp_data[0] = 0x80; |
1747 rtp_data[1] = payloadType & 0xFF; | 1743 rtp_data[1] = payloadType & 0xFF; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1878 memmove(ptrL + stride, ptrL, ptrR - ptrL); | 1874 memmove(ptrL + stride, ptrL, ptrR - ptrL); |
1879 | 1875 |
1880 // copy from temp to left pointer | 1876 // copy from temp to left pointer |
1881 memcpy(ptrL, temp, stride); | 1877 memcpy(ptrL, temp, stride); |
1882 | 1878 |
1883 // advance pointers | 1879 // advance pointers |
1884 ptrL += stride * 2; | 1880 ptrL += stride * 2; |
1885 ptrR += stride; | 1881 ptrR += stride; |
1886 } | 1882 } |
1887 } | 1883 } |
OLD | NEW |