Commit graph

79 commits

Author SHA1 Message Date
Zhong Cong
c2ddf464e5 mpeg2: reset quantization matrices on new sequence headers.
The MPEG-2 standard specifies (6.3.7) that all quantisation matrices
shall be reset to their default values when a Sequence_Header() is
decoded.

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2013-07-05 17:57:57 +02:00
Gwenole Beauchesne
800b66f071 mpeg2: cope with latest codecparser changes.
Fix build with newer MPEG-2 codecparser where GstMpegVideoPacket are
used in individual header parsers. Also use the new slice parsing API.
2013-07-05 17:57:47 +02:00
Gwenole Beauchesne
3cc7b26961 libs: use GstVaapiMiniObject for video decoders.
Port GstVaapiDecoder and GstVaapiDecoder{MPEG2,MPEG4,JPEG,H264,VC1} to
GstVaapiMiniObject. Add gst_vaapi_decoder_set_codec_state_changed_func()
helper function to let the user add a callback to a function triggered
whenever the codec state (e.g. caps) changes.
2013-05-07 17:51:27 +02:00
Gwenole Beauchesne
6439169db5 libs: refine GstVaapiMiniObject.
Drop support for user-defined data since this capability was not used
so far and GstVaapiMiniObject represents the smallest reference counted
object type. Add missing GST_VAAPI_MINI_OBJECT_CLASS() helper macro.

Besides, since GstVaapiMiniObject is a libgstvaapi internal object, it
is also possible to further simplify the layout of the object. i.e. merge
GstVaapiMiniObjectBase into GstVaapiMiniObject.
2013-05-07 17:51:27 +02:00
Gwenole Beauchesne
788d337505 decoder: fix unpaired GstBuffer map/unmaps.
This possibly fixes a few memory leaks along the way.
2013-04-10 14:58:17 +02:00
Sreerenj Balachandran
51151e7aa1 Add initial support for GStreamer 1.0.
This integrates support for GStreamer API >= 1.0 only in the libgstvaapi
core decoding library. The changes are kept rather minimal here so that
the library retains as little dependency as possible on core GStreamer
functionality.

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2013-04-10 14:58:16 +02:00
Gwenole Beauchesne
57ed7e3f8b decoder: sanitize uses of codec frame input buffer (cosmetics).
Alias GST_VAAPI_DECODER_CODEC_FRAME(decoder)->input_buffer to a simple
"buffer" variable.
2013-03-21 13:28:05 +01:00
Gwenole Beauchesne
06725d651e mpeg2: fix decoding of 4K videos.
Account for slice_vertical_position_extension when vertical_size > 2800.
2013-01-30 19:19:47 +01:00
Gwenole Beauchesne
564ca5d221 mpeg2: fix decoding of sequence_end().
There shall be only one place to call decode_current_picture(), and this
is in the end_frame() hook. The EOS unit is processed after end_frame()
so this means we cannot have a valid picture to decode/output at this
point.
2013-01-30 19:19:47 +01:00
Gwenole Beauchesne
23b2386fd0 mpeg2: 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 sequence or picture headers.
2013-01-30 19:04:16 +01:00
Sreerenj Balachandran
0d5e203e79 mpeg2: implement GstVaapiDecoder::flush() as a DPB flush. 2013-01-29 18:25:22 +01:00
Gwenole Beauchesne
0c99f351fc legal: fix year for some copyright notices (2013). 2013-01-29 14:37:02 +01:00
Gwenole Beauchesne
22094ed053 legal: fix year for some copyright notices (2012). 2013-01-29 14:37:02 +01:00
Gwenole Beauchesne
e44d8ee6e3 dpb: port to GstVaapiMiniObject. 2013-01-14 10:46:50 +01:00
Gwenole Beauchesne
6f4e01258d dpb: drop GstVaapiDpb2 interface, keep only one class.
Keep only one DPB interface and rename gst_vaapi_dpb2_get_references()
to gst_vaapi_dpb_get_neighbours() so that to retrieve pictures in DPB
around the specified picture POC.
2013-01-14 10:21:53 +01:00
Sreerenj Balachandran
eafdd771ae dpb: rename GstVaapiDpbMpeg2 to GstVaapiDpb2.
Move GstVaapiDpbMpeg2 API to a more generic version that could also be
useful to other decoders that require 2 reference pictures, e.g. VC-1.

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2013-01-14 10:11:21 +01:00
Gwenole Beauchesne
0ecb3a627b mpeg2: optimize scan for the end of the frame.
Heuristic: if the second start-code is available, check whether that
one marks the start of a new frame because e.g. this is a sequence
or picture header. This doesn't save much, since we already cache the
results.
2013-01-09 16:05:39 +01:00
Gwenole Beauchesne
3bc6078f32 mpeg2: optimize scan for start codes.
Accelerate scan for start codes by skipping up to 3 bytes per iteration.
A start code prefix is defined by the following bytes: 00 00 01. Thus,
for any group of 3 bytes (xx yy zz), we have the following possible cases:

  1. If zz != 1, this cannot be a start code, then skip 3 bytes;
  2. If yy != 0, this cannot be a start code, then skip 2 bytes;
  3. If xx != 0 or zz != 1, this cannot be a start code, then skip 1 byte;
  4. xx == 00, yy == 00, zz == 1, we have match!

