| @@ -38,6 +38,7 @@ · 37 unmodified lines |
| 38 | static const AVOption options[]={ | 38 | static const AVOption options[]={ |
| 39 | {"ich", "input channel count", OFFSET( in.ch_count ), AV_OPT_TYPE_INT, {.dbl=2}, 1, SWR_CH_MAX, 0}, | 39 | {"ich", "input channel count", OFFSET( in.ch_count ), AV_OPT_TYPE_INT, {.dbl=2}, 1, SWR_CH_MAX, 0}, |
| 40 | {"och", "output channel count", OFFSET(out.ch_count ), AV_OPT_TYPE_INT, {.dbl=2}, 1, SWR_CH_MAX, 0}, | 40 | {"och", "output channel count", OFFSET(out.ch_count ), AV_OPT_TYPE_INT, {.dbl=2}, 1, SWR_CH_MAX, 0}, |
| | 41 | {"uch", "used channel count", OFFSET(used_ch_count ), AV_OPT_TYPE_INT, {.dbl=2}, 1, SWR_CH_MAX, 0}, |
| 41 | {"isr", "input sample rate" , OFFSET( in_sample_rate), AV_OPT_TYPE_INT, {.dbl=48000}, 1, INT_MAX, 0}, | 42 | {"isr", "input sample rate" , OFFSET( in_sample_rate), AV_OPT_TYPE_INT, {.dbl=48000}, 1, INT_MAX, 0}, |
| 42 | {"osr", "output sample rate" , OFFSET(out_sample_rate), AV_OPT_TYPE_INT, {.dbl=48000}, 1, INT_MAX, 0}, | 43 | {"osr", "output sample rate" , OFFSET(out_sample_rate), AV_OPT_TYPE_INT, {.dbl=48000}, 1, INT_MAX, 0}, |
| 43 | //{"ip" , "input planar" , OFFSET( in.planar ), AV_OPT_TYPE_INT, {.dbl=0}, 0, 1, 0}, | 44 | //{"ip" , "input planar" , OFFSET( in.planar ), AV_OPT_TYPE_INT, {.dbl=0}, 0, 1, 0}, |
| @@ -76,7 +77,7 @@ SwrContext *swr_alloc(void){ · 32 unmodified lines |
| 76 | | 77 | |
| 77 | SwrContext *swr_alloc2(struct SwrContext *s, int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate, | 78 | SwrContext *swr_alloc2(struct SwrContext *s, int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate, |
| 78 | int64_t in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate, | 79 | int64_t in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate, |
| 79 | int log_offset, void *log_ctx){ | 80 | const int *channel_map, int log_offset, void *log_ctx){ |
| 80 | if(!s) s= swr_alloc(); | 81 | if(!s) s= swr_alloc(); |
| 81 | if(!s) return NULL; | 82 | if(!s) return NULL; |
| 82 | | 83 | |
| @@ -90,9 +91,11 @@ SwrContext *swr_alloc2(struct SwrContext *s, int64_t out_ch_layout, enum AVSampl · 7 unmodified lines |
| 90 | av_set_int(s, "isf", in_sample_fmt); | 91 | av_set_int(s, "isf", in_sample_fmt); |
| 91 | av_set_int(s, "isr", in_sample_rate); | 92 | av_set_int(s, "isr", in_sample_rate); |
| 92 | | 93 | |
| | 94 | s->channel_map = channel_map; |
| 93 | s-> in.ch_count= av_get_channel_layout_nb_channels(s-> in_ch_layout); | 95 | s-> in.ch_count= av_get_channel_layout_nb_channels(s-> in_ch_layout); |
| 94 | s->out.ch_count= av_get_channel_layout_nb_channels(s->out_ch_layout); | 96 | s->out.ch_count= av_get_channel_layout_nb_channels(s->out_ch_layout); |
| 95 | s->int_sample_fmt = AV_SAMPLE_FMT_S16; | 97 | s->int_sample_fmt = AV_SAMPLE_FMT_S16; |
| | 98 | s->used_ch_count= s-> in.ch_count; |
| 96 | | 99 | |
| 97 | return s; | 100 | return s; |
| 98 | } | 101 | } |
| @@ -167,13 +170,16 @@ int swr_init(SwrContext *s){ · 68 unmodified lines |
| 167 | return -1; | 170 | return -1; |
| 168 | } | 171 | } |
| 169 | | 172 | |
| 170 | if(s-> in.ch_count && s-> in_ch_layout && s->in.ch_count != av_get_channel_layout_nb_channels(s-> in_ch_layout)){ | 173 | if(!s->used_ch_count) |
| 171 | av_log(s, AV_LOG_WARNING, "Input channel layout has a different number of channels than there actually is, ignoring layout\n"); | 174 | s->used_ch_count= s->in.ch_count; |
| | 175 | |
| | 176 | if(s->used_ch_count && s-> in_ch_layout && s->used_ch_count != av_get_channel_layout_nb_channels(s-> in_ch_layout)){ |
| | 177 | av_log(s, AV_LOG_WARNING, "Input channel layout has a different number of channels than the number of used channels, ignoring layout\n"); |
| 172 | s-> in_ch_layout= 0; | 178 | s-> in_ch_layout= 0; |
| 173 | } | 179 | } |
| 174 | | 180 | |
| 175 | if(!s-> in_ch_layout) | 181 | if(!s-> in_ch_layout) |
| 176 | s-> in_ch_layout= av_get_default_channel_layout(s->in.ch_count); | 182 | s-> in_ch_layout= av_get_default_channel_layout(s->used_ch_count); |
| 177 | if(!s->out_ch_layout) | 183 | if(!s->out_ch_layout) |
| 178 | s->out_ch_layout= av_get_default_channel_layout(s->out.ch_count); | 184 | s->out_ch_layout= av_get_default_channel_layout(s->out.ch_count); |
| 179 | | 185 | |
| @@ -182,10 +188,13 @@ int swr_init(SwrContext *s){ · 2 unmodified lines |
| 182 | #define RSC 1 //FIXME finetune | 188 | #define RSC 1 //FIXME finetune |
| 183 | if(!s-> in.ch_count) | 189 | if(!s-> in.ch_count) |
| 184 | s-> in.ch_count= av_get_channel_layout_nb_channels(s-> in_ch_layout); | 190 | s-> in.ch_count= av_get_channel_layout_nb_channels(s-> in_ch_layout); |
| | 191 | if(!s->used_ch_count) |
| | 192 | s->used_ch_count= s->in.ch_count; |
| 185 | if(!s->out.ch_count) | 193 | if(!s->out.ch_count) |
| 186 | s->out.ch_count= av_get_channel_layout_nb_channels(s->out_ch_layout); | 194 | s->out.ch_count= av_get_channel_layout_nb_channels(s->out_ch_layout); |
| 187 | | 195 | |
| 188 | av_assert0(s-> in.ch_count); | 196 | av_assert0(s-> in.ch_count); |
| | 197 | av_assert0(s->used_ch_count); |
| 189 | av_assert0(s->out.ch_count); | 198 | av_assert0(s->out.ch_count); |
| 190 | s->resample_first= RSC*s->out.ch_count/s->in.ch_count - RSC < s->out_sample_rate/(float)s-> in_sample_rate - 1.0; | 199 | s->resample_first= RSC*s->out.ch_count/s->in.ch_count - RSC < s->out_sample_rate/(float)s-> in_sample_rate - 1.0; |
| 191 | | 200 | |
| @@ -193,22 +202,27 @@ av_assert0(s->out.ch_count); · 1 unmodified line |
| 193 | s->int_bps= av_get_bits_per_sample_fmt(s->int_sample_fmt)/8; | 202 | s->int_bps= av_get_bits_per_sample_fmt(s->int_sample_fmt)/8; |
| 194 | s->out.bps= av_get_bits_per_sample_fmt(s->out_sample_fmt)/8; | 203 | s->out.bps= av_get_bits_per_sample_fmt(s->out_sample_fmt)/8; |
| 195 | | 204 | |
| 196 | if(!s->resample && !s->rematrix){ | 205 | if(!s->resample && !s->rematrix && !s->channel_map){ |
| 197 | s->full_convert = swr_audio_convert_alloc(s->out_sample_fmt, | 206 | s->full_convert = swr_audio_convert_alloc(s->out_sample_fmt, |
| 198 | s-> in_sample_fmt, s-> in.ch_count, 0); | 207 | s-> in_sample_fmt, s-> in.ch_count, NULL, 0); |
| 199 | return 0; | 208 | return 0; |
| 200 | } | 209 | } |
| 201 | | 210 | |
| 202 | s->in_convert = swr_audio_convert_alloc(s->int_sample_fmt, | 211 | s->in_convert = swr_audio_convert_alloc(s->int_sample_fmt, |
| 203 | s-> in_sample_fmt, s-> in.ch_count, 0); | 212 | s-> in_sample_fmt, s->used_ch_count, s->channel_map, 0); |
| 204 | s->out_convert= swr_audio_convert_alloc(s->out_sample_fmt, | 213 | s->out_convert= swr_audio_convert_alloc(s->out_sample_fmt, |
| 205 | s->int_sample_fmt, s->out.ch_count, 0); | 214 | s->int_sample_fmt, s->out.ch_count, NULL, 0); |
| 206 | | 215 | |
| 207 | | 216 | |
| 208 | s->postin= s->in; | 217 | s->postin= s->in; |
| 209 | s->preout= s->out; | 218 | s->preout= s->out; |
| 210 | s->midbuf= s->in; | 219 | s->midbuf= s->in; |
| 211 | s->in_buffer= s->in; | 220 | s->in_buffer= s->in; |
| | 221 | if(s->channel_map){ |
| | 222 | s->postin.ch_count= |
| | 223 | s->midbuf.ch_count= |
| | 224 | s->in_buffer.ch_count= s->used_ch_count; |
| | 225 | } |
| 212 | if(!s->resample_first){ | 226 | if(!s->resample_first){ |
| 213 | s->midbuf.ch_count= s->out.ch_count; | 227 | s->midbuf.ch_count= s->out.ch_count; |
| 214 | s->in_buffer.ch_count = s->out.ch_count; | 228 | s->in_buffer.ch_count = s->out.ch_count; |
| @@ -325,7 +339,7 @@ int swr_convert(struct SwrContext *s, uint8_t *out_arg[SWR_CH_MAX], int out_coun · 110 unmodified lines |
| 325 | if((ret=realloc_audio(&s->postin, in_count))<0) | 339 | if((ret=realloc_audio(&s->postin, in_count))<0) |
| 326 | return ret; | 340 | return ret; |
| 327 | if(s->resample_first){ | 341 | if(s->resample_first){ |
| 328 | av_assert0(s->midbuf.ch_count == s-> in.ch_count); | 342 | av_assert0(s->midbuf.ch_count == s->used_ch_count); |
| 329 | if((ret=realloc_audio(&s->midbuf, out_count))<0) | 343 | if((ret=realloc_audio(&s->midbuf, out_count))<0) |
| 330 | return ret; | 344 | return ret; |
| 331 | }else{ | 345 | }else{ |