Commit a203d19a authored by gb's avatar gb

Add initial (multithreaded) decoder based on FFmpeg.

There are tons of bugs left:
- Decoder API not nice enough with error conditions
- FFmpeg parser is sometimes broken
- Packets queue can be lost
parent 5fb146c2
......@@ -252,6 +252,14 @@ else
USE_VAAPISINK_GLX=0
fi
dnl Check for FFmpeg
PKG_CHECK_MODULES(LIBAVFORMAT, [libavformat])
AC_CHECK_HEADERS([libavformat/avformat.h])
PKG_CHECK_MODULES(LIBAVCODEC, [libavcodec])
AC_CHECK_HEADERS([libavcodec/avcodec.h])
AC_CHECK_HEADERS([libavcodec/vaapi.h])
AC_DEFINE_UNQUOTED(USE_GLX, $USE_GLX,
[Defined to 1 if GLX is enabled])
AM_CONDITIONAL(USE_GLX, test $USE_GLX -eq 1)
......
......@@ -10,7 +10,20 @@ endif
libgstvaapi_includedir = \
$(includedir)/gstreamer-@GST_MAJORMINOR@/gst/vaapi
libgstvaapi_ffmpeg_source_c = \
gstvaapidecoder_ffmpeg.c \
$(NULL)
libgstvaapi_ffmpeg_source_h = \
gstvaapidecoder_ffmpeg.h \
$(NULL)
libgstvaapi_ffmpeg_source_priv_h = \
$(NULL)
libgstvaapi_source_c = \
gstvaapicontext.c \
gstvaapidecoder.c \
gstvaapidisplay.c \
gstvaapiimage.c \
gstvaapiimageformat.c \
......@@ -22,15 +35,19 @@ libgstvaapi_source_c = \
gstvaapisubpicture.c \
gstvaapisurface.c \
gstvaapisurfacepool.c \
gstvaapisurfaceproxy.c \
gstvaapiutils.c \
gstvaapivalue.c \
gstvaapivideobuffer.c \
gstvaapivideopool.c \
gstvaapivideosink.c \
gstvaapiwindow.c \
$(libgstvaapi_ffmpeg_source_c) \
$(NULL)
libgstvaapi_source_h = \
gstvaapicontext.h \
gstvaapidecoder.h \
gstvaapidisplay.h \
gstvaapiimage.h \
gstvaapiimageformat.h \
......@@ -41,21 +58,25 @@ libgstvaapi_source_h = \
gstvaapisubpicture.h \
gstvaapisurface.h \
gstvaapisurfacepool.h \
gstvaapisurfaceproxy.h \
gstvaapitypes.h \
gstvaapivalue.h \
gstvaapivideobuffer.h \
gstvaapivideopool.h \
gstvaapivideosink.h \
gstvaapiwindow.h \
$(libgstvaapi_ffmpeg_source_h) \
$(NULL)
libgstvaapi_source_priv_h = \
gstvaapicompat.h \
gstvaapidebug.h \
gstvaapidecoder_priv.h \
gstvaapidisplay_priv.h \
gstvaapiobject_priv.h \
gstvaapiutils.h \
gstvaapi_priv.h \
$(libgst_vaapi_ffmpeg_source_priv_h) \
$(NULL)
libgstvaapi_x11_source_c = \
......@@ -116,12 +137,16 @@ libgstvaapi_@GST_MAJORMINOR@_la_CFLAGS = \
-I$(top_srcdir)/gst-libs \
$(GST_BASE_CFLAGS) \
$(GST_CFLAGS) \
$(LIBAVCODEC_CFLAGS) \
$(LIBAVFORMAT_CFLAGS) \
$(LIBVA_CFLAGS) \
$(NULL)
libgstvaapi_@GST_MAJORMINOR@_la_LIBADD = \
$(GST_BASE_LIBS) \
$(GST_LIBS) \
$(LIBAVCODEC_LIBS) \
$(LIBAVFORMAT_LIBS) \
$(LIBVA_LIBS) \
$(NULL)
......
This diff is collapsed.
/*
* gstvaapidecoder.h - VA decoder abstraction
*
* gstreamer-vaapi (C) 2010 Splitted-Desktop Systems
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef GST_VAAPI_DECODER_H
#define GST_VAAPI_DECODER_H
#include <gst/gstbuffer.h>
#include <gst/vaapi/gstvaapicontext.h>
#include <gst/vaapi/gstvaapisurfaceproxy.h>
G_BEGIN_DECLS
#define GST_VAAPI_TYPE_DECODER \
(gst_vaapi_decoder_get_type())
#define GST_VAAPI_DECODER(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
GST_VAAPI_TYPE_DECODER, \
GstVaapiDecoder))
#define GST_VAAPI_DECODER_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), \
GST_VAAPI_TYPE_DECODER, \
GstVaapiDecoderClass))
#define GST_VAAPI_IS_DECODER(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_DECODER))
#define GST_VAAPI_IS_DECODER_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_DECODER))
#define GST_VAAPI_DECODER_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), \
GST_VAAPI_TYPE_DECODER, \
GstVaapiDecoderClass))
typedef enum _GstVaapiDecoderStatus GstVaapiDecoderStatus;
typedef struct _GstVaapiDecoder GstVaapiDecoder;
typedef struct _GstVaapiDecoderPrivate GstVaapiDecoderPrivate;
typedef struct _GstVaapiDecoderClass GstVaapiDecoderClass;
/**
* GstVaapiDecoderStatus:
* @GST_VAAPI_DECODER_STATUS_SUCCESS: Success.
* @GST_VAAPI_DECODER_STATUS_TIMEOUT: Timeout. Try again later.
* @GST_VAAPI_DECODER_STATUS_EOS: End-Of-Stream.
* @GST_VAAPI_DECODER_STATUS_ERROR: Unknown error.
*
* Decoder status for gst_vaapi_decoder_get_surface().
*/
enum _GstVaapiDecoderStatus {
GST_VAAPI_DECODER_STATUS_SUCCESS = 0,
GST_VAAPI_DECODER_STATUS_TIMEOUT,
GST_VAAPI_DECODER_STATUS_END_OF_STREAM,
GST_VAAPI_DECODER_STATUS_ERROR_ALLOCATION_FAILED,
GST_VAAPI_DECODER_STATUS_ERROR_INIT_FAILED,
GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN
};
/**
* GstVaapiDecoder:
*
* A VA decoder base instance.
*/
struct _GstVaapiDecoder {
/*< private >*/
GObject parent_instance;
GstVaapiDecoderPrivate *priv;
};
/**
* GstVaapiDecoderClass:
* @decode: decode one frame.
*
* A VA decoder base class.
*/
struct _GstVaapiDecoderClass {
/*< private >*/
GObjectClass parent_class;
GstVaapiDecoderStatus (*decode)(GstVaapiDecoder *decoder);
};
GType
gst_vaapi_decoder_get_type(void);
gboolean
gst_vaapi_decoder_put_buffer_data(
GstVaapiDecoder *decoder,
const guchar *buf,
guint buf_size
);
gboolean
gst_vaapi_decoder_put_buffer_data_copy(
GstVaapiDecoder *decoder,
const guchar *buf,
guint buf_size
);
gboolean
gst_vaapi_decoder_put_buffer(GstVaapiDecoder *decoder, GstBuffer *buf);
GstVaapiSurfaceProxy *
gst_vaapi_decoder_get_surface(
GstVaapiDecoder *decoder,
GstVaapiDecoderStatus *pstatus
);
GstVaapiSurfaceProxy *
gst_vaapi_decoder_timed_get_surface(
GstVaapiDecoder *decoder,
guint32 timeout,
GstVaapiDecoderStatus *pstatus
);
G_END_DECLS
#endif /* GST_VAAPI_DECODER_H */
This diff is collapsed.
/*
* gstvaapidecoder_ffmpeg.h - FFmpeg-based decoder
*
* gstreamer-vaapi (C) 2010 Splitted-Desktop Systems
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef GST_VAAPI_DECODER_FFMPEG_H
#define GST_VAAPI_DECODER_FFMPEG_H
#include <gst/vaapi/gstvaapidecoder.h>
G_BEGIN_DECLS
#define GST_VAAPI_TYPE_DECODER_FFMPEG \
(gst_vaapi_decoder_ffmpeg_get_type())
#define GST_VAAPI_DECODER_FFMPEG(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
GST_VAAPI_TYPE_DECODER_FFMPEG, \
GstVaapiDecoderFfmpeg))
#define GST_VAAPI_DECODER_FFMPEG_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), \
GST_VAAPI_TYPE_DECODER_FFMPEG, \
GstVaapiDecoderFfmpegClass))
#define GST_VAAPI_IS_DECODER_FFMPEG(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_DECODER_FFMPEG))
#define GST_VAAPI_IS_DECODER_FFMPEG_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_DECODER_FFMPEG))
#define GST_VAAPI_DECODER_FFMPEG_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), \
GST_VAAPI_TYPE_DECODER_FFMPEG, \
GstVaapiDecoderFfmpegClass))
typedef struct _GstVaapiDecoderFfmpeg GstVaapiDecoderFfmpeg;
typedef struct _GstVaapiDecoderFfmpegPrivate GstVaapiDecoderFfmpegPrivate;
typedef struct _GstVaapiDecoderFfmpegClass GstVaapiDecoderFfmpegClass;
/**
* GstVaapiDecoderFfmpeg:
*
* A decoder based on FFmpeg.
*/
struct _GstVaapiDecoderFfmpeg {
/*< private >*/
GstVaapiDecoder parent_instance;
GstVaapiDecoderFfmpegPrivate *priv;
};
/**
* GstVaapiDecoderFfmpegClass:
*
* A decoder class based on FFmpeg.
*/
struct _GstVaapiDecoderFfmpegClass {
/*< private >*/
GstVaapiDecoderClass parent_class;
};
GType
gst_vaapi_decoder_ffmpeg_get_type(void);
GstVaapiDecoder *
gst_vaapi_decoder_ffmpeg_new(GstVaapiDisplay *display, GstVaapiCodec codec);
G_END_DECLS
#endif /* GST_VAAPI_DECODER_FFMPEG_H */
/*
* gstvaapidecoder_priv.h - VA decoder abstraction (private definitions)
*
* gstreamer-vaapi (C) 2010 Splitted-Desktop Systems
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef GST_VAAPI_DECODER_PRIV_H
#define GST_VAAPI_DECODER_PRIV_H
#include <glib.h>
#include <gst/base/gstadapter.h>
#include <gst/vaapi/gstvaapidecoder.h>
#include <gst/vaapi/gstvaapicontext.h>
G_BEGIN_DECLS
#define GST_VAAPI_DECODER_CAST(decoder) ((GstVaapiDecoder *)(decoder))
/**
* GST_VAAPI_DECODER_DISPLAY:
* @decoder: a #GstVaapiDecoder
*
* Macro that evaluates to the #GstVaapiDisplay of @decoder.
* This is an internal macro that does not do any run-time type check.
*/
#undef GST_VAAPI_DECODER_DISPLAY
#define GST_VAAPI_DECODER_DISPLAY(decoder) \
GST_VAAPI_DECODER_CAST(decoder)->priv->display
/**
* GST_VAAPI_DECODER_CONTEXT:
* @decoder: a #GstVaapiDecoder
*
* Macro that evaluates to the #GstVaapiContext of @decoder.
* This is an internal macro that does not do any run-time type check.
*/
#undef GST_VAAPI_DECODER_CONTEXT
#define GST_VAAPI_DECODER_CONTEXT(decoder) \
GST_VAAPI_DECODER_CAST(decoder)->priv->context
/**
* GST_VAAPI_DECODER_CODEC:
* @decoder: a #GstVaapiDecoder
*
* Macro that evaluates to the #GstVaapiCodec of @decoder.
* This is an internal macro that does not do any run-time type check.
*/
#undef GST_VAAPI_DECODER_CODEC
#define GST_VAAPI_DECODER_CODEC(decoder) \
GST_VAAPI_DECODER_CAST(decoder)->priv->codec
#define GST_VAAPI_DECODER_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), \
GST_VAAPI_TYPE_DECODER, \
GstVaapiDecoderPrivate))
struct _GstVaapiDecoderPrivate {
GstVaapiDisplay *display;
GstVaapiContext *context;
GstVaapiCodec codec;
GstAdapter *adapter;
GMutex *adapter_mutex;
GCond *adapter_cond;
GQueue surfaces;
GMutex *surfaces_mutex;
GCond *surfaces_cond;
GThread *decoder_thread;
guint decoder_thread_cancel : 1;
};
gboolean
gst_vaapi_decoder_ensure_context(
GstVaapiDecoder *decoder,
GstVaapiProfile profile,
GstVaapiEntrypoint entrypoint,
guint width,
guint height
) attribute_hidden;
guint
gst_vaapi_decoder_copy(
GstVaapiDecoder *decoder,
guint offset,
guchar *buf,
guint buf_size
) attribute_hidden;
guint
gst_vaapi_decoder_read_avail(GstVaapiDecoder *decoder)
attribute_hidden;
guint
gst_vaapi_decoder_read(GstVaapiDecoder *decoder, guchar *buf, guint buf_size)
attribute_hidden;
void
gst_vaapi_decoder_flush(GstVaapiDecoder *decoder, guint buf_size)
attribute_hidden;
gboolean
gst_vaapi_decoder_push_surface(
GstVaapiDecoder *decoder,
GstVaapiSurface *surface
) attribute_hidden;
G_END_DECLS
#endif /* GST_VAAPI_DECODER_PRIV_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment