sylware / nyanmp (public) (License: AGPLv3) (since 2020-02-12) (hash sha1)
intended to become a collection of media players for gnu/linux based on ffmpeg, alsa, vulkan, x11, wayland, etc.
List of commits:
Subject Hash Author Date (UTC)
npv:_reasonable_ "pedanticage" of the code c5f2644d6eba84bcbcc9b0599c41e1f6733ea95c Sylvain BERTRAND 2020-08-20 16:25:50
npa:some amount of pedanticage 554bd5b07b1a82eabb2622cbf565031bf7af5c6d Sylvain BERTRAND 2020-08-18 19:33:47
hacking again on it after a rather long time cc09df4f340c9f906e0de9520d2c803ea6936769 Sylvain BERTRAND 2020-08-16 18:14:14
npv:fix initial volume not being stored ef66775061157e5af7d6938d06f38e6e7d06a873 Sylvain BERTRAND 2020-08-15 16:59:23
npv:fixing the fix 2043d3ae57ff8b4c26acfd1ee2ff8958cb887ab8 Sylvain BERTRAND 2020-07-17 19:11:14
npv:fixing minor annoyances 2b1895f92933d41a7eb6b7638a94f526e1b5e7cd Sylvain BERTRAND 2020-07-17 19:03:47
npv:spurious namespace tag 65b5c4970e0c0b651ff8d9d61ce2ab0654a039fd Sylvain BERTRAND 2020-06-06 23:22:19
npv:namespace cleanup, don't need that many short identifiers 86d95bbd53a6c9264a44ae98038db9bf4d195e29 Sylvain BERTRAND 2020-06-06 22:44:11
npv:aspect ratio handling 946f160f000a6def790ea64cde5fd31a284f2bd7 Sylvain BERTRAND 2020-06-05 22:21:40
npv:vulkan refactoring to prepare resize handling e6ce6ebf7540d3e7ac2587400e3c0b5289369d19 Sylvain BERTRAND 2020-06-03 17:48:39
npv: x11 wm sugar, fullscreen 7801421eea4849e855916665ede8e9b325520118 Sylvain BERTRAND 2020-06-02 13:39:16
npa: fix initial scheduling bd228fb06dda312888dc6425ebc08dfb2c1d06ae Sylvain BERTRAND 2020-06-02 10:17:42
npv: x11 fixes and more sugar 043ef16cabacaddada9c322fa39871048ef95aae Sylvain BERTRAND 2020-06-01 22:18:22
npv:x11 sugar acd88647f348333fee796a6062963e9cea847d2f Sylvain BERTRAND 2020-05-30 21:26:47
npv: video timer names 8ab20e0c91538f9f84c09c78ee2d5242b5b74607 Sylvain BERTRAND 2020-05-30 17:14:56
npv:less worse pause support, some cleanup ded1666c8970d67bba8f5d0d2ee25230403bc9c3 Sylvain BERTRAND 2020-05-30 16:26:21
npv:fix dynamic loading of xcb lib 0235137068f40277460c4b6ea340bc5674d8dc7d Sylvain BERTRAND 2020-05-29 21:21:01
npv:x11/xcb screensaver heartbeat bd293398599beae694bd3f862c374489067a9f53 Sylvain BERTRAND 2020-05-29 21:06:00
npa: don't slow down too much the audio thread 1b8f1e2dd1d5272cd04a8fa711f26cdc3b6e1049 Sylvain BERTRAND 2020-05-29 03:00:23
npv/npa: lockless madness and much more 368cb50098ac824cc5cb603c3e1539adfeda7e1d Sylvain BERTRAND 2020-05-29 02:20:19
Commit c5f2644d6eba84bcbcc9b0599c41e1f6733ea95c - npv:_reasonable_ "pedanticage" of the code
Author: Sylvain BERTRAND
Author date (UTC): 2020-08-20 16:25
Committer name: Sylvain BERTRAND
Committer date (UTC): 2020-08-20 16:25
Parent(s): 554bd5b07b1a82eabb2622cbf565031bf7af5c6d
Signer:
Signing key:
Signing status: N
Tree: 2421b853aa911f01aafab2e85160983b4ab98888
File Lines added Lines deleted
npv/README 19 8
npv/audio/filt/local/code.frag.c 49 22
npv/audio/filt/main.c 2 8
npv/audio/filt/namespace/main.c 6 0
npv/audio/filt/public/code.frag.c 21 21
npv/audio/local/code.frag.c 101 74
npv/audio/main.c 1 7
npv/audio/namespace/main.c 6 0
npv/audio/public/code.frag.c 37 37
npv/clk/local/code.frag.c 10 0
npv/clk/main.c 2 1
npv/clk/public/code.frag.c 8 8
npv/fmt/local/code.frag.c 21 3
npv/fmt/main.c 3 8
npv/fmt/namespace/main.c 4 0
npv/fmt/public/code.frag.c 8 8
npv/global.h 0 5
npv/local/code.frag.c 100 100
npv/main.c 3 0
npv/make-template.sh 7 0
npv/namespace/public.h 18 0
npv/pipeline/local/code.frag.c 25 7
npv/pipeline/main.c 2 8
npv/pipeline/namespace/main.c 4 0
npv/pipeline/public/code.frag.c 20 20
npv/pkt_q/local/code.frag.c 20 2
npv/pkt_q/main.c 2 6
npv/pkt_q/namespace/main.c 5 1
npv/pkt_q/public/code.frag.c 4 4
npv/public.h 16 3
npv/public/code.frag.c 88 0
npv/thdsws/local/code.frag.c 24 6
npv/thdsws/main.c 2 6
npv/thdsws/namespace/main.c 4 0
npv/thdsws/public/code.frag.c 11 11
npv/video/local/code.frag.c 64 11
npv/video/main.c 2 21
npv/video/namespace/main.c 12 0
npv/video/public/code.frag.c 17 17
npv/vk/api_usage.h 7 11
npv/vk/local/code.frag.c 91 82
npv/vk/main.c 2 0
npv/vk/namespace/main.c 2 0
npv/vk/namespace/public.h 8 0
npv/vk/public.h 4 0
npv/vk/public/code.frag.c 36 0
npv/xcb/local/code.frag.c 53 26
npv/xcb/main.c 1 8
npv/xcb/public/code.frag.c 6 6
File npv/README changed (mode: 100644) (index ae06712..03fd272)
3 3 "somewhat self-limiting": _without_ lockless and concurrently accessed "somewhat self-limiting": _without_ lockless and concurrently accessed
4 4 circular buffers. circular buffers.
5 5 BUILDING: BUILDING:
6 configure the key bindings and more in "config.h". this is a "one
7 compilation unit" project. just compile main.c and link the compiler
8 output file to your ffmpeg libs, your alsa lib (we should make this
9 dynamically loaded). the vulkan loader lib and x11 xcb libs will be
10 dynamically loaded.
11 you have to define the preprocessor macro STATIC as empty or "static".
12 you will probably have to define the _GNU_SOURCE macro on most
13 GNU/Linux systems.
6 configure the key bindings and more in "config.h". see
7 make-template.sh: this is a "one compilation unit" project. just
8 compile main.c and link the compiler output file to your ffmpeg libs,
9 your alsa lib (we should make this dynamically loaded). the vulkan
10 loader lib and x11 xcb libs will be dynamically loaded. you have to
11 define the preprocessor macro static as empty or "static". you will
12 probably have to define the _gnu_source macro on most gnu/linux systems.
14 13 HACKING: HACKING:
15 14 *.c and *.h files, except the fragments *.frag.c *.frag.h, must *.c and *.h files, except the fragments *.frag.c *.frag.h, must
16 15 "successfully" individually compile (cc -c modulo a few warnings). "successfully" individually compile (cc -c modulo a few warnings).
 
... ... HACKING:
69 68 and helps knowing where things are) and helps knowing where things are)
70 69 - _p suffix is reserved for "public" variable names (namespace noise - _p suffix is reserved for "public" variable names (namespace noise
71 70 and helps knowing where things are) and helps knowing where things are)
71 PEDANTIC:
72 careful of "standards", here iso c. many times "standards"
73 are, to a certain extend, corporation scams. they want you to depend on
74 their complexity and then will force you to use their implementations
75 because it would be nowhere reasonable to reach the same level of
76 compatibilty with modest development efforts. the best example is being
77 the hard dependence of linux on gcc (clang, over than 1 decade,is a the
78 proof that it would be hard). to approach those, a sane way would be to
79 strip them down to a mimimal usage set. for instance, in iso c, function
80 pointer and object pointer are not the same at all, due to some broken
81 or very old hardware architectures (itanium, 8086 real-mode), but "posix
82 standard" makes those pointers the same.
File npv/audio/filt/local/code.frag.c changed (mode: 100644) (index 4d044b9..d361d3e)
1 STATIC void fatal(u8 *fmt, ...)
2 {
3 va_list ap;
4
5 npv_perr("audio:filter:");
6 va_start(ap, fmt);
7 npv_vfatal(fmt, ap);
8 va_end(ap);
9 }
10 STATIC void warning(u8 *fmt, ...)
11 {
12 va_list ap;
13
14 npv_perr("audio:filter:");
15 va_start(ap, fmt);
16 npv_vwarning(fmt, ap);
17 va_end(ap);
18 }
19 STATIC void pout(u8 *fmt, ...)
20 {
21 va_list ap;
22
23 npv_pout("audio:filter:");
24 va_start(ap, fmt);
25 npv_vpout(fmt, ap);
26 va_end(ap);
27 }
1 28 STATIC void abufsrc_cfg(enum avutil_audio_fr_fmt_t fmt, int rate, int chans_n, STATIC void abufsrc_cfg(enum avutil_audio_fr_fmt_t fmt, int rate, int chans_n,
2 29 uint64_t chans_layout, bool print_info) uint64_t chans_layout, bool print_info)
3 30 { {
 
... ... STATIC void abufsrc_cfg(enum avutil_audio_fr_fmt_t fmt, int rate, int chans_n,
7 34
8 35 abufsrc_l = avfilter_get_by_name("abuffer"); abufsrc_l = avfilter_get_by_name("abuffer");
9 36 if (abufsrc_l == 0) if (abufsrc_l == 0)
10 FATALAF("audio buffer source:could not find the filter\n");
37 fatal("audio buffer source:could not find the filter\n");
11 38 abufsrc_ctx_l = avfilter_graph_alloc_filt(graph_l, abufsrc_l, abufsrc_ctx_l = avfilter_graph_alloc_filt(graph_l, abufsrc_l,
12 39 "src_abuf"); "src_abuf");
13 40 if (abufsrc_ctx_l == 0) if (abufsrc_ctx_l == 0)
14 FATALAF("audio buffer source context:could not allocate the instance in the filter graph\n");
41 fatal("audio buffer source context:could not allocate the instance in the filter graph\n");
15 42 r = avutil_opt_set(abufsrc_ctx_l, "sample_fmt", r = avutil_opt_set(abufsrc_ctx_l, "sample_fmt",
16 43 avutil_get_audio_fr_fmt_name(fmt), avutil_get_audio_fr_fmt_name(fmt),
17 44 AVUTIL_OPT_SEARCH_CHILDREN); AVUTIL_OPT_SEARCH_CHILDREN);
18 45 if (r < 0) if (r < 0)
19 FATALAF("audio buffer source context:unable to set the decoder frame format option\n");
46 fatal("audio buffer source context:unable to set the decoder frame format option\n");
20 47 r = avutil_opt_set_int(abufsrc_ctx_l, "sample_rate", r = avutil_opt_set_int(abufsrc_ctx_l, "sample_rate",
21 48 rate, AVUTIL_OPT_SEARCH_CHILDREN); rate, AVUTIL_OPT_SEARCH_CHILDREN);
22 49 if (r < 0) if (r < 0)
23 FATALAF("audio buffer source context:unable to set the decoder rate option\n");
50 fatal("audio buffer source context:unable to set the decoder rate option\n");
24 51 /* /*
25 52 * XXX: at the time of coding, bug for 1 chans layout... or I did miss * XXX: at the time of coding, bug for 1 chans layout... or I did miss
26 53 * some valuable information * some valuable information
 
... ... STATIC void abufsrc_cfg(enum avutil_audio_fr_fmt_t fmt, int rate, int chans_n,
28 55 avutil_get_chans_layout_str(chans_layout_str, sizeof(chans_layout_str), avutil_get_chans_layout_str(chans_layout_str, sizeof(chans_layout_str),
29 56 chans_n, chans_layout); chans_n, chans_layout);
30 57 if (print_info) if (print_info)
31 POUTAF("audio buffer source context:using channels layout \"%s\" (%d pcm channels)\n", chans_layout_str, chans_n);
58 pout("audio buffer source context:using channels layout \"%s\" (%d pcm channels)\n", chans_layout_str, chans_n);
32 59 r = avutil_opt_set(abufsrc_ctx_l, "channel_layout", chans_layout_str, r = avutil_opt_set(abufsrc_ctx_l, "channel_layout", chans_layout_str,
33 60 AVUTIL_OPT_SEARCH_CHILDREN); AVUTIL_OPT_SEARCH_CHILDREN);
34 61 if (r < 0) if (r < 0)
35 FATALAF("audio buffer source context:unable to set the decoder channel layout option\n");
62 fatal("audio buffer source context:unable to set the decoder channel layout option\n");
36 63 r = avfilter_init_str(abufsrc_ctx_l, 0); r = avfilter_init_str(abufsrc_ctx_l, 0);
37 64 if (r < 0) if (r < 0)
38 FATALAF("audio buffer source context:unable to initialize\n");
65 fatal("audio buffer source context:unable to initialize\n");
39 66 } }
40 67 STATIC void vol_cfg(bool muted, double vol_cfg) STATIC void vol_cfg(bool muted, double vol_cfg)
41 68 { {
 
... ... STATIC void vol_cfg(bool muted, double vol_cfg)
45 72
46 73 vol_l = avfilter_get_by_name("volume"); vol_l = avfilter_get_by_name("volume");
47 74 if (vol_l == 0) if (vol_l == 0)
48 FATALAF("volume:could not find the filter\n");
75 fatal("volume:could not find the filter\n");
49 76 vol_ctx_l = avfilter_graph_alloc_filt(graph_l, vol_l, "vol"); vol_ctx_l = avfilter_graph_alloc_filt(graph_l, vol_l, "vol");
50 77 if (vol_ctx_l == 0) if (vol_ctx_l == 0)
51 FATALAF("volume context:could not allocate the instance in the filter graph\n");
78 fatal("volume context:could not allocate the instance in the filter graph\n");
52 79 if (muted) if (muted)
53 80 vol = 0.0; vol = 0.0;
54 81 else else
 
... ... STATIC void vol_cfg(bool muted, double vol_cfg)
58 85 r = avutil_opt_set(vol_ctx_l, "volume", vol_l10n_str, r = avutil_opt_set(vol_ctx_l, "volume", vol_l10n_str,
59 86 AVUTIL_OPT_SEARCH_CHILDREN); AVUTIL_OPT_SEARCH_CHILDREN);
60 87 if (r < 0) if (r < 0)
61 FATALAF("volume context:unable to set the volume option\n");
88 fatal("volume context:unable to set the volume option\n");
62 89 r = avfilter_init_str(vol_ctx_l, 0); r = avfilter_init_str(vol_ctx_l, 0);
63 90 if (r < 0) if (r < 0)
64 FATALAF("volume buffer context:unable to initialize\n");
91 fatal("volume buffer context:unable to initialize\n");
65 92 } }
66 93 STATIC void afmt_cfg(enum avutil_audio_fr_fmt_t fmt, int rate, int chans_n, STATIC void afmt_cfg(enum avutil_audio_fr_fmt_t fmt, int rate, int chans_n,
67 94 uint64_t chans_layout, bool print_info) uint64_t chans_layout, bool print_info)
 
... ... STATIC void afmt_cfg(enum avutil_audio_fr_fmt_t fmt, int rate, int chans_n,
72 99
73 100 afmt_l = avfilter_get_by_name("aformat"); afmt_l = avfilter_get_by_name("aformat");
74 101 if (afmt_l == 0) if (afmt_l == 0)
75 FATALAF("audio format:could not find the filter");
102 fatal("audio format:could not find the filter");
76 103 afmt_ctx_l = avfilter_graph_alloc_filt(graph_l, afmt_l, "afmt"); afmt_ctx_l = avfilter_graph_alloc_filt(graph_l, afmt_l, "afmt");
77 104 if (afmt_ctx_l == 0) if (afmt_ctx_l == 0)
78 FATALAF("audio format:could not allocate the instance in the filter graph\n");
105 fatal("audio format:could not allocate the instance in the filter graph\n");
79 106 r = avutil_opt_set(afmt_ctx_l, "sample_fmts", r = avutil_opt_set(afmt_ctx_l, "sample_fmts",
80 107 avutil_get_audio_fr_fmt_name(fmt), AVUTIL_OPT_SEARCH_CHILDREN); avutil_get_audio_fr_fmt_name(fmt), AVUTIL_OPT_SEARCH_CHILDREN);
81 108 if (r < 0) if (r < 0)
82 FATALAF("audio format context:could to set the pcm sample format\n");
109 fatal("audio format context:could to set the pcm sample format\n");
83 110 snprintf(rate_str, sizeof(rate_str), "%d", rate); snprintf(rate_str, sizeof(rate_str), "%d", rate);
84 111 r = avutil_opt_set(afmt_ctx_l, "sample_rates", rate_str, r = avutil_opt_set(afmt_ctx_l, "sample_rates", rate_str,
85 112 AVUTIL_OPT_SEARCH_CHILDREN); AVUTIL_OPT_SEARCH_CHILDREN);
86 113 if (r < 0) if (r < 0)
87 FATALAF("audio format context:could not set the pcm rate\n");
114 fatal("audio format context:could not set the pcm rate\n");
88 115 avutil_get_chans_layout_str(chans_layout_str, sizeof(chans_layout_str), avutil_get_chans_layout_str(chans_layout_str, sizeof(chans_layout_str),
89 116 chans_n, chans_layout); chans_n, chans_layout);
90 117 r = avutil_opt_set(afmt_ctx_l, "channel_layouts", chans_layout_str, r = avutil_opt_set(afmt_ctx_l, "channel_layouts", chans_layout_str,
91 118 AVUTIL_OPT_SEARCH_CHILDREN); AVUTIL_OPT_SEARCH_CHILDREN);
92 119 if (r < 0) if (r < 0)
93 FATALAF("audio format context:could not set the layout of channels\n");
120 fatal("audio format context:could not set the layout of channels\n");
94 121 if (print_info) if (print_info)
95 POUTAF("audio format context:channel layout is \"%s\"\n", chans_layout_str);
122 pout("audio format context:channel layout is \"%s\"\n", chans_layout_str);
96 123 r = avfilter_init_str(afmt_ctx_l, 0); r = avfilter_init_str(afmt_ctx_l, 0);
97 124 if (r < 0) if (r < 0)
98 FATALAF("audio format context:unable to initialize\n");
125 fatal("audio format context:unable to initialize\n");
99 126 } }
100 127 STATIC void abufsink_cfg(void) STATIC void abufsink_cfg(void)
101 128 { {
 
... ... STATIC void abufsink_cfg(void)
103 130
104 131 abufsink_l = avfilter_get_by_name("abuffersink"); abufsink_l = avfilter_get_by_name("abuffersink");
105 132 if (abufsink_l == 0) if (abufsink_l == 0)
106 FATALAF("audio buffer sink:could not find the filter\n");
133 fatal("audio buffer sink:could not find the filter\n");
107 134 abufsink_ctx_l = avfilter_graph_alloc_filt(graph_l, abufsink_l, abufsink_ctx_l = avfilter_graph_alloc_filt(graph_l, abufsink_l,
108 135 "sink_abuf"); "sink_abuf");
109 136 if (abufsink_ctx_l == 0) if (abufsink_ctx_l == 0)
110 FATALAF("audio buffer sink context:could not allocate the instance in the filter graph\n");
137 fatal("audio buffer sink context:could not allocate the instance in the filter graph\n");
111 138 r = avfilter_init_str(abufsink_ctx_l, 0); r = avfilter_init_str(abufsink_ctx_l, 0);
112 139 if (r < 0) if (r < 0)
113 FATALAF("audio buffer sink context:unable to initialize\n");
140 fatal("audio buffer sink context:unable to initialize\n");
114 141 } }
115 142 STATIC void init_once_local(void) STATIC void init_once_local(void)
116 143 { {
 
... ... STATIC void init_once_public(double initial_vol)
131 158 { {
132 159 filt_p.set = avutil_audio_set_ref_alloc(); filt_p.set = avutil_audio_set_ref_alloc();
133 160 if (filt_p.set == 0) if (filt_p.set == 0)
134 FATALAF("ffmpeg:unable to allocate a reference on set of frames for the public part of the interactive latency filter\n");
161 fatal("ffmpeg:unable to allocate a reference on set of frames for the public part of the interactive latency filter\n");
135 162 filt_p.pcm_written_ufrs_n = 0; filt_p.pcm_written_ufrs_n = 0;
136 163 filt_p.vol = initial_vol; filt_p.vol = initial_vol;
137 164 filt_p.muted = false; filt_p.muted = false;
File npv/audio/filt/main.c changed (mode: 100644) (index ba5aa67..b9e009d)
7 7 #include <stdbool.h> #include <stdbool.h>
8 8 #include <stdio.h> #include <stdio.h>
9 9 #include <pthread.h> #include <pthread.h>
10 #include <stdarg.h>
10 11 #include <libavfilter/avfilter.h> #include <libavfilter/avfilter.h>
11 12 #include <libavfilter/buffersrc.h> #include <libavfilter/buffersrc.h>
12 13 #include <libavfilter/buffersink.h> #include <libavfilter/buffersink.h>
 
14 15 #include <libavutil/channel_layout.h> #include <libavutil/channel_layout.h>
15 16 #include "npv/c_fixing.h" #include "npv/c_fixing.h"
16 17 #include "npv/global.h" #include "npv/global.h"
18 #include "npv/public.h"
17 19 #include "npv/audio/public.h" #include "npv/audio/public.h"
18 20 #include "npv/audio/filt/public.h" #include "npv/audio/filt/public.h"
19 21 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
 
24 26 #include "npv/audio/filt/namespace/public.h" #include "npv/audio/filt/namespace/public.h"
25 27 #include "npv/audio/filt/namespace/main.c" #include "npv/audio/filt/namespace/main.c"
26 28 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
27 #define FATALAF(fmt, ...) FATAL("audio:filter:" fmt, ##__VA_ARGS__)
28 #define WARNINGAF(fmt, ...) WARNING("audio:filter:" fmt, ##__VA_ARGS__)
29 #define POUTAF(fmt, ...) POUT("audio:filter:" fmt, ##__VA_ARGS__)
30 /*----------------------------------------------------------------------------*/
31 29 #include "npv/audio/filt/local/state.frag.c" #include "npv/audio/filt/local/state.frag.c"
32 30 #include "npv/audio/filt/local/code.frag.c" #include "npv/audio/filt/local/code.frag.c"
33 31 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
34 32 #include "npv/audio/filt/public/code.frag.c" #include "npv/audio/filt/public/code.frag.c"
35 33 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
36 #undef FATALA
37 #undef POUTA
38 #undef WARNINGA
39 /*---------------------------------------------------------------------------*/
40 34 #define CLEANUP #define CLEANUP
41 35 #include "npv/namespace/ffmpeg.h" #include "npv/namespace/ffmpeg.h"
42 36 #include "npv/audio/namespace/ffmpeg.h" #include "npv/audio/namespace/ffmpeg.h"
File npv/audio/filt/namespace/main.c changed (mode: 100644) (index d33df01..6b543d4)
9 9 #define afmt_ctx_l npv_audio_filt_afmt_ctx_l #define afmt_ctx_l npv_audio_filt_afmt_ctx_l
10 10 #define afmt_l npv_audio_filt_afmt_l #define afmt_l npv_audio_filt_afmt_l
11 11 #define double_zero_l10n_str_l npv_audio_filt_double_zero_l10n_str_l #define double_zero_l10n_str_l npv_audio_filt_double_zero_l10n_str_l
12 #define fatal npv_audio_filt_fatal
12 13 #define graph_l npv_audio_filt_graph_l #define graph_l npv_audio_filt_graph_l
13 14 #define init_once_local npv_audio_filt_init_once_local #define init_once_local npv_audio_filt_init_once_local
14 15 #define init_once_public npv_audio_filt_init_once_public #define init_once_public npv_audio_filt_init_once_public
16 #define pout npv_audio_filt_pout
15 17 #define vol_cfg npv_audio_filt_vol_cfg #define vol_cfg npv_audio_filt_vol_cfg
16 18 #define vol_ctx_l npv_audio_filt_vol_ctx_l #define vol_ctx_l npv_audio_filt_vol_ctx_l
17 19 #define vol_l npv_audio_filt_vol_l #define vol_l npv_audio_filt_vol_l
20 #define warning npv_audio_filt_warning
18 21 /*============================================================================*/ /*============================================================================*/
19 22 #else #else
20 23 #undef abufsink_cfg #undef abufsink_cfg
 
27 30 #undef afmt_ctx_l #undef afmt_ctx_l
28 31 #undef afmt_l #undef afmt_l
29 32 #undef double_zero_l10n_str_l #undef double_zero_l10n_str_l
33 #undef fatal
30 34 #undef graph_l #undef graph_l
31 35 #undef init_once_local #undef init_once_local
32 36 #undef init_once_public #undef init_once_public
37 #undef pout
33 38 #undef vol_cfg #undef vol_cfg
34 39 #undef vol_ctx_l #undef vol_ctx_l
35 40 #undef vol_l #undef vol_l
41 #undef warning
36 42 #endif #endif
File npv/audio/filt/public/code.frag.c changed (mode: 100644) (index 5578e6c..9fb7eae)
... ... STATIC u8 filt_push_dec_sets(void)
15 15 0, AVFILTER_BUFSRC_FLAG_PUSH 0, AVFILTER_BUFSRC_FLAG_PUSH
16 16 | AVFILTER_BUFSRC_FLAG_KEEP_REF); | AVFILTER_BUFSRC_FLAG_KEEP_REF);
17 17 if (ri < 0) if (ri < 0)
18 FATALAF("ffmpeg:unable to notify the end of data to the filter source audio buffer context\n");
19 POUTAF("ffmpeg:interactive filter switched to draining\n");
18 fatal("ffmpeg:unable to notify the end of data to the filter source audio buffer context\n");
19 pout("ffmpeg:interactive filter switched to draining\n");
20 20 r8 = FILT_SWITCHED_TO_DRAINING; r8 = FILT_SWITCHED_TO_DRAINING;
21 21 goto unlock; goto unlock;
22 22 } }
 
... ... STATIC u8 filt_push_dec_sets(void)
44 44 r8 = AGAIN; r8 = AGAIN;
45 45 goto unlock; goto unlock;
46 46 } }
47 FATALAF("ffmpeg:unable to submit a decoder set of frames to the filter source audio buffer context\n");
47 fatal("ffmpeg:unable to submit a decoder set of frames to the filter source audio buffer context\n");
48 48 unlock: unlock:
49 49 npv_audio_dec_sets_unlock(); npv_audio_dec_sets_unlock();
50 50 return r8; return r8;
 
... ... STATIC u8 filt_set_try_get(void)
73 73 } else if (r == AVUTIL_AVERROR_EOF) { } else if (r == AVUTIL_AVERROR_EOF) {
74 74 return EOF_FILT; return EOF_FILT;
75 75 } }
76 FATALAF("ffmpeg:error while getting frames from the filter\n");
76 fatal("ffmpeg:error while getting frames from the filter\n");
77 77 } }
78 78 #undef AGAIN #undef AGAIN
79 79 #undef HAVE_FILT_SET #undef HAVE_FILT_SET
 
... ... STATIC void cfg(enum avutil_audio_fr_fmt_t src_fmt, int src_rate,
118 118
119 119 graph_l = avfilter_graph_alloc(); graph_l = avfilter_graph_alloc();
120 120 if (graph_l == 0) if (graph_l == 0)
121 FATALAF("unable to create filter graph\n");
121 fatal("unable to create filter graph\n");
122 122 abufsrc_cfg(src_fmt, src_rate, src_chans_n, src_chans_layout, abufsrc_cfg(src_fmt, src_rate, src_chans_n, src_chans_layout,
123 123 print_info); print_info);
124 124 vol_cfg(muted, vol); vol_cfg(muted, vol);
 
... ... STATIC void cfg(enum avutil_audio_fr_fmt_t src_fmt, int src_rate,
126 126 abufsink_cfg(); abufsink_cfg();
127 127 r = avfilter_link(abufsrc_ctx_l, 0, vol_ctx_l, 0); r = avfilter_link(abufsrc_ctx_l, 0, vol_ctx_l, 0);
128 128 if (r < 0) if (r < 0)
129 FATALAF("unable to connect the audio buffer source filter to the volume filter\n");
129 fatal("unable to connect the audio buffer source filter to the volume filter\n");
130 130 r = avfilter_link(vol_ctx_l, 0, afmt_ctx_l, 0); r = avfilter_link(vol_ctx_l, 0, afmt_ctx_l, 0);
131 131 if (r < 0) if (r < 0)
132 FATALAF("unable to connect the volume filter to the audio format filter\n");
132 fatal("unable to connect the volume filter to the audio format filter\n");
133 133 r = avfilter_link(afmt_ctx_l, 0, abufsink_ctx_l, 0); r = avfilter_link(afmt_ctx_l, 0, abufsink_ctx_l, 0);
134 134 if (r < 0) if (r < 0)
135 FATALAF("unable to connect the audio format filter to the audio buffer sink filter\n");
135 fatal("unable to connect the audio format filter to the audio buffer sink filter\n");
136 136 r = avfilter_graph_config(graph_l, 0); r = avfilter_graph_config(graph_l, 0);
137 137 if (r < 0) if (r < 0)
138 FATALAF("unable to configure the filter graph\n");
138 fatal("unable to configure the filter graph\n");
139 139 /*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
140 140 if (!print_info) if (!print_info)
141 141 return; return;
142 142 dump_str = avfilter_graph_dump(graph_l, 0); dump_str = avfilter_graph_dump(graph_l, 0);
143 143 if (dump_str == 0) { if (dump_str == 0) {
144 WARNINGAF("unable to get a filter graph description\n");
144 warning("unable to get a filter graph description\n");
145 145 return; return;
146 146 } }
147 POUTAF("GRAPH START-------------------------------------------------------\n");
148 POUT("%s", dump_str);
147 pout("GRAPH START-------------------------------------------------------\n");
148 npv_pout("%s", dump_str);
149 149 avutil_free(dump_str); avutil_free(dump_str);
150 POUTAF("GRAPH END---------------------------------------------------------\n");
150 pout("GRAPH END---------------------------------------------------------\n");
151 151 } }
152 152 STATIC void npv_audio_filt_cmd_mute(void) STATIC void npv_audio_filt_cmd_mute(void)
153 153 { {
 
... ... STATIC void npv_audio_filt_cmd_mute(void)
156 156 u8 resp[STR_SZ]; u8 resp[STR_SZ];
157 157
158 158 if (filt_p.muted) { if (filt_p.muted) {
159 POUTAF("COMMAND:unmuting\n");
159 pout("COMMAND:unmuting\n");
160 160
161 161 snprintf(vol_l10n_str, sizeof(vol_l10n_str), "%f", filt_p.vol); snprintf(vol_l10n_str, sizeof(vol_l10n_str), "%f", filt_p.vol);
162 162 r = avfilter_graph_send_cmd(graph_l, "vol", "volume", r = avfilter_graph_send_cmd(graph_l, "vol", "volume",
163 163 vol_l10n_str, resp, sizeof(resp), 0); vol_l10n_str, resp, sizeof(resp), 0);
164 164 if (r < 0) { if (r < 0) {
165 WARNINGAF("ffmpeg:volume context:unable to mute the volume to 0:response from volume filter:%s\n", resp);
165 warning("ffmpeg:volume context:unable to mute the volume to 0:response from volume filter:%s\n", resp);
166 166 } else { } else {
167 167 filt_p.muted = false; filt_p.muted = false;
168 168 } }
169 169 } else { } else {
170 POUTAF("COMMAND:muting\n");
170 pout("COMMAND:muting\n");
171 171
172 172 r = avfilter_graph_send_cmd(graph_l, "vol", "volume", r = avfilter_graph_send_cmd(graph_l, "vol", "volume",
173 173 double_zero_l10n_str_l, resp, sizeof(resp), 0); double_zero_l10n_str_l, resp, sizeof(resp), 0);
174 174 if (r < 0) { if (r < 0) {
175 WARNINGAF("ffmpeg:volume context:unable to mute the volume to 0:response from volume filter:%s\n", resp);
175 warning("ffmpeg:volume context:unable to mute the volume to 0:response from volume filter:%s\n", resp);
176 176 } else { } else {
177 177 filt_p.muted = true; filt_p.muted = true;
178 178 } }
 
... ... STATIC void npv_audio_filt_cmd_vol_down(void)
188 188 if (filt_p.vol < 0.) if (filt_p.vol < 0.)
189 189 filt_p.vol = 0.; filt_p.vol = 0.;
190 190 snprintf(vol_l10n_str, sizeof(vol_l10n_str), "%f", filt_p.vol); snprintf(vol_l10n_str, sizeof(vol_l10n_str), "%f", filt_p.vol);
191 POUTAF("COMMAND:volume down to value %s\n", vol_l10n_str);
191 pout("COMMAND:volume down to value %s\n", vol_l10n_str);
192 192 if (!filt_p.muted) { if (!filt_p.muted) {
193 193 r = avfilter_graph_send_cmd(graph_l, "vol", "volume", r = avfilter_graph_send_cmd(graph_l, "vol", "volume",
194 194 vol_l10n_str, resp, sizeof(resp), 0); vol_l10n_str, resp, sizeof(resp), 0);
195 195 if (r < 0) if (r < 0)
196 WARNINGAF("ffmpeg:volume context:unable to set the volume down to \"%s\":response from volume filter:\"%s\"\n", resp);
196 warning("ffmpeg:volume context:unable to set the volume down to \"%s\":response from volume filter:\"%s\"\n", resp);
197 197 } }
198 198 } }
199 199 STATIC void npv_audio_filt_cmd_vol_up(void) STATIC void npv_audio_filt_cmd_vol_up(void)
 
... ... STATIC void npv_audio_filt_cmd_vol_up(void)
206 206 if (filt_p.vol > 1.) if (filt_p.vol > 1.)
207 207 filt_p.vol = 1.; filt_p.vol = 1.;
208 208 snprintf(vol_l10n_str, sizeof(vol_l10n_str), "%f", filt_p.vol); snprintf(vol_l10n_str, sizeof(vol_l10n_str), "%f", filt_p.vol);
209 POUTAF("COMMAND:volume up to value %s\n", vol_l10n_str);
209 pout("COMMAND:volume up to value %s\n", vol_l10n_str);
210 210 if (!filt_p.muted) { if (!filt_p.muted) {
211 211 r = avfilter_graph_send_cmd(graph_l, "vol", "volume", r = avfilter_graph_send_cmd(graph_l, "vol", "volume",
212 212 vol_l10n_str, resp, sizeof(resp), 0); vol_l10n_str, resp, sizeof(resp), 0);
213 213 if (r < 0) if (r < 0)
214 WARNINGAF("ffmpeg:volume context:unable to set the volume up to \"%s\":response from volume filter:\"%s\"\n", resp);
214 warning("ffmpeg:volume context:unable to set the volume up to \"%s\":response from volume filter:\"%s\"\n", resp);
215 215 } }
216 216 } }
File npv/audio/local/code.frag.c changed (mode: 100644) (index 5b27e36..fe5fda0)
1 STATIC void fatal(u8 *fmt, ...)
2 {
3 va_list ap;
4
5 npv_perr("audio:");
6 va_start(ap, fmt);
7 npv_vfatal(fmt, ap);
8 va_end(ap); /* unreachable */
9 }
10 STATIC void warning(u8 *fmt, ...)
11 {
12 va_list ap;
13
14 npv_perr("audio:");
15 va_start(ap, fmt);
16 npv_vwarning(fmt, ap);
17 va_end(ap);
18 }
19 STATIC void pout(u8 *fmt, ...)
20 {
21 va_list ap;
22
23 npv_pout("audio:");
24 va_start(ap, fmt);
25 npv_vpout(fmt, ap);
26 va_end(ap);
27 }
1 28 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,
2 29 snd_pcm_fmt_t *alsa_fmt, snd_pcm_access_t *alsa_access) snd_pcm_fmt_t *alsa_fmt, snd_pcm_access_t *alsa_access)
3 30 { {
 
... ... STATIC bool ff_fmt2pcm_layout_best_effort(enum avutil_audio_fr_fmt_t ff_fmt,
40 67 *alsa_access = SND_PCM_ACCESS_RW_NONINTERLEAVED; *alsa_access = SND_PCM_ACCESS_RW_NONINTERLEAVED;
41 68 break; break;
42 69 default: default:
43 POUTA("best effort:unable to wire ffmpeg sample format \"%sbits\" to alsa sample format, \n,", ff_fmt_str);
70 pout("best effort:unable to wire ffmpeg sample format \"%sbits\" to alsa sample format, \n,", ff_fmt_str);
44 71 return false; return false;
45 72 } }
46 POUTA("best effort:ffmpeg format \"%sbits\" (%u bytes) to alsa layout \"%s\" and access \"%s\"\n", ff_fmt_str, av_get_bytes_per_sample(ff_fmt), snd_pcm_fmt_desc(*alsa_fmt), snd_pcm_access_name(*alsa_access));
73 pout("best effort:ffmpeg format \"%sbits\" (%u bytes) to alsa layout \"%s\" and access \"%s\"\n", ff_fmt_str, av_get_bytes_per_sample(ff_fmt), snd_pcm_fmt_desc(*alsa_fmt), snd_pcm_access_name(*alsa_access));
47 74 return true; return true;
48 75 } }
49 76 STATIC void pcm_hw_chans_n_decide(snd_pcm_t *pcm, STATIC void pcm_hw_chans_n_decide(snd_pcm_t *pcm,
 
... ... STATIC void pcm_hw_chans_n_decide(snd_pcm_t *pcm,
57 84 if (r == 0) { if (r == 0) {
58 85 r = snd_pcm_hw_params_set_chans_n(pcm, pcm_hw_params, chans_n); r = snd_pcm_hw_params_set_chans_n(pcm, pcm_hw_params, chans_n);
59 86 if (r != 0) if (r != 0)
60 FATALA("alsa:unable to restrict pcm device to %u channels, count which was successfully tested\n", chans_n);
61 POUTA("alsa:using %u channels\n", chans_n);
87 fatal("alsa:unable to restrict pcm device to %u channels, count which was successfully tested\n", chans_n);
88 pout("alsa:using %u channels\n", chans_n);
62 89 return; return;
63 90 } }
64 POUTA("alsa:unable to use %u channels\n", chans_n);
91 pout("alsa:unable to use %u channels\n", chans_n);
65 92 /* try to use the max chans n the pcm can */ /* try to use the max chans n the pcm can */
66 93 r = snd_pcm_hw_params_get_chans_n_max(pcm_hw_params, &chans_n_max); r = snd_pcm_hw_params_get_chans_n_max(pcm_hw_params, &chans_n_max);
67 94 if (r != 0) if (r != 0)
68 FATALA("alsa:unable to get the maximum count of pcm device channels\n");
95 fatal("alsa:unable to get the maximum count of pcm device channels\n");
69 96 r = snd_pcm_hw_params_test_chans_n(pcm, pcm_hw_params, chans_n_max); r = snd_pcm_hw_params_test_chans_n(pcm, pcm_hw_params, chans_n_max);
70 97 if (r == 0) { if (r == 0) {
71 98 r = snd_pcm_hw_params_set_chans_n(pcm, pcm_hw_params, r = snd_pcm_hw_params_set_chans_n(pcm, pcm_hw_params,
72 99 chans_n_max); chans_n_max);
73 100 if (r != 0) if (r != 0)
74 FATALA("alsa:unable to restrict pcm device to %u channels, count which was successfully tested\n", chans_n_max);
75 POUTA("alsa:using pcm maximum %u channels\n", chans_n_max);
101 fatal("alsa:unable to restrict pcm device to %u channels, count which was successfully tested\n", chans_n_max);
102 pout("alsa:using pcm maximum %u channels\n", chans_n_max);
76 103 return; return;
77 104 } }
78 105 /* ok... last try, the pcm dev min chans n */ /* ok... last try, the pcm dev min chans n */
79 106 r = snd_pcm_hw_params_get_chans_n_min(pcm_hw_params, &chans_n_min); r = snd_pcm_hw_params_get_chans_n_min(pcm_hw_params, &chans_n_min);
80 107 if (r != 0) if (r != 0)
81 FATALA("alsa:unable to get the minimum count of pcm device channels\n");
108 fatal("alsa:unable to get the minimum count of pcm device channels\n");
82 109 r = snd_pcm_hw_params_test_chans_n(pcm, pcm_hw_params, chans_n_min); r = snd_pcm_hw_params_test_chans_n(pcm, pcm_hw_params, chans_n_min);
83 110 if (r == 0) { if (r == 0) {
84 111 r = snd_pcm_hw_params_set_chans_n(pcm, pcm_hw_params, r = snd_pcm_hw_params_set_chans_n(pcm, pcm_hw_params,
85 112 chans_n_min); chans_n_min);
86 113 if (r != 0) if (r != 0)
87 FATALA("alsa:unable to restrict pcm device to %u channels, count which was successfully tested\n", chans_n_min);
88 POUTA("alsa:using pcm device minimum %u channels\n", chans_n_min);
114 fatal("alsa:unable to restrict pcm device to %u channels, count which was successfully tested\n", chans_n_min);
115 pout("alsa:using pcm device minimum %u channels\n", chans_n_min);
89 116 return; return;
90 117 } }
91 FATALA("alsa:unable to find a suitable count of channels\n");
118 fatal("alsa:unable to find a suitable count of channels\n");
92 119 } }
93 120 STATIC void pcm_hw_rate_decide(snd_pcm_t *pcm, STATIC void pcm_hw_rate_decide(snd_pcm_t *pcm,
94 121 snd_pcm_hw_params_t *pcm_hw_params, unsigned int rate) snd_pcm_hw_params_t *pcm_hw_params, unsigned int rate)
 
... ... STATIC void pcm_hw_rate_decide(snd_pcm_t *pcm,
104 131 r = snd_pcm_hw_params_set_rate(pcm, pcm_hw_params, rate, r = snd_pcm_hw_params_set_rate(pcm, pcm_hw_params, rate,
105 132 SND_PCM_ST_PLAYBACK); SND_PCM_ST_PLAYBACK);
106 133 if (r != 0) if (r != 0)
107 FATALA("alsa:unable to restrict pcm device to %uHz, which was successfully tested\n", rate);
108 POUTA("alsa:using %uHz\n", rate);
134 fatal("alsa:unable to restrict pcm device to %uHz, which was successfully tested\n", rate);
135 pout("alsa:using %uHz\n", rate);
109 136 return; return;
110 137 } }
111 POUTA("alsa:unable to use %uHz\n", rate);
138 pout("alsa:unable to use %uHz\n", rate);
112 139 /* try to use the max rate the pcm can */ /* try to use the max rate the pcm can */
113 140 r = snd_pcm_hw_params_get_rate_max(pcm_hw_params, &rate_max, r = snd_pcm_hw_params_get_rate_max(pcm_hw_params, &rate_max,
114 141 SND_PCM_ST_PLAYBACK); SND_PCM_ST_PLAYBACK);
115 142 if (r != 0) if (r != 0)
116 FATALA("alsa:unable to get the maximum rate of pcm device\n");
143 fatal("alsa:unable to get the maximum rate of pcm device\n");
117 144 r = snd_pcm_hw_params_test_rate(pcm, pcm_hw_params, rate_max, r = snd_pcm_hw_params_test_rate(pcm, pcm_hw_params, rate_max,
118 145 SND_PCM_ST_PLAYBACK); SND_PCM_ST_PLAYBACK);
119 146 if (r == 0) { if (r == 0) {
120 147 r = snd_pcm_hw_params_set_rate(pcm, pcm_hw_params, rate_max, r = snd_pcm_hw_params_set_rate(pcm, pcm_hw_params, rate_max,
121 148 SND_PCM_ST_PLAYBACK); SND_PCM_ST_PLAYBACK);
122 149 if (r != 0) if (r != 0)
123 FATALA("alsa:unable to restrict pcm device to %uHz, which was successfully tested\n", rate_max);
124 POUTA("alsa:using pcm device %uHz\n", rate_max);
150 fatal("alsa:unable to restrict pcm device to %uHz, which was successfully tested\n", rate_max);
151 pout("alsa:using pcm device %uHz\n", rate_max);
125 152 return; return;
126 153 } }
127 154 /* try to use a rate "near" of what the pcm dev can */ /* try to use a rate "near" of what the pcm dev can */
 
