4 years agoplugins: don't apply overlay composition in GLTextureUpload function.
Matthieu Bouron [Thu, 9 Jan 2014 11:54:11 +0000 (11:54 +0000)]
plugins: don't apply overlay composition in GLTextureUpload function.

The GLTextureUpload function is not in charge of doing the overlay
composition if any.

Signed-off-by: Gwenole Beauchesne <>
4 years agoencoder: re-order submission of VA objects.
Gwenole Beauchesne [Tue, 14 Jan 2014 12:47:52 +0000 (13:47 +0100)]
encoder: re-order submission of VA objects.

Change the submission order of VA objects so that to make that process
more logical. i.e. submit sequence parameter first, if any; next the
packed headers associated to sequece, picture or slices; and finally
the actual picture and associated slices.

4 years agoencoder: clean-up objects.
Gwenole Beauchesne [Tue, 14 Jan 2014 11:01:11 +0000 (12:01 +0100)]
encoder: clean-up objects.

Various clean-ups to improve consistency and readability: rename some
variables, drop unused macro definitions, drop initialization of vars
that are zero-initialized from the base class, drop un-necessary casts,
allocate GPtrArrays with a destroy function.

4 years agoencoder: h264: fix frame cropping rectangle calculation.
Gwenole Beauchesne [Mon, 13 Jan 2014 12:41:35 +0000 (13:41 +0100)]
encoder: h264: fix frame cropping rectangle calculation.

Fix frame cropping rectangle calculation to handle horizontal resolutions
that don't match a multiple of 16 pixels, but also the vertical resolution
that was incorrectly computed for progressive sequences too.

4 years agoencoder: h264: improve automatic bitrate calculation.
Gwenole Beauchesne [Mon, 13 Jan 2014 10:49:14 +0000 (11:49 +0100)]
encoder: h264: improve automatic bitrate calculation.

For non "Constant-QP" modes, we could provide more reasonable heuristics
for the target bitrate. In general, 48 bits per macroblock with all the
useful coding tools enable looks safe enough. Then, this rate is raised
by +10% to +15% for each coding tool that is disabled.

4 years agoencoder: h264: support "high-compression" tuning option.
Gwenole Beauchesne [Mon, 13 Jan 2014 10:11:25 +0000 (11:11 +0100)]
encoder: h264: support "high-compression" tuning option.

Add support for "high-compression" tuning option. First, determine the
largest supported profile by the hardware. Next, check any target limit
set by the user. Then, enable each individual coding tool based on the
resulting profile_idc value to use.

4 years agoencoder: h264: allow target decoder constraints.
Gwenole Beauchesne [Sun, 12 Jan 2014 21:24:04 +0000 (22:24 +0100)]
encoder: h264: allow target decoder constraints.

Allow user to precise the largest profile to use for encoding due
to target decoder constraints. For instance, if CABAC entropy coding
mode is requested by "constrained-baseline" profile only is desired,
then an error is returned during codec configuration.

Also make sure that the suitable profile we derived actually matches
what the HW can cope with.

4 years agoencoder: h264: refine size of coded buffer.
Gwenole Beauchesne [Sun, 12 Jan 2014 21:14:11 +0000 (22:14 +0100)]
encoder: h264: refine size of coded buffer.

Refine the heuristic to determine the maximum size of a coded buffer
to account for the exact number of slices. set_context_info() is the
last step during codec reconfiguration, no additional change is done
afterwards, so re-using the num_slices field here is fine.

4 years agoencoder: h264: expose more coding tools.
Wind Yuan [Fri, 13 Dec 2013 09:36:08 +0000 (17:36 +0800)]
encoder: h264: expose more coding tools.

Add new H.264 coding tools to improve compression:
- "cabac": enable CABAC entropy coding (default: FALSE);
- "dct8x8": enable spatial transform 8x8 (default: FALSE).

Signed-off-by: Gwenole Beauchesne <>
4 years agoencoder: h264: derive profile and level from active coding tools.
Gwenole Beauchesne [Fri, 10 Jan 2014 17:18:25 +0000 (18:18 +0100)]
encoder: h264: derive profile and level from active coding tools.

Automatically derive the minimum profile and level to be used for
encoding, based on the activated coding tools. The encoder will
be trying to generate a bitstream that has the best chances to be
decoded on most platforms by default.

Also change the default profile to "constrained-baseline" so that
to ensure maximum compatibility when the stream is decoded.

4 years agoencoder: h264: fix hardware profile lookup.
Gwenole Beauchesne [Fri, 10 Jan 2014 16:02:44 +0000 (17:02 +0100)]
encoder: h264: fix hardware profile lookup.

Fix lookup for a suitable HW profile, as to be used by the underlying
hardware, based on heuristics that lead to characterize the SW profile,
i.e. the one used by the SW level encoding logic.

Also fix constraint_set0_flag (A.2.1) and constraint_set1_flag (A.2.2)
as they should respectively match the baseline and main profile.

4 years agoencoder: h264: support only the byte-stream format.
Gwenole Beauchesne [Fri, 10 Jan 2014 13:46:15 +0000 (14:46 +0100)]
encoder: h264: support only the byte-stream format.

The libgstvaapi core encoders are meant to support raw bitstreams only.
Henceforth, we are always producing a stream in "byte-stream" format.

