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

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

Issue 1516653003: Adding Opus to RTPencode. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years 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
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 18 matching lines...) Expand all
29 // needed for NetEqDecoder 29 // needed for NetEqDecoder
30 #include "webrtc/modules/audio_coding/neteq/audio_decoder_impl.h" 30 #include "webrtc/modules/audio_coding/neteq/audio_decoder_impl.h"
31 #include "webrtc/modules/audio_coding/neteq/include/neteq.h" 31 #include "webrtc/modules/audio_coding/neteq/include/neteq.h"
32 32
33 /************************/ 33 /************************/
34 /* Define payload types */ 34 /* Define payload types */
35 /************************/ 35 /************************/
36 36
37 #include "PayloadTypes.h" 37 #include "PayloadTypes.h"
38 38
39 namespace {
40 const size_t kRtpDataSize = 8000;
41 }
42
39 /*********************/ 43 /*********************/
40 /* Misc. definitions */ 44 /* Misc. definitions */
41 /*********************/ 45 /*********************/
42 46
43 #define STOPSENDTIME 3000 47 #define STOPSENDTIME 3000
44 #define RESTARTSENDTIME 0 // 162500 48 #define RESTARTSENDTIME 0 // 162500
45 #define FIRSTLINELEN 40 49 #define FIRSTLINELEN 40
46 #define CHECK_NOT_NULL(a) \ 50 #define CHECK_NOT_NULL(a) \
47 if ((a) == 0) { \ 51 if ((a) == 0) { \
48 printf("\n %s \n line: %d \nerror at %s\n", __FILE__, __LINE__, #a); \ 52 printf("\n %s \n line: %d \nerror at %s\n", __FILE__, __LINE__, #a); \
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 #include "GSMFRInterface.h" 190 #include "GSMFRInterface.h"
187 #include "GSMFRCreation.h" 191 #include "GSMFRCreation.h"
188 #endif 192 #endif
189 #if (defined(CODEC_CNGCODEC8) || defined(CODEC_CNGCODEC16) || \ 193 #if (defined(CODEC_CNGCODEC8) || defined(CODEC_CNGCODEC16) || \
190 defined(CODEC_CNGCODEC32) || defined(CODEC_CNGCODEC48)) 194 defined(CODEC_CNGCODEC32) || defined(CODEC_CNGCODEC48))
191 #include "webrtc/modules/audio_coding/codecs/cng/webrtc_cng.h" 195 #include "webrtc/modules/audio_coding/codecs/cng/webrtc_cng.h"
192 #endif 196 #endif
193 #if ((defined CODEC_SPEEX_8) || (defined CODEC_SPEEX_16)) 197 #if ((defined CODEC_SPEEX_8) || (defined CODEC_SPEEX_16))
194 #include "SpeexInterface.h" 198 #include "SpeexInterface.h"
195 #endif 199 #endif
200 #ifdef CODEC_OPUS
201 #include "webrtc/modules/audio_coding/codecs/opus/opus_interface.h"
202 #endif
196 203
197 /***********************************/ 204 /***********************************/
198 /* Global codec instance variables */ 205 /* Global codec instance variables */
199 /***********************************/ 206 /***********************************/
200 207
201 WebRtcVadInst* VAD_inst[2]; 208 WebRtcVadInst* VAD_inst[2];
202 209
203 #ifdef CODEC_G722 210 #ifdef CODEC_G722
204 G722EncInst* g722EncState[2]; 211 G722EncInst* g722EncState[2];
205 #endif 212 #endif
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 #if (defined(CODEC_CNGCODEC8) || defined(CODEC_CNGCODEC16) || \ 264 #if (defined(CODEC_CNGCODEC8) || defined(CODEC_CNGCODEC16) || \
258 defined(CODEC_CNGCODEC32) || defined(CODEC_CNGCODEC48)) 265 defined(CODEC_CNGCODEC32) || defined(CODEC_CNGCODEC48))
259 CNG_enc_inst* CNGenc_inst[2]; 266 CNG_enc_inst* CNGenc_inst[2];
260 #endif 267 #endif
261 #ifdef CODEC_SPEEX_8 268 #ifdef CODEC_SPEEX_8
262 SPEEX_encinst_t* SPEEX8enc_inst[2]; 269 SPEEX_encinst_t* SPEEX8enc_inst[2];
263 #endif 270 #endif
264 #ifdef CODEC_SPEEX_16 271 #ifdef CODEC_SPEEX_16
265 SPEEX_encinst_t* SPEEX16enc_inst[2]; 272 SPEEX_encinst_t* SPEEX16enc_inst[2];
266 #endif 273 #endif
274 #ifdef CODEC_OPUS
275 OpusEncInst* opus_inst[2];
276 #endif
267 277
268 int main(int argc, char* argv[]) { 278 int main(int argc, char* argv[]) {
269 size_t packet_size; 279 size_t packet_size;
270 int fs; 280 int fs;
271 webrtc::NetEqDecoder usedCodec; 281 webrtc::NetEqDecoder usedCodec;
272 int payloadType; 282 int payloadType;
273 int bitrate = 0; 283 int bitrate = 0;
274 int useVAD, vad; 284 int useVAD, vad;
275 int useRed = 0; 285 int useRed = 0;
276 size_t len, enc_len; 286 size_t len, enc_len;
277 int16_t org_data[4000]; 287 int16_t org_data[4000];
278 unsigned char rtp_data[8000]; 288 unsigned char rtp_data[kRtpDataSize];
279 int16_t seqNo = 0xFFF; 289 int16_t seqNo = 0xFFF;
280 uint32_t ssrc = 1235412312; 290 uint32_t ssrc = 1235412312;
281 uint32_t timestamp = 0xAC1245; 291 uint32_t timestamp = 0xAC1245;
282 uint16_t length, plen; 292 uint16_t length, plen;
283 uint32_t offset; 293 uint32_t offset;
284 double sendtime = 0; 294 double sendtime = 0;
285 int red_PT[2] = {0}; 295 int red_PT[2] = {0};
286 uint32_t red_TS[2] = {0}; 296 uint32_t red_TS[2] = {0};
287 uint16_t red_len[2] = {0}; 297 uint16_t red_len[2] = {0};
288 size_t RTPheaderLen = 12; 298 size_t RTPheaderLen = 12;
289 uint8_t red_data[8000]; 299 uint8_t red_data[kRtpDataSize];
290 #ifdef INSERT_OLD_PACKETS 300 #ifdef INSERT_OLD_PACKETS
291 uint16_t old_length, old_plen; 301 uint16_t old_length, old_plen;
292 size_t old_enc_len; 302 size_t old_enc_len;
293 int first_old_packet = 1; 303 int first_old_packet = 1;
294 unsigned char old_rtp_data[8000]; 304 unsigned char old_rtp_data[kRtpDataSize];
295 size_t packet_age = 0; 305 size_t packet_age = 0;
296 #endif 306 #endif
297 #ifdef INSERT_DTMF_PACKETS 307 #ifdef INSERT_DTMF_PACKETS
298 int NTone = 1; 308 int NTone = 1;
299 int DTMFfirst = 1; 309 int DTMFfirst = 1;
300 uint32_t DTMFtimestamp; 310 uint32_t DTMFtimestamp;
301 bool dtmfSent = false; 311 bool dtmfSent = false;
302 #endif 312 #endif
303 bool usingStereo = false; 313 bool usingStereo = false;
304 size_t stereoMode = 0; 314 size_t stereoMode = 0;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 #endif 432 #endif
423 #ifdef CODEC_RED 433 #ifdef CODEC_RED
424 #ifdef CODEC_G711 434 #ifdef CODEC_G711
425 printf(" : red_pcm Redundancy RTP packet with 2*G711A " 435 printf(" : red_pcm Redundancy RTP packet with 2*G711A "
426 "frames\n"); 436 "frames\n");
427 #endif 437 #endif
428 #ifdef CODEC_ISAC 438 #ifdef CODEC_ISAC
429 printf(" : red_isac Redundancy RTP packet with 2*iSAC " 439 printf(" : red_isac Redundancy RTP packet with 2*iSAC "
430 "frames\n"); 440 "frames\n");
431 #endif 441 #endif
442 #endif // CODEC_RED
443 #ifdef CODEC_OPUS
444 printf(" : opus Opus codec with FEC (48kHz, 32kbps, FEC"
445 " on and tuned for 5%% packet losses)\n");
432 #endif 446 #endif
433 printf("\n"); 447 printf("\n");
434 448
435 #if (defined(CODEC_CNGCODEC8) || defined(CODEC_CNGCODEC16) || \ 449 #if (defined(CODEC_CNGCODEC8) || defined(CODEC_CNGCODEC16) || \
436 defined(CODEC_CNGCODEC32) || defined(CODEC_CNGCODEC48)) 450 defined(CODEC_CNGCODEC32) || defined(CODEC_CNGCODEC48))
437 printf("useVAD : 0 Voice Activity Detection is switched off\n"); 451 printf("useVAD : 0 Voice Activity Detection is switched off\n");
438 printf(" : 1 Voice Activity Detection is switched on\n\n"); 452 printf(" : 1 Voice Activity Detection is switched on\n\n");
439 #else 453 #else
440 printf("useVAD : 0 Voice Activity Detection switched off (on not " 454 printf("useVAD : 0 Voice Activity Detection switched off (on not "
441 "supported)\n\n"); 455 "supported)\n\n");
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 } else if (!strcmp(name, "red_pcm")) { 887 } else if (!strcmp(name, "red_pcm")) {
874 *codec = webrtc::NetEqDecoder::kDecoderPCMa; 888 *codec = webrtc::NetEqDecoder::kDecoderPCMa;
875 *PT = NETEQ_CODEC_PCMA_PT; /* this will be the PT for the sub-headers */ 889 *PT = NETEQ_CODEC_PCMA_PT; /* this will be the PT for the sub-headers */
876 *fs = 8000; 890 *fs = 8000;
877 *useRed = 1; 891 *useRed = 1;
878 } else if (!strcmp(name, "red_isac")) { 892 } else if (!strcmp(name, "red_isac")) {
879 *codec = webrtc::NetEqDecoder::kDecoderISAC; 893 *codec = webrtc::NetEqDecoder::kDecoderISAC;
880 *PT = NETEQ_CODEC_ISAC_PT; /* this will be the PT for the sub-headers */ 894 *PT = NETEQ_CODEC_ISAC_PT; /* this will be the PT for the sub-headers */
881 *fs = 16000; 895 *fs = 16000;
882 *useRed = 1; 896 *useRed = 1;
897 } else if (!strcmp(name, "opus")) {
898 *codec = webrtc::NetEqDecoder::kDecoderOpus;
899 *PT = NETEQ_CODEC_OPUS_PT; /* this will be the PT for the sub-headers */
900 *fs = 48000;
883 } else { 901 } else {
884 printf("Error: Not a supported codec (%s)\n", name); 902 printf("Error: Not a supported codec (%s)\n", name);
885 exit(0); 903 exit(0);
886 } 904 }
887 } 905 }
888 906
889 int NetEQTest_init_coders(webrtc::NetEqDecoder coder, 907 int NetEQTest_init_coders(webrtc::NetEqDecoder coder,
890 size_t enc_frameSize, 908 size_t enc_frameSize,
891 int bitrate, 909 int bitrate,
892 int sampfreq, 910 int sampfreq,
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
1404 "enc_frameSize\n"); 1422 "enc_frameSize\n");
1405 exit(0); 1423 exit(0);
1406 } 1424 }
1407 WebRtcGSMFR_EncoderInit(GSMFRenc_inst[k], 0); 1425 WebRtcGSMFR_EncoderInit(GSMFRenc_inst[k], 0);
1408 } else { 1426 } else {
1409 printf("\nError - GSM FR is only developed for 8kHz \n"); 1427 printf("\nError - GSM FR is only developed for 8kHz \n");
1410 exit(0); 1428 exit(0);
1411 } 1429 }
1412 break; 1430 break;
1413 #endif 1431 #endif
1432 #ifdef CODEC_OPUS
1433 case webrtc::NetEqDecoder::kDecoderOpus:
1434 ok = WebRtcOpus_EncoderCreate(&opus_inst[k], 1, 0);
1435 if (ok != 0) {
1436 printf("Error: Couldn't allocate memory for Opus encoding "
1437 "instance\n");
1438 exit(0);
1439 }
1440 WebRtcOpus_EnableFec(opus_inst[k]);
1441 WebRtcOpus_SetPacketLossRate(opus_inst[k], 5);
1442 break;
1443 #endif
1414 default: 1444 default:
1415 printf("Error: unknown codec in call to NetEQTest_init_coders.\n"); 1445 printf("Error: unknown codec in call to NetEQTest_init_coders.\n");
1416 exit(0); 1446 exit(0);
1417 break; 1447 break;
1418 } 1448 }
1419
1420 if (ok != 0) { 1449 if (ok != 0) {
1421 return (ok); 1450 return (ok);
1422 } 1451 }
1423 } // end for 1452 } // end for
1424 1453
1425 return (0); 1454 return (0);
1426 } 1455 }
1427 1456
1428 int NetEQTest_free_coders(webrtc::NetEqDecoder coder, size_t numChannels) { 1457 int NetEQTest_free_coders(webrtc::NetEqDecoder coder, size_t numChannels) {
1429 for (size_t k = 0; k < numChannels; k++) { 1458 for (size_t k = 0; k < numChannels; k++) {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1536 #ifdef CODEC_ISAC_SWB 1565 #ifdef CODEC_ISAC_SWB
1537 case webrtc::NetEqDecoder::kDecoderISACswb: 1566 case webrtc::NetEqDecoder::kDecoderISACswb:
1538 WebRtcIsac_Free(ISACSWB_inst[k]); 1567 WebRtcIsac_Free(ISACSWB_inst[k]);
1539 break; 1568 break;
1540 #endif 1569 #endif
1541 #ifdef CODEC_GSMFR 1570 #ifdef CODEC_GSMFR
1542 case webrtc::NetEqDecoder::kDecoderGSMFR: 1571 case webrtc::NetEqDecoder::kDecoderGSMFR:
1543 WebRtcGSMFR_FreeEnc(GSMFRenc_inst[k]); 1572 WebRtcGSMFR_FreeEnc(GSMFRenc_inst[k]);
1544 break; 1573 break;
1545 #endif 1574 #endif
1575 #ifdef CODEC_OPUS
1576 case webrtc::NetEqDecoder::kDecoderOpus:
1577 WebRtcOpus_EncoderFree(opus_inst[k]);
1578 break;
1579 #endif
1546 default: 1580 default:
1547 printf("Error: unknown codec in call to NetEQTest_init_coders.\n"); 1581 printf("Error: unknown codec in call to NetEQTest_init_coders.\n");
1548 exit(0); 1582 exit(0);
1549 break; 1583 break;
1550 } 1584 }
1551 } 1585 }
1552 1586
1553 return (0); 1587 return (0);
1554 } 1588 }
1555 1589
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1680 int noOfCalls = 0; 1714 int noOfCalls = 0;
1681 int res = 0; 1715 int res = 0;
1682 while (res <= 0) { 1716 while (res <= 0) {
1683 res = WebRtcIsac_Encode(ISACSWB_inst[k], &indata[noOfCalls * 320], 1717 res = WebRtcIsac_Encode(ISACSWB_inst[k], &indata[noOfCalls * 320],
1684 encoded); 1718 encoded);
1685 noOfCalls++; 1719 noOfCalls++;
1686 } 1720 }
1687 cdlen = static_cast<size_t>(res); 1721 cdlen = static_cast<size_t>(res);
1688 } 1722 }
1689 #endif 1723 #endif
1724 #ifdef CODEC_OPUS
1725 cdlen = WebRtcOpus_Encode(opus_inst[k],
1726 indata,
1727 frameLen,
1728 kRtpDataSize - 12,
1729 encoded);
1730 assert(cdlen > 0);
hlundin-webrtc 2015/12/11 08:30:29 Nit: CHECK_GT(cdlen, 0); I think CHECK is better t
minyue-webrtc 2015/12/11 09:03:55 Done.
1731 #endif
1690 indata += frameLen; 1732 indata += frameLen;
1691 encoded += cdlen; 1733 encoded += cdlen;
1692 totalLen += cdlen; 1734 totalLen += cdlen;
1693 1735
1694 } // end for 1736 } // end for
1695 1737
1696 first_cng = 1; 1738 first_cng = 1;
1697 return (totalLen); 1739 return (totalLen);
1698 } 1740 }
1699 1741
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1837 memmove(ptrL + stride, ptrL, ptrR - ptrL); 1879 memmove(ptrL + stride, ptrL, ptrR - ptrL);
1838 1880
1839 // copy from temp to left pointer 1881 // copy from temp to left pointer
1840 memcpy(ptrL, temp, stride); 1882 memcpy(ptrL, temp, stride);
1841 1883
1842 // advance pointers 1884 // advance pointers
1843 ptrL += stride * 2; 1885 ptrL += stride * 2;
1844 ptrR += stride; 1886 ptrR += stride;
1845 } 1887 }
1846 } 1888 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698