[FFmpeg-devel] [PATCH v3 2/2] avformat/tests/url: add test cases for handling of double dot

2020-07-27 Thread Josef Zlomek
added test cases

Signed-off-by: Josef Zlomek 
---
 libavformat/tests/url.c | 11 ++-
 tests/ref/fate/url  |  9 +
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/libavformat/tests/url.c b/libavformat/tests/url.c
index 1d961a1b43..029be6ff10 100644
--- a/libavformat/tests/url.c
+++ b/libavformat/tests/url.c
@@ -23,7 +23,7 @@
 
 static void test(const char *base, const char *rel)
 {
-char buf[200], buf2[200];
+char buf[80], buf2[80];
 ff_make_absolute_url(buf, sizeof(buf), base, rel);
 printf("%50s %-20s => %s\n", base, rel, buf);
 if (base) {
@@ -57,6 +57,9 @@ int main(void)
 test("/foo/bar", "../baz");
 test("/foo/bar", "/baz");
 test("/foo/bar", "../../../baz");
+test("/foo/bar", "..");
+test("/foo/bar/baz", "..");
+test("http://server;, "");
 test("http://server/foo/;, "baz");
 test("http://server/foo/bar;, "baz");
 test("http://server/foo/;, "../baz");
@@ -65,11 +68,17 @@ int main(void)
 test("http://server/foo/bar/123;, "https://other/url;);
 test("http://server/foo/bar?param=value/with/slashes;, "/baz");
 test("http://server/foo/bar?param;, "?someparam");
+test("http://server/foo/bar;, "simple/relative/path");
 test("http://server/foo/bar;, "//other/url");
 test("http://server/foo/bar;, "../../../../../other/url");
+test("http://server/foo/bar;, 
"a/b/../c/d/../e../..f/.../other/url/test..mp3");
+test("http://server/foo/bar;, 
"/a/b/../c/d/../e../..f/.../other/url/test..mp3");
+test("http://server/foo/bar;, "a/b/../c/d/../e../..f/.../other/url/..");
+test("http://server/foo/bar;, "a/b/../c/d/../e../..f/.../other/url/");
 test("http://server/foo/bar;, "/../../../../../other/url");
 test("http://server/foo/bar;, "/test/../../../../../other/url");
 test("http://server/foo/bar;, "/test/../../test/../../../other/url");
+test("http://server/foo/bar;, 
"/too/long1/too/long2/too/long3/too/long4/too/long5/too/long6/too/long7");
 
 printf("\nTesting av_url_split:\n");
 test2("/foo/bar");
diff --git a/tests/ref/fate/url b/tests/ref/fate/url
index 533ba2cb1e..20c37bc826 100644
--- a/tests/ref/fate/url
+++ b/tests/ref/fate/url
@@ -4,6 +4,9 @@ Testing ff_make_absolute_url:
   /foo/bar ../baz   => /baz
   /foo/bar /baz => /baz
   /foo/bar ../../../baz => /baz
+  /foo/bar ..   => /
+  /foo/bar/baz ..   => 
/foo/
+ http://server  => 
http://server
 http://server/foo/ baz  => 
http://server/foo/baz
  http://server/foo/bar baz  => 
http://server/foo/baz
 http://server/foo/ ../baz   => 
http://server/baz
@@ -12,11 +15,17 @@ Testing ff_make_absolute_url:
  http://server/foo/bar/123 https://other/url=> 
https://other/url
 http://server/foo/bar?param=value/with/slashes /baz => 
http://server/baz
 http://server/foo/bar?param ?someparam   => 
http://server/foo/bar?someparam
+ http://server/foo/bar simple/relative/path => 
http://server/foo/simple/relative/path
  http://server/foo/bar //other/url  => 
http://other/url
  http://server/foo/bar ../../../../../other/url => 
http://server/other/url
+ http://server/foo/bar 
a/b/../c/d/../e../..f/.../other/url/test..mp3 => 
http://server/foo/a/c/e../..f/.../other/url/test..mp3
+ http://server/foo/bar 
/a/b/../c/d/../e../..f/.../other/url/test..mp3 => 
http://server/a/c/e../..f/.../other/url/test..mp3
+ http://server/foo/bar 
a/b/../c/d/../e../..f/.../other/url/.. => 
http://server/foo/a/c/e../..f/.../other/
+ http://server/foo/bar 
a/b/../c/d/../e../..f/.../other/url/ => 
http://server/foo/a/c/e../..f/.../other/url/
  http://server/foo/bar /../../../../../other/url 
=> http://server/other/url
  http://server/foo/bar 
/test/../../../../../other/url => http://server/other/url
  http://server/foo/bar 
/test/../../test/../../../other/url => http://server/other/url
+ http://server/foo/bar 
/too/long1/too/long2/too/long3/too/long4/too/long5/too/long6/too/long7 => 
http://server/too/long1/too/long2/too/long3/too/long4/too/long5/too/long6/too/l
 
 Testing av_url_split:
 /foo/bar =>
-1 /foo/bar
-- 
2.17.1


[FFmpeg-devel] [PATCH v3 1/2] avformat/url: fix logic for removing ".." path components

2020-07-27 Thread Josef Zlomek
Fixes: 8814

The logic for removing ".." path components and their corresponding
upper directories was reworked.

Now, the function trim_double_dot_url splits the path by "/" into
components, and processes the components one ny one:
- if the component is "..", the last path component in output buffer is removed
- if the component is not empty, it is added to the output buffer
No temporary buffers are used anymore.

Also the path containing no '/' after '://' is returned as it is.

The duplicate logic was removed from ff_make_absolute_url.

Signed-off-by: Josef Zlomek 
---
 libavformat/url.c | 101 +++---
 1 file changed, 50 insertions(+), 51 deletions(-)

diff --git a/libavformat/url.c b/libavformat/url.c
index 20463a6674..46a08e88e3 100644
--- a/libavformat/url.c
+++ b/libavformat/url.c
@@ -82,41 +82,62 @@ static void trim_double_dot_url(char *buf, const char *rel, 
int size)
 {
 const char *p = rel;
 const char *root = rel;
-char tmp_path[MAX_URL_SIZE] = {0, };
-char *sep;
-char *node;
+char *dst;
+int dst_len = 0;
+const char *sep;
+const char *next;
+int last_is_dir;
 
 /* Get the path root of the url which start by "://" */
 if (p && (sep = strstr(p, "://"))) {
 sep += 3;
 root = strchr(sep, '/');
-if (!root)
+if (!root) {
+av_strlcpy(buf, rel, size);
 return;
+}
 }
+if (*root == '/')
+++root;
 
-/* set new current position if the root node is changed */
-p = root;
-while (p && (node = strstr(p, ".."))) {
-av_strlcat(tmp_path, p, node - p + strlen(tmp_path));
-p = node + 3;
-sep = strrchr(tmp_path, '/');
-if (sep)
-sep[0] = '\0';
-else
-tmp_path[0] = '\0';
-}
-
-if (!av_stristart(p, "/", NULL) && root != rel)
-av_strlcat(tmp_path, "/", size);
-
-av_strlcat(tmp_path, p, size);
-/* start set buf after temp path process. */
+/* Copy the root to the output buffer */
 av_strlcpy(buf, rel, root - rel + 1);
+size -= root - rel;
+dst = [root - rel];
+
+/* Split the path by "/" and remove ".." and its corresponding directory. 
*/
+last_is_dir = 1;
+for (p = root; *p; p = next) {
+next = strchr(p, '/');
+if (!next) {
+next = p + strlen(p);
+last_is_dir = 0;
+}
 
-if (!av_stristart(tmp_path, "/", NULL) && root != rel)
-av_strlcat(buf, "/", size);
+if (next - p == 2 && !strncmp(p, "..", 2)) {
+/* remove the last directory from dst */
+while (dst_len > 0 && dst[--dst_len] != '/')
+;
+dst[dst_len] = '\0';
+last_is_dir = 1;
+} else if (next > p) {
+int len_including_zero;
+/* copy the current path component to dst (including '/') */
+if (dst_len) {
+av_strlcpy(dst + dst_len, "/", size - dst_len);
+++dst_len;
+}
+len_including_zero = FFMIN(size - dst_len, next - p + 1);
+av_strlcpy(dst + dst_len, p, len_including_zero);
+dst_len += len_including_zero - 1;
+}
 
-av_strlcat(buf, tmp_path, size);
+/* skip "/" */
+while (*next == '/')
+++next;
+}
+if (last_is_dir && dst_len)
+av_strlcpy(dst + dst_len, "/", size - dst_len);
 }
 
 void ff_make_absolute_url(char *buf, int size, const char *base,
@@ -175,14 +196,11 @@ void ff_make_absolute_url(char *buf, int size, const char 
*base,
 
 root = p = buf;
 /* Get the path root of the url which start by "://" */
-if (p && strstr(p, "://")) {
-sep = strstr(p, "://");
-if (sep) {
-sep += 3;
-root = strchr(sep, '/');
-if (!root)
-return;
-}
+if (p && (sep = strstr(p, "://"))) {
+sep += 3;
+root = strchr(sep, '/');
+if (!root)
+return;
 }
 
 /* Remove the file name from the base url */
@@ -194,26 +212,7 @@ void ff_make_absolute_url(char *buf, int size, const char 
*base,
 sep[1] = '\0';
 else
 buf[0] = '\0';
-while (av_strstart(rel, "..", NULL) && sep) {
-/* Remove the path delimiter at the end */
-if (sep > root) {
-sep[0] = '\0';
-sep = strrchr(buf, '/');
-}
 
-/* If the next directory name to pop off is "..", break here */
-if (!strcmp(sep ? [1] : buf, "..")) {
-/* Readd the slash we just removed */
-av_strlcat(buf, "/", size);
-break;
-}
-/* Cut off the directory name */
-if (sep)
-sep[1] = '\0';
-else
-buf[0] = '\0';
-rel += 3;
-}
 av_strlcat(buf, rel, size);
 trim_double_dot_url(tmp_path, buf, size);
 memset(buf, 0, size);
-- 
2.17.1


Re: [FFmpeg-devel] [PATCH v2 1/2] avformat/url: check double dot is not to parent directory

2020-07-27 Thread Zlomek, Josef
On Mon, Jul 27, 2020 at 8:57 PM Marton Balint  wrote:

> It should be implemented in a way which does not use a temporary buffer.
> Seems doable.
>

You are right. I will submit a new version.

Best regards,
Josef
___
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] lavf/srt: fix build fail when used the libsrt 1.4.1

2020-07-27 Thread myp...@gmail.com
On Mon, Jul 27, 2020 at 7:37 PM myp...@gmail.com  wrote:
>
> On Sat, Jul 18, 2020 at 8:31 PM myp...@gmail.com  wrote:
> >
> > On Thu, Jul 16, 2020 at 9:35 AM myp...@gmail.com  wrote:
> > >
> > > On Tue, Jul 14, 2020 at 9:47 PM Moritz Barsnick  wrote:
> > > >
> > > > On Sun, Jul 12, 2020 at 22:44:46 +0800, myp...@gmail.com wrote:
> > > > > Maybe I give an inaccurate description in the commit message, in fact,
> > > > > libsrt 1.4.1 remove the SRTO_STRICTENC/SRTO_SMOOTHER option, it's will
> > > > > lead to FFmpeg build fail when using libsrt  version >= 1.4.1
> > > >
> > > > I don't mind you description. Yet your code change references 1.4.1:
> > > > SRT_VERSION_VALUE >= 0x010401
> > > > while I am trying to make the point that 1.4.0 also needs this change
> > > > (or 1.3.0 in one case, which is already ensured by #if).
> > > >
> > >
> > > After double-check, I think the patch is Ok, in fact, libsrt keeps the
> > > deprecated SRTO_STRICTENC/SRTO_SMOOTHER options in srt.h (inclued the
> > > options in libsrt 1.3.3/1.3.4/1.4.0) until commit
> > > 0e2201aff6b379979cec43fee5e8f162717f6346 , so FFmpeg build with libsrt
> > > 1.3.3/1.3.4/1.4.0 is OK with the patch.
> > Ping
> I'll apply it tomorrow if don't object, thx
Pushed, thx
___
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/2] avformat/tests/url: add test cases for handling of double dot

2020-07-27 Thread Steven Liu
Josef Zlomek  于2020年7月27日周一 下午8:15写道:
>
> Signed-off-by: Josef Zlomek 
> ---
>  libavformat/tests/url.c | 6 ++
>  tests/ref/fate/url  | 6 ++
>  2 files changed, 12 insertions(+)
>
> diff --git a/libavformat/tests/url.c b/libavformat/tests/url.c
> index 1d961a1b43..a27a875892 100644
> --- a/libavformat/tests/url.c
> +++ b/libavformat/tests/url.c
> @@ -57,6 +57,8 @@ int main(void)
>  test("/foo/bar", "../baz");
>  test("/foo/bar", "/baz");
>  test("/foo/bar", "../../../baz");
> +test("/foo/bar", "..");
> +test("/foo/bar/baz", "..");
>  test("http://server/foo/;, "baz");
>  test("http://server/foo/bar;, "baz");
>  test("http://server/foo/;, "../baz");
> @@ -67,6 +69,10 @@ int main(void)
>  test("http://server/foo/bar?param;, "?someparam");
>  test("http://server/foo/bar;, "//other/url");
>  test("http://server/foo/bar;, "../../../../../other/url");
> +test("http://server/foo/bar;, 
> "a/b/../c/d/../e../..f/.../other/url/test..mp3");
> +test("http://server/foo/bar;, 
> "/a/b/../c/d/../e../..f/.../other/url/test..mp3");
> +test("http://server/foo/bar;, "a/b/../c/d/../e../..f/.../other/url/..");
> +test("http://server/foo/bar;, "a/b/../c/d/../e../..f/.../other/url/");
>  test("http://server/foo/bar;, "/../../../../../other/url");
>  test("http://server/foo/bar;, "/test/../../../../../other/url");
>  test("http://server/foo/bar;, "/test/../../test/../../../other/url");
> diff --git a/tests/ref/fate/url b/tests/ref/fate/url
> index 533ba2cb1e..aa53e09fab 100644
> --- a/tests/ref/fate/url
> +++ b/tests/ref/fate/url
> @@ -4,6 +4,8 @@ Testing ff_make_absolute_url:
>/foo/bar ../baz   => 
> /baz
>/foo/bar /baz => 
> /baz
>/foo/bar ../../../baz => 
> /baz
> +  /foo/bar ..   => /
> +  /foo/bar/baz ..   => 
> /foo/
>  http://server/foo/ baz  => 
> http://server/foo/baz
>   http://server/foo/bar baz  => 
> http://server/foo/baz
>  http://server/foo/ ../baz   => 
> http://server/baz
> @@ -14,6 +16,10 @@ Testing ff_make_absolute_url:
>  http://server/foo/bar?param ?someparam   => 
> http://server/foo/bar?someparam
>   http://server/foo/bar //other/url  => 
> http://other/url
>   http://server/foo/bar ../../../../../other/url 
> => http://server/other/url
> + http://server/foo/bar 
> a/b/../c/d/../e../..f/.../other/url/test..mp3 => 
> http://server/foo/a/c/e../..f/.../other/url/test..mp3
> + http://server/foo/bar 
> /a/b/../c/d/../e../..f/.../other/url/test..mp3 => 
> http://server/a/c/e../..f/.../other/url/test..mp3
> + http://server/foo/bar 
> a/b/../c/d/../e../..f/.../other/url/.. => 
> http://server/foo/a/c/e../..f/.../other/
> + http://server/foo/bar 
> a/b/../c/d/../e../..f/.../other/url/ => 
> http://server/foo/a/c/e../..f/.../other/url/
>   http://server/foo/bar /../../../../../other/url 
> => http://server/other/url
>   http://server/foo/bar 
> /test/../../../../../other/url => http://server/other/url
>   http://server/foo/bar 
> /test/../../test/../../../other/url => http://server/other/url
> --
> 2.17.1
>
Patchiest LGTM,

Will apply after 24 hours if no objections.


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

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

Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: increase initial program date time precision

2020-07-27 Thread Steven Liu
Marton Balint  于2020年7月28日周二 上午4:15写道:
>
>
>
> On Sun, 19 Jul 2020, Marton Balint wrote:
>
> >
> >
> > On Sun, 19 Jul 2020, Steven Liu wrote:
> >
> >> Zhao Zhili  于2020年7月19日周日 下午6:26写道:
> >>>
> >>>
> >>>
> >>> > On Jul 19, 2020, at 5:20 PM, Steven Liu  wrote:
> >>> >
> >>> > Marton Balint  于2020年7月19日周日 上午6:04写道:
> >>> >>
> >>> >> Also query time only once, not for every variant stream, otherwise
> > variant
> >>> >> streams might get a slightly different initial program date time. And
> > we can
> >>> >> set this unconditionally because HLS_PROGRAM_DATE_TIME flag is checked
> >>> >> elsewhere.
> >>> >>
> >>> >> Signed-off-by: Marton Balint 
> >>> >> ---
> >>> >> libavformat/hlsenc.c | 8 ++--
> >>> >> 1 file changed, 2 insertions(+), 6 deletions(-)
> >>> >>
> >>> >> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> >>> >> index df84e6487d..39ff1fa1e7 100644
> >>> >> --- a/libavformat/hlsenc.c
> >>> >> +++ b/libavformat/hlsenc.c
> >>> >> @@ -2704,6 +2704,7 @@ static int hls_init(AVFormatContext *s)
> >>> >> char *p = NULL;
> >>> >> int http_base_proto = ff_is_http_proto(s->url);
> >>> >> int fmp4_init_filename_len = strlen(hls->fmp4_init_filename) + 1;
> >>> >> +double initial_program_date_time = av_gettime() / 100.0;
> >>> > is it AV_TIME_BASE?
> >>>
> >>> According to the documentation of av_gettime, it's not related to
> > AV_TIME_BASE.
> >>>
> >>> /**
> >>>  * Get the current time in microseconds.
> >>>  */
> >>> int64_t av_gettime(void);
> >> I saw
> >> /**
> >> * Internal time base represented as integer
> >> */
> >>
> >> #define AV_TIME_BASE100
> >> Do you mean cannot av_gettime() / AV_TIME_BASE?
> >
> > av_gettime() is always microsec according to docs, even if AV_TIME_BASE is
> > not 100. In practice however AV_TIME_BASE is assumed to be 100 in
> > a lot of places, so one can't really change it.
> >
> > IMHO it is cleaner to use 100.0 instead of AV_TIME_BASE, because
> > AV_TIME_BASE is integer, so you'd have to use (double)AV_TIME_BASE and
> > that would be ugly. So I'd rather keep 100.0.
>
> Ping, thanks,
I have no question about it, thanks for your clarify respond, LGTM.

>
> Marton
>
> >>>
> >>> >>
> >>> >> if (hls->use_localtime) {
> >>> >> pattern = get_default_pattern_localtime_fmt(s);
> >>> >> @@ -2798,12 +2799,7 @@ static int hls_init(AVFormatContext *s)
> >>> >> vs->start_pts = AV_NOPTS_VALUE;
> >>> >> vs->end_pts   = AV_NOPTS_VALUE;
> >>> >> vs->current_segment_final_filename_fmt[0] = '\0';
> >>> >> -
> >>> >> -if (hls->flags & HLS_PROGRAM_DATE_TIME) {
> >>> >> -time_t now0;
> >>> >> -time();
> >>> >> -vs->initial_prog_date_time = now0;
> >>> >> -}
> >>> >> +vs->initial_prog_date_time = initial_program_date_time;
> >>> >>
> >>> >> for (j = 0; j < vs->nb_streams; j++) {
> >>> >> vs->has_video += vs->streams[j]->codecpar->codec_type ==
> > AVMEDIA_TYPE_VIDEO;
> >>> >> --
> >>> >> 2.26.2
> >>> >>

Thanks

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

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

Re: [FFmpeg-devel] AVWriter again (was: v2 1/2] avformat/url: check double dot is not to parent directory)

2020-07-27 Thread Jean-Baptiste Kempf


On Sat, 25 Jul 2020, at 13:03, Nicolas George wrote:
> And that's all. Everything is taken care of: the string will grow as
> needed, the size will be tracked, error checks are made. Nothing to
> worry about at all.

How is that different from open_memstream, which is done for this exact purpose?

--
Jean-Baptiste Kempf -  President
+33 672 704 734
 

___
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 1/4] lavc/vaapi_encode: add EQUAL_MULTI_ROWS support for slice structure

2020-07-27 Thread Mark Thompson

On 19/07/2020 08:00, Linjie Fu wrote:

On Thu, Jun 18, 2020 at 1:36 PM Linjie Fu  wrote:


On Tue, May 12, 2020 at 9:49 PM Linjie Fu  wrote:


VA_ENC_SLICE_STRUCTURE_EQUAL_MULTI_ROWS is added to in the latest
libva (1.8.0) which matches the hardware behaviour:

/** \brief Driver supports any number of rows per slice but they must be the 
same
*   for all slices except for the last one, which must be equal or smaller
*   to the previous slices. */

And VA_ENC_SLICE_STRUCTURE_EQUAL_ROWS is kind of deprecated for iHD
since it's somehow introduced in [1] however misleading from what we
actually handle, and one row per slice would not get a good quality.

Caps query support in driver is WIP, and this would fix the multi slice
encoding for VAEntrypointEncSliceLP.

[1]

Signed-off-by: Linjie Fu 
---
  libavcodec/vaapi_encode.c | 3 +++
  1 file changed, 3 insertions(+)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index cb05ebd..234618a 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -1888,6 +1888,9 @@ static av_cold int 
vaapi_encode_init_slice_structure(AVCodecContext *avctx)
  req_slices = avctx->slices;
  }
  if (slice_structure & VA_ENC_SLICE_STRUCTURE_ARBITRARY_ROWS ||
+#if VA_CHECK_VERSION(1, 8, 0)
+slice_structure & VA_ENC_SLICE_STRUCTURE_EQUAL_MULTI_ROWS ||
+#endif
  slice_structure & VA_ENC_SLICE_STRUCTURE_ARBITRARY_MACROBLOCKS) {
  ctx->nb_slices  = req_slices;
  ctx->slice_size = ctx->slice_block_rows / ctx->nb_slices;
--
2.7.4


Full support is provided in libva[1] and media-driver[2], and we've
observed it works for multi slice encoding for AVC. (300+ cases)

Prefer to apply this soon with commit message refined.


Applied, thx.

Treating EQUAL_MULTI_ROWS in the same way as the arbitrary-size cases is just 
wrong.

Consider 9 rows, 4 slices - we pick 4 slices with sizes { 3, 2, 2, 2 }, which 
EQUAL_MULTI_ROWS does not allow.

It isn't possible to split the frame into 4 slices at all with the 
EQUAL_MULTI_ROWS structure - the closest options are 3 slices with sizes { 3, 
3, 3 } or 5 slices with sizes { 2, 2, 2, 2, 1 }.

You can see the same problem at 1080p with five slices.

Thanks,

- Mark
___
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] Support HDR10+ metadata for HEVC.

2020-07-27 Thread Mohammad Izadi
It seems FATE is for the regression test. Here is a sample that you can use
and check:

 https://www.dropbox.com/s/3ewr2t2lvv2cy8d/20200727_143643.mp4?dl=0

Thanks,
Mohammad


On Mon, Jul 27, 2020 at 7:53 AM Vittorio Giovara 
wrote:

> On Fri, Jul 24, 2020 at 11:09 PM Mohammad Izadi <
> izadi-at-google@ffmpeg.org> wrote:
>
> > On Fri, Jul 24, 2020 at 9:30 AM Andreas Rheinhardt <
> > andreas.rheinha...@gmail.com> wrote:
> >
> > > Mohammad Izadi:
> > > > From: Mohammad Izadi 
> > > >
> > > > HDR10+ is dynamic metadata (A/341 Amendment - SMPTE2094-40) that
> needs
> > > to be decoded from ITU-T T.35 in HEVC bitstream. The HDR10+ is
> > transferred
> > > to side data packet to be used or passed through.
> > > > ---
> > > >  libavcodec/avpacket.c |   1 +
> > > >  libavcodec/decode.c   |   1 +
> > > >  libavcodec/hevc_sei.c |  39 ++---
> > > >  libavcodec/hevc_sei.h |   5 ++
> > > >  libavcodec/hevcdec.c  |  16 
> > > >  libavcodec/internal.h |   9 +++
> > > >  libavcodec/packet.h   |   8 ++
> > > >  libavcodec/utils.c| 180
> ++
> > > >  libavcodec/version.h  |   2 +-
> > > >  9 files changed, 248 insertions(+), 13 deletions(-)
> > > >
> > > > diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> > > > index dce26cb31a..8307032335 <(830)%20703-2335> <(830)%20703-2335>
> 100644
> > > > --- a/libavcodec/avpacket.c
> > > > +++ b/libavcodec/avpacket.c
> > > > @@ -394,6 +394,7 @@ const char *av_packet_side_data_name(enum
> > > AVPacketSideDataType type)
> > > >  case AV_PKT_DATA_CONTENT_LIGHT_LEVEL:return "Content
> light
> > > level metadata";
> > > >  case AV_PKT_DATA_SPHERICAL:  return "Spherical
> > > Mapping";
> > > >  case AV_PKT_DATA_A53_CC: return "A53 Closed
> > > Captions";
> > > > +case AV_PKT_DATA_DYNAMIC_HDR_PLUS:   return "HDR10+
> > Dynamic
> > > Metadata (SMPTE 2094-40)";
> > > >  case AV_PKT_DATA_ENCRYPTION_INIT_INFO:   return "Encryption
> > > initialization data";
> > > >  case AV_PKT_DATA_ENCRYPTION_INFO:return "Encryption
> > > info";
> > > >  case AV_PKT_DATA_AFD:return "Active
> Format
> > > Description data";
> > > > diff --git a/libavcodec/decode.c b/libavcodec/decode.c
> > > > index de9c079f9d..cd3286f7fb 100644
> > > > --- a/libavcodec/decode.c
> > > > +++ b/libavcodec/decode.c
> > > > @@ -1698,6 +1698,7 @@ int ff_decode_frame_props(AVCodecContext
> *avctx,
> > > AVFrame *frame)
> > > >  { AV_PKT_DATA_MASTERING_DISPLAY_METADATA,
> > > AV_FRAME_DATA_MASTERING_DISPLAY_METADATA },
> > > >  { AV_PKT_DATA_CONTENT_LIGHT_LEVEL,
> > > AV_FRAME_DATA_CONTENT_LIGHT_LEVEL },
> > > >  { AV_PKT_DATA_A53_CC,
>  AV_FRAME_DATA_A53_CC
> > > },
> > > > +{ AV_PKT_DATA_DYNAMIC_HDR_PLUS,
> > >  AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
> > > >  { AV_PKT_DATA_ICC_PROFILE,
> > > AV_FRAME_DATA_ICC_PROFILE },
> > > >  };
> > > >
> > > > diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
> > > > index a4ec65dc1a..a490e752dd 100644
> > > > --- a/libavcodec/hevc_sei.c
> > > > +++ b/libavcodec/hevc_sei.c
> > > > @@ -25,6 +25,7 @@
> > > >  #include "golomb.h"
> > > >  #include "hevc_ps.h"
> > > >  #include "hevc_sei.h"
> > > > +#include "internal.h"
> > > >
> > > >  static int decode_nal_sei_decoded_picture_hash(HEVCSEIPictureHash
> *s,
> > > GetBitContext *gb)
> > > >  {
> > > > @@ -242,8 +243,8 @@ static int
> > > decode_nal_sei_user_data_unregistered(HEVCSEIUnregistered *s, GetBitC
> > > >  static int decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s,
> > > GetBitContext *gb,
> > > >   int size)
> > > >  {
> > > > -uint32_t country_code;
> > > > -uint32_t user_identifier;
> > > > +uint8_t country_code;
> > > > +uint16_t provider_code;
> > > >
> > > >  if (size < 7)
> > > >  return AVERROR(EINVAL);
> > > > @@ -255,18 +256,31 @@ static int
> > > decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s, GetBitConte
> > > >  size--;
> > > >  }
> > > >
> > > > -skip_bits(gb, 8);
> > > > -skip_bits(gb, 8);
> > > > -
> > > > -user_identifier = get_bits_long(gb, 32);
> > > > -
> > > > -switch (user_identifier) {
> > > > -case MKBETAG('G', 'A', '9', '4'):
> > > > +provider_code = get_bits(gb, 16);
> > > > +
> > > > +const uint8_t usa_country_code = 0xB5;
> > > > +const uint16_t smpte_provider_code = 0x003C;
> > > > +if (country_code == usa_country_code &&
> > > > +provider_code == smpte_provider_code) {
> > > > +// A/341 Amendment – 2094-40
> > > > +uint16_t provider_oriented_code = get_bits(gb, 16);
> > > > +uint8_t application_identifier = get_bits(gb, 8);
> > > > +const uint16_t smpte2094_40_provider_oriented_code = 0x0001;
> > > > +const uint16_t smpte2094_40_application_identifier = 0x04;
> > > > +if 

Re: [FFmpeg-devel] AVWriter again (was: v2 1/2] avformat/url: check double dot is not to parent directory)

2020-07-27 Thread Nicolas George
Marton Balint (12020-07-27):
> If I understand correctly, you are speaking about URL handling in general
> all over the codebase, and not only ff_make_absolute_url.

I thought that was what you were speaking in the first place.
ff_make_absolute_url() only does what the caller wants, the caller
decides the size of the buffer, and we can be sure it is shorter than
the concatenation of both parts.

> I think we understand the concept. It just seems a tiny bit heavy weight, or
> at least that was the primary concern as far as I remember.

That's because I made the mistake of showing the implementation and
talking about the benefits.

The implementation is my problem (and whoever would succeed me if I were
to stop maintaining it, but if it is accepted, I do not intend to). The
benefits are for everybody.

Please have a look at the other mail I just sent, where I show the
benefits and keep the implementation for myself.

Regards,

-- 
  Nicolas George


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

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

Re: [FFmpeg-devel] AVWriter again (was: v2 1/2] avformat/url: check double dot is not to parent directory)

2020-07-27 Thread Nicolas George
Steven Liu (12020-07-27):
> Because language barries. maybe I cannot deep understand, maybe need
> more code examples.
> But look interesting, maybe more easy for use.

All right, here is a practical albeit fictional example.

Let us say we want av_metadata_to_user_string() that turns an
AVDictionary into a string for users, and show_metadata_in_dialog() to
print the metadata of all the streams in a file in a GUI dialog.

av_metadata_to_user_string() using naïve av_malloc():

char *av_metadata_to_user_string(AVDictionary *meta)
{
size_t size = 1, len;
AVDictionaryEntry *entry;
char *str, *cur;

entry = NULL;
while ((entry = av_dict_get(meta, "", entry, AV_DICT_IGNORE_SUFFIX))) {
len = strlen(entry->key);
if (len > SIZE_MAX - size)
return NULL;
size += len;
len = strlen(entry->value);
if (len > SIZE_MAX - size)
return NULL;
size += len;
if (3 > SIZE_MAX - size)
return NULL;
size += 3;
}
str = av_malloc(size);
if (!str)
return AVERROR(ENOMEM);
cur = str;
entry = NULL;
while ((entry = av_dict_get(meta, "", entry, AV_DICT_IGNORE_SUFFIX))) {
cur += av_strlcatf(cur, "%s: %s\n", entry->key, entry->value, str + 
size - cur);
}
av_assert0(cur == str + size - 1);
return str;
}

av_metadata_to_user_string() using AVBPrint:

void av_metadata_to_user_string(AVWriter wr, AVDictionary *meta)
{
AVDictionaryEntry *entry;

while ((entry = av_dict_get(meta, "", entry, AV_DICT_IGNORE_SUFFIX))) {
av_writer_printf(wr, entry->key, entry->value, str + size - cur);
}
}

show_metadata_in_dialog(), without AVBPrint, but relying on Gtk+'s
features (I want to show AVWriter is good, it would be dishonest not to
use all the tools to make the other side look good):

void show_metadata_in_dialog(AVFormatContext *ctx, GtkLabel *label)
{
GString *str = g_string_new();
unsigned i;

for (i = 0; i < ctx->nb_streams; i++) {
char *meta = av_metadata_to_user_string(ctx->streams->metadata);
if (!meta)
fatal_error("out of memory");
g_string_printf("Stream #%d:\n%s\n", i, meta);
av_free(meta);
}
gtk_label_set_text(label, str->str);
g_string_free(str);
}

show_metadata_in_dialog() using AVBPrint:

void show_metadata_in_dialog(AVFormatContext *ctx, GtkLabel *label)
{
AVWriter = av_dynbuf_writer();
unsigned i;

for (i = 0; i < ctx->nb_streams; i++) {
av_writer_printf(wr, "Stream #%d:\n", i);
av_metadata_to_user_string(wr, ctx->streams->metadata);
g_string_print(wr, "\n");
}
if (av_dynbuf_writer_get_error(wr))
fatal_error("out of memory");
gtk_label_set_text(label, av_dynbuf_writer_get_data(wr, NULL));
av_dynbuf_writer_reset(wr);
}

Now, imagine if a lot of FFmpeg functions did use the same AVWriter, and
therefore worked well together.

Also, not visible in the code: unless the metadata is big, the AVWriter
version will keep all in the stack.

Regards,

-- 
  Nicolas George


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

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

Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: increase initial program date time precision

2020-07-27 Thread Marton Balint



On Sun, 19 Jul 2020, Marton Balint wrote:




On Sun, 19 Jul 2020, Steven Liu wrote:


Zhao Zhili  于2020年7月19日周日 下午6:26写道:




> On Jul 19, 2020, at 5:20 PM, Steven Liu  wrote:
>
> Marton Balint  于2020年7月19日周日 上午6:04写道:
>>
>> Also query time only once, not for every variant stream, otherwise 

variant
>> streams might get a slightly different initial program date time. And 

we can

>> set this unconditionally because HLS_PROGRAM_DATE_TIME flag is checked
>> elsewhere.
>>
>> Signed-off-by: Marton Balint 
>> ---
>> libavformat/hlsenc.c | 8 ++--
>> 1 file changed, 2 insertions(+), 6 deletions(-)
>>
>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>> index df84e6487d..39ff1fa1e7 100644
>> --- a/libavformat/hlsenc.c
>> +++ b/libavformat/hlsenc.c
>> @@ -2704,6 +2704,7 @@ static int hls_init(AVFormatContext *s)
>> char *p = NULL;
>> int http_base_proto = ff_is_http_proto(s->url);
>> int fmp4_init_filename_len = strlen(hls->fmp4_init_filename) + 1;
>> +double initial_program_date_time = av_gettime() / 100.0;
> is it AV_TIME_BASE?

According to the documentation of av_gettime, it's not related to 

AV_TIME_BASE.


/**
 * Get the current time in microseconds.
 */
int64_t av_gettime(void);

I saw
/**
* Internal time base represented as integer
*/

#define AV_TIME_BASE100
Do you mean cannot av_gettime() / AV_TIME_BASE?


av_gettime() is always microsec according to docs, even if AV_TIME_BASE is 
not 100. In practice however AV_TIME_BASE is assumed to be 100 in 
a lot of places, so one can't really change it.


IMHO it is cleaner to use 100.0 instead of AV_TIME_BASE, because 
AV_TIME_BASE is integer, so you'd have to use (double)AV_TIME_BASE and 
that would be ugly. So I'd rather keep 100.0.


Ping, thanks,

Marton



>>
>> if (hls->use_localtime) {
>> pattern = get_default_pattern_localtime_fmt(s);
>> @@ -2798,12 +2799,7 @@ static int hls_init(AVFormatContext *s)
>> vs->start_pts = AV_NOPTS_VALUE;
>> vs->end_pts   = AV_NOPTS_VALUE;
>> vs->current_segment_final_filename_fmt[0] = '\0';
>> -
>> -if (hls->flags & HLS_PROGRAM_DATE_TIME) {
>> -time_t now0;
>> -time();
>> -vs->initial_prog_date_time = now0;
>> -}
>> +vs->initial_prog_date_time = initial_program_date_time;
>>
>> for (j = 0; j < vs->nb_streams; j++) {
>> vs->has_video += vs->streams[j]->codecpar->codec_type == 

AVMEDIA_TYPE_VIDEO;

>> --
>> 2.26.2
>>
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> ___
> 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 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 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] fftools/ffmpeg: make specifying thread_queue_size turn on threaded input

2020-07-27 Thread Marton Balint



On Sat, 18 Jul 2020, Marton Balint wrote:


Threaded input can increase smoothness of e.g. x11grab significantly. Before
this patch, in order to activate threaded input the user had to specify a
"dummy" additional input, with this change it is no longer required.


Ping, will apply soon.

Regards,
Marton



Signed-off-by: Marton Balint 
---
doc/ffmpeg.texi  | 5 +++--
fftools/ffmpeg.c | 6 --
fftools/ffmpeg_opt.c | 3 ++-
3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 70b8965d7f..267ddfe8b5 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -1689,8 +1689,9 @@ not start from timestamp 0, such as transport streams.
@item -thread_queue_size @var{size} (@emph{input})
This option sets the maximum number of queued packets when reading from the
file or device. With low latency / high rate live streams, packets may be
-discarded if they are not read in a timely manner; raising this value can
-avoid it.
+discarded if they are not read in a timely manner; setting this value can
+force ffmpeg to use a separate input thread and read packets as soon as they
+arrive. By default ffmpeg only do this if multiple inputs are specified.

@item -sdp_file @var{file} (@emph{global})
Print sdp information for an output stream to @var{file}.
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 2e9448ea2b..173ac3c9a0 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -4051,7 +4051,9 @@ static int init_input_thread(int i)
int ret;
InputFile *f = input_files[i];

-if (nb_input_files == 1)
+if (f->thread_queue_size < 0)
+f->thread_queue_size = (nb_input_files > 1 ? 8 : 0);
+if (!f->thread_queue_size)
return 0;

if (f->ctx->pb ? !f->ctx->pb->seekable :
@@ -4105,7 +4107,7 @@ static int get_input_packet(InputFile *f, AVPacket *pkt)
}

#if HAVE_THREADS
-if (nb_input_files > 1)
+if (f->thread_queue_size)
return get_input_packet_mt(f, pkt);
#endif
return av_read_frame(f->ctx, pkt);
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 9d1489ce01..853550a142 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -228,6 +228,7 @@ static void init_options(OptionsContext *o)
o->limit_filesize = UINT64_MAX;
o->chapters_input_file = INT_MAX;
o->accurate_seek  = 1;
+o->thread_queue_size = -1;
}

static int show_hwaccels(void *optctx, const char *opt, const char *arg)
@@ -1270,7 +1271,7 @@ static int open_input_file(OptionsContext *o, const char 
*filename)
f->duration = 0;
f->time_base = (AVRational){ 1, 1 };
#if HAVE_THREADS
-f->thread_queue_size = o->thread_queue_size > 0 ? o->thread_queue_size : 8;
+f->thread_queue_size = o->thread_queue_size;
#endif

/* check if all codec options have been used */
--
2.26.2

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

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

___
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] AVWriter again (was: v2 1/2] avformat/url: check double dot is not to parent directory)

2020-07-27 Thread Marton Balint



On Sat, 25 Jul 2020, Nicolas George wrote:


Marton Balint (12020-07-25):

And I also would like to point out that using static strings with
MAX_URL_SIZE is not OK. This function supports an arbitrary buffer size, so
limiting it to MAX_URL_SIZE is a bug.


Excellent point. That would require changing the prototype of a few
functions, but they are internal, we can do it.


If I understand correctly, you are speaking about URL handling in general 
all over the codebase, and not only ff_make_absolute_url.




For this, I would like to pitch the AVWriter API once again,


I think we understand the concept. It just seems a tiny bit heavy weight, 
or at least that was the primary concern as far as I remember.


Regards,
Marton


is made precisely for these cases: when you need to return a string of
arbitrary length, but would like to avoid, as much a possible, the
overhead of dynamically allocating it and the many error tests that come
with it. It is like AVBPrint, but better.

Let me elaborate without polluting the discussion by showing the actual
implementation.

So, let us say that function A calls function B, and function B needs to
return a string of arbitrary length but often small (I say string, but
the API can deal with binary data).

Likely use cases: rewriting an URL like here; escaping special
characters; serialization to key=value string; serialization to JSON or
XML; character encoding conversion, zlib-style unpacking, etc.


First, from the point of view of B, the function that needs to return
the string:

Instead of either:

int B(char *buf, size_t buf_size, other arguments);
int B(char **buf, other arguments);

request an AVWriter as argument:

void B(AVWriter wr, other arguments);

Then, just write in it with the various API functions:
av_writer_write(), av_writer_printf(), etc.

And that's all. Everything is taken care of: the string will grow as
needed, the size will be tracked, error checks are made. Nothing to
worry about at all.


Now, from the point of view of A, the function that calls B and gets a
string in return:

Instead of declaring a buffer, or a pointer to a buffer, declare:

AVWriter wr = av_dynbuf_writer();

and call B with it: B(wr, ...).

Then, extract the string, check for error (of course: dynamic allocation
can happen and fail; but this error check is the only one necessary),
use the string and free it:

char *msg = av_dynbuf_writer_get_data(wr, NULL);
if (!msg)
return AVERROR(ENOMEM);
do something with msg
av_dynbuf_writer_reset(wr);

I concede, for this example, av_dynbuf_writer_get_data() is one more
step than using the pointer directly. But as soon as the code becomes
more complex, in particular as soon as it uses the same writer twice to
put two strings together, this extra step is balanced by the fewer error
checks necessary.


All said, it makes one more API to learn, but IMHO, it is very simple to
learn: seven line of sample code. And the benefits are immediate.

Plus: there are many wonderful features that I have not told you about
yet.

So, Steven, Marton and the others: presented like that, does it look
appealing? Shall I elaborate?

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

[FFmpeg-devel] [PATCH] tests/imgutils: test the output of av_image_fill_* functions

2020-07-27 Thread James Almer
Signed-off-by: James Almer 
---
Should prevent regressions like the one fixed in 5ce47d0aad
 libavutil/tests/imgutils.c |  38 
 tests/ref/fate/imgutils| 183 +
 2 files changed, 221 insertions(+)

diff --git a/libavutil/tests/imgutils.c b/libavutil/tests/imgutils.c
index 571045c857..748bd6c9d2 100644
--- a/libavutil/tests/imgutils.c
+++ b/libavutil/tests/imgutils.c
@@ -22,6 +22,7 @@
 
 int main(void)
 {
+const AVPixFmtDescriptor *desc = NULL;
 int64_t x, y;
 
 for (y = -1; yname);
+for (i = 0; i < 4 && data[i]; i++);
+printf("planes: %d", i);
+// Test the output of av_image_fill_linesizes()
+printf(", linesizes:");
+for (i = 0; i < 4; i++)
+printf(" %3d", linesizes[i]);
+// Test the output of av_image_fill_plane_sizes()
+printf(", plane_sizes:");
+for (i = 0; i < 4; i++)
+printf(" %5"SIZE_SPECIFIER, sizes[i]);
+// Test the output of av_image_fill_pointers()
+for (i = 0; i < 3 && data[i + 1]; i++)
+offsets[i] = data[i + 1] - data[i];
+printf(", plane_offsets:");
+for (i = 0; i < 3; i++)
+printf(" %5"PTRDIFF_SPECIFIER, offsets[i]);
+printf(", total_size: %d\n", total_size);
+}
 
 return 0;
 }
diff --git a/tests/ref/fate/imgutils b/tests/ref/fate/imgutils
index aba482221f..c968ea0e85 100644
--- a/tests/ref/fate/imgutils
+++ b/tests/ref/fate/imgutils
@@ -53,3 +53,186 @@
 000
 000
 000
+
+yuv420p planes: 3, linesizes:  64  32  32   0, plane_sizes:  3072   
768   768 0, plane_offsets:  3072   768 0, total_size: 4608
+yuyv422 planes: 1, linesizes: 128   0   0   0, plane_sizes:  6144 
0 0 0, plane_offsets: 0 0 0, total_size: 6144
+rgb24   planes: 1, linesizes: 192   0   0   0, plane_sizes:  9216 
0 0 0, plane_offsets: 0 0 0, total_size: 9216
+bgr24   planes: 1, linesizes: 192   0   0   0, plane_sizes:  9216 
0 0 0, plane_offsets: 0 0 0, total_size: 9216
+yuv422p planes: 3, linesizes:  64  32  32   0, plane_sizes:  3072  
1536  1536 0, plane_offsets:  3072  1536 0, total_size: 6144
+yuv444p planes: 3, linesizes:  64  64  64   0, plane_sizes:  3072  
3072  3072 0, plane_offsets:  3072  3072 0, total_size: 9216
+yuv410p planes: 3, linesizes:  64  16  16   0, plane_sizes:  3072   
192   192 0, plane_offsets:  3072   192 0, total_size: 3456
+yuv411p planes: 3, linesizes:  64  16  16   0, plane_sizes:  3072   
768   768 0, plane_offsets:  3072   768 0, total_size: 4608
+grayplanes: 2, linesizes:  64   0   0   0, plane_sizes:  3072  
1024 0 0, plane_offsets:  3072 0 0, total_size: 4096
+monow   planes: 1, linesizes:   8   0   0   0, plane_sizes:   384 
0 0 0, plane_offsets: 0 0 0, total_size: 384
+monob   planes: 1, linesizes:   8   0   0   0, plane_sizes:   384 
0 0 0, plane_offsets: 0 0 0, total_size: 384
+pal8planes: 2, linesizes:  64   0   0   0, plane_sizes:  3072  
1024 0 0, plane_offsets:  3072 0 0, total_size: 4096
+yuvj420pplanes: 3, linesizes:  64  32  32   0, plane_sizes:  3072   
768   768 0, plane_offsets:  3072   768 0, total_size: 4608
+yuvj422pplanes: 3, linesizes:  64  32  32   0, plane_sizes:  3072  
1536  1536 0, plane_offsets:  3072  1536 0, total_size: 6144
+yuvj444pplanes: 3, linesizes:  64  64  64   0, plane_sizes:  3072  
3072  3072 0, plane_offsets:  3072  3072 0, total_size: 9216
+uyvy422 planes: 1, linesizes: 128   0   0   0, plane_sizes:  6144 
0 0 0, plane_offsets: 0 0 0, total_size: 6144
+uyyvyy411   planes: 1, linesizes:  96   0   0   0, plane_sizes:  4608 
0 0 0, plane_offsets: 0 0 0, total_size: 4608
+bgr8planes: 2, linesizes:  64   0   0   0, plane_sizes:  3072  
1024 0 0, plane_offsets:  3072 0 0, total_size: 4096
+bgr4planes: 1, linesizes:  32   0   0   0, plane_sizes:  1536 
0 0 0, plane_offsets: 0 0 0, total_size: 1536
+bgr4_byte   planes: 2, linesizes:  64   0   0   0, plane_sizes:  3072  
1024 0 0, plane_offsets:  3072 0 0, total_size: 4096
+rgb8planes: 2, linesizes:  64   0   0   0, plane_sizes:  3072  
1024 0 0, plane_offsets:  3072 0 0, total_size: 4096
+rgb4planes: 1, linesizes:  32   0   0   0, plane_sizes:  1536 
0 0 0, plane_offsets: 0 0 0, total_size: 1536
+rgb4_byte   planes: 2, linesizes:  64   0   0   0, plane_sizes:  3072  
1024 0 0, plane_offsets: 

Re: [FFmpeg-devel] [PATCH v2 1/2] avformat/url: check double dot is not to parent directory

2020-07-27 Thread Marton Balint



On Mon, 27 Jul 2020, Steven Liu wrote:


Marton Balint  于2020年7月25日周六 下午5:40写道:




On Sat, 25 Jul 2020, Zlomek, Josef wrote:

> Hi Steven,
>
> It is better but still not correct. Consider this test:
>
> test("http://server/foo/bar;,
> "a/b/../c/d/../e../.../..f/g../h../other/url/a.mp3/...");
> It should give "
> http://server/foo/bar/a/c/e../.../..f/g../h../other/url/a.mp3/...;.
>
> I think the best would be to use strtok(p, "/") to split the path into the
> components and for each ".." component remove the previous one (if there
> are some still).

And I also would like to point out that using static strings with
MAX_URL_SIZE is not OK. This function supports an arbitrary buffer size,
so limiting it to MAX_URL_SIZE is a bug.

What about use av_malloc? or bprint?
I think use av_malloc maybe easter to me.


It should be implemented in a way which does not use a temporary buffer. 
Seems doable.


Regards,
Marton
___
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] Inconsistent handling of initial_padding and PTS adjustment

2020-07-27 Thread Kieran Kunhya
On Mon, 27 Jul 2020 at 11:09, Anton Khirnov  wrote:

> Quoting Kieran Kunhya (2020-07-26 01:51:22)
> > Hi,
> >
> > I notice that some encoders adjust the PTS with initial_padding and some
> > don't.
> > Is this intentional and should we decide that all encoders should do
> this?
>
> Which ones don't?
>

A few here:
https://github.com/FFmpeg/FFmpeg/search?p=1=initial_padding_q=initial_padding


> I don't think this is a matter of opinion really - if encoder adds
> padding and doesn't adjust the timestamps then the output timestamps are
> just plain wrong.
>

Well some containers have a flag for it. Right now if you encoded with
libopus into mkv or ts you get the PTS offset as well as the syntax element
written to the bitstream.

Kieran
___
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 20/22] vaapi_encode_h265: Use common handling for HDR metadata

2020-07-27 Thread Mark Thompson
---
 libavcodec/vaapi_encode_h265.c | 45 +-
 1 file changed, 6 insertions(+), 39 deletions(-)

diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index 90fea83388..f996f78f8e 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -768,39 +768,10 @@ static int 
vaapi_encode_h265_init_picture_params(AVCodecContext *avctx,
 AVMasteringDisplayMetadata *mdm =
 (AVMasteringDisplayMetadata *)sd->data;
 
-// SEI is needed when both the primaries and luminance are set
+// Only needed when both primaries and luminance are set.
 if (mdm->has_primaries && mdm->has_luminance) {
-H265RawSEIMasteringDisplayColourVolume *mdcv =
->sei_mastering_display;
-const int mapping[3] = {1, 2, 0};
-const int chroma_den = 5;
-const int luma_den   = 1;
-
-for (i = 0; i < 3; i++) {
-const int j = mapping[i];
-mdcv->display_primaries_x[i] =
-FFMIN(lrint(chroma_den *
-av_q2d(mdm->display_primaries[j][0])),
-  chroma_den);
-mdcv->display_primaries_y[i] =
-FFMIN(lrint(chroma_den *
-av_q2d(mdm->display_primaries[j][1])),
-  chroma_den);
-}
-
-mdcv->white_point_x =
-FFMIN(lrint(chroma_den * av_q2d(mdm->white_point[0])),
-  chroma_den);
-mdcv->white_point_y =
-FFMIN(lrint(chroma_den * av_q2d(mdm->white_point[1])),
-  chroma_den);
-
-mdcv->max_display_mastering_luminance =
-lrint(luma_den * av_q2d(mdm->max_luminance));
-mdcv->min_display_mastering_luminance =
-FFMIN(lrint(luma_den * av_q2d(mdm->min_luminance)),
-  mdcv->max_display_mastering_luminance);
-
+ff_cbs_h265_fill_sei_mastering_display(
+>sei_mastering_display, mdm);
 priv->sei_needed |= SEI_MASTERING_DISPLAY;
 }
 }
@@ -813,13 +784,9 @@ static int 
vaapi_encode_h265_init_picture_params(AVCodecContext *avctx,
AV_FRAME_DATA_CONTENT_LIGHT_LEVEL);
 
 if (sd) {
-AVContentLightMetadata *clm =
-(AVContentLightMetadata *)sd->data;
-H265RawSEIContentLightLevelInfo *clli =
->sei_content_light_level;
-
-clli->max_content_light_level = FFMIN(clm->MaxCLL,  65535);
-clli->max_pic_average_light_level = FFMIN(clm->MaxFALL, 65535);
+ff_cbs_h265_fill_sei_content_light_level(
+>sei_content_light_level,
+(const AVContentLightMetadata*)sd->data);
 
 priv->sei_needed |= SEI_CONTENT_LIGHT_LEVEL;
 }
-- 
2.27.0

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

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

[FFmpeg-devel] [PATCH v6 19/22] cbs_h265: Add functions to turn HDR metadata into SEI

2020-07-27 Thread Mark Thompson
---
 libavcodec/Makefile   |   2 +-
 libavcodec/cbs_h265.c | 100 ++
 libavcodec/cbs_h265.h |  18 
 3 files changed, 119 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/cbs_h265.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 6394694617..96dc1df343 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -71,7 +71,7 @@ OBJS-$(CONFIG_CABAC)   += cabac.o
 OBJS-$(CONFIG_CBS) += cbs.o
 OBJS-$(CONFIG_CBS_AV1) += cbs_av1.o
 OBJS-$(CONFIG_CBS_H264)+= cbs_h2645.o cbs_h264.o h2645_parse.o
-OBJS-$(CONFIG_CBS_H265)+= cbs_h2645.o h2645_parse.o
+OBJS-$(CONFIG_CBS_H265)+= cbs_h2645.o cbs_h265.o h2645_parse.o
 OBJS-$(CONFIG_CBS_JPEG)+= cbs_jpeg.o
 OBJS-$(CONFIG_CBS_MPEG2)   += cbs_mpeg2.o
 OBJS-$(CONFIG_CBS_VP9) += cbs_vp9.o
diff --git a/libavcodec/cbs_h265.c b/libavcodec/cbs_h265.c
new file mode 100644
index 00..afbdd37896
--- /dev/null
+++ b/libavcodec/cbs_h265.c
@@ -0,0 +1,100 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/mathematics.h"
+#include "libavutil/mastering_display_metadata.h"
+
+#include "cbs_h265.h"
+
+
+static uint32_t rescale_clip(AVRational value, uint32_t scale, uint32_t max)
+{
+int64_t scaled = av_rescale(scale, value.num, value.den);
+return av_clip64(scaled, 0, max);
+}
+
+static uint32_t rescale_fraction(AVRational value, uint32_t max)
+{
+return rescale_clip(value, max, max);
+}
+
+void 
ff_cbs_h265_fill_sei_mastering_display(H265RawSEIMasteringDisplayColourVolume 
*mdcv,
+const AVMasteringDisplayMetadata 
*mdm)
+{
+memset(mdcv, 0, sizeof(*mdcv));
+
+if (mdm->has_primaries) {
+// The values in the metadata structure are fractions between 0 and 1,
+// while the SEI message contains fixed-point values with an increment
+// of 0.2.  So, scale up by 5 to convert between them.
+
+for (int a = 0; a < 3; a++) {
+// The metadata structure stores this in RGB order, but the SEI
+// wants it in GBR order.
+static const uint8_t mapping[] = { 1, 2, 0 };
+int b = mapping[a];
+mdcv->display_primaries_x[a] =
+rescale_fraction(mdm->display_primaries[b][0], 5);
+mdcv->display_primaries_y[a] =
+rescale_fraction(mdm->display_primaries[b][1], 5);
+}
+
+mdcv->white_point_x = rescale_fraction(mdm->white_point[0], 5);
+mdcv->white_point_y = rescale_fraction(mdm->white_point[1], 5);
+}
+
+if (mdm->has_luminance) {
+// Metadata are rational values in candelas per square metre, SEI
+// contains fixed point in units of 0.0001 candelas per square
+// metre.  So scale up by 1 to convert between them, and clip to
+// ensure that we don't overflow.
+
+mdcv->max_display_mastering_luminance =
+rescale_clip(mdm->max_luminance, 1, UINT32_MAX);
+mdcv->min_display_mastering_luminance =
+rescale_clip(mdm->min_luminance, 1, UINT32_MAX);
+
+// The spec has a hard requirement that min is less than the max,
+// and the SEI-writing code enforces that.
+if (!(mdcv->min_display_mastering_luminance <
+  mdcv->max_display_mastering_luminance)) {
+if (mdcv->max_display_mastering_luminance == UINT32_MAX)
+mdcv->min_display_mastering_luminance =
+mdcv->max_display_mastering_luminance - 1;
+else
+mdcv->max_display_mastering_luminance =
+mdcv->min_display_mastering_luminance + 1;
+}
+} else {
+mdcv->max_display_mastering_luminance = 1;
+mdcv->min_display_mastering_luminance = 0;
+}
+}
+
+void ff_cbs_h265_fill_sei_content_light_level(H265RawSEIContentLightLevelInfo 
*cll,
+  const AVContentLightMetadata 
*clm)
+{
+memset(cll, 0, sizeof(*cll));
+
+// Both the metadata and the SEI are in units of candelas per square
+// metre, 

[FFmpeg-devel] [PATCH v6 22/22] h264_metadata_bsf: Improve interpretation of input display matrices

2020-07-27 Thread Mark Thompson
The previous code here only worked in more limited cases.
---
 libavcodec/h264_metadata_bsf.c | 42 +++---
 1 file changed, 29 insertions(+), 13 deletions(-)

diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
index 1d00ccdfb8..38c9e7f6f5 100644
--- a/libavcodec/h264_metadata_bsf.c
+++ b/libavcodec/h264_metadata_bsf.c
@@ -441,23 +441,39 @@ static int 
h264_metadata_handle_display_orientation(AVBSFContext *bsf,
 data = av_packet_get_side_data(pkt, AV_PKT_DATA_DISPLAYMATRIX, );
 if (data && size >= 9 * sizeof(int32_t)) {
 int32_t matrix[9];
+double dmatrix[9];
 int hflip, vflip;
-double angle;
+double scale_x, scale_y, angle;
 
 memcpy(matrix, data, sizeof(matrix));
 
-hflip = vflip = 0;
-if (matrix[0] < 0 && matrix[4] > 0)
-hflip = 1;
-else if (matrix[0] > 0 && matrix[4] < 0)
-vflip = 1;
-av_display_matrix_flip(matrix, hflip, vflip);
+for (i = 0; i < 9; i++)
+dmatrix[i] = matrix[i] / 65536.0;
+
+// Extract scale factors.
+scale_x = hypot(dmatrix[0], dmatrix[3]);
+scale_y = hypot(dmatrix[1], dmatrix[4]);
+
+// Select flips to make the main diagonal positive.
+hflip = dmatrix[0] < 0.0;
+vflip = dmatrix[4] < 0.0;
+if (hflip)
+scale_x = -scale_x;
+if (vflip)
+scale_y = -scale_y;
+
+// Rescale.
+for (i = 0; i < 9; i += 3) {
+dmatrix[i] /= scale_x;
+dmatrix[i + 1] /= scale_y;
+}
 
-angle = av_display_rotation_get(matrix);
+// Extract rotation.
+angle = atan2(dmatrix[3], dmatrix[0]);
 
-if (!(angle >= -180.0 && angle <= 180.0 /* also excludes NaN */) ||
-matrix[2] != 0 || matrix[5] != 0 ||
-matrix[6] != 0 || matrix[7] != 0) {
+if (!(angle >= -M_PI && angle <= M_PI) ||
+matrix[2] != 0.0 || matrix[5] != 0.0 ||
+matrix[6] != 0.0 || matrix[7] != 0.0) {
 av_log(bsf, AV_LOG_WARNING, "Input display matrix is not "
"representable in H.264 parameters.\n");
 } else {
@@ -465,8 +481,8 @@ static int 
h264_metadata_handle_display_orientation(AVBSFContext *bsf,
 disp->ver_flip = vflip;
 disp->anticlockwise_rotation =
 (uint16_t)rint((angle >= 0.0 ? angle
- : angle + 360.0) *
-   65536.0 / 360.0);
+ : angle + 2 * M_PI) *
+   32768.0 / M_PI);
 write = 1;
 }
 }
-- 
2.27.0

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

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

[FFmpeg-devel] [PATCH v6 21/22] h264_metadata_bsf: Refactor the filter function into smaller parts

2020-07-27 Thread Mark Thompson
---
 libavcodec/h264_metadata_bsf.c | 443 ++---
 1 file changed, 242 insertions(+), 201 deletions(-)

diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
index eb1503159b..1d00ccdfb8 100644
--- a/libavcodec/h264_metadata_bsf.c
+++ b/libavcodec/h264_metadata_bsf.c
@@ -56,6 +56,7 @@ typedef struct H264MetadataContext {
 int done_first_au;
 
 int aud;
+H264RawAUD aud_nal;
 
 AVRational sample_aspect_ratio;
 
@@ -78,6 +79,7 @@ typedef struct H264MetadataContext {
 int crop_bottom;
 
 const char *sei_user_data;
+H264RawSEIPayload sei_user_data_payload;
 
 int delete_filler;
 
@@ -89,6 +91,59 @@ typedef struct H264MetadataContext {
 } H264MetadataContext;
 
 
+static int h264_metadata_insert_aud(AVBSFContext *bsf,
+CodedBitstreamFragment *au)
+{
+H264MetadataContext *ctx = bsf->priv_data;
+int primary_pic_type_mask = 0xff;
+int err, i, j;
+
+static const int primary_pic_type_table[] = {
+0x084, // 2, 7
+0x0a5, // 0, 2, 5, 7
+0x0e7, // 0, 1, 2, 5, 6, 7
+0x210, // 4, 9
+0x318, // 3, 4, 8, 9
+0x294, // 2, 4, 7, 9
+0x3bd, // 0, 2, 3, 4, 5, 7, 8, 9
+0x3ff, // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
+};
+
+for (i = 0; i < au->nb_units; i++) {
+if (au->units[i].type == H264_NAL_SLICE ||
+au->units[i].type == H264_NAL_IDR_SLICE) {
+H264RawSlice *slice = au->units[i].content;
+for (j = 0; j < FF_ARRAY_ELEMS(primary_pic_type_table); j++) {
+if (!(primary_pic_type_table[j] &
+  (1 << slice->header.slice_type)))
+primary_pic_type_mask &= ~(1 << j);
+}
+}
+}
+for (j = 0; j < FF_ARRAY_ELEMS(primary_pic_type_table); j++)
+if (primary_pic_type_mask & (1 << j))
+break;
+if (j >= FF_ARRAY_ELEMS(primary_pic_type_table)) {
+av_log(bsf, AV_LOG_ERROR, "No usable primary_pic_type: "
+   "invalid slice types?\n");
+return AVERROR_INVALIDDATA;
+}
+
+ctx->aud_nal = (H264RawAUD) {
+.nal_unit_header.nal_unit_type = H264_NAL_AUD,
+.primary_pic_type = j,
+};
+
+err = ff_cbs_insert_unit_content(au, 0, H264_NAL_AUD,
+ >aud_nal, NULL);
+if (err < 0) {
+av_log(bsf, AV_LOG_ERROR, "Failed to insert AUD.\n");
+return err;
+}
+
+return 0;
+}
+
 static int h264_metadata_update_sps(AVBSFContext *bsf,
 H264RawSPS *sps)
 {
@@ -320,219 +375,59 @@ static int h264_metadata_update_side_data(AVBSFContext 
*bsf, AVPacket *pkt)
 return 0;
 }
 
-static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt)
+static int h264_metadata_handle_display_orientation(AVBSFContext *bsf,
+AVPacket *pkt,
+CodedBitstreamFragment *au,
+int seek_point)
 {
 H264MetadataContext *ctx = bsf->priv_data;
-CodedBitstreamFragment *au = >access_unit;
-int err, i, j, has_sps;
-H264RawAUD aud;
-
-err = ff_bsf_get_packet_ref(bsf, pkt);
-if (err < 0)
-return err;
-
-err = h264_metadata_update_side_data(bsf, pkt);
-if (err < 0)
-goto fail;
-
-err = ff_cbs_read_packet(ctx->input, au, pkt);
-if (err < 0) {
-av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n");
-goto fail;
-}
-
-if (au->nb_units == 0) {
-av_log(bsf, AV_LOG_ERROR, "No NAL units in packet.\n");
-err = AVERROR_INVALIDDATA;
-goto fail;
-}
-
-// If an AUD is present, it must be the first NAL unit.
-if (au->units[0].type == H264_NAL_AUD) {
-if (ctx->aud == REMOVE)
-ff_cbs_delete_unit(au, 0);
-} else {
-if (ctx->aud == INSERT) {
-static const int primary_pic_type_table[] = {
-0x084, // 2, 7
-0x0a5, // 0, 2, 5, 7
-0x0e7, // 0, 1, 2, 5, 6, 7
-0x210, // 4, 9
-0x318, // 3, 4, 8, 9
-0x294, // 2, 4, 7, 9
-0x3bd, // 0, 2, 3, 4, 5, 7, 8, 9
-0x3ff, // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
-};
-int primary_pic_type_mask = 0xff;
-
-for (i = 0; i < au->nb_units; i++) {
-if (au->units[i].type == H264_NAL_SLICE ||
-au->units[i].type == H264_NAL_IDR_SLICE) {
-H264RawSlice *slice = au->units[i].content;
-for (j = 0; j < FF_ARRAY_ELEMS(primary_pic_type_table); 
j++) {
- if (!(primary_pic_type_table[j] &
-   (1 << slice->header.slice_type)))
- primary_pic_type_mask &= ~(1 << j);
-}
-}
- 

[FFmpeg-devel] [PATCH v6 15/22] cbs_h264: Add support for frame packing arrangement SEI messages

2020-07-27 Thread Mark Thompson
---
 libavcodec/cbs_h264.h | 24 
 libavcodec/cbs_h2645.c|  1 +
 libavcodec/cbs_h264_syntax_template.c | 40 +++
 3 files changed, 65 insertions(+)

diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h
index 88313629f5..ca717a3b57 100644
--- a/libavcodec/cbs_h264.h
+++ b/libavcodec/cbs_h264.h
@@ -296,6 +296,29 @@ typedef struct H264RawSEIRecoveryPoint {
 uint8_t changing_slice_group_idc;
 } H264RawSEIRecoveryPoint;
 
+typedef struct H264RawSEIFramePackingArrangement {
+uint32_t frame_packing_arrangement_id;
+uint8_t  frame_packing_arrangement_cancel_flag;
+
+uint8_t  frame_packing_arrangement_type;
+uint8_t  quincunx_sampling_flag;
+uint8_t  content_interpretation_type;
+uint8_t  spatial_flipping_flag;
+uint8_t  frame0_flipped_flag;
+uint8_t  field_views_flag;
+uint8_t  current_frame_is_frame0_flag;
+uint8_t  frame0_self_contained_flag;
+uint8_t  frame1_self_contained_flag;
+uint8_t  frame0_grid_position_x;
+uint8_t  frame0_grid_position_y;
+uint8_t  frame1_grid_position_x;
+uint8_t  frame1_grid_position_y;
+uint8_t  frame_packing_arrangement_reserved_byte;
+uint16_t frame_packing_arrangement_repetition_period;
+
+uint8_t  frame_packing_arrangement_extension_flag;
+} H264RawSEIFramePackingArrangement;
+
 typedef struct H264RawSEIDisplayOrientation {
 uint8_t display_orientation_cancel_flag;
 uint8_t hor_flip;
@@ -329,6 +352,7 @@ typedef struct H264RawSEIPayload {
 H264RawSEIUserDataRegistered user_data_registered;
 H264RawSEIUserDataUnregistered user_data_unregistered;
 H264RawSEIRecoveryPoint recovery_point;
+H264RawSEIFramePackingArrangement frame_packing_arrangement;
 H264RawSEIDisplayOrientation display_orientation;
 H264RawSEIMasteringDisplayColourVolume mastering_display_colour_volume;
 H264RawSEIAlternativeTransferCharacteristics
diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 603017d8fe..1677731db9 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -1331,6 +1331,7 @@ void ff_cbs_h264_free_sei_payload(H264RawSEIPayload 
*payload)
 case H264_SEI_TYPE_PIC_TIMING:
 case H264_SEI_TYPE_PAN_SCAN_RECT:
 case H264_SEI_TYPE_RECOVERY_POINT:
+case H264_SEI_TYPE_FRAME_PACKING:
 case H264_SEI_TYPE_DISPLAY_ORIENTATION:
 case H264_SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME:
 case H264_SEI_TYPE_ALTERNATIVE_TRANSFER:
diff --git a/libavcodec/cbs_h264_syntax_template.c 
b/libavcodec/cbs_h264_syntax_template.c
index b65460996b..7880b1472c 100644
--- a/libavcodec/cbs_h264_syntax_template.c
+++ b/libavcodec/cbs_h264_syntax_template.c
@@ -779,6 +779,42 @@ static int FUNC(sei_recovery_point)(CodedBitstreamContext 
*ctx, RWContext *rw,
 return 0;
 }
 
+static int FUNC(sei_frame_packing_arrangement)(CodedBitstreamContext *ctx, 
RWContext *rw,
+   
H264RawSEIFramePackingArrangement *current)
+{
+int err;
+
+HEADER("Frame Packing Arrangement");
+
+ue(frame_packing_arrangement_id, 0, UINT32_MAX - 1);
+flag(frame_packing_arrangement_cancel_flag);
+
+if (!current->frame_packing_arrangement_cancel_flag) {
+u(7, frame_packing_arrangement_type, 0, 7);
+flag(quincunx_sampling_flag);
+u(6, content_interpretation_type, 0, 2);
+flag(spatial_flipping_flag);
+flag(frame0_flipped_flag);
+flag(field_views_flag);
+flag(current_frame_is_frame0_flag);
+flag(frame0_self_contained_flag);
+flag(frame1_self_contained_flag);
+if (!current->quincunx_sampling_flag &&
+current->frame_packing_arrangement_type != 5) {
+ub(4, frame0_grid_position_x);
+ub(4, frame0_grid_position_y);
+ub(4, frame1_grid_position_x);
+ub(4, frame1_grid_position_y);
+}
+u(8, frame_packing_arrangement_reserved_byte, 0, 0);
+ue(frame_packing_arrangement_repetition_period, 0, 16384);
+}
+
+flag(frame_packing_arrangement_extension_flag);
+
+return 0;
+}
+
 static int FUNC(sei_display_orientation)(CodedBitstreamContext *ctx, RWContext 
*rw,
  H264RawSEIDisplayOrientation *current)
 {
@@ -879,6 +915,10 @@ static int FUNC(sei_payload)(CodedBitstreamContext *ctx, 
RWContext *rw,
 CHECK(FUNC(sei_display_orientation)
   (ctx, rw, >payload.display_orientation));
 break;
+case H264_SEI_TYPE_FRAME_PACKING:
+CHECK(FUNC(sei_frame_packing_arrangement)
+  (ctx, rw, >payload.frame_packing_arrangement));
+break;
 case H264_SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME:
 CHECK(FUNC(sei_mastering_display_colour_volume)
   (ctx, rw, >payload.mastering_display_colour_volume));
-- 
2.27.0

___
ffmpeg-devel mailing list

[FFmpeg-devel] [PATCH v6 18/22] vaapi_encode_h264: Support stereo 3D metadata

2020-07-27 Thread Mark Thompson
Insert frame packing arrangement messages into the stream when input
frames have associated stereo 3D side-data.
---
 doc/encoders.texi  |  3 +++
 libavcodec/vaapi_encode.h  |  1 +
 libavcodec/vaapi_encode_h264.c | 24 +++-
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index ed8ef63784..32870f5939 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3175,6 +3175,9 @@ Include picture timing parameters 
(@emph{buffering_period} and
 @emph{pic_timing} messages).
 @item recovery_point
 Include recovery points where appropriate (@emph{recovery_point} messages).
+@item frame_packing
+Include stereo 3D metadata if the input frames have it
+(@emph{frame_packing_arrangement} messages).
 @end table
 
 @end table
diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
index 3bb240ec68..671b21f283 100644
--- a/libavcodec/vaapi_encode.h
+++ b/libavcodec/vaapi_encode.h
@@ -483,6 +483,7 @@ enum {
 SEI_RECOVERY_POINT  = 0x04,
 SEI_MASTERING_DISPLAY   = 0x08,
 SEI_CONTENT_LIGHT_LEVEL = 0x10,
+SEI_FRAME_PACKING   = 0x20,
 };
 
 
diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index 62f95ea59f..f6d16b5c24 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -25,6 +25,7 @@
 #include "libavutil/common.h"
 #include "libavutil/internal.h"
 #include "libavutil/opt.h"
+#include "libavutil/stereo3d.h"
 
 #include "avcodec.h"
 #include "cbs.h"
@@ -90,6 +91,7 @@ typedef struct VAAPIEncodeH264Context {
 H264RawSEIBufferingPeriod  sei_buffering_period;
 H264RawSEIPicTimingsei_pic_timing;
 H264RawSEIRecoveryPointsei_recovery_point;
+H264RawSEIFramePackingArrangement sei_frame_packing;
 H264RawSEIUserDataUnregistered sei_identifier;
 char  *sei_identifier_string;
 
@@ -244,6 +246,12 @@ static int 
vaapi_encode_h264_write_extra_header(AVCodecContext *avctx,
 sei->payload[i].payload.recovery_point = priv->sei_recovery_point;
 ++i;
 }
+if (priv->sei_needed & SEI_FRAME_PACKING) {
+sei->payload[i].payload_type = H264_SEI_TYPE_FRAME_PACKING;
+sei->payload[i].payload.frame_packing_arrangement =
+priv->sei_frame_packing;
+++i;
+}
 
 sei->payload_count = i;
 av_assert0(sei->payload_count > 0);
@@ -693,6 +701,17 @@ static int 
vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
 priv->sei_needed |= SEI_RECOVERY_POINT;
 }
 
+if (priv->sei & SEI_FRAME_PACKING) {
+AVFrameSideData *sd = av_frame_get_side_data(pic->input_image,
+ AV_FRAME_DATA_STEREO3D);
+if (sd) {
+ff_cbs_h264_fill_sei_frame_packing_arrangement(
+>sei_frame_packing, (const AVStereo3D*)sd->data);
+
+priv->sei_needed |= SEI_FRAME_PACKING;
+}
+}
+
 vpic->CurrPic = (VAPictureH264) {
 .picture_id  = pic->recon_surface,
 .frame_idx   = hpic->frame_num,
@@ -1264,7 +1283,7 @@ static const AVOption vaapi_encode_h264_options[] = {
 
 { "sei", "Set SEI to include",
   OFFSET(sei), AV_OPT_TYPE_FLAGS,
-  { .i64 = SEI_IDENTIFIER | SEI_TIMING | SEI_RECOVERY_POINT },
+  { .i64 = SEI_IDENTIFIER | SEI_TIMING | SEI_RECOVERY_POINT | 
SEI_FRAME_PACKING },
   0, INT_MAX, FLAGS, "sei" },
 { "identifier", "Include encoder version identifier",
   0, AV_OPT_TYPE_CONST, { .i64 = SEI_IDENTIFIER },
@@ -1275,6 +1294,9 @@ static const AVOption vaapi_encode_h264_options[] = {
 { "recovery_point", "Include recovery points where appropriate",
   0, AV_OPT_TYPE_CONST, { .i64 = SEI_RECOVERY_POINT },
   INT_MIN, INT_MAX, FLAGS, "sei" },
+{ "frame_packing", "Include frame packing arrangement for stereo 3D",
+  0, AV_OPT_TYPE_CONST, { .i64 = SEI_FRAME_PACKING },
+  INT_MIN, INT_MAX, FLAGS, "sei" },
 
 { "profile", "Set profile (profile_idc and constraint_set*_flag)",
   OFFSET(profile), AV_OPT_TYPE_INT,
-- 
2.27.0

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

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

[FFmpeg-devel] [PATCH v6 13/22] cbs: Expose the function to insert a new empty unit into a fragment

2020-07-27 Thread Mark Thompson
This will be helpful when adding new SEI to an existing access unit.
---
 libavcodec/cbs.c | 8 
 libavcodec/cbs.h | 6 ++
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index 7c1aa005c2..6677442d10 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -674,8 +674,8 @@ int ff_cbs_alloc_unit_data(CodedBitstreamUnit *unit,
 return 0;
 }
 
-static int cbs_insert_unit(CodedBitstreamFragment *frag,
-   int position)
+int ff_cbs_insert_unit(CodedBitstreamFragment *frag,
+   int position)
 {
 CodedBitstreamUnit *units;
 
@@ -734,7 +734,7 @@ int ff_cbs_insert_unit_content(CodedBitstreamFragment *frag,
 content_ref = NULL;
 }
 
-err = cbs_insert_unit(frag, position);
+err = ff_cbs_insert_unit(frag, position);
 if (err < 0) {
 av_buffer_unref(_ref);
 return err;
@@ -772,7 +772,7 @@ int ff_cbs_insert_unit_data(CodedBitstreamFragment *frag,
 return AVERROR(ENOMEM);
 }
 
-err = cbs_insert_unit(frag, position);
+err = ff_cbs_insert_unit(frag, position);
 if (err < 0) {
 av_buffer_unref(_ref);
 return err;
diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h
index 3a054aa8f3..9152d655d2 100644
--- a/libavcodec/cbs.h
+++ b/libavcodec/cbs.h
@@ -366,6 +366,12 @@ int ff_cbs_alloc_unit_content2(CodedBitstreamContext *ctx,
 int ff_cbs_alloc_unit_data(CodedBitstreamUnit *unit,
size_t size);
 
+/**
+ * Insert a new empty unit into a fragment.
+ */
+int ff_cbs_insert_unit(CodedBitstreamFragment *frag,
+   int position);
+
 /**
  * Insert a new unit into a fragment with the given content.
  *
-- 
2.27.0

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

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

[FFmpeg-devel] [PATCH v6 17/22] vaapi_encode: Unify SEI types enum

2020-07-27 Thread Mark Thompson
This was in two disjoint parts in the H.264 and H.265 files.  Unify them in
the header to avoid any confusion, because they are really the same enum.
---
 libavcodec/vaapi_encode.h  | 10 ++
 libavcodec/vaapi_encode_h264.c |  6 --
 libavcodec/vaapi_encode_h265.c |  5 -
 3 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
index 6487a99604..3bb240ec68 100644
--- a/libavcodec/vaapi_encode.h
+++ b/libavcodec/vaapi_encode.h
@@ -476,4 +476,14 @@ int ff_vaapi_encode_close(AVCodecContext *avctx);
 VAAPI_ENCODE_RC_MODE(AVBR, "Average variable-bitrate")
 
 
+// SEI types used in options for both H.264 and H.265.
+enum {
+SEI_TIMING  = 0x01,
+SEI_IDENTIFIER  = 0x02,
+SEI_RECOVERY_POINT  = 0x04,
+SEI_MASTERING_DISPLAY   = 0x08,
+SEI_CONTENT_LIGHT_LEVEL = 0x10,
+};
+
+
 #endif /* AVCODEC_VAAPI_ENCODE_H */
diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index 5e1683e851..62f95ea59f 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -35,12 +35,6 @@
 #include "internal.h"
 #include "vaapi_encode.h"
 
-enum {
-SEI_TIMING = 0x01,
-SEI_IDENTIFIER = 0x02,
-SEI_RECOVERY_POINT = 0x04,
-};
-
 // Random (version 4) ISO 11578 UUID.
 static const uint8_t vaapi_encode_h264_sei_identifier_uuid[16] = {
 0x59, 0x94, 0x8b, 0x28, 0x11, 0xec, 0x45, 0xaf,
diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index f6008778df..90fea83388 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -37,11 +37,6 @@
 #include "put_bits.h"
 #include "vaapi_encode.h"
 
-enum {
-SEI_MASTERING_DISPLAY   = 0x08,
-SEI_CONTENT_LIGHT_LEVEL = 0x10,
-};
-
 typedef struct VAAPIEncodeH265Picture {
 int pic_order_cnt;
 
-- 
2.27.0

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

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

[FFmpeg-devel] [PATCH v6 16/22] cbs_h264: Add a function to turn stereo 3D metadata into SEI

2020-07-27 Thread Mark Thompson
---
 libavcodec/cbs_h264.c | 47 +++
 libavcodec/cbs_h264.h |  8 
 2 files changed, 55 insertions(+)

diff --git a/libavcodec/cbs_h264.c b/libavcodec/cbs_h264.c
index c86c6d565c..a128745799 100644
--- a/libavcodec/cbs_h264.c
+++ b/libavcodec/cbs_h264.c
@@ -16,6 +16,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/stereo3d.h"
+
 #include "cbs_h264.h"
 #include "cbs_internal.h"
 
@@ -106,3 +108,48 @@ void ff_cbs_h264_delete_sei_message(CodedBitstreamFragment 
*au,
 (sei->payload_count - position) * sizeof(*sei->payload));
 }
 }
+
+void 
ff_cbs_h264_fill_sei_frame_packing_arrangement(H264RawSEIFramePackingArrangement
 *fp,
+const AVStereo3D *st)
+{
+static const uint8_t type_map[] = {
+[AV_STEREO3D_2D]  = 6,
+[AV_STEREO3D_SIDEBYSIDE]  = 3,
+[AV_STEREO3D_TOPBOTTOM]   = 4,
+[AV_STEREO3D_FRAMESEQUENCE]   = 5,
+[AV_STEREO3D_CHECKERBOARD]= 0,
+[AV_STEREO3D_SIDEBYSIDE_QUINCUNX] = 3,
+[AV_STEREO3D_LINES]   = 2,
+[AV_STEREO3D_COLUMNS] = 1,
+};
+
+memset(fp, 0, sizeof(*fp));
+
+if (st->type >= FF_ARRAY_ELEMS(type_map))
+return;
+
+fp->frame_packing_arrangement_type = type_map[st->type];
+
+fp->quincunx_sampling_flag =
+st->type == AV_STEREO3D_CHECKERBOARD ||
+st->type == AV_STEREO3D_SIDEBYSIDE_QUINCUNX;
+
+if (st->type == AV_STEREO3D_2D)
+fp->content_interpretation_type = 0;
+else if (st->flags & AV_STEREO3D_FLAG_INVERT)
+fp->content_interpretation_type = 2;
+else
+fp->content_interpretation_type = 1;
+
+if (st->type == AV_STEREO3D_FRAMESEQUENCE) {
+if (st->flags & AV_STEREO3D_FLAG_INVERT)
+fp->current_frame_is_frame0_flag =
+st->view == AV_STEREO3D_VIEW_RIGHT;
+else
+fp->current_frame_is_frame0_flag =
+st->view == AV_STEREO3D_VIEW_LEFT;
+}
+
+fp->frame_packing_arrangement_repetition_period =
+st->type != AV_STEREO3D_FRAMESEQUENCE;
+}
diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h
index ca717a3b57..2f537564a7 100644
--- a/libavcodec/cbs_h264.h
+++ b/libavcodec/cbs_h264.h
@@ -523,4 +523,12 @@ void ff_cbs_h264_delete_sei_message(CodedBitstreamFragment 
*access_unit,
 CodedBitstreamUnit *nal_unit,
 int position);
 
+struct AVStereo3D;
+/**
+ * Fill an SEI Frame Packing Arrangement structure with values derived from
+ * the AVStereo3D side-data structure.
+ */
+void 
ff_cbs_h264_fill_sei_frame_packing_arrangement(H264RawSEIFramePackingArrangement
 *fp,
+const struct AVStereo3D 
*st);
+
 #endif /* AVCODEC_CBS_H264_H */
-- 
2.27.0

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

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

[FFmpeg-devel] [PATCH v6 14/22] cbs_h264: Simplify SEI addition

2020-07-27 Thread Mark Thompson
At the same time, move the H.264 SEI functions to a new file - the combined
H.26[45] CBS file is already very large, and these functions do not require
any of the common read/write elements.
---
 libavcodec/Makefile|   2 +-
 libavcodec/cbs_h264.c  | 108 +
 libavcodec/cbs_h264.h  |  11 +
 libavcodec/cbs_h2645.c |  94 +--
 4 files changed, 122 insertions(+), 93 deletions(-)
 create mode 100644 libavcodec/cbs_h264.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index c48138d0ad..6394694617 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -70,7 +70,7 @@ OBJS-$(CONFIG_BSWAPDSP)+= bswapdsp.o
 OBJS-$(CONFIG_CABAC)   += cabac.o
 OBJS-$(CONFIG_CBS) += cbs.o
 OBJS-$(CONFIG_CBS_AV1) += cbs_av1.o
-OBJS-$(CONFIG_CBS_H264)+= cbs_h2645.o h2645_parse.o
+OBJS-$(CONFIG_CBS_H264)+= cbs_h2645.o cbs_h264.o h2645_parse.o
 OBJS-$(CONFIG_CBS_H265)+= cbs_h2645.o h2645_parse.o
 OBJS-$(CONFIG_CBS_JPEG)+= cbs_jpeg.o
 OBJS-$(CONFIG_CBS_MPEG2)   += cbs_mpeg2.o
diff --git a/libavcodec/cbs_h264.c b/libavcodec/cbs_h264.c
new file mode 100644
index 00..c86c6d565c
--- /dev/null
+++ b/libavcodec/cbs_h264.c
@@ -0,0 +1,108 @@
+/*
+ * 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 "cbs_h264.h"
+#include "cbs_internal.h"
+
+int ff_cbs_h264_add_sei_message(CodedBitstreamFragment *au,
+H264RawSEIPayload *payload)
+{
+H264RawSEI *sei = NULL;
+int err, i;
+
+// Find an existing SEI NAL unit to add to.
+for (i = 0; i < au->nb_units; i++) {
+if (au->units[i].type == H264_NAL_SEI) {
+sei = au->units[i].content;
+if (sei->payload_count < H264_MAX_SEI_PAYLOADS)
+break;
+
+sei = NULL;
+}
+}
+
+if (!sei) {
+// Need to make a new SEI NAL unit.  Insert it before the first
+// slice data NAL unit; if no slice data, add at the end.
+CodedBitstreamUnit *unit;
+
+for (i = 0; i < au->nb_units; i++) {
+if (au->units[i].type == H264_NAL_SLICE ||
+au->units[i].type == H264_NAL_IDR_SLICE)
+break;
+}
+
+err = ff_cbs_insert_unit(au, i);
+if (err < 0)
+goto fail;
+unit = >units[i];
+
+// Needs a context for the type information but we don't have
+// one, so forge one containing only the type information.
+err = ff_cbs_alloc_unit_content2(&(CodedBitstreamContext) {
+   .codec = _cbs_type_h264 }, unit);
+if (err < 0) {
+ff_cbs_delete_unit(au, i);
+goto fail;
+}
+sei = unit->content;
+
+*sei = (H264RawSEI) {
+.nal_unit_header = {
+.nal_unit_type = H264_NAL_SEI,
+},
+};
+}
+
+memcpy(>payload[sei->payload_count], payload, sizeof(*payload));
+++sei->payload_count;
+
+return 0;
+fail:
+ff_cbs_h264_free_sei_payload(payload);
+return err;
+}
+
+void ff_cbs_h264_delete_sei_message(CodedBitstreamFragment *au,
+CodedBitstreamUnit *nal,
+int position)
+{
+H264RawSEI *sei = nal->content;
+
+av_assert0(nal->type == H264_NAL_SEI);
+av_assert0(position >= 0 && position < sei->payload_count);
+
+if (position == 0 && sei->payload_count == 1) {
+// Deleting NAL unit entirely.
+int i;
+
+for (i = 0; i < au->nb_units; i++) {
+if (>units[i] == nal)
+break;
+}
+
+ff_cbs_delete_unit(au, i);
+} else {
+ff_cbs_h264_free_sei_payload(>payload[position]);
+
+--sei->payload_count;
+memmove(sei->payload + position,
+sei->payload + position + 1,
+(sei->payload_count - position) * sizeof(*sei->payload));
+}
+}
diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h
index a6fe0a6af2..88313629f5 100644
--- a/libavcodec/cbs_h264.h
+++ b/libavcodec/cbs_h264.h
@@ -466,11 +466,22 @@ typedef 

[FFmpeg-devel] [PATCH v6 10/22] cbs_vp9: Use table-based alloc/free

2020-07-27 Thread Mark Thompson
---
 libavcodec/cbs_vp9.c | 17 -
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/libavcodec/cbs_vp9.c b/libavcodec/cbs_vp9.c
index 6e0a7dcbea..6a480b4ce3 100644
--- a/libavcodec/cbs_vp9.c
+++ b/libavcodec/cbs_vp9.c
@@ -479,13 +479,6 @@ static int cbs_vp9_split_fragment(CodedBitstreamContext 
*ctx,
 return 0;
 }
 
-static void cbs_vp9_free_frame(void *opaque, uint8_t *content)
-{
-VP9RawFrame *frame = (VP9RawFrame*)content;
-av_buffer_unref(>data_ref);
-av_freep();
-}
-
 static int cbs_vp9_read_unit(CodedBitstreamContext *ctx,
  CodedBitstreamUnit *unit)
 {
@@ -497,8 +490,7 @@ static int cbs_vp9_read_unit(CodedBitstreamContext *ctx,
 if (err < 0)
 return err;
 
-err = ff_cbs_alloc_unit_content(unit, sizeof(*frame),
-_vp9_free_frame);
+err = ff_cbs_alloc_unit_content2(ctx, unit);
 if (err < 0)
 return err;
 frame = unit->content;
@@ -642,11 +634,18 @@ static int 
cbs_vp9_assemble_fragment(CodedBitstreamContext *ctx,
 return 0;
 }
 
+static const CodedBitstreamUnitTypeDescriptor cbs_vp9_unit_types[] = {
+CBS_UNIT_TYPE_INTERNAL_REF(0, VP9RawFrame, data),
+CBS_UNIT_TYPE_END_OF_LIST
+};
+
 const CodedBitstreamType ff_cbs_type_vp9 = {
 .codec_id  = AV_CODEC_ID_VP9,
 
 .priv_data_size= sizeof(CodedBitstreamVP9Context),
 
+.unit_types= cbs_vp9_unit_types,
+
 .split_fragment= _vp9_split_fragment,
 .read_unit = _vp9_read_unit,
 .write_unit= _vp9_write_unit,
-- 
2.27.0

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

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

[FFmpeg-devel] [PATCH v6 11/22] cbs_av1: Use table-based alloc/free

2020-07-27 Thread Mark Thompson
---
 libavcodec/cbs_av1.c | 85 
 1 file changed, 39 insertions(+), 46 deletions(-)

diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c
index 75e9cb78df..dd2bc83bd4 100644
--- a/libavcodec/cbs_av1.c
+++ b/libavcodec/cbs_av1.c
@@ -809,50 +809,6 @@ fail:
 return err;
 }
 
-static void cbs_av1_free_tile_data(AV1RawTileData *td)
-{
-av_buffer_unref(>data_ref);
-}
-
-static void cbs_av1_free_padding(AV1RawPadding *pd)
-{
-av_buffer_unref(>payload_ref);
-}
-
-static void cbs_av1_free_metadata(AV1RawMetadata *md)
-{
-switch (md->metadata_type) {
-case AV1_METADATA_TYPE_ITUT_T35:
-av_buffer_unref(>metadata.itut_t35.payload_ref);
-break;
-}
-}
-
-static void cbs_av1_free_obu(void *opaque, uint8_t *content)
-{
-AV1RawOBU *obu = (AV1RawOBU*)content;
-
-switch (obu->header.obu_type) {
-case AV1_OBU_TILE_GROUP:
-cbs_av1_free_tile_data(>obu.tile_group.tile_data);
-break;
-case AV1_OBU_FRAME:
-cbs_av1_free_tile_data(>obu.frame.tile_group.tile_data);
-break;
-case AV1_OBU_TILE_LIST:
-cbs_av1_free_tile_data(>obu.tile_list.tile_data);
-break;
-case AV1_OBU_METADATA:
-cbs_av1_free_metadata(>obu.metadata);
-break;
-case AV1_OBU_PADDING:
-cbs_av1_free_padding(>obu.padding);
-break;
-}
-
-av_freep();
-}
-
 static int cbs_av1_ref_tile_data(CodedBitstreamContext *ctx,
  CodedBitstreamUnit *unit,
  GetBitContext *gbc,
@@ -887,8 +843,7 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx,
 GetBitContext gbc;
 int err, start_pos, end_pos;
 
-err = ff_cbs_alloc_unit_content(unit, sizeof(*obu),
-_av1_free_obu);
+err = ff_cbs_alloc_unit_content2(ctx, unit);
 if (err < 0)
 return err;
 obu = unit->content;
@@ -1253,11 +1208,49 @@ static void cbs_av1_close(CodedBitstreamContext *ctx)
 av_buffer_unref(>frame_header_ref);
 }
 
+static void cbs_av1_free_metadata(void *unit, uint8_t *content)
+{
+AV1RawOBU *obu = (AV1RawOBU*)content;
+AV1RawMetadata *md;
+
+av_assert0(obu->header.obu_type == AV1_OBU_METADATA);
+md = >obu.metadata;
+
+switch (md->metadata_type) {
+case AV1_METADATA_TYPE_ITUT_T35:
+av_buffer_unref(>metadata.itut_t35.payload_ref);
+break;
+}
+}
+
+static const CodedBitstreamUnitTypeDescriptor cbs_av1_unit_types[] = {
+CBS_UNIT_TYPE_POD(AV1_OBU_SEQUENCE_HEADER,AV1RawOBU),
+CBS_UNIT_TYPE_POD(AV1_OBU_TEMPORAL_DELIMITER, AV1RawOBU),
+CBS_UNIT_TYPE_POD(AV1_OBU_FRAME_HEADER,   AV1RawOBU),
+CBS_UNIT_TYPE_POD(AV1_OBU_REDUNDANT_FRAME_HEADER, AV1RawOBU),
+
+CBS_UNIT_TYPE_INTERNAL_REF(AV1_OBU_TILE_GROUP, AV1RawOBU,
+   obu.tile_group.tile_data.data),
+CBS_UNIT_TYPE_INTERNAL_REF(AV1_OBU_FRAME,  AV1RawOBU,
+   obu.frame.tile_group.tile_data.data),
+CBS_UNIT_TYPE_INTERNAL_REF(AV1_OBU_TILE_LIST,  AV1RawOBU,
+   obu.tile_list.tile_data.data),
+CBS_UNIT_TYPE_INTERNAL_REF(AV1_OBU_PADDING,AV1RawOBU,
+   obu.padding.payload),
+
+CBS_UNIT_TYPE_COMPLEX(AV1_OBU_METADATA, AV1RawOBU,
+  _av1_free_metadata),
+
+CBS_UNIT_TYPE_END_OF_LIST
+};
+
 const CodedBitstreamType ff_cbs_type_av1 = {
 .codec_id  = AV_CODEC_ID_AV1,
 
 .priv_data_size= sizeof(CodedBitstreamAV1Context),
 
+.unit_types= cbs_av1_unit_types,
+
 .split_fragment= _av1_split_fragment,
 .read_unit = _av1_read_unit,
 .write_unit= _av1_write_obu,
-- 
2.27.0

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

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

[FFmpeg-devel] [PATCH v6 06/22] cbs: Add support functions for handling unit content references

2020-07-27 Thread Mark Thompson
Use the unit type table to determine what we need to do to clone the
internals of the unit content when making copies for refcounting or
writeability.  (This will still fail for units with complex content
if they do not have a defined clone function.)

Setup and naming from a patch by Andreas Rheinhardt
, but with the implementation changed
to use the unit type information if possible rather than requiring a
codec-specific function.
---
 libavcodec/cbs.c  | 163 ++
 libavcodec/cbs.h  |  29 +++
 libavcodec/cbs_internal.h |   1 +
 3 files changed, 193 insertions(+)

diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index 61cf8e3466..7c1aa005c2 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -871,3 +871,166 @@ int ff_cbs_alloc_unit_content2(CodedBitstreamContext *ctx,
 
 return 0;
 }
+
+static int cbs_clone_unit_content(AVBufferRef **clone_ref,
+  CodedBitstreamUnit *unit,
+  const CodedBitstreamUnitTypeDescriptor *desc)
+{
+uint8_t *src, *copy;
+uint8_t **src_ptr, **copy_ptr;
+AVBufferRef **src_buf, **copy_buf;
+int err, i;
+
+av_assert0(unit->content);
+src = unit->content;
+
+copy = av_memdup(src, desc->content_size);
+if (!copy)
+return AVERROR(ENOMEM);
+
+for (i = 0; i < desc->nb_ref_offsets; i++) {
+src_ptr  = (uint8_t**)(src + desc->ref_offsets[i]);
+src_buf  = (AVBufferRef**)(src_ptr + 1);
+copy_ptr = (uint8_t**)(copy + desc->ref_offsets[i]);
+copy_buf = (AVBufferRef**)(copy_ptr + 1);
+
+if (!*src_ptr) {
+av_assert0(!*src_buf);
+continue;
+}
+if (!*src_buf) {
+// We can't handle a non-refcounted pointer here - we don't
+// have enough information to handle whatever structure lies
+// at the other end of it.
+err = AVERROR(EINVAL);
+goto fail;
+}
+
+// src_ptr is required to point somewhere inside src_buf.  If it
+// doesn't, there is a bug somewhere.
+av_assert0(*src_ptr >= (*src_buf)->data &&
+   *src_ptr <  (*src_buf)->data + (*src_buf)->size);
+
+*copy_buf = av_buffer_ref(*src_buf);
+if (!*copy_buf) {
+err = AVERROR(ENOMEM);
+goto fail;
+}
+*copy_ptr = (*copy_buf)->data + (*src_ptr - (*src_buf)->data);
+}
+
+*clone_ref = av_buffer_create(copy, desc->content_size,
+  desc->content_free ? desc->content_free :
+  cbs_default_free_unit_content,
+  (void*)desc, 0);
+if (!*clone_ref) {
+err = AVERROR(ENOMEM);
+goto fail;
+}
+
+return 0;
+
+fail:
+for (--i; i >= 0; i--)
+av_buffer_unref((AVBufferRef**)(copy + desc->ref_offsets[i]));
+av_freep();
+*clone_ref = NULL;
+return err;
+}
+
+int ff_cbs_make_unit_refcounted(CodedBitstreamContext *ctx,
+CodedBitstreamUnit *unit)
+{
+const CodedBitstreamUnitTypeDescriptor *desc;
+AVBufferRef *ref;
+int err;
+
+av_assert0(unit->content);
+if (unit->content_ref) {
+// Already refcounted, nothing to do.
+return 0;
+}
+
+desc = cbs_find_unit_type_desc(ctx, unit);
+if (!desc)
+return AVERROR(ENOSYS);
+
+switch (desc->content_type) {
+case CBS_CONTENT_TYPE_POD:
+ref = av_buffer_alloc(desc->content_size);
+if (!ref)
+return AVERROR(ENOMEM);
+memcpy(ref->data, unit->content, desc->content_size);
+err = 0;
+break;
+
+case CBS_CONTENT_TYPE_INTERNAL_REFS:
+err = cbs_clone_unit_content(, unit, desc);
+break;
+
+case CBS_CONTENT_TYPE_COMPLEX:
+if (!desc->content_clone)
+return AVERROR_PATCHWELCOME;
+err = desc->content_clone(, unit);
+break;
+
+default:
+av_assert0(0 && "Invalid content type.");
+}
+
+if (err < 0)
+return err;
+
+unit->content_ref = ref;
+unit->content = ref->data;
+return 0;
+}
+
+int ff_cbs_make_unit_writable(CodedBitstreamContext *ctx,
+  CodedBitstreamUnit *unit)
+{
+const CodedBitstreamUnitTypeDescriptor *desc;
+AVBufferRef *ref;
+int err;
+
+// This can only be applied to refcounted units.
+err = ff_cbs_make_unit_refcounted(ctx, unit);
+if (err < 0)
+return err;
+av_assert0(unit->content && unit->content_ref);
+
+if (av_buffer_is_writable(unit->content_ref))
+return 0;
+
+desc = cbs_find_unit_type_desc(ctx, unit);
+if (!desc)
+return AVERROR(ENOSYS);
+
+switch (desc->content_type) {
+case CBS_CONTENT_TYPE_POD:
+err = av_buffer_make_writable(>content_ref);
+break;
+
+case CBS_CONTENT_TYPE_INTERNAL_REFS:
+err = 

[FFmpeg-devel] [PATCH v6 12/22] cbs_mpeg2: Use table-based alloc/free

2020-07-27 Thread Mark Thompson
---
 libavcodec/cbs_mpeg2.c | 70 +-
 1 file changed, 35 insertions(+), 35 deletions(-)

diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
index 8b6e5a9852..26400f279f 100644
--- a/libavcodec/cbs_mpeg2.c
+++ b/libavcodec/cbs_mpeg2.c
@@ -140,28 +140,6 @@
 #undef infer
 
 
-static void cbs_mpeg2_free_picture_header(void *opaque, uint8_t *content)
-{
-MPEG2RawPictureHeader *picture = (MPEG2RawPictureHeader*)content;
-av_buffer_unref(>extra_information_picture.extra_information_ref);
-av_freep();
-}
-
-static void cbs_mpeg2_free_user_data(void *opaque, uint8_t *content)
-{
-MPEG2RawUserData *user = (MPEG2RawUserData*)content;
-av_buffer_unref(>user_data_ref);
-av_freep();
-}
-
-static void cbs_mpeg2_free_slice(void *opaque, uint8_t *content)
-{
-MPEG2RawSlice *slice = (MPEG2RawSlice*)content;
-
av_buffer_unref(>header.extra_information_slice.extra_information_ref);
-av_buffer_unref(>data_ref);
-av_freep();
-}
-
 static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx,
 CodedBitstreamFragment *frag,
 int header)
@@ -231,16 +209,14 @@ static int cbs_mpeg2_read_unit(CodedBitstreamContext *ctx,
 if (err < 0)
 return err;
 
+err = ff_cbs_alloc_unit_content2(ctx, unit);
+if (err < 0)
+return err;
+
 if (MPEG2_START_IS_SLICE(unit->type)) {
-MPEG2RawSlice *slice;
+MPEG2RawSlice *slice = unit->content;
 int pos, len;
 
-err = ff_cbs_alloc_unit_content(unit, sizeof(*slice),
-_mpeg2_free_slice);
-if (err < 0)
-return err;
-slice = unit->content;
-
 err = cbs_mpeg2_read_slice_header(ctx, , >header);
 if (err < 0)
 return err;
@@ -264,12 +240,7 @@ static int cbs_mpeg2_read_unit(CodedBitstreamContext *ctx,
 #define START(start_code, type, read_func, free_func) \
 case start_code: \
 { \
-type *header; \
-err = ff_cbs_alloc_unit_content(unit, \
-sizeof(*header), free_func); \
-if (err < 0) \
-return err; \
-header = unit->content; \
+type *header = unit->content; \
 err = cbs_mpeg2_read_ ## read_func(ctx, , header); \
 if (err < 0) \
 return err; \
@@ -420,11 +391,40 @@ static int 
cbs_mpeg2_assemble_fragment(CodedBitstreamContext *ctx,
 return 0;
 }
 
+static const CodedBitstreamUnitTypeDescriptor cbs_mpeg2_unit_types[] = {
+CBS_UNIT_TYPE_INTERNAL_REF(MPEG2_START_PICTURE, MPEG2RawPictureHeader,
+   extra_information_picture.extra_information),
+
+{
+.nb_unit_types = CBS_UNIT_TYPE_RANGE,
+.unit_type_range_start = 0x01,
+.unit_type_range_end   = 0xaf,
+
+.content_type   = CBS_CONTENT_TYPE_INTERNAL_REFS,
+.content_size   = sizeof(MPEG2RawSlice),
+.nb_ref_offsets = 2,
+.ref_offsets= { offsetof(MPEG2RawSlice, 
header.extra_information_slice.extra_information),
+offsetof(MPEG2RawSlice, data) },
+},
+
+CBS_UNIT_TYPE_INTERNAL_REF(MPEG2_START_USER_DATA, MPEG2RawUserData,
+   user_data),
+
+CBS_UNIT_TYPE_POD(MPEG2_START_SEQUENCE_HEADER, MPEG2RawSequenceHeader),
+CBS_UNIT_TYPE_POD(MPEG2_START_EXTENSION,   MPEG2RawExtensionData),
+CBS_UNIT_TYPE_POD(MPEG2_START_SEQUENCE_END,MPEG2RawSequenceEnd),
+CBS_UNIT_TYPE_POD(MPEG2_START_GROUP,   
MPEG2RawGroupOfPicturesHeader),
+
+CBS_UNIT_TYPE_END_OF_LIST
+};
+
 const CodedBitstreamType ff_cbs_type_mpeg2 = {
 .codec_id  = AV_CODEC_ID_MPEG2VIDEO,
 
 .priv_data_size= sizeof(CodedBitstreamMPEG2Context),
 
+.unit_types= cbs_mpeg2_unit_types,
+
 .split_fragment= _mpeg2_split_fragment,
 .read_unit = _mpeg2_read_unit,
 .write_unit= _mpeg2_write_unit,
-- 
2.27.0

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

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

[FFmpeg-devel] [PATCH v6 07/22] cbs_h2645: Ensure that non-refcounted parameter sets are fully copied

2020-07-27 Thread Mark Thompson
Only copying the main structure is not necessarily sufficient - there
could be references to substructures.
---
 libavcodec/cbs_h2645.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 5725539e60..e19fa5249d 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -720,18 +720,20 @@ static int cbs_h26 ## h26n ## _replace_ ## 
ps_var(CodedBitstreamContext *ctx, \
 CodedBitstreamH26 ## h26n ## Context *priv = ctx->priv_data; \
 H26 ## h26n ## Raw ## ps_name *ps_var = unit->content; \
 unsigned int id = ps_var->id_element; \
+int err; \
 if (id >= FF_ARRAY_ELEMS(priv->ps_var)) { \
 av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid " #ps_name \
" id : %d.\n", id); \
 return AVERROR_INVALIDDATA; \
 } \
+err = ff_cbs_make_unit_refcounted(ctx, unit); \
+if (err < 0) \
+return err; \
 if (priv->ps_var[id] == priv->active_ ## ps_var) \
 priv->active_ ## ps_var = NULL ; \
 av_buffer_unref(>ps_var ## _ref[id]); \
-if (unit->content_ref) \
-priv->ps_var ## _ref[id] = av_buffer_ref(unit->content_ref); \
-else \
-priv->ps_var ## _ref[id] = av_buffer_alloc(sizeof(*ps_var)); \
+av_assert0(unit->content_ref); \
+priv->ps_var ## _ref[id] = av_buffer_ref(unit->content_ref); \
 if (!priv->ps_var ## _ref[id]) \
 return AVERROR(ENOMEM); \
 priv->ps_var[id] = (H26 ## h26n ## Raw ## ps_name *)priv->ps_var ## 
_ref[id]->data; \
-- 
2.27.0

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

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

[FFmpeg-devel] [PATCH v6 08/22] h264_redundant_pps: Make it reference-compatible

2020-07-27 Thread Mark Thompson
From: Andreas Rheinhardt 

Since c6a63e11092c975b89d824f08682fe31948d3686, the parameter sets
modified as content of PPS units were references shared with the
CodedBitstreamH264Context, so modifying them alters the parsing process
of future access units which meant that frames often got discarded
because invalid values were parsed. This patch makes h264_redundant_pps
compatible with the reality of reference-counted parameter sets.

Fixes #7807.

Signed-off-by: Andreas Rheinhardt 
Signed-off-by: Mark Thompson 
---
 libavcodec/h264_redundant_pps_bsf.c | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/libavcodec/h264_redundant_pps_bsf.c 
b/libavcodec/h264_redundant_pps_bsf.c
index a8af4105cf..cf41abe96c 100644
--- a/libavcodec/h264_redundant_pps_bsf.c
+++ b/libavcodec/h264_redundant_pps_bsf.c
@@ -41,8 +41,19 @@ typedef struct H264RedundantPPSContext {
 
 
 static int h264_redundant_pps_fixup_pps(H264RedundantPPSContext *ctx,
-H264RawPPS *pps)
+CodedBitstreamUnit *unit)
 {
+H264RawPPS *pps;
+int err;
+
+// The changes we are about to perform affect the parsing process,
+// so we must make sure that the PPS is writable, otherwise the
+// parsing of future slices will be incorrect and even raise errors.
+err = ff_cbs_make_unit_writable(ctx->input, unit);
+if (err < 0)
+return err;
+pps = unit->content;
+
 // Record the current value of pic_init_qp in order to fix up
 // following slices, then overwrite with the global value.
 ctx->current_pic_init_qp = pps->pic_init_qp_minus26 + 26;
@@ -89,7 +100,7 @@ static int h264_redundant_pps_filter(AVBSFContext *bsf, 
AVPacket *pkt)
 if (nal->type == H264_NAL_SPS)
 au_has_sps = 1;
 if (nal->type == H264_NAL_PPS) {
-err = h264_redundant_pps_fixup_pps(ctx, nal->content);
+err = h264_redundant_pps_fixup_pps(ctx, nal);
 if (err < 0)
 goto fail;
 if (!au_has_sps) {
@@ -145,7 +156,7 @@ static int h264_redundant_pps_init(AVBSFContext *bsf)
 
 for (i = 0; i < au->nb_units; i++) {
 if (au->units[i].type == H264_NAL_PPS) {
-err = h264_redundant_pps_fixup_pps(ctx, au->units[i].content);
+err = h264_redundant_pps_fixup_pps(ctx, >units[i]);
 if (err < 0)
 goto fail;
 }
-- 
2.27.0

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

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

[FFmpeg-devel] [PATCH v6 09/22] cbs_h265: Use table-based alloc/free

2020-07-27 Thread Mark Thompson
---
 libavcodec/cbs_h2645.c | 198 +++--
 1 file changed, 93 insertions(+), 105 deletions(-)

diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index e19fa5249d..b9233f4df7 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -454,72 +454,6 @@ static int cbs_h2645_read_more_rbsp_data(GetBitContext 
*gbc)
 #undef allocate
 
 
-static void cbs_h265_free_vps(void *opaque, uint8_t *content)
-{
-H265RawVPS *vps = (H265RawVPS*)content;
-av_buffer_unref(>extension_data.data_ref);
-av_freep();
-}
-
-static void cbs_h265_free_sps(void *opaque, uint8_t *content)
-{
-H265RawSPS *sps = (H265RawSPS*)content;
-av_buffer_unref(>extension_data.data_ref);
-av_freep();
-}
-
-static void cbs_h265_free_pps(void *opaque, uint8_t *content)
-{
-H265RawPPS *pps = (H265RawPPS*)content;
-av_buffer_unref(>extension_data.data_ref);
-av_freep();
-}
-
-static void cbs_h265_free_slice(void *opaque, uint8_t *content)
-{
-H265RawSlice *slice = (H265RawSlice*)content;
-av_buffer_unref(>data_ref);
-av_freep();
-}
-
-static void cbs_h265_free_sei_payload(H265RawSEIPayload *payload)
-{
-switch (payload->payload_type) {
-case HEVC_SEI_TYPE_BUFFERING_PERIOD:
-case HEVC_SEI_TYPE_PICTURE_TIMING:
-case HEVC_SEI_TYPE_PAN_SCAN_RECT:
-case HEVC_SEI_TYPE_RECOVERY_POINT:
-case HEVC_SEI_TYPE_DISPLAY_ORIENTATION:
-case HEVC_SEI_TYPE_ACTIVE_PARAMETER_SETS:
-case HEVC_SEI_TYPE_DECODED_PICTURE_HASH:
-case HEVC_SEI_TYPE_TIME_CODE:
-case HEVC_SEI_TYPE_MASTERING_DISPLAY_INFO:
-case HEVC_SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO:
-case HEVC_SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS:
-case HEVC_SEI_TYPE_ALPHA_CHANNEL_INFO:
-break;
-case HEVC_SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35:
-av_buffer_unref(>payload.user_data_registered.data_ref);
-break;
-case HEVC_SEI_TYPE_USER_DATA_UNREGISTERED:
-av_buffer_unref(>payload.user_data_unregistered.data_ref);
-break;
-default:
-av_buffer_unref(>payload.other.data_ref);
-break;
-}
-av_buffer_unref(>extension_data.data_ref);
-}
-
-static void cbs_h265_free_sei(void *opaque, uint8_t *content)
-{
-H265RawSEI *sei = (H265RawSEI*)content;
-int i;
-for (i = 0; i < sei->payload_count; i++)
-cbs_h265_free_sei_payload(>payload[i]);
-av_freep();
-}
-
 static int cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx,
CodedBitstreamFragment *frag,
const H2645Packet *packet)
@@ -877,16 +811,14 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
*ctx,
 if (err < 0)
 return err;
 
+err = ff_cbs_alloc_unit_content2(ctx, unit);
+if (err < 0)
+return err;
+
 switch (unit->type) {
 case HEVC_NAL_VPS:
 {
-H265RawVPS *vps;
-
-err = ff_cbs_alloc_unit_content(unit, sizeof(*vps),
-_h265_free_vps);
-if (err < 0)
-return err;
-vps = unit->content;
+H265RawVPS *vps = unit->content;
 
 err = cbs_h265_read_vps(ctx, , vps);
 if (err < 0)
@@ -899,13 +831,7 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
*ctx,
 break;
 case HEVC_NAL_SPS:
 {
-H265RawSPS *sps;
-
-err = ff_cbs_alloc_unit_content(unit, sizeof(*sps),
-_h265_free_sps);
-if (err < 0)
-return err;
-sps = unit->content;
+H265RawSPS *sps = unit->content;
 
 err = cbs_h265_read_sps(ctx, , sps);
 if (err < 0)
@@ -919,13 +845,7 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
*ctx,
 
 case HEVC_NAL_PPS:
 {
-H265RawPPS *pps;
-
-err = ff_cbs_alloc_unit_content(unit, sizeof(*pps),
-_h265_free_pps);
-if (err < 0)
-return err;
-pps = unit->content;
+H265RawPPS *pps = unit->content;
 
 err = cbs_h265_read_pps(ctx, , pps);
 if (err < 0)
@@ -954,15 +874,9 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
*ctx,
 case HEVC_NAL_IDR_N_LP:
 case HEVC_NAL_CRA_NUT:
 {
-H265RawSlice *slice;
+H265RawSlice *slice = unit->content;
 int pos, len;
 
-err = ff_cbs_alloc_unit_content(unit, sizeof(*slice),
-_h265_free_slice);
-if (err < 0)
-return err;
-slice = unit->content;
-
 err = cbs_h265_read_slice_segment_header(ctx, , 
>header);
 if (err < 0)
 return err;
@@ -984,11 +898,6 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
*ctx,
 
 case 

[FFmpeg-devel] [PATCH v6 05/22] cbs_h264: Use table-based alloc/free

2020-07-27 Thread Mark Thompson
---
 libavcodec/cbs_h2645.c | 163 ++---
 1 file changed, 70 insertions(+), 93 deletions(-)

diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index e5c8012d39..5725539e60 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -454,52 +454,6 @@ static int cbs_h2645_read_more_rbsp_data(GetBitContext 
*gbc)
 #undef allocate
 
 
-static void cbs_h264_free_pps(void *opaque, uint8_t *content)
-{
-H264RawPPS *pps = (H264RawPPS*)content;
-av_buffer_unref(>slice_group_id_ref);
-av_freep();
-}
-
-static void cbs_h264_free_sei_payload(H264RawSEIPayload *payload)
-{
-switch (payload->payload_type) {
-case H264_SEI_TYPE_BUFFERING_PERIOD:
-case H264_SEI_TYPE_PIC_TIMING:
-case H264_SEI_TYPE_PAN_SCAN_RECT:
-case H264_SEI_TYPE_RECOVERY_POINT:
-case H264_SEI_TYPE_DISPLAY_ORIENTATION:
-case H264_SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME:
-case H264_SEI_TYPE_ALTERNATIVE_TRANSFER:
-break;
-case H264_SEI_TYPE_USER_DATA_REGISTERED:
-av_buffer_unref(>payload.user_data_registered.data_ref);
-break;
-case H264_SEI_TYPE_USER_DATA_UNREGISTERED:
-av_buffer_unref(>payload.user_data_unregistered.data_ref);
-break;
-default:
-av_buffer_unref(>payload.other.data_ref);
-break;
-}
-}
-
-static void cbs_h264_free_sei(void *opaque, uint8_t *content)
-{
-H264RawSEI *sei = (H264RawSEI*)content;
-int i;
-for (i = 0; i < sei->payload_count; i++)
-cbs_h264_free_sei_payload(>payload[i]);
-av_freep();
-}
-
-static void cbs_h264_free_slice(void *opaque, uint8_t *content)
-{
-H264RawSlice *slice = (H264RawSlice*)content;
-av_buffer_unref(>data_ref);
-av_freep();
-}
-
 static void cbs_h265_free_vps(void *opaque, uint8_t *content)
 {
 H265RawVPS *vps = (H265RawVPS*)content;
@@ -802,15 +756,14 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext 
*ctx,
 if (err < 0)
 return err;
 
+err = ff_cbs_alloc_unit_content2(ctx, unit);
+if (err < 0)
+return err;
+
 switch (unit->type) {
 case H264_NAL_SPS:
 {
-H264RawSPS *sps;
-
-err = ff_cbs_alloc_unit_content(unit, sizeof(*sps), NULL);
-if (err < 0)
-return err;
-sps = unit->content;
+H264RawSPS *sps = unit->content;
 
 err = cbs_h264_read_sps(ctx, , sps);
 if (err < 0)
@@ -824,12 +777,6 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext 
*ctx,
 
 case H264_NAL_SPS_EXT:
 {
-err = ff_cbs_alloc_unit_content(unit,
-sizeof(H264RawSPSExtension),
-NULL);
-if (err < 0)
-return err;
-
 err = cbs_h264_read_sps_extension(ctx, , unit->content);
 if (err < 0)
 return err;
@@ -838,13 +785,7 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext 
*ctx,
 
 case H264_NAL_PPS:
 {
-H264RawPPS *pps;
-
-err = ff_cbs_alloc_unit_content(unit, sizeof(*pps),
-_h264_free_pps);
-if (err < 0)
-return err;
-pps = unit->content;
+H264RawPPS *pps = unit->content;
 
 err = cbs_h264_read_pps(ctx, , pps);
 if (err < 0)
@@ -860,15 +801,9 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext 
*ctx,
 case H264_NAL_IDR_SLICE:
 case H264_NAL_AUXILIARY_SLICE:
 {
-H264RawSlice *slice;
+H264RawSlice *slice = unit->content;
 int pos, len;
 
-err = ff_cbs_alloc_unit_content(unit, sizeof(*slice),
-_h264_free_slice);
-if (err < 0)
-return err;
-slice = unit->content;
-
 err = cbs_h264_read_slice_header(ctx, , >header);
 if (err < 0)
 return err;
@@ -890,11 +825,6 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext 
*ctx,
 
 case H264_NAL_AUD:
 {
-err = ff_cbs_alloc_unit_content(unit,
-sizeof(H264RawAUD), NULL);
-if (err < 0)
-return err;
-
 err = cbs_h264_read_aud(ctx, , unit->content);
 if (err < 0)
 return err;
@@ -903,11 +833,6 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext 
*ctx,
 
 case H264_NAL_SEI:
 {
-err = ff_cbs_alloc_unit_content(unit, sizeof(H264RawSEI),
-_h264_free_sei);
-if (err < 0)
-return err;
-
 err = cbs_h264_read_sei(ctx, , unit->content);
 if (err < 0)
 return err;
@@ -916,11 +841,6 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext 
*ctx,
 
 case 

[FFmpeg-devel] [PATCH v6 04/22] cbs: Add macros to support defining unit type tables

2020-07-27 Thread Mark Thompson
---
 libavcodec/cbs_internal.h | 24 
 1 file changed, 24 insertions(+)

diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h
index 282492bc88..35159f9c5f 100644
--- a/libavcodec/cbs_internal.h
+++ b/libavcodec/cbs_internal.h
@@ -167,6 +167,30 @@ int ff_cbs_write_signed(CodedBitstreamContext *ctx, 
PutBitContext *pbc,
 #define MIN_INT_BITS(length) (-(INT64_C(1) << ((length) - 1)))
 
 
+#define CBS_UNIT_TYPE_POD(type, structure) { \
+.nb_unit_types  = 1, \
+.unit_types = { type }, \
+.content_type   = CBS_CONTENT_TYPE_POD, \
+.content_size   = sizeof(structure), \
+}
+#define CBS_UNIT_TYPE_INTERNAL_REF(type, structure, ref_field) { \
+.nb_unit_types  = 1, \
+.unit_types = { type }, \
+.content_type   = CBS_CONTENT_TYPE_INTERNAL_REFS, \
+.content_size   = sizeof(structure), \
+.nb_ref_offsets = 1, \
+.ref_offsets= { offsetof(structure, ref_field) }, \
+}
+#define CBS_UNIT_TYPE_COMPLEX(type, structure, free_func) { \
+.nb_unit_types  = 1, \
+.unit_types = { type }, \
+.content_type   = CBS_CONTENT_TYPE_COMPLEX, \
+.content_size   = sizeof(structure), \
+.content_free   = free_func, \
+}
+#define CBS_UNIT_TYPE_END_OF_LIST { .nb_unit_types = 0 }
+
+
 extern const CodedBitstreamType ff_cbs_type_av1;
 extern const CodedBitstreamType ff_cbs_type_h264;
 extern const CodedBitstreamType ff_cbs_type_h265;
-- 
2.27.0

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

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

[FFmpeg-devel] [PATCH v6 02/22] cbs: Ensure that reference fields always follow the associated pointer

2020-07-27 Thread Mark Thompson
Having these together allows us to find both pointers given the address
of only one of them.
---
 libavcodec/cbs_av1.h   |  6 +++---
 libavcodec/cbs_h264.h  | 18 +-
 libavcodec/cbs_h265.h  | 16 
 libavcodec/cbs_jpeg.h  |  2 +-
 libavcodec/cbs_mpeg2.h | 10 +-
 libavcodec/cbs_vp9.h   |  2 +-
 6 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/libavcodec/cbs_av1.h b/libavcodec/cbs_av1.h
index f5fed220a5..85ff628008 100644
--- a/libavcodec/cbs_av1.h
+++ b/libavcodec/cbs_av1.h
@@ -284,8 +284,8 @@ typedef struct AV1RawFrameHeader {
 
 typedef struct AV1RawTileData {
 uint8_t *data;
-size_t   data_size;
 AVBufferRef *data_ref;
+size_t   data_size;
 } AV1RawTileData;
 
 typedef struct AV1RawTileGroup {
@@ -346,8 +346,8 @@ typedef struct AV1RawMetadataITUTT35 {
 uint8_t itu_t_t35_country_code_extension_byte;
 
 uint8_t *payload;
-size_t   payload_size;
 AVBufferRef *payload_ref;
+size_t   payload_size;
 } AV1RawMetadataITUTT35;
 
 typedef struct AV1RawMetadataTimecode {
@@ -379,8 +379,8 @@ typedef struct AV1RawMetadata {
 
 typedef struct AV1RawPadding {
 uint8_t *payload;
-size_t   payload_size;
 AVBufferRef *payload_ref;
+size_t   payload_size;
 } AV1RawPadding;
 
 
diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h
index f54ccd3b36..a6fe0a6af2 100644
--- a/libavcodec/cbs_h264.h
+++ b/libavcodec/cbs_h264.h
@@ -277,16 +277,16 @@ typedef struct H264RawSEIPanScanRect {
 typedef struct H264RawSEIUserDataRegistered {
 uint8_t itu_t_t35_country_code;
 uint8_t itu_t_t35_country_code_extension_byte;
-uint8_t *data;
-size_t data_length;
+uint8_t *data;
 AVBufferRef *data_ref;
+size_t   data_length;
 } H264RawSEIUserDataRegistered;
 
 typedef struct H264RawSEIUserDataUnregistered {
 uint8_t uuid_iso_iec_11578[16];
-uint8_t *data;
-size_t data_length;
+uint8_t *data;
 AVBufferRef *data_ref;
+size_t   data_length;
 } H264RawSEIUserDataUnregistered;
 
 typedef struct H264RawSEIRecoveryPoint {
@@ -334,9 +334,9 @@ typedef struct H264RawSEIPayload {
 H264RawSEIAlternativeTransferCharacteristics
 alternative_transfer_characteristics;
 struct {
-uint8_t *data;
-size_t data_length;
+uint8_t *data;
 AVBufferRef *data_ref;
+size_t   data_length;
 } other;
 } payload;
 } H264RawSEIPayload;
@@ -429,10 +429,10 @@ typedef struct H264RawSliceHeader {
 typedef struct H264RawSlice {
 H264RawSliceHeader header;
 
-uint8_t *data;
-size_t   data_size;
-int  data_bit_start;
+uint8_t *data;
 AVBufferRef *data_ref;
+size_t   data_size;
+int  data_bit_start;
 } H264RawSlice;
 
 typedef struct H264RawFiller {
diff --git a/libavcodec/cbs_h265.h b/libavcodec/cbs_h265.h
index 73897f77a4..c14cd4cd66 100644
--- a/libavcodec/cbs_h265.h
+++ b/libavcodec/cbs_h265.h
@@ -184,8 +184,8 @@ typedef struct H265RawVUI {
 
 typedef struct H265RawExtensionData {
 uint8_t *data;
-size_t bit_length;
 AVBufferRef *data_ref;
+size_t bit_length;
 } H265RawExtensionData;
 
 typedef struct H265RawVPS {
@@ -541,10 +541,10 @@ typedef struct  H265RawSliceHeader {
 typedef struct H265RawSlice {
 H265RawSliceHeader header;
 
-uint8_t *data;
-size_t   data_size;
-int  data_bit_start;
+uint8_t *data;
 AVBufferRef *data_ref;
+size_t   data_size;
+int  data_bit_start;
 } H265RawSlice;
 
 
@@ -600,15 +600,15 @@ typedef struct H265RawSEIUserDataRegistered {
 uint8_t itu_t_t35_country_code;
 uint8_t itu_t_t35_country_code_extension_byte;
 uint8_t *data;
-size_t   data_length;
 AVBufferRef *data_ref;
+size_t   data_length;
 } H265RawSEIUserDataRegistered;
 
 typedef struct H265RawSEIUserDataUnregistered {
 uint8_t uuid_iso_iec_11578[16];
 uint8_t *data;
-size_t   data_length;
 AVBufferRef *data_ref;
+size_t   data_length;
 } H265RawSEIUserDataUnregistered;
 
 typedef struct H265RawSEIRecoveryPoint {
@@ -710,9 +710,9 @@ typedef struct H265RawSEIPayload {
 alternative_transfer_characteristics;
 H265RawSEIAlphaChannelInfo alpha_channel_info;
 struct {
-uint8_t *data;
-size_t data_length;
+uint8_t *data;
 AVBufferRef *data_ref;
+size_t   data_length;
 } other;
 } payload;
 H265RawExtensionData extension_data;
diff --git a/libavcodec/cbs_jpeg.h b/libavcodec/cbs_jpeg.h
index ff1961106f..6305f0ee86 100644
--- a/libavcodec/cbs_jpeg.h
+++ b/libavcodec/cbs_jpeg.h
@@ -80,8 +80,8 @@ typedef struct JPEGRawScanHeader {
 typedef struct JPEGRawScan {
 JPEGRawScanHeader header;
 uint8_t  *data;
-size_tdata_size;
 AVBufferRef  *data_ref;
+size_t 

[FFmpeg-devel] [PATCH v6 03/22] cbs: Describe allocate/free methods in tabular form

2020-07-27 Thread Mark Thompson
Unit types are split into three categories, depending on how their
content is managed:
* POD structure - these require no special treatment.
* Structure containing references to refcounted buffers - these can use
  a common free function when the offsets of all the internal references
  are known.
* More complex structures - these still require ad-hoc treatment.

For each codec we can then maintain a table of descriptors for each set of
equivalent unit types, defining the mechanism needed to allocate/free that
unit content.  This is not required to be used immediately - a new alloc
function supports this, but does not replace the old one which works without
referring to these tables.
---
 libavcodec/cbs.c  | 69 +++
 libavcodec/cbs.h  |  9 +
 libavcodec/cbs_internal.h | 61 ++
 3 files changed, 139 insertions(+)

diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index 6464980c8e..61cf8e3466 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -802,3 +802,72 @@ void ff_cbs_delete_unit(CodedBitstreamFragment *frag,
 frag->units + position + 1,
 (frag->nb_units - position) * sizeof(*frag->units));
 }
+
+static void cbs_default_free_unit_content(void *opaque, uint8_t *data)
+{
+const CodedBitstreamUnitTypeDescriptor *desc = opaque;
+if (desc->content_type == CBS_CONTENT_TYPE_INTERNAL_REFS) {
+int i;
+for (i = 0; i < desc->nb_ref_offsets; i++) {
+void **ptr = (void**)(data + desc->ref_offsets[i]);
+av_buffer_unref((AVBufferRef**)(ptr + 1));
+}
+}
+av_free(data);
+}
+
+static const CodedBitstreamUnitTypeDescriptor
+*cbs_find_unit_type_desc(CodedBitstreamContext *ctx,
+ CodedBitstreamUnit *unit)
+{
+const CodedBitstreamUnitTypeDescriptor *desc;
+int i, j;
+
+if (!ctx->codec->unit_types)
+return NULL;
+
+for (i = 0;; i++) {
+desc = >codec->unit_types[i];
+if (desc->nb_unit_types == 0)
+break;
+if (desc->nb_unit_types == CBS_UNIT_TYPE_RANGE) {
+if (unit->type >= desc->unit_type_range_start &&
+unit->type <= desc->unit_type_range_end)
+return desc;
+} else {
+for (j = 0; j < desc->nb_unit_types; j++) {
+if (desc->unit_types[j] == unit->type)
+return desc;
+}
+}
+}
+return NULL;
+}
+
+int ff_cbs_alloc_unit_content2(CodedBitstreamContext *ctx,
+   CodedBitstreamUnit *unit)
+{
+const CodedBitstreamUnitTypeDescriptor *desc;
+
+av_assert0(!unit->content && !unit->content_ref);
+
+desc = cbs_find_unit_type_desc(ctx, unit);
+if (!desc)
+return AVERROR(ENOSYS);
+
+unit->content = av_mallocz(desc->content_size);
+if (!unit->content)
+return AVERROR(ENOMEM);
+
+unit->content_ref =
+av_buffer_create(unit->content, desc->content_size,
+ desc->content_free ? desc->content_free
+: cbs_default_free_unit_content,
+ (void*)desc, 0);
+if (!unit->content_ref) {
+av_freep(>content);
+return AVERROR(ENOMEM);
+}
+
+return 0;
+}
diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h
index 07faf18c5b..ea8d942894 100644
--- a/libavcodec/cbs.h
+++ b/libavcodec/cbs.h
@@ -349,6 +349,15 @@ int ff_cbs_alloc_unit_content(CodedBitstreamUnit *unit,
   size_t size,
   void (*free)(void *opaque, uint8_t *content));
 
+/**
+ * Allocate a new internal content buffer matching the type of the unit.
+ *
+ * The content will be zeroed.
+ */
+int ff_cbs_alloc_unit_content2(CodedBitstreamContext *ctx,
+   CodedBitstreamUnit *unit);
+
+
 /**
  * Allocate a new internal data buffer of the given size in the unit.
  *
diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h
index 4c5a535ca6..282492bc88 100644
--- a/libavcodec/cbs_internal.h
+++ b/libavcodec/cbs_internal.h
@@ -25,11 +25,72 @@
 #include "put_bits.h"
 
 
+enum CBSContentType {
+// Unit content is a simple structure.
+CBS_CONTENT_TYPE_POD,
+// Unit content contains some references to other structures, but all
+// managed via buffer reference counting.  The descriptor defines the
+// structure offsets of every buffer reference.
+CBS_CONTENT_TYPE_INTERNAL_REFS,
+// Unit content is something more complex.  The descriptor defines
+// special functions to manage the content.
+CBS_CONTENT_TYPE_COMPLEX,
+};
+
+enum {
+  // Maximum number of unit types described by the same unit type
+  // descriptor.
+  CBS_MAX_UNIT_TYPES  = 3,
+  // Maximum number of reference buffer offsets in any one unit.
+  CBS_MAX_REF_OFFSETS = 2,
+  // Special value used in a unit type 

[FFmpeg-devel] [PATCH v6 01/22] cbs: Mention all codecs in unit type comment

2020-07-27 Thread Mark Thompson
---
 libavcodec/cbs.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h
index e897e348a2..07faf18c5b 100644
--- a/libavcodec/cbs.h
+++ b/libavcodec/cbs.h
@@ -45,8 +45,10 @@ struct CodedBitstreamType;
 /**
  * The codec-specific type of a bitstream unit.
  *
+ * AV1: obu_type
  * H.264 / AVC: nal_unit_type
  * H.265 / HEVC: nal_unit_type
+ * JPEG: marker value (without 0xff prefix)
  * MPEG-2: start code value (without prefix)
  * VP9: unused, set to zero (every unit is a frame)
  */
-- 
2.27.0

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

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

[FFmpeg-devel] [PATCH v6 00/22] CBS unit type tables and assorted related stuff

2020-07-27 Thread Mark Thompson
Mostly a rebase and update - not much has changed since the previous version in 
May.

Thanks,

- Mark
___
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] hwcontext_vaapi: remove duplicate formats from sw_format list

2020-07-27 Thread Mark Thompson

On 24/07/2020 03:39, Haihao Xiang wrote:

hwcontext_vaapi maps different VA fourcc to the same pix_fmt for U/V
plane swap cases, however duplicate formats are not expected in sw_format
list when merging formats.

For example:
ffmpeg -loglevel debug -init_hw_device vaapi -filter_hw_device vaapi0 \
-f lavfi -i smptebars -vf \
"hwupload=derive_device=vaapi,scale_vaapi,hwdownload,format=yuv420p" \
-vframes 1 -f null -

Without this fix, an auto scaler is required for the above command
Duplicate formats in ff_merge_formats detected
[auto_scaler_0 @ 0x560df58f4550] Setting 'flags' to value 'bicubic'
[auto_scaler_0 @ 0x560df58f4550] w:iw h:ih flags:'bicubic' interl:0
[Parsed_hwupload_0 @ 0x560df58f0ec0] auto-inserting filter
'auto_scaler_0' between the filter 'graph 0 input from stream 0:0' and
the filter 'Parsed_hwupload_0'

Signed-off-by: Haihao Xiang 
---
  libavutil/hwcontext_vaapi.c | 30 +-
  1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index b31cf95850..fb9be19647 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -268,14 +268,24 @@ static int vaapi_frames_get_constraints(AVHWDeviceContext 
*hwdev,
  }
  
  for (i = j = 0; i < attr_count; i++) {

+int k;
+
  if (attr_list[i].type != VASurfaceAttribPixelFormat)
  continue;
  fourcc = attr_list[i].value.value.i;
  pix_fmt = vaapi_pix_fmt_from_fourcc(fourcc);
-if (pix_fmt != AV_PIX_FMT_NONE)
+
+if (pix_fmt == AV_PIX_FMT_NONE)
+continue;
+
+for (k = 0; k < j; k++) {
+if (constraints->valid_sw_formats[k] == pix_fmt)
+break;
+}
+
+if (k == j)
  constraints->valid_sw_formats[j++] = pix_fmt;
  }
-av_assert0(j == pix_fmt_count);
  constraints->valid_sw_formats[j] = AV_PIX_FMT_NONE;
  }
  } else {
@@ -287,9 +297,19 @@ static int vaapi_frames_get_constraints(AVHWDeviceContext 
*hwdev,
  err = AVERROR(ENOMEM);
  goto fail;
  }
-for (i = 0; i < ctx->nb_formats; i++)
-constraints->valid_sw_formats[i] = ctx->formats[i].pix_fmt;
-constraints->valid_sw_formats[i] = AV_PIX_FMT_NONE;
+for (i = j = 0; i < ctx->nb_formats; i++) {
+int k;
+
+for (k = 0; k < j; k++) {
+if (constraints->valid_sw_formats[k] == 
ctx->formats[i].pix_fmt)
+break;
+}
+
+if (k == j)
+constraints->valid_sw_formats[j++] = ctx->formats[i].pix_fmt;
+}
+
+constraints->valid_sw_formats[j] = AV_PIX_FMT_NONE;
  }
  
  constraints->valid_hw_formats = av_malloc_array(2, sizeof(pix_fmt));




Not a very fun case.  Looks like a good way to handle it, though, so applied.

Thanks,

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

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

Re: [FFmpeg-devel] [PATCH 1/4] kmsgrab: Refactor and clean error cases

2020-07-27 Thread Mark Thompson

On 05/07/2020 16:49, Mark Thompson wrote:

---
  libavdevice/kmsgrab.c | 151 ++
  1 file changed, 93 insertions(+), 58 deletions(-)


Ping set.

Thanks,

- Mark
___
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] working with file descriptors on Android

2020-07-27 Thread Olivier Ayache
When you close IContainer with InputStream. It will be automatically close.
You can see Implementation here
https://github.com/olivierayache/xuggle-xuggler/blob/ffmpeg-3.x-dev/src/com/xuggle/xuggler/io/InputOutputStreamHandler.java

For the JNI overhead it must be measured but normally by working with
native byte buffers it should be limited.

Best

Olivier

Le lun. 27 juil. 2020 à 17:02, Alex Cohn  a
écrit :

> Yes, I would definitely be glad to join forces.
>
> That's true that the fd will be closed with the stream, or when the
> owning ParcelFileDescritpor is closed. But what decides when the
> stream/ParcelFileDescritpor can be closed? With `file:` protocol, it's
> very natural that avformat closes the fd when it's done with it. Here,
> we must manage the timespan of a Java object… Not nice, IMO.
>
> I wonder what overhead Java implementation of AVIOContext introduces,
> but crossing the JNI border for every `read_packet()` may not be
> negligible.
>
> I believe that the performance price of AVIOContext which simply calls
> read(), write(), and lseek() on an `fd` is minimal, but even this must
> be measured carefully to compare with the original `file:` protocol.
>
> Sincerely,
> Alex Cohn
>
> On Mon, Jul 27, 2020 at 4:45 PM Olivier Ayache 
> wrote:
> >
> > You're welcome.
> >
> > Can I suggest you to try IContainer.open with InputStream/OutputStream.
> If
> > you use a FileInputStream created from the file descriptor retrieved with
> >
> https://developer.android.com/reference/android/content/Intent#ACTION_OPEN_DOCUMENT
> > Normally fd will be automatically closed by the stream.
> >
> > If you're interested we could work together on this because I also need
> to
> > implement this type of feature for my projects.
> >
> > Best
> >
> > Olivier
> >
> > Le lun. 27 juil. 2020 à 14:46, Alex Cohn  a
> > écrit :
> >
> > > Thanks Olivier,
> > >
> > > Custom IO looks like a nice way to work around the protocol
> > > limitations. Unfortunately, it cannot work with avio_open(), so the
> > > API becomes trickier for end users.
> > >
> > > Also, just like with pipes, I cannot reliably close the file
> > > descriptor when ffmpeg execution is over, can I?
> > >
> > > BR,
> > > Alex Cohn
> > >
> > > On Mon, Jul 27, 2020 at 11:01 AM Olivier Ayache
> > >  wrote:
> > > >
> > > > A good alternative to work with FFmpeg on Android is Xuggler, it
> presents
> > > > FFmpeg's API directly to Java/Kotlin.
> > > >
> > > > To deal with fd you can declare and implement your own IO handler by
> > > > implementing
> > > >
> > >
> https://github.com/olivierayache/xuggle-xuggler/blob/ffmpeg-3.x-dev/src/com/xuggle/xuggler/io/IURLProtocolHandler.java
> > > >
> > > > I currently maintain a fork which is fully working on Android (work
> in
> > > > progress for iOS with Kotlin multiplatform).
> > > >
> > > > https://github.com/olivierayache/xuggle-xuggler
> > > >
> > > > Best
> > > >
> > > > Olivier Ayache
> > > >
> > > > Le dim. 26 juil. 2020 à 23:16, Alex Cohn 
> a
> > > > écrit :
> > > >
> > > > > On Sun, Jul 26, 2020 at 10:21 PM Martin Storsjö 
> > > wrote:
> > > > > >
> > > > > > Hi,
> > > > > >
> > > > > > Without having too much opinion on the JNI stuff (direct access
> to
> > > > > > content:// urls might be convenient, but on the other hand, it's
> not
> > > > > > really something you'd end up with if using the command line
> tool on
> > > its
> > > > > > own - if you have one of those you most probably have some java
> code
> > > for
> > > > > > getting it anyway - as far as I remember...)
> > > > >
> > > > >
> > > > > You are more than right, Martin.
> > > > >
> > > > > None of these approaches can work with a command line tool. Worse,
> > > > > running a command line tool in the context of an Android app is
> > > > > becoming trickier with every new release of the platform, and in
> this
> > > > > case I cannot blame it on poor engineering. This happens because
> > > > > Google tries to tighten the security on Android just as much as
> > > > > possible.
> > > > >
> > > > > There is a nice cross-platform alternative, though.
> > > > > https://github.com/tanersener/mobile-ffmpeg provides Java and
> > > > > Objective-C APIs to run ffmpeg shared library "as if it were an
> > > > > executable": it can receive the input as a string which mimics the
> > > > > ffmpeg (and ffprobe) command line, and the output to stdout and
> stderr
> > > > > is captured and passed back to the mobile app. In this scenario,
> it's
> > > > > easy to get a `content:` URI by conventional Android SAF
> (structured
> > > > > access framework) API in Java and pass it as string or as a derived
> > > > > file descriptor (converted to string) to the command line parser
> that
> > > > > will eventually call protocol->url_open().
> > > > >
> > > > > The latest release (Android Q a.k.a. Android 10, also API 29) made
> yet
> > > > > another small step in this direction and caused lots of problems
> for
> > > > > apps that rely upon file access by path. This was the 

Re: [FFmpeg-devel] working with file descriptors on Android

2020-07-27 Thread Alex Cohn
Yes, I would definitely be glad to join forces.

That's true that the fd will be closed with the stream, or when the
owning ParcelFileDescritpor is closed. But what decides when the
stream/ParcelFileDescritpor can be closed? With `file:` protocol, it's
very natural that avformat closes the fd when it's done with it. Here,
we must manage the timespan of a Java object… Not nice, IMO.

I wonder what overhead Java implementation of AVIOContext introduces,
but crossing the JNI border for every `read_packet()` may not be
negligible.

I believe that the performance price of AVIOContext which simply calls
read(), write(), and lseek() on an `fd` is minimal, but even this must
be measured carefully to compare with the original `file:` protocol.

Sincerely,
Alex Cohn

On Mon, Jul 27, 2020 at 4:45 PM Olivier Ayache  wrote:
>
> You're welcome.
>
> Can I suggest you to try IContainer.open with InputStream/OutputStream. If
> you use a FileInputStream created from the file descriptor retrieved with
> https://developer.android.com/reference/android/content/Intent#ACTION_OPEN_DOCUMENT
> Normally fd will be automatically closed by the stream.
>
> If you're interested we could work together on this because I also need to
> implement this type of feature for my projects.
>
> Best
>
> Olivier
>
> Le lun. 27 juil. 2020 à 14:46, Alex Cohn  a
> écrit :
>
> > Thanks Olivier,
> >
> > Custom IO looks like a nice way to work around the protocol
> > limitations. Unfortunately, it cannot work with avio_open(), so the
> > API becomes trickier for end users.
> >
> > Also, just like with pipes, I cannot reliably close the file
> > descriptor when ffmpeg execution is over, can I?
> >
> > BR,
> > Alex Cohn
> >
> > On Mon, Jul 27, 2020 at 11:01 AM Olivier Ayache
> >  wrote:
> > >
> > > A good alternative to work with FFmpeg on Android is Xuggler, it presents
> > > FFmpeg's API directly to Java/Kotlin.
> > >
> > > To deal with fd you can declare and implement your own IO handler by
> > > implementing
> > >
> > https://github.com/olivierayache/xuggle-xuggler/blob/ffmpeg-3.x-dev/src/com/xuggle/xuggler/io/IURLProtocolHandler.java
> > >
> > > I currently maintain a fork which is fully working on Android (work in
> > > progress for iOS with Kotlin multiplatform).
> > >
> > > https://github.com/olivierayache/xuggle-xuggler
> > >
> > > Best
> > >
> > > Olivier Ayache
> > >
> > > Le dim. 26 juil. 2020 à 23:16, Alex Cohn  a
> > > écrit :
> > >
> > > > On Sun, Jul 26, 2020 at 10:21 PM Martin Storsjö 
> > wrote:
> > > > >
> > > > > Hi,
> > > > >
> > > > > Without having too much opinion on the JNI stuff (direct access to
> > > > > content:// urls might be convenient, but on the other hand, it's not
> > > > > really something you'd end up with if using the command line tool on
> > its
> > > > > own - if you have one of those you most probably have some java code
> > for
> > > > > getting it anyway - as far as I remember...)
> > > >
> > > >
> > > > You are more than right, Martin.
> > > >
> > > > None of these approaches can work with a command line tool. Worse,
> > > > running a command line tool in the context of an Android app is
> > > > becoming trickier with every new release of the platform, and in this
> > > > case I cannot blame it on poor engineering. This happens because
> > > > Google tries to tighten the security on Android just as much as
> > > > possible.
> > > >
> > > > There is a nice cross-platform alternative, though.
> > > > https://github.com/tanersener/mobile-ffmpeg provides Java and
> > > > Objective-C APIs to run ffmpeg shared library "as if it were an
> > > > executable": it can receive the input as a string which mimics the
> > > > ffmpeg (and ffprobe) command line, and the output to stdout and stderr
> > > > is captured and passed back to the mobile app. In this scenario, it's
> > > > easy to get a `content:` URI by conventional Android SAF (structured
> > > > access framework) API in Java and pass it as string or as a derived
> > > > file descriptor (converted to string) to the command line parser that
> > > > will eventually call protocol->url_open().
> > > >
> > > > The latest release (Android Q a.k.a. Android 10, also API 29) made yet
> > > > another small step in this direction and caused lots of problems for
> > > > apps that rely upon file access by path. This was the incentive for me
> > > > to work on the ways to teach avformat to work with the `content:` URIs
> > > > correctly.
> > > >
> > > > BR,
> > > > Alex Cohn
> > > > ___
> > > > 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 

Re: [FFmpeg-devel] [PATCH] hwcontext_vaapi: avoid fd leak in vaapi_device_derive

2020-07-27 Thread Mark Thompson

On 24/07/2020 08:29, Haihao Xiang wrote:

---
  libavutil/hwcontext_vaapi.c | 6 +-
  1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index fb9be19647..a4dfaba92c 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -1698,8 +1698,12 @@ static int vaapi_device_derive(AVHWDeviceContext *ctx,
  #endif
  
  priv = av_mallocz(sizeof(*priv));

-if (!priv)
+if (!priv) {
+/* fd is opened in this function */
+if (fd != src_hwctx->fd)
+close(fd);
  return AVERROR(ENOMEM);
+}
  
  if (fd == src_hwctx->fd) {

  // The fd is inherited from the source context and we are holding


Yep.  Made the comment style consistent with the rest of the file and applied.

Thanks,

- Mark
___
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] Specifying crop parameters while encoding using vaapi

2020-07-27 Thread Mark Thompson

On 27/07/2020 00:55, Satyajit Sahu wrote:

Hi,



I am facing issue with cropping parameters while transcoding. The cropping
parameters are ignored if both the way vaapi hw acceleration is used (for
decoding and encoding). But if sw decoding is used the cropping parameters
are working fine.



For below command cropping parameters are ignored.

ffmpeg -y -hwaccel vaapi -hwaccel_output_format vaapi -hwaccel_device
/dev/dri/renderD128 -i 480p.mkv -vf "fps=23.976,crop=640:400:0:139" -bf 0
-c:v h264_vaapi -b:v 6706k -pass 1 -an -f mp4 test.mp4



Warning message : “[h264_vaapi @ 0x5617a44844c0] Cropping information on
input frames ignored due to lack of API support."



But when sw decoding is used cropping works properly

ffmpeg -vaapi_device /dev/dri/renderD128 -i 480p.mkv -vf
'format=nv12,fps=23.97,crop=640:400:0:139,hwupload' -c:v h264_vaapi test.mp4



Also able to encode with cropping parameters from raw yuv file using vaapi
hw encode.

Is this some limitation from ffmpeg or the command is not proper?


VAAPI does not support cropping applied to the input surface of an encoder like 
this, but it does for filtering.

So, you can insert a scale filter (not actually doing any scaling) to make a 
surface suitable for encoding input with the cropping applied.

-vf "fps=23.976,crop=640:400:0:139,scale_vaapi=640:400"

- Mark

PS:  Please direct any future questions about using ffmpeg to the ffmpeg-user 
mailing list.  This the development list.
___
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] Support HDR10+ metadata for HEVC.

2020-07-27 Thread Vittorio Giovara
On Fri, Jul 24, 2020 at 11:09 PM Mohammad Izadi <
izadi-at-google@ffmpeg.org> wrote:

> On Fri, Jul 24, 2020 at 9:30 AM Andreas Rheinhardt <
> andreas.rheinha...@gmail.com> wrote:
>
> > Mohammad Izadi:
> > > From: Mohammad Izadi 
> > >
> > > HDR10+ is dynamic metadata (A/341 Amendment - SMPTE2094-40) that needs
> > to be decoded from ITU-T T.35 in HEVC bitstream. The HDR10+ is
> transferred
> > to side data packet to be used or passed through.
> > > ---
> > >  libavcodec/avpacket.c |   1 +
> > >  libavcodec/decode.c   |   1 +
> > >  libavcodec/hevc_sei.c |  39 ++---
> > >  libavcodec/hevc_sei.h |   5 ++
> > >  libavcodec/hevcdec.c  |  16 
> > >  libavcodec/internal.h |   9 +++
> > >  libavcodec/packet.h   |   8 ++
> > >  libavcodec/utils.c| 180 ++
> > >  libavcodec/version.h  |   2 +-
> > >  9 files changed, 248 insertions(+), 13 deletions(-)
> > >
> > > diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> > > index dce26cb31a..8307032335 <(830)%20703-2335> 100644
> > > --- a/libavcodec/avpacket.c
> > > +++ b/libavcodec/avpacket.c
> > > @@ -394,6 +394,7 @@ const char *av_packet_side_data_name(enum
> > AVPacketSideDataType type)
> > >  case AV_PKT_DATA_CONTENT_LIGHT_LEVEL:return "Content light
> > level metadata";
> > >  case AV_PKT_DATA_SPHERICAL:  return "Spherical
> > Mapping";
> > >  case AV_PKT_DATA_A53_CC: return "A53 Closed
> > Captions";
> > > +case AV_PKT_DATA_DYNAMIC_HDR_PLUS:   return "HDR10+
> Dynamic
> > Metadata (SMPTE 2094-40)";
> > >  case AV_PKT_DATA_ENCRYPTION_INIT_INFO:   return "Encryption
> > initialization data";
> > >  case AV_PKT_DATA_ENCRYPTION_INFO:return "Encryption
> > info";
> > >  case AV_PKT_DATA_AFD:return "Active Format
> > Description data";
> > > diff --git a/libavcodec/decode.c b/libavcodec/decode.c
> > > index de9c079f9d..cd3286f7fb 100644
> > > --- a/libavcodec/decode.c
> > > +++ b/libavcodec/decode.c
> > > @@ -1698,6 +1698,7 @@ int ff_decode_frame_props(AVCodecContext *avctx,
> > AVFrame *frame)
> > >  { AV_PKT_DATA_MASTERING_DISPLAY_METADATA,
> > AV_FRAME_DATA_MASTERING_DISPLAY_METADATA },
> > >  { AV_PKT_DATA_CONTENT_LIGHT_LEVEL,
> > AV_FRAME_DATA_CONTENT_LIGHT_LEVEL },
> > >  { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC
> > },
> > > +{ AV_PKT_DATA_DYNAMIC_HDR_PLUS,
> >  AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
> > >  { AV_PKT_DATA_ICC_PROFILE,
> > AV_FRAME_DATA_ICC_PROFILE },
> > >  };
> > >
> > > diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
> > > index a4ec65dc1a..a490e752dd 100644
> > > --- a/libavcodec/hevc_sei.c
> > > +++ b/libavcodec/hevc_sei.c
> > > @@ -25,6 +25,7 @@
> > >  #include "golomb.h"
> > >  #include "hevc_ps.h"
> > >  #include "hevc_sei.h"
> > > +#include "internal.h"
> > >
> > >  static int decode_nal_sei_decoded_picture_hash(HEVCSEIPictureHash *s,
> > GetBitContext *gb)
> > >  {
> > > @@ -242,8 +243,8 @@ static int
> > decode_nal_sei_user_data_unregistered(HEVCSEIUnregistered *s, GetBitC
> > >  static int decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s,
> > GetBitContext *gb,
> > >   int size)
> > >  {
> > > -uint32_t country_code;
> > > -uint32_t user_identifier;
> > > +uint8_t country_code;
> > > +uint16_t provider_code;
> > >
> > >  if (size < 7)
> > >  return AVERROR(EINVAL);
> > > @@ -255,18 +256,31 @@ static int
> > decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s, GetBitConte
> > >  size--;
> > >  }
> > >
> > > -skip_bits(gb, 8);
> > > -skip_bits(gb, 8);
> > > -
> > > -user_identifier = get_bits_long(gb, 32);
> > > -
> > > -switch (user_identifier) {
> > > -case MKBETAG('G', 'A', '9', '4'):
> > > +provider_code = get_bits(gb, 16);
> > > +
> > > +const uint8_t usa_country_code = 0xB5;
> > > +const uint16_t smpte_provider_code = 0x003C;
> > > +if (country_code == usa_country_code &&
> > > +provider_code == smpte_provider_code) {
> > > +// A/341 Amendment – 2094-40
> > > +uint16_t provider_oriented_code = get_bits(gb, 16);
> > > +uint8_t application_identifier = get_bits(gb, 8);
> > > +const uint16_t smpte2094_40_provider_oriented_code = 0x0001;
> > > +const uint16_t smpte2094_40_application_identifier = 0x04;
> > > +if (provider_oriented_code ==
> > smpte2094_40_provider_oriented_code &&
> > > +application_identifier ==
> > smpte2094_40_application_identifier) {
> > > +int err = ff_read_itu_t_t35_to_dynamic_hdr_plus(gb, s->
> > dynamic_hdr_plus.info);
> > > +if (err < 0 && s->dynamic_hdr_plus.info) {
> > > +av_buffer_unref(>dynamic_hdr_plus.info);
> > > +}
> > > +return err;
> > > +}
> > > +} else {
> > 

Re: [FFmpeg-devel] [PATCH v3 2/2] avformat/tests/url: add test cases for .. and last node is ..

2020-07-27 Thread Zlomek, Josef
This does not work for the following testcases, + lines are invalid:

+test("/foo/bar", "..");
+test("/foo/bar/baz", "..");

-  /foo/bar ..   =>
/
-  /foo/bar/baz ..   =>
/foo/
+  /foo/bar ..   =>
//foo/bar/baz
+  /foo/bar/baz ..   =>
/foo//foo/bar/baz


This one would be also nice if it worked:

+test("http://server/foo/bar;, "a/b/../c/d/../e../..f/.../other/url/");
- http://server/foo/bar
a/b/../c/d/../e../..f/.../other/url/.. =>
http://server/foo/a/c/e../..f/.../other/
+ http://server/foo/bar
a/b/../c/d/../e../..f/.../other/url/.. =>
http://server/foo/a/c/e../..f/.../other


On Mon, Jul 27, 2020 at 3:08 PM Steven Liu  wrote:

> Signed-off-by: Steven Liu 
> ---
>  libavformat/tests/url.c | 14 ++
>  tests/ref/fate/url  | 12 
>  2 files changed, 26 insertions(+)
>
> diff --git a/libavformat/tests/url.c b/libavformat/tests/url.c
> index 1d961a1b43..0de511caf9 100644
> --- a/libavformat/tests/url.c
> +++ b/libavformat/tests/url.c
> @@ -24,6 +24,8 @@
>  static void test(const char *base, const char *rel)
>  {
>  char buf[200], buf2[200];
> +memset(buf, 0, 200);
> +memset(buf2, 0, 200);
>  ff_make_absolute_url(buf, sizeof(buf), base, rel);
>  printf("%50s %-20s => %s\n", base, rel, buf);
>  if (base) {
> @@ -66,7 +68,19 @@ int main(void)
>  test("http://server/foo/bar?param=value/with/slashes;, "/baz");
>  test("http://server/foo/bar?param;, "?someparam");
>  test("http://server/foo/bar;, "//other/url");
> +test("http://server/foo/bar;, "../other/url");
> +test("http://server/foo/bar;, "other/url");
>  test("http://server/foo/bar;, "../../../../../other/url");
> +test("http://server/foo/bar;, "../../../../../other/url/test..mp3");
> +test("http://server/foo/bar;, "../../../../../other/url/test..");
> +test("http://server/foo/bar;, "../../../../../other/url/test/...");
> +test("http://server/foo/bar;,
> "../../../../../other/url/.../test/out");
> +test("http://server/foo/bar;,
> "../../../../../other/url/.../../test/out");
> +test("http://server/foo/bar;,
> "../../../../../other/url/.../..test/out");
> +test("http://server/foo/bar;, "../../../../../other/url/..");
> +test("http://server/foo/bar;, "../../../../../other/url/..mp3");
> +test("http://server/foo/bar;, "../../../../../other/url/..test/mp3");
> +test("http://server/foo/bar;, "../../../../../other/url/test../mp3");
>  test("http://server/foo/bar;, "/../../../../../other/url");
>  test("http://server/foo/bar;, "/test/../../../../../other/url");
>  test("http://server/foo/bar;, "/test/../../test/../../../other/url");
> diff --git a/tests/ref/fate/url b/tests/ref/fate/url
> index 533ba2cb1e..35eee25f4a 100644
> --- a/tests/ref/fate/url
> +++ b/tests/ref/fate/url
> @@ -13,7 +13,19 @@ Testing ff_make_absolute_url:
>  http://server/foo/bar?param=value/with/slashes /baz
>  => http://server/baz
>  http://server/foo/bar?param ?someparam
>  => http://server/foo/bar?someparam
>   http://server/foo/bar //other/url
> => http://other/url
> + http://server/foo/bar ../other/url =>
> http://server/other/url
> + http://server/foo/bar other/url =>
> http://server/foo/other/url
>   http://server/foo/bar
> ../../../../../other/url => http://server/other/url
> + http://server/foo/bar
> ../../../../../other/url/test..mp3 => http://server/other/url/test..mp3
> + http://server/foo/bar
> ../../../../../other/url/test.. => http://server/other/url/test..
> + http://server/foo/bar
> ../../../../../other/url/test/... => http://server/other/url/test/...
> + http://server/foo/bar
> ../../../../../other/url/.../test/out =>
> http://server/other/url/.../test/out
> + http://server/foo/bar
> ../../../../../other/url/.../../test/out =>
> http://server/other/url/test/out
> + http://server/foo/bar
> ../../../../../other/url/.../..test/out =>
> http://server/other/url/.../..test/out
> + http://server/foo/bar
> ../../../../../other/url/.. => http://server/other
> + http://server/foo/bar
> ../../../../../other/url/..mp3 => http://server/other/url/..mp3
> + http://server/foo/bar
> ../../../../../other/url/..test/mp3 => http://server/other/url/..test/mp3
> + http://server/foo/bar
> ../../../../../other/url/test../mp3 => http://server/other/url/test../mp3
>   

Re: [FFmpeg-devel] [PATCH v3 1/2] avformat/url: rework for trim_double_dot_url

2020-07-27 Thread Zlomek, Josef
Generally, this seems to be too complicated with too much of copying.

On Mon, Jul 27, 2020 at 3:08 PM Steven Liu  wrote:

> use two buffer for storage the path and node of URI
> remove the last node of the path if the next node is ..
> change the static strings to dynamic alloc space by size argument.
>
> Signed-off-by: Steven Liu 
> ---
>  libavformat/url.c | 83 ---
>  1 file changed, 64 insertions(+), 19 deletions(-)
>
> diff --git a/libavformat/url.c b/libavformat/url.c
> index 20463a6674..4fb703de78 100644
> --- a/libavformat/url.c
> +++ b/libavformat/url.c
> @@ -82,41 +82,78 @@ static void trim_double_dot_url(char *buf, const char
> *rel, int size)
>  {
>  const char *p = rel;
>  const char *root = rel;
> -char tmp_path[MAX_URL_SIZE] = {0, };
> +char *tmp_path = NULL;
> +char *second_buf = NULL;
> +char *first_buf = NULL;
>  char *sep;
>  char *node;
>
> +tmp_path = av_mallocz(size);
> +if (!tmp_path)
> +return;
> +
> +second_buf = av_mallocz(size);
> +if (!second_buf)
> +goto fail;
> +
> +first_buf = av_mallocz(size);
> +if (!first_buf)
> +goto fail;
>

Why 3 buffers? 1 would be enough.

+
>  /* Get the path root of the url which start by "://" */
>  if (p && (sep = strstr(p, "://"))) {
>  sep += 3;
>  root = strchr(sep, '/');
>  if (!root)
> -return;
> +goto fail;
>  }
> +av_strlcat(tmp_path, p, root - p + 1);
>
>  /* set new current position if the root node is changed */
>  p = root;
> -while (p && (node = strstr(p, ".."))) {
> -av_strlcat(tmp_path, p, node - p + strlen(tmp_path));
> -p = node + 3;
> -sep = strrchr(tmp_path, '/');
> +if (*p == '/')
> +p++;
> +while (p && (node = strchr(p, '/'))) {
> +av_strlcpy(second_buf, p, node - p + 1);
> +p = node + 1;
> +if (!strcmp(second_buf, "..")) {
>

If you used if(node - p == 2 && !strncmp(node, "..", 2)) you would not have
to copy to the second buffer.

+if (strlen(first_buf) <= 0)
> +continue;
> +sep = strrchr(first_buf, '/');
> +if (sep)
> +sep[0] = '\0';
> +else
> +memset(first_buf, 0, size);
> +
> +memset(second_buf, 0, size);
> +} else {
> +av_strlcat(first_buf, "/", size);
> +av_strlcat(first_buf, second_buf, size);
> +}
> +}
> +if (!strcmp(p, "..")) {
> +sep = strrchr(first_buf, '/');
>  if (sep)
>  sep[0] = '\0';
>  else
> -tmp_path[0] = '\0';
> +memset(first_buf, 0, size);
> +} else {
> +av_strlcat(first_buf, "/", size);
> +av_strlcat(first_buf, p, size);
>  }
>
> -if (!av_stristart(p, "/", NULL) && root != rel)
> -av_strlcat(tmp_path, "/", size);
> -
> -av_strlcat(tmp_path, p, size);
> -/* start set buf after temp path process. */
> -av_strlcpy(buf, rel, root - rel + 1);
> -
> -if (!av_stristart(tmp_path, "/", NULL) && root != rel)
> -av_strlcat(buf, "/", size);
> +if (p > root) {
> +av_strlcat(tmp_path, first_buf, size);
> +} else {
> +av_strlcat(tmp_path, p, size);
> +}
>
>  av_strlcat(buf, tmp_path, size);
> +
> +fail:
> +av_free(second_buf);
> +av_free(first_buf);
> +av_free(tmp_path);
>  }
>
>  void ff_make_absolute_url(char *buf, int size, const char *base,
> @@ -124,9 +161,11 @@ void ff_make_absolute_url(char *buf, int size, const
> char *base,
>  {
>  char *sep, *path_query;
>  char *root, *p;
> -char tmp_path[MAX_URL_SIZE];
> +char *tmp_path = av_mallocz(size);
> +
> +if (!tmp_path)
> +return;
>
> -memset(tmp_path, 0, sizeof(tmp_path));
>  /* Absolute path, relative to the current server */
>  if (base && strstr(base, "://") && rel[0] == '/') {
>  if (base != buf)
> @@ -148,12 +187,14 @@ void ff_make_absolute_url(char *buf, int size, const
> char *base,
>  trim_double_dot_url(tmp_path, buf, size);
>  memset(buf, 0, size);
>  av_strlcpy(buf, tmp_path, size);
> +av_free(tmp_path);
>  return;
>  }
>  /* If rel actually is an absolute url, just copy it */
>  if (!base || strstr(rel, "://") || rel[0] == '/') {
>  memset(buf, 0, size);
>  trim_double_dot_url(buf, rel, size);
> +av_free(tmp_path);
>  return;
>  }
>  if (base != buf)
> @@ -170,6 +211,7 @@ void ff_make_absolute_url(char *buf, int size, const
> char *base,
>  trim_double_dot_url(tmp_path, buf, size);
>  memset(buf, 0, size);
>  av_strlcpy(buf, tmp_path, size);
> +av_free(tmp_path);
>  return;
>  }
>
> @@ -180,8 +222,10 @@ void ff_make_absolute_url(char *buf, int size, const
> char *base,
>  if (sep) {
>  

Re: [FFmpeg-devel] [PATCH v2 1/2] avformat/url: check double dot is not to parent directory

2020-07-27 Thread Nicolas George
Steven Liu (12020-07-27):
> What about use av_malloc? or bprint?
> I think use av_malloc maybe easter to me.

For internal APIs, definitely BPrint over naive av_malloc(). But this is
unrelated to the issue at hand: the size limit exists in the caller of
this function, not in this function.

Regards,

-- 
  Nicolas George


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

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

Re: [FFmpeg-devel] [PATCH v3 1/2] avformat/url: rework for trim_double_dot_url

2020-07-27 Thread Nicolas George
Steven Liu (12020-07-27):
> use two buffer for storage the path and node of URI
> remove the last node of the path if the next node is ..
> change the static strings to dynamic alloc space by size argument.

?!?!??!!!?

Why do you think you need extra buffers?

This patch turns a rather straightforward task into a nightmare of
string copies.

Regards,

-- 
  Nicolas George


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

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

Re: [FFmpeg-devel] working with file descriptors on Android

2020-07-27 Thread Olivier Ayache
You're welcome.

Can I suggest you to try IContainer.open with InputStream/OutputStream. If
you use a FileInputStream created from the file descriptor retrieved with
https://developer.android.com/reference/android/content/Intent#ACTION_OPEN_DOCUMENT
Normally fd will be automatically closed by the stream.

If you're interested we could work together on this because I also need to
implement this type of feature for my projects.

Best

Olivier

Le lun. 27 juil. 2020 à 14:46, Alex Cohn  a
écrit :

> Thanks Olivier,
>
> Custom IO looks like a nice way to work around the protocol
> limitations. Unfortunately, it cannot work with avio_open(), so the
> API becomes trickier for end users.
>
> Also, just like with pipes, I cannot reliably close the file
> descriptor when ffmpeg execution is over, can I?
>
> BR,
> Alex Cohn
>
> On Mon, Jul 27, 2020 at 11:01 AM Olivier Ayache
>  wrote:
> >
> > A good alternative to work with FFmpeg on Android is Xuggler, it presents
> > FFmpeg's API directly to Java/Kotlin.
> >
> > To deal with fd you can declare and implement your own IO handler by
> > implementing
> >
> https://github.com/olivierayache/xuggle-xuggler/blob/ffmpeg-3.x-dev/src/com/xuggle/xuggler/io/IURLProtocolHandler.java
> >
> > I currently maintain a fork which is fully working on Android (work in
> > progress for iOS with Kotlin multiplatform).
> >
> > https://github.com/olivierayache/xuggle-xuggler
> >
> > Best
> >
> > Olivier Ayache
> >
> > Le dim. 26 juil. 2020 à 23:16, Alex Cohn  a
> > écrit :
> >
> > > On Sun, Jul 26, 2020 at 10:21 PM Martin Storsjö 
> wrote:
> > > >
> > > > Hi,
> > > >
> > > > Without having too much opinion on the JNI stuff (direct access to
> > > > content:// urls might be convenient, but on the other hand, it's not
> > > > really something you'd end up with if using the command line tool on
> its
> > > > own - if you have one of those you most probably have some java code
> for
> > > > getting it anyway - as far as I remember...)
> > >
> > >
> > > You are more than right, Martin.
> > >
> > > None of these approaches can work with a command line tool. Worse,
> > > running a command line tool in the context of an Android app is
> > > becoming trickier with every new release of the platform, and in this
> > > case I cannot blame it on poor engineering. This happens because
> > > Google tries to tighten the security on Android just as much as
> > > possible.
> > >
> > > There is a nice cross-platform alternative, though.
> > > https://github.com/tanersener/mobile-ffmpeg provides Java and
> > > Objective-C APIs to run ffmpeg shared library "as if it were an
> > > executable": it can receive the input as a string which mimics the
> > > ffmpeg (and ffprobe) command line, and the output to stdout and stderr
> > > is captured and passed back to the mobile app. In this scenario, it's
> > > easy to get a `content:` URI by conventional Android SAF (structured
> > > access framework) API in Java and pass it as string or as a derived
> > > file descriptor (converted to string) to the command line parser that
> > > will eventually call protocol->url_open().
> > >
> > > The latest release (Android Q a.k.a. Android 10, also API 29) made yet
> > > another small step in this direction and caused lots of problems for
> > > apps that rely upon file access by path. This was the incentive for me
> > > to work on the ways to teach avformat to work with the `content:` URIs
> > > correctly.
> > >
> > > BR,
> > > Alex Cohn
> > > ___
> > > 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 mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH v2 1/2] avformat/url: fix logic for removing ".." path components

2020-07-27 Thread Steven Liu
Josef Zlomek  于2020年7月27日周一 下午8:15写道:
>
> Fixes: 8814
>
> The logic for removing ".." path components and their corresponding
> upper directories was reworked.
>
> Now, the function trim_double_dot_url splits the path by "/" into
> components, and processes the components one ny one:
> - if the component is "..", the last path component in tmp_path is removed
> - if the component is not empty, it is added to tmp_path
>
> The duplicate logic was removed from ff_make_absolute_url.
>
> Signed-off-by: Josef Zlomek 
> ---
>  libavformat/url.c | 90 ++-
>  1 file changed, 43 insertions(+), 47 deletions(-)
>
> diff --git a/libavformat/url.c b/libavformat/url.c
> index 20463a6674..343cbca9b9 100644
> --- a/libavformat/url.c
> +++ b/libavformat/url.c
> @@ -83,8 +83,10 @@ static void trim_double_dot_url(char *buf, const char 
> *rel, int size)
>  const char *p = rel;
>  const char *root = rel;
>  char tmp_path[MAX_URL_SIZE] = {0, };
> -char *sep;
> -char *node;
> +int tmp_len = 0;
> +const char *sep;
> +const char *next;
> +int last_is_dir;
>
>  /* Get the path root of the url which start by "://" */
>  if (p && (sep = strstr(p, "://"))) {
> @@ -93,29 +95,45 @@ static void trim_double_dot_url(char *buf, const char 
> *rel, int size)
>  if (!root)
>  return;
>  }
> +if (*root == '/')
> +++root;
> +
> +/* Split the path by "/" and remove ".." and its corresponding 
> directory. */
> +last_is_dir = 1;
> +for (p = root; *p; p = next) {
> +next = strchr(p, '/');
> +if (!next) {
> +next = p + strlen(p);
> +last_is_dir = 0;
> +}
>
> -/* set new current position if the root node is changed */
> -p = root;
> -while (p && (node = strstr(p, ".."))) {
> -av_strlcat(tmp_path, p, node - p + strlen(tmp_path));
> -p = node + 3;
> -sep = strrchr(tmp_path, '/');
> -if (sep)
> -sep[0] = '\0';
> -else
> -tmp_path[0] = '\0';
> -}
> +if (next - p == 2 && !strncmp(p, "..", 2)) {
> +/* remove the last directory from tmp_path */
> +while (tmp_len > 0 && tmp_path[--tmp_len] != '/')
> +;
> +tmp_path[tmp_len] = '\0';
> +last_is_dir = 1;
> +} else if (next > p) {
> +/* copy the current path component to tmp_path (including '/') */
> +if (tmp_len) {
> +av_strlcpy(tmp_path + tmp_len, "/", sizeof(tmp_path) - 
> tmp_len);
> +++tmp_len;
> +}
> +av_strlcpy(tmp_path + tmp_len, p, FFMIN(sizeof(tmp_path) - 
> tmp_len,
> +next - p + 1));
> +tmp_len += next - p;
> +tmp_path[tmp_len] = '\0';
> +}
>
> -if (!av_stristart(p, "/", NULL) && root != rel)
> -av_strlcat(tmp_path, "/", size);
> +/* skip "/" */
> +while (*next == '/')
> +++next;
> +}
> +if (last_is_dir && tmp_len)
> +av_strlcpy(tmp_path + tmp_len, "/", sizeof(tmp_path) - tmp_len);
>
> -av_strlcat(tmp_path, p, size);
>  /* start set buf after temp path process. */
>  av_strlcpy(buf, rel, root - rel + 1);
> -
> -if (!av_stristart(tmp_path, "/", NULL) && root != rel)
> -av_strlcat(buf, "/", size);
> -
>  av_strlcat(buf, tmp_path, size);
>  }
>
> @@ -175,14 +193,11 @@ void ff_make_absolute_url(char *buf, int size, const 
> char *base,
>
>  root = p = buf;
>  /* Get the path root of the url which start by "://" */
> -if (p && strstr(p, "://")) {
> -sep = strstr(p, "://");
> -if (sep) {
> -sep += 3;
> -root = strchr(sep, '/');
> -if (!root)
> -return;
> -}
> +if (p && (sep = strstr(p, "://"))) {
> +sep += 3;
> +root = strchr(sep, '/');
> +if (!root)
> +return;
>  }
>
>  /* Remove the file name from the base url */
> @@ -194,26 +209,7 @@ void ff_make_absolute_url(char *buf, int size, const 
> char *base,
>  sep[1] = '\0';
>  else
>  buf[0] = '\0';
> -while (av_strstart(rel, "..", NULL) && sep) {
> -/* Remove the path delimiter at the end */
> -if (sep > root) {
> -sep[0] = '\0';
> -sep = strrchr(buf, '/');
> -}
>
> -/* If the next directory name to pop off is "..", break here */
> -if (!strcmp(sep ? [1] : buf, "..")) {
> -/* Readd the slash we just removed */
> -av_strlcat(buf, "/", size);
> -break;
> -}
> -/* Cut off the directory name */
> -if (sep)
> -sep[1] = '\0';
> -else
> -buf[0] = '\0';
> -rel += 3;
> -}
>  av_strlcat(buf, rel, size);
>  trim_double_dot_url(tmp_path, buf, size);
>  

[FFmpeg-devel] [PATCH v3 2/2] avformat/tests/url: add test cases for .. and last node is ..

2020-07-27 Thread Steven Liu
Signed-off-by: Steven Liu 
---
 libavformat/tests/url.c | 14 ++
 tests/ref/fate/url  | 12 
 2 files changed, 26 insertions(+)

diff --git a/libavformat/tests/url.c b/libavformat/tests/url.c
index 1d961a1b43..0de511caf9 100644
--- a/libavformat/tests/url.c
+++ b/libavformat/tests/url.c
@@ -24,6 +24,8 @@
 static void test(const char *base, const char *rel)
 {
 char buf[200], buf2[200];
+memset(buf, 0, 200);
+memset(buf2, 0, 200);
 ff_make_absolute_url(buf, sizeof(buf), base, rel);
 printf("%50s %-20s => %s\n", base, rel, buf);
 if (base) {
@@ -66,7 +68,19 @@ int main(void)
 test("http://server/foo/bar?param=value/with/slashes;, "/baz");
 test("http://server/foo/bar?param;, "?someparam");
 test("http://server/foo/bar;, "//other/url");
+test("http://server/foo/bar;, "../other/url");
+test("http://server/foo/bar;, "other/url");
 test("http://server/foo/bar;, "../../../../../other/url");
+test("http://server/foo/bar;, "../../../../../other/url/test..mp3");
+test("http://server/foo/bar;, "../../../../../other/url/test..");
+test("http://server/foo/bar;, "../../../../../other/url/test/...");
+test("http://server/foo/bar;, "../../../../../other/url/.../test/out");
+test("http://server/foo/bar;, "../../../../../other/url/.../../test/out");
+test("http://server/foo/bar;, "../../../../../other/url/.../..test/out");
+test("http://server/foo/bar;, "../../../../../other/url/..");
+test("http://server/foo/bar;, "../../../../../other/url/..mp3");
+test("http://server/foo/bar;, "../../../../../other/url/..test/mp3");
+test("http://server/foo/bar;, "../../../../../other/url/test../mp3");
 test("http://server/foo/bar;, "/../../../../../other/url");
 test("http://server/foo/bar;, "/test/../../../../../other/url");
 test("http://server/foo/bar;, "/test/../../test/../../../other/url");
diff --git a/tests/ref/fate/url b/tests/ref/fate/url
index 533ba2cb1e..35eee25f4a 100644
--- a/tests/ref/fate/url
+++ b/tests/ref/fate/url
@@ -13,7 +13,19 @@ Testing ff_make_absolute_url:
 http://server/foo/bar?param=value/with/slashes /baz => 
http://server/baz
 http://server/foo/bar?param ?someparam   => 
http://server/foo/bar?someparam
  http://server/foo/bar //other/url  => 
http://other/url
+ http://server/foo/bar ../other/url => 
http://server/other/url
+ http://server/foo/bar other/url => 
http://server/foo/other/url
  http://server/foo/bar ../../../../../other/url => 
http://server/other/url
+ http://server/foo/bar 
../../../../../other/url/test..mp3 => http://server/other/url/test..mp3
+ http://server/foo/bar 
../../../../../other/url/test.. => http://server/other/url/test..
+ http://server/foo/bar 
../../../../../other/url/test/... => http://server/other/url/test/...
+ http://server/foo/bar 
../../../../../other/url/.../test/out => http://server/other/url/.../test/out
+ http://server/foo/bar 
../../../../../other/url/.../../test/out => http://server/other/url/test/out
+ http://server/foo/bar 
../../../../../other/url/.../..test/out => 
http://server/other/url/.../..test/out
+ http://server/foo/bar ../../../../../other/url/.. 
=> http://server/other
+ http://server/foo/bar 
../../../../../other/url/..mp3 => http://server/other/url/..mp3
+ http://server/foo/bar 
../../../../../other/url/..test/mp3 => http://server/other/url/..test/mp3
+ http://server/foo/bar 
../../../../../other/url/test../mp3 => http://server/other/url/test../mp3
  http://server/foo/bar /../../../../../other/url 
=> http://server/other/url
  http://server/foo/bar 
/test/../../../../../other/url => http://server/other/url
  http://server/foo/bar 
/test/../../test/../../../other/url => http://server/other/url
-- 
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".

[FFmpeg-devel] [PATCH v3 1/2] avformat/url: rework for trim_double_dot_url

2020-07-27 Thread Steven Liu
use two buffer for storage the path and node of URI
remove the last node of the path if the next node is ..
change the static strings to dynamic alloc space by size argument.

Signed-off-by: Steven Liu 
---
 libavformat/url.c | 83 ---
 1 file changed, 64 insertions(+), 19 deletions(-)

diff --git a/libavformat/url.c b/libavformat/url.c
index 20463a6674..4fb703de78 100644
--- a/libavformat/url.c
+++ b/libavformat/url.c
@@ -82,41 +82,78 @@ static void trim_double_dot_url(char *buf, const char *rel, 
int size)
 {
 const char *p = rel;
 const char *root = rel;
-char tmp_path[MAX_URL_SIZE] = {0, };
+char *tmp_path = NULL;
+char *second_buf = NULL;
+char *first_buf = NULL;
 char *sep;
 char *node;
 
+tmp_path = av_mallocz(size);
+if (!tmp_path)
+return;
+
+second_buf = av_mallocz(size);
+if (!second_buf)
+goto fail;
+
+first_buf = av_mallocz(size);
+if (!first_buf)
+goto fail;
+
 /* Get the path root of the url which start by "://" */
 if (p && (sep = strstr(p, "://"))) {
 sep += 3;
 root = strchr(sep, '/');
 if (!root)
-return;
+goto fail;
 }
+av_strlcat(tmp_path, p, root - p + 1);
 
 /* set new current position if the root node is changed */
 p = root;
-while (p && (node = strstr(p, ".."))) {
-av_strlcat(tmp_path, p, node - p + strlen(tmp_path));
-p = node + 3;
-sep = strrchr(tmp_path, '/');
+if (*p == '/')
+p++;
+while (p && (node = strchr(p, '/'))) {
+av_strlcpy(second_buf, p, node - p + 1);
+p = node + 1;
+if (!strcmp(second_buf, "..")) {
+if (strlen(first_buf) <= 0)
+continue;
+sep = strrchr(first_buf, '/');
+if (sep)
+sep[0] = '\0';
+else
+memset(first_buf, 0, size);
+
+memset(second_buf, 0, size);
+} else {
+av_strlcat(first_buf, "/", size);
+av_strlcat(first_buf, second_buf, size);
+}
+}
+if (!strcmp(p, "..")) {
+sep = strrchr(first_buf, '/');
 if (sep)
 sep[0] = '\0';
 else
-tmp_path[0] = '\0';
+memset(first_buf, 0, size);
+} else {
+av_strlcat(first_buf, "/", size);
+av_strlcat(first_buf, p, size);
 }
 
-if (!av_stristart(p, "/", NULL) && root != rel)
-av_strlcat(tmp_path, "/", size);
-
-av_strlcat(tmp_path, p, size);
-/* start set buf after temp path process. */
-av_strlcpy(buf, rel, root - rel + 1);
-
-if (!av_stristart(tmp_path, "/", NULL) && root != rel)
-av_strlcat(buf, "/", size);
+if (p > root) {
+av_strlcat(tmp_path, first_buf, size);
+} else {
+av_strlcat(tmp_path, p, size);
+}
 
 av_strlcat(buf, tmp_path, size);
+
+fail:
+av_free(second_buf);
+av_free(first_buf);
+av_free(tmp_path);
 }
 
 void ff_make_absolute_url(char *buf, int size, const char *base,
@@ -124,9 +161,11 @@ void ff_make_absolute_url(char *buf, int size, const char 
*base,
 {
 char *sep, *path_query;
 char *root, *p;
-char tmp_path[MAX_URL_SIZE];
+char *tmp_path = av_mallocz(size);
+
+if (!tmp_path)
+return;
 
-memset(tmp_path, 0, sizeof(tmp_path));
 /* Absolute path, relative to the current server */
 if (base && strstr(base, "://") && rel[0] == '/') {
 if (base != buf)
@@ -148,12 +187,14 @@ void ff_make_absolute_url(char *buf, int size, const char 
*base,
 trim_double_dot_url(tmp_path, buf, size);
 memset(buf, 0, size);
 av_strlcpy(buf, tmp_path, size);
+av_free(tmp_path);
 return;
 }
 /* If rel actually is an absolute url, just copy it */
 if (!base || strstr(rel, "://") || rel[0] == '/') {
 memset(buf, 0, size);
 trim_double_dot_url(buf, rel, size);
+av_free(tmp_path);
 return;
 }
 if (base != buf)
@@ -170,6 +211,7 @@ void ff_make_absolute_url(char *buf, int size, const char 
*base,
 trim_double_dot_url(tmp_path, buf, size);
 memset(buf, 0, size);
 av_strlcpy(buf, tmp_path, size);
+av_free(tmp_path);
 return;
 }
 
@@ -180,8 +222,10 @@ void ff_make_absolute_url(char *buf, int size, const char 
*base,
 if (sep) {
 sep += 3;
 root = strchr(sep, '/');
-if (!root)
+if (!root) {
+av_free(tmp_path);
 return;
+}
 }
 }
 
@@ -218,6 +262,7 @@ void ff_make_absolute_url(char *buf, int size, const char 
*base,
 trim_double_dot_url(tmp_path, buf, size);
 memset(buf, 0, size);
 av_strlcpy(buf, tmp_path, size);
+av_free(tmp_path);
 }
 
 AVIODirEntry *ff_alloc_dir_entry(void)
-- 
2.25.0



___
ffmpeg-devel mailing 

Re: [FFmpeg-devel] working with file descriptors on Android

2020-07-27 Thread Alex Cohn
Thanks Olivier,

Custom IO looks like a nice way to work around the protocol
limitations. Unfortunately, it cannot work with avio_open(), so the
API becomes trickier for end users.

Also, just like with pipes, I cannot reliably close the file
descriptor when ffmpeg execution is over, can I?

BR,
Alex Cohn

On Mon, Jul 27, 2020 at 11:01 AM Olivier Ayache
 wrote:
>
> A good alternative to work with FFmpeg on Android is Xuggler, it presents
> FFmpeg's API directly to Java/Kotlin.
>
> To deal with fd you can declare and implement your own IO handler by
> implementing
> https://github.com/olivierayache/xuggle-xuggler/blob/ffmpeg-3.x-dev/src/com/xuggle/xuggler/io/IURLProtocolHandler.java
>
> I currently maintain a fork which is fully working on Android (work in
> progress for iOS with Kotlin multiplatform).
>
> https://github.com/olivierayache/xuggle-xuggler
>
> Best
>
> Olivier Ayache
>
> Le dim. 26 juil. 2020 à 23:16, Alex Cohn  a
> écrit :
>
> > On Sun, Jul 26, 2020 at 10:21 PM Martin Storsjö  wrote:
> > >
> > > Hi,
> > >
> > > Without having too much opinion on the JNI stuff (direct access to
> > > content:// urls might be convenient, but on the other hand, it's not
> > > really something you'd end up with if using the command line tool on its
> > > own - if you have one of those you most probably have some java code for
> > > getting it anyway - as far as I remember...)
> >
> >
> > You are more than right, Martin.
> >
> > None of these approaches can work with a command line tool. Worse,
> > running a command line tool in the context of an Android app is
> > becoming trickier with every new release of the platform, and in this
> > case I cannot blame it on poor engineering. This happens because
> > Google tries to tighten the security on Android just as much as
> > possible.
> >
> > There is a nice cross-platform alternative, though.
> > https://github.com/tanersener/mobile-ffmpeg provides Java and
> > Objective-C APIs to run ffmpeg shared library "as if it were an
> > executable": it can receive the input as a string which mimics the
> > ffmpeg (and ffprobe) command line, and the output to stdout and stderr
> > is captured and passed back to the mobile app. In this scenario, it's
> > easy to get a `content:` URI by conventional Android SAF (structured
> > access framework) API in Java and pass it as string or as a derived
> > file descriptor (converted to string) to the command line parser that
> > will eventually call protocol->url_open().
> >
> > The latest release (Android Q a.k.a. Android 10, also API 29) made yet
> > another small step in this direction and caused lots of problems for
> > apps that rely upon file access by path. This was the incentive for me
> > to work on the ways to teach avformat to work with the `content:` URIs
> > correctly.
> >
> > BR,
> > Alex Cohn
> > ___
> > 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 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 1/2] avformat/url: fix logic for removing ".." path components

2020-07-27 Thread Josef Zlomek
Fixes: 8814

The logic for removing ".." path components and their corresponding
upper directories was reworked.

Now, the function trim_double_dot_url splits the path by "/" into
components, and processes the components one ny one:
- if the component is "..", the last path component in tmp_path is removed
- if the component is not empty, it is added to tmp_path

The duplicate logic was removed from ff_make_absolute_url.

Signed-off-by: Josef Zlomek 
---
 libavformat/url.c | 90 ++-
 1 file changed, 43 insertions(+), 47 deletions(-)

diff --git a/libavformat/url.c b/libavformat/url.c
index 20463a6674..343cbca9b9 100644
--- a/libavformat/url.c
+++ b/libavformat/url.c
@@ -83,8 +83,10 @@ static void trim_double_dot_url(char *buf, const char *rel, 
int size)
 const char *p = rel;
 const char *root = rel;
 char tmp_path[MAX_URL_SIZE] = {0, };
-char *sep;
-char *node;
+int tmp_len = 0;
+const char *sep;
+const char *next;
+int last_is_dir;
 
 /* Get the path root of the url which start by "://" */
 if (p && (sep = strstr(p, "://"))) {
@@ -93,29 +95,45 @@ static void trim_double_dot_url(char *buf, const char *rel, 
int size)
 if (!root)
 return;
 }
+if (*root == '/')
+++root;
+
+/* Split the path by "/" and remove ".." and its corresponding directory. 
*/
+last_is_dir = 1;
+for (p = root; *p; p = next) {
+next = strchr(p, '/');
+if (!next) {
+next = p + strlen(p);
+last_is_dir = 0;
+}
 
-/* set new current position if the root node is changed */
-p = root;
-while (p && (node = strstr(p, ".."))) {
-av_strlcat(tmp_path, p, node - p + strlen(tmp_path));
-p = node + 3;
-sep = strrchr(tmp_path, '/');
-if (sep)
-sep[0] = '\0';
-else
-tmp_path[0] = '\0';
-}
+if (next - p == 2 && !strncmp(p, "..", 2)) {
+/* remove the last directory from tmp_path */
+while (tmp_len > 0 && tmp_path[--tmp_len] != '/')
+;
+tmp_path[tmp_len] = '\0';
+last_is_dir = 1;
+} else if (next > p) {
+/* copy the current path component to tmp_path (including '/') */
+if (tmp_len) {
+av_strlcpy(tmp_path + tmp_len, "/", sizeof(tmp_path) - 
tmp_len);
+++tmp_len;
+}
+av_strlcpy(tmp_path + tmp_len, p, FFMIN(sizeof(tmp_path) - tmp_len,
+next - p + 1));
+tmp_len += next - p;
+tmp_path[tmp_len] = '\0';
+}
 
-if (!av_stristart(p, "/", NULL) && root != rel)
-av_strlcat(tmp_path, "/", size);
+/* skip "/" */
+while (*next == '/')
+++next;
+}
+if (last_is_dir && tmp_len)
+av_strlcpy(tmp_path + tmp_len, "/", sizeof(tmp_path) - tmp_len);
 
-av_strlcat(tmp_path, p, size);
 /* start set buf after temp path process. */
 av_strlcpy(buf, rel, root - rel + 1);
-
-if (!av_stristart(tmp_path, "/", NULL) && root != rel)
-av_strlcat(buf, "/", size);
-
 av_strlcat(buf, tmp_path, size);
 }
 
@@ -175,14 +193,11 @@ void ff_make_absolute_url(char *buf, int size, const char 
*base,
 
 root = p = buf;
 /* Get the path root of the url which start by "://" */
-if (p && strstr(p, "://")) {
-sep = strstr(p, "://");
-if (sep) {
-sep += 3;
-root = strchr(sep, '/');
-if (!root)
-return;
-}
+if (p && (sep = strstr(p, "://"))) {
+sep += 3;
+root = strchr(sep, '/');
+if (!root)
+return;
 }
 
 /* Remove the file name from the base url */
@@ -194,26 +209,7 @@ void ff_make_absolute_url(char *buf, int size, const char 
*base,
 sep[1] = '\0';
 else
 buf[0] = '\0';
-while (av_strstart(rel, "..", NULL) && sep) {
-/* Remove the path delimiter at the end */
-if (sep > root) {
-sep[0] = '\0';
-sep = strrchr(buf, '/');
-}
 
-/* If the next directory name to pop off is "..", break here */
-if (!strcmp(sep ? [1] : buf, "..")) {
-/* Readd the slash we just removed */
-av_strlcat(buf, "/", size);
-break;
-}
-/* Cut off the directory name */
-if (sep)
-sep[1] = '\0';
-else
-buf[0] = '\0';
-rel += 3;
-}
 av_strlcat(buf, rel, size);
 trim_double_dot_url(tmp_path, buf, size);
 memset(buf, 0, size);
-- 
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 v2 2/2] avformat/tests/url: add test cases for handling of double dot

2020-07-27 Thread Josef Zlomek
Signed-off-by: Josef Zlomek 
---
 libavformat/tests/url.c | 6 ++
 tests/ref/fate/url  | 6 ++
 2 files changed, 12 insertions(+)

diff --git a/libavformat/tests/url.c b/libavformat/tests/url.c
index 1d961a1b43..a27a875892 100644
--- a/libavformat/tests/url.c
+++ b/libavformat/tests/url.c
@@ -57,6 +57,8 @@ int main(void)
 test("/foo/bar", "../baz");
 test("/foo/bar", "/baz");
 test("/foo/bar", "../../../baz");
+test("/foo/bar", "..");
+test("/foo/bar/baz", "..");
 test("http://server/foo/;, "baz");
 test("http://server/foo/bar;, "baz");
 test("http://server/foo/;, "../baz");
@@ -67,6 +69,10 @@ int main(void)
 test("http://server/foo/bar?param;, "?someparam");
 test("http://server/foo/bar;, "//other/url");
 test("http://server/foo/bar;, "../../../../../other/url");
+test("http://server/foo/bar;, 
"a/b/../c/d/../e../..f/.../other/url/test..mp3");
+test("http://server/foo/bar;, 
"/a/b/../c/d/../e../..f/.../other/url/test..mp3");
+test("http://server/foo/bar;, "a/b/../c/d/../e../..f/.../other/url/..");
+test("http://server/foo/bar;, "a/b/../c/d/../e../..f/.../other/url/");
 test("http://server/foo/bar;, "/../../../../../other/url");
 test("http://server/foo/bar;, "/test/../../../../../other/url");
 test("http://server/foo/bar;, "/test/../../test/../../../other/url");
diff --git a/tests/ref/fate/url b/tests/ref/fate/url
index 533ba2cb1e..aa53e09fab 100644
--- a/tests/ref/fate/url
+++ b/tests/ref/fate/url
@@ -4,6 +4,8 @@ Testing ff_make_absolute_url:
   /foo/bar ../baz   => /baz
   /foo/bar /baz => /baz
   /foo/bar ../../../baz => /baz
+  /foo/bar ..   => /
+  /foo/bar/baz ..   => 
/foo/
 http://server/foo/ baz  => 
http://server/foo/baz
  http://server/foo/bar baz  => 
http://server/foo/baz
 http://server/foo/ ../baz   => 
http://server/baz
@@ -14,6 +16,10 @@ Testing ff_make_absolute_url:
 http://server/foo/bar?param ?someparam   => 
http://server/foo/bar?someparam
  http://server/foo/bar //other/url  => 
http://other/url
  http://server/foo/bar ../../../../../other/url => 
http://server/other/url
+ http://server/foo/bar 
a/b/../c/d/../e../..f/.../other/url/test..mp3 => 
http://server/foo/a/c/e../..f/.../other/url/test..mp3
+ http://server/foo/bar 
/a/b/../c/d/../e../..f/.../other/url/test..mp3 => 
http://server/a/c/e../..f/.../other/url/test..mp3
+ http://server/foo/bar 
a/b/../c/d/../e../..f/.../other/url/.. => 
http://server/foo/a/c/e../..f/.../other/
+ http://server/foo/bar 
a/b/../c/d/../e../..f/.../other/url/ => 
http://server/foo/a/c/e../..f/.../other/url/
  http://server/foo/bar /../../../../../other/url 
=> http://server/other/url
  http://server/foo/bar 
/test/../../../../../other/url => http://server/other/url
  http://server/foo/bar 
/test/../../test/../../../other/url => http://server/other/url
-- 
2.17.1

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

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

Re: [FFmpeg-devel] [PATCH 1/3] avformat/url: fix logic for removing ".." path components

2020-07-27 Thread Zlomek, Josef
If your code is correct then good.

I also resubmit improved version.

Josef

On Mon, Jul 27, 2020 at 2:05 PM Steven Liu  wrote:

> Zlomek, Josef  于2020年7月27日周一 下午7:45写道:
> >
> > Hi Steven,
> >
> > ".." is always a directory.
> >
> > your tests (diff starting with -) are not correct.
> > My results (lines starting with +) are correct.
> >
> > Josef
> >
> > On Mon, Jul 27, 2020 at 1:36 PM Steven Liu 
> wrote:
> >>
> >> Josef Zlomek  于2020年7月27日周一 下午6:57写道:
> >> >
> >> > Fixes: 8814
> >> >
> >> > The logic for removing ".." path components and their corresponding
> >> > upper directories was reworked.
> >> >
> >> > Now, the function trim_double_dot_url splits the path by "/" into
> >> > components, and processes the components one ny one:
> >> > - if the component is "..", the last path component in tmp_path is
> removed
> >> > - if the component is not empty, it is added to tmp_path
> >> >
> >> > The duplicate logic was removed from ff_make_absolute_url.
> >> >
> >> > Signed-off-by: Josef Zlomek 
> >> > ---
> >> >  libavformat/url.c | 70
> +--
> >> >  1 file changed, 31 insertions(+), 39 deletions(-)
> >> >
> >> > diff --git a/libavformat/url.c b/libavformat/url.c
> >> > index 20463a6674..ccaa28a1ed 100644
> >> > --- a/libavformat/url.c
> >> > +++ b/libavformat/url.c
> >> > @@ -83,8 +83,9 @@ static void trim_double_dot_url(char *buf, const
> char *rel, int size)
> >> >  const char *p = rel;
> >> >  const char *root = rel;
> >> >  char tmp_path[MAX_URL_SIZE] = {0, };
> >> > -char *sep;
> >> > -char *node;
> >> > +int tmp_len = 0;
> >> > +const char *sep;
> >> > +const char *next;
> >> >
> >> >  /* Get the path root of the url which start by "://" */
> >> >  if (p && (sep = strstr(p, "://"))) {
> >> > @@ -93,29 +94,39 @@ static void trim_double_dot_url(char *buf, const
> char *rel, int size)
> >> >  if (!root)
> >> >  return;
> >> >  }
> >> > +if (*root == '/')
> >> > +++root;
> >> > +
> >> > +/* Split the path by "/" and remove ".." and its corresponding
> directory. */
> >> > +for (p = root; *p; p = next) {
> >> > +next = strchr(p, '/');
> >> > +if (!next)
> >> > +next = p + strlen(p);
> >> > +
> >> > +if (next - p == 2 && !strncmp(p, "..", 2)) {
> >> > +/* remove the last directory from tmp_path */
> >> > +while (tmp_len > 0 && tmp_path[--tmp_len] != '/')
> >> > +;
> >> > +tmp_path[tmp_len] = '\0';
> >> > +} else if (next > p) {
> >> > +/* copy the current path component to tmp_path
> (including '/') */
> >> > +if (tmp_len) {
> >> > +av_strlcpy(tmp_path + tmp_len, "/", sizeof(tmp_path)
> - tmp_len);
> >> > +++tmp_len;
> >> > +}
> >> > +av_strlcpy(tmp_path + tmp_len, p, FFMIN(sizeof(tmp_path)
> - tmp_len,
> >> > +next - p + 1));
> >> > +tmp_len += next - p;
> >> > +tmp_path[tmp_len] = '\0';
> >> > +}
> And I think only one loop is ok than this way.
> I will resubmit a new patch, maybe that is simpler than yours.
> >> >
> >> > -/* set new current position if the root node is changed */
> >> > -p = root;
> >> > -while (p && (node = strstr(p, ".."))) {
> >> > -av_strlcat(tmp_path, p, node - p + strlen(tmp_path));
> >> > -p = node + 3;
> >> > -sep = strrchr(tmp_path, '/');
> >> > -if (sep)
> >> > -sep[0] = '\0';
> >> > -else
> >> > -tmp_path[0] = '\0';
> >> > +/* skip "/" */
> >> > +while (*next == '/')
> >> > +++next;
> >> >  }
> >> >
> >> > -if (!av_stristart(p, "/", NULL) && root != rel)
> >> > -av_strlcat(tmp_path, "/", size);
> >> > -
> >> > -av_strlcat(tmp_path, p, size);
> >> >  /* start set buf after temp path process. */
> >> >  av_strlcpy(buf, rel, root - rel + 1);
> >> > -
> >> > -if (!av_stristart(tmp_path, "/", NULL) && root != rel)
> >> > -av_strlcat(buf, "/", size);
> >> > -
> >> >  av_strlcat(buf, tmp_path, size);
> >> >  }
> >> >
> >> > @@ -194,26 +205,7 @@ void ff_make_absolute_url(char *buf, int size,
> const char *base,
> >> >  sep[1] = '\0';
> >> >  else
> >> >  buf[0] = '\0';
> >> > -while (av_strstart(rel, "..", NULL) && sep) {
> >> > -/* Remove the path delimiter at the end */
> >> > -if (sep > root) {
> >> > -sep[0] = '\0';
> >> > -sep = strrchr(buf, '/');
> >> > -}
> >> >
> >> > -/* If the next directory name to pop off is "..", break here
> */
> >> > -if (!strcmp(sep ? [1] : buf, "..")) {
> >> > -/* Readd the slash we just removed */
> >> > -av_strlcat(buf, "/", size);
> >> > -break;
> >> > -}
> >> > -/* Cut off the 

Re: [FFmpeg-devel] [PATCH] avcodec/jpeg2000dec: Move reslevelno check before use in case JPEG2000_PGOD_RPCL

2020-07-27 Thread Gautam Ramakrishnan
On Mon, Jul 27, 2020 at 1:46 PM Michael Niedermayer
 wrote:
>
> On Mon, Jul 27, 2020 at 09:55:31AM +0530, Gautam Ramakrishnan wrote:
> > On Mon, Jul 27, 2020 at 9:48 AM Gautam Ramakrishnan
> >  wrote:
> > >
> > > On Mon, Jul 27, 2020 at 3:16 AM Michael Niedermayer
> > >  wrote:
> > > >
> > > > Fixes: division by zero
> > > > Fixes: 
> > > > 24201/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5665813827420160
> > > > Fixes: 
> > > > 24245/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-6285831682392064
> > > >
> > > > Found-by: continuous fuzzing process 
> > > > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > > > Signed-off-by: Michael Niedermayer 
> > > > ---
> > > >  libavcodec/jpeg2000dec.c | 6 +++---
> > > >  1 file changed, 3 insertions(+), 3 deletions(-)
> > > >
> > > > diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
> > > > index a470cf47da..b168e52db6 100644
> > > > --- a/libavcodec/jpeg2000dec.c
> > > > +++ b/libavcodec/jpeg2000dec.c
> > > > @@ -1401,12 +1401,12 @@ static int 
> > > > jpeg2000_decode_packets_po_iteration(Jpeg2000DecoderContext *s, Jpeg2
> > > >  if (!s->cdx[compno] || !s->cdy[compno])
> > > >  return AVERROR_INVALIDDATA;
> > > >
> > > > -trx0 = ff_jpeg2000_ceildiv(tile->coord[0][0], 
> > > > s->cdx[compno] << reducedresno);
> > > > -try0 = ff_jpeg2000_ceildiv(tile->coord[1][0], 
> > > > s->cdy[compno] << reducedresno);
> > > > -
> > > >  if (reslevelno >= codsty->nreslevels)
> > > >  continue;
> > > >
> > > > +trx0 = ff_jpeg2000_ceildiv(tile->coord[0][0], 
> > > > s->cdx[compno] << reducedresno);
> > > > +try0 = ff_jpeg2000_ceildiv(tile->coord[1][0], 
> > > > s->cdy[compno] << reducedresno);
> > > > +
> > > >  if (!(y % ((uint64_t)s->cdy[compno] << 
> > > > (rlevel->log2_prec_height + reducedresno)) == 0 ||
> > > >   (y == tile->coord[1][0] && (try0 << 
> > > > reducedresno) % (1U << (reducedresno + rlevel->log2_prec_height)
> > > >  continue;
> > > > --
> > > > 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".
> > >
> > > Looks good to me.
> > > I guess the division by zero happens because shifting by reducedresno
> > > overflows?
>
> yes
>
> > >
> > > --
> > > -
> > > Gautam |
> > Just realized, this might happen in one more place, shall send a
> > patch for the same.
>
> yes
Went through the code again, looks like this would not occur in other cases.
The other loops take into account whether reslvlno < codsty->nreslevels

I think this might be the only patch necessary
>
> thx
>
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Dictatorship naturally arises out of democracy, and the most aggravated
> form of tyranny and slavery out of the most extreme liberty. -- Plato
> ___
> 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 1/3] avformat/url: fix logic for removing ".." path components

2020-07-27 Thread Steven Liu
Zlomek, Josef  于2020年7月27日周一 下午7:45写道:
>
> Hi Steven,
>
> ".." is always a directory.
>
> your tests (diff starting with -) are not correct.
> My results (lines starting with +) are correct.
>
> Josef
>
> On Mon, Jul 27, 2020 at 1:36 PM Steven Liu  wrote:
>>
>> Josef Zlomek  于2020年7月27日周一 下午6:57写道:
>> >
>> > Fixes: 8814
>> >
>> > The logic for removing ".." path components and their corresponding
>> > upper directories was reworked.
>> >
>> > Now, the function trim_double_dot_url splits the path by "/" into
>> > components, and processes the components one ny one:
>> > - if the component is "..", the last path component in tmp_path is removed
>> > - if the component is not empty, it is added to tmp_path
>> >
>> > The duplicate logic was removed from ff_make_absolute_url.
>> >
>> > Signed-off-by: Josef Zlomek 
>> > ---
>> >  libavformat/url.c | 70 +--
>> >  1 file changed, 31 insertions(+), 39 deletions(-)
>> >
>> > diff --git a/libavformat/url.c b/libavformat/url.c
>> > index 20463a6674..ccaa28a1ed 100644
>> > --- a/libavformat/url.c
>> > +++ b/libavformat/url.c
>> > @@ -83,8 +83,9 @@ static void trim_double_dot_url(char *buf, const char 
>> > *rel, int size)
>> >  const char *p = rel;
>> >  const char *root = rel;
>> >  char tmp_path[MAX_URL_SIZE] = {0, };
>> > -char *sep;
>> > -char *node;
>> > +int tmp_len = 0;
>> > +const char *sep;
>> > +const char *next;
>> >
>> >  /* Get the path root of the url which start by "://" */
>> >  if (p && (sep = strstr(p, "://"))) {
>> > @@ -93,29 +94,39 @@ static void trim_double_dot_url(char *buf, const char 
>> > *rel, int size)
>> >  if (!root)
>> >  return;
>> >  }
>> > +if (*root == '/')
>> > +++root;
>> > +
>> > +/* Split the path by "/" and remove ".." and its corresponding 
>> > directory. */
>> > +for (p = root; *p; p = next) {
>> > +next = strchr(p, '/');
>> > +if (!next)
>> > +next = p + strlen(p);
>> > +
>> > +if (next - p == 2 && !strncmp(p, "..", 2)) {
>> > +/* remove the last directory from tmp_path */
>> > +while (tmp_len > 0 && tmp_path[--tmp_len] != '/')
>> > +;
>> > +tmp_path[tmp_len] = '\0';
>> > +} else if (next > p) {
>> > +/* copy the current path component to tmp_path (including 
>> > '/') */
>> > +if (tmp_len) {
>> > +av_strlcpy(tmp_path + tmp_len, "/", sizeof(tmp_path) - 
>> > tmp_len);
>> > +++tmp_len;
>> > +}
>> > +av_strlcpy(tmp_path + tmp_len, p, FFMIN(sizeof(tmp_path) - 
>> > tmp_len,
>> > +next - p + 1));
>> > +tmp_len += next - p;
>> > +tmp_path[tmp_len] = '\0';
>> > +}
And I think only one loop is ok than this way.
I will resubmit a new patch, maybe that is simpler than yours.
>> >
>> > -/* set new current position if the root node is changed */
>> > -p = root;
>> > -while (p && (node = strstr(p, ".."))) {
>> > -av_strlcat(tmp_path, p, node - p + strlen(tmp_path));
>> > -p = node + 3;
>> > -sep = strrchr(tmp_path, '/');
>> > -if (sep)
>> > -sep[0] = '\0';
>> > -else
>> > -tmp_path[0] = '\0';
>> > +/* skip "/" */
>> > +while (*next == '/')
>> > +++next;
>> >  }
>> >
>> > -if (!av_stristart(p, "/", NULL) && root != rel)
>> > -av_strlcat(tmp_path, "/", size);
>> > -
>> > -av_strlcat(tmp_path, p, size);
>> >  /* start set buf after temp path process. */
>> >  av_strlcpy(buf, rel, root - rel + 1);
>> > -
>> > -if (!av_stristart(tmp_path, "/", NULL) && root != rel)
>> > -av_strlcat(buf, "/", size);
>> > -
>> >  av_strlcat(buf, tmp_path, size);
>> >  }
>> >
>> > @@ -194,26 +205,7 @@ void ff_make_absolute_url(char *buf, int size, const 
>> > char *base,
>> >  sep[1] = '\0';
>> >  else
>> >  buf[0] = '\0';
>> > -while (av_strstart(rel, "..", NULL) && sep) {
>> > -/* Remove the path delimiter at the end */
>> > -if (sep > root) {
>> > -sep[0] = '\0';
>> > -sep = strrchr(buf, '/');
>> > -}
>> >
>> > -/* If the next directory name to pop off is "..", break here */
>> > -if (!strcmp(sep ? [1] : buf, "..")) {
>> > -/* Readd the slash we just removed */
>> > -av_strlcat(buf, "/", size);
>> > -break;
>> > -}
>> > -/* Cut off the directory name */
>> > -if (sep)
>> > -sep[1] = '\0';
>> > -else
>> > -buf[0] = '\0';
>> > -rel += 3;
>> > -}
>> >  av_strlcat(buf, rel, size);
>> >  trim_double_dot_url(tmp_path, buf, size);
>> >  memset(buf, 0, size);
>> > --
>> > 2.17.1
>> >
>> > ___
>> > 

Re: [FFmpeg-devel] [PATCH 3/3] avformat/url: remove duplicate call to strstr

2020-07-27 Thread Zlomek, Josef
I also noticed that the 3rd part did not make it to patchwork.
Maybe it is because it modifies the same file. I will squash it with the
first part.

Josef

On Mon, Jul 27, 2020 at 1:36 PM Steven Liu  wrote:

> Josef Zlomek  于2020年7月27日周一 下午6:57写道:
> >
> > Signed-off-by: Josef Zlomek 
> > ---
> >  libavformat/url.c | 13 +
> >  1 file changed, 5 insertions(+), 8 deletions(-)
> >
> > diff --git a/libavformat/url.c b/libavformat/url.c
> > index ccaa28a1ed..28d12fd3de 100644
> > --- a/libavformat/url.c
> > +++ b/libavformat/url.c
> > @@ -186,14 +186,11 @@ void ff_make_absolute_url(char *buf, int size,
> const char *base,
> >
> >  root = p = buf;
> >  /* Get the path root of the url which start by "://" */
> > -if (p && strstr(p, "://")) {
> > -sep = strstr(p, "://");
> > -if (sep) {
> > -sep += 3;
> > -root = strchr(sep, '/');
> > -if (!root)
> > -return;
> > -}
> > +if (p && (sep = strstr(p, "://"))) {
> > +sep += 3;
> > +root = strchr(sep, '/');
> > +if (!root)
> > +return;
> >  }
> >
> >  /* Remove the file name from the base url */
> > --
> > 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".
>
> this patch cannot get from:
> https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=1869
>
>
> Thanks
> Steven
>


-- 
Josef Zlomek
___
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] lavf/srt: fix build fail when used the libsrt 1.4.1

2020-07-27 Thread myp...@gmail.com
On Sat, Jul 18, 2020 at 8:31 PM myp...@gmail.com  wrote:
>
> On Thu, Jul 16, 2020 at 9:35 AM myp...@gmail.com  wrote:
> >
> > On Tue, Jul 14, 2020 at 9:47 PM Moritz Barsnick  wrote:
> > >
> > > On Sun, Jul 12, 2020 at 22:44:46 +0800, myp...@gmail.com wrote:
> > > > Maybe I give an inaccurate description in the commit message, in fact,
> > > > libsrt 1.4.1 remove the SRTO_STRICTENC/SRTO_SMOOTHER option, it's will
> > > > lead to FFmpeg build fail when using libsrt  version >= 1.4.1
> > >
> > > I don't mind you description. Yet your code change references 1.4.1:
> > > SRT_VERSION_VALUE >= 0x010401
> > > while I am trying to make the point that 1.4.0 also needs this change
> > > (or 1.3.0 in one case, which is already ensured by #if).
> > >
> >
> > After double-check, I think the patch is Ok, in fact, libsrt keeps the
> > deprecated SRTO_STRICTENC/SRTO_SMOOTHER options in srt.h (inclued the
> > options in libsrt 1.3.3/1.3.4/1.4.0) until commit
> > 0e2201aff6b379979cec43fee5e8f162717f6346 , so FFmpeg build with libsrt
> > 1.3.3/1.3.4/1.4.0 is OK with the patch.
> Ping
I'll apply it tomorrow if don't object, thx
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH 1/3] avformat/url: fix logic for removing ".." path components

2020-07-27 Thread Zlomek, Josef
Hi Steven,

".." is always a directory.

your tests (diff starting with -) are not correct.
My results (lines starting with +) are correct.

Josef

On Mon, Jul 27, 2020 at 1:36 PM Steven Liu  wrote:

> Josef Zlomek  于2020年7月27日周一 下午6:57写道:
> >
> > Fixes: 8814
> >
> > The logic for removing ".." path components and their corresponding
> > upper directories was reworked.
> >
> > Now, the function trim_double_dot_url splits the path by "/" into
> > components, and processes the components one ny one:
> > - if the component is "..", the last path component in tmp_path is
> removed
> > - if the component is not empty, it is added to tmp_path
> >
> > The duplicate logic was removed from ff_make_absolute_url.
> >
> > Signed-off-by: Josef Zlomek 
> > ---
> >  libavformat/url.c | 70 +--
> >  1 file changed, 31 insertions(+), 39 deletions(-)
> >
> > diff --git a/libavformat/url.c b/libavformat/url.c
> > index 20463a6674..ccaa28a1ed 100644
> > --- a/libavformat/url.c
> > +++ b/libavformat/url.c
> > @@ -83,8 +83,9 @@ static void trim_double_dot_url(char *buf, const char
> *rel, int size)
> >  const char *p = rel;
> >  const char *root = rel;
> >  char tmp_path[MAX_URL_SIZE] = {0, };
> > -char *sep;
> > -char *node;
> > +int tmp_len = 0;
> > +const char *sep;
> > +const char *next;
> >
> >  /* Get the path root of the url which start by "://" */
> >  if (p && (sep = strstr(p, "://"))) {
> > @@ -93,29 +94,39 @@ static void trim_double_dot_url(char *buf, const
> char *rel, int size)
> >  if (!root)
> >  return;
> >  }
> > +if (*root == '/')
> > +++root;
> > +
> > +/* Split the path by "/" and remove ".." and its corresponding
> directory. */
> > +for (p = root; *p; p = next) {
> > +next = strchr(p, '/');
> > +if (!next)
> > +next = p + strlen(p);
> > +
> > +if (next - p == 2 && !strncmp(p, "..", 2)) {
> > +/* remove the last directory from tmp_path */
> > +while (tmp_len > 0 && tmp_path[--tmp_len] != '/')
> > +;
> > +tmp_path[tmp_len] = '\0';
> > +} else if (next > p) {
> > +/* copy the current path component to tmp_path (including
> '/') */
> > +if (tmp_len) {
> > +av_strlcpy(tmp_path + tmp_len, "/", sizeof(tmp_path) -
> tmp_len);
> > +++tmp_len;
> > +}
> > +av_strlcpy(tmp_path + tmp_len, p, FFMIN(sizeof(tmp_path) -
> tmp_len,
> > +next - p + 1));
> > +tmp_len += next - p;
> > +tmp_path[tmp_len] = '\0';
> > +}
> >
> > -/* set new current position if the root node is changed */
> > -p = root;
> > -while (p && (node = strstr(p, ".."))) {
> > -av_strlcat(tmp_path, p, node - p + strlen(tmp_path));
> > -p = node + 3;
> > -sep = strrchr(tmp_path, '/');
> > -if (sep)
> > -sep[0] = '\0';
> > -else
> > -tmp_path[0] = '\0';
> > +/* skip "/" */
> > +while (*next == '/')
> > +++next;
> >  }
> >
> > -if (!av_stristart(p, "/", NULL) && root != rel)
> > -av_strlcat(tmp_path, "/", size);
> > -
> > -av_strlcat(tmp_path, p, size);
> >  /* start set buf after temp path process. */
> >  av_strlcpy(buf, rel, root - rel + 1);
> > -
> > -if (!av_stristart(tmp_path, "/", NULL) && root != rel)
> > -av_strlcat(buf, "/", size);
> > -
> >  av_strlcat(buf, tmp_path, size);
> >  }
> >
> > @@ -194,26 +205,7 @@ void ff_make_absolute_url(char *buf, int size,
> const char *base,
> >  sep[1] = '\0';
> >  else
> >  buf[0] = '\0';
> > -while (av_strstart(rel, "..", NULL) && sep) {
> > -/* Remove the path delimiter at the end */
> > -if (sep > root) {
> > -sep[0] = '\0';
> > -sep = strrchr(buf, '/');
> > -}
> >
> > -/* If the next directory name to pop off is "..", break here */
> > -if (!strcmp(sep ? [1] : buf, "..")) {
> > -/* Readd the slash we just removed */
> > -av_strlcat(buf, "/", size);
> > -break;
> > -}
> > -/* Cut off the directory name */
> > -if (sep)
> > -sep[1] = '\0';
> > -else
> > -buf[0] = '\0';
> > -rel += 3;
> > -}
> >  av_strlcat(buf, rel, size);
> >  trim_double_dot_url(tmp_path, buf, size);
> >  memset(buf, 0, size);
> > --
> > 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".
>
> maybe the last node is a file, not directory
>
> (base) liuqi05:clang liuqi$ make fate-url
> 

Re: [FFmpeg-devel] [PATCH 3/3] avformat/url: remove duplicate call to strstr

2020-07-27 Thread Steven Liu
Josef Zlomek  于2020年7月27日周一 下午6:57写道:
>
> Signed-off-by: Josef Zlomek 
> ---
>  libavformat/url.c | 13 +
>  1 file changed, 5 insertions(+), 8 deletions(-)
>
> diff --git a/libavformat/url.c b/libavformat/url.c
> index ccaa28a1ed..28d12fd3de 100644
> --- a/libavformat/url.c
> +++ b/libavformat/url.c
> @@ -186,14 +186,11 @@ void ff_make_absolute_url(char *buf, int size, const 
> char *base,
>
>  root = p = buf;
>  /* Get the path root of the url which start by "://" */
> -if (p && strstr(p, "://")) {
> -sep = strstr(p, "://");
> -if (sep) {
> -sep += 3;
> -root = strchr(sep, '/');
> -if (!root)
> -return;
> -}
> +if (p && (sep = strstr(p, "://"))) {
> +sep += 3;
> +root = strchr(sep, '/');
> +if (!root)
> +return;
>  }
>
>  /* Remove the file name from the base url */
> --
> 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".

this patch cannot get from:
https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=1869


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

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

Re: [FFmpeg-devel] [PATCH 1/3] avformat/url: fix logic for removing ".." path components

2020-07-27 Thread Steven Liu
Josef Zlomek  于2020年7月27日周一 下午6:57写道:
>
> Fixes: 8814
>
> The logic for removing ".." path components and their corresponding
> upper directories was reworked.
>
> Now, the function trim_double_dot_url splits the path by "/" into
> components, and processes the components one ny one:
> - if the component is "..", the last path component in tmp_path is removed
> - if the component is not empty, it is added to tmp_path
>
> The duplicate logic was removed from ff_make_absolute_url.
>
> Signed-off-by: Josef Zlomek 
> ---
>  libavformat/url.c | 70 +--
>  1 file changed, 31 insertions(+), 39 deletions(-)
>
> diff --git a/libavformat/url.c b/libavformat/url.c
> index 20463a6674..ccaa28a1ed 100644
> --- a/libavformat/url.c
> +++ b/libavformat/url.c
> @@ -83,8 +83,9 @@ static void trim_double_dot_url(char *buf, const char *rel, 
> int size)
>  const char *p = rel;
>  const char *root = rel;
>  char tmp_path[MAX_URL_SIZE] = {0, };
> -char *sep;
> -char *node;
> +int tmp_len = 0;
> +const char *sep;
> +const char *next;
>
>  /* Get the path root of the url which start by "://" */
>  if (p && (sep = strstr(p, "://"))) {
> @@ -93,29 +94,39 @@ static void trim_double_dot_url(char *buf, const char 
> *rel, int size)
>  if (!root)
>  return;
>  }
> +if (*root == '/')
> +++root;
> +
> +/* Split the path by "/" and remove ".." and its corresponding 
> directory. */
> +for (p = root; *p; p = next) {
> +next = strchr(p, '/');
> +if (!next)
> +next = p + strlen(p);
> +
> +if (next - p == 2 && !strncmp(p, "..", 2)) {
> +/* remove the last directory from tmp_path */
> +while (tmp_len > 0 && tmp_path[--tmp_len] != '/')
> +;
> +tmp_path[tmp_len] = '\0';
> +} else if (next > p) {
> +/* copy the current path component to tmp_path (including '/') */
> +if (tmp_len) {
> +av_strlcpy(tmp_path + tmp_len, "/", sizeof(tmp_path) - 
> tmp_len);
> +++tmp_len;
> +}
> +av_strlcpy(tmp_path + tmp_len, p, FFMIN(sizeof(tmp_path) - 
> tmp_len,
> +next - p + 1));
> +tmp_len += next - p;
> +tmp_path[tmp_len] = '\0';
> +}
>
> -/* set new current position if the root node is changed */
> -p = root;
> -while (p && (node = strstr(p, ".."))) {
> -av_strlcat(tmp_path, p, node - p + strlen(tmp_path));
> -p = node + 3;
> -sep = strrchr(tmp_path, '/');
> -if (sep)
> -sep[0] = '\0';
> -else
> -tmp_path[0] = '\0';
> +/* skip "/" */
> +while (*next == '/')
> +++next;
>  }
>
> -if (!av_stristart(p, "/", NULL) && root != rel)
> -av_strlcat(tmp_path, "/", size);
> -
> -av_strlcat(tmp_path, p, size);
>  /* start set buf after temp path process. */
>  av_strlcpy(buf, rel, root - rel + 1);
> -
> -if (!av_stristart(tmp_path, "/", NULL) && root != rel)
> -av_strlcat(buf, "/", size);
> -
>  av_strlcat(buf, tmp_path, size);
>  }
>
> @@ -194,26 +205,7 @@ void ff_make_absolute_url(char *buf, int size, const 
> char *base,
>  sep[1] = '\0';
>  else
>  buf[0] = '\0';
> -while (av_strstart(rel, "..", NULL) && sep) {
> -/* Remove the path delimiter at the end */
> -if (sep > root) {
> -sep[0] = '\0';
> -sep = strrchr(buf, '/');
> -}
>
> -/* If the next directory name to pop off is "..", break here */
> -if (!strcmp(sep ? [1] : buf, "..")) {
> -/* Readd the slash we just removed */
> -av_strlcat(buf, "/", size);
> -break;
> -}
> -/* Cut off the directory name */
> -if (sep)
> -sep[1] = '\0';
> -else
> -buf[0] = '\0';
> -rel += 3;
> -}
>  av_strlcat(buf, rel, size);
>  trim_double_dot_url(tmp_path, buf, size);
>  memset(buf, 0, size);
> --
> 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".

maybe the last node is a file, not directory

(base) liuqi05:clang liuqi$ make fate-url
CC libavformat/tests/url.o
LD libavformat/tests/url
TESTurl
--- src/tests/ref/fate/url 2020-07-27 19:30:58.0 +0800
+++ tests/data/fate/url 2020-07-27 19:34:25.0 +0800
@@ -15,9 +15,9 @@
  http://server/foo/bar //other/url
  => http://other/url
  http://server/foo/bar
../../../../../other/url => http://server/other/url
  http://server/foo/bar

[FFmpeg-devel] [PATCH 2/3] avformat/tests/url: add test cases for handling of double dot

2020-07-27 Thread Josef Zlomek
Signed-off-by: Josef Zlomek 
---
 libavformat/tests/url.c | 2 ++
 tests/ref/fate/url  | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/libavformat/tests/url.c b/libavformat/tests/url.c
index 1d961a1b43..d7f14da49e 100644
--- a/libavformat/tests/url.c
+++ b/libavformat/tests/url.c
@@ -67,6 +67,8 @@ int main(void)
 test("http://server/foo/bar?param;, "?someparam");
 test("http://server/foo/bar;, "//other/url");
 test("http://server/foo/bar;, "../../../../../other/url");
+test("http://server/foo/bar;, 
"a/b/../c/d/../e../..f/.../other/url/test..mp3");
+test("http://server/foo/bar;, 
"/a/b/../c/d/../e../..f/.../other/url/test..mp3");
 test("http://server/foo/bar;, "/../../../../../other/url");
 test("http://server/foo/bar;, "/test/../../../../../other/url");
 test("http://server/foo/bar;, "/test/../../test/../../../other/url");
diff --git a/tests/ref/fate/url b/tests/ref/fate/url
index 533ba2cb1e..8be9979c0b 100644
--- a/tests/ref/fate/url
+++ b/tests/ref/fate/url
@@ -14,6 +14,8 @@ Testing ff_make_absolute_url:
 http://server/foo/bar?param ?someparam   => 
http://server/foo/bar?someparam
  http://server/foo/bar //other/url  => 
http://other/url
  http://server/foo/bar ../../../../../other/url => 
http://server/other/url
+ http://server/foo/bar 
a/b/../c/d/../e../..f/.../other/url/test..mp3 => 
http://server/foo/a/c/e../..f/.../other/url/test..mp3
+ http://server/foo/bar 
/a/b/../c/d/../e../..f/.../other/url/test..mp3 => 
http://server/a/c/e../..f/.../other/url/test..mp3
  http://server/foo/bar /../../../../../other/url 
=> http://server/other/url
  http://server/foo/bar 
/test/../../../../../other/url => http://server/other/url
  http://server/foo/bar 
/test/../../test/../../../other/url => http://server/other/url
-- 
2.17.1

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

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

[FFmpeg-devel] [PATCH 3/3] avformat/url: remove duplicate call to strstr

2020-07-27 Thread Josef Zlomek
Signed-off-by: Josef Zlomek 
---
 libavformat/url.c | 13 +
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/libavformat/url.c b/libavformat/url.c
index ccaa28a1ed..28d12fd3de 100644
--- a/libavformat/url.c
+++ b/libavformat/url.c
@@ -186,14 +186,11 @@ void ff_make_absolute_url(char *buf, int size, const char 
*base,
 
 root = p = buf;
 /* Get the path root of the url which start by "://" */
-if (p && strstr(p, "://")) {
-sep = strstr(p, "://");
-if (sep) {
-sep += 3;
-root = strchr(sep, '/');
-if (!root)
-return;
-}
+if (p && (sep = strstr(p, "://"))) {
+sep += 3;
+root = strchr(sep, '/');
+if (!root)
+return;
 }
 
 /* Remove the file name from the base url */
-- 
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 1/3] avformat/url: fix logic for removing ".." path components

2020-07-27 Thread Josef Zlomek
Fixes: 8814

The logic for removing ".." path components and their corresponding
upper directories was reworked.

Now, the function trim_double_dot_url splits the path by "/" into
components, and processes the components one ny one:
- if the component is "..", the last path component in tmp_path is removed
- if the component is not empty, it is added to tmp_path

The duplicate logic was removed from ff_make_absolute_url.

Signed-off-by: Josef Zlomek 
---
 libavformat/url.c | 70 +--
 1 file changed, 31 insertions(+), 39 deletions(-)

diff --git a/libavformat/url.c b/libavformat/url.c
index 20463a6674..ccaa28a1ed 100644
--- a/libavformat/url.c
+++ b/libavformat/url.c
@@ -83,8 +83,9 @@ static void trim_double_dot_url(char *buf, const char *rel, 
int size)
 const char *p = rel;
 const char *root = rel;
 char tmp_path[MAX_URL_SIZE] = {0, };
-char *sep;
-char *node;
+int tmp_len = 0;
+const char *sep;
+const char *next;
 
 /* Get the path root of the url which start by "://" */
 if (p && (sep = strstr(p, "://"))) {
@@ -93,29 +94,39 @@ static void trim_double_dot_url(char *buf, const char *rel, 
int size)
 if (!root)
 return;
 }
+if (*root == '/')
+++root;
+
+/* Split the path by "/" and remove ".." and its corresponding directory. 
*/
+for (p = root; *p; p = next) {
+next = strchr(p, '/');
+if (!next)
+next = p + strlen(p);
+
+if (next - p == 2 && !strncmp(p, "..", 2)) {
+/* remove the last directory from tmp_path */
+while (tmp_len > 0 && tmp_path[--tmp_len] != '/')
+;
+tmp_path[tmp_len] = '\0';
+} else if (next > p) {
+/* copy the current path component to tmp_path (including '/') */
+if (tmp_len) {
+av_strlcpy(tmp_path + tmp_len, "/", sizeof(tmp_path) - 
tmp_len);
+++tmp_len;
+}
+av_strlcpy(tmp_path + tmp_len, p, FFMIN(sizeof(tmp_path) - tmp_len,
+next - p + 1));
+tmp_len += next - p;
+tmp_path[tmp_len] = '\0';
+}
 
-/* set new current position if the root node is changed */
-p = root;
-while (p && (node = strstr(p, ".."))) {
-av_strlcat(tmp_path, p, node - p + strlen(tmp_path));
-p = node + 3;
-sep = strrchr(tmp_path, '/');
-if (sep)
-sep[0] = '\0';
-else
-tmp_path[0] = '\0';
+/* skip "/" */
+while (*next == '/')
+++next;
 }
 
-if (!av_stristart(p, "/", NULL) && root != rel)
-av_strlcat(tmp_path, "/", size);
-
-av_strlcat(tmp_path, p, size);
 /* start set buf after temp path process. */
 av_strlcpy(buf, rel, root - rel + 1);
-
-if (!av_stristart(tmp_path, "/", NULL) && root != rel)
-av_strlcat(buf, "/", size);
-
 av_strlcat(buf, tmp_path, size);
 }
 
@@ -194,26 +205,7 @@ void ff_make_absolute_url(char *buf, int size, const char 
*base,
 sep[1] = '\0';
 else
 buf[0] = '\0';
-while (av_strstart(rel, "..", NULL) && sep) {
-/* Remove the path delimiter at the end */
-if (sep > root) {
-sep[0] = '\0';
-sep = strrchr(buf, '/');
-}
 
-/* If the next directory name to pop off is "..", break here */
-if (!strcmp(sep ? [1] : buf, "..")) {
-/* Readd the slash we just removed */
-av_strlcat(buf, "/", size);
-break;
-}
-/* Cut off the directory name */
-if (sep)
-sep[1] = '\0';
-else
-buf[0] = '\0';
-rel += 3;
-}
 av_strlcat(buf, rel, size);
 trim_double_dot_url(tmp_path, buf, size);
 memset(buf, 0, size);
-- 
2.17.1

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

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

Re: [FFmpeg-devel] Inconsistent handling of initial_padding and PTS adjustment

2020-07-27 Thread Anton Khirnov
Quoting Kieran Kunhya (2020-07-26 01:51:22)
> Hi,
> 
> I notice that some encoders adjust the PTS with initial_padding and some
> don't.
> Is this intentional and should we decide that all encoders should do this?

Which ones don't?

I don't think this is a matter of opinion really - if encoder adds
padding and doesn't adjust the timestamps then the output timestamps are
just plain wrong.

-- 
Anton Khirnov
___
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/internal: Remove wrong documentation

2020-07-27 Thread Anton Khirnov
Quoting Andreas Rheinhardt (2020-07-27 06:13:05)
> Has apparently been copied from ff_choose_timebase() in commit
> a45cf639e6fb8c86aff91a00970060cd0be401c9.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
> Btw: There is exactly one user of this, namely the MXF muxer.
> Should this be moved to mxfenc.c? The same issue exists for
> ff_choose_timebase(), which is only used by the nut muxer.
> 
>  libavformat/internal.h | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/libavformat/internal.h b/libavformat/internal.h
> index 17a6ab07d3..a2eac3250d 100644
> --- a/libavformat/internal.h
> +++ b/libavformat/internal.h
> @@ -538,9 +538,6 @@ enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int 
> be, int sflags);
>   */
>  AVRational ff_choose_timebase(AVFormatContext *s, AVStream *st, int 
> min_precision);
>  
> -/**
> - * Chooses a timebase for muxing the specified stream.
> - */
>  enum AVChromaLocation ff_choose_chroma_location(AVFormatContext *s, AVStream 
> *st);
>  
>  /**
> -- 
> 2.20.1

I'd say yes.

Patch looks ok either way.

-- 
Anton Khirnov
___
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]lavfi/hflip: Support Bayer pixel formats

2020-07-27 Thread Reto Kromer
Carl Eugen Hoyos wrote:

>Am So., 26. Juli 2020 um 21:28 Uhr schrieb Paul B Mahol
>:
>>
>> On 7/26/20, Carl Eugen Hoyos  wrote:
>> > Hi!
>> >
>> > Attached patch fixes a part of ticket #8819.
>> >
>> > Please comment, Carl Eugen
>> >
>>
>> Looks good, but variable name is unfortunate.
>
>New patch attached.

I am afraid, I still experience the same behaviour:

- the original image (*) has an yellow tinting
- hflip,vflip together gives the correct image texture but with
  a blue tinting
- hflip and vplip individually give a light magenta colour and a
  pattern which I consider to be a Bayer phase error

Thank you and best regards, Reto


* the clip is number 3 at https://avpres.net/CineForm/ (I could
not upload at ticket #8819 because it's 22.3 MB)

___
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 v3 1/5] avcodec/golomb: Don't emit error message in get_ue_golomb

2020-07-27 Thread Andreas Rheinhardt
Said error message is not very informative and lacked a proper logging
context; furthermore, many callers already provided more descriptive
error messages of their own. So just drop this one.

Suggested-by: James Almer 
Signed-off-by: Andreas Rheinhardt 
---
No change since last time. Will apply this tomorrow unless there are
objections.

 libavcodec/golomb.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/libavcodec/golomb.h b/libavcodec/golomb.h
index 7fd46a91bd..1f988d74aa 100644
--- a/libavcodec/golomb.h
+++ b/libavcodec/golomb.h
@@ -87,10 +87,8 @@ static inline int get_ue_golomb(GetBitContext *gb)
 int log = 2 * av_log2(buf) - 31;
 LAST_SKIP_BITS(re, gb, 32 - log);
 CLOSE_READER(re, gb);
-if (log < 7) {
-av_log(NULL, AV_LOG_ERROR, "Invalid UE golomb code\n");
+if (log < 7)
 return AVERROR_INVALIDDATA;
-}
 buf >>= log;
 buf--;
 
-- 
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 v3 4/5] avcodec/cavsdec, h264*, hevc_parser: Use get_ue_golomb_31 where possible

2020-07-27 Thread Andreas Rheinhardt
instead of get_ue_golomb(). The difference between the two is that the
latter also has to take into account the case in which the read code is
more than 9 bits (four preceding zeroes + at most five value bits) long,
leading to more code.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/cavsdec.c |  2 +-
 libavcodec/h264_parse.c  |  4 ++--
 libavcodec/h264_ps.c | 24 
 libavcodec/hevc_parser.c |  2 +-
 4 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c
index aaed807196..9c3825df38 100644
--- a/libavcodec/cavsdec.c
+++ b/libavcodec/cavsdec.c
@@ -676,7 +676,7 @@ static int decode_mb_i(AVSContext *h, int cbp_code)
 }
 h->pred_mode_Y[pos] = predpred;
 }
-pred_mode_uv = get_ue_golomb(gb);
+pred_mode_uv = get_ue_golomb_31(gb);
 if (pred_mode_uv > 6) {
 av_log(h->avctx, AV_LOG_ERROR, "illegal intra chroma pred mode\n");
 return AVERROR_INVALIDDATA;
diff --git a/libavcodec/h264_parse.c b/libavcodec/h264_parse.c
index 352ffea948..1c1d1c04b0 100644
--- a/libavcodec/h264_parse.c
+++ b/libavcodec/h264_parse.c
@@ -35,7 +35,7 @@ int ff_h264_pred_weight_table(GetBitContext *gb, const SPS 
*sps,
 pwt->use_weight = 0;
 pwt->use_weight_chroma  = 0;
 
-pwt->luma_log2_weight_denom = get_ue_golomb(gb);
+pwt->luma_log2_weight_denom = get_ue_golomb_31(gb);
 if (pwt->luma_log2_weight_denom > 7U) {
 av_log(logctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is out of 
range\n", pwt->luma_log2_weight_denom);
 pwt->luma_log2_weight_denom = 0;
@@ -43,7 +43,7 @@ int ff_h264_pred_weight_table(GetBitContext *gb, const SPS 
*sps,
 luma_def = 1 << pwt->luma_log2_weight_denom;
 
 if (sps->chroma_format_idc) {
-pwt->chroma_log2_weight_denom = get_ue_golomb(gb);
+pwt->chroma_log2_weight_denom = get_ue_golomb_31(gb);
 if (pwt->chroma_log2_weight_denom > 7U) {
 av_log(logctx, AV_LOG_ERROR, "chroma_log2_weight_denom %d is out 
of range\n", pwt->chroma_log2_weight_denom);
 pwt->chroma_log2_weight_denom = 0;
diff --git a/libavcodec/h264_ps.c b/libavcodec/h264_ps.c
index e774929e21..e21c2b56ac 100644
--- a/libavcodec/h264_ps.c
+++ b/libavcodec/h264_ps.c
@@ -181,8 +181,8 @@ static inline int decode_vui_parameters(GetBitContext *gb, 
void *logctx,
 /* chroma_location_info_present_flag */
 if (get_bits1(gb)) {
 /* chroma_sample_location_type_top_field */
-sps->chroma_location = get_ue_golomb(gb) + 1;
-get_ue_golomb(gb);  /* chroma_sample_location_type_bottom_field */
+sps->chroma_location = get_ue_golomb_31(gb) + 1;
+get_ue_golomb_31(gb);  /* chroma_sample_location_type_bottom_field */
 } else
 sps->chroma_location = AVCHROMA_LOC_LEFT;
 
@@ -224,12 +224,12 @@ static inline int decode_vui_parameters(GetBitContext 
*gb, void *logctx,
 sps->bitstream_restriction_flag = get_bits1(gb);
 if (sps->bitstream_restriction_flag) {
 get_bits1(gb); /* motion_vectors_over_pic_boundaries_flag */
-get_ue_golomb(gb); /* max_bytes_per_pic_denom */
-get_ue_golomb(gb); /* max_bits_per_mb_denom */
-get_ue_golomb(gb); /* log2_max_mv_length_horizontal */
-get_ue_golomb(gb); /* log2_max_mv_length_vertical */
-sps->num_reorder_frames = get_ue_golomb(gb);
-get_ue_golomb(gb); /*max_dec_frame_buffering*/
+get_ue_golomb_31(gb); /* max_bytes_per_pic_denom */
+get_ue_golomb_31(gb); /* max_bits_per_mb_denom */
+get_ue_golomb_31(gb); /* log2_max_mv_length_horizontal */
+get_ue_golomb_31(gb); /* log2_max_mv_length_vertical */
+sps->num_reorder_frames = get_ue_golomb_31(gb);
+get_ue_golomb_31(gb); /*max_dec_frame_buffering*/
 
 if (get_bits_left(gb) < 0) {
 sps->num_reorder_frames = 0;
@@ -403,8 +403,8 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, 
AVCodecContext *avctx,
 goto fail;
 }
 }
-sps->bit_depth_luma   = get_ue_golomb(gb) + 8;
-sps->bit_depth_chroma = get_ue_golomb(gb) + 8;
+sps->bit_depth_luma   = get_ue_golomb_31(gb) + 8;
+sps->bit_depth_chroma = get_ue_golomb_31(gb) + 8;
 if (sps->bit_depth_chroma != sps->bit_depth_luma) {
 avpriv_request_sample(avctx,
   "Different chroma and luma bit depth");
@@ -428,7 +428,7 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, 
AVCodecContext *avctx,
 sps->bit_depth_chroma  = 8;
 }
 
-log2_max_frame_num_minus4 = get_ue_golomb(gb);
+log2_max_frame_num_minus4 = get_ue_golomb_31(gb);
 if (log2_max_frame_num_minus4 < MIN_LOG2_MAX_FRAME_NUM - 4 ||
 log2_max_frame_num_minus4 > MAX_LOG2_MAX_FRAME_NUM - 4) {
 av_log(avctx, AV_LOG_ERROR,
@@ -441,7 +441,7 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, 
AVCodecContext 

[FFmpeg-devel] [PATCH v3 3/5] avcodec/golomb: Document return value of get_ue_golomb_31 on error

2020-07-27 Thread Andreas Rheinhardt
get_ue_golomb_31() reads nine bits and an array with 512 entries to
parse golomb codes. The longest golomb codes that fit into 9 bits use
four leading zeroes and five value bits and can encode numbers in the
0..30 range. 31 meanwhile is encoded on 11 bits and if the nine bits
read coincide with the first nine bits of the encoding of 31,
get_ue_golomb_31() returns 31 (and skips 11 bits).

But looking at the first nine bits only makes it impossible to distinguish
31 from 32..34. Therefore the documentation of get_ue_golomb_31() simply
states that the return value is undefined if the value of the encountered
exp golomb code was outside the 0..31 range.

But actually get_ue_golomb_31() does not behave that bad: If the returned
value is in the range of 0..30, then this is the actually encountered value,
so that this function can be used without any problems to parse and validate
parameters whose legal values are a subset of the 0..30 range.

This commit documents this fact.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/golomb.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavcodec/golomb.h b/libavcodec/golomb.h
index aed9b22471..4d531cf805 100644
--- a/libavcodec/golomb.h
+++ b/libavcodec/golomb.h
@@ -116,7 +116,8 @@ static inline unsigned get_ue_golomb_long(GetBitContext *gb)
 
 /**
  * read unsigned exp golomb code, constraint to a max of 31.
- * the return value is undefined if the stored value exceeds 31.
+ * If the value encountered is not in 0..31, the return value
+ * is outside the range 0..30.
  */
 static inline int get_ue_golomb_31(GetBitContext *gb)
 {
-- 
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 v3 5/5] avcodec/h264*: Omit potentially wrong values from log messages

2020-07-27 Thread Andreas Rheinhardt
get_ue_golomb_31() and get_ue_golomb() can only parse values within
a certain range correctly; if the parsed value is not within said range,
the latter function returns AVERROR_INVALIDDATA, while the former returns
something different from the encountered value. So the return values are
good enough to determine whether an exp golomb code in the desired range
has been encountered, but they are not necessarily correct. Therefore
they should not be used in error messages stating that a certain value
(the return value of these functions) is out-of-range; instead just state
the correct range and that the parsed value is not in said range.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/cavsdec.c |  2 +-
 libavcodec/h264_cavlc.c  | 14 +++---
 libavcodec/h264_parse.c  |  4 ++--
 libavcodec/h264_parser.c |  2 +-
 libavcodec/h264_ps.c | 28 +++-
 libavcodec/h264_sei.c|  2 +-
 libavcodec/h264_slice.c  |  2 +-
 7 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c
index 9c3825df38..6b5ad587ca 100644
--- a/libavcodec/cavsdec.c
+++ b/libavcodec/cavsdec.c
@@ -615,7 +615,7 @@ static inline int decode_residual_inter(AVSContext *h)
 /* get coded block pattern */
 int cbp = get_ue_golomb(>gb);
 if (cbp > 63U) {
-av_log(h->avctx, AV_LOG_ERROR, "illegal inter cbp %d\n", cbp);
+av_log(h->avctx, AV_LOG_ERROR, "Inter cbp not in 0-63 range\n");
 return AVERROR_INVALIDDATA;
 }
 h->cbp = cbp_tab[cbp][1];
diff --git a/libavcodec/h264_cavlc.c b/libavcodec/h264_cavlc.c
index 6481992e58..137329479c 100644
--- a/libavcodec/h264_cavlc.c
+++ b/libavcodec/h264_cavlc.c
@@ -762,7 +762,7 @@ int ff_h264_decode_mb_cavlc(const H264Context *h, 
H264SliceContext *sl)
 mb_type--;
 decode_intra_mb:
 if(mb_type > 25){
-av_log(h->avctx, AV_LOG_ERROR, "mb_type %d in %c slice too large 
at %d %d\n", mb_type, av_get_picture_type_char(sl->slice_type), sl->mb_x, 
sl->mb_y);
+av_log(h->avctx, AV_LOG_ERROR, "mb_type in %c slice too large at 
%d %d\n", av_get_picture_type_char(sl->slice_type), sl->mb_x, sl->mb_y);
 return -1;
 }
 partition_count=0;
@@ -891,7 +891,7 @@ decode_intra_mb:
 }else{
 tmp= get_ue_golomb_31(>gb);
 if(tmp>=ref_count){
-av_log(h->avctx, AV_LOG_ERROR, "ref %u 
overflow\n", tmp);
+av_log(h->avctx, AV_LOG_ERROR, "ref overflow\n");
 return -1;
 }
 }
@@ -967,7 +967,7 @@ decode_intra_mb:
 }else{
 val= get_ue_golomb_31(>gb);
 if (val >= rc) {
-av_log(h->avctx, AV_LOG_ERROR, "ref %u 
overflow\n", val);
+av_log(h->avctx, AV_LOG_ERROR, "ref 
overflow\n");
 return -1;
 }
 }
@@ -998,7 +998,7 @@ decode_intra_mb:
 }else{
 val= get_ue_golomb_31(>gb);
 if (val >= rc) {
-av_log(h->avctx, AV_LOG_ERROR, "ref %u 
overflow\n", val);
+av_log(h->avctx, AV_LOG_ERROR, "ref 
overflow\n");
 return -1;
 }
 }
@@ -1036,7 +1036,7 @@ decode_intra_mb:
 }else{
 val= get_ue_golomb_31(>gb);
 if (val >= rc) {
-av_log(h->avctx, AV_LOG_ERROR, "ref %u 
overflow\n", val);
+av_log(h->avctx, AV_LOG_ERROR, "ref 
overflow\n");
 return -1;
 }
 }
@@ -1071,7 +1071,7 @@ decode_intra_mb:
 
 if(decode_chroma){
 if(cbp > 47){
-av_log(h->avctx, AV_LOG_ERROR, "cbp too large (%u) at %d 
%d\n", cbp, sl->mb_x, sl->mb_y);
+av_log(h->avctx, AV_LOG_ERROR, "cbp >%d at %d %d\n", 47, 
sl->mb_x, sl->mb_y);
 return -1;
 }
 if (IS_INTRA4x4(mb_type))
@@ -1080,7 +1080,7 @@ decode_intra_mb:
 cbp = ff_h264_golomb_to_inter_cbp[cbp];
 }else{
 if(cbp > 15){
-av_log(h->avctx, AV_LOG_ERROR, "cbp too large (%u) at %d 
%d\n", cbp, sl->mb_x, sl->mb_y);
+av_log(h->avctx, AV_LOG_ERROR, "cbp >%d at %d %d\n", 15, 
sl->mb_x, sl->mb_y);
 return -1;
 }
 if(IS_INTRA4x4(mb_type)) cbp= golomb_to_intra4x4_cbp_gray[cbp];
diff --git a/libavcodec/h264_parse.c b/libavcodec/h264_parse.c
index 

[FFmpeg-devel] [PATCH v3 2/5] avcodec/golomb: Prevent shift by negative number

2020-07-27 Thread Andreas Rheinhardt
This happened in get_ue_golomb() if the cached bitstream reader was in
use, because there was no check to handle the case of the read value
not being in the supported range.
For consistency with the uncached bitstream reader and for compliance
with the documentation, every value not in the 0-8190 range is treated as
error although the cached bitstream reader could actually read values in
the range 0..65534 without problems.

Signed-off-by: Andreas Rheinhardt 
---
v3: Besides accepting the same range as the uncached version this
version also consumes bits in case of error like the uncached version.
Unfortunately it is not possible to always consume the same number of
bits, because the uncached version will consume 63 bits as soon as all
valid bits are zero, whereas the cached version will only consume 63
bits if the next 31 bits are zero.

 libavcodec/golomb.h | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavcodec/golomb.h b/libavcodec/golomb.h
index 1f988d74aa..aed9b22471 100644
--- a/libavcodec/golomb.h
+++ b/libavcodec/golomb.h
@@ -66,9 +66,12 @@ static inline int get_ue_golomb(GetBitContext *gb)
 return ff_ue_golomb_vlc_code[buf];
 } else {
 int log = 2 * av_log2(buf) - 31;
+
+skip_bits_long(gb, 32 - log);
+if (log < 7)
+return AVERROR_INVALIDDATA;
 buf >>= log;
 buf--;
-skip_bits_long(gb, 32 - log);
 
 return buf;
 }
-- 
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".

Re: [FFmpeg-devel] [PATCH] lavc/libxavs2.c: mark key-frame packets

2020-07-27 Thread Steven Liu
hwren  于2020年7月27日周一 下午3:59写道:
>
>

>
> 在 2020-07-27 15:26:24,"Steven Liu"  写道:
> > 于2020年7月27日周一 下午2:22写道:
> >>
> >> From: hwren 
> >>
> >> Signed-off-by: hwren 
> >> ---
> >>  libavcodec/libxavs2.c | 6 ++
> >>  1 file changed, 6 insertions(+)
> >>
> >> diff --git a/libavcodec/libxavs2.c b/libavcodec/libxavs2.c
> >> index 76b57e731e..8519f6925a 100644
> >> --- a/libavcodec/libxavs2.c
> >> +++ b/libavcodec/libxavs2.c
> >> @@ -223,6 +223,12 @@ static int xavs2_encode_frame(AVCodecContext *avctx, 
> >> AVPacket *pkt,
> >>  pkt->pts = cae->packet.pts;
> >>  pkt->dts = cae->packet.dts;
> >>
> >> +if (cae->packet.type == XAVS2_TYPE_IDR ||
> >> +cae->packet.type == XAVS2_TYPE_I ||
> >Don't support OpenGOP?
>
> There is no obvious difference between IDR/I frame in AVS2. Actually we will 
> use TYPE_I in most cases.
> So I think, when a jump occurs, ffmpeg just needs to find the closest I 
> frame. Then the decoder will
> determine the validity and discard the illegal frames. This method may 
> trigger some error reports,
> but they should be harmless.

Looks ok then.
>
> >> +cae->packet.type == XAVS2_TYPE_KEYFRAME) {
> >> +pkt->flags |= AV_PKT_FLAG_KEY;
> >> +}
> >> +
> >>  memcpy(pkt->data, cae->packet.stream, cae->packet.len);
> >>  pkt->size = cae->packet.len;
> >>
> >> --
> >> 2.23.0.windows.1
> >>

Thanks for your clarify respond

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

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

Re: [FFmpeg-devel] [PATCH] avcodec/jpeg2000dec: Move reslevelno check before use in case JPEG2000_PGOD_RPCL

2020-07-27 Thread Michael Niedermayer
On Mon, Jul 27, 2020 at 09:55:31AM +0530, Gautam Ramakrishnan wrote:
> On Mon, Jul 27, 2020 at 9:48 AM Gautam Ramakrishnan
>  wrote:
> >
> > On Mon, Jul 27, 2020 at 3:16 AM Michael Niedermayer
> >  wrote:
> > >
> > > Fixes: division by zero
> > > Fixes: 
> > > 24201/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5665813827420160
> > > Fixes: 
> > > 24245/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-6285831682392064
> > >
> > > Found-by: continuous fuzzing process 
> > > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > > Signed-off-by: Michael Niedermayer 
> > > ---
> > >  libavcodec/jpeg2000dec.c | 6 +++---
> > >  1 file changed, 3 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
> > > index a470cf47da..b168e52db6 100644
> > > --- a/libavcodec/jpeg2000dec.c
> > > +++ b/libavcodec/jpeg2000dec.c
> > > @@ -1401,12 +1401,12 @@ static int 
> > > jpeg2000_decode_packets_po_iteration(Jpeg2000DecoderContext *s, Jpeg2
> > >  if (!s->cdx[compno] || !s->cdy[compno])
> > >  return AVERROR_INVALIDDATA;
> > >
> > > -trx0 = ff_jpeg2000_ceildiv(tile->coord[0][0], 
> > > s->cdx[compno] << reducedresno);
> > > -try0 = ff_jpeg2000_ceildiv(tile->coord[1][0], 
> > > s->cdy[compno] << reducedresno);
> > > -
> > >  if (reslevelno >= codsty->nreslevels)
> > >  continue;
> > >
> > > +trx0 = ff_jpeg2000_ceildiv(tile->coord[0][0], 
> > > s->cdx[compno] << reducedresno);
> > > +try0 = ff_jpeg2000_ceildiv(tile->coord[1][0], 
> > > s->cdy[compno] << reducedresno);
> > > +
> > >  if (!(y % ((uint64_t)s->cdy[compno] << 
> > > (rlevel->log2_prec_height + reducedresno)) == 0 ||
> > >   (y == tile->coord[1][0] && (try0 << 
> > > reducedresno) % (1U << (reducedresno + rlevel->log2_prec_height)
> > >  continue;
> > > --
> > > 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".
> >
> > Looks good to me.
> > I guess the division by zero happens because shifting by reducedresno
> > overflows?

yes

> >
> > --
> > -
> > Gautam |
> Just realized, this might happen in one more place, shall send a
> patch for the same.

yes

thx

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

Dictatorship naturally arises out of democracy, and the most aggravated
form of tyranny and slavery out of the most extreme liberty. -- Plato


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] working with file descriptors on Android

2020-07-27 Thread Olivier Ayache
A good alternative to work with FFmpeg on Android is Xuggler, it presents
FFmpeg's API directly to Java/Kotlin.

To deal with fd you can declare and implement your own IO handler by
implementing
https://github.com/olivierayache/xuggle-xuggler/blob/ffmpeg-3.x-dev/src/com/xuggle/xuggler/io/IURLProtocolHandler.java

I currently maintain a fork which is fully working on Android (work in
progress for iOS with Kotlin multiplatform).

https://github.com/olivierayache/xuggle-xuggler

Best

Olivier Ayache

Le dim. 26 juil. 2020 à 23:16, Alex Cohn  a
écrit :

> On Sun, Jul 26, 2020 at 10:21 PM Martin Storsjö  wrote:
> >
> > Hi,
> >
> > Without having too much opinion on the JNI stuff (direct access to
> > content:// urls might be convenient, but on the other hand, it's not
> > really something you'd end up with if using the command line tool on its
> > own - if you have one of those you most probably have some java code for
> > getting it anyway - as far as I remember...)
>
>
> You are more than right, Martin.
>
> None of these approaches can work with a command line tool. Worse,
> running a command line tool in the context of an Android app is
> becoming trickier with every new release of the platform, and in this
> case I cannot blame it on poor engineering. This happens because
> Google tries to tighten the security on Android just as much as
> possible.
>
> There is a nice cross-platform alternative, though.
> https://github.com/tanersener/mobile-ffmpeg provides Java and
> Objective-C APIs to run ffmpeg shared library "as if it were an
> executable": it can receive the input as a string which mimics the
> ffmpeg (and ffprobe) command line, and the output to stdout and stderr
> is captured and passed back to the mobile app. In this scenario, it's
> easy to get a `content:` URI by conventional Android SAF (structured
> access framework) API in Java and pass it as string or as a derived
> file descriptor (converted to string) to the command line parser that
> will eventually call protocol->url_open().
>
> The latest release (Android Q a.k.a. Android 10, also API 29) made yet
> another small step in this direction and caused lots of problems for
> apps that rely upon file access by path. This was the incentive for me
> to work on the ways to teach avformat to work with the `content:` URIs
> correctly.
>
> BR,
> Alex Cohn
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH] lavc/libxavs2.c: mark key-frame packets

2020-07-27 Thread hwren



















在 2020-07-27 15:26:24,"Steven Liu"  写道:
> 于2020年7月27日周一 下午2:22写道:
>>
>> From: hwren 
>>
>> Signed-off-by: hwren 
>> ---
>>  libavcodec/libxavs2.c | 6 ++
>>  1 file changed, 6 insertions(+)
>>
>> diff --git a/libavcodec/libxavs2.c b/libavcodec/libxavs2.c
>> index 76b57e731e..8519f6925a 100644
>> --- a/libavcodec/libxavs2.c
>> +++ b/libavcodec/libxavs2.c
>> @@ -223,6 +223,12 @@ static int xavs2_encode_frame(AVCodecContext *avctx, 
>> AVPacket *pkt,
>>  pkt->pts = cae->packet.pts;
>>  pkt->dts = cae->packet.dts;
>>
>> +if (cae->packet.type == XAVS2_TYPE_IDR ||
>> +cae->packet.type == XAVS2_TYPE_I ||
>Don't support OpenGOP?

There is no obvious difference between IDR/I frame in AVS2. Actually we will 
use TYPE_I in most cases.
So I think, when a jump occurs, ffmpeg just needs to find the closest I frame. 
Then the decoder will
determine the validity and discard the illegal frames. This method may trigger 
some error reports,
but they should be harmless.

>> +cae->packet.type == XAVS2_TYPE_KEYFRAME) {
>> +pkt->flags |= AV_PKT_FLAG_KEY;
>> +}
>> +
>>  memcpy(pkt->data, cae->packet.stream, cae->packet.len);
>>  pkt->size = cae->packet.len;
>>
>> --
>> 2.23.0.windows.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 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/3dostr: Return directly after having read packet

2020-07-27 Thread Paul B Mahol
On 7/27/20, Andreas Rheinhardt  wrote:
> Paul B Mahol:
>> Make sure this does not break demuxing/decoding.
>>
>
> This patch is designed to not change the packets output by the demuxer
> or the demuxer's return value at all. I have tested this with a small
> sample created in a hex editor, but only demuxing (as the content of the
> packet was garbage). I'd like to test this with a real sample, but
> couldn't find one. Do you have one (after all, you wrote that demuxer)?
>

Find it on web. It is used in old dos games, like DOOM.

> - 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 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] AVWriter again (was: v2 1/2] avformat/url: check double dot is not to parent directory)

2020-07-27 Thread Steven Liu
Nicolas George  于2020年7月25日周六 下午7:03写道:
>
> Marton Balint (12020-07-25):
> > And I also would like to point out that using static strings with
> > MAX_URL_SIZE is not OK. This function supports an arbitrary buffer size, so
> > limiting it to MAX_URL_SIZE is a bug.
>
> Excellent point. That would require changing the prototype of a few
> functions, but they are internal, we can do it.
>
> For this, I would like to pitch the AVWriter API once again, because it
> is made precisely for these cases: when you need to return a string of
> arbitrary length, but would like to avoid, as much a possible, the
> overhead of dynamically allocating it and the many error tests that come
> with it. It is like AVBPrint, but better.
>
> Let me elaborate without polluting the discussion by showing the actual
> implementation.
>
> So, let us say that function A calls function B, and function B needs to
> return a string of arbitrary length but often small (I say string, but
> the API can deal with binary data).
>
> Likely use cases: rewriting an URL like here; escaping special
> characters; serialization to key=value string; serialization to JSON or
> XML; character encoding conversion, zlib-style unpacking, etc.
>
>
> First, from the point of view of B, the function that needs to return
> the string:
>
> Instead of either:
>
> int B(char *buf, size_t buf_size, other arguments);
> int B(char **buf, other arguments);
>
> request an AVWriter as argument:
>
> void B(AVWriter wr, other arguments);
>
> Then, just write in it with the various API functions:
> av_writer_write(), av_writer_printf(), etc.
>
> And that's all. Everything is taken care of: the string will grow as
> needed, the size will be tracked, error checks are made. Nothing to
> worry about at all.
>
>
> Now, from the point of view of A, the function that calls B and gets a
> string in return:
>
> Instead of declaring a buffer, or a pointer to a buffer, declare:
>
> AVWriter wr = av_dynbuf_writer();
>
> and call B with it: B(wr, ...).
>
> Then, extract the string, check for error (of course: dynamic allocation
> can happen and fail; but this error check is the only one necessary),
> use the string and free it:
>
> char *msg = av_dynbuf_writer_get_data(wr, NULL);
> if (!msg)
> return AVERROR(ENOMEM);
> do something with msg
> av_dynbuf_writer_reset(wr);
>
> I concede, for this example, av_dynbuf_writer_get_data() is one more
> step than using the pointer directly. But as soon as the code becomes
> more complex, in particular as soon as it uses the same writer twice to
> put two strings together, this extra step is balanced by the fewer error
> checks necessary.
>
>
> All said, it makes one more API to learn, but IMHO, it is very simple to
> learn: seven line of sample code. And the benefits are immediate.
>
> Plus: there are many wonderful features that I have not told you about
> yet.
>
> So, Steven, Marton and the others: presented like that, does it look
> appealing? Shall I elaborate?
Because language barries. maybe I cannot deep understand, maybe need
more code examples.
But look interesting, maybe more easy for use.
>
> 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".
___
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] lavc/libxavs2.c: mark key-frame packets

2020-07-27 Thread Steven Liu
 于2020年7月27日周一 下午2:22写道:
>
> From: hwren 
>
> Signed-off-by: hwren 
> ---
>  libavcodec/libxavs2.c | 6 ++
>  1 file changed, 6 insertions(+)
>
> diff --git a/libavcodec/libxavs2.c b/libavcodec/libxavs2.c
> index 76b57e731e..8519f6925a 100644
> --- a/libavcodec/libxavs2.c
> +++ b/libavcodec/libxavs2.c
> @@ -223,6 +223,12 @@ static int xavs2_encode_frame(AVCodecContext *avctx, 
> AVPacket *pkt,
>  pkt->pts = cae->packet.pts;
>  pkt->dts = cae->packet.dts;
>
> +if (cae->packet.type == XAVS2_TYPE_IDR ||
> +cae->packet.type == XAVS2_TYPE_I ||
Don't support OpenGOP?
> +cae->packet.type == XAVS2_TYPE_KEYFRAME) {
> +pkt->flags |= AV_PKT_FLAG_KEY;
> +}
> +
>  memcpy(pkt->data, cae->packet.stream, cae->packet.len);
>  pkt->size = cae->packet.len;
>
> --
> 2.23.0.windows.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".

Re: [FFmpeg-devel] [PATCH v2 1/2] avformat/url: check double dot is not to parent directory

2020-07-27 Thread Steven Liu
Marton Balint  于2020年7月25日周六 下午5:40写道:
>
>
>
> On Sat, 25 Jul 2020, Zlomek, Josef wrote:
>
> > Hi Steven,
> >
> > It is better but still not correct. Consider this test:
> >
> > test("http://server/foo/bar;,
> > "a/b/../c/d/../e../.../..f/g../h../other/url/a.mp3/...");
> > It should give "
> > http://server/foo/bar/a/c/e../.../..f/g../h../other/url/a.mp3/...;.
> >
> > I think the best would be to use strtok(p, "/") to split the path into the
> > components and for each ".." component remove the previous one (if there
> > are some still).
>
> And I also would like to point out that using static strings with
> MAX_URL_SIZE is not OK. This function supports an arbitrary buffer size,
> so limiting it to MAX_URL_SIZE is a bug.
What about use av_malloc? or bprint?
I think use av_malloc maybe easter to me.
>
> Regards,
> Marton
>
> >

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

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

Re: [FFmpeg-devel] [PATCH] avformat/3dostr: Return directly after having read packet

2020-07-27 Thread Andreas Rheinhardt
Paul B Mahol:
> Make sure this does not break demuxing/decoding.
> 

This patch is designed to not change the packets output by the demuxer
or the demuxer's return value at all. I have tested this with a small
sample created in a hex editor, but only demuxing (as the content of the
packet was garbage). I'd like to test this with a real sample, but
couldn't find one. Do you have one (after all, you wrote that demuxer)?

- 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] avformat/3dostr: Return directly after having read packet

2020-07-27 Thread Paul B Mahol
Make sure this does not break demuxing/decoding.

On 7/27/20, Andreas Rheinhardt  wrote:
> Avoids an avio_skip(s->pb, 0).
>
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavformat/3dostr.c | 13 -
>  1 file changed, 4 insertions(+), 9 deletions(-)
>
> diff --git a/libavformat/3dostr.c b/libavformat/3dostr.c
> index 6c49f7589c..3ec3c4393e 100644
> --- a/libavformat/3dostr.c
> +++ b/libavformat/3dostr.c
> @@ -110,15 +110,12 @@ static int threedostr_read_header(AVFormatContext *s)
>
>  static int threedostr_read_packet(AVFormatContext *s, AVPacket *pkt)
>  {
> -unsigned chunk, size, found_ssmp = 0;
> +unsigned chunk, size;
>  AVStream *st = s->streams[0];
>  int64_t pos;
>  int ret = 0;
>
> -while (!found_ssmp) {
> -if (avio_feof(s->pb))
> -return AVERROR_EOF;
> -
> +while (!avio_feof(s->pb)) {
>  pos   = avio_tell(s->pb);
>  chunk = avio_rl32(s->pb);
>  size  = avio_rb32(s->pb);
> @@ -143,9 +140,7 @@ static int threedostr_read_packet(AVFormatContext *s,
> AVPacket *pkt)
>  pkt->pos = pos;
>  pkt->stream_index = 0;
>  pkt->duration = size / st->codecpar->channels;
> -size = 0;
> -found_ssmp = 1;
> -break;
> +return ret;
>  default:
>  av_log(s, AV_LOG_DEBUG, "skipping unknown chunk: %X\n", chunk);
>  break;
> @@ -154,7 +149,7 @@ static int threedostr_read_packet(AVFormatContext *s,
> AVPacket *pkt)
>  avio_skip(s->pb, size);
>  }
>
> -return ret;
> +return AVERROR_EOF;
>  }
>
>  AVInputFormat ff_threedostr_demuxer = {
> --
> 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] [PATCH] lavc/libxavs2.c: mark key-frame packets

2020-07-27 Thread hwrenx
From: hwren 

Signed-off-by: hwren 
---
 libavcodec/libxavs2.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libavcodec/libxavs2.c b/libavcodec/libxavs2.c
index 76b57e731e..8519f6925a 100644
--- a/libavcodec/libxavs2.c
+++ b/libavcodec/libxavs2.c
@@ -223,6 +223,12 @@ static int xavs2_encode_frame(AVCodecContext *avctx, 
AVPacket *pkt,
 pkt->pts = cae->packet.pts;
 pkt->dts = cae->packet.dts;
 
+if (cae->packet.type == XAVS2_TYPE_IDR ||
+cae->packet.type == XAVS2_TYPE_I ||
+cae->packet.type == XAVS2_TYPE_KEYFRAME) {
+pkt->flags |= AV_PKT_FLAG_KEY;
+}
+
 memcpy(pkt->data, cae->packet.stream, cae->packet.len);
 pkt->size = cae->packet.len;
 
-- 
2.23.0.windows.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".