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

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

Powered by Google App Engine
This is Rietveld 408576698