summaryrefslogtreecommitdiffstats
path: root/libavcodec/cbs_mpeg2.c
Commit message (Collapse)AuthorAgeFilesLines
* cbs_mpeg2: Fix parsing the last unitAndreas Rheinhardt2019-07-291-7/+21
| | | | | | | | | | | | | | There is one way to find out if avpriv_find_start_code has found a start code or not: One has to check whether the state variable contains a start code, i.e. whether the three most significant bytes are 0x00 00 01. Checking for whether the return value is the end of the designated buffer is not enough: If the last four bytes constitute a start code, the return value is also the end of the buffer. This happens with sequence_end_codes which have been ignored for exactly this reason, although e.g. all three files used for fate tests of cbs_mpeg2 contain sequence_end_codes. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* cbs_mpeg2: Rearrange start code searchAndreas Rheinhardt2019-07-291-15/+14
| | | | | | | | | | | | | | | | 1. Currently, cbs_mpeg2_split_fragment uses essentially three variables to hold the start code values found by avpriv_find_start_code. By rearranging the code, one of them can be omitted. 2. The return value of avpriv_find_start_code points to the byte after the byte containing the start code identifier (or to the byte after the last byte of the fragment's data if no start code was found), but cbs_mpeg2_split_fragment needs to work with the pointer to the byte containing the start code identifier; it already did this, but in a clumsy way. This has been changed. 3. Also use the correct type for the variable holding the CodedBitstreamUnitType. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* cbs_mpeg2: Decompose Sequence EndAndreas Rheinhardt2019-07-291-0/+3
| | | | | | | | | Sequence End units (or actually, sequence_end_codes) have up until now not been decomposed; in fact due to a bug in cbs_mpeg2_split_fragment they have mostly been treated as part of the preceding unit. So implement decomposing them as preparation for fixing said bug. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* cbs: Don't set AVBuffer's opaqueAndreas Rheinhardt2019-07-291-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | cbs is currently inconsistent regarding the opaque field that can be used as a special argument to av_buffer_create in order to be used during freeing the buffer: ff_cbs_alloc_unit_content and all the free functions used name this parameter as if it should contain a pointer to the unit whose content is about to be created; but both ff_cbs_alloc_unit_content as well as ff_cbs_h264_add_sei_message actually use a pointer to the CodedBitstreamContext as opaque. It should actually be neither, because it is unneeded (as is evidenced by the fact that none of the free functions use this pointer at all) and because it ties the unit's content to the lifetime of other objects, although a refcounted buffer is supposed to have its own lifetime that only ends when its reference count reaches zero. This problem manifests itself in the pointer becoming dangling. The pointer to the unit can become dangling if another unit is added to the fragment later as happens in the bitstream filters; in this case, the pointer can point to the wrong unit (if the fragment's unit array needn't be relocated) or it can point to where the array was earlier. It can also become dangling if the unit's content is meant to survive the resetting of the fragment it was originally read with. This applies to the extradata of H.264 and HEVC. The pointer to the context can become dangling if the context is closed before the content is freed. Although this doesn't seem to happen right now, it could happen, in particular if one uses different CodedBitstreamContexts for in- and output. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* cbs_mpeg2: Fix parsing of picture and slice headersAndreas Rheinhardt2019-07-271-19/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 1. The extra information in slice headers was parsed incorrectly: In the first reading pass to derive the length of the extra information, one should look at bits n, n + 9, n + 18, ... and check whether they equal one (further extra information) or zero (end of extra information), but instead bits n, n + 8, n + 16, ... were inspected. The second pass of reading (where the length is already known and the bytes between the length-determining bits are copied into a buffer) did not record what was in bits n, n + 9, n + 18, ..., presuming they equal one. And during writing, the bytes in the buffer are interleaved with set bits and written. This means that if the detected length of the extra information was greater than the real length, the output was corrupted. Fortunately no sample is known that made use of this mechanism: The extra information in slices is still marked as reserved in the specifications. cbs_mpeg2 is now ready in case this changes. 2. Furthermore, the buffer is now padded and slightly different, but very similar code for reading resp. writing has been replaced by code used for both. This was made possible by a new macro, the equivalent to cbs_h2645's fixed(). 3. These changes also made it possible to remove the extra_bit_slice element from the MPEG2RawSliceHeader structure. Said element was always zero except when the detected length of the extra information was less than the real length. 4. The extra information in picture headers (which uses essentially the same syntax as the extra information in slice headers) has simply been forgotten. This meant that if this extra information was present, it was discarded during reading; and unfortunately writing created invalid bitstreams in this case (an extra_bit_picture - the last set bit of the whole unit - indicated that there would be a further byte of data, although the output didn't contain said data). This has been fixed; both types of extra information are now parsed via the same code and essentially passed through. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* cbs: Remove useless initializationsAndreas Rheinhardt2019-07-271-1/+1
| | | | | | | | | | | Up until now, a temporary variable was used and initialized every time a value was read in CBS; if reading turned out to be successfull, this value was overwritten (without having ever been looked at) with the value read if reading was successfull; on failure the variable wasn't touched either. Therefore these initializations can be and have been removed. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* mpeg2_metadata, cbs_mpeg2: Fix handling of colour_descriptionAndreas Rheinhardt2019-07-271-0/+15
| | | | | | | | | | | | | | If a sequence display extension is read with colour_description equal to zero, but a user wants to add one or more of the colour_description elements, then the colour_description elements the user did not explicitly request to be set are set to zero and not to the value equal to unknown/unspecified (namely 2). A value of zero is not only inappropriate, but explicitly forbidden. This is fixed by inferring the right default values during the reading process if the elements are absent; moreover, changing any of the colour_description elements to zero is now no longer possible. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* cbs_av1, cbs_jpeg, cbs_mpeg2, cbs_vp9: Fix undefAndreas Rheinhardt2019-06-071-1/+1
| | | | | | | | | READ has already been undefined at this point; it is obviously intended to undef WRITE. Furthermore, leb128 (in cbs_av1) was undefined too often and inconsistently. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* cbs_mpeg2: Correct error codesAndreas Rheinhardt2019-05-291-3/+1
| | | | | | | Up until now, things that are merely unsupported by cbs_mpeg2 have been declared to be invalid input. This has been changed. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* cbs_mpeg2: Fix storage type for frame_centre_*_offsetAndreas Rheinhardt2019-05-291-0/+20
| | | | | | | | | | | | | | | | | The frame_centre_horizontal/vertical_offset values contained in picture display extensions are actually signed values (i.e. it is possible to indicate that the display device should add black bars/pillars). The files sony-ct3.bs and tcela-6.bits (which are both used in fate tests for mpeg2_metadata) contain picture display extensions; the former even contains a negative frame_centre_vertical_offset. Fortunately, the old code did not damage the picture display extensions when one did a cycle of reading and writing. For the same reason the fate tests needn't be updated either. Furthermore these fields now use the trace output for matrices. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* cbs_mpeg2: Improve checks for invalid valuesAndreas Rheinhardt2019-05-281-6/+10
| | | | | | | | | | | | | | | | | | | | | MPEG-2 contains several elements that mustn't be zero according to the specifications: horizontal/vertical_size_value, aspect_ratio_information, frame_rate_code, the quantiser matrices, the colour_description elements, picture_coding_type, the f_code[r][s] values and quantiser_scale_code. It is now checked that the invalid values don't occur. The colour_description elements are treated specially in this regard: Given that there are files in the wild which use illegal values for the colour_description elements (some of them created by mpeg2_metadata), they will be corrected to the value meaning "unknown" (namely 2) during reading. This has been done in such a way that trace_headers will nevertheless report the original value, together with a message about the fixup. Furthermore, the trace_headers output of user_data has been beautified. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* cbs_mpeg2: Correct and use enum valuesAndreas Rheinhardt2019-05-281-13/+17
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* cbs_mpeg2: Improve performance of writing slicesAndreas Rheinhardt2018-11-111-12/+27
| | | | | | | | | | | | Instead of using a combination of bitreader and -writer for copying data, one can byte-align the (obsolete and removed) bitreader to improve performance. One can even use memcpy in the normal case. This improved the time needed for writing the slicedata from 33618 to 2370 decicycles when tested on a video originating from a DVD (4194394 runs). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@googlemail.com> Signed-off-by: Mark Thompson <sw@jkqxz.net>
* cbs: Add support for array subscripts in trace outputMark Thompson2018-05-021-12/+13
| | | | This makes the trace output for arrays significantly nicer.
* avcodec/cbs_mpeg2: create a reference to the existing buffer when ↵James Almer2018-04-301-7/+2
| | | | | | | decomposing slice units Reviewed-by: Mark Thompson <sw@jkqxz.net> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/cbs_mpeg2: use existing buffer reference when splitting fragmentsJames Almer2018-04-261-9/+3
| | | | | Reviewed-by: Mark Thompson <sw@jkqxz.net> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/cbs_mpeg2: use memcpy when assembling fragmentsJames Almer2018-04-251-3/+3
| | | | | | | | | | | | | before: 419022 decicycles in assemble_fragment, 2047 runs, 1 skips after: 104621 decicycles in assemble_fragment, 2045 runs, 3 skips Benched with a 2 minutes long 720x480 DVD mpeg2 sample. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/cbs: use a reference to the assembled CodedBitstreamFragment buffer ↵James Almer2018-03-051-1/+2
| | | | | | | | | | | | when writing packets This saves one malloc + memcpy per packet The CodedBitstreamFragment buffer is padded to follow the requirements of AVPacket. Reviewed-by: jkqxz Signed-off-by: James Almer <jamrial@gmail.com>
* Merge commit 'ce5870a3a8f2b10668ee4f04c2ae0287f66f31b2'Mark Thompson2018-02-211-45/+46
|\ | | | | | | | | | | | | | | | | * commit 'ce5870a3a8f2b10668ee4f04c2ae0287f66f31b2': cbs: Refcount all the things! Some changes for bitstream API. Merged-by: Mark Thompson <sw@jkqxz.net>
| * cbs: Refcount all the things!Mark Thompson2018-02-201-45/+46
| | | | | | | | | | | | | | | | This makes it easier for users of the CBS API to get alloc/free right - all subelements use the buffer API so that it's clear how to free them. It also allows eliding some redundant copies: the packet -> fragment copy disappears after this change if the input packet is refcounted, and more codec-specific cases are now possible (but not included in this patch).
* | Merge commit '1d12a545ce828eaf4fb37295400008ea37635ab8'Mark Thompson2018-02-211-2/+2
|\ \ | |/ | | | | | | | | | | | | | | | | * commit '1d12a545ce828eaf4fb37295400008ea37635ab8': cbs: Add an explicit type for coded bitstream unit types Mostly already present from 6734eef6b8b464139fdc140ec9bc9e8d74173869, two minor message changes are merged. Merged-by: Mark Thompson <sw@jkqxz.net>
| * cbs: Add an explicit type for coded bitstream unit typesMark Thompson2018-02-201-2/+2
| | | | | | | | Also fix conversion specifiers used for the unit type.
| * cbs_mpeg2: Fix marker_bit typeMark Thompson2017-12-021-1/+1
| |
| * cbs: Add padding to slice data allocationsMark Thompson2017-12-021-1/+4
| | | | | | | | | | These may be read by the bitstream reader, so they should include the necessary padding for overreads.
| * cbs: Add buffer padding when splitting fragmentsMark Thompson2017-09-121-1/+2
| | | | | | | | Remove any trailing zeroes from H.26[45] NAL units at the same time.
| * cbs: Always check for bitstream end before readingMark Thompson2017-09-121-2/+3
| |
| * lavc: Add coded bitstream read/write support for MPEG-2Mark Thompson2017-08-201-0/+409
| | | | Also enable MPEG-2 support in the trace_headers filter.
* lavu/lavc/lavf/lavfi: Do not use type modifier %zu on Windows MSVCRT.Carl Eugen Hoyos2017-12-171-1/+1
|
* cbs_mpeg2: Fix format specifierMark Thompson2017-10-241-1/+1
|
* cbs_mpeg2: Fix type for marker_bit readingMark Thompson2017-10-241-1/+1
|
* lavc: Add coded bitstream read/write support for MPEG-2Mark Thompson2017-10-171-0/+414
(cherry picked from commit 2bc9ba8d3c41f3a8e56484bd67b05040c7909a01) (cherry picked from commit a41b69b5eb950c10d8ede472bcc4e88ce4246db9)
OpenPOWER on IntegriCloud