... ... STATIC void pcm_hw_rate_decide(snd_pcm_t *pcm,
129 156 r = snd_pcm_hw_params_set_rate_near(pcm, pcm_hw_params, &rate_near, r = snd_pcm_hw_params_set_rate_near(pcm, pcm_hw_params, &rate_near,
130 157 SND_PCM_ST_PLAYBACK); SND_PCM_ST_PLAYBACK);
131 158 if (r == 0) { if (r == 0) {
132 POUTA("alsa:using pcm device %uHz\n", rate_near);
159 pout("alsa:using pcm device %uHz\n", rate_near);
133 160 return; return;
134 161 } }
135 162 /* even a "near" rate did failed... try the min */ /* even a "near" rate did failed... try the min */
136 163 r = snd_pcm_hw_params_get_rate_min(pcm_hw_params, &rate_min, r = snd_pcm_hw_params_get_rate_min(pcm_hw_params, &rate_min,
137 164 SND_PCM_ST_PLAYBACK); SND_PCM_ST_PLAYBACK);
138 165 if (r != 0) if (r != 0)
139 FATALA("alsa:unable to get the minimum rate of pcm device\n");
166 fatal("alsa:unable to get the minimum rate of pcm device\n");
140 167 r = snd_pcm_hw_params_test_rate(pcm, pcm_hw_params, rate_min, r = snd_pcm_hw_params_test_rate(pcm, pcm_hw_params, rate_min,
141 168 SND_PCM_ST_PLAYBACK); SND_PCM_ST_PLAYBACK);
142 169 if (r == 0) { if (r == 0) {
143 170 r = snd_pcm_hw_params_set_rate(pcm, pcm_hw_params, rate_min, r = snd_pcm_hw_params_set_rate(pcm, pcm_hw_params, rate_min,
144 171 SND_PCM_ST_PLAYBACK); SND_PCM_ST_PLAYBACK);
145 172 if (r != 0) if (r != 0)
146 FATALA("alsa:unable to restrict pcm device to %uHz, which was successfully tested\n", rate_min);
147 POUTA("alsa:using pcm device %uHz\n", rate_min);
173 fatal("alsa:unable to restrict pcm device to %uHz, which was successfully tested\n", rate_min);
174 pout("alsa:using pcm device %uHz\n", rate_min);
148 175 return; return;
149 176 } }
150 FATALA("alsa:unable to find a suitable rate\n");
177 fatal("alsa:unable to find a suitable rate\n");
151 178 } }
152 179 STATIC bool pcm_hw_fmt_decide_x(snd_pcm_t *pcm, STATIC bool pcm_hw_fmt_decide_x(snd_pcm_t *pcm,
153 180 snd_pcm_hw_params_t *pcm_hw_params, snd_pcm_fmt_t fmt) snd_pcm_hw_params_t *pcm_hw_params, snd_pcm_fmt_t fmt)
 
... ... STATIC bool pcm_hw_fmt_decide_x(snd_pcm_t *pcm,
159 186 return false; return false;
160 187 r = snd_pcm_hw_params_set_fmt(pcm, pcm_hw_params, fmt); r = snd_pcm_hw_params_set_fmt(pcm, pcm_hw_params, fmt);
161 188 if (r != 0) if (r != 0)
162 FATALA("alsa:unable to restrict pcm device to \"%s\", which was successfully tested\n", snd_pcm_fmt_desc(fmt));
163 POUTA("alsa:using \"%s\" format\n", snd_pcm_fmt_desc(fmt));
189 fatal("alsa:unable to restrict pcm device to \"%s\", which was successfully tested\n", snd_pcm_fmt_desc(fmt));
190 pout("alsa:using \"%s\" format\n", snd_pcm_fmt_desc(fmt));
164 191 return true; return true;
165 192 } }
166 193 #define PCM_HW_FMT_DECIDE_X(fmt) pcm_hw_fmt_decide_x(pcm, pcm_hw_params, fmt) #define PCM_HW_FMT_DECIDE_X(fmt) pcm_hw_fmt_decide_x(pcm, pcm_hw_params, fmt)
 
... ... STATIC void pcm_hw_fmt_decide(snd_pcm_t *pcm,
177 204 r = snd_pcm_hw_params_set_fmt(pcm, pcm_hw_params, r = snd_pcm_hw_params_set_fmt(pcm, pcm_hw_params,
178 205 forced_fmt); forced_fmt);
179 206 if (r != 0) if (r != 0)
180 FATALA("alsa:unable to restrict pcm device to \"%s\", which was successfully tested\n", snd_pcm_fmt_desc(forced_fmt));
181 POUTA("alsa:using forced \"%s\" format\n", snd_pcm_fmt_desc(forced_fmt));
207 fatal("alsa:unable to restrict pcm device to \"%s\", which was successfully tested\n", snd_pcm_fmt_desc(forced_fmt));
208 pout("alsa:using forced \"%s\" format\n", snd_pcm_fmt_desc(forced_fmt));
182 209 return; return;
183 210 } }
184 211 } }
 
... ... STATIC void pcm_hw_fmt_decide(snd_pcm_t *pcm,
206 233 return; return;
207 234 if (PCM_HW_FMT_DECIDE_X(SND_PCM_FMT_S8)) if (PCM_HW_FMT_DECIDE_X(SND_PCM_FMT_S8))
208 235 return; return;
209 FATALA("alsa:unable to find a suitable format\n");
236 fatal("alsa:unable to find a suitable format\n");
210 237 } }
211 238 #undef PCM_HW_FMT_DECIDE_X #undef PCM_HW_FMT_DECIDE_X
212 239 STATIC bool pcm_hw_access_decide_x(snd_pcm_t *pcm, STATIC bool pcm_hw_access_decide_x(snd_pcm_t *pcm,
 
... ... STATIC bool pcm_hw_access_decide_x(snd_pcm_t *pcm,
219 246 return false; return false;
220 247 r = snd_pcm_hw_params_set_access(pcm, pcm_hw_params, access); r = snd_pcm_hw_params_set_access(pcm, pcm_hw_params, access);
221 248 if (r != 0) if (r != 0)
222 FATALA("alsa:unable to restrict pcm device to \"%s\", which was successfully tested\n", snd_pcm_access_name(access));
223 POUTA("alsa:using \"%s\" access\n", snd_pcm_access_name(access));
249 fatal("alsa:unable to restrict pcm device to \"%s\", which was successfully tested\n", snd_pcm_access_name(access));
250 pout("alsa:using \"%s\" access\n", snd_pcm_access_name(access));
224 251 return true; return true;
225 252 } }
226 253 #define PCM_HW_ACCESS_DECIDE_X(access) \ #define PCM_HW_ACCESS_DECIDE_X(access) \
 
... ... STATIC void pcm_hw_access_decide(snd_pcm_t *pcm,
240 267 r = snd_pcm_hw_params_set_access(pcm, pcm_hw_params, r = snd_pcm_hw_params_set_access(pcm, pcm_hw_params,
241 268 forced_access); forced_access);
242 269 if (r != 0) if (r != 0)
243 FATALA("alsa:unable to restrict pcm device to \"%s\", which was successfully tested\n", snd_pcm_access_name(forced_access));
244 POUTA("alsa:using forced \"%s\" access\n", snd_pcm_access_name(forced_access));
270 fatal("alsa:unable to restrict pcm device to \"%s\", which was successfully tested\n", snd_pcm_access_name(forced_access));
271 pout("alsa:using forced \"%s\" access\n", snd_pcm_access_name(forced_access));
245 272 return; return;
246 273 } }
247 274 } }
 
... ... STATIC void pcm_hw_access_decide(snd_pcm_t *pcm,
250 277 return; return;
251 278 if (PCM_HW_ACCESS_DECIDE_X(SND_PCM_ACCESS_RW_NONINTERLEAVED)) if (PCM_HW_ACCESS_DECIDE_X(SND_PCM_ACCESS_RW_NONINTERLEAVED))
252 279 return; return;
253 FATALA("alsa:unable to find a suitable access\n");
280 fatal("alsa:unable to find a suitable access\n");
254 281 } }
255 282 #undef PCM_HW_ACCESS_DECIDE_X #undef PCM_HW_ACCESS_DECIDE_X
256 283 /* /*
 
... ... STATIC void pcm_hw_buf_sz_cfg(snd_pcm_t *pcm,
273 300
274 301 r = snd_pcm_hw_params_get_rate(pcm_hw_params, &rate, 0); r = snd_pcm_hw_params_get_rate(pcm_hw_params, &rate, 0);
275 302 if (r < 0) { if (r < 0) {
276 WARNINGA("alsa:latency control:DISABLING LATENCY CONTROL:unable to get the decided rate from the current device parameters\n");
303 warning("alsa:latency control:DISABLING LATENCY CONTROL:unable to get the decided rate from the current device parameters\n");
277 304 return; return;
278 305 } }
279 306 latency_control_target_buf_ufrs_n = (snd_pcm_ufrs_t)rate; latency_control_target_buf_ufrs_n = (snd_pcm_ufrs_t)rate;
 
... ... STATIC void pcm_hw_buf_sz_cfg(snd_pcm_t *pcm,
282 309 r = snd_pcm_hw_params_set_buf_sz_near(pcm, pcm_hw_params, r = snd_pcm_hw_params_set_buf_sz_near(pcm, pcm_hw_params,
283 310 &latency_control_buf_ufrs_n); &latency_control_buf_ufrs_n);
284 311 if (r < 0) { if (r < 0) {
285 WARNINGA("alsa:latency control:DISABLING_LATENCY_CONTROL:unable to set the audio buffer size (count of frames) to %u periods for the current device parameters\n", latency_control_buf_ufrs_n);
312 warning("alsa:latency control:DISABLING_LATENCY_CONTROL:unable to set the audio buffer size (count of frames) to %u periods for the current device parameters\n", latency_control_buf_ufrs_n);
286 313 return; return;
287 314 } }
288 POUTA("alsa:latency control:target buffer frame count is %u (~0.25 sec), got an audio buffer size set to %u frames\n", latency_control_target_buf_ufrs_n, latency_control_buf_ufrs_n);
315 pout("alsa:latency control:target buffer frame count is %u (~0.25 sec), got an audio buffer size set to %u frames\n", latency_control_target_buf_ufrs_n, latency_control_buf_ufrs_n);
289 316 } }
290 317 /* /*
291 318 * this function will "decide" the pcm dev cfg: * this function will "decide" the pcm dev cfg:
 
... ... STATIC void pcm_cfg_hw_core(snd_pcm_t *pcm, snd_pcm_hw_params_t *pcm_hw_params,
308 335 /* the return value is from a first refine of the raw hw params */ /* the return value is from a first refine of the raw hw params */
309 336 r = snd_pcm_hw_params_any(pcm, pcm_hw_params); r = snd_pcm_hw_params_any(pcm, pcm_hw_params);
310 337 if (r < 0) if (r < 0)
311 FATALA("alsa:unable to populate the hardware parameters context\n");
338 fatal("alsa:unable to populate the hardware parameters context\n");
312 339 pcm_hw_chans_n_decide(pcm, pcm_hw_params, (unsigned int)chans_n); pcm_hw_chans_n_decide(pcm, pcm_hw_params, (unsigned int)chans_n);
313 340 pcm_hw_rate_decide(pcm, pcm_hw_params, (unsigned int)rate); pcm_hw_rate_decide(pcm, pcm_hw_params, (unsigned int)rate);
314 341 /* try our best */ /* try our best */
 
... ... STATIC void pcm_cfg_hw(snd_pcm_t *pcm, unsigned int chans_n, unsigned int rate,
337 364 snd_pcm_access_t access; snd_pcm_access_t access;
338 365 snd_pcm_hw_params_t *hw_params; snd_pcm_hw_params_t *hw_params;
339 366
340 POUTA("ALSA:HW_PARAMS START------------------------------------------------------------\n");
367 pout("ALSA:HW_PARAMS START------------------------------------------------------------\n");
341 368 r = snd_pcm_hw_params_malloc(&hw_params); r = snd_pcm_hw_params_malloc(&hw_params);
342 369 if (r < 0) if (r < 0)
343 FATALA("alsa:unable to allocate hardware parameters context\n");
370 fatal("alsa:unable to allocate hardware parameters context\n");
344 371
345 372 pcm_cfg_hw_core(pcm, hw_params, chans_n, rate, ff_fmt); pcm_cfg_hw_core(pcm, hw_params, chans_n, rate, ff_fmt);
346 373
347 374 r = snd_pcm_hw_params(pcm, hw_params); r = snd_pcm_hw_params(pcm, hw_params);
348 375 if (r != 0) if (r != 0)
349 FATALA("alsa:unable to install the hardware parameters\n");
376 fatal("alsa:unable to install the hardware parameters\n");
350 377 r = snd_pcm_hw_params_current(pcm, hw_params); r = snd_pcm_hw_params_current(pcm, hw_params);
351 378 if (r != 0) if (r != 0)
352 FATALA("alsa:unable to get current hardware parameters\n");
379 fatal("alsa:unable to get current hardware parameters\n");
353 380 snd_pcm_hw_params_dump(hw_params, pcm_pout_l); snd_pcm_hw_params_dump(hw_params, pcm_pout_l);
354 381
355 382 i = 0; i = 0;
 
... ... STATIC void pcm_cfg_hw(snd_pcm_t *pcm, unsigned int chans_n, unsigned int rate,
360 387 r = snd_pcm_hw_params_supports_audio_ts_type(hw_params, i); r = snd_pcm_hw_params_supports_audio_ts_type(hw_params, i);
361 388 if (r == 1) { if (r == 1) {
362 389 selected_ts_type_p = i; selected_ts_type_p = i;
363 POUTA("kernel audio timestamp type \"%s\" is supported for the current configuration\n", kernel_ts_types_str[i]);
390 pout("kernel audio timestamp type \"%s\" is supported for the current configuration\n", kernel_ts_types_str[i]);
364 391 } }
365 392 ++i; ++i;
366 393 } }
 
... ... STATIC void pcm_cfg_hw(snd_pcm_t *pcm, unsigned int chans_n, unsigned int rate,
368 395 * we selected the most accurate, namely with the highest idx, audio ts * we selected the most accurate, namely with the highest idx, audio ts
369 396 * type * type
370 397 */ */
371 POUTA("%s will be used for the audio based clock\n", kernel_ts_types_str[selected_ts_type_p]);
398 pout("%s will be used for the audio based clock\n", kernel_ts_types_str[selected_ts_type_p]);
372 399 snd_pcm_hw_params_free(hw_params); snd_pcm_hw_params_free(hw_params);
373 POUTA("ALSA:HW_PARAMS END--------------------------------------------------------------\n");
400 pout("ALSA:HW_PARAMS END--------------------------------------------------------------\n");
374 401 } }
375 402 STATIC void pcm_cfg_sw(snd_pcm_t *pcm) STATIC void pcm_cfg_sw(snd_pcm_t *pcm)
376 403 { {
377 404 int r; int r;
378 405 snd_pcm_sw_params_t *sw_params; snd_pcm_sw_params_t *sw_params;
379 406
380 POUTA("ALSA:SW_PARAMS START------------------------------------------------------------\n");
407 pout("ALSA:SW_PARAMS START------------------------------------------------------------\n");
381 408 r = snd_pcm_sw_params_malloc(&sw_params); r = snd_pcm_sw_params_malloc(&sw_params);
382 409 if (r != 0) if (r != 0)
383 FATALA("alsa:unable to allocate software parameters structure\n");
410 fatal("alsa:unable to allocate software parameters structure\n");
384 411 r = snd_pcm_sw_params_current(pcm, sw_params); r = snd_pcm_sw_params_current(pcm, sw_params);
385 412 if (r != 0) if (r != 0)
386 FATALA("alsa:unable to get current software parameters\n");
413 fatal("alsa:unable to get current software parameters\n");
387 414 r = snd_pcm_sw_params_set_period_evt(pcm, sw_params, 1); r = snd_pcm_sw_params_set_period_evt(pcm, sw_params, 1);
388 415 if (r != 0) if (r != 0)
389 FATALA("alsa:unable to enable period event\n");
416 fatal("alsa:unable to enable period event\n");
390 417 /* enable ts to be sure */ /* enable ts to be sure */
391 418 r = snd_pcm_sw_params_set_tstamp_mode(pcm, sw_params, r = snd_pcm_sw_params_set_tstamp_mode(pcm, sw_params,
392 419 SND_PCM_TSTAMP_ENABLE); SND_PCM_TSTAMP_ENABLE);
393 420 if (r < 0) if (r < 0)
394 FATALA("unable to set timestamp mode:%s\n", snd_strerror(r));
421 fatal("unable to set timestamp mode:%s\n", snd_strerror(r));
395 422 r = snd_pcm_sw_params(pcm, sw_params); r = snd_pcm_sw_params(pcm, sw_params);
396 423 if (r != 0) if (r != 0)
397 FATALA("alsa:unable to install sotfware parameters\n");
424 fatal("alsa:unable to install sotfware parameters\n");
398 425 snd_pcm_sw_params_dump(sw_params, pcm_pout_l); snd_pcm_sw_params_dump(sw_params, pcm_pout_l);
399 426 snd_pcm_sw_params_free(sw_params); snd_pcm_sw_params_free(sw_params);
400 POUTA("ALSA:SW_PARAMS END--------------------------------------------------------------\n");
427 pout("ALSA:SW_PARAMS END--------------------------------------------------------------\n");
401 428 } }
402 429 STATIC void dec_a_grow(void) STATIC void dec_a_grow(void)
403 430 { {
 
... ... STATIC void dec_a_grow(void)
407 434 dec_sets_p.a = realloc(dec_sets_p.a, sizeof(*dec_sets_p.a) dec_sets_p.a = realloc(dec_sets_p.a, sizeof(*dec_sets_p.a)
408 435 * (dec_sets_p.n_max + 1)); * (dec_sets_p.n_max + 1));
409 436 if (dec_sets_p.a == 0) if (dec_sets_p.a == 0)
410 FATALA("unable to allocate memory for an additional pointer on a reference of a decoder set of frames\n");
437 fatal("unable to allocate memory for an additional pointer on a reference of a decoder set of frames\n");
411 438 dec_sets_p.a[new_idx] = avutil_audio_set_ref_alloc(); dec_sets_p.a[new_idx] = avutil_audio_set_ref_alloc();
412 439 if (dec_sets_p.a[new_idx] == 0) if (dec_sets_p.a[new_idx] == 0)
413 FATALA("ffmpeg:unable to allocate a reference of a decoder set of frames\n");
440 fatal("ffmpeg:unable to allocate a reference of a decoder set of frames\n");
414 441 ++dec_sets_p.n_max; ++dec_sets_p.n_max;
415 442 } }
416 443 #define AGAIN 0 #define AGAIN 0
 
... ... STATIC u8 alsa_recover(snd_pcm_sfrs_t r)
429 456
430 457 r_recovered = snd_pcm_recover(pcm_p, (int)r, 0); r_recovered = snd_pcm_recover(pcm_p, (int)r, 0);
431 458 if (r_recovered == 0) { if (r_recovered == 0) {
432 WARNINGA("alsa:pcm recovered\n");
459 warning("alsa:pcm recovered\n");
433 460 return RECOVERED; return RECOVERED;
434 461 } }
435 FATALA("alsa:unable to recover from suspend/underrun\n");
462 fatal("alsa:unable to recover from suspend/underrun\n");
436 463 } }
437 FATALA("alsa:fatal/unhandled error\n");
464 fatal("alsa:fatal/unhandled error\n");
438 465 } }
439 466 #undef AGAIN #undef AGAIN
440 467 #undef RECOVERED #undef RECOVERED
 
... ... STATIC void draining_state_handle(void)
541 568 */ */
542 569 state = snd_pcm_state(pcm_p); state = snd_pcm_state(pcm_p);
543 570 if (state != SND_PCM_STATE_SETUP) if (state != SND_PCM_STATE_SETUP)
544 FATALA("alsa:an error occured switching to/checking the pcm draining state\n");
571 fatal("alsa:an error occured switching to/checking the pcm draining state\n");
545 572 /* here pcm state is SND_PCM_STATE_SETUP */ /* here pcm state is SND_PCM_STATE_SETUP */
546 573 } }
547 EXIT("alsa pcm drained or similar, exiting\n");
574 npv_exit("alsa pcm drained or similar, exiting\n");
548 575 } }
549 576 STATIC void draining_state_switch(void) STATIC void draining_state_switch(void)
550 577 { {
 
... ... STATIC void draining_state_switch(void)
563 590 r = epoll_ctl(npv_ep_fd_p, EPOLL_CTL_DEL, pcm_pollfds_p[i].fd, r = epoll_ctl(npv_ep_fd_p, EPOLL_CTL_DEL, pcm_pollfds_p[i].fd,
564 591 0); 0);
565 592 if (r == -1) if (r == -1)
566 FATALA("unable to remove the alsa file descriptors from epoll\n");
593 fatal("unable to remove the alsa file descriptors from epoll\n");
567 594 ++i; ++i;
568 595 } }
569 596 /* start the draining timer */ /* start the draining timer */
 
... ... STATIC void draining_state_switch(void)
573 600 t.it_interval.tv_nsec = DRAINING_TIMER_INTERVAL_NSECS_N; t.it_interval.tv_nsec = DRAINING_TIMER_INTERVAL_NSECS_N;
574 601 r = timerfd_settime(draining_timer_fd_p, 0, &t, 0); r = timerfd_settime(draining_timer_fd_p, 0, &t, 0);
575 602 if (r == -1) if (r == -1)
576 FATALA("unable to arm the draining timer\n");
603 fatal("unable to arm the draining timer\n");
577 604 } }
578 605 #define NO 0 #define NO 0
579 606 #define AGAIN 0 #define AGAIN 0
 
... ... STATIC void pcm_layout2ff_fmt_strict(snd_pcm_fmt_t alsa_fmt,
713 740 *ff_fmt = AVUTIL_AUDIO_FR_FMT_U8P; *ff_fmt = AVUTIL_AUDIO_FR_FMT_U8P;
714 741 break; break;
715 742 default: default:
716 FATALA("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));
743 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));
717 744 } }
718 745 if (print_info) { if (print_info) {
719 746 u8 ff_fmt_str[STR_SZ]; u8 ff_fmt_str[STR_SZ];
720 747
721 748 avutil_get_audio_fr_fmt_str(ff_fmt_str, sizeof(ff_fmt_str), avutil_get_audio_fr_fmt_str(ff_fmt_str, sizeof(ff_fmt_str),
722 749 *ff_fmt); *ff_fmt);
723 POUTA("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);
750 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);
724 751 } }
725 752 } }
726 753 /* /*
 
... ... STATIC uint64_t pcm_chmaps2ff_chans_layout(snd_pcm_t *pcm,
738 765 pcm_chmap = snd_pcm_get_chmap(pcm); pcm_chmap = snd_pcm_get_chmap(pcm);
739 766 if (pcm_chmap == 0) { if (pcm_chmap == 0) {
740 767 if (print_info) if (print_info)
741 POUTA("alsa:no pcm channel map available, wiring to default ffmpeg channel layout\n");
768 pout("alsa:no pcm channel map available, wiring to default ffmpeg channel layout\n");
742 769 } else { } else {
743 770 if (print_info) if (print_info)
744 POUTA("alsa:your pcm device support channel maps, but fine granularity wiring strategy is not implemented\n");
771 pout("alsa:your pcm device support channel maps, but fine granularity wiring strategy is not implemented\n");
745 772 free(pcm_chmap); free(pcm_chmap);
746 773 } }
747 774 ff_chans_layout = avutil_get_default_chans_layout((int)pcm_chans_n); ff_chans_layout = avutil_get_default_chans_layout((int)pcm_chans_n);
748 775 avutil_get_chans_layout_str(chans_layout_str, sizeof(chans_layout_str), avutil_get_chans_layout_str(chans_layout_str, sizeof(chans_layout_str),
749 776 (int)pcm_chans_n, ff_chans_layout); (int)pcm_chans_n, ff_chans_layout);
750 777 if (print_info) if (print_info)
751 POUTA("alsa channel map wired to ffmpeg channel layout:\"%s\" (%u pcm channels)\n", chans_layout_str, pcm_chans_n);
778 pout("alsa channel map wired to ffmpeg channel layout:\"%s\" (%u pcm channels)\n", chans_layout_str, pcm_chans_n);
752 779 return ff_chans_layout; return ff_chans_layout;
753 780 } }
754 781 STATIC void init_pcm_once_public(u8 *pcm_str) STATIC void init_pcm_once_public(u8 *pcm_str)
 
... ... STATIC void init_pcm_once_public(u8 *pcm_str)
759 786 SND_PCM_NONBLOCK); SND_PCM_NONBLOCK);
760 787 if (r < 0) { if (r < 0) {
761 788 if (r == -EAGAIN) if (r == -EAGAIN)
762 FATALA("alsa:\"%s\" pcm is already in use\n", pcm_str);
789 fatal("alsa:\"%s\" pcm is already in use\n", pcm_str);
763 790 else else
764 FATALA("alsa:unable to open \"%s\" pcm for playback\n", pcm_str);
791 fatal("alsa:unable to open \"%s\" pcm for playback\n", pcm_str);
765 792 } }
766 793
767 794 r = snd_pcm_poll_descriptors_n(pcm_p); r = snd_pcm_poll_descriptors_n(pcm_p);
768 POUTA("alsa:have %d poll file descriptors\n", r);
795 pout("alsa:have %d poll file descriptors\n", r);
769 796 if ((r <= 0) || (r > pcm_pollfds_n_max)) if ((r <= 0) || (r > pcm_pollfds_n_max))
770 FATALA("alsa:invalid count of alsa poll file descriptors\n");
797 fatal("alsa:invalid count of alsa poll file descriptors\n");
771 798 pcm_pollfds_n_p =(u8)r; pcm_pollfds_n_p =(u8)r;
772 799 memset(pcm_pollfds_p, 0, sizeof(pcm_pollfds_p)); memset(pcm_pollfds_p, 0, sizeof(pcm_pollfds_p));
773 800 snd_pcm_poll_descriptors(pcm_p, pcm_pollfds_p, pcm_pollfds_n_max); snd_pcm_poll_descriptors(pcm_p, pcm_pollfds_p, pcm_pollfds_n_max);
 
... ... STATIC void init_once_public(u8 *pcm_str)
789 816 errno = 0; errno = 0;
790 817 draining_timer_fd_p = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK); draining_timer_fd_p = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK);
791 818 if (draining_timer_fd_p == -1) if (draining_timer_fd_p == -1)
792 FATALA("unable to get a draining timer file descriptor:%s\n", strerror(errno));
819 fatal("unable to get a draining timer file descriptor:%s\n", strerror(errno));
793 820 draining_p = false; draining_p = false;
794 821 r = pthread_mutex_init(&dec_ctx_mutex_l, 0); r = pthread_mutex_init(&dec_ctx_mutex_l, 0);
795 822 if (r != 0) if (r != 0)
796 FATALA("%d:unable to init the decoder mutex\n", r);
823 fatal("%d:unable to init the decoder mutex\n", r);
797 824 r = pthread_mutex_init(&dec_sets_p.mutex, 0); r = pthread_mutex_init(&dec_sets_p.mutex, 0);
798 825 if (r != 0) if (r != 0)
799 FATALA("%d:unable to init the mutex for the array of decoder sets\n", r);
826 fatal("%d:unable to init the mutex for the array of decoder sets\n", r);
800 827 } }
801 828 STATIC void init_once_local(void) STATIC void init_once_local(void)
802 829 { {
 
... ... STATIC void init_once_local(void)
805 832 dec_l = 0; dec_l = 0;
806 833 r = snd_output_stdio_attach(&pcm_pout_l, stdout, 0); r = snd_output_stdio_attach(&pcm_pout_l, stdout, 0);
807 834 if (r < 0) if (r < 0)
808 FATALA("alsa:unable to attach stdout\n");
835 fatal("alsa:unable to attach stdout\n");
809 836 r = snd_output_stdio_attach(&pcm_perr_l, stderr, 0); r = snd_output_stdio_attach(&pcm_perr_l, stderr, 0);
810 837 if (r < 0) if (r < 0)
811 FATALA("alsa:unable to attach stderr\n");
838 fatal("alsa:unable to attach stderr\n");
812 839 memset(pcm_silence_bufs_l, 0, sizeof(pcm_silence_bufs_l)); memset(pcm_silence_bufs_l, 0, sizeof(pcm_silence_bufs_l));
813 840 } }
814 841 STATIC void dec_a_unref_all(void) STATIC void dec_a_unref_all(void)
File npv/audio/main.c changed (mode: 100644) (index e320148..fa7c5bd)
6 6 */ */
7 7 #include <stdbool.h> #include <stdbool.h>
8 8 #include <stdint.h> #include <stdint.h>
9 #include <stdarg.h>
9 10 #include <string.h> #include <string.h>
10 11 #include <stdio.h> #include <stdio.h>
11 12 #include <unistd.h> #include <unistd.h>
 
45 46 * silence bufs * silence bufs
46 47 */ */
47 48 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
48 #define FATALA(fmt, ...) FATAL("audio:" fmt, ##__VA_ARGS__)
49 #define WARNINGA(fmt, ...) WARNING("audio:" fmt, ##__VA_ARGS__)
50 #define POUTA(fmt, ...) POUT("audio:" fmt, ##__VA_ARGS__)
51 /*----------------------------------------------------------------------------*/
52 49 #define DRAINING_TIMER_INTERVAL_NSECS_N 100000000 /* 0.1 sec */ #define DRAINING_TIMER_INTERVAL_NSECS_N 100000000 /* 0.1 sec */
53 50 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
54 51 #include "npv/audio/local/state.frag.c" #include "npv/audio/local/state.frag.c"
 
