2006-11-10 18:51:10 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000 Wim Taymans <wtay@chello.be>
|
|
|
|
* 2006 Wim Taymans <wim@fluendo.com>
|
|
|
|
* 2006 David A. Schleef <ds@schleef.org>
|
2011-09-23 16:49:05 +00:00
|
|
|
* 2011 Collabora Ltd. <tim.muller@collabora.co.uk>
|
2015-04-02 12:35:18 +00:00
|
|
|
* 2015 Tim-Philipp Müller <tim@centricular.com>
|
2006-11-10 18:51:10 +00:00
|
|
|
*
|
|
|
|
* gstmultifilesink.c:
|
|
|
|
*
|
|
|
|
* 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
|
2012-11-04 00:07:18 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2006-11-10 18:51:10 +00:00
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* SECTION:element-multifilesink
|
2018-10-22 09:39:24 +00:00
|
|
|
* @title: multifilesink
|
2006-11-10 18:51:10 +00:00
|
|
|
* @see_also: #GstFileSrc
|
|
|
|
*
|
2007-10-25 23:42:52 +00:00
|
|
|
* Write incoming data to a series of sequentially-named files.
|
2009-09-11 10:16:18 +00:00
|
|
|
*
|
2015-04-02 12:26:41 +00:00
|
|
|
* This element is usually used with data where each buffer is an
|
|
|
|
* independent unit of data in its own right (e.g. raw video buffers or
|
|
|
|
* encoded JPEG or PNG images) or with streamable container formats such
|
|
|
|
* as MPEG-TS or MPEG-PS.
|
|
|
|
*
|
|
|
|
* It is not possible to use this element to create independently playable
|
|
|
|
* mp4 files, use the splitmuxsink element for that instead.
|
|
|
|
*
|
2010-04-08 15:05:46 +00:00
|
|
|
* The filename property should contain a string with a \%d placeholder that will
|
2009-09-11 10:16:18 +00:00
|
|
|
* be substituted with the index for each filename.
|
|
|
|
*
|
2017-10-03 23:30:10 +00:00
|
|
|
* If the #GstMultiFileSink:post-messages property is %TRUE, it sends an application
|
2018-10-22 09:39:24 +00:00
|
|
|
* message named `GstMultiFileSink` after writing each buffer.
|
2009-09-11 10:16:18 +00:00
|
|
|
*
|
|
|
|
* The message's structure contains these fields:
|
|
|
|
*
|
2019-06-14 21:34:31 +00:00
|
|
|
* * #gchararray `filename`: the filename where the buffer was written.
|
2018-10-22 09:39:24 +00:00
|
|
|
* * #gint `index`: index of the buffer.
|
|
|
|
* * #GstClockTime `timestamp`: the timestamp of the buffer.
|
|
|
|
* * #GstClockTime `stream-time`: the stream time of the buffer.
|
|
|
|
* * #GstClockTime running-time`: the running_time of the buffer.
|
|
|
|
* * #GstClockTime `duration`: the duration of the buffer.
|
|
|
|
* * #guint64 `offset`: the offset of the buffer that triggered the message.
|
|
|
|
* * #guint64 `offset-end`: the offset-end of the buffer that triggered the message.
|
|
|
|
*
|
|
|
|
* ## Example launch line
|
2009-09-11 10:16:18 +00:00
|
|
|
* |[
|
2012-08-26 21:39:55 +00:00
|
|
|
* gst-launch-1.0 audiotestsrc ! multifilesink
|
2017-05-20 10:40:33 +00:00
|
|
|
* gst-launch-1.0 videotestsrc ! multifilesink post-messages=true location="frame%d"
|
2009-09-11 10:16:18 +00:00
|
|
|
* ]|
|
2018-10-22 09:39:24 +00:00
|
|
|
*
|
2006-11-10 18:51:10 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2009-09-11 10:16:18 +00:00
|
|
|
#include <gst/base/gstbasetransform.h>
|
2011-07-17 21:56:04 +00:00
|
|
|
#include <gst/video/video.h>
|
2009-09-13 19:30:34 +00:00
|
|
|
#include <glib/gstdio.h>
|
2007-07-03 08:01:18 +00:00
|
|
|
#include "gstmultifilesink.h"
|
2006-11-10 18:51:10 +00:00
|
|
|
|
|
|
|
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS_ANY);
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_multi_file_sink_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_multi_file_sink_debug
|
|
|
|
|
2009-09-11 10:16:18 +00:00
|
|
|
#define DEFAULT_LOCATION "%05d"
|
|
|
|
#define DEFAULT_INDEX 0
|
2009-09-11 11:12:54 +00:00
|
|
|
#define DEFAULT_POST_MESSAGES FALSE
|
2009-09-13 19:30:34 +00:00
|
|
|
#define DEFAULT_NEXT_FILE GST_MULTI_FILE_SINK_NEXT_BUFFER
|
2011-07-18 07:38:26 +00:00
|
|
|
#define DEFAULT_MAX_FILES 0
|
2011-09-23 16:49:05 +00:00
|
|
|
#define DEFAULT_MAX_FILE_SIZE G_GUINT64_CONSTANT(2*1024*1024*1024)
|
2015-04-20 08:07:30 +00:00
|
|
|
#define DEFAULT_MAX_FILE_DURATION GST_CLOCK_TIME_NONE
|
2015-04-02 12:35:18 +00:00
|
|
|
#define DEFAULT_AGGREGATE_GOPS FALSE
|
2021-11-02 14:46:08 +00:00
|
|
|
#define DEFAULT_MIN_KEYFRAME_DISTANCE (10 * GST_SECOND)
|
2009-09-11 10:16:18 +00:00
|
|
|
|
2006-11-10 18:51:10 +00:00
|
|
|
enum
|
|
|
|
{
|
2009-09-11 10:16:18 +00:00
|
|
|
PROP_0,
|
|
|
|
PROP_LOCATION,
|
|
|
|
PROP_INDEX,
|
2009-09-11 11:12:54 +00:00
|
|
|
PROP_POST_MESSAGES,
|
2009-09-13 19:30:34 +00:00
|
|
|
PROP_NEXT_FILE,
|
2011-07-18 07:38:26 +00:00
|
|
|
PROP_MAX_FILES,
|
2015-04-02 12:35:18 +00:00
|
|
|
PROP_MAX_FILE_SIZE,
|
2015-04-20 08:07:30 +00:00
|
|
|
PROP_MAX_FILE_DURATION,
|
2021-11-02 14:46:08 +00:00
|
|
|
PROP_AGGREGATE_GOPS,
|
|
|
|
PROP_MIN_KEYFRAME_DISTANCE
|
2006-11-10 18:51:10 +00:00
|
|
|
};
|
|
|
|
|
2009-09-11 10:16:18 +00:00
|
|
|
static void gst_multi_file_sink_finalize (GObject * object);
|
2006-11-10 18:51:10 +00:00
|
|
|
|
|
|
|
static void gst_multi_file_sink_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_multi_file_sink_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
|
2015-04-02 12:35:18 +00:00
|
|
|
static gboolean gst_multi_file_sink_start (GstBaseSink * bsink);
|
2009-09-13 19:30:34 +00:00
|
|
|
static gboolean gst_multi_file_sink_stop (GstBaseSink * sink);
|
2006-11-10 18:51:10 +00:00
|
|
|
static GstFlowReturn gst_multi_file_sink_render (GstBaseSink * sink,
|
|
|
|
GstBuffer * buffer);
|
2011-09-25 13:57:56 +00:00
|
|
|
static GstFlowReturn gst_multi_file_sink_render_list (GstBaseSink * sink,
|
|
|
|
GstBufferList * buffer_list);
|
2011-01-03 03:19:27 +00:00
|
|
|
static gboolean gst_multi_file_sink_set_caps (GstBaseSink * sink,
|
|
|
|
GstCaps * caps);
|
2011-07-17 21:36:55 +00:00
|
|
|
static gboolean gst_multi_file_sink_open_next_file (GstMultiFileSink *
|
|
|
|
multifilesink);
|
|
|
|
static void gst_multi_file_sink_close_file (GstMultiFileSink * multifilesink,
|
|
|
|
GstBuffer * buffer);
|
2016-12-31 09:52:25 +00:00
|
|
|
static void gst_multi_file_sink_add_old_file (GstMultiFileSink * multifilesink,
|
|
|
|
gchar * fn);
|
2011-07-18 07:38:26 +00:00
|
|
|
static void gst_multi_file_sink_ensure_max_files (GstMultiFileSink *
|
|
|
|
multifilesink);
|
2011-07-17 21:56:04 +00:00
|
|
|
static gboolean gst_multi_file_sink_event (GstBaseSink * sink,
|
|
|
|
GstEvent * event);
|
2006-11-10 18:51:10 +00:00
|
|
|
|
2009-09-13 19:30:34 +00:00
|
|
|
#define GST_TYPE_MULTI_FILE_SINK_NEXT (gst_multi_file_sink_next_get_type ())
|
|
|
|
static GType
|
|
|
|
gst_multi_file_sink_next_get_type (void)
|
|
|
|
{
|
2015-11-20 12:44:22 +00:00
|
|
|
static GType multi_file_sink_next_type = 0;
|
2009-09-13 19:30:34 +00:00
|
|
|
static const GEnumValue next_types[] = {
|
|
|
|
{GST_MULTI_FILE_SINK_NEXT_BUFFER, "New file for each buffer", "buffer"},
|
|
|
|
{GST_MULTI_FILE_SINK_NEXT_DISCONT, "New file after each discontinuity",
|
|
|
|
"discont"},
|
2010-02-24 03:48:10 +00:00
|
|
|
{GST_MULTI_FILE_SINK_NEXT_KEY_FRAME, "New file at each key frame "
|
|
|
|
"(Useful for MPEG-TS segmenting)", "key-frame"},
|
2011-07-17 21:56:04 +00:00
|
|
|
{GST_MULTI_FILE_SINK_NEXT_KEY_UNIT_EVENT,
|
|
|
|
"New file after a force key unit event", "key-unit-event"},
|
2011-09-23 17:31:01 +00:00
|
|
|
{GST_MULTI_FILE_SINK_NEXT_MAX_SIZE, "New file when the configured maximum "
|
|
|
|
"file size would be exceeded with the next buffer or buffer list",
|
|
|
|
"max-size"},
|
2015-04-20 08:07:30 +00:00
|
|
|
{GST_MULTI_FILE_SINK_NEXT_MAX_DURATION,
|
|
|
|
"New file when the configured maximum "
|
|
|
|
"file duration would be exceeded with the next buffer or buffer list",
|
|
|
|
"max-duration"},
|
2009-09-13 19:30:34 +00:00
|
|
|
{0, NULL, NULL}
|
|
|
|
};
|
|
|
|
|
2015-11-20 12:44:22 +00:00
|
|
|
if (!multi_file_sink_next_type) {
|
|
|
|
multi_file_sink_next_type =
|
2009-09-13 19:30:34 +00:00
|
|
|
g_enum_register_static ("GstMultiFileSinkNext", next_types);
|
|
|
|
}
|
|
|
|
|
2015-11-20 12:44:22 +00:00
|
|
|
return multi_file_sink_next_type;
|
2009-09-13 19:30:34 +00:00
|
|
|
}
|
|
|
|
|
2011-06-30 10:30:22 +00:00
|
|
|
#define gst_multi_file_sink_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE (GstMultiFileSink, gst_multi_file_sink, GST_TYPE_BASE_SINK);
|
2021-02-16 11:04:26 +00:00
|
|
|
GST_ELEMENT_REGISTER_DEFINE (multifilesink, "multifilesink", GST_RANK_NONE,
|
|
|
|
gst_multi_file_sink_get_type ());
|
2006-11-10 18:51:10 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_multi_file_sink_class_init (GstMultiFileSinkClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
2011-06-30 10:30:22 +00:00
|
|
|
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
|
2006-11-10 18:51:10 +00:00
|
|
|
GstBaseSinkClass *gstbasesink_class = GST_BASE_SINK_CLASS (klass);
|
|
|
|
|
|
|
|
gobject_class->set_property = gst_multi_file_sink_set_property;
|
|
|
|
gobject_class->get_property = gst_multi_file_sink_get_property;
|
|
|
|
|
2009-09-11 10:16:18 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_LOCATION,
|
2006-11-10 18:51:10 +00:00
|
|
|
g_param_spec_string ("location", "File Location",
|
2010-10-13 14:21:23 +00:00
|
|
|
"Location of the file to write", NULL,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-09-11 10:16:18 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_INDEX,
|
2007-10-25 23:42:52 +00:00
|
|
|
g_param_spec_int ("index", "Index",
|
|
|
|
"Index to use with location property to create file names. The "
|
2009-09-11 10:16:18 +00:00
|
|
|
"index is incremented by one for each buffer written.",
|
2010-10-13 14:21:23 +00:00
|
|
|
0, G_MAXINT, DEFAULT_INDEX,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-09-11 10:16:18 +00:00
|
|
|
/**
|
2013-11-18 14:44:36 +00:00
|
|
|
* GstMultiFileSink:post-messages:
|
2009-09-11 10:16:18 +00:00
|
|
|
*
|
|
|
|
* Post a message on the GstBus for each file.
|
|
|
|
*/
|
2009-09-11 11:12:54 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_POST_MESSAGES,
|
|
|
|
g_param_spec_boolean ("post-messages", "Post Messages",
|
|
|
|
"Post a message for each file with information of the buffer",
|
2010-10-13 14:21:23 +00:00
|
|
|
DEFAULT_POST_MESSAGES, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-09-13 19:30:34 +00:00
|
|
|
/**
|
2013-11-18 14:44:36 +00:00
|
|
|
* GstMultiFileSink:next-file:
|
2009-09-13 19:30:34 +00:00
|
|
|
*
|
|
|
|
* When to start a new file.
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_NEXT_FILE,
|
|
|
|
g_param_spec_enum ("next-file", "Next File",
|
|
|
|
"When to start a new file",
|
|
|
|
GST_TYPE_MULTI_FILE_SINK_NEXT, DEFAULT_NEXT_FILE,
|
2014-09-11 09:16:09 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-09-11 10:16:18 +00:00
|
|
|
|
2011-07-18 07:38:26 +00:00
|
|
|
|
|
|
|
/**
|
2013-11-18 14:44:36 +00:00
|
|
|
* GstMultiFileSink:max-files:
|
2011-07-18 07:38:26 +00:00
|
|
|
*
|
|
|
|
* Maximum number of files to keep on disk. Once the maximum is reached, old
|
|
|
|
* files start to be deleted to make room for new ones.
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_MAX_FILES,
|
|
|
|
g_param_spec_uint ("max-files", "Max files",
|
|
|
|
"Maximum number of files to keep on disk. Once the maximum is reached,"
|
|
|
|
"old files start to be deleted to make room for new ones.",
|
|
|
|
0, G_MAXUINT, DEFAULT_MAX_FILES,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2011-09-23 16:49:05 +00:00
|
|
|
/**
|
2013-11-18 14:44:36 +00:00
|
|
|
* GstMultiFileSink:max-file-size:
|
2011-09-23 16:49:05 +00:00
|
|
|
*
|
|
|
|
* Maximum file size before starting a new file in max-size mode.
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_MAX_FILE_SIZE,
|
|
|
|
g_param_spec_uint64 ("max-file-size", "Maximum File Size",
|
|
|
|
"Maximum file size before starting a new file in max-size mode",
|
|
|
|
0, G_MAXUINT64, DEFAULT_MAX_FILE_SIZE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2015-04-20 08:07:30 +00:00
|
|
|
/**
|
|
|
|
* GstMultiFileSink:max-file-duration:
|
|
|
|
*
|
|
|
|
* Maximum file size before starting a new file in max-size mode.
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_MAX_FILE_DURATION,
|
|
|
|
g_param_spec_uint64 ("max-file-duration", "Maximum File Duration",
|
2019-05-22 02:01:17 +00:00
|
|
|
"Maximum file duration before starting a new file in max-duration mode "
|
2018-01-16 13:19:29 +00:00
|
|
|
"(in nanoseconds)", 0, G_MAXUINT64, DEFAULT_MAX_FILE_DURATION,
|
2015-04-20 08:07:30 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2015-04-02 12:35:18 +00:00
|
|
|
/**
|
|
|
|
* GstMultiFileSink:aggregate-gops:
|
|
|
|
*
|
|
|
|
* Whether to aggregate complete GOPs before doing any processing. Set this
|
|
|
|
* to TRUE to make sure each new file starts with a keyframe. This requires
|
|
|
|
* the upstream element to flag buffers containing key units and delta
|
|
|
|
* units correctly. At least the MPEG-PS and MPEG-TS muxers should be doing
|
|
|
|
* this.
|
|
|
|
*
|
|
|
|
* Since: 1.6
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_AGGREGATE_GOPS,
|
|
|
|
g_param_spec_boolean ("aggregate-gops", "Aggregate GOPs",
|
|
|
|
"Whether to aggregate GOPs and process them as a whole without "
|
|
|
|
"splitting", DEFAULT_AGGREGATE_GOPS,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2021-11-02 14:46:08 +00:00
|
|
|
/**
|
|
|
|
* GstMultiFileSink:min-keyframe-distance:
|
|
|
|
*
|
|
|
|
* Minimum distance between keyframes in `next-file=key-frame` that causes a
|
|
|
|
* new file to be created. If two keyframes arrive closer to each other they
|
|
|
|
* will end up in the same file.
|
|
|
|
*
|
|
|
|
* Since: 1.20
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_MIN_KEYFRAME_DISTANCE,
|
|
|
|
g_param_spec_uint64 ("min-keyframe-distance", "Minimum Keyframe Distance",
|
|
|
|
"Minimum distance between keyframes to start a new file", 0,
|
|
|
|
G_MAXUINT64, DEFAULT_MIN_KEYFRAME_DISTANCE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2009-09-11 10:16:18 +00:00
|
|
|
gobject_class->finalize = gst_multi_file_sink_finalize;
|
2006-11-10 18:51:10 +00:00
|
|
|
|
2015-04-02 12:35:18 +00:00
|
|
|
gstbasesink_class->start = GST_DEBUG_FUNCPTR (gst_multi_file_sink_start);
|
2009-09-13 19:30:34 +00:00
|
|
|
gstbasesink_class->stop = GST_DEBUG_FUNCPTR (gst_multi_file_sink_stop);
|
2006-11-10 18:51:10 +00:00
|
|
|
gstbasesink_class->render = GST_DEBUG_FUNCPTR (gst_multi_file_sink_render);
|
2011-09-25 13:57:56 +00:00
|
|
|
gstbasesink_class->render_list =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_multi_file_sink_render_list);
|
2011-01-03 03:19:27 +00:00
|
|
|
gstbasesink_class->set_caps =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_multi_file_sink_set_caps);
|
2011-07-17 21:56:04 +00:00
|
|
|
gstbasesink_class->event = GST_DEBUG_FUNCPTR (gst_multi_file_sink_event);
|
2011-06-30 10:30:22 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_multi_file_sink_debug, "multifilesink", 0,
|
|
|
|
"multifilesink element");
|
|
|
|
|
2016-03-04 01:30:12 +00:00
|
|
|
gst_element_class_add_static_pad_template (gstelement_class, &sinktemplate);
|
2012-04-09 23:51:41 +00:00
|
|
|
gst_element_class_set_static_metadata (gstelement_class, "Multi-File Sink",
|
2011-06-30 10:30:22 +00:00
|
|
|
"Sink/File",
|
|
|
|
"Write buffers to a sequentially named set of files",
|
|
|
|
"David Schleef <ds@schleef.org>");
|
2020-05-29 23:29:03 +00:00
|
|
|
|
2020-06-05 22:42:25 +00:00
|
|
|
gst_type_mark_as_plugin_api (GST_TYPE_MULTI_FILE_SINK_NEXT, 0);
|
2006-11-10 18:51:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-30 10:30:22 +00:00
|
|
|
gst_multi_file_sink_init (GstMultiFileSink * multifilesink)
|
2006-11-10 18:51:10 +00:00
|
|
|
{
|
2007-10-25 23:42:52 +00:00
|
|
|
multifilesink->filename = g_strdup (DEFAULT_LOCATION);
|
|
|
|
multifilesink->index = DEFAULT_INDEX;
|
2009-09-11 11:12:54 +00:00
|
|
|
multifilesink->post_messages = DEFAULT_POST_MESSAGES;
|
2011-07-18 07:38:26 +00:00
|
|
|
multifilesink->max_files = DEFAULT_MAX_FILES;
|
2011-09-23 16:49:05 +00:00
|
|
|
multifilesink->max_file_size = DEFAULT_MAX_FILE_SIZE;
|
2015-04-20 08:07:30 +00:00
|
|
|
multifilesink->max_file_duration = DEFAULT_MAX_FILE_DURATION;
|
2021-11-02 14:46:08 +00:00
|
|
|
multifilesink->min_keyframe_distance = DEFAULT_MIN_KEYFRAME_DISTANCE;
|
2006-11-10 18:51:10 +00:00
|
|
|
|
2015-04-02 12:35:18 +00:00
|
|
|
multifilesink->aggregate_gops = DEFAULT_AGGREGATE_GOPS;
|
|
|
|
multifilesink->gop_adapter = NULL;
|
|
|
|
|
2009-09-11 10:16:18 +00:00
|
|
|
gst_base_sink_set_sync (GST_BASE_SINK (multifilesink), FALSE);
|
2010-02-24 03:48:10 +00:00
|
|
|
|
|
|
|
multifilesink->next_segment = GST_CLOCK_TIME_NONE;
|
2011-07-17 21:56:04 +00:00
|
|
|
multifilesink->force_key_unit_count = -1;
|
2006-11-10 18:51:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-09-11 10:16:18 +00:00
|
|
|
gst_multi_file_sink_finalize (GObject * object)
|
2006-11-10 18:51:10 +00:00
|
|
|
{
|
|
|
|
GstMultiFileSink *sink = GST_MULTI_FILE_SINK (object);
|
|
|
|
|
|
|
|
g_free (sink->filename);
|
2007-09-24 10:53:36 +00:00
|
|
|
|
2009-09-11 10:16:18 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2006-11-10 18:51:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_multi_file_sink_set_location (GstMultiFileSink * sink,
|
|
|
|
const gchar * location)
|
|
|
|
{
|
|
|
|
g_free (sink->filename);
|
2009-09-11 10:16:18 +00:00
|
|
|
/* FIXME: validate location to have just one %d */
|
|
|
|
sink->filename = g_strdup (location);
|
2006-11-10 18:51:10 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2009-01-28 10:29:42 +00:00
|
|
|
|
2006-11-10 18:51:10 +00:00
|
|
|
static void
|
|
|
|
gst_multi_file_sink_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstMultiFileSink *sink = GST_MULTI_FILE_SINK (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2009-09-11 10:16:18 +00:00
|
|
|
case PROP_LOCATION:
|
2006-11-10 18:51:10 +00:00
|
|
|
gst_multi_file_sink_set_location (sink, g_value_get_string (value));
|
|
|
|
break;
|
2009-09-11 10:16:18 +00:00
|
|
|
case PROP_INDEX:
|
2007-10-25 23:42:52 +00:00
|
|
|
sink->index = g_value_get_int (value);
|
|
|
|
break;
|
2009-09-11 11:12:54 +00:00
|
|
|
case PROP_POST_MESSAGES:
|
|
|
|
sink->post_messages = g_value_get_boolean (value);
|
2009-09-11 10:16:18 +00:00
|
|
|
break;
|
2009-09-13 19:30:34 +00:00
|
|
|
case PROP_NEXT_FILE:
|
|
|
|
sink->next_file = g_value_get_enum (value);
|
|
|
|
break;
|
2011-07-18 07:38:26 +00:00
|
|
|
case PROP_MAX_FILES:
|
|
|
|
sink->max_files = g_value_get_uint (value);
|
|
|
|
break;
|
2011-09-23 16:49:05 +00:00
|
|
|
case PROP_MAX_FILE_SIZE:
|
|
|
|
sink->max_file_size = g_value_get_uint64 (value);
|
|
|
|
break;
|
2015-04-20 08:07:30 +00:00
|
|
|
case PROP_MAX_FILE_DURATION:
|
|
|
|
sink->max_file_duration = g_value_get_uint64 (value);
|
|
|
|
break;
|
2015-04-02 12:35:18 +00:00
|
|
|
case PROP_AGGREGATE_GOPS:
|
|
|
|
sink->aggregate_gops = g_value_get_boolean (value);
|
|
|
|
break;
|
2021-11-02 14:46:08 +00:00
|
|
|
case PROP_MIN_KEYFRAME_DISTANCE:
|
|
|
|
sink->min_keyframe_distance = g_value_get_uint64 (value);
|
|
|
|
break;
|
2006-11-10 18:51:10 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_multi_file_sink_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstMultiFileSink *sink = GST_MULTI_FILE_SINK (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2009-09-11 10:16:18 +00:00
|
|
|
case PROP_LOCATION:
|
2006-11-10 18:51:10 +00:00
|
|
|
g_value_set_string (value, sink->filename);
|
|
|
|
break;
|
2009-09-11 10:16:18 +00:00
|
|
|
case PROP_INDEX:
|
2007-10-25 23:42:52 +00:00
|
|
|
g_value_set_int (value, sink->index);
|
|
|
|
break;
|
2009-09-11 11:12:54 +00:00
|
|
|
case PROP_POST_MESSAGES:
|
|
|
|
g_value_set_boolean (value, sink->post_messages);
|
2009-09-11 10:16:18 +00:00
|
|
|
break;
|
2009-09-13 19:30:34 +00:00
|
|
|
case PROP_NEXT_FILE:
|
|
|
|
g_value_set_enum (value, sink->next_file);
|
|
|
|
break;
|
2011-07-18 07:38:26 +00:00
|
|
|
case PROP_MAX_FILES:
|
|
|
|
g_value_set_uint (value, sink->max_files);
|
|
|
|
break;
|
2011-09-23 16:49:05 +00:00
|
|
|
case PROP_MAX_FILE_SIZE:
|
|
|
|
g_value_set_uint64 (value, sink->max_file_size);
|
|
|
|
break;
|
2015-04-20 08:07:30 +00:00
|
|
|
case PROP_MAX_FILE_DURATION:
|
|
|
|
g_value_set_uint64 (value, sink->max_file_duration);
|
|
|
|
break;
|
2015-04-02 12:35:18 +00:00
|
|
|
case PROP_AGGREGATE_GOPS:
|
|
|
|
g_value_set_boolean (value, sink->aggregate_gops);
|
|
|
|
break;
|
2021-11-02 14:46:08 +00:00
|
|
|
case PROP_MIN_KEYFRAME_DISTANCE:
|
|
|
|
g_value_set_uint64 (value, sink->min_keyframe_distance);
|
|
|
|
break;
|
2006-11-10 18:51:10 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-02 12:35:18 +00:00
|
|
|
static gboolean
|
|
|
|
gst_multi_file_sink_start (GstBaseSink * bsink)
|
|
|
|
{
|
|
|
|
GstMultiFileSink *sink = GST_MULTI_FILE_SINK (bsink);
|
|
|
|
|
|
|
|
if (sink->aggregate_gops)
|
|
|
|
sink->gop_adapter = gst_adapter_new ();
|
|
|
|
sink->potential_next_gop = NULL;
|
2015-04-20 08:07:30 +00:00
|
|
|
sink->file_pts = GST_CLOCK_TIME_NONE;
|
2015-04-02 12:35:18 +00:00
|
|
|
|
2016-12-31 09:52:25 +00:00
|
|
|
g_queue_init (&sink->old_files);
|
|
|
|
|
2015-04-02 12:35:18 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-09-13 19:30:34 +00:00
|
|
|
static gboolean
|
|
|
|
gst_multi_file_sink_stop (GstBaseSink * sink)
|
2006-11-10 18:51:10 +00:00
|
|
|
{
|
2007-10-25 23:42:52 +00:00
|
|
|
GstMultiFileSink *multifilesink;
|
2011-01-03 03:19:27 +00:00
|
|
|
int i;
|
2006-11-10 18:51:10 +00:00
|
|
|
|
2007-10-25 23:42:52 +00:00
|
|
|
multifilesink = GST_MULTI_FILE_SINK (sink);
|
2006-11-10 18:51:10 +00:00
|
|
|
|
2009-09-13 19:30:34 +00:00
|
|
|
if (multifilesink->file != NULL) {
|
|
|
|
fclose (multifilesink->file);
|
|
|
|
multifilesink->file = NULL;
|
|
|
|
}
|
2009-09-11 10:16:18 +00:00
|
|
|
|
2011-01-03 03:19:27 +00:00
|
|
|
if (multifilesink->streamheaders) {
|
|
|
|
for (i = 0; i < multifilesink->n_streamheaders; i++) {
|
|
|
|
gst_buffer_unref (multifilesink->streamheaders[i]);
|
|
|
|
}
|
|
|
|
g_free (multifilesink->streamheaders);
|
2011-08-21 12:41:14 +00:00
|
|
|
multifilesink->streamheaders = NULL;
|
2011-01-03 03:19:27 +00:00
|
|
|
}
|
|
|
|
|
2015-04-02 12:35:18 +00:00
|
|
|
if (multifilesink->gop_adapter != NULL) {
|
|
|
|
g_object_unref (multifilesink->gop_adapter);
|
|
|
|
multifilesink->gop_adapter = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (multifilesink->potential_next_gop != NULL) {
|
|
|
|
g_list_free_full (multifilesink->potential_next_gop,
|
|
|
|
(GDestroyNotify) gst_buffer_unref);
|
|
|
|
multifilesink->potential_next_gop = NULL;
|
|
|
|
}
|
|
|
|
|
2011-07-17 21:56:04 +00:00
|
|
|
multifilesink->force_key_unit_count = -1;
|
|
|
|
|
2016-12-31 09:52:25 +00:00
|
|
|
g_queue_foreach (&multifilesink->old_files, (GFunc) g_free, NULL);
|
|
|
|
g_queue_clear (&multifilesink->old_files);
|
|
|
|
|
2009-09-13 19:30:34 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2009-09-11 10:16:18 +00:00
|
|
|
|
2009-09-13 19:30:34 +00:00
|
|
|
|
2011-07-17 21:56:04 +00:00
|
|
|
static void
|
|
|
|
gst_multi_file_sink_post_message_full (GstMultiFileSink * multifilesink,
|
|
|
|
GstClockTime timestamp, GstClockTime duration, GstClockTime offset,
|
|
|
|
GstClockTime offset_end, GstClockTime running_time,
|
|
|
|
GstClockTime stream_time, const char *filename)
|
|
|
|
{
|
|
|
|
GstStructure *s;
|
|
|
|
|
|
|
|
if (!multifilesink->post_messages)
|
|
|
|
return;
|
|
|
|
|
|
|
|
s = gst_structure_new ("GstMultiFileSink",
|
|
|
|
"filename", G_TYPE_STRING, filename,
|
|
|
|
"index", G_TYPE_INT, multifilesink->index,
|
|
|
|
"timestamp", G_TYPE_UINT64, timestamp,
|
|
|
|
"stream-time", G_TYPE_UINT64, stream_time,
|
|
|
|
"running-time", G_TYPE_UINT64, running_time,
|
|
|
|
"duration", G_TYPE_UINT64, duration,
|
|
|
|
"offset", G_TYPE_UINT64, offset,
|
|
|
|
"offset-end", G_TYPE_UINT64, offset_end, NULL);
|
|
|
|
|
|
|
|
gst_element_post_message (GST_ELEMENT_CAST (multifilesink),
|
|
|
|
gst_message_new_element (GST_OBJECT_CAST (multifilesink), s));
|
|
|
|
}
|
|
|
|
|
2015-03-30 14:14:09 +00:00
|
|
|
static void
|
|
|
|
gst_multi_file_sink_post_message_from_time (GstMultiFileSink * multifilesink,
|
|
|
|
GstClockTime timestamp, GstClockTime duration, const char *filename)
|
|
|
|
{
|
|
|
|
GstClockTime running_time, stream_time;
|
|
|
|
guint64 offset, offset_end;
|
|
|
|
GstSegment *segment;
|
|
|
|
GstFormat format;
|
|
|
|
|
|
|
|
if (!multifilesink->post_messages)
|
|
|
|
return;
|
|
|
|
|
|
|
|
segment = &GST_BASE_SINK (multifilesink)->segment;
|
|
|
|
format = segment->format;
|
|
|
|
|
|
|
|
offset = -1;
|
|
|
|
offset_end = -1;
|
|
|
|
|
|
|
|
running_time = gst_segment_to_running_time (segment, format, timestamp);
|
|
|
|
stream_time = gst_segment_to_stream_time (segment, format, timestamp);
|
|
|
|
|
|
|
|
gst_multi_file_sink_post_message_full (multifilesink, timestamp, duration,
|
|
|
|
offset, offset_end, running_time, stream_time, filename);
|
|
|
|
}
|
2011-07-17 21:56:04 +00:00
|
|
|
|
2009-09-13 19:30:34 +00:00
|
|
|
static void
|
|
|
|
gst_multi_file_sink_post_message (GstMultiFileSink * multifilesink,
|
|
|
|
GstBuffer * buffer, const char *filename)
|
|
|
|
{
|
2011-07-17 21:56:04 +00:00
|
|
|
GstClockTime duration, timestamp;
|
|
|
|
GstClockTime running_time, stream_time;
|
|
|
|
guint64 offset, offset_end;
|
|
|
|
GstSegment *segment;
|
|
|
|
GstFormat format;
|
|
|
|
|
|
|
|
if (!multifilesink->post_messages)
|
|
|
|
return;
|
|
|
|
|
|
|
|
segment = &GST_BASE_SINK (multifilesink)->segment;
|
|
|
|
format = segment->format;
|
|
|
|
|
|
|
|
timestamp = GST_BUFFER_TIMESTAMP (buffer);
|
|
|
|
duration = GST_BUFFER_DURATION (buffer);
|
|
|
|
offset = GST_BUFFER_OFFSET (buffer);
|
|
|
|
offset_end = GST_BUFFER_OFFSET_END (buffer);
|
|
|
|
|
|
|
|
running_time = gst_segment_to_running_time (segment, format, timestamp);
|
|
|
|
stream_time = gst_segment_to_stream_time (segment, format, timestamp);
|
|
|
|
|
|
|
|
gst_multi_file_sink_post_message_full (multifilesink, timestamp, duration,
|
|
|
|
offset, offset_end, running_time, stream_time, filename);
|
2009-09-13 19:30:34 +00:00
|
|
|
}
|
2006-11-10 18:51:10 +00:00
|
|
|
|
2011-09-23 17:43:35 +00:00
|
|
|
static gboolean
|
|
|
|
gst_multi_file_sink_write_stream_headers (GstMultiFileSink * sink)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (sink->streamheaders == NULL)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* we want to write these at the beginning */
|
|
|
|
g_assert (sink->cur_file_size == 0);
|
|
|
|
|
|
|
|
for (i = 0; i < sink->n_streamheaders; i++) {
|
|
|
|
GstBuffer *hdr;
|
2012-01-23 16:25:37 +00:00
|
|
|
GstMapInfo map;
|
2011-09-23 17:43:35 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
hdr = sink->streamheaders[i];
|
2012-01-23 16:25:37 +00:00
|
|
|
gst_buffer_map (hdr, &map, GST_MAP_READ);
|
|
|
|
ret = fwrite (map.data, map.size, 1, sink->file);
|
|
|
|
gst_buffer_unmap (hdr, &map);
|
2011-09-23 17:43:35 +00:00
|
|
|
|
|
|
|
if (ret != 1)
|
|
|
|
return FALSE;
|
|
|
|
|
2012-01-23 16:25:37 +00:00
|
|
|
sink->cur_file_size += map.size;
|
2006-11-10 18:51:10 +00:00
|
|
|
}
|
2011-09-23 17:43:35 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2009-09-13 19:30:34 +00:00
|
|
|
}
|
2006-11-10 18:51:10 +00:00
|
|
|
|
2009-09-13 19:30:34 +00:00
|
|
|
static GstFlowReturn
|
2015-04-02 12:35:18 +00:00
|
|
|
gst_multi_file_sink_write_buffer (GstMultiFileSink * multifilesink,
|
|
|
|
GstBuffer * buffer)
|
2009-09-13 19:30:34 +00:00
|
|
|
{
|
2012-01-23 16:25:37 +00:00
|
|
|
GstMapInfo map;
|
2016-09-27 09:23:38 +00:00
|
|
|
gchar *filename;
|
2009-09-13 19:30:34 +00:00
|
|
|
gboolean ret;
|
2016-09-27 09:23:38 +00:00
|
|
|
GError *error = NULL;
|
2012-04-30 12:09:23 +00:00
|
|
|
gboolean first_file = TRUE;
|
2009-09-13 19:30:34 +00:00
|
|
|
|
2012-01-23 16:25:37 +00:00
|
|
|
gst_buffer_map (buffer, &map, GST_MAP_READ);
|
2009-09-13 19:30:34 +00:00
|
|
|
|
|
|
|
switch (multifilesink->next_file) {
|
|
|
|
case GST_MULTI_FILE_SINK_NEXT_BUFFER:
|
2016-09-27 09:23:38 +00:00
|
|
|
gst_multi_file_sink_ensure_max_files (multifilesink);
|
|
|
|
|
|
|
|
filename = g_strdup_printf (multifilesink->filename,
|
|
|
|
multifilesink->index);
|
|
|
|
ret = g_file_set_contents (filename, (char *) map.data, map.size, &error);
|
|
|
|
if (!ret)
|
|
|
|
goto write_error;
|
|
|
|
|
|
|
|
gst_multi_file_sink_post_message (multifilesink, buffer, filename);
|
2016-12-31 09:52:25 +00:00
|
|
|
|
|
|
|
gst_multi_file_sink_add_old_file (multifilesink, filename);
|
|
|
|
|
2016-09-27 09:23:38 +00:00
|
|
|
multifilesink->index++;
|
2009-09-13 19:30:34 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
case GST_MULTI_FILE_SINK_NEXT_DISCONT:
|
|
|
|
if (GST_BUFFER_IS_DISCONT (buffer)) {
|
2011-07-17 21:36:55 +00:00
|
|
|
if (multifilesink->file)
|
|
|
|
gst_multi_file_sink_close_file (multifilesink, buffer);
|
2009-09-13 19:30:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (multifilesink->file == NULL) {
|
2011-07-17 21:36:55 +00:00
|
|
|
if (!gst_multi_file_sink_open_next_file (multifilesink))
|
2010-02-24 03:48:10 +00:00
|
|
|
goto stdio_write_error;
|
|
|
|
}
|
|
|
|
|
2012-01-23 16:25:37 +00:00
|
|
|
ret = fwrite (map.data, map.size, 1, multifilesink->file);
|
2010-02-24 03:48:10 +00:00
|
|
|
if (ret != 1)
|
|
|
|
goto stdio_write_error;
|
|
|
|
|
|
|
|
break;
|
|
|
|
case GST_MULTI_FILE_SINK_NEXT_KEY_FRAME:
|
|
|
|
if (multifilesink->next_segment == GST_CLOCK_TIME_NONE) {
|
|
|
|
if (GST_BUFFER_TIMESTAMP_IS_VALID (buffer)) {
|
|
|
|
multifilesink->next_segment = GST_BUFFER_TIMESTAMP (buffer) +
|
2021-11-02 14:46:08 +00:00
|
|
|
multifilesink->min_keyframe_distance;
|
2010-02-24 03:48:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_BUFFER_TIMESTAMP_IS_VALID (buffer) &&
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer) >= multifilesink->next_segment &&
|
|
|
|
!GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT)) {
|
2012-04-30 12:09:23 +00:00
|
|
|
if (multifilesink->file) {
|
|
|
|
first_file = FALSE;
|
2011-07-17 21:36:55 +00:00
|
|
|
gst_multi_file_sink_close_file (multifilesink, buffer);
|
2012-04-30 12:09:23 +00:00
|
|
|
}
|
2021-11-02 14:46:08 +00:00
|
|
|
multifilesink->next_segment += multifilesink->min_keyframe_distance;
|
2010-02-24 03:48:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (multifilesink->file == NULL) {
|
2011-07-17 21:36:55 +00:00
|
|
|
if (!gst_multi_file_sink_open_next_file (multifilesink))
|
2009-09-13 19:30:34 +00:00
|
|
|
goto stdio_write_error;
|
2011-01-03 03:19:27 +00:00
|
|
|
|
2012-04-30 12:09:23 +00:00
|
|
|
if (!first_file)
|
|
|
|
gst_multi_file_sink_write_stream_headers (multifilesink);
|
2009-09-13 19:30:34 +00:00
|
|
|
}
|
|
|
|
|
2012-01-23 16:25:37 +00:00
|
|
|
ret = fwrite (map.data, map.size, 1, multifilesink->file);
|
2011-07-17 21:56:04 +00:00
|
|
|
if (ret != 1)
|
|
|
|
goto stdio_write_error;
|
|
|
|
|
|
|
|
break;
|
|
|
|
case GST_MULTI_FILE_SINK_NEXT_KEY_UNIT_EVENT:
|
|
|
|
if (multifilesink->file == NULL) {
|
2011-07-17 21:36:55 +00:00
|
|
|
if (!gst_multi_file_sink_open_next_file (multifilesink))
|
2009-09-13 19:30:34 +00:00
|
|
|
goto stdio_write_error;
|
2011-01-03 03:19:27 +00:00
|
|
|
|
2012-11-10 11:39:08 +00:00
|
|
|
/* we don't need to write stream headers here, they will be inserted in
|
|
|
|
* the stream by upstream elements if key unit events have
|
|
|
|
* all_headers=true set
|
|
|
|
*/
|
|
|
|
}
|
2011-12-02 01:58:30 +00:00
|
|
|
|
2012-01-23 16:25:37 +00:00
|
|
|
ret = fwrite (map.data, map.size, 1, multifilesink->file);
|
2011-12-02 01:58:30 +00:00
|
|
|
|
2009-09-13 19:30:34 +00:00
|
|
|
if (ret != 1)
|
|
|
|
goto stdio_write_error;
|
|
|
|
|
|
|
|
break;
|
2011-09-23 17:31:01 +00:00
|
|
|
case GST_MULTI_FILE_SINK_NEXT_MAX_SIZE:{
|
|
|
|
guint64 new_size;
|
|
|
|
|
2012-01-23 16:25:37 +00:00
|
|
|
new_size = multifilesink->cur_file_size + map.size;
|
2011-09-23 17:31:01 +00:00
|
|
|
if (new_size > multifilesink->max_file_size) {
|
|
|
|
|
|
|
|
GST_INFO_OBJECT (multifilesink, "current size: %" G_GUINT64_FORMAT
|
|
|
|
", new_size: %" G_GUINT64_FORMAT ", max. size %" G_GUINT64_FORMAT,
|
|
|
|
multifilesink->cur_file_size, new_size,
|
|
|
|
multifilesink->max_file_size);
|
|
|
|
|
2012-04-30 12:09:23 +00:00
|
|
|
if (multifilesink->file != NULL) {
|
|
|
|
first_file = FALSE;
|
2012-11-16 09:09:38 +00:00
|
|
|
gst_multi_file_sink_close_file (multifilesink, buffer);
|
2012-04-30 12:09:23 +00:00
|
|
|
}
|
2011-09-23 17:31:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (multifilesink->file == NULL) {
|
|
|
|
if (!gst_multi_file_sink_open_next_file (multifilesink))
|
|
|
|
goto stdio_write_error;
|
|
|
|
|
2012-04-30 12:09:23 +00:00
|
|
|
if (!first_file)
|
|
|
|
gst_multi_file_sink_write_stream_headers (multifilesink);
|
2009-09-13 19:30:34 +00:00
|
|
|
}
|
|
|
|
|
2012-01-23 16:25:37 +00:00
|
|
|
ret = fwrite (map.data, map.size, 1, multifilesink->file);
|
2011-09-23 17:31:01 +00:00
|
|
|
|
2009-09-13 19:30:34 +00:00
|
|
|
if (ret != 1)
|
|
|
|
goto stdio_write_error;
|
|
|
|
|
2012-01-23 16:25:37 +00:00
|
|
|
multifilesink->cur_file_size += map.size;
|
2009-09-13 19:30:34 +00:00
|
|
|
break;
|
2011-09-23 17:31:01 +00:00
|
|
|
}
|
2015-04-20 08:07:30 +00:00
|
|
|
case GST_MULTI_FILE_SINK_NEXT_MAX_DURATION:{
|
|
|
|
GstClockTime new_duration = 0;
|
|
|
|
|
|
|
|
if (GST_BUFFER_PTS_IS_VALID (buffer)
|
|
|
|
&& GST_CLOCK_TIME_IS_VALID (multifilesink->file_pts)) {
|
|
|
|
/* The new duration will extend to this new buffer pts ... */
|
|
|
|
new_duration = GST_BUFFER_PTS (buffer) - multifilesink->file_pts;
|
|
|
|
/* ... and duration (if it has one) */
|
|
|
|
if (GST_BUFFER_DURATION_IS_VALID (buffer))
|
|
|
|
new_duration += GST_BUFFER_DURATION (buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_duration > multifilesink->max_file_duration) {
|
|
|
|
|
|
|
|
GST_INFO_OBJECT (multifilesink,
|
|
|
|
"new_duration: %" G_GUINT64_FORMAT ", max. duration %"
|
|
|
|
G_GUINT64_FORMAT, new_duration, multifilesink->max_file_duration);
|
|
|
|
|
|
|
|
if (multifilesink->file != NULL) {
|
|
|
|
first_file = FALSE;
|
|
|
|
gst_multi_file_sink_close_file (multifilesink, buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (multifilesink->file == NULL) {
|
|
|
|
if (!gst_multi_file_sink_open_next_file (multifilesink))
|
|
|
|
goto stdio_write_error;
|
|
|
|
|
|
|
|
multifilesink->file_pts = GST_BUFFER_PTS (buffer);
|
|
|
|
if (!first_file)
|
|
|
|
gst_multi_file_sink_write_stream_headers (multifilesink);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = fwrite (map.data, map.size, 1, multifilesink->file);
|
|
|
|
|
|
|
|
if (ret != 1)
|
|
|
|
goto stdio_write_error;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2009-09-13 19:30:34 +00:00
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
2008-02-08 03:44:12 +00:00
|
|
|
|
2012-01-23 16:25:37 +00:00
|
|
|
gst_buffer_unmap (buffer, &map);
|
2009-09-11 10:16:18 +00:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
|
|
|
|
/* ERRORS */
|
2016-09-27 09:23:38 +00:00
|
|
|
write_error:
|
|
|
|
{
|
|
|
|
switch (error->code) {
|
|
|
|
case G_FILE_ERROR_NOSPC:{
|
|
|
|
GST_ELEMENT_ERROR (multifilesink, RESOURCE, NO_SPACE_LEFT, (NULL),
|
|
|
|
(NULL));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:{
|
|
|
|
GST_ELEMENT_ERROR (multifilesink, RESOURCE, WRITE,
|
|
|
|
("Error while writing to file \"%s\".", filename),
|
|
|
|
("%s", g_strerror (errno)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_error_free (error);
|
|
|
|
g_free (filename);
|
|
|
|
|
|
|
|
gst_buffer_unmap (buffer, &map);
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2009-09-13 19:30:34 +00:00
|
|
|
stdio_write_error:
|
2011-12-14 09:14:20 +00:00
|
|
|
switch (errno) {
|
|
|
|
case ENOSPC:
|
|
|
|
GST_ELEMENT_ERROR (multifilesink, RESOURCE, NO_SPACE_LEFT,
|
|
|
|
("Error while writing to file."), ("%s", g_strerror (errno)));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GST_ELEMENT_ERROR (multifilesink, RESOURCE, WRITE,
|
|
|
|
("Error while writing to file."), ("%s", g_strerror (errno)));
|
2011-06-30 10:30:22 +00:00
|
|
|
}
|
2012-01-23 16:25:37 +00:00
|
|
|
gst_buffer_unmap (buffer, &map);
|
2009-09-13 19:30:34 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2006-11-10 18:51:10 +00:00
|
|
|
}
|
2011-01-03 03:19:27 +00:00
|
|
|
|
2015-04-02 12:35:18 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_multi_file_sink_render (GstBaseSink * bsink, GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
GstMultiFileSink *sink = GST_MULTI_FILE_SINK (bsink);
|
|
|
|
GstFlowReturn flow = GST_FLOW_OK;
|
|
|
|
gboolean key_unit, header;
|
|
|
|
|
|
|
|
header = GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_HEADER);
|
|
|
|
key_unit = !GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT);
|
|
|
|
|
|
|
|
if (sink->aggregate_gops) {
|
|
|
|
GstBuffer *gop_buffer = NULL;
|
|
|
|
guint avail;
|
|
|
|
|
|
|
|
avail = gst_adapter_available (sink->gop_adapter);
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (sink, "aggregate GOP: received %s%s unit buffer: "
|
|
|
|
"%" GST_PTR_FORMAT,
|
|
|
|
(key_unit) ? "key" : "delta", (header) ? " header" : "", buffer);
|
|
|
|
|
|
|
|
/* If it's a header buffer, it might potentially be for the next GOP */
|
|
|
|
if (header) {
|
|
|
|
GST_LOG_OBJECT (sink, "Accumulating buffer to potential next GOP");
|
|
|
|
sink->potential_next_gop =
|
|
|
|
g_list_append (sink->potential_next_gop, gst_buffer_ref (buffer));
|
|
|
|
} else {
|
|
|
|
if (key_unit && avail > 0) {
|
2015-04-20 08:07:30 +00:00
|
|
|
GstClockTime pts, dts;
|
2015-04-02 12:35:18 +00:00
|
|
|
GST_LOG_OBJECT (sink, "Grabbing pending completed GOP");
|
2015-04-20 08:07:30 +00:00
|
|
|
pts = gst_adapter_prev_pts_at_offset (sink->gop_adapter, 0, NULL);
|
|
|
|
dts = gst_adapter_prev_dts_at_offset (sink->gop_adapter, 0, NULL);
|
2015-04-02 12:35:18 +00:00
|
|
|
gop_buffer = gst_adapter_take_buffer (sink->gop_adapter, avail);
|
2015-04-20 08:07:30 +00:00
|
|
|
GST_BUFFER_PTS (gop_buffer) = pts;
|
|
|
|
GST_BUFFER_DTS (gop_buffer) = dts;
|
2015-04-02 12:35:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* just accumulate the buffer */
|
|
|
|
if (sink->potential_next_gop) {
|
|
|
|
GList *tmp;
|
|
|
|
GST_LOG_OBJECT (sink,
|
|
|
|
"Carrying over pending next GOP data into adapter");
|
|
|
|
/* If we have pending data, put that first in the adapter */
|
|
|
|
for (tmp = sink->potential_next_gop; tmp; tmp = tmp->next) {
|
|
|
|
GstBuffer *tmpb = (GstBuffer *) tmp->data;
|
|
|
|
gst_adapter_push (sink->gop_adapter, tmpb);
|
|
|
|
}
|
|
|
|
g_list_free (sink->potential_next_gop);
|
|
|
|
sink->potential_next_gop = NULL;
|
|
|
|
}
|
|
|
|
GST_LOG_OBJECT (sink, "storing buffer in adapter");
|
|
|
|
gst_adapter_push (sink->gop_adapter, gst_buffer_ref (buffer));
|
|
|
|
|
|
|
|
if (gop_buffer != NULL) {
|
|
|
|
GST_DEBUG_OBJECT (sink, "writing out pending GOP, %u bytes", avail);
|
2015-04-20 08:07:30 +00:00
|
|
|
GST_DEBUG_OBJECT (sink,
|
|
|
|
"gop buffer pts:%" GST_TIME_FORMAT " dts:%" GST_TIME_FORMAT
|
|
|
|
" duration:%" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_PTS (gop_buffer)),
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_DTS (gop_buffer)),
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_DURATION (gop_buffer)));
|
2015-04-02 12:35:18 +00:00
|
|
|
flow = gst_multi_file_sink_write_buffer (sink, gop_buffer);
|
|
|
|
gst_buffer_unref (gop_buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
flow = gst_multi_file_sink_write_buffer (sink, buffer);
|
|
|
|
}
|
|
|
|
return flow;
|
|
|
|
}
|
|
|
|
|
2011-12-02 01:58:30 +00:00
|
|
|
static gboolean
|
|
|
|
buffer_list_copy_data (GstBuffer ** buf, guint idx, gpointer data)
|
2011-09-25 13:57:56 +00:00
|
|
|
{
|
|
|
|
GstBuffer *dest = data;
|
2011-12-02 01:58:30 +00:00
|
|
|
guint num, i;
|
|
|
|
|
|
|
|
if (idx == 0)
|
|
|
|
gst_buffer_copy_into (dest, *buf, GST_BUFFER_COPY_METADATA, 0, -1);
|
2011-09-25 13:57:56 +00:00
|
|
|
|
2011-12-02 01:58:30 +00:00
|
|
|
num = gst_buffer_n_memory (*buf);
|
|
|
|
for (i = 0; i < num; ++i) {
|
|
|
|
GstMemory *mem;
|
2011-09-25 13:57:56 +00:00
|
|
|
|
2012-02-13 16:13:17 +00:00
|
|
|
mem = gst_buffer_get_memory (*buf, i);
|
2012-03-30 16:13:08 +00:00
|
|
|
gst_buffer_append_memory (dest, mem);
|
2011-12-02 01:58:30 +00:00
|
|
|
}
|
2011-09-25 13:57:56 +00:00
|
|
|
|
2011-12-02 01:58:30 +00:00
|
|
|
return TRUE;
|
2011-09-25 13:57:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Our assumption for now is that the buffers in a buffer list should always
|
|
|
|
* end up in the same file. If someone wants different behaviour, they'll just
|
|
|
|
* have to add a property for that. */
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_multi_file_sink_render_list (GstBaseSink * sink, GstBufferList * list)
|
|
|
|
{
|
|
|
|
GstBuffer *buf;
|
2017-09-17 11:50:30 +00:00
|
|
|
guint size;
|
2011-09-25 13:57:56 +00:00
|
|
|
|
2017-09-17 11:50:30 +00:00
|
|
|
size = gst_buffer_list_calculate_size (list);
|
2011-09-25 13:57:56 +00:00
|
|
|
GST_LOG_OBJECT (sink, "total size of buffer list %p: %u", list, size);
|
|
|
|
|
|
|
|
/* copy all buffers in the list into one single buffer, so we can use
|
|
|
|
* the normal render function (FIXME: optimise to avoid the memcpy) */
|
2011-12-02 01:58:30 +00:00
|
|
|
buf = gst_buffer_new ();
|
2011-09-25 13:57:56 +00:00
|
|
|
gst_buffer_list_foreach (list, buffer_list_copy_data, buf);
|
2011-12-02 01:58:30 +00:00
|
|
|
g_assert (gst_buffer_get_size (buf) == size);
|
2011-09-25 13:57:56 +00:00
|
|
|
|
|
|
|
gst_multi_file_sink_render (sink, buf);
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
2011-01-03 03:19:27 +00:00
|
|
|
static gboolean
|
|
|
|
gst_multi_file_sink_set_caps (GstBaseSink * sink, GstCaps * caps)
|
|
|
|
{
|
|
|
|
GstMultiFileSink *multifilesink;
|
|
|
|
GstStructure *structure;
|
|
|
|
|
|
|
|
multifilesink = GST_MULTI_FILE_SINK (sink);
|
|
|
|
|
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
if (structure) {
|
|
|
|
const GValue *value;
|
|
|
|
|
|
|
|
value = gst_structure_get_value (structure, "streamheader");
|
|
|
|
|
|
|
|
if (GST_VALUE_HOLDS_ARRAY (value)) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (multifilesink->streamheaders) {
|
|
|
|
for (i = 0; i < multifilesink->n_streamheaders; i++) {
|
|
|
|
gst_buffer_unref (multifilesink->streamheaders[i]);
|
|
|
|
}
|
|
|
|
g_free (multifilesink->streamheaders);
|
|
|
|
}
|
|
|
|
|
|
|
|
multifilesink->n_streamheaders = gst_value_array_get_size (value);
|
|
|
|
multifilesink->streamheaders =
|
|
|
|
g_malloc (sizeof (GstBuffer *) * multifilesink->n_streamheaders);
|
|
|
|
|
|
|
|
for (i = 0; i < multifilesink->n_streamheaders; i++) {
|
|
|
|
multifilesink->streamheaders[i] =
|
|
|
|
gst_buffer_ref (gst_value_get_buffer (gst_value_array_get_value
|
|
|
|
(value, i)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2011-07-17 21:36:55 +00:00
|
|
|
|
2016-12-31 09:52:25 +00:00
|
|
|
/* Takes ownership of the filename string */
|
|
|
|
static void
|
|
|
|
gst_multi_file_sink_add_old_file (GstMultiFileSink * multifilesink, gchar * fn)
|
|
|
|
{
|
|
|
|
/* Only add file to the list if a max_files limit is set, otherwise we never
|
|
|
|
* prune the list and memory just builds up until the pipeline is stopped. */
|
|
|
|
if (multifilesink->max_files > 0) {
|
|
|
|
g_queue_push_tail (&multifilesink->old_files, fn);
|
|
|
|
} else {
|
|
|
|
g_free (fn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-18 07:38:26 +00:00
|
|
|
static void
|
|
|
|
gst_multi_file_sink_ensure_max_files (GstMultiFileSink * multifilesink)
|
|
|
|
{
|
2016-12-31 09:52:25 +00:00
|
|
|
guint max_files = multifilesink->max_files;
|
|
|
|
|
|
|
|
if (max_files == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (g_queue_get_length (&multifilesink->old_files) >= max_files) {
|
|
|
|
gchar *filename;
|
2011-07-18 07:38:26 +00:00
|
|
|
|
2016-12-31 09:52:25 +00:00
|
|
|
filename = g_queue_pop_head (&multifilesink->old_files);
|
2011-07-18 07:38:26 +00:00
|
|
|
g_remove (filename);
|
2011-11-24 17:14:53 +00:00
|
|
|
g_free (filename);
|
2011-07-18 07:38:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-17 21:56:04 +00:00
|
|
|
static gboolean
|
|
|
|
gst_multi_file_sink_event (GstBaseSink * sink, GstEvent * event)
|
|
|
|
{
|
|
|
|
GstMultiFileSink *multifilesink;
|
|
|
|
gchar *filename;
|
|
|
|
|
|
|
|
multifilesink = GST_MULTI_FILE_SINK (sink);
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_CUSTOM_DOWNSTREAM:
|
|
|
|
{
|
|
|
|
GstClockTime timestamp, duration;
|
|
|
|
GstClockTime running_time, stream_time;
|
|
|
|
guint64 offset, offset_end;
|
|
|
|
gboolean all_headers;
|
|
|
|
guint count;
|
|
|
|
|
|
|
|
if (multifilesink->next_file != GST_MULTI_FILE_SINK_NEXT_KEY_UNIT_EVENT ||
|
|
|
|
!gst_video_event_is_force_key_unit (event))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
gst_video_event_parse_downstream_force_key_unit (event, ×tamp,
|
|
|
|
&stream_time, &running_time, &all_headers, &count);
|
|
|
|
|
|
|
|
if (multifilesink->force_key_unit_count != -1 &&
|
|
|
|
multifilesink->force_key_unit_count == count)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
multifilesink->force_key_unit_count = count;
|
|
|
|
|
|
|
|
if (multifilesink->file) {
|
|
|
|
duration = GST_CLOCK_TIME_NONE;
|
|
|
|
offset = offset_end = -1;
|
|
|
|
filename = g_strdup_printf (multifilesink->filename,
|
|
|
|
multifilesink->index);
|
|
|
|
|
|
|
|
gst_multi_file_sink_close_file (multifilesink, NULL);
|
|
|
|
|
2015-04-04 14:55:00 +00:00
|
|
|
gst_multi_file_sink_post_message_full (multifilesink, timestamp,
|
|
|
|
duration, offset, offset_end, running_time, stream_time, filename);
|
|
|
|
g_free (filename);
|
2011-07-17 21:56:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (multifilesink->file == NULL) {
|
|
|
|
if (!gst_multi_file_sink_open_next_file (multifilesink))
|
|
|
|
goto stdio_write_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2015-03-30 14:14:09 +00:00
|
|
|
case GST_EVENT_EOS:
|
2015-04-02 12:35:18 +00:00
|
|
|
if (multifilesink->aggregate_gops) {
|
|
|
|
GstBuffer *buf = gst_buffer_new ();
|
|
|
|
|
|
|
|
/* push key unit buffer to force writing out the pending GOP data */
|
|
|
|
GST_INFO_OBJECT (sink, "EOS, write pending GOP data");
|
|
|
|
GST_BUFFER_FLAG_UNSET (buf, GST_BUFFER_FLAG_DELTA_UNIT);
|
|
|
|
gst_multi_file_sink_render (sink, buf);
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
}
|
2015-03-30 14:14:09 +00:00
|
|
|
if (multifilesink->file) {
|
|
|
|
gchar *filename;
|
|
|
|
|
|
|
|
filename = g_strdup_printf (multifilesink->filename,
|
|
|
|
multifilesink->index);
|
2015-04-04 14:55:00 +00:00
|
|
|
|
|
|
|
gst_multi_file_sink_close_file (multifilesink, NULL);
|
|
|
|
|
2015-03-30 14:14:09 +00:00
|
|
|
gst_multi_file_sink_post_message_from_time (multifilesink,
|
|
|
|
GST_BASE_SINK (multifilesink)->segment.position, -1, filename);
|
|
|
|
g_free (filename);
|
|
|
|
}
|
|
|
|
break;
|
2011-07-17 21:56:04 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2011-12-02 21:25:17 +00:00
|
|
|
return GST_BASE_SINK_CLASS (parent_class)->event (sink, event);
|
2011-07-17 21:56:04 +00:00
|
|
|
|
2011-12-02 21:25:17 +00:00
|
|
|
/* ERRORS */
|
2011-07-17 21:56:04 +00:00
|
|
|
stdio_write_error:
|
2011-12-02 21:25:17 +00:00
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (multifilesink, RESOURCE, WRITE,
|
|
|
|
("Error while writing to file."), (NULL));
|
|
|
|
gst_event_unref (event);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-07-17 21:56:04 +00:00
|
|
|
}
|
|
|
|
|
2011-07-17 21:36:55 +00:00
|
|
|
static gboolean
|
|
|
|
gst_multi_file_sink_open_next_file (GstMultiFileSink * multifilesink)
|
|
|
|
{
|
|
|
|
char *filename;
|
|
|
|
|
|
|
|
g_return_val_if_fail (multifilesink->file == NULL, FALSE);
|
|
|
|
|
2011-07-18 07:38:26 +00:00
|
|
|
gst_multi_file_sink_ensure_max_files (multifilesink);
|
2016-12-31 09:52:25 +00:00
|
|
|
|
2011-07-17 21:36:55 +00:00
|
|
|
filename = g_strdup_printf (multifilesink->filename, multifilesink->index);
|
|
|
|
multifilesink->file = g_fopen (filename, "wb");
|
2011-07-18 07:38:26 +00:00
|
|
|
if (multifilesink->file == NULL) {
|
|
|
|
g_free (filename);
|
2011-07-17 21:36:55 +00:00
|
|
|
return FALSE;
|
2011-07-18 07:38:26 +00:00
|
|
|
}
|
|
|
|
|
2011-07-17 21:56:04 +00:00
|
|
|
GST_INFO_OBJECT (multifilesink, "opening file %s", filename);
|
2016-05-29 16:21:47 +00:00
|
|
|
|
2016-12-31 09:52:25 +00:00
|
|
|
gst_multi_file_sink_add_old_file (multifilesink, filename);
|
2011-07-17 21:36:55 +00:00
|
|
|
|
2011-09-23 17:31:01 +00:00
|
|
|
multifilesink->cur_file_size = 0;
|
2011-07-17 21:36:55 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_multi_file_sink_close_file (GstMultiFileSink * multifilesink,
|
|
|
|
GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
char *filename;
|
|
|
|
|
|
|
|
fclose (multifilesink->file);
|
|
|
|
multifilesink->file = NULL;
|
|
|
|
|
|
|
|
if (buffer) {
|
|
|
|
filename = g_strdup_printf (multifilesink->filename, multifilesink->index);
|
|
|
|
gst_multi_file_sink_post_message (multifilesink, buffer, filename);
|
|
|
|
g_free (filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
multifilesink->index++;
|
|
|
|
}
|