However, the "codec-data" buffer which holds SPS and PPS headers is
always available. The "lengthSizeMinusOne" field is always set to 3
so that in-place "byte-stream" format to "avc" format conversion could
be performed.

4 years agoencoder: h264: clean-ups.
Gwenole Beauchesne [Fri, 10 Jan 2014 13:05:40 +0000 (14:05 +0100)]
encoder: h264: clean-ups.

Various clean-ups to improve consistency and readability: rename some
variables, drop unused macro definitions, drop initialization of vars
that are zero-initialized from the base class, drop un-necessary casts.

4 years agoencoder: mpeg2: fix hardware profile lookup.
Gwenole Beauchesne [Mon, 13 Jan 2014 16:11:15 +0000 (17:11 +0100)]
encoder: mpeg2: fix hardware profile lookup.

Fix lookup for a suitable HW profile, as to be used by the underlying
hardware, based on heuristics that lead to characterize the SW profile,
i.e. the one used by the SW level encoding logic.

4 years agoencoder: mpeg2: derive profile and level from active coding tools.
Gwenole Beauchesne [Mon, 13 Jan 2014 15:56:04 +0000 (16:56 +0100)]
encoder: mpeg2: derive profile and level from active coding tools.

Automatically derive the minimum profile and level to be used for
encoding, based on the activated coding tools. Improve lookup for
the best suitable level with the new MPEG-2 helper functions.

Also change the default profile to "simple" so that to ensure maximum
compatibility when the stream is decoded.

4 years agoencoder: mpeg2: clean-ups.
Gwenole Beauchesne [Mon, 13 Jan 2014 13:41:15 +0000 (14:41 +0100)]
encoder: mpeg2: clean-ups.

Various clean-ups to improve consistency and readability: drop unused
macro definitions, drop initialization of vars that are zero-initialized
from the base class, drop un-necessary casts.

4 years agoencoder: add tuning options API.
Gwenole Beauchesne [Mon, 13 Jan 2014 09:48:25 +0000 (10:48 +0100)]
encoder: add tuning options API.

Add encoder "tune" option to override the default behaviour that is to
favor maximum decoder compatibility at the expense of lower compression

Expected tuning options to be developed are:
- "high-compression": improve compression, target best-in-class decoders;
- "low-latency": tune for low-latency decoding;
- "low-power": tune for encoding in low power / resources conditions.

4 years agoencoder: fix bitrate units to match kbps.
Gwenole Beauchesne [Sun, 12 Jan 2014 22:17:14 +0000 (23:17 +0100)]
encoder: fix bitrate units to match kbps.

Bitrate is expressed in kilobits per second (kbps). So, this exactly
means in multiple of 1000 bits, not 1024 bits.

4 years agoencoder: clean-ups.
Gwenole Beauchesne [Sun, 12 Jan 2014 20:57:20 +0000 (21:57 +0100)]
encoder: clean-ups.

Drop obsolete and unused macros. Add a few doc comments. Slightly
improve indentation of a few leftovers.

4 years agoencoder: filter out the supported set of rate-control properties.
Gwenole Beauchesne [Sun, 12 Jan 2014 17:52:14 +0000 (18:52 +0100)]
encoder: filter out the supported set of rate-control properties.

Only expose the exact static set of supported rate-control properties
to the upper layer. For instance, if the GstVaapiEncoderXXX class does
only support CQP rate control, then only add it the the exposed enum

Add helper macros and functions to build a GType for an enum subset.

4 years agoencoder: add keyframe period API.
Gwenole Beauchesne [Fri, 10 Jan 2014 12:23:48 +0000 (13:23 +0100)]
encoder: add keyframe period API.

Add gst_vaapi_encoder_set_keyframe_period() interface to allow the
user control the maximum distance between two keyframes. This new
property can only be set prior to gst_vaapi_encoder_set_codec_state().

A value of zero for "keyframe-period" gets it re-evaluated to the
actual framerate during encoder reconfiguration.

4 years agoencoder: improve codec reconfiguration.
Gwenole Beauchesne [Fri, 10 Jan 2014 11:01:51 +0000 (12:01 +0100)]
encoder: improve codec reconfiguration.

Improve codec reconfiguration to be performed only through a single
function. That is, remove the _set_context_info() hook as subclass
should not alter the parent GstVaapiContextInfo itself. Besides, the
VA context is constructed only at the final stages of reconfigure().

4 years agoencoder: fix possible memory leak of coded buffer pools.
Gwenole Beauchesne [Fri, 10 Jan 2014 10:30:25 +0000 (11:30 +0100)]
encoder: fix possible memory leak of coded buffer pools.

Fix gst_vaapi_encoder_reconfigure_internal() to re-/allocate the coded
buffer pool only if the coded buffer size actually changed.

4 years agoencoder: add video codec-state API.
Gwenole Beauchesne [Fri, 10 Jan 2014 09:54:22 +0000 (10:54 +0100)]
encoder: add video codec-state API.

Add interface to communicate the encoder resolution and related info
like framerate, interlaced vs. progressive, etc. This new interface
supersedes gst_vaapi_encoder_set_format() and doesn't use any GstCaps
but rather use GstVideoCodecState.

Note that gst_vaapi_encoder_set_codec_state() is also a synchronization
point for codec config. This means that the encoder is reconfigured
there to match the latest properties.

