Commit Graph

309 Commits

Author SHA1 Message Date
Anton Khirnov 83548fe894 lavf: fix usage of AVIOContext.seekable
It is supposed to be a flag. The only currently defined value is
AVIO_SEEKABLE_NORMAL, but other ones may be added in the future.
However all the current lavf code treats this field as a bool (mainly
for historical reasons).
Change all those cases to properly check for AVIO_SEEKABLE_NORMAL.
2016-09-30 16:54:33 +02:00
Vittorio Giovara 41ed7ab45f cosmetics: Fix spelling mistakes
Signed-off-by: Diego Biurrun <diego@biurrun.de>
2016-05-04 18:16:21 +02:00
Luca Barbato 74d98d1b0e mpegts: Validate the SL Packet Header Configuration
timeStampLength, OCRLength and AU_Length have well specified upper
boundaries.

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
2016-05-03 14:21:45 +09:00
Luca Barbato 9765549f55 mpegts: Forward the errors on mpeg4 objects parsing
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
2016-03-20 01:04:12 +01:00
Anton Khirnov 9200514ad8 lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.

In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.

There are multiple important problems with this approach:
    - the fields in AVCodecContext are in general one of
        * stream parameters
        * codec options
        * codec state
      However, it's not clear which ones are which. It is consequently
      unclear which fields are a demuxer allowed to set or a muxer allowed to
      read. This leads to erratic behaviour depending on whether decoding or
      encoding is being performed or not (and whether it uses the AVStream
      embedded codec context).
    - various synchronization issues arising from the fact that the same
      context is used by several different APIs (muxers/demuxers,
      parsers, bitstream filters and encoders/decoders) simultaneously, with
      there being no clear rules for who can modify what and the different
      processes being typically delayed with respect to each other.
    - avformat_find_stream_info() making it necessary to support opening
      and closing a single codec context multiple times, thus
      complicating the semantics of freeing various allocated objects in the
      codec context.

Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2016-02-23 17:01:58 +01:00
Luca Barbato ce70f28a17 avpacket: Replace av_free_packet with av_packet_unref
`av_packet_unref` matches the AVFrame ref-counted API and can be used as
a drop in replacement.

Deprecate `av_free_packet`.
2015-10-26 18:00:55 +01:00
wm4 cc8db76061 mpegts: use avcodec_get_type() to set codec_type
Note that this slightly changes behavior: it sets AVMEDIA_TYPE_UNKNOWN
if the codec type is unknown. This should be ok.

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2015-09-28 10:50:50 +02:00
Vittorio Giovara 059a934806 lavc: Consistently prefix input buffer defines
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2015-07-27 15:24:59 +01:00
John Högberg 42bc768e52 mpegts: Add jpeg2000 stream type
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
2015-06-30 10:08:16 +02:00
John Högberg 82de8d7111 mpegts: Update the PSI/SI table only if the version change
If a PAT is finished while a PMT section filter is opened but
not yet finished, the PMT section filter is closed and all
the received data is discarded.

This is usually not an issue but some multiplexers (With very
quick PAT/PMT repetition settings) consistently emit a PMT
section start, then a PAT, and then the rest of the PMT,
causing the aforementioned behavior to result in no PMT being
finished.

In the most pathologic situation the stream information are lost
and the probe fallback miscategorizes subtitles as mp3 audio.

Avoid the issue through eliminating redundant PSI/SI table
updates by checking their version field, which is required by
the standard to be incremented on every change no matter how
minor.

CC: libav-stable@libav.org

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
2015-04-28 21:09:59 +02:00
Vittorio Giovara 1a3eb042c7 Replace av_dlog with normal av_log at trace level
This applies to every library where performance is not critical.
2015-04-19 12:41:59 +01:00
Diego Biurrun daf8cf358a avformat: Don't anonymously typedef structs 2015-02-14 10:13:47 -08:00
Anton Khirnov 1509c018bd mpegts: relax restrictions on matching the packet start in read_header
analyze() is currently called both when probing and from read_header().
It determines the packet start by looking for the sync byte, followed by
unset Transport Error Indicator and valid adaptation_field_control.

This makes sense to do when probing, but once we already know the format
is MPEG-TS, it is counterproductive to be so strict -- e.g. in some
files the TEI might be set and analyze() might get called with a smaller
buffer than the one used for probing, resulting in a failure.
2015-02-10 21:43:44 +01:00
wm4 6a5b8ca432 lavf: remove unused code
Nothing uses it, and it provides no public API.

Archeological finds:

