2013-08-07 19:12:45 +00:00
|
|
|
/* GStreamer
|
2013-08-28 19:58:11 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Collabora Ltd.
|
|
|
|
* Author: Thiago Sousa Santos <thiago.sousa.santos@collabora.com>
|
|
|
|
*
|
|
|
|
* gst-validate-media-check.c - Media Check CLI tool
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library 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 library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
2013-08-07 19:12:45 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
2013-08-14 19:30:39 +00:00
|
|
|
#include <gst/validate/validate.h>
|
2014-04-24 13:41:50 +00:00
|
|
|
#include <gst/validate/media-descriptor-writer.h>
|
|
|
|
#include <gst/validate/media-descriptor-parser.h>
|
|
|
|
#include <gst/validate/media-descriptor.h>
|
2013-08-07 19:12:45 +00:00
|
|
|
#include <gst/pbutils/encoding-profile.h>
|
2015-08-11 01:05:41 +00:00
|
|
|
#include <locale.h> /* for LC_ALL */
|
2013-08-07 19:12:45 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, gchar ** argv)
|
|
|
|
{
|
|
|
|
GOptionContext *ctx;
|
|
|
|
|
2014-04-24 13:41:50 +00:00
|
|
|
guint ret = 0;
|
2014-05-02 12:06:18 +00:00
|
|
|
GError *err = NULL;
|
|
|
|
gboolean full = FALSE;
|
2013-08-19 19:38:13 +00:00
|
|
|
gchar *output_file = NULL;
|
2013-08-21 14:03:19 +00:00
|
|
|
gchar *expected_file = NULL;
|
2013-08-19 19:38:13 +00:00
|
|
|
gchar *output = NULL;
|
2016-01-22 19:14:16 +00:00
|
|
|
GstValidateMediaDescriptorWriter *writer = NULL;
|
2015-03-26 14:39:12 +00:00
|
|
|
GstValidateRunner *runner = NULL;
|
2016-01-22 19:14:16 +00:00
|
|
|
GstValidateMediaDescriptorParser *reference = NULL;
|
2013-08-07 19:12:45 +00:00
|
|
|
|
|
|
|
GOptionEntry options[] = {
|
2013-08-19 19:38:13 +00:00
|
|
|
{"output-file", 'o', 0, G_OPTION_ARG_FILENAME,
|
|
|
|
&output_file, "The output file to store the results",
|
2013-08-07 19:12:45 +00:00
|
|
|
NULL},
|
2014-05-02 12:06:18 +00:00
|
|
|
{"full", 'f', 0, G_OPTION_ARG_NONE,
|
2015-06-14 21:44:26 +00:00
|
|
|
&full, "Fully analyze the file frame by frame",
|
2014-05-02 12:06:18 +00:00
|
|
|
NULL},
|
2013-08-21 14:03:19 +00:00
|
|
|
{"expected-results", 'e', 0, G_OPTION_ARG_FILENAME,
|
2013-08-21 15:11:40 +00:00
|
|
|
&expected_file, "Path to file containing the expected results "
|
|
|
|
"(or the last results found) for comparison with new results",
|
2013-08-21 14:03:19 +00:00
|
|
|
NULL},
|
2013-08-07 19:12:45 +00:00
|
|
|
{NULL}
|
|
|
|
};
|
|
|
|
|
2015-08-11 01:05:41 +00:00
|
|
|
setlocale (LC_ALL, "");
|
2013-08-20 14:43:06 +00:00
|
|
|
g_set_prgname ("gst-validate-media-check-" GST_API_VERSION);
|
2013-08-14 21:04:23 +00:00
|
|
|
ctx = g_option_context_new ("[URI]");
|
2015-06-14 21:44:26 +00:00
|
|
|
g_option_context_set_summary (ctx, "Analyzes a media file and writes "
|
2013-08-19 19:38:13 +00:00
|
|
|
"the results to stdout or a file. Can also compare the results found "
|
|
|
|
"with another results file for identifying regressions. The monitoring"
|
|
|
|
" lib from gst-validate will be enabled during the tests to identify "
|
|
|
|
"issues with the gstreamer elements involved with the media file's "
|
|
|
|
"container and codec types");
|
2013-08-07 19:12:45 +00:00
|
|
|
g_option_context_add_main_entries (ctx, options, NULL);
|
|
|
|
|
|
|
|
if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
|
|
|
|
g_printerr ("Error initializing: %s\n", err->message);
|
|
|
|
g_option_context_free (ctx);
|
2015-08-20 07:51:03 +00:00
|
|
|
g_clear_error (&err);
|
2013-08-07 19:12:45 +00:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_init (&argc, &argv);
|
2013-08-14 22:14:18 +00:00
|
|
|
gst_validate_init ();
|
2013-08-07 19:12:45 +00:00
|
|
|
|
|
|
|
if (argc != 2) {
|
2013-08-19 19:38:13 +00:00
|
|
|
gchar *msg = g_option_context_get_help (ctx, TRUE, NULL);
|
|
|
|
g_printerr ("%s\n", msg);
|
|
|
|
g_free (msg);
|
|
|
|
g_option_context_free (ctx);
|
2015-03-26 14:39:12 +00:00
|
|
|
ret = 1;
|
|
|
|
goto out;
|
2013-08-07 19:12:45 +00:00
|
|
|
}
|
2013-08-19 19:38:13 +00:00
|
|
|
g_option_context_free (ctx);
|
2013-08-07 19:12:45 +00:00
|
|
|
|
2014-04-24 13:41:50 +00:00
|
|
|
runner = gst_validate_runner_new ();
|
2015-11-30 14:54:05 +00:00
|
|
|
|
|
|
|
if (expected_file) {
|
2016-01-22 19:14:16 +00:00
|
|
|
reference =
|
|
|
|
gst_validate_media_descriptor_parser_new (runner, expected_file, NULL);
|
2015-11-30 14:54:05 +00:00
|
|
|
|
|
|
|
if (reference == NULL) {
|
|
|
|
g_print ("Could not parse file: %s\n", expected_file);
|
|
|
|
ret = 1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2016-01-22 19:14:16 +00:00
|
|
|
if (!full
|
|
|
|
&&
|
|
|
|
gst_validate_media_descriptor_has_frame_info (
|
|
|
|
(GstValidateMediaDescriptor *)
|
2015-11-30 14:54:05 +00:00
|
|
|
reference))
|
|
|
|
full = TRUE; /* Reference has frame info, activate to do comparison */
|
|
|
|
}
|
|
|
|
|
2014-06-03 08:02:10 +00:00
|
|
|
writer =
|
2016-01-22 19:14:16 +00:00
|
|
|
gst_validate_media_descriptor_writer_new_discover (runner, argv[1], full,
|
|
|
|
TRUE, NULL);
|
2014-04-24 13:41:50 +00:00
|
|
|
if (writer == NULL) {
|
2015-05-29 07:45:25 +00:00
|
|
|
g_print ("Could not discover file: %s\n", argv[1]);
|
2015-03-26 14:39:12 +00:00
|
|
|
ret = 1;
|
|
|
|
goto out;
|
2014-04-24 13:41:50 +00:00
|
|
|
}
|
2013-08-19 19:38:13 +00:00
|
|
|
|
2015-07-20 08:27:56 +00:00
|
|
|
if (output_file) {
|
2016-01-22 19:14:16 +00:00
|
|
|
if (!gst_validate_media_descriptor_writer_write (writer, output_file)) {
|
2015-07-20 08:27:56 +00:00
|
|
|
ret = 1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
2013-08-07 19:12:45 +00:00
|
|
|
|
2015-11-30 14:54:05 +00:00
|
|
|
if (reference) {
|
2016-01-22 19:14:16 +00:00
|
|
|
if (!gst_validate_media_descriptors_compare (GST_VALIDATE_MEDIA_DESCRIPTOR
|
|
|
|
(reference), GST_VALIDATE_MEDIA_DESCRIPTOR (writer))) {
|
2015-07-24 06:36:27 +00:00
|
|
|
ret = 1;
|
|
|
|
goto out;
|
|
|
|
}
|
2014-04-24 13:41:50 +00:00
|
|
|
} else {
|
2016-01-22 19:14:16 +00:00
|
|
|
output = gst_validate_media_descriptor_writer_serialize (writer);
|
2014-04-24 13:41:50 +00:00
|
|
|
g_print ("Media info:\n%s\n", output);
|
|
|
|
g_free (output);
|
2013-08-21 14:03:19 +00:00
|
|
|
}
|
|
|
|
|
2015-05-27 11:18:33 +00:00
|
|
|
ret = gst_validate_runner_exit (runner, TRUE);
|
2014-04-24 13:41:50 +00:00
|
|
|
if (ret && expected_file) {
|
2016-01-22 19:14:16 +00:00
|
|
|
output = gst_validate_media_descriptor_writer_serialize (writer);
|
2014-04-24 13:41:50 +00:00
|
|
|
g_print ("Media info:\n%s\n", output);
|
|
|
|
g_free (output);
|
|
|
|
}
|
2013-08-07 19:12:45 +00:00
|
|
|
|
2015-03-26 14:39:12 +00:00
|
|
|
out:
|
|
|
|
g_free (output_file);
|
|
|
|
g_free (expected_file);
|
|
|
|
|
2016-05-27 13:37:00 +00:00
|
|
|
if (reference) {
|
|
|
|
gst_validate_reporter_purge_reports (GST_VALIDATE_REPORTER (reference));
|
2014-04-24 13:41:50 +00:00
|
|
|
gst_object_unref (reference);
|
2016-05-27 13:37:00 +00:00
|
|
|
}
|
|
|
|
if (writer) {
|
|
|
|
gst_validate_reporter_purge_reports (GST_VALIDATE_REPORTER (writer));
|
2015-03-26 14:39:12 +00:00
|
|
|
gst_object_unref (writer);
|
2016-05-27 13:37:00 +00:00
|
|
|
}
|
2015-03-26 14:39:12 +00:00
|
|
|
if (runner)
|
|
|
|
gst_object_unref (runner);
|
2015-05-11 11:54:15 +00:00
|
|
|
gst_validate_deinit ();
|
2016-05-20 12:46:19 +00:00
|
|
|
gst_deinit ();
|
2014-04-24 13:41:50 +00:00
|
|
|
|
2015-08-24 07:39:15 +00:00
|
|
|
g_print ("\n=======> Test %s (Return value: %i)\n\n",
|
|
|
|
ret == 0 ? "PASSED" : "FAILED", ret);
|
|
|
|
|
2014-04-24 13:41:50 +00:00
|
|
|
return ret;
|
2013-08-07 19:12:45 +00:00
|
|
|
}
|