Skip to content

Commit

Permalink
debug: move some stuff to utils/debug
Browse files Browse the repository at this point in the history
The rationale is to separate the config.h-dependent stuff to a separate
file to eliminate the need to transitively include config.h.

+ fix the files that need config.h directly to include it
  • Loading branch information
MartinPulec committed Nov 28, 2024
1 parent cac114d commit abd7582
Show file tree
Hide file tree
Showing 20 changed files with 102 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/audio/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
#include "audio/playback/sdi.h"
#include "audio/resampler.hpp"
#include "audio/utils.h"
#include "config.h" // for HAVE_SPEEXDSP
#include "debug.h"
#include "host.h"
#include "module.h"
Expand Down
1 change: 1 addition & 0 deletions src/audio/playback/jack.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "audio/audio_playback.h"
#include "audio/types.h"
#include "audio/utils.h"
#include "config.h" // for PACKAGE_NAME
#include "debug.h"
#include "host.h"
#include "jack_common.h"
Expand Down
1 change: 1 addition & 0 deletions src/blackmagic_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include "host.h"
#include "tv.h"
#include "utils/color_out.h"
#include "utils/debug.h" // for DEBUG_TIMER_*
#include "utils/macros.h"
#include "utils/windows.h"
#include "utils/worker.h"
Expand Down
1 change: 1 addition & 0 deletions src/capture_filter/resize_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
#include "capture_filter/resize_utils.h"
#include "debug.h"
#include "utils/color_out.h"
#include "utils/debug.h" // for DEBUG_TIMER_*
#include "video.h"

#define DEFAULT_ALGO INTER_LINEAR
Expand Down
4 changes: 3 additions & 1 deletion src/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
* SUCH DAMAGE.
*/

#include "debug.h"
#include "utils/debug.h"

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif // defined HAVE_CONFIG_H
Expand All @@ -52,7 +55,6 @@
#include <string_view>
#include <unordered_map>

#include "debug.h"
#include "host.h"
#include "utils/color_out.h"
#include "utils/string_view_utils.hpp"
Expand Down
17 changes: 0 additions & 17 deletions src/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@
#include <stdio.h> // FILE
#endif // defined __cplusplus

#ifdef HAVE_CONFIG_H
#include "config.h" // DEBUG
#endif // defined HAVE_CONFIG_H
#include "tv.h"