Commit 101036adb9 added the API.
Commit a8dd8dc6e9 made mpegts.c use it.
Commit af8aae3fa3 disabled it by default in mpegts.c.
Commit ae2bb52cd2 removed all uses of this from mpegts.c.

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2015-02-08 21:34:05 +01:00
Kieran Kunhya 9cfa68c560 mpegts: add support for Opus
Signed-off-by: Anton Khirnov <anton@khirnov.net>
2014-12-20 11:29:19 +01:00
Vittorio Giovara 8b263331c5 mpegts: check get16() return value
And break flow of execution rather than exiting the function.

CC: libav-stable@libav.org
Bug-Id: CID 732186
2014-12-18 23:27:13 +01:00
Luca Barbato 7968059e5c mpegts: Allow custom max resync size 2014-09-03 02:38:03 +02:00
Gabriel Dume f929ab0569 cosmetics: Write NULL pointer equality checks more compactly
Signed-off-by: Diego Biurrun <diego@biurrun.de>
2014-08-15 03:18:18 -07:00
Jan Gerber fc27e7272e mpegts: do not export empty language tags
Signed-off-by: Anton Khirnov <anton@khirnov.net>
2014-07-21 19:39:31 +00:00
Alexander V. Lukyanov 5adcef9c1b mpegts: pass MpegTSContext ptr explicitly
AVFormatContext->priv_data is not always a MpegTSContext, it can be
RTSPState when decoding a RTP stream. So it is necessary to pass
MpegTSContext pointer explicitly.

Within libav, the write_section_data function doesn't actually use
the MpegTSContext at all, so this doesn't change anything at the
moment (no memory was corrupted before), but it reduces the risk of
anybody trying to touch the MpegTSContext via AVFormatContext->priv_data
in the future.

Signed-off-by: Martin Storsjö <martin@martin.st>
2014-07-10 11:24:19 +03:00
Keiji Costantini ca80e15814 mpegts: Forward error codes in various functions
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2014-03-18 08:20:35 +01:00
Keiji Costantini 86ba2327e1 mpegts: K&R formatting cosmetics
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2014-03-18 08:07:43 +01:00
Vittorio Giovara 5397386eff mathops: move macro to the only place it is used
This helps in disentangling lavf and lavc too.
2014-03-04 11:45:31 +01:00
Leandro Dorileo 8370a6fa59 libavformat/mpegts: expose raw packet size
We cannot easily determine if an mpeg TS's packet size is DVHS, FEC
or so on, for that we need to expose the internal raw_packet_size
field.

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2014-02-19 21:52:17 +01:00
Carl Eugen Hoyos 9fa75be96d mpegts: add HEVC registration descriptor 2013-12-12 16:10:15 +01:00
Mickaël Raulet b6a4701612 mpegts: Support HEVC demuxing
Signed-off-by: Anton Khirnov <anton@khirnov.net>
2013-10-31 20:20:57 +01:00
Alexandra Khirnova f369b9356c avformat: Use av_reallocp_array() where suitable
Signed-off-by: Diego Biurrun <diego@biurrun.de>
2013-09-10 12:38:32 +02:00
Ben Avison 5afe1d2791 avio: Add const qualifiers to ffio_read_indirect
This provides at least some protection against potential accidental
corruption of AVIO buffer workspace.

Signed-off-by: Martin Storsjö <martin@martin.st>
2013-08-08 11:09:00 +03:00
Ben Avison a22ae9f0c5 mpegts: Remove one 64-bit integer modulus operation per packet
The common case of the pointer having increased by one packet (which results
in no change to the modulus) can be detected with a 64-bit subtraction,
which is far cheaper than a division on many platforms.

           Before          After
           Mean   StdDev   Mean   StdDev  Change
Divisions   248.3  8.8      51.5   7.4    +381.7%
Overall    2773.2 25.6     2372.5 43.1     +16.9%

Signed-off-by: Martin Storsjö <martin@martin.st>
2013-08-05 19:25:55 +03:00
Ben Avison c84ea750cf mpegts: Make discard_pid() faster for single-program streams
When a stream contains a single program, there's no point in doing a
PID -> program lookup. Normally the one and only program isn't disabled,
so no packets should be discarded.

              Before          After
              Mean   StdDev   Mean   StdDev  Change
discard_pid()   73.8  9.4       20.2  1.5    +264.8%
Overall       2300.8 28.0     2253.1 20.6      +2.1%

Signed-off-by: Martin Storsjö <martin@martin.st>
2013-08-05 15:18:42 +03:00
Ben Avison cabb168169 mpegts: Remove one memcpy per packet
This was being performed to ensure that a complete packet was held in
contiguous memory, prior to parsing the packet. However, the source buffer
is typically large enough that the packet was already contiguous, so it is
beneficial to return the packet by reference in most cases.

         Before          After
         Mean   StdDev   Mean   StdDev  Change
