From 48d31273f5c62c4ac952566cff76baeabea1f0f0 Mon Sep 17 00:00:00 2001 From: Thomas Guillem Date: Mon, 20 Dec 2021 17:45:23 +0100 Subject: [PATCH] test: test the ancillary API --- test/Makefile.am | 3 + test/src/misc/ancillary.c | 118 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 test/src/misc/ancillary.c diff --git a/test/Makefile.am b/test/Makefile.am index 067302d17b..ab80d93f1c 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -25,6 +25,7 @@ check_PROGRAMS = \ test_libvlc_slaves \ test_libvlc_tracer \ test_src_config_chain \ + test_src_misc_ancillary \ test_src_misc_variables \ test_src_input_stream \ test_src_input_stream_fifo \ @@ -102,6 +103,8 @@ test_libvlc_slaves_SOURCES = libvlc/slaves.c test_libvlc_slaves_LDADD = $(LIBVLCCORE) $(LIBVLC) test_libvlc_meta_SOURCES = libvlc/meta.c test_libvlc_meta_LDADD = $(LIBVLCCORE) $(LIBVLC) +test_src_misc_ancillary_SOURCES = src/misc/ancillary.c +test_src_misc_ancillary_LDADD = $(LIBVLCCORE) $(LIBVLC) test_libvlc_tracer_SOURCES = libvlc/tracer.c test_libvlc_tracer_LDADD = $(LIBVLCCORE) $(LIBVLC) test_src_misc_variables_SOURCES = src/misc/variables.c diff --git a/test/src/misc/ancillary.c b/test/src/misc/ancillary.c new file mode 100644 index 0000000000..c04d86b8bf --- /dev/null +++ b/test/src/misc/ancillary.c @@ -0,0 +1,118 @@ +/***************************************************************************** + * ancillary.c: test for ancillary + ***************************************************************************** + * Copyright (C) 2021 the VideoLAN team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include +#include + +#include + +static void +ancillary_free(void *data) +{ + assert(strncmp(data, "test", 4) == 0); + free(data); +} + +int main( void ) +{ + vlc_frame_t *frame = vlc_frame_Alloc(1); + assert(frame); + + int ret; + struct vlc_ancillary *ancillary; + + /* Create and try to attach 3 ancillaries to the frame, only 2 will be + * attached. */ + for (size_t i = 0; i < 3; ++i) + { + char *data; + ret = asprintf(&data, "test%zu", i); + assert(ret > 0); + + vlc_ancillary_id id; + switch (i) + { + case 0: + /* Check that only one ancillary of the same id is added (the + * last one take precedence). */ + case 1: id = VLC_ANCILLARY_ID('t','s','t','1'); break; + case 2: id = VLC_ANCILLARY_ID('t','s','t','2'); break; + default: vlc_assert_unreachable(); + } + + ancillary = vlc_ancillary_CreateWithFreeCb(data, id, ancillary_free); + assert(ancillary); + + ret = vlc_frame_AttachAncillary(frame, ancillary); + assert(ret == VLC_SUCCESS); + vlc_ancillary_Release(ancillary); + } + + /* Check that ancillaries are copied via a vlc_frame_CopyProperties() (done + * by vlc_frame_Duplicate()). */ + vlc_frame_t *copy_frame = vlc_frame_Duplicate(frame); + assert(copy_frame); + vlc_frame_Release(frame); + frame = copy_frame; + + picture_t *picture = picture_New(VLC_CODEC_NV12, 1, 1, 1, 1); + assert(picture); + + /* Manually attach both ancillaries to a newly allocated picture. */ + ancillary = vlc_frame_GetAncillary(frame, VLC_ANCILLARY_ID('t','s','t','1')); + assert(ancillary); + picture_AttachAncillary(picture, ancillary); + + ancillary = vlc_frame_GetAncillary(frame, VLC_ANCILLARY_ID('t','s','t','2')); + assert(ancillary); + picture_AttachAncillary(picture, ancillary); + + vlc_frame_Release(frame); + + /* Check that ancillaries are copied via a picture_Clone(). */ + picture_t *clone = picture_Clone(picture); + assert(clone); + picture_Release(picture); + + /* Check that ancillaries are copied via a picture_Copy(). */ + picture_t *copy = picture_New(VLC_CODEC_I420, 1, 1, 1, 1); + assert(copy); + picture_Copy(copy, clone); + picture_Release(clone); + + /* Check that ancillaries are still valid. */ + ancillary = picture_GetAncillary(copy, VLC_ANCILLARY_ID('t','s','t','1')); + assert(ancillary); + assert(strcmp("test1", vlc_ancillary_GetData(ancillary)) == 0); + + ancillary = picture_GetAncillary(copy, VLC_ANCILLARY_ID('t','s','t','2')); + assert(ancillary); + assert(strcmp("test2", vlc_ancillary_GetData(ancillary)) == 0); + + picture_Release(copy); + + return 0; +}