#define UNUSED(x) (x=x)
Expand Down Expand Up @@ -80,11 +77,6 @@ extern "C" {
#endif

void debug_dump(const void*lp, int len);
#ifdef DEBUG
void debug_file_dump(const char *key, void (*serialize)(const void *data, FILE *), void *data);
#else
#define debug_file_dump(key, serialize, data) (void) (key), (void) (serialize), (void) (data)
#endif

#define error_msg(...) log_msg(LOG_LEVEL_ERROR, __VA_ARGS__)
#define verbose_msg(...) log_msg(LOG_LEVEL_VERBOSE, __VA_ARGS__)
Expand Down Expand Up @@ -323,13 +315,4 @@ if ((level) <= log_level) Logger(level).Get()

#endif

#ifdef DEBUG
#define DEBUG_TIMER_EVENT(name) time_ns_t name = get_time_in_ns()
#define DEBUG_TIMER_START(name) DEBUG_TIMER_EVENT(name##_start);
#define DEBUG_TIMER_STOP(name) DEBUG_TIMER_EVENT(name##_stop); log_msg(LOG_LEVEL_DEBUG2, "%s duration: %lf s\n", #name, (name##_stop - name##_start) / NS_IN_SEC_DBL) // NOLINT(cppcoreguidelines-pro-type-vararg, hicpp-vararg)
#else
#define DEBUG_TIMER_START(name)
#define DEBUG_TIMER_STOP(name)
#endif

#endif
2 changes: 2 additions & 0 deletions src/hwaccel_vdpau.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
#ifndef HWACCEL_VDPAU_H
#define HWACCEL_VDPAU_H

#include "config.h" // for HWACC_VDPAU

#ifdef HWACC_VDPAU

#include "hwaccel_libav_common.h"
Expand Down
2 changes: 2 additions & 0 deletions src/libavcodec/from_lavc_vid_conv.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

#include "color.h"
#include "compat/qsort_s.h"
#include "config.h" // for HWACC_VDPAU
#include "debug.h"
#include "host.h"
#include "hwaccel_vdpau.h"
Expand All @@ -64,6 +65,7 @@
#include "libavcodec/lavc_common.h"
#include "pixfmt_conv.h"
#include "types.h"
#include "utils/debug.h" // for DEBUG_TIMER_*
#include "utils/macros.h" // OPTIMIZED_FOR
#include "utils/misc.h" // get_cpu_core_count
#include "utils/worker.h" // task_run_parallel
Expand Down
1 change: 1 addition & 0 deletions src/libavcodec/lavc_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
* Some conversions to RGBA ignore RGB-shifts - either fix that or deprecate RGB-shifts
*/

#include "config.h" // for HAVE_SWSCALE
#include "debug.h"
#include "lib_common.h"
#include "libavcodec/lavc_common.h"
Expand Down
1 change: 1 addition & 0 deletions src/libavcodec/lavc_video.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <stdio.h>
#endif

#include "config.h" // for HAVE_SWSCALE
#include "libavcodec/lavc_common.h"

#ifdef __cplusplus
Expand Down
1 change: 1 addition & 0 deletions src/rtp/audio_decoders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
#include "types.h" // for fec_desc, fec_type
#include "ug_runtime_error.hpp"
#include "utils/color_out.h"
#include "utils/debug.h" // for DEBUG_TIMER_*
#include "utils/macros.h"
#include "utils/packet_counter.h"
#include "utils/worker.h"
Expand Down
78 changes: 78 additions & 0 deletions src/utils/debug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* @file debug.h
* @author Martin Pulec <[email protected]>
*/
/*
* Copyright (c) 2021-2024 CESNET
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, is permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of CESNET nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef UTILS_DEBUG_H_36CF2E79_AF28_4308_BA8D_56D403BDCC44
#define UTILS_DEBUG_H_36CF2E79_AF28_4308_BA8D_56D403BDCC44

#ifdef HAVE_CONFIG_H
#include "config.h" // for DEBUG
#endif

#include "../debug.h" // for log_msg
#include "tv.h" // for get_time_in_ns

#ifdef __cplusplus
#include <cstdio> // for FILE
#define EXTERNC extern "C"
#else
#include <stdio.h>
#define EXTERNC // for FILE
#endif

#ifdef DEBUG

EXTERNC void debug_file_dump(const char *key,
void (*serialize)(const void *data, FILE *),
void *data);
#define DEBUG_TIMER_EVENT(name) time_ns_t name = get_time_in_ns()
#define DEBUG_TIMER_START(name) DEBUG_TIMER_EVENT(name##_start);
#define DEBUG_TIMER_STOP(name) \
DEBUG_TIMER_EVENT(name##_stop); \
log_msg(LOG_LEVEL_DEBUG2, "%s duration: %lf s\n", #name, \
(name##_stop - name##_start) / NS_IN_SEC_DBL) \
// NOLINT(cppcoreguidelines-pro-type-vararg, hicpp-vararg)

#else

#define debug_file_dump(key, serialize, data) \
(void) (key), (void) (serialize), (void) (data)
#define DEBUG_TIMER_START(name)
#define DEBUG_TIMER_STOP(name)

#endif // ! defined DEBUG

#endif // ! defined UTILS_DEBUG_H_36CF2E79_AF28_4308_BA8D_56D403BDCC44
3 changes: 2 additions & 1 deletion src/video_codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#define __STDC_WANT_LIB_EXT1__ 1

#ifdef HAVE_CONFIG_H
#include "config.h"
#include "config.h" // for HWACC_VDPAU
#endif // HAVE_CONFIG_H
#include "config_unix.h"
#include "config_win32.h"
Expand All @@ -70,6 +70,7 @@
#include "host.h"
#include "hwaccel_vdpau.h"
#include "hwaccel_drm.h"
#include "utils/debug.h" // for DEBUG_TIMER_*
#include "utils/macros.h" // to_fourcc, OPTIMEZED_FOR
#include "video_codec.h"

Expand Down
1 change: 1 addition & 0 deletions src/video_compress/libavcodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
#include "tv.h"
#include "ug_runtime_error.hpp"
#include "utils/color_out.h"
#include "utils/debug.h" // for debug_file_dump
#include "utils/macros.h"
#include "utils/misc.h"
#include "utils/string.h" // replace_all
Expand Down
1 change: 1 addition & 0 deletions src/video_decompress/libavcodec.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include "rtp/rtpdec_h264.h"
#include "rtp/rtpenc_h264.h"
#include "tv.h"
#include "utils/debug.h" // for debug_file_dump
#include "utils/macros.h"
#include "video.h"
#include "video_codec.h"
Expand Down
1 change: 1 addition & 0 deletions src/video_display/conference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <thread>
#include <string_view>

#include "config.h" // for HAVE_OPENCV2_OPENCV_HPP
#include "debug.h"
#include "host.h"
#include "lib_common.h"
Expand Down
1 change: 1 addition & 0 deletions src/video_display/gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
#include "module.h"
#include "types.h"
#include "utils/color_out.h"
#include "utils/debug.h" // for DEBUG_TIMER_*
#include "utils/macros.h" // OPTIMIZED_FOR
#include "utils/ref_count.hpp"
#include "video.h"
Expand Down
2 changes: 2 additions & 0 deletions src/video_display/gl_vdpau.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef GL_VDPAU_HPP_667244de5757
#define GL_VDPAU_HPP_667244de5757

#include "config.h" // for HWACC_VDPAU

#ifdef HWACC_VDPAU

#ifdef __APPLE__
Expand Down
1 change: 1 addition & 0 deletions src/video_display/opengl_conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "config.h" // for HWACC_VDPAU
#include "color.h"
#include "debug.h"
#include "host.h"
Expand Down
1 change: 1 addition & 0 deletions src/video_rxtx/rtp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <sstream>
#include <string>

#include "config.h" // for PACKAGE_STRING
#include "debug.h"
#include "host.h"
#include "messaging.h"
Expand Down

0 comments on commit abd7582

Please sign in to comment.