test_thumbnailgst.c (4124B)
1 /* 2 This file is part of libextractor. 3 Copyright (C) 2026 Vidyut Samanta and Christian Grothoff 4 5 libextractor is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published 7 by the Free Software Foundation; either version 3, or (at your 8 option) any later version. 9 10 libextractor is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with libextractor; see the file COPYING. If not, write to the 17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 Boston, MA 02110-1301, USA. 19 */ 20 /** 21 * @file plugins/test_thumbnailgst.c 22 * @brief testcase for the thumbnailgst plugin 23 * @author Christian Grothoff 24 * 25 * The encoder's output depends on the GStreamer version, so the JPEG can 26 * only be checked for its magic number. The PNG round, on the other 27 * hand, is decoded: testdata/thumbnail_pattern.ogv is black for the 28 * first 20 seconds and red afterwards, so the colour of the thumbnail 29 * says whether the plugin really sampled where it claims to. 30 */ 31 #include "platform.h" 32 #include "test_lib.h" 33 #include "test_media_lib.h" 34 #ifndef WINDOWS 35 #include <sys/wait.h> 36 #endif 37 38 39 /** 40 * Check that the thumbnail was taken from the red part of the video. 41 * 42 * @param data the PNG the plugin produced 43 * @param data_len number of bytes in @a data 44 * @return non-zero if the thumbnail looks right 45 */ 46 static int 47 validate_red (const void *data, 48 size_t data_len) 49 { 50 return TEST_media_png_center_is (data, 51 data_len, 52 0xFE, 53 0x00, 54 0x00); 55 } 56 57 58 /** 59 * Main function for the thumbnailgst testcase. 60 * 61 * @param argc number of arguments (ignored) 62 * @param argv arguments (ignored) 63 * @return 0 on success 64 */ 65 int 66 main (int argc, char *argv[]) 67 { 68 uint8_t jpeg_magic[] = { 0xFF, 0xD8, 0xFF }; 69 uint8_t png_magic[] = { 137, 'P', 'N', 'G', '\r', '\n', 26, '\n' }; 70 struct SolutionData thumbnail_jpeg_sol[] = { 71 { 72 EXTRACTOR_METATYPE_THUMBNAIL, 73 EXTRACTOR_METAFORMAT_BINARY, 74 "image/jpeg", 75 (const char *) jpeg_magic, 76 sizeof (jpeg_magic), 77 0 78 }, 79 { 0, 0, NULL, NULL, 0, -1 } 80 }; 81 struct SolutionData thumbnail_png_sol[] = { 82 { 83 EXTRACTOR_METATYPE_THUMBNAIL, 84 EXTRACTOR_METAFORMAT_BINARY, 85 "image/png", 86 (const char *) png_magic, 87 sizeof (png_magic), 88 0, 89 0, 90 &validate_red 91 }, 92 { 0, 0, NULL, NULL, 0, -1 } 93 }; 94 struct ProblemSet ps_jpeg[] = { 95 { "testdata/thumbnail_pattern.ogv", 96 thumbnail_jpeg_sol }, 97 { NULL, NULL } 98 }; 99 struct ProblemSet ps_png[] = { 100 { "testdata/thumbnail_pattern.ogv", 101 thumbnail_png_sol }, 102 { NULL, NULL } 103 }; 104 #ifndef WINDOWS 105 pid_t pid; 106 int status; 107 108 /* The two rounds must not share a process: ET_main() runs each round 109 out-of-process and then in-process, and once GStreamer has been 110 initialized in this process (by the in-process leg of the first 111 round), the fork() that the out-of-process leg of the second round 112 performs inherits a GStreamer that no longer works in the child. 113 So run the first round in a child of our own, before any of that 114 has happened. */ 115 pid = fork (); 116 if (0 == pid) 117 _exit (ET_main ("thumbnailgst", 118 ps_jpeg)); 119 if (-1 == pid) 120 return 77; /* cannot fork, skip */ 121 if (pid != waitpid (pid, 122 &status, 123 0)) 124 return 1; 125 if ( (! WIFEXITED (status)) || 126 (0 != WEXITSTATUS (status)) ) 127 return 1; 128 #else 129 int ret; 130 131 ret = ET_main ("thumbnailgst", 132 ps_jpeg); 133 if (0 != ret) 134 return ret; 135 #endif 136 return ET_main ("thumbnailgst(format=png,size=32)", 137 ps_png); 138 } 139 140 141 /* end of test_thumbnailgst.c */