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

Side by Side Diff: webrtc/modules/audio_coding/codecs/opus/opus/src/doc/draft-ietf-codec-opus-update.xml

Issue 1612443002: Create local copy of Opus v1.1.2 Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: testing if neteq4_opus_network_stats.dat.sha1 needs to be updated Created 4 years, 10 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
OLDNEW
(Empty)
1 <?xml version="1.0" encoding="US-ASCII"?>
2 <!DOCTYPE rfc SYSTEM "rfc2629.dtd">
3 <?rfc toc="yes"?>
4 <?rfc tocompact="yes"?>
5 <?rfc tocdepth="3"?>
6 <?rfc tocindent="yes"?>
7 <?rfc symrefs="yes"?>
8 <?rfc sortrefs="yes"?>
9 <?rfc comments="yes"?>
10 <?rfc inline="yes"?>
11 <?rfc compact="yes"?>
12 <?rfc subcompact="no"?>
13 <rfc category="std" docName="draft-ietf-codec-opus-update-01"
14 ipr="trust200902">
15 <front>
16 <title abbrev="Opus Update">Updates to the Opus Audio Codec</title>
17
18 <author initials="JM" surname="Valin" fullname="Jean-Marc Valin">
19 <organization>Mozilla Corporation</organization>
20 <address>
21 <postal>
22 <street>331 E. Evelyn Avenue</street>
23 <city>Mountain View</city>
24 <region>CA</region>
25 <code>94041</code>
26 <country>USA</country>
27 </postal>
28 <phone>+1 650 903-0800</phone>
29 <email>jmvalin@jmvalin.ca</email>
30 </address>
31 </author>
32
33 <author initials="K." surname="Vos" fullname="Koen Vos">
34 <organization>vocTone</organization>
35 <address>
36 <postal>
37 <street></street>
38 <city></city>
39 <region></region>
40 <code></code>
41 <country></country>
42 </postal>
43 <phone></phone>
44 <email>koenvos74@gmail.com</email>
45 </address>
46 </author>
47
48
49
50 <date day="4" month="September" year="2014" />
51
52 <abstract>
53 <t>This document addresses minor issues that were found in the specificati on
54 of the Opus audio codec in <xref target="RFC6716">RFC 6716</xref>.</t>
55 </abstract>
56 </front>
57
58 <middle>
59 <section title="Introduction">
60 <t>This document addresses minor issues that were discovered in the refere nce
61 implementation of the Opus codec that serves as the specification in
62 <xref target="RFC6716">RFC 6716</xref>. Only issues affecting the decoder are
63 listed here. An up-to-date implementation of the Opus encoder can be found at
64 http://opus-codec.org/. The updated specification remains fully compatible with
65 the original specification and only one of the changes results in any diff erence
66 in the audio output.
67 </t>
68 </section>
69
70 <section title="Terminology">
71 <t>The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
72 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
73 document are to be interpreted as described in <xref
74 target="RFC2119">RFC 2119</xref>.</t>
75 </section>
76
77 <section title="Stereo State Reset in SILK">
78 <t>The reference implementation does not reinitialize the stereo state
79 during a mode switch. The old stereo memory can produce a brief impulse
80 (i.e. single sample) in the decoded audio. This can be fixed by changing
81 silk/dec_API.c at line 72:
82 <figure>
83 <artwork><![CDATA[
84 for( n = 0; n < DECODER_NUM_CHANNELS; n++ ) {
85 ret = silk_init_decoder( &channel_state[ n ] );
86 }
87 + silk_memset(&((silk_decoder *)decState)->sStereo, 0,
88 + sizeof(((silk_decoder *)decState)->sStereo));
89 + /* Not strictly needed, but it's cleaner that way */
90 + ((silk_decoder *)decState)->prev_decode_only_middle = 0;
91
92 return ret;
93 }
94 ]]></artwork>
95 </figure>
96 This change affects the normative part of the decoder. Fortunately,
97 the modified decoder is still compliant with the original specification bec ause
98 it still easily passes the testvectors. For example, for the float decoder
99 at 48 kHz, the opus_compare (arbitrary) "quality score" changes from
100 from 99.9333% to 99.925%.
101 </t>
102 </section>
103
104 <section anchor="padding" title="Parsing of the Opus Packet Padding">
105 <t>It was discovered that some invalid packets of very large size could tr igger
106 an out-of-bounds read in the Opus packet parsing code responsible for padd ing.
107 This is due to an integer overflow if the signaled padding exceeds 2^31-1 bytes
108 (the actual packet may be smaller). The code can be fixed by applying the following
109 changes at line 596 of src/opus_decoder.c:
110 <figure>
111 <artwork><![CDATA[
112 /* Padding flag is bit 6 */
113 if (ch&0x40)
114 {
115 - int padding=0;
116 int p;
117 do {
118 if (len<=0)
119 return OPUS_INVALID_PACKET;
120 p = *data++;
121 len--;
122 - padding += p==255 ? 254: p;
123 + len -= p==255 ? 254: p;
124 } while (p==255);
125 - len -= padding;
126 }
127 ]]></artwork>
128 </figure>
129 </t>
130 <t>This packet parsing issue is limited to reading memory up
131 to about 60 kB beyond the compressed buffer. This can only be triggered
132 by a compressed packet more than about 16 MB long, so it's not a proble m
133 for RTP. In theory, it <spanx style="emph">could</spanx> crash a file
134 decoder (e.g. Opus in Ogg) if the memory just after the incoming packet
135 is out-of-range, but our attempts to trigger such a crash in a producti on
136 application built using an affected version of the Opus decoder failed. </t>
137 </section>
138
139 <section anchor="resampler" title="Resampler buffer">
140 <t>The SILK resampler had the following issues:
141 <list style="numbers">
142 <t>The calls to memcpy() were using sizeof(opus_int32), but the type of the
143 local buffer was opus_int16.</t>
144 <t>Because the size was wrong, this potentially allowed the source
145 and destination regions of the memcpy() to overlap.
146 We <spanx style="emph">believe</spanx> that nSamplesIn is at least fs_ in_khZ,
147 which is at least 8.
148 Since RESAMPLER_ORDER_FIR_12 is only 8, that should not be a problem once
149 the type size is fixed.</t>
150 <t>The size of the buffer used RESAMPLER_MAX_BATCH_SIZE_IN, but the
151 data stored in it was actually _twice_ the input batch size
152 (nSamplesIn&lt;&lt;1).</t>
153 </list></t>
154 <t>
155 The fact that the code never produced any error in testing (including when run under the
156 Valgrind memory debugger), suggests that in practice
157 the batch sizes are reasonable enough that none of the issues above
158 was ever a problem. However, proving that is non-obvious.
159 </t>
160 <t>The code can be fixed by applying the following changes to line 70 of sil k/resampler_private_IIR_FIR.c:
161 <figure>
162 <artwork><![CDATA[
163 )
164 {
165 silk_resampler_state_struct *S = \
166 (silk_resampler_state_struct *)SS;
167 opus_int32 nSamplesIn;
168 opus_int32 max_index_Q16, index_increment_Q16;
169 - opus_int16 buf[ RESAMPLER_MAX_BATCH_SIZE_IN + \
170 RESAMPLER_ORDER_FIR_12 ];
171 + opus_int16 buf[ 2*RESAMPLER_MAX_BATCH_SIZE_IN + \
172 RESAMPLER_ORDER_FIR_12 ];
173
174 /* Copy buffered samples to start of buffer */
175 - silk_memcpy( buf, S->sFIR, RESAMPLER_ORDER_FIR_12 \
176 * sizeof( opus_int32 ) );
177 + silk_memcpy( buf, S->sFIR, RESAMPLER_ORDER_FIR_12 \
178 * sizeof( opus_int16 ) );
179
180 /* Iterate over blocks of frameSizeIn input samples */
181 index_increment_Q16 = S->invRatio_Q16;
182 while( 1 ) {
183 nSamplesIn = silk_min( inLen, S->batchSize );
184
185 /* Upsample 2x */
186 silk_resampler_private_up2_HQ( S->sIIR, &buf[ \
187 RESAMPLER_ORDER_FIR_12 ], in, nSamplesIn );
188
189 max_index_Q16 = silk_LSHIFT32( nSamplesIn, 16 + 1 \
190 ); /* + 1 because 2x upsampling */
191 out = silk_resampler_private_IIR_FIR_INTERPOL( out, \
192 buf, max_index_Q16, index_increment_Q16 );
193 in += nSamplesIn;
194 inLen -= nSamplesIn;
195
196 if( inLen > 0 ) {
197 /* More iterations to do; copy last part of \
198 filtered signal to beginning of buffer */
199 - silk_memcpy( buf, &buf[ nSamplesIn << 1 ], \
200 RESAMPLER_ORDER_FIR_12 * sizeof( opus_int32 ) );
201 + silk_memmove( buf, &buf[ nSamplesIn << 1 ], \
202 RESAMPLER_ORDER_FIR_12 * sizeof( opus_int16 ) );
203 } else {
204 break;
205 }
206 }
207
208 /* Copy last part of filtered signal to the state for \
209 the next call */
210 - silk_memcpy( S->sFIR, &buf[ nSamplesIn << 1 ], \
211 RESAMPLER_ORDER_FIR_12 * sizeof( opus_int32 ) );
212 + silk_memcpy( S->sFIR, &buf[ nSamplesIn << 1 ], \
213 RESAMPLER_ORDER_FIR_12 * sizeof( opus_int16 ) );
214 }
215 ]]></artwork>
216 </figure>
217 Note: due to RFC formatting conventions, lines exceeding the column width
218 in the patch above are split using a backslash character. The backslashes
219 at the end of a line and the white space at the beginning
220 of the following line are not part of the patch. A properly formatted patch
221 including the three changes above is available at
222 <eref target="http://jmvalin.ca/misc_stuff/opus_update.patch"/>.
223 </t>
224 </section>
225
226 <section title="Downmix to Mono">
227 <t>The last issue is not strictly a bug, but it is an issue that has been reported
228 when downmixing an Opus decoded stream to mono, whether this is done insid e the decoder
229 or as a post-processing step on the stereo decoder output. Opus intensity stereo allows
230 optionally coding the two channels 180-degrees out of phase on a per-band basis.
231 This provides better stereo quality than forcing the two channels to be in phase,
232 but when the output is downmixed to mono, the energy in the affected bands is cancelled
233 sometimes resulting in audible artefacts.
234 </t>
235 <t>As a work-around for this issue, the decoder MAY choose not to apply th e 180-degree
236 phase shift when the output is meant to be downmixed (inside or
237 outside of the decoder).
238 </t>
239 </section>
240 <section anchor="IANA" title="IANA Considerations">
241 <t>This document makes no request of IANA.</t>
242
243 <t>Note to RFC Editor: this section may be removed on publication as an
244 RFC.</t>
245 </section>
246
247 <section anchor="Acknowledgements" title="Acknowledgements">
248 <t>We would like to thank Juri Aedla for reporting the issue with the pars ing of
249 the Opus padding.</t>
250 </section>
251 </middle>
252
253 <back>
254 <references title="References">
255 <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.211 9.xml"?>
256 <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.671 6.xml"?>
257
258
259 </references>
260 </back>
261 </rfc>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698