4 years agovaapiencode: don't crash on NULL encoder on _finish().
Gwenole Beauchesne [Mon, 13 Jan 2014 16:18:42 +0000 (17:18 +0100)]
vaapiencode: don't crash on NULL encoder on _finish().

Don't try to destroy an encoder, in GstVideoEncoder::finish() handler,
if it was not created in the first place. Return "not-negotiated" error
since this means we did not even reach GstVideoEncoder::set_format(),
where the encoder could have been created.

This fixes a crash when the vaapiencode_* plug-in elements get deallocated
and that we failed to negotiate either pad.

4 years agovaapiencode: use more GstVaapiPluginBase facilities.
Gwenole Beauchesne [Thu, 9 Jan 2014 17:20:24 +0000 (18:20 +0100)]
vaapiencode: use more GstVaapiPluginBase facilities.

Avoid duplication of pad references or query functions since they are
provided through the GstVaapiPluginBase object.

4 years agovaapiencode: fix negotiation process of output caps.
Gwenole Beauchesne [Thu, 9 Jan 2014 17:10:35 +0000 (18:10 +0100)]
vaapiencode: fix negotiation process of output caps.

The specified caps in gst_video_encoder_set_output_state() function
arguments should not contain any resolution, pixel-aspect-ratio,
framerate, codec-data et al. Those rather should be set through the
returned GstVideoCodecState. This means that output caps creation
could be delayed until before gst_video_encoder_finish_frame() is

This greatly simplifies the GstVideoEncoder::set_format() callback
by the way.

4 years agovaapiencode: make GstVaapiEncode an abstract type.
Gwenole Beauchesne [Wed, 8 Jan 2014 17:56:23 +0000 (18:56 +0100)]
vaapiencode: make GstVaapiEncode an abstract type.

Make base GstVaapiEncode class an abstract type so that we cannot
create an instance from it without going through any of the codec
specific derived class.

4 years agovaapiencode: rename a few member functions.
Gwenole Beauchesne [Thu, 9 Jan 2014 09:09:38 +0000 (10:09 +0100)]
vaapiencode: rename a few member functions.

Rename a few member functions to make them more consistent:
- alloc_encoder(): now reduced to allocate the encoder object only;
- alloc_buffer(): allocate buffer from srcpad, and copy bitstream.

4 years agovaapiencode: update for new properties API.
Gwenole Beauchesne [Wed, 8 Jan 2014 17:36:46 +0000 (18:36 +0100)]
vaapiencode: update for new properties API.

Update MPEG-2 and H.264 encode elements to cope with the new core
libgstvaapi properties API. i.e. all configurable properties are now
directly handled at the GstVaapiEncoder level.

Besides, this also makes sure to not use or modify the GstVaapiEncoder
private definitions directly. Private data need to remain private.

4 years agoencoder: add properties API.
Gwenole Beauchesne [Mon, 6 Jan 2014 16:46:40 +0000 (17:46 +0100)]
encoder: add properties API.

Add interface to communicate configurable properties to the encoder.
This covers both the common ones (rate-control, bitrate), and the
codec specific properties.

4 years agoencoder: add bitrate API.
Gwenole Beauchesne [Mon, 6 Jan 2014 17:01:33 +0000 (18:01 +0100)]
encoder: add bitrate API.

Add gst_vaapi_encoder_set_bitrate() interface to allow the user control
the bitrate for encoding. Currently, changing this parameter is only
valid before the first frame is encoded. Should the value be modified

4 years agoencoder: add rate control API.
Gwenole Beauchesne [Mon, 6 Jan 2014 14:10:36 +0000 (15:10 +0100)]
encoder: add rate control API.

Add gst_vaapi_encoder_set_rate_control() interface to request a new
rate control mode for encoding. Changing the rate control mode is
only valid prior to encoding the very first frame. Afterwards, an
error ("operation-failed") is issued.

4 years agovaapiencode: fix indentation.
Gwenole Beauchesne [Fri, 3 Jan 2014 15:57:25 +0000 (16:57 +0100)]
vaapiencode: fix indentation.

4 years agoencoder: fix indentation.
Gwenole Beauchesne [Fri, 3 Jan 2014 15:57:09 +0000 (16:57 +0100)]
encoder: fix indentation.

4 years agoutils: add new MPEG-2 helper functions.
Gwenole Beauchesne [Mon, 13 Jan 2014 15:20:06 +0000 (16:20 +0100)]
utils: add new MPEG-2 helper functions.

Add various helper functions to convert profile, level, chroma formats
from gstreamer-vaapi world and the MPEG-2 specification world.

4 years agoutils: h264: don't use fatal asserts.
Gwenole Beauchesne [Fri, 10 Jan 2014 18:49:52 +0000 (19:49 +0100)]
utils: h264: don't use fatal asserts.

Replace g_assert() with a g_debug() so that to not make the program
abort when an unsupported value is supplied.

4 years agoutils: h264: add helpers for profile and level string mappings.
Gwenole Beauchesne [Fri, 10 Jan 2014 18:37:44 +0000 (19:37 +0100)]
utils: h264: add helpers for profile and level string mappings.

Add profile and level helper functions to convert to/from strings.

4 years agoutils: h264: expose levels in public header.
Gwenole Beauchesne [Fri, 10 Jan 2014 17:27:20 +0000 (18:27 +0100)]
utils: h264: expose levels in public header.

