]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/wv.c
avio: deprecate url_fgets
[ffmpeg] / libavformat / wv.c
index d04e00a90aaa9ac391014f41cbbdf94bd4a261df..1b6061ce43f5af12499176a8bfe3a53eb0e0430c 100644 (file)
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/audioconvert.h"
 #include "libavutil/intreadwrite.h"
 #include "avformat.h"
 #include "apetag.h"
@@ -75,7 +76,7 @@ static int wv_probe(AVProbeData *p)
         return 0;
 }
 
-static int wv_read_block_header(AVFormatContext *ctx, ByteIOContext *pb, int append)
+static int wv_read_block_header(AVFormatContext *ctx, AVIOContext *pb, int append)
 {
     WVContext *wc = ctx->priv_data;
     uint32_t tag, ver;
@@ -83,27 +84,27 @@ static int wv_read_block_header(AVFormatContext *ctx, ByteIOContext *pb, int app
     int rate, bpp, chan;
     uint32_t chmask;
 
-    wc->pos = url_ftell(pb);
+    wc->pos = avio_tell(pb);
     if(!append){
-    tag = get_le32(pb);
-    if (tag != MKTAG('w', 'v', 'p', 'k'))
-        return -1;
-    size = get_le32(pb);
-    if(size < 24 || size > WV_BLOCK_LIMIT){
-        av_log(ctx, AV_LOG_ERROR, "Incorrect block size %i\n", size);
-        return -1;
-    }
-    wc->blksize = size;
-    ver = get_le16(pb);
-    if(ver < 0x402 || ver > 0x410){
-        av_log(ctx, AV_LOG_ERROR, "Unsupported version %03X\n", ver);
-        return -1;
-    }
-    get_byte(pb); // track no
-    get_byte(pb); // track sub index
-    wc->samples = get_le32(pb); // total samples in file
-    wc->soff = get_le32(pb); // offset in samples of current block
-    get_buffer(pb, wc->extra, WV_EXTRA_SIZE);
+        tag = avio_rl32(pb);
+        if (tag != MKTAG('w', 'v', 'p', 'k'))
+            return -1;
+        size = avio_rl32(pb);
+        if(size < 24 || size > WV_BLOCK_LIMIT){
+            av_log(ctx, AV_LOG_ERROR, "Incorrect block size %i\n", size);
+            return -1;
+        }
+        wc->blksize = size;
+        ver = avio_rl16(pb);
+        if(ver < 0x402 || ver > 0x410){
+            av_log(ctx, AV_LOG_ERROR, "Unsupported version %03X\n", ver);
+            return -1;
+        }
+        avio_r8(pb); // track no
+        avio_r8(pb); // track sub index
+        wc->samples = avio_rl32(pb); // total samples in file
+        wc->soff = avio_rl32(pb); // offset in samples of current block
+        avio_read(pb, wc->extra, WV_EXTRA_SIZE);
     }else{
         size = wc->blksize;
     }
@@ -111,7 +112,7 @@ static int wv_read_block_header(AVFormatContext *ctx, ByteIOContext *pb, int app
     //parse flags
     bpp = ((wc->flags & 3) + 1) << 3;
     chan = 1 + !(wc->flags & WV_MONO);
-    chmask = wc->flags & WV_MONO ? CH_LAYOUT_MONO : CH_LAYOUT_STEREO;
+    chmask = wc->flags & WV_MONO ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;
     rate = wv_rates[(wc->flags >> 23) & 0xF];
     wc->multichannel = !!((wc->flags & WV_SINGLE_BLOCK) != WV_SINGLE_BLOCK);
     if(wc->multichannel){
@@ -119,15 +120,15 @@ static int wv_read_block_header(AVFormatContext *ctx, ByteIOContext *pb, int app
         chmask = wc->chmask;
     }
     if((rate == -1 || !chan) && !wc->block_parsed){
-        int64_t block_end = url_ftell(pb) + wc->blksize - 24;
+        int64_t block_end = avio_tell(pb) + wc->blksize - 24;
         if(url_is_streamed(pb)){
             av_log(ctx, AV_LOG_ERROR, "Cannot determine additional parameters\n");
             return -1;
         }
-        while(url_ftell(pb) < block_end){
+        while(avio_tell(pb) < block_end){
             int id, size;
-            id = get_byte(pb);
-            size = (id & 0x80) ? get_le24(pb) : get_byte(pb);
+            id = avio_r8(pb);
+            size = (id & 0x80) ? avio_rl24(pb) : avio_r8(pb);
             size <<= 1;
             if(id&0x40)
                 size--;
@@ -137,24 +138,24 @@ static int wv_read_block_header(AVFormatContext *ctx, ByteIOContext *pb, int app
                     av_log(ctx, AV_LOG_ERROR, "Insufficient channel information\n");
                     return -1;
                 }
-                chan = get_byte(pb);
+                chan = avio_r8(pb);
                 switch(size - 2){
                 case 0:
-                    chmask = get_byte(pb);
+                    chmask = avio_r8(pb);
                     break;
                 case 1:
-                    chmask = get_le16(pb);
+                    chmask = avio_rl16(pb);
                     break;
                 case 2:
-                    chmask = get_le24(pb);
+                    chmask = avio_rl24(pb);
                     break;
                 case 3:
-                    chmask = get_le32(pb);
+                    chmask = avio_rl32(pb);
                     break;
                 case 5:
-                    url_fskip(pb, 1);
-                    chan |= (get_byte(pb) & 0xF) << 8;
-                    chmask = get_le24(pb);
+                    avio_seek(pb, 1, SEEK_CUR);
+                    chan |= (avio_r8(pb) & 0xF) << 8;
+                    chmask = avio_rl24(pb);
                     break;
                 default:
                     av_log(ctx, AV_LOG_ERROR, "Invalid channel info size %d\n", size);
@@ -162,19 +163,19 @@ static int wv_read_block_header(AVFormatContext *ctx, ByteIOContext *pb, int app
                 }
                 break;
             case 0x27:
-                rate = get_le24(pb);
+                rate = avio_rl24(pb);
                 break;
             default:
-                url_fskip(pb, size);
+                avio_seek(pb, size, SEEK_CUR);
             }
             if(id&0x40)
-                url_fskip(pb, 1);
+                avio_seek(pb, 1, SEEK_CUR);
         }
         if(rate == -1){
             av_log(ctx, AV_LOG_ERROR, "Cannot determine custom sampling rate\n");
             return -1;
         }
-        url_fseek(pb, block_end - wc->blksize + 24, SEEK_SET);
+        avio_seek(pb, block_end - wc->blksize + 24, SEEK_SET);
     }
     if(!wc->bpp) wc->bpp = bpp;
     if(!wc->chan) wc->chan = chan;
@@ -200,7 +201,7 @@ static int wv_read_block_header(AVFormatContext *ctx, ByteIOContext *pb, int app
 static int wv_read_header(AVFormatContext *s,
                           AVFormatParameters *ap)
 {
-    ByteIOContext *pb = s->pb;
+    AVIOContext *pb = s->pb;
     WVContext *wc = s->priv_data;
     AVStream *st;
 
@@ -223,11 +224,11 @@ static int wv_read_header(AVFormatContext *s,
     st->duration = wc->samples;
 
     if(!url_is_streamed(s->pb)) {
-        int64_t cur = url_ftell(s->pb);
+        int64_t cur = avio_tell(s->pb);
         ff_ape_parse_tag(s);
         if(!av_metadata_get(s->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX))
             ff_id3v1_read(s);
-        url_fseek(s->pb, cur, SEEK_SET);
+        avio_seek(s->pb, cur, SEEK_SET);
     }
 
     return 0;
@@ -253,13 +254,13 @@ static int wv_read_packet(AVFormatContext *s,
     if(wc->multichannel)
         AV_WL32(pkt->data, wc->blksize + WV_EXTRA_SIZE + 12);
     memcpy(pkt->data + off, wc->extra, WV_EXTRA_SIZE);
-    ret = get_buffer(s->pb, pkt->data + WV_EXTRA_SIZE + off, wc->blksize);
+    ret = avio_read(s->pb, pkt->data + WV_EXTRA_SIZE + off, wc->blksize);
     if(ret != wc->blksize){
         av_free_packet(pkt);
         return AVERROR(EIO);
     }
     while(!(wc->flags & WV_END_BLOCK)){
-        if(get_le32(s->pb) != MKTAG('w', 'v', 'p', 'k')){
+        if(avio_rl32(s->pb) != MKTAG('w', 'v', 'p', 'k')){
             av_free_packet(pkt);
             return -1;
         }
@@ -274,16 +275,16 @@ static int wv_read_packet(AVFormatContext *s,
             return -1;
         }
         wc->blksize = size;
-        ver = get_le16(s->pb);
+        ver = avio_rl16(s->pb);
         if(ver < 0x402 || ver > 0x410){
             av_free_packet(pkt);
             av_log(s, AV_LOG_ERROR, "Unsupported version %03X\n", ver);
             return -1;
         }
-        get_byte(s->pb); // track no
-        get_byte(s->pb); // track sub index
-        wc->samples = get_le32(s->pb); // total samples in file
-        wc->soff = get_le32(s->pb); // offset in samples of current block
+        avio_r8(s->pb); // track no
+        avio_r8(s->pb); // track sub index
+        wc->samples = avio_rl32(s->pb); // total samples in file
+        wc->soff = avio_rl32(s->pb); // offset in samples of current block
         if((ret = av_append_packet(s->pb, pkt, WV_EXTRA_SIZE)) < 0){
             av_free_packet(pkt);
             return ret;
@@ -319,18 +320,18 @@ static int wv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp,
     /* if found, seek there */
     if (index >= 0){
         wc->block_parsed = 1;
-        url_fseek(s->pb, st->index_entries[index].pos, SEEK_SET);
+        avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET);
         return 0;
     }
     /* if timestamp is out of bounds, return error */
     if(timestamp < 0 || timestamp >= s->duration)
         return -1;
 
-    pos = url_ftell(s->pb);
+    pos = avio_tell(s->pb);
     do{
         ret = av_read_frame(s, pkt);
         if (ret < 0){
-            url_fseek(s->pb, pos, SEEK_SET);
+            avio_seek(s->pb, pos, SEEK_SET);
             return -1;
         }
         pts = pkt->pts;
@@ -339,7 +340,7 @@ static int wv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp,
     return 0;
 }
 
-AVInputFormat wv_demuxer = {
+AVInputFormat ff_wv_demuxer = {
     "wv",
     NULL_IF_CONFIG_SMALL("WavPack"),
     sizeof(WVContext),