]> git.sesse.net Git - ffmpeg/commitdiff
avformat: convert some avio_flush() calls to avio_write_marker(AVIO_DATA_MARKER_FLUSH...
authorMarton Balint <cus@passwd.hu>
Fri, 27 Dec 2019 12:53:00 +0000 (13:53 +0100)
committerMarton Balint <cus@passwd.hu>
Tue, 7 Jan 2020 20:51:45 +0000 (21:51 +0100)
Converting explicit avio_flush() calls helps us to buffer more data and avoid
flushing the IO context too often which causes reduced IO throughput for
non-streamed file output.

The user can control FLUSH_POINT flushing behaviour using the -flush_packets
option, the default typically means to flush unless a non-streamed file output
is used, so this change should have no adverse effect on streaming even if it
is assumed that after an avio_flush() the output buffer is clean so small
seekbacks within the output buffer will work even when the IO context is not
seekable.

Signed-off-by: Marton Balint <cus@passwd.hu>
libavformat/asfenc.c
libavformat/matroskaenc.c
libavformat/movenc.c
libavformat/mpegenc.c
libavformat/mxfenc.c
libavformat/oggenc.c

index 8eaa9d40ce4215e8899834faa9b31168747aeac4..73afb13200b1a36e8e90dffbeb79ba4eaf22e15f 100644 (file)
@@ -892,7 +892,8 @@ static void flush_packet(AVFormatContext *s)
 
     avio_write(s->pb, asf->packet_buf, s->packet_size - packet_hdr_size);
 
-    avio_flush(s->pb);
+    avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_FLUSH_POINT);
+
     asf->nb_packets++;
     asf->packet_nb_payloads     = 0;
     asf->packet_timestamp_start = -1;
index 4b6d14b435fb33ea603fb7a2dac02669c9c45e46..71c9afb15c33906e06ac939912358075d9e847e3 100644 (file)
@@ -2235,7 +2235,7 @@ static void mkv_end_cluster(AVFormatContext *s)
 
     end_ebml_master_crc32(s->pb, &mkv->cluster_bc, mkv);
     mkv->cluster_pos = -1;
-    avio_flush(s->pb);
+    avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_FLUSH_POINT);
 }
 
 static int mkv_check_new_extra_data(AVFormatContext *s, AVPacket *pkt)
index e20eea757142e9861c8027daec61b1b882f633b5..1d9497283fdc3efffd7ce2039f8e8bba6b755fd1 100644 (file)
@@ -5152,7 +5152,7 @@ static int mov_flush_fragment(AVFormatContext *s, int force)
         if (mov->flags & FF_MOV_FLAG_DELAY_MOOV) {
             if (mov->flags & FF_MOV_FLAG_GLOBAL_SIDX)
                 mov->reserved_header_pos = avio_tell(s->pb);
-            avio_flush(s->pb);
+            avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_FLUSH_POINT);
             mov->moov_written = 1;
             return 0;
         }
@@ -5176,7 +5176,7 @@ static int mov_flush_fragment(AVFormatContext *s, int force)
             mov->tracks[i].entry = 0;
             mov->tracks[i].end_reliable = 0;
         }
-        avio_flush(s->pb);
+        avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_FLUSH_POINT);
         return 0;
     }
 
@@ -5241,7 +5241,7 @@ static int mov_flush_fragment(AVFormatContext *s, int force)
         }
 
         if (write_moof) {
-            avio_flush(s->pb);
+            avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_FLUSH_POINT);
 
             mov_write_moof_tag(s->pb, mov, moof_tracks, mdat_size);
             mov->fragments++;
@@ -5273,7 +5273,7 @@ static int mov_flush_fragment(AVFormatContext *s, int force)
 
     mov->mdat_size = 0;
 
-    avio_flush(s->pb);
+    avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_FLUSH_POINT);
     return 0;
 }
 
index f8039a42c07ee086890f151cbaf0a24fb6e820f5..669ff9d152b83d53c9186d1fcb5b0925f338b532 100644 (file)
@@ -928,7 +928,7 @@ static int flush_packet(AVFormatContext *ctx, int stream_index,
     for (i = 0; i < zero_trail_bytes; i++)
         avio_w8(ctx->pb, 0x00);
 
-    avio_flush(ctx->pb);
+    avio_write_marker(ctx->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_FLUSH_POINT);
 
     s->packet_number++;
 
@@ -957,7 +957,7 @@ static void put_vcd_padding_sector(AVFormatContext *ctx)
 
     s->vcd_padding_bytes_written += s->packet_size;
 
-    avio_flush(ctx->pb);
+    avio_write_marker(ctx->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_FLUSH_POINT);
 
     /* increasing the packet number is correct. The SCR of the following packs
      * is calculated from the packet_number and it has to include the padding
index 396768d51f8b088ba6785c53eecb4ffd292af967..374a83d069f4a3e23648bb8722befb58bf0e79b7 100644 (file)
@@ -1936,7 +1936,7 @@ static int mxf_write_partition(AVFormatContext *s, int bodysid,
     }
 
     if(key)
-        avio_flush(pb);
+        avio_write_marker(pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_FLUSH_POINT);
 
     return 0;
 }
index 04f78130830469a17f50d4ccc9ead78f7b275a91..fe89f23e360193b25ed812350ac3ec7a7f73f0dc 100644 (file)
@@ -139,7 +139,7 @@ static int ogg_write_page(AVFormatContext *s, OGGPage *page, int extra_flags)
         return size;
 
     avio_write(s->pb, buf, size);
-    avio_flush(s->pb);
+    avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_FLUSH_POINT);
     av_free(buf);
     oggstream->page_count--;
     return 0;