56 53 #include "npv/audio/local/code.frag.c" #include "npv/audio/local/code.frag.c"
57 54 #include "npv/audio/public/code.frag.c" #include "npv/audio/public/code.frag.c"
58 55 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
59 #undef FATALA
60 #undef POUTA
61 #undef WARNINGA
62 56 #undef DRAINING_TIMER_INTERVAL_NSECS_N #undef DRAINING_TIMER_INTERVAL_NSECS_N
63 57 /*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
64 58 #define CLEANUP #define CLEANUP
File npv/audio/namespace/main.c changed (mode: 100644) (index 8b235ea..a374f68)
9 9 #define dec_l npv_audio_dec_l #define dec_l npv_audio_dec_l
10 10 #define draining_state_handle npv_audio_draining_state_handle #define draining_state_handle npv_audio_draining_state_handle
11 11 #define draining_state_switch npv_audio_draining_state_switch #define draining_state_switch npv_audio_draining_state_switch
12 #define fatal npv_audio_fatal
12 13 #define ff_fmt2pcm_layout_best_effort npv_audio_ff_fmt2pcm_layout_best_effort #define ff_fmt2pcm_layout_best_effort npv_audio_ff_fmt2pcm_layout_best_effort
13 14 #define filt_push_dec_sets npv_audio_filt_push_dec_sets #define filt_push_dec_sets npv_audio_filt_push_dec_sets
14 15 #define init_once_local npv_audio_init_once_local #define init_once_local npv_audio_init_once_local
 
33 34 #define pcm_perr_l npv_audio_pcm_perr_l #define pcm_perr_l npv_audio_pcm_perr_l
34 35 #define pcm_silence_bufs_l npv_audio_pcm_silence_bufs_l #define pcm_silence_bufs_l npv_audio_pcm_silence_bufs_l
35 36 #define pcm_silence_frs_write npv_audio_pcm_silence_frs_write #define pcm_silence_frs_write npv_audio_pcm_silence_frs_write
37 #define pout npv_audio_pout
38 #define warning npv_audio_warning
36 39 /*============================================================================*/ /*============================================================================*/
37 40 #else #else
38 41 #undef alsa_recover #undef alsa_recover
 
45 48 #undef dec_flush #undef dec_flush
46 49 #undef draining_state_handle #undef draining_state_handle
47 50 #undef draining_state_switch #undef draining_state_switch
51 #undef fatal
48 52 #undef ff_fmt2pcm_layout_best_effort #undef ff_fmt2pcm_layout_best_effort
49 53 #undef filt_push_dec_sets #undef filt_push_dec_sets
50 54 #undef init_once_local #undef init_once_local
 
69 73 #undef pcm_perr_l #undef pcm_perr_l
70 74 #undef pcm_silence_bufs_l #undef pcm_silence_bufs_l
71 75 #undef pcm_silence_frs_write #undef pcm_silence_frs_write
76 #undef pout
77 #undef warning
72 78 #endif #endif
File npv/audio/public/code.frag.c changed (mode: 100644) (index aff40c1..bbd0bc9)
... ... STATIC void dec_ctx_cfg(avcodec_params_t *params)
4 4
5 5 dec_l = avcodec_find_dec(params->codec_id); dec_l = avcodec_find_dec(params->codec_id);
6 6 if (dec_l == 0) if (dec_l == 0)
7 FATALA("ffmpeg:unable to find a proper decoder\n");
7 fatal("ffmpeg:unable to find a proper decoder\n");
8 8 avcodec_free_context(&dec_ctx_p); avcodec_free_context(&dec_ctx_p);
9 9 dec_ctx_p = avcodec_alloc_ctx(dec_l); dec_ctx_p = avcodec_alloc_ctx(dec_l);
10 10 if (dec_ctx_p == 0) if (dec_ctx_p == 0)
11 FATALA("ffmpeg:unable to allocate a decoder context\n");
11 fatal("ffmpeg:unable to allocate a decoder context\n");
12 12 /* XXX: useless ? */ /* XXX: useless ? */
13 13 r = avcodec_params_to_ctx(dec_ctx_p, params); r = avcodec_params_to_ctx(dec_ctx_p, params);
14 14 if (r < 0) if (r < 0)
15 FATALA("ffmpeg:unable to apply stream codec parameters in codec context\n");
15 fatal("ffmpeg:unable to apply stream codec parameters in codec context\n");
16 16 /* XXX: ffmpeg thread count default is 1, set to 0 = auto */ /* XXX: ffmpeg thread count default is 1, set to 0 = auto */
17 17 dec_ctx_p->thread_count = 0; dec_ctx_p->thread_count = 0;
18 18 r = avcodec_open2(dec_ctx_p, dec_l, 0); r = avcodec_open2(dec_ctx_p, dec_l, 0);
19 19 if (r < 0) if (r < 0)
20 FATALA("ffmpeg:unable to open the decoder context\n");
20 fatal("ffmpeg:unable to open the decoder context\n");
21 21 } }
22 22 #define AGAIN 0 #define AGAIN 0
23 23 #define HAVE_DEC_SET 1 #define HAVE_DEC_SET 1
 
... ... STATIC u8 dec_set_try_receive(void)
40 40 ++dec_sets_p.n; ++dec_sets_p.n;
41 41 return HAVE_DEC_SET; return HAVE_DEC_SET;
42 42 } else if (r == AVUTIL_AVERROR_EOF) { } else if (r == AVUTIL_AVERROR_EOF) {
43 POUTA("ffmpeg:last decoder set of frames reached (receiving)\n");
43 pout("ffmpeg:last decoder set of frames reached (receiving)\n");
44 44 dec_sets_p.eof_receive = true; dec_sets_p.eof_receive = true;
45 45 return EOF_DEC; return EOF_DEC;
46 46 } }
47 FATALA("ffmpeg:error while receiving a set of frames from the decoder\n");
47 fatal("ffmpeg:error while receiving a set of frames from the decoder\n");
48 48 } }
49 49 #undef AGAIN #undef AGAIN
50 50 #undef HAVE_DEC_SET #undef HAVE_DEC_SET
 
... ... STATIC void draining_state_evt(void)
80 80
81 81 r = read(draining_timer_fd_p, &exps_n, sizeof(exps_n)); r = read(draining_timer_fd_p, &exps_n, sizeof(exps_n));
82 82 if (r == -1) if (r == -1)
83 FATALA("unable to read the number of draining state timer expirations\n");
83 fatal("unable to read the number of draining state timer expirations\n");
84 84 draining_state_handle(); draining_state_handle();
85 85 } }
86 86 #define AGAIN 0 #define AGAIN 0
 
... ... STATIC void pcm_silence_bufs_cfg(snd_pcm_t *pcm, bool print_info)
116 116
117 117 r = snd_pcm_hw_params_malloc(&hw_params); r = snd_pcm_hw_params_malloc(&hw_params);
118 118 if (r < 0) if (r < 0)
119 FATALA("silence:alsa:unable to allocate memory for a hardware parameters container\n");
119 fatal("silence:alsa:unable to allocate memory for a hardware parameters container\n");
120 120 r = snd_pcm_hw_params_current(pcm, hw_params); r = snd_pcm_hw_params_current(pcm, hw_params);
121 121 if (r != 0) if (r != 0)
122 FATALA("silence:alsa:unable to get the pcm hardware parameters\n");
122 fatal("silence:alsa:unable to get the pcm hardware parameters\n");
123 123 r = snd_pcm_hw_params_get_buf_sz(hw_params, &buf_ufrs_n); r = snd_pcm_hw_params_get_buf_sz(hw_params, &buf_ufrs_n);
124 124 if (r < 0) if (r < 0)
125 FATALA("silence:alsa:unable to get the number of frames in the pcm buffer\n");
125 fatal("silence:alsa:unable to get the number of frames in the pcm buffer\n");
126 126 r = snd_pcm_hw_params_get_format(hw_params, &fmt); r = snd_pcm_hw_params_get_format(hw_params, &fmt);
127 127 if (r < 0) if (r < 0)
128 FATALA("silence:alsa:unable to get the pcm format\n");
128 fatal("silence:alsa:unable to get the pcm format\n");
129 129 r = snd_pcm_hw_params_get_access(hw_params, &access); r = snd_pcm_hw_params_get_access(hw_params, &access);
130 130 if (r < 0) if (r < 0)
131 FATALA("silence:alsa:unable to get the pcm access mode\n");
131 fatal("silence:alsa:unable to get the pcm access mode\n");
132 132 r = snd_pcm_hw_params_get_channels(hw_params, &chans_n); r = snd_pcm_hw_params_get_channels(hw_params, &chans_n);
133 133 if (r < 0) if (r < 0)
134 FATALA("silence:alsa:unable to get the pcm number of channels\n");
134 fatal("silence:alsa:unable to get the pcm number of channels\n");
135 135
136 136 /* wipe silence bufs first */ /* wipe silence bufs first */
137 137 c = 0; c = 0;
 
... ... STATIC void pcm_silence_bufs_cfg(snd_pcm_t *pcm, bool print_info)
151 151 buf_bytes_n = snd_pcm_frames_to_bytes(pcm, buf_bytes_n = snd_pcm_frames_to_bytes(pcm,
152 152 (snd_pcm_sframes_t)buf_ufrs_n); (snd_pcm_sframes_t)buf_ufrs_n);
153 153 if (buf_bytes_n <= 0) if (buf_bytes_n <= 0)
154 FATALA("silence:alsa:interleaved:unable to get the pcm number of bytes of all buffer frames\n");
154 fatal("silence:alsa:interleaved:unable to get the pcm number of bytes of all buffer frames\n");
155 155 pcm_silence_bufs_l[0] = malloc((size_t)buf_bytes_n); pcm_silence_bufs_l[0] = malloc((size_t)buf_bytes_n);
156 156 if (pcm_silence_bufs_l[0] == 0) if (pcm_silence_bufs_l[0] == 0)
157 FATALA("silence:interleaved:unable to allocate the silence buffer of %d bytes\n", (int)buf_bytes_n);
157 fatal("silence:interleaved:unable to allocate the silence buffer of %d bytes\n", (int)buf_bytes_n);
158 158 if (print_info) if (print_info)
159 POUTA("silence:interleaved:buffer of %d bytes is allocated\n", (int)buf_bytes_n);
159 pout("silence:interleaved:buffer of %d bytes is allocated\n", (int)buf_bytes_n);
160 160 r = snd_pcm_format_set_silence(fmt, pcm_silence_bufs_l[0], r = snd_pcm_format_set_silence(fmt, pcm_silence_bufs_l[0],
161 161 (unsigned int)buf_ufrs_n); (unsigned int)buf_ufrs_n);
162 162 if (r < 0) if (r < 0)
163 FATALA("silence:interleaved:unable to fill with silence the buffer\n");
164 POUTA("silence:interleaved:silence buffer filled with %u silence frames\n", buf_ufrs_n);
163 fatal("silence:interleaved:unable to fill with silence the buffer\n");
164 pout("silence:interleaved:silence buffer filled with %u silence frames\n", buf_ufrs_n);
165 165 } else if (access == SND_PCM_ACCESS_RW_NONINTERLEAVED } else if (access == SND_PCM_ACCESS_RW_NONINTERLEAVED
166 166 || access == SND_PCM_ACCESS_MMAP_NONINTERLEAVED) { || access == SND_PCM_ACCESS_MMAP_NONINTERLEAVED) {
167 167 ssize_t buf_bytes_n; ssize_t buf_bytes_n;
 
... ... STATIC void pcm_silence_bufs_cfg(snd_pcm_t *pcm, bool print_info)
170 170 buf_samples_n = (long)buf_ufrs_n; buf_samples_n = (long)buf_ufrs_n;
171 171 buf_bytes_n = snd_pcm_samples_to_bytes(pcm, buf_samples_n); buf_bytes_n = snd_pcm_samples_to_bytes(pcm, buf_samples_n);
172 172 if (buf_bytes_n <= 0) if (buf_bytes_n <= 0)
173 FATALA("silence:alsa:non interleaved:unable to get the pcm number of total bytes of all buffer samples\n");
173 fatal("silence:alsa:non interleaved:unable to get the pcm number of total bytes of all buffer samples\n");
174 174 c = 0; c = 0;
175 175 loop { loop {
176 176 if (c == chans_n) if (c == chans_n)
177 177 break; break;
178 178 pcm_silence_bufs_l[c] = malloc((size_t)buf_bytes_n); pcm_silence_bufs_l[c] = malloc((size_t)buf_bytes_n);
179 179 if (pcm_silence_bufs_l[c] == 0) if (pcm_silence_bufs_l[c] == 0)
180 FATALA("silence:non interleaved:unable to allocate silence buffer %u of %d bytes\n", c, (int)buf_bytes_n);
180 fatal("silence:non interleaved:unable to allocate silence buffer %u of %d bytes\n", c, (int)buf_bytes_n);
181 181 r = snd_pcm_format_set_silence(fmt, r = snd_pcm_format_set_silence(fmt,
182 182 pcm_silence_bufs_l[c], pcm_silence_bufs_l[c],
183 183 (unsigned int)buf_samples_n); (unsigned int)buf_samples_n);
184 184 if (r < 0) if (r < 0)
185 FATALA("silence:non interleaved:unable to fill with silence the buffer\n");
185 fatal("silence:non interleaved:unable to fill with silence the buffer\n");
186 186 if (print_info) if (print_info)
187 POUTA("silence:non interleaved:buffer[%u] of %d bytes is allocated\n", c, (int)buf_bytes_n);
187 pout("silence:non interleaved:buffer[%u] of %d bytes is allocated\n", c, (int)buf_bytes_n);
188 188 ++c; ++c;
189 189 } }
190 190 if (print_info) if (print_info)
191 POUTA("silence:non interleaved:allocated %u silence buffers for %u frames\n", chans_n, (unsigned int)buf_ufrs_n);
191 pout("silence:non interleaved:allocated %u silence buffers for %u frames\n", chans_n, (unsigned int)buf_ufrs_n);
192 192 } else } else
193 FATALA("silence:the pcm access type is not supported\n");
193 fatal("silence:the pcm access type is not supported\n");
194 194 snd_pcm_hw_params_free(hw_params); snd_pcm_hw_params_free(hw_params);
195 195 } }
196 196 STATIC void init_once(u8 *pcm_str) STATIC void init_once(u8 *pcm_str)
 
... ... STATIC void dec_ctx_lock(void)
211 211
212 212 r = pthread_mutex_lock(&dec_ctx_mutex_l); r = pthread_mutex_lock(&dec_ctx_mutex_l);
213 213 if (r != 0) if (r != 0)
214 FATALA("%d:unable to lock the decoder context\n", r);
214 fatal("%d:unable to lock the decoder context\n", r);
215 215 } }
216 216 STATIC void dec_ctx_unlock(void) STATIC void dec_ctx_unlock(void)
217 217 { {
 
... ... STATIC void dec_ctx_unlock(void)
219 219
220 220 r = pthread_mutex_unlock(&dec_ctx_mutex_l); r = pthread_mutex_unlock(&dec_ctx_mutex_l);
221 221 if (r != 0) if (r != 0)
222 FATALA("%d:unable to unlock the decoder context\n", r);
222 fatal("%d:unable to unlock the decoder context\n", r);
223 223 } }
224 224 STATIC void dec_sets_lock(void) STATIC void dec_sets_lock(void)
225 225 { {
 
... ... STATIC void dec_sets_lock(void)
227 227
228 228 r = pthread_mutex_lock(&dec_sets_p.mutex); r = pthread_mutex_lock(&dec_sets_p.mutex);
229 229 if (r != 0) if (r != 0)
230 FATALA("%d:unable to lock the array of decoder sets\n", r);
230 fatal("%d:unable to lock the array of decoder sets\n", r);
231 231 } }
232 232 STATIC void dec_sets_unlock(void) STATIC void dec_sets_unlock(void)
233 233 { {
 
... ... STATIC void dec_sets_unlock(void)
235 235
236 236 r = pthread_mutex_unlock(&dec_sets_p.mutex); r = pthread_mutex_unlock(&dec_sets_p.mutex);
237 237 if (r != 0) if (r != 0)
238 FATALA("%d:unable to unlock the array of decoder sets\n", r);
238 fatal("%d:unable to unlock the array of decoder sets\n", r);
239 239 } }
240 240 STATIC void pcm_cfg(snd_pcm_t *pcm, unsigned int chans_n, unsigned int rate, STATIC void pcm_cfg(snd_pcm_t *pcm, unsigned int chans_n, unsigned int rate,
241 241 enum avutil_audio_fr_fmt_t ff_fmt) enum avutil_audio_fr_fmt_t ff_fmt)
242 242 { {
243 243 pcm_cfg_hw(pcm, chans_n, rate, ff_fmt); pcm_cfg_hw(pcm, chans_n, rate, ff_fmt);
244 244 pcm_cfg_sw(pcm); pcm_cfg_sw(pcm);
245 POUTA("ALSA PCM DUMP START-------------------------------------------------------------\n");
245 pout("ALSA PCM DUMP START-------------------------------------------------------------\n");
246 246 snd_pcm_dump(pcm, pcm_pout_l); snd_pcm_dump(pcm, pcm_pout_l);
247 POUTA("ALSA PCM DUMP END---------------------------------------------------------------\n");
247 pout("ALSA PCM DUMP END---------------------------------------------------------------\n");
248 248 } }
249 249 STATIC void pcm2ff(snd_pcm_t *pcm, enum avutil_audio_fr_fmt_t *ff_fmt, STATIC void pcm2ff(snd_pcm_t *pcm, enum avutil_audio_fr_fmt_t *ff_fmt,
250 250 int *ff_rate, int *ff_chans_n, uint64_t *ff_chans_layout, int *ff_rate, int *ff_chans_n, uint64_t *ff_chans_layout,
 
... ... STATIC void pcm2ff(snd_pcm_t *pcm, enum avutil_audio_fr_fmt_t *ff_fmt,
259 259
260 260 r = snd_pcm_hw_params_malloc(&hw_params); r = snd_pcm_hw_params_malloc(&hw_params);
261 261 if (r < 0) if (r < 0)
262 FATALA("alsa:unable to allocate hardware parameters context for ffmpeg filter wiring\n");
262 fatal("alsa:unable to allocate hardware parameters context for ffmpeg filter wiring\n");
263 263 r = snd_pcm_hw_params_current(pcm, hw_params); r = snd_pcm_hw_params_current(pcm, hw_params);
264 264 if (r != 0) if (r != 0)
265 FATALA("alsa:unable to get current hardware parameters for ffmpeg filter wiring\n");
265 fatal("alsa:unable to get current hardware parameters for ffmpeg filter wiring\n");
266 266 r = snd_pcm_hw_params_get_access(hw_params, &pcm_access); r = snd_pcm_hw_params_get_access(hw_params, &pcm_access);
267 267 if (r < 0) if (r < 0)
268 FATALA("alsa:unable to get the pcm access for ffmpeg filter wiring\n");
268 fatal("alsa:unable to get the pcm access for ffmpeg filter wiring\n");
269 269 r = snd_pcm_hw_params_get_fmt(hw_params, &pcm_fmt); r = snd_pcm_hw_params_get_fmt(hw_params, &pcm_fmt);
270 270 if (r < 0) if (r < 0)
271 FATALA("alsa:unable to get the pcm format for ffmpeg filter wiring\n");
271 fatal("alsa:unable to get the pcm format for ffmpeg filter wiring\n");
272 272 /*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
273 273 pcm_layout2ff_fmt_strict(pcm_fmt, pcm_access, ff_fmt, print_info); pcm_layout2ff_fmt_strict(pcm_fmt, pcm_access, ff_fmt, print_info);
274 274 /*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
275 275 r = snd_pcm_hw_params_get_rate(hw_params, &pcm_rate, r = snd_pcm_hw_params_get_rate(hw_params, &pcm_rate,
276 276 SND_PCM_ST_PLAYBACK); SND_PCM_ST_PLAYBACK);
277 277 if (r < 0) if (r < 0)
278 FATALA("alsa:unable to get the pcm rate for ffmpeg filter wiring\n");
278 fatal("alsa:unable to get the pcm rate for ffmpeg filter wiring\n");
279 279 *ff_rate = (int)pcm_rate; *ff_rate = (int)pcm_rate;
280 280 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);
281 281 if (r < 0) if (r < 0)
282 FATALA("alsa:unable to get the pcm count of channels for ffmpeg filter wiring\n");
282 fatal("alsa:unable to get the pcm count of channels for ffmpeg filter wiring\n");
283 283 *ff_chans_n = (int)pcm_chans_n; *ff_chans_n = (int)pcm_chans_n;
284 284 /*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
285 285 *ff_chans_layout = pcm_chmaps2ff_chans_layout(pcm, pcm_chans_n, *ff_chans_layout = pcm_chmaps2ff_chans_layout(pcm, pcm_chans_n,
 
... ... STATIC void pkts_send(void) { loop
306 306 else if (r == AVUTIL_AVERROR_EOF) /* the dec is in draining mode */ else if (r == AVUTIL_AVERROR_EOF) /* the dec is in draining mode */
307 307 goto unlock_and_return; goto unlock_and_return;
308 308 else if (r != 0) else if (r != 0)
309 FATALA("error while sending a packet to the decoder\n");
309 fatal("error while sending a packet to the decoder\n");
310 310 /* r == 0 */ /* r == 0 */
311 311 npv_pipeline_limits_lock(); npv_pipeline_limits_lock();
312 312 npv_pipeline_limits_p.pkts.audio_bytes_n -= pr->sz; npv_pipeline_limits_p.pkts.audio_bytes_n -= pr->sz;
File npv/clk/local/code.frag.c added (mode: 100644) (index 0000000..047d1af)
1 STATIC void npv_clk_fatal(u8 *fmt, ...)
2 {
3 va_list ap;
4
5 npv_perr("clock:");
6 va_start(ap, fmt);
7 npv_vfatal(fmt, ap);
8 va_end(ap);
9 }
10
File npv/clk/main.c changed (mode: 100644) (index 115012d..aeeccfb)
7 7 /*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
8 8 #include <string.h> #include <string.h>
9 9 #include <pthread.h> #include <pthread.h>
10 #include <stdarg.h>
10 11 #include <alsa/asoundlib.h> #include <alsa/asoundlib.h>
11 12 #include <libavformat/avformat.h> #include <libavformat/avformat.h>
12 13 #include "npv/c_fixing.h" #include "npv/c_fixing.h"
 
16 17 #include "npv/namespace/alsa.h" #include "npv/namespace/alsa.h"
17 18 #include "npv/namespace/ffmpeg.h" #include "npv/namespace/ffmpeg.h"
18 19 /*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
19 #define FATALCLK(fmt, ...) FATAL("clock:" fmt, ##__VA_ARGS__)
20 20 #define TS_RETURNED 0 #define TS_RETURNED 0
21 21 /*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
22 22 #include "npv/clk/local/state.frag.c" #include "npv/clk/local/state.frag.c"
23 #include "npv/clk/local/code.frag.c"
23 24 #include "npv/clk/public/code.frag.c" #include "npv/clk/public/code.frag.c"
24 25 /*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
25 26 #undef TS_RETURNED #undef TS_RETURNED
File npv/clk/public/code.frag.c changed (mode: 100644) (index bbdb09a..c8a4604)
... ... STATIC void npv_clk_init_once(void)
4 4
5 5 r = snd_pcm_status_malloc(&npv_clk_l.ref.status); r = snd_pcm_status_malloc(&npv_clk_l.ref.status);
6 6 if (r != 0) if (r != 0)
7 FATALCLK("alsa:unable to allocate an alsa status structure\n");
7 npv_clk_fatal("alsa:unable to allocate an alsa status structure\n");
8 8 r = snd_pcm_status_malloc(&npv_clk_l.now.status); r = snd_pcm_status_malloc(&npv_clk_l.now.status);
9 9 if (r != 0) if (r != 0)
10 FATALCLK("alsa:unable to allocate an alsa status structure\n");
10 npv_clk_fatal("alsa:unable to allocate an alsa status structure\n");
11 11 /* we pre-allocate alsa pcm hw_params container */ /* we pre-allocate alsa pcm hw_params container */
12 12 r = snd_pcm_hw_params_malloc(&npv_clk_pcm_hw_params_l); r = snd_pcm_hw_params_malloc(&npv_clk_pcm_hw_params_l);
13 13 if (r < 0) if (r < 0)
14 FATALCLK("alsa:unable to allocate hardware parameters context\n");
14 npv_clk_fatal("alsa:unable to allocate hardware parameters context\n");
15 15 npv_clk_l.paused = false; npv_clk_l.paused = false;
16 16 } }
17 17 #define NO_REF_TIME_POINT 1 #define NO_REF_TIME_POINT 1
 
... ... STATIC u8 npv_clk_get_audio_st_ts(s64 *ts)
45 45 &ac); &ac);
46 46 r = snd_pcm_status(npv_audio_pcm_p, npv_clk_l.now.status); r = snd_pcm_status(npv_audio_pcm_p, npv_clk_l.now.status);
47 47 if (r < 0) if (r < 0)
48 FATALCLK("alsa:unable to sample timing information for 'now' time point\n");
48 npv_clk_fatal("alsa:unable to sample timing information for 'now' time point\n");
49 49 } }
50 50 snd_pcm_status_get_audio_htstamp(npv_clk_l.now.status, &hts); snd_pcm_status_get_audio_htstamp(npv_clk_l.now.status, &hts);
51 51 now_ns = (f64)hts.tv_sec * 1e9 + (f64)hts.tv_nsec; now_ns = (f64)hts.tv_sec * 1e9 + (f64)hts.tv_nsec;
 
... ... STATIC u8 npv_clk_get_audio_st_ts(s64 *ts)
60 60 /*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
61 61 r = snd_pcm_hw_params_current(npv_audio_pcm_p, npv_clk_pcm_hw_params_l); r = snd_pcm_hw_params_current(npv_audio_pcm_p, npv_clk_pcm_hw_params_l);
62 62 if (r != 0) if (r != 0)
63 FATALCLK("alsa:unable to get current hardware parameters\n");
63 npv_clk_fatal("alsa:unable to get current hardware parameters\n");
64 64 r = snd_pcm_hw_params_get_rate_numden(npv_clk_pcm_hw_params_l, r = snd_pcm_hw_params_get_rate_numden(npv_clk_pcm_hw_params_l,
65 65 &audio_rate_num_ui, &audio_rate_den_ui); &audio_rate_num_ui, &audio_rate_den_ui);
66 66 if (r < 0) if (r < 0)
67 FATALCLK("alsa:unable to get exact rate\n");
67 npv_clk_fatal("alsa:unable to get exact rate\n");
68 68 audio_rate_num = (f64)audio_rate_num_ui; audio_rate_num = (f64)audio_rate_num_ui;
69 69 audio_rate_den = (f64)audio_rate_den_ui; audio_rate_den = (f64)audio_rate_den_ui;
70 70 /*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
 
... ... STATIC void npv_clk_ref_time_point_update(s64 audio_ts,
118 118 snd_pcm_status_set_audio_htstamp_config(npv_clk_l.ref.status, &ac); snd_pcm_status_set_audio_htstamp_config(npv_clk_l.ref.status, &ac);
119 119 r = snd_pcm_status(npv_audio_pcm_p, npv_clk_l.ref.status); r = snd_pcm_status(npv_audio_pcm_p, npv_clk_l.ref.status);
120 120 if (r < 0) if (r < 0)
121 FATALCLK("unable to sample timing information for reference time point\n");
121 npv_clk_fatal("unable to sample timing information for reference time point\n");
122 122 npv_clk_l.ref.audio_st_ts = audio_ts; npv_clk_l.ref.audio_st_ts = audio_ts;
123 123 npv_clk_l.ref.written_ufrs_n = written_ufrs_n; npv_clk_l.ref.written_ufrs_n = written_ufrs_n;
124 124 npv_clk_l.ref_valid = true; npv_clk_l.ref_valid = true;
 
... ... STATIC void npv_clk_pause(void)
139 139 snd_pcm_status_set_audio_htstamp_config(npv_clk_l.now.status, &ac); snd_pcm_status_set_audio_htstamp_config(npv_clk_l.now.status, &ac);
140 140 r = snd_pcm_status(npv_audio_pcm_p, npv_clk_l.now.status); r = snd_pcm_status(npv_audio_pcm_p, npv_clk_l.now.status);
141 141 if (r < 0) if (r < 0)
142 FATALCLK("alsa:unable to sample timing information for 'paused' time point\n");
142 npv_clk_fatal("alsa:unable to sample timing information for 'paused' time point\n");
143 143 } }
144 144 STATIC void npv_clk_unpause(void) STATIC void npv_clk_unpause(void)
145 145 { {
File npv/fmt/local/code.frag.c changed (mode: 100644) (index 8fc394e..a547139)
1 STATIC void fatal(u8 *fmt, ...)
2 {
3 va_list ap;
4
5 npv_perr("format:");
6 va_start(ap, fmt);
7 npv_vfatal(fmt, ap);
8 va_end(ap); /* unreachable */
9 }
10 STATIC void pout(u8 *fmt, ...)
11 {
12 va_list ap;
13
14 npv_pout("format:");
15 va_start(ap, fmt);
16 npv_vpout(fmt, ap);
17 va_end(ap);
18 }
1 19 STATIC bool did_reached_limits(void) STATIC bool did_reached_limits(void)
2 20 { {
3 21 bool r; bool r;
 
... ... STATIC void init_once_public(u8 *url)
20 38 ctx_p = 0; ctx_p = 0;
21 39 r = avformat_open_input(&ctx_p, url, NULL, NULL); r = avformat_open_input(&ctx_p, url, NULL, NULL);
22 40 if (r < 0) if (r < 0)
23 FATALF("ffmpeg:unable to open \"%s\"\n", url);
41 fatal("ffmpeg:unable to open \"%s\"\n", url);
24 42 r = pthread_mutex_init(&ctx_mutex_l, 0); r = pthread_mutex_init(&ctx_mutex_l, 0);
25 43 if (r != 0) if (r != 0)
26 FATALF("unable to init the format mutex\n");
44 fatal("unable to init the format mutex\n");
27 45 } }
28 46 STATIC void init_once_local(void) STATIC void init_once_local(void)
29 47 { {
30 48 pkt_l = avcodec_pkt_ref_alloc(); pkt_l = avcodec_pkt_ref_alloc();
31 49 if (pkt_l == 0) if (pkt_l == 0)
32 FATALF("ffmpeg:unable to allocate a reference on a packet for encoded/compressed audio/video\n");
50 fatal("ffmpeg:unable to allocate a reference on a packet for encoded/compressed audio/video\n");
33 51 } }
File npv/fmt/main.c changed (mode: 100644) (index f5b0c4d..43010fb)
5 5 * copyright (C) 2020 Sylvain BERTRAND * copyright (C) 2020 Sylvain BERTRAND
6 6 */ */
7 7 #include <pthread.h> #include <pthread.h>
8 #include <stdarg.h>
9 #include <stdint.h>
8 10 #include <libavformat/avformat.h> #include <libavformat/avformat.h>
9 11 #include <libavcodec/avcodec.h> #include <libavcodec/avcodec.h>
10 12 #include "npv/c_fixing.h" #include "npv/c_fixing.h"
11 13 #include "npv/global.h" #include "npv/global.h"
14 #include "npv/public.h"
12 15 #include "npv/pkt_q/public.h" #include "npv/pkt_q/public.h"
13 16 #include "npv/fmt/public.h" #include "npv/fmt/public.h"
14 17 #include "npv/audio/public.h" #include "npv/audio/public.h"
 
18 21 #include "npv/fmt/namespace/public.h" #include "npv/fmt/namespace/public.h"
19 22 #include "npv/fmt/namespace/main.c" #include "npv/fmt/namespace/main.c"
20 23 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
21 #define FATALF(fmt, ...) FATAL("format:" fmt, ##__VA_ARGS__)
22 #define WARNINGF(fmt, ...) WARNING("format:" fmt, ##__VA_ARGS__)
23 #define POUTF(fmt, ...) POUT("format:" fmt, ##__VA_ARGS__)
24 /*----------------------------------------------------------------------------*/
25 24 #include "npv/fmt/local/state.frag.c" #include "npv/fmt/local/state.frag.c"
26 25 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
27 26 #include "npv/fmt/local/code.frag.c" #include "npv/fmt/local/code.frag.c"
28 27 #include "npv/fmt/public/code.frag.c" #include "npv/fmt/public/code.frag.c"
29 28 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
30 #undef FATALF
31 #undef WARNINGF
32 #undef POUTF
33 /*----------------------------------------------------------------------------*/
34 29 #define CLEANUP #define CLEANUP
35 30 #include "npv/namespace/ffmpeg.h" #include "npv/namespace/ffmpeg.h"
36 31 #include "npv/fmt/namespace/public.h" #include "npv/fmt/namespace/public.h"
File npv/fmt/namespace/main.c changed (mode: 100644) (index c35dab9..e8881cc)
11 11 #define audio npv_fmt_break_on_audio #define audio npv_fmt_break_on_audio
12 12 #define ctx_mutex_l npv_fmt_ctx_mutex_l #define ctx_mutex_l npv_fmt_ctx_mutex_l
13 13 #define did_reached_limits npv_fmt_did_reached_limits #define did_reached_limits npv_fmt_did_reached_limits
14 #define fatalf npv_fmt_fatal
14 15 #define pkt_l npv_fmt_pkt_l #define pkt_l npv_fmt_pkt_l
16 #define poutf npv_fmt_pout
15 17 #define video npv_fmt_break_on_video #define video npv_fmt_break_on_video
16 18 /*============================================================================*/ /*============================================================================*/
17 19 #else #else
 
26 28 #undef audio #undef audio
27 29 #undef ctx_mutex_l #undef ctx_mutex_l
28 30 #undef did_reached_limits #undef did_reached_limits
31 #undef fatalf
32 #undef poutf
29 33 #undef pkt_l #undef pkt_l
30 34 #undef video #undef video
31 35 #endif #endif
File npv/fmt/public/code.frag.c changed (mode: 100644) (index 243f6e1..f5c1a38)
... ... STATIC void ctx_lock(void)
4 4
5 5 r = pthread_mutex_lock(&ctx_mutex_l); r = pthread_mutex_lock(&ctx_mutex_l);
6 6 if (r != 0) if (r != 0)
7 FATALF("%d:unable to lock the format context\n", r);
7 fatal("%d:unable to lock the format context\n", r);
8 8 } }
9 9 STATIC void ctx_unlock(void) STATIC void ctx_unlock(void)
10 10 { {
 
... ... STATIC void ctx_unlock(void)
12 12
13 13 r = pthread_mutex_unlock(&ctx_mutex_l); r = pthread_mutex_unlock(&ctx_mutex_l);
14 14 if (r != 0) if (r != 0)
15 FATALF("%d:unable to unlock the format context\n", r);
15 fatal("%d:unable to unlock the format context\n", r);
16 16 } }
17 17 STATIC u8 *duration_estimate_to_str(enum avformat_duration_estimation_method_t STATIC u8 *duration_estimate_to_str(enum avformat_duration_estimation_method_t
18 18 m) m)
 