Instal <gst/vaapi/gstvaapiutils_h264.h> header but only expose the
H.264 levels in there. The additional helper functions are meant
to be private for now.

4 years agocodec: add helper macros to maintain object refcount.
Gwenole Beauchesne [Thu, 9 Jan 2014 08:27:40 +0000 (09:27 +0100)]
codec: add helper macros to maintain object refcount.

Add gst_vaapi_mini_object_{ref,unref,replace}() helper macros so that
to avoid explicit casts to GstVaapiMiniObject in all caller sites.

4 years agocodec: re-indent decoder objects.
Gwenole Beauchesne [Thu, 9 Jan 2014 08:30:49 +0000 (09:30 +0100)]
codec: re-indent decoder objects.

4 years agocodec: re-indent base codec objects.
Gwenole Beauchesne [Thu, 9 Jan 2014 08:10:21 +0000 (09:10 +0100)]
codec: re-indent base codec objects.

4 years agoplugins: do not free debug category in finalize method.
Matthieu Bouron [Fri, 3 Jan 2014 12:49:05 +0000 (12:49 +0000)]
plugins: do not free debug category in finalize method.

Fixes a crash when multiple vaapidecode elements are finalized since
the debug category is created once in the class init method.

This is a regression from git commit 7e58d60.

Signed-off-by: Gwenole Beauchesne <>
4 years agotests: simple-decoder: don't use deprecated g_thread_create().
Gwenole Beauchesne [Thu, 2 Jan 2014 10:35:30 +0000 (11:35 +0100)]
tests: simple-decoder: don't use deprecated g_thread_create().

Use g_thread_try_new() instead of the deprecated g_thread_create()
function. Provide compatibility glue for any GLib version < 2.31.2.

4 years agoFix printf()-like formats.
Gwenole Beauchesne [Thu, 2 Jan 2014 10:17:28 +0000 (11:17 +0100)]
Fix printf()-like formats.

Fix formts for various GST_DEBUG et al. invocations. More precisely,
make size_t arguments use the %zu format specifier accordingly; force
XID formats to be a 32-bit unsigned integer; and fix the format used
for gst_vaapi_create_surface_with_format() error cases since we have
been using strings nowadays.

4 years agoutils: format: drop unused helper functions.
Gwenole Beauchesne [Sat, 21 Dec 2013 06:38:14 +0000 (07:38 +0100)]
utils: format: drop unused helper functions.

The following helper functions are no longer used, thus are removed:
- gst_vaapi_video_format_from_structure()
- gst_vaapi_video_format_from_caps()
- gst_vaapi_video_format_to_caps()

4 years agoutils: re-indent GstVideoFormat related helpers.
Gwenole Beauchesne [Sat, 21 Dec 2013 06:29:50 +0000 (07:29 +0100)]
utils: re-indent GstVideoFormat related helpers.

4 years agodownload: use GstVideoInfo facilities to build output caps.
Gwenole Beauchesne [Sat, 21 Dec 2013 07:27:30 +0000 (08:27 +0100)]
download: use GstVideoInfo facilities to build output caps.

Use standard GstVideoInfo related functions to build the output caps,
thus directly preserving additional fields as needed, instead of
manually copying them over through gst_vaapi_append_surface_caps().

Also ensure that the input caps are fixated first.

4 years agoplugins: factor out construction of template caps.
Gwenole Beauchesne [Sat, 21 Dec 2013 09:41:22 +0000 (10:41 +0100)]
plugins: factor out construction of template caps.

Add new helper functions to build video template caps.
- gst_vaapi_video_format_new_template_caps():
  create GstCaps with size, frame rate and PAR to full range
- gst_vaapi_video_format_new_template_caps_from_list():
  try to create a "simplified" list from the supplied formats

4 years agoplugins: factor out construction of GValue from GstVideoFormat.
Gwenole Beauchesne [Sat, 21 Dec 2013 05:41:34 +0000 (06:41 +0100)]
plugins: factor out construction of GValue from GstVideoFormat.

Add new helper functions to build GValues from GstVideoFormat:
- gst_vaapi_value_set_format():
  build a GValue from the supplied video format
- gst_vaapi_value_set_format_list():
  build a GValue list from the supplied array of video formats

4 years agoplugins: re-indent common and video context creation utils.
Gwenole Beauchesne [Sat, 21 Dec 2013 05:22:30 +0000 (06:22 +0100)]
plugins: re-indent common and video context creation utils.

4 years agodisplay: don't use GstCaps for decode or encode profiles list.
Gwenole Beauchesne [Fri, 20 Dec 2013 14:31:14 +0000 (15:31 +0100)]
display: don't use GstCaps for decode or encode profiles list.

Replace gst_vaapi_display_get_{decode,encode}_caps() APIs with more
more convenient APIs that return an array of GstVaapiProfile instead
of GstCaps: gst_vaapi_display_get_{decode,encode}_profiles().

4 years agodisplay: don't use GstCaps for image or subpicture formats list.
Gwenole Beauchesne [Fri, 20 Dec 2013 14:15:05 +0000 (15:15 +0100)]
display: don't use GstCaps for image or subpicture formats list.

Replace gst_vaapi_display_get_{image,subpicture}_caps() APIs, that
returned GstCaps, with more convenient APIs that return an array of
GstVideoFormat: gst_vaapi_display_get_{image,subpicture}_formats().

