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
31 #include "libavutil/ffversion.h"
33
35 {
38 }
39
41 {
42 return FFMPEG_CONFIGURATION;
43 }
44
46 {
47 #define LICENSE_PREFIX "libswresample license: "
49 }
50
52 if(!s || s->
in_convert)
// s needs to be allocated but not initialized
55 return 0;
56 }
57
64
67
69 goto fail;
70
72 goto fail;
73
75 goto fail;
76
78 goto fail;
79
81 goto fail;
82
84 goto fail;
85
87 goto fail;
88
90 goto fail;
91
93 goto fail;
94
97 fail:
101 }
102
109 }
110
113 memset(a, 0, sizeof(*a));
114 }
115
120 memset(s->
in.
ch, 0,
sizeof(s->
in.
ch));
134
136 }
137
140 if(s){
144 }
145
147 }
148
151 }
152
155
157
161 }
165 }
166
170 }
171
175 }
176
178 #if CONFIG_LIBSOXR
180 #endif
182 default:
185 }
186
189
191 av_log(s,
AV_LOG_WARNING,
"Input channel layout has a different number of channels than the number of used channels, ignoring layout\n");
193 }
194
199
202
213 }else{
216 }
217 }
218
225 }
226
229
235 } else
237
241 if (s->
async > 1.0001) {
243 }
244 }
245
247 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);
248 }else
256 return -1;
257 }
258
259 #define RSC 1 //FIXME finetune
266
267 if(!s->
in.ch_count){
270 return -1;
271 }
272
274 char l1[1024], l2[1024];
278 "but there is not enough information to do it\n", l1, l2);
279 return -1;
280 }
281
285
289
293 return 0;
294 }
295
300
303
307
313 }
318 }
319
323
326 }
327
330
333
334 return 0;
335 }
336
338 int i, countb;
340
343
344 if(a->
count >= count)
345 return 0;
346
347 count*=2;
348
351
354
361 }
365
366 return 1;
367 }
368
375 int ch;
377 memcpy(out->
ch[ch], in->
ch[ch], count*out->
bps);
378 }else
380 }
381
383 int i;
384 if(!in_arg){
385 memset(out->
ch, 0,
sizeof(out->
ch));
388 out->
ch[i]= in_arg[i];
389 }else{
391 out->
ch[i]= in_arg[0] + i*out->
bps;
392 }
393 }
394
396 int i;
399 in_arg[i]= out->
ch[i];
400 }else{
401 in_arg[0]= out->
ch[0];
402 }
403 }
404
405 /**
406 *
407 * out may be equal in.
408 */
410 int ch;
413 out->
ch[ch]= in->
ch[ch] + count*out->
bps;
414 }else{
415 for(ch=out->
ch_count-1; ch>=0; ch--)
417 }
418 }
419
420 /**
421 *
422 * @return number of samples output per channel
423 */
425 const AudioData * in_param,
int in_count){
427 int ret_sum=0;
428 int border=0;
430
434
435 tmp=out=*out_param;
436 in = *in_param;
437
440 if (border == INT_MAX) {
441 return 0;
442 } else if (border < 0) {
443 return border;
444 } else if (border) {
446 in_count -= border;
448 }
449
450 do{
460
461 if(!in_count)
462 break;
468 border = 0;
469 }
470 }
471
478 in_count -= consumed;
480 }
481
482 //TODO is this check sane considering the advanced copy avoidance below
489 }else
492
493 if(in_count){
496
498 copy(&tmp, &in,
/*in_*/count);
505 continue;
506 if (padless) {
507 padless = 0;
508 continue;
509 }
510 }
511 break;
512 }while(1);
513
515
516 return ret_sum;
517 }
518
522 int ret /*, in_max*/;
524
528 return out_count;
529 }
530
531 // in_max= out_count*(int64_t)s->in_sample_rate / s->out_sample_rate + resample_filter_taps;
532 // in_count= FFMIN(in_count, in_in + 2 - s->hist_buffer_count);
533
540 }else{
544 }
547
549
551 midbuf= &midbuf_tmp;
553 preout= &preout_tmp;
554
557
560
563
566 if(preout==in){
567 out_count=
FFMIN(out_count, in_count);
//TODO check at the end if this is needed or redundant
568 av_assert0(s->
in.
planar);
//we only support planar internally so it has to be, we support copying non planar though
569 copy(out, in, out_count);
570 return out_count;
571 }
572 else if(preout==postin) preout= midbuf= postin=
out;
573 else if(preout==midbuf) preout= midbuf=
out;
575 }
576
577 if(in != postin){
579 }
580
582 if(postin != midbuf)
583 out_count=
resample(s, midbuf, out_count, postin, in_count);
584 if(midbuf != preout)
586 }else{
587 if(postin != midbuf)
589 if(midbuf != preout)
590 out_count=
resample(s, preout, out_count, midbuf, in_count);
591 }
592
593 if(preout != out && out_count){
596 int ch;
597 int dither_count=
FFMAX(out_count, 1<<16);
598
599 if (preout == in) {
603 }
604
607 if(ret)
611
614
617 int len1= out_count&~15;
618 int off = len1 * preout->
bps;
619
620 if(len1)
621 for(ch=0; ch<preout->
ch_count; ch++)
623 if(out_count != len1)
624 for(ch=0; ch<preout->
ch_count; ch++)
626 } else {
627 for(ch=0; ch<preout->
ch_count; ch++)
629 }
630 } else {
636 }
637 }
639 }
640 //FIXME packed doesn't need more than 1 chan here!
642 }
643 return out_count;
644 }
645
648 }
649
651 const uint8_t *in_arg [SWR_CH_MAX],
int in_count){
654
658 }
659
663 #define MAX_DROP_STEP 16384
666
668 s->
drop_output *= -1;
//FIXME find a less hackish solution
671 in_count = 0;
672 if(ret>0) {
675 return 0;
676 continue;
677 }
678
680 return 0;
681 }
682
683 if(!in_arg){
690 return 0;
691 }
692 }else
694
696
701 return ret;
702 }else{
704 int ret2=0;
707 if(size){
710 if(ret<0)
719 }
720
721 if(in_count){
723
724 if(in_count > out_count) { //FIXME move after swr_convert_internal
730 }else
733 }
734
735 if(out_count){
736 size =
FFMIN(in_count, out_count);
738 if(ret<0)
743 }
744 if(in_count){
746 copy(&tmp, in, in_count);
748 }
749 }
752 return ret2;
753 }
754 }
755
759
761 return 0;
762
765 }
766
770
771 if(count <= 0)
772 return 0;
773
774 #define MAX_SILENCE_STEP 16384
779 }
780
783
786 } else
788
793 }
794
798 }else{
800 }
801 }
802
805
806 if (!s || compensation_distance < 0)
808 if (!compensation_distance && sample_delta)
813 if (ret < 0)
815 }
818 }else{
820 }
821 }
822
824 if(pts == INT64_MIN)
826
829
832 } else {
835
841 if(ret<0){
843 }
847 int comp = av_clipf(fdelta, -max_soft_compensation, max_soft_compensation) *
duration ;
848 av_log(s,
AV_LOG_VERBOSE,
"compensating audio timestamp drift:%f compensation:%d in:%d\n", fdelta, comp, duration);
850 }
851 }
852
854 }
855 }