memcpy    720.7  32.7     649.8  25.1   +10.9%
Overall  2372.7  46.1    2291.7  21.8    +3.5%

Signed-off-by: Martin Storsjö <martin@martin.st>
2013-08-05 15:14:31 +03:00
Can Wu 81cf53e133 mpegts: add support for stream_type 0x42, which is CAVS
This allows demuxing and muxing of CAVS TS streams.

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2013-03-15 09:33:24 +01:00
Diego Biurrun 1ecdf8912b avformat: av_log_ask_for_sample() ---> avpriv_request_sample() 2013-03-13 20:42:21 +01:00
Diego Biurrun 63d744e2be av_log_missing_feature() ---> avpriv_report_missing_feature() 2013-03-13 20:42:21 +01:00
Anton Khirnov 1afddbe59e avpacket: use AVBuffer to allow refcounting the packets.
This will allow us to avoid copying the packets in many cases.

This breaks ABI.
2013-03-08 07:33:45 +01:00
Martin Storsjö a717f99042 mpegts: Share the cleanup code between the demuxer and lavf-internal parser functions
The lavf-internal parser functions are used when receiving
mpegts over RTP. This fixes memory leaks in this setup.

The normal mpegts demuxer close function was updated in ec7d0d2e in
2004 to fix leaks, but the parsing function used for RTP wasn't
updated and has been leaking ever since.

Signed-off-by: Martin Storsjö <martin@martin.st>
2013-01-20 18:14:17 +02:00
Michael Niedermayer 41540b36a1 bitstream: add get_bits64() to support reading more than 32 bits at once
Also remove a duplicate function in the MPEG-TS demuxer.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Signed-off-by: Justin Ruggles <justin.ruggles@gmail.com>
2012-12-07 16:15:02 -05:00
Diego Biurrun 15d35bee83 mpegts: Drop pointless casting of hex_dump_debug arguments 2012-10-01 13:18:28 +02:00
Diego Biurrun 72eaba5e4f avformat: Convert some commented-out printf/av_log instances to av_dlog 2012-10-01 10:24:28 +02:00
Christian Schmidt 07584eaf4a mpegts: check substreams before discarding
Allow to extract the AC3 core from TrueHD with the "copy" codec.

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
2012-09-12 23:43:53 +02:00
Martin Storsjö e6153f173a avopt: Store defaults for AV_OPT_TYPE_INT in the i64 union member
Signed-off-by: Martin Storsjö <martin@martin.st>
2012-09-04 23:13:44 +03:00
Anton Khirnov 36ef5369ee Replace all CODEC_ID_* with AV_CODEC_ID_* 2012-08-07 16:00:24 +02:00
Diego Biurrun 0177b7d23a Improve descriptiveness of a number of codec and container long names 2012-07-30 20:46:55 +02:00
Ronald S. Bultje ae2bb52cd2 mpegts: remove unused/incomplete/broken seeking code 2012-06-19 00:56:43 +01:00
Alex Converse a8656cd425 mpegts: Remove disabled extension matching probe. 2012-06-07 12:27:04 -07:00
Joakim Plate 68b9ed8391 mpegts: Some additional HDMV types and reg descriptors for mpegts
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2012-05-03 12:13:28 -04:00
Martin Storsjö df8aa4598c mpegts: Make sure we don't return uninitialized packets
This fixes crashes, where the demuxer could return 0 even
if the returned AVPacket isn't initialized at all. This
could happen if running into EOF or running out of probesize
with non-seekable sources.

Signed-off-by: Martin Storsjö <martin@martin.st>
2012-04-27 20:05:37 +03:00
Martin Storsjö 269cb6751b mpegts: Try seeking back even for nonseekable protocols
The mpegts demuxer reads 5 KB at startup just for discovering
the packet size. Since the default avio buffer size is 32 KB,
the seek back to the start will in most cases be within the
avio buffer, and will in most cases succeed even if the actual
protocol isn't seekable.

This makes the demuxer startup faster/with less data when
reading data from a non-seekable input, by not skipping
the first few KB.

If it fails, don't warn if the protocol isn't seekable, making
it behave as before in the failure case.

Signed-off-by: Martin Storsjö <martin@martin.st>
2012-04-23 00:02:49 +03:00
Martin Storsjö 20234a4bd7 cosmetics: Align muxer/demuxer declarations
Also add missing trailing commas, break long codec_tag lines and
add spaces in codec_tag declarations.

Signed-off-by: Martin Storsjö <martin@martin.st>
2012-04-06 19:19:59 +03:00
Alex Converse c9024a9fd7 mpegts: Fix dead error checks 2012-03-26 17:53:51 -07:00