avio: Do not flush the buffer if a constant packet size is requested

Message ID 20190131113038.84125-1-lu_zero@gentoo.org
State New
Headers show
Series
  • avio: Do not flush the buffer if a constant packet size is requested
Related show

Commit Message

Luca Barbato Jan. 31, 2019, 11:30 a.m.
---
 libavformat/aviobuf.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Martin Storsjö Jan. 31, 2019, 11:34 a.m. | #1
On Thu, 31 Jan 2019, Luca Barbato wrote:

> ---
> libavformat/aviobuf.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
> index 98e35f776c..3c882d6bdb 100644
> --- a/libavformat/aviobuf.c
> +++ b/libavformat/aviobuf.c
> @@ -244,7 +244,8 @@ void avio_write(AVIOContext *s, const unsigned char *buf, int size)
> 
> void avio_flush(AVIOContext *s)
> {
> -    flush_buffer(s);
> +    if (!s->max_packet_size || s->buf_ptr - s->buffer >= s->max_packet_size)
> +        flush_buffer(s);
>     s->must_flush = 0;
> }
> 
> -- 
> 2.12.2

You're not providing any explanation to why we should do this. And I'm 
fairly sure that this patch breaks the RTP muxer when sending over plain 
UDP.

// Martin
Luca Barbato Feb. 2, 2019, 12:25 p.m. | #2
On 31/01/2019 12:34, Martin Storsjö wrote:
> On Thu, 31 Jan 2019, Luca Barbato wrote:
> 
>> ---
>> libavformat/aviobuf.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
>> index 98e35f776c..3c882d6bdb 100644
>> --- a/libavformat/aviobuf.c
>> +++ b/libavformat/aviobuf.c
>> @@ -244,7 +244,8 @@ void avio_write(AVIOContext *s, const unsigned 
>> char *buf, int size)
>>
>> void avio_flush(AVIOContext *s)
>> {
>> -    flush_buffer(s);
>> +    if (!s->max_packet_size || s->buf_ptr - s->buffer >= 
>> s->max_packet_size)
>> +        flush_buffer(s);
>>     s->must_flush = 0;
>> }
>>
>> -- 
>> 2.12.2
> 
> You're not providing any explanation to why we should do this. And I'm 
> fairly sure that this patch breaks the RTP muxer when sending over plain 
> UDP.
> 

I'll check if does, and update the v2 again.

Patch

diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 98e35f776c..3c882d6bdb 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -244,7 +244,8 @@  void avio_write(AVIOContext *s, const unsigned char *buf, int size)
 
 void avio_flush(AVIOContext *s)
 {
-    flush_buffer(s);
+    if (!s->max_packet_size || s->buf_ptr - s->buffer >= s->max_packet_size)
+        flush_buffer(s);
     s->must_flush = 0;
 }