| @@ -38,6 +38,7 @@ · 37 unmodified lines |
| 38 | 38 | static const AVOption options[]={ |
| 39 | 39 | {"ich", "input channel count", OFFSET( in.ch_count ), AV_OPT_TYPE_INT, {.dbl=2}, 1, SWR_CH_MAX, 0}, |
| 40 | 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 | 42 | {"isr", "input sample rate" , OFFSET( in_sample_rate), AV_OPT_TYPE_INT, {.dbl=48000}, 1, INT_MAX, 0}, |
| 42 | 43 | {"osr", "output sample rate" , OFFSET(out_sample_rate), AV_OPT_TYPE_INT, {.dbl=48000}, 1, INT_MAX, 0}, |
| 43 | 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 | 78 | SwrContext *swr_alloc2(struct SwrContext *s, int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate, |
| 78 | 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 | 81 | if(!s) s= swr_alloc(); |
| 81 | 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 | 91 | av_set_int(s, "isf", in_sample_fmt); |
| 91 | 92 | av_set_int(s, "isr", in_sample_rate); |
| 92 | 93 | |
| 94 | + s->channel_map = channel_map; |
| 93 | 95 | s-> in.ch_count= av_get_channel_layout_nb_channels(s-> in_ch_layout); |
| 94 | 96 | s->out.ch_count= av_get_channel_layout_nb_channels(s->out_ch_layout); |
| 95 | 97 | s->int_sample_fmt = AV_SAMPLE_FMT_S16; |
| 98 | + s->used_ch_count= s-> in.ch_count; |
| 96 | 99 | |
| 97 | 100 | return s; |
| 98 | 101 | } |
| @@ -167,13 +170,16 @@ int swr_init(SwrContext *s){ · 68 unmodified lines |
| 167 | 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)){ |
| 171 | | − av_log(s, AV_LOG_WARNING, "Input channel layout has a different number of channels than there actually is, ignoring layout\n"); |
| 173 | + if(!s->used_ch_count) |
| 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 | 178 | s-> in_ch_layout= 0; |
| 173 | 179 | } |
| 174 | 180 | |
| 175 | 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 | 183 | if(!s->out_ch_layout) |
| 178 | 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 | 188 | #define RSC 1 //FIXME finetune |
| 183 | 189 | if(!s-> in.ch_count) |
| 184 | 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 | 193 | if(!s->out.ch_count) |
| 186 | 194 | s->out.ch_count= av_get_channel_layout_nb_channels(s->out_ch_layout); |
| 187 | 195 | |
| 188 | 196 | av_assert0(s-> in.ch_count); |
| 197 | +av_assert0(s->used_ch_count); |
| 189 | 198 | av_assert0(s->out.ch_count); |
| 190 | 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 | 202 | s->int_bps= av_get_bits_per_sample_fmt(s->int_sample_fmt)/8; |
| 194 | 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 | 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 | 208 | return 0; |
| 200 | 209 | } |
| 201 | 210 | |
| 202 | 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 | 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 | 217 | s->postin= s->in; |
| 209 | 218 | s->preout= s->out; |
| 210 | 219 | s->midbuf= s->in; |
| 211 | 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 | 226 | if(!s->resample_first){ |
| 213 | 227 | s->midbuf.ch_count= s->out.ch_count; |
| 214 | 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 | 339 | if((ret=realloc_audio(&s->postin, in_count))<0) |
| 326 | 340 | return ret; |
| 327 | 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 | 343 | if((ret=realloc_audio(&s->midbuf, out_count))<0) |
| 330 | 344 | return ret; |
| 331 | 345 | }else{ |