[vlc-commits] [Git][videolan/vlc][master] 5 commits: codec/cdg: write pixels in RGBX order

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Thu Nov 26 13:32:33 UTC 2026



Felix Paul Kühne pushed to branch master at VideoLAN / VLC


Commits:
06937394 by Martin Finkel at 2026-11-26T14:01:49+01:00
codec/cdg: write pixels in RGBX order

The decoder writes R,G,B,X on little-endian but declares XBGR, so chroma
conversions drop red and swap green and blue.

Fixes f09cb927a1ae

- - - - -
a16f17fd by Martin Finkel at 2026-11-26T14:01:49+01:00
codec/cdg: mark pictures as progressive

CD+G is never interlaced, but the default flag makes automatic
deinterlacing insert a filter on every stream.

- - - - -
b7a6ea10 by Martin Finkel at 2026-11-26T14:01:49+01:00
test: decoder: let callers inspect the decoded pictures

- - - - -
7486aef1 by Martin Finkel at 2026-11-26T14:01:49+01:00
test: decoder: load the decoder given by --codec

It defaults to "any", so the demux fuzzer is unchanged.

- - - - -
80323b37 by Martin Finkel at 2026-11-26T14:01:49+01:00
test: codec: add a decoder test driver

A decoder built with ENABLE_TEST lists packets to feed and checks on the
output. Add a CD+G test of the chroma, colour and progressive flag.

- - - - -


8 changed files:

- modules/codec/cdg.c
- test/Makefile.am
- + test/modules/codec/decoder.c
- + test/modules/codec/decoder.h
- test/modules/meson.build
- test/src/input/decoder.c
- test/src/input/decoder.h
- test/src/input/demux-run.c


Changes:

=====================================
modules/codec/cdg.c
=====================================
@@ -62,10 +62,6 @@ typedef struct
 
 #define CDG_PACKET_SIZE 24u
 
-#define CDG_COLOR_R_SHIFT  0
-#define CDG_COLOR_G_SHIFT  8
-#define CDG_COLOR_B_SHIFT 16
-
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
@@ -111,7 +107,7 @@ static int Open( vlc_object_t *p_this )
     /* Set output properties
      * TODO maybe it would be better to use RV16 or RV24 ? */
     p_dec->fmt_out.i_codec =
-    p_dec->fmt_out.video.i_chroma = VLC_CODEC_XBGR;
+    p_dec->fmt_out.video.i_chroma = VLC_CODEC_RGBX;
     p_dec->fmt_out.video.i_width = CDG_DISPLAY_WIDTH;
     p_dec->fmt_out.video.i_height = CDG_DISPLAY_HEIGHT;
     p_dec->fmt_out.video.i_sar_num = 1;
@@ -170,6 +166,7 @@ static int Decode( decoder_t *p_dec, block_t *p_block )
         p_pic = decoder_NewPicture( p_dec );
         if( !p_pic )
             goto exit;
+        p_pic->b_progressive = true;
 
         Render( p_sys, p_pic );
         p_pic->date = p_block->i_pts != VLC_TICK_INVALID ? p_block->i_pts : p_block->i_dts;
@@ -390,16 +387,13 @@ static int DecodePacket( decoder_sys_t *p_cdg, uint8_t *p_buffer, int i_buffer )
     return 0;
 }
 
-static void RenderPixel( picture_t *p_picture, int x, int y, uint32_t c )
-{
-    const int i_plane = 0;
-    const int i_pitch = p_picture->p[i_plane].i_pitch;
-    uint32_t *s = (uint32_t*)&p_picture->p[i_plane].p_pixels[y*i_pitch + x*sizeof(uint32_t)];
-    *s = c;
-}
-static uint32_t RenderRGB( int r, int g, int b )
+static void RenderPixel( picture_t *p_picture, int x, int y, const uint8_t rgb[3] )
 {
-    return ( r << CDG_COLOR_R_SHIFT ) | ( g << CDG_COLOR_G_SHIFT ) | ( b << CDG_COLOR_B_SHIFT );
+    const int i_pitch = p_picture->p[0].i_pitch;
+    uint8_t *p = &p_picture->p[0].p_pixels[y*i_pitch + 4*x];
+    p[0] = rgb[0];
+    p[1] = rgb[1];
+    p[2] = rgb[2];
 }
 
 static int Render( decoder_sys_t *p_cdg, picture_t *p_picture )
