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

Side by Side Diff: webrtc/modules/audio_coding/neteq/test/RTPencode.cc

Issue 1868143002: Convert CNG into C++ and remove it from AudioDecoder (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Implicit conversion to ArrayView in TestSidErroneous Created 4 years, 8 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
« no previous file with comments | « webrtc/modules/audio_coding/neteq/payload_splitter.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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];
1455 CNG_encoder[k] = nullptr;
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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1593 int16_t* indata, 1584 int16_t* indata,
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 bool first_cng = true;
1604 size_t tempLen; 1595 size_t tempLen;
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 size_t sampleRate_10 = static_cast<size_t>(10 * sampleRate / 1000);
1612 size_t sampleRate_20 = static_cast<size_t>(20 * sampleRate / 1000); 1603 const size_t sampleRate_20 = static_cast<size_t>(20 * sampleRate / 1000);
1613 size_t sampleRate_30 = static_cast<size_t>(30 * sampleRate / 1000); 1604 const size_t sampleRate_30 = static_cast<size_t>(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 11 matching lines...) Expand all
1635 tempLen -= sampleRate_10; 1626 tempLen -= sampleRate_10;
1636 } 1627 }
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
1636 rtc::Buffer workaround;
1645 cdlen = 0; 1637 cdlen = 0;
1646 for (size_t k = 0; k < numChannels; k++) { 1638 for (size_t k = 0; k < numChannels; k++) {
1647 WebRtcCng_Encode(CNGenc_inst[k], &indata[k * frameLen], 1639 workaround.Clear();
1648 (frameLen <= 640 ? frameLen : 640) /* max 640 */, 1640 tempLen = CNG_encoder[k]->Encode(
1649 encoded, &tempLen, first_cng); 1641 rtc::ArrayView<const int16_t>(
1642 &indata[k * frameLen],
1643 (frameLen <= 640 ? frameLen : 640) /* max 640 */),
1644 first_cng,
1645 &workaround);
1646 memcpy(encoded, workaround.data(), tempLen);
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 = false;
1655 return (cdlen); 1652 return (cdlen);
1656 } 1653 }
1657 } 1654 }
1658 1655
1659 // loop over all channels 1656 // loop over all channels
1660 size_t totalLen = 0; 1657 size_t totalLen = 0;
1661 1658
1662 for (size_t k = 0; k < numChannels; k++) { 1659 for (size_t k = 0; k < numChannels; k++) {
1663 /* Encode with the selected coder type */ 1660 /* Encode with the selected coder type */
1664 if (coder == webrtc::NetEqDecoder::kDecoderPCMu) { /*g711 u-law */ 1661 if (coder == webrtc::NetEqDecoder::kDecoderPCMu) { /*g711 u-law */
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1727 cdlen = WebRtcOpus_Encode(opus_inst[k], indata, frameLen, kRtpDataSize - 12, 1724 cdlen = WebRtcOpus_Encode(opus_inst[k], indata, frameLen, kRtpDataSize - 12,
1728 encoded); 1725 encoded);
1729 RTC_CHECK_GT(cdlen, 0u); 1726 RTC_CHECK_GT(cdlen, 0u);
1730 #endif 1727 #endif
1731 indata += frameLen; 1728 indata += frameLen;
1732 encoded += cdlen; 1729 encoded += cdlen;
1733 totalLen += cdlen; 1730 totalLen += cdlen;
1734 1731
1735 } // end for 1732 } // end for
1736 1733
1737 first_cng = 1; 1734 first_cng = true;
1738 return (totalLen); 1735 return (totalLen);
1739 } 1736 }
1740 1737
1741 void makeRTPheader(unsigned char* rtp_data, 1738 void makeRTPheader(unsigned char* rtp_data,
1742 int payloadType, 1739 int payloadType,
1743 int seqNo, 1740 int seqNo,
1744 uint32_t timestamp, 1741 uint32_t timestamp,
1745 uint32_t ssrc) { 1742 uint32_t ssrc) {
1746 rtp_data[0] = 0x80; 1743 rtp_data[0] = 0x80;
1747 rtp_data[1] = payloadType & 0xFF; 1744 rtp_data[1] = payloadType & 0xFF;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/payload_splitter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698