Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: skip first char after compare path with path separator

2020-03-29 Thread Limin Wang
On Sun, Mar 29, 2020 at 11:14:37AM +0800, Steven Liu wrote:
> before patch:
> ffmpeg -i input -g 25 -y -c:a aac -map 0:v -map 0:a
> -master_pl_name playlist.m3u8 -var_stream_map "v:0,a:0" c%v.m3u8"
> the master file playlist.m3u8 context is
> #EXTM3U
> #EXT-X-VERSION:3
> 
> #EXT-X-STREAM-INF:BANDWIDTH=2890800,RESOLUTION=1920x800,CODECS="avc1.640028,mp4a.40.2"
> /c0.m3u8
> 
> this is incorrect.
> after patch:
> #EXTM3U
> #EXT-X-VERSION:3
> 
> #EXT-X-STREAM-INF:BANDWIDTH=2890800,RESOLUTION=1920x800,CODECS="avc1.640028,mp4a.40.2"
> c0.m3u8
> 

I have send patch set to fix the issue before. Please see:
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20200326135700.11167-1-lance.lmw...@gmail.com/


> Reported-by: Ibrahim Tachijian 
> Signed-off-by: Steven Liu 
> ---
>  libavformat/hlsenc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index b4c72b6e54..a3c59432c5 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -1260,7 +1260,7 @@ static const char* get_relative_url(const char 
> *master_url, const char *media_ur
>  }
>  }
>  
> -return media_url + base_len;
> +return media_url + 1 + base_len;
>  }
>  
>  static int64_t get_stream_bit_rate(AVStream *stream)
> -- 
> 2.25.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".

-- 
Thanks,
Limin Wang
___
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 v1 1/4] avformat/hlsenc: remove the first slash of the relative path line in the master m3u8 file

2020-03-29 Thread Steven Liu


> 2020年3月26日 下午9:56,lance.lmw...@gmail.com 写道:
> 
> From: Limin Wang 
> 
> Please testing with the following command:
> ./ffmpeg -y -i input.mkv \
> -b:v:0 5250k -c:v h264 -pix_fmt yuv420p -profile:v main -level 4.1 \
> -b:a:0 256k \
> -c:a mp2 -ar 48000 -ac 2 -map 0:v -map 0:a:0\
> -f hls -var_stream_map "v:0,a:0" \
> -master_pl_name master.m3u8 -t 300 -hls_time 10 -hls_init_time 4 
> -hls_list_size \
> 10 -master_pl_publish_rate 10  -hls_flags \
> delete_segments+discont_start+split_by_time ./tmp/video.m3u8
> 
> then cat ./tmp/master.m3u8
> before:
> #EXTM3U
> #EXT-X-VERSION:3
> #EXT-X-STREAM-INF:BANDWIDTH=6056600,RESOLUTION=1280x720,CODECS="avc1.4d4829,mp4a.40.33"
> /video.m3u8
> 
> $ ./ffmpeg -i  ./tmp/master.m3u8 -c:v copy -c:a mp2 ./test.mkv
> [hls @ 0x7f82f900] Skip ('#EXT-X-VERSION:3')
> [hls @ 0x7f82f900] Opening '/video.m3u8' for reading
> [hls @ 0x7f82f900] parse_playlist error No such file or directory 
> [/video.m3u8]
> ./tmp/master.m3u8: No such file or directory
> 
> after:
> #EXTM3U
> #EXT-X-VERSION:3
> #EXT-X-STREAM-INF:BANDWIDTH=6056600,RESOLUTION=1280x720,CODECS="avc1.4d4829,mp4a.40.33"
> video.m3u8
> 
> Signed-off-by: Limin Wang 
> ---
> libavformat/hlsenc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index b4c72b6e54..a0a3a4647b 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -1260,7 +1260,7 @@ static const char* get_relative_url(const char 
> *master_url, const char *media_ur
> }
> }
> 
> -return media_url + base_len;
> +return media_url + base_len + 1;
> }
> 
> static int64_t get_stream_bit_rate(AVStream *stream)
> -- 
> 2.21.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".

LGTM

Thanks

Steven Liu



___
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 v1 2/4] avformat/hlsplaylist: simplify code for checking whether the string is empty

2020-03-29 Thread Steven Liu


> 2020年3月26日 下午9:56,lance.lmw...@gmail.com 写道:
> 
> From: Limin Wang 
> 
> Signed-off-by: Limin Wang 
> ---
> libavformat/hlsplaylist.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/libavformat/hlsplaylist.c b/libavformat/hlsplaylist.c
> index 9cbd02353f..56244496c0 100644
> --- a/libavformat/hlsplaylist.c
> +++ b/libavformat/hlsplaylist.c
> @@ -65,11 +65,11 @@ void ff_hls_write_stream_info(AVStream *st, AVIOContext 
> *out,
> if (st && st->codecpar->width > 0 && st->codecpar->height > 0)
> avio_printf(out, ",RESOLUTION=%dx%d", st->codecpar->width,
> st->codecpar->height);
> -if (codecs && strlen(codecs) > 0)
> +if (codecs && codecs[0])
> avio_printf(out, ",CODECS=\"%s\"", codecs);
> -if (agroup && strlen(agroup) > 0)
> +if (agroup && agroup[0])
> avio_printf(out, ",AUDIO=\"group_%s\"", agroup);
> -if (ccgroup && strlen(ccgroup) > 0)
> +if (ccgroup && ccgroup[0])
> avio_printf(out, ",CLOSED-CAPTIONS=\"%s\"", ccgroup);
> avio_printf(out, "\n%s\n\n", filename);
> }
> -- 
> 2.21.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".

LGTM

Thanks

Steven Liu



___
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 v1 3/4] avformat: add subtitle support in master playlist m3u8

2020-03-29 Thread Steven Liu


> 2020年3月26日 下午9:56,lance.lmw...@gmail.com 写道:
> 
> From: Limin Wang 
> 
> Test with the following command for the webvtt subtitle:
> $ ./ffmpeg -y -i input_with_subtitle.mkv \
> -b:v:0 5250k -c:v h264 -pix_fmt yuv420p -profile:v main -level 4.1 \
> -b:a:0 256k \
> -c:s webvtt -c:a mp2 -ar 48000 -ac 2 -map 0:v -map 0:a:0 -map 0:s:0 \
> -f hls -var_stream_map "v:0,a:0,s:0,sgroup:subtitle” \
What about add the example into doc/muxer.texi ?
> -master_pl_name master.m3u8 -t 300 -hls_time 10 -hls_init_time 4 
> -hls_list_size \
> 10 -master_pl_publish_rate 10  -hls_flags \
> delete_segments+discont_start+split_by_time ./tmp/video.m3u8
> 
> Check the master m3u8:
> $ cat tmp/master.m3u8
> #EXTM3U
> #EXT-X-VERSION:3
> #EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subtitle",NAME="subtitle_0",DEFAULT=YES,URI="video_vtt.m3u8"
> #EXT-X-STREAM-INF:BANDWIDTH=6056600,RESOLUTION=1280x720,CODECS="avc1.4d4829,mp4a.40.33",SUBTITLES="subtitle"
> video.m3u8
> 
> Check the result by convert to mkv:
> $ ./ffmpeg -strict experimental -i ./tmp/master.m3u8 -c:v copy -c:a mp2 -c:s 
> srt ./test.mkv
> 
> Signed-off-by: Limin Wang 
> ---
> libavformat/dashenc.c |  2 +-
> libavformat/hlsenc.c  | 26 --
> libavformat/hlsplaylist.c | 17 -
> libavformat/hlsplaylist.h |  4 +++-
> 4 files changed, 44 insertions(+), 5 deletions(-)
> 
> diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
> index 94d463972a..d1fe90b00c 100644
> --- a/libavformat/dashenc.c
> +++ b/libavformat/dashenc.c
> @@ -1311,7 +1311,7 @@ static int write_manifest(AVFormatContext *s, int final)
> get_hls_playlist_name(playlist_file, sizeof(playlist_file), NULL, 
> i);
> ff_hls_write_stream_info(st, c->m3u8_out, stream_bitrate,
>  playlist_file, agroup,
> - codec_str_ptr, NULL);
> + codec_str_ptr, NULL, NULL);
> }
> dashenc_io_close(s, &c->m3u8_out, temp_filename);
> if (use_rename)
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index a0a3a4647b..d7b9c0e20a 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -164,6 +164,7 @@ typedef struct VariantStream {
> int is_default; /* default status of audio group */
> char *language; /* audio lauguage name */
> char *agroup; /* audio group name */
> +char *sgroup; /* subtitle group name */
> char *ccgroup; /* closed caption group name */
> char *baseurl;
> char *varname; // variant name
> @@ -1289,7 +1290,9 @@ static int create_master_playlist(AVFormatContext *s,
> unsigned int i, j;
> int ret, bandwidth;
> const char *m3u8_rel_name = NULL;
> +const char *vtt_m3u8_rel_name = NULL;
> char *ccgroup;
> +char *sgroup = NULL;
> ClosedCaptionsStream *ccs;
> const char *proto = avio_find_protocol_name(hls->master_m3u8_url);
> int is_file_proto = proto && !strcmp(proto, "file");
> @@ -1412,13 +1415,24 @@ static int create_master_playlist(AVFormatContext *s,
> vs->ccgroup);
> }
> 
> +if (vid_st && vs->sgroup) {
> +sgroup = vs->sgroup;
> +vtt_m3u8_rel_name = get_relative_url(hls->master_m3u8_url, 
> vs->vtt_m3u8_name);
> +if (!vtt_m3u8_rel_name) {
> +av_log(s, AV_LOG_WARNING, "Unable to find relative subtitle 
> URL\n");
> +break;
> +}
> +
> +ff_hls_write_subtitle_rendition(hls->m3u8_out, sgroup, 
> vtt_m3u8_rel_name, vs->language, i, hls->has_default_key ? vs->is_default : 
> 1);
> +}
> +
> if (!hls->has_default_key || !hls->has_video_m3u8) {
> ff_hls_write_stream_info(vid_st, hls->m3u8_out, bandwidth, 
> m3u8_rel_name,
> -aud_st ? vs->agroup : NULL, vs->codec_attr, ccgroup);
> +aud_st ? vs->agroup : NULL, vs->codec_attr, ccgroup, 
> sgroup);
> } else {
> if (vid_st) {
> ff_hls_write_stream_info(vid_st, hls->m3u8_out, bandwidth, 
> m3u8_rel_name,
> - aud_st ? vs->agroup : NULL, 
> vs->codec_attr, ccgroup);
> + aud_st ? vs->agroup : NULL, 
> vs->codec_attr, ccgroup, sgroup);
> }
> }
> }
> @@ -1893,6 +1907,7 @@ static int 
> parse_variant_stream_mapstring(AVFormatContext *s)
>  * practical usage)
>  *
>  * agroup: is key to specify audio group. A string can be given as value.
> + * sgroup: is key to specify subtitle group. A string can be given as 
> value.
>  */
> p = av_strdup(hls->var_stream_map);
> if (!p)
> @@ -1960,6 +1975,12 @@ static int 
> parse_variant_stream_mapstring(AVFormatContext *s)
> if (!vs->agroup)
> return AVERROR(ENOMEM);
> continue;
> +} else if (av_strstart(keyval, "sgroup:", &val)) {
> +  

Re: [FFmpeg-devel] [PATCH v1 4/4] avformat/hlsenc: use av_asprintf()

2020-03-29 Thread Steven Liu


> 2020年3月26日 下午9:57,lance.lmw...@gmail.com 写道:
> 
> From: Limin Wang 
> 
> Signed-off-by: Limin Wang 
> ---
> libavformat/hlsenc.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index d7b9c0e20a..694dab42dd 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -2950,13 +2950,11 @@ static int hls_init(AVFormatContext *s)
> if (ret < 0)
> goto fail;
> } else {
> -vs->vtt_m3u8_name = av_malloc(vtt_basename_size);
> +vs->vtt_m3u8_name = av_asprintf("%s_vtt.m3u8", 
> vs->vtt_basename);
> if (!vs->vtt_m3u8_name) {
> ret = AVERROR(ENOMEM);
> goto fail;
> }
> -strcpy(vs->vtt_m3u8_name, vs->vtt_basename);
> -av_strlcat(vs->vtt_m3u8_name, "_vtt.m3u8", 
> vtt_basename_size);
> }
> av_strlcat(vs->vtt_basename, vtt_pattern, vtt_basename_size);
> }
> -- 
> 2.21.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".


LGTM


Thanks

Steven Liu



___
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 v2 2/3] avfilter/vf_mix: Check sscanf() return value

2020-03-29 Thread Nicolas George
Limin Wang (12020-03-29):
> OK, update the patch to print a message and return error.

Thanks. I have no objection to that new version, but I do not maintain
that code.

Regards,

-- 
  Nicolas George
___
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 5/5] avformat/mpeg: Don't use unintialized value

2020-03-29 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Michael Niedermayer:
>> On Sun, Jan 19, 2020 at 02:43:00PM +, Andreas Rheinhardt wrote:
>>> Michael Niedermayer:
 On Tue, Oct 22, 2019 at 03:16:45PM +0200, Andreas Rheinhardt wrote:
> vobsub_read_packet() didn't check whether an index in array of AVPackets
> was valid and therefore used uninitialized values.
>
> Signed-off-by: Andreas Rheinhardt 
> ---
> Actually I only wanted to use Valgrind to check for memleaks...
>
>  libavformat/mpeg.c | 4 
>  1 file changed, 4 insertions(+)
>
> diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c
> index 73ade71d95..474afd06b9 100644
> --- a/libavformat/mpeg.c
> +++ b/libavformat/mpeg.c
> @@ -930,6 +930,10 @@ static int vobsub_read_packet(AVFormatContext *s, 
> AVPacket *pkt)
>  FFDemuxSubtitlesQueue *tmpq = &vobsub->q[i];
>  int64_t ts;
>  av_assert0(tmpq->nb_subs);
> +
> +if (tmpq->current_sub_idx >= tmpq->nb_subs)
> +continue;

 How can this issue be reproduced ?

 thx

 [...]
>>>
>>> Read a VobSub subtitle till the end:
>>> ffmpeg -i  -c copy -f null -
>>
>> does not reproduce
>>
>> ./ffmpeg  -i fate/sub/vobsub.idx  -c copy   -f null -
>> Output file #0 does not contain any stream
>> code does not execute
> 
> Sorry, I forgot that subtitle streams are not enabled by default.
>>
>> ./ffmpeg  -i fate/sub/vobsub.idx  -c copy -map s  -f null -
>> the if does not execute
>>
>> iam obviously doing something wrong, can you provide a unambigous testcase?
>>
> You are not doing anything wrong; it's just that the sample is
> truncated: The idx file claims to contain 47 packets, yet the sub file
> contains only 46. As a result, trying to read the 47. packet (the last
> packet that exists in the FFDemuxSubtitlesQueue) fails and no attempt to
> read another packet (which would trigger what I told you) is attempted.
> 
> You can reproduce this by deleting the last line in vobsub.idx.
> 
> - Andreas
> 
Ping.

- Andreas
___
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/5] avformat/smacker: Read extradata directly into extradata

2020-03-29 Thread Andreas Rheinhardt
The Smacker demuxer reads four consecutive 32bit values from the file
header into its demux context (as four uint32_t), converting it to
native endianness in the process and then writing these four values
later (after extradata has been allocated) to extradata as four 32bit
values (converting to little endian in the process).

This commit changes this: The stream and the extradata are allocated
earlier, so that the data destined for extradata can be read directly
into extradata.

Furthermore, given that these values are not needed for demuxing itself
they are now no longer kept as part of the demuxing context.

Finally, a check regarding the number of frames has been moved up,
too, in order to exit early before unnecessarily allocating the
stream and the extradata.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/smacker.c | 47 +--
 1 file changed, 18 insertions(+), 29 deletions(-)

diff --git a/libavformat/smacker.c b/libavformat/smacker.c
index 6de0e7a0f1..4db3ec326f 100644
--- a/libavformat/smacker.c
+++ b/libavformat/smacker.c
@@ -25,10 +25,10 @@
 
 #include 
 
-#include "libavutil/bswap.h"
 #include "libavutil/channel_layout.h"
 #include "libavutil/intreadwrite.h"
 #include "avformat.h"
+#include "avio_internal.h"
 #include "internal.h"
 
 #define SMACKER_PAL 0x01
