summaryrefslogtreecommitdiff
path: root/libavcodec/h264_mp4toannexb_bsf.c
Commit message (Collapse)AuthorAgeFilesLines
* avcodec/bsf: Add FFBitStreamFilter, hide internals of BSFsAndreas Rheinhardt2022-03-231-3/+3
| | | | | | | | | | This patch is analogous to 20f972701806be20a77f808db332d9489343bb78: It hides the internal part of AVBitStreamFilter by adding a new internal structure FFBitStreamFilter (declared in bsf_internal.h) that has an AVBitStreamFilter as its first member; the internal part of AVBitStreamFilter is moved to this new structure. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* Remove/replace some unnecessary avcodec.h inclusionsAndreas Rheinhardt2021-07-221-1/+1
| | | | | | | Also remove other unnecessary headers and include headers directly while at it. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec.h: split bitstream filters API into its own headerAnton Khirnov2020-05-221-0/+1
|
* lavc: rename bsf.h to bsf_internal.hAnton Khirnov2020-05-221-1/+1
| | | | This will allow adding a public header named bsf.h
* h264_mp4toannexb: CosmeticsAndreas Rheinhardt2020-03-061-25/+25
| | | | | | | | Mainly reindentation, but some variables were also put into a smaller scope. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* h264_mp4toannexb: Improve overread checksAndreas Rheinhardt2020-03-061-8/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | 1. Left shifts of signed values are undefined as soon as the result is no longer representable in the target type. Therefore make nal_size an uint32_t and drop the check for whether it is < 0. 2. The two checks for overreads (whether the length field is contained in the packet and whether the actual unit is contained in the packet) can be combined into one because the packet is padded, i.e. a potential overread caused by reading the length field without checking whether said length field is actually part of the packet's buffer is allowed as one always stays within the padding. But one has to be aware of a pitfall: The comparison must be performed in (at least) int64_t as otherwise buf_end - buf might be promoted to uint32_t in which case an already occured overread would appear as a very large number. A comment explaining this has been added, too. 3. Units of size zero are now silently dropped; the earlier code would instead read the first byte of the next length field (or the first byte of padding) to infer the type of the current unit. 4. Futhermore, the earlier code returned the wrong error code. This has been fixed, too. Fixes #8290. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* h264_mp4toannexb: Stop reallocating the output bufferAndreas Rheinhardt2020-03-061-52/+72
| | | | | | | | | | | | | | Up until now, h264_mp4toannexb would grow the output packet's buffer by the desired amount every time another NAL unit of the input packet has been read; this commit changes this: The input buffer is now essentially parsed twice, once to determine the final size of the output packet and once to write the output packet's data. Fixes: Timeout Fixes: 19322/clusterfuzz-testcase-minimized-ffmpeg_BSF_H264_MP4TOANNEXB_fuzzer-5688407821123584 Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* h264_mp4toannexb: Consistently use pointer comparisonsAndreas Rheinhardt2020-03-061-5/+1
| | | | | | | | | h264_mp4toannexb_filter currently uses both indices/offsets as well as direct pointers comparisons for the checks whether one has reached or even surpassed the end. This commit removes the offsets. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* h264_mp4toannexb: Copy one NAL unit at a timeAndreas Rheinhardt2020-03-061-22/+15
| | | | | | | | | | | | | If processing an input NAL unit triggers the insertion of data from extradata in front of said NAL unit, the output packet is grown (i.e. reallocated) once to accomodate both the new extradata as well as the input NAL unit itself; this has been changed: In such a situation, the packet is now grown twice. While this is bad for performance, it allows to simplify the code and ultimately to stop reallocating the packet altogether. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* h264_mp4toannexb: Try to avoid four byte startcodesAndreas Rheinhardt2020-03-061-3/+3
| | | | | | | | | | | | | | | | | | | | | | According to the H.264 specifications, the only NAL units that need to have four byte startcodes in H.264 Annex B format are SPS/PPS units and units that start a new access unit. Before af7e953a, the first of these conditions wasn't upheld as already existing in-band parameter sets would not automatically be written with a four byte startcode, but only when they already were at the beginning of their input packets. But it made four byte startcodes be used too often as every unit that is written together with a parameter set that is inserted from extradata received a four byte startcode although a three byte start code would suffice unless the unit itself were a parameter set. FATE has been updated to reflect the changes. Although the patch leaves the extradata unchanged, the size of the extradata according to the FATE reports changes. This is due to a quirk in ff_h2645_packet_split which is used by extract_extradata: If the input is Annex B, the first zero of a four byte startcode is considered a part of the last unit (if any). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* h264_mp4toannexb: Simplify extradata insertionAndreas Rheinhardt2020-03-061-22/+22
| | | | | | | | | | | | | | Up until now, h264_mp4toannexb stored the offset of the first SPS and the first PPS in the (output) extradata in its context and used these two numbers together with the size of the extradata and the pointer to the extradata to determine what to insert when inserting extradata. This led to some very long lines like "s->pps_offset != -1 ? s->pps_offset : ctx->par_out->extradata_size - s->sps_offset". Therefore now pointers to SPS and PPS are stored along with their respective sizes, so that e.g. the above line can be changed to "s->sps_size". Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* h264_mp4toannexb: Don't forget numOfPictureParameterSetsAndreas Rheinhardt2020-03-061-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | The format of an AVCDecoderConfigurationRecord, the out-of-band extradata of H.264 in mp4, is as follows: First four bytes containing version, profile and level, one byte for the length size and one byte each for the number of SPS, followed by the SPS (each with its own size field), followed by a byte containing the number of PPS followed by the PPS with their size fields. While the number of SPS/PPS may be zero, the bytes containing these numbers are mandatory. Yet the byte containing the number of PPS has been ignored in two places: 1. In the initial check for whether the extradata can contain an AVCDecoderConfigurationRecord. The minimum size is 7, not 6. 2. No check is made for whether the extradata ended right after the last byte of the last SPS of the SPS array. Instead the first byte of the padding is read as if it were part of the extradata and contained the number of PPS (namely zero, given that the padding is zeroed). No error or warning was ever raised. This has been changed. Such truncated extradata is now considered invalid; the check for 2. has been incorporated into the general size check. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* h264_mp4toannexb: Add a comment about possible overreadAndreas Rheinhardt2020-03-061-0/+1
| | | | | | | | | | | Before reading a 16bit size field during parsing of extradata, no check is performed to make sure that said length field is actually contained in the extradata. Given that this overread is not dangerous (the extradata is supposed to be padded), only a comment for it has been added; the error itself will be detected as part of the normal check for overreads. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* h264_mp4toannexb: Improve extradata overread checksAndreas Rheinhardt2020-03-061-2/+2
| | | | | | | | | | | | | | | | | Currently during parsing the extradata, h264_mp4toannexb checks for overreads by adding the size of the current unit to the current position pointer and comparing this to the end position of the extradata. But pointer comparisons and pointer arithmetic are only defined if it does not exceed the object it is used on (one past the last element of an array is allowed, too). In practice, this might lead to overflows. Therefore the check has been changed to use bytestream2_get_bytes_left() which means that the pointers get subtracted and the result gets compared to the available size. Furthermore, the error code has been fixed. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* h264_mp4toannexb: Switch to GetByteContext to read extradataAndreas Rheinhardt2020-03-061-8/+15
| | | | | | | | | | | This is done in order to improve readability. No functional change is intended with this commit at all; in particular, the unsafe read functions are used throughout as h264_extradata_to_annexb already performs its own checks. (These checks will nevertheless be improved in further commits.) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* h264_mp4toannexb: Remove unnecessary checkAndreas Rheinhardt2019-12-151-7/+3
| | | | | | | | | | | There can be at most 31 SPS and 255 PPS in the mp4/Matroska extradata. Given that each has a size of at most 2^16-1, the length of the output derived from these parameter sets can never overflow an ordinary 32 bit integer. So use a simple uint32_t instead of uint64_t and replace the unnecessary check with an av_assert1. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/h264_mp4toannexb_bsf: implement a AVBSFContext.flush() callbackJames Almer2018-08-161-0/+10
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/h264_mp4toannexb_bsf: use enum constants for the NAL unit type valuesJames Almer2018-07-301-7/+8
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* h264_mp4toannexb_bsf: Fix start code size of parameter sets.Yusuke Nakamura2018-03-131-11/+11
| | | | | | Any parameter set shall have start code of at least 4 byte size. Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* Merge commit 'f3ed484953b81856e40239d2410058a96188b2be'Derek Buitenhuis2016-05-121-1/+10
|\ | | | | | | | | | | | | * commit 'f3ed484953b81856e40239d2410058a96188b2be': h264_mp4toannexb_bsf: do not fail on annex B extradata Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
| * h264_mp4toannexb_bsf: do not fail on annex B extradataAnton Khirnov2016-04-241-1/+10
| | | | | | | | | | Just pass through the bitstream as is. This is the same as what is done for HEVC already.
* | Merge commit '33d18982fa03feb061c8f744a4f0a9175c1f63ab'Derek Buitenhuis2016-04-171-113/+109
|\ \ | |/ | | | | | | | | | | | | | | * commit '33d18982fa03feb061c8f744a4f0a9175c1f63ab': lavc: add a new bitstream filtering API Conversions-by: Hendrik Leppkes <h.leppkes@gmail.com> Conversions-by: Derek Buitenguis <derek.buitenhuis@gmail.com> Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
| * lavc: add a new bitstream filtering APIAnton Khirnov2016-03-201-63/+88
| | | | | | | | Deprecate the current bitstream filtering API.
* | h264_mp4toannexb: fix the pps offset when there are more than one sps in avcc赵宇龙2015-10-101-1/+1
| | | | | | | | | | | | | | | | | | | | the pps offset is used to locate pps in the spspps_buf; however, the current calc method is wrong because it is the offset of the original avctx->extradata; when there is only one sps in the avcc; the value is correct by coincidence, however, it will fail in avcc with multi sps Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | avcodec/h264_mp4toannexb_bsf: Use av_freep() to free spspps_bufMichael Niedermayer2015-10-101-1/+1
| | | | | | | | Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | avcodec/h264_mp4toannexb_bsf: Reorder operations in nal_size checkMichael Niedermayer2015-08-211-1/+1
| | | | | | | | | | | | Fixes Ticket4778 Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | Merge commit '059a934806d61f7af9ab3fd9f74994b838ea5eba'Michael Niedermayer2015-07-271-2/+2
|\ \ | |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * commit '059a934806d61f7af9ab3fd9f74994b838ea5eba': lavc: Consistently prefix input buffer defines Conflicts: doc/examples/decoding_encoding.c libavcodec/4xm.c libavcodec/aac_adtstoasc_bsf.c libavcodec/aacdec.c libavcodec/aacenc.c libavcodec/ac3dec.h libavcodec/asvenc.c libavcodec/avcodec.h libavcodec/avpacket.c libavcodec/dvdec.c libavcodec/ffv1enc.c libavcodec/g2meet.c libavcodec/gif.c libavcodec/h264.c libavcodec/h264_mp4toannexb_bsf.c libavcodec/huffyuvdec.c libavcodec/huffyuvenc.c libavcodec/jpeglsenc.c libavcodec/libxvid.c libavcodec/mdec.c libavcodec/motionpixels.c libavcodec/mpeg4videodec.c libavcodec/mpegvideo.c libavcodec/noise_bsf.c libavcodec/nuv.c libavcodec/nvenc.c libavcodec/options.c libavcodec/parser.c libavcodec/pngenc.c libavcodec/proresenc_kostya.c libavcodec/qsvdec.c libavcodec/svq1enc.c libavcodec/tiffenc.c libavcodec/truemotion2.c libavcodec/utils.c libavcodec/utvideoenc.c libavcodec/vc1dec.c libavcodec/wmalosslessdec.c libavformat/adxdec.c libavformat/aiffdec.c libavformat/apc.c libavformat/apetag.c libavformat/avidec.c libavformat/bink.c libavformat/cafdec.c libavformat/flvdec.c libavformat/id3v2.c libavformat/isom.c libavformat/matroskadec.c libavformat/mov.c libavformat/mpc.c libavformat/mpc8.c libavformat/mpegts.c libavformat/mvi.c libavformat/mxfdec.c libavformat/mxg.c libavformat/nutdec.c libavformat/oggdec.c libavformat/oggparsecelt.c libavformat/oggparseflac.c libavformat/oggparseopus.c libavformat/oggparsespeex.c libavformat/omadec.c libavformat/rawdec.c libavformat/riffdec.c libavformat/rl2.c libavformat/rmdec.c libavformat/rtpdec_latm.c libavformat/rtpdec_mpeg4.c libavformat/rtpdec_qdm2.c libavformat/rtpdec_svq3.c libavformat/sierravmd.c libavformat/smacker.c libavformat/smush.c libavformat/spdifenc.c libavformat/takdec.c libavformat/tta.c libavformat/utils.c libavformat/vqf.c libavformat/westwood_vqa.c libavformat/xmv.c libavformat/xwma.c libavformat/yop.c Merged-by: Michael Niedermayer <michael@niedermayer.cc>
| * lavc: Consistently prefix input buffer definesVittorio Giovara2015-07-271-3/+3
| | | | | | | | Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
* | libavcodec/h264_mp4toannexb_bsf.c: Optional argument "private_spspps_buf" to ↵Ivan Uskov2015-07-261-7/+34
| | | | | | | | | | | | avoid extradata modification. Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | avcodec/h264_mp4toannexb_bsf: reset the new IDR flag when SPS/PPS is seen.Benoit Fouet2014-10-051-2/+2
| | | | | | | | Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | avcodec/h264_mp4toannexb_bsf: use the given padding in ↵Benoit Fouet2014-09-301-1/+1
| | | | | | | | | | | | h264_extradata_to_annexb(). Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | avcodec/h264_mp4toannexb_bsf: add a case when only SPS/PPS is in the stream.Benoit Fouet2014-09-301-9/+48
| | | | | | | | | | | | | | When only SPS or PPS is present in the stream, copy the missing one from AVCC before insertion to the output stream. Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | h264_mp4toannexb_bsf: rename first_idr to new_idrBenoit Fouet2014-08-011-8/+8
| | | | | | | | Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | h264_mp4toannexb_bsf: always set idr_sps_pps_seen when SPS/PPS is seen.Benoit Fouet2014-08-011-1/+1
| | | | | | | | | | | | | | In order not to break a sequence like "SPS IDR SPS IDR", the boolean telling that the SPS/PPS has been seen should always be set. Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | h264_mp4toannexb_bsf: account for consecutive IDR pictures.Benoit Fouet2014-07-311-0/+5
| | | | | | | | | | | | | | If there are consecutive IDR pictures, then SPS/PPS should be prepended to all of them, not only the first one. Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | avcodec/h264_mp4toannexb_bsf: fix issue when sps/pps are already in the bistreamChris \"Koying\" Browet2014-07-271-3/+11
| |
* | avcodec/h264_mp4toannexb_bsf: prepend global headers before any in stream ↵Michael Niedermayer2014-03-261-1/+1
| | | | | | | | | | | | | | | | parameter sets Fixes h264_mp4toannexb_bsf_failure.mkv Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | Merge commit '9b8d11a76ae7bca8bbb58abb822138f8b42c776c'Michael Niedermayer2013-12-091-12/+9
|\ \ | |/ | | | | | | | | | | | | | | | | | | | | | | | | * commit '9b8d11a76ae7bca8bbb58abb822138f8b42c776c': avcodec: Use av_reallocp where suitable Conflicts: libavcodec/bitstream.c libavcodec/eatgv.c libavcodec/flashsv.c libavcodec/libtheoraenc.c libavcodec/libvpxenc.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * avcodec: Use av_reallocp where suitableAlexandra Khirnova2013-12-091-12/+9
| | | | | | | | Signed-off-by: Martin Storsjö <martin@martin.st>
* | avcodec: use designated initializers for bitstream filtersPaul B Mahol2013-10-021-3/+3
| | | | | | | | Signed-off-by: Paul B Mahol <onemda@gmail.com>
* | lavc/h264_mp4toannexb: improve feedback in case of invalid bitstreamStefano Sabatini2013-07-171-3/+9
| |
* | Merge commit '9e80eda26d06c7c48dbec5dfe643c857c62c0ee7'Michael Niedermayer2013-06-161-1/+1
|\ \ | |/ | | | | | | | | | | * commit '9e80eda26d06c7c48dbec5dfe643c857c62c0ee7': h264_mp4toannexb_bsf: return a padded buffer Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * h264_mp4toannexb_bsf: return a padded bufferLuca Barbato2013-06-151-1/+1
| | | | | | | | | | The code using the returned buffer might expect it to be FF_INPUT_BUFFER_PADDING_SIZE padded as any other avpacket.
* | Merge commit '8d929afd256069aa881f2bf58ef9f0ffce2d6b7e'Michael Niedermayer2013-06-161-63/+71
|\ \ | |/ | | | | | | | | | | | | | | | | * commit '8d929afd256069aa881f2bf58ef9f0ffce2d6b7e': h264_mp4toannexb_bsf: factor out extradata parsing Conflicts: libavcodec/h264_mp4toannexb_bsf.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * h264_mp4toannexb_bsf: factor out extradata parsingLuca Barbato2013-06-151-68/+78
| |
* | Merge commit '5d21ca45591bb1c1d2265f8ed972d18c563f145e'Michael Niedermayer2013-06-161-32/+41
|\ \ | |/ | | | | | | | | | | | | | | | | * commit '5d21ca45591bb1c1d2265f8ed972d18c563f145e': h264_mp4toannexb_bsf: K&R formatting cosmetics Conflicts: libavcodec/h264_mp4toannexb_bsf.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * h264_mp4toannexb_bsf: K&R formatting cosmeticsLuca Barbato2013-06-151-32/+41
| |
* | Merge remote-tracking branch 'qatar/master'Michael Niedermayer2012-08-161-0/+3
|\ \ | |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * qatar/master: Fix even more missing includes after the common.h removal build: Factor out rangecoder dependencies to CONFIG_RANGECODER build: Factor out error resilience dependencies to CONFIG_ERROR_RESILIENCE x86: avcodec: Consistently name all init files Add more missing includes after removing the implicit common.h Add some more missing includes after removing the implicit common.h Don't include common.h from avutil.h rtmp: Automatically compute the hash for SWFVerification Conflicts: configure doc/APIchanges doc/examples/decoding_encoding.c libavcodec/Makefile libavcodec/assdec.c libavcodec/audio_frame_queue.c libavcodec/avpacket.c libavcodec/dv_profile.c libavcodec/dwt.c libavcodec/libtheoraenc.c libavcodec/rawdec.c libavcodec/rv40dsp.c libavcodec/tiff.c libavcodec/tiffenc.c libavcodec/v210dec.h libavcodec/vc1dsp.c libavcodec/x86/Makefile libavfilter/asrc_anullsrc.c libavfilter/avfilter.c libavfilter/buffer.c libavfilter/formats.c libavfilter/vf_ass.c libavfilter/vf_drawtext.c libavfilter/vf_fade.c libavfilter/vf_select.c libavfilter/video.c libavfilter/vsrc_testsrc.c libavformat/version.h libavutil/audioconvert.c libavutil/error.h libavutil/version.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * Don't include common.h from avutil.hMartin Storsjö2012-08-151-0/+3
| | | | | | | | Signed-off-by: Martin Storsjö <martin@martin.st>
* | h264_mp4toannexb_bsf: use i instead of misusing unit_type.Michael Niedermayer2012-03-211-2/+3
| | | | | | | | Signed-off-by: Michael Niedermayer <michaelni@gmx.at>