@@ -411,13 +405,64 @@ static int Render( decoder_sys_t *p_cdg, picture_t *p_picture )
             const int sx = x + p_cdg->i_offseth + CDG_SCREEN_BORDER_WIDTH;
             const int sy = y + p_cdg->i_offsetv + CDG_SCREEN_BORDER_HEIGHT;
             uint8_t cidx = p_cdg->p_screen[sy*CDG_SCREEN_PITCH +sx];
-            uint8_t r = p_cdg->color[cidx][0];
-            uint8_t g = p_cdg->color[cidx][1];
-            uint8_t b = p_cdg->color[cidx][2];
 
-            RenderPixel( p_picture, x, y, RenderRGB( r, g, b ) );
+            RenderPixel( p_picture, x, y, p_cdg->color[cidx] );
         }
     }
     return 0;
 }
 
+#ifdef ENABLE_TEST
+#include "../../test/modules/codec/decoder.h"
+
+/* Load colour table low (instruction 30): colour 0, which fills the initial
+ * screen, becomes R,G,B 0xf,0x8,0x1 */
+static const uint8_t test_load_colours[CDG_PACKET_SIZE] = {
+    0x09, 30, 0, 0, 0xf << 2 | 0x8 >> 2, (0x8 & 0x3) << 4 | 0x1,
+};
+/* Only pushes the previous packet out of the copy packetizer */
+static const uint8_t test_nop[CDG_PACKET_SIZE];
+
+static const struct decoder_test_packet test_packets[] = {
+    DECODER_TEST_PACKET(test_load_colours),
+    DECODER_TEST_PACKET(test_nop),
+};
+
+static int TestCheckPicture( const picture_t *pic )
+{
+    int failures = 0;
+
+    if( pic->format.i_chroma != VLC_CODEC_RGBX )
+    {
+        decoder_test_log( "FAIL: cdg: chroma %4.4s, expected RGBX\n",
+                          (const char *)&pic->format.i_chroma );
+        failures++;
+    }
+    if( !pic->b_progressive )
+    {
+        decoder_test_log( "FAIL: cdg: the picture is not progressive\n" );
+        failures++;
+    }
+
+    const uint8_t *px = pic->p[0].p_pixels;
+    if( px[0] != 0xf0 || px[1] != 0x80 || px[2] != 0x10 )
+    {
+        decoder_test_log( "FAIL: cdg: pixel %02x %02x %02x, expected f0 80 10\n",
+                          px[0], px[1], px[2] );
+        failures++;
+    }
+    return failures;
+}
+
+const struct decoder_test decoder_tests[] = {
+    {
+        .name = "cdg",
+        .codec = VLC_CODEC_CDG,
+        .packets = test_packets,
+        .packet_count = ARRAY_SIZE(test_packets),
+        .picture_count = 1,
+        .check_picture = TestCheckPicture,
+    },
+    { .name = NULL },
+};
+#endif


=====================================
test/Makefile.am
=====================================
@@ -86,6 +86,7 @@ check_PROGRAMS = \
 	test_modules_codec_cea708 \
 	test_modules_codec_cea708_aspect_ratio \
 	test_modules_codec_cea708_integration \
+	test_modules_codec_cdg \
 	test_modules_keystore \
 	test_modules_demux_json \
 	test_modules_demux_libmp4 \
@@ -431,6 +432,12 @@ test_modules_codec_cea708_aspect_ratio_LDADD = $(LIBVLCCORE) $(LIBVLC)
 
 test_modules_codec_cea708_integration_SOURCES = modules/codec/cea708_integration.c
 test_modules_codec_cea708_integration_LDADD = $(LIBVLCCORE) $(LIBVLC)
+
+test_modules_codec_cdg_SOURCES = modules/codec/decoder.c modules/codec/decoder.h \
+	src/input/decoder.c src/input/decoder.h ../modules/codec/cdg.c
+test_modules_codec_cdg_CPPFLAGS = $(AM_CPPFLAGS) -DENABLE_TEST \
+	-DMODULE_NAME=cdg_test -DMODULE_STRING=\"cdg_test\"
+test_modules_codec_cdg_LDADD = $(LIBVLCCORE) $(LIBVLC)
 test_modules_video_output_opengl_filters_SOURCES = \
 	modules/video_output/opengl/filters.c \
 	../modules/video_output/opengl/filters.c \