This algorithm requires to peek bytes from the adapter. This increases the
amount of bytes copied to a temporary buffer, but this process is much faster
than scanning for all the bytes and using shift/masks. So, overall, this is
a win.
2013-01-09 16:05:18 +01:00
Gwenole Beauchesne
0180ef635c mpeg2: drop useless gst_adapter_peek().
Drop useless gst_adapter_peek() since the returned buffer was not used
and this could incur superfluous memcpy().
2013-01-08 16:41:44 +01:00
Gwenole Beauchesne
4a69e395cd mpeg2: cosmetics: move parse_slice() down. 2013-01-07 16:12:42 +01:00
Gwenole Beauchesne
6dd8eab023 mpeg2: avoid too many allocations of parser info objects.
Move parsing back to decoding step, but keep functions separate for now.
This is needed for future optimizations that may introduce some meta data
for parsed info attached to codec frames.
2013-01-07 16:12:42 +01:00
Gwenole Beauchesne
2c449e42ca decoder: refactor decoder unit API.
Allocate decoder unit earlier in the main parse() function and don't
delegate this task to derived classes. The ultimate purpose is to get
rid of dynamic allocation of decoder units.
2013-01-07 14:10:13 +01:00
Gwenole Beauchesne
78e9a78de8 mpeg2: introduce parser info instead of MPEG-2 specific decoder unit.
Use a new GstVaapiParserInfoMpeg2 data structure instead of deriving
from GstVaapiDecoderUnit for MPEG-2 specific parser information.
2013-01-07 14:10:09 +01:00
Gwenole Beauchesne
eda01ab027 mpeg2: don't create sub-buffer for slice data.
Avoid creating a GstBuffer for slice data. Rather, directly use the codec
frame input buffer data. This is possible because the codec frame is valid
until end_frame() where we submit the VA buffers for decoding. Anyway, the
slice data buffer is copied into the VA buffer when it is created.
2013-01-03 09:08:19 +01:00
Gwenole Beauchesne
4556b1fd47 mpeg2: minor clean-ups.
Drop explicit initialization of most fields that are implicitly set to
zero. Remove some useless checks for NULL pointers.
2013-01-03 09:08:19 +01:00
Gwenole Beauchesne
7ca43932e5 mpeg2: optimize scan for the second start code.
Optimize scan for the second start code, on the next parse() call so that
to avoid scanning again earlier bytes where we didn't find any start code.
2013-01-03 09:08:19 +01:00
Gwenole Beauchesne
9458bbdc16 mpeg2: use sequence_display_extension() to compute PAR.
Also compute pixel-aspect-ratio from sequence_display_extension(),
should it exist in the bitstream.
2013-01-03 09:08:19 +01:00
Gwenole Beauchesne
65ede48b7b mpeg2: handle sequence_display_extension(). 2013-01-03 09:08:19 +01:00
Gwenole Beauchesne
748a8dbdc6 mpeg2: implement {start,end}_frame() hooks.
Implement GstVaapiDecoder.start_frame() and end_frame() semantics so
that to create new VA context earlier and submit VA pictures to the
HW for decoding as soon as possible. i.e. don't wait for the next
frame to start decoding the previous one.
2013-01-03 09:08:19 +01:00
Gwenole Beauchesne
4a39efa9f6 mpeg2: parse slice() header earlier.
Parse slice() header and first macroblock position earlier in _parse()
function instead of waiting for the _decode() stage. This doesn't change
anything but readability.
2013-01-03 09:08:19 +01:00
Gwenole Beauchesne
549b5a9389 mpeg2: add codec specific decoder unit.
Introduce new GstVaapiDecoderUnitMpeg2 object, which holds the standard
GstMpegVideoPacket and additional parsed header info. Besides, we now
parse as early as in the _parse() function so that to avoid un-necessary
creation of sub-buffers in _decode() for video packets that are not slices.
2013-01-03 09:08:19 +01:00
Gwenole Beauchesne
50090d6138 mpeg2: initial port to new GstVaapiDecoder API. 2012-12-18 15:31:51 +01:00
Sreerenj Balachandran
9367c8ea58 mpeg2: fix PAR calculation from commit bd11bae.
Invoke gst_mpeg_video_finalise_mpeg2_sequence_header() to get the
correct PAR values. While doing so, require a newer version of the
bitstream parser library.

Note: it may be necessary to also parse the Sequence_Display_Extension()
header.

