2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "libav_hacks.h"
23 #include <libavutil/mathematics.h>
24 #include <libavutil/opt.h>
26 struct SwrContext *swr_alloc_set_opts(struct SwrContext *s,
27 int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate,
28 int64_t in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate,
29 int log_offset, void *log_ctx)
31 AVAudioResampleContext *ret = avresample_alloc_context();
32 av_opt_set_int(ret, "out_channel_layout", out_ch_layout , 0);
33 av_opt_set_int(ret, "out_sample_fmt" , out_sample_fmt , 0);
34 av_opt_set_int(ret, "out_sample_rate" , out_sample_rate, 0);
35 av_opt_set_int(ret, "in_channel_layout" , in_ch_layout , 0);
36 av_opt_set_int(ret, "in_sample_fmt" , in_sample_fmt , 0);
37 av_opt_set_int(ret, "in_sample_rate" , in_sample_rate , 0);
42 int swr_init(struct SwrContext *s)
44 return avresample_open(s);
47 void swr_free(struct SwrContext **s)
53 int swr_convert(struct SwrContext *s, uint8_t **out, int out_count,
54 const uint8_t **in , int in_count)
56 return avresample_convert(s, out, 0, out_count, (uint8_t**)in, 0,in_count);
59 int64_t swr_get_delay(struct SwrContext *s, int64_t base)
61 int64_t in_sr, out_sr;
62 av_opt_get_int(s, "in_sample_rate", 0, &in_sr);
63 av_opt_get_int(s, "out_sample_rate", 0, &out_sr);
64 return av_rescale_rnd(avresample_available(s), base, out_sr, AV_ROUND_UP) + av_rescale_rnd(avresample_get_delay(s), base, in_sr, AV_ROUND_UP);
67 int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map)
69 return avresample_set_channel_mapping(s, channel_map);
72 int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride)
74 return avresample_set_matrix(s, matrix, stride);
77 int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensation_distance)
79 return avresample_set_compensation(s, sample_delta, compensation_distance);