Changeset 5734 for pjproject/trunk/pjmedia/src/pjmedia-codec/opus.c
- Timestamp:
- Feb 12, 2018 6:18:22 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia-codec/opus.c
r5731 r5734 43 43 */ 44 44 #define MAX_ENCODED_PACKET_SIZE 1280 45 46 /* Default frame time (msec) */ 47 #define PTIME 20 45 48 46 49 /* Tracing */ … … 137 140 OpusRepacketizer *dec_packer; 138 141 pjmedia_codec_opus_config cfg; 139 unsigned ptime; 142 unsigned enc_ptime; 143 unsigned dec_ptime; 140 144 pjmedia_frame dec_frame[2]; 141 145 int dec_frame_index; … … 150 154 PJMEDIA_CODEC_OPUS_DEFAULT_SAMPLE_RATE, /* Sample rate */ 151 155 1, /* Channel count */ 156 PTIME, /* Frame time */ 152 157 PJMEDIA_CODEC_OPUS_DEFAULT_BIT_RATE, /* Bit rate */ 153 158 5, /* Expected packet loss */ … … 387 392 param->info.clock_rate = opus_cfg.sample_rate = cfg->sample_rate; 388 393 param->info.max_bps = opus_cfg.sample_rate * 2; 394 param->info.frm_ptime = opus_cfg.frm_ptime = cfg->frm_ptime; 389 395 390 396 /* Set channel count */ … … 468 474 attr->info.avg_bps = opus_cfg.bit_rate; 469 475 attr->info.max_bps = opus_cfg.sample_rate * 2; 470 attr->info.frm_ptime = 20;476 attr->info.frm_ptime = opus_cfg.frm_ptime; 471 477 attr->setting.frm_per_pkt = 1; 472 478 attr->info.pcm_bits_per_sample = 16; … … 601 607 opus_data->cfg.sample_rate = attr->info.clock_rate; 602 608 opus_data->cfg.channel_cnt = attr->info.channel_cnt; 603 opus_data-> ptime= attr->info.frm_ptime;609 opus_data->enc_ptime = opus_data->dec_ptime = attr->info.frm_ptime; 604 610 605 611 /* Allocate memory used by the codec */ … … 815 821 } 816 822 817 samples_per_frame = (opus_data->cfg.sample_rate *818 opus_data->ptime) / 1000;819 820 823 pj_memcpy(tmp_buf, pkt, pkt_size); 821 824 … … 837 840 frames[i].buf = ((char*)pkt) + out_pos; 838 841 frames[i].size = size; 842 frames[i].bit_info = opus_packet_get_nb_samples(frames[i].buf, 843 frames[i].size, opus_data->cfg.sample_rate); 844 845 if (i == 0) { 846 unsigned ptime = frames[i].bit_info * 1000 / 847 opus_data->cfg.sample_rate; 848 if (ptime != opus_data->dec_ptime) { 849 PJ_LOG(4, (THIS_FILE, "Opus ptime change detected: %d ms " 850 "--> %d ms", 851 opus_data->dec_ptime, ptime)); 852 opus_data->dec_ptime = ptime; 853 opus_data->dec_frame_index = -1; 854 855 /* Signal to the stream about ptime change. */ 856 frames[i].bit_info |= 0x10000; 857 } 858 samples_per_frame = frames[i].bit_info; 859 } 860 839 861 frames[i].timestamp.u64 = ts->u64 + i * samples_per_frame; 840 862 out_pos += size; … … 867 889 868 890 samples_per_frame = (opus_data->cfg.sample_rate * 869 opus_data-> ptime) / 1000;891 opus_data->enc_ptime) / 1000; 870 892 frame_size = samples_per_frame * opus_data->cfg.channel_cnt * 871 893 sizeof(opus_int16); … … 982 1004 frm_size = PJ_MIN(frm_size, 983 1005 opus_data->cfg.sample_rate * 984 opus_data-> ptime / 1000);1006 opus_data->dec_ptime / 1000); 985 1007 } 986 1008 decoded_samples = opus_decode( opus_data->dec, … … 1042 1064 /* Recover the first packet? Don't think so, fill it with zeroes. */ 1043 1065 pj_uint16_t samples_per_frame; 1044 samples_per_frame = (pj_uint16_t)(opus_data->cfg.sample_rate *1045 opus_data->ptime) /1000;1066 samples_per_frame = opus_data->cfg.sample_rate * opus_data->dec_ptime/ 1067 1000; 1046 1068 output->type = PJMEDIA_FRAME_TYPE_AUDIO; 1047 1069 output->size = samples_per_frame << 1; … … 1057 1079 if (inframe->type != PJMEDIA_FRAME_TYPE_AUDIO) { 1058 1080 frm_size = PJ_MIN(frm_size, opus_data->cfg.sample_rate * 1059 opus_data-> ptime/1000);1081 opus_data->dec_ptime/1000); 1060 1082 } 1061 1083 decoded_samples = opus_decode(opus_data->dec,
Note: See TracChangeset
for help on using the changeset viewer.