Permalink
Browse files

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



git-svn-id: file:///var/local/repositories/ffmpeg/trunk@11071 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
  • Loading branch information...
1 parent 315194a commit 9ce92bc36357726e6f9d6d7fc0565aeca222bacc andoma committed Nov 21, 2007
Showing with 874 additions and 825 deletions.
  1. +4 −4 ffmpeg.c
  2. +6 −5 ffplay.c
  3. +15 −18 ffserver.c
  4. +6 −6 libavformat/4xm.c
  5. +2 −2 libavformat/adtsenc.c
  6. +7 −7 libavformat/aiff.c
  7. +8 −8 libavformat/amr.c
  8. +2 −2 libavformat/apc.c
  9. +6 −6 libavformat/ape.c
  10. +13 −13 libavformat/asf-enc.c
  11. +21 −21 libavformat/asf.c
  12. +7 −7 libavformat/au.c
  13. +3 −3 libavformat/avformat.h
  14. +9 −9 libavformat/avidec.c
  15. +7 −7 libavformat/avienc.c
  16. +5 −5 libavformat/avio.h
  17. +51 −16 libavformat/aviobuf.c
  18. +16 −16 libavformat/avs.c
  19. +2 −2 libavformat/bethsoftvid.c
  20. +2 −2 libavformat/c93.c
  21. +2 −2 libavformat/crcenc.c
  22. +1 −1 libavformat/daud.c
  23. +2 −2 libavformat/dsicin.c
  24. +5 −5 libavformat/dv.c
  25. +2 −2 libavformat/dvenc.c
  26. +12 −12 libavformat/dxa.c
  27. +2 −2 libavformat/eacdata.c
  28. +6 −6 libavformat/electronicarts.c
  29. +11 −11 libavformat/ffm.c
  30. +2 −2 libavformat/flic.c
  31. +31 −31 libavformat/flvdec.c
  32. +3 −3 libavformat/flvenc.c
  33. +2 −2 libavformat/framecrcenc.c
  34. +6 −6 libavformat/gif.c
  35. +1 −1 libavformat/gifdec.c
  36. +6 −6 libavformat/gxf.c
  37. +4 −4 libavformat/gxfenc.c
  38. +3 −3 libavformat/idcin.c
  39. +3 −3 libavformat/idroq.c
  40. +6 −6 libavformat/img2.c
  41. +2 −2 libavformat/ipmovie.c
  42. +4 −4 libavformat/libnut.c
  43. +18 −18 libavformat/matroskadec.c
  44. +16 −14 libavformat/matroskaenc.c
  45. +3 −3 libavformat/mm.c
  46. +7 −7 libavformat/mmf.c
  47. +4 −4 libavformat/mov.c
  48. +14 −11 libavformat/movenc.c
  49. +49 −49 libavformat/mp3.c
  50. +18 −18 libavformat/mpc.c
  51. +10 −10 libavformat/mpc8.c
  52. +42 −42 libavformat/mpeg.c
  53. +43 −43 libavformat/mpegenc.c
  54. +17 −17 libavformat/mpegts.c
  55. +5 −5 libavformat/mpegtsenc.c
  56. +6 −6 libavformat/mpjpeg.c
  57. +2 −2 libavformat/mtv.c
  58. +15 −15 libavformat/mxf.c
  59. +4 −4 libavformat/nsvdec.c
  60. +12 −12 libavformat/nutdec.c
  61. +40 −28 libavformat/nutenc.c
  62. +2 −2 libavformat/nuv.c
  63. +7 −7 libavformat/oggdec.c
  64. +19 −19 libavformat/oggenc.c
  65. +2 −2 libavformat/psxstr.c
  66. +22 −22 libavformat/raw.c
  67. +12 −12 libavformat/rmdec.c
  68. +7 −7 libavformat/rmenc.c
  69. +42 −42 libavformat/rtp.c
  70. +1 −1 libavformat/rtsp.c
  71. +2 −2 libavformat/segafilm.c
  72. +2 −2 libavformat/sierravmd.c
  73. +8 −8 libavformat/siff.c
  74. +15 −15 libavformat/smacker.c
  75. +3 −3 libavformat/sol.c
  76. +15 −15 libavformat/swf.c
  77. +2 −2 libavformat/thp.c
  78. +2 −2 libavformat/tiertexseq.c
  79. +15 −15 libavformat/tta.c
  80. +4 −4 libavformat/txd.c
  81. +25 −26 libavformat/utils.c
  82. +2 −2 libavformat/vocdec.c
  83. +3 −3 libavformat/vocenc.c
  84. +11 −11 libavformat/wav.c
  85. +2 −2 libavformat/wc3movie.c
  86. +4 −4 libavformat/westwood.c
  87. +7 −7 libavformat/wv.c
  88. +4 −4 libavformat/yuv4mpeg.c
  89. +1 −1 output_example.c
View
@@ -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]);
View
@@ -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
View
@@ -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);
View
@@ -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 =
View
@@ -84,15 +84,15 @@ 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;
}
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;
View
@@ -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;
View
@@ -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)
{
Oops, something went wrong.

0 comments on commit 9ce92bc

Please sign in to comment.