summaryrefslogtreecommitdiffstats
path: root/gst/multifile
diff options
context:
space:
mode:
authorDavid Schleef <ds@schleef.org>2008-02-08 03:44:12 +0000
committerDavid Schleef <ds@schleef.org>2008-02-08 03:44:12 +0000
commitda83e9f450e0f036dd204f2a1a84a950676113be (patch)
tree83dc311a947591a19cdb46420a0fdbc2af1e5171 /gst/multifile
parent1d5d8e1397535425815eeeb252e9213b77b57ef4 (diff)
gst/multifile/: Use g_file_[sg]et_contents() instead of using stdio functions.
Original commit message from CVS: * gst/multifile/gstmultifilesink.c: * gst/multifile/gstmultifilesrc.c: Use g_file_[sg]et_contents() instead of using stdio functions. Should be less error prone. * tests/check/elements/multifile.c: Create a temporary directory using standard functions instead of creating a directory in the current dir.
Diffstat (limited to 'gst/multifile')
-rw-r--r--gst/multifile/gstmultifilesink.c66
-rw-r--r--gst/multifile/gstmultifilesrc.c25
2 files changed, 31 insertions, 60 deletions
diff --git a/gst/multifile/gstmultifilesink.c b/gst/multifile/gstmultifilesink.c
index dd7e1f4c..583b989c 100644
--- a/gst/multifile/gstmultifilesink.c
+++ b/gst/multifile/gstmultifilesink.c
@@ -49,7 +49,7 @@ GST_DEBUG_CATEGORY_STATIC (gst_multi_file_sink_debug);
static const GstElementDetails gst_multi_file_sink_details =
GST_ELEMENT_DETAILS ("Multi-File Sink",
"Sink/File",
- "Write stream to a file",
+ "Write buffers to a sequentially named set of files",
"David Schleef <ds@schleef.org>");
enum
@@ -113,11 +113,6 @@ gst_multi_file_sink_class_init (GstMultiFileSinkClass * klass)
gstbasesink_class->get_times = NULL;
gstbasesink_class->render = GST_DEBUG_FUNCPTR (gst_multi_file_sink_render);
-
- if (sizeof (off_t) < 8) {
- GST_LOG ("No large file support, sizeof (off_t) = %" G_GSIZE_FORMAT,
- sizeof (off_t));
- }
}
static void
@@ -197,12 +192,6 @@ gst_multi_file_sink_get_property (GObject * object, guint prop_id,
}
}
-#ifdef G_OS_UNIX
-# define __GST_STDIO_SEEK_FUNCTION "lseek"
-#else
-# define __GST_STDIO_SEEK_FUNCTION "fseek"
-#endif
-
static gchar *
gst_multi_file_sink_get_filename (GstMultiFileSink * multifilesink)
{
@@ -219,7 +208,8 @@ gst_multi_file_sink_render (GstBaseSink * sink, GstBuffer * buffer)
GstMultiFileSink *multifilesink;
guint size;
gchar *filename;
- FILE *file;
+ gboolean ret;
+ GError *error = NULL;
size = GST_BUFFER_SIZE (buffer);
@@ -227,38 +217,28 @@ gst_multi_file_sink_render (GstBaseSink * sink, GstBuffer * buffer)
filename = gst_multi_file_sink_get_filename (multifilesink);
- file = fopen (filename, "wb");
- if (!file) {
- goto handle_error;
- }
-
- g_free (filename);
-
- if (size > 0 && GST_BUFFER_DATA (buffer) != NULL) {
- if (fwrite (GST_BUFFER_DATA (buffer), size, 1, file) != 1)
- goto handle_error;
+ ret = g_file_set_contents (filename, (char *) GST_BUFFER_DATA (buffer),
+ size, &error);
+ if (ret) {
+ multifilesink->index++;
+ g_free (filename);
+ return GST_FLOW_OK;
}
- multifilesink->index++;
-
- fclose (file);
-
- return GST_FLOW_OK;
-
-handle_error:
- {
- switch (errno) {
- case ENOSPC:{
- GST_ELEMENT_ERROR (multifilesink, RESOURCE, NO_SPACE_LEFT, (NULL),
- (NULL));
- break;
- }
- default:{
- GST_ELEMENT_ERROR (multifilesink, RESOURCE, WRITE,
- ("Error while writing to file \"%s\".", multifilesink->filename),
- ("%s", g_strerror (errno)));
- }
+ 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)));
}
- return GST_FLOW_ERROR;
}
+ g_error_free (error);
+ g_free (filename);
+
+ return GST_FLOW_ERROR;
}
diff --git a/gst/multifile/gstmultifilesrc.c b/gst/multifile/gstmultifilesrc.c
index f2de1b86..4a30a050 100644
--- a/gst/multifile/gstmultifilesrc.c
+++ b/gst/multifile/gstmultifilesrc.c
@@ -77,7 +77,7 @@ GST_DEBUG_CATEGORY_STATIC (gst_multi_file_src_debug);
static const GstElementDetails gst_multi_file_src_details =
GST_ELEMENT_DETAILS ("Multi-File Source",
"Source/File",
- "Read stream from files",
+ "Read a sequentially named set of files into buffers",
"David Schleef <ds@schleef.org>");
enum
@@ -267,10 +267,11 @@ gst_multi_file_src_create (GstPushSrc * src, GstBuffer ** buffer)
{
GstMultiFileSrc *multifilesrc;
guint size;
+ gchar *data;
gchar *filename;
- FILE *file;
GstBuffer *buf;
- int ret;
+ gboolean ret;
+ GError *error = NULL;
multifilesrc = GST_MULTI_FILE_SRC (src);
@@ -278,8 +279,8 @@ gst_multi_file_src_create (GstPushSrc * src, GstBuffer ** buffer)
GST_DEBUG_OBJECT (multifilesrc, "reading from file \"%s\".", filename);
- file = fopen (filename, "rb");
- if (!file) {
+ ret = g_file_get_contents (filename, &data, &size, &error);
+ if (!ret) {
if (multifilesrc->successful_read) {
/* If we've read at least one buffer successfully, not finding the
* next file is EOS. */
@@ -290,20 +291,11 @@ gst_multi_file_src_create (GstPushSrc * src, GstBuffer ** buffer)
}
}
- fseek (file, 0, SEEK_END);
- size = ftell (file);
- fseek (file, 0, SEEK_SET);
-
- buf = gst_buffer_new_and_alloc (size);
-
- ret = fread (GST_BUFFER_DATA (buf), size, 1, file);
- if (ret < 1) {
- goto handle_error;
- }
-
multifilesrc->successful_read = TRUE;
multifilesrc->index++;
+ buf = gst_buffer_new ();
+ GST_BUFFER_DATA (buf) = (unsigned char *) data;
GST_BUFFER_SIZE (buf) = size;
GST_BUFFER_OFFSET (buf) = multifilesrc->offset;
GST_BUFFER_OFFSET_END (buf) = multifilesrc->offset + size;
@@ -312,7 +304,6 @@ gst_multi_file_src_create (GstPushSrc * src, GstBuffer ** buffer)
GST_DEBUG_OBJECT (multifilesrc, "read file \"%s\".", filename);
- fclose (file);
g_free (filename);
*buffer = buf;
return GST_FLOW_OK;