File npa/npa.c changed (mode: 100644) (index 580ea57..59ac4e4) |
172 |
172 |
#define av_frs_alloc av_frame_alloc |
#define av_frs_alloc av_frame_alloc |
173 |
173 |
#define av_frs_set_silence av_samples_set_silence |
#define av_frs_set_silence av_samples_set_silence |
174 |
174 |
#define av_frs_unref av_frame_unref |
#define av_frs_unref av_frame_unref |
175 |
|
#define av_get_chan_layout_str av_get_channel_layout_string |
|
176 |
|
#define av_get_default_chans_layout av_get_default_channel_layout |
|
177 |
175 |
#define av_get_fr_fmt_name av_get_sample_fmt_name |
#define av_get_fr_fmt_name av_get_sample_fmt_name |
178 |
176 |
#define av_get_fr_fmt_str av_get_sample_fmt_string |
#define av_get_fr_fmt_str av_get_sample_fmt_string |
179 |
177 |
#define av_io_flush avio_flush |
#define av_io_flush avio_flush |
|
188 |
186 |
#define av_frs AVFrame |
#define av_frs AVFrame |
189 |
187 |
#define av_sd_pkt avcodec_send_packet |
#define av_sd_pkt avcodec_send_packet |
190 |
188 |
#define av_st AVStream |
#define av_st AVStream |
191 |
|
#define chans_layout channel_layout |
|
192 |
|
#define chans_n channels |
|
193 |
189 |
#define fmt format |
#define fmt format |
194 |
190 |
#define fr_fmt sample_fmt |
#define fr_fmt sample_fmt |
195 |
191 |
#define fr_rate sample_rate |
#define fr_rate sample_rate |
|
... |
... |
static av_filt_graph *filt_graph; |
271 |
267 |
static av_filt_ctx *abufsrc_ctx; |
static av_filt_ctx *abufsrc_ctx; |
272 |
268 |
static const av_filt *abufsrc_filt; |
static const av_filt *abufsrc_filt; |
273 |
269 |
static struct { /* used to detected reconfiguration */ |
static struct { /* used to detected reconfiguration */ |
274 |
|
int chans_n; |
|
275 |
|
uint64_t chans_layout; |
|
|
270 |
|
AVChannelLayout chans_layout; |
276 |
271 |
int rate; |
int rate; |
277 |
272 |
enum av_fr_fmt fmt; |
enum av_fr_fmt fmt; |
278 |
273 |
} abufsrc_key; |
} abufsrc_key; |
|
... |
... |
static void rd_thd_reset(int st_idx) |
769 |
764 |
* XXX: if it is ever used significantly, a fine granularity wiring strategy |
* XXX: if it is ever used significantly, a fine granularity wiring strategy |
770 |
765 |
* will be implemented instead of using the default wiring |
* will be implemented instead of using the default wiring |
771 |
766 |
*/ |
*/ |
772 |
|
static uint64_t pcm_chmaps2ff_chans_layout(snd_pcm_t *pcm, |
|
773 |
|
unsigned int pcm_chans_n, bool print_info) |
|
|
767 |
|
static void pcm_chmaps2ff_chans_layout(AVChannelLayout *ff_chans_layout, |
|
768 |
|
snd_pcm_t *pcm, unsigned int pcm_chans_n, bool print_info) |
774 |
769 |
{ |
{ |
775 |
770 |
int r; |
int r; |
776 |
|
uint64_t ff_chans_layout; |
|
|
771 |
|
|
777 |
772 |
snd_pcm_chmap_t *pcm_chmap; |
snd_pcm_chmap_t *pcm_chmap; |
778 |
773 |
u8 chans_layout_str[STR_SZ]; /* should be overkill */ |
u8 chans_layout_str[STR_SZ]; /* should be overkill */ |
779 |
774 |
|
|
|
... |
... |
static uint64_t pcm_chmaps2ff_chans_layout(snd_pcm_t *pcm, |
786 |
781 |
pout("alsa:your pcm device support channel maps, but fine granularity wiring strategy is not implemented\n"); |
pout("alsa:your pcm device support channel maps, but fine granularity wiring strategy is not implemented\n"); |
787 |
782 |
free(pcm_chmap); |
free(pcm_chmap); |
788 |
783 |
} |
} |
789 |
|
ff_chans_layout = av_get_default_chans_layout((int)pcm_chans_n); |
|
790 |
|
av_get_chan_layout_str(chans_layout_str, sizeof(chans_layout_str), |
|
791 |
|
(int)pcm_chans_n, ff_chans_layout); |
|
|
784 |
|
av_channel_layout_default(ff_chans_layout, (int)pcm_chans_n); |
|
785 |
|
av_channel_layout_describe(ff_chans_layout, chans_layout_str, |
|
786 |
|
sizeof(chans_layout_str)); |
792 |
787 |
if (print_info) |
if (print_info) |
793 |
788 |
pout("alsa channel map wired to ffmpeg channel layout:\"%s\" (%u pcm channels)\n", chans_layout_str, pcm_chans_n); |
pout("alsa channel map wired to ffmpeg channel layout:\"%s\" (%u pcm channels)\n", chans_layout_str, pcm_chans_n); |
794 |
|
return ff_chans_layout; |
|
795 |
789 |
} |
} |
796 |
790 |
/* fatal if the wiring cannot be done */ |
/* fatal if the wiring cannot be done */ |
797 |
791 |
static void pcm_layout2ff_fmt_strict(snd_pcm_fmt_t alsa_fmt, |
static void pcm_layout2ff_fmt_strict(snd_pcm_fmt_t alsa_fmt, |
|
... |
... |
static void pcm_layout2ff_fmt_strict(snd_pcm_fmt_t alsa_fmt, |
836 |
830 |
pout("alsa pcm layout \"%s\"/\"%s\" wired strictly to ffmpeg format \"%sbits\"\n", snd_pcm_fmt_desc(alsa_fmt), snd_pcm_access_name(alsa_access), ff_fmt_str); |
pout("alsa pcm layout \"%s\"/\"%s\" wired strictly to ffmpeg format \"%sbits\"\n", snd_pcm_fmt_desc(alsa_fmt), snd_pcm_access_name(alsa_access), ff_fmt_str); |
837 |
831 |
} |
} |
838 |
832 |
} |
} |
839 |
|
static void pcm2ff(snd_pcm_t *pcm, enum av_fr_fmt *ff_fmt, |
|
840 |
|
int *ff_rate, int *ff_chans_n, uint64_t *ff_chans_layout, |
|
841 |
|
bool print_info) |
|
|
833 |
|
static void pcm2ff(snd_pcm_t *pcm, enum av_fr_fmt *ff_fmt, int *ff_rate, |
|
834 |
|
AVChannelLayout *ff_chans_layout, bool print_info) |
842 |
835 |
{ |
{ |
843 |
836 |
int r; |
int r; |
844 |
837 |
snd_pcm_hw_params_t *hw_params; |
snd_pcm_hw_params_t *hw_params; |
|
... |
... |
static void pcm2ff(snd_pcm_t *pcm, enum av_fr_fmt *ff_fmt, |
870 |
863 |
r = snd_pcm_hw_params_get_chans(hw_params, &pcm_chans_n); |
r = snd_pcm_hw_params_get_chans(hw_params, &pcm_chans_n); |
871 |
864 |
if (r < 0) |
if (r < 0) |
872 |
865 |
fatal("alsa:unable to get the pcm count of channels for ffmpeg filter wiring\n"); |
fatal("alsa:unable to get the pcm count of channels for ffmpeg filter wiring\n"); |
873 |
|
*ff_chans_n = (int)pcm_chans_n; |
|
874 |
866 |
/*--------------------------------------------------------------------*/ |
/*--------------------------------------------------------------------*/ |
875 |
|
*ff_chans_layout = pcm_chmaps2ff_chans_layout(pcm, pcm_chans_n, |
|
|
867 |
|
pcm_chmaps2ff_chans_layout(ff_chans_layout, pcm, pcm_chans_n, |
876 |
868 |
print_info); |
print_info); |
877 |
869 |
/*--------------------------------------------------------------------*/ |
/*--------------------------------------------------------------------*/ |
878 |
870 |
snd_pcm_hw_params_free(hw_params); |
snd_pcm_hw_params_free(hw_params); |
879 |
871 |
} |
} |
880 |
872 |
/* XXX: we don't program the tb of the filter since it should not be used */ |
/* XXX: we don't program the tb of the filter since it should not be used */ |
881 |
|
static void abufsrc_cfg(enum av_fr_fmt fmt, int rate, int chans_n, |
|
882 |
|
uint64_t chans_layout, bool print_info) |
|
|
873 |
|
static void abufsrc_cfg(enum av_fr_fmt fmt, int rate, |
|
874 |
|
AVChannelLayout *chans_layout, bool print_info) |
883 |
875 |
{ |
{ |
884 |
876 |
int r; |
int r; |
885 |
877 |
u8 chans_layout_str[STR_SZ]; /* should be overkill */ |
u8 chans_layout_str[STR_SZ]; /* should be overkill */ |
|
... |
... |
static void abufsrc_cfg(enum av_fr_fmt fmt, int rate, int chans_n, |
899 |
891 |
AV_OPT_SEARCH_CHILDREN); |
AV_OPT_SEARCH_CHILDREN); |
900 |
892 |
if (r < 0) |
if (r < 0) |
901 |
893 |
fatal("audio buffer source context:unable to set the decoder rate option\n"); |
fatal("audio buffer source context:unable to set the decoder rate option\n"); |
902 |
|
av_get_chan_layout_str(chans_layout_str, sizeof(chans_layout_str), |
|
903 |
|
chans_n, chans_layout); |
|
|
894 |
|
av_channel_layout_describe(chans_layout, chans_layout_str, |
|
895 |
|
sizeof(chans_layout_str)); |
904 |
896 |
if (print_info) |
if (print_info) |
905 |
|
pout("audio buffer source context:using channels layout \"%s\" (%d pcm channels)\n", chans_layout_str, chans_n); |
|
|
897 |
|
pout("audio buffer source context:using channels layout \"%s\"\n", chans_layout_str); |
906 |
898 |
r = av_opt_set(abufsrc_ctx, "channel_layout", chans_layout_str, |
r = av_opt_set(abufsrc_ctx, "channel_layout", chans_layout_str, |
907 |
899 |
AV_OPT_SEARCH_CHILDREN); |
AV_OPT_SEARCH_CHILDREN); |
908 |
900 |
if (r < 0) |
if (r < 0) |
|
... |
... |
static void vol_cfg(bool muted, double vol) |
936 |
928 |
if (r < 0) |
if (r < 0) |
937 |
929 |
fatal("volume buffer context:unable to initialize\n"); |
fatal("volume buffer context:unable to initialize\n"); |
938 |
930 |
} |
} |
939 |
|
static void afmt_cfg(enum av_fr_fmt fmt, int rate, int chans_n, |
|
940 |
|
uint64_t chans_layout, bool print_info) |
|
|
931 |
|
static void afmt_cfg(enum av_fr_fmt fmt, int rate, |
|
932 |
|
AVChannelLayout *chans_layout, bool print_info) |
941 |
933 |
{ |
{ |
942 |
934 |
int r; |
int r; |
943 |
935 |
u8 rate_str[sizeof("dddddd")]; |
u8 rate_str[sizeof("dddddd")]; |
|
... |
... |
static void afmt_cfg(enum av_fr_fmt fmt, int rate, int chans_n, |
958 |
950 |
AV_OPT_SEARCH_CHILDREN); |
AV_OPT_SEARCH_CHILDREN); |
959 |
951 |
if (r < 0) |
if (r < 0) |
960 |
952 |
fatal("audio format context:could not set the pcm rate\n"); |
fatal("audio format context:could not set the pcm rate\n"); |
961 |
|
av_get_chan_layout_str(chans_layout_str, sizeof(chans_layout_str), |
|
962 |
|
chans_n, chans_layout); |
|
|
953 |
|
av_channel_layout_describe(chans_layout, chans_layout_str, |
|
954 |
|
sizeof(chans_layout_str)); |
963 |
955 |
r = av_opt_set(afmt_ctx, "channel_layouts", chans_layout_str, |
r = av_opt_set(afmt_ctx, "channel_layouts", chans_layout_str, |
964 |
956 |
AV_OPT_SEARCH_CHILDREN); |
AV_OPT_SEARCH_CHILDREN); |
965 |
957 |
if (r < 0) |
if (r < 0) |
|
... |
... |
static void dec_ctx_cfg(AVCodecParameters *params) |
1007 |
999 |
fatal("ffmpeg:unable to open the decoder context\n"); |
fatal("ffmpeg:unable to open the decoder context\n"); |
1008 |
1000 |
} |
} |
1009 |
1001 |
static void filt_graph_cfg( |
static void filt_graph_cfg( |
1010 |
|
enum av_fr_fmt src_fmt, int src_rate, int src_chans_n, |
|
1011 |
|
uint64_t src_chans_layout, |
|
|
1002 |
|
enum av_fr_fmt src_fmt, int src_rate, |
|
1003 |
|
AVChannelLayout *src_chans_layout, |
1012 |
1004 |
bool muted, double vol, |
bool muted, double vol, |
1013 |
|
enum av_fr_fmt dst_fmt, int dst_rate, int dst_chans_n, |
|
1014 |
|
uint64_t dst_chans_layout, bool print_info) |
|
|
1005 |
|
enum av_fr_fmt dst_fmt, int dst_rate, |
|
1006 |
|
AVChannelLayout *dst_chans_layout, bool print_info) |
1015 |
1007 |
{ |
{ |
1016 |
1008 |
int r; |
int r; |
1017 |
1009 |
char *dump_str; |
char *dump_str; |
|
... |
... |
static void filt_graph_cfg( |
1021 |
1013 |
filt_graph = av_filt_graph_alloc(); |
filt_graph = av_filt_graph_alloc(); |
1022 |
1014 |
if (filt_graph == 0) |
if (filt_graph == 0) |
1023 |
1015 |
fatal("unable to create filter graph\n"); |
fatal("unable to create filter graph\n"); |
1024 |
|
abufsrc_cfg(src_fmt, src_rate, src_chans_n, src_chans_layout, |
|
1025 |
|
print_info); |
|
|
1016 |
|
abufsrc_cfg(src_fmt, src_rate, src_chans_layout, print_info); |
1026 |
1017 |
/*--------------------------------------------------------------------*/ |
/*--------------------------------------------------------------------*/ |
1027 |
|
abufsrc_key.chans_n = src_chans_n; |
|
1028 |
|
abufsrc_key.chans_layout = src_chans_layout; |
|
|
1018 |
|
r = av_channel_layout_copy(&abufsrc_key.chans_layout, src_chans_layout); |
|
1019 |
|
if (r < 0) |
|
1020 |
|
fatal("unable to copy the source channel layout in the key\n"); |
1029 |
1021 |
abufsrc_key.rate = src_rate; |
abufsrc_key.rate = src_rate; |
1030 |
1022 |
abufsrc_key.fmt = src_fmt; |
abufsrc_key.fmt = src_fmt; |
1031 |
1023 |
/*--------------------------------------------------------------------*/ |
/*--------------------------------------------------------------------*/ |
1032 |
1024 |
vol_cfg(muted, vol); |
vol_cfg(muted, vol); |
1033 |
|
afmt_cfg(dst_fmt, dst_rate, dst_chans_n, dst_chans_layout, print_info); |
|
|
1025 |
|
afmt_cfg(dst_fmt, dst_rate, dst_chans_layout, print_info); |
1034 |
1026 |
abufsink_cfg(); |
abufsink_cfg(); |
1035 |
1027 |
r = av_filt_link(abufsrc_ctx, 0, vol_ctx, 0); |
r = av_filt_link(abufsrc_ctx, 0, vol_ctx, 0); |
1036 |
1028 |
if (r < 0) |
if (r < 0) |
|
... |
... |
static void filt_flush(void) |
1063 |
1055 |
enum av_fr_fmt dst_fmt; |
enum av_fr_fmt dst_fmt; |
1064 |
1056 |
int dst_rate; |
int dst_rate; |
1065 |
1057 |
int dst_chans_n; |
int dst_chans_n; |
1066 |
|
uint64_t src_chans_layout; |
|
1067 |
|
uint64_t dst_chans_layout; |
|
|
1058 |
|
AVChannelLayout src_chans_layout; |
|
1059 |
|
AVChannelLayout dst_chans_layout; |
|
1060 |
|
int r; |
|
1061 |
|
|
|
1062 |
|
memset(&src_chans_layout, 0, sizeof(src_chans_layout)); |
|
1063 |
|
memset(&dst_chans_layout, 0, sizeof(dst_chans_layout)); |
1068 |
1064 |
|
|
1069 |
1065 |
av_frs_unref(filt_frs.av); |
av_frs_unref(filt_frs.av); |
1070 |
1066 |
filt_frs.pcm_written_ufrs_n = 0; |
filt_frs.pcm_written_ufrs_n = 0; |
1071 |
1067 |
|
|
1072 |
|
pcm2ff(pcm_g, &dst_fmt, &dst_rate, &dst_chans_n, &dst_chans_layout, |
|
|
1068 |
|
pcm2ff(pcm_g, &dst_fmt, &dst_rate, &dst_chans_layout, |
1073 |
1069 |
DONT_PRINT_INFO); |
DONT_PRINT_INFO); |
1074 |
1070 |
/* the audio dec ctx may not have a valid chans layout */ |
/* the audio dec ctx may not have a valid chans layout */ |
1075 |
|
if (dec_ctx->chans_layout == 0) { |
|
1076 |
|
src_chans_layout = av_get_default_chans_layout(dec_ctx->chans_n); |
|
1077 |
|
} else |
|
1078 |
|
src_chans_layout = dec_ctx->chans_layout; |
|
|
1071 |
|
r = av_channel_layout_check(&dec_ctx->ch_layout); |
|
1072 |
|
if (r == 0) /* XXX: we expect at least chans_n to be valid */ |
|
1073 |
|
av_channel_layout_default(&src_chans_layout, |
|
1074 |
|
dec_ctx->ch_layout.nb_channels); |
|
1075 |
|
else |
|
1076 |
|
av_channel_layout_copy(&src_chans_layout, &dec_ctx->ch_layout); |
1079 |
1077 |
filt_graph_cfg( |
filt_graph_cfg( |
1080 |
|
dec_ctx->fr_fmt, dec_ctx->fr_rate, |
|
1081 |
|
dec_ctx->chans_n, src_chans_layout, |
|
|
1078 |
|
dec_ctx->fr_fmt, dec_ctx->fr_rate, &src_chans_layout, |
1082 |
1079 |
filt_frs.muted, filt_frs.vol, |
filt_frs.muted, filt_frs.vol, |
1083 |
|
dst_fmt, dst_rate, dst_chans_n, dst_chans_layout, |
|
|
1080 |
|
dst_fmt, dst_rate, &dst_chans_layout, |
1084 |
1081 |
DONT_PRINT_INFO); |
DONT_PRINT_INFO); |
|
1082 |
|
av_channel_layout_uninit(&src_chans_layout); |
|
1083 |
|
av_channel_layout_uninit(&dst_chans_layout); |
1085 |
1084 |
} |
} |
1086 |
1085 |
#undef DONT_PRINT_INFO |
#undef DONT_PRINT_INFO |
1087 |
1086 |
static void stdin_tty_init_once(void) |
static void stdin_tty_init_once(void) |
|
... |
... |
static void dec_frs_get(void) { loop |
1505 |
1504 |
}} |
}} |
1506 |
1505 |
static bool is_recfg_required(av_frs *frs) |
static bool is_recfg_required(av_frs *frs) |
1507 |
1506 |
{ |
{ |
1508 |
|
if ( frs->chans_n != abufsrc_key.chans_n |
|
1509 |
|
|| frs->chans_layout != abufsrc_key.chans_layout |
|
|
1507 |
|
if (av_channel_layout_compare(&frs->ch_layout, |
|
1508 |
|
&abufsrc_key.chans_layout) != 0 |
1510 |
1509 |
|| frs->fr_rate != abufsrc_key.rate |
|| frs->fr_rate != abufsrc_key.rate |
1511 |
1510 |
|| frs->fmt != abufsrc_key.fmt) |
|| frs->fmt != abufsrc_key.fmt) |
1512 |
1511 |
return true; |
return true; |
|
... |
... |
static bool is_recfg_required(av_frs *frs) |
1515 |
1514 |
#define AGAIN 0 |
#define AGAIN 0 |
1516 |
1515 |
#define PUSHED 1 |
#define PUSHED 1 |
1517 |
1516 |
#define FILT_RECFG_REQUIRED 2 |
#define FILT_RECFG_REQUIRED 2 |
1518 |
|
static u8 filt_graph_push_dec_frs(int *new_chans_n, uint64_t *new_chans_layout, |
|
|
1517 |
|
static u8 filt_graph_push_dec_frs(AVChannelLayout *new_chans_layout, |
1519 |
1518 |
int *new_fr_rate, enum av_fr_fmt *new_fmt) |
int *new_fr_rate, enum av_fr_fmt *new_fmt) |
1520 |
1519 |
{ |
{ |
1521 |
1520 |
int r; |
int r; |
1522 |
1521 |
|
|
1523 |
1522 |
if (dec_frs.pushed_in_filt_graph) |
if (dec_frs.pushed_in_filt_graph) |
1524 |
1523 |
dec_frs_get(); |
dec_frs_get(); |
1525 |
|
if (dec_frs.av->chans_layout == 0) /* choose one for the filt */ |
|
1526 |
|
dec_frs.av->chans_layout = av_get_default_chans_layout( |
|
1527 |
|
dec_frs.av->chans_n); |
|
1528 |
1524 |
if (is_recfg_required(dec_frs.av)) { |
if (is_recfg_required(dec_frs.av)) { |
1529 |
|
*new_chans_n = dec_frs.av->chans_n; |
|
1530 |
|
*new_chans_layout = dec_frs.av->chans_layout; |
|
|
1525 |
|
r = av_channel_layout_copy(new_chans_layout, |
|
1526 |
|
&dec_frs.av->ch_layout); |
|
1527 |
|
if (r < 0) |
|
1528 |
|
fatal("ffmpeg:unable to copy the decoder channel layout as the new channel layout\n"); |
1531 |
1529 |
*new_fr_rate = dec_frs.av->fr_rate; |
*new_fr_rate = dec_frs.av->fr_rate; |
1532 |
1530 |
*new_fmt = dec_frs.av->fmt; |
*new_fmt = dec_frs.av->fmt; |
1533 |
1531 |
return FILT_RECFG_REQUIRED; |
return FILT_RECFG_REQUIRED; |
|
... |
... |
static void dec_frs_filter(void) |
1566 |
1564 |
{ |
{ |
1567 |
1565 |
loop { |
loop { |
1568 |
1566 |
u8 r; |
u8 r; |
1569 |
|
int new_chans_n; |
|
1570 |
|
uint64_t new_chans_layout; |
|
|
1567 |
|
AVChannelLayout new_chans_layout; |
1571 |
1568 |
int new_fr_rate; |
int new_fr_rate; |
1572 |
1569 |
enum av_fr_fmt new_fmt; |
enum av_fr_fmt new_fmt; |
1573 |
|
int dst_chans_n; |
|
1574 |
|
uint64_t dst_chans_layout; |
|
|
1570 |
|
AVChannelLayout dst_chans_layout; |
1575 |
1571 |
int dst_rate; |
int dst_rate; |
1576 |
1572 |
enum av_fr_fmt dst_fmt; |
enum av_fr_fmt dst_fmt; |
1577 |
1573 |
|
|
1578 |
|
r = filt_graph_push_dec_frs(&new_chans_n, &new_chans_layout, |
|
1579 |
|
&new_fr_rate, &new_fmt); |
|
|
1574 |
|
memset(&new_chans_layout, 0, sizeof(new_chans_layout)); |
|
1575 |
|
memset(&dst_chans_layout, 0, sizeof(dst_chans_layout)); |
|
1576 |
|
|
|
1577 |
|
r = filt_graph_push_dec_frs(&new_chans_layout, &new_fr_rate, |
|
1578 |
|
&new_fmt); |
1580 |
1579 |
if (r != FILT_RECFG_REQUIRED) { |
if (r != FILT_RECFG_REQUIRED) { |
1581 |
1580 |
/* PUSHED | AGAIN */ |
/* PUSHED | AGAIN */ |
|
1581 |
|
av_channel_layout_uninit(&new_chans_layout); |
1582 |
1582 |
break; |
break; |
1583 |
1583 |
} |
} |
1584 |
1584 |
/* FILT_RECFG_REQUIRED */ |
/* FILT_RECFG_REQUIRED */ |
1585 |
|
pcm2ff(pcm_g, &dst_fmt, &dst_rate, &dst_chans_n, |
|
1586 |
|
&dst_chans_layout, PRINT_INFO); |
|
|
1585 |
|
pcm2ff(pcm_g, &dst_fmt, &dst_rate, &dst_chans_layout, |
|
1586 |
|
PRINT_INFO); |
1587 |
1587 |
filt_graph_cfg( |
filt_graph_cfg( |
1588 |
|
new_fmt, new_fr_rate, new_chans_n, new_chans_layout, |
|
|
1588 |
|
new_fmt, new_fr_rate, &new_chans_layout, |
1589 |
1589 |
filt_frs.muted, filt_frs.vol, |
filt_frs.muted, filt_frs.vol, |
1590 |
|
dst_fmt, dst_rate, dst_chans_n, dst_chans_layout, |
|
1591 |
|
PRINT_INFO); |
|
|
1590 |
|
dst_fmt, dst_rate, &dst_chans_layout, PRINT_INFO); |
|
1591 |
|
av_channel_layout_uninit(&new_chans_layout); |
|
1592 |
|
av_channel_layout_uninit(&dst_chans_layout); |
1592 |
1593 |
} |
} |
1593 |
1594 |
filt_frs_get(); |
filt_frs_get(); |
1594 |
1595 |
} |
} |
|
... |
... |
static void chans_buf_init(u8 **chans_buf, int start_fr_idx) |
1609 |
1610 |
if (is_planar_fmt == NO) { /* or is pcm interleaved */ |
if (is_planar_fmt == NO) { /* or is pcm interleaved */ |
1610 |
1611 |
int fr_bytes_n; |
int fr_bytes_n; |
1611 |
1612 |
|
|
1612 |
|
fr_bytes_n = sample_bytes_n * filt_frs.av->chans_n; |
|
|
1613 |
|
fr_bytes_n = sample_bytes_n |
|
1614 |
|
* filt_frs.av->ch_layout.nb_channels; |
1613 |
1615 |
chans_buf[0] = (u8*)filt_frs.av->data[0] + start_fr_idx |
chans_buf[0] = (u8*)filt_frs.av->data[0] + start_fr_idx |
1614 |
1616 |
* fr_bytes_n; |
* fr_bytes_n; |
1615 |
1617 |
} else { /* ff planar or pcm noninterleaved */ |
} else { /* ff planar or pcm noninterleaved */ |
|
... |
... |
static void chans_buf_init(u8 **chans_buf, int start_fr_idx) |
1617 |
1619 |
|
|
1618 |
1620 |
p = 0; |
p = 0; |
1619 |
1621 |
loop { |
loop { |
1620 |
|
if (p == filt_frs.av->chans_n) |
|
|
1622 |
|
if (p == filt_frs.av->ch_layout.nb_channels) |
1621 |
1623 |
break; |
break; |
1622 |
1624 |
chans_buf[p] = (u8*)filt_frs.av->data[p] |
chans_buf[p] = (u8*)filt_frs.av->data[p] |
1623 |
1625 |
+ start_fr_idx * sample_bytes_n; |
+ start_fr_idx * sample_bytes_n; |
|
... |
... |
static void chans_buf_inc(u8 **chans_buf, int frs_inc) |
1638 |
1640 |
if (is_planar_fmt == NO) { /* or is pcm interleaved */ |
if (is_planar_fmt == NO) { /* or is pcm interleaved */ |
1639 |
1641 |
int fr_bytes_n; |
int fr_bytes_n; |
1640 |
1642 |
|
|
1641 |
|
fr_bytes_n = sample_bytes_n * filt_frs.av->chans_n; |
|
|
1643 |
|
fr_bytes_n = sample_bytes_n |
|
1644 |
|
* filt_frs.av->ch_layout.nb_channels; |
1642 |
1645 |
chans_buf[0] += frs_inc * fr_bytes_n; |
chans_buf[0] += frs_inc * fr_bytes_n; |
1643 |
1646 |
} else { /* ff planar or pcm noninterleaved */ |
} else { /* ff planar or pcm noninterleaved */ |
1644 |
1647 |
u8 p; |
u8 p; |
1645 |
1648 |
|
|
1646 |
1649 |
p = 0; |
p = 0; |
1647 |
1650 |
loop { |
loop { |
1648 |
|
if (p == filt_frs.av->chans_n) |
|
|
1651 |
|
if (p == filt_frs.av->ch_layout.nb_channels) |
1649 |
1652 |
break; |
break; |
1650 |
1653 |
chans_buf[p] += frs_inc * sample_bytes_n; |
chans_buf[p] += frs_inc * sample_bytes_n; |
1651 |
1654 |
++p; |
++p; |
|
... |
... |
static void filt_graph_init_once(void) |
2068 |
2071 |
filt_graph = 0; |
filt_graph = 0; |
2069 |
2072 |
abufsrc_ctx = 0; |
abufsrc_ctx = 0; |
2070 |
2073 |
abufsrc_filt = 0; |
abufsrc_filt = 0; |
|
2074 |
|
memset(&abufsrc_key, 0, sizeof(abufsrc_key)); |
2071 |
2075 |
vol_ctx = 0; |
vol_ctx = 0; |
2072 |
2076 |
vol_filt = 0; |
vol_filt = 0; |
2073 |
2077 |
afmt_ctx = 0; |
afmt_ctx = 0; |
|
... |
... |
static void prepare(int st_idx, double initial_vol, |
2573 |
2577 |
enum av_fr_fmt override_initial_ff_audio_fr_fmt) |
enum av_fr_fmt override_initial_ff_audio_fr_fmt) |
2574 |
2578 |
{ |
{ |
2575 |
2579 |
enum av_fr_fmt dst_fmt; |
enum av_fr_fmt dst_fmt; |
2576 |
|
int dst_rate; |
|
2577 |
|
int dst_chans_n; |
|
2578 |
|
uint64_t src_chans_layout; |
|
2579 |
|
uint64_t dst_chans_layout; |
|
2580 |
2580 |
int initial_ff_chans_n; |
int initial_ff_chans_n; |
2581 |
2581 |
int initial_ff_rate; |
int initial_ff_rate; |
2582 |
2582 |
enum av_fr_fmt initial_ff_audio_fr_fmt; |
enum av_fr_fmt initial_ff_audio_fr_fmt; |
|
... |
... |
static void prepare(int st_idx, double initial_vol, |
2593 |
2593 |
fmt_ctx_unlock(); |
fmt_ctx_unlock(); |
2594 |
2594 |
|
|
2595 |
2595 |
if (override_initial_ff_chans_n == CHANS_N_NOT_OVERRIDDEN) |
if (override_initial_ff_chans_n == CHANS_N_NOT_OVERRIDDEN) |
2596 |
|
initial_ff_chans_n = dec_ctx->chans_n; |
|
|
2596 |
|
initial_ff_chans_n = dec_ctx->ch_layout.nb_channels; |
2597 |
2597 |
else |
else |
2598 |
2598 |
initial_ff_chans_n = override_initial_ff_chans_n; |
initial_ff_chans_n = override_initial_ff_chans_n; |
2599 |
2599 |
if (override_initial_ff_rate == RATE_NOT_OVERRIDDEN) |
if (override_initial_ff_rate == RATE_NOT_OVERRIDDEN) |
|
... |
... |
int main(int argc, u8 **args) |
2909 |
2909 |
#undef av_frs_alloc |
#undef av_frs_alloc |
2910 |
2910 |
#undef av_frs_set_silence |
#undef av_frs_set_silence |
2911 |
2911 |
#undef av_frs_unref |
#undef av_frs_unref |
2912 |
|
#undef av_get_chan_layout_str |
|
2913 |
|
#undef av_get_default_chans_layout |
|
2914 |
2912 |
#undef av_get_fr_fmt_name |
#undef av_get_fr_fmt_name |
2915 |
2913 |
#undef av_get_fr_fmt_str |
#undef av_get_fr_fmt_str |
2916 |
2914 |
#undef av_io_flush |
#undef av_io_flush |
|
... |
... |
int main(int argc, u8 **args) |
2925 |
2923 |
#undef av_frs |
#undef av_frs |
2926 |
2924 |
#undef av_sd_pkt |
#undef av_sd_pkt |
2927 |
2925 |
#undef av_st |
#undef av_st |
2928 |
|
#undef chan_layout |
|
2929 |
|
#undef chans_n |
|
2930 |
2926 |
#undef format |
#undef format |
2931 |
2927 |
#undef fr_fmt |
#undef fr_fmt |
2932 |
2928 |
#undef fr_rate |
#undef fr_rate |
File npv/audio/filt/public/code.frag.c changed (mode: 100644) (index 693218f..0312667) |
3 |
3 |
#define NO_DEC_SET 2 |
#define NO_DEC_SET 2 |
4 |
4 |
#define FILT_SWITCHED_TO_DRAINING 3 |
#define FILT_SWITCHED_TO_DRAINING 3 |
5 |
5 |
#define FILT_RECFG_REQUIRED 4 |
#define FILT_RECFG_REQUIRED 4 |
6 |
|
STATIC u8 filt_push_dec_set(int *new_chans_n, uint64_t *new_chans_layout, |
|
|
6 |
|
STATIC u8 filt_push_dec_set(AVChannelLayout *new_chans_layout, |
7 |
7 |
int *new_rate, enum avutil_audio_fr_fmt_t *new_fmt) |
int *new_rate, enum avutil_audio_fr_fmt_t *new_fmt) |
8 |
8 |
{ |
{ |
9 |
9 |
u8 r8; |
u8 r8; |
|
... |
... |
STATIC u8 filt_push_dec_set(int *new_chans_n, uint64_t *new_chans_layout, |
29 |
29 |
* XXX: this is were dynamic audio recfg is triggered and we get out of |
* XXX: this is were dynamic audio recfg is triggered and we get out of |
30 |
30 |
* the critical section asap |
* the critical section asap |
31 |
31 |
*/ |
*/ |
32 |
|
if (a[0]->chans_layout == 0) /* choose one for the filter */ |
|
33 |
|
a[0]->chans_layout = avutil_get_default_chans_layout( |
|
34 |
|
a[0]->chans_n); |
|
35 |
32 |
if (is_recfg_required(a[0])) { |
if (is_recfg_required(a[0])) { |
36 |
33 |
/* because we are in a critical section */ |
/* because we are in a critical section */ |
37 |
|
*new_chans_n = a[0]->chans_n; |
|
38 |
|
*new_chans_layout = a[0]->chans_layout; |
|
|
34 |
|
ri = av_channel_layout_copy(new_chans_layout, &a[0]->ch_layout); |
|
35 |
|
if (ri < 0) |
|
36 |
|
fatal("ffmpeg:unable to copy the channel layout of the set of frames as a new channel layout\n"); |
39 |
37 |
*new_rate = a[0]->rate; |
*new_rate = a[0]->rate; |
40 |
38 |
*new_fmt = a[0]->fmt; |
*new_fmt = a[0]->fmt; |
41 |
39 |
r8 = FILT_RECFG_REQUIRED; |
r8 = FILT_RECFG_REQUIRED; |
|
... |
... |
STATIC void init_once(double initial_vol) |
106 |
104 |
init_once_public(initial_vol); |
init_once_public(initial_vol); |
107 |
105 |
} |
} |
108 |
106 |
STATIC void cfg(avutil_rational_t tb, |
STATIC void cfg(avutil_rational_t tb, |
109 |
|
int src_chans_n, uint64_t src_chans_layout, int src_rate, |
|
|
107 |
|
AVChannelLayout *src_chans_layout, int src_rate, |
110 |
108 |
enum avutil_audio_fr_fmt_t src_fmt, |
enum avutil_audio_fr_fmt_t src_fmt, |
111 |
109 |
bool muted, double vol, |
bool muted, double vol, |
112 |
|
int dst_chans_n, uint64_t dst_chans_layout, int dst_rate, |
|
|
110 |
|
AVChannelLayout *dst_chans_layout, int dst_rate, |
113 |
111 |
enum avutil_audio_fr_fmt_t dst_fmt, |
enum avutil_audio_fr_fmt_t dst_fmt, |
114 |
112 |
bool print_info) |
bool print_info) |
115 |
113 |
{ |
{ |
|
... |
... |
STATIC void cfg(avutil_rational_t tb, |
121 |
119 |
graph_l = avfilter_graph_alloc(); |
graph_l = avfilter_graph_alloc(); |
122 |
120 |
if (graph_l == 0) |
if (graph_l == 0) |
123 |
121 |
fatal("unable to create filter graph\n"); |
fatal("unable to create filter graph\n"); |
124 |
|
abufsrc_cfg(tb, src_chans_n, src_chans_layout, src_rate, src_fmt, |
|
125 |
|
print_info); |
|
|
122 |
|
abufsrc_cfg(tb, src_chans_layout, src_rate, src_fmt, print_info); |
126 |
123 |
/*--------------------------------------------------------------------*/ |
/*--------------------------------------------------------------------*/ |
127 |
|
abufsrc_l.key.chans_n = src_chans_n; |
|
128 |
|
abufsrc_l.key.chans_layout = src_chans_layout; |
|
|
124 |
|
r = av_channel_layout_copy(&abufsrc_l.key.chans_layout, |
|
125 |
|
src_chans_layout); |
|
126 |
|
if (r < 0) |
|
127 |
|
fatal("unable to copy the source channel layout to the key\n"); |
129 |
128 |
abufsrc_l.key.rate = src_rate; |
abufsrc_l.key.rate = src_rate; |
130 |
129 |
abufsrc_l.key.fmt = src_fmt; |
abufsrc_l.key.fmt = src_fmt; |
131 |
130 |
/*--------------------------------------------------------------------*/ |
/*--------------------------------------------------------------------*/ |
132 |
131 |
vol_cfg(muted, vol); |
vol_cfg(muted, vol); |
133 |
|
afmt_cfg(dst_chans_n, dst_chans_layout, dst_rate, dst_fmt, print_info); |
|
|
132 |
|
afmt_cfg(dst_chans_layout, dst_rate, dst_fmt, print_info); |
134 |
133 |
abufsink_cfg(); |
abufsink_cfg(); |
135 |
134 |
r = avfilter_link(abufsrc_l.ctx, 0, vol_ctx_l, 0); |
r = avfilter_link(abufsrc_l.ctx, 0, vol_ctx_l, 0); |
136 |
135 |
if (r < 0) |
if (r < 0) |
File npv/audio/local/code.frag.c changed (mode: 100644) (index e10e8bd..7b27b7b) |
... |
... |
STATIC u8 *kernel_ts_types_str_l[] = { |
38 |
38 |
* XXX: if it is ever used significantly, a fine granularity wiring strategy |
* XXX: if it is ever used significantly, a fine granularity wiring strategy |
39 |
39 |
* will be implemented instead of using the default wiring |
* will be implemented instead of using the default wiring |
40 |
40 |
*/ |
*/ |
41 |
|
STATIC uint64_t pcm_chmaps2ff_chans_layout(snd_pcm_t *pcm, |
|
42 |
|
unsigned int pcm_chans_n, bool print_info) |
|
|
41 |
|
STATIC void pcm_chmaps2ff_chans_layout(AVChannelLayout *ff_chans_layout, |
|
42 |
|
snd_pcm_t *pcm, unsigned int pcm_chans_n, bool print_info) |
43 |
43 |
{ |
{ |
44 |
44 |
int r; |
int r; |
45 |
|
uint64_t ff_chans_layout; |
|
46 |
45 |
snd_pcm_chmap_t *pcm_chmap; |
snd_pcm_chmap_t *pcm_chmap; |
47 |
46 |
u8 chans_layout_str[STR_SZ]; /* should be overkill */ |
u8 chans_layout_str[STR_SZ]; /* should be overkill */ |
48 |
47 |
|
|
|
... |
... |
STATIC uint64_t pcm_chmaps2ff_chans_layout(snd_pcm_t *pcm, |
55 |
54 |
pout("alsa:your pcm device support channel maps, but fine granularity wiring strategy is not implemented, using default ffmpeg layout\n"); |
pout("alsa:your pcm device support channel maps, but fine granularity wiring strategy is not implemented, using default ffmpeg layout\n"); |
56 |
55 |
free(pcm_chmap); |
free(pcm_chmap); |
57 |
56 |
} |
} |
58 |
|
ff_chans_layout = avutil_get_default_chans_layout((int)pcm_chans_n); |
|
59 |
|
avutil_get_chans_layout_str(chans_layout_str, sizeof(chans_layout_str), |
|
60 |
|
(int)pcm_chans_n, ff_chans_layout); |
|
|
57 |
|
/* XXX: will need to get back at it if a wiring strategy is required */ |
|
58 |
|
av_channel_layout_default(ff_chans_layout, (int)pcm_chans_n); |
|
59 |
|
av_channel_layout_describe(ff_chans_layout, chans_layout_str, |
|
60 |
|
sizeof(chans_layout_str)); |
61 |
61 |
if (print_info) |
if (print_info) |
62 |
62 |
pout("alsa channel map wired to ffmpeg channel layout:\"%s\" (%u pcm channels)\n", chans_layout_str, pcm_chans_n); |
pout("alsa channel map wired to ffmpeg channel layout:\"%s\" (%u pcm channels)\n", chans_layout_str, pcm_chans_n); |
63 |
|
return ff_chans_layout; |
|
64 |
63 |
} |
} |
65 |
64 |
STATIC bool ff_fmt2pcm_layout_best_effort(enum avutil_audio_fr_fmt_t ff_fmt, |
STATIC bool ff_fmt2pcm_layout_best_effort(enum avutil_audio_fr_fmt_t ff_fmt, |
66 |
65 |
snd_pcm_fmt_t *alsa_fmt, snd_pcm_access_t *alsa_access) |
snd_pcm_fmt_t *alsa_fmt, snd_pcm_access_t *alsa_access) |
|
... |
... |
STATIC void pcm_hw_buf_sz_cfg(snd_pcm_t *pcm, |
365 |
364 |
* we try to use a sensible restrict order regarding audio props |
* we try to use a sensible restrict order regarding audio props |
366 |
365 |
*/ |
*/ |
367 |
366 |
STATIC void pcm_cfg_hw_core_best_effort(snd_pcm_t *pcm, |
STATIC void pcm_cfg_hw_core_best_effort(snd_pcm_t *pcm, |
368 |
|
snd_pcm_hw_params_t *pcm_hw_params, int chans_n, uint64_t chans_layout, |
|
|
367 |
|
snd_pcm_hw_params_t *pcm_hw_params, int chans_n, |
369 |
368 |
int rate, enum avutil_audio_fr_fmt_t ff_fmt) |
int rate, enum avutil_audio_fr_fmt_t ff_fmt) |
370 |
369 |
{ |
{ |
371 |
370 |
int r; |
int r; |
|
... |
... |
STATIC void pcm_cfg_hw_core_best_effort(snd_pcm_t *pcm, |
378 |
377 |
if (r < 0) |
if (r < 0) |
379 |
378 |
fatal("alsa:unable to populate the hardware parameters context\n"); |
fatal("alsa:unable to populate the hardware parameters context\n"); |
380 |
379 |
pcm_hw_chans_n_decide(pcm, pcm_hw_params, chans_n); |
pcm_hw_chans_n_decide(pcm, pcm_hw_params, chans_n); |
381 |
|
/* XXX: we ignore chans_layout (remapping done in bridge filt) */ |
|
382 |
380 |
pcm_hw_rate_decide(pcm, pcm_hw_params, rate); |
pcm_hw_rate_decide(pcm, pcm_hw_params, rate); |
383 |
381 |
/* try our best with the fmt */ |
/* try our best with the fmt */ |
384 |
382 |
best_effort_wiring_success = ff_fmt2pcm_layout_best_effort( |
best_effort_wiring_success = ff_fmt2pcm_layout_best_effort( |
|
... |
... |
STATIC void chans_buf_init(u8 **chans_buf, int start_fr_idx) |
469 |
467 |
if (is_planar_fmt == NO) { /* or is pcm interleaved */ |
if (is_planar_fmt == NO) { /* or is pcm interleaved */ |
470 |
468 |
int fr_bytes_n; |
int fr_bytes_n; |
471 |
469 |
|
|
472 |
|
fr_bytes_n = sample_bytes_n * npv_audio_filt_p.set->chans_n; |
|
|
470 |
|
fr_bytes_n = sample_bytes_n |
|
471 |
|
* npv_audio_filt_p.set->ch_layout.nb_channels; |
473 |
472 |
chans_buf[0] = (u8*)npv_audio_filt_p.set->data[0] + start_fr_idx |
chans_buf[0] = (u8*)npv_audio_filt_p.set->data[0] + start_fr_idx |
474 |
473 |
* fr_bytes_n; |
* fr_bytes_n; |
475 |
474 |
} else { /* ff planar or pcm noninterleaved */ |
} else { /* ff planar or pcm noninterleaved */ |
|
... |
... |
STATIC void chans_buf_init(u8 **chans_buf, int start_fr_idx) |
477 |
476 |
|
|
478 |
477 |
p = 0; |
p = 0; |
479 |
478 |
loop { |
loop { |
480 |
|
if (p == npv_audio_filt_p.set->chans_n) |
|
|
479 |
|
if (p == npv_audio_filt_p.set->ch_layout.nb_channels) |
481 |
480 |
break; |
break; |
482 |
481 |
chans_buf[p] = (u8*)npv_audio_filt_p.set->data[p] |
chans_buf[p] = (u8*)npv_audio_filt_p.set->data[p] |
483 |
482 |
+ start_fr_idx * sample_bytes_n; |
+ start_fr_idx * sample_bytes_n; |
|
... |
... |
STATIC void chans_buf_inc(u8 **chans_buf, int inc) |
498 |
497 |
if (is_planar_fmt == NO) { /* or is pcm interleaved */ |
if (is_planar_fmt == NO) { /* or is pcm interleaved */ |
499 |
498 |
int fr_bytes_n; |
int fr_bytes_n; |
500 |
499 |
|
|
501 |
|
fr_bytes_n = sample_bytes_n * npv_audio_filt_p.set->chans_n; |
|
|
500 |
|
fr_bytes_n = sample_bytes_n |
|
501 |
|
* npv_audio_filt_p.set->ch_layout.nb_channels; |
502 |
502 |
chans_buf[0] = (u8*)chans_buf[0] + inc * fr_bytes_n; |
chans_buf[0] = (u8*)chans_buf[0] + inc * fr_bytes_n; |
503 |
503 |
} else { /* ff planar or pcm noninterleaved */ |
} else { /* ff planar or pcm noninterleaved */ |
504 |
504 |
int p; |
int p; |
505 |
505 |
|
|
506 |
506 |
p = 0; |
p = 0; |
507 |
507 |
loop { |
loop { |
508 |
|
if (p == npv_audio_filt_p.set->chans_n) |
|
|
508 |
|
if (p == npv_audio_filt_p.set->ch_layout.nb_channels) |
509 |
509 |
break; |
break; |
510 |
510 |
chans_buf[p] = (u8*)chans_buf[p] + inc * sample_bytes_n; |
chans_buf[p] = (u8*)chans_buf[p] + inc * sample_bytes_n; |
511 |
511 |
++p; |
++p; |
|
... |
... |
STATIC void pcm_layout2ff_fmt_strict(snd_pcm_fmt_t alsa_fmt, |
613 |
613 |
pout("alsa pcm layout \"%s\"/\"%s\" wired strictly to ffmpeg format \"%sbits\"\n", snd_pcm_fmt_desc(alsa_fmt), snd_pcm_access_name(alsa_access), ff_fmt_str); |
pout("alsa pcm layout \"%s\"/\"%s\" wired strictly to ffmpeg format \"%sbits\"\n", snd_pcm_fmt_desc(alsa_fmt), snd_pcm_access_name(alsa_access), ff_fmt_str); |
614 |
614 |
} |
} |
615 |
615 |
} |
} |
616 |
|
STATIC void pcm2ff_strict(snd_pcm_t *pcm, int *ff_chans_n, |
|
617 |
|
uint64_t *ff_chans_layout, int *ff_rate, |
|
618 |
|
enum avutil_audio_fr_fmt_t *ff_fmt, bool print_info) |
|
|
616 |
|
STATIC void pcm2ff_strict(snd_pcm_t *pcm, AVChannelLayout *ff_chans_layout, |
|
617 |
|
int *ff_rate, enum avutil_audio_fr_fmt_t *ff_fmt, bool print_info) |
619 |
618 |
{ |
{ |
620 |
619 |
int r; |
int r; |
621 |
620 |
snd_pcm_hw_params_t *hw_params; |
snd_pcm_hw_params_t *hw_params; |
|
... |
... |
STATIC void pcm2ff_strict(snd_pcm_t *pcm, int *ff_chans_n, |
647 |
646 |
r = snd_pcm_hw_params_get_chans_n(hw_params, &pcm_chans_n); |
r = snd_pcm_hw_params_get_chans_n(hw_params, &pcm_chans_n); |
648 |
647 |
if (r < 0) |
if (r < 0) |
649 |
648 |
fatal("alsa:unable to get the pcm count of channels for ffmpeg filter wiring\n"); |
fatal("alsa:unable to get the pcm count of channels for ffmpeg filter wiring\n"); |
650 |
|
*ff_chans_n = (int)pcm_chans_n; |
|
651 |
649 |
/*--------------------------------------------------------------------*/ |
/*--------------------------------------------------------------------*/ |
652 |
|
*ff_chans_layout = pcm_chmaps2ff_chans_layout(pcm, pcm_chans_n, |
|
|
650 |
|
pcm_chmaps2ff_chans_layout(ff_chans_layout, pcm, pcm_chans_n, |
653 |
651 |
print_info); |
print_info); |
654 |
652 |
/*--------------------------------------------------------------------*/ |
/*--------------------------------------------------------------------*/ |
655 |
653 |
snd_pcm_hw_params_free(hw_params); |
snd_pcm_hw_params_free(hw_params); |
|
... |
... |
STATIC u8 dec_set_filter(void) |
666 |
664 |
u8 r; |
u8 r; |
667 |
665 |
|
|
668 |
666 |
loop { |
loop { |
669 |
|
int new_chans_n; |
|
670 |
|
uint64_t new_chans_layout; |
|
|
667 |
|
AVChannelLayout new_chans_layout; |
671 |
668 |
int new_rate; |
int new_rate; |
672 |
669 |
enum avutil_audio_fr_fmt_t new_fmt; |
enum avutil_audio_fr_fmt_t new_fmt; |
673 |
|
int dst_chans_n; |
|
674 |
|
uint64_t dst_chans_layout; |
|
|
670 |
|
AVChannelLayout dst_chans_layout; |
675 |
671 |
int dst_rate; |
int dst_rate; |
676 |
672 |
enum avutil_audio_fr_fmt_t dst_fmt; |
enum avutil_audio_fr_fmt_t dst_fmt; |
677 |
673 |
|
|
678 |
|
r = filt_push_dec_set(&new_chans_n, &new_chans_layout, |
|
679 |
|
&new_rate, &new_fmt); |
|
680 |
|
if (r == NO_DEC_SET) /* pipeline not fast enough */ |
|
|
674 |
|
memset(&new_chans_layout, 0, sizeof(new_chans_layout)); |
|
675 |
|
memset(&dst_chans_layout, 0, sizeof(dst_chans_layout)); |
|
676 |
|
|
|
677 |
|
r = filt_push_dec_set(&new_chans_layout, &new_rate, &new_fmt); |
|
678 |
|
if (r == NO_DEC_SET) {/* pipeline not fast enough */ |
|
679 |
|
av_channel_layout_uninit(&new_chans_layout); |
681 |
680 |
return NO_DEC_SET; |
return NO_DEC_SET; |
|
681 |
|
} |
682 |
682 |
else if (r != FILT_RECFG_REQUIRED) { |
else if (r != FILT_RECFG_REQUIRED) { |
683 |
683 |
/* FILT_SWITCHED_TO_DRAINING | PUSHED_ONE_SET | AGAIN */ |
/* FILT_SWITCHED_TO_DRAINING | PUSHED_ONE_SET | AGAIN */ |
|
684 |
|
av_channel_layout_uninit(&new_chans_layout); |
684 |
685 |
break; |
break; |
685 |
686 |
} |
} |
686 |
687 |
/* FILT_RECFG_REQUIRED */ |
/* FILT_RECFG_REQUIRED */ |
687 |
|
pcm2ff_strict(npv_audio_pcm_p, &dst_chans_n, &dst_chans_layout, |
|
688 |
|
&dst_rate, &dst_fmt, PRINT_INFO); |
|
|
688 |
|
pcm2ff_strict(npv_audio_pcm_p, &dst_chans_layout, &dst_rate, |
|
689 |
|
&dst_fmt, PRINT_INFO); |
689 |
690 |
filt_cfg(st_p.tb, |
filt_cfg(st_p.tb, |
690 |
|
new_chans_n, new_chans_layout, new_rate, new_fmt, |
|
|
691 |
|
&new_chans_layout, new_rate, new_fmt, |
691 |
692 |
filt_p.muted, filt_p.vol, |
filt_p.muted, filt_p.vol, |
692 |
|
dst_chans_n, dst_chans_layout, dst_rate, dst_fmt, |
|
693 |
|
PRINT_INFO); |
|
|
693 |
|
&dst_chans_layout, dst_rate, dst_fmt, PRINT_INFO); |
|
694 |
|
av_channel_layout_uninit(&new_chans_layout); |
|
695 |
|
av_channel_layout_uninit(&dst_chans_layout); |
694 |
696 |
} |
} |
695 |
697 |
r = npv_audio_filt_set_get(); |
r = npv_audio_filt_set_get(); |
696 |
698 |
if (r == EOF_FILT) { |
if (r == EOF_FILT) { |
File npv/audio/public/code.frag.c changed (mode: 100644) (index e11ee55..8d25d49) |
... |
... |
STATIC void dec_sets_unlock(void) |
253 |
253 |
if (r != 0) |
if (r != 0) |
254 |
254 |
fatal("%d:unable to unlock the array of decoder sets\n", r); |
fatal("%d:unable to unlock the array of decoder sets\n", r); |
255 |
255 |
} |
} |
256 |
|
STATIC void pcm_cfg_hw_best_effort(snd_pcm_t *pcm, int chans_n, |
|
257 |
|
uint64_t ff_chans_layout, int rate, enum avutil_audio_fr_fmt_t ff_fmt) |
|
|
256 |
|
STATIC void pcm_cfg_hw_best_effort(snd_pcm_t *pcm, int chans_n, int rate, |
|
257 |
|
enum avutil_audio_fr_fmt_t ff_fmt) |
258 |
258 |
{ |
{ |
259 |
259 |
int r; |
int r; |
260 |
260 |
s8 i; |
s8 i; |
|
... |
... |
STATIC void pcm_cfg_hw_best_effort(snd_pcm_t *pcm, int chans_n, |
265 |
265 |
r = snd_pcm_hw_params_malloc(&hw_params); |
r = snd_pcm_hw_params_malloc(&hw_params); |
266 |
266 |
if (r < 0) |
if (r < 0) |
267 |
267 |
fatal("alsa:unable to allocate hardware parameters context\n"); |
fatal("alsa:unable to allocate hardware parameters context\n"); |
268 |
|
pcm_cfg_hw_core_best_effort(pcm, hw_params, chans_n, ff_chans_layout, |
|
269 |
|
rate, ff_fmt); |
|
|
268 |
|
pcm_cfg_hw_core_best_effort(pcm, hw_params, chans_n, rate, ff_fmt); |
270 |
269 |
r = snd_pcm_hw_params(pcm, hw_params); |
r = snd_pcm_hw_params(pcm, hw_params); |
271 |
270 |
if (r != 0) |
if (r != 0) |
272 |
271 |
fatal("alsa:unable to install the hardware parameters\n"); |
fatal("alsa:unable to install the hardware parameters\n"); |
|
... |
... |
STATIC void npv_audio_prepare(int override_initial_ff_chans_n, |
364 |
363 |
int override_initial_ff_rate, |
int override_initial_ff_rate, |
365 |
364 |
enum avutil_audio_fr_fmt_t override_initial_ff_fmt) |
enum avutil_audio_fr_fmt_t override_initial_ff_fmt) |
366 |
365 |
{ |
{ |
367 |
|
int dst_chans_n; |
|
368 |
|
uint64_t dst_chans_layout; |
|
369 |
366 |
int dst_rate; |
int dst_rate; |
370 |
367 |
enum avutil_audio_fr_fmt_t dst_fmt; |
enum avutil_audio_fr_fmt_t dst_fmt; |
371 |
368 |
int initial_ff_chans_n; |
int initial_ff_chans_n; |
372 |
|
uint64_t src_chans_layout; |
|
373 |
369 |
int initial_ff_rate; |
int initial_ff_rate; |
374 |
370 |
enum avutil_audio_fr_fmt_t initial_ff_fmt; |
enum avutil_audio_fr_fmt_t initial_ff_fmt; |
|
371 |
|
int r; |
|
372 |
|
|
375 |
373 |
/* |
/* |
376 |
374 |
* do our best to match the pcm cfg to audio ff dec output OR the user |
* do our best to match the pcm cfg to audio ff dec output OR the user |
377 |
375 |
* overrides, BUT we don't expect to match it "exactly": a ff filt |
* overrides, BUT we don't expect to match it "exactly": a ff filt |
378 |
376 |
* will bridge the difference |
* will bridge the difference |
379 |
377 |
*/ |
*/ |
380 |
378 |
if (override_initial_ff_chans_n == CHANS_N_NOT_OVERRIDDEN) |
if (override_initial_ff_chans_n == CHANS_N_NOT_OVERRIDDEN) |
381 |
|
initial_ff_chans_n = dec_ctx_p->chans_n; |
|
|
379 |
|
/* we presume the dec_ctx has at least a valid chans_n */ |
|
380 |
|
initial_ff_chans_n = dec_ctx_p->ch_layout.nb_channels; |
382 |
381 |
else |
else |
383 |
382 |
initial_ff_chans_n = override_initial_ff_chans_n; |
initial_ff_chans_n = override_initial_ff_chans_n; |
384 |
|
/* the audio dec ctx may not have a valid chans layout */ |
|
385 |
|
if (dec_ctx_p->chans_layout == 0) { |
|
386 |
|
src_chans_layout = avutil_get_default_chans_layout( |
|
387 |
|
dec_ctx_p->chans_n); |
|
388 |
|
} else |
|
389 |
|
src_chans_layout = dec_ctx_p->chans_layout; |
|
390 |
383 |
if (override_initial_ff_rate == RATE_NOT_OVERRIDDEN) |
if (override_initial_ff_rate == RATE_NOT_OVERRIDDEN) |
391 |
384 |
initial_ff_rate = dec_ctx_p->fr_rate; |
initial_ff_rate = dec_ctx_p->fr_rate; |
392 |
385 |
else |
else |
|
... |
... |
STATIC void npv_audio_prepare(int override_initial_ff_chans_n, |
396 |
389 |
else |
else |
397 |
390 |
initial_ff_fmt = override_initial_ff_fmt; |
initial_ff_fmt = override_initial_ff_fmt; |
398 |
391 |
npv_audio_pcm_cfg_hw_best_effort(pcm_p, initial_ff_chans_n, |
npv_audio_pcm_cfg_hw_best_effort(pcm_p, initial_ff_chans_n, |
399 |
|
src_chans_layout, initial_ff_rate, initial_ff_fmt); |
|
|
392 |
|
initial_ff_rate, initial_ff_fmt); |
400 |
393 |
npv_audio_pcm_silence_bufs_cfg(pcm_p, PRINT_INFO); |
npv_audio_pcm_silence_bufs_cfg(pcm_p, PRINT_INFO); |
401 |
394 |
npv_audio_pcm_cfg_sw(pcm_p); |
npv_audio_pcm_cfg_sw(pcm_p); |
402 |
395 |
pout("ALSA PCM DUMP START-------------------------------------------------------------\n"); |
pout("ALSA PCM DUMP START-------------------------------------------------------------\n"); |