4 years agodisplay: allocate queried resources on-demand.
Gwenole Beauchesne [Fri, 20 Dec 2013 13:01:45 +0000 (14:01 +0100)]
display: allocate queried resources on-demand.

Allocate the set of decoders or encoders on-demand, when they are
queried. Likewise for VA display attributes, image and subpicture

4 years agodisplay: re-indent all GstVaapiDisplay related source code.
Gwenole Beauchesne [Fri, 20 Dec 2013 12:27:07 +0000 (13:27 +0100)]
display: re-indent all GstVaapiDisplay related source code.

4 years agoutils: add helper functions to get codec or profile name.
Gwenole Beauchesne [Fri, 20 Dec 2013 15:04:19 +0000 (16:04 +0100)]
utils: add helper functions to get codec or profile name.

4 years agoplugins: fix permissions for certain files.
Gwenole Beauchesne [Fri, 20 Dec 2013 16:08:23 +0000 (17:08 +0100)]
plugins: fix permissions for certain files.

Drop the execute bit for gstvaapiuploader.c and gstvaapipostproc.[ch]

4 years agoplugins: implement GLTextureUploadMeta user data copy.
Matthieu Bouron [Thu, 12 Dec 2013 17:01:29 +0000 (17:01 +0000)]
plugins: implement GLTextureUploadMeta user data copy.

Makes the copies of a buffer reference their own GLTextureUploadMeta
user data and prevent the original buffer accessing already freed
memory if its copies has been released and freed.

[Propagate the original meta texture to the copy too]
Signed-off-by: Gwenole Beauchesne <>
4 years agoplugins: factor out support for raw YUV buffers on sink pads.
Gwenole Beauchesne [Tue, 17 Dec 2013 17:52:23 +0000 (18:52 +0100)]
plugins: factor out support for raw YUV buffers on sink pads.

Factor out propose_allocation() hooks, creation of video buffer pool
for the sink pad, conversion from raw YUV buffers to VA surface backed
buffers. Update vaapidecode, vaapiencode and vaapipostproc to cope
with the new GstVaapiPluginBase abilities.

4 years agoplugins: factor out pad caps.
Gwenole Beauchesne [Tue, 17 Dec 2013 17:46:07 +0000 (18:46 +0100)]
plugins: factor out pad caps.

4 years agoplugins: factor out video context sharing code.
Gwenole Beauchesne [Fri, 13 Dec 2013 15:03:08 +0000 (16:03 +0100)]
plugins: factor out video context sharing code.

4 years agoplugins: factor out GstImplementsInterface.
Gwenole Beauchesne [Fri, 13 Dec 2013 12:24:24 +0000 (13:24 +0100)]
plugins: factor out GstImplementsInterface.

4 years agoplugins: check type of display obtained from neighbours.
Gwenole Beauchesne [Fri, 13 Dec 2013 11:00:35 +0000 (12:00 +0100)]
plugins: check type of display obtained from neighbours.

Fix display creation code to check that any display obtained from a
neighbour actually has the type we expect. Note: if display type is
set to "any", we can then accept any VA display type.

4 years agoplugins: factor out display creation process.
Gwenole Beauchesne [Fri, 13 Dec 2013 10:52:47 +0000 (11:52 +0100)]
plugins: factor out display creation process.

Move common VA display creation code to GstVaapiPluginBase, with the
default display type remaining "any". Also add a "display-changed"
hook so that subclasses could perform additional tasks when/if the
VA display changed, due to a new display type request for instance.

All plug-ins are updated to cope with the new internal APIs.

4 years agoplugins: add new base object, store display in there.
Gwenole Beauchesne [Fri, 13 Dec 2013 09:24:26 +0000 (10:24 +0100)]
plugins: add new base object, store display in there.

Introduce a new GstVaapiPluginBase object that will contain all common
data structures and perform all common tasks. First step is to have a
single place to hold VA displays.

While we are at it, also make sure to store and subsequently release
the appropriate debug category for the subclasses.

4 years agoplugins: fix GLTextureUploadMeta to work with different texture ids.
Gwenole Beauchesne [Wed, 11 Dec 2013 13:04:27 +0000 (14:04 +0100)]
plugins: fix GLTextureUploadMeta to work with different texture ids.

The GLTextureUploadMeta implementation assumed that for each upload()
sequence, the supplied texture id is always the same as the one that
was previously cached into the underlying GstVaapiTexture. Cope with
any texture id change the expense to recreate the underlying VA/GLX

4 years agoplugins: allow builds without GLX enabled for GStreamer 1.2.
Gwenole Beauchesne [Wed, 11 Dec 2013 12:25:51 +0000 (13:25 +0100)]
plugins: allow builds without GLX enabled for GStreamer 1.2.

Don't try to build GLTextureUploadMeta related code if GLX is not
enabled during GStreamer >= 1.2 builds.

4 years agoplugins: request GLTextureUpload meta on buffers in the buffer pool.
Matthieu Bouron [Wed, 20 Nov 2013 17:20:07 +0000 (17:20 +0000)]
plugins: request GLTextureUpload meta on buffers in the buffer pool.

Requesting the GLTextureUpload meta on buffers in the bufferpool
prevents such metas from being de-allocated when buffers are released
in the sink.

This is particulary useful in terms of performance when using the
GLTextureUploadMeta API since the GstVaapiTexture associated with
the target texture is stored in the meta.

