Commit Graph

684 Commits

Author SHA1 Message Date
Michael Niedermayer cb9752d897
avformat/mpegts: Reset local nb_prg on add_program() failure
add_program() will deallocate the whole array on failure so
we must clear nb_prgs

Fixes: null pointer dereference
Fixes: crash-35a3b39ddcc5babeeb005b7399a3a1217c8781bc

Found-by: Catena cyber
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-04-01 19:03:06 +02:00
Andreas Rheinhardt 790f793844 avutil/common: Don't auto-include mem.h
There are lots of files that don't need it: The number of object
files that actually need it went down from 2011 to 884 here.

Keep it for external users in order to not cause breakages.

Also improve the other headers a bit while just at it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-03-31 00:08:43 +01:00
James Almer 53cdf94653 avformat/avformat: remove AVFormatContext.ts_id
It's been replaced by a demuxer exported private option.

Signed-off-by: James Almer <jamrial@gmail.com>
2024-03-07 08:53:32 -03:00
Andreas Rheinhardt b800327f4c avformat/avformat: Add FFInputFormat, hide internals of AVInputFormat
This commit does for AVInputFormat what commit
59c9dc82f4 did for AVOutputFormat:
It adds a new type FFInputFormat, moves all the internals
of AVInputFormat to it and adds a now reduced AVInputFormat
as first member.

This does not affect/improve extensibility of both public
or private fields for demuxers (it is still a mess due to lavd).

This is possible since 50f34172e0
(which removed the last usage of an internal field of AVInputFormat
in fftools).

