forked from FFmpeg/FFmpeg
cleaned up buffer management
Originally committed as revision 5522 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
42fb414804
commit
12a195e32f
1 changed files with 34 additions and 19 deletions
|
@ -193,8 +193,6 @@ ogg_new_stream (AVFormatContext * s, uint32_t serial)
|
||||||
os = ogg->streams + idx;
|
os = ogg->streams + idx;
|
||||||
os->serial = serial;
|
os->serial = serial;
|
||||||
os->bufsize = DECODER_BUFFER_SIZE;
|
os->bufsize = DECODER_BUFFER_SIZE;
|
||||||
os->buf = av_malloc (os->bufsize);
|
|
||||||
memset (os->buf, 0, os->bufsize);
|
|
||||||
os->header = -1;
|
os->header = -1;
|
||||||
|
|
||||||
st = av_new_stream (s, idx);
|
st = av_new_stream (s, idx);
|
||||||
|
@ -207,6 +205,23 @@ ogg_new_stream (AVFormatContext * s, uint32_t serial)
|
||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
ogg_new_buf(ogg_t *ogg, int idx)
|
||||||
|
{
|
||||||
|
ogg_stream_t *os = ogg->streams + idx;
|
||||||
|
u_char *nb = av_malloc(os->bufsize);
|
||||||
|
int size = os->bufpos - os->pstart;
|
||||||
|
if(os->buf){
|
||||||
|
memcpy(nb, os->buf + os->pstart, size);
|
||||||
|
av_free(os->buf);
|
||||||
|
}
|
||||||
|
os->buf = nb;
|
||||||
|
os->bufpos = size;
|
||||||
|
os->pstart = 0;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ogg_read_page (AVFormatContext * s, int *str)
|
ogg_read_page (AVFormatContext * s, int *str)
|
||||||
{
|
{
|
||||||
|
@ -264,6 +279,9 @@ ogg_read_page (AVFormatContext * s, int *str)
|
||||||
|
|
||||||
os = ogg->streams + idx;
|
os = ogg->streams + idx;
|
||||||
|
|
||||||
|
if(os->segp == os->nsegs)
|
||||||
|
ogg_new_buf(ogg, idx);
|
||||||
|
|
||||||
if (get_buffer (bc, os->segments, nsegs) < nsegs)
|
if (get_buffer (bc, os->segments, nsegs) < nsegs)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -310,7 +328,7 @@ ogg_read_page (AVFormatContext * s, int *str)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ogg_packet (AVFormatContext * s, int *str)
|
ogg_packet (AVFormatContext * s, int *str, int *dstart, int *dsize)
|
||||||
{
|
{
|
||||||
ogg_t *ogg = s->priv_data;
|
ogg_t *ogg = s->priv_data;
|
||||||
int idx;
|
int idx;
|
||||||
|
@ -363,14 +381,6 @@ ogg_packet (AVFormatContext * s, int *str)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!complete && os->segp == os->nsegs){
|
if (!complete && os->segp == os->nsegs){
|
||||||
uint8_t *nb = av_malloc (os->bufsize);
|
|
||||||
int size = os->bufpos - os->pstart;
|
|
||||||
memset (nb, 0, os->bufsize);
|
|
||||||
memcpy (nb, os->buf + os->pstart, size);
|
|
||||||
av_free (os->buf);
|
|
||||||
os->buf = nb;
|
|
||||||
os->bufpos = size;
|
|
||||||
os->pstart = 0;
|
|
||||||
ogg->curidx = -1;
|
ogg->curidx = -1;
|
||||||
}
|
}
|
||||||
}while (!complete);
|
}while (!complete);
|
||||||
|
@ -401,6 +411,12 @@ ogg_packet (AVFormatContext * s, int *str)
|
||||||
os->codec->packet (s, idx);
|
os->codec->packet (s, idx);
|
||||||
if (str)
|
if (str)
|
||||||
*str = idx;
|
*str = idx;
|
||||||
|
if (dstart)
|
||||||
|
*dstart = os->pstart;
|
||||||
|
if (dsize)
|
||||||
|
*dsize = os->psize;
|
||||||
|
os->pstart += os->psize;
|
||||||
|
os->psize = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
os->seq++;
|
os->seq++;
|
||||||
|
@ -416,7 +432,7 @@ ogg_get_headers (AVFormatContext * s)
|
||||||
ogg_t *ogg = s->priv_data;
|
ogg_t *ogg = s->priv_data;
|
||||||
|
|
||||||
do{
|
do{
|
||||||
if (ogg_packet (s, NULL) < 0)
|
if (ogg_packet (s, NULL, NULL, NULL) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
}while (!ogg->headers);
|
}while (!ogg->headers);
|
||||||
|
|
||||||
|
@ -507,10 +523,11 @@ ogg_read_packet (AVFormatContext * s, AVPacket * pkt)
|
||||||
ogg_t *ogg;
|
ogg_t *ogg;
|
||||||
ogg_stream_t *os;
|
ogg_stream_t *os;
|
||||||
int idx = -1;
|
int idx = -1;
|
||||||
|
int pstart, psize;
|
||||||
|
|
||||||
//Get an ogg packet
|
//Get an ogg packet
|
||||||
do{
|
do{
|
||||||
if (ogg_packet (s, &idx) < 0)
|
if (ogg_packet (s, &idx, &pstart, &psize) < 0)
|
||||||
return AVERROR_IO;
|
return AVERROR_IO;
|
||||||
}while (idx < 0 || !s->streams[idx]);
|
}while (idx < 0 || !s->streams[idx]);
|
||||||
|
|
||||||
|
@ -518,18 +535,16 @@ ogg_read_packet (AVFormatContext * s, AVPacket * pkt)
|
||||||
os = ogg->streams + idx;
|
os = ogg->streams + idx;
|
||||||
|
|
||||||
//Alloc a pkt
|
//Alloc a pkt
|
||||||
if (av_new_packet (pkt, os->psize) < 0)
|
if (av_new_packet (pkt, psize) < 0)
|
||||||
return AVERROR_IO;
|
return AVERROR_IO;
|
||||||
pkt->stream_index = idx;
|
pkt->stream_index = idx;
|
||||||
memcpy (pkt->data, os->buf + os->pstart, os->psize);
|
memcpy (pkt->data, os->buf + pstart, psize);
|
||||||
if (os->lastgp != -1LL){
|
if (os->lastgp != -1LL){
|
||||||
pkt->pts = ogg_gptopts (s, idx, os->lastgp);
|
pkt->pts = ogg_gptopts (s, idx, os->lastgp);
|
||||||
os->lastgp = -1;
|
os->lastgp = -1;
|
||||||
}
|
}
|
||||||
//next
|
|
||||||
os->pstart += os->psize;
|
return psize;
|
||||||
os->psize = 0;
|
|
||||||
return os->psize;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue