Skip to content

Commit

Permalink
test: medialibrary: check that thumbnailing works
Browse files Browse the repository at this point in the history
The test creates a libvlc instance with a medialibrary and check that
the medialibrary can generate a mock thumbnail for a given mock:// URL
with different parameters.

Multiple improvements can be done from here: in particular, the
medialibrary will insist in loading its discovery modules, whereas we
only need to check whether the thumbnailing work in this current test.
Some work needs to be done to evaluate whether it's interesting enough
to cut those discovery modules out for this test or extend the scenario
to other cases like testing those discovery modules.

Regression testing from #27749
  • Loading branch information
alexandre-janniaux authored and tmatth committed Jan 25, 2023
1 parent 4791527 commit 277d731
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ check_PROGRAMS = \
test_src_misc_image \
test_src_video_output \
test_src_video_output_opengl \
test_modules_misc_medialibrary \
test_modules_packetizer_helpers \
test_modules_packetizer_hxxx \
test_modules_packetizer_h264 \
Expand Down Expand Up @@ -147,6 +148,9 @@ test_src_interface_dialog_SOURCES = src/interface/dialog.c
test_src_interface_dialog_LDADD = $(LIBVLCCORE) $(LIBVLC)
test_src_media_source_LDADD = $(LIBVLCCORE) $(LIBVLC)
test_src_media_source_SOURCES = src/media_source/media_source.c

test_modules_misc_medialibrary_SOURCES = modules/misc/medialibrary.c
test_modules_misc_medialibrary_LDADD = $(LIBVLCCORE) $(LIBVLC)
test_modules_packetizer_helpers_SOURCES = modules/packetizer/helpers.c
test_modules_packetizer_helpers_LDADD = $(LIBVLCCORE) $(LIBVLC)
test_modules_packetizer_hxxx_SOURCES = modules/packetizer/hxxx.c
Expand Down
150 changes: 150 additions & 0 deletions test/modules/misc/medialibrary.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/*****************************************************************************
* medialibrary.c: test for the medialibrary code
*****************************************************************************
* Copyright (C) 2023 Videolabs
*
* Authors: Alexandre Janniaux <[email protected]>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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

/* Define a builtin module for mocked parts */
#define MODULE_NAME test_misc_medialibrary
#define MODULE_STRING "test_misc_medialibrary"
#undef __PLUGIN__
const char vlc_module_name[] = MODULE_STRING;

#include "../../libvlc/test.h"

#include <vlc/vlc.h>

#include <vlc_common.h>
#include <vlc_image.h>
#include <vlc_picture.h>
#include <vlc_plugin.h>
#include <vlc_block.h>
#include <vlc_codec.h>
#include <vlc_filter.h>

#include <vlc_media_library.h>
#include <ftw.h>

static int exitcode = 0;

static void ValidateThumbnail(void *data, const vlc_ml_event_t *event)
{
if (event->i_type != VLC_ML_EVENT_MEDIA_THUMBNAIL_GENERATED)
return;

assert(event->media_thumbnail_generated.b_success);
vlc_sem_t *sem = data;
vlc_sem_post(sem);
}

static int OpenIntf(vlc_object_t *root)
{
vlc_medialibrary_t *ml = vlc_ml_instance_get(root);
if (ml == NULL)
{
exitcode = 77;
return VLC_SUCCESS;
}

video_format_t fmt_in;
video_format_Init(&fmt_in, VLC_CODEC_RGBA);
fmt_in.i_width = fmt_in.i_visible_width = 800;
fmt_in.i_height = fmt_in.i_visible_height = 600;

video_format_t fmt_out;
video_format_Init(&fmt_out, VLC_CODEC_PNG);
fmt_out.i_width = fmt_out.i_visible_width = 800;
fmt_out.i_height = fmt_out.i_visible_height = 600;

picture_t *picture = picture_NewFromFormat(&fmt_in);
assert(picture != NULL);

#define MOCK_URL "mock://video_track_count=1;length=100000000;" \
"video_width=800;video_height=600"
vlc_ml_media_t *media = vlc_ml_new_external_media(ml, MOCK_URL);

vlc_sem_t sem;
vlc_sem_init(&sem, 0);

vlc_ml_event_callback_t *listener =
vlc_ml_event_register_callback(ml, ValidateThumbnail, &sem);
vlc_ml_media_generate_thumbnail(ml, media->i_id,
VLC_ML_THUMBNAIL_SMALL, 800, 600, 0.f);

vlc_sem_wait(&sem);
vlc_ml_event_unregister_callback(ml, listener);

return VLC_SUCCESS;
}

/** Inject the mocked modules as a static plugin: **/
vlc_module_begin()
set_callback(OpenIntf)
set_capability("interface", 0)
vlc_module_end()

/* Helper typedef for vlc_static_modules */
typedef int (*vlc_plugin_cb)(vlc_set_cb, void*);

VLC_EXPORT const vlc_plugin_cb vlc_static_modules[] = {
VLC_SYMBOL(vlc_entry),
NULL
};

static int cleanup_tmpdir(const char *dirpath, const struct stat *sb,
int typeflag, struct FTW *ftwbuf)
{
(void)sb; (void)typeflag; (void)ftwbuf;
return remove(dirpath);
}

int main()
{
char template[] = "/tmp/vlc.test." MODULE_STRING ".XXXXXX";
const char *tempdir = mkdtemp(template);
if (tempdir == NULL)
{
assert(tempdir != NULL);
return -1;
}
fprintf(stderr, "Using XDG_DATA_HOME directory %s\n", tempdir);
setenv("XDG_DATA_HOME", tempdir, 1);

test_init();

const char * const args[] = {
"-vvv", "--vout=dummy", "--aout=dummy", "--text-renderer=dummy",
"--no-auto-preparse", "--media-library"
};

libvlc_instance_t *vlc = libvlc_new(ARRAY_SIZE(args), args);

libvlc_add_intf(vlc, MODULE_STRING);
libvlc_playlist_play(vlc);

libvlc_release(vlc);

/* Remove temporary directory */
nftw(tempdir, cleanup_tmpdir, FOPEN_MAX, FTW_DEPTH | FTW_MOUNT | FTW_PHYS);
return exitcode;
}

0 comments on commit 277d731

Please sign in to comment.