(Hint: tools/probetest.c accesses the internals of FFInputFormat
as well, but given that it is a testing tool this is not considered
a problem.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-03-07 08:53:31 -03:00
Marton Balint 0aaee4741c avformat/mpegts: detect synchronous metadata KLV more reliably
The mpegts code historically tries to strip (the first) metadata access unit
header from synchronous KLV metadata, but the detection for such streams was
unreliable causing strips of asynchronous metadata or ID3 as well.

MISB ST 1402 specifies required stream type, stream id and registration
descriptor (which eventually maps to the codec ID) so let's use all of these
for reliable detection.

Fixes a regression caused by 468615f204.

Fixes ticket #10828, #10883.

Signed-off-by: Marton Balint <cus@passwd.hu>
2024-03-04 00:33:20 +01:00
James Almer 4b8be3616d avformat/mpegts: remove decoding param from ts_packetsize option
It's a read only exported option, and not meant to be set by the user.
Also, move it to MPEGTS_OPTIONS while at it to avoid duplication.

Signed-off-by: James Almer <jamrial@gmail.com>
2024-02-19 11:25:21 -03:00
James Almer f9f56fdc37 avformat/mpegts: add a ts_id exported option
It will replace AVFormatContext.ts_id in the coming bump.

Signed-off-by: James Almer <jamrial@gmail.com>
2024-02-19 11:25:15 -03:00
Anton Khirnov 0d54ae4012 lavf/mpegts: drop a cargo-culted check
This check has survived the transition to AVCodecParameters, but is no
longer relevant after it, since the codec context is no longer updated
or accessed at all from the demuxer.
2024-02-09 16:14:56 +01:00
Thomas Siedel db6e360afb avformat/mpegts: add ts stream types for H266/VVC
Add transport stream stream type 0x33 for vvc.
Add STREAM_TYPE_VIDEO_VVC to MPEG-1/2 and MPEG-2 transport stream.
Add basic transport stream support for TS mux/demux.

Tested with:
ffmpeg -i NovosobornayaSquare_1920x1080.mp4 -c:v libvvenc test.ts && ffmpeg -i test.ts -f null -
ffmpeg -i NovosobornayaSquare_1920x1080.mp4 -c:v copy test.ts     && ffmpeg -i test.ts -f md5 -

Signed-off-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Thomas Siedel <thomas.ff@spin-digital.com>
Co-Authored-By: Nuo Mi <nuomi2021@gmail.com>
2024-01-31 22:14:12 +08:00
Anton Khirnov 08bebeb1be Revert "all: Don't set AVClass.item_name to its default value"
Some callers assume that item_name is always set, so this may be
considered an API break.

This reverts commit 0c6203c97a.
2024-01-20 10:34:48 +01:00
Andreas Rheinhardt 0c6203c97a all: Don't set AVClass.item_name to its default value
Unnecessary since acf63d5350adeae551d412db699f8ca03f7e76b9;
also avoids relocations.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-12-22 15:12:33 +01:00
James Almer 5432d2aaca avformat/avformat: use the side data from AVStream.codecpar
Deprecate AVStream.side_data and its helpers in favor of the AVStream's
codecpar.coded_side_data.

This will considerably simplify the propagation of global side data to decoders
and from encoders. Instead of having to do it inside packets, it will be
available during init().
Global and frame specific side data will therefore be distinct.

Signed-off-by: James Almer <jamrial@gmail.com>
2023-10-06 10:03:57 -03:00
Andreas Rheinhardt 7001ff74ba avformat/aviobuf: Add ffio_init_(read|write)_context()
Most users of ffio_init_context() simply want to wrap
a buffer into an AVIOContext; they do not provide
function pointers at all.

Therefore this commit adds shortcuts for these two common
operations. This also allows to accept const data when reading
(i.e. the const is now cast away at a central place in
ffio_init_read_context() instead of at several callers).
This also allows to constify the data in ff_text_init_buf().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-09-07 00:41:45 +02:00
Andreas Rheinhardt 8238bc0b5e avcodec/defs: Add AV_PROFILE_* defines, deprecate FF_PROFILE_* defines
These defines are also used in other contexts than just AVCodecContext
ones, e.g. in libavformat. Furthermore, given that these defines are
public, the AV-prefix is the right one, so deprecate (and not just move)
the FF-macros.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-09-07 00:39:02 +02:00
Romain Beauxis 468615f204 libavformat/mpegts.c: fix hardcoded 5-bytes skip for metadata streams.
Before the introduction of AV_CODEC_ID_TIMED_ID3 for timed_id3 metadata streams
in mpegts (commit 4a4437c0fb), AV_CODEC_ID_SMPTE_KLV
was the only existing codec for metadata.

It seems that this codec has a 5-bytes metadata header[1] that, for some reason,
was always skipped when decoding data packets.

However, when working with a AV_CODEC_ID_TIMED_ID3 streams, this results in the
5 first bytes of the payload being cut-off, which includes essential informations
such as the ID3 tag version.

This patch fixes the issue by keeping the 5-bytes skip only for AV_CODEC_ID_SMPTE_KLV
streams.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2023-06-20 21:08:06 -03:00
Aman Karmani 961b17eace avformat/mpegts: add AC-4 2023-06-20 01:13:38 +02:00
TADANO Tokumei 38bb137e99 lavf/mpegts.c: set some properties for ARIB caption
Some additional properties are set for ARIB caption.
* need_parsing = 0
  ARIB caption doesn't require any parser.
  This avoids "parser not found" warning message.
* need_context_update = 1
  When any profiles are changed, set this flag to notify.

Signed-off-by: rcombs <rcombs@rcombs.me>
2023-03-28 12:04:52 -04:00
Devin Heitmueller 19798229df avformat/mpegts: add support for preserving SMPTE 2038 when transcoding MPEG-TS streams
Add the appropriate descriptors to the MPEG-TS demux and mux to
ensure that SMPTE 2038 VANC streams are properly preserved
when using codec copy (including adding the appropriate PMT
descriptors).

The focus of this patch is TS input to TS output.  A separate
patch adds support for output of 2038 VANC over decklink SDI.

Thanks to Marton Balint for feedback to preserve ABI compatibility.

Signed-off-by: Devin Heitmueller <dheitmueller@ltnglobal.com>
Signed-off-by: Marton Balint <cus@passwd.hu>
2023-03-26 18:51:25 +02:00
Andreas Rheinhardt 2b41463b87 avformat/internal: Don't include avcodec.h
The general demuxing API uses parsers and decoders. Therefore
FFStream contains pointers to AVCodecContexts and
AVCodecParserContext and lavf/internal.h includes lavc/avcodec.h.

Yet actually only a few files files really use these; and it is best
when this number stays small. Therefore this commit uses opaque
structs in lavf/internal.h for these contexts and stops including
avcodec.h.
This also avoids including lavc/codec_desc.h implicitly. All other
headers are implicitly included as now (mostly through codec.h).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-09-26 03:02:50 +02:00
Marton Balint 58df81b027 avformat/mpegts: remove obsolate hacks for detecting streams with bad PMTs
Ffmpeg/ffprobe/ffplay sets scan_all_pmts to 1 when finding the streams, that
should be enough to handle files for which some early PMTs miss some streams.

Fixes ticket #9782.

Signed-off-by: Marton Balint <cus@passwd.hu>
2022-06-20 23:36:37 +02:00
Andreas Rheinhardt 35ec5c819b avformat/demux: Add new demux.h header
And move those stuff already in demuxer-only files to it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-10 07:37:38 +02:00
TADANO Tokumei ad063e6e10 avformat/mpegts.c: ignore a section with next flag
'current_next_indicator' of 0 (next) on each section header indicates
the service information is for immediate future one.
ffmpeg doesn't need to parse it but current (1) one.

ref: section 5.1.1 of DVB BlueBook A038 (EN 300 468)

Signed-off-by: TADANO Tokumei <aimingoff@pc.nifty.jp>
Signed-off-by: Marton Balint <cus@passwd.hu>
2022-04-09 20:23:45 +02:00
TADANO Tokumei 5dcedfcd17 avformat/mpegts.c: fix to check end of each descriptor of SDT
Current code incorrectly check against end of section rather than
end of descriptor.

Signed-off-by: TADANO Tokumei <aimingoff@pc.nifty.jp>
Signed-off-by: Marton Balint <cus@passwd.hu>
2022-04-09 19:58:53 +02:00
Martin Storsjö a78f136f3f configure: Use a separate config_components.h header for $ALL_COMPONENTS
This avoids unnecessary rebuilds of most source files if only the
list of enabled components has changed, but not the other properties
of the build, set in config.h.

Signed-off-by: Martin Storsjö <martin@martin.st>
2022-03-16 14:12:49 +02:00
Gyan Doshi b6bb6b9f22 avformat/mpegts: initialize max_packet_size when sub-demuxer
bca30570d2 added a user option to set max_packet_size replacing
a hardcoded value. This had a side-effect of leaving the field
set to 0 when packet demuxing is carried out from another demuxer
using avpriv functions, which could lead to demux failure.

Hardcoded max_packet_size inside avpriv_mpegts_parse_open to
2048000 to avoid this. Value chosen to be 10x that of default value
to accommodate large payloads.
2022-02-10 16:57:59 +05:30
Gyan Doshi bca30570d2 avformat/mpegts: add option max_packet_size
Makes maximum size of emitted packet user-tunable.

Default is existing 204800 bytes.
2022-01-16 10:46:38 +05:30
Andreas Rheinhardt a4798a5d51 all: Use av_memdup() where appropriate
Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-12-03 16:07:02 +01:00
Marton Balint 0b9dbfab48 avformat/mpegts: fix stream index in verbose log message
Signed-off-by: Marton Balint <cus@passwd.hu>
2021-11-25 19:11:24 +01:00
Limin Wang 08c688e64d avformat/mpegts: Fix for the DOVI video stream descriptor
By <<Dolby Vision Streams Within the MPEG-2 Transport Stream Format v1.2>>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2021-10-28 09:25:31 +08:00
Limin Wang 5779bd5b2a avformat/mpegts: add support for stream_type 0xd4, which is AVS3
GB/T 17975.1
Information technology-Generic coding of moving pictures and associated audio
information-Part 1:Systems

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2021-10-20 22:40:13 +08:00
Nachiket Tarate ff958b3846 libavformat/hls: add support for decryption of HLS media segments encrypted using SAMPLE-AES encryption method
Apple HTTP Live Streaming Sample Encryption:

https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/HLS_Sample_Encryption

Signed-off-by: Nachiket Tarate <nachiket.programmer@gmail.com>
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2021-10-13 11:23:53 +08:00
Marton Balint 9420f7e095 avformat/mpegts: fix max_packet_size in mpegts payload parsing
The maximum allowed useful PES payload data was set to PES_packet_length, but
it is in fact smaller by the length of the PES header.

This changes how corrupt streams are packetized:
- If PES header length is bigger than PES_packet_length then the PES packet
  payload will be handled as an unbound packet
- PES packets with payload across multiple MPEGTS packets will always be
  splitted if with the next chunk of data the payload should exceed
  PES_packet_length, previously a PES_header_length amount of excess was
  allowed.

Fixes ticket #9355.

Signed-off-by: Marton Balint <cus@passwd.hu>
2021-10-10 16:54:15 +02:00
Marton Balint aeea2ad0e4 avformat/mpegts: rename PES total_size to PES_packet_length
This renames PESContext->total_size to PESContext->PES_packet_length and keeps
it 0 for unbound packets, so its name and semantics will match the standard.

There should be no change in functionality.

Signed-off-by: Marton Balint <cus@passwd.hu>
2021-10-10 16:54:15 +02:00
Marton Balint 65cd43cff3 avformat/mpegts: delay allocation of PES buffer
This allows us to allocate the buffer in a single code path.

Signed-off-by: Marton Balint <cus@passwd.hu>
2021-10-10 16:54:15 +02:00
Marton Balint ce8db0c253 avformat/mpegts: use named constants for stream_id types
Signed-off-by: Marton Balint <cus@passwd.hu>
2021-10-10 16:54:15 +02:00
Michael Niedermayer 83b2e4c8f1 avformat/mpegts: use actually read packet size in mpegts_resync special case
Fixes: infinite loop
Fixes: 37986/clusterfuzz-testcase-minimized-ffmpeg_dem_MPEGTSRAW_fuzzer-5292311517462528 -

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-10-07 23:38:57 +02:00
Nicolas Jorge Dato 5a0a9f7825 avformat/mpegts: fixes overflow when parsing the PMT
When a possible overflow was detected, there was a break to exit the while
loop. However, it should have already substracted 2 bytes from
program_info_length (descriptor ID + length).

Fixes ticket #9422.

Signed-off-by: Marton Balint <cus@passwd.hu>
2021-09-18 21:19:39 +02:00
Andreas Rheinhardt 40bdd8cc05 avformat: Avoid allocation for AVStreamInternal
Do this by allocating AVStream together with the data that is
currently in AVStreamInternal; or rather: Put AVStream at the
beginning of a new structure called FFStream (which encompasses
more than just the internal fields and is a proper context in its own
right, hence the name) and remove AVStreamInternal altogether.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-17 13:22:25 +02:00
Andreas Rheinhardt fed0282508 avformat: Avoid allocation for AVFormatInternal
Do this by allocating AVFormatContext together with the data that is
currently in AVFormatInternal; or rather: Put AVFormatContext at the
beginning of a new structure called FFFormatContext (which encompasses
more than just the internal fields and is a proper context in its own
right, hence the name) and remove AVFormatInternal altogether.

The biggest simplifications occured in avformat_alloc_context(), where
one can now simply call avformat_free_context() in case of errors.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-17 04:58:34 +02:00
Andreas Rheinhardt 45bfe8b838 avformat/avio: Move internal AVIOContext fields to avio_internal.h
Currently AVIOContext's private fields are all over AVIOContext.
This commit moves them into a new structure in avio_internal.h instead.
Said structure contains the public AVIOContext as its first element
in order to avoid having to allocate a separate AVIOContextInternal
which is costly for those use cases where one just wants to access
an already existing buffer via the AVIOContext-API.
For these cases ffio_init_context() can't fail and always returned zero,
which was typically not checked. Therefore it has been made to not
return anything.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-25 23:01:54 +02:00
James Almer f140239777 avformat: move AVStream.stream_identifier to AVStreamInternal
It's a private field, no reason to have it exposed in a public header.

Signed-off-by: James Almer <jamrial@gmail.com>
2021-05-07 09:27:22 -03:00
James Almer b9c5fdf602 avformat: move AVStream.{parser,need_parsing} to AVStreamInternal
Those are private fields, no reason to have them exposed in a public
header.

Signed-off-by: James Almer <jamrial@gmail.com>
2021-05-07 09:27:21 -03:00
James Almer fab2ed4704 avformat: move AVStream.probe_packets to AVStreamInternal
It's a private fields, no reason to have it exposed in a public header.

Signed-off-by: James Almer <jamrial@gmail.com>
2021-05-07 09:27:20 -03:00
Andreas Rheinhardt bc70684e74 avformat: Constify all muxer/demuxers
This is possible now that the next-API is gone.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 11:48:06 -03:00
James Almer 03e767790c avformat/mpegts: set correct extradata size for Opus streams
map_type 0 is always 19 bytes, whereas map_type 1 and 255 are 21 + channel
count bytes.

Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-16 11:08:40 -03:00
James Almer c1fd4033dc avformat/mpegts: add missing sample_rate value to Opus extradata
Finishes fixing ticket #9190.

Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-16 11:08:40 -03:00
James Almer 42422b6dca avformat/mpegts: use av_packet_alloc() to allocate packets
Signed-off-by: James Almer <jamrial@gmail.com>
2021-03-17 15:06:49 -03:00
Marton Balint 2e2891383e avformat: remove some mpegts details from AVStream
These fields were added to support -merge_pmt_versions, but the mpegts demuxer
is also keeping track its programs internally, so that should be a better place
to handle it.

Also it is not a very good idea to keep fields like program_num or
pmt_stream_idx in an AVStream, because a single stream can be part of multiple
programs, multiple PMTs, so the stream attributes can refer to any program the
stream is part of.

Since they are not part of public API, lets simply remove them, or rather
replace them with placeholders for ABI compatibility with libavdevice.

Signed-off-by: Marton Balint <cus@passwd.hu>
2021-01-09 22:38:12 +01:00
Marton Balint e57879ec18 avformat/mpegts: use stream index based lookup with merge_pmt_versions if stream identifier matches multiple streams
Also make sure we are checking the old state of the streams because otherwise
some streams might already have the newly parsed stream identifiers which
corrupts matching.

Fixes streams having the same identifier mixed up on pmt version change.

Fixes ticket #9006.

Signed-off-by: Marton Balint <cus@passwd.hu>
2021-01-09 22:38:12 +01:00
Marton Balint f143a6c151 avformat/mpegts: only clear programs which no longer exist or have a new PMT
Otherwise there can be a small period when the programs only contain the PMT
pid.

Also make sure skip_clear only affects AVProgram clear, and that pmt_pid is
always kept as the first entry of the PID list of the programs. Also reject
PMTs for programs on the wrong PID.

Signed-off-by: Marton Balint <cus@passwd.hu>
2021-01-09 22:38:12 +01:00