Simplify GstVaapiDecoder API.

This commit is contained in:
gb 2010-05-03 20:55:17 +00:00 committed by Gwenole Beauchesne
parent 5128ed9951
commit 73766f9466
3 changed files with 11 additions and 158 deletions

View file

@ -38,7 +38,7 @@
G_DEFINE_TYPE(GstVaapiDecoder, gst_vaapi_decoder, G_TYPE_OBJECT);
/* XXX: Make it a GstVaapiDecodedSurface + propagate PTS */
/* XXX: Make it a GstVaapiDecodedSurface? */
typedef struct _DecodedSurface DecodedSurface;
struct _DecodedSurface {
GstVaapiSurfaceProxy *proxy;
@ -78,31 +78,6 @@ create_eos_buffer(void)
return buffer;
}
static GstBuffer *
create_buffer(const guchar *buf, guint buf_size, gboolean copy)
{
GstBuffer *buffer;
if (!buf || !buf_size)
return NULL;
buffer = gst_buffer_new();
if (!buffer)
return NULL;
if (copy) {
buffer->malloc_data = g_malloc(buf_size);
if (!buffer->malloc_data) {
gst_buffer_unref(buffer);
return NULL;
}
memcpy(buffer->malloc_data, buf, buf_size);
buf = buffer->malloc_data;
}
init_buffer(buffer, buf, buf_size);
return buffer;
}
static void
destroy_buffer(GstBuffer *buffer)
{
@ -410,108 +385,6 @@ gst_vaapi_decoder_init(GstVaapiDecoder *decoder)
priv->surfaces = g_queue_new();
}
/**
* gst_vaapi_decoder_get_frame_rate:
* @decoder: a #GstVaapiDecoder
* @num: return location for the numerator of the frame rate
* @den: return location for the denominator of the frame rate
*
* Retrieves the current frame rate as the fraction @num / @den. The
* default frame rate is 30 fps.
*/
void
gst_vaapi_decoder_get_frame_rate(
GstVaapiDecoder *decoder,
guint *num,
guint *den
)
{
g_return_if_fail(GST_VAAPI_IS_DECODER(decoder));
if (num)
*num = decoder->priv->fps_n;
if (den)
*den = decoder->priv->fps_d;
}
/**
* gst_vaapi_decoder_set_frame_rate:
* @decoder: a #GstVaapiDecoder
* @num: the numerator of the frame rate
* @den: the denominator of the frame rate
*
* Sets the frame rate for the stream to @num / @den. By default, the
* decoder will use the frame rate encoded in the elementary stream.
* If none is available, the decoder will default to 30 fps.
*/
void
gst_vaapi_decoder_set_frame_rate(
GstVaapiDecoder *decoder,
guint num,
guint den
)
{
g_return_if_fail(GST_VAAPI_IS_DECODER(decoder));
decoder->priv->fps_n = num;
decoder->priv->fps_d = den;
}
/**
* gst_vaapi_decoder_put_buffer_data:
* @decoder: a #GstVaapiDecoder
* @buf: pointer to buffer data
* @buf_size: size of buffer data in bytes
*
* Queues @buf_size bytes from the data @buf to the HW decoder. The
* caller is responsible for making sure @buf is live beyond this
* function. So, this function is mostly useful with static data
* buffers. gst_vaapi_decoder_put_buffer_data_copy() does the same but
* copies the data.
*
* Caller can notify an End-Of-Stream with @buf set to %NULL and
* @buf_size set to zero.
*
* Return value: %TRUE on success
*/
gboolean
gst_vaapi_decoder_put_buffer_data(
GstVaapiDecoder *decoder,
const guchar *buf,
guint buf_size
)
{
g_return_val_if_fail(GST_VAAPI_IS_DECODER(decoder), FALSE);
return push_buffer(decoder, create_buffer(buf, buf_size, FALSE));
}
/**
* gst_vaapi_decoder_put_buffer_data_copy:
* @decoder: a #GstVaapiDecoder
* @buf: pointer to buffer data
* @buf_size: size of buffer data in bytes
*
* Queues a copy of @buf to the HW decoder.
*
* Caller can notify an End-Of-Stream with @buf set to %NULL and
* @buf_size set to zero.
*
* Return value: %TRUE on success
*/
gboolean
gst_vaapi_decoder_put_buffer_data_copy(
GstVaapiDecoder *decoder,
const guchar *buf,
guint buf_size
)
{
g_return_val_if_fail(GST_VAAPI_IS_DECODER(decoder), FALSE);
return push_buffer(decoder, create_buffer(buf, buf_size, TRUE));
}
/**
* gst_vaapi_decoder_put_buffer:
* @decoder: a #GstVaapiDecoder

View file

@ -109,34 +109,6 @@ struct _GstVaapiDecoderClass {
GType
gst_vaapi_decoder_get_type(void);
void
gst_vaapi_decoder_get_frame_rate(
GstVaapiDecoder *decoder,
guint *num,
guint *den
);
void
gst_vaapi_decoder_set_frame_rate(
GstVaapiDecoder *decoder,
guint num,
guint den
);
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);

View file

@ -82,6 +82,7 @@ main(int argc, char *argv[])
GstStructure *structure;
GstVaapiDecoderStatus status;
const CodecDefs *codec;
GstBuffer *buffer;
GstVaapiSurfaceProxy *proxy;
VideoDecodeInfo info;
@ -128,9 +129,17 @@ main(int argc, char *argv[])
decoder = gst_vaapi_decoder_ffmpeg_new_from_caps(display, decoder_caps);
if (!decoder)
g_error("could not create FFmpeg decoder");
gst_caps_unref(decoder_caps);
if (!gst_vaapi_decoder_put_buffer_data(decoder, info.data, info.data_size))
buffer = gst_buffer_new();
if (!buffer)
g_error("could not create encoded data buffer");
gst_buffer_set_data(buffer, (guchar *)info.data, info.data_size);
if (!gst_vaapi_decoder_put_buffer(decoder, buffer))
g_error("could not send video data to the decoder");
gst_buffer_unref(buffer);
if (!gst_vaapi_decoder_put_buffer(decoder, NULL))
g_error("could not send EOS to the decoder");
@ -150,7 +159,6 @@ main(int argc, char *argv[])
pause();
g_object_unref(proxy);
gst_caps_unref(decoder_caps);
g_object_unref(decoder);
g_object_unref(window);
g_object_unref(display);