Commit bc0ad0fd authored by michael's avatar michael

Ensure that one can store X bytes in a fifo of size X.

Fixed issue417.


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@13405 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent 80f077ba
...@@ -587,7 +587,7 @@ static void do_audio_out(AVFormatContext *s, ...@@ -587,7 +587,7 @@ static void do_audio_out(AVFormatContext *s,
/* now encode as many frames as possible */ /* now encode as many frames as possible */
if (enc->frame_size > 1) { if (enc->frame_size > 1) {
/* output resampled raw samples */ /* output resampled raw samples */
av_fifo_realloc(&ost->fifo, av_fifo_size(&ost->fifo) + size_out + 1); av_fifo_realloc(&ost->fifo, av_fifo_size(&ost->fifo) + size_out);
av_fifo_write(&ost->fifo, buftmp, size_out); av_fifo_write(&ost->fifo, buftmp, size_out);
frame_bytes = enc->frame_size * 2 * enc->channels; frame_bytes = enc->frame_size * 2 * enc->channels;
......
...@@ -1170,7 +1170,7 @@ static int mpeg_mux_write_packet(AVFormatContext *ctx, AVPacket *pkt) ...@@ -1170,7 +1170,7 @@ static int mpeg_mux_write_packet(AVFormatContext *ctx, AVPacket *pkt)
stream->predecode_packet= pkt_desc; stream->predecode_packet= pkt_desc;
stream->next_packet= &pkt_desc->next; stream->next_packet= &pkt_desc->next;
av_fifo_realloc(&stream->fifo, av_fifo_size(&stream->fifo) + size + 1); av_fifo_realloc(&stream->fifo, av_fifo_size(&stream->fifo) + size);
if (s->is_dvd){ if (s->is_dvd){
if (is_iframe && (s->packet_number == 0 || (pts - stream->vobu_start_pts >= 36000))) { // min VOBU length 0.4 seconds (mpucoder) if (is_iframe && (s->packet_number == 0 || (pts - stream->vobu_start_pts >= 36000))) { // min VOBU length 0.4 seconds (mpucoder)
......
...@@ -22,8 +22,9 @@ ...@@ -22,8 +22,9 @@
#include "common.h" #include "common.h"
#include "fifo.h" #include "fifo.h"
int av_fifo_init(AVFifoBuffer *f, int size) int av_fifo_init(AVFifoBuffer *f, unsigned int size)
{ {
size= FFMAX(size, size+1);
f->wptr = f->rptr = f->wptr = f->rptr =
f->buffer = av_malloc(size); f->buffer = av_malloc(size);
f->end = f->buffer + size; f->end = f->buffer + size;
...@@ -56,7 +57,7 @@ int av_fifo_read(AVFifoBuffer *f, uint8_t *buf, int buf_size) ...@@ -56,7 +57,7 @@ int av_fifo_read(AVFifoBuffer *f, uint8_t *buf, int buf_size)
void av_fifo_realloc(AVFifoBuffer *f, unsigned int new_size) { void av_fifo_realloc(AVFifoBuffer *f, unsigned int new_size) {
unsigned int old_size= f->end - f->buffer; unsigned int old_size= f->end - f->buffer;
if(old_size < new_size){ if(old_size <= new_size){
int len= av_fifo_size(f); int len= av_fifo_size(f);
AVFifoBuffer f2; AVFifoBuffer f2;
......
...@@ -38,7 +38,7 @@ typedef struct AVFifoBuffer { ...@@ -38,7 +38,7 @@ typedef struct AVFifoBuffer {
* @param size of FIFO * @param size of FIFO
* @return <0 for failure >=0 otherwise * @return <0 for failure >=0 otherwise
*/ */
int av_fifo_init(AVFifoBuffer *f, int size); int av_fifo_init(AVFifoBuffer *f, unsigned int size);
/** /**
* Frees an AVFifoBuffer. * Frees an AVFifoBuffer.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment