Re: [FFmpeg-devel] [PATCH] ffmpeg_qsv: use -hwaccel_device to specify a device for VAAPI backend

2020-09-03 Thread Rogozhkin, Dmitry V
On Thu, 2020-09-03 at 12:59 +0800, myp...@gmail.com wrote:
> On Thu, Sep 3, 2020 at 9:21 AM Xiang, Haihao 
> wrote:
> > 
> > On Wed, 2020-09-02 at 14:04 +, Soft Works wrote:
> > > > -Original Message-
> > > > From: ffmpeg-devel  On Behalf
> > > > Of
> > > > Rogozhkin, Dmitry V
> > > > Sent: Wednesday, September 2, 2020 3:54 PM
> > > > To: ffmpeg-devel@ffmpeg.org
> > > > Subject: Re: [FFmpeg-devel] [PATCH] ffmpeg_qsv: use
> > > > -hwaccel_device to
> > > > specify a device for VAAPI backend
> > > > 
> > > > On Wed, 2020-09-02 at 07:31 +, Soft Works wrote:
> > > > > > -Original Message-
> > > > > > From: ffmpeg-devel  On
> > > > > > Behalf Of
> > > > > > Rogozhkin, Dmitry V
> > > > > > Sent: Wednesday, September 2, 2020 9:00 AM
> > > > > > To: ffmpeg-devel@ffmpeg.org
> > > > > > Subject: Re: [FFmpeg-devel] [PATCH] ffmpeg_qsv: use
> > > > > > -hwaccel_device
> > > > > > to specify a device for VAAPI backend
> > > > > > 
> > > > > > On Wed, 2020-09-02 at 04:28 +, Xiang, Haihao wrote:
> > > > > > > On Wed, 2020-09-02 at 04:20 +, Soft Works wrote:
> > > > > > > > > -Original Message-
> > > > > > > > > From: ffmpeg-devel 
> > > > > > > > > On
> > > > 
> > > > Behalf
> > > > > > 
> > > > > > Of
> > > > > > > > > Haihao Xiang
> > > > > > > > > Sent: Wednesday, September 2, 2020 6:01 AM
> > > > > > > > > To: ffmpeg-devel@ffmpeg.org
> > > > > > > > > Cc: Haihao Xiang 
> > > > > > > > > Subject: [FFmpeg-devel] [PATCH] ffmpeg_qsv: use
> > > > > > > > > -hwaccel_device to specify a device for VAAPI backend
> > > > > > > > > 
> > > > > > > > > According to the FFmpeg documentation,
> > > > > > > > > -hwaccel_device can be
> > > > > > > > > used to select a device for hardware acceleration
> > > > > > > > > 
> > > > > > > > > Example:
> > > > > > > > > ffmpeg -hwaccel qsv -hwaccel_device
> > > > > > > > > /dev/dri/renderD129 -c:v
> > > > > > > > > h264_qsv \ -i
> > > > > > > > > in.h264 -c:v hevc_qsv out.h265
> > > > > > > > 
> > > > > > > > No. The docs say about hwaccel_device
> > > > > > > > 
> > > > > > > > It can either refer to an existing device created with
> > > > > > > > -init_hw_device by name,
> > > > > > > > 
> > > > > > > > => /dev/dri/renderD129 is not an existing device name
> > > > > > > > 
> > > > > > > > or it can create a new device as if ‘-init_hw_device’
> > > > > > > > type:hwaccel_device were called immediately before.
> > > > > > > > 
> > > > > > > > => /dev/dri/renderD129 is not a valid string for
> > > > > > > > init_hw_device
> > > > > > 
> > > > > > Well, it seems that's where documentation does not reflect
> > > > > > the
> > > > > > reality since (as pointed by Haihao below)
> > > > > > https://trac.ffmpeg.org/wiki/Hardware/VAAPI
> > > > > > is full of contradictory examples.
> > > > > > 
> > > > > > > > 
> > > > > > > > 
> > > > > > > > Hence, the patch doesn't make sense.
> > > > > > > 
> > > > > > > in https://trac.ffmpeg.org/wiki/Hardware/VAAPI,
> > > > > > > 
> > > > > > > If only one stream is being used, -hwaccel_device can
> > > > > > > also accept
> > > > > > > a device path directly
> > > > > > > 
> > > > > > > ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128
> > > > > > > -i ...
> > > > > > > 
> > > > > > > I think it can be applied to qsv too.
> > > > > > > 
> > > > > > 
> > > > > > I agree. Part of ffmpeg help:
> > > > > > -hwaccel hwaccel name  use HW accelerated decoding
> > > > > > -hwaccel_device devicename  select a device for HW
> > > > > > acceleration
> > > > > > 
> > > > > > To me specifying device via -hwaccel_device in the way it
> > > > > > is being
> > > > > > suggest in commit is pretty intuitive and is better than
> > > > > > explain
> > > > > > people that there is - qsv_device for that purpose.
> > > > > > Niceness of
> > > > > > -hwaccel_device is that it is not tight to particular
> > > > > > acceleration,
> > > > > > hence easier to work with for end users.
> > > > > 
> > > > > In case of QSV, the usage of hwaccel_device is already
> > > > > defined:
> > > > > 
> > > > > device selects a value in ‘MFX_IMPL_*’. Allowed values are:
> > > > > auto sw  hw  auto_any hw_any hw2 hw3 hw4
> > > > > 
> > > > > I agree that it would be more intuitive, but you can't just
> > > > > give it a
> > > > > different meaning from one day to another and break
> > > > > functionality.
> > > > 
> > > > Adding new values does not break functionality! No
> > > > one  suggests to drop
> > > > existing set of values (sw, hw, etc.) - these are remaining.
> > > > But basically
> > > > suggestion is to extend allowed set to accept drm device
> > > > specification on
> > > > Linux, that's it. Honestly, I don't see problem here.
> > > > Some background story: hw,hw2,hw3 allows to select adapter for
> > > > msdk
> > > > library on Windows, but they don't allow to do that on Linux.
> > > > On Linux all
> > > > these hw options are basically the same for the reason that
> > > > device is being
> > > > specified externally via SetHandle 

Re: [FFmpeg-devel] [PATCH 3/5] avcodec: add MobiClip video decoder

2020-09-03 Thread Paul B Mahol
On 9/1/20, Paul B Mahol  wrote:
> Signed-off-by: Paul B Mahol 
> ---
>  libavcodec/Makefile |1 +
>  libavcodec/allcodecs.c  |1 +
>  libavcodec/codec_desc.c |7 +
>  libavcodec/codec_id.h   |1 +
>  libavcodec/mobiclip.c   | 1427 +++
>  5 files changed, 1437 insertions(+)
>  create mode 100644 libavcodec/mobiclip.c

Gonna apply this patch set.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 4/5] avformat: add moflex demuxer

