[FFmpeg-devel] [PATCH v4 9/9] avformat/utils: Remove unnecessary initializations
Andreas Rheinhardt
andreas.rheinhardt at gmail.com
Fri Sep 20 23:39:16 EEST 2019
Up until now, read_frame_internal always initialized the packet it
received. But since the recent changes to ff_read_packet, this is no
longer needed: If the parsing queue is initially empty upon entering
read_frame_internal, the packet will now either contain content upon
success or be blank upon failure of ff_read_packet. If the parsing
queue is initially not empty, the packet will be overwritten with the
oldest one from the parsing queue.
Similarly, it is unnecessary to initialize ret in read_frame_internal.
In parse_packet, it is easily possible to only initialize the packet
used as temporary storage for the output if said packet is used at all;
furthermore, this packet doesn't need to be zero-initialized, because
av_init_packet will initialize every field except size and data and
those fields will be set by av_parser_parse2.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
libavformat/utils.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 28950b9290..b1a79dd54e 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1445,15 +1445,15 @@ void ff_packet_list_free(AVPacketList **pkt_buf, AVPacketList **pkt_buf_end)
static int parse_packet(AVFormatContext *s, AVPacket *pkt,
int stream_index, int flush)
{
- AVPacket out_pkt = { 0 };
+ AVPacket out_pkt;
AVStream *st = s->streams[stream_index];
uint8_t *data = pkt->data;
int size = pkt->size;
int ret = 0, got_output = flush;
- av_init_packet(&out_pkt);
-
- if (!size && !flush && st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) {
+ if (size || flush) {
+ av_init_packet(&out_pkt);
+ } else if (st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) {
// preserve 0-size sync packets
compute_pkt_fields(s, st, st->parser, pkt, AV_NOPTS_VALUE, AV_NOPTS_VALUE);
}
@@ -1574,11 +1574,9 @@ static int64_t ts_to_samples(AVStream *st, int64_t ts)
static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
{
- int ret = 0, i, got_packet = 0;
+ int ret, i, got_packet = 0;
AVDictionary *metadata = NULL;
- av_init_packet(pkt);
-
while (!got_packet && !s->internal->parse_queue) {
AVStream *st;
--
2.20.1
More information about the ffmpeg-devel
mailing list