av: Port to new avio protocol handler

This commit is contained in:
Sebastian Dröge 2012-12-04 17:47:20 +01:00
parent 5f03a7d869
commit 06ed3e4060
3 changed files with 69 additions and 81 deletions

View file

@ -30,6 +30,7 @@
#include <libavcodec/avcodec.h> #include <libavcodec/avcodec.h>
#include <libavformat/avformat.h> #include <libavformat/avformat.h>
#include <libavformat/url.h>
#include "gstav.h" #include "gstav.h"
#include "gstavutils.h" #include "gstavutils.h"
@ -149,8 +150,8 @@ plugin_init (GstPlugin * plugin)
gst_ffmpegaudioresample_register (plugin); gst_ffmpegaudioresample_register (plugin);
#endif #endif
av_register_protocol2 (&gstreamer_protocol, sizeof (URLProtocol)); ffurl_register_protocol (&gstreamer_protocol, sizeof (URLProtocol));
av_register_protocol2 (&gstpipe_protocol, sizeof (URLProtocol)); ffurl_register_protocol (&gstpipe_protocol, sizeof (URLProtocol));
/* Now we can return the pointer to the newly created Plugin object. */ /* Now we can return the pointer to the newly created Plugin object. */
return TRUE; return TRUE;

View file

@ -26,6 +26,7 @@
#include <libavcodec/avcodec.h> #include <libavcodec/avcodec.h>
#include <libavformat/avformat.h> #include <libavformat/avformat.h>
#include <libavformat/url.h>
#include <gst/gst.h> #include <gst/gst.h>

View file

@ -25,6 +25,7 @@
#include <errno.h> #include <errno.h>
#include <libavformat/avformat.h> #include <libavformat/avformat.h>
#include <libavformat/url.h>
#include <gst/gst.h> #include <gst/gst.h>
@ -57,7 +58,7 @@ gst_ffmpegdata_open (URLContext * h, const char *filename, int flags)
h->flags &= ~GST_FFMPEG_URL_STREAMHEADER; h->flags &= ~GST_FFMPEG_URL_STREAMHEADER;
/* we don't support R/W together */ /* 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"); GST_WARNING ("Only read-only or write-only are supported");
return -EINVAL; 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 */ /* make sure we're a pad and that we're of the right type */
g_return_val_if_fail (GST_IS_PAD (pad), -EINVAL); g_return_val_if_fail (GST_IS_PAD (pad), -EINVAL);
switch (flags) { if ((flags & AVIO_FLAG_READ)) {
case URL_RDONLY:
g_return_val_if_fail (GST_PAD_IS_SINK (pad), -EINVAL); g_return_val_if_fail (GST_PAD_IS_SINK (pad), -EINVAL);
break; }
case URL_WRONLY: if ((flags & AVIO_FLAG_WRITE)) {
g_return_val_if_fail (GST_PAD_IS_SRC (pad), -EINVAL); g_return_val_if_fail (GST_PAD_IS_SRC (pad), -EINVAL);
break;
} }
info->eos = FALSE; info->eos = FALSE;
@ -98,7 +97,7 @@ gst_ffmpegdata_peek (URLContext * h, unsigned char *buf, int size)
GstFlowReturn ret; GstFlowReturn ret;
int total = 0; 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; info = (GstProtocolInfo *) h->priv_data;
GST_DEBUG ("Pulling %d bytes at position %" G_GUINT64_FORMAT, size, 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); GST_DEBUG ("Writing %d bytes", size);
info = (GstProtocolInfo *) h->priv_data; 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 */ /* create buffer and push data further */
outbuf = gst_buffer_new_and_alloc (size); outbuf = gst_buffer_new_and_alloc (size);
@ -185,10 +184,7 @@ gst_ffmpegdata_seek (URLContext * h, int64_t pos, int whence)
info = (GstProtocolInfo *) h->priv_data; info = (GstProtocolInfo *) h->priv_data;
/* TODO : if we are push-based, we need to return sensible info */ /* TODO : if we are push-based, we need to return sensible info */
if ((h->flags & AVIO_FLAG_READ)) {
switch (h->flags) {
case URL_RDONLY:
{
/* sinkpad */ /* sinkpad */
switch (whence) { switch (whence) {
case SEEK_SET: case SEEK_SET:
@ -219,9 +215,8 @@ gst_ffmpegdata_seek (URLContext * h, int64_t pos, int whence)
if (whence != AVSEEK_SIZE) if (whence != AVSEEK_SIZE)
info->offset = newpos; info->offset = newpos;
} }
break;
case URL_WRONLY: if ((h->flags & AVIO_FLAG_WRITE)) {
{
GstSegment segment; GstSegment segment;
oldpos = info->offset; oldpos = info->offset;
@ -247,11 +242,6 @@ gst_ffmpegdata_seek (URLContext * h, int64_t pos, int whence)
segment.time = newpos; segment.time = newpos;
gst_pad_push_event (info->pad, gst_event_new_segment (&segment)); gst_pad_push_event (info->pad, gst_event_new_segment (&segment));
} }
break;
}
default:
g_assert (0);
break;
} }
GST_DEBUG ("Now at offset %" G_GUINT64_FORMAT " (returning %" G_GUINT64_FORMAT 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"); GST_LOG ("Closing file");
switch (h->flags) { if ((h->flags & AVIO_FLAG_WRITE)) {
case URL_WRONLY:
{
/* send EOS - that closes down the stream */ /* send EOS - that closes down the stream */
gst_pad_push_event (info->pad, gst_event_new_eos ()); gst_pad_push_event (info->pad, gst_event_new_eos ());
break;
}
default:
break;
} }
/* clean up data */ /* clean up data */
@ -292,6 +276,7 @@ gst_ffmpegdata_close (URLContext * h)
URLProtocol gstreamer_protocol = { URLProtocol gstreamer_protocol = {
/*.name = */ "gstreamer", /*.name = */ "gstreamer",
/*.url_open = */ gst_ffmpegdata_open, /*.url_open = */ gst_ffmpegdata_open,
/*.url_open2 = */ NULL,
/*.url_read = */ gst_ffmpegdata_read, /*.url_read = */ gst_ffmpegdata_read,
/*.url_write = */ gst_ffmpegdata_write, /*.url_write = */ gst_ffmpegdata_write,
/*.url_seek = */ gst_ffmpegdata_seek, /*.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); GST_LOG ("Opening %s", filename);
/* we don't support W together */ /* we don't support W together */
if (flags != URL_RDONLY) { if ((flags & AVIO_FLAG_WRITE)) {
GST_WARNING ("Only read-only is supported"); GST_WARNING ("Only read-only is supported");
return -EINVAL; return -EINVAL;
} }
@ -379,6 +364,7 @@ gst_ffmpeg_pipe_close (URLContext * h)
URLProtocol gstpipe_protocol = { URLProtocol gstpipe_protocol = {
"gstpipe", "gstpipe",
gst_ffmpeg_pipe_open, gst_ffmpeg_pipe_open,
NULL,
gst_ffmpeg_pipe_read, gst_ffmpeg_pipe_read,
NULL, NULL,
NULL, NULL,