From bced3c218a795992dd8a9b60d5d38f35fa5c0b4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Fri, 23 Sep 2011 18:31:01 +0100 Subject: [PATCH] multifilesink: add new 'max-size' mode for switching to the next file --- gst/multifile/gstmultifilesink.c | 35 ++++++++++++++++++++++++++++++++ gst/multifile/gstmultifilesink.h | 5 ++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/gst/multifile/gstmultifilesink.c b/gst/multifile/gstmultifilesink.c index 20d38377ea..607311855f 100644 --- a/gst/multifile/gstmultifilesink.c +++ b/gst/multifile/gstmultifilesink.c @@ -176,6 +176,9 @@ gst_multi_file_sink_next_get_type (void) "(Useful for MPEG-TS segmenting)", "key-frame"}, {GST_MULTI_FILE_SINK_NEXT_KEY_UNIT_EVENT, "New file after a force key unit event", "key-unit-event"}, + {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"}, {0, NULL, NULL} }; @@ -573,6 +576,37 @@ gst_multi_file_sink_render (GstBaseSink * sink, GstBuffer * buffer) goto stdio_write_error; break; + case GST_MULTI_FILE_SINK_NEXT_MAX_SIZE:{ + guint64 new_size; + + new_size = multifilesink->cur_file_size + GST_BUFFER_SIZE (buffer); + 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); + + if (multifilesink->file != NULL) + gst_multi_file_sink_close_file (multifilesink, NULL); + } + + if (multifilesink->file == NULL) { + if (!gst_multi_file_sink_open_next_file (multifilesink)) + goto stdio_write_error; + + /* FIXME: write stream headers if present */ + } + + ret = fwrite (GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer), 1, + multifilesink->file); + + if (ret != 1) + goto stdio_write_error; + + multifilesink->cur_file_size += GST_BUFFER_SIZE (buffer); + break; + } default: g_assert_not_reached (); } @@ -744,6 +778,7 @@ gst_multi_file_sink_open_next_file (GstMultiFileSink * multifilesink) multifilesink->files = g_slist_append (multifilesink->files, filename); multifilesink->n_files += 1; + multifilesink->cur_file_size = 0; return TRUE; } diff --git a/gst/multifile/gstmultifilesink.h b/gst/multifile/gstmultifilesink.h index 8d38f7cfe1..5dbd6cc714 100644 --- a/gst/multifile/gstmultifilesink.h +++ b/gst/multifile/gstmultifilesink.h @@ -56,7 +56,8 @@ typedef enum { GST_MULTI_FILE_SINK_NEXT_BUFFER, GST_MULTI_FILE_SINK_NEXT_DISCONT, GST_MULTI_FILE_SINK_NEXT_KEY_FRAME, - GST_MULTI_FILE_SINK_NEXT_KEY_UNIT_EVENT + GST_MULTI_FILE_SINK_NEXT_KEY_UNIT_EVENT, + GST_MULTI_FILE_SINK_NEXT_MAX_SIZE } GstMultiFileSinkNext; struct _GstMultiFileSink @@ -77,6 +78,8 @@ struct _GstMultiFileSink int n_streamheaders; GstBuffer **streamheaders; guint force_key_unit_count; + + guint64 cur_file_size; guint64 max_file_size; };