Use it instead of url_is_streamed and AVIOContext.is_streamed.
/* XXX: potential leak */
return -1;
}
- c->fmt_ctx.pb->is_streamed = 1;
+ c->fmt_ctx.pb->seekable = 0;
/*
* HACK to avoid mpeg ps muxer to spit many underflow errors
}
ost = ctx->streams[pkt.stream_index];
- ctx->pb->is_streamed = 1;
+ ctx->pb->seekable = 0;
if (pkt.dts != AV_NOPTS_VALUE)
pkt.dts = av_rescale_q(pkt.dts, ist->time_base, ost->time_base);
if (pkt.pts != AV_NOPTS_VALUE)
/* XXX: potential leak */
return -1;
}
- c->fmt_ctx.pb->is_streamed = 1;
+ c->fmt_ctx.pb->seekable = 0;
av_write_trailer(ctx);
len = url_close_dyn_buf(ctx->pb, &c->pb_buffer);
c->buffer_ptr = c->pb_buffer;
pb = avio_alloc_context(c->buffer, c->buffer_end - c->buffer,
0, NULL, NULL, NULL, NULL);
- pb->is_streamed = 1;
+ pb->seekable = 0;
if (av_open_input_stream(&s, pb, c->stream->feed_filename, fmt_in, NULL) < 0) {
av_free(pb);
offset += avio_tell(pb); /* Compute absolute data offset */
if (st->codec->block_align) /* Assume COMM already parsed */
goto got_sound;
- if (url_is_streamed(pb)) {
+ if (!pb->seekable) {
av_log(s, AV_LOG_ERROR, "file is not seekable\n");
return -1;
}
end_size++;
}
- if (!url_is_streamed(s->pb)) {
+ if (s->pb->seekable) {
/* File length */
avio_seek(pb, aiff->form, SEEK_SET);
avio_wb32(pb, file_size - aiff->form - 4);
ape_dumpinfo(s, ape);
/* try to read APE tags */
- if (!url_is_streamed(pb)) {
+ if (pb->seekable) {
ff_ape_parse_tag(s);
avio_seek(pb, 0, SEEK_SET);
}
avio_wl64(pb, duration); /* end time stamp (in 100ns units) */
avio_wl64(pb, asf->duration); /* duration (in 100ns units) */
avio_wl64(pb, PREROLL_TIME); /* start time stamp */
- avio_wl32(pb, (asf->is_streamed || url_is_streamed(pb)) ? 3 : 2); /* ??? */
+ avio_wl32(pb, (asf->is_streamed || !pb->seekable ) ? 3 : 2); /* ??? */
avio_wl32(pb, s->packet_size); /* packet size */
avio_wl32(pb, s->packet_size); /* packet size */
avio_wl32(pb, bit_rate); /* Nominal data rate in bps */
}
avio_flush(s->pb);
- if (asf->is_streamed || url_is_streamed(s->pb)) {
+ if (asf->is_streamed || !s->pb->seekable) {
put_chunk(s, 0x4524, 0, 0); /* end of stream */
} else {
/* rewrite an updated header */
AVIOContext *pb = s->pb;
int64_t file_size;
- if (!url_is_streamed(s->pb)) {
+ if (s->pb->seekable) {
/* update file size */
file_size = avio_tell(pb);
break;
case MKTAG('i', 'n', 'd', 'x'):
i= avio_tell(pb);
- if(!url_is_streamed(pb) && !(s->flags & AVFMT_FLAG_IGNIDX)){
+ if(pb->seekable && !(s->flags & AVFMT_FLAG_IGNIDX)){
read_braindead_odml_indx(s, 0);
}
avio_seek(pb, i+size, SEEK_SET);
return -1;
}
- if(!avi->index_loaded && !url_is_streamed(pb))
+ if(!avi->index_loaded && pb->seekable)
avi_load_index(s);
avi->index_loaded = 1;
avi->non_interleaved |= guess_ni_flag(s);
}
avio_wl32(pb, bitrate / 8); /* XXX: not quite exact */
avio_wl32(pb, 0); /* padding */
- if (url_is_streamed(pb))
+ if (!pb->seekable)
avio_wl32(pb, AVIF_TRUSTCKTYPE | AVIF_ISINTERLEAVED); /* flags */
else
avio_wl32(pb, AVIF_TRUSTCKTYPE | AVIF_HASINDEX | AVIF_ISINTERLEAVED); /* flags */
avio_wl32(pb, 0); /* start */
avist->frames_hdr_strm = avio_tell(pb); /* remember this offset to fill later */
- if (url_is_streamed(pb))
+ if (!pb->seekable)
avio_wl32(pb, AVI_MAX_RIFF_SIZE); /* FIXME: this may be broken, but who cares */
else
avio_wl32(pb, 0); /* length, XXX: filled later */
}
}
- if (!url_is_streamed(pb)) {
+ if (pb->seekable) {
unsigned char tag[5];
int j;
ff_end_tag(pb, list2);
}
- if (!url_is_streamed(pb)) {
+ if (pb->seekable) {
/* AVI could become an OpenDML one, if it grows beyond 2Gb range */
avi->odml_list = ff_start_tag(pb, "JUNK");
ffio_wfourcc(pb, "odml");
char ix_tag[] = "ix00";
int i, j;
- assert(!url_is_streamed(pb));
+ assert(pb->seekable);
if (avi->riff_id > AVI_MASTER_INDEX_SIZE)
return -1;
int i;
char tag[5];
- if (!url_is_streamed(pb)) {
+ if (pb->seekable) {
AVIStream *avist;
AVIIentry* ie = 0, *tie;
int empty, stream_id = -1;
avist->packet_count++;
// Make sure to put an OpenDML chunk when the file size exceeds the limits
- if (!url_is_streamed(pb) &&
+ if (pb->seekable &&
(avio_tell(pb) - avi->riff_start > AVI_MAX_RIFF_SIZE)) {
avi_write_ix(s);
avist->audio_strm_length += size;
}
- if (!url_is_streamed(s->pb)) {
+ if (s->pb->seekable) {
AVIIndex* idx = &avist->indexes;
int cl = idx->entry / AVI_INDEX_CLUSTER_SIZE;
int id = idx->entry % AVI_INDEX_CLUSTER_SIZE;
int i, j, n, nb_frames;
int64_t file_size;
- if (!url_is_streamed(pb)){
+ if (pb->seekable){
if (avi->riff_id == 1) {
ff_end_tag(pb, avi->movi_list);
res = avi_write_idx1(s);
*/
int av_register_protocol2(URLProtocol *protocol, int size);
+#define AVIO_SEEKABLE_NORMAL 0x0001 /**< Seeking works like for a local file */
+
/**
* Bytestream IO Context.
* New fields can be added to the end with minor version bumps.
int must_flush; /**< true if the next seek should flush */
int eof_reached; /**< true if eof reached */
int write_flag; /**< true if open for writing */
- int is_streamed;
+#if FF_API_OLD_AVIO
+ attribute_deprecated int is_streamed;
+#endif
int max_packet_size;
unsigned long checksum;
unsigned char *checksum_ptr;
int (*read_pause)(void *opaque, int pause);
int64_t (*read_seek)(void *opaque, int stream_index,
int64_t timestamp, int flags);
+ /**
+ * A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
+ */
+ int seekable;
} AVIOContext;
#if FF_API_OLD_AVIO
unsigned int avio_rb32(AVIOContext *s);
uint64_t avio_rb64(AVIOContext *s);
-static inline int url_is_streamed(AVIOContext *s)
+#if FF_API_OLD_AVIO
+/**
+ * @deprecated Use AVIOContext.seekable field directly.
+ */
+attribute_deprecated static inline int url_is_streamed(AVIOContext *s)
{
- return s->is_streamed;
+ return !s->seekable;
}
+#endif
/**
* Create and initialize a AVIOContext for accessing the
s->must_flush = 0;
s->eof_reached = 0;
s->error = 0;
+#if FF_API_OLD_AVIO
s->is_streamed = 0;
+#endif
+ s->seekable = AVIO_SEEKABLE_NORMAL;
s->max_packet_size = 0;
s->update_checksum= NULL;
if(!read_packet && !write_flag){
offset1 >= 0 && offset1 <= (s->buf_end - s->buffer)) {
/* can do the seek inside the buffer */
s->buf_ptr = s->buffer + offset1;
- } else if ((s->is_streamed ||
+ } else if ((!s->seekable ||
offset1 <= s->buf_end + SHORT_SEEK_THRESHOLD - s->buffer) &&
!s->write_flag && offset1 >= 0 &&
(whence != SEEK_END || force)) {
av_freep(s);
return AVERROR(EIO);
}
+#if FF_API_OLD_AVIO
(*s)->is_streamed = h->is_streamed;
+#endif
+ (*s)->seekable = h->is_streamed ? 0 : AVIO_SEEKABLE_NORMAL;
(*s)->max_packet_size = max_packet_size;
if(h->prot) {
(*s)->read_pause = (int (*)(void *, int))h->prot->url_read_pause;
BinkDemuxContext *bink = s->priv_data;
AVStream *vst = s->streams[0];
- if (url_is_streamed(s->pb))
+ if (!s->pb->seekable)
return -1;
/* seek to the first frame */
/* stop at data chunk if seeking is not supported or
data chunk size is unknown */
- if (found_data && (caf->data_size < 0 || url_is_streamed(pb)))
+ if (found_data && (caf->data_size < 0 || !pb->seekable))
break;
tag = avio_rb32(pb);
avio_skip(pb, 4); /* edit count */
caf->data_start = avio_tell(pb);
caf->data_size = size < 0 ? -1 : size - 4;
- if (caf->data_size > 0 && !url_is_streamed(pb))
+ if (caf->data_size > 0 && pb->seekable)
avio_skip(pb, caf->data_size);
found_data = 1;
break;
goto fail;
ffm->write_index = avio_rb64(pb);
/* get also filesize */
- if (!url_is_streamed(pb)) {
+ if (pb->seekable) {
ffm->file_size = avio_size(pb);
if (ffm->write_index)
adjust_write_index(s);
AVIOContext *pb = s->pb;
AVStream *st;
- if (url_is_streamed(s->pb))
+ if (!s->pb->seekable)
return AVERROR(EIO);
avio_seek(pb, avio_size(pb) - 36, SEEK_SET);
if (!ff_flac_is_extradata_valid(s->streams[0]->codec, &format, &streaminfo))
return -1;
- if (!url_is_streamed(pb)) {
+ if (pb->seekable) {
/* rewrite the STREAMINFO header block data */
file_size = avio_tell(pb);
avio_seek(pb, 8, SEEK_SET);
}
// if not streamed and no duration from metadata then seek to end to find the duration from the timestamps
- if(!url_is_streamed(s->pb) && (!s->duration || s->duration==AV_NOPTS_VALUE)){
+ if(s->pb->seekable && (!s->duration || s->duration==AV_NOPTS_VALUE)){
int size;
const int64_t pos= avio_tell(s->pb);
const int64_t fsize= avio_size(s->pb);
if (ts - min_ts > (uint64_t)(max_ts - ts)) flags |= AVSEEK_FLAG_BACKWARD;
- if (url_is_streamed(s->pb)) {
+ if (!s->pb->seekable) {
if (stream_index < 0) {
stream_index = av_find_default_stream_index(s);
if (stream_index < 0)
uint8_t tracks[255] = {0};
int i, media_info = 0;
- if (url_is_streamed(pb)) {
+ if (!pb->seekable) {
av_log(s, AV_LOG_ERROR, "gxf muxer does not support streamed output, patch welcome");
return -1;
}
uint8_t buf[ID3v1_TAG_SIZE];
int64_t filesize, position = avio_tell(s->pb);
- if (!url_is_streamed(s->pb)) {
+ if (s->pb->seekable) {
/* XXX: change that */
filesize = avio_size(s->pb);
if (filesize > 128) {
int i;
// we should not do any seeking in the streaming case
- if (url_is_streamed(matroska->ctx->pb) ||
+ if (!matroska->ctx->pb->seekable ||
(matroska->ctx->flags & AVFMT_FLAG_IGNIDX))
return;
if (ret < 0) return ret;
}
- if (url_is_streamed(s->pb))
+ if (!s->pb->seekable)
mkv_write_seekhead(pb, mkv->main_seekhead);
mkv->cues = mkv_start_cues(mkv->segment_offset);
return AVERROR(EINVAL);
}
- if (url_is_streamed(s->pb)) {
+ if (!s->pb->seekable) {
if (!mkv->dyn_bc)
url_open_dyn_buf(&mkv->dyn_bc);
pb = mkv->dyn_bc;
static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt)
{
MatroskaMuxContext *mkv = s->priv_data;
- AVIOContext *pb = url_is_streamed(s->pb) ? mkv->dyn_bc : s->pb;
+ AVIOContext *pb = s->pb->seekable ? s->pb : mkv->dyn_bc;
AVCodecContext *codec = s->streams[pkt->stream_index]->codec;
int ret, keyframe = !!(pkt->flags & AV_PKT_FLAG_KEY);
int64_t ts = mkv->tracks[pkt->stream_index].write_dts ? pkt->dts : pkt->pts;
- int cluster_size = avio_tell(pb) - (url_is_streamed(s->pb) ? 0 : mkv->cluster_pos);
+ int cluster_size = avio_tell(pb) - (s->pb->seekable ? mkv->cluster_pos : 0);
// start a new cluster every 5 MB or 5 sec, or 32k / 1 sec for streaming or
// after 4k and on a keyframe
if (mkv->cluster_pos &&
- ((url_is_streamed(s->pb) && (cluster_size > 32*1024 || ts > mkv->cluster_pts + 1000))
+ ((!s->pb->seekable && (cluster_size > 32*1024 || ts > mkv->cluster_pts + 1000))
|| cluster_size > 5*1024*1024 || ts > mkv->cluster_pts + 5000
|| (codec->codec_type == AVMEDIA_TYPE_VIDEO && keyframe && cluster_size > 4*1024))) {
av_log(s, AV_LOG_DEBUG, "Starting new cluster at offset %" PRIu64
end_ebml_master(pb, mkv->cluster);
}
- if (!url_is_streamed(pb)) {
+ if (pb->seekable) {
cuespos = mkv_write_cues(pb, mkv->cues, s->nb_streams);
ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_CUES , cuespos);
int64_t pos, size;
int gatetime;
- if (!url_is_streamed(s->pb)) {
+ if (s->pb->seekable) {
/* Fill in length fields */
end_tag_be(pb, mmf->awapos);
end_tag_be(pb, mmf->atrpos);
if (err < 0)
return err;
if (c->found_moov && c->found_mdat &&
- (url_is_streamed(pb) || start_pos + a.size == avio_size(pb)))
+ (!pb->seekable || start_pos + a.size == avio_size(pb)))
return 0;
left = a.size - avio_tell(pb) + start_pos;
if (left > 0) /* skip garbage at atom end */
mov->fc = s;
/* .mov and .mp4 aren't streamable anyway (only progressive download if moov is before mdat) */
- if(!url_is_streamed(pb))
+ if(pb->seekable)
atom.size = avio_size(pb);
else
atom.size = INT64_MAX;
}
av_dlog(mov->fc, "on_parse_exit_offset=%lld\n", avio_tell(pb));
- if (!url_is_streamed(pb) && mov->chapter_track > 0)
+ if (pb->seekable && mov->chapter_track > 0)
mov_read_chapters(s);
return 0;
AVIndexEntry *current_sample = &avst->index_entries[msc->current_sample];
int64_t dts = av_rescale(current_sample->timestamp, AV_TIME_BASE, msc->time_scale);
av_dlog(s, "stream %d, sample %d, dts %"PRId64"\n", i, msc->current_sample, dts);
- if (!sample || (url_is_streamed(s->pb) && current_sample->pos < sample->pos) ||
- (!url_is_streamed(s->pb) &&
+ if (!sample || (!s->pb->seekable && current_sample->pos < sample->pos) ||
+ (s->pb->seekable &&
((msc->pb != s->pb && dts < best_dts) || (msc->pb == s->pb &&
((FFABS(best_dts - dts) <= AV_TIME_BASE && current_sample->pos < sample->pos) ||
(FFABS(best_dts - dts) > AV_TIME_BASE && dts < best_dts)))))) {
sample = mov_find_next_sample(s, &st);
if (!sample) {
mov->found_mdat = 0;
- if (!url_is_streamed(s->pb) ||
+ if (s->pb->seekable||
mov_read_default(mov, s->pb, (MOVAtom){ AV_RL32("root"), INT64_MAX }) < 0 ||
s->pb->eof_reached)
return AVERROR_EOF;
unsigned int samplesInChunk = 0;
int size= pkt->size;
- if (url_is_streamed(s->pb)) return 0; /* Can't handle that */
+ if (!s->pb->seekable) return 0; /* Can't handle that */
if (!size) return 0; /* Discard 0 sized packets */
if (enc->codec_id == CODEC_ID_AMR_NB) {
MOVMuxContext *mov = s->priv_data;
int i, hint_track = 0;
- if (url_is_streamed(s->pb)) {
+ if (!s->pb->seekable) {
av_log(s, AV_LOG_ERROR, "muxer does not support non seekable output\n");
return -1;
}
st->duration = c->fcount;
/* try to read APE tags */
- if (!url_is_streamed(s->pb)) {
+ if (s->pb->seekable) {
int64_t pos = avio_tell(s->pb);
ff_ape_parse_tag(s);
if (!av_metadata_get(s->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX))
int i;
for(i=0; i<s->nb_streams; i++){
if(startcode == s->streams[i]->id &&
- !url_is_streamed(s->pb) /* index useless on streams anyway */) {
+ s->pb->seekable /* index useless on streams anyway */) {
ff_reduce_index(s, i);
av_add_index_entry(s->streams[i], *ppos, dts, 0, 0, AVINDEX_KEYFRAME /* FIXME keyframe? */);
}
mxf_write_klv_fill(s);
mxf_write_random_index_pack(s);
- if (!url_is_streamed(s->pb)) {
+ if (s->pb->seekable) {
avio_seek(pb, 0, SEEK_SET);
if (mxf->edit_unit_byte_count) {
mxf_write_partition(s, 1, 2, header_closed_partition_key, 1);
s->data_offset= pos-8;
- if(!url_is_streamed(bc)){
+ if(bc->seekable){
int64_t orig_pos= avio_tell(bc);
find_and_decode_index(nut);
avio_seek(bc, orig_pos, SEEK_SET);
int i;
int64_t size, end;
- if(url_is_streamed(s->pb))
+ if(!s->pb->seekable)
return 0;
// already set
s->data_offset = avio_tell(s->pb);
av_dlog(s, "data offset %#llx\n", s->data_offset);
- if (url_is_streamed(s->pb))
+ if (!s->pb->seekable)
return 0;
// find REOB/REOF/REOS to load index
avio_seek(s->pb, avio_size(s->pb)-48-8, SEEK_SET);
if (!data_off)
data_off = avio_tell(pb) - 18;
- if (indx_off && !url_is_streamed(pb) && !(s->flags & AVFMT_FLAG_IGNIDX) &&
+ if (indx_off && pb->seekable && !(s->flags & AVFMT_FLAG_IGNIDX) &&
avio_seek(pb, indx_off, SEEK_SET) >= 0) {
rm_read_index(s);
avio_seek(pb, data_off + 18, SEEK_SET);
avio_wb32(s, 0); /* data offset : will be patched after */
avio_wb16(s, ctx->nb_streams); /* num streams */
flags = 1 | 2; /* save allowed & perfect play */
- if (url_is_streamed(s))
+ if (!s->seekable)
flags |= 4; /* live broadcast */
avio_wb16(s, flags);
avio_wb32(s, 0); /* start time */
avio_wb32(s, BUFFER_DURATION); /* preroll */
/* duration */
- if (url_is_streamed(s) || !stream->total_frames)
+ if (!s->seekable || !stream->total_frames)
avio_wb32(s, (int)(3600 * 1000));
else
avio_wb32(s, (int)(stream->total_frames * 1000 / stream->frame_rate));
int data_size, index_pos, i;
AVIOContext *pb = s->pb;
- if (!url_is_streamed(s->pb)) {
+ if (s->pb->seekable) {
/* end of file: finish to write header */
index_pos = avio_tell(pb);
data_size = index_pos - rm->data_pos;
return AVERROR_INVALIDDATA;
}
- if (url_is_streamed(s->pb)) {
+ if (!s->pb->seekable) {
av_log(s, AV_LOG_ERROR, "muxer does not support non seekable output\n");
return AVERROR_INVALIDDATA;
}
AVIOContext *pb = s->pb;
AVCodecContext *enc = s->streams[0]->codec;
- if (!url_is_streamed(s->pb)) {
+ if (s->pb->seekable) {
/* update number of samples */
int64_t file_size = avio_tell(pb);
int64_t num_samples = (file_size - sox->header_size - 4LL) >> 2LL;
avio_flush(s->pb);
/* patch file size and number of frames if not streamed */
- if (!url_is_streamed(s->pb) && video_enc) {
+ if (s->pb->seekable && video_enc) {
file_size = avio_tell(pb);
avio_seek(pb, 4, SEEK_SET);
avio_wl32(pb, file_size);
/* simulate tty display speed */
s->chars_per_frame = FFMAX(av_q2d(st->time_base) * (ap->sample_rate ? ap->sample_rate : LINE_RATE), 1);
- if (!url_is_streamed(avctx->pb)) {
+ if (avctx->pb->seekable) {
s->fsize = avio_size(avctx->pb);
st->duration = (s->fsize + s->chars_per_frame - 1) / s->chars_per_frame;
if ((!strcmp(ic->iformat->name, "mpeg") ||
!strcmp(ic->iformat->name, "mpegts")) &&
- file_size && !url_is_streamed(ic->pb)) {
+ file_size && ic->pb->seekable) {
/* get accurate estimate from the PTSes */
av_estimate_timings_from_pts(ic, old_offset);
} else if (av_has_duration(ic)) {
RCVContext *ctx = s->priv_data;
AVIOContext *pb = s->pb;
- if (!url_is_streamed(s->pb)) {
+ if (s->pb->seekable) {
avio_seek(pb, 0, SEEK_SET);
avio_wl24(pb, ctx->frames);
avio_flush(pb);
return AVERROR(EIO);
voc->remaining_size = avio_rl24(pb);
if (!voc->remaining_size) {
- if (url_is_streamed(s->pb))
+ if (!s->pb->seekable)
return AVERROR(EIO);
voc->remaining_size = avio_size(pb) - avio_tell(pb);
}
ff_end_tag(pb, fmt);
if (s->streams[0]->codec->codec_tag != 0x01 /* hence for all other than PCM */
- && !url_is_streamed(s->pb)) {
+ && s->pb->seekable) {
fact = ff_start_tag(pb, "fact");
avio_wl32(pb, 0);
ff_end_tag(pb, fact);
avio_flush(pb);
- if (!url_is_streamed(s->pb)) {
+ if (s->pb->seekable) {
ff_end_tag(pb, wav->data);
/* update file size */
}
if((rate == -1 || !chan) && !wc->block_parsed){
int64_t block_end = avio_tell(pb) + wc->blksize - 24;
- if(url_is_streamed(pb)){
+ if(!pb->seekable){
av_log(ctx, AV_LOG_ERROR, "Cannot determine additional parameters\n");
return -1;
}
st->start_time = 0;
st->duration = wc->samples;
- if(!url_is_streamed(s->pb)) {
+ if(s->pb->seekable) {
int64_t cur = avio_tell(s->pb);
ff_ape_parse_tag(s);
if(!av_metadata_get(s->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX))