Browse code

avio: introduce an AVIOContext.seekable field

Use it instead of url_is_streamed and AVIOContext.is_streamed.

Anton Khirnov authored on 2011/03/06 05:06:46
Showing 40 changed files
... ...
@@ -2260,7 +2260,7 @@ static int http_prepare_data(HTTPContext *c)
2260 2260
             /* XXX: potential leak */
2261 2261
             return -1;
2262 2262
         }
2263
-        c->fmt_ctx.pb->is_streamed = 1;
2263
+        c->fmt_ctx.pb->seekable = 0;
2264 2264
 
2265 2265
         /*
2266 2266
          * HACK to avoid mpeg ps muxer to spit many underflow errors
... ...
@@ -2399,7 +2399,7 @@ static int http_prepare_data(HTTPContext *c)
2399 2399
                     }
2400 2400
                     ost = ctx->streams[pkt.stream_index];
2401 2401
 
2402
-                    ctx->pb->is_streamed = 1;
2402
+                    ctx->pb->seekable = 0;
2403 2403
                     if (pkt.dts != AV_NOPTS_VALUE)
2404 2404
                         pkt.dts = av_rescale_q(pkt.dts, ist->time_base, ost->time_base);
2405 2405
                     if (pkt.pts != AV_NOPTS_VALUE)
... ...
@@ -2436,7 +2436,7 @@ static int http_prepare_data(HTTPContext *c)
2436 2436
             /* XXX: potential leak */
2437 2437
             return -1;
2438 2438
         }
2439
-        c->fmt_ctx.pb->is_streamed = 1;
2439
+        c->fmt_ctx.pb->seekable = 0;
2440 2440
         av_write_trailer(ctx);
2441 2441
         len = url_close_dyn_buf(ctx->pb, &c->pb_buffer);
2442 2442
         c->buffer_ptr = c->pb_buffer;
... ...
@@ -2723,7 +2723,7 @@ static int http_receive_data(HTTPContext *c)
2723 2723
 
2724 2724
             pb = avio_alloc_context(c->buffer, c->buffer_end - c->buffer,
2725 2725
                                     0, NULL, NULL, NULL, NULL);
2726
-            pb->is_streamed = 1;
2726
+            pb->seekable = 0;
2727 2727
 
