Commit Graph

1855 Commits

Author SHA1 Message Date
Michael Niedermayer
c48ceff786 avformat/utils: Fix integer overflow in end time calculation in update_stream_timings()
Fixes: crbug 829153

Reported-by: Matt Wolenetz <wolenetz@google.com>
Reviewed-by: Matt Wolenetz <wolenetz@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-04-13 21:46:16 +02:00
Bela Bodecs
3e1204b94d avformat/utils: Stream specifier enhancement 2.
In some cases, mainly working with multiprogram mpeg-ts containers as
input, it would be handy to select sub stream of a specific program by
their metadata.
This patch makes it possible to narrow the stream selection among
streams of the specified program by stream metadata.

Examples:
p:601:m:language:hun  will select all sub streams of program with id 601
where sub streams have metadata key named 'language' with value 'hun'.
p:602:m:guide  will select all sub streams of program with id 602 where
sub streams have metadata key named 'guide'.

Signed-off-by: Bela Bodecs <bodecsb@vivanet.hu>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-04-13 21:44:28 +02:00
Bela Bodecs
37d0213968 avformat/utils: Stream specifier enhancement
Currently when specifying the program id you can only decide to select
all stream of the specified program (e.g. p:103 will select all streams
of program 103) or narrow the selection to a specific stream sub index
(e.g. p:145:1 will select 2nd stream of program 145.) But you can not
specify like all audio streams of program 145 or 3rd video stream of
program 311.
In some case, mainly working with multiprogram mpeg-ts containers as
input, this feature would be handy.
This patch makes it possible to narrow the stream selection among
streams of the specified program by stream type and optionally its
index. Handled types: a, v, s, d.
Examples: p:601:a  will select all audio streams of program 601,
p:603:a:1 will select 2nd audio streams of program 603,
p:604:v:0 will select first video stream of program 604.

Signed-off-by: Bela Bodecs <bodecsb@vivanet.hu>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-04-12 23:52:59 +02:00
James Almer
58ce4fdeae avformat/utils: optimize ff_packet_list_free()
Don't constantly overwrite the list's head pointer.

Signed-off-by: James Almer <jamrial@gmail.com>
2018-04-04 00:15:38 -03:00
James Almer
3a4d74c1ff avformat/utils: make AVPacketList helper functions shared
Based on a patch by Luca Barbato.

Signed-off-by: James Almer <jamrial@gmail.com>
2018-04-04 00:15:37 -03:00
James Almer
02ae52db87 avformat/utils: use av_packet_make_refcounted to ensure packets are ref counted
Simplifies code, while also fixing a potential leak of side data in pkt.

Signed-off-by: James Almer <jamrial@gmail.com>
2018-04-02 00:37:51 -03:00
Sasi Inguva
829aebf95d lavf/utils.c: Don't compute start_time from DISCARD packets for video.
Signed-off-by: Sasi Inguva <isasi@isasi.mtv.corp.google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-03-24 03:11:08 +01:00
Michael Niedermayer
1b1362e408 avformat/utils: Fix integer overflow of fps_first/last_dts
Fixes: runtime error: signed integer overflow: 7738135736989908991 - -7898362169240453118 cannot be represented in type 'long'
Fixes: Chromium bug 796778
Reported-by: Matt Wolenetz <wolenetz@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-03-07 20:37:33 +01:00
James Almer
2aa42fac77 avformat/utils: simplify ff_alloc_extradata()
Cosmetic refactor

Reviewed-by: 74a2fa708af88d225ed708af758f236f869b1a57
Signed-off-by: James Almer <jamrial@gmail.com>
2018-03-06 19:13:46 -03:00
James Almer
0ca33b1d4e avformat/utils: free existing extradata before trying to allocate a new one
This prevents leaks in the rare cases the function is called when extradata
already exists.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2018-03-06 19:13:12 -03:00
James Almer
f235359b2b avformat/utils: don't overwrite the return value of read_packet()
This only affected demuxers that didn't return reference counted packets.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2018-02-26 22:17:21 -03:00
Tomas Härdin
5655048c73 Add muxer/demuxer for raw codec2 and .c2 files 2018-02-24 17:06:31 +01:00
Marton Balint
fa8308d3d4 avformat: deprecate AVFormatContext filename field
Signed-off-by: Marton Balint <cus@passwd.hu>
2018-01-28 23:06:43 +01:00
Marton Balint
18ac642359 avformat: migrate to AVFormatContext->url
Signed-off-by: Marton Balint <cus@passwd.hu>
2018-01-28 23:06:43 +01:00
Marton Balint
ea3672b7d6 avformat: add url field to AVFormatContext
This will replace the 1024 character limited filename field. Compatiblity for
output contexts are provided by copying filename field to URL if URL is unset
and by providing an internal function for muxers to set both url and filename
at once.