=====================================
test/modules/codec/decoder.c
=====================================
@@ -0,0 +1,102 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*****************************************************************************
+ * decoder.c: decoder test driver
+ *****************************************************************************
+ * Copyright (C) 2026 VLC authors and VideoLAN
+ *****************************************************************************/
+
+/* Built with the decoder module under test as a static plugin: MODULE_NAME
+ * and MODULE_STRING name that module. */
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#undef VLC_DYNAMIC_PLUGIN
+
+#include "../../libvlc/test.h"
+#include "../../../lib/libvlc_internal.h"
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_block.h>
+#include <vlc_es.h>
+#include "../../src/input/decoder.h"
+#include "decoder.h"
+
+VLC_EXPORT const vlc_plugin_cb vlc_static_modules[] = {
+    VLC_SYMBOL(vlc_entry),
+    NULL
+};
+
+struct test_run
+{
+    const struct decoder_test *test;
+    unsigned pictures;
+    int failures;
+};
+
+static void OnPicture(void *opaque, const picture_t *pic)
+{
+    struct test_run *run = opaque;
+    run->failures += run->test->check_picture(pic);
+    run->pictures++;
+}
+
+static int RunTest(vlc_object_t *parent, const struct decoder_test *test)
+{
+    struct test_run run = { .test = test };
+
+    es_format_t fmt;
+    es_format_Init(&fmt, VIDEO_ES, test->codec);
+    decoder_t *dec = test_decoder_create(parent, &fmt, OnPicture, &run);
+    es_format_Clean(&fmt);
+    if (dec == NULL)
+    {
+        test_log("FAIL: %s: cannot load the decoder\n", test->name);
+        return 1;
+    }
+
+    for (size_t i = 0; i < test->packet_count; i++)
+    {
+        const struct decoder_test_packet *packet = &test->packets[i];
+        block_t *block = block_Alloc(packet->size);
+        assert(block != NULL);
+        memcpy(block->p_buffer, packet->data, packet->size);
+        block->i_pts = block->i_dts = VLC_TICK_0 + i * VLC_TICK_FROM_MS(40);
+        test_decoder_process(dec, block);
+    }
+    test_decoder_process(dec, NULL);
+    test_decoder_destroy(dec);
+
+    if (run.pictures != test->picture_count)
+    {
+        test_log("FAIL: %s: %u pictures, expected %u\n", test->name,
+                 run.pictures, test->picture_count);
+        run.failures++;
+    }
+    return run.failures != 0;
+}
+
+int main(void)
+{
+    test_init();
+
+    libvlc_instance_t *vlc = libvlc_new(test_defaults_nargs, test_defaults_args);
+    assert(vlc != NULL);
+    vlc_object_t *parent = VLC_OBJECT(vlc->p_libvlc_int);
+
+    /* Only the module built with the tests, not its plugin */
+    var_Create(parent, "codec", VLC_VAR_STRING);
+    var_SetString(parent, "codec", MODULE_STRING ",none");
+
+    int ret = 0;
+    for (const struct decoder_test *test = decoder_tests;
+         test->name != NULL; test++)
+    {
+        test_log("Testing %s\n", test->name);
+        if (RunTest(parent, test))
+            ret = 1;
+    }
+
+    libvlc_release(vlc);
+    return ret;
+}


=====================================
test/modules/codec/decoder.h
=====================================
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*****************************************************************************
+ * decoder.h: decoder test driver
+ *****************************************************************************
+ * Copyright (C) 2026 VLC authors and VideoLAN
+ *****************************************************************************/
+
+#ifndef VLC_TEST_MODULES_CODEC_DECODER_H
+#define VLC_TEST_MODULES_CODEC_DECODER_H
+
+#include <stdio.h>
+
+#include <vlc_common.h>
+
+/* A video decoder module built with ENABLE_TEST defines decoder_tests[], ended
+ * by an entry without a name. The driver loads the module and feeds each
+ * test's packets through the packetizer and the decoder, with dts = pts, then
+ * drains them. check_picture returns the number of failures. */
+
+struct decoder_test_packet
+{
+    const uint8_t *data;
+    size_t size;
+};
+
+#define DECODER_TEST_PACKET(p) { (p), sizeof (p) }
+
+struct decoder_test
+{
+    const char *name;
+    vlc_fourcc_t codec;
+    const struct decoder_test_packet *packets;
+    size_t packet_count;
+
+    unsigned picture_count;
+    int (*check_picture)(const picture_t *pic);
+};
+
+extern const struct decoder_test decoder_tests[];
+
+#define decoder_test_log(...) fprintf(stderr, "testapi: " __VA_ARGS__)
+
+#endif


=====================================
test/modules/meson.build
=====================================
@@ -177,6 +177,17 @@ vlc_tests += {
     'module_depends' : vlc_plugins_targets.keys()
 }
 
