From c5f2644d6eba84bcbcc9b0599c41e1f6733ea95c Mon Sep 17 00:00:00 2001 From: Sylvain BERTRAND Date: Thu, 20 Aug 2020 16:25:50 +0000 Subject: [PATCH] npv:_reasonable_ "pedanticage" of the code --- npv/README | 27 +++-- npv/audio/filt/local/code.frag.c | 71 +++++++++----- npv/audio/filt/main.c | 10 +- npv/audio/filt/namespace/main.c | 6 ++ npv/audio/filt/public/code.frag.c | 42 ++++---- npv/audio/local/code.frag.c | 175 +++++++++++++++++++-------------- npv/audio/main.c | 8 +- npv/audio/namespace/main.c | 6 ++ npv/audio/public/code.frag.c | 74 +++++++------- npv/clk/local/code.frag.c | 10 ++ npv/clk/main.c | 3 +- npv/clk/public/code.frag.c | 16 +-- npv/fmt/local/code.frag.c | 24 ++++- npv/fmt/main.c | 11 +-- npv/fmt/namespace/main.c | 4 + npv/fmt/public/code.frag.c | 16 +-- npv/global.h | 27 +++-- npv/local/code.frag.c | 200 +++++++++++++++++++------------------- npv/main.c | 3 + npv/make-template.sh | 7 ++ npv/namespace/public.h | 18 ++++ npv/pipeline/local/code.frag.c | 32 ++++-- npv/pipeline/main.c | 10 +- npv/pipeline/namespace/main.c | 4 + npv/pipeline/public/code.frag.c | 40 ++++---- npv/pkt_q/local/code.frag.c | 22 ++++- npv/pkt_q/main.c | 8 +- npv/pkt_q/namespace/main.c | 6 +- npv/pkt_q/public/code.frag.c | 8 +- npv/public.h | 19 +++- npv/public/code.frag.c | 88 +++++++++++++++++ npv/thdsws/local/code.frag.c | 30 ++++-- npv/thdsws/main.c | 8 +- npv/thdsws/namespace/main.c | 4 + npv/thdsws/public/code.frag.c | 22 ++--- npv/video/local/code.frag.c | 75 +++++++++++--- npv/video/main.c | 23 +---- npv/video/namespace/main.c | 12 +++ npv/video/public/code.frag.c | 34 +++---- npv/vk/api_usage.h | 18 ++-- npv/vk/local/code.frag.c | 173 +++++++++++++++++---------------- npv/vk/main.c | 2 + npv/vk/namespace/main.c | 2 + npv/vk/namespace/public.h | 8 ++ npv/vk/public.h | 4 + npv/vk/public/code.frag.c | 36 +++++++ npv/xcb/local/code.frag.c | 79 ++++++++++----- npv/xcb/main.c | 9 +- npv/xcb/public/code.frag.c | 12 +-- 49 files changed, 969 insertions(+), 577 deletions(-) create mode 100644 npv/clk/local/code.frag.c rewrite npv/global.h (66%) create mode 100755 npv/make-template.sh create mode 100644 npv/public/code.frag.c diff --git a/npv/README b/npv/README index ae06712..03fd272 100644 --- a/npv/README +++ b/npv/README @@ -3,14 +3,13 @@ "somewhat self-limiting": _without_ lockless and concurrently accessed circular buffers. BUILDING: - configure the key bindings and more in "config.h". this is a "one - compilation unit" project. just compile main.c and link the compiler - output file to your ffmpeg libs, your alsa lib (we should make this - dynamically loaded). the vulkan loader lib and x11 xcb libs will be - dynamically loaded. - you have to define the preprocessor macro STATIC as empty or "static". - you will probably have to define the _GNU_SOURCE macro on most - GNU/Linux systems. + configure the key bindings and more in "config.h". see + make-template.sh: this is a "one compilation unit" project. just + compile main.c and link the compiler output file to your ffmpeg libs, + your alsa lib (we should make this dynamically loaded). the vulkan + loader lib and x11 xcb libs will be dynamically loaded. you have to + define the preprocessor macro static as empty or "static". you will + probably have to define the _gnu_source macro on most gnu/linux systems. HACKING: *.c and *.h files, except the fragments *.frag.c *.frag.h, must "successfully" individually compile (cc -c modulo a few warnings). @@ -69,3 +68,15 @@ HACKING: and helps knowing where things are) - _p suffix is reserved for "public" variable names (namespace noise and helps knowing where things are) +PEDANTIC: + careful of "standards", here iso c. many times "standards" + are, to a certain extend, corporation scams. they want you to depend on + their complexity and then will force you to use their implementations + because it would be nowhere reasonable to reach the same level of + compatibilty with modest development efforts. the best example is being + the hard dependence of linux on gcc (clang, over than 1 decade,is a the + proof that it would be hard). to approach those, a sane way would be to + strip them down to a mimimal usage set. for instance, in iso c, function + pointer and object pointer are not the same at all, due to some broken + or very old hardware architectures (itanium, 8086 real-mode), but "posix + standard" makes those pointers the same. diff --git a/npv/audio/filt/local/code.frag.c b/npv/audio/filt/local/code.frag.c index 4d044b9..d361d3e 100644 --- a/npv/audio/filt/local/code.frag.c +++ b/npv/audio/filt/local/code.frag.c @@ -1,3 +1,30 @@ +STATIC void fatal(u8 *fmt, ...) +{ + va_list ap; + + npv_perr("audio:filter:"); + va_start(ap, fmt); + npv_vfatal(fmt, ap); + va_end(ap); +} +STATIC void warning(u8 *fmt, ...) +{ + va_list ap; + + npv_perr("audio:filter:"); + va_start(ap, fmt); + npv_vwarning(fmt, ap); + va_end(ap); +} +STATIC void pout(u8 *fmt, ...) +{ + va_list ap; + + npv_pout("audio:filter:"); + va_start(ap, fmt); + npv_vpout(fmt, ap); + va_end(ap); +} STATIC void abufsrc_cfg(enum avutil_audio_fr_fmt_t fmt, int rate, int chans_n, uint64_t chans_layout, bool print_info) { @@ -7,20 +34,20 @@ STATIC void abufsrc_cfg(enum avutil_audio_fr_fmt_t fmt, int rate, int chans_n, abufsrc_l = avfilter_get_by_name("abuffer"); if (abufsrc_l == 0) - FATALAF("audio buffer source:could not find the filter\n"); + fatal("audio buffer source:could not find the filter\n"); abufsrc_ctx_l = avfilter_graph_alloc_filt(graph_l, abufsrc_l, "src_abuf"); if (abufsrc_ctx_l == 0) - FATALAF("audio buffer source context:could not allocate the instance in the filter graph\n"); + fatal("audio buffer source context:could not allocate the instance in the filter graph\n"); r = avutil_opt_set(abufsrc_ctx_l, "sample_fmt", avutil_get_audio_fr_fmt_name(fmt), AVUTIL_OPT_SEARCH_CHILDREN); if (r < 0) - FATALAF("audio buffer source context:unable to set the decoder frame format option\n"); + fatal("audio buffer source context:unable to set the decoder frame format option\n"); r = avutil_opt_set_int(abufsrc_ctx_l, "sample_rate", rate, AVUTIL_OPT_SEARCH_CHILDREN); if (r < 0) - FATALAF("audio buffer source context:unable to set the decoder rate option\n"); + fatal("audio buffer source context:unable to set the decoder rate option\n"); /* * XXX: at the time of coding, bug for 1 chans layout... or I did miss * some valuable information @@ -28,14 +55,14 @@ STATIC void abufsrc_cfg(enum avutil_audio_fr_fmt_t fmt, int rate, int chans_n, avutil_get_chans_layout_str(chans_layout_str, sizeof(chans_layout_str), chans_n, chans_layout); if (print_info) - POUTAF("audio buffer source context:using channels layout \"%s\" (%d pcm channels)\n", chans_layout_str, chans_n); + pout("audio buffer source context:using channels layout \"%s\" (%d pcm channels)\n", chans_layout_str, chans_n); r = avutil_opt_set(abufsrc_ctx_l, "channel_layout", chans_layout_str, AVUTIL_OPT_SEARCH_CHILDREN); if (r < 0) - FATALAF("audio buffer source context:unable to set the decoder channel layout option\n"); + fatal("audio buffer source context:unable to set the decoder channel layout option\n"); r = avfilter_init_str(abufsrc_ctx_l, 0); if (r < 0) - FATALAF("audio buffer source context:unable to initialize\n"); + fatal("audio buffer source context:unable to initialize\n"); } STATIC void vol_cfg(bool muted, double vol_cfg) { @@ -45,10 +72,10 @@ STATIC void vol_cfg(bool muted, double vol_cfg) vol_l = avfilter_get_by_name("volume"); if (vol_l == 0) - FATALAF("volume:could not find the filter\n"); + fatal("volume:could not find the filter\n"); vol_ctx_l = avfilter_graph_alloc_filt(graph_l, vol_l, "vol"); if (vol_ctx_l == 0) - FATALAF("volume context:could not allocate the instance in the filter graph\n"); + fatal("volume context:could not allocate the instance in the filter graph\n"); if (muted) vol = 0.0; else @@ -58,10 +85,10 @@ STATIC void vol_cfg(bool muted, double vol_cfg) r = avutil_opt_set(vol_ctx_l, "volume", vol_l10n_str, AVUTIL_OPT_SEARCH_CHILDREN); if (r < 0) - FATALAF("volume context:unable to set the volume option\n"); + fatal("volume context:unable to set the volume option\n"); r = avfilter_init_str(vol_ctx_l, 0); if (r < 0) - FATALAF("volume buffer context:unable to initialize\n"); + fatal("volume buffer context:unable to initialize\n"); } STATIC void afmt_cfg(enum avutil_audio_fr_fmt_t fmt, int rate, int chans_n, uint64_t chans_layout, bool print_info) @@ -72,30 +99,30 @@ STATIC void afmt_cfg(enum avutil_audio_fr_fmt_t fmt, int rate, int chans_n, afmt_l = avfilter_get_by_name("aformat"); if (afmt_l == 0) - FATALAF("audio format:could not find the filter"); + fatal("audio format:could not find the filter"); afmt_ctx_l = avfilter_graph_alloc_filt(graph_l, afmt_l, "afmt"); if (afmt_ctx_l == 0) - FATALAF("audio format:could not allocate the instance in the filter graph\n"); + fatal("audio format:could not allocate the instance in the filter graph\n"); r = avutil_opt_set(afmt_ctx_l, "sample_fmts", avutil_get_audio_fr_fmt_name(fmt), AVUTIL_OPT_SEARCH_CHILDREN); if (r < 0) - FATALAF("audio format context:could to set the pcm sample format\n"); + fatal("audio format context:could to set the pcm sample format\n"); snprintf(rate_str, sizeof(rate_str), "%d", rate); r = avutil_opt_set(afmt_ctx_l, "sample_rates", rate_str, AVUTIL_OPT_SEARCH_CHILDREN); if (r < 0) - FATALAF("audio format context:could not set the pcm rate\n"); + fatal("audio format context:could not set the pcm rate\n"); avutil_get_chans_layout_str(chans_layout_str, sizeof(chans_layout_str), chans_n, chans_layout); r = avutil_opt_set(afmt_ctx_l, "channel_layouts", chans_layout_str, AVUTIL_OPT_SEARCH_CHILDREN); if (r < 0) - FATALAF("audio format context:could not set the layout of channels\n"); + fatal("audio format context:could not set the layout of channels\n"); if (print_info) - POUTAF("audio format context:channel layout is \"%s\"\n", chans_layout_str); + pout("audio format context:channel layout is \"%s\"\n", chans_layout_str); r = avfilter_init_str(afmt_ctx_l, 0); if (r < 0) - FATALAF("audio format context:unable to initialize\n"); + fatal("audio format context:unable to initialize\n"); } STATIC void abufsink_cfg(void) { @@ -103,14 +130,14 @@ STATIC void abufsink_cfg(void) abufsink_l = avfilter_get_by_name("abuffersink"); if (abufsink_l == 0) - FATALAF("audio buffer sink:could not find the filter\n"); + fatal("audio buffer sink:could not find the filter\n"); abufsink_ctx_l = avfilter_graph_alloc_filt(graph_l, abufsink_l, "sink_abuf"); if (abufsink_ctx_l == 0) - FATALAF("audio buffer sink context:could not allocate the instance in the filter graph\n"); + fatal("audio buffer sink context:could not allocate the instance in the filter graph\n"); r = avfilter_init_str(abufsink_ctx_l, 0); if (r < 0) - FATALAF("audio buffer sink context:unable to initialize\n"); + fatal("audio buffer sink context:unable to initialize\n"); } STATIC void init_once_local(void) { @@ -131,7 +158,7 @@ STATIC void init_once_public(double initial_vol) { filt_p.set = avutil_audio_set_ref_alloc(); if (filt_p.set == 0) - FATALAF("ffmpeg:unable to allocate a reference on set of frames for the public part of the interactive latency filter\n"); + fatal("ffmpeg:unable to allocate a reference on set of frames for the public part of the interactive latency filter\n"); filt_p.pcm_written_ufrs_n = 0; filt_p.vol = initial_vol; filt_p.muted = false; diff --git a/npv/audio/filt/main.c b/npv/audio/filt/main.c index ba5aa67..b9e009d 100644 --- a/npv/audio/filt/main.c +++ b/npv/audio/filt/main.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -14,6 +15,7 @@ #include #include "npv/c_fixing.h" #include "npv/global.h" +#include "npv/public.h" #include "npv/audio/public.h" #include "npv/audio/filt/public.h" /*----------------------------------------------------------------------------*/ @@ -24,19 +26,11 @@ #include "npv/audio/filt/namespace/public.h" #include "npv/audio/filt/namespace/main.c" /*----------------------------------------------------------------------------*/ -#define FATALAF(fmt, ...) FATAL("audio:filter:" fmt, ##__VA_ARGS__) -#define WARNINGAF(fmt, ...) WARNING("audio:filter:" fmt, ##__VA_ARGS__) -#define POUTAF(fmt, ...) POUT("audio:filter:" fmt, ##__VA_ARGS__) -/*----------------------------------------------------------------------------*/ #include "npv/audio/filt/local/state.frag.c" #include "npv/audio/filt/local/code.frag.c" /*----------------------------------------------------------------------------*/ #include "npv/audio/filt/public/code.frag.c" /*----------------------------------------------------------------------------*/ -#undef FATALA -#undef POUTA -#undef WARNINGA -/*---------------------------------------------------------------------------*/ #define CLEANUP #include "npv/namespace/ffmpeg.h" #include "npv/audio/namespace/ffmpeg.h" diff --git a/npv/audio/filt/namespace/main.c b/npv/audio/filt/namespace/main.c index d33df01..6b543d4 100644 --- a/npv/audio/filt/namespace/main.c +++ b/npv/audio/filt/namespace/main.c @@ -9,12 +9,15 @@ #define afmt_ctx_l npv_audio_filt_afmt_ctx_l #define afmt_l npv_audio_filt_afmt_l #define double_zero_l10n_str_l npv_audio_filt_double_zero_l10n_str_l +#define fatal npv_audio_filt_fatal #define graph_l npv_audio_filt_graph_l #define init_once_local npv_audio_filt_init_once_local #define init_once_public npv_audio_filt_init_once_public +#define pout npv_audio_filt_pout #define vol_cfg npv_audio_filt_vol_cfg #define vol_ctx_l npv_audio_filt_vol_ctx_l #define vol_l npv_audio_filt_vol_l +#define warning npv_audio_filt_warning /*============================================================================*/ #else #undef abufsink_cfg @@ -27,10 +30,13 @@ #undef afmt_ctx_l #undef afmt_l #undef double_zero_l10n_str_l +#undef fatal #undef graph_l #undef init_once_local #undef init_once_public +#undef pout #undef vol_cfg #undef vol_ctx_l #undef vol_l +#undef warning #endif diff --git a/npv/audio/filt/public/code.frag.c b/npv/audio/filt/public/code.frag.c index 5578e6c..9fb7eae 100644 --- a/npv/audio/filt/public/code.frag.c +++ b/npv/audio/filt/public/code.frag.c @@ -15,8 +15,8 @@ STATIC u8 filt_push_dec_sets(void) 0, AVFILTER_BUFSRC_FLAG_PUSH | AVFILTER_BUFSRC_FLAG_KEEP_REF); if (ri < 0) - FATALAF("ffmpeg:unable to notify the end of data to the filter source audio buffer context\n"); - POUTAF("ffmpeg:interactive filter switched to draining\n"); + fatal("ffmpeg:unable to notify the end of data to the filter source audio buffer context\n"); + pout("ffmpeg:interactive filter switched to draining\n"); r8 = FILT_SWITCHED_TO_DRAINING; goto unlock; } @@ -44,7 +44,7 @@ STATIC u8 filt_push_dec_sets(void) r8 = AGAIN; goto unlock; } - FATALAF("ffmpeg:unable to submit a decoder set of frames to the filter source audio buffer context\n"); + fatal("ffmpeg:unable to submit a decoder set of frames to the filter source audio buffer context\n"); unlock: npv_audio_dec_sets_unlock(); return r8; @@ -73,7 +73,7 @@ STATIC u8 filt_set_try_get(void) } else if (r == AVUTIL_AVERROR_EOF) { return EOF_FILT; } - FATALAF("ffmpeg:error while getting frames from the filter\n"); + fatal("ffmpeg:error while getting frames from the filter\n"); } #undef AGAIN #undef HAVE_FILT_SET @@ -118,7 +118,7 @@ STATIC void cfg(enum avutil_audio_fr_fmt_t src_fmt, int src_rate, graph_l = avfilter_graph_alloc(); if (graph_l == 0) - FATALAF("unable to create filter graph\n"); + fatal("unable to create filter graph\n"); abufsrc_cfg(src_fmt, src_rate, src_chans_n, src_chans_layout, print_info); vol_cfg(muted, vol); @@ -126,28 +126,28 @@ STATIC void cfg(enum avutil_audio_fr_fmt_t src_fmt, int src_rate, abufsink_cfg(); r = avfilter_link(abufsrc_ctx_l, 0, vol_ctx_l, 0); if (r < 0) - FATALAF("unable to connect the audio buffer source filter to the volume filter\n"); + fatal("unable to connect the audio buffer source filter to the volume filter\n"); r = avfilter_link(vol_ctx_l, 0, afmt_ctx_l, 0); if (r < 0) - FATALAF("unable to connect the volume filter to the audio format filter\n"); + fatal("unable to connect the volume filter to the audio format filter\n"); r = avfilter_link(afmt_ctx_l, 0, abufsink_ctx_l, 0); if (r < 0) - FATALAF("unable to connect the audio format filter to the audio buffer sink filter\n"); + fatal("unable to connect the audio format filter to the audio buffer sink filter\n"); r = avfilter_graph_config(graph_l, 0); if (r < 0) - FATALAF("unable to configure the filter graph\n"); + fatal("unable to configure the filter graph\n"); /*--------------------------------------------------------------------*/ if (!print_info) return; dump_str = avfilter_graph_dump(graph_l, 0); if (dump_str == 0) { - WARNINGAF("unable to get a filter graph description\n"); + warning("unable to get a filter graph description\n"); return; } - POUTAF("GRAPH START-------------------------------------------------------\n"); - POUT("%s", dump_str); + pout("GRAPH START-------------------------------------------------------\n"); + npv_pout("%s", dump_str); avutil_free(dump_str); - POUTAF("GRAPH END---------------------------------------------------------\n"); + pout("GRAPH END---------------------------------------------------------\n"); } STATIC void npv_audio_filt_cmd_mute(void) { @@ -156,23 +156,23 @@ STATIC void npv_audio_filt_cmd_mute(void) u8 resp[STR_SZ]; if (filt_p.muted) { - POUTAF("COMMAND:unmuting\n"); + pout("COMMAND:unmuting\n"); snprintf(vol_l10n_str, sizeof(vol_l10n_str), "%f", filt_p.vol); r = avfilter_graph_send_cmd(graph_l, "vol", "volume", vol_l10n_str, resp, sizeof(resp), 0); if (r < 0) { - WARNINGAF("ffmpeg:volume context:unable to mute the volume to 0:response from volume filter:%s\n", resp); + warning("ffmpeg:volume context:unable to mute the volume to 0:response from volume filter:%s\n", resp); } else { filt_p.muted = false; } } else { - POUTAF("COMMAND:muting\n"); + pout("COMMAND:muting\n"); r = avfilter_graph_send_cmd(graph_l, "vol", "volume", double_zero_l10n_str_l, resp, sizeof(resp), 0); if (r < 0) { - WARNINGAF("ffmpeg:volume context:unable to mute the volume to 0:response from volume filter:%s\n", resp); + warning("ffmpeg:volume context:unable to mute the volume to 0:response from volume filter:%s\n", resp); } else { filt_p.muted = true; } @@ -188,12 +188,12 @@ STATIC void npv_audio_filt_cmd_vol_down(void) if (filt_p.vol < 0.) filt_p.vol = 0.; snprintf(vol_l10n_str, sizeof(vol_l10n_str), "%f", filt_p.vol); - POUTAF("COMMAND:volume down to value %s\n", vol_l10n_str); + pout("COMMAND:volume down to value %s\n", vol_l10n_str); if (!filt_p.muted) { r = avfilter_graph_send_cmd(graph_l, "vol", "volume", vol_l10n_str, resp, sizeof(resp), 0); if (r < 0) - WARNINGAF("ffmpeg:volume context:unable to set the volume down to \"%s\":response from volume filter:\"%s\"\n", resp); + warning("ffmpeg:volume context:unable to set the volume down to \"%s\":response from volume filter:\"%s\"\n", resp); } } STATIC void npv_audio_filt_cmd_vol_up(void) @@ -206,11 +206,11 @@ STATIC void npv_audio_filt_cmd_vol_up(void) if (filt_p.vol > 1.) filt_p.vol = 1.; snprintf(vol_l10n_str, sizeof(vol_l10n_str), "%f", filt_p.vol); - POUTAF("COMMAND:volume up to value %s\n", vol_l10n_str); + pout("COMMAND:volume up to value %s\n", vol_l10n_str); if (!filt_p.muted) { r = avfilter_graph_send_cmd(graph_l, "vol", "volume", vol_l10n_str, resp, sizeof(resp), 0); if (r < 0) - WARNINGAF("ffmpeg:volume context:unable to set the volume up to \"%s\":response from volume filter:\"%s\"\n", resp); + warning("ffmpeg:volume context:unable to set the volume up to \"%s\":response from volume filter:\"%s\"\n", resp); } } diff --git a/npv/audio/local/code.frag.c b/npv/audio/local/code.frag.c index 5b27e36..fe5fda0 100644 --- a/npv/audio/local/code.frag.c +++ b/npv/audio/local/code.frag.c @@ -1,3 +1,30 @@ +STATIC void fatal(u8 *fmt, ...) +{ + va_list ap; + + npv_perr("audio:"); + va_start(ap, fmt); + npv_vfatal(fmt, ap); + va_end(ap); /* unreachable */ +} +STATIC void warning(u8 *fmt, ...) +{ + va_list ap; + + npv_perr("audio:"); + va_start(ap, fmt); + npv_vwarning(fmt, ap); + va_end(ap); +} +STATIC void pout(u8 *fmt, ...) +{ + va_list ap; + + npv_pout("audio:"); + va_start(ap, fmt); + npv_vpout(fmt, ap); + va_end(ap); +} STATIC bool ff_fmt2pcm_layout_best_effort(enum avutil_audio_fr_fmt_t ff_fmt, snd_pcm_fmt_t *alsa_fmt, snd_pcm_access_t *alsa_access) { @@ -40,10 +67,10 @@ STATIC bool ff_fmt2pcm_layout_best_effort(enum avutil_audio_fr_fmt_t ff_fmt, *alsa_access = SND_PCM_ACCESS_RW_NONINTERLEAVED; break; default: - POUTA("best effort:unable to wire ffmpeg sample format \"%sbits\" to alsa sample format, \n,", ff_fmt_str); + pout("best effort:unable to wire ffmpeg sample format \"%sbits\" to alsa sample format, \n,", ff_fmt_str); return false; } - 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)); + 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)); return true; } STATIC void pcm_hw_chans_n_decide(snd_pcm_t *pcm, @@ -57,38 +84,38 @@ STATIC void pcm_hw_chans_n_decide(snd_pcm_t *pcm, if (r == 0) { r = snd_pcm_hw_params_set_chans_n(pcm, pcm_hw_params, chans_n); if (r != 0) - FATALA("alsa:unable to restrict pcm device to %u channels, count which was successfully tested\n", chans_n); - POUTA("alsa:using %u channels\n", chans_n); + fatal("alsa:unable to restrict pcm device to %u channels, count which was successfully tested\n", chans_n); + pout("alsa:using %u channels\n", chans_n); return; } - POUTA("alsa:unable to use %u channels\n", chans_n); + pout("alsa:unable to use %u channels\n", chans_n); /* try to use the max chans n the pcm can */ r = snd_pcm_hw_params_get_chans_n_max(pcm_hw_params, &chans_n_max); if (r != 0) - FATALA("alsa:unable to get the maximum count of pcm device channels\n"); + fatal("alsa:unable to get the maximum count of pcm device channels\n"); r = snd_pcm_hw_params_test_chans_n(pcm, pcm_hw_params, chans_n_max); if (r == 0) { r = snd_pcm_hw_params_set_chans_n(pcm, pcm_hw_params, chans_n_max); if (r != 0) - FATALA("alsa:unable to restrict pcm device to %u channels, count which was successfully tested\n", chans_n_max); - POUTA("alsa:using pcm maximum %u channels\n", chans_n_max); + fatal("alsa:unable to restrict pcm device to %u channels, count which was successfully tested\n", chans_n_max); + pout("alsa:using pcm maximum %u channels\n", chans_n_max); return; } /* ok... last try, the pcm dev min chans n */ r = snd_pcm_hw_params_get_chans_n_min(pcm_hw_params, &chans_n_min); if (r != 0) - FATALA("alsa:unable to get the minimum count of pcm device channels\n"); + fatal("alsa:unable to get the minimum count of pcm device channels\n"); r = snd_pcm_hw_params_test_chans_n(pcm, pcm_hw_params, chans_n_min); if (r == 0) { r = snd_pcm_hw_params_set_chans_n(pcm, pcm_hw_params, chans_n_min); if (r != 0) - FATALA("alsa:unable to restrict pcm device to %u channels, count which was successfully tested\n", chans_n_min); - POUTA("alsa:using pcm device minimum %u channels\n", chans_n_min); + fatal("alsa:unable to restrict pcm device to %u channels, count which was successfully tested\n", chans_n_min); + pout("alsa:using pcm device minimum %u channels\n", chans_n_min); return; } - FATALA("alsa:unable to find a suitable count of channels\n"); + fatal("alsa:unable to find a suitable count of channels\n"); } STATIC void pcm_hw_rate_decide(snd_pcm_t *pcm, snd_pcm_hw_params_t *pcm_hw_params, unsigned int rate) @@ -104,24 +131,24 @@ STATIC void pcm_hw_rate_decide(snd_pcm_t *pcm, r = snd_pcm_hw_params_set_rate(pcm, pcm_hw_params, rate, SND_PCM_ST_PLAYBACK); if (r != 0) - FATALA("alsa:unable to restrict pcm device to %uHz, which was successfully tested\n", rate); - POUTA("alsa:using %uHz\n", rate); + fatal("alsa:unable to restrict pcm device to %uHz, which was successfully tested\n", rate); + pout("alsa:using %uHz\n", rate); return; } - POUTA("alsa:unable to use %uHz\n", rate); + pout("alsa:unable to use %uHz\n", rate); /* try to use the max rate the pcm can */ r = snd_pcm_hw_params_get_rate_max(pcm_hw_params, &rate_max, SND_PCM_ST_PLAYBACK); if (r != 0) - FATALA("alsa:unable to get the maximum rate of pcm device\n"); + fatal("alsa:unable to get the maximum rate of pcm device\n"); r = snd_pcm_hw_params_test_rate(pcm, pcm_hw_params, rate_max, SND_PCM_ST_PLAYBACK); if (r == 0) { r = snd_pcm_hw_params_set_rate(pcm, pcm_hw_params, rate_max, SND_PCM_ST_PLAYBACK); if (r != 0) - FATALA("alsa:unable to restrict pcm device to %uHz, which was successfully tested\n", rate_max); - POUTA("alsa:using pcm device %uHz\n", rate_max); + fatal("alsa:unable to restrict pcm device to %uHz, which was successfully tested\n", rate_max); + pout("alsa:using pcm device %uHz\n", rate_max); return; } /* try to use a rate "near" of what the pcm dev can */ @@ -129,25 +156,25 @@ STATIC void pcm_hw_rate_decide(snd_pcm_t *pcm, r = snd_pcm_hw_params_set_rate_near(pcm, pcm_hw_params, &rate_near, SND_PCM_ST_PLAYBACK); if (r == 0) { - POUTA("alsa:using pcm device %uHz\n", rate_near); + pout("alsa:using pcm device %uHz\n", rate_near); return; } /* even a "near" rate did failed... try the min */ r = snd_pcm_hw_params_get_rate_min(pcm_hw_params, &rate_min, SND_PCM_ST_PLAYBACK); if (r != 0) - FATALA("alsa:unable to get the minimum rate of pcm device\n"); + fatal("alsa:unable to get the minimum rate of pcm device\n"); r = snd_pcm_hw_params_test_rate(pcm, pcm_hw_params, rate_min, SND_PCM_ST_PLAYBACK); if (r == 0) { r = snd_pcm_hw_params_set_rate(pcm, pcm_hw_params, rate_min, SND_PCM_ST_PLAYBACK); if (r != 0) - FATALA("alsa:unable to restrict pcm device to %uHz, which was successfully tested\n", rate_min); - POUTA("alsa:using pcm device %uHz\n", rate_min); + fatal("alsa:unable to restrict pcm device to %uHz, which was successfully tested\n", rate_min); + pout("alsa:using pcm device %uHz\n", rate_min); return; } - FATALA("alsa:unable to find a suitable rate\n"); + fatal("alsa:unable to find a suitable rate\n"); } STATIC bool pcm_hw_fmt_decide_x(snd_pcm_t *pcm, snd_pcm_hw_params_t *pcm_hw_params, snd_pcm_fmt_t fmt) @@ -159,8 +186,8 @@ STATIC bool pcm_hw_fmt_decide_x(snd_pcm_t *pcm, return false; r = snd_pcm_hw_params_set_fmt(pcm, pcm_hw_params, fmt); if (r != 0) - FATALA("alsa:unable to restrict pcm device to \"%s\", which was successfully tested\n", snd_pcm_fmt_desc(fmt)); - POUTA("alsa:using \"%s\" format\n", snd_pcm_fmt_desc(fmt)); + fatal("alsa:unable to restrict pcm device to \"%s\", which was successfully tested\n", snd_pcm_fmt_desc(fmt)); + pout("alsa:using \"%s\" format\n", snd_pcm_fmt_desc(fmt)); return true; } #define PCM_HW_FMT_DECIDE_X(fmt) pcm_hw_fmt_decide_x(pcm, pcm_hw_params, fmt) @@ -177,8 +204,8 @@ STATIC void pcm_hw_fmt_decide(snd_pcm_t *pcm, r = snd_pcm_hw_params_set_fmt(pcm, pcm_hw_params, forced_fmt); if (r != 0) - FATALA("alsa:unable to restrict pcm device to \"%s\", which was successfully tested\n", snd_pcm_fmt_desc(forced_fmt)); - POUTA("alsa:using forced \"%s\" format\n", snd_pcm_fmt_desc(forced_fmt)); + fatal("alsa:unable to restrict pcm device to \"%s\", which was successfully tested\n", snd_pcm_fmt_desc(forced_fmt)); + pout("alsa:using forced \"%s\" format\n", snd_pcm_fmt_desc(forced_fmt)); return; } } @@ -206,7 +233,7 @@ STATIC void pcm_hw_fmt_decide(snd_pcm_t *pcm, return; if (PCM_HW_FMT_DECIDE_X(SND_PCM_FMT_S8)) return; - FATALA("alsa:unable to find a suitable format\n"); + fatal("alsa:unable to find a suitable format\n"); } #undef PCM_HW_FMT_DECIDE_X STATIC bool pcm_hw_access_decide_x(snd_pcm_t *pcm, @@ -219,8 +246,8 @@ STATIC bool pcm_hw_access_decide_x(snd_pcm_t *pcm, return false; r = snd_pcm_hw_params_set_access(pcm, pcm_hw_params, access); if (r != 0) - FATALA("alsa:unable to restrict pcm device to \"%s\", which was successfully tested\n", snd_pcm_access_name(access)); - POUTA("alsa:using \"%s\" access\n", snd_pcm_access_name(access)); + fatal("alsa:unable to restrict pcm device to \"%s\", which was successfully tested\n", snd_pcm_access_name(access)); + pout("alsa:using \"%s\" access\n", snd_pcm_access_name(access)); return true; } #define PCM_HW_ACCESS_DECIDE_X(access) \ @@ -240,8 +267,8 @@ STATIC void pcm_hw_access_decide(snd_pcm_t *pcm, r = snd_pcm_hw_params_set_access(pcm, pcm_hw_params, forced_access); if (r != 0) - FATALA("alsa:unable to restrict pcm device to \"%s\", which was successfully tested\n", snd_pcm_access_name(forced_access)); - POUTA("alsa:using forced \"%s\" access\n", snd_pcm_access_name(forced_access)); + fatal("alsa:unable to restrict pcm device to \"%s\", which was successfully tested\n", snd_pcm_access_name(forced_access)); + pout("alsa:using forced \"%s\" access\n", snd_pcm_access_name(forced_access)); return; } } @@ -250,7 +277,7 @@ STATIC void pcm_hw_access_decide(snd_pcm_t *pcm, return; if (PCM_HW_ACCESS_DECIDE_X(SND_PCM_ACCESS_RW_NONINTERLEAVED)) return; - FATALA("alsa:unable to find a suitable access\n"); + fatal("alsa:unable to find a suitable access\n"); } #undef PCM_HW_ACCESS_DECIDE_X /* @@ -273,7 +300,7 @@ STATIC void pcm_hw_buf_sz_cfg(snd_pcm_t *pcm, r = snd_pcm_hw_params_get_rate(pcm_hw_params, &rate, 0); if (r < 0) { - WARNINGA("alsa:latency control:DISABLING LATENCY CONTROL:unable to get the decided rate from the current device parameters\n"); + warning("alsa:latency control:DISABLING LATENCY CONTROL:unable to get the decided rate from the current device parameters\n"); return; } latency_control_target_buf_ufrs_n = (snd_pcm_ufrs_t)rate; @@ -282,10 +309,10 @@ STATIC void pcm_hw_buf_sz_cfg(snd_pcm_t *pcm, r = snd_pcm_hw_params_set_buf_sz_near(pcm, pcm_hw_params, &latency_control_buf_ufrs_n); if (r < 0) { - 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); + 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); return; } - 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); + 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); } /* * this function will "decide" the pcm dev cfg: @@ -308,7 +335,7 @@ STATIC void pcm_cfg_hw_core(snd_pcm_t *pcm, snd_pcm_hw_params_t *pcm_hw_params, /* the return value is from a first refine of the raw hw params */ r = snd_pcm_hw_params_any(pcm, pcm_hw_params); if (r < 0) - FATALA("alsa:unable to populate the hardware parameters context\n"); + fatal("alsa:unable to populate the hardware parameters context\n"); pcm_hw_chans_n_decide(pcm, pcm_hw_params, (unsigned int)chans_n); pcm_hw_rate_decide(pcm, pcm_hw_params, (unsigned int)rate); /* try our best */ @@ -337,19 +364,19 @@ STATIC void pcm_cfg_hw(snd_pcm_t *pcm, unsigned int chans_n, unsigned int rate, snd_pcm_access_t access; snd_pcm_hw_params_t *hw_params; - POUTA("ALSA:HW_PARAMS START------------------------------------------------------------\n"); + pout("ALSA:HW_PARAMS START------------------------------------------------------------\n"); r = snd_pcm_hw_params_malloc(&hw_params); if (r < 0) - FATALA("alsa:unable to allocate hardware parameters context\n"); + fatal("alsa:unable to allocate hardware parameters context\n"); pcm_cfg_hw_core(pcm, hw_params, chans_n, rate, ff_fmt); r = snd_pcm_hw_params(pcm, hw_params); if (r != 0) - FATALA("alsa:unable to install the hardware parameters\n"); + fatal("alsa:unable to install the hardware parameters\n"); r = snd_pcm_hw_params_current(pcm, hw_params); if (r != 0) - FATALA("alsa:unable to get current hardware parameters\n"); + fatal("alsa:unable to get current hardware parameters\n"); snd_pcm_hw_params_dump(hw_params, pcm_pout_l); i = 0; @@ -360,7 +387,7 @@ STATIC void pcm_cfg_hw(snd_pcm_t *pcm, unsigned int chans_n, unsigned int rate, r = snd_pcm_hw_params_supports_audio_ts_type(hw_params, i); if (r == 1) { selected_ts_type_p = i; - POUTA("kernel audio timestamp type \"%s\" is supported for the current configuration\n", kernel_ts_types_str[i]); + pout("kernel audio timestamp type \"%s\" is supported for the current configuration\n", kernel_ts_types_str[i]); } ++i; } @@ -368,36 +395,36 @@ STATIC void pcm_cfg_hw(snd_pcm_t *pcm, unsigned int chans_n, unsigned int rate, * we selected the most accurate, namely with the highest idx, audio ts * type */ - POUTA("%s will be used for the audio based clock\n", kernel_ts_types_str[selected_ts_type_p]); + pout("%s will be used for the audio based clock\n", kernel_ts_types_str[selected_ts_type_p]); snd_pcm_hw_params_free(hw_params); - POUTA("ALSA:HW_PARAMS END--------------------------------------------------------------\n"); + pout("ALSA:HW_PARAMS END--------------------------------------------------------------\n"); } STATIC void pcm_cfg_sw(snd_pcm_t *pcm) { int r; snd_pcm_sw_params_t *sw_params; - POUTA("ALSA:SW_PARAMS START------------------------------------------------------------\n"); + pout("ALSA:SW_PARAMS START------------------------------------------------------------\n"); r = snd_pcm_sw_params_malloc(&sw_params); if (r != 0) - FATALA("alsa:unable to allocate software parameters structure\n"); + fatal("alsa:unable to allocate software parameters structure\n"); r = snd_pcm_sw_params_current(pcm, sw_params); if (r != 0) - FATALA("alsa:unable to get current software parameters\n"); + fatal("alsa:unable to get current software parameters\n"); r = snd_pcm_sw_params_set_period_evt(pcm, sw_params, 1); if (r != 0) - FATALA("alsa:unable to enable period event\n"); + fatal("alsa:unable to enable period event\n"); /* enable ts to be sure */ r = snd_pcm_sw_params_set_tstamp_mode(pcm, sw_params, SND_PCM_TSTAMP_ENABLE); if (r < 0) - FATALA("unable to set timestamp mode:%s\n", snd_strerror(r)); + fatal("unable to set timestamp mode:%s\n", snd_strerror(r)); r = snd_pcm_sw_params(pcm, sw_params); if (r != 0) - FATALA("alsa:unable to install sotfware parameters\n"); + fatal("alsa:unable to install sotfware parameters\n"); snd_pcm_sw_params_dump(sw_params, pcm_pout_l); snd_pcm_sw_params_free(sw_params); - POUTA("ALSA:SW_PARAMS END--------------------------------------------------------------\n"); + pout("ALSA:SW_PARAMS END--------------------------------------------------------------\n"); } STATIC void dec_a_grow(void) { @@ -407,10 +434,10 @@ STATIC void dec_a_grow(void) dec_sets_p.a = realloc(dec_sets_p.a, sizeof(*dec_sets_p.a) * (dec_sets_p.n_max + 1)); if (dec_sets_p.a == 0) - FATALA("unable to allocate memory for an additional pointer on a reference of a decoder set of frames\n"); + fatal("unable to allocate memory for an additional pointer on a reference of a decoder set of frames\n"); dec_sets_p.a[new_idx] = avutil_audio_set_ref_alloc(); if (dec_sets_p.a[new_idx] == 0) - FATALA("ffmpeg:unable to allocate a reference of a decoder set of frames\n"); + fatal("ffmpeg:unable to allocate a reference of a decoder set of frames\n"); ++dec_sets_p.n_max; } #define AGAIN 0 @@ -429,12 +456,12 @@ STATIC u8 alsa_recover(snd_pcm_sfrs_t r) r_recovered = snd_pcm_recover(pcm_p, (int)r, 0); if (r_recovered == 0) { - WARNINGA("alsa:pcm recovered\n"); + warning("alsa:pcm recovered\n"); return RECOVERED; } - FATALA("alsa:unable to recover from suspend/underrun\n"); + fatal("alsa:unable to recover from suspend/underrun\n"); } - FATALA("alsa:fatal/unhandled error\n"); + fatal("alsa:fatal/unhandled error\n"); } #undef AGAIN #undef RECOVERED @@ -541,10 +568,10 @@ STATIC void draining_state_handle(void) */ state = snd_pcm_state(pcm_p); if (state != SND_PCM_STATE_SETUP) - FATALA("alsa:an error occured switching to/checking the pcm draining state\n"); + fatal("alsa:an error occured switching to/checking the pcm draining state\n"); /* here pcm state is SND_PCM_STATE_SETUP */ } - EXIT("alsa pcm drained or similar, exiting\n"); + npv_exit("alsa pcm drained or similar, exiting\n"); } STATIC void draining_state_switch(void) { @@ -563,7 +590,7 @@ STATIC void draining_state_switch(void) r = epoll_ctl(npv_ep_fd_p, EPOLL_CTL_DEL, pcm_pollfds_p[i].fd, 0); if (r == -1) - FATALA("unable to remove the alsa file descriptors from epoll\n"); + fatal("unable to remove the alsa file descriptors from epoll\n"); ++i; } /* start the draining timer */ @@ -573,7 +600,7 @@ STATIC void draining_state_switch(void) t.it_interval.tv_nsec = DRAINING_TIMER_INTERVAL_NSECS_N; r = timerfd_settime(draining_timer_fd_p, 0, &t, 0); if (r == -1) - FATALA("unable to arm the draining timer\n"); + fatal("unable to arm the draining timer\n"); } #define NO 0 #define AGAIN 0 @@ -713,14 +740,14 @@ STATIC void pcm_layout2ff_fmt_strict(snd_pcm_fmt_t alsa_fmt, *ff_fmt = AVUTIL_AUDIO_FR_FMT_U8P; break; default: - 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)); + 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)); } if (print_info) { u8 ff_fmt_str[STR_SZ]; avutil_get_audio_fr_fmt_str(ff_fmt_str, sizeof(ff_fmt_str), *ff_fmt); - 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); + 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); } } /* @@ -738,17 +765,17 @@ STATIC uint64_t pcm_chmaps2ff_chans_layout(snd_pcm_t *pcm, pcm_chmap = snd_pcm_get_chmap(pcm); if (pcm_chmap == 0) { if (print_info) - POUTA("alsa:no pcm channel map available, wiring to default ffmpeg channel layout\n"); + pout("alsa:no pcm channel map available, wiring to default ffmpeg channel layout\n"); } else { if (print_info) - POUTA("alsa:your pcm device support channel maps, but fine granularity wiring strategy is not implemented\n"); + pout("alsa:your pcm device support channel maps, but fine granularity wiring strategy is not implemented\n"); free(pcm_chmap); } ff_chans_layout = avutil_get_default_chans_layout((int)pcm_chans_n); avutil_get_chans_layout_str(chans_layout_str, sizeof(chans_layout_str), (int)pcm_chans_n, ff_chans_layout); if (print_info) - POUTA("alsa channel map wired to ffmpeg channel layout:\"%s\" (%u pcm channels)\n", chans_layout_str, pcm_chans_n); + pout("alsa channel map wired to ffmpeg channel layout:\"%s\" (%u pcm channels)\n", chans_layout_str, pcm_chans_n); return ff_chans_layout; } STATIC void init_pcm_once_public(u8 *pcm_str) @@ -759,15 +786,15 @@ STATIC void init_pcm_once_public(u8 *pcm_str) SND_PCM_NONBLOCK); if (r < 0) { if (r == -EAGAIN) - FATALA("alsa:\"%s\" pcm is already in use\n", pcm_str); + fatal("alsa:\"%s\" pcm is already in use\n", pcm_str); else - FATALA("alsa:unable to open \"%s\" pcm for playback\n", pcm_str); + fatal("alsa:unable to open \"%s\" pcm for playback\n", pcm_str); } r = snd_pcm_poll_descriptors_n(pcm_p); - POUTA("alsa:have %d poll file descriptors\n", r); + pout("alsa:have %d poll file descriptors\n", r); if ((r <= 0) || (r > pcm_pollfds_n_max)) - FATALA("alsa:invalid count of alsa poll file descriptors\n"); + fatal("alsa:invalid count of alsa poll file descriptors\n"); pcm_pollfds_n_p =(u8)r; memset(pcm_pollfds_p, 0, sizeof(pcm_pollfds_p)); snd_pcm_poll_descriptors(pcm_p, pcm_pollfds_p, pcm_pollfds_n_max); @@ -789,14 +816,14 @@ STATIC void init_once_public(u8 *pcm_str) errno = 0; draining_timer_fd_p = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK); if (draining_timer_fd_p == -1) - FATALA("unable to get a draining timer file descriptor:%s\n", strerror(errno)); + fatal("unable to get a draining timer file descriptor:%s\n", strerror(errno)); draining_p = false; r = pthread_mutex_init(&dec_ctx_mutex_l, 0); if (r != 0) - FATALA("%d:unable to init the decoder mutex\n", r); + fatal("%d:unable to init the decoder mutex\n", r); r = pthread_mutex_init(&dec_sets_p.mutex, 0); if (r != 0) - FATALA("%d:unable to init the mutex for the array of decoder sets\n", r); + fatal("%d:unable to init the mutex for the array of decoder sets\n", r); } STATIC void init_once_local(void) { @@ -805,10 +832,10 @@ STATIC void init_once_local(void) dec_l = 0; r = snd_output_stdio_attach(&pcm_pout_l, stdout, 0); if (r < 0) - FATALA("alsa:unable to attach stdout\n"); + fatal("alsa:unable to attach stdout\n"); r = snd_output_stdio_attach(&pcm_perr_l, stderr, 0); if (r < 0) - FATALA("alsa:unable to attach stderr\n"); + fatal("alsa:unable to attach stderr\n"); memset(pcm_silence_bufs_l, 0, sizeof(pcm_silence_bufs_l)); } STATIC void dec_a_unref_all(void) diff --git a/npv/audio/main.c b/npv/audio/main.c index e320148..fa7c5bd 100644 --- a/npv/audio/main.c +++ b/npv/audio/main.c @@ -6,6 +6,7 @@ */ #include #include +#include #include #include #include @@ -45,10 +46,6 @@ * silence bufs */ /*----------------------------------------------------------------------------*/ -#define FATALA(fmt, ...) FATAL("audio:" fmt, ##__VA_ARGS__) -#define WARNINGA(fmt, ...) WARNING("audio:" fmt, ##__VA_ARGS__) -#define POUTA(fmt, ...) POUT("audio:" fmt, ##__VA_ARGS__) -/*----------------------------------------------------------------------------*/ #define DRAINING_TIMER_INTERVAL_NSECS_N 100000000 /* 0.1 sec */ /*----------------------------------------------------------------------------*/ #include "npv/audio/local/state.frag.c" @@ -56,9 +53,6 @@ #include "npv/audio/local/code.frag.c" #include "npv/audio/public/code.frag.c" /*----------------------------------------------------------------------------*/ -#undef FATALA -#undef POUTA -#undef WARNINGA #undef DRAINING_TIMER_INTERVAL_NSECS_N /*---------------------------------------------------------------------------*/ #define CLEANUP diff --git a/npv/audio/namespace/main.c b/npv/audio/namespace/main.c index 8b235ea..a374f68 100644 --- a/npv/audio/namespace/main.c +++ b/npv/audio/namespace/main.c @@ -9,6 +9,7 @@ #define dec_l npv_audio_dec_l #define draining_state_handle npv_audio_draining_state_handle #define draining_state_switch npv_audio_draining_state_switch +#define fatal npv_audio_fatal #define ff_fmt2pcm_layout_best_effort npv_audio_ff_fmt2pcm_layout_best_effort #define filt_push_dec_sets npv_audio_filt_push_dec_sets #define init_once_local npv_audio_init_once_local @@ -33,6 +34,8 @@ #define pcm_perr_l npv_audio_pcm_perr_l #define pcm_silence_bufs_l npv_audio_pcm_silence_bufs_l #define pcm_silence_frs_write npv_audio_pcm_silence_frs_write +#define pout npv_audio_pout +#define warning npv_audio_warning /*============================================================================*/ #else #undef alsa_recover @@ -45,6 +48,7 @@ #undef dec_flush #undef draining_state_handle #undef draining_state_switch +#undef fatal #undef ff_fmt2pcm_layout_best_effort #undef filt_push_dec_sets #undef init_once_local @@ -69,4 +73,6 @@ #undef pcm_perr_l #undef pcm_silence_bufs_l #undef pcm_silence_frs_write +#undef pout +#undef warning #endif diff --git a/npv/audio/public/code.frag.c b/npv/audio/public/code.frag.c index aff40c1..bbd0bc9 100644 --- a/npv/audio/public/code.frag.c +++ b/npv/audio/public/code.frag.c @@ -4,20 +4,20 @@ STATIC void dec_ctx_cfg(avcodec_params_t *params) dec_l = avcodec_find_dec(params->codec_id); if (dec_l == 0) - FATALA("ffmpeg:unable to find a proper decoder\n"); + fatal("ffmpeg:unable to find a proper decoder\n"); avcodec_free_context(&dec_ctx_p); dec_ctx_p = avcodec_alloc_ctx(dec_l); if (dec_ctx_p == 0) - FATALA("ffmpeg:unable to allocate a decoder context\n"); + fatal("ffmpeg:unable to allocate a decoder context\n"); /* XXX: useless ? */ r = avcodec_params_to_ctx(dec_ctx_p, params); if (r < 0) - FATALA("ffmpeg:unable to apply stream codec parameters in codec context\n"); + fatal("ffmpeg:unable to apply stream codec parameters in codec context\n"); /* XXX: ffmpeg thread count default is 1, set to 0 = auto */ dec_ctx_p->thread_count = 0; r = avcodec_open2(dec_ctx_p, dec_l, 0); if (r < 0) - FATALA("ffmpeg:unable to open the decoder context\n"); + fatal("ffmpeg:unable to open the decoder context\n"); } #define AGAIN 0 #define HAVE_DEC_SET 1 @@ -40,11 +40,11 @@ STATIC u8 dec_set_try_receive(void) ++dec_sets_p.n; return HAVE_DEC_SET; } else if (r == AVUTIL_AVERROR_EOF) { - POUTA("ffmpeg:last decoder set of frames reached (receiving)\n"); + pout("ffmpeg:last decoder set of frames reached (receiving)\n"); dec_sets_p.eof_receive = true; return EOF_DEC; } - FATALA("ffmpeg:error while receiving a set of frames from the decoder\n"); + fatal("ffmpeg:error while receiving a set of frames from the decoder\n"); } #undef AGAIN #undef HAVE_DEC_SET @@ -80,7 +80,7 @@ STATIC void draining_state_evt(void) r = read(draining_timer_fd_p, &exps_n, sizeof(exps_n)); if (r == -1) - FATALA("unable to read the number of draining state timer expirations\n"); + fatal("unable to read the number of draining state timer expirations\n"); draining_state_handle(); } #define AGAIN 0 @@ -116,22 +116,22 @@ STATIC void pcm_silence_bufs_cfg(snd_pcm_t *pcm, bool print_info) r = snd_pcm_hw_params_malloc(&hw_params); if (r < 0) - FATALA("silence:alsa:unable to allocate memory for a hardware parameters container\n"); + fatal("silence:alsa:unable to allocate memory for a hardware parameters container\n"); r = snd_pcm_hw_params_current(pcm, hw_params); if (r != 0) - FATALA("silence:alsa:unable to get the pcm hardware parameters\n"); + fatal("silence:alsa:unable to get the pcm hardware parameters\n"); r = snd_pcm_hw_params_get_buf_sz(hw_params, &buf_ufrs_n); if (r < 0) - FATALA("silence:alsa:unable to get the number of frames in the pcm buffer\n"); + fatal("silence:alsa:unable to get the number of frames in the pcm buffer\n"); r = snd_pcm_hw_params_get_format(hw_params, &fmt); if (r < 0) - FATALA("silence:alsa:unable to get the pcm format\n"); + fatal("silence:alsa:unable to get the pcm format\n"); r = snd_pcm_hw_params_get_access(hw_params, &access); if (r < 0) - FATALA("silence:alsa:unable to get the pcm access mode\n"); + fatal("silence:alsa:unable to get the pcm access mode\n"); r = snd_pcm_hw_params_get_channels(hw_params, &chans_n); if (r < 0) - FATALA("silence:alsa:unable to get the pcm number of channels\n"); + fatal("silence:alsa:unable to get the pcm number of channels\n"); /* wipe silence bufs first */ c = 0; @@ -151,17 +151,17 @@ STATIC void pcm_silence_bufs_cfg(snd_pcm_t *pcm, bool print_info) buf_bytes_n = snd_pcm_frames_to_bytes(pcm, (snd_pcm_sframes_t)buf_ufrs_n); if (buf_bytes_n <= 0) - FATALA("silence:alsa:interleaved:unable to get the pcm number of bytes of all buffer frames\n"); + fatal("silence:alsa:interleaved:unable to get the pcm number of bytes of all buffer frames\n"); pcm_silence_bufs_l[0] = malloc((size_t)buf_bytes_n); if (pcm_silence_bufs_l[0] == 0) - FATALA("silence:interleaved:unable to allocate the silence buffer of %d bytes\n", (int)buf_bytes_n); + fatal("silence:interleaved:unable to allocate the silence buffer of %d bytes\n", (int)buf_bytes_n); if (print_info) - POUTA("silence:interleaved:buffer of %d bytes is allocated\n", (int)buf_bytes_n); + pout("silence:interleaved:buffer of %d bytes is allocated\n", (int)buf_bytes_n); r = snd_pcm_format_set_silence(fmt, pcm_silence_bufs_l[0], (unsigned int)buf_ufrs_n); if (r < 0) - FATALA("silence:interleaved:unable to fill with silence the buffer\n"); - POUTA("silence:interleaved:silence buffer filled with %u silence frames\n", buf_ufrs_n); + fatal("silence:interleaved:unable to fill with silence the buffer\n"); + pout("silence:interleaved:silence buffer filled with %u silence frames\n", buf_ufrs_n); } else if (access == SND_PCM_ACCESS_RW_NONINTERLEAVED || access == SND_PCM_ACCESS_MMAP_NONINTERLEAVED) { ssize_t buf_bytes_n; @@ -170,27 +170,27 @@ STATIC void pcm_silence_bufs_cfg(snd_pcm_t *pcm, bool print_info) buf_samples_n = (long)buf_ufrs_n; buf_bytes_n = snd_pcm_samples_to_bytes(pcm, buf_samples_n); if (buf_bytes_n <= 0) - FATALA("silence:alsa:non interleaved:unable to get the pcm number of total bytes of all buffer samples\n"); + fatal("silence:alsa:non interleaved:unable to get the pcm number of total bytes of all buffer samples\n"); c = 0; loop { if (c == chans_n) break; pcm_silence_bufs_l[c] = malloc((size_t)buf_bytes_n); if (pcm_silence_bufs_l[c] == 0) - FATALA("silence:non interleaved:unable to allocate silence buffer %u of %d bytes\n", c, (int)buf_bytes_n); + fatal("silence:non interleaved:unable to allocate silence buffer %u of %d bytes\n", c, (int)buf_bytes_n); r = snd_pcm_format_set_silence(fmt, pcm_silence_bufs_l[c], (unsigned int)buf_samples_n); if (r < 0) - FATALA("silence:non interleaved:unable to fill with silence the buffer\n"); + fatal("silence:non interleaved:unable to fill with silence the buffer\n"); if (print_info) - POUTA("silence:non interleaved:buffer[%u] of %d bytes is allocated\n", c, (int)buf_bytes_n); + pout("silence:non interleaved:buffer[%u] of %d bytes is allocated\n", c, (int)buf_bytes_n); ++c; } if (print_info) - POUTA("silence:non interleaved:allocated %u silence buffers for %u frames\n", chans_n, (unsigned int)buf_ufrs_n); + pout("silence:non interleaved:allocated %u silence buffers for %u frames\n", chans_n, (unsigned int)buf_ufrs_n); } else - FATALA("silence:the pcm access type is not supported\n"); + fatal("silence:the pcm access type is not supported\n"); snd_pcm_hw_params_free(hw_params); } STATIC void init_once(u8 *pcm_str) @@ -211,7 +211,7 @@ STATIC void dec_ctx_lock(void) r = pthread_mutex_lock(&dec_ctx_mutex_l); if (r != 0) - FATALA("%d:unable to lock the decoder context\n", r); + fatal("%d:unable to lock the decoder context\n", r); } STATIC void dec_ctx_unlock(void) { @@ -219,7 +219,7 @@ STATIC void dec_ctx_unlock(void) r = pthread_mutex_unlock(&dec_ctx_mutex_l); if (r != 0) - FATALA("%d:unable to unlock the decoder context\n", r); + fatal("%d:unable to unlock the decoder context\n", r); } STATIC void dec_sets_lock(void) { @@ -227,7 +227,7 @@ STATIC void dec_sets_lock(void) r = pthread_mutex_lock(&dec_sets_p.mutex); if (r != 0) - FATALA("%d:unable to lock the array of decoder sets\n", r); + fatal("%d:unable to lock the array of decoder sets\n", r); } STATIC void dec_sets_unlock(void) { @@ -235,16 +235,16 @@ STATIC void dec_sets_unlock(void) r = pthread_mutex_unlock(&dec_sets_p.mutex); if (r != 0) - FATALA("%d:unable to unlock the array of decoder sets\n", r); + fatal("%d:unable to unlock the array of decoder sets\n", r); } STATIC void pcm_cfg(snd_pcm_t *pcm, unsigned int chans_n, unsigned int rate, enum avutil_audio_fr_fmt_t ff_fmt) { pcm_cfg_hw(pcm, chans_n, rate, ff_fmt); pcm_cfg_sw(pcm); - POUTA("ALSA PCM DUMP START-------------------------------------------------------------\n"); + pout("ALSA PCM DUMP START-------------------------------------------------------------\n"); snd_pcm_dump(pcm, pcm_pout_l); - POUTA("ALSA PCM DUMP END---------------------------------------------------------------\n"); + pout("ALSA PCM DUMP END---------------------------------------------------------------\n"); } STATIC void pcm2ff(snd_pcm_t *pcm, enum avutil_audio_fr_fmt_t *ff_fmt, int *ff_rate, int *ff_chans_n, uint64_t *ff_chans_layout, @@ -259,27 +259,27 @@ STATIC void pcm2ff(snd_pcm_t *pcm, enum avutil_audio_fr_fmt_t *ff_fmt, r = snd_pcm_hw_params_malloc(&hw_params); if (r < 0) - FATALA("alsa:unable to allocate hardware parameters context for ffmpeg filter wiring\n"); + fatal("alsa:unable to allocate hardware parameters context for ffmpeg filter wiring\n"); r = snd_pcm_hw_params_current(pcm, hw_params); if (r != 0) - FATALA("alsa:unable to get current hardware parameters for ffmpeg filter wiring\n"); + fatal("alsa:unable to get current hardware parameters for ffmpeg filter wiring\n"); r = snd_pcm_hw_params_get_access(hw_params, &pcm_access); if (r < 0) - FATALA("alsa:unable to get the pcm access for ffmpeg filter wiring\n"); + fatal("alsa:unable to get the pcm access for ffmpeg filter wiring\n"); r = snd_pcm_hw_params_get_fmt(hw_params, &pcm_fmt); if (r < 0) - FATALA("alsa:unable to get the pcm format for ffmpeg filter wiring\n"); + fatal("alsa:unable to get the pcm format for ffmpeg filter wiring\n"); /*--------------------------------------------------------------------*/ pcm_layout2ff_fmt_strict(pcm_fmt, pcm_access, ff_fmt, print_info); /*--------------------------------------------------------------------*/ r = snd_pcm_hw_params_get_rate(hw_params, &pcm_rate, SND_PCM_ST_PLAYBACK); if (r < 0) - FATALA("alsa:unable to get the pcm rate for ffmpeg filter wiring\n"); + fatal("alsa:unable to get the pcm rate for ffmpeg filter wiring\n"); *ff_rate = (int)pcm_rate; r = snd_pcm_hw_params_get_chans_n(hw_params, &pcm_chans_n); if (r < 0) - FATALA("alsa:unable to get the pcm count of channels for ffmpeg filter wiring\n"); + fatal("alsa:unable to get the pcm count of channels for ffmpeg filter wiring\n"); *ff_chans_n = (int)pcm_chans_n; /*--------------------------------------------------------------------*/ *ff_chans_layout = pcm_chmaps2ff_chans_layout(pcm, pcm_chans_n, @@ -306,7 +306,7 @@ STATIC void pkts_send(void) { loop else if (r == AVUTIL_AVERROR_EOF) /* the dec is in draining mode */ goto unlock_and_return; else if (r != 0) - FATALA("error while sending a packet to the decoder\n"); + fatal("error while sending a packet to the decoder\n"); /* r == 0 */ npv_pipeline_limits_lock(); npv_pipeline_limits_p.pkts.audio_bytes_n -= pr->sz; diff --git a/npv/clk/local/code.frag.c b/npv/clk/local/code.frag.c new file mode 100644 index 0000000..047d1af --- /dev/null +++ b/npv/clk/local/code.frag.c @@ -0,0 +1,10 @@ +STATIC void npv_clk_fatal(u8 *fmt, ...) +{ + va_list ap; + + npv_perr("clock:"); + va_start(ap, fmt); + npv_vfatal(fmt, ap); + va_end(ap); +} + diff --git a/npv/clk/main.c b/npv/clk/main.c index 115012d..aeeccfb 100644 --- a/npv/clk/main.c +++ b/npv/clk/main.c @@ -7,6 +7,7 @@ /*---------------------------------------------------------------------------*/ #include #include +#include #include #include #include "npv/c_fixing.h" @@ -16,10 +17,10 @@ #include "npv/namespace/alsa.h" #include "npv/namespace/ffmpeg.h" /*---------------------------------------------------------------------------*/ -#define FATALCLK(fmt, ...) FATAL("clock:" fmt, ##__VA_ARGS__) #define TS_RETURNED 0 /*---------------------------------------------------------------------------*/ #include "npv/clk/local/state.frag.c" +#include "npv/clk/local/code.frag.c" #include "npv/clk/public/code.frag.c" /*---------------------------------------------------------------------------*/ #undef TS_RETURNED diff --git a/npv/clk/public/code.frag.c b/npv/clk/public/code.frag.c index bbdb09a..c8a4604 100644 --- a/npv/clk/public/code.frag.c +++ b/npv/clk/public/code.frag.c @@ -4,14 +4,14 @@ STATIC void npv_clk_init_once(void) r = snd_pcm_status_malloc(&npv_clk_l.ref.status); if (r != 0) - FATALCLK("alsa:unable to allocate an alsa status structure\n"); + npv_clk_fatal("alsa:unable to allocate an alsa status structure\n"); r = snd_pcm_status_malloc(&npv_clk_l.now.status); if (r != 0) - FATALCLK("alsa:unable to allocate an alsa status structure\n"); + npv_clk_fatal("alsa:unable to allocate an alsa status structure\n"); /* we pre-allocate alsa pcm hw_params container */ r = snd_pcm_hw_params_malloc(&npv_clk_pcm_hw_params_l); if (r < 0) - FATALCLK("alsa:unable to allocate hardware parameters context\n"); + npv_clk_fatal("alsa:unable to allocate hardware parameters context\n"); npv_clk_l.paused = false; } #define NO_REF_TIME_POINT 1 @@ -45,7 +45,7 @@ STATIC u8 npv_clk_get_audio_st_ts(s64 *ts) &ac); r = snd_pcm_status(npv_audio_pcm_p, npv_clk_l.now.status); if (r < 0) - FATALCLK("alsa:unable to sample timing information for 'now' time point\n"); + npv_clk_fatal("alsa:unable to sample timing information for 'now' time point\n"); } snd_pcm_status_get_audio_htstamp(npv_clk_l.now.status, &hts); now_ns = (f64)hts.tv_sec * 1e9 + (f64)hts.tv_nsec; @@ -60,11 +60,11 @@ STATIC u8 npv_clk_get_audio_st_ts(s64 *ts) /*--------------------------------------------------------------------*/ r = snd_pcm_hw_params_current(npv_audio_pcm_p, npv_clk_pcm_hw_params_l); if (r != 0) - FATALCLK("alsa:unable to get current hardware parameters\n"); + npv_clk_fatal("alsa:unable to get current hardware parameters\n"); r = snd_pcm_hw_params_get_rate_numden(npv_clk_pcm_hw_params_l, &audio_rate_num_ui, &audio_rate_den_ui); if (r < 0) - FATALCLK("alsa:unable to get exact rate\n"); + npv_clk_fatal("alsa:unable to get exact rate\n"); audio_rate_num = (f64)audio_rate_num_ui; audio_rate_den = (f64)audio_rate_den_ui; /*--------------------------------------------------------------------*/ @@ -118,7 +118,7 @@ STATIC void npv_clk_ref_time_point_update(s64 audio_ts, snd_pcm_status_set_audio_htstamp_config(npv_clk_l.ref.status, &ac); r = snd_pcm_status(npv_audio_pcm_p, npv_clk_l.ref.status); if (r < 0) - FATALCLK("unable to sample timing information for reference time point\n"); + npv_clk_fatal("unable to sample timing information for reference time point\n"); npv_clk_l.ref.audio_st_ts = audio_ts; npv_clk_l.ref.written_ufrs_n = written_ufrs_n; npv_clk_l.ref_valid = true; @@ -139,7 +139,7 @@ STATIC void npv_clk_pause(void) snd_pcm_status_set_audio_htstamp_config(npv_clk_l.now.status, &ac); r = snd_pcm_status(npv_audio_pcm_p, npv_clk_l.now.status); if (r < 0) - FATALCLK("alsa:unable to sample timing information for 'paused' time point\n"); + npv_clk_fatal("alsa:unable to sample timing information for 'paused' time point\n"); } STATIC void npv_clk_unpause(void) { diff --git a/npv/fmt/local/code.frag.c b/npv/fmt/local/code.frag.c index 8fc394e..a547139 100644 --- a/npv/fmt/local/code.frag.c +++ b/npv/fmt/local/code.frag.c @@ -1,3 +1,21 @@ +STATIC void fatal(u8 *fmt, ...) +{ + va_list ap; + + npv_perr("format:"); + va_start(ap, fmt); + npv_vfatal(fmt, ap); + va_end(ap); /* unreachable */ +} +STATIC void pout(u8 *fmt, ...) +{ + va_list ap; + + npv_pout("format:"); + va_start(ap, fmt); + npv_vpout(fmt, ap); + va_end(ap); +} STATIC bool did_reached_limits(void) { bool r; @@ -20,14 +38,14 @@ STATIC void init_once_public(u8 *url) ctx_p = 0; r = avformat_open_input(&ctx_p, url, NULL, NULL); if (r < 0) - FATALF("ffmpeg:unable to open \"%s\"\n", url); + fatal("ffmpeg:unable to open \"%s\"\n", url); r = pthread_mutex_init(&ctx_mutex_l, 0); if (r != 0) - FATALF("unable to init the format mutex\n"); + fatal("unable to init the format mutex\n"); } STATIC void init_once_local(void) { pkt_l = avcodec_pkt_ref_alloc(); if (pkt_l == 0) - FATALF("ffmpeg:unable to allocate a reference on a packet for encoded/compressed audio/video\n"); + fatal("ffmpeg:unable to allocate a reference on a packet for encoded/compressed audio/video\n"); } diff --git a/npv/fmt/main.c b/npv/fmt/main.c index f5b0c4d..43010fb 100644 --- a/npv/fmt/main.c +++ b/npv/fmt/main.c @@ -5,10 +5,13 @@ * copyright (C) 2020 Sylvain BERTRAND */ #include +#include +#include #include #include #include "npv/c_fixing.h" #include "npv/global.h" +#include "npv/public.h" #include "npv/pkt_q/public.h" #include "npv/fmt/public.h" #include "npv/audio/public.h" @@ -18,19 +21,11 @@ #include "npv/fmt/namespace/public.h" #include "npv/fmt/namespace/main.c" /*----------------------------------------------------------------------------*/ -#define FATALF(fmt, ...) FATAL("format:" fmt, ##__VA_ARGS__) -#define WARNINGF(fmt, ...) WARNING("format:" fmt, ##__VA_ARGS__) -#define POUTF(fmt, ...) POUT("format:" fmt, ##__VA_ARGS__) -/*----------------------------------------------------------------------------*/ #include "npv/fmt/local/state.frag.c" /*----------------------------------------------------------------------------*/ #include "npv/fmt/local/code.frag.c" #include "npv/fmt/public/code.frag.c" /*----------------------------------------------------------------------------*/ -#undef FATALF -#undef WARNINGF -#undef POUTF -/*----------------------------------------------------------------------------*/ #define CLEANUP #include "npv/namespace/ffmpeg.h" #include "npv/fmt/namespace/public.h" diff --git a/npv/fmt/namespace/main.c b/npv/fmt/namespace/main.c index c35dab9..e8881cc 100644 --- a/npv/fmt/namespace/main.c +++ b/npv/fmt/namespace/main.c @@ -11,7 +11,9 @@ #define audio npv_fmt_break_on_audio #define ctx_mutex_l npv_fmt_ctx_mutex_l #define did_reached_limits npv_fmt_did_reached_limits +#define fatalf npv_fmt_fatal #define pkt_l npv_fmt_pkt_l +#define poutf npv_fmt_pout #define video npv_fmt_break_on_video /*============================================================================*/ #else @@ -26,6 +28,8 @@ #undef audio #undef ctx_mutex_l #undef did_reached_limits +#undef fatalf +#undef poutf #undef pkt_l #undef video #endif diff --git a/npv/fmt/public/code.frag.c b/npv/fmt/public/code.frag.c index 243f6e1..f5c1a38 100644 --- a/npv/fmt/public/code.frag.c +++ b/npv/fmt/public/code.frag.c @@ -4,7 +4,7 @@ STATIC void ctx_lock(void) r = pthread_mutex_lock(&ctx_mutex_l); if (r != 0) - FATALF("%d:unable to lock the format context\n", r); + fatal("%d:unable to lock the format context\n", r); } STATIC void ctx_unlock(void) { @@ -12,7 +12,7 @@ STATIC void ctx_unlock(void) r = pthread_mutex_unlock(&ctx_mutex_l); if (r != 0) - FATALF("%d:unable to unlock the format context\n", r); + fatal("%d:unable to unlock the format context\n", r); } STATIC u8 *duration_estimate_to_str(enum avformat_duration_estimation_method_t m) @@ -50,7 +50,7 @@ STATIC u8 pkts_read_and_q(void) { loop else if (r == AVERROR_EOF) return EOF_FMT; else if (r != 0) - FATALF("ffmpeg:error while reading coded/compressed data into packets\n"); + fatal("ffmpeg:error while reading coded/compressed data into packets\n"); /* r == 0 */ if (pkt_l->st_idx == npv_audio_st_p.idx) { npv_pipeline_limits_lock(); @@ -93,11 +93,11 @@ STATIC void probe_best_sts( /* probe beyond the header, if any */ r = avformat_find_st_info(ctx_p, 0); if (r < 0) - FATALF("ffmpeg:unable to probe\n"); + fatal("ffmpeg:unable to probe\n"); r = avformat_find_best_st(ctx_p, AVUTIL_AVMEDIA_TYPE_AUDIO, -1, -1, 0, 0); if (r < 0) - FATALF("ffmpeg:no audio stream found\n"); + fatal("ffmpeg:no audio stream found\n"); /* we copy what we need */ *best_a_idx = r; *best_a_id = ctx_p->sts[r]->id; @@ -108,15 +108,15 @@ STATIC void probe_best_sts( r = avformat_find_best_st(ctx_p, AVUTIL_AVMEDIA_TYPE_VIDEO, -1, -1, 0, 0); if (r < 0) - FATALF("ffmpeg:no video stream found\n"); + fatal("ffmpeg:no video stream found\n"); /* we copy what we need */ *best_v_idx = r; *best_v_id = ctx_p->sts[r]->id; *best_v_tb = &ctx_p->sts[r]->tb; *best_v_start_time = ctx_p->sts[r]->start_time; *best_v_codec_params = ctx_p->sts[r]->codecpar; /* used once for init */ - POUTF("####%s#### probing: %u streams and %u programs\n", ctx_p->url, ctx_p->sts_n, ctx_p->programs_n); - 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); + pout("####%s#### probing: %u streams and %u programs\n", ctx_p->url, ctx_p->sts_n, ctx_p->programs_n); + 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); } STATIC void flush(void) { diff --git a/npv/global.h b/npv/global.h dissimilarity index 66% index 48e72b9..52a58e8 100644 --- a/npv/global.h +++ b/npv/global.h @@ -1,16 +1,11 @@ -#ifndef NPV_GLOBAL_H -#define NPV_GLOBAL_H -/* - * code protected with a GNU affero GPLv3 license - * copyright (C) 2020 Sylvain BERTRAND - */ -#include -#include -#include "c_fixing.h" -#define POUT(fmt, ...) ({flockfile(stdout);fprintf(stdout, fmt, ##__VA_ARGS__);funlockfile(stdout);}) -#define PERR(fmt, ...) ({flockfile(stderr);fprintf(stderr, fmt, ##__VA_ARGS__);funlockfile(stderr);}) -#define WARNING(fmt, ...) ({flockfile(stderr);fprintf(stderr, "WARNING:" fmt, ##__VA_ARGS__);funlockfile(stderr);}) -#define FATAL(fmt, ...) ({PERR("FATAL:" fmt, ##__VA_ARGS__);exit(1);}) -#define EXIT(fmt, ...) ({POUT("EXITING:" fmt, ##__VA_ARGS__);exit(0);}) -#define STR_SZ U8_MAX -#endif +#ifndef NPV_GLOBAL_H +#define NPV_GLOBAL_H +/* + * code protected with a GNU affero GPLv3 license + * copyright (C) 2020 Sylvain BERTRAND + */ +#include +#include +#include "c_fixing.h" +#define STR_SZ U8_MAX +#endif diff --git a/npv/local/code.frag.c b/npv/local/code.frag.c index 333beb0..4ba09e8 100644 --- a/npv/local/code.frag.c +++ b/npv/local/code.frag.c @@ -13,34 +13,34 @@ STATIC void sigs_init_once(void) r = sigfillset(&sset); if (r == -1) - FATAL("unable to get a full signal mask\n"); + fatal("unable to get a full signal mask\n"); /* the "controlling terminal" line asks for a core dump, leave it be */ r = sigdelset(&sset, SIGQUIT); if (r == -1) - FATAL("unable to remove SIGQUIT from our signal mask\n"); + fatal("unable to remove SIGQUIT from our signal mask\n"); r = pthread_sigmask(SIG_SETMASK, &sset, 0); if (r != 0) - FATAL("unable to \"block\" \"all\" signals\n"); + fatal("unable to \"block\" \"all\" signals\n"); /* from here, we "steal" signals with signalfd */ r = sigemptyset(&sset); if (r == -1) - FATAL("unable to get an empty signal mask\n"); + fatal("unable to get an empty signal mask\n"); /* we are asked nicely to terminate */ r = sigaddset(&sset, SIGTERM); if (r == -1) - FATAL("unable to add SIGTERM to our signal mask\n"); + fatal("unable to add SIGTERM to our signal mask\n"); /* the "controlling terminal" line (^c) asks nicely to terminate */ r = sigaddset(&sset, SIGINT); if (r == -1) - FATAL("unable to add SIGINT to our signal mask\n"); + fatal("unable to add SIGINT to our signal mask\n"); r = signalfd(-1, &sset, SFD_NONBLOCK); if (r == -1) - FATAL("unable to get a signalfd file descriptor\n"); + fatal("unable to get a signalfd file descriptor\n"); sig_fd_l = r; } STATIC void prefill_wait(void) { loop @@ -67,7 +67,7 @@ STATIC void prefill_wait(void) { loop if (r == 0) break; if (r != EINTR) - FATAL("prefill wait timer failed:%d\n", r); + fatal("prefill wait timer failed:%d\n", r); /* r == EINTR */ memcpy(&wanted, &rem, sizeof(wanted)); memset(&rem, 0, sizeof(rem)); @@ -90,7 +90,7 @@ STATIC void predecode_wait(void) if (r == 0) break; if (r != EINTR) - FATAL("predecoding wait timer failed:%d\n", r); + fatal("predecoding wait timer failed:%d\n", r); /* r == EINTR */ memcpy(&wanted, &rem, sizeof(wanted)); memset(&rem, 0, sizeof(rem)); @@ -100,7 +100,7 @@ STATIC void evt_init_once(void) { ep_fd_p = epoll_create1(0); if (ep_fd_p == -1) - FATAL("unable to create the epoll file descriptor\n"); + fatal("unable to create the epoll file descriptor\n"); } STATIC void evt_add_all_fds(void) { @@ -113,21 +113,21 @@ STATIC void evt_add_all_fds(void) evt.data.fd = sig_fd_l; r = epoll_ctl(ep_fd_p, EPOLL_CTL_ADD, sig_fd_l, &evt); if (r == -1) - FATAL("unable to add the signalfd file descriptior to the epoll file descriptor\n"); + fatal("unable to add the signalfd file descriptior to the epoll file descriptor\n"); /*--------------------------------------------------------------------*/ /* the video timer */ evt.events = EPOLLIN; evt.data.fd = npv_video_timer_fd_p; r = epoll_ctl(ep_fd_p, EPOLL_CTL_ADD, npv_video_timer_fd_p, &evt); if (r == -1) - FATAL("unable to add the video timer file descriptor\n"); + fatal("unable to add the video timer file descriptor\n"); /*--------------------------------------------------------------------*/ /* the x11 xcb file descriptor */ evt.events = EPOLLIN; evt.data.fd = npv_xcb_p.fd; r = epoll_ctl(ep_fd_p, EPOLL_CTL_ADD, npv_xcb_p.fd, &evt); if (r == -1) - FATAL("unable to add the x11 xcb file descriptor\n"); + fatal("unable to add the x11 xcb file descriptor\n"); /*--------------------------------------------------------------------*/ /* alsa pcm poll file descriptors */ i = 0; @@ -139,7 +139,7 @@ STATIC void evt_add_all_fds(void) r = epoll_ctl(ep_fd_p, EPOLL_CTL_ADD, npv_audio_pcm_pollfds_p[i].fd, &evt); if (r == -1) - FATAL("unable to add alsa poll file descriptor index %d to epoll file descriptor\n", i); + fatal("unable to add alsa poll file descriptor index %d to epoll file descriptor\n", i); ++i; } /*--------------------------------------------------------------------*/ @@ -149,7 +149,7 @@ STATIC void evt_add_all_fds(void) r = epoll_ctl(ep_fd_p, EPOLL_CTL_ADD, npv_audio_draining_timer_fd_p, &evt); if (r == -1) - FATAL("unable to add the draining timer file descriptor\n"); + fatal("unable to add the draining timer file descriptor\n"); /*--------------------------------------------------------------------*/ /* the xcb screensaver heartbeat timer */ evt.events = EPOLLIN; @@ -157,7 +157,7 @@ STATIC void evt_add_all_fds(void) r = epoll_ctl(ep_fd_p, EPOLL_CTL_ADD, npv_xcb_p.screensaver_heartbeat_timer_fd, &evt); if (r == -1) - FATAL("unable to add the xcb screensaver heartbeat timer file descriptor\n"); + fatal("unable to add the xcb screensaver heartbeat timer file descriptor\n"); /*--------------------------------------------------------------------*/ /* the xcb mouse visibility timer */ evt.events = EPOLLIN; @@ -165,7 +165,7 @@ STATIC void evt_add_all_fds(void) r = epoll_ctl(ep_fd_p, EPOLL_CTL_ADD, npv_xcb_p.mouse_visibility_timer_fd, &evt); if (r == -1) - FATAL("unable to add the xcb screensaver heartbeat timer file descriptor\n"); + fatal("unable to add the xcb screensaver heartbeat timer file descriptor\n"); } STATIC void evt_sigs(void) { @@ -175,15 +175,15 @@ STATIC void evt_sigs(void) /* no short reads */ r = read(sig_fd_l, &siginfo, sizeof(siginfo)); if (r != sizeof(siginfo)) - FATAL("unable to read signal information\n"); + fatal("unable to read signal information\n"); switch (siginfo.ssi_signo) { case SIGTERM: - EXIT("received SIGTERM\n"); + exit_ok("received SIGTERM\n"); case SIGINT: - EXIT("received SIGINT\n"); + exit_ok("received SIGINT\n"); default: - WARNING("signal handle:unwanted signal %d received, discarding\n", siginfo.ssi_signo); + warning("signal handle:unwanted signal %d received, discarding\n", siginfo.ssi_signo); } } STATIC void evt_accumulate(struct epoll_event *evt, bool *have_evt_sigs, @@ -198,7 +198,7 @@ STATIC void evt_accumulate(struct epoll_event *evt, bool *have_evt_sigs, *have_evt_sigs = true; return; } - FATAL("event loop wait:signal:unexpected event\n"); + fatal("event loop wait:signal:unexpected event\n"); } /*-------------------------------------------------------------------*/ /* only update alsa fds */ @@ -225,7 +225,7 @@ STATIC void evt_accumulate(struct epoll_event *evt, bool *have_evt_sigs, *have_evt_video = true; return; } - FATAL("event loop wait:video:unexpected event\n"); + fatal("event loop wait:video:unexpected event\n"); } /*-------------------------------------------------------------------*/ if (evt->data.fd == npv_audio_draining_timer_fd_p) { @@ -233,7 +233,7 @@ STATIC void evt_accumulate(struct epoll_event *evt, bool *have_evt_sigs, *have_evt_pcm_draining = true; return; } - FATAL("event loop wait:audio draining timer:unexpected event\n"); + fatal("event loop wait:audio draining timer:unexpected event\n"); } /*-------------------------------------------------------------------*/ if (evt->data.fd == npv_xcb_p.screensaver_heartbeat_timer_fd) { @@ -241,7 +241,7 @@ STATIC void evt_accumulate(struct epoll_event *evt, bool *have_evt_sigs, *have_evt_xcb_screensaver_heartbeat = true; return; } - FATAL("event loop wait:xcb screensaver heartbeat timer:unexpected event\n"); + fatal("event loop wait:xcb screensaver heartbeat timer:unexpected event\n"); } /*-------------------------------------------------------------------*/ if (evt->data.fd == npv_xcb_p.mouse_visibility_timer_fd) { @@ -249,7 +249,7 @@ STATIC void evt_accumulate(struct epoll_event *evt, bool *have_evt_sigs, *have_evt_xcb_mouse_visibility = true; return; } - FATAL("event loop wait:xcb mouse visibility timer:unexpected event\n"); + fatal("event loop wait:xcb mouse visibility timer:unexpected event\n"); } } /* @@ -278,10 +278,10 @@ STATIC void evts_loop(void) fds_n = epoll_wait(ep_fd_p, evts, EPOLL_EVTS_N, -1); if (fds_n == -1) { if (errno == EINTR) { - WARNING("event loop wait:was interrupted by a signal\n"); + warning("event loop wait:was interrupted by a signal\n"); return; } - FATAL("event loop wait:an error occured\n"); + fatal("event loop wait:an error occured\n"); } have_evt_sigs = false; @@ -327,9 +327,9 @@ STATIC void evts_loop(void) npv_audio_pcm_pollfds_p, npv_audio_pcm_pollfds_n_p, &pcm_evts); if (r != 0) - FATAL("alsa:error processing the poll file descriptors\n"); + fatal("alsa:error processing the poll file descriptors\n"); if ((pcm_evts & ~POLLOUT) != 0) - FATAL("alsa:unexpected events\n"); + fatal("alsa:unexpected events\n"); if ((pcm_evts & POLLOUT) != 0) npv_audio_evt_pcm_write(); } @@ -350,7 +350,7 @@ STATIC void ff_log_stdout(void *a, int b, const char *fmt, va_list ap) } STATIC void usage(void) { - POUT("\ + pout("\ npv [-f send a fullscreen message to the window manager at start] [-p alsa pcm]\n\ [-v volume(0..100)] [-h window height in pixels] [-w window width in pixels]\n\ [-b packet buffer prefill wait(0..100)] [-help] url\n"); @@ -371,46 +371,46 @@ STATIC void opts_parse(int argc, u8 **args, u8 **url, bool* start_fullscreen, ++i; } else if (strcmp("-p", args[i]) == 0) { *pcm_str = args[i + 1]; - POUT("-p:alsa pcm \"%s\"\n", *pcm_str); + pout("-p:alsa pcm \"%s\"\n", *pcm_str); i += 2; } else if (strcmp("-v", args[i]) == 0) { unsigned long vol_ul; if ((i + 1) == argc) - FATAL("-v:initial volume is missing\n"); + fatal("-v:initial volume is missing\n"); vol_ul = strtoul(args[i + 1], 0, 10); if (vol_ul < 0 || 100 < vol_ul) - FATAL("-v:invalid volume value %lu (0..100)\n", vol_ul); + fatal("-v:invalid volume value %lu (0..100)\n", vol_ul); *vol = (double)vol_ul / 100.; - POUT("-v:using initial volume %f\n", *vol); + pout("-v:using initial volume %f\n", *vol); i += 2; } else if (strcmp("-h", args[i]) == 0) { unsigned long h_ul; if ((i + 1) == argc) - FATAL("-h:initial window pixel height is missing\n"); + fatal("-h:initial window pixel height is missing\n"); h_ul = strtoul(args[i + 1], 0, 10); if (h_ul == 0 || h_ul > U16_MAX) - FATAL("-h:invalid window pixel height %lu (1..%lu)\n", h_ul, U16_MAX); + fatal("-h:invalid window pixel height %lu (1..%lu)\n", h_ul, U16_MAX); *h = (u16)h_ul; - POUT("-h:using initial window height %lu pixels\n", h_ul); + pout("-h:using initial window height %lu pixels\n", h_ul); i += 2; } else if (strcmp("-w", args[i]) == 0) { unsigned long w_ul; if ((i + 1) == argc) - FATAL("-h:initial window pixel width is missing\n"); + fatal("-h:initial window pixel width is missing\n"); w_ul = strtoul(args[i + 1], 0, 10); if (w_ul == 0 || w_ul > U16_MAX) - FATAL("-w:invalid window pixel width %lu (1..%lu)\n", w_ul, U16_MAX); + fatal("-w:invalid window pixel width %lu (1..%lu)\n", w_ul, U16_MAX); *w = (u16)w_ul; - POUT("-w:using initial window width %lu pixels\n", w_ul); + pout("-w:using initial window width %lu pixels\n", w_ul); i += 2; } else if (strcmp("-b", args[i]) == 0) { if ((i + 1) == argc) - FATAL("-b:percent value for prefill of buffer of packet queues is missing\n"); + fatal("-b:percent value for prefill of buffer of packet queues is missing\n"); *pkts_prefill_percent = (u8)strtoul(args[i + 1], 0, 10); - POUT("-v:using a %u prefilled buffer of packet queues\n", *pkts_prefill_percent); + pout("-v:using a %u prefilled buffer of packet queues\n", *pkts_prefill_percent); i += 2; } else if (strcmp("-help", args[i]) == 0) { usage(); @@ -421,9 +421,9 @@ STATIC void opts_parse(int argc, u8 **args, u8 **url, bool* start_fullscreen, } } if (url_idx == -1) - FATAL("missing url\n"); + fatal("missing url\n"); *url = args[url_idx]; - POUT("url-->####%s####\n", *url); + pout("url-->####%s####\n", *url); } #define WIDTH_NOT_DEFINED 0 #define HEIGHT_NOT_DEFINED 0 @@ -560,11 +560,11 @@ STATIC u8 *ts_to_str(int64_t ts, avutil_rational_t time_base, } return str; } -#define RED if (stdout_is_tty) POUT("\x1b[38;2;255;0;0m") -#define GREEN if (stdout_is_tty) POUT("\x1b[38;2;0;255;0m") -#define BLUE if (stdout_is_tty) POUT("\x1b[38;2;0;0;255m") -#define PURPLE if (stdout_is_tty) POUT("\x1b[38;2;255;0;255m") -#define RESTORE if (stdout_is_tty) POUT("\x1b[39;49m"); +#define RED if (stdout_is_tty) pout("\x1b[38;2;255;0;0m") +#define GREEN if (stdout_is_tty) pout("\x1b[38;2;0;255;0m") +#define BLUE if (stdout_is_tty) pout("\x1b[38;2;0;0;255m") +#define PURPLE if (stdout_is_tty) pout("\x1b[38;2;255;0;255m") +#define RESTORE if (stdout_is_tty) pout("\x1b[39;49m"); #define TS_FROM_CLK_OK 0 /* we don't lock anything as an act of faith */ STATIC void npv_cmd_info(void) @@ -584,63 +584,63 @@ STATIC void npv_cmd_info(void) stdout_is_tty = true; RESTORE; - GREEN;POUT("================================================================================\n");RESTORE; - PURPLE;POUT("%s\n", npv_fmt_ctx_p->url);RESTORE; + GREEN;pout("================================================================================\n");RESTORE; + PURPLE;pout("%s\n", npv_fmt_ctx_p->url);RESTORE; r8 = npv_clk_get_audio_st_ts(&audio_now); if (r8 != TS_FROM_CLK_OK) { - POUT("information unavailable at the time of the command due to an unavailable audio clock\n"); + pout("information unavailable at the time of the command due to an unavailable audio clock\n"); return; } ts_str = ts_to_str(audio_now, npv_audio_st_p.tb, &remaining); - RED;POUT("%s", ts_str);RESTORE; + RED;pout("%s", ts_str);RESTORE; if (remaining != 0) - POUT(" remaining %"PRId64" time base units", remaining); + pout(" remaining %"PRId64" time base units", remaining); else - POUT("\n"); - POUT("\t%"PRId64" stream time base units (%d/%d seconds)\n", + pout("\n"); + pout("\t%"PRId64" stream time base units (%d/%d seconds)\n", audio_now, npv_audio_st_p.tb.num, npv_audio_st_p.tb.den); - BLUE;POUT("--------------------------------------------------------------------------------\n");RESTORE; - POUT("format:"); + BLUE;pout("--------------------------------------------------------------------------------\n");RESTORE; + pout("format:"); if (npv_fmt_ctx_p->duration == AV_NOPTS_VALUE) { - POUT("duration is not provided\n"); + pout("duration is not provided\n"); } else { snprintf(duration_str, sizeof(duration_str), "%"PRId64, npv_fmt_ctx_p->duration); ts_str = ts_to_str(npv_fmt_ctx_p->duration, AV_TIME_BASE_Q, &remaining); - POUT("duration=");RED;POUT("%s", ts_str);RESTORE; + pout("duration=");RED;pout("%s", ts_str);RESTORE; if (remaining != 0) - POUT(" remaining %"PRId64" av_time_base units\n", + pout(" remaining %"PRId64" av_time_base units\n", remaining); else - POUT("\n"); - POUT("\t%s av_time_base units (1/%d seconds)\n\testimation method is %s\n", + pout("\n"); + pout("\t%s av_time_base units (1/%d seconds)\n\testimation method is %s\n", duration_str, AV_TIME_BASE, duration_estimate_to_str( npv_fmt_ctx_p->duration_estimation_method)); } - BLUE;POUT("--------------------------------------------------------------------------------\n");RESTORE; - POUT("stream:audio_id=%d", npv_audio_st_p.id); + BLUE;pout("--------------------------------------------------------------------------------\n");RESTORE; + pout("stream:audio_id=%d", npv_audio_st_p.id); if (npv_fmt_ctx_p->streams[npv_audio_st_p.idx]->duration == AV_NOPTS_VALUE) { - POUT(";duration is not provided\n"); + pout(";duration is not provided\n"); } else { snprintf(duration_str, sizeof(duration_str), "%"PRId64, npv_fmt_ctx_p->streams[npv_audio_st_p.idx]->duration); ts_str = ts_to_str( npv_fmt_ctx_p->streams[npv_audio_st_p.idx]->duration, npv_audio_st_p.tb, &remaining); - POUT(";duration=");RED;POUT("%s\n", ts_str);RESTORE; + pout(";duration=");RED;pout("%s\n", ts_str);RESTORE; if (remaining != 0) - POUT(" remaining %"PRId64" stream time base units\n", + pout(" remaining %"PRId64" stream time base units\n", remaining); else - POUT("\n"); - POUT("\t%s stream time base units (%d/%d seconds)\n", + pout("\n"); + pout("\t%s stream time base units (%d/%d seconds)\n", duration_str, npv_audio_st_p.tb.num, npv_audio_st_p.tb.den); } - BLUE;POUT("--------------------------------------------------------------------------------\n");RESTORE; - GREEN;POUT("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");RESTORE; + BLUE;pout("--------------------------------------------------------------------------------\n");RESTORE; + GREEN;pout("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");RESTORE; } #undef TS_FROM_CLK_OK #undef RED @@ -651,7 +651,7 @@ STATIC void npv_cmd_info(void) /*==== while waiting for the osd -- end ======================================*/ STATIC void npv_cmd_quit(void) { - EXIT("quit command received\n"); + exit_ok("quit command received\n"); } STATIC void seek_lock(void) { @@ -694,7 +694,7 @@ STATIC void seek_x(s64 delta) s64 video_now; if (npv_audio_draining_p) { - WARNING("seek:audio is draining, seeking disable\n"); + warning("seek:audio is draining, seeking disable\n"); return; } if (paused_p) /* we don't seek in pause */ @@ -706,13 +706,13 @@ STATIC void seek_x(s64 delta) r = npv_clk_get_audio_st_ts(&audio_now); if (r != TS_FROM_CLK_OK) { - WARNING("seek:audio:clock timestamp unavailable, ignoring command\n"); + warning("seek:audio:clock timestamp unavailable, ignoring command\n"); seek_unlock(); return; } r = npv_clk_get_video_st_ts(&video_now); if (r != TS_FROM_CLK_OK) { - WARNING("seek:video:clock timestamp unavailable, ignoring command\n"); + warning("seek:video:clock timestamp unavailable, ignoring command\n"); seek_unlock(); return; } @@ -728,14 +728,14 @@ STATIC void seek_x(s64 delta) if (npv_audio_st_p.start_time != AV_NOPTS_VALUE) if (new_audio_ts < npv_audio_st_p.start_time) new_audio_ts = npv_audio_st_p.start_time; - POUT("trying to seek to %"PRId64" audio stream time base units\n", new_audio_ts); + pout("trying to seek to %"PRId64" audio stream time base units\n", new_audio_ts); a = avformat_seek_pkt(npv_fmt_ctx_p, npv_audio_st_p.id, new_audio_ts, 0); if (a < 0) { - POUT("unable to seek to %"PRId64" audio stream time base units\n", new_audio_ts); + pout("unable to seek to %"PRId64" audio stream time base units\n", new_audio_ts); goto try_restore_audio; } - POUT("audio seek to %"PRId64" audio stream time base units\n", new_audio_ts); + pout("audio seek to %"PRId64" audio stream time base units\n", new_audio_ts); /*--------------------------------------------------------------------*/ new_video_ts = video_now + delta * npv_video_st_p.tb.den / npv_video_st_p.tb.num; @@ -743,14 +743,14 @@ STATIC void seek_x(s64 delta) if (npv_video_st_p.start_time != AV_NOPTS_VALUE) if (new_video_ts < npv_video_st_p.start_time) new_video_ts = npv_video_st_p.start_time; - POUT("trying to seek to %"PRId64" video stream time base units\n", new_video_ts); + pout("trying to seek to %"PRId64" video stream time base units\n", new_video_ts); a = avformat_seek_pkt(npv_fmt_ctx_p, npv_video_st_p.id, new_video_ts, 0); if (a < 0) { - POUT("unable to seek to %"PRId64" video stream time base units but audio was seeked)\n", new_video_ts); + pout("unable to seek to %"PRId64" video stream time base units but audio was seeked)\n", new_video_ts); goto try_restore_video; } - POUT("video seek to %"PRId64" video stream time base units\n", new_video_ts); + pout("video seek to %"PRId64" video stream time base units\n", new_video_ts); flush: npv_video_dec_flush(); npv_audio_dec_flush(); @@ -761,60 +761,60 @@ flush: npv_pipeline_prefill_reset(npv_pipeline_limits_p.pkts.prefill.percent); seek_unlock(); - POUT("prefilling audio and video buffers..."); + pout("prefilling audio and video buffers..."); prefill_wait(); /* use the lock on the pipeline limits */ - POUT("done\n"); - POUT("predecoding audio and video..."); + pout("done\n"); + pout("predecoding audio and video..."); predecode_wait(); /* use the lock on the pipeline limits */ - POUT("done\n"); + pout("done\n"); (void)snd_pcm_prepare(npv_audio_pcm_p); return; try_restore_video: a = avformat_seek_pkt(npv_fmt_ctx_p, npv_video_st_p.id, video_now, 0); if (a < 0) /* we don't send an application error */ - EXIT("unable to restore video to %"PRId64" video stream time base units\n", video_now); + exit_ok("unable to restore video to %"PRId64" video stream time base units\n", video_now); try_restore_audio: a = avformat_seek_pkt(npv_fmt_ctx_p, npv_audio_st_p.id, audio_now, 0); if (a < 0) /* we don't send an application error */ - EXIT("unable to restore audio to %"PRId64" audio stream time base units\n", audio_now); + exit_ok("unable to restore audio to %"PRId64" audio stream time base units\n", audio_now); goto flush; } #undef TS_FROM_CLK_OK STATIC void npv_cmd_rewind(void) { - POUT("COMMAND:rewind\n"); + pout("COMMAND:rewind\n"); seek_x(-SEEK_DELTA); } STATIC void npv_cmd_rewind_big(void) { - POUT("COMMAND:rewind big\n"); + pout("COMMAND:rewind big\n"); seek_x(-SEEK_DELTA_BIG); } STATIC void npv_cmd_fastforward(void) { - POUT("COMMAND:fastforward\n"); + pout("COMMAND:fastforward\n"); seek_x(SEEK_DELTA); } STATIC void npv_cmd_fastforward_big(void) { - POUT("COMMAND:fastforward big\n"); + pout("COMMAND:fastforward big\n"); seek_x(SEEK_DELTA_BIG); } STATIC void npv_cmd_pause(void) { if (npv_audio_draining_p) { - WARNING("pause:audio is draining, toggling pause is disable\n"); + warning("pause:audio is draining, toggling pause is disable\n"); return; } if (paused_p) { int r; - POUT("COMMAND:unpause\n"); + pout("COMMAND:unpause\n"); paused_p = false; npv_fmt_ctx_lock(); avformat_read_play(npv_fmt_ctx_p); @@ -824,7 +824,7 @@ STATIC void npv_cmd_pause(void) } else { int r; - POUT("COMMAND:pause\n"); + pout("COMMAND:pause\n"); paused_p = true; npv_fmt_ctx_lock(); avformat_read_pause(npv_fmt_ctx_p); @@ -883,14 +883,14 @@ int main(int argc, u8 **args) avutil_log_set_callback(avutil_log_default_callback); npv_pipeline_read_thd_start(); - POUT("prefilling audio and video buffers..."); + pout("prefilling audio and video buffers..."); prefill_wait(); - POUT("done\n"); + pout("done\n"); npv_pipeline_audio_thd_start(); npv_pipeline_video_thd_start(); - POUT("predecoding audio and video..."); + pout("predecoding audio and video..."); predecode_wait(); - POUT("done\n"); + pout("done\n"); npv_video_timer_start(); npv_xcb_screensaver_heartbeat_timer_start(); diff --git a/npv/main.c b/npv/main.c index c7bfb0b..1e9ab6e 100644 --- a/npv/main.c +++ b/npv/main.c @@ -42,6 +42,7 @@ #include "npv/thdsws/public.h" #include "npv/clk/public.h" /*---------------------------------------------------------------------------*/ +#include "npv/namespace/public.h" #include "npv/namespace/ffmpeg.h" #include "npv/audio/namespace/ffmpeg.h" #include "npv/namespace/public.h" @@ -51,8 +52,10 @@ /*---------------------------------------------------------------------------*/ #include "npv/local/state.frag.c" #include "npv/local/code.frag.c" +#include "npv/public/code.frag.c" /*--------------------------------------------------------------------------*/ #define CLEANUP +#include "npv/namespace/public.h" #include "npv/namespace/ffmpeg.h" #include "npv/audio/namespace/ffmpeg.h" #include "npv/namespace/public.h" diff --git a/npv/make-template.sh b/npv/make-template.sh new file mode 100755 index 0000000..b95910a --- /dev/null +++ b/npv/make-template.sh @@ -0,0 +1,7 @@ +#!/bin/sh +cc main.c -lc -ldl -D_GNU_SOURCE -DSTATIC=static -I../ \ + $(pkg-config --cflags xcb) \ + $(pkg-config --cflags --libs libavcodec libavdevice libavfilter \ + libavformat libavutil libpostproc libswresample libswscale \ + alsa) \ + -o /tmp/npv diff --git a/npv/namespace/public.h b/npv/namespace/public.h index 311ab37..6775d79 100644 --- a/npv/namespace/public.h +++ b/npv/namespace/public.h @@ -1,8 +1,26 @@ #ifndef CLEANUP #define ep_fd_p npv_ep_fd_p +#define exit_ok npv_exit +#define fatal npv_fatal #define paused_p npv_paused_p +#define perr npv_perr +#define pout npv_pout +#define vfatal npv_vfatal +#define vwarning npv_vwarning +#define vpout npv_vpout +#define vperr npv_vperr +#define warning npv_warning /*============================================================================*/ #else #undef ep_fd_p +#undef exit_ok +#undef fatal #undef paused_p +#undef perr +#undef pout +#undef vfatal +#undef vwarning +#undef vpout +#undef vperr +#undef warning #endif diff --git a/npv/pipeline/local/code.frag.c b/npv/pipeline/local/code.frag.c index 8557e17..0fa7a21 100644 --- a/npv/pipeline/local/code.frag.c +++ b/npv/pipeline/local/code.frag.c @@ -1,3 +1,21 @@ +STATIC void fatal(u8 *fmt, ...) +{ + va_list ap; + + npv_perr("pipeline:"); + va_start(ap, fmt); + npv_vfatal(fmt, ap); + va_end(ap); /* unreachable */ +} +STATIC void pout(u8 *fmt, ...) +{ + va_list ap; + + npv_pout("pipeline:"); + va_start(ap, fmt); + npv_vpout(fmt, ap); + va_end(ap); +} STATIC void wait(long ns) { struct timespec wanted; @@ -14,7 +32,7 @@ STATIC void wait(long ns) if (r == 0) break; if (r != EINTR) - FATALP("data wait timer failed:%d\n", r); + fatal("data wait timer failed:%d\n", r); /* r == EINTR */ memcpy(&wanted, &rem, sizeof(wanted)); memset(&rem, 0, sizeof(rem)); @@ -52,10 +70,10 @@ STATIC void *read_thd_entry(void *arg) r = sigfillset(&sset); if (r == -1) - FATALP("read thread:unable to get a full signal mask\n"); + fatal("read thread:unable to get a full signal mask\n"); r = pthread_sigmask(SIG_SETMASK, &sset, 0); if (r != 0) - FATALP("read thread:unable to \"block\" \"all\" signals\n"); + fatal("read thread:unable to \"block\" \"all\" signals\n"); read(); /* unreachable */ } @@ -113,10 +131,10 @@ STATIC void *audio_thd_entry(void *arg) r = sigfillset(&sset); if (r == -1) - FATALP("send thread:unable to get a full signal mask\n"); + fatal("send thread:unable to get a full signal mask\n"); r = pthread_sigmask(SIG_SETMASK, &sset, 0); if (r != 0) - FATALP("send thread:unable to \"block\" \"all\" signals\n"); + fatal("send thread:unable to \"block\" \"all\" signals\n"); audio(); /* unreachable */ } @@ -170,10 +188,10 @@ STATIC void *video_thd_entry(void *arg) r = sigfillset(&sset); if (r == -1) - FATALP("send thread:unable to get a full signal mask\n"); + fatal("send thread:unable to get a full signal mask\n"); r = pthread_sigmask(SIG_SETMASK, &sset, 0); if (r != 0) - FATALP("send thread:unable to \"block\" \"all\" signals\n"); + fatal("send thread:unable to \"block\" \"all\" signals\n"); video(); /* unreachable */ } diff --git a/npv/pipeline/main.c b/npv/pipeline/main.c index 5679b81..c05a201 100644 --- a/npv/pipeline/main.c +++ b/npv/pipeline/main.c @@ -5,6 +5,7 @@ * copyright (C) 2020 Sylvain BERTRAND */ #include +#include #include #include #include @@ -12,6 +13,7 @@ #include #include "npv/c_fixing.h" #include "npv/global.h" +#include "npv/public.h" #include "npv/pkt_q/public.h" #include "npv/pipeline/public.h" #include "npv/fmt/public.h" @@ -22,19 +24,11 @@ #include "npv/pipeline/namespace/public.h" #include "npv/pipeline/namespace/main.c" /*----------------------------------------------------------------------------*/ -#define FATALP(fmt, ...) FATAL("pipeline:" fmt, ##__VA_ARGS__) -#define WARNINGP(fmt, ...) WARNING("pipeline:" fmt, ##__VA_ARGS__) -#define POUTP(fmt, ...) POUT("pipeline:" fmt, ##__VA_ARGS__) -/*----------------------------------------------------------------------------*/ #include "npv/pipeline/local/state.frag.c" /*----------------------------------------------------------------------------*/ #include "npv/pipeline/local/code.frag.c" #include "npv/pipeline/public/code.frag.c" /*----------------------------------------------------------------------------*/ -#undef FATALP -#undef WARNINGP -#undef POUTP -/*---------------------------------------------------------------------------*/ #define CLEANUP #include "npv/namespace/ffmpeg.h" #include "npv/pipeline/namespace/public.h" diff --git a/npv/pipeline/namespace/main.c b/npv/pipeline/namespace/main.c index 3b29232..35f28c2 100644 --- a/npv/pipeline/namespace/main.c +++ b/npv/pipeline/namespace/main.c @@ -6,8 +6,10 @@ #define audio npv_pipeline_audio #define audio_thd_entry npv_pipeline_audio_thd_entry #define eof_pkt_l npv_pipeline_eof_pkt_l +#define fatal npv_pipeline_fatal #define have_enough_predecoded_audio_frs npv_pipeline_have_enough_predecoded_audio_frs #define have_enough_predecoded_video_frs npv_pipeline_have_enough_predecoded_video_frs +#define pout npv_pipeline_pout #define read npv_pipeline_read #define read_thd_entry npv_pipeline_read_thd_entry #define timer_ack npv_pipeline_timer_ack @@ -20,8 +22,10 @@ #undef audio #undef audio_thd_entry #undef eof_pkt_l +#undef fatal #undef have_enough_predecoded_audio_frs #undef have_enough_predecoded_video_frs +#undef pout #undef read #undef read_thd_entry #undef timer_ack diff --git a/npv/pipeline/public/code.frag.c b/npv/pipeline/public/code.frag.c index 4cbc664..f522590 100644 --- a/npv/pipeline/public/code.frag.c +++ b/npv/pipeline/public/code.frag.c @@ -11,18 +11,18 @@ STATIC void limits_reset(void) STATIC void prefill_reset(u8 percent) { if (percent > 100) - FATALP("invalid prefill of %u%% for the buffer of packet queues\n", percent); + fatal("invalid prefill of %u%% for the buffer of packet queues\n", percent); if (percent != 0) { limits_p.pkts.prefill.audio_bytes_rem = limits_p.pkts.limit.audio_bytes_n * percent / 100; - POUTP("prefill size for the audio packet queue buffer is %u%%/%"PRId64" bytes\n", percent, limits_p.pkts.prefill.audio_bytes_rem); + pout("prefill size for the audio packet queue buffer is %u%%/%"PRId64" bytes\n", percent, limits_p.pkts.prefill.audio_bytes_rem); limits_p.pkts.prefill.video_bytes_rem = limits_p.pkts.limit.video_bytes_n * percent / 100; - POUTP("prefill size for the video packet queue buffer is %u%%/%"PRId64" bytes\n", percent, limits_p.pkts.prefill.video_bytes_rem); + pout("prefill size for the video packet queue buffer is %u%%/%"PRId64" bytes\n", percent, limits_p.pkts.prefill.video_bytes_rem); } else { limits_p.pkts.prefill.audio_bytes_rem = 0; limits_p.pkts.prefill.video_bytes_rem = 0; - POUTP("prefill for the packet queue buffers is disabled\n"); + pout("prefill for the packet queue buffers is disabled\n"); } } STATIC void init_once(void) @@ -31,13 +31,13 @@ STATIC void init_once(void) eof_pkt_l = avcodec_pkt_ref_alloc(); if (eof_pkt_l == 0) - FATALP("ffmpeg:unable to allocate a null/eof reference on a packet\n"); + fatal("ffmpeg:unable to allocate a null/eof reference on a packet\n"); eof_pkt_l->data = 0; eof_pkt_l->sz = 0; r = pthread_mutex_init(&limits_p.mutex, 0); if (r != 0) - FATALP("unable to initialize the mutex to guard the accounting of limits\n"); + fatal("unable to initialize the mutex to guard the accounting of limits\n"); } STATIC void limits_lock(void) { @@ -45,7 +45,7 @@ STATIC void limits_lock(void) r = pthread_mutex_lock(&limits_p.mutex); if (r != 0) - FATALP("unable to lock the limits\n"); + fatal("unable to lock the limits\n"); } STATIC void limits_unlock(void) { @@ -53,7 +53,7 @@ STATIC void limits_unlock(void) r = pthread_mutex_unlock(&limits_p.mutex); if (r != 0) - FATALP("unable to unlock the limits\n"); + fatal("unable to unlock the limits\n"); } STATIC void read_thd_start(void) { @@ -63,14 +63,14 @@ STATIC void read_thd_start(void) r = pthread_attr_init(&attr); if (r != 0) - FATALP("unable to initialize read thread attribute\n"); + fatal("unable to initialize read thread attribute\n"); r = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); if (r != 0) - FATALP("unable to set the read thread attribute to detach mode\n"); + fatal("unable to set the read thread attribute to detach mode\n"); r = pthread_create(&id, &attr, &read_thd_entry, 0); if (r != 0) - FATALP("unable to create the read thread\n"); - POUTP("read thread %lu\n", (unsigned long)id); + fatal("unable to create the read thread\n"); + pout("read thread %lu\n", (unsigned long)id); pthread_attr_destroy(&attr); } STATIC void audio_thd_start(void) @@ -81,14 +81,14 @@ STATIC void audio_thd_start(void) r = pthread_attr_init(&attr); if (r != 0) - FATALP("unable to initialize audio thread attribute\n"); + fatal("unable to initialize audio thread attribute\n"); r = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); if (r != 0) - FATALP("unable to set the audio thread attribute to detach mode\n"); + fatal("unable to set the audio thread attribute to detach mode\n"); r = pthread_create(&id, &attr, &audio_thd_entry, 0); if (r != 0) - FATALP("unable to create the audio thread\n"); - POUTP("audio thread %lu\n", (unsigned long)id); + fatal("unable to create the audio thread\n"); + pout("audio thread %lu\n", (unsigned long)id); pthread_attr_destroy(&attr); } STATIC void video_thd_start(void) @@ -99,13 +99,13 @@ STATIC void video_thd_start(void) r = pthread_attr_init(&attr); if (r != 0) - FATALP("unable to initialize video thread attribute\n"); + fatal("unable to initialize video thread attribute\n"); r = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); if (r != 0) - FATALP("unable to set the video thread attribute to detach mode\n"); + fatal("unable to set the video thread attribute to detach mode\n"); r = pthread_create(&id, &attr, &video_thd_entry, 0); if (r != 0) - FATALP("unable to create the video thread\n"); - POUTP("video thread %lu\n", (unsigned long)id); + fatal("unable to create the video thread\n"); + pout("video thread %lu\n", (unsigned long)id); pthread_attr_destroy(&attr); } diff --git a/npv/pkt_q/local/code.frag.c b/npv/pkt_q/local/code.frag.c index d1d4c92..fb03e2b 100644 --- a/npv/pkt_q/local/code.frag.c +++ b/npv/pkt_q/local/code.frag.c @@ -1,3 +1,21 @@ +STATIC void fatal(u8 *fmt, ...) +{ + va_list ap; + + npv_perr("packet queue:"); + va_start(ap, fmt); + npv_vfatal(fmt, ap); + va_end(ap); /* unreachable */ +} +STATIC void fatalx(u8 *fmt, struct pkt_q_t *this, ...) +{ + va_list ap; + + npv_perr("%s:packet queue:", this->msg_hdr); + va_start(ap, this); + npv_vfatal(fmt, ap); + va_end(ap); /* unreachable */ +} STATIC void grow(struct pkt_q_t *this) { u32 p; @@ -6,9 +24,9 @@ STATIC void grow(struct pkt_q_t *this) new_idx = this->n_max; this->q = realloc(this->q, sizeof(*this->q) * (this->n_max + 1)); if (this->q == 0) - FATALXPQ("unable to allocate more memory for packet reference pointers\n"); + fatalx("unable to allocate more memory for packet reference pointers\n", this); this->q[new_idx] = avcodec_pkt_ref_alloc(); if (this->q[new_idx] == 0) - FATALXPQ("ffmpeg:unable to allocate a new packet reference\n"); + fatalx("ffmpeg:unable to allocate a new packet reference\n", this); ++this->n_max; } diff --git a/npv/pkt_q/main.c b/npv/pkt_q/main.c index df4253a..775c86a 100644 --- a/npv/pkt_q/main.c +++ b/npv/pkt_q/main.c @@ -1,17 +1,16 @@ #ifndef NPV_PKT_Q_MAIN_C #define NPV_PKT_Q_MAIN_C #include +#include #include #include #include #include "npv/c_fixing.h" #include "npv/global.h" +#include "npv/public.h" #include "npv/pkt_q/public.h" #include "npv/pipeline/public.h" /*----------------------------------------------------------------------------*/ -#define FATALPQ(fmt, ...) FATAL("packet queue:" fmt, ##__VA_ARGS__) -#define FATALXPQ(fmt, ...) FATAL("%s:packet queue:" fmt, this->msg_hdr, ##__VA_ARGS__) -/*----------------------------------------------------------------------------*/ #include "npv/namespace/ffmpeg.h" #include "npv/pkt_q/namespace/public.h" #include "npv/pkt_q/namespace/main.c" @@ -19,9 +18,6 @@ #include "npv/pkt_q/local/code.frag.c" #include "npv/pkt_q/public/code.frag.c" /*----------------------------------------------------------------------------*/ -#undef FATALPQ -#undef FATALXPQ -/*----------------------------------------------------------------------------*/ #define CLEANUP #include "npv/namespace/ffmpeg.h" #include "npv/pkt_q/namespace/public.h" diff --git a/npv/pkt_q/namespace/main.c b/npv/pkt_q/namespace/main.c index c7f494e..ed7e92e 100644 --- a/npv/pkt_q/namespace/main.c +++ b/npv/pkt_q/namespace/main.c @@ -1,5 +1,7 @@ #ifndef CLEANUP -#define grow npv_pkt_q_grow +#define fatal npv_pkt_q_fatal +#define fatalx npv_pkt_q_fatalx +#define grow npv_pkt_q_grow /*---------------------------------------------------------------------------*/ /* some struct field names */ #define sz size @@ -7,6 +9,8 @@ /*---------------------------------------------------------------------------*/ /*============================================================================*/ #else +#undef fatal +#undef fatalx #undef grow /*---------------------------------------------------------------------------*/ #undef sz diff --git a/npv/pkt_q/public/code.frag.c b/npv/pkt_q/public/code.frag.c index 73121c9..ce11e63 100644 --- a/npv/pkt_q/public/code.frag.c +++ b/npv/pkt_q/public/code.frag.c @@ -4,7 +4,7 @@ STATIC void lock(struct pkt_q_t *this) r = pthread_mutex_lock(&this->mutex); if (r != 0) - FATALXPQ("%d:unable to lock packet queue\n", r); + fatalx("%d:unable to lock packet queue\n", this, r); } STATIC void unlock(struct pkt_q_t *this) { @@ -12,7 +12,7 @@ STATIC void unlock(struct pkt_q_t *this) r = pthread_mutex_unlock(&this->mutex); if (r != 0) - FATALXPQ("%d:unable to unlock packet queue\n", r); + fatalx("%d:unable to unlock packet queue\n", this, r); } /* actually rotate the pkt ref ptrs */ STATIC void deq(struct pkt_q_t *this) @@ -55,14 +55,14 @@ STATIC struct pkt_q_t *new(u8 *msg_hdr) this = malloc(sizeof(*this)); if (this == 0) - FATALPQ("unable to allocate memory for the %s packet queue\n", msg_hdr); + fatal("unable to allocate memory for the %s packet queue\n", msg_hdr); this->q = 0; this->n = 0; this->n_max = 0; this->msg_hdr = strdup(msg_hdr); r = pthread_mutex_init(&this->mutex, 0); if (r != 0) - FATALPQ("unable to init the mutex for the %s packet queue\n", msg_hdr); + fatal("unable to init the mutex for the %s packet queue\n", msg_hdr); return this; } STATIC bool has_eof(struct pkt_q_t *this) diff --git a/npv/public.h b/npv/public.h index e6d1950..3b37217 100644 --- a/npv/public.h +++ b/npv/public.h @@ -5,11 +5,24 @@ * copyright (C) 2020 Sylvain BERTRAND */ #include -/*---------------------------------------------------------------------------*/ +#include +#include +#include "npv/c_fixing.h" +/*----------------------------------------------------------------------------*/ #include "npv/namespace/public.h" -/*---------------------------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ #include "npv/public/state.frag.h" -/*---------------------------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ +STATIC void pout(u8 *fmt, ...); +STATIC void vpout(u8 *fmt, va_list ap); +STATIC void perr(u8 *fmt, ...); +STATIC void vperr(u8 *fmt, va_list ap); +STATIC void warning(u8 *fmt, ...); +STATIC void vwarning(u8 *fmt, va_list ap); +STATIC void fatal(u8 *fmt, ...); +STATIC void vfatal(u8 *fmt, va_list ap); +STATIC void exit_ok(u8 *fmt, ...); +/*----------------------------------------------------------------------------*/ #define CLEANUP #include "npv/namespace/public.h" #undef CLEANUP diff --git a/npv/public/code.frag.c b/npv/public/code.frag.c new file mode 100644 index 0000000..7fded40 --- /dev/null +++ b/npv/public/code.frag.c @@ -0,0 +1,88 @@ +STATIC void pout(u8 *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + flockfile(stdout); + vfprintf(stdout, fmt, ap); + funlockfile(stdout); + va_end(ap); +} +STATIC void vpout(u8 *fmt, va_list ap) +{ + va_list aq; + + va_copy(aq, ap); + flockfile(stdout); + vfprintf(stdout, fmt, aq); + funlockfile(stdout); + va_end(aq); +} +STATIC void perr(u8 *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + flockfile(stderr); + vfprintf(stderr, fmt, ap); + funlockfile(stderr); + va_end(ap); +} +STATIC void vperr(u8 *fmt, va_list ap) +{ + va_list aq; + + va_copy(aq, ap); + flockfile(stderr); + vfprintf(stderr, fmt, aq); + funlockfile(stderr); + va_end(aq); +} +STATIC void warning(u8 *fmt, ...) +{ + va_list ap; + + perr("WARNING:"); + va_start(ap, fmt); + vperr(fmt, ap); + va_end(ap); +} +STATIC void vwarning(u8 *fmt, va_list ap) +{ + va_list aq; + + perr("WARNING:"); + va_copy(aq, ap); + vperr(fmt, aq); + va_end(aq); +} +STATIC void fatal(u8 *fmt, ...) +{ + va_list ap; + + perr("FATAL:"); + va_start(ap, fmt); + vperr(fmt, ap); + va_end(ap); + exit(EXIT_FAILURE); +} +STATIC void vfatal(u8 *fmt, va_list ap) +{ + va_list aq; + + perr("FATAL:"); + va_copy(aq, ap); + vperr(fmt, aq); + va_end(aq); + exit(EXIT_FAILURE); +} +STATIC void exit_ok(u8 *fmt, ...) +{ + va_list ap; + + pout("EXIT:"); + va_start(ap, fmt); + vpout(fmt, ap); + va_end(ap); + exit(EXIT_SUCCESS); +} diff --git a/npv/thdsws/local/code.frag.c b/npv/thdsws/local/code.frag.c index 9edf3ed..2dcf8b0 100644 --- a/npv/thdsws/local/code.frag.c +++ b/npv/thdsws/local/code.frag.c @@ -4,13 +4,31 @@ struct thdsws_ctx_private_t { pthread_cond_t have_fr_to_scale; struct SwsContext *sws; }; +STATIC void fatal(u8 *fmt, ...) +{ + va_list ap; + + npv_perr("scaler:"); + va_start(ap, fmt); + npv_vfatal(fmt, ap); + va_end(ap); /* unreachable */ +} +STATIC void fatalw(u8 *fmt, ...) +{ + va_list ap; + + npv_perr("scaler worker:"); + va_start(ap, fmt); + npv_vfatal(fmt, ap); + va_end(ap); /* unreachable */ +} STATIC void state_lock(struct thdsws_ctx_private_t *ctx_priv) { int r; r = pthread_mutex_lock(&ctx_priv->mutex); if (r != 0) - FATALTS("unable to lock the state\n"); + fatal("unable to lock the state\n"); } STATIC void state_unlock(struct thdsws_ctx_private_t *ctx_priv) { @@ -18,7 +36,7 @@ STATIC void state_unlock(struct thdsws_ctx_private_t *ctx_priv) r = pthread_mutex_unlock(&ctx_priv->mutex); if (r != 0) - FATALTS("unable to unlock the state\n"); + fatal("unable to unlock the state\n"); } STATIC void do_work(struct thdsws_ctx_t *ctx, struct thdsws_ctx_private_t *ctx_priv) { @@ -27,7 +45,7 @@ STATIC void do_work(struct thdsws_ctx_t *ctx, struct thdsws_ctx_private_t *ctx_p (int)ctx->cfg.width, (int)ctx->cfg.height, ctx->cfg.dst_fmt, (int)ctx->cfg.flags, 0, 0, 0); if (ctx_priv->sws == 0) - FATALTSW("unable to get a ffmpeg context\n"); + fatalw("unable to get a ffmpeg context\n"); /* XXX: this is the hotspot */ (void)sws_scale(ctx_priv->sws, @@ -58,7 +76,7 @@ STATIC void worker(struct thdsws_ctx_t *ctx, &ctx_priv->mutex); /* on exit the mutex is locked */ if (r != 0) - FATALTSW("an error occured while waiting for a frame\n"); + fatalw("an error occured while waiting for a frame\n"); if (ctx_priv->state != IDLE) break; /* state == IDLE */ @@ -75,11 +93,11 @@ STATIC void *worker_entry(void *arg) r = sigfillset(&sset); if (r == -1) - FATALTSW("unable to get a full signal mask\n"); + fatalw("unable to get a full signal mask\n"); r = pthread_sigmask(SIG_SETMASK, &sset, 0); if (r != 0) - FATALTSW("unable to \"block\" \"all\" signals\n"); + fatalw("unable to \"block\" \"all\" signals\n"); ctx = arg; ctx_priv = ctx->private; diff --git a/npv/thdsws/main.c b/npv/thdsws/main.c index b9b1c00..fee6e13 100644 --- a/npv/thdsws/main.c +++ b/npv/thdsws/main.c @@ -5,6 +5,7 @@ * copyright (C) 2020 Sylvain BERTRAND */ #include +#include #include #include #include @@ -13,21 +14,16 @@ #include #include "npv/c_fixing.h" #include "npv/global.h" +#include "npv/public.h" #include "npv/thdsws/public.h" /*----------------------------------------------------------------------------*/ #include "npv/namespace/ffmpeg.h" #include "npv/thdsws/namespace/public.h" #include "npv/thdsws/namespace/main.c" /*----------------------------------------------------------------------------*/ -#define FATALTS(fmt, ...) FATAL("scaler:" fmt, ##__VA_ARGS__) -#define FATALTSW(fmt, ...) FATAL("scaler worker:" fmt, ##__VA_ARGS__) -/*----------------------------------------------------------------------------*/ #include "npv/thdsws/local/code.frag.c" #include "npv/thdsws/public/code.frag.c" /*----------------------------------------------------------------------------*/ -#undef FATALTS -#undef FATALTSW -/*----------------------------------------------------------------------------*/ #define CLEANUP #include "npv/namespace/ffmpeg.h" #include "npv/thdsws/namespace/public.h" diff --git a/npv/thdsws/namespace/main.c b/npv/thdsws/namespace/main.c index 6bc4dbc..f1a9355 100644 --- a/npv/thdsws/namespace/main.c +++ b/npv/thdsws/namespace/main.c @@ -1,10 +1,14 @@ #ifndef CLEANUP +#define fatal npv_thdsws_fatal +#define fatalw npv_thdsws_fatalw #define worker_entry npv_thdsws_worker_entry #define worker npv_thdsws_worker #define do_work npv_thdsws_do_work #define state_lock npv_thdsws_state_lock #define state_unlock npv_thdsws_state_unlock #else +#undef fatal +#undef fatalw #undef worker_entry #undef worker #undef do_work diff --git a/npv/thdsws/public/code.frag.c b/npv/thdsws/public/code.frag.c index f993791..d8ca6b2 100644 --- a/npv/thdsws/public/code.frag.c +++ b/npv/thdsws/public/code.frag.c @@ -8,12 +8,12 @@ STATIC void thdsws_run(struct thdsws_ctx_t *ctx) state_lock(ctx_priv); if (ctx_priv->state == RUNNING) - FATALTS("the worker thread is already running, did you forget to wait for it to idle\n"); + fatal("the worker thread is already running, did you forget to wait for it to idle\n"); ctx_priv->state = RUNNING; state_unlock(ctx_priv); r = pthread_cond_signal(&ctx_priv->have_fr_to_scale); if (r != 0) - FATALTS("unable to signal the worker thread a frame is to be scaled\n"); + fatal("unable to signal the worker thread a frame is to be scaled\n"); } #undef RUNNING #define RUNNING 1 @@ -43,32 +43,32 @@ STATIC struct thdsws_ctx_t *thdsws_init_once(void) ctx = calloc(1, sizeof(*ctx)); if (ctx == 0) - FATALTS("unable to allocate memory for context\n"); + fatal("unable to allocate memory for context\n"); ctx_priv = calloc(1, sizeof(*ctx_priv)); if (ctx_priv == 0) - FATALTS("unable to allocate memory for private context\n"); + fatal("unable to allocate memory for private context\n"); ctx->private = ctx_priv; r = pthread_mutex_init(&ctx_priv->mutex, 0); if (r != 0) - FATALTS("unable to create the state mutex\n"); + fatal("unable to create the state mutex\n"); r = pthread_cond_init(&ctx_priv->have_fr_to_scale, 0); if (r != 0) - FATALTS("unable to create waiting condition\n"); + fatal("unable to create waiting condition\n"); r = pthread_attr_init(&attr); if (r != 0) - FATALTS("unable to initialize a worker thread attribute\n"); + fatal("unable to initialize a worker thread attribute\n"); r = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); if (r != 0) - FATALTS("unable to set the worker thread attribute to detach mode\n"); + fatal("unable to set the worker thread attribute to detach mode\n"); /* be really sure the entry state is correct _before_ thd creation */ ctx_priv->state = IDLE; r = pthread_create(&worker, &attr, &worker_entry, ctx); if (r != 0) - FATALTS("unable to create the worker thread\n"); + fatal("unable to create the worker thread\n"); pthread_attr_destroy(&attr); return ctx; } @@ -101,11 +101,11 @@ STATIC void thdsws_wait_for_idle(struct thdsws_ctx_t *ctx) memcpy(&ts, &rem, sizeof(ts)); continue; } - FATALTS("unable to sleep to wait for idle\n"); + fatal("unable to sleep to wait for idle\n"); } ++nanoloops_n; if (nanoloops_n == TIMEOUT_UNITS_N) - FATALTS("wait for idle timeout\n"); + fatal("wait for idle timeout\n"); } } #undef TIME_UNIT_NS diff --git a/npv/video/local/code.frag.c b/npv/video/local/code.frag.c index 8115561..0ccccd2 100644 --- a/npv/video/local/code.frag.c +++ b/npv/video/local/code.frag.c @@ -1,3 +1,57 @@ +STATIC void fatal(u8 *fmt, ...) +{ + va_list ap; + + npv_perr("video:"); + va_start(ap, fmt); + npv_vfatal(fmt, ap); + va_end(ap); /* unreachable */ +} +STATIC void warning(u8 *fmt, ...) +{ + va_list ap; + + npv_perr("video:"); + va_start(ap, fmt); + npv_vwarning(fmt, ap); + va_end(ap); +} +STATIC void fatalff(u8 *fmt, ...) +{ + va_list ap; + + npv_perr("ffmpeg:"); + va_start(ap, fmt); + npv_vfatal(fmt, ap); + va_end(ap); /* unreachable */ +} +STATIC void poutff(u8 *fmt, ...) +{ + va_list ap; + + npv_pout("ffmpeg:"); + va_start(ap, fmt); + npv_vpout(fmt, ap); + va_end(ap); +} +STATIC void fatalvk(u8 *fmt, ...) +{ + va_list ap; + + npv_perr("video:"); + va_start(ap, fmt); + npv_vk_vfatal(fmt, ap); + va_end(ap); /* unreachable */ +} +STATIC void warningvk(u8 *fmt, ...) +{ + va_list ap; + + npv_perr("video:"); + va_start(ap, fmt); + npv_vk_vwarning(fmt, ap); + va_end(ap); +} STATIC void init_once_local(void) { u8 i; @@ -154,10 +208,9 @@ STATIC bool try_alloc_scaler_img_dev_mem(struct vk_mem_rqmts_t *img_rqmts, info.mem_type_idx = mem_type_idx; vk_alloc_mem(&info, &scaler_p.img.dev_mem); if (r < 0) { - 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); + 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); return false; } - //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); return true; } /* @@ -183,7 +236,7 @@ STATIC void scaler_img_dev_mem_alloc(void) ++mem_type; } if (!npv_vk_surf_p.dev.phydev.is_discret_gpu) - FATALVVK("physical device:%p:scaler image:unable to find proper memory type or to allocate memory\n", npv_vk_surf_p.dev.phydev.vk); + fatalvk("physical device:%p:scaler image:unable to find proper memory type or to allocate memory\n", npv_vk_surf_p.dev.phydev.vk); /* * lookup again, but relax the match based on discret gpu constraint for * gpu @@ -197,7 +250,7 @@ STATIC void scaler_img_dev_mem_alloc(void) return; ++mem_type; } - FATALVVK("physical device:%p:unable to find proper memory type or to allocate memory\n", npv_vk_surf_p.dev.phydev.vk); + fatalvk("physical device:%p:unable to find proper memory type or to allocate memory\n", npv_vk_surf_p.dev.phydev.vk); } #undef IGNORE_GPU_IS_DISCRET STATIC void scaler_img_dev_mem_bind(void) @@ -231,18 +284,18 @@ STATIC void dec_a_grow(void) dec_frs_p.a = realloc(dec_frs_p.a, sizeof(*dec_frs_p.a) * (dec_frs_p.n_max + 1)); if (dec_frs_p.a == 0) - FATALV("unable to allocate memory for an additional pointer on a decoded frame reference\n"); + fatal("unable to allocate memory for an additional pointer on a decoded frame reference\n"); dec_frs_p.priv_a = realloc(dec_frs_p.priv_a, sizeof(*dec_frs_p.priv_a) * (dec_frs_p.n_max + 1)); if (dec_frs_p.priv_a == 0) - FATALV("unable to allocate memory for an additional pointer on private data for decoded frames\n"); + fatal("unable to allocate memory for an additional pointer on private data for decoded frames\n"); dec_frs_p.a[new_idx] = avutil_video_fr_ref_alloc(); if (dec_frs_p.a[new_idx] == 0) - FATALV("ffmpeg:unable to allocate a decoded frame reference\n"); + fatal("ffmpeg:unable to allocate a decoded frame reference\n"); dec_frs_p.priv_a[new_idx] = calloc(1, sizeof(**dec_frs_p.priv_a)); if (dec_frs_p.priv_a[new_idx] == 0) - FATALV("unable to allocate decoded frame private data\n"); + fatal("unable to allocate decoded frame private data\n"); ++dec_frs_p.n_max; } @@ -255,7 +308,7 @@ STATIC void fr_drop(u16 fr) priv_save = dec_frs_p.priv_a[fr]; if (!priv_save->was_qed_to_pe) - WARNINGV("dropping undisplayed frame\n"); + warning("dropping undisplayed frame\n"); save = dec_frs_p.a[fr]; avutil_video_fr_unref(save); memset(priv_save, 0, sizeof(*priv_save)); @@ -494,7 +547,7 @@ STATIC u8 swpchn_next_img(u32 *swpchn_img) { loop continue; } else if (r >= 0) return READY; - 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); + 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); }} #undef READY #undef NOT_READY @@ -584,5 +637,5 @@ STATIC void timer_ack(void) exps_n = 0; r = read(timer_fd_p, &exps_n, sizeof(exps_n)); if (r == -1) - FATALV("unable to read the number of timer expirations\n"); + fatal("unable to read the number of timer expirations\n"); } diff --git a/npv/video/main.c b/npv/video/main.c index 6ed4966..e538da2 100644 --- a/npv/video/main.c +++ b/npv/video/main.c @@ -5,6 +5,7 @@ * copyright (C) 2020 Sylvain BERTRAND */ #include +#include #include #include #include @@ -33,33 +34,13 @@ #include "npv/video/namespace/public.h" #include "npv/video/namespace/main.c" /*----------------------------------------------------------------------------*/ -#define FATALV(fmt, ...) FATAL("video:" fmt, ##__VA_ARGS__) -#define WARNINGV(fmt, ...) WARNING("video:" fmt, ##__VA_ARGS__) -#define POUTV(fmt, ...) POUT("video:" fmt, ##__VA_ARGS__) - -#define FATALVFF(fmt, ...) FATALV("ffmpeg:" fmt, ##__VA_ARGS__) -#define WARNINGVFF(fmt, ...) WARNINGV("ffmpeg:" fmt, ##__VA_ARGS__) -#define POUTVFF(fmt, ...) POUTV("ffmpeg:" fmt, ##__VA_ARGS__) - -#define FATALVVK(fmt, ...) FATALVK("video:" fmt, ##__VA_ARGS__) -#define POUTVVK(fmt, ...) POUTVK("video:" fmt, ##__VA_ARGS__) -#define WARNINGVVK(fmt, ...) WARNINGVK("video:" fmt, ##__VA_ARGS__) -#define IF_FATALVVK(fmt, ...) IF_FATALVK("video:" fmt, ##__VA_ARGS__) +#define IF_FATALVVK(...) IF_FATALVK("video:" __VA_ARGS__) /*----------------------------------------------------------------------------*/ #include "npv/video/local/state.frag.c" /*----------------------------------------------------------------------------*/ #include "npv/video/local/code.frag.c" #include "npv/video/public/code.frag.c" /*----------------------------------------------------------------------------*/ -#undef FATALV -#undef WARNINGV -#undef POUTV -#undef FATALVFF -#undef WARNINGVFF -#undef POUTVFF -#undef FATALVVK -#undef POUTVVK -#undef WARNINGVVK #undef IF_FATALVVK /*----------------------------------------------------------------------------*/ #define CLEANUP diff --git a/npv/video/namespace/main.c b/npv/video/namespace/main.c index dd118e0..7844aa7 100644 --- a/npv/video/namespace/main.c +++ b/npv/video/namespace/main.c @@ -11,6 +11,9 @@ #define dec_a_grow npv_video_dec_a_grow #define dec_ctx_mutex_l npv_video_dec_ctx_mutex_l #define dec_l npv_video_dec_l +#define fatal npv_video_fatal +#define fatalff npv_video_fatalff +#define fatalvk npv_video_fatalvk #define fr_drop npv_video_fr_drop #define frs_drop npv_video_frs_drop #define frs_clear_last_qed_to_pe npv_video_frs_clear_last_qed_to_pe @@ -20,6 +23,7 @@ #define init_once_public npv_video_init_once_public #define last_fr_sent_to_pe_l npv_video_last_fr_sent_to_pe_l #define match_mem_type npv_video_match_mem_type +#define poutff npv_video_poutff #define receive_fr_l npv_video_receive_fr_l #define scaler_img_create npv_video_scaler_img_create #define scaler_img_destroy npv_video_scaler_img_destroy @@ -36,6 +40,8 @@ #define tmp_mem_rqmts_l npv_video_tmp_mem_rqmts_l #define tmp_scaler_img_mem_rqmts_get npv_video_tmp_scaler_img_mem_rqmts_get #define try_alloc_scaler_img_dev_mem npv_video_try_alloc_scaler_img_dev_mem +#define warning npv_video_warning +#define warningvk npv_video_warningvk /*============================================================================*/ #else /*----------------------------------------------------------------------------*/ @@ -50,6 +56,9 @@ #undef dec_a_grow #undef dec_ctx_mutex_l #undef dec_l +#undef fatal +#undef fatalff +#undef fatalvk #undef fr_drop #undef frs_clear_last_qed_to_pe #undef frs_drop @@ -59,6 +68,7 @@ #undef init_once_public #undef last_fr_sent_to_pe_l #undef match_mem_type +#undef poutff #undef receive_fr_l #undef scaler_img_create #undef scaler_img_destroy @@ -75,4 +85,6 @@ #undef tmp_mem_rqmts_l #undef tmp_scaler_img_mem_rqmts_get #undef try_alloc_scaler_img_dev_mem +#undef warning +#undef warningvk #endif diff --git a/npv/video/public/code.frag.c b/npv/video/public/code.frag.c index 0087c16..b2604be 100644 --- a/npv/video/public/code.frag.c +++ b/npv/video/public/code.frag.c @@ -7,13 +7,13 @@ STATIC void init_once_public(void) errno = 0; timer_fd_p = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK); if (timer_fd_p == -1) - FATALV("unable to get a timer file descriptor:%s\n", strerror(errno)); + fatal("unable to get a timer file descriptor:%s\n", strerror(errno)); memset(&st_p, 0, sizeof(st_p)); pkt_q_p = npv_pkt_q_new("video"); dec_ctx_p = 0; r = pthread_mutex_init(&dec_ctx_mutex_l, 0); if (r != 0) - FATALV("unable to create the mutex for the decoder context\n"); + fatal("unable to create the mutex for the decoder context\n"); dec_frs_p.eof_receive = false; dec_frs_p.n_max = 0; @@ -22,7 +22,7 @@ STATIC void init_once_public(void) dec_frs_p.priv_a = 0; r = pthread_mutex_init(&dec_frs_p.mutex, 0); if (r != 0) - FATALV("unable to create the mutex for the array of frames\n"); + fatal("unable to create the mutex for the array of frames\n"); scaler_p.img.vk = 0; memset(&scaler_p.img.layout, 0, sizeof(scaler_p.img.layout)); @@ -38,7 +38,7 @@ STATIC void init_once_public(void) /* we are targetting AVUTIL_PIX_FMT_RGB32/sRGB */ scaler_p.ctx = npv_thdsws_init_once(); if (scaler_p.ctx == 0) - FATALVFF("scaler:unable to initialize\n"); + fatalff("scaler:unable to initialize\n"); } #undef NO_FR STATIC void init_once(void) @@ -52,20 +52,20 @@ STATIC void dec_ctx_cfg(avcodec_params_t *params) dec_l = avcodec_find_dec(params->codec_id); if (dec_l == 0) - FATALVFF("unable to find a proper decoder\n"); + fatalff("unable to find a proper decoder\n"); avcodec_free_context(&dec_ctx_p); dec_ctx_p = avcodec_alloc_ctx(dec_l); if (dec_ctx_p == 0) - FATALVFF("unable to allocate an decoder context\n"); + fatalff("unable to allocate an decoder context\n"); /* XXX: useless ? */ r = avcodec_params_to_ctx(dec_ctx_p, params); if (r < 0) - FATALVFF("unable to apply stream codec parameters in codec context\n"); + fatalff("unable to apply stream codec parameters in codec context\n"); /* XXX: ffmpeg thread count default is 1, set to 0 = auto */ dec_ctx_p->thread_count = 0; r = avcodec_open2(dec_ctx_p, dec_l, 0); if (r < 0) - FATALVFF("unable to open the decoder context\n"); + fatalff("unable to open the decoder context\n"); /* we will define the video aspect ratio with those values */ aspect_ratio.width = params->width; @@ -82,7 +82,7 @@ STATIC void timer_start(void) t.it_interval.tv_nsec = 2000000; /* 2ms */ r = timerfd_settime(timer_fd_p, 0, &t, 0); if (r == -1) - FATALV("unable to arm the timer\n"); + fatal("unable to arm the timer\n"); } STATIC void timer_slow_start(void) { @@ -95,7 +95,7 @@ STATIC void timer_slow_start(void) t.it_interval.tv_nsec = 100000000; /* 100ms */ r = timerfd_settime(timer_fd_p, 0, &t, 0); if (r == -1) - FATALV("unable to arm the timer\n"); + fatal("unable to arm the timer\n"); } #define AGAIN 0 #define HAVE_FR 1 @@ -122,13 +122,13 @@ STATIC u8 dec_fr_try_receive(void) dec_frs_unlock(); return HAVE_FR; } else if (r == AVUTIL_AVERROR_EOF) { - POUTVFF("last decoder frame reached (receiving)\n"); + poutff("last decoder frame reached (receiving)\n"); dec_frs_lock(); dec_frs_p.eof_receive = true; dec_frs_unlock(); return EOF_DEC; } - FATALVFF("error while receiving frame from the decoder\n"); + fatalff("error while receiving frame from the decoder\n"); } #undef AGAIN #undef HAVE_FR @@ -165,7 +165,7 @@ STATIC void dec_ctx_lock(void) r = pthread_mutex_lock(&dec_ctx_mutex_l); if (r != 0) - FATALV("%d:unable to lock the video decoder context\n", r); + fatal("%d:unable to lock the video decoder context\n", r); } STATIC void dec_ctx_unlock(void) { @@ -173,7 +173,7 @@ STATIC void dec_ctx_unlock(void) r = pthread_mutex_unlock(&dec_ctx_mutex_l); if (r != 0) - FATALV("%d:unable to unlock the video decoder context\n", r); + fatal("%d:unable to unlock the video decoder context\n", r); } STATIC void dec_frs_lock(void) { @@ -181,7 +181,7 @@ STATIC void dec_frs_lock(void) r = pthread_mutex_lock(&dec_frs_p.mutex); if (r != 0) - FATALV("%d:unable to lock the array of decoder frames\n", r); + fatal("%d:unable to lock the array of decoder frames\n", r); } STATIC void dec_frs_unlock(void) { @@ -189,7 +189,7 @@ STATIC void dec_frs_unlock(void) r = pthread_mutex_unlock(&dec_frs_p.mutex); if (r != 0) - FATALV("%d:unable to unlock the array of decoder frames\n", r); + fatal("%d:unable to unlock the array of decoder frames\n", r); } /* go non-blocking or a worker thread is needed */ #define NO_FR 0 @@ -269,7 +269,7 @@ STATIC void pkts_send(void) { loop else if (r == AVUTIL_AVERROR_EOF) /* the dec is in draining mode */ goto unlock_and_return; else if (r != 0) - FATALV("error while sending a packet to the decoder\n"); + fatal("error while sending a packet to the decoder\n"); /* r == 0 */ npv_pipeline_limits_lock(); npv_pipeline_limits_p.pkts.video_bytes_n -= pr->sz; diff --git a/npv/vk/api_usage.h b/npv/vk/api_usage.h index 3668ad1..8ee52a2 100644 --- a/npv/vk/api_usage.h +++ b/npv/vk/api_usage.h @@ -8,13 +8,9 @@ * this is the simplification and taylorization of vk api for the specific * uses of npv */ -#define FATALVK(fmt, ...) FATAL("vulkan:" fmt, ##__VA_ARGS__) -#define WARNINGVK(fmt, ...) WARNING("vulkan:" fmt, ##__VA_ARGS__) -#define POUTVK(fmt, ...) POUT("vulkan:" fmt, ##__VA_ARGS__) - #define IF_FATALVK(fmt, ...) \ if (r < 0) \ - FATALVK(fmt, ##__VA_ARGS__) + npv_vk_fatal(fmt, __VA_ARGS__) /*----------------------------------------------------------------------------*/ #define vk_get_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) @@ -74,10 +70,10 @@ r = npv_vk_surf_p.dev.dl_vk_q_submit(npv_vk_surf_p.dev.q, 1, info, 0) r = npv_vk_surf_p.dev.dl_vk_q_wait_idle(npv_vk_surf_p.dev.q) #define vk_get_img_subrsrc_layout(...) \ -npv_vk_surf_p.dev.dl_vk_get_img_subrsrc_layout(npv_vk_surf_p.dev.vk, ##__VA_ARGS__) +npv_vk_surf_p.dev.dl_vk_get_img_subrsrc_layout(npv_vk_surf_p.dev.vk, __VA_ARGS__) #define vk_acquire_next_img(...) \ -r = npv_vk_surf_p.dev.dl_vk_acquire_next_img(npv_vk_surf_p.dev.vk,##__VA_ARGS__) +r = npv_vk_surf_p.dev.dl_vk_acquire_next_img(npv_vk_surf_p.dev.vk, __VA_ARGS__) #define vk_reset_cb(cb) \ r = npv_vk_surf_p.dev.dl_vk_reset_cb(cb, 0) @@ -179,13 +175,13 @@ r = npv_dl_vk_enumerate_instance_version r = npv_dl_vk_enumerate_instance_layer_props #define vk_enumerate_instance_ext_props(...) \ -r = npv_dl_vk_enumerate_instance_ext_props(0,##__VA_ARGS__) +r = npv_dl_vk_enumerate_instance_ext_props(0, __VA_ARGS__) #define vk_create_instance(info) \ r = npv_dl_vk_create_instance(info, 0, &npv_vk_instance_l) #define vk_enumerate_phydevs(...) \ -r = npv_dl_vk_enumerate_phydevs(npv_vk_instance_l,##__VA_ARGS__) +r = npv_dl_vk_enumerate_phydevs(npv_vk_instance_l, __VA_ARGS__) #define vk_enumerate_dev_ext_props(phydev, props_n, props) \ r = npv_dl_vk_enumerate_dev_ext_props(phydev, 0, props_n, props) @@ -203,8 +199,8 @@ r = npv_dl_vk_create_xcb_surf(npv_vk_instance_l, info, 0, &npv_vk_surf_p.vk) #define vk_get_phydev_surf_support(phydev, q_fam, supported) \ r = npv_dl_vk_get_phydev_surf_support(phydev, q_fam, npv_vk_surf_p.vk, supported) -#define vk_get_phydev_surf_texel_mem_blk_confs(info, ...) \ -r = npv_dl_vk_get_phydev_surf_texel_mem_blk_confs(npv_vk_surf_p.dev.phydev.vk, info, ##__VA_ARGS__) +#define vk_get_phydev_surf_texel_mem_blk_confs(...) \ +r = npv_dl_vk_get_phydev_surf_texel_mem_blk_confs(npv_vk_surf_p.dev.phydev.vk, __VA_ARGS__) #define vk_get_phydev_mem_props npv_dl_vk_get_phydev_mem_props diff --git a/npv/vk/local/code.frag.c b/npv/vk/local/code.frag.c index 28b0c34..dd5e2ee 100644 --- a/npv/vk/local/code.frag.c +++ b/npv/vk/local/code.frag.c @@ -1,7 +1,16 @@ +STATIC void pout(u8 *fmt, ...) +{ + va_list ap; + + npv_pout("vulkan:"); + va_start(ap, fmt); + npv_vpout(fmt, ap); + va_end(ap); +} #define INSTANCE_STATIC_SYM(x,y) \ npv_dl_##y = vk_get_instance_proc_addr(0, #x); \ if (npv_dl_##y == 0) \ - FATALVK("unable to find vulkan " #x "\n"); + fatal("unable to find vulkan " #x "\n"); STATIC void instance_static_syms(void) { INSTANCE_STATIC_SYM(vkEnumerateInstanceVersion, @@ -17,7 +26,7 @@ STATIC void instance_static_syms(void) #define INSTANCE_SYM(x,y) \ npv_dl_##y = vk_get_instance_proc_addr(instance_l, #x); \ if (npv_dl_##y == 0) \ - FATALVK("unable to find vulkan " #x "\n"); + fatal("unable to find vulkan " #x "\n"); STATIC void instance_syms(void) { INSTANCE_SYM(vkEnumeratePhysicalDevices, vk_enumerate_phydevs); @@ -46,7 +55,7 @@ STATIC void instance_syms(void) #define DEV_SYM(x,y) \ surf_p.dev.dl_##y = vk_get_dev_proc_addr(surf_p.dev.vk, #x); \ if (surf_p.dev.dl_##y == 0) \ - FATALVK("unable to find vulkan device " #x "\n"); + fatal("unable to find vulkan device " #x "\n"); STATIC void dev_syms(void) { DEV_SYM(vkGetDeviceQueue, vk_get_dev_q); @@ -81,7 +90,7 @@ STATIC void dev_syms(void) #define DLSYM(x, y) \ npv_dl_##y = dlsym(loader_l, #x); \ if (npv_dl_##y == 0) \ - FATALVK("%s:unable to find " #x "\n", dlerror()); + fatal("%s:unable to find " #x "\n", dlerror()); STATIC void loader_syms(void) { DLSYM(vkGetInstanceProcAddr, vk_get_instance_proc_addr); @@ -94,7 +103,7 @@ STATIC void load_vk_loader(void) /* no '/' in the shared dynamic lib path name, then standard lookup */ loader_l = dlopen("libvulkan.so.1", RTLD_LAZY); if (loader_l == 0) - FATALVK("%s:unable to load the vulkan loader dynamic shared library\n", dlerror()); + fatal("%s:unable to load the vulkan loader dynamic shared library\n", dlerror()); } STATIC void check_vk_version(void) { @@ -103,11 +112,11 @@ STATIC void check_vk_version(void) vk_enumerate_instance_version(&api_version); if (r != vk_success) - FATALVK("%d:unable to enumerate instance version\n", r); - 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)); + fatal("%d:unable to enumerate instance version\n", r); + 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)); if (VK_VERSION_MAJOR(api_version) == 1 && VK_VERSION_MINOR(api_version) == 0) - FATALVK("instance version too old\n"); + fatal("instance version too old\n"); } #define EXTS_N_MAX 256 /* in theory, this could change on the fly */ @@ -121,19 +130,19 @@ STATIC void instance_exts_dump(void) n = EXTS_N_MAX; vk_enumerate_instance_ext_props(&n, exts); if (r != vk_success && r != vk_incomplete) { - WARNINGVK("%d:unable to enumerate instance extension(s)\n", r); + warning("%d:unable to enumerate instance extension(s)\n", r); return; } if (r == vk_incomplete) { - WARNINGVK("too many extensions (%u/%u), dumping disabled", n, EXTS_N_MAX); + warning("too many extensions (%u/%u), dumping disabled", n, EXTS_N_MAX); return; } /* vk_success */ - POUTVK("have %u instance extension(s)\n", n); + pout("have %u instance extension(s)\n", n); loop { if (n == 0) break; - POUTVK("instance extension:name=%s:specification version=%u\n", exts[n - 1].name, exts[n - 1].spec_version); + pout("instance extension:name=%s:specification version=%u\n", exts[n - 1].name, exts[n - 1].spec_version); n--; } } @@ -150,19 +159,19 @@ STATIC void instance_layers_dump(void) n = LAYERS_N_MAX; vk_enumerate_instance_layer_props(&n, layers); if (r != vk_success && r != vk_incomplete) { - WARNINGVK("%d:unable to enumerate instance layer(s)\n", r); + warning("%d:unable to enumerate instance layer(s)\n", r); return; } if (r == vk_incomplete) { - WARNINGVK("too many layers (%u/%u), dumping disabled", n, LAYERS_N_MAX); + warning("too many layers (%u/%u), dumping disabled", n, LAYERS_N_MAX); return; } /* vk_success */ - POUTVK("have %u instance layer(s)\n", n); + pout("have %u instance layer(s)\n", n); loop { if (n == 0) break; - 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); + 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); n--; } } @@ -191,7 +200,7 @@ STATIC void instance_create(void) loop { if (i == ARRAY_N(exts)) break; - POUTVK("will use instance extension %s\n", exts[i]); + pout("will use instance extension %s\n", exts[i]); ++i; } memset(&info, 0, sizeof(info)); @@ -200,7 +209,7 @@ STATIC void instance_create(void) info.enabled_ext_names = exts; vk_create_instance(&info); IF_FATALVK("%d:unable to create an instance\n", r); - POUTVK("instance handle %p\n", instance_l); + pout("instance handle %p\n", instance_l); } STATIC void tmp_phydevs_get(void) { @@ -212,13 +221,13 @@ STATIC void tmp_phydevs_get(void) n = tmp_phydevs_n_max; vk_enumerate_phydevs(&n, phydevs); if (r != vk_success && r != vk_incomplete) - FATALVK("%ld:unable to enumerate physical devices\n", r); + fatal("%ld:unable to enumerate physical devices\n", r); if (r == vk_incomplete) - FATALVK("too many vulkan physical devices %u/%u for our temporary storage\n", n, tmp_phydevs_n_max); + fatal("too many vulkan physical devices %u/%u for our temporary storage\n", n, tmp_phydevs_n_max); /* vk_success */ - POUTVK("detected %u physical devices\n", n); + pout("detected %u physical devices\n", n); if (n == 0) - FATALVK("no vulkan physical devices, exiting\n"); + fatal("no vulkan physical devices, exiting\n"); tmp_phydevs_n_l = n; memset(tmp_phydevs_l, 0, sizeof(tmp_phydevs_l)); n = 0; @@ -240,19 +249,19 @@ STATIC void phydev_exts_dump(void *phydev) n = EXTS_N_MAX; vk_enumerate_dev_ext_props(phydev, &n, exts); if (r != vk_success && r != vk_incomplete) { - WARNINGVK("physical device:%p:%d:unable to enumerate device extension(s)\n", phydev, r); + warning("physical device:%p:%d:unable to enumerate device extension(s)\n", phydev, r); return; } if (r == vk_incomplete) { - WARNINGVK("physical device:%p:too many extensions (%u/%u), dumping disabled", phydev, n, EXTS_N_MAX); + warning("physical device:%p:too many extensions (%u/%u), dumping disabled", phydev, n, EXTS_N_MAX); return; } /* vk_success */ - POUTVK("physical device:%p:have %u device extension(s)\n", phydev, n); + pout("physical device:%p:have %u device extension(s)\n", phydev, n); loop { if (n == 0) break; - POUTVK("physical device:%p:device extension:name=%s:specification version=%u\n", phydev, exts[n - 1].name, exts[n - 1].spec_version); + pout("physical device:%p:device extension:name=%s:specification version=%u\n", phydev, exts[n - 1].name, exts[n - 1].spec_version); n--; } } @@ -317,17 +326,17 @@ STATIC void tmp_phydevs_props_dump(void) memset(&props, 0, sizeof(props)); props.type = vk_struct_type_phydev_props; vk_get_phydev_props(p->vk, &props); - 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)); - 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)); - POUTVK("physical device:%p:properties:vendor id=%#x\n", p->vk, props.core.vendor_id); - POUTVK("physical device:%p:properties:device id=%#x\n", p->vk, props.core.dev_id); - POUTVK("physical device:%p:properties:type=%s\n", p->vk, dev_type_str(props.core.dev_type)); + 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)); + 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)); + pout("physical device:%p:properties:vendor id=%#x\n", p->vk, props.core.vendor_id); + pout("physical device:%p:properties:device id=%#x\n", p->vk, props.core.dev_id); + pout("physical device:%p:properties:type=%s\n", p->vk, dev_type_str(props.core.dev_type)); if (props.core.dev_type == vk_phydev_type_discrete_gpu) p->is_discret_gpu = true; else p->is_discret_gpu = false; - POUTVK("physical device:%p:properties:name=%s\n", p->vk, props.core.name); - POUTVK("physical device:%p:properties:pipeline cache uuid=%s\n", p->vk, uuid_str(props.core.pl_cache_uuid)); + pout("physical device:%p:properties:name=%s\n", p->vk, props.core.name); + pout("physical device:%p:properties:pipeline cache uuid=%s\n", p->vk, uuid_str(props.core.pl_cache_uuid)); /* disp the limits and sparse props at "higher log lvl", if needed in the end */ ++i; } @@ -353,20 +362,20 @@ STATIC void tmp_phydevs_mem_props_get(void) STATIC void phydev_mem_type_dump(void *phydev, u8 i, struct vk_mem_type_t *type) { - POUTVK("physical device:%p:memory type:%u:heap:%u\n", phydev, i, type->heap); - POUTVK("physical device:%p:memory type:%u:flags:%#08x\n", phydev, i, type->prop_flags); + pout("physical device:%p:memory type:%u:heap:%u\n", phydev, i, type->heap); + pout("physical device:%p:memory type:%u:flags:%#08x\n", phydev, i, type->prop_flags); if ((type->prop_flags & vk_mem_prop_dev_local_bit) != 0) - POUTVK("physical device:%p:memory type:%u:device local\n", phydev, i); + pout("physical device:%p:memory type:%u:device local\n", phydev, i); if ((type->prop_flags & vk_mem_prop_host_visible_bit) != 0) - POUTVK("physical device:%p:memory type:%u:host visible\n", phydev, i); + pout("physical device:%p:memory type:%u:host visible\n", phydev, i); if ((type->prop_flags & vk_mem_prop_host_cached_bit) != 0) - POUTVK("physical device:%p:memory type:%u:host cached\n", phydev, i); + pout("physical device:%p:memory type:%u:host cached\n", phydev, i); } STATIC void tmp_phydev_mem_types_dump(struct tmp_phydev_t *p) { u8 i; - POUTVK("physical device:%p:%u memory types\n", p->vk, p->mem_props.core.mem_types_n); + pout("physical device:%p:%u memory types\n", p->vk, p->mem_props.core.mem_types_n); i = 0; loop { if (i == p->mem_props.core.mem_types_n) @@ -379,18 +388,18 @@ STATIC void tmp_phydev_mem_types_dump(struct tmp_phydev_t *p) STATIC void phydev_mem_heap_dump(void *phydev, u8 i, struct vk_mem_heap_t *heap) { - POUTVK("physical device:%p:memory heap:%u:size:%u bytes\n", phydev, i, heap->sz); - POUTVK("physical device:%p:memory heap:%u:flags:%#08x\n", phydev, i, heap->flags); + pout("physical device:%p:memory heap:%u:size:%u bytes\n", phydev, i, heap->sz); + pout("physical device:%p:memory heap:%u:flags:%#08x\n", phydev, i, heap->flags); if ((heap->flags & vk_mem_heap_dev_local_bit) != 0) - POUTVK("physical device:%p:memory heap:%u:device local\n", phydev, i); + pout("physical device:%p:memory heap:%u:device local\n", phydev, i); if ((heap->flags & vk_mem_heap_multi_instance_bit) != 0) - POUTVK("physical device:%p:memory type:%u:multi instance\n", phydev, i); + pout("physical device:%p:memory type:%u:multi instance\n", phydev, i); } STATIC void tmp_phydev_mem_heaps_dump(struct tmp_phydev_t *p) { u8 i; - POUTVK("physical device:%p:%u memory heaps\n", p->vk, p->mem_props.core.mem_heaps_n); + pout("physical device:%p:%u memory heaps\n", p->vk, p->mem_props.core.mem_heaps_n); i = 0; loop { if (i == p->mem_props.core.mem_heaps_n) @@ -426,7 +435,7 @@ STATIC void tmp_phydev_q_fams_get(struct tmp_phydev_t *p) n = 0; vk_get_phydev_q_fam_props(p->vk, &n, 0); if (n > tmp_phydev_q_fams_n_max) - FATALVK("physical device:%p:too many queue families %u/%u\n", p->vk, n, tmp_phydev_q_fams_n_max); + fatal("physical device:%p:too many queue families %u/%u\n", p->vk, n, tmp_phydev_q_fams_n_max); memset(p->q_fams, 0, sizeof(p->q_fams)); i = 0; loop { @@ -437,7 +446,7 @@ STATIC void tmp_phydev_q_fams_get(struct tmp_phydev_t *p) } vk_get_phydev_q_fam_props(p->vk, &n, p->q_fams); p->q_fams_n = n; - POUTVK("physical device:%p:have %u queue families\n", p->vk, p->q_fams_n); + pout("physical device:%p:have %u queue families\n", p->vk, p->q_fams_n); } STATIC void tmp_phydevs_q_fams_get(void) { @@ -460,18 +469,18 @@ STATIC void tmp_phydev_q_fams_dump(struct tmp_phydev_t *p) if (i == p->q_fams_n) break; if ((p->q_fams[i].core.flags & vk_q_gfx_bit) != 0) - POUTVK("physical device:%p:queue family:%u:flags:graphics\n", p->vk, i); + pout("physical device:%p:queue family:%u:flags:graphics\n", p->vk, i); if ((p->q_fams[i].core.flags & vk_q_compute_bit) != 0) - POUTVK("physical device:%p:queue family:%u:flags:compute\n", p->vk, i); + pout("physical device:%p:queue family:%u:flags:compute\n", p->vk, i); if ((p->q_fams[i].core.flags & vk_q_transfer_bit) != 0) - POUTVK("physical device:%p:queue family:%u:flags:transfer\n", p->vk, i); + pout("physical device:%p:queue family:%u:flags:transfer\n", p->vk, i); if ((p->q_fams[i].core.flags & vk_q_sparse_binding_bit) != 0) - POUTVK("physical device:%p:queue family:%u:flags:sparse binding\n", p->vk, i); + pout("physical device:%p:queue family:%u:flags:sparse binding\n", p->vk, i); if ((p->q_fams[i].core.flags & vk_q_protected_bit) != 0) - POUTVK("physical device:%p:queue family:%u:flags:protected\n", p->vk, i); - POUTVK("physical device:%p:queue family:%u:%u queues\n", p->vk, i, p->q_fams[i].core.qs_n); - POUTVK("physical device:%p:queue family:%u:%u bits timestamps\n", p->vk, i, p->q_fams[i].core.timestamp_valid_bits); - 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); + pout("physical device:%p:queue family:%u:flags:protected\n", p->vk, i); + pout("physical device:%p:queue family:%u:%u queues\n", p->vk, i, p->q_fams[i].core.qs_n); + pout("physical device:%p:queue family:%u:%u bits timestamps\n", p->vk, i, p->q_fams[i].core.timestamp_valid_bits); + 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); ++i; } } @@ -517,10 +526,10 @@ STATIC void tmp_phydevs_q_fams_surf_support_get(void) vk_get_phydev_surf_support(p->vk, j, &supported); 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 (supported == vk_true) { - POUTVK("physical device:%p:queue family:%u:surface:%p:does support wsi/(image presentation to our surface) \n", p->vk, j, surf_p.vk); + pout("physical device:%p:queue family:%u:surface:%p:does support wsi/(image presentation to our surface) \n", p->vk, j, surf_p.vk); p->q_fams_surf_support[j] = true; } else { - 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); + 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); p->q_fams_surf_support[j] = false; } ++j; @@ -572,7 +581,7 @@ STATIC void tmp_phydev_and_q_fam_select(void) != 0) { surf_p.dev.phydev.q_fam = j; tmp_selected_phydev_cherry_pick(i); - 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); + 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); return; } ++j; @@ -589,7 +598,7 @@ STATIC void texel_mem_blk_confs_dump(u32 confs_n, loop { if (i == confs_n) break; - 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); + 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); ++i; } } @@ -613,7 +622,7 @@ STATIC void phydev_surf_texel_mem_blk_conf_select(void) vk_get_phydev_surf_texel_mem_blk_confs(&info, &confs_n, 0); 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 (confs_n > CONFS_N_MAX) - 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); + 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); memset(confs, 0, sizeof(confs[0]) * confs_n); i = 0; @@ -626,7 +635,7 @@ STATIC void phydev_surf_texel_mem_blk_conf_select(void) vk_get_phydev_surf_texel_mem_blk_confs(&info, &confs_n, confs); 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 (confs_n == 0) - FATALVK("physical device:%p:surface:%p:no valid surface texel memory block configuration\n", surf_p.dev.phydev.vk, surf_p.vk); + fatal("physical device:%p:surface:%p:no valid surface texel memory block configuration\n", surf_p.dev.phydev.vk, surf_p.vk); texel_mem_blk_confs_dump(confs_n, confs); cc = &surf_p.dev.phydev.selected_texel_mem_blk_conf_core; @@ -635,9 +644,9 @@ STATIC void phydev_surf_texel_mem_blk_conf_select(void) * get from ff scaler */ cc->fmt = vk_texel_mem_blk_fmt_b8g8r8a8_srgb; - 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); + 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); cc->color_space = vk_color_space_srgb_nonlinear; - 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); + 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); } #undef CONFS_N_MAX STATIC void phydev_surf_caps_get(void) @@ -655,20 +664,20 @@ STATIC void phydev_surf_caps_get(void) 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); /* we have room for a maximum of 3 images per swapchain */ if (surf_p.dev.phydev.surf_caps.core.imgs_n_min > swpchn_imgs_n_max) - 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); + 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); } STATIC void phydev_surf_caps_dump(void) { - 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); - 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); - 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); - 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); - 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); - 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); - 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); - 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); - 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); - 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); } STATIC void tmp_phydev_surf_present_modes_get(void) { @@ -698,11 +707,11 @@ STATIC void tmp_phydev_surf_present_modes_dump(void) u8 i; i = 0; - POUTVK("physical device:%p:surface:%p:%u present modes\n", surf_p.dev.phydev.vk, surf_p.vk, tmp_present_modes_n_l); + pout("physical device:%p:surface:%p:%u present modes\n", surf_p.dev.phydev.vk, surf_p.vk, tmp_present_modes_n_l); loop { if (i == (u8)tmp_present_modes_n_l) break; - 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])); + 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])); ++i; } } @@ -763,13 +772,13 @@ STATIC void dev_create(void) info.enabled_ext_names = exts; vk_create_dev(&info); IF_FATALVK("%d:physical device:%p:unable to create a vulkan device\n", r, surf_p.dev.phydev.vk); - POUTVK("physical device:%p:vulkan device created with one proper queue:%p\n", surf_p.dev.phydev.vk, surf_p.dev.vk); + pout("physical device:%p:vulkan device created with one proper queue:%p\n", surf_p.dev.phydev.vk, surf_p.dev.vk); } STATIC void q_get(void) { - POUTVK("device:%p:getting queue:family=%u queue=0\n", surf_p.dev.vk, surf_p.dev.phydev.q_fam); + pout("device:%p:getting queue:family=%u queue=0\n", surf_p.dev.vk, surf_p.dev.phydev.q_fam); vk_get_dev_q(); - POUTVK("device:%p:got queue:%p\n", surf_p.dev.vk, surf_p.dev.q); + pout("device:%p:got queue:%p\n", surf_p.dev.vk, surf_p.dev.q); } STATIC void cp_create(void) { @@ -782,7 +791,7 @@ STATIC void cp_create(void) info.q_fam = surf_p.dev.phydev.q_fam; vk_create_cp(&info); IF_FATALVK("%d:unable create the commmand pool\n", r); - 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); + 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); } STATIC void dev_init(void) { @@ -806,7 +815,7 @@ STATIC void surf_create(xcb_connection_t *c, u32 win_id) vk_xcb_info.win = win_id; vk_create_xcb_surf(&vk_xcb_info); IF_FATALVK("%d:xcb:%p:window id:%#x:unable to create a vulkan surface from this x11 window\n", r, c, win_id); - POUTVK("xcb:%p:window id:%#x:created vk_surface=%p\n", c, win_id, surf_p.vk); + pout("xcb:%p:window id:%#x:created vk_surface=%p\n", c, win_id, surf_p.vk); } STATIC void swpchn_init_once(void) { @@ -876,7 +885,7 @@ STATIC void sems_create(void) info.type = vk_struct_type_sem_create_info; vk_create_sem(&info, &surf_p.dev.sems[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); - POUTVK("device:%p:semaphore %u for the synchronization of the swapchain created %p\n", surf_p.dev.vk, sem, surf_p.dev.sems[sem]); + pout("device:%p:semaphore %u for the synchronization of the swapchain created %p\n", surf_p.dev.vk, sem, surf_p.dev.sems[sem]); ++sem; } } @@ -892,5 +901,5 @@ STATIC void swpchn_imgs_cbs_init_once(void) alloc_info.cbs_n = swpchn_imgs_n_max; vk_alloc_cbs(&alloc_info); 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); - 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); + 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); } diff --git a/npv/vk/main.c b/npv/vk/main.c index 187ac30..1dab8ad 100644 --- a/npv/vk/main.c +++ b/npv/vk/main.c @@ -5,12 +5,14 @@ * copyright (C) 2020 Sylvain BERTRAND */ #include +#include #include #include #include #include #include #include "npv/c_fixing.h" +#include "npv/public.h" #include "npv/nyanvk/consts.h" #include "npv/nyanvk/types.h" #include "npv/global.h" diff --git a/npv/vk/namespace/main.c b/npv/vk/namespace/main.c index 11a6a2a..893a047 100644 --- a/npv/vk/namespace/main.c +++ b/npv/vk/namespace/main.c @@ -21,6 +21,7 @@ #define phydev_surf_caps_dump npv_vk_phydev_surf_caps_dump #define phydev_surf_caps_get npv_vk_phydev_surf_caps_get #define phydev_surf_texel_mem_blk_conf_select npv_vk_phydev_surf_texel_mem_blk_conf_select +#define pout npv_vk_pout #define present_mode_to_str npv_vk_present_mode_to_str #define q_get npv_vk_q_get #define sems_create npv_vk_sems_create @@ -81,6 +82,7 @@ #undef phydev_surf_caps_dump #undef phydev_surf_caps_get #undef phydev_surf_texel_mem_blk_conf_select +#undef pout #undef present_mode_to_str #undef q_get #undef sems_create diff --git a/npv/vk/namespace/public.h b/npv/vk/namespace/public.h index b8f5672..1d2b6bd 100644 --- a/npv/vk/namespace/public.h +++ b/npv/vk/namespace/public.h @@ -1,5 +1,6 @@ #ifndef CLEANUP #define dev_t npv_vk_dev_t +#define fatal npv_vk_fatal #define init_once npv_vk_init_once #define phydev_t npv_vk_phydev_t #define sem_acquire_img_done npv_vk_sem_acquire_img_done @@ -10,9 +11,13 @@ #define swpchn_update npv_vk_swpchn_update #define swpchn_imgs_n_max npv_vk_swpchn_imgs_n_max #define swpchn_t npv_vk_swpchn_t +#define vfatal npv_vk_vfatal +#define vwarning npv_vk_vwarning +#define warning npv_vk_warning /*============================================================================*/ #else #undef dev_t +#undef fatal #undef init_once #undef phydev_t #undef sem_acquire_img_done @@ -23,5 +28,8 @@ #undef swpchn_update #undef swpchn_imgs_n_max #undef swpchn_t +#undef vfatal +#undef vwarning +#undef warning #endif diff --git a/npv/vk/public.h b/npv/vk/public.h index 8837c61..ddb7bcd 100644 --- a/npv/vk/public.h +++ b/npv/vk/public.h @@ -19,6 +19,10 @@ STATIC void init_once(void); STATIC void surf_init_once(xcb_connection_t *c, u32 wind_id); STATIC void swpchn_update(void); +STATIC void fatal(u8 *fmt, ...); +STATIC void warning(u8 *fmt, ...); +STATIC void vfatal(u8 *fmt, va_list ap); +STATIC void vwarning(u8 *fmt, va_list ap); /*----------------------------------------------------------------------------*/ #define CLEANUP #include "npv/vk/namespace/public.h" diff --git a/npv/vk/public/code.frag.c b/npv/vk/public/code.frag.c index fa53616..021e14f 100644 --- a/npv/vk/public/code.frag.c +++ b/npv/vk/public/code.frag.c @@ -1,3 +1,39 @@ +STATIC void fatal(u8 *fmt, ...) +{ + va_list ap; + + npv_perr("vulkan:"); + va_start(ap, fmt); + npv_vfatal(fmt, ap); + va_end(ap); /* unreachable */ +} +STATIC void vfatal(u8 *fmt, va_list ap) +{ + va_list aq; + + npv_perr("vulkan:"); + va_copy(aq, ap); + npv_vfatal(fmt, aq); + va_end(aq); +} +STATIC void warning(u8 *fmt, ...) +{ + va_list ap; + + npv_perr("vulkan:"); + va_start(ap, fmt); + npv_vwarning(fmt, ap); + va_end(ap); +} +STATIC void vwarning(u8 *fmt, va_list ap) +{ + va_list aq; + + npv_perr("vulkan:"); + va_copy(aq, ap); + npv_vwarning(fmt, aq); + va_end(aq); +} STATIC void swpchn_update(void) { phydev_surf_caps_get(); diff --git a/npv/xcb/local/code.frag.c b/npv/xcb/local/code.frag.c index 600e27e..1695161 100644 --- a/npv/xcb/local/code.frag.c +++ b/npv/xcb/local/code.frag.c @@ -1,20 +1,47 @@ +STATIC void npv_xcb_fatal(u8 *fmt, ...) +{ + va_list ap; + + npv_perr("xcb:"); + va_start(ap, fmt); + npv_vfatal(fmt, ap); + va_end(ap); /* unreachable */ +} +STATIC void npv_xcb_warning(u8 *fmt, ...) +{ + va_list ap; + + npv_perr("xcb:"); + va_start(ap, fmt); + npv_vwarning(fmt, ap); + va_end(ap); +} +STATIC void npv_xcb_pout(u8 *fmt, ...) +{ + va_list ap; + + npv_pout("xcb:"); + va_start(ap, fmt); + npv_vpout(fmt, ap); + va_end(ap); +} STATIC void npv_xcb_libs_load(void) { npv_xcb_lib_l = dlopen("libxcb.so.1", RTLD_LAZY); if (npv_xcb_lib_l == 0) - FATALX("%s:unable to load the xcb dynamic shared library\n", dlerror()); + npv_xcb_fatal("%s:unable to load the xcb dynamic shared library\n", dlerror()); npv_xcb_xfixes_lib_l = dlopen("libxcb-xfixes.so.0", RTLD_LAZY); if (npv_xcb_xfixes_lib_l == 0) - FATALX("%s:unable to load the xcb xfixes dynamic shared library\n", dlerror()); + npv_xcb_fatal("%s:unable to load the xcb xfixes dynamic shared library\n", dlerror()); } #define XCB_DLSYM(x) \ npv_dl_##x = dlsym(npv_xcb_lib_l, #x); \ if (npv_dl_##x == 0) \ - FATALX("%s:unable to find " #x "\n", dlerror()); + npv_xcb_fatal("%s:unable to find " #x "\n", dlerror()); #define XCB_XFIXES_DLSYM(x) \ npv_dl_##x = dlsym(npv_xcb_xfixes_lib_l, #x); \ if (npv_dl_##x == 0) \ - FATALX("%s:unable to find " #x "\n", dlerror()); + npv_xcb_fatal("%s:unable to find " #x "\n", dlerror()); STATIC void npv_xcb_syms(void) { XCB_DLSYM(xcb_connect); @@ -53,7 +80,7 @@ STATIC void npv_xcb_win_create(void) u32 value_list[2]; npv_xcb_p.win_id = npv_dl_xcb_generate_id(npv_xcb_p.c); - 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); + 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); value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; value_list[0] = npv_xcb_p.scr->black_pixel; @@ -78,12 +105,12 @@ STATIC void npv_xcb_win_map(void) xcb_generic_error_t *e; cookie = npv_dl_xcb_map_window_checked(npv_xcb_p.c, npv_xcb_p.win_id); - 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); + 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); e = npv_dl_xcb_request_check(npv_xcb_p.c, cookie); if (e != 0) - 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); - 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); + 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); + 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); } /* * a disp is n scrs and 1 [set of] keyboard[s] and 1 [set of] mouse[s] @@ -97,20 +124,20 @@ STATIC void npv_xcb_connect(void) npv_xcb_p.disp_env = getenv("DISPLAY"); if (npv_xcb_p.disp_env == 0 || npv_xcb_p.disp_env[0] == 0) - FATALX("no x11 DISPLAY environment variable, exiting\n"); + npv_xcb_fatal("no x11 DISPLAY environment variable, exiting\n"); npv_xcb_p.scr_idx = 0; /* should be 0 though */ npv_xcb_p.c = npv_dl_xcb_connect(0, &npv_xcb_p.scr_idx); r = npv_dl_xcb_connection_has_error(npv_xcb_p.c); if (r > 0) - FATALX("%d:%s:error while connecting to the x11 server\n", r, npv_xcb_p.disp_env); - 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); + npv_xcb_fatal("%d:%s:error while connecting to the x11 server\n", r, npv_xcb_p.disp_env); + 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); npv_xcb_p.fd = npv_dl_xcb_get_file_descriptor(npv_xcb_p.c); if (npv_xcb_p.fd == -1) - FATALX("'%s':unable to get the connection file descriptor for epoll\n", npv_xcb_p.disp_env); - POUTX("'%s':connection:%p:file descriptor %d\n", npv_xcb_p.disp_env, npv_xcb_p.c, npv_xcb_p.fd); + npv_xcb_fatal("'%s':unable to get the connection file descriptor for epoll\n", npv_xcb_p.disp_env); + npv_xcb_pout("'%s':connection:%p:file descriptor %d\n", npv_xcb_p.disp_env, npv_xcb_p.c, npv_xcb_p.fd); } STATIC void npv_xcb_scr_get(void) { @@ -121,7 +148,7 @@ STATIC void npv_xcb_scr_get(void) npv_xcb_p.setup = npv_dl_xcb_get_setup(npv_xcb_p.c); scrs_n = npv_dl_xcb_setup_roots_length(npv_xcb_p.setup); - POUTX("'%s':connection:%p:has %d screens (should be 1)\n", npv_xcb_p.disp_env, npv_xcb_p.c, scrs_n); + npv_xcb_pout("'%s':connection:%p:has %d screens (should be 1)\n", npv_xcb_p.disp_env, npv_xcb_p.c, scrs_n); iter = npv_dl_xcb_setup_roots_iterator(npv_xcb_p.setup); i = 0; @@ -136,10 +163,10 @@ STATIC void npv_xcb_scr_get(void) } npv_dl_xcb_screen_next(&iter); } - 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); - 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); - 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); - 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); + 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); + 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); + 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); + 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); } #define MIN_SZ_BIT (1 << 4) #define MAX_SZ_BIT (1 << 5) @@ -229,13 +256,13 @@ STATIC void npv_xcb_evt_key_release(xcb_generic_event_t *evt) if (b == ARRAY_N(npv_x11_binds)) break; if (key->detail == npv_x11_binds[b].keycode) { - 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); + 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); npv_x11_binds[b].cmd(); return; } ++b; } - POUTX("'%s':connection:%p:event:key release:keycode:%#02x\n", npv_xcb_p.disp_env, npv_xcb_p.c, key->detail); + npv_xcb_pout("'%s':connection:%p:event:key release:keycode:%#02x\n", npv_xcb_p.disp_env, npv_xcb_p.c, key->detail); } STATIC void npv_xcb_evt_leave_win(xcb_generic_event_t *evt) { @@ -256,7 +283,7 @@ STATIC void npv_xcb_mouse_visibility_timer_start(void) t.it_value.tv_sec = npv_xcb_mouse_visibility_interval_s; r = timerfd_settime(npv_xcb_p.mouse_visibility_timer_fd, 0, &t, 0); if (r == -1) - FATALX("unable to arm the mouse visibility timer to %u seconds\n", npv_xcb_mouse_visibility_interval_s); + npv_xcb_fatal("unable to arm the mouse visibility timer to %u seconds\n", npv_xcb_mouse_visibility_interval_s); } STATIC void npv_xcb_evt_enter_win(xcb_generic_event_t *evt) { @@ -348,7 +375,7 @@ STATIC void npv_xcb_screensaver_heartbeat_timer_init_once(void) npv_xcb_p.screensaver_heartbeat_timer_fd = timerfd_create( CLOCK_MONOTONIC, TFD_NONBLOCK); if (npv_xcb_p.screensaver_heartbeat_timer_fd == -1) - FATALX("unable to get a timer file descriptor for the screensaver heartbeat:%s\n", strerror(errno)); + npv_xcb_fatal("unable to get a timer file descriptor for the screensaver heartbeat:%s\n", strerror(errno)); } STATIC void npv_xcb_mouse_visibilty_init_once(void) { @@ -358,7 +385,7 @@ STATIC void npv_xcb_mouse_visibilty_init_once(void) xfixes = npv_dl_xcb_get_extension_data(npv_xcb_p.c, npv_dl_xcb_xfixes_id); if (xfixes->response_type != 1 || xfixes->present == 0) - WARNINGX("the server is missing xfixes extension\n"); + npv_xcb_warning("the server is missing xfixes extension\n"); /* the hice/show cursor is supported from version 4 */ npv_dl_xcb_xfixes_query_version(npv_xcb_p.c, 4, 0); /*--------------------------------------------------------------------*/ @@ -370,7 +397,7 @@ STATIC void npv_xcb_mouse_visibilty_init_once(void) npv_xcb_p.mouse_visibility_timer_fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK); if (npv_xcb_p.mouse_visibility_timer_fd == -1) - FATALX("unable to get a timer file descriptor for the mouse visibility management:%s\n", strerror(errno)); + npv_xcb_fatal("unable to get a timer file descriptor for the mouse visibility management:%s\n", strerror(errno)); } #define NET_WM_STATE "_NET_WM_STATE" #define NET_WM_STATE_FULLSCREEN "_NET_WM_STATE_FULLSCREEN" @@ -395,7 +422,7 @@ STATIC void npv_xcb_fullscreen_action(u32 action) reply = npv_dl_xcb_intern_atom_reply(npv_xcb_p.c, cookie_net_wm_state, &err); if (reply == 0) { - WARNINGX("unable to set fullscreen:unable to get the _NET_WM_STATE atom:%d\n", err->error_code); + npv_xcb_warning("unable to set fullscreen:unable to get the _NET_WM_STATE atom:%d\n", err->error_code); free(err); return; } @@ -405,7 +432,7 @@ STATIC void npv_xcb_fullscreen_action(u32 action) reply = npv_dl_xcb_intern_atom_reply(npv_xcb_p.c, cookie_net_wm_state_fullscreen, &err); if (reply == 0) { - WARNINGX("unable to set fullscreen:unable to get the _NET_WM_STATE_FULLSCREEN atom:%d\n", err->error_code); + npv_xcb_warning("unable to set fullscreen:unable to get the _NET_WM_STATE_FULLSCREEN atom:%d\n", err->error_code); free(err); return; } diff --git a/npv/xcb/main.c b/npv/xcb/main.c index 470d0bc..f0e085b 100644 --- a/npv/xcb/main.c +++ b/npv/xcb/main.c @@ -5,6 +5,7 @@ * copyright (C) 2020 Sylvain BERTRAND */ #include +#include #include #include #include @@ -21,16 +22,8 @@ /*----------------------------------------------------------------------------*/ #include "npv/config.h" /*----------------------------------------------------------------------------*/ -#define FATALX(fmt, ...) FATAL("xcb:" fmt, ##__VA_ARGS__) -#define WARNINGX(fmt, ...) WARNING("xcb:" fmt, ##__VA_ARGS__) -#define POUTX(fmt, ...) POUT("xcb:" fmt, ##__VA_ARGS__) -/*----------------------------------------------------------------------------*/ #include "npv/xcb/local/state.frag.c" /*----------------------------------------------------------------------------*/ #include "npv/xcb/local/code.frag.c" #include "npv/xcb/public/code.frag.c" -/*----------------------------------------------------------------------------*/ -#undef FATALX -#undef WARNINGX -#undef POUTX #endif diff --git a/npv/xcb/public/code.frag.c b/npv/xcb/public/code.frag.c index 0713bf3..3937c78 100644 --- a/npv/xcb/public/code.frag.c +++ b/npv/xcb/public/code.frag.c @@ -33,8 +33,8 @@ STATIC void npv_xcb_init_once(u16 win_width, u16 win_height, r = npv_dl_xcb_flush(npv_xcb_p.c); if (r <= 0) - 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); - POUTX("'%s':connection:%p:connection flushed\n", npv_xcb_p.disp_env, npv_xcb_p.c); + 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); + npv_xcb_pout("'%s':connection:%p:connection flushed\n", npv_xcb_p.disp_env, npv_xcb_p.c); npv_xcb_fullscreen_init_once(start_fullscreen); } STATIC void npv_xcb_screensaver_heartbeat_timer_start(void) @@ -47,7 +47,7 @@ STATIC void npv_xcb_screensaver_heartbeat_timer_start(void) t.it_interval.tv_sec = npv_xcb_screensaver_heartbeat_timeout_s; r = timerfd_settime(npv_xcb_p.screensaver_heartbeat_timer_fd, 0, &t, 0); if (r == -1) - FATALX("unable to arm the screensaver heartbeat timer to %u seconds\n", npv_xcb_screensaver_heartbeat_timeout_s); + npv_xcb_fatal("unable to arm the screensaver heartbeat timer to %u seconds\n", npv_xcb_screensaver_heartbeat_timeout_s); } STATIC void npv_xcb_screensaver_heartbeat_timer_evt(void) { @@ -58,7 +58,7 @@ STATIC void npv_xcb_screensaver_heartbeat_timer_evt(void) r = read(npv_xcb_p.screensaver_heartbeat_timer_fd, &exps_n, sizeof(exps_n)); if (r == -1) - FATALX("unable to read the number of timer expirations related to the xcb screensaver heartbeat\n"); + npv_xcb_fatal("unable to read the number of timer expirations related to the xcb screensaver heartbeat\n"); if (!npv_paused_p) { npv_dl_xcb_force_screen_saver(npv_xcb_p.c, XCB_SCREEN_SAVER_RESET); @@ -76,14 +76,14 @@ STATIC void npv_xcb_mouse_visibility_timer_evt(void) exps_n = 0; r = read(npv_xcb_p.mouse_visibility_timer_fd, &exps_n, sizeof(exps_n)); if (r == -1) - FATALX("unable to read the number of timer expirations related to the xcb mouse visibility\n"); + npv_xcb_fatal("unable to read the number of timer expirations related to the xcb mouse visibility\n"); if (npv_xcb_p.mouse_hidden) return; cookie = npv_dl_xcb_query_pointer(npv_xcb_p.c, npv_xcb_p.win_id); err = 0; reply = npv_dl_xcb_query_pointer_reply(npv_xcb_p.c, cookie, &err); if (reply == 0) { - WARNINGX("an error occured while handling the mouse pointer visibility:%d\n", err->error_code); + npv_xcb_warning("an error occured while handling the mouse pointer visibility:%d\n", err->error_code); free(err); return; } -- 2.11.4.GIT