Signed-off-by: Sreerenj Balachandran <sreerenj.balachandran@intel.com>
Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2012-11-15 16:23:27 +01:00
Simon Farnsworth
bd11baedc5 mpeg2: use pixel-aspec-ratio information from bitstream parser.
Signed-off-by: Simon Farnsworth <simon.farnsworth@onelan.co.uk>
Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2012-10-11 14:58:38 +02:00
Gwenole Beauchesne
388e881ba9 mpeg2: add decode_packet() helper function.
Split decode_buffer() into the core infrastructure that determines
the packets contained in the adapter and the actual function that
decodes the packet data.
2012-10-10 09:45:03 +02:00
Gwenole Beauchesne
dc03ca9100 mpeg2: fix end-of-stream conditions (flush).
Decode pending data in the adapter prior to processing the actual
code for end-of-stream. Initial code from Feng Yuan.
2012-10-09 18:08:50 +02:00
Gwenole Beauchesne
91da4fcb18 mpeg2: fix memory leak of empty packets.
Fix memory leakage of empty packets, i.e. packets that only contain
the start code prefix. In particular, free empty user-data packets.

Besides, the codec parser will already fail gracefully if the packet
to parse does not have the minimum required size. So, we can also
completely drop the block of code that used to handle packets of size 4
(including the start code).
2012-10-09 18:05:48 +02:00
Gwenole Beauchesne
8f7d19f010 mpeg2: fix return value for "no-data" conditions.
Fix return value when the second scan for start code fails. This means
there is not enough data to determine the full extents of the current
packet and the function shall return GST_VAAPI_DECODER_STATUS_ERROR_NO_DATA
in this case, instead of GST_VAAPI_DECODER_STATUS_SUCCESS.
2012-10-09 18:05:47 +02:00
Gwenole Beauchesne
a10b3d3032 decoder: cope with new GstVaapiContextInfo based API.
Update decoders to report the maximum number of reference frames to use.
2012-09-10 18:27:40 +02:00
Gwenole Beauchesne
61cc02f54b libs: fix build in strict ISO C mode. 2012-09-07 16:23:42 +02:00
Gwenole Beauchesne
1fb8f4791f mpeg2: include start code into VA slice data buffer.
Integrate the start code prefix in the slice data buffer that is submitted
to the hardware. VA-API specifies that slice_data_offset is the offset to
the first byte of slice data. And, for MPEG-2, slice() data begins with
the slice_start_code. Some VA driver implementations (EMGD) expect this.
2012-08-27 10:36:51 +02:00
Gwenole Beauchesne
49b1dca2d3 mpeg2: fix calculation of macroblock_offset.
Fix decoding of streams with extra slice() information before the first
macroblock(). e.g. this fixes sony-ct3.bs from conformance test.
2012-04-02 18:42:12 +02:00
Gwenole Beauchesne
2d36f6199e mpeg2: fix interpolation of GOP TSN from new PTS.
New GOP TSN base could be mis-calculated. In particular, this fixes
decoding of uruseiyatsura.vob from <http://samples.mplayerhq.hu/>.
2012-04-02 18:09:21 +02:00
Gwenole Beauchesne
9c8b85b3c7 mpeg2: fix decoding of high profile streams.
Allow MPEG-2 High profile streams only if the HW supports that profile
or no High profile specific bits are used, and thus Main profile could
be used instead. i.e. chroma_format is 4:2:0, intra_dc_precision is not
set to 11 and no sequence_scalable_extension() was parsed.
2012-04-02 16:12:32 +02:00
Gwenole Beauchesne
5975def8ab mpeg2: allocate dummy picture for first field based I-frame.
In P-pictures, prediction shall be made from the two most recently
decoded reference fields. However, when the first I-frame is a field,
the next field of the current picture could be a P-picture but only a
single field was decoded so far. In this case, create a dummy picture
with POC = -1 that will be used as reference.

Some VA drivers would error out if P-pictures don't have a forward
reference picture. This is true in general but not in this very specific
initial case.
2012-04-02 11:36:56 +02:00
Gwenole Beauchesne
99932049e4 mpeg2: fix simple to main profile fallback.
Allow fallback from simple to main profile when the HW decoder does
not support the former profile and that no sequence_header_extension()
is available to point out this.
2012-04-02 11:36:56 +02:00
Gwenole Beauchesne
75538bbc9b decoder: use POC to maintain the DPB.
Introduce a POC field in GstVaapiPicture so that to store simpler sequential
numbers. A signed 32-bit integer should be enough for 1 year of continuous
video streaming at 60 Hz.

Use this new POC value to maintain the DPB, instead of 64-bit timestamps.
This also aligns with H.264 that will be migrated to GstVaapiDpb infrastructure.
2012-03-30 17:08:37 +02:00
Gwenole Beauchesne
d51bb87482 mpeg2: rework generation of presentation timestamps.
Always prefer PTS from the demuxer layer for GOP times. If this is invalid,
i.e. demuxer could not determine the PTS or the generated PTS is lower than
max PTS from past pictures, then try to fix it up based on the duration of
a frame.

For picture PTS, simply use the GOP PTS formerly computed then use TSN to
reconstruct a current time. Also now handle wrapped TSN correctly.
2012-03-30 17:08:37 +02:00
Gwenole Beauchesne
6eeb20a953 mpeg2: ignore empty user-data packets.
Fix tcela-8.bits conformance test.
2012-03-30 17:08:37 +02:00
Gwenole Beauchesne
7af40475d5 mpeg2: review and report errors accordingly.
Use GST_ERROR() to report real errors instead of hiding them into
GST_DEBUG().
2012-03-29 11:13:20 +02:00