Skip to content

Commit 53785b0

Browse files
committed
send correct ToC byte for SC-VBR frames
1 parent 15165ad commit 53785b0

File tree

2 files changed

+75
-15
lines changed

2 files changed

+75
-15
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ The Rohde & Schwarz CMW500 can be extended for EVS – however here, this transc
7272

7373
Although this list is rather long, these features are disabled at SDP negotiation via the `force_limitations.patch` and should not create an interoperability issue.
7474

75-
* VBR: The lowest mode is variable in bitrate (average 5.9 kbit/s); untested.
76-
* Compound payload: Several frames per payload, for example when FEC or a packetization time (ptime) longer than 20 ms are used. This is useful to lower the overall overhead (RTP, UDP, and IP) of the lowest mode even further.
75+
* Compound payload: Several frames per payload, for example when FEC or a packetization time (ptime) longer than 20 ms are used. This is useful to lower the overall overhead (RTP, UDP, and IP).
7776
* Packet-Loss Concealment (native PLC), see [ASTERISK-25629…](http://issues.asterisk.org/jira/browse/ASTERISK-25629)
7877
* Channel Awareness (RTCP interaction), see [ASTERISK-26584…](http://issues.asterisk.org/jira/browse/ASTERISK-26584)
7978
* Compact Format mode; not sure if that is possible with Asterisk, see `codec_evs.c:evs_sample_counter`

codecs/codec_evs.c

Lines changed: 74 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ struct evs_coder_pvt {
5050
};
5151

5252
static Word16 unpack_bit(UWord8 **pt, UWord8 *mask);
53+
static Word16 rate2AMRWB_IOmode(Word32 rate);
54+
static Word16 rate2EVSmode(Word32 rate);
5355
static short select_mode(short Opt_AMR_WB, short Opt_RF_ON, long total_brate);
5456
static int select_bit_rate(int bit_rate, int max_bandwidth);
5557

@@ -68,6 +70,72 @@ static Word16 unpack_bit(UWord8 **pt, UWord8 *mask)
6870
return bit;
6971
}
7072

73+
static Word16 rate2AMRWB_IOmode(Word32 rate)
74+
{
75+
switch (rate) {
76+
/* EVS AMR-WB IO modes */
77+
case SID_1k75:
78+
return AMRWB_IO_SID;
79+
case ACELP_6k60:
80+
return AMRWB_IO_6600;
81+
case ACELP_8k85:
82+
return AMRWB_IO_8850;
83+
case ACELP_12k65:
84+
return AMRWB_IO_1265;
85+
case ACELP_14k25:
86+
return AMRWB_IO_1425;
87+
case ACELP_15k85:
88+
return AMRWB_IO_1585;
89+
case ACELP_18k25:
90+
return AMRWB_IO_1825;
91+
case ACELP_19k85:
92+
return AMRWB_IO_1985;
93+
case ACELP_23k05:
94+
return AMRWB_IO_2305;
95+
case ACELP_23k85:
96+
return AMRWB_IO_2385;
97+
default:
98+
return -1;
99+
}
100+
}
101+
102+
static Word16 rate2EVSmode(Word32 rate)
103+
{
104+
switch (rate) {
105+
/* EVS Primary modes */
106+
case FRAME_NO_DATA :
107+
return NO_DATA;
108+
case SID_2k40:
109+
return PRIMARY_SID;
110+
case PPP_NELP_2k80:
111+
return PRIMARY_2800;
112+
case ACELP_7k20:
113+
return PRIMARY_7200;
114+
case ACELP_8k00:
115+
return PRIMARY_8000;
116+
case ACELP_9k60:
117+
return PRIMARY_9600;
118+
case ACELP_13k20:
119+
return PRIMARY_13200;
120+
case ACELP_16k40:
121+
return PRIMARY_16400;
122+
case ACELP_24k40:
123+
return PRIMARY_24400;
124+
case ACELP_32k:
125+
return PRIMARY_32000;
126+
case ACELP_48k:
127+
return PRIMARY_48000;
128+
case ACELP_64k:
129+
return PRIMARY_64000;
130+
case HQ_96k:
131+
return PRIMARY_96000;
132+
case HQ_128k:
133+
return PRIMARY_128000;
134+
default:
135+
return rate2AMRWB_IOmode(rate);
136+
}
137+
}
138+
71139
/* Copy & Paste from lib_enc/io_enc.c:io_ini_enc */
72140
static short select_mode(short Opt_AMR_WB, short Opt_RF_ON, long total_brate)
73141
{
@@ -170,9 +238,7 @@ static int lintoevs_new(struct ast_trans_pvt *pvt)
170238
* library "lib_enc/io_enc.c:io_ini_enc" cases:
171239
* 1) st->Opt_SC_VBR && !st->Opt_DTX_ON
172240
* 2) st->total_brate == ACELP_5k90 */
173-
if (0 == bit_rate_evs) {
174-
apvt->encoder->Opt_SC_VBR = 1;
175-
}
241+
apvt->encoder->Opt_SC_VBR = (0 == bit_rate_evs);
176242
if (sample_rate <= 8000 || max_bandwidth == NB) {
177243
apvt->encoder->max_bwidth = NB;
178244
} else if (sample_rate <= 16000 || max_bandwidth == WB || apvt->encoder->Opt_SC_VBR) {
@@ -315,13 +381,10 @@ static struct ast_frame *lintoevs_frameout(struct ast_trans_pvt *pvt)
315381
samples += n_samples;
316382
pvt->samples -= n_samples;
317383

318-
if (apvt->encoder->nb_bits_tot == 0) {
384+
bit_rate = rate2EVSmode(apvt->encoder->nb_bits_tot * 50);
385+
if (bit_rate == NO_DATA) {
319386
continue; /* happens in case of DTX */
320-
} else if (apvt->encoder->nb_bits_tot == 35) {
321-
bit_rate = AMRWB_IO_SID;
322-
} else if (apvt->encoder->nb_bits_tot == 48) {
323-
bit_rate = PRIMARY_SID;
324-
} else if (apvt->encoder->nb_bits_tot < 56) {
387+
} else if (bit_rate < 0) {
325388
ast_log(LOG_ERROR, "Error encoding the 3GPP EVS frame (code: %d)\n", apvt->encoder->nb_bits_tot);
326389
continue;
327390
}
@@ -374,10 +437,8 @@ static struct ast_frame *lintoevs_frameout(struct ast_trans_pvt *pvt)
374437
static int evstolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
375438
{
376439
/* ToDo: 1) Packet-Loss Concealment (PLC)
377-
* 2) SID frames (DTX/VAD/CN) are untested
378-
* 3) SC-VBR is untested
379-
* 4) several frames; currently just one frame
380-
* 5) Compact format; currently only Header-Full format */
440+
* 2) several frames; currently just one frame
441+
* 3) Compact format; currently only Header-Full format */
381442
struct evs_coder_pvt *apvt = pvt->pvt;
382443
const short n_samples = pvt->t->dst_codec.sample_rate / 50;
383444

0 commit comments

Comments
 (0)