aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/gstreamer_extractor.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/gstreamer_extractor.c')
-rw-r--r--src/plugins/gstreamer_extractor.c66
1 files changed, 34 insertions, 32 deletions
diff --git a/src/plugins/gstreamer_extractor.c b/src/plugins/gstreamer_extractor.c
index b67047b..f1f666c 100644
--- a/src/plugins/gstreamer_extractor.c
+++ b/src/plugins/gstreamer_extractor.c
@@ -29,6 +29,10 @@
29#include <glib-object.h> 29#include <glib-object.h>
30#include <gst/pbutils/pbutils.h> 30#include <gst/pbutils/pbutils.h>
31#include <gst/tag/tag.h> 31#include <gst/tag/tag.h>
32#include <gst/app/gstappsrc.h>
33
34GST_DEBUG_CATEGORY_STATIC (gstreamer_extractor);
35#define GST_CAT_DEFAULT gstreamer_extractor
32 36
33struct KnownTag 37struct KnownTag
34{ 38{
@@ -668,6 +672,8 @@ initialize ()
668 672
669 gst_init (NULL, NULL); 673 gst_init (NULL, NULL);
670 674
675 GST_DEBUG_CATEGORY_INIT (gstreamer_extractor, "GstExtractor",
676 0, "GStreamer-based libextractor plugin");
671 dc = gst_discoverer_new (timeout * GST_SECOND, &err); 677 dc = gst_discoverer_new (timeout * GST_SECOND, &err);
672 if (G_UNLIKELY (dc == NULL)) { 678 if (G_UNLIKELY (dc == NULL)) {
673 g_print ("Error initializing: %s\n", err->message); 679 g_print ("Error initializing: %s\n", err->message);
@@ -719,37 +725,32 @@ _source_setup (GstDiscoverer * dc, GstElement * source, PrivStruct * ps)
719static void 725static void
720feed_data (GstElement * appsrc, guint size, PrivStruct * ps) 726feed_data (GstElement * appsrc, guint size, PrivStruct * ps)
721{ 727{
722 GstBuffer *buffer;
723 GstFlowReturn ret; 728 GstFlowReturn ret;
724 GstMemory *data;
725 GstMapInfo mi;
726 long data_len; 729 long data_len;
727 int eos = FALSE; 730 uint8_t *le_data;
728 731
729 if (ps->length > 0 && ps->offset >= ps->length) { 732 if (ps->length > 0 && ps->offset >= ps->length) {
730 /* we are at the EOS, send end-of-stream */ 733 /* we are at the EOS, send end-of-stream */
731 g_signal_emit_by_name (ps->source, "end-of-stream", &ret); 734 ret = gst_app_src_end_of_stream (GST_APP_SRC (ps->source));
732 return; 735 return;
733 } 736 }
734 737
735 buffer = gst_buffer_new ();
736
737 if (ps->length > 0 && ps->offset + size > ps->length) 738 if (ps->length > 0 && ps->offset + size > ps->length)
738 size = ps->length - ps->offset; 739 size = ps->length - ps->offset;
739 740
740 data = gst_allocator_alloc (NULL, size, NULL); 741 data_len = ps->ec->read (ps->ec->cls, (void **) &le_data, size);
741 eos = TRUE; 742 if (data_len > 0)
742 if (gst_memory_map (data, &mi, GST_MAP_WRITE | GST_MAP_READ))
743 { 743 {
744 uint8_t *le_data; 744 GstMemory *mem;
745 data_len = ps->ec->read (ps->ec->cls, (void **) &le_data, size); 745 GstMapInfo mi;
746 if (data_len > 0) 746 mem = gst_allocator_alloc (NULL, data_len, NULL);
747 memcpy (mi.data, le_data, data_len); 747 if (gst_memory_map (mem, &mi, GST_MAP_WRITE))
748 gst_memory_unmap (data, &mi);
749 if (data_len > 0)
750 { 748 {
751 gst_memory_resize (data, 0, data_len); 749 GstBuffer *buffer;
752 gst_buffer_append_memory (buffer, data); 750 memcpy (mi.data, le_data, data_len);
751 gst_memory_unmap (mem, &mi);
752 buffer = gst_buffer_new ();
753 gst_buffer_append_memory (buffer, mem);
753 754
754 /* we need to set an offset for random access */ 755 /* we need to set an offset for random access */
755 GST_BUFFER_OFFSET (buffer) = ps->offset; 756 GST_BUFFER_OFFSET (buffer) = ps->offset;
@@ -757,20 +758,17 @@ feed_data (GstElement * appsrc, guint size, PrivStruct * ps)
757 758
758 GST_DEBUG ("feed buffer %p, offset %" G_GUINT64_FORMAT "-%u", buffer, 759 GST_DEBUG ("feed buffer %p, offset %" G_GUINT64_FORMAT "-%u", buffer,
759 ps->offset, data_len); 760 ps->offset, data_len);
760 g_signal_emit_by_name (ps->source, "push-buffer", buffer, &ret); 761 ret = gst_app_src_push_buffer (GST_APP_SRC (ps->source), buffer);
761 eos = FALSE; 762 ps->offset += data_len;
763 }
764 else
765 {
766 gst_memory_unref (mem);
767 ret = gst_app_src_end_of_stream (GST_APP_SRC (ps->source));
762 } 768 }
763 } 769 }
764 770 else
765 if (eos) 771 ret = gst_app_src_end_of_stream (GST_APP_SRC (ps->source));
766 {
767 g_signal_emit_by_name (ps->source, "end-of-stream", &ret);
768 gst_memory_unref (data);
769 }
770
771 gst_buffer_unref (buffer);
772
773 ps->offset += data_len;
774 772
775 return; 773 return;
776} 774}
@@ -871,8 +869,10 @@ send_structure_foreach (GQuark field_id, const GValue *value,
871 } 869 }
872 /* This is a potential source of invalid characters */ 870 /* This is a potential source of invalid characters */
873 /* And it also might attempt to serialize binary data - such as images. */ 871 /* And it also might attempt to serialize binary data - such as images. */
872 str = gst_value_serialize (value);
873 g_print ("Will not try to serialize structure field %s (%s) = %s\n", field_name, type_name, str);
874 g_free (str);
874 str = NULL; 875 str = NULL;
875 g_print ("Will not try to serialize structure field %s (%s)\n", field_name, type_name);
876 break; 876 break;
877 } 877 }
878 if (str != NULL) 878 if (str != NULL)
@@ -1361,8 +1361,10 @@ send_toc_tags_foreach (const GstTagList * tags, const gchar * tag,
1361 } 1361 }
1362 /* This is a potential source of invalid characters */ 1362 /* This is a potential source of invalid characters */
1363 /* And it also might attempt to serialize binary data - such as images. */ 1363 /* And it also might attempt to serialize binary data - such as images. */
1364 str = gst_value_serialize (&val);
1365 g_print ("Will not try to serialize tag %s (%s) = %s\n", tag, type_name, str);
1366 g_free (str);
1364 str = NULL; 1367 str = NULL;
1365 g_print ("Will not try to serialize tag %s (%s)\n", tag, type_name);
1366 break; 1368 break;
1367 } 1369 }
1368 if (str != NULL) 1370 if (str != NULL)