mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-30 21:51:09 +00:00
2f4517a70b
Original commit message from CVS: Patch by: Alessandro Decina <alessandro at nnva dot org> * ext/annodex/gstannodex.c: (gst_annodex_granule_to_time): Do some extra sanity checks. Fixes #350340. * ext/annodex/gstcmmlenc.c: (gst_cmml_enc_change_state), (gst_cmml_enc_parse_tag_head), (gst_cmml_enc_parse_tag_clip), (gst_cmml_enc_push_clip), (gst_cmml_enc_push): Check if clip->start_time is valid before adding the clip to the track list. Reset enc->preamble going from PAUSED to READY. Don't use GST_FLOW_UNEXPECTED for wrong usage of the element, it is only used for EOS. Only post an error message if we were the one that created the fatal GstFlowReturn value. * ext/annodex/gstcmmlutils.c: (gst_cmml_clock_time_from_npt), (gst_cmml_clock_time_to_granule), (gst_cmml_track_list_has_clip): Parse the seconds field of the npt-sec time format using %llu rather than %d and check that the value scaled by GST_SECOND doesn't overflow. Use guint64(s) to represent the keyindex and keyoffset fields of a granulepos. Lookup a clip's track with clip->track rather than clip->id which makes no sense. Identify a clip by its track and start time and not its xml id. do some more input checking and make sure we don't do undefined shifts. * tests/check/elements/cmmldec.c: (setup_cmmldec), (teardown_cmmldec), (check_output_buffer_is_equal), (push_data), (cmml_tag_message_pop), (check_headers), (push_clip_full), (push_clip), (push_empty_clip), (check_output_clip), (GST_START_TEST), (cmmldec_suite): * tests/check/elements/cmmlenc.c: (setup_cmmlenc), (teardown_cmmlenc), (check_output_buffer_is_equal), (push_data), (check_headers), (push_clip), (check_clip_times), (check_clip), (check_empty_clip), (GST_START_TEST), (cmmlenc_suite): Added some more checks.
166 lines
4.5 KiB
C
166 lines
4.5 KiB
C
/*
|
|
* gstannodex.c - GStreamer annodex plugin
|
|
* Copyright (C) 2005 Alessandro Decina
|
|
*
|
|
* Authors:
|
|
* Alessandro Decina <alessandro@nnva.org>
|
|
*
|
|
* 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 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.
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
#include "config.h"
|
|
#endif
|
|
|
|
#include <math.h>
|
|
#include <gst/tag/tag.h>
|
|
#include "gstcmmlparser.h"
|
|
#include "gstcmmlenc.h"
|
|
#include "gstcmmldec.h"
|
|
|
|
GstClockTime
|
|
gst_annodex_granule_to_time (gint64 granulepos, gint64 granulerate_n,
|
|
gint64 granulerate_d, guint8 granuleshift)
|
|
{
|
|
gint64 keyindex, keyoffset;
|
|
gint64 granulerate;
|
|
GstClockTime res;
|
|
|
|
g_return_val_if_fail (granuleshift <= 64, GST_CLOCK_TIME_NONE);
|
|
|
|
if (granulepos == -1)
|
|
return GST_CLOCK_TIME_NONE;
|
|
|
|
if (granulepos == 0 || granulerate_n == 0 || granulerate_d == 0)
|
|
return 0;
|
|
|
|
if (granuleshift != 0 && granuleshift != 64) {
|
|
keyindex = granulepos >> granuleshift;
|
|
keyoffset = granulepos - (keyindex << granuleshift);
|
|
granulepos = keyindex + keyoffset;
|
|
}
|
|
|
|
/* GST_SECOND / (granulerate_n / granulerate_d) */
|
|
granulerate = gst_util_uint64_scale (GST_SECOND,
|
|
granulerate_d, granulerate_n);
|
|
|
|
/* granulepos * granulerate */
|
|
res = gst_util_uint64_scale (granulepos, granulerate, 1);
|
|
|
|
return res;
|
|
}
|
|
|
|
GValueArray *
|
|
gst_annodex_parse_headers (const gchar * headers)
|
|
{
|
|
GValueArray *array;
|
|
GValue val = { 0 };
|
|
gchar *header_name = NULL;
|
|
gchar *header_value = NULL;
|
|
gchar *line, *column, *space, *tmp;
|
|
gchar **lines;
|
|
gint i = 0;
|
|
|
|
array = g_value_array_new (0);
|
|
g_value_init (&val, G_TYPE_STRING);
|
|
|
|
lines = g_strsplit (headers, "\r\n", 0);
|
|
line = lines[i];
|
|
while (line != NULL && *line != '\0') {
|
|
if (line[0] == '\t' || line[0] == ' ') {
|
|
/* WSP: continuation line */
|
|
if (header_value == NULL)
|
|
/* continuation line without a previous value */
|
|
goto fail;
|
|
|
|
tmp = g_strjoin (" ", header_value, g_strstrip (line), NULL);
|
|
g_free (header_value);
|
|
header_value = tmp;
|
|
} else {
|
|
if (header_name) {
|
|
g_value_take_string (&val, header_name);
|
|
g_value_array_append (array, &val);
|
|
g_value_take_string (&val, header_value);
|
|
g_value_array_append (array, &val);
|
|
}
|
|
/* search the column starting from line[1] as an header name can't be
|
|
* empty */
|
|
column = g_strstr_len (line + 1, strlen (line) - 1, ":");
|
|
if (column == NULL)
|
|
/* bad syntax */
|
|
goto fail;
|
|
|
|
if (*(space = column + 1) != ' ')
|
|
/* bad syntax */
|
|
goto fail;
|
|
|
|
header_name = g_strndup (line, column - line);
|
|
header_value = g_strdup (space + 1);
|
|
}
|
|
|
|
line = lines[++i];
|
|
}
|
|
|
|
if (header_name) {
|
|
g_value_take_string (&val, header_name);
|
|
g_value_array_append (array, &val);
|
|
g_value_take_string (&val, header_value);
|
|
g_value_array_append (array, &val);
|
|
}
|
|
|
|
g_value_unset (&val);
|
|
g_strfreev (lines);
|
|
|
|
return array;
|
|
|
|
fail:
|
|
GST_WARNING ("could not parse annodex headers");
|
|
g_free (header_name);
|
|
g_free (header_value);
|
|
g_strfreev (lines);
|
|
g_value_array_free (array);
|
|
g_value_unset (&val);
|
|
return NULL;
|
|
}
|
|
|
|
static gboolean
|
|
plugin_init (GstPlugin * plugin)
|
|
{
|
|
gst_tag_register (GST_TAG_CMML_STREAM, GST_TAG_FLAG_META,
|
|
GST_TYPE_CMML_TAG_STREAM, "cmml-stream", "annodex CMML stream tag", NULL);
|
|
|
|
gst_tag_register (GST_TAG_CMML_HEAD, GST_TAG_FLAG_META,
|
|
GST_TYPE_CMML_TAG_HEAD, "cmml-head", "annodex CMML head tag", NULL);
|
|
|
|
gst_tag_register (GST_TAG_CMML_CLIP, GST_TAG_FLAG_META,
|
|
GST_TYPE_CMML_TAG_CLIP, "cmml-clip", "annodex CMML clip tag", NULL);
|
|
|
|
gst_cmml_parser_init ();
|
|
|
|
if (!gst_cmml_enc_plugin_init (plugin))
|
|
return FALSE;
|
|
|
|
if (!gst_cmml_dec_plugin_init (plugin))
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
GST_VERSION_MINOR,
|
|
"annodex",
|
|
"annodex stream manipulation (info about annodex: http://www.annodex.net)",
|
|
plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
|