Signed-off-by: Marton Balint <cus@passwd.hu>
2018-01-28 23:06:43 +01:00
Richard Shaffer
8a4cc0a256 avformat: add option to parse/store ID3 PRIV tags in metadata.
Enables getting access to ID3 PRIV tags from the command-line or metadata API
when demuxing. The PRIV owner is stored as the metadata key prepended with
"id3v2_priv.", and the data is stored as the metadata value. As PRIV tags may
contain arbitrary data, non-printable characters, including NULL bytes, are
escaped as \xXX.

Similarly, any metadata tags that begin with "id3v2_priv." are inserted as ID3
PRIV tags into the output (assuming the format supports ID3). \xXX sequences in
the value are un-escaped to their byte value.

Signed-off-by: wm4 <nfxjfg@googlemail.com>
2018-01-24 04:01:01 +01:00
wm4
631c56a8e4 avformat: make avformat_network_init() explicitly optional
It was sort of optional before - if you didn't call it, networking was
initialized on demand, and an ugly warning was logged. Also, the doxygen
comments threatened that it would be made strictly required one day.

Make it explicitly optional. I would prefer to deprecate it fully, but
there might still be legitimate reasons to use this. But the average
user won't need it.

This is needed only for two reasons: to initialize TLS libraries like
OpenSSL and GnuTLS, and winsock.

OpenSSL and GnuTLS were already silently initialized on demand if the
global network init function was not called. They also have various
thread-safety acrobatics, which make concurrent initialization within
libavformat safe. In addition, the libraries are moving towards making
their global init functions safe, which removes all need for central
global init. In particular, GnuTLS 3.5.16 and OpenSSL 1.1.0g have been
found to have safe init functions. In all cases, they use internal
reference counters to avoid that the global uninit functions interfere
with concurrent uses of the library by other API users who called global
init.

winsock should be thread-safe as well, and maintains an internal
reference counter as well.

Since we still support ancient TLS libraries, which do not have this
fixed, and since it's unknown whether winsock and GnuTLS
reinitialization is costly in any way, don't deprecate the libavformat
functions yet.
2018-01-16 12:57:04 +01:00
wm4
6512ff72f9 avformat: deprecate another ffserver API leftover 2018-01-16 12:54:53 +01:00
Karthick Jeyapal
e8f71ef338 avformat/hlsenc, utils: Moved is_http_proto from hlsenc to utils for re-use
Reviewed-by: Aman Gupta <aman@tmm1.net>
Reviewed-by: Steven Liu <lq@onvideo.cn>
2017-12-29 18:11:09 +08:00
wm4
86a13bf2ff lavc, lavf: move avformat static mutex from avcodec to avformat
It's completely absurd that libavcodec would care about libavformat
locking, but it was there because the lock manager was in libavcodec.

This is more stright forward. Changes ABI, but we don't require ABI
compatibility currently.
2017-12-26 02:50:00 +01:00
James Almer
31de45d20b avformat/utils: fix mixed declarations and code
Signed-off-by: James Almer <jamrial@gmail.com>
2017-11-24 17:46:16 -03:00
Dale Curtis
03fbc0daa7 avformat/utils: Prevent undefined shift with wrap_bits > 64.
2LL << (wrap_bits=64 - 1) does not fit in int64_t; change the
code to use a uint64_t (2ULL) and add an av_assert2() to
ensure wrap_bits <= 64.

Signed-off-by: Dale Curtis <dalecurtis@chromium.org>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-11-24 19:03:03 +01:00
James Almer
d8ea66ab33 avformat/utils: remove usage of AVCodecContext accessors
Signed-off-by: James Almer <jamrial@gmail.com>
2017-11-15 01:14:22 -03:00
Michael Niedermayer
b197d83ca3 avformat/utils: Look at the first 3 frames if timestamps indicate frame reorder but decoder delay does not
Fixes: Ticket6487

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-11-11 14:15:15 +01:00
John Stebbins
c84bc81158 avformat/utils: preserve AV_PKT_FLAG_DISCARD in parse_packet
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-11-11 14:15:15 +01:00
Aurelien Jacobs
018eef1a1b aptx: add raw muxer and demuxer for aptX 2017-11-10 21:32:06 +00:00
James Almer
cd1ff3e45d avformat: move priv_pts from AVStream to an internal struct
It has no reason to be in a public header, even if defined as private.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2017-11-07 23:20:50 -03:00
James Almer
b7785d10b0 avformat: deprecate getters and setters for AVFormatContext and AVStream fields
The fields can be accessed directly, so these are not needed anymore.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2017-10-29 10:29:43 -03:00
James Almer
1e5669457f Merge commit '9e4a5eb51b9f3b2bff0ef08e0074b7fe4893075d'
* commit '9e4a5eb51b9f3b2bff0ef08e0074b7fe4893075d':
  avformat: Free the internal codec context at the end