@@ -51,7 +51,6 @@ typedef struct SmackerContext {
 uint32_t flags;
 uint32_t audio[7];
 uint32_t treesize;
-uint32_t mmap_size, mclr_size, full_size, type_size;
 uint8_t  aflags[7];
 uint32_t rates[7];
 uint32_t pad;
@@ -128,6 +127,10 @@ static int smacker_read_header(AVFormatContext *s)
 smk->flags = avio_rl32(pb);
 if(smk->flags & SMACKER_FLAG_RING_FRAME)
 smk->frames++;
+if (smk->frames > 0xFF) {
+av_log(s, AV_LOG_ERROR, "Too many frames: %"PRIu32"\n", smk->frames);
+return AVERROR_INVALIDDATA;
+}
 for(i = 0; i < 7; i++)
 smk->audio[i] = avio_rl32(pb);
 smk->treesize = avio_rl32(pb);
@@ -137,21 +140,25 @@ static int smacker_read_header(AVFormatContext *s)
 return AVERROR_INVALIDDATA;
 }
 
-//FIXME remove extradata "rebuilding"
-smk->mmap_size = avio_rl32(pb);
-smk->mclr_size = avio_rl32(pb);
-smk->full_size = avio_rl32(pb);
-smk->type_size = avio_rl32(pb);
+st = avformat_new_stream(s, NULL);
+if (!st)
+return AVERROR(ENOMEM);
+
+if ((ret = ff_alloc_extradata(st->codecpar, smk->treesize + 16)) < 0) {
+av_log(s, AV_LOG_ERROR,
+   "Cannot allocate %"PRIu32" bytes of extradata\n",
+   smk->treesize + 16);
+return ret;
+}
+if ((ret = ffio_read_size(pb, st->codecpar->extradata, 16)) < 0)
+return ret;
+
 for(i = 0; i < 7; i++) {
 smk->rates[i]  = avio_rl24(pb);
 smk->aflags[i] = avio_r8(pb);
 }
 smk->pad = avio_rl32(pb);
 /* setup data */
-if(smk->frames > 0xFF) {
-av_log(s, AV_LOG_ERROR, "Too many frames: %"PRIu32"\n", smk->frames);
-return AVERROR_INVALIDDATA;
-}
 smk->frm_size = av_malloc_array(smk->frames, sizeof(*smk->frm_size));
 smk->frm_flags = av_malloc(smk->frames);
 if (!smk->frm_size || !smk->frm_flags) {
@@ -171,12 +178,6 @@ static int smacker_read_header(AVFormatContext *s)
 }
 
 /* init video codec */
-st = avformat_new_stream(s, NULL);
-if (!st) {
-av_freep(&smk->frm_size);
-av_freep(&smk->frm_flags);
-return AVERROR(ENOMEM);
-}
 smk->videoindex = st->index;
 st->codecpar->width = smk->width;
 st->codecpar->height = smk->height;
@@ -233,24 +234,12 @@ static int smacker_read_header(AVFormatContext *s)
 
 
 /* load trees to extradata, they will be unpacked by decoder */
-if ((ret = ff_alloc_extradata(st->codecpar, smk->treesize + 16)) < 0) {
-av_log(s, AV_LOG_ERROR,
-   "Cannot allocate %"PRIu32" bytes of extradata\n",
-   smk->treesize + 16);
-av_freep(&smk->frm_size);
-av_freep(&smk->frm_flags);
-return ret;
-}
 ret = avio_read(pb, st->codecpar->extradata + 16, 
st->codecpar->extradata_size - 16);
 if(ret != st->codecpar->extradata_size - 16){
 av_freep(&smk->frm_size);
 av_freep(&smk->frm_flags);
 return AVERROR(EIO);
 }
-((int32_t*)st->codecpar->extradata)[0] = av_le2ne32(smk->mmap_size);
-((int32_t*)st->codecpar->extradata)[1] = av_le2ne32(smk->mclr_size);
-((int32_t*)st->codecpar->extradata)[2] = av_le2ne32(smk->full_size);
-((int32_t*)st->codecpar->extradata)[3] = av_le2ne32(smk->type_size);
 
 smk->curstream = -1;
 smk->nextpos = avio_tell(pb);
-- 
2.20.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 v2 3/4] avformat: add subtitle support in master playlist m3u8

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

Test with the following command for the webvtt subtitle:
$ ./ffmpeg -y -i input_with_subtitle.mkv \
 -b:v:0 5250k -c:v h264 -pix_fmt yuv420p -profile:v main -level 4.1 \
 -b:a:0 256k \
 -c:s webvtt -c:a mp2 -ar 48000 -ac 2 -map 0:v -map 0:a:0 -map 0:s:0 \
 -f hls -var_stream_map "v:0,a:0,s:0,sgroup:subtitle" \
 -master_pl_name master.m3u8 -t 300 -hls_time 10 -hls_init_time 4 
-hls_list_size \
 10 -master_pl_publish_rate 10  -hls_flags \
 delete_segments+discont_start+split_by_time ./tmp/video.m3u8

Check the master m3u8:
$ cat tmp/master.m3u8
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subtitle",NAME="subtitle_0",DEFAULT=YES,URI="video_vtt.m3u8"
#EXT-X-STREAM-INF:BANDWIDTH=6056600,RESOLUTION=1280x720,CODECS="avc1.4d4829,mp4a.40.33",SUBTITLES="subtitle"
video.m3u8

Check the result by convert to mkv:
$ ./ffmpeg -strict experimental -i ./tmp/master.m3u8 -c:v copy -c:a mp2 -c:s 
srt ./test.mkv

Signed-off-by: Limin Wang 
---
 doc/muxers.texi   | 15 +++
 libavformat/dashenc.c |  2 +-
 libavformat/hlsenc.c  | 26 --
 libavformat/hlsplaylist.c | 17 -
 libavformat/hlsplaylist.h |  4 +++-
 5 files changed, 59 insertions(+), 5 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index d304181..5b40691 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -1062,6 +1062,21 @@ have and language is named ENG, the other audio language 
is named CHN.
 
 By default, a single hls variant containing all the encoded streams is created.
 
