aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/rawvideodec.c
diff options
context:
space:
mode:
authorTimothy Gu <timothygu99@gmail.com>2015-11-20 21:15:08 -0800
committerTimothy Gu <timothygu99@gmail.com>2015-11-23 18:33:48 -0800
commite1a214cadf92af6e1f5614c4d801d63e462d8272 (patch)
tree02e5fe20d414dbf2aaf351ef5d48929251a8bda7 /libavformat/rawvideodec.c
parent7c91b3021c7af9bea6b65f51d645f7574a883870 (diff)
downloadffmpeg-e1a214cadf92af6e1f5614c4d801d63e462d8272.tar.gz
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().
Diffstat (limited to 'libavformat/rawvideodec.c')
-rw-r--r--libavformat/rawvideodec.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/libavformat/rawvideodec.c b/libavformat/rawvideodec.c
index 7f355eff5b..91bdba0e9a 100644
--- a/libavformat/rawvideodec.c
+++ b/libavformat/rawvideodec.c
@@ -39,6 +39,7 @@ static int rawvideo_read_header(AVFormatContext *ctx)
RawVideoDemuxerContext *s = ctx->priv_data;
enum AVPixelFormat pix_fmt;
AVStream *st;
+ int packet_size;
st = avformat_new_stream(ctx, NULL);
if (!st)
@@ -59,7 +60,11 @@ static int rawvideo_read_header(AVFormatContext *ctx)
st->codec->width = s->width;
st->codec->height = s->height;
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);
return 0;
@@ -68,18 +73,10 @@ static int rawvideo_read_header(AVFormatContext *ctx)
static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
{
- int packet_size, ret, width, height;
- AVStream *st = s->streams[0];
-
- width = st->codec->width;
- height = st->codec->height;
-
- packet_size = av_image_get_buffer_size(st->codec->pix_fmt, width, height, 1);
- if (packet_size < 0)
- return -1;
+ int ret;
- ret = av_get_packet(s->pb, pkt, packet_size);
- pkt->pts = pkt->dts = pkt->pos / packet_size;
+ ret = av_get_packet(s->pb, pkt, s->packet_size);
+ pkt->pts = pkt->dts = pkt->pos / s->packet_size;
pkt->stream_index = 0;
if (ret < 0)