Commit Graph

673 Commits

Author SHA1 Message Date
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
Marton Balint 10c8e53294 avformat/mpegts: rework clearing and adding pid to program
And use better function names.

Signed-off-by: Marton Balint <cus@passwd.hu>
2021-01-09 22:38:12 +01:00
Marton Balint 5ea37923a8 avformat/mpegts: never discard PAT pid
PID 0 was removed from the pid list when then PMT was parsed, it is better
to explictly avoid it from being discarded instead of keeing it in the list of
every program.

Signed-off-by: Marton Balint <cus@passwd.hu>
2021-01-09 22:38:12 +01:00
Michael Niedermayer 654b21ef17 avformat/mpegts: Fix argument type for av_log
Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-12-28 19:36:57 +01:00
Michael Niedermayer c0e660ba14 avformat/mpegts: simplify nb_packets code
Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-12-22 00:30:50 +01:00
Michael Niedermayer ef7b117b7b avformat/mpegts: Increase pcr_incr width to 64bit
Fixes: division by zero
Fixes: 26459/clusterfuzz-testcase-minimized-ffmpeg_dem_MPEGTSRAW_fuzzer-5666350112178176
Fixes: 28154/clusterfuzz-testcase-minimized-ffmpeg_dem_MPEGTSRAW_fuzzer-5195728439476224

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>
2020-12-22 00:30:50 +01:00
Michael Niedermayer 4bdb7966fa avformat/mpegts: Limit iterations of get_packet_size()
This is a pathological case where the fuzzer provides only 2 bytes per iteration.

Fixes: Timeout (>30 -> 0.9sec)
Fixes: 26488/clusterfuzz-testcase-minimized-ffmpeg_dem_MPEGTS_fuzzer-5911031077142528

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-11-29 16:10:55 +01:00
Marton Balint bf19833ae2 avformat/mpegts: make sure mpegts_read_header always stops at the first pmt
mpegts_read_header stops parsing the file at the first PMT. However the check
that ensured this was wrong because streams can also be added before the first
PMT is received (e.g. EIT).

So let's make sure we are in the header reading phase by checking if ts->pkt is
unset instead of checking if the number of streams found so far is 0.

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-11-19 21:22:07 +01:00
Michael Niedermayer 79cf7c7191 avformat/mpegts: Limit copied data to space
Fixes: out of array access
Fixes: 26816/clusterfuzz-testcase-minimized-ffmpeg_dem_MPEGTSRAW_fuzzer-6282861159907328.fuzz

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>
2020-11-07 20:10:51 +01:00
Anton Khirnov 108864acee lavf: move AVStream.{request_probe,skip_to_keyframe} to AVStreamInternal
Those are private fields, no reason to have them exposed in a public
header.
2020-10-28 14:57:01 +01:00
Anton Khirnov 323c9a8c52 lavf: move AVStream.{pts_wrap_*,update_initial_durations_done} to AVStreamInternal
Those are private fields, no reason to have them exposed in a public
header.
2020-10-28 14:54:51 +01:00
Brad Hards fcec7a6848 avformat/mpegts: replace magic descriptor_tag values with defines
This takes the used values from ISO/IEC 13818-1 Table 2-45 and adds
them to the mpegts.h header. No functional changes.

Signed-off-by: Brad Hards <bradh@frogmouth.net>
Signed-off-by: Marton Balint <cus@passwd.hu>
2020-10-16 23:31:45 +02:00