summaryrefslogtreecommitdiff
path: root/libavformat
diff options
context:
space:
mode:
authorMarton Balint <cus@passwd.hu>2020-03-27 00:00:53 +0100
committerMarton Balint <cus@passwd.hu>2020-05-07 22:41:24 +0200
commitc31ba86c37d6caeed6983343b22e8dbc99dce3cf (patch)
tree094317bd6b1b85740ab9fae4cb2c0283f061e755 /libavformat
parent7a8a5c200bd4a3960e3524d14697656c3696beea (diff)
avformat/mux: factorize interleaved write_packet
Signed-off-by: Marton Balint <cus@passwd.hu>
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/mux.c52
1 files changed, 21 insertions, 31 deletions
diff --git a/libavformat/mux.c b/libavformat/mux.c
index 4c632a8dfe..4c282a489d 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -1125,6 +1125,25 @@ static int do_packet_auto_bsf(AVFormatContext *s, AVPacket *pkt) {
return 1;
}
+static int interleaved_write_packet(AVFormatContext *s, AVPacket *pkt, int flush)
+{
+ for (;; ) {
+ AVPacket opkt;
+ int ret = interleave_packet(s, &opkt, pkt, flush);
+ if (ret <= 0)
+ return ret;
+
+ pkt = NULL;
+
+ ret = write_packet(s, &opkt);
+
+ av_packet_unref(&opkt);
+
+ if (ret < 0)
+ return ret;
+ }
+}
+
int av_write_frame(AVFormatContext *s, AVPacket *in)
{
AVPacket local_pkt, *pkt = &local_pkt;
@@ -1220,22 +1239,8 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
av_log(s, AV_LOG_TRACE, "av_interleaved_write_frame FLUSH\n");
flush = 1;
}
+ return interleaved_write_packet(s, pkt, flush);
- for (;; ) {
- AVPacket opkt;
- int ret = interleave_packet(s, &opkt, pkt, flush);
- if (ret <= 0)
- return ret;
-
- pkt = NULL;
-
- ret = write_packet(s, &opkt);
-
- av_packet_unref(&opkt);
-
- if (ret < 0)
- return ret;
- }
fail:
av_packet_unref(pkt);
return ret;
@@ -1245,23 +1250,8 @@ int av_write_trailer(AVFormatContext *s)
{
int ret, i;
- for (;; ) {
- AVPacket pkt;
- ret = interleave_packet(s, &pkt, NULL, 1);
- if (ret < 0)
- goto fail;
- if (!ret)
- break;
-
- ret = write_packet(s, &pkt);
-
- av_packet_unref(&pkt);
+ ret = interleaved_write_packet(s, NULL, 1);
- if (ret < 0)
- goto fail;
- }
-
-fail:
if (s->oformat->write_trailer) {
if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_TRAILER);