[vlc-commits] [Git][videolan/vlc][master] 2 commits: mock: move define where it is used

Steve Lhomme (@robUx4) gitlab at videolan.org
Sat Jul 6 07:46:01 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
97775e74 by Thomas Guillem at 2024-07-06T07:22:15+00:00
mock: move define where it is used

Because it uses local variables to the function.

- - - - -
a088bc28 by Thomas Guillem at 2024-07-06T07:22:15+00:00
mock: add a free callback to options

Even if for now, we have only one string (that was freed correctly).

Add the possibility to use strings in track options without leaking when
the option is overridden.

- - - - -


1 changed file:

- modules/demux/mock.c


Changes:

=====================================
modules/demux/mock.c
=====================================
@@ -183,81 +183,77 @@ var_Read_float(const char *psz)
     return atof(psz);
 }
 
+#define FREE_CB(x) free(x)
+#define NO_FREE(x) (void) x
+
 #define OPTIONS_AUDIO(Y) \
-    Y(audio, packetized, bool, add_bool, Bool, true) \
-    Y(audio, add_track_at, vlc_tick_t, add_integer, Integer, VLC_TICK_INVALID) \
-    Y(audio, channels, unsigned, add_integer, Unsigned, 2) \
-    Y(audio, format, vlc_fourcc_t, add_string, Fourcc, "f32l") \
-    Y(audio, rate, unsigned, add_integer, Unsigned, 48000) \
-    Y(audio, sample_length, vlc_tick_t, add_integer, Integer, VLC_TICK_FROM_MS(40)) \
-    Y(audio, sinewave, bool, add_bool, Bool, true) \
-    Y(audio, sinewave_frequency, unsigned, add_integer, Integer, 500) \
-    Y(audio, sinewave_amplitude, float, add_float, Float, 0.2)
+    Y(audio, packetized, bool, add_bool, Bool, true, NO_FREE) \
+    Y(audio, add_track_at, vlc_tick_t, add_integer, Integer, VLC_TICK_INVALID, NO_FREE) \
+    Y(audio, channels, unsigned, add_integer, Unsigned, 2, NO_FREE) \
+    Y(audio, format, vlc_fourcc_t, add_string, Fourcc, "f32l", NO_FREE) \
+    Y(audio, rate, unsigned, add_integer, Unsigned, 48000, NO_FREE) \
+    Y(audio, sample_length, vlc_tick_t, add_integer, Integer, VLC_TICK_FROM_MS(40), NO_FREE) \
+    Y(audio, sinewave, bool, add_bool, Bool, true, NO_FREE) \
+    Y(audio, sinewave_frequency, unsigned, add_integer, Integer, 500, NO_FREE) \
+    Y(audio, sinewave_amplitude, float, add_float, Float, 0.2, NO_FREE)
 
 #define OPTIONS_VIDEO(Y) \
-    Y(video, packetized, bool, add_bool, Bool, true)\
-    Y(video, add_track_at, vlc_tick_t, add_integer, Integer, VLC_TICK_INVALID) \
-    Y(video, chroma, vlc_fourcc_t, add_string, Fourcc, "I420") \
-    Y(video, width, unsigned, add_integer, Unsigned, 640) \
-    Y(video, height, unsigned, add_integer, Unsigned, 480) \
-    Y(video, frame_rate, unsigned, add_integer, Unsigned, 25) \
-    Y(video, frame_rate_base, unsigned, add_integer, Unsigned, 1) \
-    Y(video, colorbar, bool, add_bool, Bool, false) \
-    Y(video, orientation, unsigned, add_integer, Unsigned, ORIENT_NORMAL) \
-    Y(video, image_count, unsigned, add_integer, Unsigned, 0)
+    Y(video, packetized, bool, add_bool, Bool, true, NO_FREE) \
+    Y(video, add_track_at, vlc_tick_t, add_integer, Integer, VLC_TICK_INVALID, NO_FREE) \
+    Y(video, chroma, vlc_fourcc_t, add_string, Fourcc, "I420", NO_FREE) \
+    Y(video, width, unsigned, add_integer, Unsigned, 640, NO_FREE) \
+    Y(video, height, unsigned, add_integer, Unsigned, 480, NO_FREE) \
+    Y(video, frame_rate, unsigned, add_integer, Unsigned, 25, NO_FREE) \
+    Y(video, frame_rate_base, unsigned, add_integer, Unsigned, 1, NO_FREE) \
+    Y(video, colorbar, bool, add_bool, Bool, false, NO_FREE) \
+    Y(video, orientation, unsigned, add_integer, Unsigned, ORIENT_NORMAL, NO_FREE) \
+    Y(video, image_count, unsigned, add_integer, Unsigned, 0, NO_FREE)
 
 #define OPTIONS_SUB(Y) \