+@example
+ffmpeg -y -i input_with_subtitle.mkv \
+ -b:v:0 5250k -c:v h264 -pix_fmt yuv420p -profile:v main -level 4.1 \
+ -b:a:0 256k \
+ -c:s webvtt -c:a mp2 -ar 48000 -ac 2 -map 0:v -map 0:a:0 -map 0:s:0 \
+ -f hls -var_stream_map "v:0,a:0,s:0,sgroup:subtitle" \
+ -master_pl_name master.m3u8 -t 300 -hls_time 10 -hls_init_time 4 
-hls_list_size \
+ 10 -master_pl_publish_rate 10  -hls_flags \
+ delete_segments+discont_start+split_by_time ./tmp/video.m3u8
+@end example
+
+This example adds @code{#EXT-X-MEDIA} tag with @code{TYPE=SUBTITLES} in
+the master playlist with webvtt subtitle group name 'subtitle'. Please make 
sure
+the input file has one text subtitle stream at least.
+
 @item cc_stream_map
 Map string which specifies different closed captions groups and their
 attributes. The closed captions stream groups are separated by space.
diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 94d4639..d1fe90b 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -1311,7 +1311,7 @@ static int write_manifest(AVFormatContext *s, int final)
 get_hls_playlist_name(playlist_file, sizeof(playlist_file), NULL, 
i);
 ff_hls_write_stream_info(st, c->m3u8_out, stream_bitrate,
  playlist_file, agroup,
- codec_str_ptr, NULL);
+ codec_str_ptr, NULL, NULL);
 }
 dashenc_io_close(s, &c->m3u8_out, temp_filename);
 if (use_rename)
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index a0a3a46..d7b9c0e 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -164,6 +164,7 @@ typedef struct VariantStream {
 int is_default; /* default status of audio group */
 char *language; /* audio lauguage name */
 char *agroup; /* audio group name */
+char *sgroup; /* subtitle group name */
 char *ccgroup; /* closed caption group name */
 char *baseurl;
 char *varname; // variant name
@@ -1289,7 +1290,9 @@ static int create_master_playlist(AVFormatContext *s,
 unsigned int i, j;
 int ret, bandwidth;
 const char *m3u8_rel_name = NULL;
+const char *vtt_m3u8_rel_name = NULL;
 char *ccgroup;
+char *sgroup = NULL;
 ClosedCaptionsStream *ccs;
 const char *proto = avio_find_protocol_name(hls->master_m3u8_url);
 int is_file_proto = proto && !strcmp(proto, "file");
@@ -1412,13 +1415,24 @@ static int create_master_playlist(AVFormatContext *s,
 vs->ccgroup);
 }
 
+if (vid_st && vs->sgroup) {
+sgroup = vs->sgroup;
+vtt_m3u8_rel_name = get_relative_url(hls->master_m3u8_url, 
vs->vtt_m3u8_name);
+if (!vtt_m3u8_rel_name) {
+av_log(s, AV_LOG_WARNING, "Unable to find relative subtitle 
URL\n");
+break;
+}
+
+ff_hls_write_subtitle_rendition(hls->m3u8_out, sgroup, 
vtt_m3u8_rel_name, vs->language, i, hls->has_default_key ? vs->is_default : 1);
+}
+
 if (!hls->has_default_key || !hls->has_video_m3u8) {
 ff_hls_write_stream_info(vid_st, hls->m3u8_out, bandwidth, 
m3u8_rel_name,
-aud_st ? vs->agroup : NULL, vs->codec_attr, ccgroup);
+aud_st ? vs->agroup : NULL, vs->codec_attr, ccgroup, 
sgroup);
 } else {
 if (vid_st) {
 ff_hls_write_stream_info(vid_s

[FFmpeg-devel] [PATCH 2/5] avformat/smacker: Create audio streams immediately

2020-03-29 Thread Andreas Rheinhardt
The Smacker demuxer currently parses several fields that indicate
how many audio streams a file contains. This data is parsed and stored
into arrays in the demuxer's context and although the data is used only
to initialize the audio streams, it is kept for the whole lifetime of
the demuxer.

This has been changed: The data is used directly to create
the audio streams and no longer kept at all.

This also simplifies error handling in case adding a new stream fails:
Several arrays which until now have been allocated between parsing the
data determining how many audio streams to create and actually creating
them would need to be freed in this case. Now the streams are created
first, so freeing is no longer an issue.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/smacker.c | 82 ---
 1 file changed, 39 insertions(+), 43 deletions(-)

diff --git a/libavformat/smacker.c b/libavformat/smacker.c
index 4db3ec326f..b08f7bb4e6 100644
--- a/libavformat/smacker.c
+++ b/libavformat/smacker.c
@@ -51,8 +51,6 @@ typedef struct SmackerContext {
 uint32_t flags;
 uint32_t audio[7];
 uint32_t treesize;
-uint8_t  aflags[7];
-uint32_t rates[7];
 uint32_t pad;
 /* frame info */
 uint32_t *frm_size;
@@ -107,7 +105,7 @@ static int smacker_read_header(AVFormatContext *s)
 {
 AVIOContext *pb = s->pb;
 SmackerContext *smk = s->priv_data;
-AVStream *st, *ast[7];
+AVStream *st;
 int i, ret;
 int tbase;
 
@@ -153,9 +151,45 @@ static int smacker_read_header(AVFormatContext *s)
 if ((ret = ffio_read_size(pb, st->codecpar->extradata, 16)) < 0)
 return ret;
 
+/* handle possible audio streams */
 for(i = 0; i < 7; i++) {
-smk->rates[i]  = avio_rl24(pb);
-smk->aflags[i] = avio_r8(pb);
+uint32_t rate = avio_rl24(pb);
+uint8_t aflag = avio_r8(pb);
+
+smk->indexes[i] = -1;
+
+if (rate) {
+AVStream *ast = avformat_new_stream(s, NULL);
+if (!ast)
+return AVERROR(ENOMEM);
+
+smk->indexes[i] = ast->index;
+ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
+if (aflag & SMK_AUD_BINKAUD) {
+ast->codecpar->codec_id  = AV_CODEC_ID_BINKAUDIO_RDFT;
+} else if (aflag & SMK_AUD_USEDCT) {
+ast->codecpar->codec_id  = AV_CODEC_ID_BINKAUDIO_DCT;
+} else if (aflag & SMK_AUD_PACKED) {
+ast->codecpar->codec_id  = AV_CODEC_ID_SMACKAUDIO;
+ast->codecpar->codec_tag = MKTAG('S', 'M', 'K', 'A');
+} else {
+ast->codecpar->codec_id  = AV_CODEC_ID_PCM_U8;
+}
+if (aflag & SMK_AUD_STEREO) {
+ast->codecpar->channels   = 2;
+ast->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
+} else {
+ast->codecpar->channels   = 1;
+ast->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
+}
+ast->codecpar->sample_rate = rate;
+ast->codecpar->bits_per_coded_sample = (aflag & SMK_AUD_16BITS) ? 
16 : 8;
+if (ast->codecpar->bits_per_coded_sample == 16 &&
+ast->codecpar->codec_id == AV_CODEC_ID_PCM_U8)
+ast->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE;
+avpriv_set_pts_info(ast, 64, 1, ast->codecpar->sample_rate
+* ast->codecpar->channels * 
ast->codecpar->bits_per_coded_sample / 8);
+}
 }
 smk->pad = avio_rl32(pb);
 /* setup data */
@@ -194,44 +228,6 @@ static int smacker_read_header(AVFormatContext *s)
 av_reduce(&tbase, &smk->pts_inc, tbase, smk->pts_inc, (1UL<<31)-1);
 avpriv_set_pts_info(st, 33, smk->pts_inc, tbase);
 st->duration = smk->frames;
-/* handle possible audio streams */
-for(i = 0; i < 7; i++) {
-smk->indexes[i] = -1;
-if (smk->rates[i]) {
-ast[i] = avformat_new_stream(s, NULL);
-if (!ast[i]) {
-av_freep(&smk->frm_size);
-av_freep(&smk->frm_flags);
-return AVERROR(ENOMEM);
-}
-smk->indexes[i] = ast[i]->index;
-ast[i]->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
-if (smk->aflags[i] & SMK_AUD_BINKAUD) {
-ast[i]->codecpar->codec_id = AV_CODEC_ID_BINKAUDIO_RDFT;
-} else if (smk->aflags[i] & SMK_AUD_USEDCT) {
-ast[i]->codecpar->codec_id = AV_CODEC_ID_BINKAUDIO_DCT;
-} else if (smk->aflags[i] & SMK_AUD_PACKED){
-ast[i]->codecpar->codec_id = AV_CODEC_ID_SMACKAUDIO;
-ast[i]->codecpar->codec_tag = MKTAG('S', 'M', 'K', 'A');
-} else {
-ast[i]->codecpar->codec_id = AV_CODEC_ID_PCM_U8;
-}
-if (smk->aflags[i] & SMK_AUD_STEREO) {
-ast[i]->codecpar->channels   = 2;
-ast[i]->codecpar->cha

[FFmpeg-devel] [PATCH 4/5] avformat/smacker: Remove unused structure

2020-03-29 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/smacker.c | 5 -
 1 file changed, 5 deletions(-)

diff --git a/libavformat/smacker.c b/libavformat/smacker.c
index 1e8858dd4e..c934615c54 100644
--- a/libavformat/smacker.c
+++ b/libavformat/smacker.c
@@ -61,11 +61,6 @@ typedef struct SmackerContext {
 int64_t aud_pts[7];
 } SmackerContext;
 
-typedef struct SmackerFrame {
-int64_t pts;
-int stream;
-} SmackerFrame;
-
 /* palette used in Smacker */
 static const uint8_t smk_pal[64] = {
 0x00, 0x04, 0x08, 0x0C, 0x10, 0x14, 0x18, 0x1C,
-- 
2.20.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/5] avformat/smacker: Only store what is needed later

2020-03-29 Thread Andreas Rheinhardt
This commit removes data that is only used during smacker_read_header()
from the demuxer's context and replaces the data that is used by local
variables. The other data is completely dropped.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/smacker.c | 74 +++
 1 file changed, 33 insertions(+), 41 deletions(-)

diff --git a/libavformat/smacker.c b/libavformat/smacker.c
index b08f7bb4e6..1e8858dd4e 100644
--- a/libavformat/smacker.c
+++ b/libavformat/smacker.c
@@ -43,22 +43,12 @@ enum SAudFlags {
 };
 
 typedef struct SmackerContext {
-/* Smacker file header */
-uint32_t magic;
-uint32_t width, height;
 uint32_t frames;
-int  pts_inc;
-uint32_t flags;
-uint32_t audio[7];
-uint32_t treesize;
-uint32_t pad;
 /* frame info */
 uint32_t *frm_size;
 uint8_t  *frm_flags;
 /* internal variables */
 int cur_frame;
-int is_ver4;
-int64_t cur_pts;
 /* current frame for demuxing */
 uint8_t pal[768];
 int indexes[7];
@@ -106,34 +96,36 @@ static int smacker_read_header(AVFormatContext *s)
 AVIOContext *pb = s->pb;
 SmackerContext *smk = s->priv_data;
 AVStream *st;
-int i, ret;
+uint32_t magic, width, height, flags, treesize;
+int i, ret, pts_inc;
 int tbase;
 
 /* read and check header */
-smk->magic = avio_rl32(pb);
-if (smk->magic != MKTAG('S', 'M', 'K', '2') && smk->magic != MKTAG('S', 
'M', 'K', '4'))
+magic  = avio_rl32(pb);
+if (magic != MKTAG('S', 'M', 'K', '2') && magic != MKTAG('S', 'M', 'K', 
'4'))
 return AVERROR_INVALIDDATA;
-smk->width = avio_rl32(pb);
-smk->height = avio_rl32(pb);
+width  = avio_rl32(pb);
+height = avio_rl32(pb);
 smk->frames = avio_rl32(pb);
-smk->pts_inc = (int32_t)avio_rl32(pb);
-if (smk->pts_inc > INT_MAX / 100) {
-av_log(s, AV_LOG_ERROR, "pts_inc %d is too large\n", smk->pts_inc);
+pts_inc = avio_rl32(pb);
+if (pts_inc > INT_MAX / 100) {
+av_log(s, AV_LOG_ERROR, "pts_inc %d is too large\n", pts_inc);
 return AVERROR_INVALIDDATA;
 }
 
-smk->flags = avio_rl32(pb);
-if(smk->flags & SMACKER_FLAG_RING_FRAME)
+flags = avio_rl32(pb);
+if (flags & SMACKER_FLAG_RING_FRAME)
 smk->frames++;
 if (smk->frames > 0xFF) {
 av_log(s, AV_LOG_ERROR, "Too many frames: %"PRIu32"\n", smk->frames);
 return AVERROR_INVALIDDATA;
 }
-for(i = 0; i < 7; i++)
-smk->audio[i] = avio_rl32(pb);
-smk->treesize = avio_rl32(pb);
 
-if(smk->treesize >= UINT_MAX/4){ // smk->treesize + 16 must not overflow 
(this check is probably redundant)
+avio_skip(pb, 28); /* Unused audio related data */
+
+treesize = avio_rl32(pb);
+if (treesize >= UINT_MAX/4) {
+// treesize + 16 must not overflow (this check is probably redundant)
 av_log(s, AV_LOG_ERROR, "treesize too large\n");
 return AVERROR_INVALIDDATA;
 }
@@ -142,10 +134,24 @@ static int smacker_read_header(AVFormatContext *s)
 if (!st)
 return AVERROR(ENOMEM);
 
-if ((ret = ff_alloc_extradata(st->codecpar, smk->treesize + 16)) < 0) {
+/* Smacker uses 10 as internal timebase */
+if (pts_inc < 0)
+pts_inc = -pts_inc;
+else
+pts_inc *= 100;
+tbase = 10;
+av_reduce(&tbase, &pts_inc, tbase, pts_inc, (1UL << 31) - 1);
+avpriv_set_pts_info(st, 33, pts_inc, tbase);
+
+/* init video codec */
+st->codecpar->width = width;
+st->codecpar->height= height;
+st->codecpar->codec_tag = magic;
+
+if ((ret = ff_alloc_extradata(st->codecpar, treesize + 16)) < 0) {
 av_log(s, AV_LOG_ERROR,
"Cannot allocate %"PRIu32" bytes of extradata\n",
-   smk->treesize + 16);
+   treesize + 16);
 return ret;
 }
 if ((ret = ffio_read_size(pb, st->codecpar->extradata, 16)) < 0)
@@ -191,7 +197,7 @@ static int smacker_read_header(AVFormatContext *s)
 * ast->codecpar->channels * 
ast->codecpar->bits_per_coded_sample / 8);
 }
 }
-smk->pad = avio_rl32(pb);
+avio_rl32(pb); /* padding */
 /* setup data */
 smk->frm_size = av_malloc_array(smk->frames, sizeof(*smk->frm_size));
 smk->frm_flags = av_malloc(smk->frames);
@@ -201,8 +207,6 @@ static int smacker_read_header(AVFormatContext *s)
 return AVERROR(ENOMEM);
 }
 
-smk->is_ver4 = (smk->magic != MKTAG('S', 'M', 'K', '2'));
-
 /* read frame info */
 for(i = 0; i < smk->frames; i++) {
 smk->frm_size[i] = avio_rl32(pb);
@@ -211,22 +215,10 @@ static int smacker_read_header(AVFormatContext *s)
 smk->frm_flags[i] = avio_r8(pb);
 }
 
-/* init video codec */
 smk->videoindex = st->index;
-st->codecpar->width = smk->width;
-st->codecpar->height = smk->height;
 st->codecpar->format = AV_PIX_FMT_PAL8;
 st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
 st->

[FFmpeg-devel] [PATCH 5/5] avformat/smacker: Cosmetics

2020-03-29 Thread Andreas Rheinhardt
This is mainly about improving legibility of the code and getting rid of
overlong lines by using variables for st->codecpar instead of accessing
the codec parameters via st->codecpar->.

Also, some code has been moved to better fitting places.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/smacker.c | 75 +++
 1 file changed, 40 insertions(+), 35 deletions(-)

diff --git a/libavformat/smacker.c b/libavformat/smacker.c
index c934615c54..8b1e185817 100644
--- a/libavformat/smacker.c
+++ b/libavformat/smacker.c
@@ -91,6 +91,7 @@ static int smacker_read_header(AVFormatContext *s)
 AVIOContext *pb = s->pb;
 SmackerContext *smk = s->priv_data;
 AVStream *st;
+AVCodecParameters *par;
 uint32_t magic, width, height, flags, treesize;
 int i, ret, pts_inc;
 int tbase;
@@ -129,6 +130,7 @@ static int smacker_read_header(AVFormatContext *s)
 if (!st)
 return AVERROR(ENOMEM);
 
+smk->videoindex = st->index;
 /* Smacker uses 10 as internal timebase */
 if (pts_inc < 0)
 pts_inc = -pts_inc;
@@ -137,23 +139,28 @@ static int smacker_read_header(AVFormatContext *s)
 tbase = 10;
 av_reduce(&tbase, &pts_inc, tbase, pts_inc, (1UL << 31) - 1);
 avpriv_set_pts_info(st, 33, pts_inc, tbase);
+st->duration = smk->frames;
 
 /* init video codec */
-st->codecpar->width = width;
-st->codecpar->height= height;
-st->codecpar->codec_tag = magic;
-
-if ((ret = ff_alloc_extradata(st->codecpar, treesize + 16)) < 0) {
+par = st->codecpar;
+par->width  = width;
+par->height = height;
+par->format = AV_PIX_FMT_PAL8;
+par->codec_type = AVMEDIA_TYPE_VIDEO;
+par->codec_id   = AV_CODEC_ID_SMACKVIDEO;
+par->codec_tag  = magic;
+
+if ((ret = ff_alloc_extradata(par, treesize + 16)) < 0) {
 av_log(s, AV_LOG_ERROR,
"Cannot allocate %"PRIu32" bytes of extradata\n",
treesize + 16);
 return ret;
 }
-if ((ret = ffio_read_size(pb, st->codecpar->extradata, 16)) < 0)
+if ((ret = ffio_read_size(pb, par->extradata, 16)) < 0)
 return ret;
 
 /* handle possible audio streams */
-for(i = 0; i < 7; i++) {
+for (i = 0; i < 7; i++) {
 uint32_t rate = avio_rl24(pb);
 uint8_t aflag = avio_r8(pb);
 
@@ -161,40 +168,44 @@ static int smacker_read_header(AVFormatContext *s)
 
 if (rate) {
 AVStream *ast = avformat_new_stream(s, NULL);
+AVCodecParameters *par;
 if (!ast)
 return AVERROR(ENOMEM);
 
 smk->indexes[i] = ast->index;
-ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
+par = ast->codecpar;
+par->codec_type = AVMEDIA_TYPE_AUDIO;
 if (aflag & SMK_AUD_BINKAUD) {
-ast->codecpar->codec_id  = AV_CODEC_ID_BINKAUDIO_RDFT;
+par->codec_id  = AV_CODEC_ID_BINKAUDIO_RDFT;
 } else if (aflag & SMK_AUD_USEDCT) {
-ast->codecpar->codec_id  = AV_CODEC_ID_BINKAUDIO_DCT;
+par->codec_id  = AV_CODEC_ID_BINKAUDIO_DCT;
 } else if (aflag & SMK_AUD_PACKED) {
-ast->codecpar->codec_id  = AV_CODEC_ID_SMACKAUDIO;
-ast->codecpar->codec_tag = MKTAG('S', 'M', 'K', 'A');
+par->codec_id  = AV_CODEC_ID_SMACKAUDIO;
+par->codec_tag = MKTAG('S', 'M', 'K', 'A');
 } else {
-ast->codecpar->codec_id  = AV_CODEC_ID_PCM_U8;
+par->codec_id  = AV_CODEC_ID_PCM_U8;
 }
 if (aflag & SMK_AUD_STEREO) {
-ast->codecpar->channels   = 2;
-ast->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
+par->channels   = 2;
+par->channel_layout = AV_CH_LAYOUT_STEREO;
 } else {
-ast->codecpar->channels   = 1;
-ast->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
+par->channels   = 1;
+par->channel_layout = AV_CH_LAYOUT_MONO;
 }
-ast->codecpar->sample_rate = rate;
-ast->codecpar->bits_per_coded_sample = (aflag & SMK_AUD_16BITS) ? 
16 : 8;
-if (ast->codecpar->bits_per_coded_sample == 16 &&
-ast->codecpar->codec_id == AV_CODEC_ID_PCM_U8)
-ast->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE;
-avpriv_set_pts_info(ast, 64, 1, ast->codecpar->sample_rate
-* ast->codecpar->channels * 
ast->codecpar->bits_per_coded_sample / 8);
+par->sample_rate = rate;
+par->bits_per_coded_sample = (aflag & SMK_AUD_16BITS) ? 16 : 8;
+if (par->bits_per_coded_sample == 16 &&
+par->codec_id == AV_CODEC_ID_PCM_U8)
+par->codec_id = AV_CODEC_ID_PCM_S16LE;
+avpriv_set_pts_info(ast, 64, 1, par->sample_rate * p

Re: [FFmpeg-devel] [PATCH v1 3/4] avformat: add subtitle support in master playlist m3u8

2020-03-29 Thread Limin Wang
On Sun, Mar 29, 2020 at 04:32:06PM +0800, Steven Liu wrote:
> 
> 
> > 2020年3月26日 下午9:56,lance.lmw...@gmail.com 写道:
> > 
> > From: Limin Wang 
> > 
> > Test with the following command for the webvtt subtitle:
> > $ ./ffmpeg -y -i input_with_subtitle.mkv \
> > -b:v:0 5250k -c:v h264 -pix_fmt yuv420p -profile:v main -level 4.1 \
> > -b:a:0 256k \
> > -c:s webvtt -c:a mp2 -ar 48000 -ac 2 -map 0:v -map 0:a:0 -map 0:s:0 \
> > -f hls -var_stream_map "v:0,a:0,s:0,sgroup:subtitle” \
> What about add the example into doc/muxer.texi ?

Sure, I have add one example into muxer.texi and send updated the patch.

> > -master_pl_name master.m3u8 -t 300 -hls_time 10 -hls_init_time 4 
> > -hls_list_size \
> > 10 -master_pl_publish_rate 10  -hls_flags \
> > delete_segments+discont_start+split_by_time ./tmp/video.m3u8
> > 
> > Check the master m3u8:
> > $ cat tmp/master.m3u8
> > #EXTM3U
> > #EXT-X-VERSION:3
> > #EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subtitle",NAME="subtitle_0",DEFAULT=YES,URI="video_vtt.m3u8"
> > #EXT-X-STREAM-INF:BANDWIDTH=6056600,RESOLUTION=1280x720,CODECS="avc1.4d4829,mp4a.40.33",SUBTITLES="subtitle"
> > video.m3u8
> > 
> > Check the result by convert to mkv:
> > $ ./ffmpeg -strict experimental -i ./tmp/master.m3u8 -c:v copy -c:a mp2 
> > -c:s srt ./test.mkv
> > 
> > Signed-off-by: Limin Wang 
> > ---
> > libavformat/dashenc.c |  2 +-
> > libavformat/hlsenc.c  | 26 --
> > libavformat/hlsplaylist.c | 17 -
> > libavformat/hlsplaylist.h |  4 +++-
> > 4 files changed, 44 insertions(+), 5 deletions(-)
> > 
> > diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
> > index 94d463972a..d1fe90b00c 100644
> > --- a/libavformat/dashenc.c
> > +++ b/libavformat/dashenc.c
> > @@ -1311,7 +1311,7 @@ static int write_manifest(AVFormatContext *s, int 
> > final)
> > get_hls_playlist_name(playlist_file, sizeof(playlist_file), 
> > NULL, i);
> > ff_hls_write_stream_info(st, c->m3u8_out, stream_bitrate,
> >  playlist_file, agroup,
> > - codec_str_ptr, NULL);
> > + codec_str_ptr, NULL, NULL);
> > }
> > dashenc_io_close(s, &c->m3u8_out, temp_filename);
> > if (use_rename)
> > diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> > index a0a3a4647b..d7b9c0e20a 100644
> > --- a/libavformat/hlsenc.c
> > +++ b/libavformat/hlsenc.c
> > @@ -164,6 +164,7 @@ typedef struct VariantStream {
> > int is_default; /* default status of audio group */
> > char *language; /* audio lauguage name */
> > char *agroup; /* audio group name */
> > +char *sgroup; /* subtitle group name */
> > char *ccgroup; /* closed caption group name */
> > char *baseurl;
> > char *varname; // variant name
> > @@ -1289,7 +1290,9 @@ static int create_master_playlist(AVFormatContext *s,
> > unsigned int i, j;
> > int ret, bandwidth;
> > const char *m3u8_rel_name = NULL;
> > +const char *vtt_m3u8_rel_name = NULL;
> > char *ccgroup;
> > +char *sgroup = NULL;
> > ClosedCaptionsStream *ccs;
> > const char *proto = avio_find_protocol_name(hls->master_m3u8_url);
> > int is_file_proto = proto && !strcmp(proto, "file");
> > @@ -1412,13 +1415,24 @@ static int create_master_playlist(AVFormatContext 
> > *s,
> > vs->ccgroup);
> > }
> > 
> > +if (vid_st && vs->sgroup) {
> > +sgroup = vs->sgroup;
> > +vtt_m3u8_rel_name = get_relative_url(hls->master_m3u8_url, 
> > vs->vtt_m3u8_name);
> > +if (!vtt_m3u8_rel_name) {
> > +av_log(s, AV_LOG_WARNING, "Unable to find relative 
> > subtitle URL\n");
> > +break;
> > +}
> > +
> > +ff_hls_write_subtitle_rendition(hls->m3u8_out, sgroup, 
> > vtt_m3u8_rel_name, vs->language, i, hls->has_default_key ? vs->is_default : 
> > 1);
> > +}
> > +
> > if (!hls->has_default_key || !hls->has_video_m3u8) {
> > ff_hls_write_stream_info(vid_st, hls->m3u8_out, bandwidth, 
> > m3u8_rel_name,
> > -aud_st ? vs->agroup : NULL, vs->codec_attr, ccgroup);
> > +aud_st ? vs->agroup : NULL, vs->codec_attr, ccgroup, 
> > sgroup);
> > } else {
> > if (vid_st) {
> > ff_hls_write_stream_info(vid_st, hls->m3u8_out, bandwidth, 
> > m3u8_rel_name,
> > - aud_st ? vs->agroup : NULL, 
> > vs->codec_attr, ccgroup);
> > + aud_st ? vs->agroup : NULL, 
> > vs->codec_attr, ccgroup, sgroup);
> > }
> > }
> > }
> > @@ -1893,6 +1907,7 @@ static int 
> > parse_variant_stream_mapstring(AVFormatContext *s)
> >  * practical usage)
> >  *
> >  * agroup: is key to specify audio group. A string can be given as 
> > value.
> > + * sgroup: is key to specify subtitle group. A

Re: [FFmpeg-devel] [PATCH v2 2/2] avformat: add demuxer for Pro Pinball Series' Soundbanks

2020-03-29 Thread Zane van Iperen
On Sun, 29 Mar 2020 01:49:32 +0100
"Carl Eugen Hoyos"  wrote:


> Apart from what I wrote on irc:
> What surprises me most is that iirc, you explained that the
> sample_rate is written repeatedly to the file and is always identical
> in one file. Why is that not checked?
> 

The main reason is that the track headers are spread out all over the
file, which will almost certainly be larger than the probe buffer.

The best I can do is check that the sample rate of the first track
matches that of the file (as it's immediately after the main header).
I do this in the next version of the patch, which I will be posting
later.

> You seem to have a fine (and small) collection of sample rates to
> check against.
> 
> Carl Eugen

Zane

___
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/mxfdec: Correct confusing struct tag

2020-03-29 Thread Paul B Mahol
lgtm

On 3/29/20, Andreas Rheinhardt  wrote:
> Don't use typedef struct MXFTrack {...} MXFTimecodeComponent, in
> particular given the fact that MXFTrack is a type of its own.
>
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavformat/mxfdec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
> index 3374f36a88..fdd0dd2a88 100644
> --- a/libavformat/mxfdec.c
> +++ b/libavformat/mxfdec.c
> @@ -131,7 +131,7 @@ typedef struct MXFSequence {
>  uint8_t origin;
>  } MXFSequence;
>
> -typedef struct MXFTrack {
> +typedef struct MXFTimecodeComponent {
>  UID uid;
>  enum MXFMetadataSetType type;
>  int drop_frame;
> --
> 2.20.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 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] Query regarding codec parsers

2020-03-29 Thread Gautam Ramakrishnan
Hello,

I had gone through ticket #7445 and it mentions about JPEG2000 parser.
What exactly does a parser do and how is it different from a decoder?
I am unable to understand the exact use case of a parser.

-- 
-
Gautam |
___
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] Query regarding codec parsers

2020-03-29 Thread Carl Eugen Hoyos
Am So., 29. März 2020 um 14:23 Uhr schrieb Gautam Ramakrishnan
:

> I had gone through ticket #7445

Better tickets are imo:
https://trac.ffmpeg.org/ticket/4669
https://trac.ffmpeg.org/ticket/4679
sample in http://samples.ffmpeg.org/ffmpeg-bugs/trac/ticket4679/
https://trac.ffmpeg.org/ticket/4827
https://trac.ffmpeg.org/ticket/5360

Two of them look easy to fix, the difficulty could be to explain
why your fix is correct (in the commit message).

> and it mentions about JPEG2000 parser.
> What exactly does a parser do and how is it different from a decoder?
> I am unable to understand the exact use case of a parser.

Try the following:
$ cat 1.jpg 2.jpg | ffmpeg -i -f null -
(Is expected to decode two frames as can be seen in the console output,
also works for example with png)

$ cat 1.j2k 2.j2k | ffmpeg -i - -f null -
Will only decode one frame because there is no parser to split the
input.

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] avformat/mxfdec: Correct confusing struct tag

2020-03-29 Thread Tomas Härdin
sön 2020-03-29 klockan 06:06 +0200 skrev Andreas Rheinhardt:
> Don't use typedef struct MXFTrack {...} MXFTimecodeComponent, in
> particular given the fact that MXFTrack is a type of its own.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavformat/mxfdec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
> index 3374f36a88..fdd0dd2a88 100644
> --- a/libavformat/mxfdec.c
> +++ b/libavformat/mxfdec.c
> @@ -131,7 +131,7 @@ typedef struct MXFSequence {
>  uint8_t origin;
>  } MXFSequence;
>  
> -typedef struct MXFTrack {
> +typedef struct MXFTimecodeComponent {
>  UID uid;
>  enum MXFMetadataSetType type;
>  int drop_frame;

I noticed this as well, just the other day. LGTM

/Tomas

___
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 v5 1/2] avcodec: add support for Cunning Developments' ADPCM

2020-03-29 Thread Zane van Iperen
Signed-off-by: Zane van Iperen 
---
 Changelog   |  1 +
 doc/general.texi|  1 +
 libavcodec/Makefile |  1 +
 libavcodec/adpcm.c  | 33 +
 libavcodec/adpcm_data.c | 13 +
 libavcodec/adpcm_data.h |  2 ++
 libavcodec/allcodecs.c  |  1 +
 libavcodec/avcodec.h|  1 +
 libavcodec/codec_desc.c |  7 +++
 libavcodec/version.h|  4 ++--
 10 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/Changelog b/Changelog
index 05b9a84562..4bcd109f64 100644
--- a/Changelog
+++ b/Changelog
@@ -55,6 +55,7 @@ version :
 - CRI HCA decoder
 - CRI HCA demuxer
 - overlay_cuda filter
+- Cunning Developments ADPCM decoder
 
 
 version 4.2:
diff --git a/doc/general.texi b/doc/general.texi
index 752618a00b..dc847c577c 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -1099,6 +1099,7 @@ following image formats are supported:
 @item ADPCM G.726@tab  X  @tab  X
 @item ADPCM IMA AMV  @tab @tab  X
 @tab Used in AMV files
+@item ADPCM IMA Cunning Developments  @tab @tab  X
 @item ADPCM IMA Electronic Arts EACS  @tab @tab  X
 @item ADPCM IMA Electronic Arts SEAD  @tab @tab  X
 @item ADPCM IMA Funcom   @tab @tab  X
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index c1c9a44f2b..e799077f09 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -839,6 +839,7 @@ OBJS-$(CONFIG_ADPCM_IMA_AMV_DECODER)  += adpcm.o 
adpcm_data.o
 OBJS-$(CONFIG_ADPCM_IMA_ALP_DECODER)  += adpcm.o adpcm_data.o
 OBJS-$(CONFIG_ADPCM_IMA_APC_DECODER)  += adpcm.o adpcm_data.o
 OBJS-$(CONFIG_ADPCM_IMA_APM_DECODER)  += adpcm.o adpcm_data.o
+OBJS-$(CONFIG_ADPCM_IMA_CUNNING_DECODER)  += adpcm.o adpcm_data.o
 OBJS-$(CONFIG_ADPCM_IMA_DAT4_DECODER) += adpcm.o adpcm_data.o
 OBJS-$(CONFIG_ADPCM_IMA_DK3_DECODER)  += adpcm.o adpcm_data.o
 OBJS-$(CONFIG_ADPCM_IMA_DK4_DECODER)  += adpcm.o adpcm_data.o
diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c
index e9abddc43c..89c4572538 100644
--- a/libavcodec/adpcm.c
+++ b/libavcodec/adpcm.c
@@ -16,6 +16,7 @@
  * Simon & Schuster Interactive ADPCM decoder by Zane van Iperen 
(z...@zanevaniperen.com)
  * Ubisoft ADPCM decoder by Zane van Iperen (z...@zanevaniperen.com)
  * High Voltage Software ALP decoder by Zane van Iperen 
(z...@zanevaniperen.com)
+ * Cunning Developments decoder by Zane van Iperen (z...@zanevaniperen.com)
  *
  * This file is part of FFmpeg.
  *
@@ -109,6 +110,9 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx)
 unsigned int max_channels = 2;
 
 switch(avctx->codec->id) {
+case AV_CODEC_ID_ADPCM_IMA_CUNNING:
+max_channels = 1;
+break;
 case AV_CODEC_ID_ADPCM_DTK:
 case AV_CODEC_ID_ADPCM_EA:
 min_channels = 2;
@@ -325,6 +329,26 @@ static inline int16_t 
adpcm_ima_mtf_expand_nibble(ADPCMChannelStatus *c, int nib
 return (int16_t)c->predictor;
 }
 
+static inline int16_t adpcm_ima_cunning_expand_nibble(ADPCMChannelStatus *c, 
int8_t nibble)
+{
+int step_index;
+int predictor;
+int step;
+
+nibble = sign_extend(nibble & 0xF, 4);
+
+step = ff_adpcm_ima_cunning_step_table[c->step_index];
+step_index = c->step_index + ff_adpcm_ima_cunning_index_table[abs(nibble)];
+step_index = av_clip(step_index, 0, 60);
+
+predictor = c->predictor + (step * nibble);
+
+c->predictor = av_clip_int16(predictor);
+c->step_index = step_index;
+
+return (int16_t)c->predictor;
+}
+
 static inline int16_t adpcm_ima_wav_expand_nibble(ADPCMChannelStatus *c, 
GetBitContext *gb, int bps)
 {
 int nibble, step_index, predictor, sign, delta, diff, step, shift;
@@ -713,6 +737,7 @@ static int get_nb_samples(AVCodecContext *avctx, 
GetByteContext *gb,
 /* simple 4-bit adpcm */
 case AV_CODEC_ID_ADPCM_CT:
 case AV_CODEC_ID_ADPCM_IMA_APC:
+case AV_CODEC_ID_ADPCM_IMA_CUNNING:
 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
 case AV_CODEC_ID_ADPCM_IMA_OKI:
 case AV_CODEC_ID_ADPCM_IMA_WS:
@@ -1304,6 +1329,13 @@ static int adpcm_decode_frame(AVCodecContext *avctx, 
void *data,
 samples += avctx->channels;
 }
 break;
+case AV_CODEC_ID_ADPCM_IMA_CUNNING:
+while (bytestream2_get_bytes_left(&gb) > 0) {
+int v = bytestream2_get_byteu(&gb);
+*samples++ = adpcm_ima_cunning_expand_nibble(&c->status[0], v & 
0x0F);
+*samples++ = adpcm_ima_cunning_expand_nibble(&c->status[0], v >> 
4);
+}
+break;
 case AV_CODEC_ID_ADPCM_IMA_OKI:
 while (bytestream2_get_bytes_left(&gb) > 0) {
 int v = bytestream2_get_byteu(&gb);
@@ -2053,6 +2085,7 @@ ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_XAS,  
sample_fmts_s16p, adpcm_ea_xas,
 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_AMV, sample_fmts_s16,  adpcm_ima_amv,  
   "ADPCM IMA AMV");
 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_APC, sample_fmts_s16,  adpcm_ima_apc,  
   "ADPCM IMA CRYO APC");
 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_AP

[FFmpeg-devel] [PATCH v5 0/2] Pro Pinball Series Soundbank demuxer + decoder.

2020-03-29 Thread Zane van Iperen
Adds support for the soundbank files used by the Pro Pinball series of games.

Please CC for review.

v5:
  - add probe function
  - add flag #define's

v4:
  - fix adpcm index table type

v3:
  - fix potential memory leak if read_header() fails
  - fix a buffer overread
  - attempt seek before updating state
  - remove unneeded check
  - naming fixes

v2:
  - Add sanity checks in header fields
  - Formatting and comment fixes
  - Change the struct names to match the files

Zane van Iperen (2):
  avcodec: add support for Cunning Developments' ADPCM
  avformat: add demuxer for Pro Pinball Series' Soundbanks

 Changelog|   2 +
 doc/general.texi |   1 +
 libavcodec/Makefile  |   1 +
 libavcodec/adpcm.c   |  33 +
 libavcodec/adpcm_data.c  |  13 ++
 libavcodec/adpcm_data.h  |   2 +
 libavcodec/allcodecs.c   |   1 +
 libavcodec/avcodec.h |   1 +
 libavcodec/codec_desc.c  |   7 ++
 libavcodec/version.h |   4 +-
 libavformat/Makefile |   1 +
 libavformat/allformats.c |   1 +
 libavformat/pp_bnk.c | 259 +++
 libavformat/version.h|   2 +-
 14 files changed, 325 insertions(+), 3 deletions(-)
 create mode 100644 libavformat/pp_bnk.c

-- 
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 v5 2/2] avformat: add demuxer for Pro Pinball Series' Soundbanks

2020-03-29 Thread Zane van Iperen
Signed-off-by: Zane van Iperen 
---
 Changelog|   1 +
 libavformat/Makefile |   1 +
 libavformat/allformats.c |   1 +
 libavformat/pp_bnk.c | 259 +++
 libavformat/version.h|   2 +-
 5 files changed, 263 insertions(+), 1 deletion(-)
 create mode 100644 libavformat/pp_bnk.c

diff --git a/Changelog b/Changelog
index 4bcd109f64..8e19a71e1a 100644
--- a/Changelog
+++ b/Changelog
@@ -56,6 +56,7 @@ version :
 - CRI HCA demuxer
 - overlay_cuda filter
 - Cunning Developments ADPCM decoder
+- Pro Pinball Series Soundbank demuxer
 
 
 version 4.2:
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 8fd0d43721..9df99133fa 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -428,6 +428,7 @@ OBJS-$(CONFIG_PCM_VIDC_DEMUXER)  += pcmdec.o pcm.o
 OBJS-$(CONFIG_PCM_VIDC_MUXER)+= pcmenc.o rawenc.o
 OBJS-$(CONFIG_PJS_DEMUXER)   += pjsdec.o subtitles.o
 OBJS-$(CONFIG_PMP_DEMUXER)   += pmpdec.o
+OBJS-$(CONFIG_PP_BNK_DEMUXER)+= pp_bnk.o
 OBJS-$(CONFIG_PVA_DEMUXER)   += pva.o
 OBJS-$(CONFIG_PVF_DEMUXER)   += pvfdec.o pcm.o
 OBJS-$(CONFIG_QCP_DEMUXER)   += qcp.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 39d2c352f5..3919c9e4c1 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -341,6 +341,7 @@ extern AVInputFormat  ff_pcm_u8_demuxer;
 extern AVOutputFormat ff_pcm_u8_muxer;
 extern AVInputFormat  ff_pjs_demuxer;
 extern AVInputFormat  ff_pmp_demuxer;
+extern AVInputFormat  ff_pp_bnk_demuxer;
 extern AVOutputFormat ff_psp_muxer;
 extern AVInputFormat  ff_pva_demuxer;
 extern AVInputFormat  ff_pvf_demuxer;
diff --git a/libavformat/pp_bnk.c b/libavformat/pp_bnk.c
new file mode 100644
index 00..dbaf4923b5
--- /dev/null
+++ b/libavformat/pp_bnk.c
@@ -0,0 +1,259 @@
+/*
+ * Pro Pinball Series Soundbank (44c, 22c, 11c, 5c) demuxer.
+ *
+ * Copyright (C) 2020 Zane van Iperen (z...@zanevaniperen.com)
+ *
+ * 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 "avformat.h"
+#include "internal.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/avassert.h"
+#include "libavutil/internal.h"
+
+#define PP_BNK_MAX_READ_SIZE4096
+#define PP_BNK_FILE_HEADER_SIZE 20
+#define PP_BNK_TRACK_SIZE   20
+
+typedef struct PPBnkHeader {
+uint32_tbank_id;/*< Bank ID, useless for our purposes. */
+uint32_tsample_rate;/*< Sample rate of the contained tracks. */
+uint32_talways1;/*< Unknown, always seems to be 1. */
+uint32_ttrack_count;/*< Number of tracks in the file. */
+uint32_tflags;  /*< Flags. 2 == music, 0 == sfx. */
+} PPBnkHeader;
+
+typedef struct PPBnkTrack {
+uint32_tid; /*< Track ID. Usually track[i].id == 
track[i-1].id + 1, but not always */
+uint32_tsize;   /*< Size of the data in bytes. */
+uint32_tsample_rate;/*< Sample rate. */
+uint32_talways1_1;  /*< Unknown, always seems to be 1. */
+uint32_talways1_2;  /*< Unknown, always seems to be 1. */
+} PPBnkTrack;
+
+typedef struct PPBnkCtxTrack {
+int64_t data_offset;
+uint32_tdata_size;
+} PPBnkCtxTrack;
+
+typedef struct PPBnkCtx {
+int track_count;
+PPBnkCtxTrack   *tracks;
+uint32_tcurrent_track;
+uint32_tbytes_read;
+} PPBnkCtx;
+
+
+enum {
+PP_BNK_FLAG_PERSIST = (1 << 0), /*< This is a large file, keep in memory. 
*/
+PP_BNK_FLAG_MUSIC   = (1 << 1), /*< This is music. */
+PP_BNK_FLAG_MASK= (PP_BNK_FLAG_PERSIST | PP_BNK_FLAG_MUSIC)
+};
+
+static void pp_bnk_parse_header(PPBnkHeader *hdr, const uint8_t *buf)
+{
+hdr->bank_id= AV_RL32(buf +  0);
+hdr->sample_rate= AV_RL32(buf +  4);
+hdr->always1= AV_RL32(buf +  8);
+hdr->track_count= AV_RL32(buf + 12);
+hdr->flags  = AV_RL32(buf + 16);
+}
+
+static void pp_bnk_parse_track(PPBnkTrack *trk, const uint8_t *buf)
+{
+trk->id = AV_RL32(buf +  0);
+trk->size   = AV_RL32(buf +  4);
+trk->sample_rate= AV_RL32(buf +  8);
+trk->always1_1 

Re: [FFmpeg-devel] Query regarding codec parsers

2020-03-29 Thread Gautam Ramakrishnan
On Sun, Mar 29, 2020 at 6:12 PM Carl Eugen Hoyos  wrote:
>
> Am So., 29. März 2020 um 14:23 Uhr schrieb Gautam Ramakrishnan
> :
>
> > I had gone through ticket #7445
>
> Better tickets are imo:
> https://trac.ffmpeg.org/ticket/4669
> https://trac.ffmpeg.org/ticket/4679
> sample in http://samples.ffmpeg.org/ffmpeg-bugs/trac/ticket4679/
> https://trac.ffmpeg.org/ticket/4827
> https://trac.ffmpeg.org/ticket/5360
>
> Two of them look easy to fix, the difficulty could be to explain
> why your fix is correct (in the commit message).
>
Sure, i shall work on them then. I thought it would  be difficult to fix these.
> > and it mentions about JPEG2000 parser.
> > What exactly does a parser do and how is it different from a decoder?
> > I am unable to understand the exact use case of a parser.
>
> Try the following:
> $ cat 1.jpg 2.jpg | ffmpeg -i -f null -
> (Is expected to decode two frames as can be seen in the console output,
> also works for example with png)
>
> $ cat 1.j2k 2.j2k | ffmpeg -i - -f null -
> Will only decode one frame because there is no parser to split the
> input.
>
So does it basically try to find the SOC marker and EOC markers and split
the streams into frames?
> 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".



-- 
-
Gautam |
___
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 v2] avcodec/v4l2_m2m: fix setting the frame rate

2020-03-29 Thread Andriy Gelman
On Tue, 17. Mar 19:29, Ming Qian wrote:
> v4l2 set the frame rate through frame intervals,
> not set frame rate directly.
> the frame rate and frame intervals are reciprocal.
> so in libavdevice/v4l2.c we can see the following code:
>   tpf->numerator   = framerate_q.den;
>   tpf->denominator = framerate_q.num;
> 
> Signed-off-by: Ming Qian 
> ---
>  libavcodec/v4l2_m2m_enc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavcodec/v4l2_m2m_enc.c b/libavcodec/v4l2_m2m_enc.c
> index c9f1741bfd..84de63ec9d 100644
> --- a/libavcodec/v4l2_m2m_enc.c
> +++ b/libavcodec/v4l2_m2m_enc.c
> @@ -172,7 +172,7 @@ static int v4l2_prepare_encoder(V4L2m2mContext *s)
>   * settingss
>   */
>  if (avctx->framerate.num || avctx->framerate.den)
> -v4l2_set_timeperframe(s, avctx->framerate.num, avctx->framerate.den);
> +v4l2_set_timeperframe(s, avctx->framerate.den, avctx->framerate.num);
>  
>  /* set ext ctrls */
>  v4l2_set_ext_ctrl(s, MPEG_CID(HEADER_MODE), 
> MPEG_VIDEO(HEADER_MODE_SEPARATE), "header mode");
> -- 
> 2.17.1

v4l2m2m doesn't have a maintainer.
Any objections if I apply this patch? 

I'd set commit message to:
"The driver's frame period is incorrectly set to the frame rate. This
is fixed in the commit."

Thanks
-- 
Andriy
___
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] Query regarding codec parsers

2020-03-29 Thread Carl Eugen Hoyos
Am So., 29. März 2020 um 16:45 Uhr schrieb Gautam Ramakrishnan
:

> > > What exactly does a parser do and how is it different from a decoder?
> > > I am unable to understand the exact use case of a parser.
> >
> > Try the following:
> > $ cat 1.jpg 2.jpg | ffmpeg -i -f null -
> > (Is expected to decode two frames as can be seen in the console output,
> > also works for example with png)
> >
> > $ cat 1.j2k 2.j2k | ffmpeg -i - -f null -
> > Will only decode one frame because there is no parser to split the
> > input.
> >
> So does it basically try to find the SOC marker and EOC markers and
> split the streams into frames?

Basically, yes.
Look at existing parsers in libavcodec/*parser* (or git grep AVCodecParser),
especially the jpeg parser.

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 v3] avcodec/v4l2_m2m: handle the v4l2 eos event

2020-03-29 Thread Andriy Gelman
On Tue, 17. Mar 19:39, Ming Qian wrote:
> when the last frame of capture is dequeueed,
> driver may send this V4L2_EVENT_EOS event,
> if this event is received, then we can set the capture port done

s/dequeueed/dequeued

Also I'd change the last line to:
"If this event is received, then the capture buffers have been flushed and   
avcodec_receive_packet()/avcodec_receive_frame() can return AVERROR_EOF.
Otherwise, the draining continues until all the capture buffers have been 
dequeued or
VIDIOC_DQBUF ioctl returns an EPIPE error.

> 
> if the v4l2 m2m driver don't support V4L2_EVENT_EOS,
> just output some error message, not make it error.

Some devices may not support V4L2_EVENT_EOS. This is logged as a warning
message and not treated as a fatal error during initialization.

> 
> Without this patch imx8qm often hangs at the end of encoding/decoding when
> flushing the capture buffers
> 
> Signed-off-by: Ming Qian 
> ---
>  libavcodec/v4l2_context.c |  5 +
>  libavcodec/v4l2_m2m_dec.c |  9 +
>  libavcodec/v4l2_m2m_enc.c | 20 
>  3 files changed, 34 insertions(+)
> 
> diff --git a/libavcodec/v4l2_context.c b/libavcodec/v4l2_context.c
> index 8110bbb555..c10862aa12 100644
> --- a/libavcodec/v4l2_context.c
> +++ b/libavcodec/v4l2_context.c
> @@ -171,6 +171,11 @@ static int v4l2_handle_event(V4L2Context *ctx)
>  return 0;
>  }
>  
> +if (evt.type == V4L2_EVENT_EOS) {
> +ctx->done = 1;
> +return 0;
> +}
> +

The comments above the function definition should be updated 
because the function would also handle end of stream event. 

>  if (evt.type != V4L2_EVENT_SOURCE_CHANGE)
>  return 0;
>  
> diff --git a/libavcodec/v4l2_m2m_dec.c b/libavcodec/v4l2_m2m_dec.c
> index d666edffe4..7a4d2a43cb 100644
> --- a/libavcodec/v4l2_m2m_dec.c
> +++ b/libavcodec/v4l2_m2m_dec.c
> @@ -123,6 +123,15 @@ static int v4l2_prepare_decoder(V4L2m2mContext *s)
>  }
>  }
>  

> +memset(&sub, 0, sizeof(sub));
> +sub.type = V4L2_EVENT_EOS;
> +ret = ioctl(s->fd, VIDIOC_SUBSCRIBE_EVENT, &sub);
> +if (ret < 0) {
> +av_log(s->avctx, AV_LOG_ERROR,
> +"the v4l2 driver does not support VIDIOC_SUBSCRIBE_EVENT\n"
> +"you must provide an eos event to finish encode\n");
> +}
> +

Since some decoders may work fine without this event, I'd suggest to change to 
AV_LOG_WARNING,
and set the message as: 
"the v4l2 driver does not support end of stream VIDIOC_SUBSCRIBE_EVENT\n"

>  return 0;
>  }
>  
> diff --git a/libavcodec/v4l2_m2m_enc.c b/libavcodec/v4l2_m2m_enc.c
> index 84de63ec9d..13bd9d29f4 100644
> --- a/libavcodec/v4l2_m2m_enc.c
> +++ b/libavcodec/v4l2_m2m_enc.c
> @@ -155,6 +155,24 @@ static int v4l2_check_b_frame_support(V4L2m2mContext *s)
>  return AVERROR_PATCHWELCOME;
>  }
>  
> +static int v4l2_subscribe_eos_event(V4L2m2mContext *s)
> +{
> +struct v4l2_event_subscription sub;
> +int ret;
> +

> +memset(&sub, 0, sizeof(sub));
> +sub.type = V4L2_EVENT_EOS;
> +ret = ioctl(s->fd, VIDIOC_SUBSCRIBE_EVENT, &sub);
> +if (ret < 0) {
> +av_log(s->avctx, AV_LOG_ERROR,
> +"the v4l2 driver does not support VIDIOC_SUBSCRIBE_EVENT\n"
> +"you must provide an eos event to finish encode\n");
> +return ret;
> +}

Same here for loglevel and message.

> +
> +return 0;
> +}
> +
>  static int v4l2_prepare_encoder(V4L2m2mContext *s)
>  {
>  AVCodecContext *avctx = s->avctx;
> @@ -164,6 +182,8 @@ static int v4l2_prepare_encoder(V4L2m2mContext *s)
>  /**
>   * requirements
>   */
> +v4l2_subscribe_eos_event(s);
> +
>  ret = v4l2_check_b_frame_support(s);
>  if (ret)
>  return ret;
> -- 
> 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".

Thanks
-- 
Andriy
___
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] [RFC, PATCH]lavu/log: Do not change the terminal background colour

2020-03-29 Thread Carl Eugen Hoyos
Hi!

Attached patch fixes ticket #8587, not sure if we want this or not,
but I do not consider the missing encircled / blinking effect (that is
not used by our command line tools) an issue.

Please comment, Carl Eugen
From 64eeec19197fe7726f3bb103417ae3277b1cd8f9 Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos 
Date: Sun, 29 Mar 2020 14:32:38 +0200
Subject: [PATCH] lavu/log: Always use the default background color.

Fixes ticket #8587.
---
 libavutil/log.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavutil/log.c b/libavutil/log.c
index 8d4945249e..352a2d9d2a 100644
--- a/libavutil/log.c
+++ b/libavutil/log.c
@@ -90,7 +90,7 @@ static HANDLE con;
 #else
 
 static const uint32_t color[16 + AV_CLASS_CATEGORY_NB] = {
-[AV_LOG_PANIC  /8] =  52 << 16 | 196 << 8 | 0x41,
+[AV_LOG_PANIC  /8] = 196 << 8 | 0x41,
 [AV_LOG_FATAL  /8] = 208 <<  8 | 0x41,
 [AV_LOG_ERROR  /8] = 196 <<  8 | 0x11,
 [AV_LOG_WARNING/8] = 226 <<  8 | 0x03,
@@ -196,8 +196,7 @@ static void ansi_fputs(int level, int tint, const char *str, int local_use_color
 str);
 } else if (local_use_color == 256) {
 fprintf(stderr,
-"\033[48;5;%"PRIu32"m\033[38;5;%"PRIu32"m%s\033[0m",
-(color[level] >> 16) & 0xff,
+"\033[49m\033[38;5;%"PRIu32"m%s\033[0m",
 (color[level] >> 8) & 0xff,
 str);
 } else
-- 
2.24.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 v5 2/2] avformat: add demuxer for Pro Pinball Series' Soundbanks

2020-03-29 Thread Michael Niedermayer
On Sun, Mar 29, 2020 at 01:30:36PM +, Zane van Iperen wrote:
[...]

> +static int pp_bnk_probe(const AVProbeData *p)
> +{
> +uint32_t sample_rate = AV_RL32(p->buf +  4);
> +uint32_t track_count = AV_RL32(p->buf + 12);
> +uint32_t flags   = AV_RL32(p->buf + 16);
> +
> +if (track_count == 0 || sample_rate == 0)
> +return 0;
> +
> +/* Sometimes we have the first track header, so check that too. */
> +if (p->buf_size >= 32 && AV_RL32(p->buf + 28) != sample_rate)
> +return 0;
> +
> +/* These limits are based on analysing the game files. */
> +if (track_count > 113 || sample_rate > 44100)
> +return 10;
> +
> +if ((flags & ~PP_BNK_FLAG_MASK) != 0)
> +return 10;
> +
> +return AVPROBE_SCORE_MAX / 4 + 1;
> +}

Fails 
tools/probetest 256 4096
testing size=1
testing size=2
testing size=4
testing size=8
testing size=16
Failure of pp_bnk probing code with score=26 type=0 p=EB2 size=16
testing size=32
testing size=64
testing size=128
testing size=256
testing size=512
testing size=1024
testing size=2048

thx

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

What does censorship reveal? It reveals fear. -- Julian Assange


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 v5 2/2] avformat: add demuxer for Pro Pinball Series' Soundbanks

2020-03-29 Thread Zane van Iperen
On Sun, 29 Mar 2020 18:21:37 +0200
"Michael Niedermayer"  wrote:

> On Sun, Mar 29, 2020 at 01:30:36PM +, Zane van Iperen wrote:
> [...]
> 
> > +static int pp_bnk_probe(const AVProbeData *p)
> > +{
> > +uint32_t sample_rate = AV_RL32(p->buf +  4);
> > +uint32_t track_count = AV_RL32(p->buf + 12);
> > +uint32_t flags   = AV_RL32(p->buf + 16);
> > +
> > +if (track_count == 0 || sample_rate == 0)
> > +return 0;
> > +
> > +/* Sometimes we have the first track header, so check that
> > too. */
> > +if (p->buf_size >= 32 && AV_RL32(p->buf + 28) != sample_rate)
> > +return 0;
> > +
> > +/* These limits are based on analysing the game files. */
> > +if (track_count > 113 || sample_rate > 44100)
> > +return 10;
> > +
> > +if ((flags & ~PP_BNK_FLAG_MASK) != 0)
> > +return 10;
> > +
> > +return AVPROBE_SCORE_MAX / 4 + 1;
> > +}  
> 
> Fails
> tools/probetest 256 4096
> testing size=1
> testing size=2
> testing size=4
> testing size=8
> testing size=16
> Failure of pp_bnk probing code with score=26 type=0 p=EB2 size=16
> testing size=32
> testing size=64
> testing size=128
> testing size=256
> testing size=512
> testing size=1024
> testing size=2048
> 

I did not know that tool existed!

Have fixed the problem by checking for the specific sample
rates found in those files.

Would sending a v6 so soon after the v5 be considered spamming?

Thanks,
Zane

> thx
> 
> [...]
> --
> Michael GnuPG fingerprint:
> 9FF2128B147EF6730BADF133611EC787040B0FAB
> 
> What does censorship reveal? It reveals fear. -- Julian Assange
> ___
> 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 v6 1/2] avcodec: add support for Cunning Developments' ADPCM

2020-03-29 Thread Zane van Iperen
Signed-off-by: Zane van Iperen 
---
 Changelog   |  1 +
 doc/general.texi|  1 +
 libavcodec/Makefile |  1 +
 libavcodec/adpcm.c  | 33 +
 libavcodec/adpcm_data.c | 13 +
 libavcodec/adpcm_data.h |  2 ++
 libavcodec/allcodecs.c  |  1 +
 libavcodec/avcodec.h|  1 +
 libavcodec/codec_desc.c |  7 +++
 libavcodec/version.h|  4 ++--
 10 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/Changelog b/Changelog
index 05b9a84562..4bcd109f64 100644
--- a/Changelog
+++ b/Changelog
@@ -55,6 +55,7 @@ version :
 - CRI HCA decoder
 - CRI HCA demuxer
 - overlay_cuda filter
+- Cunning Developments ADPCM decoder
 
 
 version 4.2:
diff --git a/doc/general.texi b/doc/general.texi
index 752618a00b..dc847c577c 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -1099,6 +1099,7 @@ following image formats are supported:
 @item ADPCM G.726@tab  X  @tab  X
 @item ADPCM IMA AMV  @tab @tab  X
 @tab Used in AMV files
+@item ADPCM IMA Cunning Developments  @tab @tab  X
 @item ADPCM IMA Electronic Arts EACS  @tab @tab  X
 @item ADPCM IMA Electronic Arts SEAD  @tab @tab  X
 @item ADPCM IMA Funcom   @tab @tab  X
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index c1c9a44f2b..e799077f09 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -839,6 +839,7 @@ OBJS-$(CONFIG_ADPCM_IMA_AMV_DECODER)  += adpcm.o 
adpcm_data.o
 OBJS-$(CONFIG_ADPCM_IMA_ALP_DECODER)  += adpcm.o adpcm_data.o
 OBJS-$(CONFIG_ADPCM_IMA_APC_DECODER)  += adpcm.o adpcm_data.o
 OBJS-$(CONFIG_ADPCM_IMA_APM_DECODER)  += adpcm.o adpcm_data.o
+OBJS-$(CONFIG_ADPCM_IMA_CUNNING_DECODER)  += adpcm.o adpcm_data.o
 OBJS-$(CONFIG_ADPCM_IMA_DAT4_DECODER) += adpcm.o adpcm_data.o
 OBJS-$(CONFIG_ADPCM_IMA_DK3_DECODER)  += adpcm.o adpcm_data.o
 OBJS-$(CONFIG_ADPCM_IMA_DK4_DECODER)  += adpcm.o adpcm_data.o
diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c
index e9abddc43c..89c4572538 100644
--- a/libavcodec/adpcm.c
+++ b/libavcodec/adpcm.c
@@ -16,6 +16,7 @@
  * Simon & Schuster Interactive ADPCM decoder by Zane van Iperen 
(z...@zanevaniperen.com)
  * Ubisoft ADPCM decoder by Zane van Iperen (z...@zanevaniperen.com)
  * High Voltage Software ALP decoder by Zane van Iperen 
(z...@zanevaniperen.com)
+ * Cunning Developments decoder by Zane van Iperen (z...@zanevaniperen.com)
  *
  * This file is part of FFmpeg.
  *
@@ -109,6 +110,9 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx)
 unsigned int max_channels = 2;
 
 switch(avctx->codec->id) {
+case AV_CODEC_ID_ADPCM_IMA_CUNNING:
+max_channels = 1;
+break;
 case AV_CODEC_ID_ADPCM_DTK:
 case AV_CODEC_ID_ADPCM_EA:
 min_channels = 2;
@@ -325,6 +329,26 @@ static inline int16_t 
adpcm_ima_mtf_expand_nibble(ADPCMChannelStatus *c, int nib
 return (int16_t)c->predictor;
 }
 
+static inline int16_t adpcm_ima_cunning_expand_nibble(ADPCMChannelStatus *c, 
int8_t nibble)
+{
+int step_index;
+int predictor;
+int step;
+
+nibble = sign_extend(nibble & 0xF, 4);
+
+step = ff_adpcm_ima_cunning_step_table[c->step_index];
+step_index = c->step_index + ff_adpcm_ima_cunning_index_table[abs(nibble)];
+step_index = av_clip(step_index, 0, 60);
+
+predictor = c->predictor + (step * nibble);
+
+c->predictor = av_clip_int16(predictor);
+c->step_index = step_index;
+
+return (int16_t)c->predictor;
+}
+
 static inline int16_t adpcm_ima_wav_expand_nibble(ADPCMChannelStatus *c, 
GetBitContext *gb, int bps)
 {
 int nibble, step_index, predictor, sign, delta, diff, step, shift;
@@ -713,6 +737,7 @@ static int get_nb_samples(AVCodecContext *avctx, 
GetByteContext *gb,
 /* simple 4-bit adpcm */
 case AV_CODEC_ID_ADPCM_CT:
 case AV_CODEC_ID_ADPCM_IMA_APC:
+case AV_CODEC_ID_ADPCM_IMA_CUNNING:
 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
 case AV_CODEC_ID_ADPCM_IMA_OKI:
 case AV_CODEC_ID_ADPCM_IMA_WS:
@@ -1304,6 +1329,13 @@ static int adpcm_decode_frame(AVCodecContext *avctx, 
void *data,
 samples += avctx->channels;
 }
 break;
+case AV_CODEC_ID_ADPCM_IMA_CUNNING:
+while (bytestream2_get_bytes_left(&gb) > 0) {
+int v = bytestream2_get_byteu(&gb);
+*samples++ = adpcm_ima_cunning_expand_nibble(&c->status[0], v & 
0x0F);
+*samples++ = adpcm_ima_cunning_expand_nibble(&c->status[0], v >> 
4);
+}
+break;
 case AV_CODEC_ID_ADPCM_IMA_OKI:
 while (bytestream2_get_bytes_left(&gb) > 0) {
 int v = bytestream2_get_byteu(&gb);
@@ -2053,6 +2085,7 @@ ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_XAS,  
sample_fmts_s16p, adpcm_ea_xas,
 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_AMV, sample_fmts_s16,  adpcm_ima_amv,  
   "ADPCM IMA AMV");
 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_APC, sample_fmts_s16,  adpcm_ima_apc,  
   "ADPCM IMA CRYO APC");
 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_AP

[FFmpeg-devel] [PATCH v6 2/2] avformat: add demuxer for Pro Pinball Series' Soundbanks

2020-03-29 Thread Zane van Iperen
Signed-off-by: Zane van Iperen 
---
 Changelog|   1 +
 libavformat/Makefile |   1 +
 libavformat/allformats.c |   1 +
 libavformat/pp_bnk.c | 263 +++
 libavformat/version.h|   2 +-
 5 files changed, 267 insertions(+), 1 deletion(-)
 create mode 100644 libavformat/pp_bnk.c

diff --git a/Changelog b/Changelog
index 4bcd109f64..8e19a71e1a 100644
--- a/Changelog
+++ b/Changelog
@@ -56,6 +56,7 @@ version :
 - CRI HCA demuxer
 - overlay_cuda filter
 - Cunning Developments ADPCM decoder
+- Pro Pinball Series Soundbank demuxer
 
 
 version 4.2:
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 8fd0d43721..9df99133fa 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -428,6 +428,7 @@ OBJS-$(CONFIG_PCM_VIDC_DEMUXER)  += pcmdec.o pcm.o
 OBJS-$(CONFIG_PCM_VIDC_MUXER)+= pcmenc.o rawenc.o
 OBJS-$(CONFIG_PJS_DEMUXER)   += pjsdec.o subtitles.o
 OBJS-$(CONFIG_PMP_DEMUXER)   += pmpdec.o
+OBJS-$(CONFIG_PP_BNK_DEMUXER)+= pp_bnk.o
 OBJS-$(CONFIG_PVA_DEMUXER)   += pva.o
 OBJS-$(CONFIG_PVF_DEMUXER)   += pvfdec.o pcm.o
 OBJS-$(CONFIG_QCP_DEMUXER)   += qcp.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 39d2c352f5..3919c9e4c1 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -341,6 +341,7 @@ extern AVInputFormat  ff_pcm_u8_demuxer;
 extern AVOutputFormat ff_pcm_u8_muxer;
 extern AVInputFormat  ff_pjs_demuxer;
 extern AVInputFormat  ff_pmp_demuxer;
+extern AVInputFormat  ff_pp_bnk_demuxer;
 extern AVOutputFormat ff_psp_muxer;
 extern AVInputFormat  ff_pva_demuxer;
 extern AVInputFormat  ff_pvf_demuxer;
diff --git a/libavformat/pp_bnk.c b/libavformat/pp_bnk.c
new file mode 100644
index 00..592d25ab52
--- /dev/null
+++ b/libavformat/pp_bnk.c
@@ -0,0 +1,263 @@
+/*
+ * Pro Pinball Series Soundbank (44c, 22c, 11c, 5c) demuxer.
+ *
+ * Copyright (C) 2020 Zane van Iperen (z...@zanevaniperen.com)
+ *
+ * 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 "avformat.h"
+#include "internal.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/avassert.h"
+#include "libavutil/internal.h"
+
+#define PP_BNK_MAX_READ_SIZE4096
+#define PP_BNK_FILE_HEADER_SIZE 20
+#define PP_BNK_TRACK_SIZE   20
+
+typedef struct PPBnkHeader {
+uint32_tbank_id;/*< Bank ID, useless for our purposes. */
+uint32_tsample_rate;/*< Sample rate of the contained tracks. */
+uint32_talways1;/*< Unknown, always seems to be 1. */
+uint32_ttrack_count;/*< Number of tracks in the file. */
+uint32_tflags;  /*< Flags. 2 == music, 0 == sfx. */
+} PPBnkHeader;
+
+typedef struct PPBnkTrack {
+uint32_tid; /*< Track ID. Usually track[i].id == 
track[i-1].id + 1, but not always */
+uint32_tsize;   /*< Size of the data in bytes. */
+uint32_tsample_rate;/*< Sample rate. */
+uint32_talways1_1;  /*< Unknown, always seems to be 1. */
+uint32_talways1_2;  /*< Unknown, always seems to be 1. */
+} PPBnkTrack;
+
+typedef struct PPBnkCtxTrack {
+int64_t data_offset;
+uint32_tdata_size;
+} PPBnkCtxTrack;
+
+typedef struct PPBnkCtx {
+int track_count;
+PPBnkCtxTrack   *tracks;
+uint32_tcurrent_track;
+uint32_tbytes_read;
+} PPBnkCtx;
+
+
+enum {
+PP_BNK_FLAG_PERSIST = (1 << 0), /*< This is a large file, keep in memory. 
*/
+PP_BNK_FLAG_MUSIC   = (1 << 1), /*< This is music. */
+PP_BNK_FLAG_MASK= (PP_BNK_FLAG_PERSIST | PP_BNK_FLAG_MUSIC)
+};
+
+static void pp_bnk_parse_header(PPBnkHeader *hdr, const uint8_t *buf)
+{
+hdr->bank_id= AV_RL32(buf +  0);
+hdr->sample_rate= AV_RL32(buf +  4);
+hdr->always1= AV_RL32(buf +  8);
+hdr->track_count= AV_RL32(buf + 12);
+hdr->flags  = AV_RL32(buf + 16);
+}
+
+static void pp_bnk_parse_track(PPBnkTrack *trk, const uint8_t *buf)
+{
+trk->id = AV_RL32(buf +  0);
+trk->size   = AV_RL32(buf +  4);
+trk->sample_rate= AV_RL32(buf +  8);
+trk->always1_1 

[FFmpeg-devel] [PATCH v6 0/2] Pro Pinball Series Soundbank demuxer + decoder.

2020-03-29 Thread Zane van Iperen
Adds support for the soundbank files used by the Pro Pinball series of games.

Please CC for review.

v6:
  - fix tools/probetest failure

v5:
  - add probe function
  - add flag #define's

v4:
  - fix adpcm index table type

v3:
  - fix potential memory leak if read_header() fails
  - fix a buffer overread
  - attempt seek before updating state
  - remove unneeded check
  - naming fixes

v2:
  - Add sanity checks in header fields
  - Formatting and comment fixes
  - Change the struct names to match the files

Zane van Iperen (2):
  avcodec: add support for Cunning Developments' ADPCM
  avformat: add demuxer for Pro Pinball Series' Soundbanks

 Changelog|   2 +
 doc/general.texi |   1 +
 libavcodec/Makefile  |   1 +
 libavcodec/adpcm.c   |  33 +
 libavcodec/adpcm_data.c  |  13 ++
 libavcodec/adpcm_data.h  |   2 +
 libavcodec/allcodecs.c   |   1 +
 libavcodec/avcodec.h |   1 +
 libavcodec/codec_desc.c  |   7 ++
 libavcodec/version.h |   4 +-
 libavformat/Makefile |   1 +
 libavformat/allformats.c |   1 +
 libavformat/pp_bnk.c | 263 +++
 libavformat/version.h|   2 +-
 14 files changed, 329 insertions(+), 3 deletions(-)
 create mode 100644 libavformat/pp_bnk.c

-- 
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] mov: fix seek to next root atom in fragmented mp4

2020-03-29 Thread John Stebbins
If some but not all moof's are referenced in an sidx, whole fragments
were being skipped.

Fixes tickets 7377, 7389, and 8502
May also fix 8070 but the sample links expired, so I can't test.
---
 libavformat/mov.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index f280f360b6..8ed8b7f6e9 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -7724,7 +7724,8 @@ static int mov_switch_root(AVFormatContext *s, int64_t 
target, int index)
 mov->next_root_atom = 0;
 if (index < 0 || index >= mov->frag_index.nb_items)
 index = search_frag_moof_offset(&mov->frag_index, target);
-if (index < mov->frag_index.nb_items) {
+if (index < mov->frag_index.nb_items &&
+mov->frag_index.item[index].moof_offset == target) {
 if (index + 1 < mov->frag_index.nb_items)
 mov->next_root_atom = mov->frag_index.item[index + 1].moof_offset;
 if (mov->frag_index.item[index].headers_read)
-- 
2.25.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] mov: fix seek to next root atom in fragmented mp4

2020-03-29 Thread Andreas Rheinhardt
John Stebbins:
> If some but not all moof's are referenced in an sidx, whole fragments
> were being skipped.
> 
> Fixes tickets 7377, 7389, and 8502
> May also fix 8070 but the sample links expired, so I can't test.

Sample can be found here:
https://samples.ffmpeg.org/ffmpeg-bugs/trac/ticket8070/
(You may probably thank Carl-Eugen for this.)

- Andreas
___
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] mov: fix seek to next root atom in fragmented mp4

2020-03-29 Thread John Stebbins
On Sun, 2020-03-29 at 22:38 +0200, Andreas Rheinhardt wrote:
> John Stebbins:
> > If some but not all moof's are referenced in an sidx, whole
> > fragments
> > were being skipped.
> > 
> > Fixes tickets 7377, 7389, and 8502
> > May also fix 8070 but the sample links expired, so I can't test.
> 
> Sample can be found here:
> https://samples.ffmpeg.org/ffmpeg-bugs/trac/ticket8070/
> (You may probably thank Carl-Eugen for this.)
> 

Thanks.  So this patch *does not* fix 8070.  I'll investigate...
___
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/mpegts: use a buffer pool for PES payloads

2020-03-29 Thread James Almer
This produces a small speed up in demuxing

Signed-off-by: James Almer 
---
 libavformat/mpegts.c | 20 
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 7f56bacb2c..7746a524c4 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -157,6 +157,8 @@ struct MpegTSContext {
 int resync_size;
 int merge_pmt_versions;
 
+AVBufferPool *pool;
+
 /**/
 /* private mpegts data */
 /* scan context */
@@ -1177,8 +1179,7 @@ static int mpegts_push_data(MpegTSFilter *filter,
 pes->total_size = MAX_PES_PAYLOAD;
 
 /* allocate pes buffer */
-pes->buffer = av_buffer_alloc(pes->total_size +
-  
AV_INPUT_BUFFER_PADDING_SIZE);
+pes->buffer = av_buffer_pool_get(ts->pool);
 if (!pes->buffer)
 return AVERROR(ENOMEM);
 
@@ -1351,8 +1352,7 @@ skip:
 if (ret < 0)
 return ret;
 pes->total_size = MAX_PES_PAYLOAD;
-pes->buffer = av_buffer_alloc(pes->total_size +
-  
AV_INPUT_BUFFER_PADDING_SIZE);
+pes->buffer = av_buffer_pool_get(ts->pool);
 if (!pes->buffer)
 return AVERROR(ENOMEM);
 ts->stop_parse = 1;
@@ -3032,6 +3032,10 @@ static int mpegts_read_header(AVFormatContext *s)
 ts->stream = s;
 ts->auto_guess = 0;
 
+ts->pool = av_buffer_pool_init(MAX_PES_PAYLOAD + 
AV_INPUT_BUFFER_PADDING_SIZE, NULL);
+if (!ts->pool)
+return AVERROR(ENOMEM);
+
 if (s->iformat == &ff_mpegts_demuxer) {
 /* normal demux */
 
@@ -3200,6 +3204,8 @@ static void mpegts_free(MpegTSContext *ts)
 
 clear_programs(ts);
 
+av_buffer_pool_uninit(&ts->pool);
+
 for (i = 0; i < NB_PID_MAX; i++)
 if (ts->pids[i])
 mpegts_close_filter(ts, ts->pids[i]);
@@ -3295,6 +3301,12 @@ MpegTSContext *avpriv_mpegts_parse_open(AVFormatContext 
*s)
 ts->stream = s;
 ts->auto_guess = 1;
 
+ts->pool = av_buffer_pool_init(MAX_PES_PAYLOAD + 
AV_INPUT_BUFFER_PADDING_SIZE, NULL);
+if (!ts->pool) {
+av_free(ts);
+return NULL;
+}
+
 mpegts_open_section_filter(ts, SDT_PID, sdt_cb, ts, 1);
 mpegts_open_section_filter(ts, PAT_PID, pat_cb, ts, 1);
 mpegts_open_section_filter(ts, EIT_PID, eit_cb, ts, 1);
-- 
2.25.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".

[FFmpeg-devel] [PATCH] libavformat/mov: fix multiple trun per traf

2020-03-29 Thread John Stebbins
dts would start over at the beginning of each trun when they should be
computed contiguously for each trun in a traf

Fixes ticket 8070
---
 libavformat/isom.h |  1 +
 libavformat/mov.c  | 12 +++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/libavformat/isom.h b/libavformat/isom.h
index 4943b80ccf..41a9c64c11 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -129,6 +129,7 @@ typedef struct MOVFragmentStreamInfo {
 int64_t sidx_pts;
 int64_t first_tfra_pts;
 int64_t tfdt_dts;
+int64_t next_trun_dts;
 int index_entry;
 MOVEncryptionIndex *encryption_index;
 } MOVFragmentStreamInfo;
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 8ed8b7f6e9..f96a7d8e39 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1335,6 +1335,7 @@ static int update_frag_index(MOVContext *c, int64_t 
offset)
 frag_stream_info[i].id = c->fc->streams[i]->id;
 frag_stream_info[i].sidx_pts = AV_NOPTS_VALUE;
 frag_stream_info[i].tfdt_dts = AV_NOPTS_VALUE;
+frag_stream_info[i].next_trun_dts = AV_NOPTS_VALUE;
 frag_stream_info[i].first_tfra_pts = AV_NOPTS_VALUE;
 frag_stream_info[i].index_entry = -1;
 frag_stream_info[i].encryption_index = NULL;
@@ -4609,6 +4610,7 @@ static int mov_read_tfhd(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 MOVFragment *frag = &c->fragment;
 MOVTrackExt *trex = NULL;
 int flags, track_id, i;
+MOVFragmentStreamInfo * frag_stream_info;
 
 avio_r8(pb); /* version */
 flags = avio_rb24(pb);
@@ -4642,6 +4644,10 @@ static int mov_read_tfhd(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
  avio_rb32(pb) : trex->flags;
 av_log(c->fc, AV_LOG_TRACE, "frag flags 0x%x\n", frag->flags);
 
+frag_stream_info = get_current_frag_stream_info(&c->frag_index);
+if (frag_stream_info)
+frag_stream_info->next_trun_dts = AV_NOPTS_VALUE;
+
 return 0;
 }
 
@@ -4795,7 +4801,9 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 frag_stream_info = get_current_frag_stream_info(&c->frag_index);
 if (frag_stream_info)
 {
-if (frag_stream_info->first_tfra_pts != AV_NOPTS_VALUE &&
+if (frag_stream_info->next_trun_dts != AV_NOPTS_VALUE) {
+dts = frag_stream_info->next_trun_dts - sc->time_offset;
+} else if (frag_stream_info->first_tfra_pts != AV_NOPTS_VALUE &&
 c->use_mfra_for == FF_MOV_FLAG_MFRA_PTS) {
 pts = frag_stream_info->first_tfra_pts;
 av_log(c->fc, AV_LOG_DEBUG, "found mfra time %"PRId64
@@ -4950,6 +4958,8 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 sc->nb_frames_for_fps ++;
 }
 }
+if (frag_stream_info)
+frag_stream_info->next_trun_dts = dts + sc->time_offset;
 if (i < entries) {
 // EOF found before reading all entries.  Fix the hole this would
 // leave in index_entries and ctts_data
-- 
2.25.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] mov: fix seek to next root atom in fragmented mp4

2020-03-29 Thread Carl Eugen Hoyos
Am So., 29. März 2020 um 22:33 Uhr schrieb John Stebbins
:
>
> If some but not all moof's are referenced in an sidx, whole fragments
> were being skipped.
>
> Fixes tickets 7377, 7389, and 8502
> May also fix 8070 but the sample links expired, so I can't test.

Thank you for looking into this!

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".

[FFmpeg-devel] [GSoC] [WIP] [RFC] FLIF Encoder & Decoder Project

2020-03-29 Thread Kartik K. Khullar
This is my WIP patch for GSoC and I worked on transformations involved in
encoding/decoding FLIF images. I have created a module under libavcodec and
as guided by my mentors I have tried to use pixel data from AVFrame structs.
Module covers all the chunks of code for YCoCg Transformation that will be
used in final encoder/decoder. Necessary structs and methods have been made
as suggested by my mentors. The module compiles/builds successfully.
Also I have attached a small code 'transformtest.c' which I wrote for
testing the implementation of pixel transformation.
The variable AVFrame::data[] is of type uint8_t* and I was initially
unaware of this so I stored the YCoCg values in 'data'. So the negative
values which were the output of transformation of RGB -> YCoCg were not
stored properly and thats where the output is wrong.
Just wanted to ask, if I should be using some other structs for storing the
YCoCg values and not AVFrame, because AVFrame seems to be the standard
struct in FFmpeg where the raw media resides.
Attaching some testcases of RGB and its corresponding YCoCg values for
testing purposes.

Thanks
Kartik K. Khullar
#include "transformflif16.h"

int process(Transform transform, AVFrame *frame, int p){
switch(transform.transform_number){
case 1: //Transform number for YCoCg transformation is 1 officially.
if(!transform.done){
			TransformYCoCg transformYCoCg = initYCoCg(frame, p);
if(!processYCoCg(frame))
	transform.done = 1;
return 0;
}
		break;

/*
Rest of the cases will be implemented here.
*/

default:
break;
}
return 0;
}

TransformYCoCg initYCoCg(AVFrame *frame, int p){
	TransformYCoCg transform;
	transform.num_planes = p;
	transform.ranges = getRanges(transform.num_planes, frame);
transform.origmax4 = max(transform.ranges[0].max, transform.ranges[1].max, transform.ranges[2].max)/4 -1;
for(p=0; pdata[0][r*width + c];
G = frame->data[1][r*width + c];
B = frame->data[2][r*width + c];

Y = (((R + B)>>1) + G)>>1;
Co = R - B;
Cg = G - ((R + B)>>1);

frame->data[0][r*width + c] = Y;
frame->data[1][r*width + c] = Co;
frame->data[2][r*width + c] = Cg;
}
}
	return 0;
}

int invProcessYCoCg(AVFrame *frame){
	int r, c;
ColorVal R,G,B,Y,Co,Cg;

//Assuming all the channels will have same width and height
	int height = frame[0].height;
int width = frame[0].width;

	for (r=0; rdata[0][r*width + c];
Co= frame->data[1][r*width + c];
Cg= frame->data[2][r*width + c];

R = Co + Y + ((1-Cg)>>1) - (Co>>1);
G = Y - ((-Cg)>>1);
B = Y + ((1-Cg)>>1) - (Co>>1);

frame->data[0][r*width + c] = R;
frame->data[1][r*width + c] = G;
frame->data[2][r*width + c] = B;
}
}
	return 0;
}

ColorRanges* getRanges(int p, AVFrame *frame){
ColorRanges ranges[p];
int i, c, r, width, height;
uint8_t min, max;

for(i=0; idata[p][0];
max = frame->data[p][0];
for(r=0; r frame->data[p][r*width + c])
min = frame->data[p][r*width + c];
if(max < frame->data[p][r*width + c])
max = frame->data[p][r*width + c];
}
}
ranges[p].min = min;
ranges[p].max = max;
}
return ranges;
}

int max(int a, int b, int c){
	if(a > b){
		if(a > c)
			return a;
		else
			return c;
	}
	else
		return b;
}

int min(int a, int b){
	if(a < b)
		return a;
	else
		return b;
}

int get_min_y(int origmax4){
	return 0;
}

int get_max_y(int origmax4){
	return 4*origmax4-1;
}

int get_min_co(int origmax4, int yval){
	int newmax = 4*origmax4 - 1;
	if (yval < origmax4-1)
	return -3 - 4*yval; 
	else if (yval >= 3*origmax4)
  	return 4*(yval - newmax);
else
  	return -newmax;
}

int get_max_co(int origmax4, int yval){
	int newmax = 4*origmax4 - 1;
	if (yval < origmax4-1)
	return 3 + 4*yval; 
	else if (yval >= 3*origmax4)
  	return 4*(newmax - yval);
else
  	return newmax;
}

int get_min_cg(int origmax4, int yval, int coval){
	int newmax = 4*origmax4 - 1;
	if (yval < origmax4-1)
	return -2 - 2*yval; 
	else if (yval >= 3*origmax4)
  	return -2*(newmax-yval) + 2*((abs(coval)+1)/2);
else{
  	return min(2*yval + 1, 2*newmax - 2*yval - 2*abs(coval)+1)/2;
	}
}

int get_max_cg(int origmax4, int yval, int coval){
	int newmax = 4*origmax4 - 1;
	if (yval < origmax4-1)
	return 1 + 2*yval - 2*(abs(coval)/2); 
	else if (yval >= 3*origmax4)
  	return 2 * (newmax-yval);
else
  	return min(2*(yval- newmax), -2*yval - 1 + 2*(abs(coval)/2));
}

int min_range_YCoCg(int p, int origmax4){
	switch(p){
		case 0:
			return 0;
case 1:
			return -4*origmax4+1;
case 2:
			return -4*origmax4+1;
		default:
			return 0;
			break;
	}
}

int max_range_YC

Re: [FFmpeg-devel] [PATCH v6 2/2] libavcodec/jpeg2000dec.c: Handle non EOC streams

2020-03-29 Thread Michael Niedermayer
On Sat, Mar 28, 2020 at 09:16:41PM +0530, gautamr...@gmail.com wrote:
> From: Gautam Ramakrishnan 
> 
> This patch allows decoding of j2k streams which do
> not have an EOC marker. OpenJPEG implements a similar
> check.
> ---
>  libavcodec/jpeg2000dec.c | 8 ++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
> index 55fab00152..4f923d620d 100644
> --- a/libavcodec/jpeg2000dec.c
> +++ b/libavcodec/jpeg2000dec.c
> @@ -2078,8 +2078,12 @@ static int 
> jpeg2000_read_main_headers(Jpeg2000DecoderContext *s)
>  
>  len = bytestream2_get_be16(&s->g);
>  if (len < 2 || bytestream2_get_bytes_left(&s->g) < len - 2) {
> -av_log(s->avctx, AV_LOG_ERROR, "Invalid len %d left=%d\n", len, 
> bytestream2_get_bytes_left(&s->g));
> -return AVERROR_INVALIDDATA;
> +if (s->avctx->strict_std_compliance >= FF_COMPLIANCE_STRICT) {
> +av_log(s->avctx, AV_LOG_ERROR, "Invalid len %d left=%d\n", 
> len, bytestream2_get_bytes_left(&s->g));
> +return AVERROR_INVALIDDATA;
> +}
> +av_log(s->avctx, AV_LOG_WARNING, "Mising EOC Marker.\n");

> +return 0;

this should be the same as the other EOC handling is (break)
(makes no differences of course but its more consistent and if any code is
 added in the future it could become a bug)

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

Breaking DRM is a little like attempting to break through a door even
though the window is wide open and the only thing in the house is a bunch
of things you dont want and which you would get tomorrow for free anyway


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 v6 1/2] libavcodec/jpeg2000dec.c: Add functions and modify structs for PPT marker support

2020-03-29 Thread Michael Niedermayer
On Sat, Mar 28, 2020 at 09:16:40PM +0530, gautamr...@gmail.com wrote:
> From: Gautam Ramakrishnan 
> 
> This patch adds support for the PPT marker. It breaks down the
> jpeg2000_decode_packet() function to decode headers and data
> separately.
> ---
>  libavcodec/jpeg2000dec.c | 202 +--
>  1 file changed, 172 insertions(+), 30 deletions(-)
> 

[...]

> @@ -927,30 +965,38 @@ static int getlblockinc(Jpeg2000DecoderContext *s)
>  return res;
>  }
>  
> -static int jpeg2000_decode_packet(Jpeg2000DecoderContext *s, Jpeg2000Tile 
> *tile, int *tp_index,
> -  Jpeg2000CodingStyle *codsty,
> -  Jpeg2000ResLevel *rlevel, int precno,
> -  int layno, uint8_t *expn, int numgbits)
> +static int jpeg2000_decode_packet_header(Jpeg2000DecoderContext *s, 
> Jpeg2000Tile *tile,
> + int *tp_index,
> + Jpeg2000CodingStyle *codsty,
> + Jpeg2000ResLevel *rlevel, int 
> precno,
> + int layno, uint8_t *expn, int 
> numgbits,
> + int *process_data)
>  {
>  int bandno, cblkno, ret, nb_code_blocks;
> -int cwsno;
>  
> -if (layno < rlevel->band[0].prec[precno].decoded_layers)
> +if (layno < rlevel->band[0].prec[precno].decoded_layers) {
> +*process_data = 0;
>  return 0;
> +}
>  rlevel->band[0].prec[precno].decoded_layers = layno + 1;
>  
> -if (bytestream2_get_bytes_left(&s->g) == 0 && s->bit_index == 8) {
> -if (*tp_index < FF_ARRAY_ELEMS(tile->tile_part) - 1) {
> -s->g = tile->tile_part[++(*tp_index)].tpg;
> +if (tile->has_ppt) {
> +s->g = tile->packed_headers_stream;
> +} else {
> +s->g = tile->tile_part[*tp_index].tpg;
> +if (bytestream2_get_bytes_left(&s->g) == 0 && s->bit_index == 8) 
> {
> +if (*tp_index < FF_ARRAY_ELEMS(tile->tile_part) - 1) {
> +s->g = tile->tile_part[++(*tp_index)].tpg;
> +}
>  }
> +if (bytestream2_peek_be32(&s->g) == JPEG2000_SOP_FIXED_BYTES)
> +bytestream2_skip(&s->g, JPEG2000_SOP_BYTE_LENGTH);
>  }
>  
> -if (bytestream2_peek_be32(&s->g) == JPEG2000_SOP_FIXED_BYTES)
> -bytestream2_skip(&s->g, JPEG2000_SOP_BYTE_LENGTH);
> -
>  if (!(ret = get_bits(s, 1))) {
>  jpeg2000_flush(s);
> -return 0;
> +*process_data = 0;
> +goto end;
>  } else if (ret < 0)
>  return ret;
>  
> @@ -1055,6 +1101,34 @@ static int 
> jpeg2000_decode_packet(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
>  else
>  av_log(s->avctx, AV_LOG_ERROR, "EPH marker not found. instead 
> %X\n", bytestream2_peek_be32(&s->g));
>  }
> +end:
> +if (tile->has_ppt)
> +tile->packed_headers_stream = s->g;
> +else
> +tile->tile_part[*tp_index].tpg = s->g;
> +return 0;
> +}
> +
> +static int jpeg2000_decode_packet_data(Jpeg2000DecoderContext *s, 
> Jpeg2000Tile *tile,
> +   int *tp_index,
> +   Jpeg2000CodingStyle *codsty,
> +   Jpeg2000ResLevel *rlevel, int precno,
> +   int layno, uint8_t *expn, int 
> numgbits)
> +{
> +int bandno, cblkno, nb_code_blocks;
> +int cwsno;
> +
> +s->g = tile->tile_part[*tp_index].tpg;
> +if (tile->has_ppt) {
> +if (bytestream2_get_bytes_left(&s->g) == 0 && s->bit_index == 8) {
> +if (*tp_index < FF_ARRAY_ELEMS(tile->tile_part) - 1) {
> +s->g = tile->tile_part[++(*tp_index)].tpg;
> +}
> +}
> +if (bytestream2_peek_be32(&s->g) == JPEG2000_SOP_FIXED_BYTES)
> +bytestream2_skip(&s->g, JPEG2000_SOP_BYTE_LENGTH);
> +}
> +
>  
>  for (bandno = 0; bandno < rlevel->nbands; bandno++) {
>  Jpeg2000Band *band = rlevel->band + bandno;
> @@ -1097,6 +1171,7 @@ static int 
> jpeg2000_decode_packet(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
>  av_freep(&cblk->lengthinc);
>  }
>  }
> +tile->tile_part[*tp_index].tpg = s->g;
>  return 0;
>  }

I think this function spliting should be in a seperate patch from adding 
ppt support.
It would make the changes more readable in the git log

thanks

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

I have never wished to cater to the crowd; for what I know they do not
approve, and what they approve I do not know. -- Epicurus


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-

Re: [FFmpeg-devel] [PATCH 4/4] avfilter/vf_derain.c: put all the calculation in model file.

2020-03-29 Thread Guo, Yejun


> -Original Message-
> From: Steven Liu [mailto:l...@chinaffmpeg.org]
> Sent: Monday, March 23, 2020 1:05 PM
> To: FFmpeg development discussions and patches 
> Cc: Steven Liu ; Guo, Yejun 
> Subject: Re: [FFmpeg-devel] [PATCH 4/4] avfilter/vf_derain.c: put all the
> calculation in model file.
> 
> 
> LGTM

thanks, and the rest patches of this patch set ask for review, thanks.

> 
> Thanks
> 
> Steven Liu
> 
> 

___
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 v6 1/2] libavcodec/jpeg2000dec.c: Add functions and modify structs for PPT marker support

2020-03-29 Thread Gautam Ramakrishnan
On Mon, Mar 30, 2020 at 6:31 AM Michael Niedermayer
 wrote:
>
> On Sat, Mar 28, 2020 at 09:16:40PM +0530, gautamr...@gmail.com wrote:
> > From: Gautam Ramakrishnan 
> >
> > This patch adds support for the PPT marker. It breaks down the
> > jpeg2000_decode_packet() function to decode headers and data
> > separately.
> > ---
> >  libavcodec/jpeg2000dec.c | 202 +--
> >  1 file changed, 172 insertions(+), 30 deletions(-)
> >
>
> [...]
>
> > @@ -927,30 +965,38 @@ static int getlblockinc(Jpeg2000DecoderContext *s)
> >  return res;
> >  }
> >
> > -static int jpeg2000_decode_packet(Jpeg2000DecoderContext *s, Jpeg2000Tile 
> > *tile, int *tp_index,
> > -  Jpeg2000CodingStyle *codsty,
> > -  Jpeg2000ResLevel *rlevel, int precno,
> > -  int layno, uint8_t *expn, int numgbits)
> > +static int jpeg2000_decode_packet_header(Jpeg2000DecoderContext *s, 
> > Jpeg2000Tile *tile,
> > + int *tp_index,
> > + Jpeg2000CodingStyle *codsty,
> > + Jpeg2000ResLevel *rlevel, int 
> > precno,
> > + int layno, uint8_t *expn, int 
> > numgbits,
> > + int *process_data)
> >  {
> >  int bandno, cblkno, ret, nb_code_blocks;
> > -int cwsno;
> >
> > -if (layno < rlevel->band[0].prec[precno].decoded_layers)
> > +if (layno < rlevel->band[0].prec[precno].decoded_layers) {
> > +*process_data = 0;
> >  return 0;
> > +}
> >  rlevel->band[0].prec[precno].decoded_layers = layno + 1;
> >
> > -if (bytestream2_get_bytes_left(&s->g) == 0 && s->bit_index == 8) {
> > -if (*tp_index < FF_ARRAY_ELEMS(tile->tile_part) - 1) {
> > -s->g = tile->tile_part[++(*tp_index)].tpg;
> > +if (tile->has_ppt) {
> > +s->g = tile->packed_headers_stream;
> > +} else {
> > +s->g = tile->tile_part[*tp_index].tpg;
> > +if (bytestream2_get_bytes_left(&s->g) == 0 && s->bit_index == 
> > 8) {
> > +if (*tp_index < FF_ARRAY_ELEMS(tile->tile_part) - 1) {
> > +s->g = tile->tile_part[++(*tp_index)].tpg;
> > +}
> >  }
> > +if (bytestream2_peek_be32(&s->g) == JPEG2000_SOP_FIXED_BYTES)
> > +bytestream2_skip(&s->g, JPEG2000_SOP_BYTE_LENGTH);
> >  }
> >
> > -if (bytestream2_peek_be32(&s->g) == JPEG2000_SOP_FIXED_BYTES)
> > -bytestream2_skip(&s->g, JPEG2000_SOP_BYTE_LENGTH);
> > -
> >  if (!(ret = get_bits(s, 1))) {
> >  jpeg2000_flush(s);
> > -return 0;
> > +*process_data = 0;
> > +goto end;
> >  } else if (ret < 0)
> >  return ret;
> >
> > @@ -1055,6 +1101,34 @@ static int 
> > jpeg2000_decode_packet(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
> >  else
> >  av_log(s->avctx, AV_LOG_ERROR, "EPH marker not found. instead 
> > %X\n", bytestream2_peek_be32(&s->g));
> >  }
> > +end:
> > +if (tile->has_ppt)
> > +tile->packed_headers_stream = s->g;
> > +else
> > +tile->tile_part[*tp_index].tpg = s->g;
> > +return 0;
> > +}
> > +
> > +static int jpeg2000_decode_packet_data(Jpeg2000DecoderContext *s, 
> > Jpeg2000Tile *tile,
> > +   int *tp_index,
> > +   Jpeg2000CodingStyle *codsty,
> > +   Jpeg2000ResLevel *rlevel, int 
> > precno,
> > +   int layno, uint8_t *expn, int 
> > numgbits)
> > +{
> > +int bandno, cblkno, nb_code_blocks;
> > +int cwsno;
> > +
> > +s->g = tile->tile_part[*tp_index].tpg;
> > +if (tile->has_ppt) {
> > +if (bytestream2_get_bytes_left(&s->g) == 0 && s->bit_index == 8) {
> > +if (*tp_index < FF_ARRAY_ELEMS(tile->tile_part) - 1) {
> > +s->g = tile->tile_part[++(*tp_index)].tpg;
> > +}
> > +}
> > +if (bytestream2_peek_be32(&s->g) == JPEG2000_SOP_FIXED_BYTES)
> > +bytestream2_skip(&s->g, JPEG2000_SOP_BYTE_LENGTH);
> > +}
> > +
> >
> >  for (bandno = 0; bandno < rlevel->nbands; bandno++) {
> >  Jpeg2000Band *band = rlevel->band + bandno;
> > @@ -1097,6 +1171,7 @@ static int 
> > jpeg2000_decode_packet(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
> >  av_freep(&cblk->lengthinc);
> >  }
> >  }
> > +tile->tile_part[*tp_index].tpg = s->g;
> >  return 0;
> >  }
>
> I think this function spliting should be in a seperate patch from adding
> ppt support.
> It would make the changes more readable in the git log
>
I have had lot of trouble understanding how to do this and took the easy route.
I shall just split the function without creating the two new functions
in one patch
as mentione

[FFmpeg-devel] [PATCH v7 2/3] libavcodec/jpeg2000dec.c: Add support for PPT marker

2020-03-29 Thread gautamramk
From: Gautam Ramakrishnan 

This patch adds functional changes to support the
PPT marker.
---
 libavcodec/jpeg2000dec.c | 178 +++
 1 file changed, 144 insertions(+), 34 deletions(-)

diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index 4ee20e41b1..71f1245fc1 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -859,6 +859,39 @@ static int get_plt(Jpeg2000DecoderContext *s, int n)
 return 0;
 }
 
+static int get_ppt(Jpeg2000DecoderContext *s, int n)
+{
+Jpeg2000Tile *tile;
+
+if (s->curtileno < 0)
+return AVERROR_INVALIDDATA;
+
+tile = &s->tile[s->curtileno];
+if (tile->tp_idx != 0) {
+av_log(s->avctx, AV_LOG_ERROR,
+   "PPT marker can occur only on first tile part of a tile.\n");
+return AVERROR_INVALIDDATA;
+}
+
+tile->has_ppt = 1;  // this tile has a ppt marker
+/*Zppt = */ bytestream2_get_byte(&s->g);
+if (!tile->packed_headers) {
+tile->packed_headers = av_malloc_array(n - 3, sizeof(uint8_t));
+memcpy(tile->packed_headers, s->g.buffer, sizeof(uint8_t)*(n - 3));
+tile->packed_headers_size = n - 3;
+} else {
+tile->packed_headers = av_realloc_array(tile->packed_headers,
+tile->packed_headers_size + n 
- 3,
+sizeof(uint8_t));
+memcpy(tile->packed_headers + tile->packed_headers_size,
+   s->g.buffer, sizeof(uint8_t)*(n - 3));
+tile->packed_headers_size += n - 3;
+}
+bytestream2_skip(&s->g, n - 3);
+
+return 0;
+}
+
 static int init_tile(Jpeg2000DecoderContext *s, int tileno)
 {
 int compno;
@@ -931,20 +964,21 @@ static int getlblockinc(Jpeg2000DecoderContext *s)
 return res;
 }
 
-static int jpeg2000_decode_packet(Jpeg2000DecoderContext *s, Jpeg2000Tile 
*tile, int *tp_index,
-  Jpeg2000CodingStyle *codsty,
-  Jpeg2000ResLevel *rlevel, int precno,
-  int layno, uint8_t *expn, int numgbits)
+static int jpeg2000_decode_packet_header(Jpeg2000DecoderContext *s, 
Jpeg2000Tile *tile,
+ int *tp_index,
+ Jpeg2000CodingStyle *codsty,
+ Jpeg2000ResLevel *rlevel, int precno,
+ int layno, uint8_t *expn, int 
numgbits,
+ int *process_data)
 {
 int bandno, cblkno, ret, nb_code_blocks;
-int cwsno;
 
-// This part decodes the packet header
-
-if (layno < rlevel->band[0].prec[precno].decoded_layers)
+if (layno < rlevel->band[0].prec[precno].decoded_layers) {
+*process_data = 0;
 return 0;
+}
 rlevel->band[0].prec[precno].decoded_layers = layno + 1;
-// Select appropriate stream to read from
+// Select stream to read from
 if (tile->has_ppt) {
 s->g = tile->packed_headers_stream;
 } else {
@@ -960,12 +994,8 @@ static int jpeg2000_decode_packet(Jpeg2000DecoderContext 
*s, Jpeg2000Tile *tile,
 
 if (!(ret = get_bits(s, 1))) {
 jpeg2000_flush(s);
-// Save state of stream
-if (tile->has_ppt)
-tile->packed_headers_stream = s->g;
-else
-tile->tile_part[*tp_index].tpg = s->g;
-return 0;
+*process_data = 0;
+goto end;
 } else if (ret < 0)
 return ret;
 
@@ -1070,14 +1100,24 @@ static int 
jpeg2000_decode_packet(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
 else
 av_log(s->avctx, AV_LOG_ERROR, "EPH marker not found. instead 
%X\n", bytestream2_peek_be32(&s->g));
 }
-
+end:
+// Save stream state
 if (tile->has_ppt)
 tile->packed_headers_stream = s->g;
 else
 tile->tile_part[*tp_index].tpg = s->g;
+return 0;
+}
+
+static int jpeg2000_decode_packet_data(Jpeg2000DecoderContext *s, Jpeg2000Tile 
*tile,
+   int *tp_index,
+   Jpeg2000CodingStyle *codsty,
+   Jpeg2000ResLevel *rlevel, int precno,
+   int layno, uint8_t *expn, int numgbits)
+{
+int bandno, cblkno, nb_code_blocks;
+int cwsno;
 
-// This part decodes the packet data.
-// Select appropriate stream to read from
 s->g = tile->tile_part[*tp_index].tpg;
 if (tile->has_ppt) {
 if (bytestream2_get_bytes_left(&s->g) == 0 && s->bit_index == 8) {
@@ -1088,6 +1128,8 @@ static int jpeg2000_decode_packet(Jpeg2000DecoderContext 
*s, Jpeg2000Tile *tile,
 if (bytestream2_peek_be32(&s->g) == JPEG2000_SOP_FIXED_BYTES)
 bytestream2_skip(&s->g, JPEG2000_SOP_BYTE_LENGTH);
 }
+
+
 for (bandno = 0; bandno < rlevel->nbands; bandno++) {
 Jpeg2000Band *band = rlevel->band + 

[FFmpeg-devel] [PATCH v7 3/3] libavcodec/jpeg2000dec.c: Handle non EOC streams

2020-03-29 Thread gautamramk
From: Gautam Ramakrishnan 

This patch allows decoding of j2k streams which do
not have an EOC marker.
---
 libavcodec/jpeg2000dec.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index 71f1245fc1..a319297ae7 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -2080,8 +2080,12 @@ static int 
jpeg2000_read_main_headers(Jpeg2000DecoderContext *s)
 
 len = bytestream2_get_be16(&s->g);
 if (len < 2 || bytestream2_get_bytes_left(&s->g) < len - 2) {
-av_log(s->avctx, AV_LOG_ERROR, "Invalid len %d left=%d\n", len, 
bytestream2_get_bytes_left(&s->g));
-return AVERROR_INVALIDDATA;
+if (s->avctx->strict_std_compliance >= FF_COMPLIANCE_STRICT) {
+av_log(s->avctx, AV_LOG_ERROR, "Invalid len %d left=%d\n", 
len, bytestream2_get_bytes_left(&s->g));
+return AVERROR_INVALIDDATA;
+}
+av_log(s->avctx, AV_LOG_WARNING, "Mising EOC Marker.\n");
+break;
 }
 
 switch (marker) {
-- 
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 v7 1/3] libavcodec/jpeg2000dec.c: Split function and modify structs for PPM marker support

2020-03-29 Thread gautamramk
From: Gautam Ramakrishnan 

---
 libavcodec/jpeg2000dec.c | 48 ++--
 1 file changed, 41 insertions(+), 7 deletions(-)

diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index 7103cd6ceb..4ee20e41b1 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -83,6 +83,10 @@ typedef struct Jpeg2000Tile {
 Jpeg2000QuantStyle  qntsty[4];
 Jpeg2000POC poc;
 Jpeg2000TileParttile_part[32];
+uint8_t has_ppt;// whether this tile has a ppt 
marker
+uint8_t *packed_headers;// contains packed headers. 
Used only along with PPT marker
+int packed_headers_size;// size in bytes of the packed 
headers
+GetByteContext  packed_headers_stream;  // byte context corresponding 
to packed headers
 uint16_t tp_idx;// Tile-part index
 int coord[2][2];// border coordinates {{x0, x1}, {y0, 
y1}}
 } Jpeg2000Tile;
@@ -935,21 +939,32 @@ static int jpeg2000_decode_packet(Jpeg2000DecoderContext 
*s, Jpeg2000Tile *tile,
 int bandno, cblkno, ret, nb_code_blocks;
 int cwsno;
 
+// This part decodes the packet header
+
 if (layno < rlevel->band[0].prec[precno].decoded_layers)
 return 0;
 rlevel->band[0].prec[precno].decoded_layers = layno + 1;
-
-if (bytestream2_get_bytes_left(&s->g) == 0 && s->bit_index == 8) {
-if (*tp_index < FF_ARRAY_ELEMS(tile->tile_part) - 1) {
-s->g = tile->tile_part[++(*tp_index)].tpg;
+// Select appropriate stream to read from
+if (tile->has_ppt) {
+s->g = tile->packed_headers_stream;
+} else {
+s->g = tile->tile_part[*tp_index].tpg;
+if (bytestream2_get_bytes_left(&s->g) == 0 && s->bit_index == 8) {
+if (*tp_index < FF_ARRAY_ELEMS(tile->tile_part) - 1) {
+s->g = tile->tile_part[++(*tp_index)].tpg;
+}
 }
+if (bytestream2_peek_be32(&s->g) == JPEG2000_SOP_FIXED_BYTES)
+bytestream2_skip(&s->g, JPEG2000_SOP_BYTE_LENGTH);
 }
 
-if (bytestream2_peek_be32(&s->g) == JPEG2000_SOP_FIXED_BYTES)
-bytestream2_skip(&s->g, JPEG2000_SOP_BYTE_LENGTH);
-
 if (!(ret = get_bits(s, 1))) {
 jpeg2000_flush(s);
+// Save state of stream
+if (tile->has_ppt)
+tile->packed_headers_stream = s->g;
+else
+tile->tile_part[*tp_index].tpg = s->g;
 return 0;
 } else if (ret < 0)
 return ret;
@@ -1056,6 +1071,23 @@ static int jpeg2000_decode_packet(Jpeg2000DecoderContext 
*s, Jpeg2000Tile *tile,
 av_log(s->avctx, AV_LOG_ERROR, "EPH marker not found. instead 
%X\n", bytestream2_peek_be32(&s->g));
 }
 
+if (tile->has_ppt)
+tile->packed_headers_stream = s->g;
+else
+tile->tile_part[*tp_index].tpg = s->g;
+
+// This part decodes the packet data.
+// Select appropriate stream to read from
+s->g = tile->tile_part[*tp_index].tpg;
+if (tile->has_ppt) {
+if (bytestream2_get_bytes_left(&s->g) == 0 && s->bit_index == 8) {
+if (*tp_index < FF_ARRAY_ELEMS(tile->tile_part) - 1) {
+s->g = tile->tile_part[++(*tp_index)].tpg;
+}
+}
+if (bytestream2_peek_be32(&s->g) == JPEG2000_SOP_FIXED_BYTES)
+bytestream2_skip(&s->g, JPEG2000_SOP_BYTE_LENGTH);
+}
 for (bandno = 0; bandno < rlevel->nbands; bandno++) {
 Jpeg2000Band *band = rlevel->band + bandno;
 Jpeg2000Prec *prec = band->prec + precno;
@@ -1097,6 +1129,8 @@ static int jpeg2000_decode_packet(Jpeg2000DecoderContext 
*s, Jpeg2000Tile *tile,
 av_freep(&cblk->lengthinc);
 }
 }
+// Save state of stream
+tile->tile_part[*tp_index].tpg = s->g;
 return 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".