Signed-off-by: Gwenole Beauchesne <>
4 years agoplugins: robustify GstVideoGLTextureUploadMeta implementation.
Gwenole Beauchesne [Wed, 11 Dec 2013 09:51:03 +0000 (10:51 +0100)]
plugins: robustify GstVideoGLTextureUploadMeta implementation.

Make GstVideoGLTextureUploadMeta::upload() implementation more robust
when the GstVaapiTexture associated with the supplied texture id could
not be created.

4 years agoh264: improve robustness when packets are missing.
Gwenole Beauchesne [Tue, 10 Dec 2013 15:14:27 +0000 (16:14 +0100)]
h264: improve robustness when packets are missing.

Improve robustness when some expected packets where not received yet
or that were not correctly decoded. For example, don't try to decode
a picture if there was no valid frame headers parsed so far.

4 years agodecoder: h264: fix decoding of BA3_SVA_C.264.
Gwenole Beauchesne [Tue, 10 Dec 2013 13:20:55 +0000 (14:20 +0100)]
decoder: h264: fix decoding of BA3_SVA_C.264.

Conformance test Base_Ext_Main_profiles/BA3_SVA_C.264 complys with
extended profile specifications. However, the SPS header has the
constraint_set1_flag syntax element set to 1. This means that, if
a Main profile compliant decoder is available, then it should be
able to decode this stream.

This changes makes it possible to fall-back from Extended profile
to Main profile if constraint_set1_flag is set to 1.

4 years agoutils: h264: add more profiles.
Gwenole Beauchesne [Tue, 10 Dec 2013 10:13:01 +0000 (11:13 +0100)]
utils: h264: add more profiles.

Add extended profile (A.2.3), high 4:2:2 profile (A.2.6), high 4:2:2
profiles (A.2.7, A.2.10), scalable profiles (G.10.1.1, G.10.1.2) and
multiview profiles (H.10.1.1, H.10.1.2).

Document "Constrained Baseline" and "High 10" profiles.

4 years agocodecparsers: update to gst-vaapi-branch commit e7d0e18.
Gwenole Beauchesne [Tue, 10 Dec 2013 14:21:51 +0000 (15:21 +0100)]
codecparsers: update to gst-vaapi-branch commit e7d0e18.

e7d0e18 h264: complete set of NAL unit types

4 years agodecoder: h264: add support for constrained baseline profile.
Wind Yuan [Fri, 6 Dec 2013 07:08:26 +0000 (15:08 +0800)]
decoder: h264: add support for constrained baseline profile.

Recognize streams marked as conforming to the "Constrained Baseline
Profile". If VA driver supports that as is, fine. Otherwise, fallback
to baseline, main or high profile.

Constrained Baseline Profile conveys coding tools that are common
to baseline profile and main profile.

[Added fallbacks to main and high profiles]
Signed-off-by: Gwenole Beauchesne <>
4 years agodecoder: h264: fix decoding of scaling lists.
Gwenole Beauchesne [Mon, 9 Dec 2013 11:46:45 +0000 (12:46 +0100)]
decoder: h264: fix decoding of scaling lists.

The GStreamer codecparser layer now parses the scaling lists in zigzag
scan order, as expected, so that to match the original bitstream layout
and specification. However, further convert the scaling lists into
raster scan order to fit the existing practice in most VA drivers.

4 years agocodecparsers: update to gst-vaapi-branch commit 177c73b.
Gwenole Beauchesne [Mon, 9 Dec 2013 11:07:28 +0000 (12:07 +0100)]
codecparsers: update to gst-vaapi-branch commit 177c73b.

a7e3255 add H.265 (HEVC) bitstream parser
177c73b h264: fix picture level scaling lists derivation (rule B)
14733f1 h264: fix parsing of VCL HRD parameters
59a0b47 h264: store quantization matrices in zig-zag order
ffb6e26 h264: add helpers to convert quantization matrices
c78a504 mpeg2: also initialize debug category in parse_sequence_header()
719d1b0 mpeg2: turn internal consistency check into a g_assert()
5241d8e all: remove some unused functions
18eb312 all: fix for GST_DISABLE_GST_DEBUG
963c04a all: make warnings more meaningful

4 years agoutils: add helpers for H.264 levels.
Gwenole Beauchesne [Fri, 6 Dec 2013 18:05:52 +0000 (19:05 +0100)]
utils: add helpers for H.264 levels.

- gst_vaapi_utils_h264_get_level():
  Returns GstVaapiLevelH264 from H.264 level_idc value
- gst_vaapi_utils_h264_get_level_idc():
  Returns H.264 level_idc value from GstVaapiLevelH264
- gst_vaapi_utils_h264_get_level_limits():
  Returns level limits as specified in Table A-1 of the H.264 standard
- gst_vaapi_utils_h264_get_level_limits_table():
  Returns the Table A-1 specification

4 years agoutils: add new H.264 profiles.
Gwenole Beauchesne [Fri, 6 Dec 2013 16:34:52 +0000 (17:34 +0100)]
utils: add new H.264 profiles.

Add "Constrained Baseline Profile" and "High 10 Profile" definitions
and helper functiions.

4 years agoutils: add new H.264 helper functions.
Gwenole Beauchesne [Fri, 6 Dec 2013 16:21:52 +0000 (17:21 +0100)]
utils: add new H.264 helper functions.