-    Y(sub, packetized, bool, add_bool, Bool, true)\
-    Y(sub, add_track_at, vlc_tick_t, add_integer, Integer, VLC_TICK_INVALID) \
-    Y(sub, format, vlc_fourcc_t, add_string, Fourcc, "subt") \
-    Y(sub, page, unsigned, add_integer, Integer, 0)
+    Y(sub, packetized, bool, add_bool, Bool, true, NO_FREE) \
+    Y(sub, add_track_at, vlc_tick_t, add_integer, Integer, VLC_TICK_INVALID, NO_FREE) \
+    Y(sub, format, vlc_fourcc_t, add_string, Fourcc, "subt", NO_FREE) \
+    Y(sub, page, unsigned, add_integer, Integer, 0, NO_FREE)
 
 /* var_name, type, module_header_type, getter, default_value */
 #define OPTIONS_GLOBAL(X) \
-    X(node_count, ssize_t, add_integer, Ssize, 0) \
-    X(length, vlc_tick_t, add_integer, Integer, VLC_TICK_FROM_MS(5000)) \
-    X(audio_track_count, ssize_t, add_integer, Ssize, 0) \
-    X(video_track_count, ssize_t, add_integer, Ssize, 0) \
-    X(sub_track_count, ssize_t, add_integer, Ssize, 0) \
-    X(input_sample_length, vlc_tick_t, add_integer, Integer, VLC_TICK_FROM_MS(40) ) \
-    X(title_count, ssize_t, add_integer, Ssize, 0 ) \
-    X(chapter_count, ssize_t, add_integer, Ssize, 0) \
-    X(null_names, bool, add_bool, Bool, false) \
-    X(program_count, ssize_t, add_integer, Ssize, 0) \
-    X(attachment_count, ssize_t, add_integer, Ssize, 0) \
-    X(can_seek, bool, add_bool, Bool, true) \
-    X(can_pause, bool, add_bool, Bool, true) \
-    X(can_control_pace, bool, add_bool, Bool, true) \
-    X(can_control_rate, bool, add_bool, Bool, true) \
-    X(can_record, bool, add_bool, Bool, true) \
-    X(error, bool, add_bool, Bool, false) \
-    X(pts_delay, vlc_tick_t, add_integer, Unsigned, DEFAULT_PTS_DELAY) \
-    X(config, char *, add_string, String, NULL )
-
-#define DECLARE_OPTION(var_name, type, module_header_type, getter, default_value)\
+    X(node_count, ssize_t, add_integer, Ssize, 0, NO_FREE) \
+    X(length, vlc_tick_t, add_integer, Integer, VLC_TICK_FROM_MS(5000), NO_FREE) \
+    X(audio_track_count, ssize_t, add_integer, Ssize, 0, NO_FREE) \
+    X(video_track_count, ssize_t, add_integer, Ssize, 0, NO_FREE) \
+    X(sub_track_count, ssize_t, add_integer, Ssize, 0, NO_FREE) \
+    X(input_sample_length, vlc_tick_t, add_integer, Integer, VLC_TICK_FROM_MS(40), NO_FREE) \
+    X(title_count, ssize_t, add_integer, Ssize, 0, NO_FREE) \
+    X(chapter_count, ssize_t, add_integer, Ssize, 0, NO_FREE) \
+    X(null_names, bool, add_bool, Bool, false, NO_FREE) \
+    X(program_count, ssize_t, add_integer, Ssize, 0, NO_FREE) \
+    X(attachment_count, ssize_t, add_integer, Ssize, 0, NO_FREE) \
+    X(can_seek, bool, add_bool, Bool, true, NO_FREE) \
+    X(can_pause, bool, add_bool, Bool, true, NO_FREE) \
+    X(can_control_pace, bool, add_bool, Bool, true, NO_FREE) \
+    X(can_control_rate, bool, add_bool, Bool, true, NO_FREE) \
+    X(can_record, bool, add_bool, Bool, true, NO_FREE) \
+    X(error, bool, add_bool, Bool, false, NO_FREE) \
+    X(pts_delay, vlc_tick_t, add_integer, Unsigned, DEFAULT_PTS_DELAY, NO_FREE) \
+    X(config, char *, add_string, String, NULL, FREE_CB)
+
+#define DECLARE_OPTION(var_name, type, module_header_type, getter, default_value, free_cb) \
     type var_name;