Merged-by: James Almer <jamrial@gmail.com>
2017-10-28 14:01:25 -03:00
James Almer
b89081e01b avformat: remove dead av_stream_get_side_data() cruft
Signed-off-by: James Almer <jamrial@gmail.com>
2017-10-22 01:36:28 -03:00
James Almer
ca4df37f06 avformat: remove ABI portion of the side data merging API
Signed-off-by: James Almer <jamrial@gmail.com>
2017-10-22 01:29:41 -03:00
Lukas Stabe
1fd80106be avformat: fix id3 chapters
These changes store id3 chapter data in ID3v2ExtraMeta and introduce
ff_id3v2_parse_chapters to parse them into the format context if needed.

Encoders using ff_id3v2_read, which previously parsed chapters into the
format context automatically, were adjusted to call
ff_id3v2_parse_chapters.

Signed-off-by: wm4 <nfxjfg@googlemail.com>
2017-10-05 17:10:23 +02:00
Carl Eugen Hoyos
2f3a3a7e32 lavf/utils: Do not force chapter end time before chapter start.
Fixes ticket #6671.
2017-09-20 00:57:29 +02:00
Marton Balint
7160992431 avformat/utils: always av_reduce r_frame_rate
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Marton Balint <cus@passwd.hu>
2017-08-17 21:02:40 +02:00
Steven Siloti
949debd1d1 avformat/utils: fix memory leak in avformat_free_context
The pointer to the packet queue is stored in the internal structure
so the queue needs to be flushed before internal is freed.

Signed-off-by: Steven Siloti <ssiloti@bittorrent.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-08-05 23:24:02 +02:00
wm4
66cf78e932 lavf: consider codec framerate for framerate detection
Fixes detection of some TV sample as 24.5 FPS. With the patch applied,
it's detected as 25 FPS.

This is enabled for mpegts only.
2017-06-07 11:08:06 +02:00
Michael Niedermayer
850cbd496f avformat/utils: Slightly un-clutter code in determinable_frame_size() by using a switch
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-06-06 18:31:47 +02:00
Marton Balint
880504814a avformat/utils: change bitrate to int64_t in av_find_best_stream
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Marton Balint <cus@passwd.hu>
2017-06-04 15:02:53 +02:00
Marton Balint
47c699f7be avformat/utils: return impaired streams in av_find_best_stream if only those exist
Fixes ticket #6397.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Marton Balint <cus@passwd.hu>
2017-06-04 15:02:53 +02:00
Michael Niedermayer
53e0d5d724 avformat/options: log filename on open
The loglevel is choosen so that the main filename and any images of
multi image sequences are shown only at debug level to avoid
clutter.

This makes exploits in playlists more visible. As they would show
accesses to private/sensitive files

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-06-03 23:14:04 +02:00
Aaron Levinson
b9d2005ea5 avformat/utils: free AVStream.codec properly in free_stream()
Fixes memory leaks.

Signed-off-by: James Almer <jamrial@gmail.com>
2017-05-06 17:23:28 -03:00
Luca Barbato
9e4a5eb51b avformat: Free the internal codec context at the end
Avoid a use after free in avformat_find_stream_info.

CC: libav-stable@libav.org
2017-04-13 13:37:10 +02:00
James Almer
b8f26779d6 lavf: use the new bitstream filter for extracting extradata
This merges commits 8e2ea69135 and
096a8effa3 by Anton Khirnov, with the
following change:

- extract_extradata_check() is added to know if the codec is supported
by the bsf before trying to initialize it. This behaviour is similar to
the old AVCodecParser.split checks.

The FATE reference changes are due to the filtered out NAL units that
the old AVCodecParser.split implementation left alone.
Decoding is unchanged as the functions that parse extradata simply
ignored said unnecessary NAL units.

Signed-off-by: James Almer <jamrial@gmail.com>
2017-04-07 17:16:17 -03:00
James Almer
40fa9d416a Revert "Merge commit '8e2ea691351c5079cdab245ff7bfa5c0f3e3bfe4'"
This reverts commit 1c193ac1f9, reversing
changes made to 7ebc9f8df4.

