[FFmpeg-devel] [PATCH 2/2] avio: add an inline avio_error function as a replacement for url_ferror

Anton Khirnov anton
Fri Mar 4 20:33:01 CET 2011


---
 ffplay.c              |    2 +-
 libavformat/asfdec.c  |    2 +-
 libavformat/avio.h    |    6 +++++-
 libavformat/aviobuf.c |    6 +++---
 libavformat/dsicin.c  |    2 +-
 libavformat/mxg.c     |    2 +-
 libavformat/utils.c   |   10 +++++-----
 libavformat/wtv.c     |    2 +-
 8 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/ffplay.c b/ffplay.c
index d5a0219..6578824 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -2570,7 +2570,7 @@ static int decode_thread(void *arg)
         if (ret < 0) {
             if (ret == AVERROR_EOF || avio_eof(ic->pb))
                 eof=1;
-            if (url_ferror(ic->pb))
+            if (avio_error(ic->pb))
                 break;
             SDL_Delay(100); /* wait for user event */
             continue;
diff --git a/libavformat/asfdec.c b/libavformat/asfdec.c
index 974be9a..de602f0 100644
--- a/libavformat/asfdec.c
+++ b/libavformat/asfdec.c
@@ -743,7 +743,7 @@ static int ff_asf_get_packet(AVFormatContext *s, AVIOContext *pb)
          * imply complete -EAGAIN handling support at random positions in
          * the stream.
          */
-        if (url_ferror(pb) == AVERROR(EAGAIN))
+        if (avio_error(pb) == AVERROR(EAGAIN))
             return AVERROR(EAGAIN);
         if (!avio_eof(pb))
             av_log(s, AV_LOG_ERROR, "ff asf bad header %x  at:%"PRId64"\n", c, avio_tell(pb));
diff --git a/libavformat/avio.h b/libavformat/avio.h
index 230fa0e..7136eef 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -425,6 +425,7 @@ attribute_deprecated int url_fskip(AVIOContext *s, int64_t offset);
 attribute_deprecated int64_t url_ftell(AVIOContext *s);
 attribute_deprecated int64_t url_fsize(AVIOContext *s);
 attribute_deprecated int url_feof(AVIOContext *s);
+attribute_deprecated int url_ferror(AVIOContext *s);
 /**
  * @}
  */
@@ -493,7 +494,10 @@ static av_always_inline int avio_eof(AVIOContext *s)
     return s ? s->eof_reached : 0;
 }
 
-int url_ferror(AVIOContext *s);
+static av_always_inline int avio_error(AVIOContext *s)
+{
+    return s ? s->error : 0;
+}
 
 int av_url_read_fpause(AVIOContext *h, int pause);
 int64_t av_url_read_fseek(AVIOContext *h, int stream_index,
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 34b7f71..aff1d13 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -272,7 +272,6 @@ int url_feof(AVIOContext *s)
         return 0;
     return s->eof_reached;
 }
-#endif
 
 int url_ferror(AVIOContext *s)
 {
@@ -280,6 +279,7 @@ int url_ferror(AVIOContext *s)
         return 0;
     return s->error;
 }
+#endif
 
 void avio_wl32(AVIOContext *s, unsigned int val)
 {
@@ -597,7 +597,7 @@ int avio_read(AVIOContext *s, unsigned char *buf, int size)
         }
     }
     if (size1 == size) {
-        if (url_ferror(s)) return url_ferror(s);
+        if (avio_error(s)) return avio_error(s);
         if (avio_eof(s))   return AVERROR_EOF;
     }
     return size1 - size;
@@ -620,7 +620,7 @@ int ffio_read_partial(AVIOContext *s, unsigned char *buf, int size)
     memcpy(buf, s->buf_ptr, len);
     s->buf_ptr += len;
     if (!len) {
-        if (url_ferror(s)) return url_ferror(s);
+        if (avio_error(s)) return avio_error(s);
         if (avio_eof(s))   return AVERROR_EOF;
     }
     return len;
diff --git a/libavformat/dsicin.c b/libavformat/dsicin.c
index ab211e5..f0564bf 100644
--- a/libavformat/dsicin.c
+++ b/libavformat/dsicin.c
@@ -147,7 +147,7 @@ static int cin_read_frame_header(CinDemuxContext *cin, AVIOContext *pb) {
     hdr->video_frame_size = avio_rl32(pb);
     hdr->audio_frame_size = avio_rl32(pb);
 
-    if (avio_eof(pb) || url_ferror(pb))
+    if (avio_eof(pb) || avio_error(pb))
         return AVERROR(EIO);
 
     if (avio_rl32(pb) != 0xAA55AA55)
diff --git a/libavformat/mxg.c b/libavformat/mxg.c
index b85d434..5c496a4 100644
--- a/libavformat/mxg.c
+++ b/libavformat/mxg.c
@@ -132,7 +132,7 @@ static int mxg_read_packet(AVFormatContext *s, AVPacket *pkt)
     uint8_t *startmarker_ptr, *end, *search_end, marker;
     MXGContext *mxg = s->priv_data;
 
-    while (!avio_eof(s->pb) && !url_ferror(s->pb)){
+    while (!avio_eof(s->pb) && !avio_error(s->pb)){
         if (mxg->cache_size <= OVERREAD_SIZE) {
             /* update internal buffer */
             ret = mxg_update_cache(s, DEFAULT_PACKET_SIZE + OVERREAD_SIZE);
diff --git a/libavformat/utils.c b/libavformat/utils.c
index abe3cf9..00bb2b7 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2988,7 +2988,7 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt)
 
     ret= s->oformat->write_packet(s, pkt);
     if(!ret)
-        ret= url_ferror(s->pb);
+        ret= avio_error(s->pb);
     return ret;
 }
 
@@ -3110,8 +3110,8 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt){
 
         if(ret<0)
             return ret;
-        if(url_ferror(s->pb))
-            return url_ferror(s->pb);
+        if(avio_error(s->pb))
+            return avio_error(s->pb);
     }
 }
 
@@ -3133,7 +3133,7 @@ int av_write_trailer(AVFormatContext *s)
 
         if(ret<0)
             goto fail;
-        if(url_ferror(s->pb))
+        if(avio_error(s->pb))
             goto fail;
     }
 
@@ -3141,7 +3141,7 @@ int av_write_trailer(AVFormatContext *s)
         ret = s->oformat->write_trailer(s);
 fail:
     if(ret == 0)
-       ret=url_ferror(s->pb);
+       ret=avio_error(s->pb);
     for(i=0;i<s->nb_streams;i++) {
         av_freep(&s->streams[i]->priv_data);
         av_freep(&s->streams[i]->index_entries);
diff --git a/libavformat/wtv.c b/libavformat/wtv.c
index 7601162..f3b4784 100644
--- a/libavformat/wtv.c
+++ b/libavformat/wtv.c
@@ -77,7 +77,7 @@ static int wtvfile_read_packet(void *opaque, uint8_t *buf, int buf_size)
     AVIOContext *pb = wf->pb_filesystem;
     int nread = 0;
 
-    if (wf->error || url_ferror(pb))
+    if (wf->error || avio_error(pb))
         return -1;
     if (wf->position >= wf->length || avio_eof(pb))
         return 0;
-- 
1.7.4.1




More information about the ffmpeg-devel mailing list