... ... STATIC u8 pkts_read_and_q(void) { loop
50 50 else if (r == AVERROR_EOF) else if (r == AVERROR_EOF)
51 51 return EOF_FMT; return EOF_FMT;
52 52 else if (r != 0) else if (r != 0)
53 FATALF("ffmpeg:error while reading coded/compressed data into packets\n");
53 fatal("ffmpeg:error while reading coded/compressed data into packets\n");
54 54 /* r == 0 */ /* r == 0 */
55 55 if (pkt_l->st_idx == npv_audio_st_p.idx) { if (pkt_l->st_idx == npv_audio_st_p.idx) {
56 56 npv_pipeline_limits_lock(); npv_pipeline_limits_lock();
 
... ... STATIC void probe_best_sts(
93 93 /* probe beyond the header, if any */ /* probe beyond the header, if any */
94 94 r = avformat_find_st_info(ctx_p, 0); r = avformat_find_st_info(ctx_p, 0);
95 95 if (r < 0) if (r < 0)
96 FATALF("ffmpeg:unable to probe\n");
96 fatal("ffmpeg:unable to probe\n");
97 97 r = avformat_find_best_st(ctx_p, AVUTIL_AVMEDIA_TYPE_AUDIO, -1, -1, 0, r = avformat_find_best_st(ctx_p, AVUTIL_AVMEDIA_TYPE_AUDIO, -1, -1, 0,
98 98 0); 0);
99 99 if (r < 0) if (r < 0)
100 FATALF("ffmpeg:no audio stream found\n");
100 fatal("ffmpeg:no audio stream found\n");
101 101 /* we copy what we need */ /* we copy what we need */
102 102 *best_a_idx = r; *best_a_idx = r;
103 103 *best_a_id = ctx_p->sts[r]->id; *best_a_id = ctx_p->sts[r]->id;
 
... ... STATIC void probe_best_sts(
108 108 r = avformat_find_best_st(ctx_p, AVUTIL_AVMEDIA_TYPE_VIDEO, -1, -1, 0, r = avformat_find_best_st(ctx_p, AVUTIL_AVMEDIA_TYPE_VIDEO, -1, -1, 0,
109 109 0); 0);
110 110 if (r < 0) if (r < 0)
111 FATALF("ffmpeg:no video stream found\n");
111 fatal("ffmpeg:no video stream found\n");
112 112 /* we copy what we need */ /* we copy what we need */
113 113 *best_v_idx = r; *best_v_idx = r;
114 114 *best_v_id = ctx_p->sts[r]->id; *best_v_id = ctx_p->sts[r]->id;
115 115 *best_v_tb = &ctx_p->sts[r]->tb; *best_v_tb = &ctx_p->sts[r]->tb;
116 116 *best_v_start_time = ctx_p->sts[r]->start_time; *best_v_start_time = ctx_p->sts[r]->start_time;
117 117 *best_v_codec_params = ctx_p->sts[r]->codecpar; /* used once for init */ *best_v_codec_params = ctx_p->sts[r]->codecpar; /* used once for init */
118 POUTF("####%s#### probing: %u streams and %u programs\n", ctx_p->url, ctx_p->sts_n, ctx_p->programs_n);
119 POUTF("####%s#### probing: best video stream index=%d/id=%d, best audio stream index=%d/id=%d\n", ctx_p->url, *best_v_idx, *best_v_id, *best_a_idx, *best_a_id);
118 pout("####%s#### probing: %u streams and %u programs\n", ctx_p->url, ctx_p->sts_n, ctx_p->programs_n);
119 pout("####%s#### probing: best video stream index=%d/id=%d, best audio stream index=%d/id=%d\n", ctx_p->url, *best_v_idx, *best_v_id, *best_a_idx, *best_a_id);
120 120 } }
121 121 STATIC void flush(void) STATIC void flush(void)
122 122 { {
File npv/global.h changed (mode: 100644) (index 48e72b9..52a58e8)
7 7 #include <stdio.h> #include <stdio.h>
8 8 #include <stdlib.h> #include <stdlib.h>
9 9 #include "c_fixing.h" #include "c_fixing.h"
10 #define POUT(fmt, ...) ({flockfile(stdout);fprintf(stdout, fmt, ##__VA_ARGS__);funlockfile(stdout);})
11 #define PERR(fmt, ...) ({flockfile(stderr);fprintf(stderr, fmt, ##__VA_ARGS__);funlockfile(stderr);})
12 #define WARNING(fmt, ...) ({flockfile(stderr);fprintf(stderr, "WARNING:" fmt, ##__VA_ARGS__);funlockfile(stderr);})
13 #define FATAL(fmt, ...) ({PERR("FATAL:" fmt, ##__VA_ARGS__);exit(1);})
14 #define EXIT(fmt, ...) ({POUT("EXITING:" fmt, ##__VA_ARGS__);exit(0);})
15 10 #define STR_SZ U8_MAX #define STR_SZ U8_MAX
16 11 #endif #endif
File npv/local/code.frag.c changed (mode: 100644) (index 333beb0..4ba09e8)
... ... STATIC void sigs_init_once(void)
13 13
14 14 r = sigfillset(&sset); r = sigfillset(&sset);
15 15 if (r == -1) if (r == -1)
16 FATAL("unable to get a full signal mask\n");
16 fatal("unable to get a full signal mask\n");
17 17
18 18 /* the "controlling terminal" line asks for a core dump, leave it be */ /* the "controlling terminal" line asks for a core dump, leave it be */
19 19 r = sigdelset(&sset, SIGQUIT); r = sigdelset(&sset, SIGQUIT);
20 20 if (r == -1) if (r == -1)
21 FATAL("unable to remove SIGQUIT from our signal mask\n");
21 fatal("unable to remove SIGQUIT from our signal mask\n");
22 22
23 23 r = pthread_sigmask(SIG_SETMASK, &sset, 0); r = pthread_sigmask(SIG_SETMASK, &sset, 0);
24 24 if (r != 0) if (r != 0)
25 FATAL("unable to \"block\" \"all\" signals\n");
25 fatal("unable to \"block\" \"all\" signals\n");
26 26
27 27 /* from here, we "steal" signals with signalfd */ /* from here, we "steal" signals with signalfd */
28 28
29 29 r = sigemptyset(&sset); r = sigemptyset(&sset);
30 30 if (r == -1) if (r == -1)
31 FATAL("unable to get an empty signal mask\n");
31 fatal("unable to get an empty signal mask\n");
32 32 /* we are asked nicely to terminate */ /* we are asked nicely to terminate */
33 33 r = sigaddset(&sset, SIGTERM); r = sigaddset(&sset, SIGTERM);
34 34 if (r == -1) if (r == -1)
35 FATAL("unable to add SIGTERM to our signal mask\n");
35 fatal("unable to add SIGTERM to our signal mask\n");
36 36 /* the "controlling terminal" line (^c) asks nicely to terminate */ /* the "controlling terminal" line (^c) asks nicely to terminate */
37 37 r = sigaddset(&sset, SIGINT); r = sigaddset(&sset, SIGINT);
38 38 if (r == -1) if (r == -1)
39 FATAL("unable to add SIGINT to our signal mask\n");
39 fatal("unable to add SIGINT to our signal mask\n");
40 40
41 41 r = signalfd(-1, &sset, SFD_NONBLOCK); r = signalfd(-1, &sset, SFD_NONBLOCK);
42 42 if (r == -1) if (r == -1)
43 FATAL("unable to get a signalfd file descriptor\n");
43 fatal("unable to get a signalfd file descriptor\n");
44 44 sig_fd_l = r; sig_fd_l = r;
45 45 } }
46 46 STATIC void prefill_wait(void) { loop STATIC void prefill_wait(void) { loop
 
... ... STATIC void prefill_wait(void) { loop
67 67 if (r == 0) if (r == 0)
68 68 break; break;
69 69 if (r != EINTR) if (r != EINTR)
70 FATAL("prefill wait timer failed:%d\n", r);
70 fatal("prefill wait timer failed:%d\n", r);
71 71 /* r == EINTR */ /* r == EINTR */
72 72 memcpy(&wanted, &rem, sizeof(wanted)); memcpy(&wanted, &rem, sizeof(wanted));
73 73 memset(&rem, 0, sizeof(rem)); memset(&rem, 0, sizeof(rem));
 
... ... STATIC void predecode_wait(void)
90 90 if (r == 0) if (r == 0)
91 91 break; break;
92 92 if (r != EINTR) if (r != EINTR)
93 FATAL("predecoding wait timer failed:%d\n", r);
93 fatal("predecoding wait timer failed:%d\n", r);
94 94 /* r == EINTR */ /* r == EINTR */
95 95 memcpy(&wanted, &rem, sizeof(wanted)); memcpy(&wanted, &rem, sizeof(wanted));
96 96 memset(&rem, 0, sizeof(rem)); memset(&rem, 0, sizeof(rem));
 
... ... STATIC void evt_init_once(void)
100 100 { {
101 101 ep_fd_p = epoll_create1(0); ep_fd_p = epoll_create1(0);
102 102 if (ep_fd_p == -1) if (ep_fd_p == -1)
103 FATAL("unable to create the epoll file descriptor\n");
103 fatal("unable to create the epoll file descriptor\n");
104 104 } }
105 105 STATIC void evt_add_all_fds(void) STATIC void evt_add_all_fds(void)
106 106 { {
 
... ... STATIC void evt_add_all_fds(void)
113 113 evt.data.fd = sig_fd_l; evt.data.fd = sig_fd_l;
114 114 r = epoll_ctl(ep_fd_p, EPOLL_CTL_ADD, sig_fd_l, &evt); r = epoll_ctl(ep_fd_p, EPOLL_CTL_ADD, sig_fd_l, &evt);
115 115 if (r == -1) if (r == -1)
116 FATAL("unable to add the signalfd file descriptior to the epoll file descriptor\n");
116 fatal("unable to add the signalfd file descriptior to the epoll file descriptor\n");
117 117 /*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
118 118 /* the video timer */ /* the video timer */
119 119 evt.events = EPOLLIN; evt.events = EPOLLIN;
120 120 evt.data.fd = npv_video_timer_fd_p; evt.data.fd = npv_video_timer_fd_p;
121 121 r = epoll_ctl(ep_fd_p, EPOLL_CTL_ADD, npv_video_timer_fd_p, &evt); r = epoll_ctl(ep_fd_p, EPOLL_CTL_ADD, npv_video_timer_fd_p, &evt);
122 122 if (r == -1) if (r == -1)
123 FATAL("unable to add the video timer file descriptor\n");
123 fatal("unable to add the video timer file descriptor\n");
124 124 /*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
125 125 /* the x11 xcb file descriptor */ /* the x11 xcb file descriptor */
126 126 evt.events = EPOLLIN; evt.events = EPOLLIN;
127 127 evt.data.fd = npv_xcb_p.fd; evt.data.fd = npv_xcb_p.fd;
128 128 r = epoll_ctl(ep_fd_p, EPOLL_CTL_ADD, npv_xcb_p.fd, &evt); r = epoll_ctl(ep_fd_p, EPOLL_CTL_ADD, npv_xcb_p.fd, &evt);
129 129 if (r == -1) if (r == -1)
130 FATAL("unable to add the x11 xcb file descriptor\n");
130 fatal("unable to add the x11 xcb file descriptor\n");
131 131 /*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
132 132 /* alsa pcm poll file descriptors */ /* alsa pcm poll file descriptors */
133 133 i = 0; i = 0;
 
... ... STATIC void evt_add_all_fds(void)
139 139 r = epoll_ctl(ep_fd_p, EPOLL_CTL_ADD, r = epoll_ctl(ep_fd_p, EPOLL_CTL_ADD,
140 140 npv_audio_pcm_pollfds_p[i].fd, &evt); npv_audio_pcm_pollfds_p[i].fd, &evt);
141 141 if (r == -1) if (r == -1)
142 FATAL("unable to add alsa poll file descriptor index %d to epoll file descriptor\n", i);
142 fatal("unable to add alsa poll file descriptor index %d to epoll file descriptor\n", i);
143 143 ++i; ++i;
144 144 } }
145 145 /*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
 
... ... STATIC void evt_add_all_fds(void)
149 149 r = epoll_ctl(ep_fd_p, EPOLL_CTL_ADD, npv_audio_draining_timer_fd_p, r = epoll_ctl(ep_fd_p, EPOLL_CTL_ADD, npv_audio_draining_timer_fd_p,
150 150 &evt); &evt);
151 151 if (r == -1) if (r == -1)
152 FATAL("unable to add the draining timer file descriptor\n");
152 fatal("unable to add the draining timer file descriptor\n");
153 153 /*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
154 154 /* the xcb screensaver heartbeat timer */ /* the xcb screensaver heartbeat timer */
155 155 evt.events = EPOLLIN; evt.events = EPOLLIN;
 
... ... STATIC void evt_add_all_fds(void)
157 157 r = epoll_ctl(ep_fd_p, EPOLL_CTL_ADD, r = epoll_ctl(ep_fd_p, EPOLL_CTL_ADD,
158 158 npv_xcb_p.screensaver_heartbeat_timer_fd, &evt); npv_xcb_p.screensaver_heartbeat_timer_fd, &evt);
159 159 if (r == -1) if (r == -1)
160 FATAL("unable to add the xcb screensaver heartbeat timer file descriptor\n");
160 fatal("unable to add the xcb screensaver heartbeat timer file descriptor\n");
161 161 /*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
162 162 /* the xcb mouse visibility timer */ /* the xcb mouse visibility timer */
163 163 evt.events = EPOLLIN; evt.events = EPOLLIN;
 
... ... STATIC void evt_add_all_fds(void)
165 165 r = epoll_ctl(ep_fd_p, EPOLL_CTL_ADD, r = epoll_ctl(ep_fd_p, EPOLL_CTL_ADD,
166 166 npv_xcb_p.mouse_visibility_timer_fd, &evt); npv_xcb_p.mouse_visibility_timer_fd, &evt);
167 167 if (r == -1) if (r == -1)
168 FATAL("unable to add the xcb screensaver heartbeat timer file descriptor\n");
168 fatal("unable to add the xcb screensaver heartbeat timer file descriptor\n");
169 169 } }
170 170 STATIC void evt_sigs(void) STATIC void evt_sigs(void)
171 171 { {
 
... ... STATIC void evt_sigs(void)
175 175 /* no short reads */ /* no short reads */
176 176 r = read(sig_fd_l, &siginfo, sizeof(siginfo)); r = read(sig_fd_l, &siginfo, sizeof(siginfo));
177 177 if (r != sizeof(siginfo)) if (r != sizeof(siginfo))
178 FATAL("unable to read signal information\n");
178 fatal("unable to read signal information\n");
179 179
180 180 switch (siginfo.ssi_signo) { switch (siginfo.ssi_signo) {
181 181 case SIGTERM: case SIGTERM:
182 EXIT("received SIGTERM\n");
182 exit_ok("received SIGTERM\n");
183 183 case SIGINT: case SIGINT:
184 EXIT("received SIGINT\n");
184 exit_ok("received SIGINT\n");
185 185 default: default:
186 WARNING("signal handle:unwanted signal %d received, discarding\n", siginfo.ssi_signo);
186 warning("signal handle:unwanted signal %d received, discarding\n", siginfo.ssi_signo);
187 187 } }
188 188 } }
189 189 STATIC void evt_accumulate(struct epoll_event *evt, bool *have_evt_sigs, STATIC void evt_accumulate(struct epoll_event *evt, bool *have_evt_sigs,
 
... ... STATIC void evt_accumulate(struct epoll_event *evt, bool *have_evt_sigs,
198 198 *have_evt_sigs = true; *have_evt_sigs = true;
199 199 return; return;
200 200 } }
201 FATAL("event loop wait:signal:unexpected event\n");
201 fatal("event loop wait:signal:unexpected event\n");
202 202 } }
203 203 /*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/
204 204 /* only update alsa fds */ /* only update alsa fds */
 
... ... STATIC void evt_accumulate(struct epoll_event *evt, bool *have_evt_sigs,
225 225 *have_evt_video = true; *have_evt_video = true;
226 226 return; return;
227 227 } }
228 FATAL("event loop wait:video:unexpected event\n");
228 fatal("event loop wait:video:unexpected event\n");
229 229 } }
230 230 /*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/
231 231 if (evt->data.fd == npv_audio_draining_timer_fd_p) { if (evt->data.fd == npv_audio_draining_timer_fd_p) {
 
... ... STATIC void evt_accumulate(struct epoll_event *evt, bool *have_evt_sigs,
233 233 *have_evt_pcm_draining = true; *have_evt_pcm_draining = true;
234 234 return; return;
235 235 } }
236 FATAL("event loop wait:audio draining timer:unexpected event\n");
236 fatal("event loop wait:audio draining timer:unexpected event\n");
237 237 } }
238 238 /*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/
239 239 if (evt->data.fd == npv_xcb_p.screensaver_heartbeat_timer_fd) { if (evt->data.fd == npv_xcb_p.screensaver_heartbeat_timer_fd) {
 
... ... STATIC void evt_accumulate(struct epoll_event *evt, bool *have_evt_sigs,
241 241 *have_evt_xcb_screensaver_heartbeat = true; *have_evt_xcb_screensaver_heartbeat = true;
242 242 return; return;
243 243 } }
244 FATAL("event loop wait:xcb screensaver heartbeat timer:unexpected event\n");
244 fatal("event loop wait:xcb screensaver heartbeat timer:unexpected event\n");
245 245 } }
246 246 /*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/
247 247 if (evt->data.fd == npv_xcb_p.mouse_visibility_timer_fd) { if (evt->data.fd == npv_xcb_p.mouse_visibility_timer_fd) {
 
... ... STATIC void evt_accumulate(struct epoll_event *evt, bool *have_evt_sigs,
249 249 *have_evt_xcb_mouse_visibility = true; *have_evt_xcb_mouse_visibility = true;
250 250 return; return;
251 251 } }
252 FATAL("event loop wait:xcb mouse visibility timer:unexpected event\n");
252 fatal("event loop wait:xcb mouse visibility timer:unexpected event\n");
253 253 } }
254 254 } }
255 255 /* /*
 
... ... STATIC void evts_loop(void)
278 278 fds_n = epoll_wait(ep_fd_p, evts, EPOLL_EVTS_N, -1); fds_n = epoll_wait(ep_fd_p, evts, EPOLL_EVTS_N, -1);
279 279 if (fds_n == -1) { if (fds_n == -1) {
280 280 if (errno == EINTR) { if (errno == EINTR) {
281 WARNING("event loop wait:was interrupted by a signal\n");
281 warning("event loop wait:was interrupted by a signal\n");
282 282 return; return;
283 283 } }
284 FATAL("event loop wait:an error occured\n");
284 fatal("event loop wait:an error occured\n");
285 285 } }
286 286
287 287 have_evt_sigs = false; have_evt_sigs = false;
 
... ... STATIC void evts_loop(void)
327 327 npv_audio_pcm_pollfds_p, npv_audio_pcm_pollfds_n_p, npv_audio_pcm_pollfds_p, npv_audio_pcm_pollfds_n_p,
328 328 &pcm_evts); &pcm_evts);
329 329 if (r != 0) if (r != 0)
330 FATAL("alsa:error processing the poll file descriptors\n");
330 fatal("alsa:error processing the poll file descriptors\n");
331 331 if ((pcm_evts & ~POLLOUT) != 0) if ((pcm_evts & ~POLLOUT) != 0)
332 FATAL("alsa:unexpected events\n");
332 fatal("alsa:unexpected events\n");
333 333 if ((pcm_evts & POLLOUT) != 0) if ((pcm_evts & POLLOUT) != 0)
334 334 npv_audio_evt_pcm_write(); npv_audio_evt_pcm_write();
335 335 } }
 
... ... STATIC void ff_log_stdout(void *a, int b, const char *fmt, va_list ap)
350 350 } }
351 351 STATIC void usage(void) STATIC void usage(void)
352 352 { {
353 POUT("\
353 pout("\
354 354 npv [-f send a fullscreen message to the window manager at start] [-p alsa pcm]\n\ npv [-f send a fullscreen message to the window manager at start] [-p alsa pcm]\n\
355 355 [-v volume(0..100)] [-h window height in pixels] [-w window width in pixels]\n\ [-v volume(0..100)] [-h window height in pixels] [-w window width in pixels]\n\
356 356 [-b packet buffer prefill wait(0..100)] [-help] url\n"); [-b packet buffer prefill wait(0..100)] [-help] url\n");
 
... ... STATIC void opts_parse(int argc, u8 **args, u8 **url, bool* start_fullscreen,
371 371 ++i; ++i;
372 372 } else if (strcmp("-p", args[i]) == 0) { } else if (strcmp("-p", args[i]) == 0) {
373 373 *pcm_str = args[i + 1]; *pcm_str = args[i + 1];
374 POUT("-p:alsa pcm \"%s\"\n", *pcm_str);
374 pout("-p:alsa pcm \"%s\"\n", *pcm_str);
375 375 i += 2; i += 2;
376 376 } else if (strcmp("-v", args[i]) == 0) { } else if (strcmp("-v", args[i]) == 0) {
377 377 unsigned long vol_ul; unsigned long vol_ul;
378 378
379 379 if ((i + 1) == argc) if ((i + 1) == argc)
380 FATAL("-v:initial volume is missing\n");
380 fatal("-v:initial volume is missing\n");
381 381 vol_ul = strtoul(args[i + 1], 0, 10); vol_ul = strtoul(args[i + 1], 0, 10);
382 382 if (vol_ul < 0 || 100 < vol_ul) if (vol_ul < 0 || 100 < vol_ul)
383 FATAL("-v:invalid volume value %lu (0..100)\n", vol_ul);
383 fatal("-v:invalid volume value %lu (0..100)\n", vol_ul);
384 384 *vol = (double)vol_ul / 100.; *vol = (double)vol_ul / 100.;
385 POUT("-v:using initial volume %f\n", *vol);
385 pout("-v:using initial volume %f\n", *vol);
386 386 i += 2; i += 2;
387 387 } else if (strcmp("-h", args[i]) == 0) { } else if (strcmp("-h", args[i]) == 0) {
388 388 unsigned long h_ul; unsigned long h_ul;
389 389
390 390 if ((i + 1) == argc) if ((i + 1) == argc)
391 FATAL("-h:initial window pixel height is missing\n");
391 fatal("-h:initial window pixel height is missing\n");
392 392 h_ul = strtoul(args[i + 1], 0, 10); h_ul = strtoul(args[i + 1], 0, 10);
393 393 if (h_ul == 0 || h_ul > U16_MAX) if (h_ul == 0 || h_ul > U16_MAX)
394 FATAL("-h:invalid window pixel height %lu (1..%lu)\n", h_ul, U16_MAX);
394 fatal("-h:invalid window pixel height %lu (1..%lu)\n", h_ul, U16_MAX);
395 395 *h = (u16)h_ul; *h = (u16)h_ul;
396 POUT("-h:using initial window height %lu pixels\n", h_ul);
396 pout("-h:using initial window height %lu pixels\n", h_ul);
397 397 i += 2; i += 2;
398 398 } else if (strcmp("-w", args[i]) == 0) { } else if (strcmp("-w", args[i]) == 0) {
399 399 unsigned long w_ul; unsigned long w_ul;
400 400
401 401 if ((i + 1) == argc) if ((i + 1) == argc)
402 FATAL("-h:initial window pixel width is missing\n");
402 fatal("-h:initial window pixel width is missing\n");
403 403 w_ul = strtoul(args[i + 1], 0, 10); w_ul = strtoul(args[i + 1], 0, 10);
404 404 if (w_ul == 0 || w_ul > U16_MAX) if (w_ul == 0 || w_ul > U16_MAX)
405 FATAL("-w:invalid window pixel width %lu (1..%lu)\n", w_ul, U16_MAX);
405 fatal("-w:invalid window pixel width %lu (1..%lu)\n", w_ul, U16_MAX);
406 406 *w = (u16)w_ul; *w = (u16)w_ul;
407 POUT("-w:using initial window width %lu pixels\n", w_ul);
407 pout("-w:using initial window width %lu pixels\n", w_ul);
408 408 i += 2; i += 2;
409 409 } else if (strcmp("-b", args[i]) == 0) { } else if (strcmp("-b", args[i]) == 0) {
410 410 if ((i + 1) == argc) if ((i + 1) == argc)
411 FATAL("-b:percent value for prefill of buffer of packet queues is missing\n");
411 fatal("-b:percent value for prefill of buffer of packet queues is missing\n");
412 412 *pkts_prefill_percent = (u8)strtoul(args[i + 1], 0, 10); *pkts_prefill_percent = (u8)strtoul(args[i + 1], 0, 10);
413 POUT("-v:using a %u prefilled buffer of packet queues\n", *pkts_prefill_percent);
413 pout("-v:using a %u prefilled buffer of packet queues\n", *pkts_prefill_percent);
414 414 i += 2; i += 2;
415 415 } else if (strcmp("-help", args[i]) == 0) { } else if (strcmp("-help", args[i]) == 0) {
416 416 usage(); usage();
 
... ... STATIC void opts_parse(int argc, u8 **args, u8 **url, bool* start_fullscreen,
421 421 } }
422 422 } }
423 423 if (url_idx == -1) if (url_idx == -1)
424 FATAL("missing url\n");
424 fatal("missing url\n");
425 425 *url = args[url_idx]; *url = args[url_idx];
426 POUT("url-->####%s####\n", *url);
426 pout("url-->####%s####\n", *url);
427 427 } }
428 428 #define WIDTH_NOT_DEFINED 0 #define WIDTH_NOT_DEFINED 0
429 429 #define HEIGHT_NOT_DEFINED 0 #define HEIGHT_NOT_DEFINED 0
 
... ... STATIC u8 *ts_to_str(int64_t ts, avutil_rational_t time_base,
560 560 } }
561 561 return str; return str;
562 562 } }
563 #define RED if (stdout_is_tty) POUT("\x1b[38;2;255;0;0m")
564 #define GREEN if (stdout_is_tty) POUT("\x1b[38;2;0;255;0m")
565 #define BLUE if (stdout_is_tty) POUT("\x1b[38;2;0;0;255m")
566 #define PURPLE if (stdout_is_tty) POUT("\x1b[38;2;255;0;255m")
567 #define RESTORE if (stdout_is_tty) POUT("\x1b[39;49m");
563 #define RED if (stdout_is_tty) pout("\x1b[38;2;255;0;0m")
564 #define GREEN if (stdout_is_tty) pout("\x1b[38;2;0;255;0m")
565 #define BLUE if (stdout_is_tty) pout("\x1b[38;2;0;0;255m")
566 #define PURPLE if (stdout_is_tty) pout("\x1b[38;2;255;0;255m")
567 #define RESTORE if (stdout_is_tty) pout("\x1b[39;49m");
568 568 #define TS_FROM_CLK_OK 0 #define TS_FROM_CLK_OK 0
569 569 /* we don't lock anything as an act of faith */ /* we don't lock anything as an act of faith */
570 570 STATIC void npv_cmd_info(void) STATIC void npv_cmd_info(void)
 
... ... STATIC void npv_cmd_info(void)
584 584 stdout_is_tty = true; stdout_is_tty = true;
585 585
586 586 RESTORE; RESTORE;
587 GREEN;POUT("================================================================================\n");RESTORE;
588 PURPLE;POUT("%s\n", npv_fmt_ctx_p->url);RESTORE;
587 GREEN;pout("================================================================================\n");RESTORE;
588 PURPLE;pout("%s\n", npv_fmt_ctx_p->url);RESTORE;
589 589
590 590 r8 = npv_clk_get_audio_st_ts(&audio_now); r8 = npv_clk_get_audio_st_ts(&audio_now);
591 591 if (r8 != TS_FROM_CLK_OK) { if (r8 != TS_FROM_CLK_OK) {
592 POUT("information unavailable at the time of the command due to an unavailable audio clock\n");
592 pout("information unavailable at the time of the command due to an unavailable audio clock\n");
593 593 return; return;
594 594 } }
595 595 ts_str = ts_to_str(audio_now, npv_audio_st_p.tb, &remaining); ts_str = ts_to_str(audio_now, npv_audio_st_p.tb, &remaining);
596 RED;POUT("%s", ts_str);RESTORE;
596 RED;pout("%s", ts_str);RESTORE;
597 597 if (remaining != 0) if (remaining != 0)
598 POUT(" remaining %"PRId64" time base units", remaining);
598 pout(" remaining %"PRId64" time base units", remaining);
599 599 else else
600 POUT("\n");
601 POUT("\t%"PRId64" stream time base units (%d/%d seconds)\n",
600 pout("\n");
601 pout("\t%"PRId64" stream time base units (%d/%d seconds)\n",
602 602 audio_now, npv_audio_st_p.tb.num, npv_audio_st_p.tb.den); audio_now, npv_audio_st_p.tb.num, npv_audio_st_p.tb.den);
603 BLUE;POUT("--------------------------------------------------------------------------------\n");RESTORE;
604 POUT("format:");
603 BLUE;pout("--------------------------------------------------------------------------------\n");RESTORE;
604 pout("format:");
605 605 if (npv_fmt_ctx_p->duration == AV_NOPTS_VALUE) { if (npv_fmt_ctx_p->duration == AV_NOPTS_VALUE) {
606 POUT("duration is not provided\n");
606 pout("duration is not provided\n");
607 607 } else { } else {
608 608 snprintf(duration_str, sizeof(duration_str), "%"PRId64, snprintf(duration_str, sizeof(duration_str), "%"PRId64,
609 609 npv_fmt_ctx_p->duration); npv_fmt_ctx_p->duration);
610 610 ts_str = ts_to_str(npv_fmt_ctx_p->duration, AV_TIME_BASE_Q, ts_str = ts_to_str(npv_fmt_ctx_p->duration, AV_TIME_BASE_Q,
611 611 &remaining); &remaining);
612 POUT("duration=");RED;POUT("%s", ts_str);RESTORE;
612 pout("duration=");RED;pout("%s", ts_str);RESTORE;
613 613 if (remaining != 0) if (remaining != 0)
614 POUT(" remaining %"PRId64" av_time_base units\n",
614 pout(" remaining %"PRId64" av_time_base units\n",
615 615 remaining); remaining);
616 616 else else
617 POUT("\n");
618 POUT("\t%s av_time_base units (1/%d seconds)\n\testimation method is %s\n",
617 pout("\n");
618 pout("\t%s av_time_base units (1/%d seconds)\n\testimation method is %s\n",
619 619 duration_str, AV_TIME_BASE, duration_estimate_to_str( duration_str, AV_TIME_BASE, duration_estimate_to_str(
620 620 npv_fmt_ctx_p->duration_estimation_method)); npv_fmt_ctx_p->duration_estimation_method));
621 621 } }
622 BLUE;POUT("--------------------------------------------------------------------------------\n");RESTORE;
623 POUT("stream:audio_id=%d", npv_audio_st_p.id);
622 BLUE;pout("--------------------------------------------------------------------------------\n");RESTORE;
623 pout("stream:audio_id=%d", npv_audio_st_p.id);
624 624 if (npv_fmt_ctx_p->streams[npv_audio_st_p.idx]->duration == AV_NOPTS_VALUE) { if (npv_fmt_ctx_p->streams[npv_audio_st_p.idx]->duration == AV_NOPTS_VALUE) {
625 POUT(";duration is not provided\n");
625 pout(";duration is not provided\n");
626 626 } else { } else {
627 627 snprintf(duration_str, sizeof(duration_str), "%"PRId64, snprintf(duration_str, sizeof(duration_str), "%"PRId64,
628 628 npv_fmt_ctx_p->streams[npv_audio_st_p.idx]->duration); npv_fmt_ctx_p->streams[npv_audio_st_p.idx]->duration);
629 629 ts_str = ts_to_str( ts_str = ts_to_str(
630 630 npv_fmt_ctx_p->streams[npv_audio_st_p.idx]->duration, npv_fmt_ctx_p->streams[npv_audio_st_p.idx]->duration,
631 631 npv_audio_st_p.tb, &remaining); npv_audio_st_p.tb, &remaining);
632 POUT(";duration=");RED;POUT("%s\n", ts_str);RESTORE;
632 pout(";duration=");RED;pout("%s\n", ts_str);RESTORE;
633 633 if (remaining != 0) if (remaining != 0)
634 POUT(" remaining %"PRId64" stream time base units\n",
634 pout(" remaining %"PRId64" stream time base units\n",
635 635 remaining); remaining);
636 636 else else
637 POUT("\n");
638 POUT("\t%s stream time base units (%d/%d seconds)\n",
637 pout("\n");
638 pout("\t%s stream time base units (%d/%d seconds)\n",
639 639 duration_str, npv_audio_st_p.tb.num, duration_str, npv_audio_st_p.tb.num,
640 640 npv_audio_st_p.tb.den); npv_audio_st_p.tb.den);
641 641 } }
642 BLUE;POUT("--------------------------------------------------------------------------------\n");RESTORE;
643 GREEN;POUT("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");RESTORE;
642 BLUE;pout("--------------------------------------------------------------------------------\n");RESTORE;
643 GREEN;pout("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");RESTORE;
644 644 } }
645 645 #undef TS_FROM_CLK_OK #undef TS_FROM_CLK_OK
646 646 #undef RED #undef RED
 
