mirror of
https://github.com/librempeg/librempeg
synced 2024-11-23 19:58:59 +00:00
avformat/rawvideodec: Rework packet size calculation
Calculate packet size only once, and propagate errors earlier in the chain. Also remove use of the deprecated av_image_get_buffer_size().
This commit is contained in:
parent
7c91b3021c
commit
e1a214cadf
@ -39,6 +39,7 @@ static int rawvideo_read_header(AVFormatContext *ctx)
|
|||||||
RawVideoDemuxerContext *s = ctx->priv_data;
|
RawVideoDemuxerContext *s = ctx->priv_data;
|
||||||
enum AVPixelFormat pix_fmt;
|
enum AVPixelFormat pix_fmt;
|
||||||
AVStream *st;
|
AVStream *st;
|
||||||
|
int packet_size;
|
||||||
|
|
||||||
st = avformat_new_stream(ctx, NULL);
|
st = avformat_new_stream(ctx, NULL);
|
||||||
if (!st)
|
if (!st)
|
||||||
@ -59,7 +60,11 @@ static int rawvideo_read_header(AVFormatContext *ctx)
|
|||||||
st->codec->width = s->width;
|
st->codec->width = s->width;
|
||||||
st->codec->height = s->height;
|
st->codec->height = s->height;
|
||||||
st->codec->pix_fmt = pix_fmt;
|
st->codec->pix_fmt = pix_fmt;
|
||||||
st->codec->bit_rate = av_rescale_q(avpicture_get_size(st->codec->pix_fmt, s->width, s->height),
|
packet_size = av_image_get_buffer_size(st->codec->pix_fmt, s->width, s->height, 1);
|
||||||
|
if (packet_size < 0)
|
||||||
|
return packet_size;
|
||||||
|
ctx->packet_size = packet_size;
|
||||||
|
st->codec->bit_rate = av_rescale_q(ctx->packet_size,
|
||||||
(AVRational){8,1}, st->time_base);
|
(AVRational){8,1}, st->time_base);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -68,18 +73,10 @@ static int rawvideo_read_header(AVFormatContext *ctx)
|
|||||||
|
|
||||||
static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
|
static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
|
||||||
{
|
{
|
||||||
int packet_size, ret, width, height;
|
int ret;
|
||||||
AVStream *st = s->streams[0];
|
|
||||||
|
|
||||||
width = st->codec->width;
|
ret = av_get_packet(s->pb, pkt, s->packet_size);
|
||||||
height = st->codec->height;
|
pkt->pts = pkt->dts = pkt->pos / s->packet_size;
|
||||||
|
|
||||||
packet_size = av_image_get_buffer_size(st->codec->pix_fmt, width, height, 1);
|
|
||||||
if (packet_size < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
ret = av_get_packet(s->pb, pkt, packet_size);
|
|
||||||
pkt->pts = pkt->dts = pkt->pos / packet_size;
|
|
||||||
|
|
||||||
pkt->stream_index = 0;
|
pkt->stream_index = 0;
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user