Lines Matching +full:- +full:s
2 * Copyright (C) 2011-2013 Michael Niedermayer (michaelni@gmx.at)
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
49 return &LICENSE_PREFIX FFMPEG_LICENSE[sizeof(LICENSE_PREFIX) - 1]; in swresample_license()
52 int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map){ in swr_set_channel_mapping() argument
53 if(!s || s->in_convert) // s needs to be allocated but not initialized in swr_set_channel_mapping()
55 s->channel_map = channel_map; in swr_set_channel_mapping()
59 struct SwrContext *swr_alloc_set_opts(struct SwrContext *s, in swr_alloc_set_opts() argument
63 if(!s) s= swr_alloc(); in swr_alloc_set_opts()
64 if(!s) return NULL; in swr_alloc_set_opts()
66 s->log_level_offset= log_offset; in swr_alloc_set_opts()
67 s->log_ctx= log_ctx; in swr_alloc_set_opts()
69 if (av_opt_set_int(s, "ocl", out_ch_layout, 0) < 0) in swr_alloc_set_opts()
72 if (av_opt_set_int(s, "osf", out_sample_fmt, 0) < 0) in swr_alloc_set_opts()
75 if (av_opt_set_int(s, "osr", out_sample_rate, 0) < 0) in swr_alloc_set_opts()
78 if (av_opt_set_int(s, "icl", in_ch_layout, 0) < 0) in swr_alloc_set_opts()
81 if (av_opt_set_int(s, "isf", in_sample_fmt, 0) < 0) in swr_alloc_set_opts()
84 if (av_opt_set_int(s, "isr", in_sample_rate, 0) < 0) in swr_alloc_set_opts()
87 if (av_opt_set_int(s, "ich", av_get_channel_layout_nb_channels(s-> user_in_ch_layout), 0) < 0) in swr_alloc_set_opts()
90 if (av_opt_set_int(s, "och", av_get_channel_layout_nb_channels(s->user_out_ch_layout), 0) < 0) in swr_alloc_set_opts()
93 av_opt_set_int(s, "uch", 0, 0); in swr_alloc_set_opts()
94 return s; in swr_alloc_set_opts()
96 av_log(s, AV_LOG_ERROR, "Failed to set option\n"); in swr_alloc_set_opts()
97 swr_free(&s); in swr_alloc_set_opts()
102 a->fmt = fmt; in set_audiodata_fmt()
103 a->bps = av_get_bytes_per_sample(fmt); in set_audiodata_fmt()
104 a->planar= av_sample_fmt_is_planar(fmt); in set_audiodata_fmt()
105 if (a->ch_count == 1) in set_audiodata_fmt()
106 a->planar = 1; in set_audiodata_fmt()
110 av_free(a->data); in free_temp()
114 static void clear_context(SwrContext *s){ in clear_context() argument
115 s->in_buffer_index= 0; in clear_context()
116 s->in_buffer_count= 0; in clear_context()
117 s->resample_in_constraint= 0; in clear_context()
118 memset(s->in.ch, 0, sizeof(s->in.ch)); in clear_context()
119 memset(s->out.ch, 0, sizeof(s->out.ch)); in clear_context()
120 free_temp(&s->postin); in clear_context()
121 free_temp(&s->midbuf); in clear_context()
122 free_temp(&s->preout); in clear_context()
123 free_temp(&s->in_buffer); in clear_context()
124 free_temp(&s->silence); in clear_context()
125 free_temp(&s->drop_temp); in clear_context()
126 free_temp(&s->dither.noise); in clear_context()
127 free_temp(&s->dither.temp); in clear_context()
128 swri_audio_convert_free(&s-> in_convert); in clear_context()
129 swri_audio_convert_free(&s->out_convert); in clear_context()
130 swri_audio_convert_free(&s->full_convert); in clear_context()
131 swri_rematrix_free(s); in clear_context()
133 s->delayed_samples_fixup = 0; in clear_context()
134 s->flushed = 0; in clear_context()
138 SwrContext *s= *ss; in swr_free() local
139 if(s){ in swr_free()
140 clear_context(s); in swr_free()
141 if (s->resampler) in swr_free()
142 s->resampler->free(&s->resample); in swr_free()
148 av_cold void swr_close(SwrContext *s){ in swr_close() argument
149 clear_context(s); in swr_close()
152 av_cold int swr_init(struct SwrContext *s){ in swr_init() argument
156 clear_context(s); in swr_init()
158 if(s-> in_sample_fmt >= AV_SAMPLE_FMT_NB){ in swr_init()
159 av_log(s, AV_LOG_ERROR, "Requested input sample format %d is invalid\n", s->in_sample_fmt); in swr_init()
162 if(s->out_sample_fmt >= AV_SAMPLE_FMT_NB){ in swr_init()
163 … av_log(s, AV_LOG_ERROR, "Requested output sample format %d is invalid\n", s->out_sample_fmt); in swr_init()
167 if(s-> in_sample_rate <= 0){ in swr_init()
168 av_log(s, AV_LOG_ERROR, "Requested input sample rate %d is invalid\n", s->in_sample_rate); in swr_init()
171 if(s->out_sample_rate <= 0){ in swr_init()
172 av_log(s, AV_LOG_ERROR, "Requested output sample rate %d is invalid\n", s->out_sample_rate); in swr_init()
175 s->out.ch_count = s-> user_out_ch_count; in swr_init()
176 s-> in.ch_count = s-> user_in_ch_count; in swr_init()
177 s->used_ch_count = s->user_used_ch_count; in swr_init()
179 s-> in_ch_layout = s-> user_in_ch_layout; in swr_init()
180 s->out_ch_layout = s->user_out_ch_layout; in swr_init()
182 s->int_sample_fmt= s->user_int_sample_fmt; in swr_init()
184 s->dither.method = s->user_dither_method; in swr_init()
186 if(av_get_channel_layout_nb_channels(s-> in_ch_layout) > SWR_CH_MAX) { in swr_init()
187 …av_log(s, AV_LOG_WARNING, "Input channel layout 0x%"PRIx64" is invalid or unsupported.\n", s-> in_… in swr_init()
188 s->in_ch_layout = 0; in swr_init()
191 if(av_get_channel_layout_nb_channels(s->out_ch_layout) > SWR_CH_MAX) { in swr_init()
192 …av_log(s, AV_LOG_WARNING, "Output channel layout 0x%"PRIx64" is invalid or unsupported.\n", s->out… in swr_init()
193 s->out_ch_layout = 0; in swr_init()
196 switch(s->engine){ in swr_init()
198 case SWR_ENGINE_SOXR: s->resampler = &swri_soxr_resampler; break; in swr_init()
200 case SWR_ENGINE_SWR : s->resampler = &swri_resampler; break; in swr_init()
202 av_log(s, AV_LOG_ERROR, "Requested resampling engine is unavailable\n"); in swr_init()
206 if(!s->used_ch_count) in swr_init()
207 s->used_ch_count= s->in.ch_count; in swr_init()
209 …if(s->used_ch_count && s-> in_ch_layout && s->used_ch_count != av_get_channel_layout_nb_channels(s… in swr_init()
210 …av_log(s, AV_LOG_WARNING, "Input channel layout has a different number of channels than the number… in swr_init()
211 s-> in_ch_layout= 0; in swr_init()
214 if(!s-> in_ch_layout) in swr_init()
215 s-> in_ch_layout= av_get_default_channel_layout(s->used_ch_count); in swr_init()
216 if(!s->out_ch_layout) in swr_init()
217 s->out_ch_layout= av_get_default_channel_layout(s->out.ch_count); in swr_init()
219 s->rematrix= s->out_ch_layout !=s->in_ch_layout || s->rematrix_volume!=1.0 || in swr_init()
220 s->rematrix_custom; in swr_init()
222 if(s->int_sample_fmt == AV_SAMPLE_FMT_NONE){ in swr_init()
223 if( av_get_bytes_per_sample(s-> in_sample_fmt) <= 2 in swr_init()
224 && av_get_bytes_per_sample(s->out_sample_fmt) <= 2){ in swr_init()
225 s->int_sample_fmt= AV_SAMPLE_FMT_S16P; in swr_init()
226 }else if( av_get_bytes_per_sample(s-> in_sample_fmt) <= 2 in swr_init()
227 && !s->rematrix in swr_init()
228 && s->out_sample_rate==s->in_sample_rate in swr_init()
229 && !(s->flags & SWR_FLAG_RESAMPLE)){ in swr_init()
230 s->int_sample_fmt= AV_SAMPLE_FMT_S16P; in swr_init()
231 }else if( av_get_planar_sample_fmt(s-> in_sample_fmt) == AV_SAMPLE_FMT_S32P in swr_init()
232 && av_get_planar_sample_fmt(s->out_sample_fmt) == AV_SAMPLE_FMT_S32P in swr_init()
233 && !s->rematrix in swr_init()
234 && s->out_sample_rate == s->in_sample_rate in swr_init()
235 && !(s->flags & SWR_FLAG_RESAMPLE) in swr_init()
236 && s->engine != SWR_ENGINE_SOXR){ in swr_init()
237 s->int_sample_fmt= AV_SAMPLE_FMT_S32P; in swr_init()
238 }else if(av_get_bytes_per_sample(s->in_sample_fmt) <= 4){ in swr_init()
239 s->int_sample_fmt= AV_SAMPLE_FMT_FLTP; in swr_init()
241 s->int_sample_fmt= AV_SAMPLE_FMT_DBLP; in swr_init()
244 …av_log(s, AV_LOG_DEBUG, "Using %s internally between filters\n", av_get_sample_fmt_name(s->int_sam… in swr_init()
246 if( s->int_sample_fmt != AV_SAMPLE_FMT_S16P in swr_init()
247 &&s->int_sample_fmt != AV_SAMPLE_FMT_S32P in swr_init()
248 &&s->int_sample_fmt != AV_SAMPLE_FMT_S64P in swr_init()
249 &&s->int_sample_fmt != AV_SAMPLE_FMT_FLTP in swr_init()
250 &&s->int_sample_fmt != AV_SAMPLE_FMT_DBLP){ in swr_init()
251 …_log(s, AV_LOG_ERROR, "Requested sample format %s is not supported internally, s16p/s32p/s64p/fltp… in swr_init()
255 set_audiodata_fmt(&s-> in, s-> in_sample_fmt); in swr_init()
256 set_audiodata_fmt(&s->out, s->out_sample_fmt); in swr_init()
258 if (s->firstpts_in_samples != AV_NOPTS_VALUE) { in swr_init()
259 if (!s->async && s->min_compensation >= FLT_MAX/2) in swr_init()
260 s->async = 1; in swr_init()
261 s->firstpts = in swr_init()
262 s->outpts = s->firstpts_in_samples * s->out_sample_rate; in swr_init()
264 s->firstpts = AV_NOPTS_VALUE; in swr_init()
266 if (s->async) { in swr_init()
267 if (s->min_compensation >= FLT_MAX/2) in swr_init()
268 s->min_compensation = 0.001; in swr_init()
269 if (s->async > 1.0001) { in swr_init()
270 s->max_soft_compensation = s->async / (double) s->in_sample_rate; in swr_init()
274 if (s->out_sample_rate!=s->in_sample_rate || (s->flags & SWR_FLAG_RESAMPLE)){ in swr_init()
275 …s->resample = s->resampler->init(s->resample, s->out_sample_rate, s->in_sample_rate, s->filter_siz… in swr_init()
276 if (!s->resample) { in swr_init()
277 av_log(s, AV_LOG_ERROR, "Failed to initialize resampler\n"); in swr_init()
281 s->resampler->free(&s->resample); in swr_init()
282 if( s->int_sample_fmt != AV_SAMPLE_FMT_S16P in swr_init()
283 && s->int_sample_fmt != AV_SAMPLE_FMT_S32P in swr_init()
284 && s->int_sample_fmt != AV_SAMPLE_FMT_FLTP in swr_init()
285 && s->int_sample_fmt != AV_SAMPLE_FMT_DBLP in swr_init()
286 && s->resample){ in swr_init()
287 av_log(s, AV_LOG_ERROR, "Resampling only supported with internal s16p/s32p/fltp/dblp\n"); in swr_init()
293 if(!s-> in.ch_count) in swr_init()
294 s-> in.ch_count= av_get_channel_layout_nb_channels(s-> in_ch_layout); in swr_init()
295 if(!s->used_ch_count) in swr_init()
296 s->used_ch_count= s->in.ch_count; in swr_init()
297 if(!s->out.ch_count) in swr_init()
298 s->out.ch_count= av_get_channel_layout_nb_channels(s->out_ch_layout); in swr_init()
300 if(!s-> in.ch_count){ in swr_init()
301 av_assert0(!s->in_ch_layout); in swr_init()
302 av_log(s, AV_LOG_ERROR, "Input channel count and layout are unset\n"); in swr_init()
307 av_get_channel_layout_string(l1, sizeof(l1), s-> in.ch_count, s-> in_ch_layout); in swr_init()
308 av_get_channel_layout_string(l2, sizeof(l2), s->out.ch_count, s->out_ch_layout); in swr_init()
309 … if (s->out_ch_layout && s->out.ch_count != av_get_channel_layout_nb_channels(s->out_ch_layout)) { in swr_init()
310 …av_log(s, AV_LOG_ERROR, "Output channel layout %s mismatches specified channel count %d\n", l2, s-… in swr_init()
314 if (s->in_ch_layout && s->used_ch_count != av_get_channel_layout_nb_channels(s->in_ch_layout)) { in swr_init()
315 …av_log(s, AV_LOG_ERROR, "Input channel layout %s mismatches specified channel count %d\n", l1, s->… in swr_init()
320 …if ((!s->out_ch_layout || !s->in_ch_layout) && s->used_ch_count != s->out.ch_count && !s->rematrix… in swr_init()
321 av_log(s, AV_LOG_ERROR, "Rematrix is needed between %s and %s " in swr_init()
327 av_assert0(s->used_ch_count); in swr_init()
328 av_assert0(s->out.ch_count); in swr_init()
329 …s->resample_first= RSC*s->out.ch_count/s->used_ch_count - RSC < s->out_sample_rate/(float)s-> in_s… in swr_init()
331 s->in_buffer= s->in; in swr_init()
332 s->silence = s->in; in swr_init()
333 s->drop_temp= s->out; in swr_init()
335 if ((ret = swri_dither_init(s, s->out_sample_fmt, s->int_sample_fmt)) < 0) in swr_init()
338 if(!s->resample && !s->rematrix && !s->channel_map && !s->dither.method){ in swr_init()
339 s->full_convert = swri_audio_convert_alloc(s->out_sample_fmt, in swr_init()
340 s-> in_sample_fmt, s-> in.ch_count, NULL, 0); in swr_init()
344 s->in_convert = swri_audio_convert_alloc(s->int_sample_fmt, in swr_init()
345 … s-> in_sample_fmt, s->used_ch_count, s->channel_map, 0); in swr_init()
346 s->out_convert= swri_audio_convert_alloc(s->out_sample_fmt, in swr_init()
347 s->int_sample_fmt, s->out.ch_count, NULL, 0); in swr_init()
349 if (!s->in_convert || !s->out_convert) { in swr_init()
354 s->postin= s->in; in swr_init()
355 s->preout= s->out; in swr_init()
356 s->midbuf= s->in; in swr_init()
358 if(s->channel_map){ in swr_init()
359 s->postin.ch_count= in swr_init()
360 s->midbuf.ch_count= s->used_ch_count; in swr_init()
361 if(s->resample) in swr_init()
362 s->in_buffer.ch_count= s->used_ch_count; in swr_init()
364 if(!s->resample_first){ in swr_init()
365 s->midbuf.ch_count= s->out.ch_count; in swr_init()
366 if(s->resample) in swr_init()
367 s->in_buffer.ch_count = s->out.ch_count; in swr_init()
370 set_audiodata_fmt(&s->postin, s->int_sample_fmt); in swr_init()
371 set_audiodata_fmt(&s->midbuf, s->int_sample_fmt); in swr_init()
372 set_audiodata_fmt(&s->preout, s->int_sample_fmt); in swr_init()
374 if(s->resample){ in swr_init()
375 set_audiodata_fmt(&s->in_buffer, s->int_sample_fmt); in swr_init()
378 av_assert0(!s->preout.count); in swr_init()
379 s->dither.noise = s->preout; in swr_init()
380 s->dither.temp = s->preout; in swr_init()
381 if (s->dither.method > SWR_DITHER_NS) { in swr_init()
382 s->dither.noise.bps = 4; in swr_init()
383 s->dither.noise.fmt = AV_SAMPLE_FMT_FLTP; in swr_init()
384 s->dither.noise_scale = 1; in swr_init()
387 if(s->rematrix || s->dither.method) { in swr_init()
388 ret = swri_rematrix_init(s); in swr_init()
395 swr_close(s); in swr_init()
404 if(count < 0 || count > INT_MAX/2/a->bps/a->ch_count) in swri_realloc_audio()
407 if(a->count >= count) in swri_realloc_audio()
412 countb= FFALIGN(count*a->bps, ALIGN); in swri_realloc_audio()
415 av_assert0(a->bps); in swri_realloc_audio()
416 av_assert0(a->ch_count); in swri_realloc_audio()
418 a->data= av_mallocz_array(countb, a->ch_count); in swri_realloc_audio()
419 if(!a->data) in swri_realloc_audio()
421 for(i=0; i<a->ch_count; i++){ in swri_realloc_audio()
422 a->ch[i]= a->data + i*(a->planar ? countb : a->bps); in swri_realloc_audio()
423 if(a->count && a->planar) memcpy(a->ch[i], old.ch[i], a->count*a->bps); in swri_realloc_audio()
425 if(a->count && !a->planar) memcpy(a->ch[0], old.ch[0], a->count*a->ch_count*a->bps); in swri_realloc_audio()
427 a->count= count; in swri_realloc_audio()
434 av_assert0(out->planar == in->planar); in copy()
435 av_assert0(out->bps == in->bps); in copy()
436 av_assert0(out->ch_count == in->ch_count); in copy()
437 if(out->planar){ in copy()
439 for(ch=0; ch<out->ch_count; ch++) in copy()
440 memcpy(out->ch[ch], in->ch[ch], count*out->bps); in copy()
442 memcpy(out->ch[0], in->ch[0], count*out->ch_count*out->bps); in copy()
448 memset(out->ch, 0, sizeof(out->ch)); in fill_audiodata()
449 }else if(out->planar){ in fill_audiodata()
450 for(i=0; i<out->ch_count; i++) in fill_audiodata()
451 out->ch[i]= in_arg[i]; in fill_audiodata()
453 for(i=0; i<out->ch_count; i++) in fill_audiodata()
454 out->ch[i]= in_arg[0] + i*out->bps; in fill_audiodata()
460 if(out->planar){ in reversefill_audiodata()
461 for(i=0; i<out->ch_count; i++) in reversefill_audiodata()
462 in_arg[i]= out->ch[i]; in reversefill_audiodata()
464 in_arg[0]= out->ch[0]; in reversefill_audiodata()
474 if(in->planar){ in buf_set()
475 for(ch=0; ch<out->ch_count; ch++) in buf_set()
476 out->ch[ch]= in->ch[ch] + count*out->bps; in buf_set()
478 for(ch=out->ch_count-1; ch>=0; ch--) in buf_set()
479 out->ch[ch]= in->ch[0] + (ch + count*out->ch_count) * out->bps; in buf_set()
487 static int resample(SwrContext *s, AudioData *out_param, int out_count, in resample() argument
492 int padless = ARCH_X86 && s->engine == SWR_ENGINE_SWR ? 7 : 0; in resample()
494 av_assert1(s->in_buffer.ch_count == in_param->ch_count); in resample()
495 av_assert1(s->in_buffer.planar == in_param->planar); in resample()
496 av_assert1(s->in_buffer.fmt == in_param->fmt); in resample()
501 border = s->resampler->invert_initial_buffer(s->resample, &s->in_buffer, in resample()
502 &in, in_count, &s->in_buffer_index, &s->in_buffer_count); in resample()
509 in_count -= border; in resample()
510 s->resample_in_constraint = 0; in resample()
515 if(!s->resample_in_constraint && s->in_buffer_count){ in resample()
516 buf_set(&tmp, &s->in_buffer, s->in_buffer_index); in resample()
517 …ret= s->resampler->multiple_resample(s->resample, &out, out_count, &tmp, s->in_buffer_count, &cons… in resample()
518 out_count -= ret; in resample()
521 s->in_buffer_count -= consumed; in resample()
522 s->in_buffer_index += consumed; in resample()
526 if(s->in_buffer_count <= border){ in resample()
527 buf_set(&in, &in, -s->in_buffer_count); in resample()
528 in_count += s->in_buffer_count; in resample()
529 s->in_buffer_count=0; in resample()
530 s->in_buffer_index=0; in resample()
535 if((s->flushed || in_count > padless) && !s->in_buffer_count){ in resample()
536 s->in_buffer_index=0; in resample()
537 …ret= s->resampler->multiple_resample(s->resample, &out, out_count, &in, FFMAX(in_count-padless, 0)… in resample()
538 out_count -= ret; in resample()
541 in_count -= consumed; in resample()
546 size= s->in_buffer_index + s->in_buffer_count + in_count; in resample()
547 if( size > s->in_buffer.count in resample()
548 && s->in_buffer_count + in_count <= s->in_buffer_index){ in resample()
549 buf_set(&tmp, &s->in_buffer, s->in_buffer_index); in resample()
550 copy(&s->in_buffer, &tmp, s->in_buffer_count); in resample()
551 s->in_buffer_index=0; in resample()
553 if((ret=swri_realloc_audio(&s->in_buffer, size)) < 0) in resample()
558 … if(s->in_buffer_count && s->in_buffer_count+2 < count && out_count) count= s->in_buffer_count+2; in resample()
560 buf_set(&tmp, &s->in_buffer, s->in_buffer_index + s->in_buffer_count); in resample()
562 s->in_buffer_count += count; in resample()
563 in_count -= count; in resample()
566 s->resample_in_constraint= 0; in resample()
567 if(s->in_buffer_count != count || in_count) in resample()
577 s->resample_in_constraint= !!out_count; in resample()
582 static int swr_convert_internal(struct SwrContext *s, AudioData *out, int out_count, in swr_convert_internal() argument
588 if(s->full_convert){ in swr_convert_internal()
589 av_assert0(!s->resample); in swr_convert_internal()
590 swri_audio_convert(s->full_convert, out, in, in_count); in swr_convert_internal()
594 // in_max= out_count*(int64_t)s->in_sample_rate / s->out_sample_rate + resample_filter_taps; in swr_convert_internal()
595 // in_count= FFMIN(in_count, in_in + 2 - s->hist_buffer_count); in swr_convert_internal()
597 if((ret=swri_realloc_audio(&s->postin, in_count))<0) in swr_convert_internal()
599 if(s->resample_first){ in swr_convert_internal()
600 av_assert0(s->midbuf.ch_count == s->used_ch_count); in swr_convert_internal()
601 if((ret=swri_realloc_audio(&s->midbuf, out_count))<0) in swr_convert_internal()
604 av_assert0(s->midbuf.ch_count == s->out.ch_count); in swr_convert_internal()
605 if((ret=swri_realloc_audio(&s->midbuf, in_count))<0) in swr_convert_internal()
608 if((ret=swri_realloc_audio(&s->preout, out_count))<0) in swr_convert_internal()
611 postin= &s->postin; in swr_convert_internal()
613 midbuf_tmp= s->midbuf; in swr_convert_internal()
615 preout_tmp= s->preout; in swr_convert_internal()
618 if(s->int_sample_fmt == s-> in_sample_fmt && s->in.planar && !s->channel_map) in swr_convert_internal()
621 if(s->resample_first ? !s->resample : !s->rematrix) in swr_convert_internal()
624 if(s->resample_first ? !s->rematrix : !s->resample) in swr_convert_internal()
627 if(s->int_sample_fmt == s->out_sample_fmt && s->out.planar in swr_convert_internal()
628 && !(s->out_sample_fmt==AV_SAMPLE_FMT_S32P && (s->dither.output_sample_bits&31))){ in swr_convert_internal()
631 …av_assert0(s->in.planar); //we only support planar internally so it has to be, we support copying … in swr_convert_internal()
641 swri_audio_convert(s->in_convert, postin, in, in_count); in swr_convert_internal()
644 if(s->resample_first){ in swr_convert_internal()
646 out_count= resample(s, midbuf, out_count, postin, in_count); in swr_convert_internal()
648 swri_rematrix(s, preout, midbuf, out_count, preout==out); in swr_convert_internal()
651 swri_rematrix(s, midbuf, postin, in_count, midbuf==out); in swr_convert_internal()
653 out_count= resample(s, preout, out_count, midbuf, in_count); in swr_convert_internal()
658 if(s->dither.method){ in swr_convert_internal()
663 conv_src = &s->dither.temp; in swr_convert_internal()
664 if((ret=swri_realloc_audio(&s->dither.temp, dither_count))<0) in swr_convert_internal()
668 if((ret=swri_realloc_audio(&s->dither.noise, dither_count))<0) in swr_convert_internal()
671 for(ch=0; ch<s->dither.noise.ch_count; ch++) in swr_convert_internal()
672 …if((ret=swri_get_dither(s, s->dither.noise.ch[ch], s->dither.noise.count, (12345678913579ULL*ch + … in swr_convert_internal()
674 av_assert0(s->dither.noise.ch_count == preout->ch_count); in swr_convert_internal()
676 if(s->dither.noise_pos + out_count > s->dither.noise.count) in swr_convert_internal()
677 s->dither.noise_pos = 0; in swr_convert_internal()
679 if (s->dither.method < SWR_DITHER_NS){ in swr_convert_internal()
680 if (s->mix_2_1_simd) { in swr_convert_internal()
682 int off = len1 * preout->bps; in swr_convert_internal()
685 for(ch=0; ch<preout->ch_count; ch++) in swr_convert_internal()
686 …s->mix_2_1_simd(conv_src->ch[ch], preout->ch[ch], s->dither.noise.ch[ch] + s->dither.noise.bps * s… in swr_convert_internal()
688 for(ch=0; ch<preout->ch_count; ch++) in swr_convert_internal()
689 …s->mix_2_1_f(conv_src->ch[ch] + off, preout->ch[ch] + off, s->dither.noise.ch[ch] + s->dither.nois… in swr_convert_internal()
691 for(ch=0; ch<preout->ch_count; ch++) in swr_convert_internal()
692 …s->mix_2_1_f(conv_src->ch[ch], preout->ch[ch], s->dither.noise.ch[ch] + s->dither.noise.bps * s->d… in swr_convert_internal()
695 switch(s->int_sample_fmt) { in swr_convert_internal()
696 …case AV_SAMPLE_FMT_S16P :swri_noise_shaping_int16(s, conv_src, preout, &s->dither.noise, out_count… in swr_convert_internal()
697 …case AV_SAMPLE_FMT_S32P :swri_noise_shaping_int32(s, conv_src, preout, &s->dither.noise, out_count… in swr_convert_internal()
698 …case AV_SAMPLE_FMT_FLTP :swri_noise_shaping_float(s, conv_src, preout, &s->dither.noise, out_count… in swr_convert_internal()
699 …case AV_SAMPLE_FMT_DBLP :swri_noise_shaping_double(s,conv_src, preout, &s->dither.noise, out_count… in swr_convert_internal()
702 s->dither.noise_pos += out_count; in swr_convert_internal()
705 swri_audio_convert(s->out_convert, out, conv_src, out_count); in swr_convert_internal()
710 int swr_is_initialized(struct SwrContext *s) { in swr_is_initialized() argument
711 return !!s->in_buffer.ch_count; in swr_is_initialized()
714 int attribute_align_arg swr_convert(struct SwrContext *s, uint8_t *out_arg[SWR_CH_MAX], int out_cou… in swr_convert() argument
716 AudioData * in= &s->in; in swr_convert()
717 AudioData *out= &s->out; in swr_convert()
720 if (!swr_is_initialized(s)) { in swr_convert()
721 av_log(s, AV_LOG_ERROR, "Context has not been initialized\n"); in swr_convert()
725 max_output = swr_get_out_samples(s, in_count); in swr_convert()
728 while(s->drop_output > 0){ in swr_convert()
732 if((ret=swri_realloc_audio(&s->drop_temp, FFMIN(s->drop_output, MAX_DROP_STEP)))<0) in swr_convert()
735 reversefill_audiodata(&s->drop_temp, tmp_arg); in swr_convert()
736 s->drop_output *= -1; //FIXME find a less hackish solution in swr_convert()
737 …ret = swr_convert(s, tmp_arg, FFMIN(-s->drop_output, MAX_DROP_STEP), in_arg, in_count); //FIXME op… in swr_convert()
738 s->drop_output *= -1; in swr_convert()
741 s->drop_output -= ret; in swr_convert()
742 if (!s->drop_output && !out_arg) in swr_convert()
747 av_assert0(s->drop_output); in swr_convert()
752 if(s->resample){ in swr_convert()
753 if (!s->flushed) in swr_convert()
754 s->resampler->flush(s); in swr_convert()
755 s->resample_in_constraint = 0; in swr_convert()
756 s->flushed = 1; in swr_convert()
757 }else if(!s->in_buffer_count){ in swr_convert()
765 if(s->resample){ in swr_convert()
766 int ret = swr_convert_internal(s, out, out_count, in, in_count); in swr_convert()
767 if(ret>0 && !s->drop_output) in swr_convert()
768 s->outpts += ret * (int64_t)s->in_sample_rate; in swr_convert()
777 size = FFMIN(out_count, s->in_buffer_count); in swr_convert()
779 buf_set(&tmp, &s->in_buffer, s->in_buffer_index); in swr_convert()
780 ret= swr_convert_internal(s, out, size, &tmp, size); in swr_convert()
784 s->in_buffer_count -= ret; in swr_convert()
785 s->in_buffer_index += ret; in swr_convert()
787 out_count -= ret; in swr_convert()
788 if(!s->in_buffer_count) in swr_convert()
789 s->in_buffer_index = 0; in swr_convert()
793 size= s->in_buffer_index + s->in_buffer_count + in_count - out_count; in swr_convert()
796 if( size > s->in_buffer.count in swr_convert()
797 && s->in_buffer_count + in_count - out_count <= s->in_buffer_index){ in swr_convert()
798 buf_set(&tmp, &s->in_buffer, s->in_buffer_index); in swr_convert()
799 copy(&s->in_buffer, &tmp, s->in_buffer_count); in swr_convert()
800 s->in_buffer_index=0; in swr_convert()
802 if((ret=swri_realloc_audio(&s->in_buffer, size)) < 0) in swr_convert()
808 ret= swr_convert_internal(s, out, size, in, size); in swr_convert()
812 in_count -= ret; in swr_convert()
816 buf_set(&tmp, &s->in_buffer, s->in_buffer_index + s->in_buffer_count); in swr_convert()
818 s->in_buffer_count += in_count; in swr_convert()
821 if(ret2>0 && !s->drop_output) in swr_convert()
822 s->outpts += ret2 * (int64_t)s->in_sample_rate; in swr_convert()
828 int swr_drop_output(struct SwrContext *s, int count){ in swr_drop_output() argument
830 s->drop_output += count; in swr_drop_output()
832 if(s->drop_output <= 0) in swr_drop_output()
835 av_log(s, AV_LOG_VERBOSE, "discarding %d audio samples\n", count); in swr_drop_output()
836 return swr_convert(s, NULL, s->drop_output, tmp_arg, 0); in swr_drop_output()
839 int swr_inject_silence(struct SwrContext *s, int count){ in swr_inject_silence() argument
848 if ((ret = swr_inject_silence(s, MAX_SILENCE_STEP)) < 0) in swr_inject_silence()
850 count -= MAX_SILENCE_STEP; in swr_inject_silence()
853 if((ret=swri_realloc_audio(&s->silence, count))<0) in swr_inject_silence()
856 if(s->silence.planar) for(i=0; i<s->silence.ch_count; i++) { in swr_inject_silence()
857 memset(s->silence.ch[i], s->silence.bps==1 ? 0x80 : 0, count*s->silence.bps); in swr_inject_silence()
859 … memset(s->silence.ch[0], s->silence.bps==1 ? 0x80 : 0, count*s->silence.bps*s->silence.ch_count); in swr_inject_silence()
861 reversefill_audiodata(&s->silence, tmp_arg); in swr_inject_silence()
862 av_log(s, AV_LOG_VERBOSE, "adding %d audio samples of silence\n", count); in swr_inject_silence()
863 ret = swr_convert(s, NULL, 0, (const uint8_t**)tmp_arg, count); in swr_inject_silence()
867 int64_t swr_get_delay(struct SwrContext *s, int64_t base){ in swr_get_delay() argument
868 if (s->resampler && s->resample){ in swr_get_delay()
869 return s->resampler->get_delay(s, base); in swr_get_delay()
871 return (s->in_buffer_count*base + (s->in_sample_rate>>1))/ s->in_sample_rate; in swr_get_delay()
875 int swr_get_out_samples(struct SwrContext *s, int in_samples) in swr_get_out_samples() argument
882 if (s->resampler && s->resample) { in swr_get_out_samples()
883 if (!s->resampler->get_out_samples) in swr_get_out_samples()
885 out_samples = s->resampler->get_out_samples(s, in_samples); in swr_get_out_samples()
887 out_samples = s->in_buffer_count + in_samples; in swr_get_out_samples()
888 av_assert0(s->out_sample_rate == s->in_sample_rate); in swr_get_out_samples()
897 int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensation_distance){ in swr_set_compensation() argument
900 if (!s || compensation_distance < 0) in swr_set_compensation()
904 if (!s->resample) { in swr_set_compensation()
905 s->flags |= SWR_FLAG_RESAMPLE; in swr_set_compensation()
906 ret = swr_init(s); in swr_set_compensation()
910 if (!s->resampler->set_compensation){ in swr_set_compensation()
913 return s->resampler->set_compensation(s->resample, sample_delta, compensation_distance); in swr_set_compensation()
917 int64_t swr_next_pts(struct SwrContext *s, int64_t pts){ in swr_next_pts() argument
919 return s->outpts; in swr_next_pts()
921 if (s->firstpts == AV_NOPTS_VALUE) in swr_next_pts()
922 s->outpts = s->firstpts = pts; in swr_next_pts()
924 if(s->min_compensation >= FLT_MAX) { in swr_next_pts()
925 … return (s->outpts = pts - swr_get_delay(s, s->in_sample_rate * (int64_t)s->out_sample_rate)); in swr_next_pts()
927 …int64_t delta = pts - swr_get_delay(s, s->in_sample_rate * (int64_t)s->out_sample_rate) - s->outpt… in swr_next_pts()
928 double fdelta = delta /(double)(s->in_sample_rate * (int64_t)s->out_sample_rate); in swr_next_pts()
930 if(fabs(fdelta) > s->min_compensation) { in swr_next_pts()
931 if(s->outpts == s->firstpts || fabs(fdelta) > s->min_hard_compensation){ in swr_next_pts()
933 if(delta > 0) ret = swr_inject_silence(s, delta / s->out_sample_rate); in swr_next_pts()
934 else ret = swr_drop_output (s, -delta / s-> in_sample_rate); in swr_next_pts()
936 … av_log(s, AV_LOG_ERROR, "Failed to compensate for timestamp delta of %f\n", fdelta); in swr_next_pts()
938 } else if(s->soft_compensation_duration && s->max_soft_compensation) { in swr_next_pts()
939 int duration = s->out_sample_rate * s->soft_compensation_duration; in swr_next_pts()
940 …double max_soft_compensation = s->max_soft_compensation / (s->max_soft_compensation < 0 ? -s->in_s… in swr_next_pts()
941 … int comp = av_clipf(fdelta, -max_soft_compensation, max_soft_compensation) * duration ; in swr_next_pts()
942 …av_log(s, AV_LOG_VERBOSE, "compensating audio timestamp drift:%f compensation:%d in:%d\n", fdelta,… in swr_next_pts()
943 swr_set_compensation(s, comp, duration); in swr_next_pts()
947 return s->outpts; in swr_next_pts()