mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-28 04:31:06 +00:00
Revert "multifilesink: streamline the file-switch code a bit"
This reverts commit f1ceaab02f
.
This broke atomic file writes in "buffer" mode. It did make
sure that any streamheaders are prepended to each file in
buffer mode as well, but that's not really needed in practice,
whereas atomic file writes are, so let's restore the status
quo ante for now since this was primarily a code cleanup anyway,
and if anyone needs to streamheaders in buffer mode too they
can make a patch to implement that differently. Re-implementing
the atomic writes in the element also seems way too much work.
https://bugzilla.gnome.org/show_bug.cgi?id=766990
This commit is contained in:
parent
6ab88a7f78
commit
023998dd76
1 changed files with 35 additions and 15 deletions
|
@ -580,8 +580,6 @@ gst_multi_file_sink_write_stream_headers (GstMultiFileSink * sink)
|
||||||
if (sink->streamheaders == NULL)
|
if (sink->streamheaders == NULL)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (sink, "Writing stream headers");
|
|
||||||
|
|
||||||
/* we want to write these at the beginning */
|
/* we want to write these at the beginning */
|
||||||
g_assert (sink->cur_file_size == 0);
|
g_assert (sink->cur_file_size == 0);
|
||||||
|
|
||||||
|
@ -609,27 +607,29 @@ gst_multi_file_sink_write_buffer (GstMultiFileSink * multifilesink,
|
||||||
GstBuffer * buffer)
|
GstBuffer * buffer)
|
||||||
{
|
{
|
||||||
GstMapInfo map;
|
GstMapInfo map;
|
||||||
|
gchar *filename;
|
||||||
gboolean ret;
|
gboolean ret;
|
||||||
|
GError *error = NULL;
|
||||||
gboolean first_file = TRUE;
|
gboolean first_file = TRUE;
|
||||||
|
|
||||||
gst_buffer_map (buffer, &map, GST_MAP_READ);
|
gst_buffer_map (buffer, &map, GST_MAP_READ);
|
||||||
|
|
||||||
switch (multifilesink->next_file) {
|
switch (multifilesink->next_file) {
|
||||||
case GST_MULTI_FILE_SINK_NEXT_BUFFER:
|
case GST_MULTI_FILE_SINK_NEXT_BUFFER:
|
||||||
if (multifilesink->files != NULL)
|
gst_multi_file_sink_ensure_max_files (multifilesink);
|
||||||
first_file = FALSE;
|
|
||||||
if (!gst_multi_file_sink_open_next_file (multifilesink))
|
filename = g_strdup_printf (multifilesink->filename,
|
||||||
goto stdio_write_error;
|
multifilesink->index);
|
||||||
if (first_file == FALSE)
|
ret = g_file_set_contents (filename, (char *) map.data, map.size, &error);
|
||||||
gst_multi_file_sink_write_stream_headers (multifilesink);
|
if (!ret)
|
||||||
GST_DEBUG_OBJECT (multifilesink,
|
goto write_error;
|
||||||
"Writing buffer data (%" G_GSIZE_FORMAT " bytes) to new file",
|
|
||||||
map.size);
|
multifilesink->files = g_slist_append (multifilesink->files, filename);
|
||||||
ret = fwrite (map.data, map.size, 1, multifilesink->file);
|
multifilesink->n_files += 1;
|
||||||
if (ret != 1)
|
|
||||||
goto stdio_write_error;
|
gst_multi_file_sink_post_message (multifilesink, buffer, filename);
|
||||||
|
multifilesink->index++;
|
||||||
|
|
||||||
gst_multi_file_sink_close_file (multifilesink, buffer);
|
|
||||||
break;
|
break;
|
||||||
case GST_MULTI_FILE_SINK_NEXT_DISCONT:
|
case GST_MULTI_FILE_SINK_NEXT_DISCONT:
|
||||||
if (GST_BUFFER_IS_DISCONT (buffer)) {
|
if (GST_BUFFER_IS_DISCONT (buffer)) {
|
||||||
|
@ -776,6 +776,26 @@ gst_multi_file_sink_write_buffer (GstMultiFileSink * multifilesink,
|
||||||
return GST_FLOW_OK;
|
return GST_FLOW_OK;
|
||||||
|
|
||||||
/* ERRORS */
|
/* ERRORS */
|
||||||
|
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;
|
||||||
|
}
|
||||||
stdio_write_error:
|
stdio_write_error:
|
||||||
switch (errno) {
|
switch (errno) {
|
||||||
case ENOSPC:
|
case ENOSPC:
|
||||||
|
|
Loading…
Reference in a new issue