1
mirror of https://git.videolan.org/git/ffmpeg.git synced 2024-09-04 07:21:31 +02:00
Commit Graph

39 Commits

Author SHA1 Message Date
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
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
Andreas Rheinhardt
56450a0ee4 avformat: Constify the API wrt AV(In|Out)putFormat
Also constify AVProbeData.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 10:43:08 -03:00
Andreas Rheinhardt
3651d6f276 avformat/webm_chunk: Use ff_stream_encode_params_copy()
It is simpler and more complete (e.g. it copies the framerate
information which allows to write the default duration element).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-18 02:29:23 +02:00
Andreas Rheinhardt
aef670cff4 avformat/webm_chunk: Open AVIOContext before initializing sub-muxer
The description of AVOutputFormat.init contains the statement that "this
method must not write output". Due to this, the webm_chunk muxer defers
opening the AVIOContext for the child muxer until avformat_write_header(),
i.e. there is no AVIOContext when the sub-muxer's avformat_init_output()
is called. But this violates the documentation of said function which
requires the AVFormatContext to have an already opened AVIOContext.
This commit fixes this.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-23 07:15:35 +02:00
Andreas Rheinhardt
0c0a1d73c2 avformat/Makefile: Remove false dependencies of WebM and Matroska muxer
These muxers don't depend on the WebM Chunk or the WebM DASH Manifest
muxers.

Furthermore, remove some #if checks in webm_chunk.c and webmdashenc.c.
They are always true now that webm_chunk.c and webmdashenc.c are only
compiled when their corresponding muxers are enabled.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-04-14 18:43:44 +02:00
Andreas Rheinhardt
d8e63ed70e avformat/webm_chunk: Remove superfluous headers
libavutil/avstring.h is unnecessary since 8a632b3e. The other
unnecessary headers were never used.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-04-14 18:33:14 +02:00
Andreas Rheinhardt
107783006c avformat/webm_chunk: Cosmetics
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-03-26 02:39:14 +01:00
Andreas Rheinhardt
f289a6b721 avformat/webm_chunk: Check unchecked functions for errors
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-03-26 02:31:52 +01:00
Andreas Rheinhardt
d624fb5dad avformat/webm_chunk: Add deinit function
This fixes memleaks if an error happens after one of the allocations
in init; or if the trailer isn't written (e.g. because there was an
error when writing a packet).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-03-26 02:28:13 +01:00
Andreas Rheinhardt
42b000427d avformat/webm_chunk: Add init function
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-03-26 02:25:14 +01:00
Andreas Rheinhardt
73a595b8e8 avformat/webm_chunk: Remove unnecessary variable
chunk_start_index (which was set via an option) was only used to
initialize chunk_index and otherwise unused. So initialize chunk_index
directly via the option and remove chunk_start_index.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-03-26 02:22:46 +01:00
Andreas Rheinhardt
8a632b3e2e avformat/webm_chunk: Don't copy header filename
Instead just reuse the filename string that is given via an option
for the child muxer's url field.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-03-26 02:17:40 +01:00
Andreas Rheinhardt
f397dc3378 avformat/webm_chunk: Don't keep pointer to AVOutputFormat
It is no longer needed given that the function pointers of the child
muxer's AVOutputFormat are no longer called directly.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-03-26 02:12:10 +01:00
Andreas Rheinhardt
3d4dd9195f avformat/webm_chunk: Avoid unnecessary flushes
The webm_chunk muxer caches its output to a dynamic buffer and when it
outputs anything, it explicitly flushes it. So set the flags indicating
that flushing after each packet should not be done automatically
(basically avoiding avio_write_marker() to be called by flush_if_needed()
in libavformat/mux.c).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-03-26 02:08:17 +01:00
Andreas Rheinhardt
e70c2d02fc avformat/webm_chunk: Use API functions for child muxer
instead of calling the write_header/packet/trailer functions directly
via the function pointers. Also, use distinct AVStreams for the child
AVFormatContext (up until now the two AVFormatContexts shared their
AVStreams because allocating their own was deemed too onerous).

Using the function pointers directly meant that the Matroska muxer's
init-function was never called, because init-functions were only
introduced a few months after webm_chunk has been added and no one
thought of/bothered to adapt webm_chunk for this (when the init-function
was added in b287d7ea, the code setting the timebase was moved to it,
so that the timebases were no longer set to ms-precision when using
the webm_chunk muxer; this has been fixed after some time in 42a635dd
by setting the timebases direcly (instead of calling the init-function)).

And when 982a98a0 added a deinit-function for the Matroska muxer, it
introduced memleaks in webm_chunk, because the child muxer's internal
structures were no longer freed when calling write_trailer directly.
(Given that the init function has never ever been called, the child
muxer has never ever been properly initialized, so that the
deinit-function was not called when freeing the child context.)

This commit stops calling the function pointers directly and instead
uses the standard API functions for muxers. This fixes the above
mentioned memleaks. (Memleaks are still possible on error. This will be
fixed in a future commit that adds a deinit-function to webm_chunk
itself.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-03-26 01:54:56 +01:00
Andreas Rheinhardt
a9004ffe0f avformat/webm_chunk: Use appropriate initializer for AV_OPT_TYPE_STRING
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-03-26 01:54:06 +01:00
Andreas Rheinhardt
b1b847ba56 avformat/webm_chunk: Copy more information to the child AVFormatContext
In particular the flags are important so that AVFMT_FLAG_BITEXACT can be
honoured by the child muxer.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-03-26 01:52:10 +01:00
Andreas Rheinhardt
2a78968849 avformat/webm_chunk: Close IO if writing header fails
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-03-26 01:49:34 +01:00
Andreas Rheinhardt
0b1af9d330 avformat/webm_chunk: Don't use child AVFormatContext for logging
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-03-26 01:44:06 +01:00
Andreas Rheinhardt
24a64e0462 lavf/webm_chunk: Correct duration if start time > 0
Up until now, it was simply presumed that the first packet had a pts of
zero; otherwise the duration of the first chunk was wrong.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-07-12 14:59:58 +02:00
Andreas Rheinhardt
8c6ee7626b lavf/webm_chunk: Fix NULL dereference
The earlier version of the webm_chunk muxer had several bugs:

1. If the first packet of an audio stream didn't have a PTS of zero,
then no chunk will be started before a packet is delivered to the
underlying Matroska/WebM muxer, i.e. the AVFormatContext used to write
these packets had a NULL as AVIOContext for output. This is behind the
crash in ticket #5752.

2. If an error happens during writing a packet, the underlyimg
Matroska/WebM muxer context is freed. This leads to a use-after-free
coupled with a double-free in webm_chunk_write_trailer (which supposes
that the underlying AVFormatContext is still valid).

3. Even when no error occurs at all, webm_chunk_write_trailer is still
buggy: After the underlying Matroska/WebM muxer has written its trailer,
ending the chunk implicitly flushes it again which is illegal at this
point.

These bugs have been fixed.

Fixes #5752.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-07-12 14:56:27 +02:00
Michael Niedermayer
1a74b04737 avformat/webm_chunk: Specify expected argument length of get_chunk_filename()
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-05-25 02:05:22 +02:00
Michael Niedermayer
3b5b977c9f avformat/webm_chunk: Check header filename length
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-05-25 02:05:20 +02:00
Andreas Rheinhardt
73ef1f47f5 lavf/webm_chunk: Respect buffer size
The last argument of av_strlcpy is supposed to contain the size of the
destination buffer, but it was filled with the size of the source
string, effectively negating its very purpose.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-05-02 20:28:02 +02:00
Carl Eugen Hoyos
9461e4bc69 lavf: Constify AVOutputFormat pointer. 2019-03-20 18:38:48 +01:00
Marton Balint
2dbe936bf7 avformat/webm_chunk: always use a static buffer for get_chunk_filename
My conversation from AVFormatContext->filename to AVFormatContext->url was
wrong in this case because get_chunk_filename uses filename as an output
buffer, and not as an input buffer.

Fixes ticket #7188.

Signed-off-by: Marton Balint <cus@passwd.hu>
2018-05-15 22:18:58 +02: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
Vignesh Venkatasubramanian
7238c53048 libavformat/webm_chunk: Option to specify HTTP header
Add an option to specify HTTP header in the WebM Chunk Muxer (this
works the same way as the 'method' parameter in the HLS muxer).

Signed-off-by: Vignesh Venkatasubramanian <vigneshv@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-09-16 03:13:21 +02:00
Carl Eugen Hoyos
2dfd0f4b9e lavf/webm_chunk: Print an error if no header filename was provided. 2016-09-03 14:31:55 +02:00
Vignesh Venkatasubramanian
42a635ddae webm_chunk: Set pts precision to milliseconds
Milliseconds is the de-factor precision for timestamps in
Matroska/WebM media.

Signed-off-by: Vignesh Venkatasubramanian <vigneshv@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-08-25 22:22:28 +02:00
Derek Buitenhuis
6f69f7a8bf Merge commit '9200514ad8717c63f82101dc394f4378854325bf'
* commit '9200514ad8717c63f82101dc394f4378854325bf':
  lavf: replace AVStream.codec with AVStream.codecpar

This has been a HUGE effort from:
    - Derek Buitenhuis <derek.buitenhuis@gmail.com>
    - Hendrik Leppkes <h.leppkes@gmail.com>
    - wm4 <nfxjfg@googlemail.com>
    - Clément Bœsch <clement@stupeflix.com>
    - James Almer <jamrial@gmail.com>
    - Michael Niedermayer <michael@niedermayer.cc>
    - Rostislav Pehlivanov <atomnuker@gmail.com>

Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2016-04-10 20:59:55 +01:00
Derek Buitenhuis
bc9a5965c8 Merge commit '9f61abc8111c7c43f49ca012e957a108b9cc7610'
This also deprecates our old duplicated callbacks.

* commit '9f61abc8111c7c43f49ca012e957a108b9cc7610':
  lavf: allow custom IO for all files

Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2016-02-10 14:42:41 +00:00
Michael Niedermayer
fe3fed0b14 Update demuxers and protocols for protocol whitelist support
Reviewed-by: Andreas Cadhalpun <andreas.cadhalpun@googlemail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-02-02 04:16:50 +01:00
Vignesh Venkatasubramanian
34ae98a771 lavf/webm_chunk: Remove AVFMT_ALLOW_FLUSH
The flag was set unintentionally and the code will break if a NULL
packet is passed in.

Signed-off-by: Vignesh Venkatasubramanian <vigneshv@google.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-06-09 21:19:57 +02:00
Vignesh Venkatasubramanian
ccb8f67499 lavf/webm_chunk: Fix a memory leak.
Fix a duplicate memory allocation. priv_data should be allocated
in line 64 call to avformat_alloc_output_context2 since we pass
the correct AVFormat to it. This removes the duplicate allocation.

Signed-off-by: Vignesh Venkatasubramanian <vigneshv@google.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-04-30 23:33:10 +02:00
Vignesh Venkatasubramanian
e2784a1d96 lavf/webm_chunk: Use dyn_buf to write chunks
Use dyn_duf to write chunks so that we create the actual chunk
file only after the entire chunk data is available. This will help
not confuse other software looking at the chunk file (e.g. a web
server) by seeing a zero length file when ffmpeg is writing into
it.

Signed-off-by: Vignesh Venkatasubramanian <vigneshv@google.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-04-30 21:25:09 +02:00
Vignesh Venkatasubramanian
8ca170a78a libavformat/webm_chunk: Write first audio packet.
Fix a bug where the chunk muxer doesn't write the very first audio
packet (with pts == 0).

Signed-off-by: Vignesh Venkatasubramanian <vigneshv@google.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-04-28 02:27:01 +02:00
Vignesh Venkatasubramanian
6fd300ac6c lavf: Add support for WebM Live Muxing
This patch adds support for WebM Live Muxing by adding a new WebM
Chunk muxer. It writes out live WebM Chunks which can be used for
playback using Live DASH Clients.

Please see muxers.texi for sample usage.

Signed-off-by: Vignesh Venkatasubramanian <vigneshv@google.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-04-07 15:08:59 +02:00