... ... STATIC void npv_cmd_info(void)
651 651 /*==== while waiting for the osd -- end ======================================*/ /*==== while waiting for the osd -- end ======================================*/
652 652 STATIC void npv_cmd_quit(void) STATIC void npv_cmd_quit(void)
653 653 { {
654 EXIT("quit command received\n");
654 exit_ok("quit command received\n");
655 655 } }
656 656 STATIC void seek_lock(void) STATIC void seek_lock(void)
657 657 { {
 
... ... STATIC void seek_x(s64 delta)
694 694 s64 video_now; s64 video_now;
695 695
696 696 if (npv_audio_draining_p) { if (npv_audio_draining_p) {
697 WARNING("seek:audio is draining, seeking disable\n");
697 warning("seek:audio is draining, seeking disable\n");
698 698 return; return;
699 699 } }
700 700 if (paused_p) /* we don't seek in pause */ if (paused_p) /* we don't seek in pause */
 
... ... STATIC void seek_x(s64 delta)
706 706
707 707 r = npv_clk_get_audio_st_ts(&audio_now); r = npv_clk_get_audio_st_ts(&audio_now);
708 708 if (r != TS_FROM_CLK_OK) { if (r != TS_FROM_CLK_OK) {
709 WARNING("seek:audio:clock timestamp unavailable, ignoring command\n");
709 warning("seek:audio:clock timestamp unavailable, ignoring command\n");
710 710 seek_unlock(); seek_unlock();
711 711 return; return;
712 712 } }
713 713 r = npv_clk_get_video_st_ts(&video_now); r = npv_clk_get_video_st_ts(&video_now);
714 714 if (r != TS_FROM_CLK_OK) { if (r != TS_FROM_CLK_OK) {
715 WARNING("seek:video:clock timestamp unavailable, ignoring command\n");
715 warning("seek:video:clock timestamp unavailable, ignoring command\n");
716 716 seek_unlock(); seek_unlock();
717 717 return; return;
718 718 } }
 
... ... STATIC void seek_x(s64 delta)
728 728 if (npv_audio_st_p.start_time != AV_NOPTS_VALUE) if (npv_audio_st_p.start_time != AV_NOPTS_VALUE)
729 729 if (new_audio_ts < npv_audio_st_p.start_time) if (new_audio_ts < npv_audio_st_p.start_time)
730 730 new_audio_ts = npv_audio_st_p.start_time; new_audio_ts = npv_audio_st_p.start_time;
731 POUT("trying to seek to %"PRId64" audio stream time base units\n", new_audio_ts);
731 pout("trying to seek to %"PRId64" audio stream time base units\n", new_audio_ts);
732 732 a = avformat_seek_pkt(npv_fmt_ctx_p, npv_audio_st_p.id, new_audio_ts, a = avformat_seek_pkt(npv_fmt_ctx_p, npv_audio_st_p.id, new_audio_ts,
733 733 0); 0);
734 734 if (a < 0) { if (a < 0) {
735 POUT("unable to seek to %"PRId64" audio stream time base units\n", new_audio_ts);
735 pout("unable to seek to %"PRId64" audio stream time base units\n", new_audio_ts);
736 736 goto try_restore_audio; goto try_restore_audio;
737 737 } }
738 POUT("audio seek to %"PRId64" audio stream time base units\n", new_audio_ts);
738 pout("audio seek to %"PRId64" audio stream time base units\n", new_audio_ts);
739 739 /*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
740 740 new_video_ts = video_now + delta * npv_video_st_p.tb.den new_video_ts = video_now + delta * npv_video_st_p.tb.den
741 741 / npv_video_st_p.tb.num; / npv_video_st_p.tb.num;
 
... ... STATIC void seek_x(s64 delta)
743 743 if (npv_video_st_p.start_time != AV_NOPTS_VALUE) if (npv_video_st_p.start_time != AV_NOPTS_VALUE)
744 744 if (new_video_ts < npv_video_st_p.start_time) if (new_video_ts < npv_video_st_p.start_time)
745 745 new_video_ts = npv_video_st_p.start_time; new_video_ts = npv_video_st_p.start_time;
746 POUT("trying to seek to %"PRId64" video stream time base units\n", new_video_ts);
746 pout("trying to seek to %"PRId64" video stream time base units\n", new_video_ts);
747 747 a = avformat_seek_pkt(npv_fmt_ctx_p, npv_video_st_p.id, new_video_ts, a = avformat_seek_pkt(npv_fmt_ctx_p, npv_video_st_p.id, new_video_ts,
748 748 0); 0);
749 749 if (a < 0) { if (a < 0) {
750 POUT("unable to seek to %"PRId64" video stream time base units but audio was seeked)\n", new_video_ts);
750 pout("unable to seek to %"PRId64" video stream time base units but audio was seeked)\n", new_video_ts);
751 751 goto try_restore_video; goto try_restore_video;
752 752 } }
753 POUT("video seek to %"PRId64" video stream time base units\n", new_video_ts);
753 pout("video seek to %"PRId64" video stream time base units\n", new_video_ts);
754 754 flush: flush:
755 755 npv_video_dec_flush(); npv_video_dec_flush();
756 756 npv_audio_dec_flush(); npv_audio_dec_flush();
 
... ... flush:
761 761 npv_pipeline_prefill_reset(npv_pipeline_limits_p.pkts.prefill.percent); npv_pipeline_prefill_reset(npv_pipeline_limits_p.pkts.prefill.percent);
762 762 seek_unlock(); seek_unlock();
763 763
764 POUT("prefilling audio and video buffers...");
764 pout("prefilling audio and video buffers...");
765 765 prefill_wait(); /* use the lock on the pipeline limits */ prefill_wait(); /* use the lock on the pipeline limits */
766 POUT("done\n");
767 POUT("predecoding audio and video...");
766 pout("done\n");
767 pout("predecoding audio and video...");
768 768 predecode_wait(); /* use the lock on the pipeline limits */ predecode_wait(); /* use the lock on the pipeline limits */
769 POUT("done\n");
769 pout("done\n");
770 770 (void)snd_pcm_prepare(npv_audio_pcm_p); (void)snd_pcm_prepare(npv_audio_pcm_p);
771 771 return; return;
772 772
773 773 try_restore_video: try_restore_video:
774 774 a = avformat_seek_pkt(npv_fmt_ctx_p, npv_video_st_p.id, video_now, 0); a = avformat_seek_pkt(npv_fmt_ctx_p, npv_video_st_p.id, video_now, 0);
775 775 if (a < 0) /* we don't send an application error */ if (a < 0) /* we don't send an application error */
776 EXIT("unable to restore video to %"PRId64" video stream time base units\n", video_now);
776 exit_ok("unable to restore video to %"PRId64" video stream time base units\n", video_now);
777 777 try_restore_audio: try_restore_audio:
778 778 a = avformat_seek_pkt(npv_fmt_ctx_p, npv_audio_st_p.id, audio_now, 0); a = avformat_seek_pkt(npv_fmt_ctx_p, npv_audio_st_p.id, audio_now, 0);
779 779 if (a < 0) /* we don't send an application error */ if (a < 0) /* we don't send an application error */
780 EXIT("unable to restore audio to %"PRId64" audio stream time base units\n", audio_now);
780 exit_ok("unable to restore audio to %"PRId64" audio stream time base units\n", audio_now);
781 781 goto flush; goto flush;
782 782 } }
783 783 #undef TS_FROM_CLK_OK #undef TS_FROM_CLK_OK
784 784 STATIC void npv_cmd_rewind(void) STATIC void npv_cmd_rewind(void)
785 785 { {
786 POUT("COMMAND:rewind\n");
786 pout("COMMAND:rewind\n");
787 787 seek_x(-SEEK_DELTA); seek_x(-SEEK_DELTA);
788 788 } }
789 789
790 790 STATIC void npv_cmd_rewind_big(void) STATIC void npv_cmd_rewind_big(void)
791 791 { {
792 POUT("COMMAND:rewind big\n");
792 pout("COMMAND:rewind big\n");
793 793 seek_x(-SEEK_DELTA_BIG); seek_x(-SEEK_DELTA_BIG);
794 794 } }
795 795
796 796 STATIC void npv_cmd_fastforward(void) STATIC void npv_cmd_fastforward(void)
797 797 { {
798 POUT("COMMAND:fastforward\n");
798 pout("COMMAND:fastforward\n");
799 799 seek_x(SEEK_DELTA); seek_x(SEEK_DELTA);
800 800 } }
801 801
802 802 STATIC void npv_cmd_fastforward_big(void) STATIC void npv_cmd_fastforward_big(void)
803 803 { {
804 POUT("COMMAND:fastforward big\n");
804 pout("COMMAND:fastforward big\n");
805 805 seek_x(SEEK_DELTA_BIG); seek_x(SEEK_DELTA_BIG);
806 806 } }
807 807
808 808 STATIC void npv_cmd_pause(void) STATIC void npv_cmd_pause(void)
809 809 { {
810 810 if (npv_audio_draining_p) { if (npv_audio_draining_p) {
811 WARNING("pause:audio is draining, toggling pause is disable\n");
811 warning("pause:audio is draining, toggling pause is disable\n");
812 812 return; return;
813 813 } }
814 814 if (paused_p) { if (paused_p) {
815 815 int r; int r;
816 816
817 POUT("COMMAND:unpause\n");
817 pout("COMMAND:unpause\n");
818 818 paused_p = false; paused_p = false;
819 819 npv_fmt_ctx_lock(); npv_fmt_ctx_lock();
820 820 avformat_read_play(npv_fmt_ctx_p); avformat_read_play(npv_fmt_ctx_p);
 
... ... STATIC void npv_cmd_pause(void)
824 824 } else { } else {
825 825 int r; int r;
826 826
827 POUT("COMMAND:pause\n");
827 pout("COMMAND:pause\n");
828 828 paused_p = true; paused_p = true;
829 829 npv_fmt_ctx_lock(); npv_fmt_ctx_lock();
830 830 avformat_read_pause(npv_fmt_ctx_p); avformat_read_pause(npv_fmt_ctx_p);
 
... ... int main(int argc, u8 **args)
883 883 avutil_log_set_callback(avutil_log_default_callback); avutil_log_set_callback(avutil_log_default_callback);
884 884
885 885 npv_pipeline_read_thd_start(); npv_pipeline_read_thd_start();
886 POUT("prefilling audio and video buffers...");
886 pout("prefilling audio and video buffers...");
887 887 prefill_wait(); prefill_wait();
888 POUT("done\n");
888 pout("done\n");
889 889 npv_pipeline_audio_thd_start(); npv_pipeline_audio_thd_start();
890 890 npv_pipeline_video_thd_start(); npv_pipeline_video_thd_start();
891 POUT("predecoding audio and video...");
891 pout("predecoding audio and video...");
892 892 predecode_wait(); predecode_wait();
893 POUT("done\n");
893 pout("done\n");
894 894 npv_video_timer_start(); npv_video_timer_start();
895 895 npv_xcb_screensaver_heartbeat_timer_start(); npv_xcb_screensaver_heartbeat_timer_start();
896 896
File npv/main.c changed (mode: 100644) (index c7bfb0b..1e9ab6e)
42 42 #include "npv/thdsws/public.h" #include "npv/thdsws/public.h"
43 43 #include "npv/clk/public.h" #include "npv/clk/public.h"
44 44 /*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
45 #include "npv/namespace/public.h"
45 46 #include "npv/namespace/ffmpeg.h" #include "npv/namespace/ffmpeg.h"
46 47 #include "npv/audio/namespace/ffmpeg.h" #include "npv/audio/namespace/ffmpeg.h"
47 48 #include "npv/namespace/public.h" #include "npv/namespace/public.h"
 
51 52 /*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
52 53 #include "npv/local/state.frag.c" #include "npv/local/state.frag.c"
53 54 #include "npv/local/code.frag.c" #include "npv/local/code.frag.c"
55 #include "npv/public/code.frag.c"
54 56 /*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
55 57 #define CLEANUP #define CLEANUP
58 #include "npv/namespace/public.h"
56 59 #include "npv/namespace/ffmpeg.h" #include "npv/namespace/ffmpeg.h"
57 60 #include "npv/audio/namespace/ffmpeg.h" #include "npv/audio/namespace/ffmpeg.h"
58 61 #include "npv/namespace/public.h" #include "npv/namespace/public.h"
File npv/make-template.sh added (mode: 100755) (index 0000000..b95910a)
1 #!/bin/sh
2 cc main.c -lc -ldl -D_GNU_SOURCE -DSTATIC=static -I../ \
3 $(pkg-config --cflags xcb) \
4 $(pkg-config --cflags --libs libavcodec libavdevice libavfilter \
5 libavformat libavutil libpostproc libswresample libswscale \
6 alsa) \
7 -o /tmp/npv
File npv/namespace/public.h changed (mode: 100644) (index 311ab37..6775d79)
1 1 #ifndef CLEANUP #ifndef CLEANUP
2 2 #define ep_fd_p npv_ep_fd_p #define ep_fd_p npv_ep_fd_p
3 #define exit_ok npv_exit
4 #define fatal npv_fatal
3 5 #define paused_p npv_paused_p #define paused_p npv_paused_p
6 #define perr npv_perr
7 #define pout npv_pout
8 #define vfatal npv_vfatal
9 #define vwarning npv_vwarning
10 #define vpout npv_vpout
11 #define vperr npv_vperr
12 #define warning npv_warning
4 13 /*============================================================================*/ /*============================================================================*/
5 14 #else #else
6 15 #undef ep_fd_p #undef ep_fd_p
16 #undef exit_ok
17 #undef fatal
7 18 #undef paused_p #undef paused_p
19 #undef perr
20 #undef pout
21 #undef vfatal
22 #undef vwarning
23 #undef vpout
24 #undef vperr
25 #undef warning
8 26 #endif #endif
File npv/pipeline/local/code.frag.c changed (mode: 100644) (index 8557e17..0fa7a21)
1 STATIC void fatal(u8 *fmt, ...)
2 {
3 va_list ap;
4
5 npv_perr("pipeline:");
6 va_start(ap, fmt);
7 npv_vfatal(fmt, ap);
8 va_end(ap); /* unreachable */
9 }
10 STATIC void pout(u8 *fmt, ...)
11 {
12 va_list ap;
13
14 npv_pout("pipeline:");
15 va_start(ap, fmt);
16 npv_vpout(fmt, ap);
17 va_end(ap);
18 }
1 19 STATIC void wait(long ns) STATIC void wait(long ns)
2 20 { {
3 21 struct timespec wanted; struct timespec wanted;
 
... ... STATIC void wait(long ns)
14 32 if (r == 0) if (r == 0)
15 33 break; break;
16 34 if (r != EINTR) if (r != EINTR)
17 FATALP("data wait timer failed:%d\n", r);
35 fatal("data wait timer failed:%d\n", r);
18 36 /* r == EINTR */ /* r == EINTR */
19 37 memcpy(&wanted, &rem, sizeof(wanted)); memcpy(&wanted, &rem, sizeof(wanted));
20 38 memset(&rem, 0, sizeof(rem)); memset(&rem, 0, sizeof(rem));
 
... ... STATIC void *read_thd_entry(void *arg)
52 70
53 71 r = sigfillset(&sset); r = sigfillset(&sset);
54 72 if (r == -1) if (r == -1)
55 FATALP("read thread:unable to get a full signal mask\n");
73 fatal("read thread:unable to get a full signal mask\n");
56 74 r = pthread_sigmask(SIG_SETMASK, &sset, 0); r = pthread_sigmask(SIG_SETMASK, &sset, 0);
57 75 if (r != 0) if (r != 0)
58 FATALP("read thread:unable to \"block\" \"all\" signals\n");
76 fatal("read thread:unable to \"block\" \"all\" signals\n");
59 77 read(); read();
60 78 /* unreachable */ /* unreachable */
61 79 } }
 
... ... STATIC void *audio_thd_entry(void *arg)
113 131
114 132 r = sigfillset(&sset); r = sigfillset(&sset);
115 133 if (r == -1) if (r == -1)
116 FATALP("send thread:unable to get a full signal mask\n");
134 fatal("send thread:unable to get a full signal mask\n");
117 135 r = pthread_sigmask(SIG_SETMASK, &sset, 0); r = pthread_sigmask(SIG_SETMASK, &sset, 0);
118 136 if (r != 0) if (r != 0)
119 FATALP("send thread:unable to \"block\" \"all\" signals\n");
137 fatal("send thread:unable to \"block\" \"all\" signals\n");
120 138 audio(); audio();
121 139 /* unreachable */ /* unreachable */
122 140 } }
 
... ... STATIC void *video_thd_entry(void *arg)
170 188
171 189 r = sigfillset(&sset); r = sigfillset(&sset);
172 190 if (r == -1) if (r == -1)
173 FATALP("send thread:unable to get a full signal mask\n");
191 fatal("send thread:unable to get a full signal mask\n");
174 192 r = pthread_sigmask(SIG_SETMASK, &sset, 0); r = pthread_sigmask(SIG_SETMASK, &sset, 0);
175 193 if (r != 0) if (r != 0)
176 FATALP("send thread:unable to \"block\" \"all\" signals\n");
194 fatal("send thread:unable to \"block\" \"all\" signals\n");
177 195 video(); video();
178 196 /* unreachable */ /* unreachable */
179 197 } }
File npv/pipeline/main.c changed (mode: 100644) (index 5679b81..c05a201)
5 5 * copyright (C) 2020 Sylvain BERTRAND * copyright (C) 2020 Sylvain BERTRAND
6 6 */ */
7 7 #include <stdbool.h> #include <stdbool.h>
8 #include <stdarg.h>
8 9 #include <string.h> #include <string.h>
9 10 #include <time.h> #include <time.h>
10 11 #include <signal.h> #include <signal.h>
 
12 13 #include <pthread.h> #include <pthread.h>
13 14 #include "npv/c_fixing.h" #include "npv/c_fixing.h"
14 15 #include "npv/global.h" #include "npv/global.h"
16 #include "npv/public.h"
15 17 #include "npv/pkt_q/public.h" #include "npv/pkt_q/public.h"
16 18 #include "npv/pipeline/public.h" #include "npv/pipeline/public.h"
17 19 #include "npv/fmt/public.h" #include "npv/fmt/public.h"
 
22 24 #include "npv/pipeline/namespace/public.h" #include "npv/pipeline/namespace/public.h"
23 25 #include "npv/pipeline/namespace/main.c" #include "npv/pipeline/namespace/main.c"
24 26 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
25 #define FATALP(fmt, ...) FATAL("pipeline:" fmt, ##__VA_ARGS__)
26 #define WARNINGP(fmt, ...) WARNING("pipeline:" fmt, ##__VA_ARGS__)
27 #define POUTP(fmt, ...) POUT("pipeline:" fmt, ##__VA_ARGS__)
28 /*----------------------------------------------------------------------------*/
29 27 #include "npv/pipeline/local/state.frag.c" #include "npv/pipeline/local/state.frag.c"
30 28 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
31 29 #include "npv/pipeline/local/code.frag.c" #include "npv/pipeline/local/code.frag.c"
32 30 #include "npv/pipeline/public/code.frag.c" #include "npv/pipeline/public/code.frag.c"
33 31 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
34 #undef FATALP
35 #undef WARNINGP
36 #undef POUTP
37 /*---------------------------------------------------------------------------*/
38 32 #define CLEANUP #define CLEANUP
39 33 #include "npv/namespace/ffmpeg.h" #include "npv/namespace/ffmpeg.h"
40 34 #include "npv/pipeline/namespace/public.h" #include "npv/pipeline/namespace/public.h"
File npv/pipeline/namespace/main.c changed (mode: 100644) (index 3b29232..35f28c2)
6 6 #define audio npv_pipeline_audio #define audio npv_pipeline_audio
7 7 #define audio_thd_entry npv_pipeline_audio_thd_entry #define audio_thd_entry npv_pipeline_audio_thd_entry
8 8 #define eof_pkt_l npv_pipeline_eof_pkt_l #define eof_pkt_l npv_pipeline_eof_pkt_l
9 #define fatal npv_pipeline_fatal
9 10 #define have_enough_predecoded_audio_frs npv_pipeline_have_enough_predecoded_audio_frs #define have_enough_predecoded_audio_frs npv_pipeline_have_enough_predecoded_audio_frs
10 11 #define have_enough_predecoded_video_frs npv_pipeline_have_enough_predecoded_video_frs #define have_enough_predecoded_video_frs npv_pipeline_have_enough_predecoded_video_frs
12 #define pout npv_pipeline_pout
11 13 #define read npv_pipeline_read #define read npv_pipeline_read
12 14 #define read_thd_entry npv_pipeline_read_thd_entry #define read_thd_entry npv_pipeline_read_thd_entry
13 15 #define timer_ack npv_pipeline_timer_ack #define timer_ack npv_pipeline_timer_ack
 
20 22 #undef audio #undef audio
21 23 #undef audio_thd_entry #undef audio_thd_entry
22 24 #undef eof_pkt_l #undef eof_pkt_l
25 #undef fatal
23 26 #undef have_enough_predecoded_audio_frs #undef have_enough_predecoded_audio_frs
24 27 #undef have_enough_predecoded_video_frs #undef have_enough_predecoded_video_frs
28 #undef pout
25 29 #undef read #undef read
26 30 #undef read_thd_entry #undef read_thd_entry
27 31 #undef timer_ack #undef timer_ack
File npv/pipeline/public/code.frag.c changed (mode: 100644) (index 4cbc664..f522590)
... ... STATIC void limits_reset(void)
11 11 STATIC void prefill_reset(u8 percent) STATIC void prefill_reset(u8 percent)
12 12 { {
13 13 if (percent > 100) if (percent > 100)
14 FATALP("invalid prefill of %u%% for the buffer of packet queues\n", percent);
14 fatal("invalid prefill of %u%% for the buffer of packet queues\n", percent);
15 15 if (percent != 0) { if (percent != 0) {
16 16 limits_p.pkts.prefill.audio_bytes_rem = limits_p.pkts.prefill.audio_bytes_rem =
17 17 limits_p.pkts.limit.audio_bytes_n * percent / 100; limits_p.pkts.limit.audio_bytes_n * percent / 100;
18 POUTP("prefill size for the audio packet queue buffer is %u%%/%"PRId64" bytes\n", percent, limits_p.pkts.prefill.audio_bytes_rem);
18 pout("prefill size for the audio packet queue buffer is %u%%/%"PRId64" bytes\n", percent, limits_p.pkts.prefill.audio_bytes_rem);
19 19 limits_p.pkts.prefill.video_bytes_rem = limits_p.pkts.prefill.video_bytes_rem =
20 20 limits_p.pkts.limit.video_bytes_n * percent / 100; limits_p.pkts.limit.video_bytes_n * percent / 100;
21 POUTP("prefill size for the video packet queue buffer is %u%%/%"PRId64" bytes\n", percent, limits_p.pkts.prefill.video_bytes_rem);
21 pout("prefill size for the video packet queue buffer is %u%%/%"PRId64" bytes\n", percent, limits_p.pkts.prefill.video_bytes_rem);
22 22 } else { } else {
23 23 limits_p.pkts.prefill.audio_bytes_rem = 0; limits_p.pkts.prefill.audio_bytes_rem = 0;
24 24 limits_p.pkts.prefill.video_bytes_rem = 0; limits_p.pkts.prefill.video_bytes_rem = 0;
25 POUTP("prefill for the packet queue buffers is disabled\n");
25 pout("prefill for the packet queue buffers is disabled\n");
26 26 } }
27 27 } }
28 28 STATIC void init_once(void) STATIC void init_once(void)
 
... ... STATIC void init_once(void)
31 31
32 32 eof_pkt_l = avcodec_pkt_ref_alloc(); eof_pkt_l = avcodec_pkt_ref_alloc();
33 33 if (eof_pkt_l == 0) if (eof_pkt_l == 0)
34 FATALP("ffmpeg:unable to allocate a null/eof reference on a packet\n");
34 fatal("ffmpeg:unable to allocate a null/eof reference on a packet\n");
35 35 eof_pkt_l->data = 0; eof_pkt_l->data = 0;
36 36 eof_pkt_l->sz = 0; eof_pkt_l->sz = 0;
37 37
38 38 r = pthread_mutex_init(&limits_p.mutex, 0); r = pthread_mutex_init(&limits_p.mutex, 0);
39 39 if (r != 0) if (r != 0)
40 FATALP("unable to initialize the mutex to guard the accounting of limits\n");
40 fatal("unable to initialize the mutex to guard the accounting of limits\n");
41 41 } }
42 42 STATIC void limits_lock(void) STATIC void limits_lock(void)
43 43 { {
 
... ... STATIC void limits_lock(void)
45 45
46 46 r = pthread_mutex_lock(&limits_p.mutex); r = pthread_mutex_lock(&limits_p.mutex);
47 47 if (r != 0) if (r != 0)
48 FATALP("unable to lock the limits\n");
48 fatal("unable to lock the limits\n");
49 49 } }
50 50 STATIC void limits_unlock(void) STATIC void limits_unlock(void)
51 51 { {
 
... ... STATIC void limits_unlock(void)
53 53
54 54 r = pthread_mutex_unlock(&limits_p.mutex); r = pthread_mutex_unlock(&limits_p.mutex);
55 55 if (r != 0) if (r != 0)
56 FATALP("unable to unlock the limits\n");
56 fatal("unable to unlock the limits\n");
57 57 } }
58 58 STATIC void read_thd_start(void) STATIC void read_thd_start(void)
59 59 { {
 
... ... STATIC void read_thd_start(void)
63 63
64 64 r = pthread_attr_init(&attr); r = pthread_attr_init(&attr);
65 65 if (r != 0) if (r != 0)
66 FATALP("unable to initialize read thread attribute\n");
66 fatal("unable to initialize read thread attribute\n");
67 67 r = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); r = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
68 68 if (r != 0) if (r != 0)
69 FATALP("unable to set the read thread attribute to detach mode\n");
69 fatal("unable to set the read thread attribute to detach mode\n");
70 70 r = pthread_create(&id, &attr, &read_thd_entry, 0); r = pthread_create(&id, &attr, &read_thd_entry, 0);
71 71 if (r != 0) if (r != 0)
72 FATALP("unable to create the read thread\n");
73 POUTP("read thread %lu\n", (unsigned long)id);
72 fatal("unable to create the read thread\n");
73 pout("read thread %lu\n", (unsigned long)id);
74 74 pthread_attr_destroy(&attr); pthread_attr_destroy(&attr);
75 75 } }
76 76 STATIC void audio_thd_start(void) STATIC void audio_thd_start(void)
 
... ... STATIC void audio_thd_start(void)
81 81
82 82 r = pthread_attr_init(&attr); r = pthread_attr_init(&attr);
83 83 if (r != 0) if (r != 0)
84 FATALP("unable to initialize audio thread attribute\n");
84 fatal("unable to initialize audio thread attribute\n");
85 85 r = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); r = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
86 86 if (r != 0) if (r != 0)
87 FATALP("unable to set the audio thread attribute to detach mode\n");
87 fatal("unable to set the audio thread attribute to detach mode\n");
88 88 r = pthread_create(&id, &attr, &audio_thd_entry, 0); r = pthread_create(&id, &attr, &audio_thd_entry, 0);
89 89 if (r != 0) if (r != 0)
90 FATALP("unable to create the audio thread\n");
91 POUTP("audio thread %lu\n", (unsigned long)id);
90 fatal("unable to create the audio thread\n");
91 pout("audio thread %lu\n", (unsigned long)id);
92 92 pthread_attr_destroy(&attr); pthread_attr_destroy(&attr);
93 93 } }
94 94 STATIC void video_thd_start(void) STATIC void video_thd_start(void)
 
... ... STATIC void video_thd_start(void)
99 99
100 100 r = pthread_attr_init(&attr); r = pthread_attr_init(&attr);
101 101 if (r != 0) if (r != 0)
102 FATALP("unable to initialize video thread attribute\n");
102 fatal("unable to initialize video thread attribute\n");
103 103 r = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); r = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
104 104 if (r != 0) if (r != 0)
105 FATALP("unable to set the video thread attribute to detach mode\n");
105 fatal("unable to set the video thread attribute to detach mode\n");
106 106 r = pthread_create(&id, &attr, &video_thd_entry, 0); r = pthread_create(&id, &attr, &video_thd_entry, 0);
107 107 if (r != 0) if (r != 0)
108 FATALP("unable to create the video thread\n");
109 POUTP("video thread %lu\n", (unsigned long)id);
108 fatal("unable to create the video thread\n");
109 pout("video thread %lu\n", (unsigned long)id);
110 110 pthread_attr_destroy(&attr); pthread_attr_destroy(&attr);
111 111 } }
File npv/pkt_q/local/code.frag.c changed (mode: 100644) (index d1d4c92..fb03e2b)
1 STATIC void fatal(u8 *fmt, ...)
2 {
3 va_list ap;
4
5 npv_perr("packet queue:");
6 va_start(ap, fmt);
7 npv_vfatal(fmt, ap);
8 va_end(ap); /* unreachable */
9 }
10 STATIC void fatalx(u8 *fmt, struct pkt_q_t *this, ...)
11 {
12 va_list ap;
13
14 npv_perr("%s:packet queue:", this->msg_hdr);
15 va_start(ap, this);
16 npv_vfatal(fmt, ap);
17 va_end(ap); /* unreachable */
18 }
1 19 STATIC void grow(struct pkt_q_t *this) STATIC void grow(struct pkt_q_t *this)
2 20 { {
3 21 u32 p; u32 p;
 
... ... STATIC void grow(struct pkt_q_t *this)
6 24 new_idx = this->n_max; new_idx = this->n_max;
7 25 this->q = realloc(this->q, sizeof(*this->q) * (this->n_max + 1)); this->q = realloc(this->q, sizeof(*this->q) * (this->n_max + 1));
8 26 if (this->q == 0) if (this->q == 0)
9 FATALXPQ("unable to allocate more memory for packet reference pointers\n");
27 fatalx("unable to allocate more memory for packet reference pointers\n", this);
10 28 this->q[new_idx] = avcodec_pkt_ref_alloc(); this->q[new_idx] = avcodec_pkt_ref_alloc();
11 29 if (this->q[new_idx] == 0) if (this->q[new_idx] == 0)
12 FATALXPQ("ffmpeg:unable to allocate a new packet reference\n");
30 fatalx("ffmpeg:unable to allocate a new packet reference\n", this);
13 31 ++this->n_max; ++this->n_max;
14 32 } }
File npv/pkt_q/main.c changed (mode: 100644) (index df4253a..775c86a)
1 1 #ifndef NPV_PKT_Q_MAIN_C #ifndef NPV_PKT_Q_MAIN_C
2 2 #define NPV_PKT_Q_MAIN_C #define NPV_PKT_Q_MAIN_C
3 3 #include <stdlib.h> #include <stdlib.h>
4 #include <stdarg.h>
4 5 #include <string.h> #include <string.h>
5 6 #include <pthread.h> #include <pthread.h>
6 7 #include <libavcodec/avcodec.h> #include <libavcodec/avcodec.h>
7 8 #include "npv/c_fixing.h" #include "npv/c_fixing.h"
8 9 #include "npv/global.h" #include "npv/global.h"
10 #include "npv/public.h"
9 11 #include "npv/pkt_q/public.h" #include "npv/pkt_q/public.h"
10 12 #include "npv/pipeline/public.h" #include "npv/pipeline/public.h"
11 13 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
12 #define FATALPQ(fmt, ...) FATAL("packet queue:" fmt, ##__VA_ARGS__)
13 #define FATALXPQ(fmt, ...) FATAL("%s:packet queue:" fmt, this->msg_hdr, ##__VA_ARGS__)
14 /*----------------------------------------------------------------------------*/
15 14 #include "npv/namespace/ffmpeg.h" #include "npv/namespace/ffmpeg.h"
16 15 #include "npv/pkt_q/namespace/public.h" #include "npv/pkt_q/namespace/public.h"
17 16 #include "npv/pkt_q/namespace/main.c" #include "npv/pkt_q/namespace/main.c"
 
19 18 #include "npv/pkt_q/local/code.frag.c" #include "npv/pkt_q/local/code.frag.c"
20 19 #include "npv/pkt_q/public/code.frag.c" #include "npv/pkt_q/public/code.frag.c"
21 20 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
22 #undef FATALPQ
23 #undef FATALXPQ
24 /*----------------------------------------------------------------------------*/
25 21 #define CLEANUP #define CLEANUP
26 22 #include "npv/namespace/ffmpeg.h" #include "npv/namespace/ffmpeg.h"
27 23 #include "npv/pkt_q/namespace/public.h" #include "npv/pkt_q/namespace/public.h"
File npv/pkt_q/namespace/main.c changed (mode: 100644) (index c7f494e..ed7e92e)
1 1 #ifndef CLEANUP #ifndef CLEANUP
2 #define grow npv_pkt_q_grow
2 #define fatal npv_pkt_q_fatal
3 #define fatalx npv_pkt_q_fatalx
4 #define grow npv_pkt_q_grow
3 5 /*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
4 6 /* some struct field names */ /* some struct field names */
5 7 #define sz size #define sz size
 
7 9 /*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
8 10 /*============================================================================*/ /*============================================================================*/
9 11 #else #else
12 #undef fatal
13 #undef fatalx
10 14 #undef grow #undef grow
11 15 /*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
12 16 #undef sz #undef sz
File npv/pkt_q/public/code.frag.c changed (mode: 100644) (index 73121c9..ce11e63)
... ... STATIC void lock(struct pkt_q_t *this)
4 4
5 5 r = pthread_mutex_lock(&this->mutex); r = pthread_mutex_lock(&this->mutex);
6 6 if (r != 0) if (r != 0)
7 FATALXPQ("%d:unable to lock packet queue\n", r);
7 fatalx("%d:unable to lock packet queue\n", this, r);
8 8 } }
9 9 STATIC void unlock(struct pkt_q_t *this) STATIC void unlock(struct pkt_q_t *this)
10 10 { {
 
... ... STATIC void unlock(struct pkt_q_t *this)
12 12
13 13 r = pthread_mutex_unlock(&this->mutex); r = pthread_mutex_unlock(&this->mutex);
14 14 if (r != 0) if (r != 0)
15 FATALXPQ("%d:unable to unlock packet queue\n", r);
15 fatalx("%d:unable to unlock packet queue\n", this, r);
16 16 } }
17 17 /* actually rotate the pkt ref ptrs */ /* actually rotate the pkt ref ptrs */
18 18 STATIC void deq(struct pkt_q_t *this) STATIC void deq(struct pkt_q_t *this)
 
... ... STATIC struct pkt_q_t *new(u8 *msg_hdr)
55 55
56 56 this = malloc(sizeof(*this)); this = malloc(sizeof(*this));
57 57 if (this == 0) if (this == 0)
58 FATALPQ("unable to allocate memory for the %s packet queue\n", msg_hdr);
58 fatal("unable to allocate memory for the %s packet queue\n", msg_hdr);
59 59 this->q = 0; this->q = 0;
60 60 this->n = 0; this->n = 0;
61 61 this->n_max = 0; this->n_max = 0;
62 62 this->msg_hdr = strdup(msg_hdr); this->msg_hdr = strdup(msg_hdr);
63 63 r = pthread_mutex_init(&this->mutex, 0); r = pthread_mutex_init(&this->mutex, 0);
64 64 if (r != 0) if (r != 0)
65 FATALPQ("unable to init the mutex for the %s packet queue\n", msg_hdr);
65 fatal("unable to init the mutex for the %s packet queue\n", msg_hdr);
66 66 return this; return this;
67 67 } }
68 68 STATIC bool has_eof(struct pkt_q_t *this) STATIC bool has_eof(struct pkt_q_t *this)
File npv/public.h changed (mode: 100644) (index e6d1950..3b37217)
5 5 * copyright (C) 2020 Sylvain BERTRAND * copyright (C) 2020 Sylvain BERTRAND
6 6 */ */
7 7 #include <stdbool.h> #include <stdbool.h>
8 /*---------------------------------------------------------------------------*/
8 #include <stdarg.h>
9 #include <stdint.h>
10 #include "npv/c_fixing.h"
11 /*----------------------------------------------------------------------------*/
9 12 #include "npv/namespace/public.h" #include "npv/namespace/public.h"
10 /*---------------------------------------------------------------------------*/
13 /*----------------------------------------------------------------------------*/
11 14 #include "npv/public/state.frag.h" #include "npv/public/state.frag.h"
12 /*---------------------------------------------------------------------------*/
15 /*----------------------------------------------------------------------------*/
16 STATIC void pout(u8 *fmt, ...);
17 STATIC void vpout(u8 *fmt, va_list ap);
18 STATIC void perr(u8 *fmt, ...);
19 STATIC void vperr(u8 *fmt, va_list ap);
20 STATIC void warning(u8 *fmt, ...);
21 STATIC void vwarning(u8 *fmt, va_list ap);
22 STATIC void fatal(u8 *fmt, ...);
23 STATIC void vfatal(u8 *fmt, va_list ap);
24 STATIC void exit_ok(u8 *fmt, ...);
25 /*----------------------------------------------------------------------------*/
13 26 #define CLEANUP #define CLEANUP
14 27 #include "npv/namespace/public.h" #include "npv/namespace/public.h"
15 28 #undef CLEANUP #undef CLEANUP
File npv/public/code.frag.c added (mode: 100644) (index 0000000..7fded40)
1 STATIC void pout(u8 *fmt, ...)
2 {
3 va_list ap;
4
5 va_start(ap, fmt);
6 flockfile(stdout);
7 vfprintf(stdout, fmt, ap);
8 funlockfile(stdout);
9 va_end(ap);
10 }
11 STATIC void vpout(u8 *fmt, va_list ap)
12 {
13 va_list aq;
14
15 va_copy(aq, ap);
16 flockfile(stdout);
17 vfprintf(stdout, fmt, aq);
18 funlockfile(stdout);
19 va_end(aq);
20 }
21 STATIC void perr(u8 *fmt, ...)
22 {
23 va_list ap;
24
25 va_start(ap, fmt);
26 flockfile(stderr);
27 vfprintf(stderr, fmt, ap);
28 funlockfile(stderr);
29 va_end(ap);
30 }
31 STATIC void vperr(u8 *fmt, va_list ap)
32 {
33 va_list aq;
34
35 va_copy(aq, ap);
36 flockfile(stderr);
37 vfprintf(stderr, fmt, aq);
38 funlockfile(stderr);
39 va_end(aq);
40 }
41 STATIC void warning(u8 *fmt, ...)
42 {
43 va_list ap;
44
45 perr("WARNING:");
46 va_start(ap, fmt);
47 vperr(fmt, ap);
48 va_end(ap);
49 }
50 STATIC void vwarning(u8 *fmt, va_list ap)
51 {
52 va_list aq;
53
54 perr("WARNING:");
55 va_copy(aq, ap);
56 vperr(fmt, aq);
57 va_end(aq);
58 }
59 STATIC void fatal(u8 *fmt, ...)
60 {
61 va_list ap;
62
63 perr("FATAL:");
64 va_start(ap, fmt);
65 vperr(fmt, ap);
66 va_end(ap);
67 exit(EXIT_FAILURE);
68 }
69 STATIC void vfatal(u8 *fmt, va_list ap)
70 {
71 va_list aq;
72
73 perr("FATAL:");
74 va_copy(aq, ap);
75 vperr(fmt, aq);
76 va_end(aq);
77 exit(EXIT_FAILURE);
78 }
79 STATIC void exit_ok(u8 *fmt, ...)
80 {
81 va_list ap;
82
83 pout("EXIT:");
84 va_start(ap, fmt);
85 vpout(fmt, ap);
86 va_end(ap);
87 exit(EXIT_SUCCESS);
88 }
File npv/thdsws/local/code.frag.c changed (mode: 100644) (index 9edf3ed..2dcf8b0)
... ... struct thdsws_ctx_private_t {
4 4 pthread_cond_t have_fr_to_scale; pthread_cond_t have_fr_to_scale;
5 5 struct SwsContext *sws; struct SwsContext *sws;
6 6 }; };
7 STATIC void fatal(u8 *fmt, ...)
8 {
9 va_list ap;
10
11 npv_perr("scaler:");
12 va_start(ap, fmt);
13 npv_vfatal(fmt, ap);
14 va_end(ap); /* unreachable */
15 }
16 STATIC void fatalw(u8 *fmt, ...)
17 {
18 va_list ap;
19
20 npv_perr("scaler worker:");
21 va_start(ap, fmt);
22 npv_vfatal(fmt, ap);
23 va_end(ap); /* unreachable */
24 }
7 25 STATIC void state_lock(struct thdsws_ctx_private_t *ctx_priv) STATIC void state_lock(struct thdsws_ctx_private_t *ctx_priv)
8 26 { {
9 27 int r; int r;
10 28
11 29 r = pthread_mutex_lock(&ctx_priv->mutex); r = pthread_mutex_lock(&ctx_priv->mutex);
12 30 if (r != 0) if (r != 0)
13 FATALTS("unable to lock the state\n");
31 fatal("unable to lock the state\n");
14 32 } }
15 33 STATIC void state_unlock(struct thdsws_ctx_private_t *ctx_priv) STATIC void state_unlock(struct thdsws_ctx_private_t *ctx_priv)
16 34 { {
 
... ... STATIC void state_unlock(struct thdsws_ctx_private_t *ctx_priv)
18 36
19 37 r = pthread_mutex_unlock(&ctx_priv->mutex); r = pthread_mutex_unlock(&ctx_priv->mutex);
20 38 if (r != 0) if (r != 0)
21 FATALTS("unable to unlock the state\n");
39 fatal("unable to unlock the state\n");
22 40 } }
23 41 STATIC void do_work(struct thdsws_ctx_t *ctx, struct thdsws_ctx_private_t *ctx_priv) STATIC void do_work(struct thdsws_ctx_t *ctx, struct thdsws_ctx_private_t *ctx_priv)
24 42 { {
 
... ... STATIC void do_work(struct thdsws_ctx_t *ctx, struct thdsws_ctx_private_t *ctx_p
27 45 (int)ctx->cfg.width, (int)ctx->cfg.height, ctx->cfg.dst_fmt, (int)ctx->cfg.width, (int)ctx->cfg.height, ctx->cfg.dst_fmt,
28 46 (int)ctx->cfg.flags, 0, 0, 0); (int)ctx->cfg.flags, 0, 0, 0);
29 47 if (ctx_priv->sws == 0) if (ctx_priv->sws == 0)
30 FATALTSW("unable to get a ffmpeg context\n");
48 fatalw("unable to get a ffmpeg context\n");
31 49
32 50 /* XXX: this is the hotspot */ /* XXX: this is the hotspot */
33 51 (void)sws_scale(ctx_priv->sws, (void)sws_scale(ctx_priv->sws,
 
... ... STATIC void worker(struct thdsws_ctx_t *ctx,
58 76 &ctx_priv->mutex); &ctx_priv->mutex);
59 77 /* on exit the mutex is locked */ /* on exit the mutex is locked */
60 78 if (r != 0) if (r != 0)
61 FATALTSW("an error occured while waiting for a frame\n");
79 fatalw("an error occured while waiting for a frame\n");
62 80 if (ctx_priv->state != IDLE) if (ctx_priv->state != IDLE)
63 81 break; break;
64 82 /* state == IDLE */ /* state == IDLE */
 
... ... STATIC void *worker_entry(void *arg)
75 93
76 94 r = sigfillset(&sset); r = sigfillset(&sset);
77 95 if (r == -1) if (r == -1)
78 FATALTSW("unable to get a full signal mask\n");
96 fatalw("unable to get a full signal mask\n");
79 97
80 98 r = pthread_sigmask(SIG_SETMASK, &sset, 0); r = pthread_sigmask(SIG_SETMASK, &sset, 0);
81 99 if (r != 0) if (r != 0)
82 FATALTSW("unable to \"block\" \"all\" signals\n");
100 fatalw("unable to \"block\" \"all\" signals\n");
83 101
84 102 ctx = arg; ctx = arg;
85 103 ctx_priv = ctx->private; ctx_priv = ctx->private;
File npv/thdsws/main.c changed (mode: 100644) (index b9b1c00..fee6e13)
5 5 * copyright (C) 2020 Sylvain BERTRAND * copyright (C) 2020 Sylvain BERTRAND
6 6 */ */
7 7 #include <stdlib.h> #include <stdlib.h>
8 #include <stdarg.h>
8 9 #include <signal.h> #include <signal.h>
9 10 #include <pthread.h> #include <pthread.h>
10 11 #include <errno.h> #include <errno.h>
 
13 14 #include <time.h> #include <time.h>
14 15 #include "npv/c_fixing.h" #include "npv/c_fixing.h"
15 16 #include "npv/global.h" #include "npv/global.h"
17 #include "npv/public.h"
16 18 #include "npv/thdsws/public.h" #include "npv/thdsws/public.h"
17 19 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
18 20 #include "npv/namespace/ffmpeg.h" #include "npv/namespace/ffmpeg.h"
19 21 #include "npv/thdsws/namespace/public.h" #include "npv/thdsws/namespace/public.h"
20 22 #include "npv/thdsws/namespace/main.c" #include "npv/thdsws/namespace/main.c"
21 23 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
22 #define FATALTS(fmt, ...) FATAL("scaler:" fmt, ##__VA_ARGS__)
23 #define FATALTSW(fmt, ...) FATAL("scaler worker:" fmt, ##__VA_ARGS__)
24 /*----------------------------------------------------------------------------*/
25 24 #include "npv/thdsws/local/code.frag.c" #include "npv/thdsws/local/code.frag.c"
26 25 #include "npv/thdsws/public/code.frag.c" #include "npv/thdsws/public/code.frag.c"
27 26 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
28 #undef FATALTS
29 #undef FATALTSW
30 /*----------------------------------------------------------------------------*/
31 27 #define CLEANUP #define CLEANUP
32 28 #include "npv/namespace/ffmpeg.h" #include "npv/namespace/ffmpeg.h"
33 29 #include "npv/thdsws/namespace/public.h" #include "npv/thdsws/namespace/public.h"
File npv/thdsws/namespace/main.c changed (mode: 100644) (index 6bc4dbc..f1a9355)
1 1 #ifndef CLEANUP #ifndef CLEANUP
2 #define fatal npv_thdsws_fatal
3 #define fatalw npv_thdsws_fatalw
2 4 #define worker_entry npv_thdsws_worker_entry #define worker_entry npv_thdsws_worker_entry
3 5 #define worker npv_thdsws_worker #define worker npv_thdsws_worker
4 6 #define do_work npv_thdsws_do_work #define do_work npv_thdsws_do_work
5 7 #define state_lock npv_thdsws_state_lock #define state_lock npv_thdsws_state_lock
6 8 #define state_unlock npv_thdsws_state_unlock #define state_unlock npv_thdsws_state_unlock
7 9 #else #else
10 #undef fatal
11 #undef fatalw
8 12 #undef worker_entry #undef worker_entry
9 13 #undef worker #undef worker
10 14 #undef do_work #undef do_work
File npv/thdsws/public/code.frag.c changed (mode: 100644) (index f993791..d8ca6b2)
... ... STATIC void thdsws_run(struct thdsws_ctx_t *ctx)
8 8
9 9 state_lock(ctx_priv); state_lock(ctx_priv);
10 10 if (ctx_priv->state == RUNNING) if (ctx_priv->state == RUNNING)
11 FATALTS("the worker thread is already running, did you forget to wait for it to idle\n");
11 fatal("the worker thread is already running, did you forget to wait for it to idle\n");
12 12 ctx_priv->state = RUNNING; ctx_priv->state = RUNNING;
13 13 state_unlock(ctx_priv); state_unlock(ctx_priv);
14 14 r = pthread_cond_signal(&ctx_priv->have_fr_to_scale); r = pthread_cond_signal(&ctx_priv->have_fr_to_scale);
15 15 if (r != 0) if (r != 0)
16 FATALTS("unable to signal the worker thread a frame is to be scaled\n");
16 fatal("unable to signal the worker thread a frame is to be scaled\n");
17 17 } }
18 18 #undef RUNNING #undef RUNNING
19 19 #define RUNNING 1 #define RUNNING 1
 