Several FATE tests started failing after this merge, so it's reverted
until it can be properly fixed.
2017-03-23 19:34:00 -03:00
James Almer
1c193ac1f9 Merge commit '8e2ea691351c5079cdab245ff7bfa5c0f3e3bfe4'
* commit '8e2ea691351c5079cdab245ff7bfa5c0f3e3bfe4':
  lavf: use the new bitstream filter for extracting extradata

Merged-by: James Almer <jamrial@gmail.com>
2017-03-23 16:52:42 -03:00
James Almer
4de591e6fb Merge commit '83548fe894cdb455cc127f754d09905b6d23c173'
* commit '83548fe894cdb455cc127f754d09905b6d23c173':
  lavf: fix usage of AVIOContext.seekable

Merged-by: James Almer <jamrial@gmail.com>
2017-03-21 17:02:30 -03:00
wm4
d682ae70b4 avcodec, avformat: deprecate anything related to side data merging
This patch deprecates anything that has to do with merging/splitting
side data. Automatic side data merging (and splitting), as well as all
API symbols involved in it, are removed completely.

Two FF_API_ defines are dedicated to deprecating API symbols related to
this: FF_API_MERGE_SD_API removes av_packet_split/merge_side_data in
libavcodec, and FF_API_LAVF_KEEPSIDE_FLAG deprecates
AVFMT_FLAG_KEEP_SIDE_DATA in libavformat.

Since it was claimed that changing the default from merging side data to
not doing it is an ABI change, there are two additional FF_API_ defines,
which stop using the side data merging/splitting by default (and remove
any code in avformat/avcodec doing this): FF_API_MERGE_SD in libavcodec,
and FF_API_LAVF_MERGE_SD in libavformat.

It is very much intended that FF_API_MERGE_SD and FF_API_LAVF_MERGE_SD
are quickly defined to 0 in the next ABI bump, while the API symbols are
retained for a longer time for the sake of compatibility.
AVFMT_FLAG_KEEP_SIDE_DATA will (very much intentionally) do nothing for
most of the time it will still be defined. Keep in mind that no code
exists that actually tries to unset this flag for any reason, nor does
such code need to exist. Code setting this flag explicitly will work as
before. Thus it's ok for AVFMT_FLAG_KEEP_SIDE_DATA to do nothing once
side data merging has been removed from libavformat.

In order to avoid that anyone in the future does this incorrectly, here
is a small guide how to update the internal code on bumps:

- next ABI bump (probably soon):
  - define FF_API_LAVF_MERGE_SD to 0, and remove all code covered by it
  - define FF_API_MERGE_SD to 0, and remove all code covered by it
- next API bump (typically two years in the future or so):
  - define FF_API_LAVF_KEEPSIDE_FLAG to 0, and remove all code covered
    by it
  - define FF_API_MERGE_SD_API to 0, and remove all code covered by it

This forces anyone who actually wants packet side data to temporarily
use deprecated API to get it all. If you ask me, this is batshit fucked
up crazy, but it's how we roll. Making AVFMT_FLAG_KEEP_SIDE_DATA to be
set by default was rejected as an ABI change, so I'm going all the way
to get rid of this once and for all.

Reviewed-by: James Almer <jamrial@gmail.com>
Reviewed-by: Rostislav Pehlivanov <atomnuker@gmail.com>
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
2017-03-21 06:13:45 +01:00
Michael Niedermayer
3206ea4ba3 avformat/utils: Also fill dts==RELATIVE_TS_BASE packets in update_initial_durations()
This dts value can end up in the list in the absence of durations and is in that
case semantically identical to AV_NOPTS_VALUE. We can alternatively prevent
storing RELATIVE_TS_BASE if there is no duration.

Fixes Ticket3640

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-02-19 02:07:12 +01:00
Paul Arzelier
65862f57ad avformat: Ignore ID3v2 tags if other tags are present e.g. vorbis
Reviewed-by: wm4 <nfxjfg@googlemail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-01-28 23:08:42 +01:00
Matt Wolenetz
fe7547d69e lavf/utils.c Protect against accessing entries[nb_entries]
In ff_index_search_timestamp(), if b == num_entries,
m == num_entries - 1, and entries[m].flags & AVINDEX_DISCARD_FRAME is
true, then the search for the next non-discarded packet could access
entries[nb_entries], exceeding its bounds. This change adds a protection
against that scenario. Reference: https://crbug.com/666770

Reviewed-by: Sasi Inguva <isasi@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-12-30 00:11:18 +01:00