Merge pull request #4324 from FernetMenta/wasapi
[vuplus_xbmc] / lib / xbmc-libav-hacks / swresample.c
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
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)
8  *  any later version.
9  *
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.
14  *
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/>.
18  *
19  */
20
21 #include "libav_hacks.h"
22
23 #include <libavutil/mathematics.h>
24 #include <libavutil/opt.h>
25
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)
30 {
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);
38     return ret;
39 }
40
41
42 int swr_init(struct SwrContext *s)
43 {
44     return avresample_open(s);
45 }
46
47 void swr_free(struct SwrContext **s)
48 {
49     avresample_close(*s);
50     *s = NULL;
51 }
52
53 int swr_convert(struct SwrContext *s, uint8_t **out, int out_count,
54                 const uint8_t **in , int in_count)
55 {
56     return avresample_convert(s, out, 0, out_count, (uint8_t**)in, 0,in_count);
57 }
58
59 int64_t swr_get_delay(struct SwrContext *s, int64_t base)
60 {
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);
65 }
66
67 int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map)
68 {
69     return avresample_set_channel_mapping(s, channel_map);
70 }
71
72 int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride)
73 {
74     return avresample_set_matrix(s, matrix, stride);
75 }
76
77 int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensation_distance)
78 {
79     return avresample_set_compensation(s, sample_delta, compensation_distance);
80 }