* Profiles:
- gst_vaapi_utils_h264_get_profile():
  Returns GstVaapiProfile from H.264 profile_idc value
- gst_vaapi_utils_h264_get_profile_idc():
  Returns H.264 profile_idc value from GstVaapiProfile

* Chroma formats:
- gst_vaapi_utils_h264_get_chroma_type():
  Returns GstVaapiChromaType from H.264 chroma_format_idc value
- gst_vaapi_utils_h264_get_chroma_format_idc():
  Returns H.264 chroma_format_idc value from GstVaapiChromaType

4 years agoFix missing files in distribution tarball.
Matthieu Bouron [Tue, 3 Dec 2013 11:05:17 +0000 (11:05 +0000)]
Fix missing files in distribution tarball.

[Additional fixes and clean-ups]
Signed-off-by: Gwenole Beauchesne <>
4 years agoencoder: fix computation of max coded buffer size (again).
Gwenole Beauchesne [Thu, 5 Dec 2013 17:13:54 +0000 (18:13 +0100)]
encoder: fix computation of max coded buffer size (again).

The previous fix was only valid to express the maximum size of the
macroblock layer, i.e. without any headers. Now, also account for
the slice headers and top picture header, but also any other header
we might stuff into the VA coded buffer, e.g. sequence headers.

4 years agoencoder: fix computation of max coded buffer size.
Gwenole Beauchesne [Wed, 4 Dec 2013 18:10:13 +0000 (19:10 +0100)]
encoder: fix computation of max coded buffer size.

Fix coded buffer size for each codec. A generic issue was that the
number of macroblocks was incorrectly computed. The second issue was
specific to MPEG-2 were the max number of bits per macroblock, and
as defined by the standard, was incorrectly mapped to the (lower)
H.264 requirement. i.e. 4608 bits vs. 3200 bits limit.

4 years agoencoder: simplify VA context initialization process.
Gwenole Beauchesne [Wed, 4 Dec 2013 17:48:35 +0000 (18:48 +0100)]
encoder: simplify VA context initialization process.

Change get_context_info() into a set_context_info() function that
initializes common defaults into the base class, thus allowing the
subclasses to specialize the context info further on.

The set_context_info() hook is also the location where additional
context specific data could be initialized. At this point, we are
guaranteed to have valid video resolution size and framerate. i.e.
gst_vaapi_encoder_set_format() was called beforehand.

4 years agoencoder: fix mpeg2 compilation error.
Wind Yuan [Tue, 26 Nov 2013 06:38:23 +0000 (14:38 +0800)]
encoder: fix mpeg2 compilation error.

Signed-off-by: Gwenole Beauchesne <>
4 years agoencoder: clean-ups and document public APIs.
Gwenole Beauchesne [Wed, 4 Dec 2013 16:55:18 +0000 (17:55 +0100)]
encoder: clean-ups and document public APIs.

Clean public APIs up so that to better align with the decoder APIs.
Most importantly, gst_vaapi_encoder_get_buffer() is changed to only
return the VA coded buffer proxy. Also provide useful documentation
for the public APIs.

4 years agoencoder: avoid extra allocations of GstVaapiEncoderSyncPic objects.
Gwenole Beauchesne [Wed, 4 Dec 2013 16:05:17 +0000 (17:05 +0100)]
encoder: avoid extra allocations of GstVaapiEncoderSyncPic objects.

Kill GstVaapiEncoderSyncPic objects that are internally and temporarily
allocated. Rather, associate a GstVaapiEncPicture to a coded buffer
through GstVaapiCodedBufferProxy user-data facility.

Besides, use a GAsyncQueue to maintain a thread-safe queue object of
coded buffers.

Partial fix for the following report:

4 years agoencoder: refactor status codes.
Gwenole Beauchesne [Tue, 3 Dec 2013 16:04:43 +0000 (17:04 +0100)]
encoder: refactor status codes.

Drop obsolete or unused status codes. Align some status codes with the
decoder counterparts.

4 years agoencoder: fix subclassing process.
Gwenole Beauchesne [Wed, 4 Dec 2013 10:54:40 +0000 (11:54 +0100)]
encoder: fix subclassing process.

Fix the GstVaapiEncoderClass parent class type. Make sure to validate
subclass hooks as early as possible, i.e. in gst_vaapi_encoder_init(),
thus avoiding useless run-time checks. Also simplify the subclass
initialization process to be less error prone.

4 years agoencoder: rework GstVaapiCodedBuffer and related proxy.
Gwenole Beauchesne [Tue, 3 Dec 2013 15:11:46 +0000 (16:11 +0100)]
encoder: rework GstVaapiCodedBuffer and related proxy.

Refactor the GstVaapiCodedBuffer APIs so that to more clearly separate
public and private interfaces. Besides, the map/unmap APIs should not
be exposed as is but appropriate accessors should be provided instead.

* GstVaapiCodedBuffer: VA coded buffer abstraction
- gst_vaapi_coded_buffer_get_size(): get coded buffer size.
- gst_vaapi_coded_buffer_copy_into(): copy coded buffer into GstBuffer

* GstVaapiCodedBufferPool: pool of VA coded buffer objects
- gst_vaapi_coded_buffer_pool_new(): create a pool of coded buffers of
  the specified max size, and bound to the supplied encoder