2728 2728
             if (av_open_input_stream(&s, pb, c->stream->feed_filename, fmt_in, NULL) < 0) {
2729 2729
                 av_free(pb);
... ...
@@ -238,7 +238,7 @@ static int aiff_read_header(AVFormatContext *s,
238 238
             offset += avio_tell(pb);    /* Compute absolute data offset */
239 239
             if (st->codec->block_align)    /* Assume COMM already parsed */
240 240
                 goto got_sound;
241
-            if (url_is_streamed(pb)) {
241
+            if (!pb->seekable) {
242 242
                 av_log(s, AV_LOG_ERROR, "file is not seekable\n");
243 243
                 return -1;
244 244
             }
... ...
@@ -124,7 +124,7 @@ static int aiff_write_trailer(AVFormatContext *s)
124 124
         end_size++;
125 125
     }
126 126
 
127
-    if (!url_is_streamed(s->pb)) {
127
+    if (s->pb->seekable) {
128 128
         /* File length */
129 129
         avio_seek(pb, aiff->form, SEEK_SET);
130 130
         avio_wb32(pb, file_size - aiff->form - 4);
... ...
@@ -296,7 +296,7 @@ static int ape_read_header(AVFormatContext * s, AVFormatParameters * ap)
296 296
     ape_dumpinfo(s, ape);
297 297
 
298 298
     /* try to read APE tags */
299
-    if (!url_is_streamed(pb)) {
299
+    if (pb->seekable) {
300 300
         ff_ape_parse_tag(s);
301 301
         avio_seek(pb, 0, SEEK_SET);
302 302
     }
... ...
@@ -347,7 +347,7 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data
347 347
     avio_wl64(pb, duration); /* end time stamp (in 100ns units) */
348 348
     avio_wl64(pb, asf->duration); /* duration (in 100ns units) */
349 349
     avio_wl64(pb, PREROLL_TIME); /* start time stamp */
350
-    avio_wl32(pb, (asf->is_streamed || url_is_streamed(pb)) ? 3 : 2); /* ??? */
350
+    avio_wl32(pb, (asf->is_streamed || !pb->seekable ) ? 3 : 2); /* ??? */
351 351
     avio_wl32(pb, s->packet_size); /* packet size */
352 352
     avio_wl32(pb, s->packet_size); /* packet size */
353 353
     avio_wl32(pb, bit_rate); /* Nominal data rate in bps */
... ...
@@ -866,7 +866,7 @@ static int asf_write_trailer(AVFormatContext *s)
866 866
     }
867 867
     avio_flush(s->pb);
868 868
 
869
-    if (asf->is_streamed || url_is_streamed(s->pb)) {
869
+    if (asf->is_streamed || !s->pb->seekable) {
870 870
         put_chunk(s, 0x4524, 0, 0); /* end of stream */
871 871
     } else {
872 872
         /* rewrite an updated header */
... ...
@@ -91,7 +91,7 @@ static int au_write_trailer(AVFormatContext *s)
91 91
     AVIOContext *pb = s->pb;
92 92
     int64_t file_size;
93 93
 
94
-    if (!url_is_streamed(s->pb)) {
94
+    if (s->pb->seekable) {
95 95
 
96 96
         /* update file size */
97 97
         file_size = avio_tell(pb);
... ...
@@ -665,7 +665,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
665 665
             break;
666 666
         case MKTAG('i', 'n', 'd', 'x'):
667 667
             i= avio_tell(pb);
668
-            if(!url_is_streamed(pb) && !(s->flags & AVFMT_FLAG_IGNIDX)){
668
+            if(pb->seekable && !(s->flags & AVFMT_FLAG_IGNIDX)){
669 669
                 read_braindead_odml_indx(s, 0);
670 670
             }
671 671
             avio_seek(pb, i+size, SEEK_SET);
... ...
@@ -721,7 +721,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
721 721
         return -1;
722 722
     }
723 723
 
724
-    if(!avi->index_loaded && !url_is_streamed(pb))
724
+    if(!avi->index_loaded && pb->seekable)
725 725
         avi_load_index(s);
726 726
     avi->index_loaded = 1;
727 727
     avi->non_interleaved |= guess_ni_flag(s);
... ...
@@ -197,7 +197,7 @@ static int avi_write_header(AVFormatContext *s)
197 197
     }
198 198
     avio_wl32(pb, bitrate / 8); /* XXX: not quite exact */
199 199
     avio_wl32(pb, 0); /* padding */
200
-    if (url_is_streamed(pb))
200
+    if (!pb->seekable)
201 201
         avio_wl32(pb, AVIF_TRUSTCKTYPE | AVIF_ISINTERLEAVED); /* flags */
202 202
     else
203 203
         avio_wl32(pb, AVIF_TRUSTCKTYPE | AVIF_HASINDEX | AVIF_ISINTERLEAVED); /* flags */
... ...
@@ -259,7 +259,7 @@ static int avi_write_header(AVFormatContext *s)
259 259
 
260 260
         avio_wl32(pb, 0); /* start */
261 261
         avist->frames_hdr_strm = avio_tell(pb); /* remember this offset to fill later */
262
-        if (url_is_streamed(pb))
262
+        if (!pb->seekable)
263 263
             avio_wl32(pb, AVI_MAX_RIFF_SIZE); /* FIXME: this may be broken, but who cares */
264 264
         else
265 265
             avio_wl32(pb, 0); /* length, XXX: filled later */
... ...
@@ -303,7 +303,7 @@ static int avi_write_header(AVFormatContext *s)
303 303
         }
304 304
       }
305 305
 
306
-        if (!url_is_streamed(pb)) {
306
+        if (pb->seekable) {
307 307
             unsigned char tag[5];
308 308
             int j;
309 309
 
... ...
@@ -362,7 +362,7 @@ static int avi_write_header(AVFormatContext *s)
362 362
         ff_end_tag(pb, list2);
363 363
     }
364 364
 
365
-    if (!url_is_streamed(pb)) {
365
+    if (pb->seekable) {
366 366
         /* AVI could become an OpenDML one, if it grows beyond 2Gb range */
367 367
         avi->odml_list = ff_start_tag(pb, "JUNK");
368 368
         ffio_wfourcc(pb, "odml");
... ...
@@ -406,7 +406,7 @@ static int avi_write_ix(AVFormatContext *s)
406 406
     char ix_tag[] = "ix00";
407 407
     int i, j;
408 408
 
409
-    assert(!url_is_streamed(pb));
409
+    assert(pb->seekable);
410 410
 
411 411
     if (avi->riff_id > AVI_MASTER_INDEX_SIZE)
412 412
         return -1;
... ...
@@ -464,7 +464,7 @@ static int avi_write_idx1(AVFormatContext *s)
464 464
     int i;
465 465
     char tag[5];
466 466
 
467
-    if (!url_is_streamed(pb)) {
467
+    if (pb->seekable) {
468 468
         AVIStream *avist;
469 469
         AVIIentry* ie = 0, *tie;
470 470
         int empty, stream_id = -1;
... ...
@@ -532,7 +532,7 @@ static int avi_write_packet(AVFormatContext *s, AVPacket *pkt)
532 532
     avist->packet_count++;
533 533
 
534 534
     // Make sure to put an OpenDML chunk when the file size exceeds the limits
535
-    if (!url_is_streamed(pb) &&
535
+    if (pb->seekable &&
536 536
         (avio_tell(pb) - avi->riff_start > AVI_MAX_RIFF_SIZE)) {
537 537
 
538 538
         avi_write_ix(s);
... ...
@@ -552,7 +552,7 @@ static int avi_write_packet(AVFormatContext *s, AVPacket *pkt)
552 552
        avist->audio_strm_length += size;
553 553
     }
554 554
 
555
-    if (!url_is_streamed(s->pb)) {
555
+    if (s->pb->seekable) {
556 556
         AVIIndex* idx = &avist->indexes;
557 557
         int cl = idx->entry / AVI_INDEX_CLUSTER_SIZE;
558 558
         int id = idx->entry % AVI_INDEX_CLUSTER_SIZE;
... ...
@@ -590,7 +590,7 @@ static int avi_write_trailer(AVFormatContext *s)
590 590
     int i, j, n, nb_frames;
591 591
     int64_t file_size;
592 592
 
593
-    if (!url_is_streamed(pb)){
593
+    if (pb->seekable){
594 594
         if (avi->riff_id == 1) {
595 595
             ff_end_tag(pb, avi->movi_list);
596 596
             res = avi_write_idx1(s);
... ...
@@ -332,6 +332,8 @@ attribute_deprecated int av_register_protocol(URLProtocol *protocol);
332 332
  */
333 333
 int av_register_protocol2(URLProtocol *protocol, int size);
334 334
 
335
+#define AVIO_SEEKABLE_NORMAL 0x0001 /**< Seeking works like for a local file */
336
+
335 337
 /**
336 338
  * Bytestream IO Context.
337 339
  * New fields can be added to the end with minor version bumps.
... ...
@@ -351,7 +353,9 @@ typedef struct {
351 351
     int must_flush; /**< true if the next seek should flush */
352 352
     int eof_reached; /**< true if eof reached */
353 353
     int write_flag;  /**< true if open for writing */
354
-    int is_streamed;
354
+#if FF_API_OLD_AVIO
355
+    attribute_deprecated int is_streamed;
356
+#endif
355 357
     int max_packet_size;
356 358
     unsigned long checksum;
357 359
     unsigned char *checksum_ptr;
... ...
@@ -360,6 +364,10 @@ typedef struct {
360 360
     int (*read_pause)(void *opaque, int pause);
361 361
     int64_t (*read_seek)(void *opaque, int stream_index,
362 362
                          int64_t timestamp, int flags);
363
+    /**
364
+     * A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
365
+     */
366
+    int seekable;
363 367
 } AVIOContext;
364 368
 
365 369
 #if FF_API_OLD_AVIO
... ...
@@ -604,10 +612,15 @@ unsigned int avio_rb24(AVIOContext *s);
604 604
 unsigned int avio_rb32(AVIOContext *s);
605 605
 uint64_t     avio_rb64(AVIOContext *s);
606 606
 
607
-static inline int url_is_streamed(AVIOContext *s)
607
+#if FF_API_OLD_AVIO
608
+/**
609
+ * @deprecated Use AVIOContext.seekable field directly.
610
+ */
611
+attribute_deprecated static inline int url_is_streamed(AVIOContext *s)
608 612
 {
609
-    return s->is_streamed;
613
+    return !s->seekable;
610 614
 }
615
+#endif
611 616
 
612 617
 /**
613 618
  * Create and initialize a AVIOContext for accessing the
... ...
@@ -62,7 +62,10 @@ int ffio_init_context(AVIOContext *s,
62 62
     s->must_flush = 0;
63 63
     s->eof_reached = 0;
64 64
     s->error = 0;
65
+#if FF_API_OLD_AVIO
65 66
     s->is_streamed = 0;
67
+#endif
68
+    s->seekable = AVIO_SEEKABLE_NORMAL;
66 69
     s->max_packet_size = 0;
67 70
     s->update_checksum= NULL;
68 71
     if(!read_packet && !write_flag){
... ...
@@ -202,7 +205,7 @@ int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
202 202
         offset1 >= 0 && offset1 <= (s->buf_end - s->buffer)) {
203 203
         /* can do the seek inside the buffer */
204 204
         s->buf_ptr = s->buffer + offset1;
205
-    } else if ((s->is_streamed ||
205
+    } else if ((!s->seekable ||
206 206
                offset1 <= s->buf_end + SHORT_SEEK_THRESHOLD - s->buffer) &&
207 207
                !s->write_flag && offset1 >= 0 &&
208 208
               (whence != SEEK_END || force)) {
... ...
@@ -831,7 +834,10 @@ int url_fdopen(AVIOContext **s, URLContext *h)
831 831
         av_freep(s);
832 832
         return AVERROR(EIO);
833 833
     }
834
+#if FF_API_OLD_AVIO
834 835
     (*s)->is_streamed = h->is_streamed;
836
+#endif
837
+    (*s)->seekable = h->is_streamed ? 0 : AVIO_SEEKABLE_NORMAL;
835 838
     (*s)->max_packet_size = max_packet_size;
836 839
     if(h->prot) {
837 840
         (*s)->read_pause = (int (*)(void *, int))h->prot->url_read_pause;
... ...
@@ -247,7 +247,7 @@ static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, in
247 247
     BinkDemuxContext *bink = s->priv_data;
248 248
     AVStream *vst = s->streams[0];
249 249
 
250
-    if (url_is_streamed(s->pb))
250
+    if (!s->pb->seekable)
251 251
         return -1;
252 252
 
253 253
     /* seek to the first frame */
... ...
@@ -223,7 +223,7 @@ static int read_header(AVFormatContext *s,
223 223
 
224 224
         /* stop at data chunk if seeking is not supported or
225 225
            data chunk size is unknown */
226
-        if (found_data && (caf->data_size < 0 || url_is_streamed(pb)))
226
+        if (found_data && (caf->data_size < 0 || !pb->seekable))
227 227
             break;
228 228
 
229 229
         tag  = avio_rb32(pb);
... ...
@@ -236,7 +236,7 @@ static int read_header(AVFormatContext *s,
236 236
             avio_skip(pb, 4); /* edit count */
237 237
             caf->data_start = avio_tell(pb);
238 238
             caf->data_size  = size < 0 ? -1 : size - 4;
239
-            if (caf->data_size > 0 && !url_is_streamed(pb))
239
+            if (caf->data_size > 0 && pb->seekable)
240 240
                 avio_skip(pb, caf->data_size);
241 241
             found_data = 1;
242 242
             break;
... ...
@@ -281,7 +281,7 @@ static int ffm_read_header(AVFormatContext *s, AVFormatParameters *ap)
281 281
         goto fail;
282 282
     ffm->write_index = avio_rb64(pb);
283 283
     /* get also filesize */
284
-    if (!url_is_streamed(pb)) {
284
+    if (pb->seekable) {
285 285
         ffm->file_size = avio_size(pb);
286 286
         if (ffm->write_index)
287 287
             adjust_write_index(s);
... ...
@@ -40,7 +40,7 @@ static int read_header(AVFormatContext *s,
40 40
     AVIOContext *pb = s->pb;
41 41
     AVStream *st;
42 42
 
43
-    if (url_is_streamed(s->pb))
43
+    if (!s->pb->seekable)
44 44
         return AVERROR(EIO);
45 45
 
46 46
     avio_seek(pb, avio_size(pb) - 36, SEEK_SET);
... ...
@@ -98,7 +98,7 @@ static int flac_write_trailer(struct AVFormatContext *s)
98 98
     if (!ff_flac_is_extradata_valid(s->streams[0]->codec, &format, &streaminfo))
99 99
         return -1;
100 100
 
101
-    if (!url_is_streamed(pb)) {
101
+    if (pb->seekable) {
102 102
         /* rewrite the STREAMINFO header block data */
103 103
         file_size = avio_tell(pb);
104 104
         avio_seek(pb, 8, SEEK_SET);
... ...
@@ -437,7 +437,7 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
437 437
  }
438 438
 
439 439
     // if not streamed and no duration from metadata then seek to end to find the duration from the timestamps
440
-    if(!url_is_streamed(s->pb) && (!s->duration || s->duration==AV_NOPTS_VALUE)){
440
+    if(s->pb->seekable && (!s->duration || s->duration==AV_NOPTS_VALUE)){
441 441
         int size;
442 442
         const int64_t pos= avio_tell(s->pb);
443 443
         const int64_t fsize= avio_size(s->pb);
... ...
@@ -539,7 +539,7 @@ static int flv_read_seek2(AVFormatContext *s, int stream_index,
539 539
 
540 540
     if (ts - min_ts > (uint64_t)(max_ts - ts)) flags |= AVSEEK_FLAG_BACKWARD;
541 541
 
542
-    if (url_is_streamed(s->pb)) {
542
+    if (!s->pb->seekable) {
543 543
         if (stream_index < 0) {
544 544
             stream_index = av_find_default_stream_index(s);
545 545
             if (stream_index < 0)
... ...
@@ -634,7 +634,7 @@ static int gxf_write_header(AVFormatContext *s)
634 634
     uint8_t tracks[255] = {0};
635 635
     int i, media_info = 0;
636 636
 
637
-    if (url_is_streamed(pb)) {
637
+    if (!pb->seekable) {
638 638
         av_log(s, AV_LOG_ERROR, "gxf muxer does not support streamed output, patch welcome");
639 639
         return -1;
640 640
     }
... ...
@@ -229,7 +229,7 @@ void ff_id3v1_read(AVFormatContext *s)
229 229
     uint8_t buf[ID3v1_TAG_SIZE];
230 230
     int64_t filesize, position = avio_tell(s->pb);
231 231
 
232
-    if (!url_is_streamed(s->pb)) {
232
+    if (s->pb->seekable) {
233 233
         /* XXX: change that */
234 234
         filesize = avio_size(s->pb);
235 235
         if (filesize > 128) {
... ...
@@ -1117,7 +1117,7 @@ static void matroska_execute_seekhead(MatroskaDemuxContext *matroska)
1117 1117
     int i;
1118 1118
 
1119 1119
     // we should not do any seeking in the streaming case
1120
-    if (url_is_streamed(matroska->ctx->pb) ||
1120
+    if (!matroska->ctx->pb->seekable ||
1121 1121
         (matroska->ctx->flags & AVFMT_FLAG_IGNIDX))
1122 1122
         return;
1123 1123
 
... ...
@@ -848,7 +848,7 @@ static int mkv_write_header(AVFormatContext *s)
848 848
         if (ret < 0) return ret;
849 849
     }
850 850
 
851
-    if (url_is_streamed(s->pb))
851
+    if (!s->pb->seekable)
852 852
         mkv_write_seekhead(pb, mkv->main_seekhead);
853 853
 
854 854
     mkv->cues = mkv_start_cues(mkv->segment_offset);
... ...
@@ -1024,7 +1024,7 @@ static int mkv_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
1024 1024
         return AVERROR(EINVAL);
1025 1025
     }
1026 1026
 
1027
-    if (url_is_streamed(s->pb)) {
1027
+    if (!s->pb->seekable) {
1028 1028
         if (!mkv->dyn_bc)
1029 1029
             url_open_dyn_buf(&mkv->dyn_bc);
1030 1030
         pb = mkv->dyn_bc;
... ...
@@ -1076,16 +1076,16 @@ static int mkv_copy_packet(MatroskaMuxContext *mkv, const AVPacket *pkt)
1076 1076
 static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt)
1077 1077
 {
1078 1078
     MatroskaMuxContext *mkv = s->priv_data;
1079
-    AVIOContext *pb = url_is_streamed(s->pb) ? mkv->dyn_bc : s->pb;
1079
+    AVIOContext *pb = s->pb->seekable ? s->pb : mkv->dyn_bc;
1080 1080
     AVCodecContext *codec = s->streams[pkt->stream_index]->codec;
1081 1081
     int ret, keyframe = !!(pkt->flags & AV_PKT_FLAG_KEY);
1082 1082
     int64_t ts = mkv->tracks[pkt->stream_index].write_dts ? pkt->dts : pkt->pts;
1083
-    int cluster_size = avio_tell(pb) - (url_is_streamed(s->pb) ? 0 : mkv->cluster_pos);
1083
+    int cluster_size = avio_tell(pb) - (s->pb->seekable ? mkv->cluster_pos : 0);
1084 1084
 
1085 1085
     // start a new cluster every 5 MB or 5 sec, or 32k / 1 sec for streaming or
1086 1086
     // after 4k and on a keyframe
1087 1087
     if (mkv->cluster_pos &&
1088
-        ((url_is_streamed(s->pb) && (cluster_size > 32*1024 || ts > mkv->cluster_pts + 1000))
1088
+        ((!s->pb->seekable && (cluster_size > 32*1024 || ts > mkv->cluster_pts + 1000))
1089 1089
          ||                      cluster_size > 5*1024*1024 || ts > mkv->cluster_pts + 5000
1090 1090
          || (codec->codec_type == AVMEDIA_TYPE_VIDEO && keyframe && cluster_size > 4*1024))) {
1091 1091
         av_log(s, AV_LOG_DEBUG, "Starting new cluster at offset %" PRIu64
... ...
@@ -1139,7 +1139,7 @@ static int mkv_write_trailer(AVFormatContext *s)
1139 1139
         end_ebml_master(pb, mkv->cluster);
1140 1140
     }
1141 1141
 
1142
-    if (!url_is_streamed(pb)) {
1142
+    if (pb->seekable) {
1143 1143
         cuespos = mkv_write_cues(pb, mkv->cues, s->nb_streams);
1144 1144
 
1145 1145
         ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_CUES    , cuespos);
... ...
@@ -133,7 +133,7 @@ static int mmf_write_trailer(AVFormatContext *s)
133 133
     int64_t pos, size;
134 134
     int gatetime;
135 135
 
136
-    if (!url_is_streamed(s->pb)) {
136
+    if (s->pb->seekable) {
137 137
         /* Fill in length fields */
138 138
         end_tag_be(pb, mmf->awapos);
139 139
         end_tag_be(pb, mmf->atrpos);
... ...
@@ -304,7 +304,7 @@ static int mov_read_default(MOVContext *c, AVIOContext *pb, MOVAtom atom)
304 304
             if (err < 0)
305 305
                 return err;
306 306
             if (c->found_moov && c->found_mdat &&
307
-                (url_is_streamed(pb) || start_pos + a.size == avio_size(pb)))
307
+                (!pb->seekable || start_pos + a.size == avio_size(pb)))
308 308
                 return 0;
309 309
             left = a.size - avio_tell(pb) + start_pos;
310 310
             if (left > 0) /* skip garbage at atom end */
... ...
@@ -2354,7 +2354,7 @@ static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap)
2354 2354
 
2355 2355
     mov->fc = s;
2356 2356
     /* .mov and .mp4 aren't streamable anyway (only progressive download if moov is before mdat) */
2357
-    if(!url_is_streamed(pb))
2357
+    if(pb->seekable)
2358 2358
         atom.size = avio_size(pb);
2359 2359
     else
2360 2360
         atom.size = INT64_MAX;
... ...
@@ -2370,7 +2370,7 @@ static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap)
2370 2370
     }
2371 2371
     av_dlog(mov->fc, "on_parse_exit_offset=%lld\n", avio_tell(pb));
2372 2372
 
2373
-    if (!url_is_streamed(pb) && mov->chapter_track > 0)
2373
+    if (pb->seekable && mov->chapter_track > 0)
2374 2374
         mov_read_chapters(s);
2375 2375
 
2376 2376
     return 0;
... ...
@@ -2388,8 +2388,8 @@ static AVIndexEntry *mov_find_next_sample(AVFormatContext *s, AVStream **st)
2388 2388
             AVIndexEntry *current_sample = &avst->index_entries[msc->current_sample];
2389 2389
             int64_t dts = av_rescale(current_sample->timestamp, AV_TIME_BASE, msc->time_scale);
2390 2390
             av_dlog(s, "stream %d, sample %d, dts %"PRId64"\n", i, msc->current_sample, dts);
2391
-            if (!sample || (url_is_streamed(s->pb) && current_sample->pos < sample->pos) ||
2392
-                (!url_is_streamed(s->pb) &&
2391
+            if (!sample || (!s->pb->seekable && current_sample->pos < sample->pos) ||
2392
+                (s->pb->seekable &&
2393 2393
                  ((msc->pb != s->pb && dts < best_dts) || (msc->pb == s->pb &&
2394 2394
                  ((FFABS(best_dts - dts) <= AV_TIME_BASE && current_sample->pos < sample->pos) ||
2395 2395
                   (FFABS(best_dts - dts) > AV_TIME_BASE && dts < best_dts)))))) {
... ...
@@ -2413,7 +2413,7 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
2413 2413
     sample = mov_find_next_sample(s, &st);
2414 2414
     if (!sample) {
2415 2415
         mov->found_mdat = 0;
2416
-        if (!url_is_streamed(s->pb) ||
2416
+        if (s->pb->seekable||
2417 2417
             mov_read_default(mov, s->pb, (MOVAtom){ AV_RL32("root"), INT64_MAX }) < 0 ||
2418 2418
             s->pb->eof_reached)
2419 2419
             return AVERROR_EOF;
... ...
@@ -1955,7 +1955,7 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
1955 1955
     unsigned int samplesInChunk = 0;
1956 1956
     int size= pkt->size;
1957 1957
 
1958
-    if (url_is_streamed(s->pb)) return 0; /* Can't handle that */
1958
+    if (!s->pb->seekable) return 0; /* Can't handle that */
1959 1959
     if (!size) return 0; /* Discard 0 sized packets */
1960 1960
 
1961 1961
     if (enc->codec_id == CODEC_ID_AMR_NB) {
... ...
@@ -2090,7 +2090,7 @@ static int mov_write_header(AVFormatContext *s)
2090 2090
     MOVMuxContext *mov = s->priv_data;
2091 2091
     int i, hint_track = 0;
2092 2092
 
2093
-    if (url_is_streamed(s->pb)) {
2093
+    if (!s->pb->seekable) {
2094 2094
         av_log(s, AV_LOG_ERROR, "muxer does not support non seekable output\n");
2095 2095
         return -1;
2096 2096
     }
... ...
@@ -93,7 +93,7 @@ static int mpc_read_header(AVFormatContext *s, AVFormatParameters *ap)
93 93
     st->duration = c->fcount;
94 94
 
95 95
     /* try to read APE tags */
96
-    if (!url_is_streamed(s->pb)) {
96
+    if (s->pb->seekable) {
97 97
         int64_t pos = avio_tell(s->pb);
98 98
         ff_ape_parse_tag(s);
99 99
         if (!av_metadata_get(s->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX))
... ...
@@ -402,7 +402,7 @@ static int mpegps_read_pes_header(AVFormatContext *s,
402 402
         int i;
403 403
         for(i=0; i<s->nb_streams; i++){
404 404
             if(startcode == s->streams[i]->id &&
405
-               !url_is_streamed(s->pb) /* index useless on streams anyway */) {
405
+               s->pb->seekable /* index useless on streams anyway */) {
406 406
                 ff_reduce_index(s, i);
407 407
                 av_add_index_entry(s->streams[i], *ppos, dts, 0, 0, AVINDEX_KEYFRAME /* FIXME keyframe? */);
408 408
             }
... ...
@@ -1784,7 +1784,7 @@ static int mxf_write_footer(AVFormatContext *s)
1784 1784
     mxf_write_klv_fill(s);
1785 1785
     mxf_write_random_index_pack(s);
1786 1786
 
1787
-    if (!url_is_streamed(s->pb)) {
1787
+    if (s->pb->seekable) {
1788 1788
         avio_seek(pb, 0, SEEK_SET);
1789 1789
         if (mxf->edit_unit_byte_count) {
1790 1790
             mxf_write_partition(s, 1, 2, header_closed_partition_key, 1);
... ...
@@ -653,7 +653,7 @@ static int nut_read_header(AVFormatContext *s, AVFormatParameters *ap)
653 653
 
654 654
     s->data_offset= pos-8;
655 655
 
656
-    if(!url_is_streamed(bc)){
656
+    if(bc->seekable){
657 657
         int64_t orig_pos= avio_tell(bc);
658 658
         find_and_decode_index(nut);
659 659
         avio_seek(bc, orig_pos, SEEK_SET);
... ...
@@ -455,7 +455,7 @@ ogg_get_length (AVFormatContext * s)
455 455
     int i;
456 456
     int64_t size, end;
457 457
 
458
-    if(url_is_streamed(s->pb))
458
+    if(!s->pb->seekable)
459 459
         return 0;
460 460
 
461 461
 // already set
... ...
@@ -177,7 +177,7 @@ static int r3d_read_header(AVFormatContext *s, AVFormatParameters *ap)
177 177
 
178 178
     s->data_offset = avio_tell(s->pb);
179 179
     av_dlog(s, "data offset %#llx\n", s->data_offset);
180
-    if (url_is_streamed(s->pb))
180
+    if (!s->pb->seekable)
181 181
         return 0;
182 182
     // find REOB/REOF/REOS to load index
183 183
     avio_seek(s->pb, avio_size(s->pb)-48-8, SEEK_SET);
... ...
@@ -481,7 +481,7 @@ static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap)
481 481
 
482 482
     if (!data_off)
483 483
         data_off = avio_tell(pb) - 18;
484
-    if (indx_off && !url_is_streamed(pb) && !(s->flags & AVFMT_FLAG_IGNIDX) &&
484
+    if (indx_off && pb->seekable && !(s->flags & AVFMT_FLAG_IGNIDX) &&
485 485
         avio_seek(pb, indx_off, SEEK_SET) >= 0) {
486 486
         rm_read_index(s);
487 487
         avio_seek(pb, data_off + 18, SEEK_SET);
... ...
@@ -118,7 +118,7 @@ static int rv10_write_header(AVFormatContext *ctx,
118 118
     avio_wb32(s, 0);           /* data offset : will be patched after */
119 119
     avio_wb16(s, ctx->nb_streams);    /* num streams */
120 120
     flags = 1 | 2; /* save allowed & perfect play */
121
-    if (url_is_streamed(s))
121
+    if (!s->seekable)
122 122
         flags |= 4; /* live broadcast */
123 123
     avio_wb16(s, flags);
124 124
 
... ...
@@ -170,7 +170,7 @@ static int rv10_write_header(AVFormatContext *ctx,
170 170
         avio_wb32(s, 0);           /* start time */
171 171
         avio_wb32(s, BUFFER_DURATION);           /* preroll */
172 172
         /* duration */
173
-        if (url_is_streamed(s) || !stream->total_frames)
173
+        if (!s->seekable || !stream->total_frames)
174 174
             avio_wb32(s, (int)(3600 * 1000));
175 175
         else
176 176
             avio_wb32(s, (int)(stream->total_frames * 1000 / stream->frame_rate));
... ...
@@ -434,7 +434,7 @@ static int rm_write_trailer(AVFormatContext *s)
434 434
     int data_size, index_pos, i;
435 435
     AVIOContext *pb = s->pb;
436 436
 
437
-    if (!url_is_streamed(s->pb)) {
437
+    if (s->pb->seekable) {
438 438
         /* end of file: finish to write header */
439 439
         index_pos = avio_tell(pb);
440 440
         data_size = index_pos - rm->data_pos;
... ...
@@ -38,7 +38,7 @@ static int rso_write_header(AVFormatContext *s)
38 38
         return AVERROR_INVALIDDATA;
39 39
     }
40 40
 
41
-    if (url_is_streamed(s->pb)) {
41
+    if (!s->pb->seekable) {
42 42
         av_log(s, AV_LOG_ERROR, "muxer does not support non seekable output\n");
43 43
         return AVERROR_INVALIDDATA;
44 44
     }
... ...
@@ -96,7 +96,7 @@ static int sox_write_trailer(AVFormatContext *s)
96 96
     AVIOContext *pb = s->pb;
97 97
     AVCodecContext *enc = s->streams[0]->codec;
98 98
 
99
-    if (!url_is_streamed(s->pb)) {
99
+    if (s->pb->seekable) {
100 100
         /* update number of samples */
101 101
         int64_t file_size = avio_tell(pb);
102 102
         int64_t num_samples = (file_size - sox->header_size - 4LL) >> 2LL;
... ...
@@ -492,7 +492,7 @@ static int swf_write_trailer(AVFormatContext *s)
492 492
     avio_flush(s->pb);
493 493
 
494 494
     /* patch file size and number of frames if not streamed */
495
-    if (!url_is_streamed(s->pb) && video_enc) {
495
+    if (s->pb->seekable && video_enc) {
496 496
         file_size = avio_tell(pb);
497 497
         avio_seek(pb, 4, SEEK_SET);
498 498
         avio_wl32(pb, file_size);
... ...
@@ -88,7 +88,7 @@ static int read_header(AVFormatContext *avctx,
88 88
     /* simulate tty display speed */
89 89
     s->chars_per_frame = FFMAX(av_q2d(st->time_base) * (ap->sample_rate ? ap->sample_rate : LINE_RATE), 1);
90 90
 
91
-    if (!url_is_streamed(avctx->pb)) {
91
+    if (avctx->pb->seekable) {
92 92
         s->fsize = avio_size(avctx->pb);
93 93
         st->duration = (s->fsize + s->chars_per_frame - 1) / s->chars_per_frame;
94 94
 
... ...
@@ -2019,7 +2019,7 @@ static void av_estimate_timings(AVFormatContext *ic, int64_t old_offset)
2019 2019
 
2020 2020
     if ((!strcmp(ic->iformat->name, "mpeg") ||
2021 2021
          !strcmp(ic->iformat->name, "mpegts")) &&
2022
-        file_size && !url_is_streamed(ic->pb)) {
2022
+        file_size && ic->pb->seekable) {
2023 2023
         /* get accurate estimate from the PTSes */
2024 2024
         av_estimate_timings_from_pts(ic, old_offset);
2025 2025
     } else if (av_has_duration(ic)) {
... ...
@@ -73,7 +73,7 @@ static int vc1test_write_trailer(AVFormatContext *s)
73 73
     RCVContext *ctx = s->priv_data;
74 74
     AVIOContext *pb = s->pb;
75 75
 
76
-    if (!url_is_streamed(s->pb)) {
76
+    if (s->pb->seekable) {
77 77
         avio_seek(pb, 0, SEEK_SET);
78 78
         avio_wl24(pb, ctx->frames);
79 79
         avio_flush(pb);
... ...
@@ -78,7 +78,7 @@ voc_get_packet(AVFormatContext *s, AVPacket *pkt, AVStream *st, int max_size)
78 78
             return AVERROR(EIO);
79 79
         voc->remaining_size = avio_rl24(pb);
80 80
         if (!voc->remaining_size) {
81
-            if (url_is_streamed(s->pb))
81
+            if (!s->pb->seekable)
82 82
                 return AVERROR(EIO);
83 83
             voc->remaining_size = avio_size(pb) - avio_tell(pb);
84 84
         }
... ...
@@ -58,7 +58,7 @@ static int wav_write_header(AVFormatContext *s)
58 58
     ff_end_tag(pb, fmt);
59 59
 
60 60
     if (s->streams[0]->codec->codec_tag != 0x01 /* hence for all other than PCM */
61
-        && !url_is_streamed(s->pb)) {
61
+        && s->pb->seekable) {
62 62
         fact = ff_start_tag(pb, "fact");
63 63
         avio_wl32(pb, 0);
64 64
         ff_end_tag(pb, fact);
... ...
@@ -98,7 +98,7 @@ static int wav_write_trailer(AVFormatContext *s)
98 98
 
99 99
     avio_flush(pb);
100 100
 
101
-    if (!url_is_streamed(s->pb)) {
101
+    if (s->pb->seekable) {
102 102
         ff_end_tag(pb, wav->data);
103 103
 
104 104
         /* update file size */
... ...
@@ -121,7 +121,7 @@ static int wv_read_block_header(AVFormatContext *ctx, AVIOContext *pb, int appen
121 121
     }
122 122
     if((rate == -1 || !chan) && !wc->block_parsed){
123 123
         int64_t block_end = avio_tell(pb) + wc->blksize - 24;
124
-        if(url_is_streamed(pb)){
124
+        if(!pb->seekable){
125 125
             av_log(ctx, AV_LOG_ERROR, "Cannot determine additional parameters\n");
126 126
             return -1;
127 127
         }
... ...
@@ -223,7 +223,7 @@ static int wv_read_header(AVFormatContext *s,
223 223
     st->start_time = 0;
224 224
     st->duration = wc->samples;
225 225
 
226
-    if(!url_is_streamed(s->pb)) {
226
+    if(s->pb->seekable) {
227 227
         int64_t cur = avio_tell(s->pb);
228 228
         ff_ape_parse_tag(s);
229 229
         if(!av_metadata_get(s->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX))