forked from videolan/vlc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: medialibrary: check that thumbnailing works
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
1 parent
4791527
commit 277d731
Showing
2 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |