File npv/audio/filt/public/code.frag.c changed (mode: 100644) (index 2fd1fef..77bd9c9) |
1 |
|
/*NSPC*/ |
|
2 |
1 |
#define AGAIN 0 |
#define AGAIN 0 |
3 |
2 |
#define PUSHED_ONE_SET 1 |
#define PUSHED_ONE_SET 1 |
4 |
3 |
#define NO_DEC_SET 2 |
#define NO_DEC_SET 2 |
|
... |
... |
STATIC u8 filt_push_dec_set(int *new_chans_n, uint64_t *new_chans_layout, |
30 |
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 |
31 |
30 |
* the critical section asap |
* the critical section asap |
32 |
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); |
33 |
35 |
if (is_recfg_required(a[0])) { |
if (is_recfg_required(a[0])) { |
34 |
36 |
/* because we are in a critical section */ |
/* because we are in a critical section */ |
35 |
37 |
*new_chans_n = a[0]->chans_n; |
*new_chans_n = a[0]->chans_n; |
|
... |
... |
STATIC u8 filt_set_get(void) |
93 |
95 |
#define DONT_PRINT_INFO false |
#define DONT_PRINT_INFO false |
94 |
96 |
STATIC void filt_flush(void) |
STATIC void filt_flush(void) |
95 |
97 |
{ |
{ |
96 |
|
int dst_chans_n; |
|
97 |
|
enum avutil_audio_fr_fmt_t dst_fmt; |
|
98 |
|
uint64_t src_chans_layout; |
|
99 |
|
uint64_t dst_chans_layout; |
|
100 |
|
int dst_rate; |
|
101 |
|
|
|
102 |
98 |
avutil_audio_set_unref(filt_p.set); |
avutil_audio_set_unref(filt_p.set); |
103 |
99 |
filt_p.pcm_written_ufrs_n = 0; |
filt_p.pcm_written_ufrs_n = 0; |
104 |
|
|
|
105 |
|
npv_audio_pcm2ff_strict(npv_audio_pcm_p, &dst_chans_n, |
|
106 |
|
&dst_chans_layout, &dst_rate, &dst_fmt, DONT_PRINT_INFO); |
|
107 |
|
/* the audio dec ctx may not have a valid chans layout */ |
|
108 |
|
if (npv_audio_dec_ctx_p->chans_layout == 0) |
|
109 |
|
src_chans_layout = avutil_get_default_chans_layout( |
|
110 |
|
npv_audio_dec_ctx_p->chans_n); |
|
111 |
|
else |
|
112 |
|
src_chans_layout = npv_audio_dec_ctx_p->chans_layout; |
|
113 |
|
cfg(npv_audio_dec_ctx_p->chans_n, src_chans_layout, |
|
114 |
|
npv_audio_dec_ctx_p->fr_rate, npv_audio_dec_ctx_p->fr_fmt, |
|
115 |
|
filt_p.muted, filt_p.vol, |
|
116 |
|
dst_chans_n, dst_chans_layout, dst_rate, dst_fmt, |
|
117 |
|
DONT_PRINT_INFO); |
|
118 |
100 |
} |
} |
119 |
101 |
#undef DONT_PRINT_INFO |
#undef DONT_PRINT_INFO |
120 |
102 |
STATIC void init_once(double initial_vol) |
STATIC void init_once(double initial_vol) |
File npv/audio/local/code.frag.c changed (mode: 100644) (index 48f17da..3f827fe) |
... |
... |
STATIC void draining_state_switch(void) |
568 |
568 |
if (r == -1) |
if (r == -1) |
569 |
569 |
fatal("unable to arm the draining timer\n"); |
fatal("unable to arm the draining timer\n"); |
570 |
570 |
} |
} |
|
571 |
|
/* fatal if the wiring cannot be done */ |
|
572 |
|
STATIC void pcm_layout2ff_fmt_strict(snd_pcm_fmt_t alsa_fmt, |
|
573 |
|
snd_pcm_access_t alsa_access, enum avutil_audio_fr_fmt_t *ff_fmt, |
|
574 |
|
bool print_info) |
|
575 |
|
{ |
|
576 |
|
/* |
|
577 |
|
* ff fmt byte order is always native. |
|
578 |
|
* here we handle little endian only |
|
579 |
|
*/ |
|
580 |
|
switch (alsa_fmt) { |
|
581 |
|
case SND_PCM_FMT_FLOAT: |
|
582 |
|
if (alsa_access == SND_PCM_ACCESS_RW_INTERLEAVED) |
|
583 |
|
*ff_fmt = AVUTIL_AUDIO_FR_FMT_FLT; |
|
584 |
|
else |
|
585 |
|
*ff_fmt = AVUTIL_AUDIO_FR_FMT_FLTP; |
|
586 |
|
break; |
|
587 |
|
case SND_PCM_FMT_S32: |
|
588 |
|
if (alsa_access == SND_PCM_ACCESS_RW_INTERLEAVED) |
|
589 |
|
*ff_fmt = AVUTIL_AUDIO_FR_FMT_S32; |
|
590 |
|
else |
|
591 |
|
*ff_fmt = AVUTIL_AUDIO_FR_FMT_S32P; |
|
592 |
|
break; |
|
593 |
|
case SND_PCM_FMT_S16: |
|
594 |
|
if (alsa_access == SND_PCM_ACCESS_RW_INTERLEAVED) |
|
595 |
|
*ff_fmt = AVUTIL_AUDIO_FR_FMT_S16; |
|
596 |
|
else |
|
597 |
|
*ff_fmt = AVUTIL_AUDIO_FR_FMT_S16P; |
|
598 |
|
break; |
|
599 |
|
case SND_PCM_FMT_U8: |
|
600 |
|
if (alsa_access == SND_PCM_ACCESS_RW_INTERLEAVED) |
|
601 |
|
*ff_fmt = AVUTIL_AUDIO_FR_FMT_U8; |
|
602 |
|
else |
|
603 |
|
*ff_fmt = AVUTIL_AUDIO_FR_FMT_U8P; |
|
604 |
|
break; |
|
605 |
|
default: |
|
606 |
|
fatal("unable to wire strictly alsa layout \"%s\"/\"%s\" to a ffmpeg format\n", snd_pcm_fmt_desc(alsa_fmt), snd_pcm_access_name(alsa_access)); |
|
607 |
|
} |
|
608 |
|
if (print_info) { |
|
609 |
|
u8 ff_fmt_str[STR_SZ]; |
|
610 |
|
|
|
611 |
|
avutil_get_audio_fr_fmt_str(ff_fmt_str, sizeof(ff_fmt_str), |
|
612 |
|
*ff_fmt); |
|
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); |
|
614 |
|
} |
|
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) |
|
619 |
|
{ |
|
620 |
|
int r; |
|
621 |
|
snd_pcm_hw_params_t *hw_params; |
|
622 |
|
unsigned int pcm_chans_n; |
|
623 |
|
unsigned int pcm_rate; |
|
624 |
|
snd_pcm_fmt_t pcm_fmt; |
|
625 |
|
snd_pcm_access_t pcm_access; |
|
626 |
|
|
|
627 |
|
r = snd_pcm_hw_params_malloc(&hw_params); |
|
628 |
|
if (r < 0) |
|
629 |
|
fatal("alsa:unable to allocate hardware parameters context for ffmpeg filter wiring\n"); |
|
630 |
|
r = snd_pcm_hw_params_current(pcm, hw_params); |
|
631 |
|
if (r != 0) |
|
632 |
|
fatal("alsa:unable to get current hardware parameters for ffmpeg filter wiring\n"); |
|
633 |
|
r = snd_pcm_hw_params_get_access(hw_params, &pcm_access); |
|
634 |
|
if (r < 0) |
|
635 |
|
fatal("alsa:unable to get the pcm access for ffmpeg filter wiring\n"); |
|
636 |
|
r = snd_pcm_hw_params_get_fmt(hw_params, &pcm_fmt); |
|
637 |
|
if (r < 0) |
|
638 |
|
fatal("alsa:unable to get the pcm format for ffmpeg filter wiring\n"); |
|
639 |
|
/*--------------------------------------------------------------------*/ |
|
640 |
|
pcm_layout2ff_fmt_strict(pcm_fmt, pcm_access, ff_fmt, print_info); |
|
641 |
|
/*--------------------------------------------------------------------*/ |
|
642 |
|
r = snd_pcm_hw_params_get_rate(hw_params, &pcm_rate, |
|
643 |
|
SND_PCM_ST_PLAYBACK); |
|
644 |
|
if (r < 0) |
|
645 |
|
fatal("alsa:unable to get the pcm rate for ffmpeg filter wiring\n"); |
|
646 |
|
*ff_rate = (int)pcm_rate; |
|
647 |
|
r = snd_pcm_hw_params_get_chans_n(hw_params, &pcm_chans_n); |
|
648 |
|
if (r < 0) |
|
649 |
|
fatal("alsa:unable to get the pcm count of channels for ffmpeg filter wiring\n"); |
|
650 |
|
*ff_chans_n = (int)pcm_chans_n; |
|
651 |
|
/*--------------------------------------------------------------------*/ |
|
652 |
|
*ff_chans_layout = pcm_chmaps2ff_chans_layout(pcm, pcm_chans_n, |
|
653 |
|
print_info); |
|
654 |
|
/*--------------------------------------------------------------------*/ |
|
655 |
|
snd_pcm_hw_params_free(hw_params); |
|
656 |
|
} |
571 |
657 |
#define NO_DEC_SET 2 |
#define NO_DEC_SET 2 |
572 |
658 |
#define FILT_RECFG_REQUIRED 4 |
#define FILT_RECFG_REQUIRED 4 |
573 |
659 |
#define EOF_FILT 2 |
#define EOF_FILT 2 |
|
... |
... |
STATIC u8 dec_set_filter(void) |
600 |
686 |
/* FILT_RECFG_REQUIRED */ |
/* FILT_RECFG_REQUIRED */ |
601 |
687 |
pcm2ff_strict(npv_audio_pcm_p, &dst_chans_n, &dst_chans_layout, |
pcm2ff_strict(npv_audio_pcm_p, &dst_chans_n, &dst_chans_layout, |
602 |
688 |
&dst_rate, &dst_fmt, PRINT_INFO); |
&dst_rate, &dst_fmt, PRINT_INFO); |
603 |
|
/* may not have a valid src chans layout, "fix it" */ |
|
604 |
|
if (new_chans_layout == 0) |
|
605 |
|
new_chans_layout = avutil_get_default_chans_layout( |
|
606 |
|
new_chans_n); |
|
607 |
689 |
filt_cfg(new_chans_n, new_chans_layout, new_rate, new_fmt, |
filt_cfg(new_chans_n, new_chans_layout, new_rate, new_fmt, |
608 |
690 |
filt_p.muted, filt_p.vol, |
filt_p.muted, filt_p.vol, |
609 |
691 |
dst_chans_n, dst_chans_layout, dst_rate, dst_fmt, |
dst_chans_n, dst_chans_layout, dst_rate, dst_fmt, |
|
... |
... |
STATIC void dec_a_unref_all(void) |
794 |
876 |
} |
} |
795 |
877 |
dec_sets_p.n = 0; |
dec_sets_p.n = 0; |
796 |
878 |
} |
} |
797 |
|
/* fatal if the wiring cannot be done */ |
|
798 |
|
STATIC void pcm_layout2ff_fmt_strict(snd_pcm_fmt_t alsa_fmt, |
|
799 |
|
snd_pcm_access_t alsa_access, enum avutil_audio_fr_fmt_t *ff_fmt, |
|
800 |
|
bool print_info) |
|
801 |
|
{ |
|
802 |
|
/* |
|
803 |
|
* ff fmt byte order is always native. |
|
804 |
|
* here we handle little endian only |
|
805 |
|
*/ |
|
806 |
|
switch (alsa_fmt) { |
|
807 |
|
case SND_PCM_FMT_FLOAT: |
|
808 |
|
if (alsa_access == SND_PCM_ACCESS_RW_INTERLEAVED) |
|
809 |
|
*ff_fmt = AVUTIL_AUDIO_FR_FMT_FLT; |
|
810 |
|
else |
|
811 |
|
*ff_fmt = AVUTIL_AUDIO_FR_FMT_FLTP; |
|
812 |
|
break; |
|
813 |
|
case SND_PCM_FMT_S32: |
|
814 |
|
if (alsa_access == SND_PCM_ACCESS_RW_INTERLEAVED) |
|
815 |
|
*ff_fmt = AVUTIL_AUDIO_FR_FMT_S32; |
|
816 |
|
else |
|
817 |
|
*ff_fmt = AVUTIL_AUDIO_FR_FMT_S32P; |
|
818 |
|
break; |
|
819 |
|
case SND_PCM_FMT_S16: |
|
820 |
|
if (alsa_access == SND_PCM_ACCESS_RW_INTERLEAVED) |
|
821 |
|
*ff_fmt = AVUTIL_AUDIO_FR_FMT_S16; |
|
822 |
|
else |
|
823 |
|
*ff_fmt = AVUTIL_AUDIO_FR_FMT_S16P; |
|
824 |
|
break; |
|
825 |
|
case SND_PCM_FMT_U8: |
|
826 |
|
if (alsa_access == SND_PCM_ACCESS_RW_INTERLEAVED) |
|
827 |
|
*ff_fmt = AVUTIL_AUDIO_FR_FMT_U8; |
|
828 |
|
else |
|
829 |
|
*ff_fmt = AVUTIL_AUDIO_FR_FMT_U8P; |
|
830 |
|
break; |
|
831 |
|
default: |
|
832 |
|
fatal("unable to wire strictly alsa layout \"%s\"/\"%s\" to a ffmpeg format\n", snd_pcm_fmt_desc(alsa_fmt), snd_pcm_access_name(alsa_access)); |
|
833 |
|
} |
|
834 |
|
if (print_info) { |
|
835 |
|
u8 ff_fmt_str[STR_SZ]; |
|
836 |
|
|
|
837 |
|
avutil_get_audio_fr_fmt_str(ff_fmt_str, sizeof(ff_fmt_str), |
|
838 |
|
*ff_fmt); |
|
839 |
|
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); |
|
840 |
|
} |
|
841 |
|
} |
|
File npv/audio/public/code.frag.c changed (mode: 100644) (index 9ac9f70..8a2da33) |
... |
... |
STATIC void npv_audio_prepare(int override_initial_ff_chans_n, |
397 |
397 |
#undef RATE_NOT_OVERRIDDEN |
#undef RATE_NOT_OVERRIDDEN |
398 |
398 |
#undef AUDIO_FR_FMT_NOT_OVERRIDDEN |
#undef AUDIO_FR_FMT_NOT_OVERRIDDEN |
399 |
399 |
#undef PRINT_INFO |
#undef PRINT_INFO |
400 |
|
STATIC void pcm2ff_strict(snd_pcm_t *pcm, int *ff_chans_n, |
|
401 |
|
uint64_t *ff_chans_layout, int *ff_rate, |
|
402 |
|
enum avutil_audio_fr_fmt_t *ff_fmt, bool print_info) |
|
403 |
|
{ |
|
404 |
|
int r; |
|
405 |
|
snd_pcm_hw_params_t *hw_params; |
|
406 |
|
unsigned int pcm_chans_n; |
|
407 |
|
unsigned int pcm_rate; |
|
408 |
|
snd_pcm_fmt_t pcm_fmt; |
|
409 |
|
snd_pcm_access_t pcm_access; |
|
410 |
|
|
|
411 |
|
r = snd_pcm_hw_params_malloc(&hw_params); |
|
412 |
|
if (r < 0) |
|
413 |
|
fatal("alsa:unable to allocate hardware parameters context for ffmpeg filter wiring\n"); |
|
414 |
|
r = snd_pcm_hw_params_current(pcm, hw_params); |
|
415 |
|
if (r != 0) |
|
416 |
|
fatal("alsa:unable to get current hardware parameters for ffmpeg filter wiring\n"); |
|
417 |
|
r = snd_pcm_hw_params_get_access(hw_params, &pcm_access); |
|
418 |
|
if (r < 0) |
|
419 |
|
fatal("alsa:unable to get the pcm access for ffmpeg filter wiring\n"); |
|
420 |
|
r = snd_pcm_hw_params_get_fmt(hw_params, &pcm_fmt); |
|
421 |
|
if (r < 0) |
|
422 |
|
fatal("alsa:unable to get the pcm format for ffmpeg filter wiring\n"); |
|
423 |
|
/*--------------------------------------------------------------------*/ |
|
424 |
|
pcm_layout2ff_fmt_strict(pcm_fmt, pcm_access, ff_fmt, print_info); |
|
425 |
|
/*--------------------------------------------------------------------*/ |
|
426 |
|
r = snd_pcm_hw_params_get_rate(hw_params, &pcm_rate, |
|
427 |
|
SND_PCM_ST_PLAYBACK); |
|
428 |
|
if (r < 0) |
|
429 |
|
fatal("alsa:unable to get the pcm rate for ffmpeg filter wiring\n"); |
|
430 |
|
*ff_rate = (int)pcm_rate; |
|
431 |
|
r = snd_pcm_hw_params_get_chans_n(hw_params, &pcm_chans_n); |
|
432 |
|
if (r < 0) |
|
433 |
|
fatal("alsa:unable to get the pcm count of channels for ffmpeg filter wiring\n"); |
|
434 |
|
*ff_chans_n = (int)pcm_chans_n; |
|
435 |
|
/*--------------------------------------------------------------------*/ |
|
436 |
|
*ff_chans_layout = pcm_chmaps2ff_chans_layout(pcm, pcm_chans_n, |
|
437 |
|
print_info); |
|
438 |
|
/*--------------------------------------------------------------------*/ |
|
439 |
|
snd_pcm_hw_params_free(hw_params); |
|
440 |
|
} |
|