[FFmpeg-devel] [PATCH v1] lavc/libdavs2.c: optimize frame copy

mypopy at gmail.com mypopy at gmail.com
Wed Jul 3 09:38:38 EEST 2019


On Wed, Jul 3, 2019 at 11:24 AM hwrenx <hwrenx at 126.com> wrote:
>
> Signed-off-by: hwrenx <hwrenx at 126.com>
> ---
>  libavcodec/libdavs2.c | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/libavcodec/libdavs2.c b/libavcodec/libdavs2.c
> index 218f3ec..15ed3a1 100644
> --- a/libavcodec/libdavs2.c
> +++ b/libavcodec/libdavs2.c
> @@ -62,7 +62,7 @@ static int davs2_dump_frames(AVCodecContext *avctx, davs2_picture_t *pic, int *g
>                               davs2_seq_info_t *headerset, int ret_type, AVFrame *frame)
>  {
>      DAVS2Context *cad    = avctx->priv_data;
> -    int bytes_per_sample = pic->bytes_per_sample;
> +    int bytes_per_sample = pic->bytes_per_sample == 8 ? 1 : 2;
Looks like davs2 use a wrong name for bits per sample, I think need to
fix in davs2 first, it's better than the workaround in the wrapper.
>      int plane = 0;
>      int line  = 0;
>
> @@ -104,6 +104,7 @@ static int davs2_dump_frames(AVCodecContext *avctx, davs2_picture_t *pic, int *g
>
>      for (plane = 0; plane < 3; ++plane) {
>          int size_line = pic->widths[plane] * bytes_per_sample;
> +        void *dst, *src;
>          frame->buf[plane]  = av_buffer_alloc(size_line * pic->lines[plane]);
>
>          if (!frame->buf[plane]){
> @@ -114,10 +115,14 @@ static int davs2_dump_frames(AVCodecContext *avctx, davs2_picture_t *pic, int *g
>          frame->data[plane]     = frame->buf[plane]->data;
>          frame->linesize[plane] = size_line;
>
> -        for (line = 0; line < pic->lines[plane]; ++line)
> -            memcpy(frame->data[plane] + line * size_line,
> -                   pic->planes[plane] + line * pic->strides[plane],
> -                   pic->widths[plane] * bytes_per_sample);
> +        dst = frame->data[plane];
> +        src = pic->planes[plane];
> +
> +        for (line = 0; line < pic->lines[plane]; ++line) {
> +            memcpy(dst, src, size_line);
> +            dst += size_line;
> +            src += pic->strides[plane];
> +        }
>      }
>
>      frame->width     = cad->headerset.width;
> --
> 2.7.4
>


More information about the ffmpeg-devel mailing list