+vlc_tests += {
+    'name' : 'test_modules_codec_cdg',
+    'sources' : files('codec/decoder.c', '../src/input/decoder.c',
+                      '../../modules/codec/cdg.c'),
+    'suite' : ['modules', 'test_modules'],
+    'c_args' : ['-DENABLE_TEST', '-DMODULE_NAME=cdg_test',
+                '-DMODULE_STRING="cdg_test"'],
+    'link_with' : [libvlc, libvlccore],
+    'module_depends' : ['packetizer_copy']
+}
+
 vlc_tests += {
     'name' : 'test_modules_video_output_opengl_filters',
     'sources' : files(


=====================================
test/src/input/decoder.c
=====================================
@@ -44,6 +44,8 @@ struct decoder_owner
     decoder_t dec;
     es_format_t fmt_in;
     decoder_t *packetizer;
+    void (*on_picture)(void *opaque, const picture_t *pic);
+    void *opaque;
 };
 
 static inline struct decoder_owner *dec_get_owner(decoder_t *dec)
@@ -67,7 +69,9 @@ static vlc_decoder_device * get_no_device( decoder_t *dec )
 
 static void queue_video(decoder_t *dec, picture_t *pic)
 {
-    (void) dec;
+    struct decoder_owner *owner = dec_get_owner(dec);
+    if (owner->on_picture != NULL)
+        owner->on_picture(owner->opaque, pic);
     picture_Release(pic);
 }
 
@@ -104,7 +108,7 @@ static int decoder_load(decoder_t *decoder, bool is_packetizer,
 
     decoder->b_frame_drop_allowed = true;
 
-    decoder_LoadModule(decoder, is_packetizer, false);
+    decoder_LoadModule(decoder, is_packetizer, !is_packetizer);
     if (!decoder->p_module)
     {
         decoder_Clean( decoder );
@@ -129,7 +133,10 @@ void test_decoder_destroy(decoder_t *decoder)
     decoder_destroy_clean(decoder);
 }
 
-decoder_t *test_decoder_create(vlc_object_t *parent, const es_format_t *fmt)
+decoder_t *test_decoder_create(vlc_object_t *parent, const es_format_t *fmt,
+                               void (*on_picture)(void *opaque,
+                                                  const picture_t *pic),
+                               void *opaque)
 {
     assert(parent && fmt);
     decoder_t *packetizer = decoder_create(parent);
@@ -144,6 +151,8 @@ decoder_t *test_decoder_create(vlc_object_t *parent, const es_format_t *fmt)
 
     struct decoder_owner *owner = dec_get_owner(decoder);
     owner->packetizer = packetizer;
+    owner->on_picture = on_picture;
+    owner->opaque = opaque;
 
     static const struct decoder_owner_callbacks dec_video_cbs =
     {


=====================================
test/src/input/decoder.h
=====================================
@@ -20,6 +20,10 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
-decoder_t *test_decoder_create(vlc_object_t *parent, const es_format_t *fmt);
+/* on_picture is called with each decoded picture, released after the call */
+decoder_t *test_decoder_create(vlc_object_t *parent, const es_format_t *fmt,
+                               void (*on_picture)(void *opaque,
+                                                  const picture_t *pic),
+                               void *opaque);
 void test_decoder_destroy(decoder_t *decoder);
 int test_decoder_process(decoder_t *decoder, block_t *block);


=====================================
test/src/input/demux-run.c
=====================================
@@ -86,7 +86,7 @@ static es_out_id_t *EsOutAdd(es_out_t *out, input_source_t* in, const es_format_
     ctx->ids = id;
 #ifdef HAVE_DECODERS
     es_format_Copy(&id->fmt, fmt);
-    id->decoder = test_decoder_create(ctx->parent, &id->fmt);
+    id->decoder = test_decoder_create(ctx->parent, &id->fmt, NULL, NULL);
     if (id->decoder == NULL)
         es_format_Clean(&id->fmt);
 #endif
@@ -165,7 +165,7 @@ static int EsOutControl(es_out_t *out, input_source_t* in, int query, va_list ar
             es_out_id_t* id = va_arg(args, es_out_id_t*);
             EsOutCheckId(ctx, id);
             test_decoder_destroy(id->decoder);
-            test_decoder_create(ctx->parent, &id->fmt);
+            test_decoder_create(ctx->parent, &id->fmt, NULL, NULL);
 #endif
             break;
         }



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/c5845546724b963b7e605aa5f41892092f7e52ba...80323b37b54088b40939505bbd147db11574b631

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/c5845546724b963b7e605aa5f41892092f7e52ba...80323b37b54088b40939505bbd147db11574b631
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help




More information about the vlc-commits mailing list