-#define DECLARE_SUBOPTION(a,b,c,d,e,f) DECLARE_OPTION(b,c,d,e,f)
-
-#define OVERRIDE_OPTION(group_name, var_name, type, module_header_type, getter, default_value) \
-    if (!strcmp(""#var_name, config_chain->psz_name)) \
-    { \
-        track->group_name.var_name = var_Read_ ## type(config_chain->psz_value); \
-        break; \
-    }
+#define DECLARE_SUBOPTION(a,b,c,d,e,f,g) DECLARE_OPTION(b,c,d,e,f,g)
 
 #define READ(var_name, member_name, getter) \
     sys->member_name = var_Inherit##getter(obj, "mock-"#var_name);
-#define READ_OPTION(var_name, type, module_header_type, getter, default_value) \
+#define READ_OPTION(var_name, type, module_header_type, getter, default_value, free_cb) \
     READ(var_name, var_name, getter)
-#define READ_SUBOPTION(group_name, var_name, type, module_header_type, getter, default_value) \
+#define READ_SUBOPTION(group_name, var_name, type, module_header_type, getter, default_value, free_cb) \
     READ(group_name##_##var_name, group_name.var_name, getter)
 
-#define DECLARE_MODULE_OPTIONS(var_name, type, module_header_type, getter, default_value) \
+#define DECLARE_MODULE_OPTIONS(var_name, type, module_header_type, getter, default_value, free_cb) \
     module_header_type("mock-"#var_name, default_value, #var_name, NULL) \
     change_volatile() \
     change_safe()
-#define DECLARE_MODULE_SUBOPTIONS(a,b,c,d,e,f) \
-    DECLARE_MODULE_OPTIONS(a##_##b,c,d,e,f)
+#define DECLARE_MODULE_SUBOPTIONS(a,b,c,d,e,f,g) \
+    DECLARE_MODULE_OPTIONS(a##_##b,c,d,e,f,g)
 
 struct mock_video_options
 {
@@ -1046,18 +1042,26 @@ static int
 OverrideTrackOptions(const config_chain_t *config_chain,
                      struct mock_track *track)
 {
+#define OVERRIDE_SUBOPTION(group_name, var_name, type, module_header_type, getter, default_value, free_cb) \
+    if (!strcmp(""#var_name, config_chain->psz_name)) \
+    { \
+        free_cb(track->group_name.var_name); \
+        track->group_name.var_name = var_Read_ ## type(config_chain->psz_value); \
+        break; \
+    }
+
     for (; config_chain ; config_chain = config_chain->p_next)
     {
         switch (track->fmt.i_cat)
         {
             case VIDEO_ES:
-                OPTIONS_VIDEO(OVERRIDE_OPTION)
+                OPTIONS_VIDEO(OVERRIDE_SUBOPTION)
                         break;
             case AUDIO_ES:
-                OPTIONS_AUDIO(OVERRIDE_OPTION)
+                OPTIONS_AUDIO(OVERRIDE_SUBOPTION)
                         break;
             case SPU_ES:
-                OPTIONS_SUB(OVERRIDE_OPTION)
+                OPTIONS_SUB(OVERRIDE_SUBOPTION)
                         break;
             default:
                 vlc_assert_unreachable();
@@ -1430,11 +1434,20 @@ Close(vlc_object_t *obj)
     demux_t *demux = (demux_t*)obj;
     struct demux_sys *sys = demux->p_sys;
 
-    free( sys->config );
+#define FREE_OPTIONS(var_name, type, module_header_type, getter, default_value, free_cb) \
+    free_cb(sys->var_name);
+#define FREE_SUBOPTIONS(group_name, var_name, type, module_header_type, getter, default_value, free_cb) \
+    free_cb(track->group_name.var_name);
+
+    OPTIONS_GLOBAL(FREE_OPTIONS);
 
     struct mock_track *track;
     vlc_vector_foreach(track, &sys->tracks)
     {
+        OPTIONS_AUDIO(FREE_SUBOPTIONS);
+        OPTIONS_VIDEO(FREE_SUBOPTIONS);
+        OPTIONS_SUB(FREE_SUBOPTIONS);
+
         DeleteTrack(demux, track);
     }
     vlc_vector_clear(&sys->tracks);



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/976f847333fbf97fc16c85902d764a14b61163fc...a088bc28f69e1e91a217687e81b4dd3b92868e77

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/976f847333fbf97fc16c85902d764a14b61163fc...a088bc28f69e1e91a217687e81b4dd3b92868e77
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list