Mercurial > libavformat.hg
changeset 4669:d6eb19c43e99 libavformat
Allocate AVFifoBuffer through the fifo API to reduce future API/ABI issues.
Yes this breaks ABI/API but ive already broken it and will bump avutil major
soon.
author | michael |
---|---|
date | Sun, 08 Mar 2009 14:16:55 +0000 |
parents | 1f87eacc3c32 |
children | b1feed18d106 |
files | audiointerleave.c audiointerleave.h dvenc.c mpegenc.c swf.h swfenc.c |
diffstat | 6 files changed, 41 insertions(+), 41 deletions(-) [+] |
line wrap: on
line diff
--- a/audiointerleave.c Sat Mar 07 22:42:09 2009 +0000 +++ b/audiointerleave.c Sun Mar 08 14:16:55 2009 +0000 @@ -33,7 +33,7 @@ AudioInterleaveContext *aic = st->priv_data; if (st->codec->codec_type == CODEC_TYPE_AUDIO) - av_fifo_free(&aic->fifo); + av_fifo_free(aic->fifo); } } @@ -62,7 +62,7 @@ aic->time_base = time_base; aic->fifo_size = 100* *aic->samples; - av_fifo_init(&aic->fifo, 100 * *aic->samples); + aic->fifo= av_fifo_alloc(100 * *aic->samples); } } @@ -75,12 +75,12 @@ AVStream *st = s->streams[stream_index]; AudioInterleaveContext *aic = st->priv_data; - int size = FFMIN(av_fifo_size(&aic->fifo), *aic->samples * aic->sample_size); - if (!size || (!flush && size == av_fifo_size(&aic->fifo))) + int size = FFMIN(av_fifo_size(aic->fifo), *aic->samples * aic->sample_size); + if (!size || (!flush && size == av_fifo_size(aic->fifo))) return 0; av_new_packet(pkt, size); - av_fifo_read(&aic->fifo, pkt->data, size); + av_fifo_read(aic->fifo, pkt->data, size); pkt->dts = pkt->pts = aic->dts; pkt->duration = av_rescale_q(*aic->samples, st->time_base, aic->time_base); @@ -104,13 +104,13 @@ AVStream *st = s->streams[pkt->stream_index]; AudioInterleaveContext *aic = st->priv_data; if (st->codec->codec_type == CODEC_TYPE_AUDIO) { - unsigned new_size = av_fifo_size(&aic->fifo) + pkt->size; + unsigned new_size = av_fifo_size(aic->fifo) + pkt->size; if (new_size > aic->fifo_size) { - if (av_fifo_realloc2(&aic->fifo, new_size) < 0) + if (av_fifo_realloc2(aic->fifo, new_size) < 0) return -1; aic->fifo_size = new_size; } - av_fifo_generic_write(&aic->fifo, pkt->data, pkt->size, NULL); + av_fifo_generic_write(aic->fifo, pkt->data, pkt->size, NULL); } else { // rewrite pts and dts to be decoded time line position pkt->pts = pkt->dts = aic->dts;
--- a/audiointerleave.h Sat Mar 07 22:42:09 2009 +0000 +++ b/audiointerleave.h Sun Mar 08 14:16:55 2009 +0000 @@ -27,7 +27,7 @@ #include "avformat.h" typedef struct { - AVFifoBuffer fifo; + AVFifoBuffer *fifo; unsigned fifo_size; ///< size of currently allocated FIFO uint64_t dts; ///< current dts int sample_size; ///< size of one sample all channels included
--- a/dvenc.c Sat Mar 07 22:42:09 2009 +0000 +++ b/dvenc.c Sun Mar 08 14:16:55 2009 +0000 @@ -38,7 +38,7 @@ const DVprofile* sys; /* current DV profile, e.g.: 525/60, 625/50 */ int n_ast; /* number of stereo audio streams (up to 2) */ AVStream *ast[2]; /* stereo audio streams */ - AVFifoBuffer audio_data[2]; /* FIFO for storing excessive amounts of PCM */ + AVFifoBuffer *audio_data[2]; /* FIFO for storing excessive amounts of PCM */ int frames; /* current frame number */ time_t start_time; /* recording start time */ int has_audio; /* frame under contruction has audio */ @@ -189,8 +189,8 @@ if (of*2 >= size) continue; - frame_ptr[d] = av_fifo_peek(&c->audio_data[channel], of*2+1); // FIXME: maybe we have to admit - frame_ptr[d+1] = av_fifo_peek(&c->audio_data[channel], of*2); // that DV is a big-endian PCM + frame_ptr[d] = av_fifo_peek(c->audio_data[channel], of*2+1); // FIXME: maybe we have to admit + frame_ptr[d+1] = av_fifo_peek(c->audio_data[channel], of*2); // that DV is a big-endian PCM } frame_ptr += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */ } @@ -251,12 +251,12 @@ for (i = 0; i < c->n_ast && st != c->ast[i]; i++); /* FIXME: we have to have more sensible approach than this one */ - if (av_fifo_size(&c->audio_data[i]) + data_size >= 100*AVCODEC_MAX_AUDIO_FRAME_SIZE) + if (av_fifo_size(c->audio_data[i]) + data_size >= 100*AVCODEC_MAX_AUDIO_FRAME_SIZE) av_log(st->codec, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient video data or severe sync problem.\n", c->frames); - av_fifo_generic_write(&c->audio_data[i], data, data_size, NULL); + av_fifo_generic_write(c->audio_data[i], data, data_size, NULL); /* Let us see if we've got enough audio for one DV frame. */ - c->has_audio |= ((reqasize <= av_fifo_size(&c->audio_data[i])) << i); + c->has_audio |= ((reqasize <= av_fifo_size(c->audio_data[i])) << i); break; default: @@ -269,8 +269,8 @@ c->has_audio = 0; for (i=0; i < c->n_ast; i++) { dv_inject_audio(c, i, *frame); - av_fifo_drain(&c->audio_data[i], reqasize); - c->has_audio |= ((reqasize <= av_fifo_size(&c->audio_data[i])) << i); + av_fifo_drain(c->audio_data[i], reqasize); + c->has_audio |= ((reqasize <= av_fifo_size(c->audio_data[i])) << i); } c->has_video = 0; @@ -337,10 +337,10 @@ c->start_time = (time_t)s->timestamp; for (i=0; i < c->n_ast; i++) { - if (c->ast[i] && av_fifo_init(&c->audio_data[i], 100*AVCODEC_MAX_AUDIO_FRAME_SIZE) < 0) { + if (c->ast[i] && !(c->audio_data[i]=av_fifo_alloc(100*AVCODEC_MAX_AUDIO_FRAME_SIZE))) { while (i > 0) { i--; - av_fifo_free(&c->audio_data[i]); + av_fifo_free(c->audio_data[i]); } goto bail_out; } @@ -356,7 +356,7 @@ { int i; for (i=0; i < c->n_ast; i++) - av_fifo_free(&c->audio_data[i]); + av_fifo_free(c->audio_data[i]); } #if CONFIG_DV_MUXER
--- a/mpegenc.c Sat Mar 07 22:42:09 2009 +0000 +++ b/mpegenc.c Sun Mar 08 14:16:55 2009 +0000 @@ -40,7 +40,7 @@ } PacketDesc; typedef struct { - AVFifoBuffer fifo; + AVFifoBuffer *fifo; uint8_t id; int max_buffer_size; /* in bytes */ int buffer_index; @@ -381,7 +381,7 @@ default: return -1; } - av_fifo_init(&stream->fifo, 16); + stream->fifo= av_fifo_alloc(16); } bitrate = 0; audio_bitrate = 0; @@ -786,7 +786,7 @@ startcode = 0x100 + id; } - stuffing_size = payload_size - av_fifo_size(&stream->fifo); + stuffing_size = payload_size - av_fifo_size(stream->fifo); // first byte does not fit -> reset pts/dts + stuffing if(payload_size <= trailer_size && pts != AV_NOPTS_VALUE){ @@ -913,8 +913,8 @@ } /* output data */ - assert(payload_size - stuffing_size <= av_fifo_size(&stream->fifo)); - av_fifo_generic_read(&stream->fifo, payload_size - stuffing_size, &put_buffer, ctx->pb); + assert(payload_size - stuffing_size <= av_fifo_size(stream->fifo)); + av_fifo_generic_read(stream->fifo, payload_size - stuffing_size, &put_buffer, ctx->pb); stream->bytes_to_iframe -= payload_size - stuffing_size; }else{ payload_size= @@ -1031,7 +1031,7 @@ for(i=0; i<ctx->nb_streams; i++){ AVStream *st = ctx->streams[i]; StreamInfo *stream = st->priv_data; - const int avail_data= av_fifo_size(&stream->fifo); + const int avail_data= av_fifo_size(stream->fifo); const int space= stream->max_buffer_size - stream->buffer_index; int rel_space= 1024*space / stream->max_buffer_size; PacketDesc *next_pkt= stream->premux_packet; @@ -1091,7 +1091,7 @@ st = ctx->streams[best_i]; stream = st->priv_data; - assert(av_fifo_size(&stream->fifo) > 0); + assert(av_fifo_size(stream->fifo) > 0); assert(avail_space >= s->packet_size || ignore_constraints); @@ -1107,7 +1107,7 @@ //av_log(ctx, AV_LOG_DEBUG, "dts:%f pts:%f scr:%f stream:%d\n", timestamp_packet->dts/90000.0, timestamp_packet->pts/90000.0, scr/90000.0, best_i); es_size= flush_packet(ctx, best_i, timestamp_packet->pts, timestamp_packet->dts, scr, trailer_size); }else{ - assert(av_fifo_size(&stream->fifo) == trailer_size); + assert(av_fifo_size(stream->fifo) == trailer_size); es_size= flush_packet(ctx, best_i, AV_NOPTS_VALUE, AV_NOPTS_VALUE, scr, trailer_size); } @@ -1170,18 +1170,18 @@ stream->predecode_packet= pkt_desc; stream->next_packet= &pkt_desc->next; - if (av_fifo_realloc2(&stream->fifo, av_fifo_size(&stream->fifo) + size) < 0) + if (av_fifo_realloc2(stream->fifo, av_fifo_size(stream->fifo) + size) < 0) return -1; if (s->is_dvd){ if (is_iframe && (s->packet_number == 0 || (pts - stream->vobu_start_pts >= 36000))) { // min VOBU length 0.4 seconds (mpucoder) - stream->bytes_to_iframe = av_fifo_size(&stream->fifo); + stream->bytes_to_iframe = av_fifo_size(stream->fifo); stream->align_iframe = 1; stream->vobu_start_pts = pts; } } - av_fifo_generic_write(&stream->fifo, buf, size, NULL); + av_fifo_generic_write(stream->fifo, buf, size, NULL); for(;;){ int ret= output_packet(ctx, 0); @@ -1213,8 +1213,8 @@ for(i=0;i<ctx->nb_streams;i++) { stream = ctx->streams[i]->priv_data; - assert(av_fifo_size(&stream->fifo) == 0); - av_fifo_free(&stream->fifo); + assert(av_fifo_size(stream->fifo) == 0); + av_fifo_free(stream->fifo); } return 0; }
--- a/swf.h Sat Mar 07 22:42:09 2009 +0000 +++ b/swf.h Sun Mar 08 14:16:55 2009 +0000 @@ -75,7 +75,7 @@ int video_frame_number; int frame_rate; int tag; - AVFifoBuffer audio_fifo; + AVFifoBuffer *audio_fifo; AVCodecContext *audio_enc, *video_enc; } SWFContext;
--- a/swfenc.c Sat Mar 07 22:42:09 2009 +0000 +++ b/swfenc.c Sun Mar 08 14:16:55 2009 +0000 @@ -192,7 +192,7 @@ return -1; } swf->audio_enc = enc; - av_fifo_init(&swf->audio_fifo, AUDIO_FIFO_SIZE); + swf->audio_fifo= av_fifo_alloc(AUDIO_FIFO_SIZE); } else { av_log(s, AV_LOG_ERROR, "SWF muxer only supports MP3\n"); return -1; @@ -414,12 +414,12 @@ swf->swf_frame_number++; /* streaming sound always should be placed just before showframe tags */ - if (swf->audio_enc && av_fifo_size(&swf->audio_fifo)) { - int frame_size = av_fifo_size(&swf->audio_fifo); + if (swf->audio_enc && av_fifo_size(swf->audio_fifo)) { + int frame_size = av_fifo_size(swf->audio_fifo); put_swf_tag(s, TAG_STREAMBLOCK | TAG_LONG); put_le16(pb, swf->sound_samples); put_le16(pb, 0); // seek samples - av_fifo_generic_read(&swf->audio_fifo, frame_size, &put_buffer, pb); + av_fifo_generic_read(swf->audio_fifo, frame_size, &put_buffer, pb); put_swf_end_tag(s); /* update FIFO */ @@ -444,12 +444,12 @@ if (swf->swf_frame_number == 16000) av_log(enc, AV_LOG_INFO, "warning: Flash Player limit of 16000 frames reached\n"); - if (av_fifo_size(&swf->audio_fifo) + size > AUDIO_FIFO_SIZE) { + if (av_fifo_size(swf->audio_fifo) + size > AUDIO_FIFO_SIZE) { av_log(s, AV_LOG_ERROR, "audio fifo too small to mux audio essence\n"); return -1; } - av_fifo_generic_write(&swf->audio_fifo, buf, size, NULL); + av_fifo_generic_write(swf->audio_fifo, buf, size, NULL); swf->sound_samples += enc->frame_size; /* if audio only stream make sure we add swf frames */ @@ -481,7 +481,7 @@ if (enc->codec_type == CODEC_TYPE_VIDEO) video_enc = enc; else - av_fifo_free(&swf->audio_fifo); + av_fifo_free(swf->audio_fifo); } put_swf_tag(s, TAG_END);