1 /*
2 * Copyright (C) 2011-2013 Michael Niedermayer (michaelni@gmx.at)
3 *
4 * This file is part of libswresample
5 *
6 * libswresample is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * libswresample is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with libswresample; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
26
28
30
32 {
35 }
36
38 {
39 return FFMPEG_CONFIGURATION;
40 }
41
43 {
44 #define LICENSE_PREFIX "libswresample license: "
46 }
47
49 if(!s || s->
in_convert)
// s needs to be allocated but not initialized
52 return 0;
53 }
54
60 if(!s) return NULL;
61
64
76 }
77
82 }
83
86 memset(a, 0, sizeof(*a));
87 }
88
93 memset(s->
in.
ch, 0,
sizeof(s->
in.
ch));
107
109 }
110
113 if(s){
117 }
118
120 }
121
124 }
125
128
130
134 }
138 }
139
143 }
144
148 }
149
151 #if CONFIG_LIBSOXR
152 extern struct Resampler const soxr_resampler;
154 #endif
156 default:
159 }
160
163
165 av_log(s,
AV_LOG_WARNING,
"Input channel layout has a different number of channels than the number of used channels, ignoring layout\n");
166 s-> in_ch_layout= 0;
167 }
168
169 if(!s-> in_ch_layout)
173
176
187 }else{
190 }
191 }
192
199 }
200
203
209 } else
211
215 if (s->
async > 1.0001) {
217 }
218 }
219
221 s->
resample = s->
resampler->
init(s->
resample, s->
out_sample_rate, s->
in_sample_rate, s->
filter_size, s->
phase_shift, s->
linear_interp, s->
cutoff, s->
int_sample_fmt, s->
filter_type, s->
kaiser_beta, s->
precision, s->
cheby);
222 }else
230 return -1;
231 }
232
233 #define RSC 1 //FIXME finetune
240
241 if(!s->
in.ch_count){
244 return -1;
245 }
246
248 char l1[1024], l2[1024];
252 "but there is not enough information to do it\n", l1, l2);
253 return -1;
254 }
255
259
263
266 s-> in_sample_fmt, s->
in.ch_count, NULL, 0);
267 return 0;
268 }
269
274
277
281
287 }
292 }
293
297
300 }
301
304
307
308 return 0;
309 }
310
312 int i, countb;
314
317
318 if(a->
count >= count)
319 return 0;
320
321 count*=2;
322
325
328
335 }
339
340 return 1;
341 }
342
349 int ch;
351 memcpy(out->
ch[ch], in->
ch[ch], count*out->
bps);
352 }else
354 }
355
357 int i;
358 if(!in_arg){
359 memset(out->
ch, 0,
sizeof(out->
ch));
362 out->
ch[i]= in_arg[i];
363 }else{
365 out->
ch[i]= in_arg[0] + i*out->
bps;
366 }
367 }
368
370 int i;
373 in_arg[i]= out->
ch[i];
374 }else{
375 in_arg[0]= out->
ch[0];
376 }
377 }
378
379 /**
380 *
381 * out may be equal in.
382 */
384 int ch;
387 out->
ch[ch]= in->
ch[ch] + count*out->
bps;
388 }else{
389 for(ch=out->
ch_count-1; ch>=0; ch--)
391 }
392 }
393
394 /**
395 *
396 * @return number of samples output per channel
397 */
399 const AudioData * in_param,
int in_count){
401 int ret_sum=0;
402 int border=0;
404
408
409 tmp=out=*out_param;
410 in = *in_param;
411
414 if (border == INT_MAX) return 0;
415 else if (border < 0) return border;
417
418 do{
428
429 if(!in_count)
430 break;
436 border = 0;
437 }
438 }
439
446 in_count -= consumed;
448 }
449
450 //TODO is this check sane considering the advanced copy avoidance below
457 }else
460
461 if(in_count){
464
466 copy(&tmp, &in,
/*in_*/count);
473 continue;
474 if (padless) {
475 padless = 0;
476 continue;
477 }
478 }
479 break;
480 }while(1);
481
483
484 return ret_sum;
485 }
486
490 int ret /*, in_max*/;
492
496 return out_count;
497 }
498
499 // in_max= out_count*(int64_t)s->in_sample_rate / s->out_sample_rate + resample_filter_taps;
500 // in_count= FFMIN(in_count, in_in + 2 - s->hist_buffer_count);
501
508 }else{
512 }
515
517
519 midbuf= &midbuf_tmp;
521 preout= &preout_tmp;
522
525
527 midbuf= postin;
528
530 preout= midbuf;
531
534 if(preout==in){
535 out_count=
FFMIN(out_count, in_count);
//TODO check at the end if this is needed or redundant
536 av_assert0(s->
in.
planar);
//we only support planar internally so it has to be, we support copying non planar though
537 copy(out, in, out_count);
538 return out_count;
539 }
540 else if(preout==postin) preout= midbuf= postin=
out;
541 else if(preout==midbuf) preout= midbuf=
out;
543 }
544
545 if(in != postin){
547 }
548
550 if(postin != midbuf)
551 out_count=
resample(s, midbuf, out_count, postin, in_count);
552 if(midbuf != preout)
554 }else{
555 if(postin != midbuf)
557 if(midbuf != preout)
558 out_count=
resample(s, preout, out_count, midbuf, in_count);
559 }
560
561 if(preout != out && out_count){
564 int ch;
565 int dither_count=
FFMAX(out_count, 1<<16);
566
567 if (preout == in) {
571 }
572
575 if(ret)
579
582
585 int len1= out_count&~15;
586 int off = len1 * preout->
bps;
587
588 if(len1)
589 for(ch=0; ch<preout->
ch_count; ch++)
591 if(out_count != len1)
592 for(ch=0; ch<preout->
ch_count; ch++)
594 } else {
595 for(ch=0; ch<preout->
ch_count; ch++)
597 }
598 } else {
604 }
605 }
607 }
608 //FIXME packed doesn't need more than 1 chan here!
610 }
611 return out_count;
612 }
613
616 }
617
619 const uint8_t *in_arg [SWR_CH_MAX],
int in_count){
622
626 }
627
631 #define MAX_DROP_STEP 16384
634
636 s->
drop_output *= -1;
//FIXME find a less hackish solution
639 in_count = 0;
640 if(ret>0) {
642 continue;
643 }
644
646 return 0;
647 }
648
649 if(!in_arg){
656 return 0;
657 }
658 }else
660
662
667 return ret;
668 }else{
670 int ret2=0;
673 if(size){
676 if(ret<0)
685 }
686
687 if(in_count){
689
690 if(in_count > out_count) { //FIXME move after swr_convert_internal
696 }else
699 }
700
701 if(out_count){
702 size =
FFMIN(in_count, out_count);
704 if(ret<0)
709 }
710 if(in_count){
712 copy(&tmp, in, in_count);
714 }
715 }
718 return ret2;
719 }
720 }
721
724
726 return 0;
727
730 }
731
735
736 if(count <= 0)
737 return 0;
738
739 #define MAX_SILENCE_STEP 16384
744 }
745
748
751 } else
753
758 }
759
763 }else{
765 }
766 }
767
770
771 if (!s || compensation_distance < 0)
773 if (!compensation_distance && sample_delta)
778 if (ret < 0)
780 }
783 }else{
785 }
786 }
787
789 if(pts == INT64_MIN)
791
794
797 } else {
800
806 if(ret<0){
808 }
812 int comp = av_clipf(fdelta, -max_soft_compensation, max_soft_compensation) *
duration ;
813 av_log(s,
AV_LOG_VERBOSE,
"compensating audio timestamp drift:%f compensation:%d in:%d\n", fdelta, comp, duration);
815 }
816 }
817
819 }
820 }