Message ID | 20200814140244.2292-1-jamrial@gmail.com |
---|---|
State | Accepted |
Commit | a72d5290c5b70780fe7132c68498c0aa1456908f |
Headers | show |
Series | [FFmpeg-devel] avformat/av1dec: inline obu_read_data() and obu_prefetch() into obu_get_packet() | expand |
Context | Check | Description |
---|---|---|
andriy/default | pending | |
andriy/make | success | Make finished |
andriy/make_fate | success | Make fate finished |
On Fri, Aug 14, 2020 at 10:30 PM James Almer <jamrial@gmail.com> wrote: > They don't really help making the demuxer more readable. > > Signed-off-by: James Almer <jamrial@gmail.com> > --- > libavformat/av1dec.c | 56 +++++++++++++++++--------------------------- > 1 file changed, 21 insertions(+), 35 deletions(-) > Good improvment, LGTM > > diff --git a/libavformat/av1dec.c b/libavformat/av1dec.c > index 0693e40ac1..c06f5303f5 100644 > --- a/libavformat/av1dec.c > +++ b/libavformat/av1dec.c > @@ -382,60 +382,46 @@ static int obu_read_header(AVFormatContext *s) > return read_header(s, &c->framerate, &c->bsf, c); > } > > -static int obu_prefetch(AVFormatContext *s, uint8_t* dest) > +static int obu_get_packet(AVFormatContext *s, AVPacket *pkt) > { > ObuContext *c = s->priv_data; > + uint8_t header[MAX_OBU_HEADER_SIZE]; > + int64_t obu_size; > int size = av_fifo_space(c->fifo); > + int ret, len, type; > + > av_fifo_generic_write(c->fifo, s->pb, size, > (int (*)(void*, void*, int))avio_read); > size = av_fifo_size(c->fifo); > - if (size > 0) { > - av_fifo_generic_peek(c->fifo, dest, size, NULL); > + if (!size) > + return 0; > + > + av_fifo_generic_peek(c->fifo, header, size, NULL); > + > + len = read_obu_with_size(header, size, &obu_size, &type); > + if (len < 0) { > + av_log(c, AV_LOG_ERROR, "Failed to read obu\n"); > + return len; > } > - return size; > -} > > -static int obu_read_data(AVFormatContext *s, AVPacket *pkt, int len) > -{ > - int size, left; > - ObuContext *c = s->priv_data; > - int ret = av_new_packet(pkt, len); > + ret = av_new_packet(pkt, len); > if (ret < 0) { > av_log(c, AV_LOG_ERROR, "Failed to allocate packet for obu\n"); > return ret; > } > - size = FFMIN(av_fifo_size(c->fifo), len); > + size = FFMIN(size, len); > av_fifo_generic_read(c->fifo, pkt->data, size, NULL); > - left = len - size; > - if (left > 0) { > - ret = avio_read(s->pb, pkt->data + size, left); > - if (ret != left) { > - av_log(c, AV_LOG_ERROR, "Failed to read %d frome file\n", > left); > + len -= size; > + if (len > 0) { > + ret = avio_read(s->pb, pkt->data + size, len); > + if (ret != len) { > + av_log(c, AV_LOG_ERROR, "Failed to read %d frome file\n", > len); > return ret < 0 ? ret : AVERROR_INVALIDDATA; > } > } > return 0; > } > > -static int obu_get_packet(AVFormatContext *s, AVPacket *pkt) > -{ > - ObuContext *c = s->priv_data; > - int64_t obu_size; > - int ret, type; > - uint8_t header[MAX_OBU_HEADER_SIZE]; > - > - ret = obu_prefetch(s, header); > - if (!ret) > - return 0; > - > - ret = read_obu_with_size(header, ret, &obu_size, &type); > - if (ret < 0) { > - av_log(c, AV_LOG_ERROR, "Failed to read obu\n"); > - return ret; > - } > - return obu_read_data(s, pkt, ret); > -} > - > static int obu_read_packet(AVFormatContext *s, AVPacket *pkt) > { > ObuContext *c = s->priv_data; > -- > 2.27.0 > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
On 8/15/2020 12:39 PM, Guangxin Xu wrote: > On Fri, Aug 14, 2020 at 10:30 PM James Almer <jamrial@gmail.com> wrote: > >> They don't really help making the demuxer more readable. >> >> Signed-off-by: James Almer <jamrial@gmail.com> >> --- >> libavformat/av1dec.c | 56 +++++++++++++++++--------------------------- >> 1 file changed, 21 insertions(+), 35 deletions(-) >> > Good improvment, > LGTM Applied. Thanks.
diff --git a/libavformat/av1dec.c b/libavformat/av1dec.c index 0693e40ac1..c06f5303f5 100644 --- a/libavformat/av1dec.c +++ b/libavformat/av1dec.c @@ -382,60 +382,46 @@ static int obu_read_header(AVFormatContext *s) return read_header(s, &c->framerate, &c->bsf, c); } -static int obu_prefetch(AVFormatContext *s, uint8_t* dest) +static int obu_get_packet(AVFormatContext *s, AVPacket *pkt) { ObuContext *c = s->priv_data; + uint8_t header[MAX_OBU_HEADER_SIZE]; + int64_t obu_size; int size = av_fifo_space(c->fifo); + int ret, len, type; + av_fifo_generic_write(c->fifo, s->pb, size, (int (*)(void*, void*, int))avio_read); size = av_fifo_size(c->fifo); - if (size > 0) { - av_fifo_generic_peek(c->fifo, dest, size, NULL); + if (!size) + return 0; + + av_fifo_generic_peek(c->fifo, header, size, NULL); + + len = read_obu_with_size(header, size, &obu_size, &type); + if (len < 0) { + av_log(c, AV_LOG_ERROR, "Failed to read obu\n"); + return len; } - return size; -} -static int obu_read_data(AVFormatContext *s, AVPacket *pkt, int len) -{ - int size, left; - ObuContext *c = s->priv_data; - int ret = av_new_packet(pkt, len); + ret = av_new_packet(pkt, len); if (ret < 0) { av_log(c, AV_LOG_ERROR, "Failed to allocate packet for obu\n"); return ret; } - size = FFMIN(av_fifo_size(c->fifo), len); + size = FFMIN(size, len); av_fifo_generic_read(c->fifo, pkt->data, size, NULL); - left = len - size; - if (left > 0) { - ret = avio_read(s->pb, pkt->data + size, left); - if (ret != left) { - av_log(c, AV_LOG_ERROR, "Failed to read %d frome file\n", left); + len -= size; + if (len > 0) { + ret = avio_read(s->pb, pkt->data + size, len); + if (ret != len) { + av_log(c, AV_LOG_ERROR, "Failed to read %d frome file\n", len); return ret < 0 ? ret : AVERROR_INVALIDDATA; } } return 0; } -static int obu_get_packet(AVFormatContext *s, AVPacket *pkt) -{ - ObuContext *c = s->priv_data; - int64_t obu_size; - int ret, type; - uint8_t header[MAX_OBU_HEADER_SIZE]; - - ret = obu_prefetch(s, header); - if (!ret) - return 0; - - ret = read_obu_with_size(header, ret, &obu_size, &type); - if (ret < 0) { - av_log(c, AV_LOG_ERROR, "Failed to read obu\n"); - return ret; - } - return obu_read_data(s, pkt, ret); -} - static int obu_read_packet(AVFormatContext *s, AVPacket *pkt) { ObuContext *c = s->priv_data;
They don't really help making the demuxer more readable. Signed-off-by: James Almer <jamrial@gmail.com> --- libavformat/av1dec.c | 56 +++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 35 deletions(-)