... ... STATIC struct thdsws_ctx_t *thdsws_init_once(void)
43 43
44 44 ctx = calloc(1, sizeof(*ctx)); ctx = calloc(1, sizeof(*ctx));
45 45 if (ctx == 0) if (ctx == 0)
46 FATALTS("unable to allocate memory for context\n");
46 fatal("unable to allocate memory for context\n");
47 47 ctx_priv = calloc(1, sizeof(*ctx_priv)); ctx_priv = calloc(1, sizeof(*ctx_priv));
48 48 if (ctx_priv == 0) if (ctx_priv == 0)
49 FATALTS("unable to allocate memory for private context\n");
49 fatal("unable to allocate memory for private context\n");
50 50 ctx->private = ctx_priv; ctx->private = ctx_priv;
51 51
52 52 r = pthread_mutex_init(&ctx_priv->mutex, 0); r = pthread_mutex_init(&ctx_priv->mutex, 0);
53 53 if (r != 0) if (r != 0)
54 FATALTS("unable to create the state mutex\n");
54 fatal("unable to create the state mutex\n");
55 55 r = pthread_cond_init(&ctx_priv->have_fr_to_scale, 0); r = pthread_cond_init(&ctx_priv->have_fr_to_scale, 0);
56 56 if (r != 0) if (r != 0)
57 FATALTS("unable to create waiting condition\n");
57 fatal("unable to create waiting condition\n");
58 58
59 59 r = pthread_attr_init(&attr); r = pthread_attr_init(&attr);
60 60 if (r != 0) if (r != 0)
61 FATALTS("unable to initialize a worker thread attribute\n");
61 fatal("unable to initialize a worker thread attribute\n");
62 62
63 63 r = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); r = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
64 64 if (r != 0) if (r != 0)
65 FATALTS("unable to set the worker thread attribute to detach mode\n");
65 fatal("unable to set the worker thread attribute to detach mode\n");
66 66
67 67 /* be really sure the entry state is correct _before_ thd creation */ /* be really sure the entry state is correct _before_ thd creation */
68 68 ctx_priv->state = IDLE; ctx_priv->state = IDLE;
69 69 r = pthread_create(&worker, &attr, &worker_entry, ctx); r = pthread_create(&worker, &attr, &worker_entry, ctx);
70 70 if (r != 0) if (r != 0)
71 FATALTS("unable to create the worker thread\n");
71 fatal("unable to create the worker thread\n");
72 72 pthread_attr_destroy(&attr); pthread_attr_destroy(&attr);
73 73 return ctx; return ctx;
74 74 } }
 
... ... STATIC void thdsws_wait_for_idle(struct thdsws_ctx_t *ctx)
101 101 memcpy(&ts, &rem, sizeof(ts)); memcpy(&ts, &rem, sizeof(ts));
102 102 continue; continue;
103 103 } }
104 FATALTS("unable to sleep to wait for idle\n");
104 fatal("unable to sleep to wait for idle\n");
105 105 } }
106 106 ++nanoloops_n; ++nanoloops_n;
107 107 if (nanoloops_n == TIMEOUT_UNITS_N) if (nanoloops_n == TIMEOUT_UNITS_N)
108 FATALTS("wait for idle timeout\n");
108 fatal("wait for idle timeout\n");
109 109 } }
110 110 } }
111 111 #undef TIME_UNIT_NS #undef TIME_UNIT_NS
File npv/video/local/code.frag.c changed (mode: 100644) (index 8115561..0ccccd2)
1 STATIC void fatal(u8 *fmt, ...)
2 {
3 va_list ap;
4
5 npv_perr("video:");
6 va_start(ap, fmt);
7 npv_vfatal(fmt, ap);
8 va_end(ap); /* unreachable */
9 }
10 STATIC void warning(u8 *fmt, ...)
11 {
12 va_list ap;
13
14 npv_perr("video:");
15 va_start(ap, fmt);
16 npv_vwarning(fmt, ap);
17 va_end(ap);
18 }
19 STATIC void fatalff(u8 *fmt, ...)
20 {
21 va_list ap;
22
23 npv_perr("ffmpeg:");
24 va_start(ap, fmt);
25 npv_vfatal(fmt, ap);
26 va_end(ap); /* unreachable */
27 }
28 STATIC void poutff(u8 *fmt, ...)
29 {
30 va_list ap;
31
32 npv_pout("ffmpeg:");
33 va_start(ap, fmt);
34 npv_vpout(fmt, ap);
35 va_end(ap);
36 }
37 STATIC void fatalvk(u8 *fmt, ...)
38 {
39 va_list ap;
40
41 npv_perr("video:");
42 va_start(ap, fmt);
43 npv_vk_vfatal(fmt, ap);
44 va_end(ap); /* unreachable */
45 }
46 STATIC void warningvk(u8 *fmt, ...)
47 {
48 va_list ap;
49
50 npv_perr("video:");
51 va_start(ap, fmt);
52 npv_vk_vwarning(fmt, ap);
53 va_end(ap);
54 }
1 55 STATIC void init_once_local(void) STATIC void init_once_local(void)
2 56 { {
3 57 u8 i; u8 i;
 
... ... STATIC bool try_alloc_scaler_img_dev_mem(struct vk_mem_rqmts_t *img_rqmts,
154 208 info.mem_type_idx = mem_type_idx; info.mem_type_idx = mem_type_idx;
155 209 vk_alloc_mem(&info, &scaler_p.img.dev_mem); vk_alloc_mem(&info, &scaler_p.img.dev_mem);
156 210 if (r < 0) { if (r < 0) {
157 WARNINGVVK("%d:device:%p:unable to allocate %lu bytes from physical dev %p memory type %u\n", r, npv_vk_surf_p.dev.vk, img_rqmts->core.sz, npv_vk_surf_p.dev.phydev.vk, mem_type_idx);
211 warningvk("%d:device:%p:unable to allocate %lu bytes from physical dev %p memory type %u\n", r, npv_vk_surf_p.dev.vk, img_rqmts->core.sz, npv_vk_surf_p.dev.phydev.vk, mem_type_idx);
158 212 return false; return false;
159 213 } }
160 //POUTVVK("device:%p:physical device:%p:scaler queue image:%u:%lu bytes allocated from memory type %u\n", npv_vk_surf_p.dev.vk, npv_vk_surf_p.dev.phydev.vk, i, img_rqmts->core.sz, mem_type_idx);
161 214 return true; return true;
162 215 } }
163 216 /* /*
 
... ... STATIC void scaler_img_dev_mem_alloc(void)
183 236 ++mem_type; ++mem_type;
184 237 } }
185 238 if (!npv_vk_surf_p.dev.phydev.is_discret_gpu) if (!npv_vk_surf_p.dev.phydev.is_discret_gpu)
186 FATALVVK("physical device:%p:scaler image:unable to find proper memory type or to allocate memory\n", npv_vk_surf_p.dev.phydev.vk);
239 fatalvk("physical device:%p:scaler image:unable to find proper memory type or to allocate memory\n", npv_vk_surf_p.dev.phydev.vk);
187 240 /* /*
188 241 * lookup again, but relax the match based on discret gpu constraint for * lookup again, but relax the match based on discret gpu constraint for
189 242 * gpu * gpu
 
... ... STATIC void scaler_img_dev_mem_alloc(void)
197 250 return; return;
198 251 ++mem_type; ++mem_type;
199 252 } }
200 FATALVVK("physical device:%p:unable to find proper memory type or to allocate memory\n", npv_vk_surf_p.dev.phydev.vk);
253 fatalvk("physical device:%p:unable to find proper memory type or to allocate memory\n", npv_vk_surf_p.dev.phydev.vk);
201 254 } }
202 255 #undef IGNORE_GPU_IS_DISCRET #undef IGNORE_GPU_IS_DISCRET
203 256 STATIC void scaler_img_dev_mem_bind(void) STATIC void scaler_img_dev_mem_bind(void)
 
... ... STATIC void dec_a_grow(void)
231 284 dec_frs_p.a = realloc(dec_frs_p.a, sizeof(*dec_frs_p.a) dec_frs_p.a = realloc(dec_frs_p.a, sizeof(*dec_frs_p.a)
232 285 * (dec_frs_p.n_max + 1)); * (dec_frs_p.n_max + 1));
233 286 if (dec_frs_p.a == 0) if (dec_frs_p.a == 0)
234 FATALV("unable to allocate memory for an additional pointer on a decoded frame reference\n");
287 fatal("unable to allocate memory for an additional pointer on a decoded frame reference\n");
235 288 dec_frs_p.priv_a = realloc(dec_frs_p.priv_a, dec_frs_p.priv_a = realloc(dec_frs_p.priv_a,
236 289 sizeof(*dec_frs_p.priv_a) * (dec_frs_p.n_max + 1)); sizeof(*dec_frs_p.priv_a) * (dec_frs_p.n_max + 1));
237 290 if (dec_frs_p.priv_a == 0) if (dec_frs_p.priv_a == 0)
238 FATALV("unable to allocate memory for an additional pointer on private data for decoded frames\n");
291 fatal("unable to allocate memory for an additional pointer on private data for decoded frames\n");
239 292
240 293 dec_frs_p.a[new_idx] = avutil_video_fr_ref_alloc(); dec_frs_p.a[new_idx] = avutil_video_fr_ref_alloc();
241 294 if (dec_frs_p.a[new_idx] == 0) if (dec_frs_p.a[new_idx] == 0)
242 FATALV("ffmpeg:unable to allocate a decoded frame reference\n");
295 fatal("ffmpeg:unable to allocate a decoded frame reference\n");
243 296 dec_frs_p.priv_a[new_idx] = calloc(1, sizeof(**dec_frs_p.priv_a)); dec_frs_p.priv_a[new_idx] = calloc(1, sizeof(**dec_frs_p.priv_a));
244 297 if (dec_frs_p.priv_a[new_idx] == 0) if (dec_frs_p.priv_a[new_idx] == 0)
245 FATALV("unable to allocate decoded frame private data\n");
298 fatal("unable to allocate decoded frame private data\n");
246 299
247 300 ++dec_frs_p.n_max; ++dec_frs_p.n_max;
248 301 } }
 
... ... STATIC void fr_drop(u16 fr)
255 308
256 309 priv_save = dec_frs_p.priv_a[fr]; priv_save = dec_frs_p.priv_a[fr];
257 310 if (!priv_save->was_qed_to_pe) if (!priv_save->was_qed_to_pe)
258 WARNINGV("dropping undisplayed frame\n");
311 warning("dropping undisplayed frame\n");
259 312 save = dec_frs_p.a[fr]; save = dec_frs_p.a[fr];
260 313 avutil_video_fr_unref(save); avutil_video_fr_unref(save);
261 314 memset(priv_save, 0, sizeof(*priv_save)); memset(priv_save, 0, sizeof(*priv_save));
 
... ... STATIC u8 swpchn_next_img(u32 *swpchn_img) { loop
494 547 continue; continue;
495 548 } else if (r >= 0) } else if (r >= 0)
496 549 return READY; return READY;
497 FATALVK("%d:device:%p:unable to acquire next image from swapchain %p\n", r, npv_vk_surf_p.dev.vk, npv_vk_surf_p.dev.swpchn.vk);
550 npv_vk_fatal("%d:device:%p:unable to acquire next image from swapchain %p\n", r, npv_vk_surf_p.dev.vk, npv_vk_surf_p.dev.swpchn.vk);
498 551 }} }}
499 552 #undef READY #undef READY
500 553 #undef NOT_READY #undef NOT_READY
 
... ... STATIC void timer_ack(void)
584 637 exps_n = 0; exps_n = 0;
585 638 r = read(timer_fd_p, &exps_n, sizeof(exps_n)); r = read(timer_fd_p, &exps_n, sizeof(exps_n));
586 639 if (r == -1) if (r == -1)
587 FATALV("unable to read the number of timer expirations\n");
640 fatal("unable to read the number of timer expirations\n");
588 641 } }
File npv/video/main.c changed (mode: 100644) (index 6ed4966..e538da2)
5 5 * copyright (C) 2020 Sylvain BERTRAND * copyright (C) 2020 Sylvain BERTRAND
6 6 */ */
7 7 #include <stdbool.h> #include <stdbool.h>
8 #include <stdarg.h>
8 9 #include <stdint.h> #include <stdint.h>
9 10 #include <unistd.h> #include <unistd.h>
10 11 #include <stdlib.h> #include <stdlib.h>
 
33 34 #include "npv/video/namespace/public.h" #include "npv/video/namespace/public.h"
34 35 #include "npv/video/namespace/main.c" #include "npv/video/namespace/main.c"
35 36 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
36 #define FATALV(fmt, ...) FATAL("video:" fmt, ##__VA_ARGS__)
37 #define WARNINGV(fmt, ...) WARNING("video:" fmt, ##__VA_ARGS__)
38 #define POUTV(fmt, ...) POUT("video:" fmt, ##__VA_ARGS__)
39
40 #define FATALVFF(fmt, ...) FATALV("ffmpeg:" fmt, ##__VA_ARGS__)
41 #define WARNINGVFF(fmt, ...) WARNINGV("ffmpeg:" fmt, ##__VA_ARGS__)
42 #define POUTVFF(fmt, ...) POUTV("ffmpeg:" fmt, ##__VA_ARGS__)
43
44 #define FATALVVK(fmt, ...) FATALVK("video:" fmt, ##__VA_ARGS__)
45 #define POUTVVK(fmt, ...) POUTVK("video:" fmt, ##__VA_ARGS__)
46 #define WARNINGVVK(fmt, ...) WARNINGVK("video:" fmt, ##__VA_ARGS__)
47 #define IF_FATALVVK(fmt, ...) IF_FATALVK("video:" fmt, ##__VA_ARGS__)
37 #define IF_FATALVVK(...) IF_FATALVK("video:" __VA_ARGS__)
48 38 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
49 39 #include "npv/video/local/state.frag.c" #include "npv/video/local/state.frag.c"
50 40 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
51 41 #include "npv/video/local/code.frag.c" #include "npv/video/local/code.frag.c"
52 42 #include "npv/video/public/code.frag.c" #include "npv/video/public/code.frag.c"
53 43 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
54 #undef FATALV
55 #undef WARNINGV
56 #undef POUTV
57 #undef FATALVFF
58 #undef WARNINGVFF
59 #undef POUTVFF
60 #undef FATALVVK
61 #undef POUTVVK
62 #undef WARNINGVVK
63 44 #undef IF_FATALVVK #undef IF_FATALVVK
64 45 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
65 46 #define CLEANUP #define CLEANUP
File npv/video/namespace/main.c changed (mode: 100644) (index dd118e0..7844aa7)
11 11 #define dec_a_grow npv_video_dec_a_grow #define dec_a_grow npv_video_dec_a_grow
12 12 #define dec_ctx_mutex_l npv_video_dec_ctx_mutex_l #define dec_ctx_mutex_l npv_video_dec_ctx_mutex_l
13 13 #define dec_l npv_video_dec_l #define dec_l npv_video_dec_l
14 #define fatal npv_video_fatal
15 #define fatalff npv_video_fatalff
16 #define fatalvk npv_video_fatalvk
14 17 #define fr_drop npv_video_fr_drop #define fr_drop npv_video_fr_drop
15 18 #define frs_drop npv_video_frs_drop #define frs_drop npv_video_frs_drop
16 19 #define frs_clear_last_qed_to_pe npv_video_frs_clear_last_qed_to_pe #define frs_clear_last_qed_to_pe npv_video_frs_clear_last_qed_to_pe
 
20 23 #define init_once_public npv_video_init_once_public #define init_once_public npv_video_init_once_public
21 24 #define last_fr_sent_to_pe_l npv_video_last_fr_sent_to_pe_l #define last_fr_sent_to_pe_l npv_video_last_fr_sent_to_pe_l
22 25 #define match_mem_type npv_video_match_mem_type #define match_mem_type npv_video_match_mem_type
26 #define poutff npv_video_poutff
23 27 #define receive_fr_l npv_video_receive_fr_l #define receive_fr_l npv_video_receive_fr_l
24 28 #define scaler_img_create npv_video_scaler_img_create #define scaler_img_create npv_video_scaler_img_create
25 29 #define scaler_img_destroy npv_video_scaler_img_destroy #define scaler_img_destroy npv_video_scaler_img_destroy
 
36 40 #define tmp_mem_rqmts_l npv_video_tmp_mem_rqmts_l #define tmp_mem_rqmts_l npv_video_tmp_mem_rqmts_l
37 41 #define tmp_scaler_img_mem_rqmts_get npv_video_tmp_scaler_img_mem_rqmts_get #define tmp_scaler_img_mem_rqmts_get npv_video_tmp_scaler_img_mem_rqmts_get
38 42 #define try_alloc_scaler_img_dev_mem npv_video_try_alloc_scaler_img_dev_mem #define try_alloc_scaler_img_dev_mem npv_video_try_alloc_scaler_img_dev_mem
43 #define warning npv_video_warning
44 #define warningvk npv_video_warningvk
39 45 /*============================================================================*/ /*============================================================================*/
40 46 #else #else
41 47 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
 
50 56 #undef dec_a_grow #undef dec_a_grow
51 57 #undef dec_ctx_mutex_l #undef dec_ctx_mutex_l
52 58 #undef dec_l #undef dec_l
59 #undef fatal
60 #undef fatalff
61 #undef fatalvk
53 62 #undef fr_drop #undef fr_drop
54 63 #undef frs_clear_last_qed_to_pe #undef frs_clear_last_qed_to_pe
55 64 #undef frs_drop #undef frs_drop
 
59 68 #undef init_once_public #undef init_once_public
60 69 #undef last_fr_sent_to_pe_l #undef last_fr_sent_to_pe_l
61 70 #undef match_mem_type #undef match_mem_type
71 #undef poutff
62 72 #undef receive_fr_l #undef receive_fr_l
63 73 #undef scaler_img_create #undef scaler_img_create
64 74 #undef scaler_img_destroy #undef scaler_img_destroy
 
75 85 #undef tmp_mem_rqmts_l #undef tmp_mem_rqmts_l
76 86 #undef tmp_scaler_img_mem_rqmts_get #undef tmp_scaler_img_mem_rqmts_get
77 87 #undef try_alloc_scaler_img_dev_mem #undef try_alloc_scaler_img_dev_mem
88 #undef warning
89 #undef warningvk
78 90 #endif #endif
File npv/video/public/code.frag.c changed (mode: 100644) (index 0087c16..b2604be)
... ... STATIC void init_once_public(void)
7 7 errno = 0; errno = 0;
8 8 timer_fd_p = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK); timer_fd_p = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK);
9 9 if (timer_fd_p == -1) if (timer_fd_p == -1)
10 FATALV("unable to get a timer file descriptor:%s\n", strerror(errno));
10 fatal("unable to get a timer file descriptor:%s\n", strerror(errno));
11 11 memset(&st_p, 0, sizeof(st_p)); memset(&st_p, 0, sizeof(st_p));
12 12 pkt_q_p = npv_pkt_q_new("video"); pkt_q_p = npv_pkt_q_new("video");
13 13 dec_ctx_p = 0; dec_ctx_p = 0;
14 14 r = pthread_mutex_init(&dec_ctx_mutex_l, 0); r = pthread_mutex_init(&dec_ctx_mutex_l, 0);
15 15 if (r != 0) if (r != 0)
16 FATALV("unable to create the mutex for the decoder context\n");
16 fatal("unable to create the mutex for the decoder context\n");
17 17
18 18 dec_frs_p.eof_receive = false; dec_frs_p.eof_receive = false;
19 19 dec_frs_p.n_max = 0; dec_frs_p.n_max = 0;
 
... ... STATIC void init_once_public(void)
22 22 dec_frs_p.priv_a = 0; dec_frs_p.priv_a = 0;
23 23 r = pthread_mutex_init(&dec_frs_p.mutex, 0); r = pthread_mutex_init(&dec_frs_p.mutex, 0);
24 24 if (r != 0) if (r != 0)
25 FATALV("unable to create the mutex for the array of frames\n");
25 fatal("unable to create the mutex for the array of frames\n");
26 26
27 27 scaler_p.img.vk = 0; scaler_p.img.vk = 0;
28 28 memset(&scaler_p.img.layout, 0, sizeof(scaler_p.img.layout)); memset(&scaler_p.img.layout, 0, sizeof(scaler_p.img.layout));
 
... ... STATIC void init_once_public(void)
38 38 /* we are targetting AVUTIL_PIX_FMT_RGB32/sRGB */ /* we are targetting AVUTIL_PIX_FMT_RGB32/sRGB */
39 39 scaler_p.ctx = npv_thdsws_init_once(); scaler_p.ctx = npv_thdsws_init_once();
40 40 if (scaler_p.ctx == 0) if (scaler_p.ctx == 0)
41 FATALVFF("scaler:unable to initialize\n");
41 fatalff("scaler:unable to initialize\n");
42 42 } }
43 43 #undef NO_FR #undef NO_FR
44 44 STATIC void init_once(void) STATIC void init_once(void)
 
... ... STATIC void dec_ctx_cfg(avcodec_params_t *params)
52 52
53 53 dec_l = avcodec_find_dec(params->codec_id); dec_l = avcodec_find_dec(params->codec_id);
54 54 if (dec_l == 0) if (dec_l == 0)
55 FATALVFF("unable to find a proper decoder\n");
55 fatalff("unable to find a proper decoder\n");
56 56 avcodec_free_context(&dec_ctx_p); avcodec_free_context(&dec_ctx_p);
57 57 dec_ctx_p = avcodec_alloc_ctx(dec_l); dec_ctx_p = avcodec_alloc_ctx(dec_l);
58 58 if (dec_ctx_p == 0) if (dec_ctx_p == 0)
59 FATALVFF("unable to allocate an decoder context\n");
59 fatalff("unable to allocate an decoder context\n");
60 60 /* XXX: useless ? */ /* XXX: useless ? */
61 61 r = avcodec_params_to_ctx(dec_ctx_p, params); r = avcodec_params_to_ctx(dec_ctx_p, params);
62 62 if (r < 0) if (r < 0)
63 FATALVFF("unable to apply stream codec parameters in codec context\n");
63 fatalff("unable to apply stream codec parameters in codec context\n");
64 64 /* XXX: ffmpeg thread count default is 1, set to 0 = auto */ /* XXX: ffmpeg thread count default is 1, set to 0 = auto */
65 65 dec_ctx_p->thread_count = 0; dec_ctx_p->thread_count = 0;
66 66 r = avcodec_open2(dec_ctx_p, dec_l, 0); r = avcodec_open2(dec_ctx_p, dec_l, 0);
67 67 if (r < 0) if (r < 0)
68 FATALVFF("unable to open the decoder context\n");
68 fatalff("unable to open the decoder context\n");
69 69
70 70 /* we will define the video aspect ratio with those values */ /* we will define the video aspect ratio with those values */
71 71 aspect_ratio.width = params->width; aspect_ratio.width = params->width;
 
... ... STATIC void timer_start(void)
82 82 t.it_interval.tv_nsec = 2000000; /* 2ms */ t.it_interval.tv_nsec = 2000000; /* 2ms */
83 83 r = timerfd_settime(timer_fd_p, 0, &t, 0); r = timerfd_settime(timer_fd_p, 0, &t, 0);
84 84 if (r == -1) if (r == -1)
85 FATALV("unable to arm the timer\n");
85 fatal("unable to arm the timer\n");
86 86 } }
87 87 STATIC void timer_slow_start(void) STATIC void timer_slow_start(void)
88 88 { {
 
... ... STATIC void timer_slow_start(void)
95 95 t.it_interval.tv_nsec = 100000000; /* 100ms */ t.it_interval.tv_nsec = 100000000; /* 100ms */
96 96 r = timerfd_settime(timer_fd_p, 0, &t, 0); r = timerfd_settime(timer_fd_p, 0, &t, 0);
97 97 if (r == -1) if (r == -1)
98 FATALV("unable to arm the timer\n");
98 fatal("unable to arm the timer\n");
99 99 } }
100 100 #define AGAIN 0 #define AGAIN 0
101 101 #define HAVE_FR 1 #define HAVE_FR 1
 
... ... STATIC u8 dec_fr_try_receive(void)
122 122 dec_frs_unlock(); dec_frs_unlock();
123 123 return HAVE_FR; return HAVE_FR;
124 124 } else if (r == AVUTIL_AVERROR_EOF) { } else if (r == AVUTIL_AVERROR_EOF) {
125 POUTVFF("last decoder frame reached (receiving)\n");
125 poutff("last decoder frame reached (receiving)\n");
126 126 dec_frs_lock(); dec_frs_lock();
127 127 dec_frs_p.eof_receive = true; dec_frs_p.eof_receive = true;
128 128 dec_frs_unlock(); dec_frs_unlock();
129 129 return EOF_DEC; return EOF_DEC;
130 130 } }
131 FATALVFF("error while receiving frame from the decoder\n");
131 fatalff("error while receiving frame from the decoder\n");
132 132 } }
133 133 #undef AGAIN #undef AGAIN
134 134 #undef HAVE_FR #undef HAVE_FR
 
... ... STATIC void dec_ctx_lock(void)
165 165
166 166 r = pthread_mutex_lock(&dec_ctx_mutex_l); r = pthread_mutex_lock(&dec_ctx_mutex_l);
167 167 if (r != 0) if (r != 0)
168 FATALV("%d:unable to lock the video decoder context\n", r);
168 fatal("%d:unable to lock the video decoder context\n", r);
169 169 } }
170 170 STATIC void dec_ctx_unlock(void) STATIC void dec_ctx_unlock(void)
171 171 { {
 
... ... STATIC void dec_ctx_unlock(void)
173 173
174 174 r = pthread_mutex_unlock(&dec_ctx_mutex_l); r = pthread_mutex_unlock(&dec_ctx_mutex_l);
175 175 if (r != 0) if (r != 0)
176 FATALV("%d:unable to unlock the video decoder context\n", r);
176 fatal("%d:unable to unlock the video decoder context\n", r);
177 177 } }
178 178 STATIC void dec_frs_lock(void) STATIC void dec_frs_lock(void)
179 179 { {
 
... ... STATIC void dec_frs_lock(void)
181 181
182 182 r = pthread_mutex_lock(&dec_frs_p.mutex); r = pthread_mutex_lock(&dec_frs_p.mutex);
183 183 if (r != 0) if (r != 0)
184 FATALV("%d:unable to lock the array of decoder frames\n", r);
184 fatal("%d:unable to lock the array of decoder frames\n", r);
185 185 } }
186 186 STATIC void dec_frs_unlock(void) STATIC void dec_frs_unlock(void)
187 187 { {
 
... ... STATIC void dec_frs_unlock(void)
189 189
190 190 r = pthread_mutex_unlock(&dec_frs_p.mutex); r = pthread_mutex_unlock(&dec_frs_p.mutex);
191 191 if (r != 0) if (r != 0)
192 FATALV("%d:unable to unlock the array of decoder frames\n", r);
192 fatal("%d:unable to unlock the array of decoder frames\n", r);
193 193 } }
194 194 /* go non-blocking or a worker thread is needed */ /* go non-blocking or a worker thread is needed */
195 195 #define NO_FR 0 #define NO_FR 0
 
