dv: Don't return EIO upon EOF

Message ID 20170111192210.15893-1-stebbins@jetheaddev.com
State New
Headers show

Commit Message

John Stebbins Jan. 11, 2017, 7:22 p.m.
---
 libavformat/dv.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Diego Biurrun Jan. 12, 2017, 12:31 p.m. | #1
On Wed, Jan 11, 2017 at 12:22:10PM -0700, John Stebbins wrote:
> --- a/libavformat/dv.c
> +++ b/libavformat/dv.c
> @@ -478,7 +478,7 @@ static int dv_read_header(AVFormatContext *s)
>  static int dv_read_packet(AVFormatContext *s, AVPacket *pkt)
>  {
> -    int size;
> +    int size, result;
>      RawDVContext *c = s->priv_data;
>  
> @@ -487,7 +487,10 @@ static int dv_read_packet(AVFormatContext *s, AVPacket *pkt)
>          if (!c->dv_demux->sys)
>              return AVERROR(EIO);
>          size = c->dv_demux->sys->frame_size;
> -        if (avio_read(s->pb, c->buf, size) <= 0)
> +        result = avio_read(s->pb, c->buf, size);
> +        if (result == AVERROR_EOF)
> +            return result;
> +        if (result <= 0)
>              return AVERROR(EIO);

nit: The variable could have smaller scope.

Is there a specific problem that this fixes?

probably OK

Diego
John Stebbins Jan. 12, 2017, 5:27 p.m. | #2
On 01/12/2017 05:31 AM, Diego Biurrun wrote:
> On Wed, Jan 11, 2017 at 12:22:10PM -0700, John Stebbins wrote:
>> --- a/libavformat/dv.c
>> +++ b/libavformat/dv.c
>> @@ -478,7 +478,7 @@ static int dv_read_header(AVFormatContext *s)
>>  static int dv_read_packet(AVFormatContext *s, AVPacket *pkt)
>>  {
>> -    int size;
>> +    int size, result;
>>      RawDVContext *c = s->priv_data;
>>  
>> @@ -487,7 +487,10 @@ static int dv_read_packet(AVFormatContext *s, AVPacket *pkt)
>>          if (!c->dv_demux->sys)
>>              return AVERROR(EIO);
>>          size = c->dv_demux->sys->frame_size;
>> -        if (avio_read(s->pb, c->buf, size) <= 0)
>> +        result = avio_read(s->pb, c->buf, size);
>> +        if (result == AVERROR_EOF)
>> +            return result;
>> +        if (result <= 0)
>>              return AVERROR(EIO);
> nit: The variable could have smaller scope.
Ok. Will submit update to fix.
>
> Is there a specific problem that this fixes?
Yes.  HandBrake shows that encodes do not finish successfully because we receive EIO from libav instead of EOF.
Diego Biurrun Jan. 12, 2017, 7 p.m. | #3
On Thu, Jan 12, 2017 at 10:27:59AM -0700, John Stebbins wrote:
> On 01/12/2017 05:31 AM, Diego Biurrun wrote:
> > On Wed, Jan 11, 2017 at 12:22:10PM -0700, John Stebbins wrote:
> >> --- a/libavformat/dv.c
> >> +++ b/libavformat/dv.c
> >> @@ -478,7 +478,7 @@ static int dv_read_header(AVFormatContext *s)
> >>  static int dv_read_packet(AVFormatContext *s, AVPacket *pkt)
> >>  {
> >> -    int size;
> >> +    int size, result;
> >>      RawDVContext *c = s->priv_data;
> >>  
> >> @@ -487,7 +487,10 @@ static int dv_read_packet(AVFormatContext *s, AVPacket *pkt)
> >>          if (!c->dv_demux->sys)
> >>              return AVERROR(EIO);
> >>          size = c->dv_demux->sys->frame_size;
> >> -        if (avio_read(s->pb, c->buf, size) <= 0)
> >> +        result = avio_read(s->pb, c->buf, size);
> >> +        if (result == AVERROR_EOF)
> >> +            return result;
> >> +        if (result <= 0)
> >>              return AVERROR(EIO);
> > nit: The variable could have smaller scope.
> Ok. Will submit update to fix.

Feel free to fix that on push in the future.

Diego

Patch

diff --git a/libavformat/dv.c b/libavformat/dv.c
index d4e5180..7e52e42 100644
--- a/libavformat/dv.c
+++ b/libavformat/dv.c
@@ -478,7 +478,7 @@  static int dv_read_header(AVFormatContext *s)
 
 static int dv_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
-    int size;
+    int size, result;
     RawDVContext *c = s->priv_data;
 
     size = avpriv_dv_get_packet(c->dv_demux, pkt);
@@ -487,7 +487,10 @@  static int dv_read_packet(AVFormatContext *s, AVPacket *pkt)
         if (!c->dv_demux->sys)
             return AVERROR(EIO);
         size = c->dv_demux->sys->frame_size;
-        if (avio_read(s->pb, c->buf, size) <= 0)
+        result = avio_read(s->pb, c->buf, size);
+        if (result == AVERROR_EOF)
+            return result;
+        if (result <= 0)
             return AVERROR(EIO);
 
         size = avpriv_dv_produce_packet(c->dv_demux, pkt, c->buf, size);