- switch (errno) {
- case ENOSPC:{
- GST_ELEMENT_ERROR (filesink, RESOURCE, NO_SPACE_LEFT, (NULL), (NULL));
- break;
- }
- default:{
- GST_ELEMENT_ERROR (filesink, RESOURCE, WRITE,
- (_("Error while writing to file \"%s\"."), filesink->filename),
- ("%s", g_strerror (errno)));
- }
+ GST_LOG_OBJECT (sink, "empty buffer list");
+ return GST_FLOW_OK;
+ }
+}
+
+static GstFlowReturn
+gst_file_sink_render (GstBaseSink * sink, GstBuffer * buffer)
+{
+ GstFileSink *filesink;
+ GstFlowReturn flow;
+ guint8 n_mem;
+ gboolean sync_after;
+
+ filesink = GST_FILE_SINK_CAST (sink);
+
+ sync_after = GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_SYNC_AFTER);
+
+ n_mem = gst_buffer_n_memory (buffer);
+
+ if (n_mem > 0 && (sync_after || !filesink->buffer)) {
+ flow = gst_file_sink_flush_buffer (filesink);
+ if (flow == GST_FLOW_OK)
+ flow =
+ gst_file_sink_render_buffers (filesink, &buffer, 1, &n_mem, n_mem,
+ gst_buffer_get_size (buffer));
+ } else if (n_mem > 0) {
+ GST_DEBUG_OBJECT (filesink,
+ "Queueing buffer of %" G_GSIZE_FORMAT " bytes at offset %"
+ G_GUINT64_FORMAT, gst_buffer_get_size (buffer),
+ filesink->current_pos + filesink->current_buffer_size);
+
+ filesink->current_buffer_size += gst_buffer_get_size (buffer);
+ gst_buffer_list_add (filesink->buffer, gst_buffer_ref (buffer));
+
+ if (filesink->current_buffer_size > filesink->buffer_size)
+ flow = gst_file_sink_flush_buffer (filesink);
+ else
+ flow = GST_FLOW_OK;
+ } else {
+ flow = GST_FLOW_OK;
+ }
+
+ if (flow == GST_FLOW_OK && sync_after) {
+ if (fsync (fileno (filesink->file))) {
+ GST_ELEMENT_ERROR (filesink, RESOURCE, WRITE,
+ (_("Error while writing to file \"%s\"."), filesink->filename),
+ ("%s", g_strerror (errno)));
+ flow = GST_FLOW_ERROR;