... ... STATIC void pkts_send(void) { loop
269 269 else if (r == AVUTIL_AVERROR_EOF) /* the dec is in draining mode */ else if (r == AVUTIL_AVERROR_EOF) /* the dec is in draining mode */
270 270 goto unlock_and_return; goto unlock_and_return;
271 271 else if (r != 0) else if (r != 0)
272 FATALV("error while sending a packet to the decoder\n");
272 fatal("error while sending a packet to the decoder\n");
273 273 /* r == 0 */ /* r == 0 */
274 274 npv_pipeline_limits_lock(); npv_pipeline_limits_lock();
275 275 npv_pipeline_limits_p.pkts.video_bytes_n -= pr->sz; npv_pipeline_limits_p.pkts.video_bytes_n -= pr->sz;
File npv/vk/api_usage.h changed (mode: 100644) (index 3668ad1..8ee52a2)
8 8 * this is the simplification and taylorization of vk api for the specific * this is the simplification and taylorization of vk api for the specific
9 9 * uses of npv * uses of npv
10 10 */ */
11 #define FATALVK(fmt, ...) FATAL("vulkan:" fmt, ##__VA_ARGS__)
12 #define WARNINGVK(fmt, ...) WARNING("vulkan:" fmt, ##__VA_ARGS__)
13 #define POUTVK(fmt, ...) POUT("vulkan:" fmt, ##__VA_ARGS__)
14
15 11 #define IF_FATALVK(fmt, ...) \ #define IF_FATALVK(fmt, ...) \
16 12 if (r < 0) \ if (r < 0) \
17 FATALVK(fmt, ##__VA_ARGS__)
13 npv_vk_fatal(fmt, __VA_ARGS__)
18 14 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
19 15 #define vk_get_dev_q() \ #define vk_get_dev_q() \
20 16 npv_vk_surf_p.dev.dl_vk_get_dev_q(npv_vk_surf_p.dev.vk, npv_vk_surf_p.dev.phydev.q_fam, 0, &npv_vk_surf_p.dev.q) npv_vk_surf_p.dev.dl_vk_get_dev_q(npv_vk_surf_p.dev.vk, npv_vk_surf_p.dev.phydev.q_fam, 0, &npv_vk_surf_p.dev.q)
 
... ... r = npv_vk_surf_p.dev.dl_vk_q_submit(npv_vk_surf_p.dev.q, 1, info, 0)
74 70 r = npv_vk_surf_p.dev.dl_vk_q_wait_idle(npv_vk_surf_p.dev.q) r = npv_vk_surf_p.dev.dl_vk_q_wait_idle(npv_vk_surf_p.dev.q)
75 71
76 72 #define vk_get_img_subrsrc_layout(...) \ #define vk_get_img_subrsrc_layout(...) \
77 npv_vk_surf_p.dev.dl_vk_get_img_subrsrc_layout(npv_vk_surf_p.dev.vk, ##__VA_ARGS__)
73 npv_vk_surf_p.dev.dl_vk_get_img_subrsrc_layout(npv_vk_surf_p.dev.vk, __VA_ARGS__)
78 74
79 75 #define vk_acquire_next_img(...) \ #define vk_acquire_next_img(...) \
80 r = npv_vk_surf_p.dev.dl_vk_acquire_next_img(npv_vk_surf_p.dev.vk,##__VA_ARGS__)
76 r = npv_vk_surf_p.dev.dl_vk_acquire_next_img(npv_vk_surf_p.dev.vk, __VA_ARGS__)
81 77
82 78 #define vk_reset_cb(cb) \ #define vk_reset_cb(cb) \
83 79 r = npv_vk_surf_p.dev.dl_vk_reset_cb(cb, 0) r = npv_vk_surf_p.dev.dl_vk_reset_cb(cb, 0)
 
... ... r = npv_dl_vk_enumerate_instance_version
179 175 r = npv_dl_vk_enumerate_instance_layer_props r = npv_dl_vk_enumerate_instance_layer_props
180 176
181 177 #define vk_enumerate_instance_ext_props(...) \ #define vk_enumerate_instance_ext_props(...) \
182 r = npv_dl_vk_enumerate_instance_ext_props(0,##__VA_ARGS__)
178 r = npv_dl_vk_enumerate_instance_ext_props(0, __VA_ARGS__)
183 179
184 180 #define vk_create_instance(info) \ #define vk_create_instance(info) \
185 181 r = npv_dl_vk_create_instance(info, 0, &npv_vk_instance_l) r = npv_dl_vk_create_instance(info, 0, &npv_vk_instance_l)
186 182
187 183 #define vk_enumerate_phydevs(...) \ #define vk_enumerate_phydevs(...) \
188 r = npv_dl_vk_enumerate_phydevs(npv_vk_instance_l,##__VA_ARGS__)
184 r = npv_dl_vk_enumerate_phydevs(npv_vk_instance_l, __VA_ARGS__)
189 185
190 186 #define vk_enumerate_dev_ext_props(phydev, props_n, props) \ #define vk_enumerate_dev_ext_props(phydev, props_n, props) \
191 187 r = npv_dl_vk_enumerate_dev_ext_props(phydev, 0, props_n, props) r = npv_dl_vk_enumerate_dev_ext_props(phydev, 0, props_n, props)
 
... ... r = npv_dl_vk_create_xcb_surf(npv_vk_instance_l, info, 0, &npv_vk_surf_p.vk)
203 199 #define vk_get_phydev_surf_support(phydev, q_fam, supported) \ #define vk_get_phydev_surf_support(phydev, q_fam, supported) \
204 200 r = npv_dl_vk_get_phydev_surf_support(phydev, q_fam, npv_vk_surf_p.vk, supported) r = npv_dl_vk_get_phydev_surf_support(phydev, q_fam, npv_vk_surf_p.vk, supported)
205 201
206 #define vk_get_phydev_surf_texel_mem_blk_confs(info, ...) \
207 r = npv_dl_vk_get_phydev_surf_texel_mem_blk_confs(npv_vk_surf_p.dev.phydev.vk, info, ##__VA_ARGS__)
202 #define vk_get_phydev_surf_texel_mem_blk_confs(...) \
203 r = npv_dl_vk_get_phydev_surf_texel_mem_blk_confs(npv_vk_surf_p.dev.phydev.vk, __VA_ARGS__)
208 204
209 205 #define vk_get_phydev_mem_props npv_dl_vk_get_phydev_mem_props #define vk_get_phydev_mem_props npv_dl_vk_get_phydev_mem_props
210 206
File npv/vk/local/code.frag.c changed (mode: 100644) (index 28b0c34..dd5e2ee)
1 STATIC void pout(u8 *fmt, ...)
2 {
3 va_list ap;
4
5 npv_pout("vulkan:");
6 va_start(ap, fmt);
7 npv_vpout(fmt, ap);
8 va_end(ap);
9 }
1 10 #define INSTANCE_STATIC_SYM(x,y) \ #define INSTANCE_STATIC_SYM(x,y) \
2 11 npv_dl_##y = vk_get_instance_proc_addr(0, #x); \ npv_dl_##y = vk_get_instance_proc_addr(0, #x); \
3 12 if (npv_dl_##y == 0) \ if (npv_dl_##y == 0) \
4 FATALVK("unable to find vulkan " #x "\n");
13 fatal("unable to find vulkan " #x "\n");
5 14 STATIC void instance_static_syms(void) STATIC void instance_static_syms(void)
6 15 { {
7 16 INSTANCE_STATIC_SYM(vkEnumerateInstanceVersion, INSTANCE_STATIC_SYM(vkEnumerateInstanceVersion,
 
... ... STATIC void instance_static_syms(void)
17 26 #define INSTANCE_SYM(x,y) \ #define INSTANCE_SYM(x,y) \
18 27 npv_dl_##y = vk_get_instance_proc_addr(instance_l, #x); \ npv_dl_##y = vk_get_instance_proc_addr(instance_l, #x); \
19 28 if (npv_dl_##y == 0) \ if (npv_dl_##y == 0) \
20 FATALVK("unable to find vulkan " #x "\n");
29 fatal("unable to find vulkan " #x "\n");
21 30 STATIC void instance_syms(void) STATIC void instance_syms(void)
22 31 { {
23 32 INSTANCE_SYM(vkEnumeratePhysicalDevices, vk_enumerate_phydevs); INSTANCE_SYM(vkEnumeratePhysicalDevices, vk_enumerate_phydevs);
 
... ... STATIC void instance_syms(void)
46 55 #define DEV_SYM(x,y) \ #define DEV_SYM(x,y) \
47 56 surf_p.dev.dl_##y = vk_get_dev_proc_addr(surf_p.dev.vk, #x); \ surf_p.dev.dl_##y = vk_get_dev_proc_addr(surf_p.dev.vk, #x); \
48 57 if (surf_p.dev.dl_##y == 0) \ if (surf_p.dev.dl_##y == 0) \
49 FATALVK("unable to find vulkan device " #x "\n");
58 fatal("unable to find vulkan device " #x "\n");
50 59 STATIC void dev_syms(void) STATIC void dev_syms(void)
51 60 { {
52 61 DEV_SYM(vkGetDeviceQueue, vk_get_dev_q); DEV_SYM(vkGetDeviceQueue, vk_get_dev_q);
 
... ... STATIC void dev_syms(void)
81 90 #define DLSYM(x, y) \ #define DLSYM(x, y) \
82 91 npv_dl_##y = dlsym(loader_l, #x); \ npv_dl_##y = dlsym(loader_l, #x); \
83 92 if (npv_dl_##y == 0) \ if (npv_dl_##y == 0) \
84 FATALVK("%s:unable to find " #x "\n", dlerror());
93 fatal("%s:unable to find " #x "\n", dlerror());
85 94 STATIC void loader_syms(void) STATIC void loader_syms(void)
86 95 { {
87 96 DLSYM(vkGetInstanceProcAddr, vk_get_instance_proc_addr); DLSYM(vkGetInstanceProcAddr, vk_get_instance_proc_addr);
 
... ... STATIC void load_vk_loader(void)
94 103 /* no '/' in the shared dynamic lib path name, then standard lookup */ /* no '/' in the shared dynamic lib path name, then standard lookup */
95 104 loader_l = dlopen("libvulkan.so.1", RTLD_LAZY); loader_l = dlopen("libvulkan.so.1", RTLD_LAZY);
96 105 if (loader_l == 0) if (loader_l == 0)
97 FATALVK("%s:unable to load the vulkan loader dynamic shared library\n", dlerror());
106 fatal("%s:unable to load the vulkan loader dynamic shared library\n", dlerror());
98 107 } }
99 108 STATIC void check_vk_version(void) STATIC void check_vk_version(void)
100 109 { {
 
... ... STATIC void check_vk_version(void)
103 112
104 113 vk_enumerate_instance_version(&api_version); vk_enumerate_instance_version(&api_version);
105 114 if (r != vk_success) if (r != vk_success)
106 FATALVK("%d:unable to enumerate instance version\n", r);
107 POUTVK("vulkan instance version %#x = %u.%u.%u\n", api_version, VK_VERSION_MAJOR(api_version), VK_VERSION_MINOR(api_version), VK_VERSION_PATCH(api_version));
115 fatal("%d:unable to enumerate instance version\n", r);
116 pout("vulkan instance version %#x = %u.%u.%u\n", api_version, VK_VERSION_MAJOR(api_version), VK_VERSION_MINOR(api_version), VK_VERSION_PATCH(api_version));
108 117 if (VK_VERSION_MAJOR(api_version) == 1 if (VK_VERSION_MAJOR(api_version) == 1
109 118 && VK_VERSION_MINOR(api_version) == 0) && VK_VERSION_MINOR(api_version) == 0)
110 FATALVK("instance version too old\n");
119 fatal("instance version too old\n");
111 120 } }
112 121 #define EXTS_N_MAX 256 #define EXTS_N_MAX 256
113 122 /* in theory, this could change on the fly */ /* in theory, this could change on the fly */
 
... ... STATIC void instance_exts_dump(void)
121 130 n = EXTS_N_MAX; n = EXTS_N_MAX;
122 131 vk_enumerate_instance_ext_props(&n, exts); vk_enumerate_instance_ext_props(&n, exts);
123 132 if (r != vk_success && r != vk_incomplete) { if (r != vk_success && r != vk_incomplete) {
124 WARNINGVK("%d:unable to enumerate instance extension(s)\n", r);
133 warning("%d:unable to enumerate instance extension(s)\n", r);
125 134 return; return;
126 135 } }
127 136 if (r == vk_incomplete) { if (r == vk_incomplete) {
128 WARNINGVK("too many extensions (%u/%u), dumping disabled", n, EXTS_N_MAX);
137 warning("too many extensions (%u/%u), dumping disabled", n, EXTS_N_MAX);
129 138 return; return;
130 139 } }
131 140 /* vk_success */ /* vk_success */
132 POUTVK("have %u instance extension(s)\n", n);
141 pout("have %u instance extension(s)\n", n);
133 142 loop { loop {
134 143 if (n == 0) if (n == 0)
135 144 break; break;
136 POUTVK("instance extension:name=%s:specification version=%u\n", exts[n - 1].name, exts[n - 1].spec_version);
145 pout("instance extension:name=%s:specification version=%u\n", exts[n - 1].name, exts[n - 1].spec_version);
137 146 n--; n--;
138 147 } }
139 148 } }
 
... ... STATIC void instance_layers_dump(void)
150 159 n = LAYERS_N_MAX; n = LAYERS_N_MAX;
151 160 vk_enumerate_instance_layer_props(&n, layers); vk_enumerate_instance_layer_props(&n, layers);
152 161 if (r != vk_success && r != vk_incomplete) { if (r != vk_success && r != vk_incomplete) {
153 WARNINGVK("%d:unable to enumerate instance layer(s)\n", r);
162 warning("%d:unable to enumerate instance layer(s)\n", r);
154 163 return; return;
155 164 } }
156 165 if (r == vk_incomplete) { if (r == vk_incomplete) {
157 WARNINGVK("too many layers (%u/%u), dumping disabled", n, LAYERS_N_MAX);
166 warning("too many layers (%u/%u), dumping disabled", n, LAYERS_N_MAX);
158 167 return; return;
159 168 } }
160 169 /* vk_success */ /* vk_success */
161 POUTVK("have %u instance layer(s)\n", n);
170 pout("have %u instance layer(s)\n", n);
162 171 loop { loop {
163 172 if (n == 0) if (n == 0)
164 173 break; break;
165 POUTVK("instance layer:%u:name=%s:specification version=%u:implementation version=%u:description=%s\n", n, layers[n].name, layers[n].spec_version, layers[n].implementation_version, layers[n].desc);
174 pout("instance layer:%u:name=%s:specification version=%u:implementation version=%u:description=%s\n", n, layers[n].name, layers[n].spec_version, layers[n].implementation_version, layers[n].desc);
166 175 n--; n--;
167 176 } }
168 177 } }
 
... ... STATIC void instance_create(void)
191 200 loop { loop {
192 201 if (i == ARRAY_N(exts)) if (i == ARRAY_N(exts))
193 202 break; break;
194 POUTVK("will use instance extension %s\n", exts[i]);
203 pout("will use instance extension %s\n", exts[i]);
195 204 ++i; ++i;
196 205 } }
197 206 memset(&info, 0, sizeof(info)); memset(&info, 0, sizeof(info));
 
... ... STATIC void instance_create(void)
200 209 info.enabled_ext_names = exts; info.enabled_ext_names = exts;
201 210 vk_create_instance(&info); vk_create_instance(&info);
202 211 IF_FATALVK("%d:unable to create an instance\n", r); IF_FATALVK("%d:unable to create an instance\n", r);
203 POUTVK("instance handle %p\n", instance_l);
212 pout("instance handle %p\n", instance_l);
204 213 } }
205 214 STATIC void tmp_phydevs_get(void) STATIC void tmp_phydevs_get(void)
206 215 { {
 
... ... STATIC void tmp_phydevs_get(void)
212 221 n = tmp_phydevs_n_max; n = tmp_phydevs_n_max;
213 222 vk_enumerate_phydevs(&n, phydevs); vk_enumerate_phydevs(&n, phydevs);
214 223 if (r != vk_success && r != vk_incomplete) if (r != vk_success && r != vk_incomplete)
215 FATALVK("%ld:unable to enumerate physical devices\n", r);
224 fatal("%ld:unable to enumerate physical devices\n", r);
216 225 if (r == vk_incomplete) if (r == vk_incomplete)
217 FATALVK("too many vulkan physical devices %u/%u for our temporary storage\n", n, tmp_phydevs_n_max);
226 fatal("too many vulkan physical devices %u/%u for our temporary storage\n", n, tmp_phydevs_n_max);
218 227 /* vk_success */ /* vk_success */
219 POUTVK("detected %u physical devices\n", n);
228 pout("detected %u physical devices\n", n);
220 229 if (n == 0) if (n == 0)
221 FATALVK("no vulkan physical devices, exiting\n");
230 fatal("no vulkan physical devices, exiting\n");
222 231 tmp_phydevs_n_l = n; tmp_phydevs_n_l = n;
223 232 memset(tmp_phydevs_l, 0, sizeof(tmp_phydevs_l)); memset(tmp_phydevs_l, 0, sizeof(tmp_phydevs_l));
224 233 n = 0; n = 0;
 
... ... STATIC void phydev_exts_dump(void *phydev)
240 249 n = EXTS_N_MAX; n = EXTS_N_MAX;
241 250 vk_enumerate_dev_ext_props(phydev, &n, exts); vk_enumerate_dev_ext_props(phydev, &n, exts);
242 251 if (r != vk_success && r != vk_incomplete) { if (r != vk_success && r != vk_incomplete) {
243 WARNINGVK("physical device:%p:%d:unable to enumerate device extension(s)\n", phydev, r);
252 warning("physical device:%p:%d:unable to enumerate device extension(s)\n", phydev, r);
244 253 return; return;
245 254 } }
246 255 if (r == vk_incomplete) { if (r == vk_incomplete) {
247 WARNINGVK("physical device:%p:too many extensions (%u/%u), dumping disabled", phydev, n, EXTS_N_MAX);
256 warning("physical device:%p:too many extensions (%u/%u), dumping disabled", phydev, n, EXTS_N_MAX);
248 257 return; return;
249 258 } }
250 259 /* vk_success */ /* vk_success */
251 POUTVK("physical device:%p:have %u device extension(s)\n", phydev, n);
260 pout("physical device:%p:have %u device extension(s)\n", phydev, n);
252 261 loop { loop {
253 262 if (n == 0) if (n == 0)
254 263 break; break;
255 POUTVK("physical device:%p:device extension:name=%s:specification version=%u\n", phydev, exts[n - 1].name, exts[n - 1].spec_version);
264 pout("physical device:%p:device extension:name=%s:specification version=%u\n", phydev, exts[n - 1].name, exts[n - 1].spec_version);
256 265 n--; n--;
257 266 } }
258 267 } }
 
... ... STATIC void tmp_phydevs_props_dump(void)
317 326 memset(&props, 0, sizeof(props)); memset(&props, 0, sizeof(props));
318 327 props.type = vk_struct_type_phydev_props; props.type = vk_struct_type_phydev_props;
319 328 vk_get_phydev_props(p->vk, &props); vk_get_phydev_props(p->vk, &props);
320 POUTVK("physical device:%p:properties:api version=%#x=%u.%u.%u\n", p->vk, props.core.api_version, VK_VERSION_MAJOR(props.core.api_version), VK_VERSION_MINOR(props.core.api_version), VK_VERSION_PATCH(props.core.api_version));
321 POUTVK("physical device:%p:properties:driver version=%#x=%u.%u.%u\n", p->vk, props.core.driver_version, VK_VERSION_MAJOR(props.core.driver_version), VK_VERSION_MINOR(props.core.driver_version), VK_VERSION_PATCH(props.core.driver_version));
322 POUTVK("physical device:%p:properties:vendor id=%#x\n", p->vk, props.core.vendor_id);
323 POUTVK("physical device:%p:properties:device id=%#x\n", p->vk, props.core.dev_id);
324 POUTVK("physical device:%p:properties:type=%s\n", p->vk, dev_type_str(props.core.dev_type));
329 pout("physical device:%p:properties:api version=%#x=%u.%u.%u\n", p->vk, props.core.api_version, VK_VERSION_MAJOR(props.core.api_version), VK_VERSION_MINOR(props.core.api_version), VK_VERSION_PATCH(props.core.api_version));
330 pout("physical device:%p:properties:driver version=%#x=%u.%u.%u\n", p->vk, props.core.driver_version, VK_VERSION_MAJOR(props.core.driver_version), VK_VERSION_MINOR(props.core.driver_version), VK_VERSION_PATCH(props.core.driver_version));
331 pout("physical device:%p:properties:vendor id=%#x\n", p->vk, props.core.vendor_id);
332 pout("physical device:%p:properties:device id=%#x\n", p->vk, props.core.dev_id);
333 pout("physical device:%p:properties:type=%s\n", p->vk, dev_type_str(props.core.dev_type));
325 334 if (props.core.dev_type == vk_phydev_type_discrete_gpu) if (props.core.dev_type == vk_phydev_type_discrete_gpu)
326 335 p->is_discret_gpu = true; p->is_discret_gpu = true;
327 336 else else
328 337 p->is_discret_gpu = false; p->is_discret_gpu = false;
329 POUTVK("physical device:%p:properties:name=%s\n", p->vk, props.core.name);
330 POUTVK("physical device:%p:properties:pipeline cache uuid=%s\n", p->vk, uuid_str(props.core.pl_cache_uuid));
338 pout("physical device:%p:properties:name=%s\n", p->vk, props.core.name);
339 pout("physical device:%p:properties:pipeline cache uuid=%s\n", p->vk, uuid_str(props.core.pl_cache_uuid));
331 340 /* disp the limits and sparse props at "higher log lvl", if needed in the end */ /* disp the limits and sparse props at "higher log lvl", if needed in the end */
332 341 ++i; ++i;
333 342 } }
 
... ... STATIC void tmp_phydevs_mem_props_get(void)
353 362 STATIC void phydev_mem_type_dump(void *phydev, u8 i, STATIC void phydev_mem_type_dump(void *phydev, u8 i,
354 363 struct vk_mem_type_t *type) struct vk_mem_type_t *type)
355 364 { {
356 POUTVK("physical device:%p:memory type:%u:heap:%u\n", phydev, i, type->heap);
357 POUTVK("physical device:%p:memory type:%u:flags:%#08x\n", phydev, i, type->prop_flags);
365 pout("physical device:%p:memory type:%u:heap:%u\n", phydev, i, type->heap);
366 pout("physical device:%p:memory type:%u:flags:%#08x\n", phydev, i, type->prop_flags);
358 367 if ((type->prop_flags & vk_mem_prop_dev_local_bit) != 0) if ((type->prop_flags & vk_mem_prop_dev_local_bit) != 0)
359 POUTVK("physical device:%p:memory type:%u:device local\n", phydev, i);
368 pout("physical device:%p:memory type:%u:device local\n", phydev, i);
360 369 if ((type->prop_flags & vk_mem_prop_host_visible_bit) != 0) if ((type->prop_flags & vk_mem_prop_host_visible_bit) != 0)
361 POUTVK("physical device:%p:memory type:%u:host visible\n", phydev, i);
370 pout("physical device:%p:memory type:%u:host visible\n", phydev, i);
362 371 if ((type->prop_flags & vk_mem_prop_host_cached_bit) != 0) if ((type->prop_flags & vk_mem_prop_host_cached_bit) != 0)
363 POUTVK("physical device:%p:memory type:%u:host cached\n", phydev, i);
372 pout("physical device:%p:memory type:%u:host cached\n", phydev, i);
364 373 } }
365 374 STATIC void tmp_phydev_mem_types_dump(struct tmp_phydev_t *p) STATIC void tmp_phydev_mem_types_dump(struct tmp_phydev_t *p)
366 375 { {
367 376 u8 i; u8 i;
368 377
369 POUTVK("physical device:%p:%u memory types\n", p->vk, p->mem_props.core.mem_types_n);
378 pout("physical device:%p:%u memory types\n", p->vk, p->mem_props.core.mem_types_n);
370 379 i = 0; i = 0;
371 380 loop { loop {
372 381 if (i == p->mem_props.core.mem_types_n) if (i == p->mem_props.core.mem_types_n)
 
... ... STATIC void tmp_phydev_mem_types_dump(struct tmp_phydev_t *p)
379 388 STATIC void phydev_mem_heap_dump(void *phydev, u8 i, STATIC void phydev_mem_heap_dump(void *phydev, u8 i,
380 389 struct vk_mem_heap_t *heap) struct vk_mem_heap_t *heap)
381 390 { {
382 POUTVK("physical device:%p:memory heap:%u:size:%u bytes\n", phydev, i, heap->sz);
383 POUTVK("physical device:%p:memory heap:%u:flags:%#08x\n", phydev, i, heap->flags);
391 pout("physical device:%p:memory heap:%u:size:%u bytes\n", phydev, i, heap->sz);
392 pout("physical device:%p:memory heap:%u:flags:%#08x\n", phydev, i, heap->flags);
384 393 if ((heap->flags & vk_mem_heap_dev_local_bit) != 0) if ((heap->flags & vk_mem_heap_dev_local_bit) != 0)
385 POUTVK("physical device:%p:memory heap:%u:device local\n", phydev, i);
394 pout("physical device:%p:memory heap:%u:device local\n", phydev, i);
386 395 if ((heap->flags & vk_mem_heap_multi_instance_bit) != 0) if ((heap->flags & vk_mem_heap_multi_instance_bit) != 0)
387 POUTVK("physical device:%p:memory type:%u:multi instance\n", phydev, i);
396 pout("physical device:%p:memory type:%u:multi instance\n", phydev, i);
388 397 } }
389 398 STATIC void tmp_phydev_mem_heaps_dump(struct tmp_phydev_t *p) STATIC void tmp_phydev_mem_heaps_dump(struct tmp_phydev_t *p)
390 399 { {
391 400 u8 i; u8 i;
392 401
393 POUTVK("physical device:%p:%u memory heaps\n", p->vk, p->mem_props.core.mem_heaps_n);
402 pout("physical device:%p:%u memory heaps\n", p->vk, p->mem_props.core.mem_heaps_n);
394 403 i = 0; i = 0;
395 404 loop { loop {
396 405 if (i == p->mem_props.core.mem_heaps_n) if (i == p->mem_props.core.mem_heaps_n)
 
... ... STATIC void tmp_phydev_q_fams_get(struct tmp_phydev_t *p)
426 435 n = 0; n = 0;
427 436 vk_get_phydev_q_fam_props(p->vk, &n, 0); vk_get_phydev_q_fam_props(p->vk, &n, 0);
428 437 if (n > tmp_phydev_q_fams_n_max) if (n > tmp_phydev_q_fams_n_max)
429 FATALVK("physical device:%p:too many queue families %u/%u\n", p->vk, n, tmp_phydev_q_fams_n_max);
438 fatal("physical device:%p:too many queue families %u/%u\n", p->vk, n, tmp_phydev_q_fams_n_max);
430 439 memset(p->q_fams, 0, sizeof(p->q_fams)); memset(p->q_fams, 0, sizeof(p->q_fams));
431 440 i = 0; i = 0;
432 441 loop { loop {
 
... ... STATIC void tmp_phydev_q_fams_get(struct tmp_phydev_t *p)
437 446 } }
438 447 vk_get_phydev_q_fam_props(p->vk, &n, p->q_fams); vk_get_phydev_q_fam_props(p->vk, &n, p->q_fams);
439 448 p->q_fams_n = n; p->q_fams_n = n;
440 POUTVK("physical device:%p:have %u queue families\n", p->vk, p->q_fams_n);
449 pout("physical device:%p:have %u queue families\n", p->vk, p->q_fams_n);
441 450 } }
442 451 STATIC void tmp_phydevs_q_fams_get(void) STATIC void tmp_phydevs_q_fams_get(void)
443 452 { {
 
... ... STATIC void tmp_phydev_q_fams_dump(struct tmp_phydev_t *p)
460 469 if (i == p->q_fams_n) if (i == p->q_fams_n)
461 470 break; break;
462 471 if ((p->q_fams[i].core.flags & vk_q_gfx_bit) != 0) if ((p->q_fams[i].core.flags & vk_q_gfx_bit) != 0)
463 POUTVK("physical device:%p:queue family:%u:flags:graphics\n", p->vk, i);
472 pout("physical device:%p:queue family:%u:flags:graphics\n", p->vk, i);
464 473 if ((p->q_fams[i].core.flags & vk_q_compute_bit) != 0) if ((p->q_fams[i].core.flags & vk_q_compute_bit) != 0)
465 POUTVK("physical device:%p:queue family:%u:flags:compute\n", p->vk, i);
474 pout("physical device:%p:queue family:%u:flags:compute\n", p->vk, i);
466 475 if ((p->q_fams[i].core.flags & vk_q_transfer_bit) != 0) if ((p->q_fams[i].core.flags & vk_q_transfer_bit) != 0)
467 POUTVK("physical device:%p:queue family:%u:flags:transfer\n", p->vk, i);
476 pout("physical device:%p:queue family:%u:flags:transfer\n", p->vk, i);
468 477 if ((p->q_fams[i].core.flags & vk_q_sparse_binding_bit) != 0) if ((p->q_fams[i].core.flags & vk_q_sparse_binding_bit) != 0)
469 POUTVK("physical device:%p:queue family:%u:flags:sparse binding\n", p->vk, i);
478 pout("physical device:%p:queue family:%u:flags:sparse binding\n", p->vk, i);
470 479 if ((p->q_fams[i].core.flags & vk_q_protected_bit) != 0) if ((p->q_fams[i].core.flags & vk_q_protected_bit) != 0)
471 POUTVK("physical device:%p:queue family:%u:flags:protected\n", p->vk, i);
472 POUTVK("physical device:%p:queue family:%u:%u queues\n", p->vk, i, p->q_fams[i].core.qs_n);
473 POUTVK("physical device:%p:queue family:%u:%u bits timestamps\n", p->vk, i, p->q_fams[i].core.timestamp_valid_bits);
474 POUTVK("physical device:%p:queue family:%u:(width=%u,height=%u,depth=%u) minimum image transfer granularity\n", p->vk, i, p->q_fams[i].core.min_img_transfer_granularity.width, p->q_fams[i].core.min_img_transfer_granularity.height, p->q_fams[i].core.min_img_transfer_granularity.depth);
480 pout("physical device:%p:queue family:%u:flags:protected\n", p->vk, i);
481 pout("physical device:%p:queue family:%u:%u queues\n", p->vk, i, p->q_fams[i].core.qs_n);
482 pout("physical device:%p:queue family:%u:%u bits timestamps\n", p->vk, i, p->q_fams[i].core.timestamp_valid_bits);
483 pout("physical device:%p:queue family:%u:(width=%u,height=%u,depth=%u) minimum image transfer granularity\n", p->vk, i, p->q_fams[i].core.min_img_transfer_granularity.width, p->q_fams[i].core.min_img_transfer_granularity.height, p->q_fams[i].core.min_img_transfer_granularity.depth);
475 484 ++i; ++i;
476 485 } }
477 486 } }
 
... ... STATIC void tmp_phydevs_q_fams_surf_support_get(void)
517 526 vk_get_phydev_surf_support(p->vk, j, &supported); vk_get_phydev_surf_support(p->vk, j, &supported);
518 527 IF_FATALVK("%d:physical device:%p:queue family:%u:surface:%p:unable to query queue family wsi/(image presentation to our surface) support\n", r, p->vk, j, surf_p.vk); IF_FATALVK("%d:physical device:%p:queue family:%u:surface:%p:unable to query queue family wsi/(image presentation to our surface) support\n", r, p->vk, j, surf_p.vk);
519 528 if (supported == vk_true) { if (supported == vk_true) {
520 POUTVK("physical device:%p:queue family:%u:surface:%p:does support wsi/(image presentation to our surface) \n", p->vk, j, surf_p.vk);
529 pout("physical device:%p:queue family:%u:surface:%p:does support wsi/(image presentation to our surface) \n", p->vk, j, surf_p.vk);
521 530 p->q_fams_surf_support[j] = true; p->q_fams_surf_support[j] = true;
522 531 } else { } else {
523 POUTVK("physical device:%p:queue family:%u:surface:%p:does not support wsi/(image presentation to our surface)\n", p->vk, j, surf_p.vk);
532 pout("physical device:%p:queue family:%u:surface:%p:does not support wsi/(image presentation to our surface)\n", p->vk, j, surf_p.vk);
524 533 p->q_fams_surf_support[j] = false; p->q_fams_surf_support[j] = false;
525 534 } }
526 535 ++j; ++j;
 
... ... STATIC void tmp_phydev_and_q_fam_select(void)
572 581 != 0) { != 0) {
573 582 surf_p.dev.phydev.q_fam = j; surf_p.dev.phydev.q_fam = j;
574 583 tmp_selected_phydev_cherry_pick(i); tmp_selected_phydev_cherry_pick(i);
575 POUTVK("physical device %p selected for (wsi/image presentation to our surface %p) using its queue family %u\n", surf_p.dev.phydev.vk, surf_p.vk, surf_p.dev.phydev.q_fam);
584 pout("physical device %p selected for (wsi/image presentation to our surface %p) using its queue family %u\n", surf_p.dev.phydev.vk, surf_p.vk, surf_p.dev.phydev.q_fam);
576 585 return; return;
577 586 } }
578 587 ++j; ++j;
 
... ... STATIC void texel_mem_blk_confs_dump(u32 confs_n,
589 598 loop { loop {
590 599 if (i == confs_n) if (i == confs_n)
591 600 break; break;
592 POUTVK("physical device:%p:surface:%p:texel memory block configuration:format=%u color_space=%u\n", surf_p.dev.phydev.vk, surf_p.vk, confs[i].core.fmt, confs[i].core.color_space);
601 pout("physical device:%p:surface:%p:texel memory block configuration:format=%u color_space=%u\n", surf_p.dev.phydev.vk, surf_p.vk, confs[i].core.fmt, confs[i].core.color_space);
593 602 ++i; ++i;
594 603 } }
595 604 } }
 
... ... STATIC void phydev_surf_texel_mem_blk_conf_select(void)
613 622 vk_get_phydev_surf_texel_mem_blk_confs(&info, &confs_n, 0); vk_get_phydev_surf_texel_mem_blk_confs(&info, &confs_n, 0);
614 623 IF_FATALVK("%d:physical device:%p:surface:%p:unable get the count of valid surface texel memory block configurations\n", r, surf_p.dev.phydev.vk, surf_p.vk); IF_FATALVK("%d:physical device:%p:surface:%p:unable get the count of valid surface texel memory block configurations\n", r, surf_p.dev.phydev.vk, surf_p.vk);
615 624 if (confs_n > CONFS_N_MAX) if (confs_n > CONFS_N_MAX)
616 FATALVK("physical device:%p:surface:%p:too many surface texel memory block configurations %u/%u\n", surf_p.dev.phydev.vk, surf_p.vk, confs_n, CONFS_N_MAX);
625 fatal("physical device:%p:surface:%p:too many surface texel memory block configurations %u/%u\n", surf_p.dev.phydev.vk, surf_p.vk, confs_n, CONFS_N_MAX);
617 626
618 627 memset(confs, 0, sizeof(confs[0]) * confs_n); memset(confs, 0, sizeof(confs[0]) * confs_n);
619 628 i = 0; i = 0;
 
... ... STATIC void phydev_surf_texel_mem_blk_conf_select(void)
626 635 vk_get_phydev_surf_texel_mem_blk_confs(&info, &confs_n, confs); vk_get_phydev_surf_texel_mem_blk_confs(&info, &confs_n, confs);
627 636 IF_FATALVK("%d:physical device:%p:surface:%p:unable get the valid surface texel memory block configurations\n", r, surf_p.dev.phydev.vk, surf_p.vk); IF_FATALVK("%d:physical device:%p:surface:%p:unable get the valid surface texel memory block configurations\n", r, surf_p.dev.phydev.vk, surf_p.vk);
628 637 if (confs_n == 0) if (confs_n == 0)
629 FATALVK("physical device:%p:surface:%p:no valid surface texel memory block configuration\n", surf_p.dev.phydev.vk, surf_p.vk);
638 fatal("physical device:%p:surface:%p:no valid surface texel memory block configuration\n", surf_p.dev.phydev.vk, surf_p.vk);
630 639 texel_mem_blk_confs_dump(confs_n, confs); texel_mem_blk_confs_dump(confs_n, confs);
631 640
632 641 cc = &surf_p.dev.phydev.selected_texel_mem_blk_conf_core; cc = &surf_p.dev.phydev.selected_texel_mem_blk_conf_core;
 
... ... STATIC void phydev_surf_texel_mem_blk_conf_select(void)
635 644 * get from ff scaler * get from ff scaler
636 645 */ */
637 646 cc->fmt = vk_texel_mem_blk_fmt_b8g8r8a8_srgb; cc->fmt = vk_texel_mem_blk_fmt_b8g8r8a8_srgb;
638 POUTVK("physical device:%p:surface:%p:using our surface texel memory block format %u\n", surf_p.dev.phydev.vk, surf_p.vk, cc->fmt);
647 pout("physical device:%p:surface:%p:using our surface texel memory block format %u\n", surf_p.dev.phydev.vk, surf_p.vk, cc->fmt);
639 648 cc->color_space = vk_color_space_srgb_nonlinear; cc->color_space = vk_color_space_srgb_nonlinear;
640 POUTVK("physical device:%p:surface:%p:using prefered surface texel memory block color space %u\n", surf_p.dev.phydev.vk, surf_p.vk, cc->color_space);
649 pout("physical device:%p:surface:%p:using prefered surface texel memory block color space %u\n", surf_p.dev.phydev.vk, surf_p.vk, cc->color_space);
641 650 } }
642 651 #undef CONFS_N_MAX #undef CONFS_N_MAX
643 652 STATIC void phydev_surf_caps_get(void) STATIC void phydev_surf_caps_get(void)
 
... ... STATIC void phydev_surf_caps_get(void)
655 664 IF_FATALVK("%d:physical device:%p:surface:%p:unable to get our surface capabilities in the context of the selected physical device\n", r, surf_p.dev.phydev.vk, surf_p.vk); IF_FATALVK("%d:physical device:%p:surface:%p:unable to get our surface capabilities in the context of the selected physical device\n", r, surf_p.dev.phydev.vk, surf_p.vk);
656 665 /* we have room for a maximum of 3 images per swapchain */ /* we have room for a maximum of 3 images per swapchain */
657 666 if (surf_p.dev.phydev.surf_caps.core.imgs_n_min > swpchn_imgs_n_max) if (surf_p.dev.phydev.surf_caps.core.imgs_n_min > swpchn_imgs_n_max)
658 FATALVK("physical device:%p:surface:%p:we have room for %u images per swapchain, but this swapchain requires a minimum of %u images\n", surf_p.dev.phydev.vk, surf_p.vk, swpchn_imgs_n_max, surf_p.dev.phydev.surf_caps.core.imgs_n_min);
667 fatal("physical device:%p:surface:%p:we have room for %u images per swapchain, but this swapchain requires a minimum of %u images\n", surf_p.dev.phydev.vk, surf_p.vk, swpchn_imgs_n_max, surf_p.dev.phydev.surf_caps.core.imgs_n_min);
659 668 } }
660 669 STATIC void phydev_surf_caps_dump(void) STATIC void phydev_surf_caps_dump(void)
661 670 { {
662 POUTVK("physical device:%p:surface:%p:imgs_n_min=%u\n", surf_p.dev.phydev.vk, surf_p.vk, surf_p.dev.phydev.surf_caps.core.imgs_n_min);
663 POUTVK("physical device:%p:surface:%p:imgs_n_max=%u\n", surf_p.dev.phydev.vk, surf_p.vk, surf_p.dev.phydev.surf_caps.core.imgs_n_max);
664 POUTVK("physical device:%p:surface:%p:current extent=(width=%u, height=%u)\n", surf_p.dev.phydev.vk, surf_p.vk, surf_p.dev.phydev.surf_caps.core.current_extent.width, surf_p.dev.phydev.surf_caps.core.current_extent.height);
665 POUTVK("physical device:%p:surface:%p:minimal extent=(width=%u, height=%u)\n", surf_p.dev.phydev.vk, surf_p.vk, surf_p.dev.phydev.surf_caps.core.img_extent_min.width, surf_p.dev.phydev.surf_caps.core.img_extent_min.height);
666 POUTVK("physical device:%p:surface:%p:maximal extent=(width=%u, height=%u)\n", surf_p.dev.phydev.vk, surf_p.vk, surf_p.dev.phydev.surf_caps.core.img_extent_max.width, surf_p.dev.phydev.surf_caps.core.img_extent_max.height);
667 POUTVK("physical device:%p:surface:%p:img_array_layers_n_max=%u\n", surf_p.dev.phydev.vk, surf_p.vk, surf_p.dev.phydev.surf_caps.core.img_array_layers_n_max);
668 POUTVK("physical device:%p:surface:%p:supported_transforms=%#08x\n", surf_p.dev.phydev.vk, surf_p.vk, surf_p.dev.phydev.surf_caps.core.supported_transforms);
669 POUTVK("physical device:%p:surface:%p:current_transform=%#08x\n", surf_p.dev.phydev.vk, surf_p.vk, surf_p.dev.phydev.surf_caps.core.current_transform);
670 POUTVK("physical device:%p:surface:%p:supported_composite_alpha=%#08x\n", surf_p.dev.phydev.vk, surf_p.vk, surf_p.dev.phydev.surf_caps.core.supported_composite_alpha);
671 POUTVK("physical device:%p:surface:%p:supported_img_usage_flags=%#08x\n", surf_p.dev.phydev.vk, surf_p.vk, surf_p.dev.phydev.surf_caps.core.supported_img_usage_flags);
671 pout("physical device:%p:surface:%p:imgs_n_min=%u\n", surf_p.dev.phydev.vk, surf_p.vk, surf_p.dev.phydev.surf_caps.core.imgs_n_min);
672 pout("physical device:%p:surface:%p:imgs_n_max=%u\n", surf_p.dev.phydev.vk, surf_p.vk, surf_p.dev.phydev.surf_caps.core.imgs_n_max);
673 pout("physical device:%p:surface:%p:current extent=(width=%u, height=%u)\n", surf_p.dev.phydev.vk, surf_p.vk, surf_p.dev.phydev.surf_caps.core.current_extent.width, surf_p.dev.phydev.surf_caps.core.current_extent.height);
674 pout("physical device:%p:surface:%p:minimal extent=(width=%u, height=%u)\n", surf_p.dev.phydev.vk, surf_p.vk, surf_p.dev.phydev.surf_caps.core.img_extent_min.width, surf_p.dev.phydev.surf_caps.core.img_extent_min.height);
675 pout("physical device:%p:surface:%p:maximal extent=(width=%u, height=%u)\n", surf_p.dev.phydev.vk, surf_p.vk, surf_p.dev.phydev.surf_caps.core.img_extent_max.width, surf_p.dev.phydev.surf_caps.core.img_extent_max.height);
676 pout("physical device:%p:surface:%p:img_array_layers_n_max=%u\n", surf_p.dev.phydev.vk, surf_p.vk, surf_p.dev.phydev.surf_caps.core.img_array_layers_n_max);
677 pout("physical device:%p:surface:%p:supported_transforms=%#08x\n", surf_p.dev.phydev.vk, surf_p.vk, surf_p.dev.phydev.surf_caps.core.supported_transforms);
678 pout("physical device:%p:surface:%p:current_transform=%#08x\n", surf_p.dev.phydev.vk, surf_p.vk, surf_p.dev.phydev.surf_caps.core.current_transform);
679 pout("physical device:%p:surface:%p:supported_composite_alpha=%#08x\n", surf_p.dev.phydev.vk, surf_p.vk, surf_p.dev.phydev.surf_caps.core.supported_composite_alpha);
680 pout("physical device:%p:surface:%p:supported_img_usage_flags=%#08x\n", surf_p.dev.phydev.vk, surf_p.vk, surf_p.dev.phydev.surf_caps.core.supported_img_usage_flags);
672 681 } }
673 682 STATIC void tmp_phydev_surf_present_modes_get(void) STATIC void tmp_phydev_surf_present_modes_get(void)
674 683 { {
 
... ... STATIC void tmp_phydev_surf_present_modes_dump(void)
698 707 u8 i; u8 i;
699 708
700 709 i = 0; i = 0;
701 POUTVK("physical device:%p:surface:%p:%u present modes\n", surf_p.dev.phydev.vk, surf_p.vk, tmp_present_modes_n_l);
710 pout("physical device:%p:surface:%p:%u present modes\n", surf_p.dev.phydev.vk, surf_p.vk, tmp_present_modes_n_l);
702 711 loop { loop {
703 712 if (i == (u8)tmp_present_modes_n_l) if (i == (u8)tmp_present_modes_n_l)
704 713 break; break;
705 POUTVK("physical device:%p:surface:%p:present mode=%s\n", surf_p.dev.phydev.vk, surf_p.vk, present_mode_to_str(tmp_present_modes_l[i]));
714 pout("physical device:%p:surface:%p:present mode=%s\n", surf_p.dev.phydev.vk, surf_p.vk, present_mode_to_str(tmp_present_modes_l[i]));
706 715 ++i; ++i;
707 716 } }
708 717 } }
 
... ... STATIC void dev_create(void)
763 772 info.enabled_ext_names = exts; info.enabled_ext_names = exts;
764 773 vk_create_dev(&info); vk_create_dev(&info);
765 774 IF_FATALVK("%d:physical device:%p:unable to create a vulkan device\n", r, surf_p.dev.phydev.vk); IF_FATALVK("%d:physical device:%p:unable to create a vulkan device\n", r, surf_p.dev.phydev.vk);
766 POUTVK("physical device:%p:vulkan device created with one proper queue:%p\n", surf_p.dev.phydev.vk, surf_p.dev.vk);
775 pout("physical device:%p:vulkan device created with one proper queue:%p\n", surf_p.dev.phydev.vk, surf_p.dev.vk);
767 776 } }
768 777 STATIC void q_get(void) STATIC void q_get(void)
769 778 { {
770 POUTVK("device:%p:getting queue:family=%u queue=0\n", surf_p.dev.vk, surf_p.dev.phydev.q_fam);
779 pout("device:%p:getting queue:family=%u queue=0\n", surf_p.dev.vk, surf_p.dev.phydev.q_fam);
771 780 vk_get_dev_q(); vk_get_dev_q();
772 POUTVK("device:%p:got queue:%p\n", surf_p.dev.vk, surf_p.dev.q);
781 pout("device:%p:got queue:%p\n", surf_p.dev.vk, surf_p.dev.q);
773 782 } }
774 783 STATIC void cp_create(void) STATIC void cp_create(void)
775 784 { {
 
... ... STATIC void cp_create(void)
782 791 info.q_fam = surf_p.dev.phydev.q_fam; info.q_fam = surf_p.dev.phydev.q_fam;
783 792 vk_create_cp(&info); vk_create_cp(&info);
784 793 IF_FATALVK("%d:unable create the commmand pool\n", r); IF_FATALVK("%d:unable create the commmand pool\n", r);
785 POUTVK("device:%p:queue family:%u:created command pool %p\n", surf_p.dev.vk, surf_p.dev.phydev.q_fam, surf_p.dev.cp);
794 pout("device:%p:queue family:%u:created command pool %p\n", surf_p.dev.vk, surf_p.dev.phydev.q_fam, surf_p.dev.cp);
786 795 } }
787 796 STATIC void dev_init(void) STATIC void dev_init(void)
788 797 { {
 
... ... STATIC void surf_create(xcb_connection_t *c, u32 win_id)
806 815 vk_xcb_info.win = win_id; vk_xcb_info.win = win_id;
807 816 vk_create_xcb_surf(&vk_xcb_info); vk_create_xcb_surf(&vk_xcb_info);
808 817 IF_FATALVK("%d:xcb:%p:window id:%#x:unable to create a vulkan surface from this x11 window\n", r, c, win_id); IF_FATALVK("%d:xcb:%p:window id:%#x:unable to create a vulkan surface from this x11 window\n", r, c, win_id);
809 POUTVK("xcb:%p:window id:%#x:created vk_surface=%p\n", c, win_id, surf_p.vk);
818 pout("xcb:%p:window id:%#x:created vk_surface=%p\n", c, win_id, surf_p.vk);
810 819 } }
811 820 STATIC void swpchn_init_once(void) STATIC void swpchn_init_once(void)
812 821 { {
 
... ... STATIC void sems_create(void)
876 885 info.type = vk_struct_type_sem_create_info; info.type = vk_struct_type_sem_create_info;
877 886 vk_create_sem(&info, &surf_p.dev.sems[sem]); vk_create_sem(&info, &surf_p.dev.sems[sem]);
878 887 IF_FATALVK("%d:device:%p:unable to create a semaphore %u for the synchronization of the swapchain\n", r, surf_p.dev.vk, sem); IF_FATALVK("%d:device:%p:unable to create a semaphore %u for the synchronization of the swapchain\n", r, surf_p.dev.vk, sem);
879 POUTVK("device:%p:semaphore %u for the synchronization of the swapchain created %p\n", surf_p.dev.vk, sem, surf_p.dev.sems[sem]);
888 pout("device:%p:semaphore %u for the synchronization of the swapchain created %p\n", surf_p.dev.vk, sem, surf_p.dev.sems[sem]);
880 889 ++sem; ++sem;
881 890 } }
882 891 } }
 
... ... STATIC void swpchn_imgs_cbs_init_once(void)
892 901 alloc_info.cbs_n = swpchn_imgs_n_max; alloc_info.cbs_n = swpchn_imgs_n_max;
893 902 vk_alloc_cbs(&alloc_info); vk_alloc_cbs(&alloc_info);
894 903 IF_FATALVK("%d:device:%p:unable to allocate command buffers for our swapchain images from %p command pool\n", r, surf_p.dev.vk, surf_p.dev.cp); IF_FATALVK("%d:device:%p:unable to allocate command buffers for our swapchain images from %p command pool\n", r, surf_p.dev.vk, surf_p.dev.cp);
895 POUTVK("device:%p:allocated %u command buffers for our swapchain images from %p command pool\n", surf_p.dev.vk, surf_p.dev.swpchn.imgs_n, surf_p.dev.cp);
904 pout("device:%p:allocated %u command buffers for our swapchain images from %p command pool\n", surf_p.dev.vk, surf_p.dev.swpchn.imgs_n, surf_p.dev.cp);
896 905 } }
File npv/vk/main.c changed (mode: 100644) (index 187ac30..1dab8ad)
5 5 * copyright (C) 2020 Sylvain BERTRAND * copyright (C) 2020 Sylvain BERTRAND
6 6 */ */
7 7 #include <stdbool.h> #include <stdbool.h>
8 #include <stdarg.h>
8 9 #include <stdio.h> #include <stdio.h>
9 10 #include <dlfcn.h> #include <dlfcn.h>
10 11 #include <stdlib.h> #include <stdlib.h>
11 12 #include <string.h> #include <string.h>
12 13 #include <xcb/xcb.h> #include <xcb/xcb.h>
13 14 #include "npv/c_fixing.h" #include "npv/c_fixing.h"
15 #include "npv/public.h"
14 16 #include "npv/nyanvk/consts.h" #include "npv/nyanvk/consts.h"
15 17 #include "npv/nyanvk/types.h" #include "npv/nyanvk/types.h"
16 18 #include "npv/global.h" #include "npv/global.h"
File npv/vk/namespace/main.c changed (mode: 100644) (index 11a6a2a..893a047)
21 21 #define phydev_surf_caps_dump npv_vk_phydev_surf_caps_dump #define phydev_surf_caps_dump npv_vk_phydev_surf_caps_dump
22 22 #define phydev_surf_caps_get npv_vk_phydev_surf_caps_get #define phydev_surf_caps_get npv_vk_phydev_surf_caps_get
23 23 #define phydev_surf_texel_mem_blk_conf_select npv_vk_phydev_surf_texel_mem_blk_conf_select #define phydev_surf_texel_mem_blk_conf_select npv_vk_phydev_surf_texel_mem_blk_conf_select
24 #define pout npv_vk_pout
24 25 #define present_mode_to_str npv_vk_present_mode_to_str #define present_mode_to_str npv_vk_present_mode_to_str
25 26 #define q_get npv_vk_q_get #define q_get npv_vk_q_get
26 27 #define sems_create npv_vk_sems_create #define sems_create npv_vk_sems_create
 
81 82 #undef phydev_surf_caps_dump #undef phydev_surf_caps_dump
82 83 #undef phydev_surf_caps_get #undef phydev_surf_caps_get
83 84 #undef phydev_surf_texel_mem_blk_conf_select #undef phydev_surf_texel_mem_blk_conf_select
85 #undef pout
84 86 #undef present_mode_to_str #undef present_mode_to_str
85 87 #undef q_get #undef q_get
86 88 #undef sems_create #undef sems_create
File npv/vk/namespace/public.h changed (mode: 100644) (index b8f5672..1d2b6bd)
1 1 #ifndef CLEANUP #ifndef CLEANUP
2 2 #define dev_t npv_vk_dev_t #define dev_t npv_vk_dev_t
3 #define fatal npv_vk_fatal
3 4 #define init_once npv_vk_init_once #define init_once npv_vk_init_once
4 5 #define phydev_t npv_vk_phydev_t #define phydev_t npv_vk_phydev_t
5 6 #define sem_acquire_img_done npv_vk_sem_acquire_img_done #define sem_acquire_img_done npv_vk_sem_acquire_img_done
 
10 11 #define swpchn_update npv_vk_swpchn_update #define swpchn_update npv_vk_swpchn_update
11 12 #define swpchn_imgs_n_max npv_vk_swpchn_imgs_n_max #define swpchn_imgs_n_max npv_vk_swpchn_imgs_n_max
12 13 #define swpchn_t npv_vk_swpchn_t #define swpchn_t npv_vk_swpchn_t
14 #define vfatal npv_vk_vfatal
15 #define vwarning npv_vk_vwarning
16 #define warning npv_vk_warning
13 17 /*============================================================================*/ /*============================================================================*/
14 18 #else #else
15 19 #undef dev_t #undef dev_t
20 #undef fatal
16 21 #undef init_once #undef init_once
17 22 #undef phydev_t #undef phydev_t
18 23 #undef sem_acquire_img_done #undef sem_acquire_img_done
 
23 28 #undef swpchn_update #undef swpchn_update
24 29 #undef swpchn_imgs_n_max #undef swpchn_imgs_n_max
25 30 #undef swpchn_t #undef swpchn_t
31 #undef vfatal
32 #undef vwarning
33 #undef warning
26 34 #endif #endif
27 35
File npv/vk/public.h changed (mode: 100644) (index 8837c61..ddb7bcd)
19 19 STATIC void init_once(void); STATIC void init_once(void);
20 20 STATIC void surf_init_once(xcb_connection_t *c, u32 wind_id); STATIC void surf_init_once(xcb_connection_t *c, u32 wind_id);
21 21 STATIC void swpchn_update(void); STATIC void swpchn_update(void);
22 STATIC void fatal(u8 *fmt, ...);
23 STATIC void warning(u8 *fmt, ...);
24 STATIC void vfatal(u8 *fmt, va_list ap);
25 STATIC void vwarning(u8 *fmt, va_list ap);
22 26 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
23 27 #define CLEANUP #define CLEANUP
24 28 #include "npv/vk/namespace/public.h" #include "npv/vk/namespace/public.h"
File npv/vk/public/code.frag.c changed (mode: 100644) (index fa53616..021e14f)
1 STATIC void fatal(u8 *fmt, ...)
2 {
3 va_list ap;
4
5 npv_perr("vulkan:");
6 va_start(ap, fmt);
7 npv_vfatal(fmt, ap);
8 va_end(ap); /* unreachable */
9 }
10 STATIC void vfatal(u8 *fmt, va_list ap)
11 {
12 va_list aq;
13
14 npv_perr("vulkan:");
15 va_copy(aq, ap);
16 npv_vfatal(fmt, aq);
17 va_end(aq);
18 }
19 STATIC void warning(u8 *fmt, ...)
20 {
21 va_list ap;
22
23 npv_perr("vulkan:");
24 va_start(ap, fmt);
25 npv_vwarning(fmt, ap);
26 va_end(ap);
27 }
28 STATIC void vwarning(u8 *fmt, va_list ap)
29 {
30 va_list aq;
31
32 npv_perr("vulkan:");
33 va_copy(aq, ap);
34 npv_vwarning(fmt, aq);
35 va_end(aq);
36 }
1 37 STATIC void swpchn_update(void) STATIC void swpchn_update(void)
2 38 { {
3 39 phydev_surf_caps_get(); phydev_surf_caps_get();
File npv/xcb/local/code.frag.c changed (mode: 100644) (index 600e27e..1695161)
1 STATIC void npv_xcb_fatal(u8 *fmt, ...)
2 {
3 va_list ap;
4
5 npv_perr("xcb:");
6 va_start(ap, fmt);
7 npv_vfatal(fmt, ap);
8 va_end(ap); /* unreachable */
9 }
10 STATIC void npv_xcb_warning(u8 *fmt, ...)
11 {
12 va_list ap;
13
14 npv_perr("xcb:");
15 va_start(ap, fmt);
16 npv_vwarning(fmt, ap);
17 va_end(ap);
18 }
19 STATIC void npv_xcb_pout(u8 *fmt, ...)
20 {
21 va_list ap;
22
23 npv_pout("xcb:");
24 va_start(ap, fmt);
25 npv_vpout(fmt, ap);
26 va_end(ap);
27 }
1 28 STATIC void npv_xcb_libs_load(void) STATIC void npv_xcb_libs_load(void)
2 29 { {
3 30 npv_xcb_lib_l = dlopen("libxcb.so.1", RTLD_LAZY); npv_xcb_lib_l = dlopen("libxcb.so.1", RTLD_LAZY);
4 31 if (npv_xcb_lib_l == 0) if (npv_xcb_lib_l == 0)
5 FATALX("%s:unable to load the xcb dynamic shared library\n", dlerror());
32 npv_xcb_fatal("%s:unable to load the xcb dynamic shared library\n", dlerror());
6 33 npv_xcb_xfixes_lib_l = dlopen("libxcb-xfixes.so.0", RTLD_LAZY); npv_xcb_xfixes_lib_l = dlopen("libxcb-xfixes.so.0", RTLD_LAZY);
7 34 if (npv_xcb_xfixes_lib_l == 0) if (npv_xcb_xfixes_lib_l == 0)
8 FATALX("%s:unable to load the xcb xfixes dynamic shared library\n", dlerror());
35 npv_xcb_fatal("%s:unable to load the xcb xfixes dynamic shared library\n", dlerror());
9 36 } }
10 37 #define XCB_DLSYM(x) \ #define XCB_DLSYM(x) \
11 38 npv_dl_##x = dlsym(npv_xcb_lib_l, #x); \ npv_dl_##x = dlsym(npv_xcb_lib_l, #x); \
12 39 if (npv_dl_##x == 0) \ if (npv_dl_##x == 0) \
13 FATALX("%s:unable to find " #x "\n", dlerror());
40 npv_xcb_fatal("%s:unable to find " #x "\n", dlerror());
14 41 #define XCB_XFIXES_DLSYM(x) \ #define XCB_XFIXES_DLSYM(x) \
15 42 npv_dl_##x = dlsym(npv_xcb_xfixes_lib_l, #x); \ npv_dl_##x = dlsym(npv_xcb_xfixes_lib_l, #x); \
16 43 if (npv_dl_##x == 0) \ if (npv_dl_##x == 0) \
17 FATALX("%s:unable to find " #x "\n", dlerror());
44 npv_xcb_fatal("%s:unable to find " #x "\n", dlerror());
18 45 STATIC void npv_xcb_syms(void) STATIC void npv_xcb_syms(void)
19 46 { {
20 47 XCB_DLSYM(xcb_connect); XCB_DLSYM(xcb_connect);
 
... ... STATIC void npv_xcb_win_create(void)
53 80 u32 value_list[2]; u32 value_list[2];
54 81
55 82 npv_xcb_p.win_id = npv_dl_xcb_generate_id(npv_xcb_p.c); npv_xcb_p.win_id = npv_dl_xcb_generate_id(npv_xcb_p.c);
56 POUTX("'%s':connection:%p:screen:%d:root window id:%#x:window id=%#x\n", npv_xcb_p.disp_env, npv_xcb_p.c, npv_xcb_p.scr_idx, npv_xcb_p.scr->root, npv_xcb_p.win_id);
83 npv_xcb_pout("'%s':connection:%p:screen:%d:root window id:%#x:window id=%#x\n", npv_xcb_p.disp_env, npv_xcb_p.c, npv_xcb_p.scr_idx, npv_xcb_p.scr->root, npv_xcb_p.win_id);
57 84
58 85 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
59 86 value_list[0] = npv_xcb_p.scr->black_pixel; value_list[0] = npv_xcb_p.scr->black_pixel;
 
... ... STATIC void npv_xcb_win_map(void)
78 105 xcb_generic_error_t *e; xcb_generic_error_t *e;
79 106
80 107 cookie = npv_dl_xcb_map_window_checked(npv_xcb_p.c, npv_xcb_p.win_id); cookie = npv_dl_xcb_map_window_checked(npv_xcb_p.c, npv_xcb_p.win_id);
81 POUTX("'%s':connection:%p:screen:%d:root window id:%#x:window id:%#x:map window request cookie=%#x\n", npv_xcb_p.disp_env, npv_xcb_p.c, npv_xcb_p.scr_idx, npv_xcb_p.scr->root, npv_xcb_p.win_id, cookie);
108 npv_xcb_pout("'%s':connection:%p:screen:%d:root window id:%#x:window id:%#x:map window request cookie=%#x\n", npv_xcb_p.disp_env, npv_xcb_p.c, npv_xcb_p.scr_idx, npv_xcb_p.scr->root, npv_xcb_p.win_id, cookie);
82 109
83 110 e = npv_dl_xcb_request_check(npv_xcb_p.c, cookie); e = npv_dl_xcb_request_check(npv_xcb_p.c, cookie);
84 111 if (e != 0) if (e != 0)
85 FATALX("'%s':connection:%p:screen:%d:root window id:%#x:window id:%#x:unable to map window\n", npv_xcb_p.disp_env, npv_xcb_p.c, npv_xcb_p.scr_idx, npv_xcb_p.scr->root, npv_xcb_p.win_id);
86 POUTX("'%s':connection:%p:screen:%d:root window id:%#x:window id:%#x:window mapped\n", npv_xcb_p.disp_env, npv_xcb_p.c, npv_xcb_p.scr_idx, npv_xcb_p.scr->root, npv_xcb_p.win_id);
112 npv_xcb_fatal("'%s':connection:%p:screen:%d:root window id:%#x:window id:%#x:unable to map window\n", npv_xcb_p.disp_env, npv_xcb_p.c, npv_xcb_p.scr_idx, npv_xcb_p.scr->root, npv_xcb_p.win_id);
113 npv_xcb_pout("'%s':connection:%p:screen:%d:root window id:%#x:window id:%#x:window mapped\n", npv_xcb_p.disp_env, npv_xcb_p.c, npv_xcb_p.scr_idx, npv_xcb_p.scr->root, npv_xcb_p.win_id);
87 114 } }
88 115 /* /*
89 116 * a disp is n scrs and 1 [set of] keyboard[s] and 1 [set of] mouse[s] * a disp is n scrs and 1 [set of] keyboard[s] and 1 [set of] mouse[s]
 
... ... STATIC void npv_xcb_connect(void)
97 124
98 125 npv_xcb_p.disp_env = getenv("DISPLAY"); npv_xcb_p.disp_env = getenv("DISPLAY");
99 126 if (npv_xcb_p.disp_env == 0 || npv_xcb_p.disp_env[0] == 0) if (npv_xcb_p.disp_env == 0 || npv_xcb_p.disp_env[0] == 0)
100 FATALX("no x11 DISPLAY environment variable, exiting\n");
127 npv_xcb_fatal("no x11 DISPLAY environment variable, exiting\n");
101 128
102 129 npv_xcb_p.scr_idx = 0; npv_xcb_p.scr_idx = 0;
103 130 /* should be 0 though */ /* should be 0 though */
104 131 npv_xcb_p.c = npv_dl_xcb_connect(0, &npv_xcb_p.scr_idx); npv_xcb_p.c = npv_dl_xcb_connect(0, &npv_xcb_p.scr_idx);
105 132 r = npv_dl_xcb_connection_has_error(npv_xcb_p.c); r = npv_dl_xcb_connection_has_error(npv_xcb_p.c);
106 133 if (r > 0) if (r > 0)
107 FATALX("%d:%s:error while connecting to the x11 server\n", r, npv_xcb_p.disp_env);
108 POUTX("'%s':connection=%p, default screen index is %d (should be 0)\n", npv_xcb_p.disp_env, npv_xcb_p.c, npv_xcb_p.scr_idx);
134 npv_xcb_fatal("%d:%s:error while connecting to the x11 server\n", r, npv_xcb_p.disp_env);
135 npv_xcb_pout("'%s':connection=%p, default screen index is %d (should be 0)\n", npv_xcb_p.disp_env, npv_xcb_p.c, npv_xcb_p.scr_idx);
109 136
110 137 npv_xcb_p.fd = npv_dl_xcb_get_file_descriptor(npv_xcb_p.c); npv_xcb_p.fd = npv_dl_xcb_get_file_descriptor(npv_xcb_p.c);
111 138 if (npv_xcb_p.fd == -1) if (npv_xcb_p.fd == -1)
112 FATALX("'%s':unable to get the connection file descriptor for epoll\n", npv_xcb_p.disp_env);
113 POUTX("'%s':connection:%p:file descriptor %d\n", npv_xcb_p.disp_env, npv_xcb_p.c, npv_xcb_p.fd);
139 npv_xcb_fatal("'%s':unable to get the connection file descriptor for epoll\n", npv_xcb_p.disp_env);
140 npv_xcb_pout("'%s':connection:%p:file descriptor %d\n", npv_xcb_p.disp_env, npv_xcb_p.c, npv_xcb_p.fd);
114 141 } }
115 142 STATIC void npv_xcb_scr_get(void) STATIC void npv_xcb_scr_get(void)
116 143 { {
 
... ... STATIC void npv_xcb_scr_get(void)
121 148 npv_xcb_p.setup = npv_dl_xcb_get_setup(npv_xcb_p.c); npv_xcb_p.setup = npv_dl_xcb_get_setup(npv_xcb_p.c);
122 149
123 150 scrs_n = npv_dl_xcb_setup_roots_length(npv_xcb_p.setup); scrs_n = npv_dl_xcb_setup_roots_length(npv_xcb_p.setup);
124 POUTX("'%s':connection:%p:has %d screens (should be 1)\n", npv_xcb_p.disp_env, npv_xcb_p.c, scrs_n);
151 npv_xcb_pout("'%s':connection:%p:has %d screens (should be 1)\n", npv_xcb_p.disp_env, npv_xcb_p.c, scrs_n);
125 152
126 153 iter = npv_dl_xcb_setup_roots_iterator(npv_xcb_p.setup); iter = npv_dl_xcb_setup_roots_iterator(npv_xcb_p.setup);
127 154 i = 0; i = 0;
 
... ... STATIC void npv_xcb_scr_get(void)
136 163 } }
137 164 npv_dl_xcb_screen_next(&iter); npv_dl_xcb_screen_next(&iter);
138 165 } }
139 POUTX("'%s':connection:%p:screen:%d:root window id:%#x:width=%d pixels\n", npv_xcb_p.disp_env, npv_xcb_p.c, npv_xcb_p.scr_idx, npv_xcb_p.scr->root, npv_xcb_p.scr->width_in_pixels);
140 POUTX("'%s':connection:%p:screen:%d:root window id:%#x:height=%d pixels\n", npv_xcb_p.disp_env, npv_xcb_p.c, npv_xcb_p.scr_idx, npv_xcb_p.scr->root, npv_xcb_p.scr->height_in_pixels);
141 POUTX("'%s':connection:%p:screen:%d:root window id:%#x:white pixel=0x%08x\n", npv_xcb_p.disp_env, npv_xcb_p.c, npv_xcb_p.scr_idx, npv_xcb_p.scr->root, npv_xcb_p.scr->white_pixel);
142 POUTX("'%s':connection:%p:screen:%d:root window id:%#x:black pixel=0x%08x\n", npv_xcb_p.disp_env, npv_xcb_p.c, npv_xcb_p.scr_idx, npv_xcb_p.scr->root, npv_xcb_p.scr->black_pixel);
166 npv_xcb_pout("'%s':connection:%p:screen:%d:root window id:%#x:width=%d pixels\n", npv_xcb_p.disp_env, npv_xcb_p.c, npv_xcb_p.scr_idx, npv_xcb_p.scr->root, npv_xcb_p.scr->width_in_pixels);
167 npv_xcb_pout("'%s':connection:%p:screen:%d:root window id:%#x:height=%d pixels\n", npv_xcb_p.disp_env, npv_xcb_p.c, npv_xcb_p.scr_idx, npv_xcb_p.scr->root, npv_xcb_p.scr->height_in_pixels);
168 npv_xcb_pout("'%s':connection:%p:screen:%d:root window id:%#x:white pixel=0x%08x\n", npv_xcb_p.disp_env, npv_xcb_p.c, npv_xcb_p.scr_idx, npv_xcb_p.scr->root, npv_xcb_p.scr->white_pixel);
169 npv_xcb_pout("'%s':connection:%p:screen:%d:root window id:%#x:black pixel=0x%08x\n", npv_xcb_p.disp_env, npv_xcb_p.c, npv_xcb_p.scr_idx, npv_xcb_p.scr->root, npv_xcb_p.scr->black_pixel);
143 170 } }
144 171 #define MIN_SZ_BIT (1 << 4) #define MIN_SZ_BIT (1 << 4)
145 172 #define MAX_SZ_BIT (1 << 5) #define MAX_SZ_BIT (1 << 5)
 
... ... STATIC void npv_xcb_evt_key_release(xcb_generic_event_t *evt)
229 256 if (b == ARRAY_N(npv_x11_binds)) if (b == ARRAY_N(npv_x11_binds))
230 257 break; break;
231 258 if (key->detail == npv_x11_binds[b].keycode) { if (key->detail == npv_x11_binds[b].keycode) {
232 POUTX("'%s':connection:%p:event:key release:keycode:%#02x:running command for bind \"%s\"\n", npv_xcb_p.disp_env, npv_xcb_p.c, key->detail, npv_x11_binds[b].name);
259 npv_xcb_pout("'%s':connection:%p:event:key release:keycode:%#02x:running command for bind \"%s\"\n", npv_xcb_p.disp_env, npv_xcb_p.c, key->detail, npv_x11_binds[b].name);
233 260 npv_x11_binds[b].cmd(); npv_x11_binds[b].cmd();
234 261 return; return;
235 262 } }
236 263 ++b; ++b;
237 264 } }
238 POUTX("'%s':connection:%p:event:key release:keycode:%#02x\n", npv_xcb_p.disp_env, npv_xcb_p.c, key->detail);
265 npv_xcb_pout("'%s':connection:%p:event:key release:keycode:%#02x\n", npv_xcb_p.disp_env, npv_xcb_p.c, key->detail);
239 266 } }
240 267 STATIC void npv_xcb_evt_leave_win(xcb_generic_event_t *evt) STATIC void npv_xcb_evt_leave_win(xcb_generic_event_t *evt)
241 268 { {
 
... ... STATIC void npv_xcb_mouse_visibility_timer_start(void)
256 283 t.it_value.tv_sec = npv_xcb_mouse_visibility_interval_s; t.it_value.tv_sec = npv_xcb_mouse_visibility_interval_s;
257 284 r = timerfd_settime(npv_xcb_p.mouse_visibility_timer_fd, 0, &t, 0); r = timerfd_settime(npv_xcb_p.mouse_visibility_timer_fd, 0, &t, 0);
258 285 if (r == -1) if (r == -1)
259 FATALX("unable to arm the mouse visibility timer to %u seconds\n", npv_xcb_mouse_visibility_interval_s);
286 npv_xcb_fatal("unable to arm the mouse visibility timer to %u seconds\n", npv_xcb_mouse_visibility_interval_s);
260 287 } }
261 288 STATIC void npv_xcb_evt_enter_win(xcb_generic_event_t *evt) STATIC void npv_xcb_evt_enter_win(xcb_generic_event_t *evt)
262 289 { {
 
... ... STATIC void npv_xcb_screensaver_heartbeat_timer_init_once(void)
348 375 npv_xcb_p.screensaver_heartbeat_timer_fd = timerfd_create( npv_xcb_p.screensaver_heartbeat_timer_fd = timerfd_create(
349 376 CLOCK_MONOTONIC, TFD_NONBLOCK); CLOCK_MONOTONIC, TFD_NONBLOCK);
350 377 if (npv_xcb_p.screensaver_heartbeat_timer_fd == -1) if (npv_xcb_p.screensaver_heartbeat_timer_fd == -1)
351 FATALX("unable to get a timer file descriptor for the screensaver heartbeat:%s\n", strerror(errno));
378 npv_xcb_fatal("unable to get a timer file descriptor for the screensaver heartbeat:%s\n", strerror(errno));
352 379 } }
353 380 STATIC void npv_xcb_mouse_visibilty_init_once(void) STATIC void npv_xcb_mouse_visibilty_init_once(void)
354 381 { {
 
... ... STATIC void npv_xcb_mouse_visibilty_init_once(void)
358 385 xfixes = npv_dl_xcb_get_extension_data(npv_xcb_p.c, xfixes = npv_dl_xcb_get_extension_data(npv_xcb_p.c,
359 386 npv_dl_xcb_xfixes_id); npv_dl_xcb_xfixes_id);
360 387 if (xfixes->response_type != 1 || xfixes->present == 0) if (xfixes->response_type != 1 || xfixes->present == 0)
361 WARNINGX("the server is missing xfixes extension\n");
388 npv_xcb_warning("the server is missing xfixes extension\n");
362 389 /* the hice/show cursor is supported from version 4 */ /* the hice/show cursor is supported from version 4 */
363 390 npv_dl_xcb_xfixes_query_version(npv_xcb_p.c, 4, 0); npv_dl_xcb_xfixes_query_version(npv_xcb_p.c, 4, 0);
364 391 /*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
 
... ... STATIC void npv_xcb_mouse_visibilty_init_once(void)
370 397 npv_xcb_p.mouse_visibility_timer_fd = timerfd_create(CLOCK_MONOTONIC, npv_xcb_p.mouse_visibility_timer_fd = timerfd_create(CLOCK_MONOTONIC,
371 398 TFD_NONBLOCK); TFD_NONBLOCK);
372 399 if (npv_xcb_p.mouse_visibility_timer_fd == -1) if (npv_xcb_p.mouse_visibility_timer_fd == -1)
373 FATALX("unable to get a timer file descriptor for the mouse visibility management:%s\n", strerror(errno));
400 npv_xcb_fatal("unable to get a timer file descriptor for the mouse visibility management:%s\n", strerror(errno));
374 401 } }
375 402 #define NET_WM_STATE "_NET_WM_STATE" #define NET_WM_STATE "_NET_WM_STATE"
376 403 #define NET_WM_STATE_FULLSCREEN "_NET_WM_STATE_FULLSCREEN" #define NET_WM_STATE_FULLSCREEN "_NET_WM_STATE_FULLSCREEN"
 
... ... STATIC void npv_xcb_fullscreen_action(u32 action)
395 422 reply = npv_dl_xcb_intern_atom_reply(npv_xcb_p.c, cookie_net_wm_state, reply = npv_dl_xcb_intern_atom_reply(npv_xcb_p.c, cookie_net_wm_state,
396 423 &err); &err);
397 424 if (reply == 0) { if (reply == 0) {
398 WARNINGX("unable to set fullscreen:unable to get the _NET_WM_STATE atom:%d\n", err->error_code);
425 npv_xcb_warning("unable to set fullscreen:unable to get the _NET_WM_STATE atom:%d\n", err->error_code);
399 426 free(err); free(err);
400 427 return; return;
401 428 } }
 
... ... STATIC void npv_xcb_fullscreen_action(u32 action)
405 432 reply = npv_dl_xcb_intern_atom_reply(npv_xcb_p.c, reply = npv_dl_xcb_intern_atom_reply(npv_xcb_p.c,
406 433 cookie_net_wm_state_fullscreen, &err); cookie_net_wm_state_fullscreen, &err);
407 434 if (reply == 0) { if (reply == 0) {
408 WARNINGX("unable to set fullscreen:unable to get the _NET_WM_STATE_FULLSCREEN atom:%d\n", err->error_code);
435 npv_xcb_warning("unable to set fullscreen:unable to get the _NET_WM_STATE_FULLSCREEN atom:%d\n", err->error_code);
409 436 free(err); free(err);
410 437 return; return;
411 438 } }
File npv/xcb/main.c changed (mode: 100644) (index 470d0bc..f0e085b)
5 5 * copyright (C) 2020 Sylvain BERTRAND * copyright (C) 2020 Sylvain BERTRAND
6 6 */ */
7 7 #include <stdbool.h> #include <stdbool.h>
8 #include <stdarg.h>
8 9 #include <string.h> #include <string.h>
9 10 #include <stdlib.h> #include <stdlib.h>
10 11 #include <stdio.h> #include <stdio.h>
 
21 22 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
22 23 #include "npv/config.h" #include "npv/config.h"
23 24 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
24 #define FATALX(fmt, ...) FATAL("xcb:" fmt, ##__VA_ARGS__)
25 #define WARNINGX(fmt, ...) WARNING("xcb:" fmt, ##__VA_ARGS__)
26 #define POUTX(fmt, ...) POUT("xcb:" fmt, ##__VA_ARGS__)
27 /*----------------------------------------------------------------------------*/
28 25 #include "npv/xcb/local/state.frag.c" #include "npv/xcb/local/state.frag.c"
29 26 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
30 27 #include "npv/xcb/local/code.frag.c" #include "npv/xcb/local/code.frag.c"
31 28 #include "npv/xcb/public/code.frag.c" #include "npv/xcb/public/code.frag.c"
32 /*----------------------------------------------------------------------------*/
33 #undef FATALX
34 #undef WARNINGX
35 #undef POUTX
36 29 #endif #endif
File npv/xcb/public/code.frag.c changed (mode: 100644) (index 0713bf3..3937c78)
... ... STATIC void npv_xcb_init_once(u16 win_width, u16 win_height,
33 33
34 34 r = npv_dl_xcb_flush(npv_xcb_p.c); r = npv_dl_xcb_flush(npv_xcb_p.c);
35 35 if (r <= 0) if (r <= 0)
36 FATALX("%d:xcb:'%s':connection:%p:screen:%d:root window id:%#x:window id:%#x:unable to flush the connection\n", r, npv_xcb_p.disp_env, npv_xcb_p.c, npv_xcb_p.scr_idx, npv_xcb_p.scr->root, npv_xcb_p.win_id);
37 POUTX("'%s':connection:%p:connection flushed\n", npv_xcb_p.disp_env, npv_xcb_p.c);
36 npv_xcb_fatal("%d:xcb:'%s':connection:%p:screen:%d:root window id:%#x:window id:%#x:unable to flush the connection\n", r, npv_xcb_p.disp_env, npv_xcb_p.c, npv_xcb_p.scr_idx, npv_xcb_p.scr->root, npv_xcb_p.win_id);
37 npv_xcb_pout("'%s':connection:%p:connection flushed\n", npv_xcb_p.disp_env, npv_xcb_p.c);
38 38 npv_xcb_fullscreen_init_once(start_fullscreen); npv_xcb_fullscreen_init_once(start_fullscreen);
39 39 } }
40 40 STATIC void npv_xcb_screensaver_heartbeat_timer_start(void) STATIC void npv_xcb_screensaver_heartbeat_timer_start(void)
 
... ... STATIC void npv_xcb_screensaver_heartbeat_timer_start(void)
47 47 t.it_interval.tv_sec = npv_xcb_screensaver_heartbeat_timeout_s; t.it_interval.tv_sec = npv_xcb_screensaver_heartbeat_timeout_s;
48 48 r = timerfd_settime(npv_xcb_p.screensaver_heartbeat_timer_fd, 0, &t, 0); r = timerfd_settime(npv_xcb_p.screensaver_heartbeat_timer_fd, 0, &t, 0);
49 49 if (r == -1) if (r == -1)
50 FATALX("unable to arm the screensaver heartbeat timer to %u seconds\n", npv_xcb_screensaver_heartbeat_timeout_s);
50 npv_xcb_fatal("unable to arm the screensaver heartbeat timer to %u seconds\n", npv_xcb_screensaver_heartbeat_timeout_s);
51 51 } }
52 52 STATIC void npv_xcb_screensaver_heartbeat_timer_evt(void) STATIC void npv_xcb_screensaver_heartbeat_timer_evt(void)
53 53 { {
 
... ... STATIC void npv_xcb_screensaver_heartbeat_timer_evt(void)
58 58 r = read(npv_xcb_p.screensaver_heartbeat_timer_fd, &exps_n, r = read(npv_xcb_p.screensaver_heartbeat_timer_fd, &exps_n,
59 59 sizeof(exps_n)); sizeof(exps_n));
60 60 if (r == -1) if (r == -1)
61 FATALX("unable to read the number of timer expirations related to the xcb screensaver heartbeat\n");
61 npv_xcb_fatal("unable to read the number of timer expirations related to the xcb screensaver heartbeat\n");
62 62 if (!npv_paused_p) { if (!npv_paused_p) {
63 63 npv_dl_xcb_force_screen_saver(npv_xcb_p.c, npv_dl_xcb_force_screen_saver(npv_xcb_p.c,
64 64 XCB_SCREEN_SAVER_RESET); XCB_SCREEN_SAVER_RESET);
 
... ... STATIC void npv_xcb_mouse_visibility_timer_evt(void)
76 76 exps_n = 0; exps_n = 0;
77 77 r = read(npv_xcb_p.mouse_visibility_timer_fd, &exps_n, sizeof(exps_n)); r = read(npv_xcb_p.mouse_visibility_timer_fd, &exps_n, sizeof(exps_n));
78 78 if (r == -1) if (r == -1)
79 FATALX("unable to read the number of timer expirations related to the xcb mouse visibility\n");
79 npv_xcb_fatal("unable to read the number of timer expirations related to the xcb mouse visibility\n");
80 80 if (npv_xcb_p.mouse_hidden) if (npv_xcb_p.mouse_hidden)
81 81 return; return;
82 82 cookie = npv_dl_xcb_query_pointer(npv_xcb_p.c, npv_xcb_p.win_id); cookie = npv_dl_xcb_query_pointer(npv_xcb_p.c, npv_xcb_p.win_id);
83 83 err = 0; err = 0;
84 84 reply = npv_dl_xcb_query_pointer_reply(npv_xcb_p.c, cookie, &err); reply = npv_dl_xcb_query_pointer_reply(npv_xcb_p.c, cookie, &err);
85 85 if (reply == 0) { if (reply == 0) {
86 WARNINGX("an error occured while handling the mouse pointer visibility:%d\n", err->error_code);
86 npv_xcb_warning("an error occured while handling the mouse pointer visibility:%d\n", err->error_code);
87 87 free(err); free(err);
88 88 return; return;
89 89 } }
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/sylware/nyanmp

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/sylware/nyanmp

Clone this repository using git:
git clone git://git.rocketgit.com/user/sylware/nyanmp

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main