Commit 899681cd authored by Björn Axelsson's avatar Björn Axelsson Committed by Andreas Öman

Use dynamically allocated ByteIOContext in AVFormatContext

patch by: Björn Axelsson, bjorn d axelsson a intinor d se
thread: [PATCH] Remove static ByteIOContexts, 06 nov 2007

Originally committed as revision 11071 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 79815f62
......@@ -920,9 +920,9 @@ static void print_report(AVFormatContext **output_files,
oc = output_files[0];
total_size = url_fsize(&oc->pb);
total_size = url_fsize(oc->pb);
if(total_size<0) // FIXME improve url_fsize() so it works with non seekable output too
total_size= url_ftell(&oc->pb);
total_size= url_ftell(oc->pb);
buf[0] = '\0';
ti1 = 1e10;
......@@ -1948,7 +1948,7 @@ static int av_encode(AVFormatContext **output_files,
break;
/* finish if limit size exhausted */
if (limit_filesize != 0 && limit_filesize < url_ftell(&output_files[0]->pb))
if (limit_filesize != 0 && limit_filesize < url_ftell(output_files[0]->pb))
break;
/* read a frame from it and output it in the fifo */
......@@ -3835,7 +3835,7 @@ static int av_exit()
AVFormatContext *s = output_files[i];
int j;
if (!(s->oformat->flags & AVFMT_NOFILE))
url_fclose(&s->pb);
url_fclose(s->pb);
for(j=0;j<s->nb_streams;j++) {
av_free(s->streams[j]->codec);
av_free(s->streams[j]);
......
......@@ -1912,7 +1912,8 @@ static int decode_thread(void *arg)
ret = -1;
goto fail;
}
ic->pb.eof_reached= 0; //FIXME hack, ffplay maybe should not use url_feof() to test for the end
if(ic->pb)
ic->pb->eof_reached= 0; //FIXME hack, ffplay maybe should not use url_feof() to test for the end
/* if seeking requested, we execute it */
if (start_time != AV_NOPTS_VALUE) {
......@@ -1980,7 +1981,7 @@ static int decode_thread(void *arg)
#if defined(CONFIG_RTSP_DEMUXER) || defined(CONFIG_MMSH_PROTOCOL)
if (is->paused &&
(!strcmp(ic->iformat->name, "rtsp") ||
!strcmp(url_fileno(&ic->pb)->prot->name, "mmsh"))) {
(ic->pb && !strcmp(url_fileno(ic->pb)->prot->name, "mmsh")))) {
/* wait 10 ms to avoid trying to get another packet */
/* XXX: horrible */
SDL_Delay(10);
......@@ -2023,14 +2024,14 @@ static int decode_thread(void *arg)
if (is->audioq.size > MAX_AUDIOQ_SIZE ||
is->videoq.size > MAX_VIDEOQ_SIZE ||
is->subtitleq.size > MAX_SUBTITLEQ_SIZE ||
url_feof(&ic->pb)) {
url_feof(ic->pb)) {
/* wait 10 ms */
SDL_Delay(10);
continue;
}
ret = av_read_frame(ic, pkt);
if (ret < 0) {
if (url_ferror(&ic->pb) == 0) {
if (url_ferror(ic->pb) == 0) {
SDL_Delay(100); /* wait for user event */
continue;
} else
......@@ -2282,7 +2283,7 @@ static void event_loop(void)
do_seek:
if (cur_stream) {
if (seek_by_bytes) {
pos = url_ftell(&cur_stream->ic->pb);
pos = url_ftell(cur_stream->ic->pb);
if (cur_stream->ic->bit_rate)
incr *= cur_stream->ic->bit_rate / 60.0;
else
......
......@@ -752,7 +752,7 @@ static void close_connection(HTTPContext *c)
/* prepare header */
if (url_open_dyn_buf(&ctx->pb) >= 0) {
av_write_trailer(ctx);
url_close_dyn_buf(&ctx->pb, &c->pb_buffer);
url_close_dyn_buf(ctx->pb, &c->pb_buffer);
}
}
}
......@@ -1596,9 +1596,9 @@ static void compute_stats(HTTPContext *c)
char *p;
time_t ti;
int i, len;
ByteIOContext pb1, *pb = &pb1;
ByteIOContext *pb;
if (url_open_dyn_buf(pb) < 0) {
if (url_open_dyn_buf(&pb) < 0) {
/* XXX: return an error ? */
c->buffer_ptr = c->buffer;
c->buffer_end = c->buffer;
......@@ -2032,13 +2032,13 @@ static int http_prepare_data(HTTPContext *c)
/* XXX: potential leak */
return -1;
}
c->fmt_ctx.pb.is_streamed = 1;
c->fmt_ctx.pb->is_streamed = 1;
av_set_parameters(&c->fmt_ctx, NULL);
if (av_write_header(&c->fmt_ctx) < 0)
return -1;
len = url_close_dyn_buf(&c->fmt_ctx.pb, &c->pb_buffer);
len = url_close_dyn_buf(c->fmt_ctx.pb, &c->pb_buffer);
c->buffer_ptr = c->pb_buffer;
c->buffer_end = c->pb_buffer + len;
......@@ -2182,7 +2182,7 @@ static int http_prepare_data(HTTPContext *c)
if (av_write_frame(ctx, &pkt))
c->state = HTTPSTATE_SEND_DATA_TRAILER;
len = url_close_dyn_buf(&ctx->pb, &c->pb_buffer);
len = url_close_dyn_buf(ctx->pb, &c->pb_buffer);
c->cur_frame_bytes = len;
c->buffer_ptr = c->pb_buffer;
c->buffer_end = c->pb_buffer + len;
......@@ -2208,7 +2208,7 @@ static int http_prepare_data(HTTPContext *c)
return -1;
}
av_write_trailer(ctx);
len = url_close_dyn_buf(&ctx->pb, &c->pb_buffer);
len = url_close_dyn_buf(ctx->pb, &c->pb_buffer);
c->buffer_ptr = c->pb_buffer;
c->buffer_end = c->pb_buffer + len;
......@@ -2261,7 +2261,7 @@ static int http_send_data(HTTPContext *c)
if (c->rtp_protocol == RTSP_PROTOCOL_RTP_TCP) {
/* RTP packets are sent inside the RTSP TCP connection */
ByteIOContext pb1, *pb = &pb1;
ByteIOContext *pb;
int interleaved_index, size;
uint8_t header[4];
HTTPContext *rtsp_c;
......@@ -2273,7 +2273,7 @@ static int http_send_data(HTTPContext *c)
/* if already sending something, then wait. */
if (rtsp_c->state != RTSPSTATE_WAIT_REQUEST)
break;
if (url_open_dyn_buf(pb) < 0)
if (url_open_dyn_buf(&pb) < 0)
goto fail1;
interleaved_index = c->packet_stream_index * 2;
/* RTCP packets are sent at odd indexes */
......@@ -2432,14 +2432,13 @@ static int http_receive_data(HTTPContext *c)
/* We have a header in our hands that contains useful data */
AVFormatContext s;
AVInputFormat *fmt_in;
ByteIOContext *pb = &s.pb;
int i;
memset(&s, 0, sizeof(s));
url_open_buf(pb, c->buffer, c->buffer_end - c->buffer, URL_RDONLY);
pb->buf_end = c->buffer_end; /* ?? */
pb->is_streamed = 1;
url_open_buf(&s.pb, c->buffer, c->buffer_end - c->buffer, URL_RDONLY);
s.pb->buf_end = c->buffer_end; /* ?? */
s.pb->is_streamed = 1;
/* use feed output format name to find corresponding input format */
fmt_in = av_find_input_format(feed->fmt->name);
......@@ -2553,7 +2552,6 @@ static int rtsp_parse_request(HTTPContext *c)
char url[1024];
char protocol[32];
char line[1024];
ByteIOContext pb1;
int len;
RTSPHeader header1, *header = &header1;
......@@ -2568,8 +2566,7 @@ static int rtsp_parse_request(HTTPContext *c)
av_strlcpy(c->url, url, sizeof(c->url));
av_strlcpy(c->protocol, protocol, sizeof(c->protocol));
c->pb = &pb1;
if (url_open_dyn_buf(c->pb) < 0) {
if (url_open_dyn_buf(&c->pb) < 0) {
/* XXX: cannot do more */
c->pb = NULL; /* safety */
return -1;
......@@ -3164,7 +3161,7 @@ static int rtp_new_av_stream(HTTPContext *c,
av_free(ctx);
return -1;
}
url_close_dyn_buf(&ctx->pb, &dummy_buf);
url_close_dyn_buf(ctx->pb, &dummy_buf);
av_free(dummy_buf);
c->rtp_ctx[stream_index] = ctx;
......@@ -3479,7 +3476,7 @@ static void build_feed_streams(void)
}
/* XXX: need better api */
av_freep(&s->priv_data);
url_fclose(&s->pb);
url_fclose(s->pb);
}
/* get feed size and write index */
fd = open(feed->feed_filename, O_RDONLY);
......
......@@ -92,7 +92,7 @@ static int fourxm_probe(AVProbeData *p)
static int fourxm_read_header(AVFormatContext *s,
AVFormatParameters *ap)
{
ByteIOContext *pb = &s->pb;
ByteIOContext *pb = s->pb;
unsigned int fourcc_tag;
unsigned int size;
int header_size;
......@@ -224,7 +224,7 @@ static int fourxm_read_packet(AVFormatContext *s,
AVPacket *pkt)
{
FourxmDemuxContext *fourxm = s->priv_data;
ByteIOContext *pb = &s->pb;
ByteIOContext *pb = s->pb;
unsigned int fourcc_tag;
unsigned int size, out_size;
int ret = 0;
......@@ -235,7 +235,7 @@ static int fourxm_read_packet(AVFormatContext *s,
while (!packet_read) {
if ((ret = get_buffer(&s->pb, header, 8)) < 0)
if ((ret = get_buffer(s->pb, header, 8)) < 0)
return ret;
fourcc_tag = AV_RL32(&header[0]);
size = AV_RL32(&header[4]);
......@@ -265,9 +265,9 @@ static int fourxm_read_packet(AVFormatContext *s,
return AVERROR(EIO);
pkt->stream_index = fourxm->video_stream_index;
pkt->pts = fourxm->video_pts;
pkt->pos = url_ftell(&s->pb);
pkt->pos = url_ftell(s->pb);
memcpy(pkt->data, header, 8);
ret = get_buffer(&s->pb, &pkt->data[8], size);
ret = get_buffer(s->pb, &pkt->data[8], size);
if (ret < 0)
av_free_packet(pkt);
......@@ -282,7 +282,7 @@ static int fourxm_read_packet(AVFormatContext *s,
size-=8;
if (track_number == fourxm->selected_track) {
ret= av_get_packet(&s->pb, pkt, size);
ret= av_get_packet(s->pb, pkt, size);
if(ret<0)
return AVERROR(EIO);
pkt->stream_index =
......
......@@ -84,7 +84,7 @@ static int adts_write_frame_header(AVFormatContext *s, int size)
put_bits(&pb, 2, 0); /* number_of_raw_data_blocks_in_frame */
flush_put_bits(&pb);
put_buffer(&s->pb, buf, ADTS_HEADER_SIZE);
put_buffer(s->pb, buf, ADTS_HEADER_SIZE);
return 0;
}
......@@ -92,7 +92,7 @@ static int adts_write_frame_header(AVFormatContext *s, int size)
static int adts_write_packet(AVFormatContext *s, AVPacket *pkt)
{
ADTSContext *adts = s->priv_data;
ByteIOContext *pb = &s->pb;
ByteIOContext *pb = s->pb;
if (!pkt->size)
return 0;
......
......@@ -161,7 +161,7 @@ typedef struct {
static int aiff_write_header(AVFormatContext *s)
{
AIFFOutputContext *aiff = s->priv_data;
ByteIOContext *pb = &s->pb;
ByteIOContext *pb = s->pb;
AVCodecContext *enc = s->streams[0]->codec;
AVExtFloat sample_rate;
int aifc = 0;
......@@ -231,14 +231,14 @@ static int aiff_write_header(AVFormatContext *s)
static int aiff_write_packet(AVFormatContext *s, AVPacket *pkt)
{
ByteIOContext *pb = &s->pb;
ByteIOContext *pb = s->pb;
put_buffer(pb, pkt->data, pkt->size);
return 0;
}
static int aiff_write_trailer(AVFormatContext *s)
{
ByteIOContext *pb = &s->pb;
ByteIOContext *pb = s->pb;
AIFFOutputContext *aiff = s->priv_data;
AVCodecContext *enc = s->streams[0]->codec;
......@@ -250,7 +250,7 @@ static int aiff_write_trailer(AVFormatContext *s)
end_size++;
}
if (!url_is_streamed(&s->pb)) {
if (!url_is_streamed(s->pb)) {
/* File length */
url_fseek(pb, aiff->form, SEEK_SET);
put_be32(pb, (uint32_t)(file_size - aiff->form - 4));
......@@ -293,7 +293,7 @@ static int aiff_read_header(AVFormatContext *s,
offset_t offset = 0;
uint32_t tag;
unsigned version = AIFF_C_VERSION1;
ByteIOContext *pb = &s->pb;
ByteIOContext *pb = s->pb;
AVStream * st = s->streams[0];
/* check FORM header */
......@@ -399,11 +399,11 @@ static int aiff_read_packet(AVFormatContext *s,
int res;
/* End of stream may be reached */
if (url_feof(&s->pb))
if (url_feof(s->pb))
return AVERROR(EIO);
/* Now for that packet */
res = av_get_packet(&s->pb, pkt, (MAX_SIZE / st->codec->block_align) * st->codec->block_align);
res = av_get_packet(s->pb, pkt, (MAX_SIZE / st->codec->block_align) * st->codec->block_align);
if (res < 0)
return res;
......
......@@ -33,7 +33,7 @@ static const char AMRWB_header [] = "#!AMR-WB\n";
#ifdef CONFIG_MUXERS
static int amr_write_header(AVFormatContext *s)
{
ByteIOContext *pb = &s->pb;
ByteIOContext *pb = s->pb;
AVCodecContext *enc = s->streams[0]->codec;
s->priv_data = NULL;
......@@ -56,8 +56,8 @@ static int amr_write_header(AVFormatContext *s)
static int amr_write_packet(AVFormatContext *s, AVPacket *pkt)
{
put_buffer(&s->pb, pkt->data, pkt->size);
put_flush_packet(&s->pb);
put_buffer(s->pb, pkt->data, pkt->size);
put_flush_packet(s->pb);
return 0;
}
#endif /* CONFIG_MUXERS */
......@@ -78,7 +78,7 @@ static int amr_probe(AVProbeData *p)
static int amr_read_header(AVFormatContext *s,
AVFormatParameters *ap)
{
ByteIOContext *pb = &s->pb;
ByteIOContext *pb = s->pb;
AVStream *st;
uint8_t header[9];
......@@ -120,13 +120,13 @@ static int amr_read_packet(AVFormatContext *s,
AVCodecContext *enc = s->streams[0]->codec;
int read, size = 0, toc, mode;
if (url_feof(&s->pb))
if (url_feof(s->pb))
{
return AVERROR(EIO);
}
//FIXME this is wrong, this should rather be in a AVParset
toc=get_byte(&s->pb);
toc=get_byte(s->pb);
mode = (toc >> 3) & 0x0F;
if (enc->codec_id == CODEC_ID_AMR_NB)
......@@ -152,10 +152,10 @@ static int amr_read_packet(AVFormatContext *s,
}
pkt->stream_index = 0;
pkt->pos= url_ftell(&s->pb);
pkt->pos= url_ftell(s->pb);
pkt->data[0]=toc;
pkt->duration= enc->codec_id == CODEC_ID_AMR_NB ? 160 : 320;
read = get_buffer(&s->pb, pkt->data+1, size-1);
read = get_buffer(s->pb, pkt->data+1, size-1);
if (read != size-1)
{
......
......@@ -32,7 +32,7 @@ static int apc_probe(AVProbeData *p)
static int apc_read_header(AVFormatContext *s, AVFormatParameters *ap)
{
ByteIOContext *pb = &s->pb;
ByteIOContext *pb = s->pb;
AVStream *st;
get_le32(pb); /* CRYO */
......@@ -74,7 +74,7 @@ static int apc_read_header(AVFormatContext *s, AVFormatParameters *ap)
static int apc_read_packet(AVFormatContext *s, AVPacket *pkt)
{
if (av_get_packet(&s->pb, pkt, MAX_READ_SIZE) <= 0)
if (av_get_packet(s->pb, pkt, MAX_READ_SIZE) <= 0)
return AVERROR(EIO);
pkt->stream_index = 0;
return 0;
......
......@@ -110,7 +110,7 @@ typedef struct {
static void ape_tag_read_field(AVFormatContext *s)
{
ByteIOContext *pb = &s->pb;
ByteIOContext *pb = s->pb;
uint8_t buf[1024];
uint32_t size;
int i;
......@@ -143,7 +143,7 @@ static void ape_tag_read_field(AVFormatContext *s)
static void ape_parse_tag(AVFormatContext *s)
{
ByteIOContext *pb = &s->pb;
ByteIOContext *pb = s->pb;
int file_size = url_fsize(pb);
uint32_t val, fields, tag_bytes;
uint8_t buf[8];
......@@ -270,7 +270,7 @@ static void ape_dumpinfo(APEContext * ape_ctx)
static int ape_read_header(AVFormatContext * s, AVFormatParameters * ap)
{
ByteIOContext *pb = &s->pb;
ByteIOContext *pb = s->pb;
APEContext *ape = s->priv_data;
AVStream *st;
uint32_t tag;
......@@ -456,12 +456,12 @@ static int ape_read_packet(AVFormatContext * s, AVPacket * pkt)
APEContext *ape = s->priv_data;
uint32_t extra_size = 8;
if (url_feof(&s->pb))
if (url_feof(s->pb))
return AVERROR_IO;
if (ape->currentframe > ape->totalframes)
return AVERROR_IO;
url_fseek (&s->pb, ape->frames[ape->currentframe].pos, SEEK_SET);
url_fseek (s->pb, ape->frames[ape->currentframe].pos, SEEK_SET);
/* Calculate how many blocks there are in this frame */
if (ape->currentframe == (ape->totalframes - 1))
......@@ -474,7 +474,7 @@ static int ape_read_packet(AVFormatContext * s, AVPacket * pkt)
AV_WL32(pkt->data , nblocks);
AV_WL32(pkt->data + 4, ape->frames[ape->currentframe].skip);
ret = get_buffer(&s->pb, pkt->data + extra_size, ape->frames[ape->currentframe].size);
ret = get_buffer(s->pb, pkt->data + extra_size, ape->frames[ape->currentframe].size);
pkt->pts = ape->frames[ape->currentframe].pts;
pkt->stream_index = 0;
......
......@@ -244,7 +244,7 @@ static void end_header(ByteIOContext *pb, int64_t pos)
static void put_chunk(AVFormatContext *s, int type, int payload_length, int flags)
{
ASFContext *asf = s->priv_data;
ByteIOContext *pb = &s->pb;
ByteIOContext *pb = s->pb;
int length;
length = payload_length + 8;
......@@ -270,7 +270,7 @@ static int64_t unix_to_file_time(int ti)
static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data_chunk_size)
{
ASFContext *asf = s->priv_data;
ByteIOContext *pb = &s->pb;
ByteIOContext *pb = s->pb;
int header_size, n, extra_size, extra_size2, wav_extra_size, file_time;
int has_title;
AVCodecContext *enc;
......@@ -506,7 +506,7 @@ static int asf_write_header(AVFormatContext *s)
return -1;
}
put_flush_packet(&s->pb);
put_flush_packet(s->pb);
asf->packet_nb_payloads = 0;
asf->packet_timestamp_start = -1;
......@@ -535,7 +535,7 @@ static int put_payload_parsing_info(
)
{
ASFContext *asf = s->priv_data;
ByteIOContext *pb = &s->pb;
ByteIOContext *pb = s->pb;
int ppi_size, i;
int64_t start= url_ftell(pb);
......@@ -600,9 +600,9 @@ static void flush_packet(AVFormatContext *s)
assert(packet_hdr_size <= asf->packet_size_left);
memset(asf->packet_buf + packet_filled_size, 0, asf->packet_size_left);
put_buffer(&s->pb, asf->packet_buf, asf->packet_size - packet_hdr_size);
put_buffer(s->pb, asf->packet_buf, asf->packet_size - packet_hdr_size);
put_flush_packet(&s->pb);
put_flush_packet(s->pb);
asf->nb_packets++;
asf->packet_nb_payloads = 0;
asf->packet_timestamp_start = -1;
......@@ -766,7 +766,7 @@ static int asf_write_packet(AVFormatContext *s, AVPacket *pkt)
//
static int asf_write_index(AVFormatContext *s, ASFIndex *index, uint16_t max, uint32_t count)
{
ByteIOContext *pb = &s->pb;
ByteIOContext *pb = s->pb;
int i;
put_guid(pb, &simple_index_header);
......@@ -793,22 +793,22 @@ static int asf_write_trailer(AVFormatContext *s)
flush_packet(s);
/* write index */
data_size = url_ftell(&s->pb);
data_size = url_ftell(s->pb);
if ((!asf->is_streamed) && (asf->nb_index_count != 0)) {
asf_write_index(s, asf->index_ptr, asf->maximum_packet, asf->nb_index_count);
}
put_flush_packet(&s->pb);
put_flush_packet(s->pb);
if (asf->is_streamed || url_is_streamed(&s->pb)) {
if (asf->is_streamed || url_is_streamed(s->pb)) {
put_chunk(s, 0x4524, 0, 0); /* end of stream */
} else {
/* rewrite an updated header */
file_size = url_ftell(&s->pb);
url_fseek(&s->pb, 0, SEEK_SET);
file_size = url_ftell(s->pb);
url_fseek(s->pb, 0, SEEK_SET);
asf_write_header1(s, file_size, data_size - asf->data_offset);
}
put_flush_packet(&s->pb);
put_flush_packet(s->pb);
av_free(asf->index_ptr);
return 0;
}
......
......@@ -148,7 +148,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
{
ASFContext *asf = s->priv_data;
GUID g;
ByteIOContext *pb = &s->pb;
ByteIOContext *pb = s->pb;
AVStream *st;
ASFStream *asf_st;
int size, i;
......@@ -582,12 +582,12 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
static int asf_get_packet(AVFormatContext *s)
{
ASFContext *asf = s->priv_data;
ByteIOContext *pb = &s->pb;
ByteIOContext *pb = s->pb;
uint32_t packet_length, padsize;
int rsize = 8;
int c, d, e, off;
off= (url_ftell(&s->pb) - s->data_offset) % asf->packet_size + 3;
off= (url_ftell(s->pb) - s->data_offset) % asf->packet_size + 3;
c=d=e=-1;
while(off-- > 0){
......@@ -658,7 +658,7 @@ static int asf_get_packet(AVFormatContext *s)
*/
static int asf_read_frame_header(AVFormatContext *s){
ASFContext *asf = s->priv_data;
ByteIOContext *pb = &s->pb;
ByteIOContext *pb = s->pb;
int rsize = 1;
int num = get_byte(pb);
int64_t ts0, ts1;
......@@ -731,7 +731,7 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
{
ASFContext *asf = s->priv_data;
ASFStream *asf_st = 0;
ByteIOContext *pb = &s->pb;
ByteIOContext *pb = s->pb;
//static int pc = 0;
for (;;) {
if(url_feof(pb))
......@@ -745,7 +745,7 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
/* fail safe */
url_fskip(pb, ret);
asf->packet_pos= url_ftell(&s->pb);
asf->packet_pos= url_ftell(s->pb);
if (asf->data_object_size != (uint64_t)-1 &&
(asf->packet_pos - asf->data_object_offset >= asf->data_object_size))
return AVERROR(EIO); /* Do not exceed the size of the data object */
......@@ -968,7 +968,7 @@ static int64_t asf_read_pts(AVFormatContext *s, int stream_index, int64_t *ppos,
pos= (pos+asf->packet_size-1-s->data_offset)/asf->packet_size*asf->packet_size+ s->data_offset;
*ppos= pos;
url_fseek(&s->pb, pos, SEEK_SET);
url_fseek(s->pb, pos, SEEK_SET);
//printf("asf_read_pts\n");
asf_reset_header(s);
......@@ -1012,21 +1012,21 @@ static void asf_build_simple_index(AVFormatContext *s, int stream_index)
int i;