Commit Graph

30 Commits

Author SHA1 Message Date
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
Anton Khirnov 9f61abc811 lavf: allow custom IO for all files
Some (de)muxers open additional files beyond the main IO context.
Currently, they call avio_open() directly, which prevents the caller
from using custom IO for such streams.

This commit adds callbacks to AVFormatContext that default to
avio_open2()/avio_close(), but can be overridden by the caller. All
muxers and demuxers using AVIO are switched to using those callbacks
instead of calling avio_open()/avio_close() directly.

(de)muxers that use the URLProtocol layer directly instead of AVIO
remain unconverted for now. This should be fixed in later commits.
2016-01-24 16:45:32 +01:00
Vittorio Giovara 8a78ae2d21 segment: Check open_null_ctx() return value
Reported-By: infer
2015-06-12 17:02:48 +01:00
Diego Biurrun daf8cf358a avformat: Don't anonymously typedef structs 2015-02-14 10:13:47 -08:00
Vittorio Giovara 3a6dfec864 segment: Check av_get_frame_filename() return value
CC: libav-stable@libav.org
Bug-Id: CID 1265713
2015-01-23 14:55:03 +00:00
Luca Barbato b3f0465736 segment: Fix the failure paths
A failure in segment_end() or segment_start() would lead to freeing
a dangling pointer and in general further calls to seg_write_packet()
or to seg_write_trailer() would have the same faulty behaviour.

CC: libav-stable@libav.org
Reported-By: luodalongde@gmail.com
2015-01-07 12:36:28 +01:00
Martin Storsjö 28816050e4 lavf: Set the stream time base hint properly for chained muxers
This avoids warnings about using the codec time base as time
base hint.

Signed-off-by: Martin Storsjö <martin@martin.st>
2014-10-06 23:30:52 +03:00
Gabriel Dume 4b1f5e5090 cosmetics: Write NULL pointer inequality checks more compactly
Signed-off-by: Diego Biurrun <diego@biurrun.de>
2014-08-15 05:34:13 -07:00
Luca Barbato 87a3ea3192 segment: Report the current media sequence
Useful for debugging mostly.
2014-04-30 17:52:03 +02:00
Enrique Arizón Benito 5c08ae4f37 segment: Add an option to prepend a string to the list entries
Useful to generate lists with absolute urls.

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
2014-04-29 12:14:00 +02:00
Anton Khirnov cf679b9476 hls, segment: fix splitting for audio-only streams.
CC:libav-stable@libav.org
2013-04-27 10:19:04 +02:00
Xi Wang e8769b37fe segment: fix NULL pointer dereference in seg_write_header()
Since the pointer `oc' is NULL, oc->oformat->name will cause a null
pointer dereference.  This patch changes it to seg->oformat->name.

Signed-off-by: Xi Wang <xi.wang@gmail.com>
Signed-off-by: Martin Storsjö <martin@martin.st>
2012-11-14 12:33:27 +02:00
Luca Barbato 26db9100b2 segment: support applehttp style list 2012-10-10 18:56:55 +02:00
Luca Barbato 0826d8513d segment: drop global headers setting
avconv provides an option to set it externally and there isn't a way for
the outer demuxer to report the inner demuxer flag.

Solves a bad interaction between mpegts and x264, but requires
additional setting for the user.
2012-10-08 11:22:42 +02:00
Martin Storsjö 91c1567beb segment: Add comments about calls that only are relevant for some muxers
Signed-off-by: Martin Storsjö <martin@martin.st>
2012-10-04 18:22:47 +03:00
Martin Storsjö c864c3968a segment: Add an option for omitting the first header and final trailer
This allows writing totally bare segments, without any header/trailer
included anywhere.

Signed-off-by: Martin Storsjö <martin@martin.st>
2012-10-04 13:52:09 +03:00
Martin Storsjö a854362b40 segment: Flush buffered data before finishing a segment
This makes sure any buffered data is written to the segment, for
muxers that buffer up data internally (e.g. fragmented mp4).

Signed-off-by: Martin Storsjö <martin@martin.st>
2012-10-04 13:52:09 +03:00
Martin Storsjö f7b240434c segment: Set the resend_headers flag for each segment
This makes sure new inline headers are emitted when the next
packet is written. This allows segmenting mpegts without calling
write_header/write_trailer (nor freeing/reiniting the muxer)
for each segment.

Signed-off-by: Martin Storsjö <martin@martin.st>
2012-10-04 13:52:09 +03:00
Martin Storsjö 378a6315b7 segment: Add an option for disabling writing of a header/trailer to each segment
Some segmented formats (such as fragmented mp4) are "bare", as in,
the segment files do not have the same headers/trailers as full normal
files of that format have.

Signed-off-by: Martin Storsjö <martin@martin.st>
2012-10-04 13:52:09 +03:00
Martin Storsjö eb447d5159 segment: Free and reinit the muxer before calling avformat_write_header
This makes sure the muxers are set up in the way they expect
with no data left around from the previous run (which could
cause various issues including memory leaks, depending on the chaine
muxer).

This fixes memory leaks with the mpegts and flv muxers. It also
makes the usage of chained muxers correct.

Signed-off-by: Martin Storsjö <martin@martin.st>
2012-10-04 13:52:09 +03:00
Martin Storsjö 73871dc96f segment: Use the public av_write_header/av_write_trailer functions
With this change, the segmenter muxer doesn't rely on anything
not available/supported to libavformat external users, making
the segmenter muxer do things just like a normal segmenter
application using libavformat would do.

Signed-off-by: Martin Storsjö <martin@martin.st>
2012-10-04 13:52:09 +03:00
Martin Storsjö 0edae4e628 segment: Properly create new AVStreams for the chained muxer
Before, the chained muxer reused the AVStreams array from
the outer muxer, which made it impossible to use the proper
public functions (such as av_write_frame) when calling the
chained muxer.

Signed-off-by: Martin Storsjö <martin@martin.st>
2012-10-04 13:52:09 +03:00
Martin Storsjö aa9f128b7c segment: Add a missing space
Signed-off-by: Martin Storsjö <martin@martin.st>
2012-10-04 13:52:08 +03:00
Martin Storsjö 4edb34f6cc segment: Pass the interrupt callback on to the chained AVFormatContext, too
This might not be needed at the moment, but it's good practice to
pass it to all chained AVFormatContexts, if it would happen to be
used there at a later point.

Signed-off-by: Martin Storsjö <martin@martin.st>
2012-10-02 22:14:07 +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
Diego Biurrun 0177b7d23a Improve descriptiveness of a number of codec and container long names 2012-07-30 20:46:55 +02:00
Janne Grunau 1cdcf043ca segment: remove unnecessary <strings.h> include 2012-06-15 19:10:58 +02:00
Luca Barbato 3b52e9da10 segment: reorder seg_write_header allocation
As pointed by Paul B Mahol <onemda@gmail.com> the previous code could
lead to null pointer dereference.
2012-04-27 14:03:43 -07:00
Luca Barbato 0c1759ac4b segment: implement wrap around
Provide a way to wrap around the segment index so pseudostreaming
live through a web server and html5 browser is simpler.

Also ensure that 0 (disable) is a valid value across the options
providing wrap around.
2012-02-28 15:01:20 +01:00
Luca Barbato 02e8f03296 segment: introduce segmented chain muxer
It behaves similarly to image2 muxer
2011-12-19 18:31:28 +01:00