summaryrefslogtreecommitdiff
path: root/libavformat/mux.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2019-08-09 03:19:42 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-04-01 04:31:39 +0200
commitf4190a49ae2a3b17a12eaf75c1e9c3dfdae3e9e3 (patch)
treea2d881a39404033cf734aa72ba01a7ec4383b74c /libavformat/mux.c
parenta500b975a87174f1994cf497892c2529cf42e834 (diff)
avformat/mux: Only prepare input packet if there is a packet
It is unnecessary to call prepare_input_packet if there is no packet as it doesn't do anything, except when the currently inactive code guarded by !FF_API_COMPUTE_PKT_FIELDS2 || !FF_API_LAVF_AVCTX becomes active: Then attempting to access pkt->stream_index will crash. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavformat/mux.c')
-rw-r--r--libavformat/mux.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/libavformat/mux.c b/libavformat/mux.c
index bfd1bf491b..cc2d1e275a 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -771,9 +771,6 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
static int check_packet(AVFormatContext *s, AVPacket *pkt)
{
- if (!pkt)
- return 0;
-
if (pkt->stream_index < 0 || pkt->stream_index >= s->nb_streams) {
av_log(s, AV_LOG_ERROR, "Invalid packet stream index: %d\n",
pkt->stream_index);
@@ -887,10 +884,6 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt)
{
int ret;
- ret = prepare_input_packet(s, pkt);
- if (ret < 0)
- return ret;
-
if (!pkt) {
if (s->oformat->flags & AVFMT_ALLOW_FLUSH) {
ret = s->oformat->write_packet(s, NULL);
@@ -902,6 +895,10 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt)
return 1;
}
+ ret = prepare_input_packet(s, pkt);
+ if (ret < 0)
+ return ret;
+
ret = do_packet_auto_bsf(s, pkt);
if (ret <= 0)
return ret;
@@ -1191,13 +1188,13 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
{
int ret, flush = 0;
- ret = prepare_input_packet(s, pkt);
- if (ret < 0)
- goto fail;
-
if (pkt) {
AVStream *st = s->streams[pkt->stream_index];
+ ret = prepare_input_packet(s, pkt);
+ if (ret < 0)
+ goto fail;
+
ret = do_packet_auto_bsf(s, pkt);
if (ret == 0)
return 0;