From 06ed3e40604b2a4683b0edfaae1f3ae6ccee0e57 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 4 Dec 2012 17:47:20 +0100 Subject: [PATCH] av: Port to new avio protocol handler --- ext/libav/gstav.c | 5 +- ext/libav/gstav.h | 1 + ext/libav/gstavprotocol.c | 150 +++++++++++++++++++++------------------------- 3 files changed, 72 insertions(+), 84 deletions(-) diff --git a/ext/libav/gstav.c b/ext/libav/gstav.c index 4217dd4..5413a38 100644 --- a/ext/libav/gstav.c +++ b/ext/libav/gstav.c @@ -30,6 +30,7 @@ #include #include +#include #include "gstav.h" #include "gstavutils.h" @@ -149,8 +150,8 @@ plugin_init (GstPlugin * plugin) gst_ffmpegaudioresample_register (plugin); #endif - av_register_protocol2 (&gstreamer_protocol, sizeof (URLProtocol)); - av_register_protocol2 (&gstpipe_protocol, sizeof (URLProtocol)); + ffurl_register_protocol (&gstreamer_protocol, sizeof (URLProtocol)); + ffurl_register_protocol (&gstpipe_protocol, sizeof (URLProtocol)); /* Now we can return the pointer to the newly created Plugin object. */ return TRUE; diff --git a/ext/libav/gstav.h b/ext/libav/gstav.h index edb5bd2..8b6d40b 100644 --- a/ext/libav/gstav.h +++ b/ext/libav/gstav.h @@ -26,6 +26,7 @@ #include #include +#include #include diff --git a/ext/libav/gstavprotocol.c b/ext/libav/gstavprotocol.c index a30a918..a2f0b83 100644 --- a/ext/libav/gstavprotocol.c +++ b/ext/libav/gstavprotocol.c @@ -25,6 +25,7 @@ #include #include +#include #include @@ -57,7 +58,7 @@ gst_ffmpegdata_open (URLContext * h, const char *filename, int flags) h->flags &= ~GST_FFMPEG_URL_STREAMHEADER; /* we don't support R/W together */ - if (flags != URL_RDONLY && flags != URL_WRONLY) { + if ((flags & AVIO_FLAG_WRITE) && (flags & AVIO_FLAG_READ)) { GST_WARNING ("Only read-only or write-only are supported"); return -EINVAL; } @@ -70,13 +71,11 @@ gst_ffmpegdata_open (URLContext * h, const char *filename, int flags) /* make sure we're a pad and that we're of the right type */ g_return_val_if_fail (GST_IS_PAD (pad), -EINVAL); - switch (flags) { - case URL_RDONLY: - g_return_val_if_fail (GST_PAD_IS_SINK (pad), -EINVAL); - break; - case URL_WRONLY: - g_return_val_if_fail (GST_PAD_IS_SRC (pad), -EINVAL); - break; + if ((flags & AVIO_FLAG_READ)) { + g_return_val_if_fail (GST_PAD_IS_SINK (pad), -EINVAL); + } + if ((flags & AVIO_FLAG_WRITE)) { + g_return_val_if_fail (GST_PAD_IS_SRC (pad), -EINVAL); } info->eos = FALSE; @@ -98,7 +97,7 @@ gst_ffmpegdata_peek (URLContext * h, unsigned char *buf, int size) GstFlowReturn ret; int total = 0; - g_return_val_if_fail (h->flags == URL_RDONLY, AVERROR (EIO)); + g_return_val_if_fail ((h->flags & AVIO_FLAG_READ), AVERROR (EIO)); info = (GstProtocolInfo *) h->priv_data; GST_DEBUG ("Pulling %d bytes at position %" G_GUINT64_FORMAT, size, @@ -159,7 +158,7 @@ gst_ffmpegdata_write (URLContext * h, const unsigned char *buf, int size) GST_DEBUG ("Writing %d bytes", size); info = (GstProtocolInfo *) h->priv_data; - g_return_val_if_fail (h->flags != URL_RDONLY, -EIO); + g_return_val_if_fail ((h->flags & AVIO_FLAG_WRITE), -EIO); /* create buffer and push data further */ outbuf = gst_buffer_new_and_alloc (size); @@ -185,73 +184,64 @@ gst_ffmpegdata_seek (URLContext * h, int64_t pos, int whence) info = (GstProtocolInfo *) h->priv_data; /* TODO : if we are push-based, we need to return sensible info */ - - switch (h->flags) { - case URL_RDONLY: - { - /* sinkpad */ - switch (whence) { - case SEEK_SET: - newpos = (guint64) pos; - break; - case SEEK_CUR: - newpos = info->offset + pos; - break; - case SEEK_END: - case AVSEEK_SIZE: - /* ffmpeg wants to know the current end position in bytes ! */ - { - gint64 duration; - - GST_DEBUG ("Seek end"); - - if (gst_pad_is_linked (info->pad)) - if (gst_pad_query_duration (GST_PAD_PEER (info->pad), - GST_FORMAT_BYTES, &duration)) - newpos = ((guint64) duration) + pos; - } - break; - default: - g_assert (0); - break; + if ((h->flags & AVIO_FLAG_READ)) { + /* sinkpad */ + switch (whence) { + case SEEK_SET: + newpos = (guint64) pos; + break; + case SEEK_CUR: + newpos = info->offset + pos; + break; + case SEEK_END: + case AVSEEK_SIZE: + /* ffmpeg wants to know the current end position in bytes ! */ + { + gint64 duration; + + GST_DEBUG ("Seek end"); + + if (gst_pad_is_linked (info->pad)) + if (gst_pad_query_duration (GST_PAD_PEER (info->pad), + GST_FORMAT_BYTES, &duration)) + newpos = ((guint64) duration) + pos; } - /* FIXME : implement case for push-based behaviour */ - if (whence != AVSEEK_SIZE) - info->offset = newpos; + break; + default: + g_assert (0); + break; } - break; - case URL_WRONLY: - { - GstSegment segment; - - oldpos = info->offset; - - /* srcpad */ - switch (whence) { - case SEEK_SET: - { - info->offset = (guint64) pos; - break; - } - case SEEK_CUR: - info->offset += pos; - break; - default: - break; - } - newpos = info->offset; + /* FIXME : implement case for push-based behaviour */ + if (whence != AVSEEK_SIZE) + info->offset = newpos; + } + + if ((h->flags & AVIO_FLAG_WRITE)) { + GstSegment segment; - if (newpos != oldpos) { - gst_segment_init (&segment, GST_FORMAT_BYTES); - segment.start = newpos; - segment.time = newpos; - gst_pad_push_event (info->pad, gst_event_new_segment (&segment)); + oldpos = info->offset; + + /* srcpad */ + switch (whence) { + case SEEK_SET: + { + info->offset = (guint64) pos; + break; } - break; + case SEEK_CUR: + info->offset += pos; + break; + default: + break; + } + newpos = info->offset; + + if (newpos != oldpos) { + gst_segment_init (&segment, GST_FORMAT_BYTES); + segment.start = newpos; + segment.time = newpos; + gst_pad_push_event (info->pad, gst_event_new_segment (&segment)); } - default: - g_assert (0); - break; } GST_DEBUG ("Now at offset %" G_GUINT64_FORMAT " (returning %" G_GUINT64_FORMAT @@ -270,15 +260,9 @@ gst_ffmpegdata_close (URLContext * h) GST_LOG ("Closing file"); - switch (h->flags) { - case URL_WRONLY: - { - /* send EOS - that closes down the stream */ - gst_pad_push_event (info->pad, gst_event_new_eos ()); - break; - } - default: - break; + if ((h->flags & AVIO_FLAG_WRITE)) { + /* send EOS - that closes down the stream */ + gst_pad_push_event (info->pad, gst_event_new_eos ()); } /* clean up data */ @@ -292,6 +276,7 @@ gst_ffmpegdata_close (URLContext * h) URLProtocol gstreamer_protocol = { /*.name = */ "gstreamer", /*.url_open = */ gst_ffmpegdata_open, + /*.url_open2 = */ NULL, /*.url_read = */ gst_ffmpegdata_read, /*.url_write = */ gst_ffmpegdata_write, /*.url_seek = */ gst_ffmpegdata_seek, @@ -310,7 +295,7 @@ gst_ffmpeg_pipe_open (URLContext * h, const char *filename, int flags) GST_LOG ("Opening %s", filename); /* we don't support W together */ - if (flags != URL_RDONLY) { + if ((flags & AVIO_FLAG_WRITE)) { GST_WARNING ("Only read-only is supported"); return -EINVAL; } @@ -379,6 +364,7 @@ gst_ffmpeg_pipe_close (URLContext * h) URLProtocol gstpipe_protocol = { "gstpipe", gst_ffmpeg_pipe_open, + NULL, gst_ffmpeg_pipe_read, NULL, NULL, -- 2.7.4