* GstVaapiCodedBufferProxy: pool-allocated VA coded buffer object proxy
- gst_vaapi_coded_buffer_proxy_new_from_pool(): create coded buf from pool
- gst_vaapi_coded_buffer_proxy_get_buffer(): get underlying coded buffer
- gst_vaapi_coded_buffer_proxy_get_buffer_size(): get coded buffer size

Rationale: more optimized transfer functions might be provided in the
future, thus rendering the map/unmap mechanism obsolete or sub-optimal.

4 years agoplugins: fix reference leaks of VA display objects.
Gwenole Beauchesne [Fri, 29 Nov 2013 13:02:52 +0000 (14:02 +0100)]
plugins: fix reference leaks of VA display objects.

Fix GstElement::set_context() implementation for all plug-in elements
to avoid leaking an extra reference to the VA display, thus preventing
correct cleanup of VA resources in GStreamer 1.2 builds.

4 years agoplugins: simplify gst_vaapi_ensure_display().
Gwenole Beauchesne [Fri, 29 Nov 2013 12:56:12 +0000 (13:56 +0100)]
plugins: simplify gst_vaapi_ensure_display().

Return earlier if the creation of a VA display failed. Likewise, simplify
gst_vaapi_video_context_propagate() now that we are guaranteed to have a
valid VA display.

4 years agoplugins: fix memory leaks through GstVideoMeta maps.
Gwenole Beauchesne [Thu, 28 Nov 2013 18:08:28 +0000 (19:08 +0100)]
plugins: fix memory leaks through GstVideoMeta maps.

When GstVideoMeta maps were used, the supporting functions incorrectly
used gst_buffer_get_memory() instead of gst_buffer_peek_memory(), thus
always increasing the associated GstMemory reference count and giving
zero chance to actually release that, and subsequently the VA display.

4 years agoplugins: use G_PARAM_STATIC_STRINGS.
Gwenole Beauchesne [Thu, 28 Nov 2013 13:15:44 +0000 (14:15 +0100)]

This avoids a few string copies during initialization.

4 years agoplugins: simplify VA video meta to only reference surface proxies.
Gwenole Beauchesne [Thu, 28 Nov 2013 16:28:11 +0000 (17:28 +0100)]
plugins: simplify VA video meta to only reference surface proxies.

Simplify GstVaapiVideoMeta to only hold a surface proxy, which is
now allocated from a surface pool. This also means that the local
reference to the VA surface is also gone, as it could be extracted
from the associated surface proxy.

4 years agoplugins: drop obsolete functions.
Gwenole Beauchesne [Thu, 28 Nov 2013 15:51:37 +0000 (16:51 +0100)]
plugins: drop obsolete functions.

Drop the following functions that are not longer used:
- gst_vaapi_video_buffer_new_with_surface()
- gst_vaapi_video_meta_new_with_surface()
- gst_vaapi_video_meta_set_surface()
- gst_vaapi_video_meta_set_surface_from_pool()

4 years agoplugins: allow VA video meta to be allocated from surface proxy pools.
Gwenole Beauchesne [Thu, 28 Nov 2013 15:37:31 +0000 (16:37 +0100)]
plugins: allow VA video meta to be allocated from surface proxy pools.

Fix gst_vaapi_video_meta_new_from_pool() to allocate VA surface proxies
from surface pools instead of plain VA surfaces. This is to simplify
allocations now that surface proxies are created from a surface pool.

4 years agosurfaceproxy: add copy function.
Gwenole Beauchesne [Thu, 28 Nov 2013 16:25:05 +0000 (17:25 +0100)]
surfaceproxy: add copy function.

Add gst_vaapi_surface_proxy_copy() function that creates a new surface
proxy with the same information from the parent proxy, except that the
user-defined destroy notify function is not copied over.

The underlying VA surface is pushed back to the video pool only when
the last reference to the parent surface proxy is released.

4 years agovaapiencode: optimize _handle_frame() to avoid extra allocation.
Gwenole Beauchesne [Thu, 28 Nov 2013 14:56:53 +0000 (15:56 +0100)]
vaapiencode: optimize _handle_frame() to avoid extra allocation.

Optimize gst_vaapiencode_handle_frame() to avoid extra memory allocation,
and in particular the GstVaapiEncObjUserData object. i.e. directly use
the VA surface proxy from the source buffer. This also makes the user
data attached to the GstVideoCodecFrame more consistent between both
the decoder and encoder plug-in elements.

4 years agovaapiencode: fix memory leaks in _push_frame() on error.
Gwenole Beauchesne [Thu, 28 Nov 2013 14:14:43 +0000 (15:14 +0100)]
vaapiencode: fix memory leaks in _push_frame() on error.

Simplify gst_vaapiencode_push_frame(), while also removing the call
to gst_video_encoder_negotiate() since this is implicit in _finish()
if caps changed. Also fixed memory leaks that occured on error.

4 years agovaapiencode: additional clean-ups.
Gwenole Beauchesne [Thu, 28 Nov 2013 12:57:54 +0000 (13:57 +0100)]
vaapiencode: additional clean-ups.

Constify pointers wherever possible. Drop unused variables, and use
consistent variable names. Fix gst_vaapiencode_h264_allocate_buffer()
to correctly report errors, especially when in-place conversion from
bytestream to avcC format failed.