2020-09-03 Thread Andreas Rheinhardt
Paul B Mahol:
> Signed-off-by: Paul B Mahol 
> ---
>  libavformat/Makefile |   1 +
>  libavformat/allformats.c |   1 +
>  libavformat/moflex.c | 360 +++
>  3 files changed, 362 insertions(+)
>  create mode 100644 libavformat/moflex.c
> 
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index cbb33fe37c..1e0ac317e5 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -319,6 +319,7 @@ OBJS-$(CONFIG_MLV_DEMUXER)   += mlvdec.o 
> riffdec.o
>  OBJS-$(CONFIG_MM_DEMUXER)+= mm.o
>  OBJS-$(CONFIG_MMF_DEMUXER)   += mmf.o
>  OBJS-$(CONFIG_MMF_MUXER) += mmf.o rawenc.o
> +OBJS-$(CONFIG_MOFLEX_DEMUXER)+= moflex.o
>  OBJS-$(CONFIG_MOV_DEMUXER)   += mov.o mov_chan.o mov_esds.o 
> replaygain.o
>  OBJS-$(CONFIG_MOV_MUXER) += movenc.o av1.o avc.o hevc.o 
> vpcc.o \
>  movenchint.o mov_chan.o rtp.o \
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index 0aa9dd7198..28331facb9 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -249,6 +249,7 @@ extern AVInputFormat  ff_mlv_demuxer;
>  extern AVInputFormat  ff_mm_demuxer;
>  extern AVInputFormat  ff_mmf_demuxer;
>  extern AVOutputFormat ff_mmf_muxer;
> +extern AVInputFormat  ff_moflex_demuxer;
>  extern AVInputFormat  ff_mov_demuxer;
>  extern AVOutputFormat ff_mov_muxer;
>  extern AVOutputFormat ff_mp2_muxer;
> diff --git a/libavformat/moflex.c b/libavformat/moflex.c
> new file mode 100644
> index 00..989623396f
> --- /dev/null
> +++ b/libavformat/moflex.c
> @@ -0,0 +1,360 @@
> +/*
> + * MOFLEX demuxer
> + * Copyright (c) 2020 Paul B Mahol
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
> + */
> +
> +#include "libavcodec/bytestream.h"
> +
> +#include "avformat.h"
> +#include "internal.h"
> +
> +typedef struct BitReader {
> +unsigned last;
> +unsigned pos;
> +} BitReader;
> +
> +typedef struct MOFLEXDemuxContext {
> +unsigned size;
> +int64_t pos;
> +int64_t ts;
> +int flags;
> +int in_block;
> +
> +BitReader br;
> +} MOFLEXDemuxContext;
> +
> +static int pop(BitReader *br, AVIOContext *pb)
> +{
> +if (avio_feof(pb))
> +return AVERROR_EOF;
> +
> +if ((br->pos & 7) == 0)
> +br->last = (unsigned)avio_r8(pb) << 24U;
> +else
> +br->last <<= 1;
> +
> +br->pos++;
> +return !!(br->last & 0x8000);
> +}
> +
> +static int pop_int(BitReader *br, AVIOContext *pb, int n)
> +{
> +int value = 0;
> +
> +for (int i = 0; i < n; i++) {
> +int ret = pop(br, pb);
> +
> +if (ret < 0)
> +return ret;
> +value = 2 * value + ret;
> +}
> +
> +return value;
> +}
> +
> +static int pop_length(BitReader *br, AVIOContext *pb)
> +{
> +int ret, n = 1;
> +
> +while ((ret = pop(br, pb)) == 0)
> +n++;
> +
> +if (ret < 0)
> +return ret;
> +return n;
> +}
> +
> +static int read_var_byte(AVFormatContext *s, unsigned *out)
> +{
> +AVIOContext *pb = s->pb;
> +unsigned value = 0, data;
> +
> +data = avio_r8(pb);
> +if (!(data & 0x80)) {
> +*out = data;
> +return 0;
> +}
> +
> +value = (data & 0x7F) << 7;
> +data = avio_r8(pb);
> +if (!(data & 0x80)) {
> +value |= data;
> +*out = value;
> +return 0;
> +}
> +
> +value = ((data & 0x7F) | value) << 7;
> +data = avio_r8(pb);
> +if (!(data & 0x80)) {
> +value |= data;
> +*out = value;
> +return 0;
> +}
> +
> +value = (((data & 0x7F) | value) << 7) | avio_r8(pb);
> +*out = value;
> +
> +return 0;
> +}
> +
> +static int moflex_probe(const AVProbeData *p)
> +{
> +GetByteContext gb;
> +int score = 0;
> +
> +bytestream2_init(&gb, p->buf, p->buf_size);
> +
> +if (bytestream2_get_be16(&gb) != 0x4C32)
> +return 0;
> +score += 10;
> +
> +bytestream2_skip(&gb, 10);
> +if (bytestream2_get_be16(&gb) == 0)
> +return 0;
> +score += 5;
> +
> +while (bytestream2_get_bytes_left(&gb) > 0) {
> +int type = bytestream2_get_byte(&gb);
> + 

Re: [FFmpeg-devel] [PATCH 4/5] avformat: add moflex demuxer

2020-09-03 Thread Paul B Mahol
On 9/3/20, Andreas Rheinhardt  wrote:
> Paul B Mahol:
>> Signed-off-by: Paul B Mahol 
>> ---
>>  libavformat/Makefile |   1 +
>>  libavformat/allformats.c |   1 +
>>  libavformat/moflex.c | 360 +++
>>  3 files changed, 362 insertions(+)
>>  create mode 100644 libavformat/moflex.c
>>
>> diff --git a/libavformat/Makefile b/libavformat/Makefile
>> index cbb33fe37c..1e0ac317e5 100644
>> --- a/libavformat/Makefile
>> +++ b/libavformat/Makefile
>> @@ -319,6 +319,7 @@ OBJS-$(CONFIG_MLV_DEMUXER)   += mlvdec.o
>> riffdec.o
>>  OBJS-$(CONFIG_MM_DEMUXER)+= mm.o
>>  OBJS-$(CONFIG_MMF_DEMUXER)   += mmf.o
>>  OBJS-$(CONFIG_MMF_MUXER) += mmf.o rawenc.o
>> +OBJS-$(CONFIG_MOFLEX_DEMUXER)+= moflex.o
>>  OBJS-$(CONFIG_MOV_DEMUXER)   += mov.o mov_chan.o mov_esds.o
>> replaygain.o
>>  OBJS-$(CONFIG_MOV_MUXER) += movenc.o av1.o avc.o hevc.o
>> vpcc.o \
>>  movenchint.o mov_chan.o rtp.o
>> \
>> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
>> index 0aa9dd7198..28331facb9 100644
>> --- a/libavformat/allformats.c
>> +++ b/libavformat/allformats.c
>> @@ -249,6 +249,7 @@ extern AVInputFormat  ff_mlv_demuxer;
>>  extern AVInputFormat  ff_mm_demuxer;
>>  extern AVInputFormat  ff_mmf_demuxer;
>>  extern AVOutputFormat ff_mmf_muxer;
>> +extern AVInputFormat  ff_moflex_demuxer;
>>  extern AVInputFormat  ff_mov_demuxer;
>>  extern AVOutputFormat ff_mov_muxer;
>>  extern AVOutputFormat ff_mp2_muxer;
>> diff --git a/libavformat/moflex.c b/libavformat/moflex.c
>> new file mode 100644
>> index 00..989623396f
>> --- /dev/null
>> +++ b/libavformat/moflex.c
>> @@ -0,0 +1,360 @@
>> +/*
>> + * MOFLEX demuxer
>> + * Copyright (c) 2020 Paul B Mahol
>> + *
>> + * This file is part of FFmpeg.
>> + *
>> + * FFmpeg is free software; you can redistribute it and/or
>> + * modify it under the terms of the GNU Lesser General Public
>> + * License as published by the Free Software Foundation; either
>> + * version 2.1 of the License, or (at your option) any later version.
>> + *
>> + * FFmpeg is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>> + * Lesser General Public License for more details.
>> + *
>> + * You should have received a copy of the GNU Lesser General Public
>> + * License along with FFmpeg; if not, write to the Free Software
>> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
>> 02110-1301 USA
>> + */
>> +
>> +#include "libavcodec/bytestream.h"
>> +
>> +#include "avformat.h"
>> +#include "internal.h"
>> +
>> +typedef struct BitReader {
>> +unsigned last;
>> +unsigned pos;
>> +} BitReader;
>> +
>> +typedef struct MOFLEXDemuxContext {
>> +unsigned size;
>> +int64_t pos;
>> +int64_t ts;
>> +int flags;
>> +int in_block;
>> +
>> +BitReader br;
>> +} MOFLEXDemuxContext;
>> +
>> +static int pop(BitReader *br, AVIOContext *pb)
>> +{
>> +if (avio_feof(pb))
>> +return AVERROR_EOF;
>> +
>> +if ((br->pos & 7) == 0)
>> +br->last = (unsigned)avio_r8(pb) << 24U;
>> +else
>> +br->last <<= 1;
>> +
>> +br->pos++;
>> +return !!(br->last & 0x8000);
>> +}
>> +
>> +static int pop_int(BitReader *br, AVIOContext *pb, int n)
>> +{
>> +int value = 0;
>> +
>> +for (int i = 0; i < n; i++) {
>> +int ret = pop(br, pb);
>> +
>> +if (ret < 0)
>> +return ret;
>> +value = 2 * value + ret;
>> +}
>> +
>> +return value;
>> +}
>> +
>> +static int pop_length(BitReader *br, AVIOContext *pb)
>> +{
>> +int ret, n = 1;
>> +
>> +while ((ret = pop(br, pb)) == 0)
>> +n++;
>> +
>> +if (ret < 0)
>> +return ret;
>> +return n;
>> +}
>> +
>> +static int read_var_byte(AVFormatContext *s, unsigned *out)
>> +{
>> +AVIOContext *pb = s->pb;
>> +unsigned value = 0, data;
>> +
>> +data = avio_r8(pb);
>> +if (!(data & 0x80)) {
>> +*out = data;
>> +return 0;
>> +}
>> +
>> +value = (data & 0x7F) << 7;
>> +data = avio_r8(pb);
>> +if (!(data & 0x80)) {
>> +value |= data;
>> +*out = value;
>> +return 0;
>> +}
>> +
>> +value = ((data & 0x7F) | value) << 7;
>> +data = avio_r8(pb);
>> +if (!(data & 0x80)) {
>> +value |= data;
>> +*out = value;
>> +return 0;
>> +}
>> +
>> +value = (((data & 0x7F) | value) << 7) | avio_r8(pb);
>> +*out = value;
>> +
>> +return 0;
>> +}
>> +
>> +static int moflex_probe(const AVProbeData *p)
>> +{
>> +GetByteContext gb;
>> +int score = 0;
>> +
>> +bytestream2_init(&gb, p->buf, p->buf_size);
>> +
>> +if (bytestream2_get_be16(&gb) != 0x4C32)
>> +return 0;
>> +score += 10;
>> +
>> +bytestream2_skip(

Re: [FFmpeg-devel] [PATCH 4/5] avformat: add moflex demuxer

2020-09-03 Thread Andreas Rheinhardt
Paul B Mahol:
> On 9/3/20, Andreas Rheinhardt  wrote:
>> Paul B Mahol:
>>> Signed-off-by: Paul B Mahol 
>>> ---
>>>  libavformat/Makefile |   1 +
>>>  libavformat/allformats.c |   1 +
>>>  libavformat/moflex.c | 360 +++
>>>  3 files changed, 362 insertions(+)
>>>  create mode 100644 libavformat/moflex.c
>>>
>>> diff --git a/libavformat/Makefile b/libavformat/Makefile
>>> index cbb33fe37c..1e0ac317e5 100644
>>> --- a/libavformat/Makefile
>>> +++ b/libavformat/Makefile
>>> @@ -319,6 +319,7 @@ OBJS-$(CONFIG_MLV_DEMUXER)   += mlvdec.o
>>> riffdec.o
>>>  OBJS-$(CONFIG_MM_DEMUXER)+= mm.o
>>>  OBJS-$(CONFIG_MMF_DEMUXER)   += mmf.o
>>>  OBJS-$(CONFIG_MMF_MUXER) += mmf.o rawenc.o
>>> +OBJS-$(CONFIG_MOFLEX_DEMUXER)+= moflex.o
>>>  OBJS-$(CONFIG_MOV_DEMUXER)   += mov.o mov_chan.o mov_esds.o
>>> replaygain.o
>>>  OBJS-$(CONFIG_MOV_MUXER) += movenc.o av1.o avc.o hevc.o
>>> vpcc.o \
>>>  movenchint.o mov_chan.o rtp.o
>>> \
>>> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
>>> index 0aa9dd7198..28331facb9 100644
>>> --- a/libavformat/allformats.c
>>> +++ b/libavformat/allformats.c
>>> @@ -249,6 +249,7 @@ extern AVInputFormat  ff_mlv_demuxer;
>>>  extern AVInputFormat  ff_mm_demuxer;
>>>  extern AVInputFormat  ff_mmf_demuxer;
>>>  extern AVOutputFormat ff_mmf_muxer;
>>> +extern AVInputFormat  ff_moflex_demuxer;
>>>  extern AVInputFormat  ff_mov_demuxer;
>>>  extern AVOutputFormat ff_mov_muxer;
>>>  extern AVOutputFormat ff_mp2_muxer;
>>> diff --git a/libavformat/moflex.c b/libavformat/moflex.c
>>> new file mode 100644
>>> index 00..989623396f
>>> --- /dev/null
>>> +++ b/libavformat/moflex.c
>>> @@ -0,0 +1,360 @@
>>> +/*
>>> + * MOFLEX demuxer
>>> + * Copyright (c) 2020 Paul B Mahol
>>> + *
>>> + * This file is part of FFmpeg.
>>> + *
>>> + * FFmpeg is free software; you can redistribute it and/or
>>> + * modify it under the terms of the GNU Lesser General Public
>>> + * License as published by the Free Software Foundation; either
>>> + * version 2.1 of the License, or (at your option) any later version.
>>> + *
>>> + * FFmpeg is distributed in the hope that it will be useful,
>>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>>> + * Lesser General Public License for more details.
>>> + *
>>> + * You should have received a copy of the GNU Lesser General Public
>>> + * License along with FFmpeg; if not, write to the Free Software
>>> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
>>> 02110-1301 USA
>>> + */
>>> +
>>> +#include "libavcodec/bytestream.h"
>>> +
>>> +#include "avformat.h"
>>> +#include "internal.h"
>>> +
>>> +typedef struct BitReader {
>>> +unsigned last;
>>> +unsigned pos;
>>> +} BitReader;
>>> +
>>> +typedef struct MOFLEXDemuxContext {
>>> +unsigned size;
>>> +int64_t pos;
>>> +int64_t ts;
>>> +int flags;
>>> +int in_block;
>>> +
>>> +BitReader br;
>>> +} MOFLEXDemuxContext;
>>> +
>>> +static int pop(BitReader *br, AVIOContext *pb)
>>> +{
>>> +if (avio_feof(pb))
>>> +return AVERROR_EOF;
>>> +
>>> +if ((br->pos & 7) == 0)
>>> +br->last = (unsigned)avio_r8(pb) << 24U;
>>> +else
>>> +br->last <<= 1;
>>> +
>>> +br->pos++;
>>> +return !!(br->last & 0x8000);
>>> +}
>>> +
>>> +static int pop_int(BitReader *br, AVIOContext *pb, int n)
>>> +{
>>> +int value = 0;
>>> +
>>> +for (int i = 0; i < n; i++) {
>>> +int ret = pop(br, pb);
>>> +
>>> +if (ret < 0)
>>> +return ret;
>>> +value = 2 * value + ret;
>>> +}
>>> +
>>> +return value;
>>> +}
>>> +
>>> +static int pop_length(BitReader *br, AVIOContext *pb)
>>> +{
>>> +int ret, n = 1;
>>> +
>>> +while ((ret = pop(br, pb)) == 0)
>>> +n++;
>>> +
>>> +if (ret < 0)
>>> +return ret;
>>> +return n;
>>> +}
>>> +
>>> +static int read_var_byte(AVFormatContext *s, unsigned *out)
>>> +{
>>> +AVIOContext *pb = s->pb;
>>> +unsigned value = 0, data;
>>> +
>>> +data = avio_r8(pb);
>>> +if (!(data & 0x80)) {
>>> +*out = data;
>>> +return 0;
>>> +}
>>> +
>>> +value = (data & 0x7F) << 7;
>>> +data = avio_r8(pb);
>>> +if (!(data & 0x80)) {
>>> +value |= data;
>>> +*out = value;
>>> +return 0;
>>> +}
>>> +
>>> +value = ((data & 0x7F) | value) << 7;
>>> +data = avio_r8(pb);
>>> +if (!(data & 0x80)) {
>>> +value |= data;
>>> +*out = value;
>>> +return 0;
>>> +}
>>> +
>>> +value = (((data & 0x7F) | value) << 7) | avio_r8(pb);
>>> +*out = value;
>>> +
>>> +return 0;
>>> +}
>>> +
>>> +static int moflex_probe(const AVProbeData *p)
>>> +{
>>> +GetByteContext gb;
>>> +int score = 0;
>>> +

Re: [FFmpeg-devel] [PATCH 4/5] avformat: add moflex demuxer

2020-09-03 Thread Paul B Mahol
On 9/3/20, Andreas Rheinhardt  wrote:
> Paul B Mahol:
>> On 9/3/20, Andreas Rheinhardt  wrote:
>>> Paul B Mahol:
 Signed-off-by: Paul B Mahol 
 ---
  libavformat/Makefile |   1 +
  libavformat/allformats.c |   1 +
  libavformat/moflex.c | 360 +++
  3 files changed, 362 insertions(+)
  create mode 100644 libavformat/moflex.c

 diff --git a/libavformat/Makefile b/libavformat/Makefile
 index cbb33fe37c..1e0ac317e5 100644
 --- a/libavformat/Makefile
 +++ b/libavformat/Makefile
 @@ -319,6 +319,7 @@ OBJS-$(CONFIG_MLV_DEMUXER)   += mlvdec.o
 riffdec.o
  OBJS-$(CONFIG_MM_DEMUXER)+= mm.o
  OBJS-$(CONFIG_MMF_DEMUXER)   += mmf.o
  OBJS-$(CONFIG_MMF_MUXER) += mmf.o rawenc.o
 +OBJS-$(CONFIG_MOFLEX_DEMUXER)+= moflex.o
  OBJS-$(CONFIG_MOV_DEMUXER)   += mov.o mov_chan.o mov_esds.o
 replaygain.o
  OBJS-$(CONFIG_MOV_MUXER) += movenc.o av1.o avc.o hevc.o
 vpcc.o \
  movenchint.o mov_chan.o
 rtp.o
 \
 diff --git a/libavformat/allformats.c b/libavformat/allformats.c
 index 0aa9dd7198..28331facb9 100644
 --- a/libavformat/allformats.c
 +++ b/libavformat/allformats.c
 @@ -249,6 +249,7 @@ extern AVInputFormat  ff_mlv_demuxer;
  extern AVInputFormat  ff_mm_demuxer;
  extern AVInputFormat  ff_mmf_demuxer;
  extern AVOutputFormat ff_mmf_muxer;
 +extern AVInputFormat  ff_moflex_demuxer;
  extern AVInputFormat  ff_mov_demuxer;
  extern AVOutputFormat ff_mov_muxer;
  extern AVOutputFormat ff_mp2_muxer;
 diff --git a/libavformat/moflex.c b/libavformat/moflex.c
 new file mode 100644
 index 00..989623396f
 --- /dev/null
 +++ b/libavformat/moflex.c
 @@ -0,0 +1,360 @@
 +/*
 + * MOFLEX demuxer
 + * Copyright (c) 2020 Paul B Mahol
 + *
 + * This file is part of FFmpeg.
 + *
 + * FFmpeg is free software; you can redistribute it and/or
 + * modify it under the terms of the GNU Lesser General Public
 + * License as published by the Free Software Foundation; either
 + * version 2.1 of the License, or (at your option) any later version.
 + *
 + * FFmpeg is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 + * Lesser General Public License for more details.
 + *
 + * You should have received a copy of the GNU Lesser General Public
 + * License along with FFmpeg; if not, write to the Free Software
 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 02110-1301 USA
 + */
 +
 +#include "libavcodec/bytestream.h"
 +
 +#include "avformat.h"
 +#include "internal.h"
 +
 +typedef struct BitReader {
 +unsigned last;
 +unsigned pos;
 +} BitReader;
 +
 +typedef struct MOFLEXDemuxContext {
 +unsigned size;
 +int64_t pos;
 +int64_t ts;
 +int flags;
 +int in_block;
 +
 +BitReader br;
 +} MOFLEXDemuxContext;
 +
 +static int pop(BitReader *br, AVIOContext *pb)
 +{
 +if (avio_feof(pb))
 +return AVERROR_EOF;
 +
 +if ((br->pos & 7) == 0)
 +br->last = (unsigned)avio_r8(pb) << 24U;
 +else
 +br->last <<= 1;
 +
 +br->pos++;
 +return !!(br->last & 0x8000);
 +}
 +
 +static int pop_int(BitReader *br, AVIOContext *pb, int n)
 +{
 +int value = 0;
 +
 +for (int i = 0; i < n; i++) {
 +int ret = pop(br, pb);
 +
 +if (ret < 0)
 +return ret;
 +value = 2 * value + ret;
 +}
 +
 +return value;
 +}
 +
 +static int pop_length(BitReader *br, AVIOContext *pb)
 +{
 +int ret, n = 1;
 +
 +while ((ret = pop(br, pb)) == 0)
 +n++;
 +
 +if (ret < 0)
 +return ret;
 +return n;
 +}
 +
 +static int read_var_byte(AVFormatContext *s, unsigned *out)
 +{
 +AVIOContext *pb = s->pb;
 +unsigned value = 0, data;
 +
 +data = avio_r8(pb);
 +if (!(data & 0x80)) {
 +*out = data;
 +return 0;
 +}
 +
 +value = (data & 0x7F) << 7;
 +data = avio_r8(pb);
 +if (!(data & 0x80)) {
 +value |= data;
 +*out = value;
 +return 0;
 +}
 +
 +value = ((data & 0x7F) | value) << 7;
 +data = avio_r8(pb);
 +if (!(data & 0x80)) {
 +value |= data;
 +*out = value;
 +return 0;
 +}
 +
 +value = (((data & 0x7F) | valu

Re: [FFmpeg-devel] [PATCH 4/5] avformat: add moflex demuxer

2020-09-03 Thread Andreas Rheinhardt
Paul B Mahol:
> On 9/3/20, Andreas Rheinhardt  wrote:
>> Paul B Mahol:
>>> On 9/3/20, Andreas Rheinhardt  wrote:
 Paul B Mahol:
> Signed-off-by: Paul B Mahol 
> ---
>  libavformat/Makefile |   1 +
>  libavformat/allformats.c |   1 +
>  libavformat/moflex.c | 360 +++
>  3 files changed, 362 insertions(+)
>  create mode 100644 libavformat/moflex.c
>
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index cbb33fe37c..1e0ac317e5 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -319,6 +319,7 @@ OBJS-$(CONFIG_MLV_DEMUXER)   += mlvdec.o
> riffdec.o
>  OBJS-$(CONFIG_MM_DEMUXER)+= mm.o
>  OBJS-$(CONFIG_MMF_DEMUXER)   += mmf.o
>  OBJS-$(CONFIG_MMF_MUXER) += mmf.o rawenc.o
> +OBJS-$(CONFIG_MOFLEX_DEMUXER)+= moflex.o
>  OBJS-$(CONFIG_MOV_DEMUXER)   += mov.o mov_chan.o mov_esds.o
> replaygain.o
>  OBJS-$(CONFIG_MOV_MUXER) += movenc.o av1.o avc.o hevc.o
> vpcc.o \
>  movenchint.o mov_chan.o
> rtp.o
> \
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index 0aa9dd7198..28331facb9 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -249,6 +249,7 @@ extern AVInputFormat  ff_mlv_demuxer;
>  extern AVInputFormat  ff_mm_demuxer;
>  extern AVInputFormat  ff_mmf_demuxer;
>  extern AVOutputFormat ff_mmf_muxer;
> +extern AVInputFormat  ff_moflex_demuxer;
>  extern AVInputFormat  ff_mov_demuxer;
>  extern AVOutputFormat ff_mov_muxer;
>  extern AVOutputFormat ff_mp2_muxer;
> diff --git a/libavformat/moflex.c b/libavformat/moflex.c
> new file mode 100644
> index 00..989623396f
> --- /dev/null
> +++ b/libavformat/moflex.c
> @@ -0,0 +1,360 @@
> +/*
> + * MOFLEX demuxer
> + * Copyright (c) 2020 Paul B Mahol
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> 02110-1301 USA
> + */
> +
> +#include "libavcodec/bytestream.h"
> +
> +#include "avformat.h"
> +#include "internal.h"
> +
> +typedef struct BitReader {
> +unsigned last;
> +unsigned pos;
> +} BitReader;
> +
> +typedef struct MOFLEXDemuxContext {
> +unsigned size;
> +int64_t pos;
> +int64_t ts;
> +int flags;
> +int in_block;
> +
> +BitReader br;
> +} MOFLEXDemuxContext;
> +
> +static int pop(BitReader *br, AVIOContext *pb)
> +{
> +if (avio_feof(pb))
> +return AVERROR_EOF;
> +
> +if ((br->pos & 7) == 0)
> +br->last = (unsigned)avio_r8(pb) << 24U;
> +else
> +br->last <<= 1;
> +
> +br->pos++;
> +return !!(br->last & 0x8000);
> +}
> +
> +static int pop_int(BitReader *br, AVIOContext *pb, int n)
> +{
> +int value = 0;
> +
> +for (int i = 0; i < n; i++) {
> +int ret = pop(br, pb);
> +
> +if (ret < 0)
> +return ret;
> +value = 2 * value + ret;
> +}
> +
> +return value;
> +}
> +
> +static int pop_length(BitReader *br, AVIOContext *pb)
> +{
> +int ret, n = 1;
> +
> +while ((ret = pop(br, pb)) == 0)
> +n++;
> +
> +if (ret < 0)
> +return ret;
> +return n;
> +}
> +
> +static int read_var_byte(AVFormatContext *s, unsigned *out)
> +{
> +AVIOContext *pb = s->pb;
> +unsigned value = 0, data;
> +
> +data = avio_r8(pb);
> +if (!(data & 0x80)) {
> +*out = data;
> +return 0;
> +}
> +
> +value = (data & 0x7F) << 7;
> +data = avio_r8(pb);
> +if (!(data & 0x80)) {
> +value |= data;
> +*out = value;
> +return 0;
> +}
> +
> +value = ((data & 0x7F) | value) << 7;
> +data = avio_r8(pb);
> 

Re: [FFmpeg-devel] [PATCH 4/5] avformat: add moflex demuxer

2020-09-03 Thread Paul B Mahol
On 9/3/20, Andreas Rheinhardt  wrote:
> Paul B Mahol:
>> Signed-off-by: Paul B Mahol 
>> ---
>>  libavformat/Makefile |   1 +
>>  libavformat/allformats.c |   1 +
>>  libavformat/moflex.c | 360 +++
>>  3 files changed, 362 insertions(+)
>>  create mode 100644 libavformat/moflex.c
>>
>> diff --git a/libavformat/Makefile b/libavformat/Makefile
>> index cbb33fe37c..1e0ac317e5 100644
>> --- a/libavformat/Makefile
>> +++ b/libavformat/Makefile
>> @@ -319,6 +319,7 @@ OBJS-$(CONFIG_MLV_DEMUXER)   += mlvdec.o
>> riffdec.o
>>  OBJS-$(CONFIG_MM_DEMUXER)+= mm.o
>>  OBJS-$(CONFIG_MMF_DEMUXER)   += mmf.o
>>  OBJS-$(CONFIG_MMF_MUXER) += mmf.o rawenc.o
>> +OBJS-$(CONFIG_MOFLEX_DEMUXER)+= moflex.o
>>  OBJS-$(CONFIG_MOV_DEMUXER)   += mov.o mov_chan.o mov_esds.o
>> replaygain.o
>>  OBJS-$(CONFIG_MOV_MUXER) += movenc.o av1.o avc.o hevc.o
>> vpcc.o \
>>  movenchint.o mov_chan.o rtp.o
>> \
>> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
>> index 0aa9dd7198..28331facb9 100644
>> --- a/libavformat/allformats.c
>> +++ b/libavformat/allformats.c
>> @@ -249,6 +249,7 @@ extern AVInputFormat  ff_mlv_demuxer;
>>  extern AVInputFormat  ff_mm_demuxer;
>>  extern AVInputFormat  ff_mmf_demuxer;
>>  extern AVOutputFormat ff_mmf_muxer;
>> +extern AVInputFormat  ff_moflex_demuxer;
>>  extern AVInputFormat  ff_mov_demuxer;
>>  extern AVOutputFormat ff_mov_muxer;
>>  extern AVOutputFormat ff_mp2_muxer;
>> diff --git a/libavformat/moflex.c b/libavformat/moflex.c
>> new file mode 100644
>> index 00..989623396f
>> --- /dev/null
>> +++ b/libavformat/moflex.c
>> @@ -0,0 +1,360 @@
>> +/*
>> + * MOFLEX demuxer
>> + * Copyright (c) 2020 Paul B Mahol
>> + *
>> + * This file is part of FFmpeg.
>> + *
>> + * FFmpeg is free software; you can redistribute it and/or
>> + * modify it under the terms of the GNU Lesser General Public
>> + * License as published by the Free Software Foundation; either
>> + * version 2.1 of the License, or (at your option) any later version.
>> + *
>> + * FFmpeg is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>> + * Lesser General Public License for more details.
>> + *
>> + * You should have received a copy of the GNU Lesser General Public
>> + * License along with FFmpeg; if not, write to the Free Software
>> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
>> 02110-1301 USA
>> + */
>> +
>> +#include "libavcodec/bytestream.h"
>> +
>> +#include "avformat.h"
>> +#include "internal.h"
>> +
>> +typedef struct BitReader {
>> +unsigned last;
>> +unsigned pos;
>> +} BitReader;
>> +
>> +typedef struct MOFLEXDemuxContext {
>> +unsigned size;
>> +int64_t pos;
>> +int64_t ts;
>> +int flags;
>> +int in_block;
>> +
>> +BitReader br;
>> +} MOFLEXDemuxContext;
>> +
>> +static int pop(BitReader *br, AVIOContext *pb)
>> +{
>> +if (avio_feof(pb))
>> +return AVERROR_EOF;
>> +
>> +if ((br->pos & 7) == 0)
>> +br->last = (unsigned)avio_r8(pb) << 24U;
>> +else
>> +br->last <<= 1;
>> +
>> +br->pos++;
>> +return !!(br->last & 0x8000);
>> +}
>> +
>> +static int pop_int(BitReader *br, AVIOContext *pb, int n)
>> +{
>> +int value = 0;
>> +
>> +for (int i = 0; i < n; i++) {
>> +int ret = pop(br, pb);
>> +
>> +if (ret < 0)
>> +return ret;
>> +value = 2 * value + ret;
>> +}
>> +
>> +return value;
>> +}
>> +
>> +static int pop_length(BitReader *br, AVIOContext *pb)
>> +{
>> +int ret, n = 1;
>> +
>> +while ((ret = pop(br, pb)) == 0)
>> +n++;
>> +
>> +if (ret < 0)
>> +return ret;
>> +return n;
>> +}
>> +
>> +static int read_var_byte(AVFormatContext *s, unsigned *out)
>> +{
>> +AVIOContext *pb = s->pb;
>> +unsigned value = 0, data;
>> +
>> +data = avio_r8(pb);
>> +if (!(data & 0x80)) {
>> +*out = data;
>> +return 0;
>> +}
>> +
>> +value = (data & 0x7F) << 7;
>> +data = avio_r8(pb);
>> +if (!(data & 0x80)) {
>> +value |= data;
>> +*out = value;
>> +return 0;
>> +}
>> +
>> +value = ((data & 0x7F) | value) << 7;
>> +data = avio_r8(pb);
>> +if (!(data & 0x80)) {
>> +value |= data;
>> +*out = value;
>> +return 0;
>> +}
>> +
>> +value = (((data & 0x7F) | value) << 7) | avio_r8(pb);
>> +*out = value;
>> +
>> +return 0;
>> +}
>> +
>> +static int moflex_probe(const AVProbeData *p)
>> +{
>> +GetByteContext gb;
>> +int score = 0;
>> +
>> +bytestream2_init(&gb, p->buf, p->buf_size);
>> +
>> +if (bytestream2_get_be16(&gb) != 0x4C32)
>> +return 0;
>> +score += 10;
>> +
>> +bytestream2_skip(

Re: [FFmpeg-devel] [PATCH 4/5] avformat: add moflex demuxer

2020-09-03 Thread Andreas Rheinhardt
Paul B Mahol:
> On 9/3/20, Andreas Rheinhardt  wrote:
>> Paul B Mahol:
>>> Signed-off-by: Paul B Mahol 
>>> ---
>>>  libavformat/Makefile |   1 +
>>>  libavformat/allformats.c |   1 +
>>>  libavformat/moflex.c | 360 +++
>>>  3 files changed, 362 insertions(+)
>>>  create mode 100644 libavformat/moflex.c
>>>
>>> diff --git a/libavformat/Makefile b/libavformat/Makefile
>>> index cbb33fe37c..1e0ac317e5 100644
>>> --- a/libavformat/Makefile
>>> +++ b/libavformat/Makefile
>>> @@ -319,6 +319,7 @@ OBJS-$(CONFIG_MLV_DEMUXER)   += mlvdec.o
>>> riffdec.o
>>>  OBJS-$(CONFIG_MM_DEMUXER)+= mm.o
>>>  OBJS-$(CONFIG_MMF_DEMUXER)   += mmf.o
>>>  OBJS-$(CONFIG_MMF_MUXER) += mmf.o rawenc.o
>>> +OBJS-$(CONFIG_MOFLEX_DEMUXER)+= moflex.o
>>>  OBJS-$(CONFIG_MOV_DEMUXER)   += mov.o mov_chan.o mov_esds.o
>>> replaygain.o
>>>  OBJS-$(CONFIG_MOV_MUXER) += movenc.o av1.o avc.o hevc.o
>>> vpcc.o \
>>>  movenchint.o mov_chan.o rtp.o
>>> \
>>> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
>>> index 0aa9dd7198..28331facb9 100644
>>> --- a/libavformat/allformats.c
>>> +++ b/libavformat/allformats.c
>>> @@ -249,6 +249,7 @@ extern AVInputFormat  ff_mlv_demuxer;
>>>  extern AVInputFormat  ff_mm_demuxer;
>>>  extern AVInputFormat  ff_mmf_demuxer;
>>>  extern AVOutputFormat ff_mmf_muxer;
>>> +extern AVInputFormat  ff_moflex_demuxer;
>>>  extern AVInputFormat  ff_mov_demuxer;
>>>  extern AVOutputFormat ff_mov_muxer;
>>>  extern AVOutputFormat ff_mp2_muxer;
>>> diff --git a/libavformat/moflex.c b/libavformat/moflex.c
>>> new file mode 100644
>>> index 00..989623396f
>>> --- /dev/null
>>> +++ b/libavformat/moflex.c
>>> @@ -0,0 +1,360 @@
>>> +/*
>>> + * MOFLEX demuxer
>>> + * Copyright (c) 2020 Paul B Mahol
>>> + *
>>> + * This file is part of FFmpeg.
>>> + *
>>> + * FFmpeg is free software; you can redistribute it and/or
>>> + * modify it under the terms of the GNU Lesser General Public
>>> + * License as published by the Free Software Foundation; either
>>> + * version 2.1 of the License, or (at your option) any later version.
>>> + *
>>> + * FFmpeg is distributed in the hope that it will be useful,
>>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>>> + * Lesser General Public License for more details.
>>> + *
>>> + * You should have received a copy of the GNU Lesser General Public
>>> + * License along with FFmpeg; if not, write to the Free Software
>>> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
>>> 02110-1301 USA
>>> + */
>>> +
>>> +#include "libavcodec/bytestream.h"
>>> +
>>> +#include "avformat.h"
>>> +#include "internal.h"
>>> +
>>> +typedef struct BitReader {
>>> +unsigned last;
>>> +unsigned pos;
>>> +} BitReader;
>>> +
>>> +typedef struct MOFLEXDemuxContext {
>>> +unsigned size;
>>> +int64_t pos;
>>> +int64_t ts;
>>> +int flags;
>>> +int in_block;
>>> +
>>> +BitReader br;
>>> +} MOFLEXDemuxContext;
>>> +
>>> +static int pop(BitReader *br, AVIOContext *pb)
>>> +{
>>> +if (avio_feof(pb))
>>> +return AVERROR_EOF;
>>> +
>>> +if ((br->pos & 7) == 0)
>>> +br->last = (unsigned)avio_r8(pb) << 24U;
>>> +else
>>> +br->last <<= 1;
>>> +
>>> +br->pos++;
>>> +return !!(br->last & 0x8000);
>>> +}
>>> +
>>> +static int pop_int(BitReader *br, AVIOContext *pb, int n)
>>> +{
>>> +int value = 0;
>>> +
>>> +for (int i = 0; i < n; i++) {
>>> +int ret = pop(br, pb);
>>> +
>>> +if (ret < 0)
>>> +return ret;
>>> +value = 2 * value + ret;
>>> +}
>>> +
>>> +return value;
>>> +}
>>> +
>>> +static int pop_length(BitReader *br, AVIOContext *pb)
>>> +{
>>> +int ret, n = 1;
>>> +
>>> +while ((ret = pop(br, pb)) == 0)
>>> +n++;
>>> +
>>> +if (ret < 0)
>>> +return ret;
>>> +return n;
>>> +}
>>> +
>>> +static int read_var_byte(AVFormatContext *s, unsigned *out)
>>> +{
>>> +AVIOContext *pb = s->pb;
>>> +unsigned value = 0, data;
>>> +
>>> +data = avio_r8(pb);
>>> +if (!(data & 0x80)) {
>>> +*out = data;
>>> +return 0;
>>> +}
>>> +
>>> +value = (data & 0x7F) << 7;
>>> +data = avio_r8(pb);
>>> +if (!(data & 0x80)) {
>>> +value |= data;
>>> +*out = value;
>>> +return 0;
>>> +}
>>> +
>>> +value = ((data & 0x7F) | value) << 7;
>>> +data = avio_r8(pb);
>>> +if (!(data & 0x80)) {
>>> +value |= data;
>>> +*out = value;
>>> +return 0;
>>> +}
>>> +
>>> +value = (((data & 0x7F) | value) << 7) | avio_r8(pb);
>>> +*out = value;
>>> +
>>> +return 0;
>>> +}
>>> +
>>> +static int moflex_probe(const AVProbeData *p)
>>> +{
>>> +GetByteContext gb;
>>> +int score = 0;
>>> +

Re: [FFmpeg-devel] [PATCH 4/5] avformat: add moflex demuxer

2020-09-03 Thread Paul B Mahol
On 9/3/20, Andreas Rheinhardt  wrote:
> Paul B Mahol:
>> On 9/3/20, Andreas Rheinhardt  wrote:
>>> Paul B Mahol:
 Signed-off-by: Paul B Mahol 
 ---
  libavformat/Makefile |   1 +
  libavformat/allformats.c |   1 +
  libavformat/moflex.c | 360 +++
  3 files changed, 362 insertions(+)
  create mode 100644 libavformat/moflex.c

 diff --git a/libavformat/Makefile b/libavformat/Makefile
 index cbb33fe37c..1e0ac317e5 100644
 --- a/libavformat/Makefile
 +++ b/libavformat/Makefile
 @@ -319,6 +319,7 @@ OBJS-$(CONFIG_MLV_DEMUXER)   += mlvdec.o
 riffdec.o
  OBJS-$(CONFIG_MM_DEMUXER)+= mm.o
  OBJS-$(CONFIG_MMF_DEMUXER)   += mmf.o
  OBJS-$(CONFIG_MMF_MUXER) += mmf.o rawenc.o
 +OBJS-$(CONFIG_MOFLEX_DEMUXER)+= moflex.o
  OBJS-$(CONFIG_MOV_DEMUXER)   += mov.o mov_chan.o mov_esds.o
 replaygain.o
  OBJS-$(CONFIG_MOV_MUXER) += movenc.o av1.o avc.o hevc.o
 vpcc.o \
  movenchint.o mov_chan.o
 rtp.o
 \
 diff --git a/libavformat/allformats.c b/libavformat/allformats.c
 index 0aa9dd7198..28331facb9 100644
 --- a/libavformat/allformats.c
 +++ b/libavformat/allformats.c
 @@ -249,6 +249,7 @@ extern AVInputFormat  ff_mlv_demuxer;
  extern AVInputFormat  ff_mm_demuxer;
  extern AVInputFormat  ff_mmf_demuxer;
  extern AVOutputFormat ff_mmf_muxer;
 +extern AVInputFormat  ff_moflex_demuxer;
  extern AVInputFormat  ff_mov_demuxer;
  extern AVOutputFormat ff_mov_muxer;
  extern AVOutputFormat ff_mp2_muxer;
 diff --git a/libavformat/moflex.c b/libavformat/moflex.c
 new file mode 100644
 index 00..989623396f
 --- /dev/null
 +++ b/libavformat/moflex.c
 @@ -0,0 +1,360 @@
 +/*
 + * MOFLEX demuxer
 + * Copyright (c) 2020 Paul B Mahol
 + *
 + * This file is part of FFmpeg.
 + *
 + * FFmpeg is free software; you can redistribute it and/or
 + * modify it under the terms of the GNU Lesser General Public
 + * License as published by the Free Software Foundation; either
 + * version 2.1 of the License, or (at your option) any later version.
 + *
 + * FFmpeg is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 + * Lesser General Public License for more details.
 + *
 + * You should have received a copy of the GNU Lesser General Public
 + * License along with FFmpeg; if not, write to the Free Software
 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 02110-1301 USA
 + */
 +
 +#include "libavcodec/bytestream.h"
 +
 +#include "avformat.h"
 +#include "internal.h"
 +
 +typedef struct BitReader {
 +unsigned last;
 +unsigned pos;
 +} BitReader;
 +
 +typedef struct MOFLEXDemuxContext {
 +unsigned size;
 +int64_t pos;
 +int64_t ts;
 +int flags;
 +int in_block;
 +
 +BitReader br;
 +} MOFLEXDemuxContext;
 +
 +static int pop(BitReader *br, AVIOContext *pb)
 +{
 +if (avio_feof(pb))
 +return AVERROR_EOF;
 +
 +if ((br->pos & 7) == 0)
 +br->last = (unsigned)avio_r8(pb) << 24U;
 +else
 +br->last <<= 1;
 +
 +br->pos++;
 +return !!(br->last & 0x8000);
 +}
 +
 +static int pop_int(BitReader *br, AVIOContext *pb, int n)
 +{
 +int value = 0;
 +
 +for (int i = 0; i < n; i++) {
 +int ret = pop(br, pb);
 +
 +if (ret < 0)
 +return ret;
 +value = 2 * value + ret;
 +}
 +
 +return value;
 +}
 +
 +static int pop_length(BitReader *br, AVIOContext *pb)
 +{
 +int ret, n = 1;
 +
 +while ((ret = pop(br, pb)) == 0)
 +n++;
 +
 +if (ret < 0)
 +return ret;
 +return n;
 +}
 +
 +static int read_var_byte(AVFormatContext *s, unsigned *out)
 +{
 +AVIOContext *pb = s->pb;
 +unsigned value = 0, data;
 +
 +data = avio_r8(pb);
 +if (!(data & 0x80)) {
 +*out = data;
 +return 0;
 +}
 +
 +value = (data & 0x7F) << 7;
 +data = avio_r8(pb);
 +if (!(data & 0x80)) {
 +value |= data;
 +*out = value;
 +return 0;
 +}
 +
 +value = ((data & 0x7F) | value) << 7;
 +data = avio_r8(pb);
 +if (!(data & 0x80)) {
 +value |= data;
 +*out = value;
 +return 0;
 +}
 +
 +value = (((data & 0x7F) | valu

Re: [FFmpeg-devel] [PATCH 4/5] avformat: add moflex demuxer

2020-09-03 Thread Paul B Mahol
On 9/3/20, Andreas Rheinhardt  wrote:
> Paul B Mahol:
>> On 9/3/20, Andreas Rheinhardt  wrote:
>>> Paul B Mahol:
 Signed-off-by: Paul B Mahol 
 ---
  libavformat/Makefile |   1 +
  libavformat/allformats.c |   1 +
  libavformat/moflex.c | 360 +++
  3 files changed, 362 insertions(+)
  create mode 100644 libavformat/moflex.c

 diff --git a/libavformat/Makefile b/libavformat/Makefile
 index cbb33fe37c..1e0ac317e5 100644
 --- a/libavformat/Makefile
 +++ b/libavformat/Makefile
 @@ -319,6 +319,7 @@ OBJS-$(CONFIG_MLV_DEMUXER)   += mlvdec.o
 riffdec.o
  OBJS-$(CONFIG_MM_DEMUXER)+= mm.o
  OBJS-$(CONFIG_MMF_DEMUXER)   += mmf.o
  OBJS-$(CONFIG_MMF_MUXER) += mmf.o rawenc.o
 +OBJS-$(CONFIG_MOFLEX_DEMUXER)+= moflex.o
  OBJS-$(CONFIG_MOV_DEMUXER)   += mov.o mov_chan.o mov_esds.o
 replaygain.o
  OBJS-$(CONFIG_MOV_MUXER) += movenc.o av1.o avc.o hevc.o
 vpcc.o \
  movenchint.o mov_chan.o
 rtp.o
 \
 diff --git a/libavformat/allformats.c b/libavformat/allformats.c
 index 0aa9dd7198..28331facb9 100644
 --- a/libavformat/allformats.c
 +++ b/libavformat/allformats.c
 @@ -249,6 +249,7 @@ extern AVInputFormat  ff_mlv_demuxer;
  extern AVInputFormat  ff_mm_demuxer;
  extern AVInputFormat  ff_mmf_demuxer;
  extern AVOutputFormat ff_mmf_muxer;
 +extern AVInputFormat  ff_moflex_demuxer;
  extern AVInputFormat  ff_mov_demuxer;
  extern AVOutputFormat ff_mov_muxer;
  extern AVOutputFormat ff_mp2_muxer;
 diff --git a/libavformat/moflex.c b/libavformat/moflex.c
 new file mode 100644
 index 00..989623396f
 --- /dev/null
 +++ b/libavformat/moflex.c
 @@ -0,0 +1,360 @@
 +/*
 + * MOFLEX demuxer
 + * Copyright (c) 2020 Paul B Mahol
 + *
 + * This file is part of FFmpeg.
 + *
 + * FFmpeg is free software; you can redistribute it and/or
 + * modify it under the terms of the GNU Lesser General Public
 + * License as published by the Free Software Foundation; either
 + * version 2.1 of the License, or (at your option) any later version.
 + *
 + * FFmpeg is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 + * Lesser General Public License for more details.
 + *
 + * You should have received a copy of the GNU Lesser General Public
 + * License along with FFmpeg; if not, write to the Free Software
 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 02110-1301 USA
 + */
 +
 +#include "libavcodec/bytestream.h"
 +
 +#include "avformat.h"
 +#include "internal.h"
 +
 +typedef struct BitReader {
 +unsigned last;
 +unsigned pos;
 +} BitReader;
 +
 +typedef struct MOFLEXDemuxContext {
 +unsigned size;
 +int64_t pos;
 +int64_t ts;
 +int flags;
 +int in_block;
 +
 +BitReader br;
 +} MOFLEXDemuxContext;
 +
 +static int pop(BitReader *br, AVIOContext *pb)
 +{
 +if (avio_feof(pb))
 +return AVERROR_EOF;
 +
 +if ((br->pos & 7) == 0)
 +br->last = (unsigned)avio_r8(pb) << 24U;
 +else
 +br->last <<= 1;
 +
 +br->pos++;
 +return !!(br->last & 0x8000);
 +}
 +
 +static int pop_int(BitReader *br, AVIOContext *pb, int n)
 +{
 +int value = 0;
 +
 +for (int i = 0; i < n; i++) {
 +int ret = pop(br, pb);
 +
 +if (ret < 0)
 +return ret;
 +value = 2 * value + ret;
 +}
 +
 +return value;
 +}
 +
 +static int pop_length(BitReader *br, AVIOContext *pb)
 +{
 +int ret, n = 1;
 +
 +while ((ret = pop(br, pb)) == 0)
 +n++;
 +
 +if (ret < 0)
 +return ret;
 +return n;
 +}
 +
 +static int read_var_byte(AVFormatContext *s, unsigned *out)
 +{
 +AVIOContext *pb = s->pb;
 +unsigned value = 0, data;
 +
 +data = avio_r8(pb);
 +if (!(data & 0x80)) {
 +*out = data;
 +return 0;
 +}
 +
 +value = (data & 0x7F) << 7;
 +data = avio_r8(pb);
 +if (!(data & 0x80)) {
 +value |= data;
 +*out = value;
 +return 0;
 +}
 +
 +value = ((data & 0x7F) | value) << 7;
 +data = avio_r8(pb);
 +if (!(data & 0x80)) {
 +value |= data;
 +*out = value;
 +return 0;
 +}
 +
 +value = (((data & 0x7F) | valu

Re: [FFmpeg-devel] [PATCH 4/5] avformat: add moflex demuxer

2020-09-03 Thread Andreas Rheinhardt
Paul B Mahol:
> On 9/3/20, Andreas Rheinhardt  wrote:
>> Paul B Mahol:
>>> On 9/3/20, Andreas Rheinhardt  wrote:
 Paul B Mahol:
> Signed-off-by: Paul B Mahol 
> ---
>  libavformat/Makefile |   1 +
>  libavformat/allformats.c |   1 +
>  libavformat/moflex.c | 360 +++
>  3 files changed, 362 insertions(+)
>  create mode 100644 libavformat/moflex.c
>
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index cbb33fe37c..1e0ac317e5 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -319,6 +319,7 @@ OBJS-$(CONFIG_MLV_DEMUXER)   += mlvdec.o
> riffdec.o
>  OBJS-$(CONFIG_MM_DEMUXER)+= mm.o
>  OBJS-$(CONFIG_MMF_DEMUXER)   += mmf.o
>  OBJS-$(CONFIG_MMF_MUXER) += mmf.o rawenc.o
> +OBJS-$(CONFIG_MOFLEX_DEMUXER)+= moflex.o
>  OBJS-$(CONFIG_MOV_DEMUXER)   += mov.o mov_chan.o mov_esds.o
> replaygain.o
>  OBJS-$(CONFIG_MOV_MUXER) += movenc.o av1.o avc.o hevc.o
> vpcc.o \
>  movenchint.o mov_chan.o
> rtp.o
> \
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index 0aa9dd7198..28331facb9 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -249,6 +249,7 @@ extern AVInputFormat  ff_mlv_demuxer;
>  extern AVInputFormat  ff_mm_demuxer;
>  extern AVInputFormat  ff_mmf_demuxer;
>  extern AVOutputFormat ff_mmf_muxer;
> +extern AVInputFormat  ff_moflex_demuxer;
>  extern AVInputFormat  ff_mov_demuxer;
>  extern AVOutputFormat ff_mov_muxer;
>  extern AVOutputFormat ff_mp2_muxer;
> diff --git a/libavformat/moflex.c b/libavformat/moflex.c
> new file mode 100644
> index 00..989623396f
> --- /dev/null
> +++ b/libavformat/moflex.c
> @@ -0,0 +1,360 @@
> +/*
> + * MOFLEX demuxer
> + * Copyright (c) 2020 Paul B Mahol
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> 02110-1301 USA
> + */
> +
> +#include "libavcodec/bytestream.h"
> +
> +#include "avformat.h"
> +#include "internal.h"
> +
> +typedef struct BitReader {
> +unsigned last;
> +unsigned pos;
> +} BitReader;
> +
> +typedef struct MOFLEXDemuxContext {
> +unsigned size;
> +int64_t pos;
> +int64_t ts;
> +int flags;
> +int in_block;
> +
> +BitReader br;
> +} MOFLEXDemuxContext;
> +
> +static int pop(BitReader *br, AVIOContext *pb)
> +{
> +if (avio_feof(pb))
> +return AVERROR_EOF;
> +
> +if ((br->pos & 7) == 0)
> +br->last = (unsigned)avio_r8(pb) << 24U;
> +else
> +br->last <<= 1;
> +
> +br->pos++;
> +return !!(br->last & 0x8000);
> +}
> +
> +static int pop_int(BitReader *br, AVIOContext *pb, int n)
> +{
> +int value = 0;
> +
> +for (int i = 0; i < n; i++) {
> +int ret = pop(br, pb);
> +
> +if (ret < 0)
> +return ret;
> +value = 2 * value + ret;
> +}
> +
> +return value;
> +}
> +
> +static int pop_length(BitReader *br, AVIOContext *pb)
> +{
> +int ret, n = 1;
> +
> +while ((ret = pop(br, pb)) == 0)
> +n++;
> +
> +if (ret < 0)
> +return ret;
> +return n;
> +}
> +
> +static int read_var_byte(AVFormatContext *s, unsigned *out)
> +{
> +AVIOContext *pb = s->pb;
> +unsigned value = 0, data;
> +
> +data = avio_r8(pb);
> +if (!(data & 0x80)) {
> +*out = data;
> +return 0;
> +}
> +
> +value = (data & 0x7F) << 7;
> +data = avio_r8(pb);
> +if (!(data & 0x80)) {
> +value |= data;
> +*out = value;
> +return 0;
> +}
> +
> +value = ((data & 0x7F) | value) << 7;
> +data = avio_r8(pb);
> 

Re: [FFmpeg-devel] [PATCH 4/5] avformat: add moflex demuxer

2020-09-03 Thread Andreas Rheinhardt
Paul B Mahol:
> On 9/3/20, Andreas Rheinhardt  wrote:
>> Paul B Mahol:
>>> On 9/3/20, Andreas Rheinhardt  wrote:
 Paul B Mahol:
> Signed-off-by: Paul B Mahol 
> ---
>  libavformat/Makefile |   1 +
>  libavformat/allformats.c |   1 +
>  libavformat/moflex.c | 360 +++
>  3 files changed, 362 insertions(+)
>  create mode 100644 libavformat/moflex.c
>
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index cbb33fe37c..1e0ac317e5 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -319,6 +319,7 @@ OBJS-$(CONFIG_MLV_DEMUXER)   += mlvdec.o
> riffdec.o
>  OBJS-$(CONFIG_MM_DEMUXER)+= mm.o
>  OBJS-$(CONFIG_MMF_DEMUXER)   += mmf.o
>  OBJS-$(CONFIG_MMF_MUXER) += mmf.o rawenc.o
> +OBJS-$(CONFIG_MOFLEX_DEMUXER)+= moflex.o
>  OBJS-$(CONFIG_MOV_DEMUXER)   += mov.o mov_chan.o mov_esds.o
> replaygain.o
>  OBJS-$(CONFIG_MOV_MUXER) += movenc.o av1.o avc.o hevc.o
> vpcc.o \
>  movenchint.o mov_chan.o
> rtp.o
> \
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index 0aa9dd7198..28331facb9 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -249,6 +249,7 @@ extern AVInputFormat  ff_mlv_demuxer;
>  extern AVInputFormat  ff_mm_demuxer;
>  extern AVInputFormat  ff_mmf_demuxer;
>  extern AVOutputFormat ff_mmf_muxer;
> +extern AVInputFormat  ff_moflex_demuxer;
>  extern AVInputFormat  ff_mov_demuxer;
>  extern AVOutputFormat ff_mov_muxer;
>  extern AVOutputFormat ff_mp2_muxer;
> diff --git a/libavformat/moflex.c b/libavformat/moflex.c
> new file mode 100644
> index 00..989623396f
> --- /dev/null
> +++ b/libavformat/moflex.c
> @@ -0,0 +1,360 @@
> +/*
> + * MOFLEX demuxer
> + * Copyright (c) 2020 Paul B Mahol
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> 02110-1301 USA
> + */
> +
> +#include "libavcodec/bytestream.h"
> +
> +#include "avformat.h"
> +#include "internal.h"
> +
> +typedef struct BitReader {
> +unsigned last;
> +unsigned pos;
> +} BitReader;
> +
> +typedef struct MOFLEXDemuxContext {
> +unsigned size;
> +int64_t pos;
> +int64_t ts;
> +int flags;
> +int in_block;
> +
> +BitReader br;
> +} MOFLEXDemuxContext;
> +
> +static int pop(BitReader *br, AVIOContext *pb)
> +{
> +if (avio_feof(pb))
> +return AVERROR_EOF;
> +
> +if ((br->pos & 7) == 0)
> +br->last = (unsigned)avio_r8(pb) << 24U;
> +else
> +br->last <<= 1;
> +
> +br->pos++;
> +return !!(br->last & 0x8000);
> +}
> +
> +static int pop_int(BitReader *br, AVIOContext *pb, int n)
> +{
> +int value = 0;
> +
> +for (int i = 0; i < n; i++) {
> +int ret = pop(br, pb);
> +
> +if (ret < 0)
> +return ret;
> +value = 2 * value + ret;
> +}
> +
> +return value;
> +}
> +
> +static int pop_length(BitReader *br, AVIOContext *pb)
> +{
> +int ret, n = 1;
> +
> +while ((ret = pop(br, pb)) == 0)
> +n++;
> +
> +if (ret < 0)
> +return ret;
> +return n;
> +}
> +
> +static int read_var_byte(AVFormatContext *s, unsigned *out)
> +{
> +AVIOContext *pb = s->pb;
> +unsigned value = 0, data;
> +
> +data = avio_r8(pb);
> +if (!(data & 0x80)) {
> +*out = data;
> +return 0;
> +}
> +
> +value = (data & 0x7F) << 7;
> +data = avio_r8(pb);
> +if (!(data & 0x80)) {
> +value |= data;
> +*out = value;
> +return 0;
> +}
> +
> +value = ((data & 0x7F) | value) << 7;
> +data = avio_r8(pb);
> 

Re: [FFmpeg-devel] [PATCH 1/4] avformat/mov: Fix return type used for av_seek in mfra code

2020-09-03 Thread Derek Buitenhuis
On 01/09/2020 16:03, Derek Buitenhuis wrote:
> It should be a 64-bit integer, otherwise it overflows and fails
> on files greater than 2GB on some systems like x86_64 Linux.
> 
> Signed-off-by: Derek Buitenhuis 
> ---
>  libavformat/mov.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Ping on this set.

- Derek
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/4] avformat/mov: Fix return type used for av_seek in mfra code

2020-09-03 Thread Paul B Mahol
On 9/1/20, Derek Buitenhuis  wrote:
> It should be a 64-bit integer, otherwise it overflows and fails
> on files greater than 2GB on some systems like x86_64 Linux.
>
> Signed-off-by: Derek Buitenhuis 
> ---
>  libavformat/mov.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index dcec74662d..f0b4edc2ed 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -5095,7 +5095,7 @@ static int mov_read_sidx(MOVContext *c, AVIOContext
> *pb, MOVAtom atom)
>  // See if the remaining bytes are just an mfra which we can ignore.
>  is_complete = offset == stream_size;
>  if (!is_complete) {
> -int ret;
> +int64_t ret;
>  int64_t original_pos = avio_tell(pb);
>  int32_t mfra_size;
>  if ((ret = avio_seek(pb, stream_size - 4, SEEK_SET)) < 0)
> --
> 2.28.0
>

Of course LGTM.

> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] tests: fix warning ISO C90 forbids mixed declarations and code

2020-09-03 Thread lance . lmwang
From: Limin Wang 

Signed-off-by: Limin Wang 
---
 tests/checkasm/vf_hflip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/checkasm/vf_hflip.c b/tests/checkasm/vf_hflip.c
index 48ebf85..2d6fdec 100644
--- a/tests/checkasm/vf_hflip.c
+++ b/tests/checkasm/vf_hflip.c
@@ -40,10 +40,10 @@ static void check_hflip(int step, const char * report_name){
 int i;
 int step_array[4] = {1, 1, 1, 1};
 FlipContext s;
-s.bayer_plus1 = 1;
 
 declare_func(void, const uint8_t *src, uint8_t *dst, int w);
 
+s.bayer_plus1 = 1;
 memset(src, 0, WIDTH_PADDED);
 memset(dst_ref, 0, WIDTH_PADDED);
 memset(dst_new, 0, WIDTH_PADDED);
-- 
1.8.3.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] request to upload sample

2020-09-03 Thread Paul B Mahol
On 9/1/20, Paul B Mahol  wrote:
> Hi.
>
> Please upload this file to FATE servers.
>
> http://trac.ffmpeg.org/raw-attachment/ticket/8872/200828-005.wav
>
> Will add chapter/cue test later.
>

Ping.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] [GSoC v3 1/7] avformat/abr: Adaptive Bitrate support

2020-09-03 Thread Steven Liu


> 在 2020年8月23日,20:23,Hongcheng Zhong  写道:
> 
> From: spartazhc 
> 
> Add abr module for hls/dash.
> 
> Signed-off-by: spartazhc 
> 
> v1 fixed:
> 1. add an "ff" prefix to the protocol name to mark it internal.
> 2. use 1.2f for float constant 1.2.
> 3. simplify abr_seek for we just need AVSEEK_SIZE only.
> 
> v2 fixed:
> 1. fix error return
> 2. simplify abr_seek
> 
> v3 fixed:
> 1. rewrite hls_param_parse function
> 2. fix error code return
> 3. use unsigned type and const prefix
> 4. fix documentation
> 5. fix abr_rule
> 6. rename cur_pls to cur_var
> 7. add type input and output
> ---
> doc/protocols.texi  |   7 ++
> libavformat/Makefile|   1 +
> libavformat/ffabr.c | 271 
> libavformat/protocols.c |   1 +
> 4 files changed, 280 insertions(+)
> create mode 100644 libavformat/ffabr.c
> 
> diff --git a/doc/protocols.texi b/doc/protocols.texi
> index 7b3df96fda..e31de80ab6 100644
> --- a/doc/protocols.texi
> +++ b/doc/protocols.texi
> @@ -232,6 +232,13 @@ For example, to convert a GIF file given inline with 
> @command{ffmpeg}:
> ffmpeg -i 
> "data:image/gif;base64,R0lGODdhCAAIAMIE//8AAP//AP///ywACAAIAAADF0gEDLojDgdGiJdJqUX02iB4E8Q9jUMkADs="
>  smiley.png
> @end example
> 
> +@section ffabr
> +
> +Adaptive bitrate sub-protocol work for hls/dash, ffabr is internal.
> +
> +The ffabr protocol takes stream information from hls/dash as input,
> +use bandwidth estimation to decide whether to switch or not.
> +
> @section file
> 
> File access protocol.
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index cbb33fe37c..68b004eee0 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -598,6 +598,7 @@ OBJS-$(CONFIG_CACHE_PROTOCOL)+= cache.o
> OBJS-$(CONFIG_CONCAT_PROTOCOL)   += concat.o
> OBJS-$(CONFIG_CRYPTO_PROTOCOL)   += crypto.o
> OBJS-$(CONFIG_DATA_PROTOCOL) += data_uri.o
> +OBJS-$(CONFIG_FFABR_PROTOCOL)+= ffabr.o
> OBJS-$(CONFIG_FFRTMPCRYPT_PROTOCOL)  += rtmpcrypt.o rtmpdigest.o rtmpdh.o
> OBJS-$(CONFIG_FFRTMPHTTP_PROTOCOL)   += rtmphttp.o
> OBJS-$(CONFIG_FILE_PROTOCOL) += file.o
> diff --git a/libavformat/ffabr.c b/libavformat/ffabr.c
> new file mode 100644
> index 00..1785ef5643
> --- /dev/null
> +++ b/libavformat/ffabr.c
> @@ -0,0 +1,271 @@
> +/*
> + * Adaptive Bitrate Module for HLS / DASH
> + * Copyright (c) 2020
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
> + */
> +
> +#include 
> +#include "avformat.h"
> +#include "libavutil/avassert.h"
> +#include "libavutil/avstring.h"
> +#include "libavutil/common.h"
> +#include "libavutil/opt.h"
> +#include "libavutil/time.h"
> +#include "url.h"
> +
> +#define ABR_NOT_SWITCH -1
> +
> +enum ABRFormatType {
> +ABR_TYPE_HLS,
> +ABR_TYPE_DASH
> +};
> +
> +typedef struct Variant {
> +uint32_t bitrate;
> +size_t index;
> +} variant;
> +
> +typedef struct ABRContext {
> +const AVClass *class;
> +URLContext *hd;
> +AVDictionary *abr_params;
> +AVDictionary *abr_metadata;
> +enum ABRFormatType format;
> +uint8_t cur_var;
> +uint8_t type;
> +int8_t can_switch;
> +size_t n_variants;
> +variant *variants;
> +size_t n_throughputs;
> +float *throughputs;
> +} ABRContext;
> +
> +static float harmonic_mean(const float *arr, size_t num)
> +{
> +float tmp = 0;
> +
> +if (!num) return 0;
> +
> +for (size_t i = 0; i < num; i++) {
> +tmp += 1 / arr[i];
> +}
> +
> +return num / tmp;
> +}
> +
> +static int hls_param_parse(ABRContext *c, const AVDictionaryEntry *entry)
> +{
> +AVDictionaryEntry *en;
> +size_t index;
> +char key_tmp[20];
> +
> +
> +en = av_dict_get(c->abr_params, "cur_var", entry, AV_DICT_IGNORE_SUFFIX);
> +if (en) {
> +c->cur_var = strtol(en->value, NULL, 10);
I saw you define it with uint8_t, maybe this will overflow if use long strtol
or define it int64_t and strtoll here?
> +}
> +en = av_dict_get(c->abr_params, "type", entry, AV_DICT_IGNORE_SUFFIX);
> +if (en) {
> +c->type = strtol(en->value, NULL, 10);
I saw you define it with uint8_t, maybe this will overflow if use long strtol

> +}
> +e

Re: [FFmpeg-devel] [PATCH] [GSoC v3 6/7] avformat/hls add metadata "abr_initial" for ffplay

2020-09-03 Thread Steven Liu


> 在 2020年8月23日,20:23,Hongcheng Zhong  写道:
> 
> From: spartazhc 
> 
> Add an AVDictionary option "abr_initial", which could be used to send
> message to ffplay. Currently, the first entry "abr_init_duration" is
> added.
> 
> Signed-off-by: spartazhc 
> ---
> doc/demuxers.texi |  3 +++
> libavformat/hls.c | 14 ++
> 2 files changed, 17 insertions(+)
> 
> diff --git a/doc/demuxers.texi b/doc/demuxers.texi
> index 4cdbd95962..761a372b86 100644
> --- a/doc/demuxers.texi
> +++ b/doc/demuxers.texi
> @@ -324,6 +324,9 @@ It accepts the following options:
> @item abr
> enable abr to switch streams.
> 
> +@item abr_initial
> +metadata used by abr for ffplay.
> +
> @item live_start_index
> segment index to start live streams at (negative values are from the end).
> 
> diff --git a/libavformat/hls.c b/libavformat/hls.c
> index 37a5a017b1..5c251cd002 100644
> --- a/libavformat/hls.c
> +++ b/libavformat/hls.c
> @@ -243,6 +243,7 @@ typedef struct HLSContext {
> AVIOContext *playlist_pb;
> 
> int abr;
> +AVDictionary *abr_initial;
> struct throughput  *throughputs;
> struct switch_task *switch_tasks;
> struct switch_info *switch_info;
> @@ -2308,6 +2309,7 @@ static int hls_read_header(AVFormatContext *s)
> }
> 
> if (c->abr) {
> +int64_t abr_init_duration = AV_NOPTS_VALUE;
> c->switch_tasks = av_malloc(c->n_playlists * sizeof(struct 
> switch_task));
> if (!c->switch_tasks) {
> ret = AVERROR(ENOMEM);
> @@ -2326,6 +2328,15 @@ static int hls_read_header(AVFormatContext *s)
> for (i = 0; i < c->n_playlists; i++) {
> struct playlist *pls = c->playlists[i];
> int type;
> +int64_t start = 0;
> +for (int i = 0; i < c->cur_seq_no + 1; i++) {
> +start += pls->segments[i]->duration;
> +}
> +start = av_rescale_q(start,
> +AV_TIME_BASE_Q,
> +get_timebase(pls));
> +if (abr_init_duration == AV_NOPTS_VALUE || abr_init_duration > 
> start)
> +abr_init_duration = start;
> 
> c->switch_tasks[i].switch_timestamp = AV_NOPTS_VALUE;
> type = playlist_type_simple(pls);
> @@ -2337,6 +2348,7 @@ static int hls_read_header(AVFormatContext *s)
> c->switch_info[SWITCH_VIDEO].pls_index = pls->index;
> }
> }
> +av_dict_set_int(&c->abr_initial, "abr_init_duration", 
> abr_init_duration, 0);
> }
> update_noheader_flag(s);
> 
> @@ -2768,6 +2780,8 @@ static int hls_probe(const AVProbeData *p)
> static const AVOption hls_options[] = {
> {"abr", "enable abr to switch streams",
> OFFSET(abr), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS },
> +{"abr_initial",  "metadata used by abr for ffplay",
> +OFFSET(abr_initial), AV_OPT_TYPE_DICT, { 0 }, 0, 0, FLAGS },
> {"live_start_index", "segment index to start live streams at (negative 
> values are from the end)",
> OFFSET(live_start_index), AV_OPT_TYPE_INT, {.i64 = -3}, INT_MIN, 
> INT_MAX, FLAGS},
> {"allowed_extensions", "List of file extensions that hls is allowed to 
> access",
> -- 
> 2.28.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-requ...@ffmpeg.org with subject "unsubscribe".

should be ok.

Thanks
Steven






___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] [GSoC v3 5/7] ffplay: add an option to enable abr

2020-09-03 Thread Steven Liu


> 在 2020年8月23日,20:23,Hongcheng Zhong  写道:
> 
> From: spartazhc 
> 
> Add abr option, ffplay can play hls using abr by:
> ffplay -i http://xxx/master.m3u8 -abr
> 
> Structure ABRList is added to save stream type and index, it is
> used to allow packet_queue_put function to put pkt which from same
> type(for example: video pkt) but different stream index to queue.
> 
> Signed-off-by: spartazhc 
> 
> v1 fixed:
> None.
> 
> v2 fixed:
> 1. check malloc result and return error message
> 
> Signed-off-by: spartazhc 
> ---
> doc/ffplay.texi  |   2 +
> fftools/ffplay.c | 151 ---
> 2 files changed, 144 insertions(+), 9 deletions(-)
> 
> diff --git a/doc/ffplay.texi b/doc/ffplay.texi
> index f3761bb12e..6a24542cda 100644
> --- a/doc/ffplay.texi
> +++ b/doc/ffplay.texi
> @@ -46,6 +46,8 @@ Disable audio.
> Disable video.
> @item -sn
> Disable subtitles.
> +@item -abr
> +Enable adaptive bitrate for hls/dash.
> @item -ss @var{pos}
> Seek to @var{pos}. Note that in most formats it is not possible to seek
> exactly, so @command{ffplay} will seek to the nearest seek point to
> diff --git a/fftools/ffplay.c b/fftools/ffplay.c
> index 6c9c041e9a..30944ba4be 100644
> --- a/fftools/ffplay.c
> +++ b/fftools/ffplay.c
> @@ -201,6 +201,15 @@ typedef struct Decoder {
> SDL_Thread *decoder_tid;
> } Decoder;
> 
> +typedef struct ABRList {
> +int **audio_list;
> +int audios;
> +int **video_list;
> +int videos;
> +int **sub_list;
> +int subs;
> +} ABRList;
> +
> typedef struct VideoState {
> SDL_Thread *read_tid;
> AVInputFormat *iformat;
> @@ -305,6 +314,8 @@ typedef struct VideoState {
> int last_video_stream, last_audio_stream, last_subtitle_stream;
> 
> SDL_cond *continue_read_thread;
> +
> +ABRList *abr_list;
> } VideoState;
> 
> /* options specified by the user */
> @@ -356,6 +367,7 @@ static char *afilters = NULL;
> static int autorotate = 1;
> static int find_stream_info = 1;
> static int filter_nbthreads = 0;
> +static int abr = 0;
> 
> /* current context */
> static int is_full_screen;
> @@ -1262,6 +1274,29 @@ static void stream_component_close(VideoState *is, int 
> stream_index)
> }
> }
> 
> +static void free_abr_dynarray(int **list, int num)
> +{
> +for (int i = 0; i < num; i++) {
> +av_free(list[i]);
> +}
> +}
> +
> +static void free_abr_list(ABRList *abrlist)
> +{
> +if (abrlist->audios) {
> +free_abr_dynarray(abrlist->audio_list, abrlist->audios);
> +av_freep(&abrlist->audio_list);
> +}
> +if (abrlist->videos) {
> +free_abr_dynarray(abrlist->video_list, abrlist->videos);
> +av_freep(&abrlist->video_list);
> +}
> +if (abrlist->subs) {
> +free_abr_dynarray(abrlist->sub_list, abrlist->subs);
> +av_freep(&abrlist->sub_list);
> +}
> +}
> +
> static void stream_close(VideoState *is)
> {
> /* XXX: use a special url_shutdown call to abort parse cleanly */
> @@ -2753,6 +2788,67 @@ static int is_realtime(AVFormatContext *s)
> return 0;
> }
> 
> +static av_cold int abr_init_list(VideoState *is)
> +{
> +int stream_index, *tmp;
> +AVStream *st;
> +int nb_streams = is->ic->nb_streams;
> +ABRList *abrlist = is->abr_list;
> +
> +for (stream_index = 0; stream_index < nb_streams; stream_index++) {
> +st = is->ic->streams[stream_index];
> +tmp = av_memdup(&stream_index, sizeof(int));
> +if (!tmp)
> +return AVERROR(ENOMEM);
> +switch (st->codecpar->codec_type) {
> +case AVMEDIA_TYPE_AUDIO:
> +av_dynarray_add(&abrlist->audio_list, &abrlist->audios, tmp);
> +break;
> +case AVMEDIA_TYPE_VIDEO:
> +av_dynarray_add(&abrlist->video_list, &abrlist->videos, tmp);
> +break;
> +case AVMEDIA_TYPE_SUBTITLE:
> +av_dynarray_add(&abrlist->sub_list, &abrlist->subs, tmp);
> +break;
> +default:
> +av_free(tmp);
> +break;
> +}
> +}
> +return 0;
> +}
> +
> +static int abr_check_list(ABRList *abr_list, enum AVMediaType type, int st)
> +{
> +int **st_list;
> +int n_st;
> +switch (type) {
> +case AVMEDIA_TYPE_AUDIO:
> +st_list = abr_list->audio_list;
> +n_st = abr_list->audios;
> +break;
> +case AVMEDIA_TYPE_VIDEO:
> +st_list = abr_list->video_list;
> +n_st = abr_list->videos;
> +break;
> +case AVMEDIA_TYPE_SUBTITLE:
> +st_list = abr_list->sub_list;
> +n_st = abr_list->subs;
> +break;
> +default:
> +break;
> +}
> +if (!st_list)
> +return 0;
> +for (int i = 0; i < n_st; i++) {
> +if (*st_list[i] == st)
> +return 1;
> +}
> +return 0;
> +}
> +
> +
> +
> /* this thread gets the stream from the disk or the network */
> 

[FFmpeg-devel] [PATCH 2/2] Add mutithread function for dnn_backend_native_layer_conv2d.c

2020-09-03 Thread xujunzz
From: Xu Jun 

Use pthread to multithread dnn_execute_layer_conv2d.
Can be tested with command "./ffmpeg_g -i input.png -vf \
format=yuvj420p,dnn_processing=dnn_backend=native:model= \
espcn.model:input=x:output=y:options=conv2d_threads=23 \
 -y sr_native.jpg -benchmark"

before patch: utime=11.238s stime=0.005s rtime=11.248s
after patch:  utime=20.817s stime=0.047s rtime=1.051s
on my 3900X 12c24t @4.2GHz

About the increase of utime, it's because that CPU HyperThreading
technology makes logical cores twice of physical cores while cpu's
counting performance improves less than double. And utime sums
all cpu's logical cores' runtime. As a result, using threads num
near cpu's logical core's number will double utime, while reduce
rtime less than half for HyperThreading CPUs.

Signed-off-by: Xu Jun 
---
 .../dnn/dnn_backend_native_layer_conv2d.c | 92 ---
 1 file changed, 81 insertions(+), 11 deletions(-)

diff --git a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c 
b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c
index d079795bf8..8da99540ed 100644
--- a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c
+++ b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c
@@ -19,10 +19,27 @@
  */
 
 #include "libavutil/avassert.h"
+#include "libavutil/thread.h"
+#include "libavutil/cpu.h"
 #include "dnn_backend_native_layer_conv2d.h"
 
 #define CLAMP_TO_EDGE(x, w) ((x) < 0 ? 0 : ((x) >= (w) ? (w - 1) : (x)))
 
+//struct to pass parameters
+typedef struct thread_common_param{
+DnnOperand *operands;
+const int32_t *input_operand_indexes;
+int32_t output_operand_index;
+const void *parameters;
+NativeContext *ctx;
+int thread_num;
+} thread_common_param;
+
+typedef struct thread_param{
+thread_common_param *thread_common_param;
+int thread_index
+} thread_param;
+
 int dnn_load_layer_conv2d(Layer *layer, AVIOContext *model_file_context, int 
file_size, int operands_num)
 {
 ConvolutionalParams *conv_params;
@@ -88,17 +105,20 @@ int dnn_load_layer_conv2d(Layer *layer, AVIOContext 
*model_file_context, int fil
 return dnn_size;
 }
 
-int dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t 
*input_operand_indexes,
- int32_t output_operand_index, const void 
*parameters, NativeContext *ctx)
+static void * dnn_execute_layer_conv2d_thread(void *threadarg)
 {
+//pass parameters
+thread_param *thread_param = (struct thread_param *)threadarg;
+thread_common_param *thread_common_param = 
thread_param->thread_common_param;
+DnnOperand *operands = thread_common_param->operands;
 float *output;
-int32_t input_operand_index = input_operand_indexes[0];
+int32_t input_operand_index = 
thread_common_param->input_operand_indexes[0];
 int number = operands[input_operand_index].dims[0];
 int height = operands[input_operand_index].dims[1];
 int width = operands[input_operand_index].dims[2];
 int channel = operands[input_operand_index].dims[3];
 const float *input = operands[input_operand_index].data;
-const ConvolutionalParams *conv_params = (const ConvolutionalParams 
*)parameters;
+const ConvolutionalParams *conv_params = (const ConvolutionalParams 
*)(thread_common_param->parameters);
 
 int radius = conv_params->kernel_size >> 1;
 int src_linesize = width * conv_params->input_num;
@@ -106,7 +126,11 @@ int dnn_execute_layer_conv2d(DnnOperand *operands, const 
int32_t *input_operand_
 int filter_size = conv_params->kernel_size * filter_linesize;
 int pad_size = (conv_params->padding_method == VALID) ? 
(conv_params->kernel_size - 1) / 2 * conv_params->dilation : 0;
 
-DnnOperand *output_operand = &operands[output_operand_index];
+int thread_stride = (height - pad_size * 2) / 
thread_common_param->thread_num;
+int thread_start = thread_stride * thread_param->thread_index + pad_size;
+int thread_end = (thread_param->thread_index == 
thread_common_param->thread_num - 1) ? (height - pad_size) : (thread_start + 
thread_stride);
+
+DnnOperand *output_operand = 
&operands[thread_common_param->output_operand_index];
 output_operand->dims[0] = number;
 output_operand->dims[1] = height - pad_size * 2;
 output_operand->dims[2] = width - pad_size * 2;
@@ -114,19 +138,21 @@ int dnn_execute_layer_conv2d(DnnOperand *operands, const 
int32_t *input_operand_
 output_operand->data_type = operands[input_operand_index].data_type;
 output_operand->length = calculate_operand_data_length(output_operand);
 if (output_operand->length <= 0) {
-av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n");
-return DNN_ERROR;
+av_log(thread_common_param->ctx, AV_LOG_ERROR, "The output data length 
overflow\n");
+return (void *)DNN_ERROR;
 }
 output_operand->data = av_realloc(output_operand->data, 
output_operand->length);
 if (!output_operand->data) {
-av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory 

[FFmpeg-devel] [PATCH 1/2] dnn_backend_native.c: parse options in native backend

2020-09-03 Thread xujunzz
From: Xu Jun 

Signed-off-by: Xu Jun 
---
 libavfilter/dnn/dnn_backend_native.c | 22 --
 libavfilter/dnn/dnn_backend_native.h | 13 +
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/libavfilter/dnn/dnn_backend_native.c 
b/libavfilter/dnn/dnn_backend_native.c
index a8fe6b94eb..83205aac72 100644
--- a/libavfilter/dnn/dnn_backend_native.c
+++ b/libavfilter/dnn/dnn_backend_native.c
@@ -31,7 +31,7 @@
 static const AVClass dnn_native_class = {
 .class_name = "dnn_native",
 .item_name  = av_default_item_name,
-.option = NULL,
+.option = dnn_native_options,
 .version= LIBAVUTIL_VERSION_INT,
 .category   = AV_CLASS_CATEGORY_FILTER,
 };
@@ -112,6 +112,22 @@ static DNNReturnType set_input_native(void *model, DNNData 
*input, const char *i
 return DNN_SUCCESS;
 }
 
+static int dnn_parse_options(void *ctx, const char *options)
+{
+AVDictionary *dict = NULL;
+int err = av_dict_parse_string(&dict, options, "=", "&", 0);
+if (err < 0) {
+av_dict_free(&dict);
+return err;
+}
+
+av_opt_set_defaults(ctx);
+err = av_opt_set_dict(ctx, &dict);
+
+av_dict_free(&dict);
+return err;
+}
+
 // Loads model and its parameters that are stored in a binary file with 
following structure:
 // layers_num,layer_type,layer_parameterss,layer_type,layer_parameters...
 // For CONV layer: activation_function, input_num, output_num, kernel_size, 
kernel, biases
@@ -174,6 +190,9 @@ DNNModel *ff_dnn_load_model_native(const char 
*model_filename, const char *optio
 }
 
 native_model->ctx.class = &dnn_native_class;
+model->options = options;
+if (dnn_parse_options(&native_model->ctx, model->options) < 0)
+goto fail;
 model->model = (void *)native_model;
 
 avio_seek(model_file_context, file_size - 8, SEEK_SET);
@@ -248,7 +267,6 @@ DNNModel *ff_dnn_load_model_native(const char 
*model_filename, const char *optio
 
 model->set_input = &set_input_native;
 model->get_input = &get_input_native;
-model->options = options;
 
 return model;
 
diff --git a/libavfilter/dnn/dnn_backend_native.h 
b/libavfilter/dnn/dnn_backend_native.h
index 197f557dee..a19b9a4233 100644
--- a/libavfilter/dnn/dnn_backend_native.h
+++ b/libavfilter/dnn/dnn_backend_native.h
@@ -29,6 +29,7 @@
 
 #include "../dnn_interface.h"
 #include "libavformat/avio.h"
+#include "libavutil/opt.h"
 
 /**
  * the enum value of DNNLayerType should not be changed,
@@ -106,10 +107,22 @@ typedef struct InputParams{
 int height, width, channels;
 } InputParams;
 
+typedef struct NativeOptions{
+uint32_t conv2d_threads;
+} NativeOptions;
+
 typedef struct NativeContext {
 const AVClass *class;
+NativeOptions options;
 } NativeContext;
 
+#define OFFSET(x) offsetof(NativeContext, x)
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM
+static const AVOption dnn_native_options[] = {
+{ "conv2d_threads", "threads num for conv2d layer", 
OFFSET(options.conv2d_threads), AV_OPT_TYPE_INT,  { .i64 = 0 }, INT_MIN, 
INT_MAX, FLAGS },
+{ NULL },
+};
+
 // Represents simple feed-forward convolutional network.
 typedef struct NativeModel{
 NativeContext ctx;
-- 
2.28.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-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [aarch64] yuv2planeX - unroll outer loop by 4 to increase performance by 6.3%

2020-09-03 Thread Sebastian Pop
On Wed, Aug 19, 2020 at 6:55 AM Michael Niedermayer 
wrote:

> faster is better obviously, so if its tested with odd sizes and arm
> developers had a chance to comment. it should be ok


Hi, I'm looking for feedback from ARM maintainers on the attached patch.
Ok to commit the patch?

Thanks,
Sebastian

On Wed, Aug 19, 2020 at 1:37 PM Sebastian Pop  wrote:

> Thanks Michael for your feedback.
>
> On Wed, Aug 19, 2020 at 6:55 AM Michael Niedermayer 
> wrote:
>
>> faster is better obviously, so if its tested with odd sizes and arm
>> developers had a chance to comment. it should be ok
>>
>>
> The current patch was tested with `make check` on Arm64 Graviton2.
> I also have tested randomly selected rescale factors, for example:
> ./ffmpeg -nostats -f lavfi -i testsrc2=4k:d=2 -vf
> bench=start,scale=1023x42,bench=stop -f null -
>
>
>> one potential improvment is to use the unrolled code for odd width
>> too and use the non unrolled for the end
>>
>
> Done.  Please see the amended patch.
>
> Thanks,
> Sebastian
>


0001-aarch64-yuv2planeX-unroll-outer-loop-by-4-increases-.patch
Description: Binary data
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] avcodec/dxtory: unbreak decoding after 6e1a167c556

2020-09-03 Thread Paul B Mahol
get_unary() takes at minimum only 1 bit.

Signed-off-by: Paul B Mahol 
---

As this is important fix, will apply in next 5 minutes.
I kindly ask authors of various timeouts changes to kindly
test their changes more carefully.

---
 libavcodec/dxtory.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavcodec/dxtory.c b/libavcodec/dxtory.c
index bc19f27951..3cd95afe80 100644
--- a/libavcodec/dxtory.c
+++ b/libavcodec/dxtory.c
@@ -395,7 +395,7 @@ static int dx2_decode_slice_5x5(GetBitContext *gb, AVFrame 
*frame,
 int stride   = frame->linesize[0];
 uint8_t *dst = frame->data[0] + stride * line;
 
-for (y = 0; y < left && get_bits_left(gb) > 6 * width; y++) {
+for (y = 0; y < left && get_bits_left(gb) >= 3 * width; y++) {
 for (x = 0; x < width; x++) {
 b = decode_sym_565(gb, lru[0], 5);
 g = decode_sym_565(gb, lru[1], is_565 ? 6 : 5);
@@ -462,7 +462,7 @@ static int dx2_decode_slice_rgb(GetBitContext *gb, AVFrame 
*frame,
 int stride   = frame->linesize[0];
 uint8_t *dst = frame->data[0] + stride * line;
 
-for (y = 0; y < left && get_bits_left(gb) > 6 * width; y++) {
+for (y = 0; y < left && get_bits_left(gb) >= 3 * width; y++) {
 for (x = 0; x < width; x++) {
 dst[x * 3 + 0] = decode_sym(gb, lru[0]);
 dst[x * 3 + 1] = decode_sym(gb, lru[1]);
@@ -508,7 +508,7 @@ static int dx2_decode_slice_410(GetBitContext *gb, AVFrame 
*frame,
 uint8_t *U  = frame->data[1] + (ustride >> 2) * line;
 uint8_t *V  = frame->data[2] + (vstride >> 2) * line;
 
-for (y = 0; y < left - 3 && get_bits_left(gb) > 9 * width; y += 4) {
+for (y = 0; y < left - 3 && get_bits_left(gb) >= 4 * width; y += 4) {
 for (x = 0; x < width; x += 4) {
 for (j = 0; j < 4; j++)
 for (i = 0; i < 4; i++)
@@ -553,7 +553,7 @@ static int dx2_decode_slice_420(GetBitContext *gb, AVFrame 
*frame,
 uint8_t *V  = frame->data[2] + (vstride >> 1) * line;
 
 
-for (y = 0; y < left - 1 && get_bits_left(gb) > 6 * width; y += 2) {
+for (y = 0; y < left - 1 && get_bits_left(gb) >= 3 * width; y += 2) {
 for (x = 0; x < width; x += 2) {
 Y[x + 0 + 0 * ystride] = decode_sym(gb, lru[0]);
 Y[x + 1 + 0 * ystride] = decode_sym(gb, lru[0]);
@@ -597,7 +597,7 @@ static int dx2_decode_slice_444(GetBitContext *gb, AVFrame 
*frame,
 uint8_t *U  = frame->data[1] + ustride * line;
 uint8_t *V  = frame->data[2] + vstride * line;
 
-for (y = 0; y < left && get_bits_left(gb) > 6 * width; y++) {
+for (y = 0; y < left && get_bits_left(gb) >= 3 * width; y++) {
 for (x = 0; x < width; x++) {
 Y[x] = decode_sym(gb, lru[0]);
 U[x] = decode_sym(gb, lru[1]) ^ 0x80;
-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avcodec/dxtory: unbreak decoding after 6e1a167c556

2020-09-03 Thread Nicolas George
Paul B Mahol (12020-09-03):
> get_unary() takes at minimum only 1 bit.
> 
> Signed-off-by: Paul B Mahol 
> ---
> 
> As this is important fix, will apply in next 5 minutes.

Five minutes, for an important fix of a commit that was there for
eighteen months? Please.

Like any other fix, wait for review.

-- 
  Nicolas George


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avcodec/dxtory: unbreak decoding after 6e1a167c556

2020-09-03 Thread James Almer
On 9/3/2020 2:03 PM, Paul B Mahol wrote:
> get_unary() takes at minimum only 1 bit.
> 
> Signed-off-by: Paul B Mahol 
> ---
> 
> As this is important fix, will apply in next 5 minutes.
> I kindly ask authors of various timeouts changes to kindly
> test their changes more carefully.

That change is two years and a half old by now. Maybe the decoder needs
a fate test, seeing how it's barely used so we can't rely on users
finding such regressions in a timely manner.

> 
> ---
>  libavcodec/dxtory.c | 10 +-
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/libavcodec/dxtory.c b/libavcodec/dxtory.c
> index bc19f27951..3cd95afe80 100644
> --- a/libavcodec/dxtory.c
> +++ b/libavcodec/dxtory.c
> @@ -395,7 +395,7 @@ static int dx2_decode_slice_5x5(GetBitContext *gb, 
> AVFrame *frame,
>  int stride   = frame->linesize[0];
>  uint8_t *dst = frame->data[0] + stride * line;
>  
> -for (y = 0; y < left && get_bits_left(gb) > 6 * width; y++) {
> +for (y = 0; y < left && get_bits_left(gb) >= 3 * width; y++) {
>  for (x = 0; x < width; x++) {
>  b = decode_sym_565(gb, lru[0], 5);
>  g = decode_sym_565(gb, lru[1], is_565 ? 6 : 5);
> @@ -462,7 +462,7 @@ static int dx2_decode_slice_rgb(GetBitContext *gb, 
> AVFrame *frame,
>  int stride   = frame->linesize[0];
>  uint8_t *dst = frame->data[0] + stride * line;
>  
> -for (y = 0; y < left && get_bits_left(gb) > 6 * width; y++) {
> +for (y = 0; y < left && get_bits_left(gb) >= 3 * width; y++) {
>  for (x = 0; x < width; x++) {
>  dst[x * 3 + 0] = decode_sym(gb, lru[0]);
>  dst[x * 3 + 1] = decode_sym(gb, lru[1]);
> @@ -508,7 +508,7 @@ static int dx2_decode_slice_410(GetBitContext *gb, 
> AVFrame *frame,
>  uint8_t *U  = frame->data[1] + (ustride >> 2) * line;
>  uint8_t *V  = frame->data[2] + (vstride >> 2) * line;
>  
> -for (y = 0; y < left - 3 && get_bits_left(gb) > 9 * width; y += 4) {
> +for (y = 0; y < left - 3 && get_bits_left(gb) >= 4 * width; y += 4) {
>  for (x = 0; x < width; x += 4) {
>  for (j = 0; j < 4; j++)
>  for (i = 0; i < 4; i++)
> @@ -553,7 +553,7 @@ static int dx2_decode_slice_420(GetBitContext *gb, 
> AVFrame *frame,
>  uint8_t *V  = frame->data[2] + (vstride >> 1) * line;
>  
>  
> -for (y = 0; y < left - 1 && get_bits_left(gb) > 6 * width; y += 2) {
> +for (y = 0; y < left - 1 && get_bits_left(gb) >= 3 * width; y += 2) {
>  for (x = 0; x < width; x += 2) {
>  Y[x + 0 + 0 * ystride] = decode_sym(gb, lru[0]);
>  Y[x + 1 + 0 * ystride] = decode_sym(gb, lru[0]);
> @@ -597,7 +597,7 @@ static int dx2_decode_slice_444(GetBitContext *gb, 
> AVFrame *frame,
>  uint8_t *U  = frame->data[1] + ustride * line;
>  uint8_t *V  = frame->data[2] + vstride * line;
>  
> -for (y = 0; y < left && get_bits_left(gb) > 6 * width; y++) {
> +for (y = 0; y < left && get_bits_left(gb) >= 3 * width; y++) {
>  for (x = 0; x < width; x++) {
>  Y[x] = decode_sym(gb, lru[0]);
>  U[x] = decode_sym(gb, lru[1]) ^ 0x80;
> 

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avcodec/dxtory: unbreak decoding after 6e1a167c556

2020-09-03 Thread Paul B Mahol
On 9/3/20, Nicolas George  wrote:
> Paul B Mahol (12020-09-03):
>> get_unary() takes at minimum only 1 bit.
>>
>> Signed-off-by: Paul B Mahol 
>> ---
>>
>> As this is important fix, will apply in next 5 minutes.
>
> Five minutes, for an important fix of a commit that was there for
> eighteen months? Please.
>
> Like any other fix, wait for review.

Ah, you still here !

I wondered will you get bait
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avcodec/dxtory: unbreak decoding after 6e1a167c556

2020-09-03 Thread Nicolas George
Paul B Mahol (12020-09-03):
> I wondered will you get bait

Was this the only reason you threatened to commit without review?

-- 
  Nicolas George


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] avformat/dashdec: only limit DASH manifest size according to AVBprint limits

2020-09-03 Thread Jan Ekström
Currently the API is internally limited to unsigned integers, so if we
limit the file size as well as the amount to read to UINT_MAX - 1, we
do not require additional limiting to be performed on the values.

This change is based on the fact that initially the 8*1024 value added
in 96d70694aea64616c68db8be306c159c73fb3980 was only for the case where
the file size was not known. It was not a maximum file size limit.

In 29121188983932f79aef8501652630d322a9974c this was reworked to be
a maximum manifest file size limit, while its commit message appears
to only note that it added support for larger manifest file sizes.

This should enable various unfortunately large MPEG-DASH manifests,
such as Youtube's multi-megabyte live stream archives to load up
as well as bring back the original intent of the logic.
---
 libavformat/dashdec.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
index c5a5ff607b..1e9985f32c 100644
--- a/libavformat/dashdec.c
+++ b/libavformat/dashdec.c
@@ -29,7 +29,7 @@
 #include "dash.h"
 
 #define INITIAL_BUFFER_SIZE 32768
-#define MAX_MANIFEST_SIZE 50 * 1024
+#define MAX_BPRINT_READ_SIZE (UINT_MAX - 1)
 #define DEFAULT_MANIFEST_SIZE 8 * 1024
 
 struct fragment {
@@ -1256,14 +1256,16 @@ static int parse_manifest(AVFormatContext *s, const 
char *url, AVIOContext *in)
 }
 
 filesize = avio_size(in);
-if (filesize > MAX_MANIFEST_SIZE) {
+filesize = filesize > 0 ? filesize : DEFAULT_MANIFEST_SIZE;
+
+if (filesize > MAX_BPRINT_READ_SIZE) {
 av_log(s, AV_LOG_ERROR, "Manifest too large: %"PRId64"\n", filesize);
 return AVERROR_INVALIDDATA;
 }
 
-av_bprint_init(&buf, (filesize > 0) ? filesize + 1 : 
DEFAULT_MANIFEST_SIZE, AV_BPRINT_SIZE_UNLIMITED);
+av_bprint_init(&buf, filesize + 1, AV_BPRINT_SIZE_UNLIMITED);
 
-if ((ret = avio_read_to_bprint(in, &buf, MAX_MANIFEST_SIZE)) < 0 ||
+if ((ret = avio_read_to_bprint(in, &buf, MAX_BPRINT_READ_SIZE)) < 0 ||
 !avio_feof(in) ||
 (filesize = buf.len) == 0) {
 av_log(s, AV_LOG_ERROR, "Unable to read to manifest '%s'\n", url);
-- 
2.26.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/4] avformat/mov: Fix return type used for av_seek in mfra code

2020-09-03 Thread Derek Buitenhuis
On 03/09/2020 14:47, Paul B Mahol wrote:
> Of course LGTM.

Pushed.

- Derek
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] avformat/yuv4mpegenc: simplify writing the header

2020-09-03 Thread James Almer
Actually write it in yuv4_write_header() instead of with the first
packet.

Signed-off-by: James Almer 
---
 libavformat/yuv4mpegenc.c | 35 ++-
 1 file changed, 14 insertions(+), 21 deletions(-)

diff --git a/libavformat/yuv4mpegenc.c b/libavformat/yuv4mpegenc.c
index e84dbf9568..c4781042bd 100644
--- a/libavformat/yuv4mpegenc.c
+++ b/libavformat/yuv4mpegenc.c
@@ -26,14 +26,16 @@
 
 #define Y4M_LINE_MAX 256
 
-static int yuv4_generate_header(AVFormatContext *s, char* buf)
+static int yuv4_write_header(AVFormatContext *s)
 {
 AVStream *st;
+AVIOContext *pb = s->pb;
 int width, height;
 int raten, rated, aspectn, aspectd, n;
 char inter;
 const char *colorspace = "";
 const char *colorrange = "";
+char buf[Y4M_LINE_MAX + 1];
 int field_order;
 
 st = s->streams[0];
@@ -173,7 +175,15 @@ static int yuv4_generate_header(AVFormatContext *s, char* 
buf)
  Y4M_MAGIC, width, height, raten, rated, inter,
  aspectn, aspectd, colorspace, colorrange);
 
-return n;
+if (n < 0) {
+av_log(s, AV_LOG_ERROR,
+   "Error. YUV4MPEG stream header write failed.\n");
+return AVERROR(EIO);
+}
+
+avio_write(pb, buf, strlen(buf));
+
+return 0;
 }
 
 
@@ -182,26 +192,12 @@ static int yuv4_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 AVStream *st = s->streams[pkt->stream_index];
 AVIOContext *pb = s->pb;
 AVFrame *frame;
-int* first_pkt = s->priv_data;
 int width, height, h_chroma_shift, v_chroma_shift;
 int i;
-char buf2[Y4M_LINE_MAX + 1];
 uint8_t *ptr, *ptr1, *ptr2;
 
 frame = (AVFrame *)pkt->data;
 
-/* for the first packet we have to output the header as well */
-if (*first_pkt) {
-*first_pkt = 0;
-if (yuv4_generate_header(s, buf2) < 0) {
-av_log(s, AV_LOG_ERROR,
-   "Error. YUV4MPEG stream header write failed.\n");
-return AVERROR(EIO);
-} else {
-avio_write(pb, buf2, strlen(buf2));
-}
-}
-
 /* construct frame header */
 
 avio_printf(s->pb, "%s\n", Y4M_FRAME_MAGIC);
@@ -279,10 +275,8 @@ static int yuv4_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 return 0;
 }
 
-static int yuv4_write_header(AVFormatContext *s)
+static int yuv4_init(AVFormatContext *s)
 {
-int *first_pkt = s->priv_data;
-
 if (s->nb_streams != 1)
 return AVERROR(EIO);
 
@@ -347,7 +341,6 @@ static int yuv4_write_header(AVFormatContext *s)
 return AVERROR(EIO);
 }
 
-*first_pkt = 1;
 return 0;
 }
 
@@ -355,9 +348,9 @@ AVOutputFormat ff_yuv4mpegpipe_muxer = {
 .name  = "yuv4mpegpipe",
 .long_name = NULL_IF_CONFIG_SMALL("YUV4MPEG pipe"),
 .extensions= "y4m",
-.priv_data_size= sizeof(int),
 .audio_codec   = AV_CODEC_ID_NONE,
 .video_codec   = AV_CODEC_ID_WRAPPED_AVFRAME,
+.init  = yuv4_init,
 .write_header  = yuv4_write_header,
 .write_packet  = yuv4_write_packet,
 };
-- 
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-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avformat/yuv4mpegenc: simplify writing the header

2020-09-03 Thread Paul B Mahol
On 9/3/20, James Almer  wrote:
> Actually write it in yuv4_write_header() instead of with the first
> packet.
>
> Signed-off-by: James Almer 
> ---
>  libavformat/yuv4mpegenc.c | 35 ++-
>  1 file changed, 14 insertions(+), 21 deletions(-)
>

Nice catch, LGTM

> diff --git a/libavformat/yuv4mpegenc.c b/libavformat/yuv4mpegenc.c
> index e84dbf9568..c4781042bd 100644
> --- a/libavformat/yuv4mpegenc.c
> +++ b/libavformat/yuv4mpegenc.c
> @@ -26,14 +26,16 @@
>
>  #define Y4M_LINE_MAX 256
>
> -static int yuv4_generate_header(AVFormatContext *s, char* buf)
> +static int yuv4_write_header(AVFormatContext *s)
>  {
>  AVStream *st;
> +AVIOContext *pb = s->pb;
>  int width, height;
>  int raten, rated, aspectn, aspectd, n;
>  char inter;
>  const char *colorspace = "";
>  const char *colorrange = "";
> +char buf[Y4M_LINE_MAX + 1];
>  int field_order;
>
>  st = s->streams[0];
> @@ -173,7 +175,15 @@ static int yuv4_generate_header(AVFormatContext *s,
> char* buf)
>   Y4M_MAGIC, width, height, raten, rated, inter,
>   aspectn, aspectd, colorspace, colorrange);
>
> -return n;
> +if (n < 0) {
> +av_log(s, AV_LOG_ERROR,
> +   "Error. YUV4MPEG stream header write failed.\n");
> +return AVERROR(EIO);
> +}
> +
> +avio_write(pb, buf, strlen(buf));
> +
> +return 0;
>  }
>
>
> @@ -182,26 +192,12 @@ static int yuv4_write_packet(AVFormatContext *s,
> AVPacket *pkt)
>  AVStream *st = s->streams[pkt->stream_index];
>  AVIOContext *pb = s->pb;
>  AVFrame *frame;
> -int* first_pkt = s->priv_data;
>  int width, height, h_chroma_shift, v_chroma_shift;
>  int i;
> -char buf2[Y4M_LINE_MAX + 1];
>  uint8_t *ptr, *ptr1, *ptr2;
>
>  frame = (AVFrame *)pkt->data;
>
> -/* for the first packet we have to output the header as well */
> -if (*first_pkt) {
> -*first_pkt = 0;
> -if (yuv4_generate_header(s, buf2) < 0) {
> -av_log(s, AV_LOG_ERROR,
> -   "Error. YUV4MPEG stream header write failed.\n");
> -return AVERROR(EIO);
> -} else {
> -avio_write(pb, buf2, strlen(buf2));
> -}
> -}
> -
>  /* construct frame header */
>
>  avio_printf(s->pb, "%s\n", Y4M_FRAME_MAGIC);
> @@ -279,10 +275,8 @@ static int yuv4_write_packet(AVFormatContext *s,
> AVPacket *pkt)
>  return 0;
>  }
>
> -static int yuv4_write_header(AVFormatContext *s)
> +static int yuv4_init(AVFormatContext *s)
>  {
> -int *first_pkt = s->priv_data;
> -
>  if (s->nb_streams != 1)
>  return AVERROR(EIO);
>
> @@ -347,7 +341,6 @@ static int yuv4_write_header(AVFormatContext *s)
>  return AVERROR(EIO);
>  }
>
> -*first_pkt = 1;
>  return 0;
>  }
>
> @@ -355,9 +348,9 @@ AVOutputFormat ff_yuv4mpegpipe_muxer = {
>  .name  = "yuv4mpegpipe",
>  .long_name = NULL_IF_CONFIG_SMALL("YUV4MPEG pipe"),
>  .extensions= "y4m",
> -.priv_data_size= sizeof(int),
>  .audio_codec   = AV_CODEC_ID_NONE,
>  .video_codec   = AV_CODEC_ID_WRAPPED_AVFRAME,
> +.init  = yuv4_init,
>  .write_header  = yuv4_write_header,
>  .write_packet  = yuv4_write_packet,
>  };
> --
> 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-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v3] avformat: add mca demuxer

2020-09-03 Thread Paul B Mahol
On 9/3/20, liush...@aosc.io  wrote:
> From: Zixing Liu 
>
> Signed-off-by: liushuyu 
> ---
>  Changelog|   1 +
>  doc/general.texi |   2 +
>  libavformat/Makefile |   1 +
>  libavformat/allformats.c |   1 +
>  libavformat/mca.c| 228 +++
>  libavformat/version.h|   4 +-
>  6 files changed, 235 insertions(+), 2 deletions(-)
>  create mode 100644 libavformat/mca.c
>
> diff --git a/Changelog b/Changelog
> index 7467e73..ae4219f 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -15,6 +15,7 @@ version :
>  - Argonaut Games ASF muxer
>  - AV1 Low overhead bitstream format demuxer
>  - RPZA video encoder
> +- MCA demuxer
>
>
>  version 4.3:
> diff --git a/doc/general.texi b/doc/general.texi
> index d618565..fa76ed4 100644
> --- a/doc/general.texi
> +++ b/doc/general.texi
> @@ -524,6 +524,8 @@ library:
>  @tab Metadata in text format.
>  @item MAXIS XA  @tab   @tab X
>  @tab Used in Sim City 3000; file extension .xa.
> +@item MCA   @tab   @tab X
> +@tab Used in some games from Capcom; file extension .mca.
>  @item MD Studio @tab   @tab X
>  @item Metal Gear Solid: The Twin Snakes @tab @tab X
>  @item Megalux Frame @tab   @tab X
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index cbb33fe..7f5ab21 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -305,6 +305,7 @@ OBJS-$(CONFIG_MATROSKA_MUXER)+=
> matroskaenc.o matroska.o \
>  av1.o avc.o hevc.o \
>  flacenc_header.o avlanguage.o \
>  vorbiscomment.o wv.o
> +OBJS-$(CONFIG_MCA_DEMUXER)   += mca.o
>  OBJS-$(CONFIG_MCC_DEMUXER)   += mccdec.o subtitles.o
>  OBJS-$(CONFIG_MD5_MUXER) += hashenc.o
>  OBJS-$(CONFIG_MGSTS_DEMUXER) += mgsts.o
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index 0aa9dd7..8a71de6 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -232,6 +232,7 @@ extern AVInputFormat  ff_lvf_demuxer;
>  extern AVInputFormat  ff_lxf_demuxer;
>  extern AVInputFormat  ff_m4v_demuxer;
>  extern AVOutputFormat ff_m4v_muxer;
> +extern AVInputFormat  ff_mca_demuxer;
>  extern AVInputFormat  ff_mcc_demuxer;
>  extern AVOutputFormat ff_md5_muxer;
>  extern AVInputFormat  ff_matroska_demuxer;
> diff --git a/libavformat/mca.c b/libavformat/mca.c
> new file mode 100644
> index 000..ad3fe48
> --- /dev/null
> +++ b/libavformat/mca.c
> @@ -0,0 +1,228 @@
> +/*
> + * MCA demuxer
> + * Copyright (c) 2020 Zixing Liu
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
> USA
> + */
> +
> +#include "libavutil/intreadwrite.h"
> +#include "avformat.h"
> +#include "avio_internal.h"
> +#include "internal.h"
> +
> +typedef struct MCADemuxContext {
> +uint32_t block_count;
> +uint16_t block_size;
> +uint32_t current_block;
> +uint32_t data_start;
> +uint32_t samples_per_block;
> +} MCADemuxContext;
> +
> +static int probe(const AVProbeData *p)
> +{
> +if (AV_RL32(p->buf) == MKTAG('M', 'A', 'D', 'P') &&
> +AV_RL16(p->buf + 4) <= 0xff)
> +return AVPROBE_SCORE_MAX / 3 * 2;
> +return 0;
> +}
> +
> +static int read_header(AVFormatContext *s)
> +{
> +AVStream *st;
> +MCADemuxContext *m = s->priv_data;
> +AVCodecParameters *par;
> +int64_t file_size = avio_size(s->pb);
> +uint16_t version = 0;
> +uint32_t header_size, data_size, data_offset, loop_start, loop_end,
> +nb_samples, nb_metadata, coef_offset = 0;
> +int ch, ret;
> +int64_t ret_size;
> +
> +st = avformat_new_stream(s, NULL);
> +if (!st)
> +return AVERROR(ENOMEM);
> +par = st->codecpar;
> +par->codec_type = AVMEDIA_TYPE_AUDIO;
> +
> +// parse file headers
> +avio_skip(s->pb, 0x4);  // skip the file magic
> +version  = avio_rl16(s->pb);
> +avio_skip(s->pb, 0x2);  // padding
> +par->channels= avio_r8(s->pb);
> +avio_skip(s->pb, 0x1);  // padding
> +m->block_size= avio_rl16(s->pb);
> +nb_samples   = avio_rl32(s

Re: [FFmpeg-devel] [PATCH] avformat/yuv4mpegenc: simplify writing the header

2020-09-03 Thread James Almer
On 9/3/2020 4:16 PM, Paul B Mahol wrote:
> On 9/3/20, James Almer  wrote:
>> Actually write it in yuv4_write_header() instead of with the first
>> packet.
>>
>> Signed-off-by: James Almer 
>> ---
>>  libavformat/yuv4mpegenc.c | 35 ++-
>>  1 file changed, 14 insertions(+), 21 deletions(-)
>>
> 
> Nice catch, LGTM

Pushed, thanks.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 2/2] Add mutithread function for dnn_backend_native_layer_conv2d.c

2020-09-03 Thread Michael Niedermayer
On Thu, Sep 03, 2020 at 11:57:24PM +0800, xuju...@sjtu.edu.cn wrote:
> From: Xu Jun 
> 
> Use pthread to multithread dnn_execute_layer_conv2d.
> Can be tested with command "./ffmpeg_g -i input.png -vf \
> format=yuvj420p,dnn_processing=dnn_backend=native:model= \
> espcn.model:input=x:output=y:options=conv2d_threads=23 \
>  -y sr_native.jpg -benchmark"
> 
> before patch: utime=11.238s stime=0.005s rtime=11.248s
> after patch:  utime=20.817s stime=0.047s rtime=1.051s
> on my 3900X 12c24t @4.2GHz
> 
> About the increase of utime, it's because that CPU HyperThreading
> technology makes logical cores twice of physical cores while cpu's
> counting performance improves less than double. And utime sums
> all cpu's logical cores' runtime. As a result, using threads num
> near cpu's logical core's number will double utime, while reduce
> rtime less than half for HyperThreading CPUs.
> 
> Signed-off-by: Xu Jun 
> ---
>  .../dnn/dnn_backend_native_layer_conv2d.c | 92 ---
>  1 file changed, 81 insertions(+), 11 deletions(-)

[...]

> +typedef struct thread_param{
> +thread_common_param *thread_common_param;
> +int thread_index

semicolon missing


[...]
> +//join threads, res gets function return
> +for (int i = 0; i < thread_num; i++){
> +pthread_join(thread_id[i], &res);

this should be under something like HAVE_PTHREAD_CANCEL

thx

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

He who knows, does not speak. He who speaks, does not know. -- Lao Tsu


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v3] avformat: add mca demuxer

2020-09-03 Thread Carl Eugen Hoyos
Am Do., 3. Sept. 2020 um 01:17 Uhr schrieb :

> +static int probe(const AVProbeData *p)
> +{
> +if (AV_RL32(p->buf) == MKTAG('M', 'A', 'D', 'P') &&
> +AV_RL16(p->buf + 4) <= 0xff)
> +return AVPROBE_SCORE_MAX / 3 * 2;
> +return 0;
> +}

> +if (version <= 4) {
> +// version <= 4 needs to use the file size to calculate the offsets
> +if (file_size < 0) {
> +return AVERROR(EIO);
> +}
> +if (file_size - data_size > UINT32_MAX)
> +return AVERROR_INVALIDDATA;
> +m->data_start = file_size - data_size;
> +if (version <= 3) {
> +nb_metadata = 0;
> +// header_size is not available or incorrect in older versions
> +header_size = m->data_start;
> +}
> +} else if (version == 5) {
> +// read data_start location from the header
> +if (0x30 * par->channels + 0x4 > header_size)
> +return AVERROR_INVALIDDATA;
> +data_offset = header_size - 0x30 * par->channels - 0x4;
> +if ((ret_size = avio_seek(s->pb, data_offset, SEEK_SET)) < 0)
> +return ret_size;
> +m->data_start = avio_rl32(s->pb);
> +// check if the metadata is reasonable
> +if (file_size > 0 && (int64_t)m->data_start + data_size > file_size) 
> {
> +// the header is broken beyond repair
> +if ((int64_t)header_size + data_size > file_size) {
> +av_log(s, AV_LOG_ERROR,
> +   "MCA metadata corrupted, unable to determine the data 
> offset.\n");
> +return AVERROR_INVALIDDATA;
> +}
> +// recover the data_start information from the data size
> +av_log(s, AV_LOG_WARNING,
> +   "Incorrect header size found in metadata, "
> +   "header size approximated from the data size\n");
> +if (file_size - data_offset > UINT32_MAX)
> +return AVERROR_INVALIDDATA;
> +m->data_start = file_size - data_size;
> +}
> +} else {
> +avpriv_request_sample(s, "version %d", version);
> +return AVERROR_PATCHWELCOME;
> +}

It seems to me that you are much stricter checking the version
when reading the header information than when probing the file
but if there is a difference, the probing should be stricter.

Please check in the probe function if version <= 5.

Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avcodec/dxtory: unbreak decoding after 6e1a167c556

2020-09-03 Thread Michael Niedermayer
On Thu, Sep 03, 2020 at 07:03:23PM +0200, Paul B Mahol wrote:
> get_unary() takes at minimum only 1 bit.
> 
> Signed-off-by: Paul B Mahol 
> ---
> 
> As this is important fix, will apply in next 5 minutes.
> I kindly ask authors of various timeouts changes to kindly
> test their changes more carefully.

Can you provide test samples and a fate test ?


> 
> ---
>  libavcodec/dxtory.c | 10 +-
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/libavcodec/dxtory.c b/libavcodec/dxtory.c
> index bc19f27951..3cd95afe80 100644
> --- a/libavcodec/dxtory.c
> +++ b/libavcodec/dxtory.c
> @@ -395,7 +395,7 @@ static int dx2_decode_slice_5x5(GetBitContext *gb, 
> AVFrame *frame,
>  int stride   = frame->linesize[0];
>  uint8_t *dst = frame->data[0] + stride * line;
>  
> -for (y = 0; y < left && get_bits_left(gb) > 6 * width; y++) {
> +for (y = 0; y < left && get_bits_left(gb) >= 3 * width; y++) {
>  for (x = 0; x < width; x++) {
>  b = decode_sym_565(gb, lru[0], 5);
>  g = decode_sym_565(gb, lru[1], is_565 ? 6 : 5);
> @@ -462,7 +462,7 @@ static int dx2_decode_slice_rgb(GetBitContext *gb, 
> AVFrame *frame,
>  int stride   = frame->linesize[0];
>  uint8_t *dst = frame->data[0] + stride * line;
>  
> -for (y = 0; y < left && get_bits_left(gb) > 6 * width; y++) {
> +for (y = 0; y < left && get_bits_left(gb) >= 3 * width; y++) {
>  for (x = 0; x < width; x++) {
>  dst[x * 3 + 0] = decode_sym(gb, lru[0]);
>  dst[x * 3 + 1] = decode_sym(gb, lru[1]);

> @@ -508,7 +508,7 @@ static int dx2_decode_slice_410(GetBitContext *gb, 
> AVFrame *frame,
>  uint8_t *U  = frame->data[1] + (ustride >> 2) * line;
>  uint8_t *V  = frame->data[2] + (vstride >> 2) * line;
>  
> -for (y = 0; y < left - 3 && get_bits_left(gb) > 9 * width; y += 4) {
> +for (y = 0; y < left - 3 && get_bits_left(gb) >= 4 * width; y += 4) {
>  for (x = 0; x < width; x += 4) {
>  for (j = 0; j < 4; j++)
>  for (i = 0; i < 4; i++)

iam not sure this is correct
let us consider the equal case occurs get_bits_left(gb) == 4 * width;
now this is read as 4x4 blocks, each will read a minimum of 18 bits 16 luma
and 2 chroma. 18*(width/4) == 4 * width doesnt look right

thx

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Asymptotically faster algorithms should always be preferred if you have
asymptotical amounts of data


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v3] avformat: add mca demuxer

2020-09-03 Thread liushuyu

On 2020-09-03 13:31, Paul B Mahol wrote:

On 9/3/20, liush...@aosc.io  wrote:

From: Zixing Liu 

Signed-off-by: liushuyu 
---
 Changelog|   1 +
 doc/general.texi |   2 +
 libavformat/Makefile |   1 +
 libavformat/allformats.c |   1 +
 libavformat/mca.c| 228 
+++

 libavformat/version.h|   4 +-
 6 files changed, 235 insertions(+), 2 deletions(-)
 create mode 100644 libavformat/mca.c

diff --git a/Changelog b/Changelog
index 7467e73..ae4219f 100644
--- a/Changelog
+++ b/Changelog
@@ -15,6 +15,7 @@ version :
 - Argonaut Games ASF muxer
 - AV1 Low overhead bitstream format demuxer
 - RPZA video encoder
+- MCA demuxer


 version 4.3:
diff --git a/doc/general.texi b/doc/general.texi
index d618565..fa76ed4 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -524,6 +524,8 @@ library:
 @tab Metadata in text format.
 @item MAXIS XA  @tab   @tab X
 @tab Used in Sim City 3000; file extension .xa.
+@item MCA   @tab   @tab X
+@tab Used in some games from Capcom; file extension .mca.
 @item MD Studio @tab   @tab X
 @item Metal Gear Solid: The Twin Snakes @tab @tab X
 @item Megalux Frame @tab   @tab X
diff --git a/libavformat/Makefile b/libavformat/Makefile
index cbb33fe..7f5ab21 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -305,6 +305,7 @@ OBJS-$(CONFIG_MATROSKA_MUXER)+=
matroskaenc.o matroska.o \
 av1.o avc.o hevc.o \
 flacenc_header.o 
avlanguage.o \

 vorbiscomment.o wv.o
+OBJS-$(CONFIG_MCA_DEMUXER)   += mca.o
 OBJS-$(CONFIG_MCC_DEMUXER)   += mccdec.o subtitles.o
 OBJS-$(CONFIG_MD5_MUXER) += hashenc.o
 OBJS-$(CONFIG_MGSTS_DEMUXER) += mgsts.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 0aa9dd7..8a71de6 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -232,6 +232,7 @@ extern AVInputFormat  ff_lvf_demuxer;
 extern AVInputFormat  ff_lxf_demuxer;
 extern AVInputFormat  ff_m4v_demuxer;
 extern AVOutputFormat ff_m4v_muxer;
+extern AVInputFormat  ff_mca_demuxer;
 extern AVInputFormat  ff_mcc_demuxer;
 extern AVOutputFormat ff_md5_muxer;
 extern AVInputFormat  ff_matroska_demuxer;
diff --git a/libavformat/mca.c b/libavformat/mca.c
new file mode 100644
index 000..ad3fe48
--- /dev/null
+++ b/libavformat/mca.c
@@ -0,0 +1,228 @@
+/*
+ * MCA demuxer
+ * Copyright (c) 2020 Zixing Liu
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
02110-1301

USA
+ */
+
+#include "libavutil/intreadwrite.h"
+#include "avformat.h"
+#include "avio_internal.h"
+#include "internal.h"
+
+typedef struct MCADemuxContext {
+uint32_t block_count;
+uint16_t block_size;
+uint32_t current_block;
+uint32_t data_start;
+uint32_t samples_per_block;
+} MCADemuxContext;
+
+static int probe(const AVProbeData *p)
+{
+if (AV_RL32(p->buf) == MKTAG('M', 'A', 'D', 'P') &&
+AV_RL16(p->buf + 4) <= 0xff)
+return AVPROBE_SCORE_MAX / 3 * 2;
+return 0;
+}
+
+static int read_header(AVFormatContext *s)
+{
+AVStream *st;
+MCADemuxContext *m = s->priv_data;
+AVCodecParameters *par;
+int64_t file_size = avio_size(s->pb);
+uint16_t version = 0;
+uint32_t header_size, data_size, data_offset, loop_start, 
loop_end,

+nb_samples, nb_metadata, coef_offset = 0;
+int ch, ret;
+int64_t ret_size;
+
+st = avformat_new_stream(s, NULL);
+if (!st)
+return AVERROR(ENOMEM);
+par = st->codecpar;
+par->codec_type = AVMEDIA_TYPE_AUDIO;
+
+// parse file headers
+avio_skip(s->pb, 0x4);  // skip the file magic
+version  = avio_rl16(s->pb);
+avio_skip(s->pb, 0x2);  // padding
+par->channels= avio_r8(s->pb);
+avio_skip(s->pb, 0x1);  // padding
+m->block_size= avio_rl16(s->pb);
+nb_samples   = avio_rl32(s->pb);
+par->sample_rate = avio_rl32(s->pb);
+loop_start   = avio_rl32(s->pb);
+loop_end = avio_rl32(s->pb);
+header_size  = avio_rl32(s->pb);
+data_size= avio_rl32(s->pb);
+  

Re: [FFmpeg-devel] [PATCH v3] avformat: add mca demuxer

2020-09-03 Thread liushuyu

On 2020-09-03 14:17, Carl Eugen Hoyos wrote:

Am Do., 3. Sept. 2020 um 01:17 Uhr schrieb :


+static int probe(const AVProbeData *p)
+{
+if (AV_RL32(p->buf) == MKTAG('M', 'A', 'D', 'P') &&
+AV_RL16(p->buf + 4) <= 0xff)
+return AVPROBE_SCORE_MAX / 3 * 2;
+return 0;
+}



+if (version <= 4) {
+// version <= 4 needs to use the file size to calculate the 
offsets

+if (file_size < 0) {
+return AVERROR(EIO);
+}
+if (file_size - data_size > UINT32_MAX)
+return AVERROR_INVALIDDATA;
+m->data_start = file_size - data_size;
+if (version <= 3) {
+nb_metadata = 0;
+// header_size is not available or incorrect in older 
versions

+header_size = m->data_start;
+}
+} else if (version == 5) {
+// read data_start location from the header
+if (0x30 * par->channels + 0x4 > header_size)
+return AVERROR_INVALIDDATA;
+data_offset = header_size - 0x30 * par->channels - 0x4;
+if ((ret_size = avio_seek(s->pb, data_offset, SEEK_SET)) < 0)
+return ret_size;
+m->data_start = avio_rl32(s->pb);
+// check if the metadata is reasonable
+if (file_size > 0 && (int64_t)m->data_start + data_size > 
file_size) {

+// the header is broken beyond repair
+if ((int64_t)header_size + data_size > file_size) {
+av_log(s, AV_LOG_ERROR,
+   "MCA metadata corrupted, unable to determine 
the data offset.\n");

+return AVERROR_INVALIDDATA;
+}
+// recover the data_start information from the data size
+av_log(s, AV_LOG_WARNING,
+   "Incorrect header size found in metadata, "
+   "header size approximated from the data size\n");
+if (file_size - data_offset > UINT32_MAX)
+return AVERROR_INVALIDDATA;
+m->data_start = file_size - data_size;
+}
+} else {
+avpriv_request_sample(s, "version %d", version);
+return AVERROR_PATCHWELCOME;
+}


It seems to me that you are much stricter checking the version
when reading the header information than when probing the file
but if there is a difference, the probing should be stricter.

Please check in the probe function if version <= 5.


Will do. Should I also keep the else clause here?


+} else {
+avpriv_request_sample(s, "version %d", version);
+return AVERROR_PATCHWELCOME;
+}



Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Thanks for your review again!

Thanks,
Zixing
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avcodec/dxtory: unbreak decoding after 6e1a167c556

2020-09-03 Thread Paul B Mahol
On 9/3/20, Michael Niedermayer  wrote:
> On Thu, Sep 03, 2020 at 07:03:23PM +0200, Paul B Mahol wrote:
>> get_unary() takes at minimum only 1 bit.
>>
>> Signed-off-by: Paul B Mahol 
>> ---
>>
>> As this is important fix, will apply in next 5 minutes.
>> I kindly ask authors of various timeouts changes to kindly
>> test their changes more carefully.
>
> Can you provide test samples and a fate test ?

Why should I? Nobody uploads my request to wav CUE thing.

Test samples can be generated by installing trial dxtory capture and recording
mainly black frames from some simple game. On windows, or under virtualbox.

I can upload files, but I value my time and will not do it for nothing
in return.

The ones who are actually paid to the actual work should make sure
they do not break
decoders.

>
>
>>
>> ---
>>  libavcodec/dxtory.c | 10 +-
>>  1 file changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/libavcodec/dxtory.c b/libavcodec/dxtory.c
>> index bc19f27951..3cd95afe80 100644
>> --- a/libavcodec/dxtory.c
>> +++ b/libavcodec/dxtory.c
>> @@ -395,7 +395,7 @@ static int dx2_decode_slice_5x5(GetBitContext *gb,
>> AVFrame *frame,
>>  int stride   = frame->linesize[0];
>>  uint8_t *dst = frame->data[0] + stride * line;
>>
>> -for (y = 0; y < left && get_bits_left(gb) > 6 * width; y++) {
>> +for (y = 0; y < left && get_bits_left(gb) >= 3 * width; y++) {
>>  for (x = 0; x < width; x++) {
>>  b = decode_sym_565(gb, lru[0], 5);
>>  g = decode_sym_565(gb, lru[1], is_565 ? 6 : 5);
>> @@ -462,7 +462,7 @@ static int dx2_decode_slice_rgb(GetBitContext *gb,
>> AVFrame *frame,
>>  int stride   = frame->linesize[0];
>>  uint8_t *dst = frame->data[0] + stride * line;
>>
>> -for (y = 0; y < left && get_bits_left(gb) > 6 * width; y++) {
>> +for (y = 0; y < left && get_bits_left(gb) >= 3 * width; y++) {
>>  for (x = 0; x < width; x++) {
>>  dst[x * 3 + 0] = decode_sym(gb, lru[0]);
>>  dst[x * 3 + 1] = decode_sym(gb, lru[1]);
>
>> @@ -508,7 +508,7 @@ static int dx2_decode_slice_410(GetBitContext *gb,
>> AVFrame *frame,
>>  uint8_t *U  = frame->data[1] + (ustride >> 2) * line;
>>  uint8_t *V  = frame->data[2] + (vstride >> 2) * line;
>>
>> -for (y = 0; y < left - 3 && get_bits_left(gb) > 9 * width; y += 4) {
>> +for (y = 0; y < left - 3 && get_bits_left(gb) >= 4 * width; y += 4)
>> {
>>  for (x = 0; x < width; x += 4) {
>>  for (j = 0; j < 4; j++)
>>  for (i = 0; i < 4; i++)
>
> iam not sure this is correct
> let us consider the equal case occurs get_bits_left(gb) == 4 * width;
> now this is read as 4x4 blocks, each will read a minimum of 18 bits 16 luma
> and 2 chroma. 18*(width/4) == 4 * width doesnt look right

This is correct and it is for support odd dimensions (not supported at
all from beginning) in next patch, the ones non-aligned to subsampled
constraints.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 1/3] avcodec/dxtory: unbreak decoding after 6e1a167c556

2020-09-03 Thread Paul B Mahol
get_unary() takes at minimum only 1 bit.

Signed-off-by: Paul B Mahol 
---
 libavcodec/dxtory.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavcodec/dxtory.c b/libavcodec/dxtory.c
index bc19f27951..3cd95afe80 100644
--- a/libavcodec/dxtory.c
+++ b/libavcodec/dxtory.c
@@ -395,7 +395,7 @@ static int dx2_decode_slice_5x5(GetBitContext *gb, AVFrame 
*frame,
 int stride   = frame->linesize[0];
 uint8_t *dst = frame->data[0] + stride * line;
 
-for (y = 0; y < left && get_bits_left(gb) > 6 * width; y++) {
+for (y = 0; y < left && get_bits_left(gb) >= 3 * width; y++) {
 for (x = 0; x < width; x++) {
 b = decode_sym_565(gb, lru[0], 5);
 g = decode_sym_565(gb, lru[1], is_565 ? 6 : 5);
@@ -462,7 +462,7 @@ static int dx2_decode_slice_rgb(GetBitContext *gb, AVFrame 
*frame,
 int stride   = frame->linesize[0];
 uint8_t *dst = frame->data[0] + stride * line;
 
-for (y = 0; y < left && get_bits_left(gb) > 6 * width; y++) {
+for (y = 0; y < left && get_bits_left(gb) >= 3 * width; y++) {
 for (x = 0; x < width; x++) {
 dst[x * 3 + 0] = decode_sym(gb, lru[0]);
 dst[x * 3 + 1] = decode_sym(gb, lru[1]);
@@ -508,7 +508,7 @@ static int dx2_decode_slice_410(GetBitContext *gb, AVFrame 
*frame,
 uint8_t *U  = frame->data[1] + (ustride >> 2) * line;
 uint8_t *V  = frame->data[2] + (vstride >> 2) * line;
 
-for (y = 0; y < left - 3 && get_bits_left(gb) > 9 * width; y += 4) {
+for (y = 0; y < left - 3 && get_bits_left(gb) >= 4 * width; y += 4) {
 for (x = 0; x < width; x += 4) {
 for (j = 0; j < 4; j++)
 for (i = 0; i < 4; i++)
@@ -553,7 +553,7 @@ static int dx2_decode_slice_420(GetBitContext *gb, AVFrame 
*frame,
 uint8_t *V  = frame->data[2] + (vstride >> 1) * line;
 
 
-for (y = 0; y < left - 1 && get_bits_left(gb) > 6 * width; y += 2) {
+for (y = 0; y < left - 1 && get_bits_left(gb) >= 3 * width; y += 2) {
 for (x = 0; x < width; x += 2) {
 Y[x + 0 + 0 * ystride] = decode_sym(gb, lru[0]);
 Y[x + 1 + 0 * ystride] = decode_sym(gb, lru[0]);
@@ -597,7 +597,7 @@ static int dx2_decode_slice_444(GetBitContext *gb, AVFrame 
*frame,
 uint8_t *U  = frame->data[1] + ustride * line;
 uint8_t *V  = frame->data[2] + vstride * line;
 
-for (y = 0; y < left && get_bits_left(gb) > 6 * width; y++) {
+for (y = 0; y < left && get_bits_left(gb) >= 3 * width; y++) {
 for (x = 0; x < width; x++) {
 Y[x] = decode_sym(gb, lru[0]);
 U[x] = decode_sym(gb, lru[1]) ^ 0x80;
-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 3/3] avcodec/dxtory: add missed rgb555/rgb565 formats for vflip case

2020-09-03 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 libavcodec/dxtory.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavcodec/dxtory.c b/libavcodec/dxtory.c
index 9e7ba3e94d..3eac0bfb3c 100644
--- a/libavcodec/dxtory.c
+++ b/libavcodec/dxtory.c
@@ -62,6 +62,8 @@ static void do_vflip(AVCodecContext *avctx, AVFrame *pic, int 
vflip)
 pic->linesize[1] = -pic->linesize[1];
 pic->data[2] += (avctx->height - 1) * pic->linesize[2];
 pic->linesize[2] = -pic->linesize[2];
+case AV_PIX_FMT_RGB555LE:
+case AV_PIX_FMT_RGB565LE:
 case AV_PIX_FMT_BGR24:
 case AV_PIX_FMT_RGB24:
 pic->data[0] += (avctx->height - 1) * pic->linesize[0];
-- 
2.17.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v4 0/1] avformat: add mca demuxer

2020-09-03 Thread liushuyu
From: liushuyu 

This patch adds the MCA demuxer to FFmpeg.

MCA is a format used by Capcom in some of their games, the audio format
is always ADPCM_THP_LE in these files.

This MCA demuxer implementation currently supports MCA version 1-5 and
can partially handle some of the version 5 files with minor damages to
the file header.

There are some sample files I have prepared that you can try:

* (version 4) https://streams.videolan.org/ffmpeg/incoming/bgm18_1632b.mca
* (version 5) https://streams.videolan.org/ffmpeg/incoming/bgm020_1632.mca

N.B. Files using version 1 to 3 are harder to find, I don't seem to find
any to test.

As required by
https://ffmpeg.org/developer.html#New-codecs-or-formats-checklist, the
minor version of libavformat is updated to 52.

Patch version 2 changes:

* changed version field to uint16_t and remove redundant compares

Patch version 3 changes:

* dropped excessive comments about offsets
* removed redundant headers
* indentation fixes and paddings around '='
* aliased st->codecpar to par to shorten the code
* made m->samples_per_block zero check earlier
* m->coef_offset converted to a local variable
* replaced avio_read() checks with ffio_read_size()
* moved sample size check to read_header()
* manual sample copying replaced with av_get_packet()

Patch version 4 changes

* check version early in the probe()
* removed redundant av_new_packet() call
* libavformat minor version updated to 54

Zixing Liu (1):
  avformat: add mca demuxer

 Changelog|   1 +
 doc/general.texi |   2 +
 libavformat/Makefile |   1 +
 libavformat/allformats.c |   1 +
 libavformat/mca.c| 226 +++
 libavformat/version.h|   2 +-
 6 files changed, 232 insertions(+), 1 deletion(-)
 create mode 100644 libavformat/mca.c

-- 
2.28.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-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v4 1/1] avformat: add mca demuxer

2020-09-03 Thread liushuyu
From: Zixing Liu 

Signed-off-by: liushuyu 
---
 Changelog|   1 +
 doc/general.texi |   2 +
 libavformat/Makefile |   1 +
 libavformat/allformats.c |   1 +
 libavformat/mca.c| 226 +++
 libavformat/version.h|   2 +-
 6 files changed, 232 insertions(+), 1 deletion(-)
 create mode 100644 libavformat/mca.c

diff --git a/Changelog b/Changelog
index d8109c6..d5f1b04 100644
--- a/Changelog
+++ b/Changelog
@@ -20,6 +20,7 @@ version :
 - MobiClip video decoder
 - MOFLEX demuxer
 - MODS demuxer
+- MCA demuxer
 
 
 version 4.3:
diff --git a/doc/general.texi b/doc/general.texi
index d618565..fa76ed4 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -524,6 +524,8 @@ library:
 @tab Metadata in text format.
 @item MAXIS XA  @tab   @tab X
 @tab Used in Sim City 3000; file extension .xa.
+@item MCA   @tab   @tab X
+@tab Used in some games from Capcom; file extension .mca.
 @item MD Studio @tab   @tab X
 @item Metal Gear Solid: The Twin Snakes @tab @tab X
 @item Megalux Frame @tab   @tab X
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 7f852c0..9d2e157 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -305,6 +305,7 @@ OBJS-$(CONFIG_MATROSKA_MUXER)+= matroskaenc.o 
matroska.o \
 av1.o avc.o hevc.o \
 flacenc_header.o avlanguage.o \
 vorbiscomment.o wv.o
+OBJS-$(CONFIG_MCA_DEMUXER)   += mca.o
 OBJS-$(CONFIG_MCC_DEMUXER)   += mccdec.o subtitles.o
 OBJS-$(CONFIG_MD5_MUXER) += hashenc.o
 OBJS-$(CONFIG_MGSTS_DEMUXER) += mgsts.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 8a733b3..0e79eef 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -232,6 +232,7 @@ extern AVInputFormat  ff_lvf_demuxer;
 extern AVInputFormat  ff_lxf_demuxer;
 extern AVInputFormat  ff_m4v_demuxer;
 extern AVOutputFormat ff_m4v_muxer;
+extern AVInputFormat  ff_mca_demuxer;
 extern AVInputFormat  ff_mcc_demuxer;
 extern AVOutputFormat ff_md5_muxer;
 extern AVInputFormat  ff_matroska_demuxer;
diff --git a/libavformat/mca.c b/libavformat/mca.c
new file mode 100644
index 000..f3f3471
--- /dev/null
+++ b/libavformat/mca.c
@@ -0,0 +1,226 @@
+/*
+ * MCA demuxer
+ * Copyright (c) 2020 Zixing Liu
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/intreadwrite.h"
+#include "avformat.h"
+#include "avio_internal.h"
+#include "internal.h"
+
+typedef struct MCADemuxContext {
+uint32_t block_count;
+uint16_t block_size;
+uint32_t current_block;
+uint32_t data_start;
+uint32_t samples_per_block;
+} MCADemuxContext;
+
+static int probe(const AVProbeData *p)
+{
+if (AV_RL32(p->buf) == MKTAG('M', 'A', 'D', 'P') &&
+AV_RL16(p->buf + 4) <= 0x5)
+return AVPROBE_SCORE_MAX / 3 * 2;
+return 0;
+}
+
+static int read_header(AVFormatContext *s)
+{
+AVStream *st;
+MCADemuxContext *m = s->priv_data;
+AVCodecParameters *par;
+int64_t file_size = avio_size(s->pb);
+uint16_t version = 0;
+uint32_t header_size, data_size, data_offset, loop_start, loop_end,
+nb_samples, nb_metadata, coef_offset = 0;
+int ch, ret;
+int64_t ret_size;
+
+st = avformat_new_stream(s, NULL);
+if (!st)
+return AVERROR(ENOMEM);
+par = st->codecpar;
+par->codec_type = AVMEDIA_TYPE_AUDIO;
+
+// parse file headers
+avio_skip(s->pb, 0x4);  // skip the file magic
+version  = avio_rl16(s->pb);
+avio_skip(s->pb, 0x2);  // padding
+par->channels= avio_r8(s->pb);
+avio_skip(s->pb, 0x1);  // padding
+m->block_size= avio_rl16(s->pb);
+nb_samples   = avio_rl32(s->pb);
+par->sample_rate = avio_rl32(s->pb);
+loop_start   = avio_rl32(s->pb);
+loop_end = avio_rl32(s->pb);
+header_size  = avio_rl32(s->pb);
+data_size= avio_rl32(s->pb);
+avio_skip(s->pb, 0x4);
+nb_metadata  = avio_rl16(s->pb);
+avio_skip(s->pb, 0x2);  // unknown u16 field
+

[FFmpeg-devel] [PATCH 2/3] avcodec/dxtory: support subsample formats with non-aligned dimensions

2020-09-03 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 libavcodec/dxtory.c | 185 
 1 file changed, 171 insertions(+), 14 deletions(-)

diff --git a/libavcodec/dxtory.c b/libavcodec/dxtory.c
index 3cd95afe80..9e7ba3e94d 100644
--- a/libavcodec/dxtory.c
+++ b/libavcodec/dxtory.c
@@ -32,6 +32,25 @@
 #include "internal.h"
 #include "unary.h"
 
+static int64_t get_raw_size(enum AVPixelFormat fmt, int width, int height)
+{
+switch (fmt) {
+case AV_PIX_FMT_RGB555LE:
+case AV_PIX_FMT_RGB565LE:
+return width * height * 2LL;
+case AV_PIX_FMT_RGB24:
+case AV_PIX_FMT_BGR24:
+case AV_PIX_FMT_YUV444P:
+return width * height * 3LL;
+case AV_PIX_FMT_YUV420P:
+return (int64_t)(width * height) + AV_CEIL_RSHIFT(width, 1) * 
AV_CEIL_RSHIFT(height, 1);
+case AV_PIX_FMT_YUV410P:
+return (int64_t)(width * height) + AV_CEIL_RSHIFT(width, 2) * 
AV_CEIL_RSHIFT(height, 2);
+}
+
+return 0;
+}
+
 static void do_vflip(AVCodecContext *avctx, AVFrame *pic, int vflip)
 {
 if (!vflip)
@@ -51,17 +70,17 @@ static void do_vflip(AVCodecContext *avctx, AVFrame *pic, 
int vflip)
 case AV_PIX_FMT_YUV410P:
 pic->data[0] += (avctx->height - 1) * pic->linesize[0];
 pic->linesize[0] = -pic->linesize[0];
-pic->data[1] += ((avctx->height >> 2) - 1) * pic->linesize[1];
+pic->data[1] += (AV_CEIL_RSHIFT(avctx->height, 2) - 1) * 
pic->linesize[1];
 pic->linesize[1] = -pic->linesize[1];
-pic->data[2] += ((avctx->height >> 2) - 1) * pic->linesize[2];
+pic->data[2] += (AV_CEIL_RSHIFT(avctx->height, 2) - 1) * 
pic->linesize[2];
 pic->linesize[2] = -pic->linesize[2];
 break;
 case AV_PIX_FMT_YUV420P:
 pic->data[0] += (avctx->height - 1) * pic->linesize[0];
 pic->linesize[0] = -pic->linesize[0];
-pic->data[1] += ((avctx->height >> 1) - 1) * pic->linesize[1];
+pic->data[1] += (AV_CEIL_RSHIFT(avctx->height, 1) - 1) * 
pic->linesize[1];
 pic->linesize[1] = -pic->linesize[1];
-pic->data[2] += ((avctx->height >> 1) - 1) * pic->linesize[2];
+pic->data[2] += (AV_CEIL_RSHIFT(avctx->height, 1) - 1) * 
pic->linesize[2];
 pic->linesize[2] = -pic->linesize[2];
 break;
 }
@@ -75,7 +94,7 @@ static int dxtory_decode_v1_rgb(AVCodecContext *avctx, 
AVFrame *pic,
 uint8_t *dst;
 int ret;
 
-if (src_size < avctx->width * avctx->height * (int64_t)bpp) {
+if (src_size < get_raw_size(id, avctx->width, avctx->height)) {
 av_log(avctx, AV_LOG_ERROR, "packet too small\n");
 return AVERROR_INVALIDDATA;
 }
@@ -104,9 +123,11 @@ static int dxtory_decode_v1_410(AVCodecContext *avctx, 
AVFrame *pic,
 {
 int h, w;
 uint8_t *Y1, *Y2, *Y3, *Y4, *U, *V;
+int height, width, hmargin, vmargin;
+int huvborder;
 int ret;
 
-if (src_size < FFALIGN(avctx->width, 4) * FFALIGN(avctx->height, 4) * 9LL 
/ 8) {
+if (src_size < get_raw_size(AV_PIX_FMT_YUV410P, avctx->width, 
avctx->height)) {
 av_log(avctx, AV_LOG_ERROR, "packet too small\n");
 return AVERROR_INVALIDDATA;
 }
@@ -117,14 +138,20 @@ static int dxtory_decode_v1_410(AVCodecContext *avctx, 
AVFrame *pic,
 
 do_vflip(avctx, pic, vflipped);
 
+height = avctx->height & ~3;
+width  = avctx->width  & ~3;
+hmargin = avctx->width  - width;
+vmargin = avctx->height - height;
+huvborder = AV_CEIL_RSHIFT(avctx->width, 2) - 1;
+
 Y1 = pic->data[0];
 Y2 = pic->data[0] + pic->linesize[0];
 Y3 = pic->data[0] + pic->linesize[0] * 2;
 Y4 = pic->data[0] + pic->linesize[0] * 3;
 U  = pic->data[1];
 V  = pic->data[2];
-for (h = 0; h < avctx->height; h += 4) {
-for (w = 0; w < avctx->width; w += 4) {
+for (h = 0; h < height; h += 4) {
+for (w = 0; w < width; w += 4) {
 AV_COPY32U(Y1 + w, src);
 AV_COPY32U(Y2 + w, src + 4);
 AV_COPY32U(Y3 + w, src + 8);
@@ -133,6 +160,18 @@ static int dxtory_decode_v1_410(AVCodecContext *avctx, 
AVFrame *pic,
 V[w >> 2] = src[17] + 0x80;
 src += 18;
 }
+if (hmargin) {
+for (w = 0; w < hmargin; w++) {
+Y1[width + w] = src[w];
+Y2[width + w] = src[w + hmargin * 1];
+Y3[width + w] = src[w + hmargin * 2];
+Y4[width + w] = src[w + hmargin * 3];
+}
+src += 4 * hmargin;
+U[huvborder] = src[0] + 0x80;
+V[huvborder] = src[1] + 0x80;
+src += 2;
+}
 Y1 += pic->linesize[0] << 2;
 Y2 += pic->linesize[0] << 2;
 Y3 += pic->linesize[0] << 2;
@@ -141,6 +180,33 @@ static int dxtory_decode_v1_410(AVCodecContext *avctx, 
AVFrame *pic,
 V  += pic->linesize[2];
 }
 
+if (vmargin) {
+for (w = 0; w < width; w += 4) {
+AV_COPY32U(Y1 + w, src);
+if (vmargin > 1)
+

Re: [FFmpeg-devel] [PATCH] lavc/vaapi_encode_h265: fix max_transform_hierarchy_depth_inter/intra

2020-09-03 Thread Linjie Fu
On Thu, Sep 3, 2020 at 1:32 PM Xiang, Haihao  wrote:
>
> On Mon, 2020-04-13 at 13:06 +, Fu, Linjie wrote:
> > > From: ffmpeg-devel  On Behalf Of
> > > Mark Thompson
> > > Sent: Monday, April 13, 2020 20:20
> > > To: ffmpeg-devel@ffmpeg.org
> > > Subject: Re: [FFmpeg-devel] [PATCH] lavc/vaapi_encode_h265: fix
> > > max_transform_hierarchy_depth_inter/intra
> > >
> > > On 13/04/2020 05:32, Linjie Fu wrote:
> > > > Set the max_transform_hierarchy_depth_inter/intra to 2 by default
> > > > based on the Programmer's Reference Manuals (PRM) in [1].
> > > >
> > > > Intel Encoder only supports 2 levels of quad-tree. That is:
> > > > - max_transform_hierarchy_depth_inter/intra <= 2.
> > > >
> > > > [1] 
> > > >  > >
> > > kbl-vol10-hevc.pdf>
> > > >
> > > > Signed-off-by: Linjie Fu 
> > > > ---
> > > > Fixed value for intel platform, makes more sense on TGL+ platform.
> > > > (If conflict with other driver capability, we may add query support
> > > >  later)
> > > >  libavcodec/vaapi_encode_h265.c | 5 +++--
> > > >  1 file changed, 3 insertions(+), 2 deletions(-)
> > > >
> > > > diff --git a/libavcodec/vaapi_encode_h265.c
> > >
> > > b/libavcodec/vaapi_encode_h265.c
> > > > index cd48545..d6cb82a 100644
> > > > --- a/libavcodec/vaapi_encode_h265.c
> > > > +++ b/libavcodec/vaapi_encode_h265.c
> > > > @@ -445,8 +445,9 @@ static int
> > >
> > > vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx)
> > > >  sps->log2_min_luma_transform_block_size_minus2   = 0;
> > > >  sps->log2_diff_max_min_luma_transform_block_size = 3;
> > > >  // Full transform hierarchy allowed (2-5).
> > > > -sps->max_transform_hierarchy_depth_inter = 3;
> > > > -sps->max_transform_hierarchy_depth_intra = 3;
> > > > +// Default to 2 based on Programmer's Reference Manuals of Intel
> > >
> > > graphics
> > > > +sps->max_transform_hierarchy_depth_inter = 2;
> > > > +sps->max_transform_hierarchy_depth_intra = 2;
> > > >  // AMP works.
> > > >  sps->amp_enabled_flag = 1;
> > > >  // SAO and temporal MVP do not work.
> > > >
> > >
> > > I don't much like the idea of changing this based on a value in a Kaby 
> > > Lake
> > > document given that the current value hasn't had any problems on Kaby 
> > > Lake.
> > > Can you explain the benefits of changing this?
> >
> > It fixes the encoding issue for HEVC on gen12+ platform.
> > We didn't notice this either, until it triggers gpu hang for encoding on 
> > Tiger
> > Lake (gen12).
> >
> > > Can you confirm that it continues to work on all the other 
> > > currently-working
> > > platforms?
> > >
> >
> > Yes, we set up CI and runs full-round tests for conformance and catch
> > regression on different
> > platforms(CFL/CML/ICL/KBL/SKL).
> >
> > Identical fix has been merged in gstreamer-vaapi, no regression is detected 
> > on
> > other platforms.
> >
> https://gitlab.freedesktop.org/gstreamer/gstreamer-vaapi/-/merge_requests/282/diffs?commit_id=17d82e14e78af901f1cd7f2344e173ad6ae6a8a6
>
> Hi Mark,
>
> Till now we didn't see regression with Linjie's patch, do you have any other
> concern on Linjie's patch?
>
Also ping for this, since TGL has been announced recently.

- Linjie
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v4 1/2] libavcodec/webp: add support for animated WebP decoding

2020-09-03 Thread Lynne
Aug 28, 2020, 06:23 by jo...@pex.com:

> Fixes: 4907
>
> Adds support for decoding of animated WebP.
>
> The WebP parser now splits the input stream into packets containing one frame.
>
> The WebP decoder adds the animation related features according to the specs:
> https://developers.google.com/speed/webp/docs/riff_container#animation
> The frames of the animation may be smaller than the image canvas.
> Therefore, the frame is decoded to a temporary frame,
> then it is blended into the canvas, the canvas is copied to the output frame,
> and finally the frame is disposed from the canvas.
>
> The output to AV_PIX_FMT_YUVA420P/AV_PIX_FMT_YUV420P is still supported.
> The background color is specified only as BGRA in the WebP file
> so it is converted to YUVA if YUV formats are output.
>
> Signed-off-by: Josef Zlomek <> jo...@pex.com> >
>

Sorry it took me so long to get to this.
Took a look and the patch looks fine to me.
Will apply in a few days unless someone else has comments or I find something I
missed. Its not a small patch after all.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".