[FFmpeg-devel] [PATCH 1/4] avutil/vulkan_functions: add EnumerateInstanceLayerProperties

2021-11-23 Thread Wu Jianhua
Signed-off-by: Wu Jianhua 
---
 libavutil/vulkan_functions.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavutil/vulkan_functions.h b/libavutil/vulkan_functions.h
index 85a9f943c8..96922d7286 100644
--- a/libavutil/vulkan_functions.h
+++ b/libavutil/vulkan_functions.h
@@ -45,6 +45,7 @@ typedef enum FFVulkanExtensions {
 #define FN_LIST(MACRO) 
  \
 /* Instance */ 
  \
 MACRO(0, 0, FF_VK_EXT_NO_FLAG,  
EnumerateInstanceExtensionProperties)\
+MACRO(0, 0, FF_VK_EXT_NO_FLAG,  
EnumerateInstanceLayerProperties)\
 MACRO(0, 0, FF_VK_EXT_NO_FLAG,  CreateInstance)
  \
 MACRO(1, 0, FF_VK_EXT_NO_FLAG,  DestroyInstance)   
  \

  \
-- 
2.25.1

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

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


[FFmpeg-devel] [PATCH 2/4] avutil/hwcontext_vulkan: check if created before destroying the device

2021-11-23 Thread Wu Jianhua
Signed-off-by: Wu Jianhua 
---
 libavutil/hwcontext_vulkan.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index f1e750cd3e..4ac1058181 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -1150,7 +1150,8 @@ static void vulkan_device_free(AVHWDeviceContext *ctx)
 FFVulkanFunctions *vk = &p->vkfn;
 AVVulkanDeviceContext *hwctx = ctx->hwctx;
 
-vk->DestroyDevice(hwctx->act_dev, hwctx->alloc);
+if (hwctx->act_dev)
+vk->DestroyDevice(hwctx->act_dev, hwctx->alloc);
 
 if (p->debug_ctx)
 vk->DestroyDebugUtilsMessengerEXT(hwctx->inst, p->debug_ctx,
-- 
2.25.1

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

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


[FFmpeg-devel] [PATCH 3/4] avutil/hwcontext_vulkan: check if created before destroying the instance

2021-11-23 Thread Wu Jianhua
Signed-off-by: Wu Jianhua 
---
 libavutil/hwcontext_vulkan.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index 4ac1058181..644ed947f8 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -1157,7 +1157,8 @@ static void vulkan_device_free(AVHWDeviceContext *ctx)
 vk->DestroyDebugUtilsMessengerEXT(hwctx->inst, p->debug_ctx,
   hwctx->alloc);
 
-vk->DestroyInstance(hwctx->inst, hwctx->alloc);
+if (hwctx->inst)
+vk->DestroyInstance(hwctx->inst, hwctx->alloc);
 
 if (p->libvulkan)
 dlclose(p->libvulkan);
-- 
2.25.1

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

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


[FFmpeg-devel] [PATCH 4/4] avutil/hwcontext_vulkan: fully support customizable validation layers

2021-11-23 Thread Wu Jianhua
Validation layer is an indispensable part of developing on Vulkan.

The following commands is on how to enable validation layers:

ffmpeg -init_hw_device 
vulkan=0,debug=1,validation_layers=VK_LAYER_KHRONOS_validation+VK_LAYER_LUNARG_api_dump

Signed-off-by: Wu Jianhua 
---
 libavutil/hwcontext_vulkan.c | 110 ---
 libavutil/hwcontext_vulkan.h |   7 +++
 2 files changed, 97 insertions(+), 20 deletions(-)

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index 644ed947f8..b808f8f76c 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -146,6 +146,13 @@ typedef struct AVVkFrameInternal {
 }  
\
 } while(0)
 
+#define RELEASE_PROPS(props, count)
\
+if (props) {   
\
+for (int i = 0; i < count; i++)
\
+av_free((void *)((props)[i])); 
\
+av_free((void *)props);
\
+}
+
 static const struct {
 enum AVPixelFormat pixfmt;
 const VkFormat vkfmts[4];
@@ -511,15 +518,83 @@ static int check_extensions(AVHWDeviceContext *ctx, int 
dev, AVDictionary *opts,
 return 0;
 
 fail:
-if (extension_names)
-for (int i = 0; i < extensions_found; i++)
-av_free((void *)extension_names[i]);
-av_free(extension_names);
+RELEASE_PROPS(extension_names, extensions_found);
 av_free(user_exts_str);
 av_free(sup_ext);
 return err;
 }
 
+static int check_validation_layers(AVHWDeviceContext *ctx, AVDictionary *opts,
+   const char * const **dst, uint32_t *num)
+{
+int found, err = 0;
+VulkanDevicePriv *priv = ctx->internal->priv;
+FFVulkanFunctions *vk = &priv->vkfn;
+
+uint32_t sup_layer_count;
+VkLayerProperties *sup_layers;
+
+AVDictionaryEntry *user_layers;
+char *user_layers_str, *save, *token;
+
+const char **enabled_layers = NULL;
+uint32_t enabled_layers_count = 0;
+
+user_layers = av_dict_get(opts, "validation_layers", NULL, 0);
+if (!user_layers)
+return 0;
+
+user_layers_str = av_strdup(user_layers->value);
+if (!user_layers_str) {
+err = AVERROR(EINVAL);
+goto fail;
+}
+
+vk->EnumerateInstanceLayerProperties(&sup_layer_count, NULL);
+sup_layers = av_malloc_array(sup_layer_count, sizeof(VkLayerProperties));
+if (!sup_layers)
+return AVERROR(ENOMEM);
+vk->EnumerateInstanceLayerProperties(&sup_layer_count, sup_layers);
+
+av_log(ctx, AV_LOG_VERBOSE, "Supported Validation layers:\n");
+for (int i = 0; i < sup_layer_count; i++)
+av_log(ctx, AV_LOG_VERBOSE, "\t%s\n", sup_layers[i].layerName);
+
+token = av_strtok(user_layers_str, "+", &save);
+while (token) {
+found = 0;
+for (int j = 0; j < sup_layer_count; j++) {
+if (!strcmp(token, sup_layers[j].layerName)) {
+found = 1;
+break;
+}
+}
+if (found) {
+av_log(ctx, AV_LOG_VERBOSE, "Requested Validation Layer: %s\n", 
token);
+ADD_VAL_TO_LIST(enabled_layers, enabled_layers_count, token);
+} else {
+av_log(ctx, AV_LOG_ERROR,
+   "Validation Layer \"%s\" not support.\n", token);
+err = AVERROR(EINVAL);
+goto fail;
+}
+token = av_strtok(NULL, "+", &save);
+}
+
+*dst = enabled_layers;
+*num = enabled_layers_count;
+
+av_free(sup_layers);
+av_free(user_layers_str);
+return 0;
+
+fail:
+RELEASE_PROPS(enabled_layers, enabled_layers_count);
+av_free(sup_layers);
+av_free(user_layers_str);
+return err;
+}
+
 /* Creates a VkInstance */
 static int create_instance(AVHWDeviceContext *ctx, AVDictionary *opts)
 {
@@ -558,13 +633,18 @@ static int create_instance(AVHWDeviceContext *ctx, 
AVDictionary *opts)
 /* Check for present/missing extensions */
 err = check_extensions(ctx, 0, opts, &inst_props.ppEnabledExtensionNames,
&inst_props.enabledExtensionCount, debug_mode);
+hwctx->enabled_inst_extensions = inst_props.ppEnabledExtensionNames;
+hwctx->nb_enabled_inst_extensions = inst_props.enabledExtensionCount;
 if (err < 0)
 return err;
 
 if (debug_mode) {
-static const char *layers[] = { "VK_LAYER_KHRONOS_validation" };
-inst_props.ppEnabledLayerNames = layers;
-inst_props.enabledLayerCount = FF_ARRAY_ELEMS(layers);
+err = check_validation_layers(ctx, opts, 
&inst_props.ppEnabledLayerNames,
+  &inst_props.enabledLayerCount);
+hwctx->enabled_validation_layers = inst_props.ppEnabledLayerNames;
+hwctx->nb_enabled

Re: [FFmpeg-devel] [PATCH 4/4] avutil/hwcontext_vulkan: fully support customizable validation layers

2021-11-23 Thread Lynne
23 Nov 2021, 10:01 by jianhua...@intel.com:

> Validation layer is an indispensable part of developing on Vulkan.
>
> The following commands is on how to enable validation layers:
>
> ffmpeg -init_hw_device 
> vulkan=0,debug=1,validation_layers=VK_LAYER_KHRONOS_validation+VK_LAYER_LUNARG_api_dump
>
> Signed-off-by: Wu Jianhua 
> ---
>  libavutil/hwcontext_vulkan.c | 110 ---
>  libavutil/hwcontext_vulkan.h |   7 +++
>  2 files changed, 97 insertions(+), 20 deletions(-)
>
> diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
> index 644ed947f8..b808f8f76c 100644
> --- a/libavutil/hwcontext_vulkan.c
> +++ b/libavutil/hwcontext_vulkan.c
> @@ -146,6 +146,13 @@ typedef struct AVVkFrameInternal {
>  }  \
>  } while(0)
>  
> +#define RELEASE_PROPS(props, count)  
>   \
> +if (props) { 
>   \
> +for (int i = 0; i < count; i++)  
>   \
> +av_free((void *)((props)[i]));   
>   \
> +av_free((void *)props);  
>   \
> +}
> +
>  static const struct {
>  enum AVPixelFormat pixfmt;
>  const VkFormat vkfmts[4];
> @@ -511,15 +518,83 @@ static int check_extensions(AVHWDeviceContext *ctx, int 
> dev, AVDictionary *opts,
>  return 0;
>  
>  fail:
> -if (extension_names)
> -for (int i = 0; i < extensions_found; i++)
> -av_free((void *)extension_names[i]);
> -av_free(extension_names);
> +RELEASE_PROPS(extension_names, extensions_found);
>  av_free(user_exts_str);
>  av_free(sup_ext);
>  return err;
>  }
>  
> +static int check_validation_layers(AVHWDeviceContext *ctx, AVDictionary 
> *opts,
> +   const char * const **dst, uint32_t *num)
> +{
> +int found, err = 0;
> +VulkanDevicePriv *priv = ctx->internal->priv;
> +FFVulkanFunctions *vk = &priv->vkfn;
> +
> +uint32_t sup_layer_count;
> +VkLayerProperties *sup_layers;
> +
> +AVDictionaryEntry *user_layers;
> +char *user_layers_str, *save, *token;
> +
> +const char **enabled_layers = NULL;
> +uint32_t enabled_layers_count = 0;
> +
> +user_layers = av_dict_get(opts, "validation_layers", NULL, 0);
> +if (!user_layers)
> +return 0;
> +
> +user_layers_str = av_strdup(user_layers->value);
> +if (!user_layers_str) {
> +err = AVERROR(EINVAL);
> +goto fail;
> +}
> +
> +vk->EnumerateInstanceLayerProperties(&sup_layer_count, NULL);
> +sup_layers = av_malloc_array(sup_layer_count, sizeof(VkLayerProperties));
> +if (!sup_layers)
> +return AVERROR(ENOMEM);
> +vk->EnumerateInstanceLayerProperties(&sup_layer_count, sup_layers);
> +
> +av_log(ctx, AV_LOG_VERBOSE, "Supported Validation layers:\n");
> +for (int i = 0; i < sup_layer_count; i++)
> +av_log(ctx, AV_LOG_VERBOSE, "\t%s\n", sup_layers[i].layerName);
> +
> +token = av_strtok(user_layers_str, "+", &save);
> +while (token) {
> +found = 0;
> +for (int j = 0; j < sup_layer_count; j++) {
> +if (!strcmp(token, sup_layers[j].layerName)) {
> +found = 1;
> +break;
> +}
> +}
> +if (found) {
> +av_log(ctx, AV_LOG_VERBOSE, "Requested Validation Layer: %s\n", 
> token);
> +ADD_VAL_TO_LIST(enabled_layers, enabled_layers_count, token);
> +} else {
> +av_log(ctx, AV_LOG_ERROR,
> +   "Validation Layer \"%s\" not support.\n", token);
> +err = AVERROR(EINVAL);
> +goto fail;
> +}
> +token = av_strtok(NULL, "+", &save);
> +}
> +
> +*dst = enabled_layers;
> +*num = enabled_layers_count;
> +
> +av_free(sup_layers);
> +av_free(user_layers_str);
> +return 0;
> +
> +fail:
> +RELEASE_PROPS(enabled_layers, enabled_layers_count);
> +av_free(sup_layers);
> +av_free(user_layers_str);
> +return err;
> +}
> +
>  /* Creates a VkInstance */
>  static int create_instance(AVHWDeviceContext *ctx, AVDictionary *opts)
>  {
> @@ -558,13 +633,18 @@ static int create_instance(AVHWDeviceContext *ctx, 
> AVDictionary *opts)
>  /* Check for present/missing extensions */
>  err = check_extensions(ctx, 0, opts, &inst_props.ppEnabledExtensionNames,
>  &inst_props.enabledExtensionCount, debug_mode);
> +hwctx->enabled_inst_extensions = inst_props.ppEnabledExtensionNames;
> +hwctx->nb_enabled_inst_extensions = inst_props.enabledExtensionCount;
>  if (err < 0)
>  return err;
>  
>  if (debug_mode) {
> -static const char *layers[] = { "VK_LAYER_KHRONOS_validation" };
> -inst_props.ppEnabledLayerNames = layers;
> -inst_props.enabledLayerCount = FF_ARRAY_ELEMS(layers);
> +err = chec

Re: [FFmpeg-devel] [PATCH 4/4] avutil/hwcontext_vulkan: fully support customizable validation layers

2021-11-23 Thread Wu, Jianhua



> -Original Message-
> From: ffmpeg-devel  On Behalf Of
> Lynne
> Sent: Tuesday, November 23, 2021 5:23 PM
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH 4/4] avutil/hwcontext_vulkan: fully
> support customizable validation layers
> 
> 23 Nov 2021, 10:01 by jianhua...@intel.com:
> 
> > Validation layer is an indispensable part of developing on Vulkan.
> >
> > The following commands is on how to enable validation layers:
> >
> > ffmpeg -init_hw_device
> >
> vulkan=0,debug=1,validation_layers=VK_LAYER_KHRONOS_validation+VK_L
> AYE
> > R_LUNARG_api_dump
> >
> > Signed-off-by: Wu Jianhua 
> > ---
> >  libavutil/hwcontext_vulkan.c | 110 ---
> 
> >  libavutil/hwcontext_vulkan.h |   7 +++
> >  2 files changed, 97 insertions(+), 20 deletions(-)
> >
> > diff --git a/libavutil/hwcontext_vulkan.c
> > b/libavutil/hwcontext_vulkan.c index 644ed947f8..b808f8f76c 100644
> > --- a/libavutil/hwcontext_vulkan.c
> > +++ b/libavutil/hwcontext_vulkan.c
> > @@ -146,6 +146,13 @@ typedef struct AVVkFrameInternal {
> >  }  \
> >  } while(0)
> >
> > +#define RELEASE_PROPS(props, count)
> > \
> > +if (props) {   
> > \
> > +for (int i = 0; i < count; i++)
> > \
> > +av_free((void *)((props)[i])); 
> > \
> > +av_free((void *)props);
> > \
> > +}
> > +
> >  static const struct {
> >  enum AVPixelFormat pixfmt;
> >  const VkFormat vkfmts[4];
> > @@ -511,15 +518,83 @@ static int check_extensions(AVHWDeviceContext
> > *ctx, int dev, AVDictionary *opts,  return 0;
> >
> >  fail:
> > -if (extension_names)
> > -for (int i = 0; i < extensions_found; i++)
> > -av_free((void *)extension_names[i]);
> > -av_free(extension_names);
> > +RELEASE_PROPS(extension_names, extensions_found);
> >  av_free(user_exts_str);
> >  av_free(sup_ext);
> >  return err;
> >  }
> >
> > +static int check_validation_layers(AVHWDeviceContext *ctx, AVDictionary
> *opts,
> > +   const char * const **dst, uint32_t
> > +*num) {
> > +int found, err = 0;
> > +VulkanDevicePriv *priv = ctx->internal->priv;
> > +FFVulkanFunctions *vk = &priv->vkfn;
> > +
> > +uint32_t sup_layer_count;
> > +VkLayerProperties *sup_layers;
> > +
> > +AVDictionaryEntry *user_layers;
> > +char *user_layers_str, *save, *token;
> > +
> > +const char **enabled_layers = NULL;
> > +uint32_t enabled_layers_count = 0;
> > +
> > +user_layers = av_dict_get(opts, "validation_layers", NULL, 0);
> > +if (!user_layers)
> > +return 0;
> > +
> > +user_layers_str = av_strdup(user_layers->value);
> > +if (!user_layers_str) {
> > +err = AVERROR(EINVAL);
> > +goto fail;
> > +}
> > +
> > +vk->EnumerateInstanceLayerProperties(&sup_layer_count, NULL);
> > +sup_layers = av_malloc_array(sup_layer_count,
> sizeof(VkLayerProperties));
> > +if (!sup_layers)
> > +return AVERROR(ENOMEM);
> > +vk->EnumerateInstanceLayerProperties(&sup_layer_count,
> > + sup_layers);
> > +
> > +av_log(ctx, AV_LOG_VERBOSE, "Supported Validation layers:\n");
> > +for (int i = 0; i < sup_layer_count; i++)
> > +av_log(ctx, AV_LOG_VERBOSE, "\t%s\n",
> > + sup_layers[i].layerName);
> > +
> > +token = av_strtok(user_layers_str, "+", &save);
> > +while (token) {
> > +found = 0;
> > +for (int j = 0; j < sup_layer_count; j++) {
> > +if (!strcmp(token, sup_layers[j].layerName)) {
> > +found = 1;
> > +break;
> > +}
> > +}
> > +if (found) {
> > +av_log(ctx, AV_LOG_VERBOSE, "Requested Validation Layer: %s\n",
> token);
> > +ADD_VAL_TO_LIST(enabled_layers, enabled_layers_count, token);
> > +} else {
> > +av_log(ctx, AV_LOG_ERROR,
> > +   "Validation Layer \"%s\" not support.\n", token);
> > +err = AVERROR(EINVAL);
> > +goto fail;
> > +}
> > +token = av_strtok(NULL, "+", &save);
> > +}
> > +
> > +*dst = enabled_layers;
> > +*num = enabled_layers_count;
> > +
> > +av_free(sup_layers);
> > +av_free(user_layers_str);
> > +return 0;
> > +
> > +fail:
> > +RELEASE_PROPS(enabled_layers, enabled_layers_count);
> > +av_free(sup_layers);
> > +av_free(user_layers_str);
> > +return err;
> > +}
> > +
> >  /* Creates a VkInstance */
> >  static int create_instance(AVHWDeviceContext *ctx, AVDictionary
> > *opts)  { @@ -558,13 +633,18 @@ static int
> > create_instance(AVHWDeviceContext *ctx, AVDictionary *opts)
> >  /* Check for present/mis

Re: [FFmpeg-devel] [PATCH 4/4] avutil/hwcontext_vulkan: fully support customizable validation layers

2021-11-23 Thread Lynne
23 Nov 2021, 10:48 by jianhua...@intel.com:

>
>
>> -Original Message-
>> From: ffmpeg-devel  On Behalf Of
>> Lynne
>> Sent: Tuesday, November 23, 2021 5:23 PM
>> To: FFmpeg development discussions and patches > de...@ffmpeg.org>
>> Subject: Re: [FFmpeg-devel] [PATCH 4/4] avutil/hwcontext_vulkan: fully
>> support customizable validation layers
>>
>> 23 Nov 2021, 10:01 by jianhua...@intel.com:
>>
>> > Validation layer is an indispensable part of developing on Vulkan.
>> >
>> > The following commands is on how to enable validation layers:
>> >
>> > ffmpeg -init_hw_device
>> >
>> vulkan=0,debug=1,validation_layers=VK_LAYER_KHRONOS_validation+VK_L
>> AYE
>> > R_LUNARG_api_dump
>> >
>> > Signed-off-by: Wu Jianhua 
>> > ---
>> >  libavutil/hwcontext_vulkan.c | 110 ---
>> 
>> >  libavutil/hwcontext_vulkan.h |   7 +++
>> >  2 files changed, 97 insertions(+), 20 deletions(-)
>> >
>> > diff --git a/libavutil/hwcontext_vulkan.c
>> > b/libavutil/hwcontext_vulkan.c index 644ed947f8..b808f8f76c 100644
>> > --- a/libavutil/hwcontext_vulkan.c
>> > +++ b/libavutil/hwcontext_vulkan.c
>> > @@ -146,6 +146,13 @@ typedef struct AVVkFrameInternal {
>> >  }  \
>> >  } while(0)
>> >
>> > +#define RELEASE_PROPS(props, count)   
>> >  \
>> > +if (props) {  
>> >  \
>> > +for (int i = 0; i < count; i++)   
>> >  \
>> > +av_free((void *)((props)[i]));
>> >  \
>> > +av_free((void *)props);   
>> >  \
>> > +}
>> > +
>> >  static const struct {
>> >  enum AVPixelFormat pixfmt;
>> >  const VkFormat vkfmts[4];
>> > @@ -511,15 +518,83 @@ static int check_extensions(AVHWDeviceContext
>> > *ctx, int dev, AVDictionary *opts,  return 0;
>> >
>> >  fail:
>> > -if (extension_names)
>> > -for (int i = 0; i < extensions_found; i++)
>> > -av_free((void *)extension_names[i]);
>> > -av_free(extension_names);
>> > +RELEASE_PROPS(extension_names, extensions_found);
>> >  av_free(user_exts_str);
>> >  av_free(sup_ext);
>> >  return err;
>> >  }
>> >
>> > +static int check_validation_layers(AVHWDeviceContext *ctx, AVDictionary
>> *opts,
>> > +   const char * const **dst, uint32_t
>> > +*num) {
>> > +int found, err = 0;
>> > +VulkanDevicePriv *priv = ctx->internal->priv;
>> > +FFVulkanFunctions *vk = &priv->vkfn;
>> > +
>> > +uint32_t sup_layer_count;
>> > +VkLayerProperties *sup_layers;
>> > +
>> > +AVDictionaryEntry *user_layers;
>> > +char *user_layers_str, *save, *token;
>> > +
>> > +const char **enabled_layers = NULL;
>> > +uint32_t enabled_layers_count = 0;
>> > +
>> > +user_layers = av_dict_get(opts, "validation_layers", NULL, 0);
>> > +if (!user_layers)
>> > +return 0;
>> > +
>> > +user_layers_str = av_strdup(user_layers->value);
>> > +if (!user_layers_str) {
>> > +err = AVERROR(EINVAL);
>> > +goto fail;
>> > +}
>> > +
>> > +vk->EnumerateInstanceLayerProperties(&sup_layer_count, NULL);
>> > +sup_layers = av_malloc_array(sup_layer_count,
>> sizeof(VkLayerProperties));
>> > +if (!sup_layers)
>> > +return AVERROR(ENOMEM);
>> > +vk->EnumerateInstanceLayerProperties(&sup_layer_count,
>> > + sup_layers);
>> > +
>> > +av_log(ctx, AV_LOG_VERBOSE, "Supported Validation layers:\n");
>> > +for (int i = 0; i < sup_layer_count; i++)
>> > +av_log(ctx, AV_LOG_VERBOSE, "\t%s\n",
>> > + sup_layers[i].layerName);
>> > +
>> > +token = av_strtok(user_layers_str, "+", &save);
>> > +while (token) {
>> > +found = 0;
>> > +for (int j = 0; j < sup_layer_count; j++) {
>> > +if (!strcmp(token, sup_layers[j].layerName)) {
>> > +found = 1;
>> > +break;
>> > +}
>> > +}
>> > +if (found) {
>> > +av_log(ctx, AV_LOG_VERBOSE, "Requested Validation Layer: 
>> > %s\n",
>> token);
>> > +ADD_VAL_TO_LIST(enabled_layers, enabled_layers_count, token);
>> > +} else {
>> > +av_log(ctx, AV_LOG_ERROR,
>> > +   "Validation Layer \"%s\" not support.\n", token);
>> > +err = AVERROR(EINVAL);
>> > +goto fail;
>> > +}
>> > +token = av_strtok(NULL, "+", &save);
>> > +}
>> > +
>> > +*dst = enabled_layers;
>> > +*num = enabled_layers_count;
>> > +
>> > +av_free(sup_layers);
>> > +av_free(user_layers_str);
>> > +return 0;
>> > +
>> > +fail:
>> > +RELEASE_PROPS(enabled_layers, enabled_layers_count);
>> > +av_free(sup_layers);
>> > +av_free(user_layers_str);
>> > +return err;
>> > +}
>> > +
>> >  /* Creates a VkInstance */
>> >  static int 

[FFmpeg-devel] [PATCH 1/4] lavfi/allfilters: move vf_chromaber_vulkan to video section

2021-11-23 Thread Anton Khirnov
---
 libavfilter/allfilters.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 29da7ef0d2..8c8a56fd58 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -104,7 +104,6 @@ extern const AVFilter ff_af_bandreject;
 extern const AVFilter ff_af_bass;
 extern const AVFilter ff_af_biquad;
 extern const AVFilter ff_af_bs2b;
-extern const AVFilter ff_vf_chromaber_vulkan;
 extern const AVFilter ff_af_channelmap;
 extern const AVFilter ff_af_channelsplit;
 extern const AVFilter ff_af_chorus;
@@ -185,6 +184,7 @@ extern const AVFilter ff_vf_boxblur;
 extern const AVFilter ff_vf_boxblur_opencl;
 extern const AVFilter ff_vf_bwdif;
 extern const AVFilter ff_vf_cas;
+extern const AVFilter ff_vf_chromaber_vulkan;
 extern const AVFilter ff_vf_chromahold;
 extern const AVFilter ff_vf_chromakey;
 extern const AVFilter ff_vf_chromanr;
-- 
2.33.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 3/4] ffmpeg: make -bits_per_raw_sample a per-output-stream option

2021-11-23 Thread Anton Khirnov
Also, document it and make it apply to audio in addition to video.
---
 doc/ffmpeg.texi  |  7 +++
 fftools/ffmpeg.c | 11 +++
 fftools/ffmpeg.h |  3 +++
 fftools/ffmpeg_opt.c | 11 +++
 4 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 8418573618..5279a05b10 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -1945,6 +1945,13 @@ filter (scale, aresample) in the graph.
 On by default, to explicitly disable it you need to specify
 @code{-noauto_conversion_filters}.
 
+@item -bits_per_raw_sample[:@var{stream_specifier}] @var{value} 
(@emph{output,per-stream})
+Declare the number of bits per raw sample in the given output stream to be
+@var{value}. Note that this option sets the information provided to the
+encoder/muxer, it does not change the stream to conform to this value. Setting
+values that do not match the stream properties may result in encoding failures
+or invalid output files.
+
 @end table
 
 @section Preset files
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 7dfcfc13f5..55ad4e558e 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3411,13 +3411,16 @@ static int init_output_stream_encode(OutputStream *ost, 
AVFrame *frame)
 switch (enc_ctx->codec_type) {
 case AVMEDIA_TYPE_AUDIO:
 enc_ctx->sample_fmt = 
av_buffersink_get_format(ost->filter->filter);
-if (dec_ctx)
-enc_ctx->bits_per_raw_sample = FFMIN(dec_ctx->bits_per_raw_sample,
- 
av_get_bytes_per_sample(enc_ctx->sample_fmt) << 3);
 enc_ctx->sample_rate= 
av_buffersink_get_sample_rate(ost->filter->filter);
 enc_ctx->channel_layout = 
av_buffersink_get_channel_layout(ost->filter->filter);
 enc_ctx->channels   = 
av_buffersink_get_channels(ost->filter->filter);
 
+if (ost->bits_per_raw_sample)
+enc_ctx->bits_per_raw_sample = ost->bits_per_raw_sample;
+else if (dec_ctx)
+enc_ctx->bits_per_raw_sample = FFMIN(dec_ctx->bits_per_raw_sample,
+ 
av_get_bytes_per_sample(enc_ctx->sample_fmt) << 3);
+
 init_encoder_time_base(ost, av_make_q(1, enc_ctx->sample_rate));
 break;
 
@@ -3460,7 +3463,7 @@ static int init_output_stream_encode(OutputStream *ost, 
AVFrame *frame)
 enc_ctx->width   != dec_ctx->width  ||
 enc_ctx->height  != dec_ctx->height ||
 enc_ctx->pix_fmt != dec_ctx->pix_fmt) {
-enc_ctx->bits_per_raw_sample = frame_bits_per_raw_sample;
+enc_ctx->bits_per_raw_sample = ost->bits_per_raw_sample;
 }
 
 // Field order: autodetection
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 545ff1c8e7..3d9bb30e72 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -236,6 +236,8 @@ typedef struct OptionsContext {
 intnb_enc_time_bases;
 SpecifierOpt *autoscale;
 intnb_autoscale;
+SpecifierOpt *bits_per_raw_sample;
+intnb_bits_per_raw_sample;
 } OptionsContext;
 
 typedef struct InputFilter {
@@ -493,6 +495,7 @@ typedef struct OutputStream {
 int top_field_first;
 int rotate_overridden;
 int autoscale;
+int bits_per_raw_sample;
 double rotate_override_value;
 
 AVRational frame_aspect_ratio;
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index b423d0e59c..e839a830a6 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -96,6 +96,7 @@ static const char *const opt_name_discard[]   
= {"discard", NULL
 static const char *const opt_name_disposition[]   = 
{"disposition", NULL};
 static const char *const opt_name_time_bases[]= {"time_base", 
NULL};
 static const char *const opt_name_enc_time_bases[]= 
{"enc_time_base", NULL};
+static const char *const opt_name_bits_per_raw_sample[]   = 
{"bits_per_raw_sample", NULL};
 
 #define WARN_MULTIPLE_OPT_USAGE(name, type, so, st)\
 {\
@@ -167,7 +168,6 @@ int abort_on_flags= 0;
 int print_stats   = -1;
 int qp_hist   = 0;
 int stdin_interaction = 1;
-int frame_bits_per_raw_sample = 0;
 float max_error_rate  = 2.0/3;
 char *filter_nbthreads;
 int filter_complex_nbthreads = 0;
@@ -1636,6 +1636,9 @@ static OutputStream *new_output_stream(OptionsContext *o, 
AVFormatContext *oc, e
 ost->muxing_queue_data_threshold = 50*1024*1024;
 MATCH_PER_STREAM_OPT(muxing_queue_data_threshold, i, 
ost->muxing_queue_data_threshold, oc, st);
 
+MATCH_PER_STREAM_OPT(bits_per_raw_sample, i, ost->bits_per_raw_sample,
+ oc, st);
+
 if (oc->oformat->flags & AVFMT_GLOBALHEADER)
 ost->enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
 
@@ -1801,7 +1804,6 @@ static OutputStream *new_video_stream(OptionsContext *o, 
AVFormatContext *oc, in
 exit_program(1);
 }
 
-video_enc->bits_per_raw_sample = frame_bits_per_raw_sample;

[FFmpeg-devel] [PATCH 4/4] ffmpeg: only copy bits_per_sample from decoder when it remains valid

2021-11-23 Thread Anton Khirnov
I.e. when the only filters that are applied do not modify the frame
data.
---
 fftools/ffmpeg.c| 14 +-
 fftools/ffmpeg.h|  3 +++
 fftools/ffmpeg_filter.c | 26 ++
 3 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 55ad4e558e..ff4bae11b3 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3417,7 +3417,7 @@ static int init_output_stream_encode(OutputStream *ost, 
AVFrame *frame)
 
 if (ost->bits_per_raw_sample)
 enc_ctx->bits_per_raw_sample = ost->bits_per_raw_sample;
-else if (dec_ctx)
+else if (dec_ctx && ost->filter->graph->is_meta)
 enc_ctx->bits_per_raw_sample = FFMIN(dec_ctx->bits_per_raw_sample,
  
av_get_bytes_per_sample(enc_ctx->sample_fmt) << 3);
 
@@ -3443,7 +3443,10 @@ static int init_output_stream_encode(OutputStream *ost, 
AVFrame *frame)
 av_buffersink_get_sample_aspect_ratio(ost->filter->filter);
 
 enc_ctx->pix_fmt = av_buffersink_get_format(ost->filter->filter);
-if (dec_ctx)
+
+if (ost->bits_per_raw_sample)
+enc_ctx->bits_per_raw_sample = ost->bits_per_raw_sample;
+else if (dec_ctx && ost->filter->graph->is_meta)
 enc_ctx->bits_per_raw_sample = FFMIN(dec_ctx->bits_per_raw_sample,
  
av_pix_fmt_desc_get(enc_ctx->pix_fmt)->comp[0].depth);
 
@@ -3459,13 +3462,6 @@ static int init_output_stream_encode(OutputStream *ost, 
AVFrame *frame)
 
 ost->st->avg_frame_rate = ost->frame_rate;
 
-if (!dec_ctx ||
-enc_ctx->width   != dec_ctx->width  ||
-enc_ctx->height  != dec_ctx->height ||
-enc_ctx->pix_fmt != dec_ctx->pix_fmt) {
-enc_ctx->bits_per_raw_sample = ost->bits_per_raw_sample;
-}
-
 // Field order: autodetection
 if (frame) {
 if (enc_ctx->flags & (AV_CODEC_FLAG_INTERLACED_DCT | 
AV_CODEC_FLAG_INTERLACED_ME) &&
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 3d9bb30e72..51ab81b161 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -294,6 +294,9 @@ typedef struct FilterGraph {
 
 AVFilterGraph *graph;
 int reconfiguration;
+// true when the filtergraph contains only meta filters
+// that do not modify the frame data
+int is_meta;
 
 InputFilter   **inputs;
 int  nb_inputs;
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index c70903295f..ac7a74ba02 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -980,6 +980,30 @@ static void cleanup_filtergraph(FilterGraph *fg)
 avfilter_graph_free(&fg->graph);
 }
 
+static int filter_is_buffersrc(const AVFilterContext *f)
+{
+return f->nb_inputs == 0 &&
+   (!strcmp(f->filter->name, "buffersrc") ||
+!strcmp(f->filter->name, "abuffersrc"));
+}
+
+static int graph_is_meta(AVFilterGraph *graph)
+{
+for (unsigned i = 0; i < graph->nb_filters; i++) {
+const AVFilterContext *f = graph->filters[i];
+
+/* in addition to filters flagged as meta, also
+ * disregard sinks and buffersources (but not other sources,
+ * since they introduce data we are not aware of)
+ */
+if (!((f->filter->flags & AVFILTER_FLAG_META) ||
+  f->nb_outputs == 0  ||
+  filter_is_buffersrc(f)))
+return 0;
+}
+return 1;
+}
+
 int configure_filtergraph(FilterGraph *fg)
 {
 AVFilterInOut *inputs, *outputs, *cur;
@@ -1080,6 +1104,8 @@ int configure_filtergraph(FilterGraph *fg)
 if ((ret = avfilter_graph_config(fg->graph, NULL)) < 0)
 goto fail;
 
+fg->is_meta = graph_is_meta(fg->graph);
+
 /* limit the lists of allowed formats to the ones selected, to
  * make sure they stay the same if the filtergraph is reconfigured later */
 for (i = 0; i < fg->nb_outputs; i++) {
-- 
2.33.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 2/4] avfilter: add AVFILTER_FLAG_META

2021-11-23 Thread Anton Khirnov
This flag allows distinguishing between filters that actually modify the
data and those that only modify metadata or gather some stream
information.
---
 doc/APIchanges |  3 +++
 libavfilter/af_acopy.c |  1 +
 libavfilter/af_aformat.c   |  1 +
 libavfilter/af_anull.c |  1 +
 libavfilter/af_asdr.c  |  1 +
 libavfilter/af_asetrate.c  |  1 +
 libavfilter/af_ashowinfo.c |  1 +
 libavfilter/af_asr.c   |  1 +
 libavfilter/af_astats.c|  2 +-
 libavfilter/af_drmeter.c   |  1 +
 libavfilter/af_replaygain.c|  1 +
 libavfilter/af_silencedetect.c |  1 +
 libavfilter/af_volumedetect.c  |  1 +
 libavfilter/avfilter.h | 16 
 libavfilter/f_bench.c  |  2 ++
 libavfilter/f_cue.c|  1 +
 libavfilter/f_latency.c|  3 ++-
 libavfilter/f_metadata.c   |  6 --
 libavfilter/f_perms.c  |  6 --
 libavfilter/f_realtime.c   |  2 ++
 libavfilter/f_segment.c|  4 ++--
 libavfilter/f_select.c |  2 +-
 libavfilter/f_sendcmd.c|  2 ++
 libavfilter/f_sidedata.c   |  6 --
 libavfilter/fifo.c |  2 ++
 libavfilter/setpts.c   |  2 ++
 libavfilter/settb.c|  2 ++
 libavfilter/split.c|  4 ++--
 libavfilter/trim.c |  1 +
 libavfilter/version.h  |  2 +-
 libavfilter/vf_addroi.c|  2 ++
 libavfilter/vf_aspect.c|  2 ++
 libavfilter/vf_bbox.c  |  2 +-
 libavfilter/vf_blackdetect.c   |  2 +-
 libavfilter/vf_blackframe.c|  1 +
 libavfilter/vf_copy.c  |  1 +
 libavfilter/vf_cropdetect.c|  2 +-
 libavfilter/vf_entropy.c   |  2 +-
 libavfilter/vf_find_rect.c |  1 +
 libavfilter/vf_format.c|  4 
 libavfilter/vf_fps.c   |  1 +
 libavfilter/vf_framestep.c |  2 +-
 libavfilter/vf_freezedetect.c  |  1 +
 libavfilter/vf_identity.c  |  8 ++--
 libavfilter/vf_idet.c  |  1 +
 libavfilter/vf_mestimate.c |  1 +
 libavfilter/vf_null.c  |  1 +
 libavfilter/vf_ocr.c   |  1 +
 libavfilter/vf_psnr.c  |  4 +++-
 libavfilter/vf_qp.c|  3 ++-
 libavfilter/vf_readeia608.c|  4 +++-
 libavfilter/vf_readvitc.c  |  1 +
 libavfilter/vf_scdet.c |  1 +
 libavfilter/vf_setparams.c |  3 +++
 libavfilter/vf_showinfo.c  |  1 +
 libavfilter/vf_ssim.c  |  4 +++-
 libavfilter/vf_vfrdet.c|  1 +
 libavfilter/vf_vidstabdetect.c |  1 +
 libavfilter/vf_vif.c   |  4 +++-
 libavfilter/vf_vmafmotion.c|  1 +
 60 files changed, 116 insertions(+), 26 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 565f7e091e..031e09aab2 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -14,6 +14,9 @@ libavutil: 2021-04-27
 
 API changes, most recent first:
 
+2021-11-xx - xx - lavfi 8.18.100 - avfilter.h
+  Add AVFILTER_FLAG_META.
+
 2021-11-17 - xx - lavf 57.9.100 - frame.h
   Add AV_FRAME_DATA_DOVI_RPU_BUFFER.
 
diff --git a/libavfilter/af_acopy.c b/libavfilter/af_acopy.c
index 32455d9186..751644ebc7 100644
--- a/libavfilter/af_acopy.c
+++ b/libavfilter/af_acopy.c
@@ -63,6 +63,7 @@ static const AVFilterPad acopy_outputs[] = {
 const AVFilter ff_af_acopy = {
 .name  = "acopy",
 .description   = NULL_IF_CONFIG_SMALL("Copy the input audio unchanged to 
the output."),
+.flags = AVFILTER_FLAG_META,
 FILTER_INPUTS(acopy_inputs),
 FILTER_OUTPUTS(acopy_outputs),
 };
diff --git a/libavfilter/af_aformat.c b/libavfilter/af_aformat.c
index 7e25c0c6a4..8fdb070b4e 100644
--- a/libavfilter/af_aformat.c
+++ b/libavfilter/af_aformat.c
@@ -162,6 +162,7 @@ const AVFilter ff_af_aformat = {
 .uninit= uninit,
 .priv_size = sizeof(AFormatContext),
 .priv_class= &aformat_class,
+.flags = AVFILTER_FLAG_META,
 FILTER_INPUTS(avfilter_af_aformat_inputs),
 FILTER_OUTPUTS(avfilter_af_aformat_outputs),
 FILTER_QUERY_FUNC(query_formats),
diff --git a/libavfilter/af_anull.c b/libavfilter/af_anull.c
index 065d37e17e..2c52636250 100644
--- a/libavfilter/af_anull.c
+++ b/libavfilter/af_anull.c
@@ -44,6 +44,7 @@ static const AVFilterPad avfilter_af_anull_outputs[] = {
 const AVFilter ff_af_anull = {
 .name  = "anull",
 .description   = NULL_IF_CONFIG_SMALL("Pass the source unchanged to the 
output."),
+.flags = AVFILTER_FLAG_META,
 FILTER_INPUTS(avfilter_af_anull_inputs),
 FILTER_OUTPUTS(avfilter_af_anull_outputs),
 };
diff --git a/libavfilter/af_asdr.c b/libavfilter/af_asdr.c
index 72b6dfa78b..2e9bbb4649 100644
--- a/libavfilter/af_asdr.c
+++ b/libavfilter/af_asdr.c
@@ -166,6 +166,7 @@ const AVFilter ff_af_asdr = {
 .priv_size  = sizeof(AudioSDRContext),
 .activate   = activate,
 .uninit = uninit,
+.flags  = AVFILTER_FLAG_META,
 FILTER_INPUTS(inputs),
 FILTER_OUTPUTS(outputs),
 FILTER_SINGLE_SAMPLEFMT(AV_SAMPLE_FMT_DBLP),
diff

Re: [FFmpeg-devel] [PATCH 2/4] avfilter: add AVFILTER_FLAG_META

2021-11-23 Thread Hendrik Leppkes
On Tue, Nov 23, 2021 at 11:31 AM Anton Khirnov  wrote:
>
> This flag allows distinguishing between filters that actually modify the
> data and those that only modify metadata or gather some stream
> information.

A "meta" filter has me associate it with other concepts, maybe
spelling out "metadata" would be better?

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

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


Re: [FFmpeg-devel] [PATCH 4/4] avutil/hwcontext_vulkan: fully support customizable validation layers

2021-11-23 Thread Wu Jianhua
Lynne:
>23 Nov 2021, 10:48 by jianhua...@intel.com:
>>Lynne:
>>> From: ffmpeg-devel  On Behalf Of
>>> Lynne
>>> Sent: Tuesday, November 23, 2021 5:23 PM
>>> To: FFmpeg development discussions and patches >> de...@ffmpeg.org>
>>> Subject: Re: [FFmpeg-devel] [PATCH 4/4] avutil/hwcontext_vulkan: fully
>>> support customizable validation layers
>>>
>>> 23 Nov 2021, 10:01 by jianhua...@intel.com:
>>>
>>> > Validation layer is an indispensable part of developing on Vulkan.
>>> >
>>> > The following commands is on how to enable validation layers:
>>> >
>>> > ffmpeg -init_hw_device
>>> >
>>> vulkan=0,debug=1,validation_layers=VK_LAYER_KHRONOS_validation+VK_L
>>> AYE
>>> > R_LUNARG_api_dump
>>> >
>>> > Signed-off-by: Wu Jianhua 
>>> > ---
>>> >  libavutil/hwcontext_vulkan.c | 110 ---
>>> 
>>> >  libavutil/hwcontext_vulkan.h |   7 +++
>>> >  2 files changed, 97 insertions(+), 20 deletions(-)
>>> >
>>> >
>>> > +/**
>>> > + * Enabled validation layers.
>>> > + * If no layers are enabled, set these fields to NULL, and 0 
>>> > respectively.
>>> > + */
>>> > +const char * const *enabled_validation_layers;
>>> > +int nb_enabled_validation_layers;
>>> > +
>>> >
>>>
>>> Why are you exposing them? Do API users really need to know this?
>>>
>>
>> It's okay. For it's only integrated in a really small separate function it
>> could be skipped by the status debug_mode as before. And validation
>> layers are embed by other specific drivers, platforms(such as those
>> specific layers in androids) or SDK, the FFmpeg is not need to do anything
>> more whatever the current is compiled with optimization mode or debug mode.
>> The use who only want to use filter is simply not able to know how to
>> enable the debug_mode. For me, as a user also, it is important to me, I
>> don't want to changed the code then compiling to use the specific validation
>> layers again and again.  And not only the developer need to use it, those
>> people who help us test could report a more detailed problem. I think it's
>> really benefit.
>>
>
> Sorry, I didn't quite understand that.
> I'm not objecting to being able to use custom debug layers and activating
> them if they're requested from the user. We already do that for the
> standard debug layer anyway. I'm just not sure I understand why filters
> would need to know if a debug layer is ran, and which one it is, by exposing
> them via the public API.
>

Oh! My bad. I supposed you mean we may be not necessary to expose
layer info to the Device Context, right?

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

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


[FFmpeg-devel] [PATCH] avformat/mov: add option max_stts_delta

2021-11-23 Thread Gyan Doshi
Very high stts sample deltas may occasionally be intended but usually
they are written in error or used to store a negative value for dts correction
when treated as signed 32-bit integers.

This option lets the user set an upper limit, beyond which the delta
is clamped to 1. Negative values of under 1 second are used to adjust
dts.

Unit is the track time scale. Default is INT_MAX which maintains current 
handling.
---
 doc/demuxers.texi  |  5 +
 libavformat/isom.h |  1 +
 libavformat/mov.c  | 14 +-
 3 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index cab8a7072c..f91ac92cf1 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -715,6 +715,11 @@ specify.
 16-byte key, in hex, to decrypt files encrypted using ISO Common Encryption 
(CENC/AES-128 CTR; ISO/IEC 23001-7).
 @end table
 
+@item max_stts_delta
+The sample offsets stored in a track's stts box are 32-bit unsigned integers. 
However, very large values usually indicate
+a value written by error or a storage of a small negative value as a way to 
correct accumulated DTS delay.
+Range is 0 to UINT_MAX. Default is INT_MAX.
+
 @subsection Audible AAX
 
 Audible AAX files are encrypted M4B files, and they can be decrypted by 
specifying a 4 byte activation secret.
diff --git a/libavformat/isom.h b/libavformat/isom.h
index ef8f19b18c..625dea8421 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -305,6 +305,7 @@ typedef struct MOVContext {
 int32_t movie_display_matrix[3][3]; ///< display matrix from mvhd
 int have_read_mfra_size;
 uint32_t mfra_size;
+uint32_t max_stts_delta;
 } MOVContext;
 
 int ff_mp4_read_descr_len(AVIOContext *pb);
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 451cb78bbf..bbda07ac42 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3965,14 +3965,17 @@ static void mov_build_index(MOVContext *mov, AVStream 
*st)
 current_offset += sample_size;
 stream_size += sample_size;
 
-/* A negative sample duration is invalid based on the spec,
- * but some samples need it to correct the DTS. */
-if (sc->stts_data[stts_index].duration < 0) {
+/* STTS sample offsets are uint32 but some files store it as 
int32
+ * with negative values used to correct DTS delays.
+   There may be abnormally large values as well. */
+if (sc->stts_data[stts_index].duration > mov->max_stts_delta) {
+// assume high delta is a negative correction if less than 
1 second
+int32_t delta_magnitude = *((int32_t 
*)&sc->stts_data[stts_index].duration);
 av_log(mov->fc, AV_LOG_WARNING,
-   "Invalid SampleDelta %d in STTS, at %d st:%d\n",
+   "Correcting too large SampleDelta %u in STTS, at %d 
st:%d.\n",
sc->stts_data[stts_index].duration, stts_index,
st->index);
-dts_correction += sc->stts_data[stts_index].duration - 1;
+dts_correction += (delta_magnitude < 0 && 
FFABS(delta_magnitude) < sc->time_scale ? delta_magnitude - 1 : 0);
 sc->stts_data[stts_index].duration = 1;
 }
 current_dts += sc->stts_data[stts_index].duration;
@@ -8566,6 +8569,7 @@ static const AVOption mov_options[] = {
 { "decryption_key", "The media decryption key (hex)", 
OFFSET(decryption_key), AV_OPT_TYPE_BINARY, .flags = AV_OPT_FLAG_DECODING_PARAM 
},
 { "enable_drefs", "Enable external track support.", OFFSET(enable_drefs), 
AV_OPT_TYPE_BOOL,
 {.i64 = 0}, 0, 1, FLAGS },
+{ "max_stts_delta", "treat offsets above this value as invalid", 
OFFSET(max_stts_delta), AV_OPT_TYPE_INT, {.i64 = INT_MAX}, 0, UINT_MAX, .flags 
= AV_OPT_FLAG_DECODING_PARAM },
 
 { NULL },
 };
-- 
2.33.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 v2] avformat/mov: add option max_stts_delta

2021-11-23 Thread Gyan Doshi
Very high stts sample deltas may occasionally be intended but usually
they are written in error or used to store a negative value for dts correction
when treated as signed 32-bit integers.

This option lets the user set an upper limit, beyond which the delta
is clamped to 1. Negative values of under 1 second are used to adjust
dts.

Unit is the track time scale. Default is INT_MAX which maintains current 
handling.
---
 doc/demuxers.texi  |  6 ++
 libavformat/isom.h |  1 +
 libavformat/mov.c  | 14 +-
 3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index cab8a7072c..15078b9b1b 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -713,6 +713,12 @@ specify.
 
 @item decryption_key
 16-byte key, in hex, to decrypt files encrypted using ISO Common Encryption 
(CENC/AES-128 CTR; ISO/IEC 23001-7).
+
+@item max_stts_delta
+The sample offsets stored in a track's stts box are 32-bit unsigned integers. 
However, very large values usually indicate
+a value written by error or a storage of a small negative value as a way to 
correct accumulated DTS delay.
+Range is 0 to UINT_MAX. Default is INT_MAX.
+
 @end table
 
 @subsection Audible AAX
diff --git a/libavformat/isom.h b/libavformat/isom.h
index ef8f19b18c..625dea8421 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -305,6 +305,7 @@ typedef struct MOVContext {
 int32_t movie_display_matrix[3][3]; ///< display matrix from mvhd
 int have_read_mfra_size;
 uint32_t mfra_size;
+uint32_t max_stts_delta;
 } MOVContext;
 
 int ff_mp4_read_descr_len(AVIOContext *pb);
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 451cb78bbf..bbda07ac42 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3965,14 +3965,17 @@ static void mov_build_index(MOVContext *mov, AVStream 
*st)
 current_offset += sample_size;
 stream_size += sample_size;
 
-/* A negative sample duration is invalid based on the spec,
- * but some samples need it to correct the DTS. */
-if (sc->stts_data[stts_index].duration < 0) {
+/* STTS sample offsets are uint32 but some files store it as 
int32
+ * with negative values used to correct DTS delays.
+   There may be abnormally large values as well. */
+if (sc->stts_data[stts_index].duration > mov->max_stts_delta) {
+// assume high delta is a negative correction if less than 
1 second
+int32_t delta_magnitude = *((int32_t 
*)&sc->stts_data[stts_index].duration);
 av_log(mov->fc, AV_LOG_WARNING,
-   "Invalid SampleDelta %d in STTS, at %d st:%d\n",
+   "Correcting too large SampleDelta %u in STTS, at %d 
st:%d.\n",
sc->stts_data[stts_index].duration, stts_index,
st->index);
-dts_correction += sc->stts_data[stts_index].duration - 1;
+dts_correction += (delta_magnitude < 0 && 
FFABS(delta_magnitude) < sc->time_scale ? delta_magnitude - 1 : 0);
 sc->stts_data[stts_index].duration = 1;
 }
 current_dts += sc->stts_data[stts_index].duration;
@@ -8566,6 +8569,7 @@ static const AVOption mov_options[] = {
 { "decryption_key", "The media decryption key (hex)", 
OFFSET(decryption_key), AV_OPT_TYPE_BINARY, .flags = AV_OPT_FLAG_DECODING_PARAM 
},
 { "enable_drefs", "Enable external track support.", OFFSET(enable_drefs), 
AV_OPT_TYPE_BOOL,
 {.i64 = 0}, 0, 1, FLAGS },
+{ "max_stts_delta", "treat offsets above this value as invalid", 
OFFSET(max_stts_delta), AV_OPT_TYPE_INT, {.i64 = INT_MAX}, 0, UINT_MAX, .flags 
= AV_OPT_FLAG_DECODING_PARAM },
 
 { NULL },
 };
-- 
2.33.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 1/2] avformat/mxf: support MCA audio information

2021-11-23 Thread Marc-Antoine Arnaud
---
 doc/demuxers.texi |  10 ++
 libavformat/mxf.h |   1 +
 libavformat/mxfdec.c  | 293 +-
 libavformat/version.h |   2 +-
 4 files changed, 299 insertions(+), 7 deletions(-)

diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index 1c9575b2e8..fecfeadb47 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -770,6 +770,16 @@ MJPEG stream. Turning this option on by setting it to 1 
will result in a stricte
 of the boundary value.
 @end table
 
+@section mxf
+
+MXF demuxer.
+
+@table @option
+
+@item -skip_audio_reordering @var{bool}
+This option will disable the audio reordering based on Multi-Channel Audio 
(MCA) labelling (SMPTE ST-377-4).
+@end table
+
 @section rawvideo
 
 Raw video demuxer.
diff --git a/libavformat/mxf.h b/libavformat/mxf.h
index fe9c52732c..cddbcb13c9 100644
--- a/libavformat/mxf.h
+++ b/libavformat/mxf.h
@@ -50,6 +50,7 @@ enum MXFMetadataSetType {
 TaggedValue,
 TapeDescriptor,
 AVCSubDescriptor,
+MCASubDescriptor,
 };
 
 enum MXFFrameLayout {
diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index af9d33f796..58ba330475 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -51,11 +51,14 @@
 #include "libavutil/mastering_display_metadata.h"
 #include "libavutil/mathematics.h"
 #include "libavcodec/bytestream.h"
+#include "libavcodec/internal.h"
+#include "libavutil/channel_layout.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/parseutils.h"
 #include "libavutil/timecode.h"
 #include "libavutil/opt.h"
 #include "avformat.h"
+#include "avlanguage.h"
 #include "internal.h"
 #include "mxf.h"
 
@@ -177,6 +180,8 @@ typedef struct {
 int body_sid;
 MXFWrappingScheme wrapping;
 int edit_units_per_packet; /* how many edit units to read at a time (PCM, 
ClipWrapped) */
+int require_reordering;
+int channel_ordering[FF_SANE_NB_CHANNELS];
 } MXFTrack;
 
 typedef struct MXFDescriptor {
@@ -205,6 +210,8 @@ typedef struct MXFDescriptor {
 unsigned int vert_subsampling;
 UID *file_descriptors_refs;
 int file_descriptors_count;
+UID *sub_descriptors_refs;
+int sub_descriptors_count;
 int linked_track_id;
 uint8_t *extradata;
 int extradata_size;
@@ -217,6 +224,15 @@ typedef struct MXFDescriptor {
 size_t coll_size;
 } MXFDescriptor;
 
+typedef struct MXFMCASubDescriptor {
+MXFMetadataSet meta;
+UID uid;
+UID mca_link_id;
+UID mca_group_link_id;
+UID mca_label_dictionary_id;
+char *language;
+} MXFMCASubDescriptor;
+
 typedef struct MXFIndexTableSegment {
 MXFMetadataSet meta;
 int edit_unit_byte_count;
@@ -290,6 +306,7 @@ typedef struct MXFContext {
 int nb_index_tables;
 MXFIndexTable *index_tables;
 int eia608_extract;
+int skip_audio_reordering;
 } MXFContext;
 
 /* NOTE: klv_offset is not set (-1) for local keys */
@@ -311,6 +328,9 @@ static const uint8_t mxf_system_item_key_cp[]  
= { 0x06,0x0e,0x2b,0x
 static const uint8_t mxf_system_item_key_gc[]  = { 
0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x03,0x01,0x14 };
 static const uint8_t mxf_klv_key[] = { 
0x06,0x0e,0x2b,0x34 };
 static const uint8_t mxf_apple_coll_prefix[]   = { 
0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0e,0x0e,0x20,0x04,0x01,0x05,0x03,0x01 };
+static const uint8_t mxf_audio_channel[]   = { 
0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0d,0x03,0x02,0x01 };
+static const uint8_t mxf_soundfield_group[]= { 
0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0d,0x03,0x02,0x02 };
+
 /* complete keys to match */
 static const uint8_t mxf_crypto_source_container_ul[]  = { 
0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x09,0x06,0x01,0x01,0x02,0x02,0x00,0x00,0x00 
};
 static const uint8_t mxf_encrypted_triplet_key[]   = { 
0x06,0x0e,0x2b,0x34,0x02,0x04,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x7e,0x01,0x00 
};
@@ -323,6 +343,15 @@ static const uint8_t mxf_indirect_value_utf16be[]  
= { 0x42,0x01,0x10,0x
 static const uint8_t mxf_apple_coll_max_cll[]  = { 
0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0e,0x0e,0x20,0x04,0x01,0x05,0x03,0x01,0x01 
};
 static const uint8_t mxf_apple_coll_max_fall[] = { 
0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0e,0x0e,0x20,0x04,0x01,0x05,0x03,0x01,0x02 
};
 
+static const uint8_t mxf_mca_label_dictionary_id[] = { 
0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0e,0x01,0x03,0x07,0x01,0x01,0x00,0x00,0x00 
};
+static const uint8_t mxf_mca_tag_symbol[]  = { 
0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0e,0x01,0x03,0x07,0x01,0x02,0x00,0x00,0x00 
};
+static const uint8_t mxf_mca_tag_name[]= { 
0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0e,0x01,0x03,0x07,0x01,0x03,0x00,0x00,0x00 
};
+static const uint8_t mxf_mca_link_id[] = { 
0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0e,0x01,0x03,0x07,0x01,0x05,0x00,0x00,0x00 
};
+static const uint8_t mxf_soundfield_group_link_id[]= { 
0x06,0x0e,0x2b,0x

[FFmpeg-devel] [PATCH 2/2] avformat/mxf: add documentation for eia608_extract parameter

2021-11-23 Thread Marc-Antoine Arnaud
---
 doc/demuxers.texi | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index fecfeadb47..06f666b5f1 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -776,6 +776,9 @@ MXF demuxer.
 
 @table @option
 
+@item -eia608_extract @var{bool}
+Extract EIA-608 captions from SMPTE 436M track
+
 @item -skip_audio_reordering @var{bool}
 This option will disable the audio reordering based on Multi-Channel Audio 
(MCA) labelling (SMPTE ST-377-4).
 @end table
-- 
2.33.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 4/4] avutil/hwcontext_vulkan: fully support customizable validation layers

2021-11-23 Thread Lynne
23 Nov 2021, 12:03 by toq...@outlook.com:

> Lynne:
> >23 Nov 2021, 10:48 by jianhua...@intel.com:
> >>Lynne:
>
 From: ffmpeg-devel  On Behalf Of
 Lynne
 Sent: Tuesday, November 23, 2021 5:23 PM
 To: FFmpeg development discussions and patches >>> de...@ffmpeg.org>
 Subject: Re: [FFmpeg-devel] [PATCH 4/4] avutil/hwcontext_vulkan: fully
 support customizable validation layers

 23 Nov 2021, 10:01 by jianhua...@intel.com:

 > Validation layer is an indispensable part of developing on Vulkan.
 >
 > The following commands is on how to enable validation layers:
 >
 > ffmpeg -init_hw_device
 >
 vulkan=0,debug=1,validation_layers=VK_LAYER_KHRONOS_validation+VK_L
 AYE
 > R_LUNARG_api_dump
 >
 > Signed-off-by: Wu Jianhua 
 > ---
 >  libavutil/hwcontext_vulkan.c | 110 ---
 
 >  libavutil/hwcontext_vulkan.h |   7 +++
 >  2 files changed, 97 insertions(+), 20 deletions(-)
 >
 >
 > +/**
 > + * Enabled validation layers.
 > + * If no layers are enabled, set these fields to NULL, and 0 
 > respectively.
 > + */
 > +const char * const *enabled_validation_layers;
 > +int nb_enabled_validation_layers;
 > +
 >

 Why are you exposing them? Do API users really need to know this?

>>>
>>> It's okay. For it's only integrated in a really small separate function it
>>> could be skipped by the status debug_mode as before. And validation
>>> layers are embed by other specific drivers, platforms(such as those
>>> specific layers in androids) or SDK, the FFmpeg is not need to do anything
>>> more whatever the current is compiled with optimization mode or debug mode.
>>> The use who only want to use filter is simply not able to know how to
>>> enable the debug_mode. For me, as a user also, it is important to me, I
>>> don't want to changed the code then compiling to use the specific validation
>>> layers again and again.  And not only the developer need to use it, those
>>> people who help us test could report a more detailed problem. I think it's
>>> really benefit.
>>>
>>
>> Sorry, I didn't quite understand that.
>> I'm not objecting to being able to use custom debug layers and activating
>> them if they're requested from the user. We already do that for the
>> standard debug layer anyway. I'm just not sure I understand why filters
>> would need to know if a debug layer is ran, and which one it is, by exposing
>> them via the public API.
>>
>
> Oh! My bad. I supposed you mean we may be not necessary to expose
> layer info to the Device Context, right?
>

Yup, that's right. We'd like to keep the API as small as possible, and
it's already quite large compared to other hwcontexts. In this case,
I don't think it's necessary. API users already know, since they can request
layers, and filters shouldn't have to know.

So just remove the public API part of the patch.

As for the rest, could you always include VK_LAYER_KHRONOS_validation
if debug mode is on? This patch removes that. And free the array of
extensions once the instance has been initialized.
___
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 3/4] avutil/hwcontext_vulkan: check if created before destroying the instance

2021-11-23 Thread Dennis Mungai
On Tue, 23 Nov 2021, 12:06 Wu Jianhua,  wrote:

> Signed-off-by: Wu Jianhua 
> ---
>  libavutil/hwcontext_vulkan.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
> index 4ac1058181..644ed947f8 100644
> --- a/libavutil/hwcontext_vulkan.c
> +++ b/libavutil/hwcontext_vulkan.c
> @@ -1157,7 +1157,8 @@ static void vulkan_device_free(AVHWDeviceContext
> *ctx)
>  vk->DestroyDebugUtilsMessengerEXT(hwctx->inst, p->debug_ctx,
>hwctx->alloc);
>
> -vk->DestroyInstance(hwctx->inst, hwctx->alloc);
> +if (hwctx->inst)
> +vk->DestroyInstance(hwctx->inst, hwctx->alloc);
>
>  if (p->libvulkan)
>  dlclose(p->libvulkan);
> --
> 2.25.1
>


Ping.

This fixes a (somewhat obscure) bug where a "generic library error" is
reported when running multiple concurrent ffmpeg commands with one or more
Vulkan filter chains.

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

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


Re: [FFmpeg-devel] [PATCH 4/4] avutil/hwcontext_vulkan: fully support customizable validation layers

2021-11-23 Thread Wu Jianhua
Lynne:
> 23 Nov 2021, 12:03 by toq...@outlook.com:
>
>> Lynne:
>> >23 Nov 2021, 10:48 by jianhua...@intel.com:
>> >>Lynne:
>>
> From: ffmpeg-devel  On Behalf Of
> Lynne
> Sent: Tuesday, November 23, 2021 5:23 PM
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH 4/4] avutil/hwcontext_vulkan: fully
> support customizable validation layers
>
> 23 Nov 2021, 10:01 by jianhua...@intel.com:
>
> > Validation layer is an indispensable part of developing on Vulkan.
> >
> > The following commands is on how to enable validation layers:
> >
> > ffmpeg -init_hw_device
> >
> vulkan=0,debug=1,validation_layers=VK_LAYER_KHRONOS_validation+VK_L
> AYE
> > R_LUNARG_api_dump
> >
> > Signed-off-by: Wu Jianhua 
> > ---
> >  libavutil/hwcontext_vulkan.c | 110 ---
> 
> >  libavutil/hwcontext_vulkan.h |   7 +++
> >  2 files changed, 97 insertions(+), 20 deletions(-)
> >
> >
> > +/**
> > + * Enabled validation layers.
> > + * If no layers are enabled, set these fields to NULL, and 0 
> > respectively.
> > + */
> > +const char * const *enabled_validation_layers;
> > +int nb_enabled_validation_layers;
> > +
> >
>
> Why are you exposing them? Do API users really need to know this?
>

 It's okay. For it's only integrated in a really small separate function it
 could be skipped by the status debug_mode as before. And validation
 layers are embed by other specific drivers, platforms(such as those
 specific layers in androids) or SDK, the FFmpeg is not need to do anything
 more whatever the current is compiled with optimization mode or debug mode.
 The use who only want to use filter is simply not able to know how to
 enable the debug_mode. For me, as a user also, it is important to me, I
 don't want to changed the code then compiling to use the specific 
 validation
 layers again and again.  And not only the developer need to use it, those
 people who help us test could report a more detailed problem. I think it's
 really benefit.

>>>
>>> Sorry, I didn't quite understand that.
>>> I'm not objecting to being able to use custom debug layers and activating
>>> them if they're requested from the user. We already do that for the
>>> standard debug layer anyway. I'm just not sure I understand why filters
>>> would need to know if a debug layer is ran, and which one it is, by exposing
>>> them via the public API.
>>>
>>
>> Oh! My bad. I supposed you mean we may be not necessary to expose
>> layer info to the Device Context, right?
>>
>
> Yup, that's right. We'd like to keep the API as small as possible, and
> it's already quite large compared to other hwcontexts. In this case,
> I don't think it's necessary. API users already know, since they can request
> layers, and filters shouldn't have to know.
>
> So just remove the public API part of the patch.
>
> As for the rest, could you always include VK_LAYER_KHRONOS_validation
> if debug mode is on? This patch removes that. And free the array of
> extensions once the instance has been initialized.
>

Sure I do. I'll update this patch soon.

Thanks,
Jianhua
___
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 3/4] avutil/hwcontext_vulkan: check if created before destroying the instance

2021-11-23 Thread Wu Jianhua
Dennis Mungai:
> Sent: 2021年11月23日 22:58
> To: FFmpeg development discussions and patches
> Cc: Wu Jianhua
> Subject: Re: [FFmpeg-devel] [PATCH 3/4] avutil/hwcontext_vulkan: check if 
> created before destroying the instance
>
> On Tue, 23 Nov 2021, 12:06 Wu Jianhua,  wrote:
>
>> Signed-off-by: Wu Jianhua 
>> ---
>>  libavutil/hwcontext_vulkan.c | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
>> index 4ac1058181..644ed947f8 100644
>> --- a/libavutil/hwcontext_vulkan.c
>> +++ b/libavutil/hwcontext_vulkan.c
>> @@ -1157,7 +1157,8 @@ static void vulkan_device_free(AVHWDeviceContext
>> *ctx)
>>  vk->DestroyDebugUtilsMessengerEXT(hwctx->inst, p->debug_ctx,
>>hwctx->alloc);
>>
>> -vk->DestroyInstance(hwctx->inst, hwctx->alloc);
>> +if (hwctx->inst)
>> +vk->DestroyInstance(hwctx->inst, hwctx->alloc);
>>
>>  if (p->libvulkan)
>>  dlclose(p->libvulkan);
>> --
>> 2.25.1
>>
>
> Ping.
>
> This fixes a (somewhat obscure) bug where a "generic library error" is
> reported when running multiple concurrent ffmpeg commands with one or more
> Vulkan filter chains.
>

Hi Dennis:

Glad that this patch is helpful, but I’m unable to do more. Lynne may help apply
this patch when she sees your ping.

Thanks,
Jianhua



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

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


[FFmpeg-devel] [PATCH v4 1/4] avformat/imf: Headers

2021-11-23 Thread pal
From: Pierre-Anthony Lemieux 

Signed-off-by: Pierre-Anthony Lemieux 
---

Notes:
The IMF demuxer accepts as input an IMF CPL. The assets referenced by the 
CPL can be
contained in multiple deliveries, each defined by an ASSETMAP file:

ffmpeg -assetmaps ,,... -i 

If -assetmaps is not specified, FFMPEG looks for a file called ASSETMAP.xml 
in the same directory as the CPL.

EXAMPLE:
ffmpeg -i 
http://ffmpeg-imf-samples-public.s3-website-us-west-1.amazonaws.com/countdown/CPL_f5095caa-f204-4e1c-8a84-7af48c7ae16b.xml
 out.mp4

The Interoperable Master Format (IMF) is a file-based media format for the
delivery and storage of professional audio-visual masters.
An IMF Composition consists of an XML playlist (the Composition Playlist)
and a collection of MXF files (the Track Files). The Composition Playlist 
(CPL)
assembles the Track Files onto a timeline, which consists of multiple 
tracks.
The location of the Track Files referenced by the Composition Playlist is 
stored
in one or more XML documents called Asset Maps. More details at 
https://www.imfug.com/explainer.
The IMF standard was first introduced in 2013 and is managed by the SMPTE.

Header and build files.

CHANGE NOTES:

- fixed patchwork warnings
- updated patch notes
- added LGPL license
- removed imf_internal.h
- Improve error handling, including removing exit()
- Fix code style
- Allow custom I/O for all files (following DASH and HLS template)
- fix realloc memory leak

 libavformat/imf.h | 197 ++
 1 file changed, 197 insertions(+)
 create mode 100644 libavformat/imf.h

diff --git a/libavformat/imf.h b/libavformat/imf.h
new file mode 100644
index 00..59283a5d3a
--- /dev/null
+++ b/libavformat/imf.h
@@ -0,0 +1,197 @@
+/*
+ * Copyright (c) Sandflow Consulting LLC
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice, 
this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * 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
+ */
+
+/**
+ * Public header file for the processing of Interoperable Master Format (IMF) 
packages.
+ * 
+ * @author Pierre-Anthony Lemieux
+ * @author Valentin Noel
+ * @file
+ * @ingroup lavu_imf
+ */
+
+#ifndef AVFORMAT_IMF_H
+#define AVFORMAT_IMF_H
+
+#include "avformat.h"
+#include "libavformat/avio.h"
+#include "libavutil/rational.h"
+#include 
+
+#define IMF_UUID_FORMAT 
"urn:uuid:%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
+
+/**
+ * UUID as defined in IETF RFC 422
+ */
+typedef uint8_t UUID[16];
+
+/**
+ * IMF Composition Playlist Base Resource
+ */
+typedef struct IMFBaseResource {
+AVRational edit_rate; /**< BaseResourceType/EditRate */
+unsigned long entry_point; /**< BaseResourceType/EntryPoint */
+unsigned long duration; /**< BaseResourceType/Duration */
+unsigned long repeat_count; /**< BaseResourceType/RepeatCount */
+} IMFBaseResource;
+
+/**
+ * IMF Composition Play

[FFmpeg-devel] [PATCH v4 2/4] avformat/imf: CPL processor

2021-11-23 Thread pal
From: Pierre-Anthony Lemieux 

Signed-off-by: Pierre-Anthony Lemieux 
---

Notes:
Implements IMF Composition Playlist (CPL) parsing.

 libavformat/imf_cpl.c | 716 ++
 1 file changed, 716 insertions(+)
 create mode 100644 libavformat/imf_cpl.c

diff --git a/libavformat/imf_cpl.c b/libavformat/imf_cpl.c
new file mode 100644
index 00..0dfd85f433
--- /dev/null
+++ b/libavformat/imf_cpl.c
@@ -0,0 +1,716 @@
+/*
+ * Copyright (c) Sandflow Consulting LLC
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice, 
this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * 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
+ */
+
+/**
+ * Implements IMP CPL processing
+ *
+ * @author Pierre-Anthony Lemieux
+ * @file
+ * @ingroup lavu_imf
+ */
+
+#include "imf.h"
+#include "libavformat/mxf.h"
+#include "libavutil/bprint.h"
+#include "libavutil/error.h"
+#include 
+
+xmlNodePtr imf_xml_get_child_element_by_name(xmlNodePtr parent, const char 
*name_utf8)
+{
+xmlNodePtr cur_element;
+
+cur_element = xmlFirstElementChild(parent);
+while (cur_element) {
+if (xmlStrcmp(cur_element->name, name_utf8) == 0)
+return cur_element;
+cur_element = xmlNextElementSibling(cur_element);
+}
+return NULL;
+}
+
+int imf_xml_read_UUID(xmlNodePtr element, uint8_t uuid[16])
+{
+xmlChar *element_text = NULL;
+int scanf_ret;
+int ret = 0;
+
+element_text = xmlNodeListGetString(element->doc, 
element->xmlChildrenNode, 1);
+scanf_ret = sscanf(element_text,
+IMF_UUID_FORMAT,
+&uuid[0],
+&uuid[1],
+&uuid[2],
+&uuid[3],
+&uuid[4],
+&uuid[5],
+&uuid[6],
+&uuid[7],
+&uuid[8],
+&uuid[9],
+&uuid[10],
+&uuid[11],
+&uuid[12],
+&uuid[13],
+&uuid[14],
+&uuid[15]);
+if (scanf_ret != 16) {
+av_log(NULL, AV_LOG_ERROR, "Invalid UUID\n");
+ret = AVERROR_INVALIDDATA;
+}
+xmlFree(element_text);
+
+return ret;
+}
+
+int imf_xml_read_rational(xmlNodePtr element, AVRational *rational)
+{
+xmlChar *element_text = NULL;
+int ret = 0;
+
+element_text = xmlNodeListGetString(element->doc, 
element->xmlChildrenNode, 1);
+if (sscanf(element_text, "%i %i", &rational->num, &rational->den) != 2) {
+av_log(NULL, AV_LOG_ERROR, "Invalid rational number\n");
+ret = AVERROR_INVALIDDATA;
+}
+xmlFree(element_text);
+
+return ret;
+}
+
+int imf_xml_read_ulong(xmlNodePtr element, unsigned long *number)
+{
+xmlChar *element_text = NULL;
+int ret = 0;
+
+element_text = xmlNodeListGetString(element->doc, 
element->xmlChildrenNode, 1);
+if (sscanf(element_text, "%lu", number) != 1) {
+av_log(NULL, AV_LOG_ERROR, "Invalid unsigned long");
+ret = AVERROR_INVALIDDATA;
+}
+xmlFree(element_text);
+
+return ret;
+}
+
+static void imf_base_virtual_track_init(IMFBaseVirtualTrack *track)
+{
+memset(track->id_uuid, 0, sizeof(track->id_u

[FFmpeg-devel] [PATCH v4 3/4] avformat/imf: Demuxer implementation

2021-11-23 Thread pal
From: Pierre-Anthony Lemieux 

Signed-off-by: Pierre-Anthony Lemieux 
---

Notes:
Implements the IMF demuxer.

 libavformat/imfdec.c | 807 +++
 1 file changed, 807 insertions(+)
 create mode 100644 libavformat/imfdec.c

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
new file mode 100644
index 00..05c2a52f88
--- /dev/null
+++ b/libavformat/imfdec.c
@@ -0,0 +1,807 @@
+/*
+ * Copyright (c) Sandflow Consulting LLC
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice, 
this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * 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
+ */
+
+/**
+ * Demuxes an IMF Composition
+ *
+ * References
+ * OV 2067-0:2018 - SMPTE Overview Document - Interoperable Master Format
+ * ST 2067-2:2020 - SMPTE Standard - Interoperable Master Format — Core 
Constraints
+ * ST 2067-3:2020 - SMPTE Standard - Interoperable Master Format — Composition 
Playlist
+ * ST 2067-5:2020 - SMPTE Standard - Interoperable Master Format — Essence 
Component
+ * ST 2067-20:2016 - SMPTE Standard - Interoperable Master Format — 
Application #2
+ * ST 2067-21:2020 - SMPTE Standard - Interoperable Master Format — 
Application #2 Extended
+ * ST 2067-102:2017 - SMPTE Standard - Interoperable Master Format — Common 
Image Pixel Color Schemes
+ * ST 429-9:2007 - SMPTE Standard - D-Cinema Packaging — Asset Mapping and 
File Segmentation
+ *
+ * @author Marc-Antoine Arnaud
+ * @author Valentin Noel
+ * @author Nicholas Vanderzwet
+ * @file
+ * @ingroup lavu_imf
+ */
+
+#include "imf.h"
+#include "internal.h"
+#include "libavutil/avstring.h"
+#include "libavutil/bprint.h"
+#include "libavutil/opt.h"
+#include "mxf.h"
+#include "url.h"
+#include 
+#include 
+
+#define MAX_BPRINT_READ_SIZE (UINT_MAX - 1)
+#define DEFAULT_ASSETMAP_SIZE 8 * 1024
+#define IMF_AVRATIONAL_FORMAT "%d/%d"
+#define IMF_AVRATIONAL_ARG(rational) rational.num, rational.den
+
+/**
+ * IMF Asset locator
+ */
+typedef struct IMFAssetLocator {
+UUID uuid;
+char *absolute_uri;
+} IMFAssetLocator;
+
+/**
+ * IMF Asset locator map
+ * Results from the parsing of one or more ASSETMAP XML files
+ */
+typedef struct IMFAssetLocatorMap {
+uint8_t asset_count;
+IMFAssetLocator **assets;
+} IMFAssetLocatorMap;
+
+typedef struct IMFVirtualTrackResourcePlaybackCtx {
+IMFAssetLocator *locator;
+IMFTrackFileResource *resource;
+AVFormatContext *ctx;
+} IMFVirtualTrackResourcePlaybackCtx;
+
+typedef struct IMFVirtualTrackPlaybackCtx {
+// Track index in playlist
+int32_t index;
+// Time counters
+AVRational current_timestamp;
+AVRational duration;
+// Resources
+unsigned int resource_count;
+IMFVirtualTrackResourcePlaybackCtx *resources;
+// Decoding cursors
+uint32_t current_resource_index;
+int64_t last_pts;
+} IMFVirtualTrackPlaybackCtx;
+
+typedef struct IMFContext {
+const AVClass *class;
+const char *base_url;
+char *asset_map_paths;
+AVIOInterruptCB *interrupt_callback;
+AVDictionary *avio_opts;
+IMFC

[FFmpeg-devel] [PATCH v4 4/4] avformat/imf: Tests and build files

2021-11-23 Thread pal
From: Pierre-Anthony Lemieux 

Signed-off-by: Pierre-Anthony Lemieux 
---

Notes:
Tests and build files for the IMF demuxer.

 MAINTAINERS  |   1 +
 configure|   3 +-
 doc/demuxers.texi|   6 +
 libavformat/Makefile |   2 +
 libavformat/allformats.c |   1 +
 libavformat/tests/imf.c  | 498 +++
 6 files changed, 510 insertions(+), 1 deletion(-)
 create mode 100644 libavformat/tests/imf.c

diff --git a/MAINTAINERS b/MAINTAINERS
index dcac46003e..7a6972fe1a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -433,6 +433,7 @@ Muxers/Demuxers:
   idroqdec.cMike Melanson
   iff.c Jaikrishnan Menon
   img2*.c   Michael Niedermayer
+  imf*.cMarc-Antoine Arnaud, Pierre-Anthony 
Lemieux, Valentin Noël
   ipmovie.c Mike Melanson
   ircam*Paul B Mahol
   iss.c Stefan Gehrer
diff --git a/configure b/configure
index d068b11073..ee39528835 100755
--- a/configure
+++ b/configure
@@ -298,7 +298,7 @@ External library support:
   --enable-libxvid enable Xvid encoding via xvidcore,
native MPEG-4/Xvid encoder exists [no]
   --enable-libxml2 enable XML parsing using the C library libxml2, 
needed
-   for dash demuxing support [no]
+   for dash and imf demuxing support [no]
   --enable-libzimg enable z.lib, needed for zscale filter [no]
   --enable-libzmq  enable message passing via libzmq [no]
   --enable-libzvbi enable teletext support via libzvbi [no]
@@ -3377,6 +3377,7 @@ hls_muxer_select="mpegts_muxer"
 hls_muxer_suggest="gcrypt openssl"
 image2_alias_pix_demuxer_select="image2_demuxer"
 image2_brender_pix_demuxer_select="image2_demuxer"
+imf_demuxer_deps="libxml2"
 ipod_muxer_select="mov_muxer"
 ismv_muxer_select="mov_muxer"
 ivf_muxer_select="av1_metadata_bsf vp9_superframe_bsf"
diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index cab8a7072c..655704d2c4 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -267,6 +267,12 @@ which streams to actually receive.
 Each stream mirrors the @code{id} and @code{bandwidth} properties from the
 @code{} as metadata keys named "id" and "variant_bitrate" 
respectively.
 
+@section imf
+
+Interoperable Master Format demuxer.
+
+This demuxer presents audio and video streams found in an IMF Composition.
+
 @section flv, live_flv, kux
 
 Adobe Flash Video Format demuxer.
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 3d6c8ef8f5..dda2bc9a47 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -285,6 +285,7 @@ OBJS-$(CONFIG_IMAGE_WEBP_PIPE_DEMUXER)+= img2dec.o 
img2.o
 OBJS-$(CONFIG_IMAGE_XBM_PIPE_DEMUXER) += img2dec.o img2.o
 OBJS-$(CONFIG_IMAGE_XPM_PIPE_DEMUXER) += img2dec.o img2.o
 OBJS-$(CONFIG_IMAGE_XWD_PIPE_DEMUXER) += img2dec.o img2.o
+OBJS-$(CONFIG_IMF_DEMUXER)   += imfdec.o imf_cpl.o
 OBJS-$(CONFIG_INGENIENT_DEMUXER) += ingenientdec.o rawdec.o
 OBJS-$(CONFIG_IPMOVIE_DEMUXER)   += ipmovie.o
 OBJS-$(CONFIG_IPU_DEMUXER)   += ipudec.o rawdec.o
@@ -694,6 +695,7 @@ TESTPROGS-$(CONFIG_FFRTMPCRYPT_PROTOCOL) += rtmpdh
 TESTPROGS-$(CONFIG_MOV_MUXER)+= movenc
 TESTPROGS-$(CONFIG_NETWORK)  += noproxy
 TESTPROGS-$(CONFIG_SRTP) += srtp
+TESTPROGS-$(CONFIG_IMF_DEMUXER)  += imf
 
 TOOLS = aviocat \
 ismindex\
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index cbfadcb639..91cd9a4c73 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -212,6 +212,7 @@ extern const AVInputFormat  ff_image2pipe_demuxer;
 extern const AVOutputFormat ff_image2pipe_muxer;
 extern const AVInputFormat  ff_image2_alias_pix_demuxer;
 extern const AVInputFormat  ff_image2_brender_pix_demuxer;
+extern const AVInputFormat  ff_imf_demuxer;
 extern const AVInputFormat  ff_ingenient_demuxer;
 extern const AVInputFormat  ff_ipmovie_demuxer;
 extern const AVOutputFormat ff_ipod_muxer;
diff --git a/libavformat/tests/imf.c b/libavformat/tests/imf.c
new file mode 100644
index 00..51bbbc579d
--- /dev/null
+++ b/libavformat/tests/imf.c
@@ -0,0 +1,498 @@
+/*
+ * Copyright (c) Sandflow Consulting LLC
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice, 
this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentatio

[FFmpeg-devel] [PATCH] avformat/concatdec: copy side data

2021-11-23 Thread Nicolas Gaullier
Fixes mpeg2video stream copy to mpeg muxer.
Note: this is a following of 1ec86be79b11.

Signed-off-by: Nicolas Gaullier 
---
 libavformat/concatdec.c | 11 +++
 tests/ref/fate/concat-demuxer-extended-lavf-mxf |  2 +-
 tests/ref/fate/concat-demuxer-extended-lavf-mxf_d10 |  2 +-
 tests/ref/fate/concat-demuxer-simple1-lavf-mxf  |  1 +
 tests/ref/fate/concat-demuxer-simple1-lavf-mxf_d10  |  1 +
 tests/ref/fate/concat-demuxer-simple2-lavf-ts   |  1 +
 6 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index 8d80e536d1..1e53651945 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -190,6 +190,17 @@ static int copy_stream_props(AVStream *st, AVStream 
*source_st)
 st->sample_aspect_ratio = source_st->sample_aspect_ratio;
 avpriv_set_pts_info(st, 64, source_st->time_base.num, 
source_st->time_base.den);
 
+// copy side data
+for (int i = 0; i < source_st->nb_side_data; i++) {
+const AVPacketSideData *sd_src = &source_st->side_data[i];
+uint8_t *dst_data;
+
+dst_data = av_stream_new_side_data(st, sd_src->type, sd_src->size);
+if (!dst_data)
+return AVERROR(ENOMEM);
+memcpy(dst_data, sd_src->data, sd_src->size);
+}
+
 av_dict_copy(&st->metadata, source_st->metadata, 0);
 return 0;
 }
diff --git a/tests/ref/fate/concat-demuxer-extended-lavf-mxf 
b/tests/ref/fate/concat-demuxer-extended-lavf-mxf
index a3b205539a..edfb4cfcff 100644
--- a/tests/ref/fate/concat-demuxer-extended-lavf-mxf
+++ b/tests/ref/fate/concat-demuxer-extended-lavf-mxf
@@ -1 +1 @@
-0ea04f40869068b282a67e5b8f2a6127 
*tests/data/fate/concat-demuxer-extended-lavf-mxf.ffprobe
+41c317ac3b57addfb93f7ac9d2db822e 
*tests/data/fate/concat-demuxer-extended-lavf-mxf.ffprobe
diff --git a/tests/ref/fate/concat-demuxer-extended-lavf-mxf_d10 
b/tests/ref/fate/concat-demuxer-extended-lavf-mxf_d10
index 9cbc8df831..974fefb64c 100644
--- a/tests/ref/fate/concat-demuxer-extended-lavf-mxf_d10
+++ b/tests/ref/fate/concat-demuxer-extended-lavf-mxf_d10
@@ -1 +1 @@
-88abe27eddff160aafd622ed02c26eb6 
*tests/data/fate/concat-demuxer-extended-lavf-mxf_d10.ffprobe
+d6da934b59deb2e341de15fc33b002e3 
*tests/data/fate/concat-demuxer-extended-lavf-mxf_d10.ffprobe
diff --git a/tests/ref/fate/concat-demuxer-simple1-lavf-mxf 
b/tests/ref/fate/concat-demuxer-simple1-lavf-mxf
index fc8034bd29..dc048f396a 100644
--- a/tests/ref/fate/concat-demuxer-simple1-lavf-mxf
+++ b/tests/ref/fate/concat-demuxer-simple1-lavf-mxf
@@ -121,4 +121,5 @@ Strings Metadata
 video|0|37|1.48|34|1.36|1|0.04|24786|212480|K_|1
 Strings Metadata
 
0|mpeg2video|4|video|[0][0][0][0]|0x|352|288|0|0|0|0|1|1:1|11:9|yuv420p|8|tv|unknown|unknown|unknown|left|progressive|1|N/A|25/1|25/1|1/25|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|51|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0x060A2B340101010501010D001301
+CPB properties|0|0|0|49152|-1
 
1|pcm_s16le|unknown|audio|[0][0][0][0]|0x|s16|48000|1|unknown|16|N/A|0/0|0/0|1/48000|0|0.00|N/A|N/A|768000|N/A|N/A|N/A|N/A|50|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0x060A2B340101010501010D001301
diff --git a/tests/ref/fate/concat-demuxer-simple1-lavf-mxf_d10 
b/tests/ref/fate/concat-demuxer-simple1-lavf-mxf_d10
index 59c6372ef2..7ec7eab979 100644
--- a/tests/ref/fate/concat-demuxer-simple1-lavf-mxf_d10
+++ b/tests/ref/fate/concat-demuxer-simple1-lavf-mxf_d10
@@ -79,4 +79,5 @@ Strings Metadata
 audio|1|65280|1.36|65280|1.36|1920|0.04|7680|2074624|K_|1
 Strings Metadata
 
0|mpeg2video|0|video|[0][0][0][0]|0x|720|608|0|0|0|0|0|1:1|45:38|yuv422p|5|tv|unknown|unknown|unknown|topleft|tb|1|N/A|25/1|25/1|1/25|0|0.00|N/A|N/A|3000|N/A|N/A|N/A|N/A|35|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0x060A2B340101010501010D001301
+CPB properties|3000|0|0|1212416|-1
 
1|pcm_s16le|unknown|audio|[0][0][0][0]|0x|s16|48000|2|unknown|16|N/A|0/0|0/0|1/48000|0|0.00|N/A|N/A|1536000|N/A|N/A|N/A|N/A|35|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0x060A2B340101010501010D001301
diff --git a/tests/ref/fate/concat-demuxer-simple2-lavf-ts 
b/tests/ref/fate/concat-demuxer-simple2-lavf-ts
index b9106f0ea9..2ab1df4939 100644
--- a/tests/ref/fate/concat-demuxer-simple2-lavf-ts
+++ b/tests/ref/fate/concat-demuxer-simple2-lavf-ts
@@ -213,3 +213,4 @@ 
video|1|175582|1.950911|171982|1.910911|3600|0.04|15019|224848|__MPEGTS Stre
 
 
0|mp2|unknown|audio|[3][0][0][0]|0x0003|s16p|44100|1|mono|0|N/A|0/0|0/0|1/9|0|0.00|N/A|N/A|64000|N/A|N/A|N/A|N/A|89|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|this
 is stream 0
 
1|mpeg2video|4|video|[2][0][0][0]|0x0002|352|288|0|0|0|0|1|1:1|11:9|yuv420p|8|tv|unknown|unknown|unknown|left|progressive|1|N/A|25/1|25/1|1/9|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|60|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|this
 is stream 1
+CPB properties|

Re: [FFmpeg-devel] [PATCH v4 3/4] avformat/imf: Demuxer implementation

2021-11-23 Thread Paul B Mahol
better use av_realloc_f
___
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] avfilter: add audio spectral stats filter

2021-11-23 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 doc/filters.texi|  63 
 libavfilter/Makefile|   1 +
 libavfilter/af_aspectralstats.c | 605 
 libavfilter/allfilters.c|   1 +
 4 files changed, 670 insertions(+)
 create mode 100644 libavfilter/af_aspectralstats.c

diff --git a/doc/filters.texi b/doc/filters.texi
index c3ccaf97c4..04cbf4231d 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -2694,6 +2694,69 @@ Set oversampling factor.
 
 This filter supports the all above options as @ref{commands}.
 
+@section aspectralstats
+
+Display frequency domain statistical information about the audio channels.
+Statistics are calculated and stored as metadata for each audio channel and 
for each audio frame.
+
+It accepts the following option:
+@table @option
+@item win_size
+Set the window length in samples. Default value is 2048.
+Allowed range is from 32 to 65536.
+
+@item win_func
+Set window function.
+
+It accepts the following values:
+@table @samp
+@item rect
+@item bartlett
+@item hann, hanning
+@item hamming
+@item blackman
+@item welch
+@item flattop
+@item bharris
+@item bnuttall
+@item bhann
+@item sine
+@item nuttall
+@item lanczos
+@item gauss
+@item tukey
+@item dolph
+@item cauchy
+@item parzen
+@item poisson
+@item bohman
+@end table
+Default is @code{hann}.
+
+@item overlap
+Set window overlap. Allowed range is from @code{0}
+to @code{1}. Default value is @code{0.5}.
+
+@end table
+
+A list of each metadata key follows:
+
+@table @option
+@item mean
+@item variance
+@item centroid
+@item spread
+@item skewness
+@item kurtosis
+@item entropy
+@item flatness
+@item crest
+@item flux
+@item sloope
+@item decrease
+@item rolloff
+@end table
+
 @section asr
 Automatic Speech Recognition
 
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 0e27aeeff6..551d13aadc 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -92,6 +92,7 @@ OBJS-$(CONFIG_ASETTB_FILTER) += settb.o
 OBJS-$(CONFIG_ASHOWINFO_FILTER)  += af_ashowinfo.o
 OBJS-$(CONFIG_ASIDEDATA_FILTER)  += f_sidedata.o
 OBJS-$(CONFIG_ASOFTCLIP_FILTER)  += af_asoftclip.o
+OBJS-$(CONFIG_ASPECTRALSTATS_FILTER) += af_aspectralstats.o
 OBJS-$(CONFIG_ASPLIT_FILTER) += split.o
 OBJS-$(CONFIG_ASR_FILTER)+= af_asr.o
 OBJS-$(CONFIG_ASTATS_FILTER) += af_astats.o
diff --git a/libavfilter/af_aspectralstats.c b/libavfilter/af_aspectralstats.c
new file mode 100644
index 00..da418d22bf
--- /dev/null
+++ b/libavfilter/af_aspectralstats.c
@@ -0,0 +1,605 @@
+/*
+ * Copyright (c) 2021 Paul B Mahol
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+#include 
+
+#include "libavutil/audio_fifo.h"
+#include "libavutil/opt.h"
+#include "libavutil/tx.h"
+#include "audio.h"
+#include "avfilter.h"
+#include "filters.h"
+#include "internal.h"
+#include "window_func.h"
+
+typedef struct ChannelSpectralStats {
+float mean;
+float variance;
+float centroid;
+float spread;
+float skewness;
+float kurtosis;
+float entropy;
+float flatness;
+float crest;
+float flux;
+float slope;
+float decrease;
+float rolloff;
+} ChannelSpectralStats;
+
+typedef struct AudioSpectralStatsContext {
+const AVClass *class;
+int win_size;
+int win_func;
+float overlap;
+int nb_channels;
+int hop_size;
+ChannelSpectralStats *stats;
+AVAudioFifo *fifo;
+float *window_func_lut;
+int64_t pts;
+int eof;
+av_tx_fn tx_fn;
+AVTXContext **fft;
+AVComplexFloat **fft_in;
+AVComplexFloat **fft_out;
+float **prev_magnitude;
+float **magnitude;
+} AudioSpectralStatsContext;
+
+#define OFFSET(x) offsetof(AudioSpectralStatsContext, x)
+#define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
+
+static const AVOption aspectralstats_options[] = {
+{ "win_size", "set the window size", OFFSET(win_size), AV_OPT_TYPE_INT, 
{.i64=2048}, 32, 65536, A },
+WIN_FUNC_OPTION("win_func", OFFSET(win_func), A, WFUNC_HANNING),
+{ "overlap", "set window overlap", OFFSET(overlap), AV_OPT_TYPE_FLOAT, 
{.dbl=0.5}, 0,  1, A },
+{ NULL }
+};
+
+AVFILTER_DEFINE_CLASS(aspectralsta

[FFmpeg-devel] [PATCH v5 1/4] avformat/imf: Headers

2021-11-23 Thread pal
From: Pierre-Anthony Lemieux 

Signed-off-by: Pierre-Anthony Lemieux 
---

Notes:
The IMF demuxer accepts as input an IMF CPL. The assets referenced by the 
CPL can be
contained in multiple deliveries, each defined by an ASSETMAP file:

ffmpeg -assetmaps ,,... -i 

If -assetmaps is not specified, FFMPEG looks for a file called ASSETMAP.xml 
in the same directory as the CPL.

EXAMPLE:
ffmpeg -i 
http://ffmpeg-imf-samples-public.s3-website-us-west-1.amazonaws.com/countdown/CPL_f5095caa-f204-4e1c-8a84-7af48c7ae16b.xml
 out.mp4

The Interoperable Master Format (IMF) is a file-based media format for the
delivery and storage of professional audio-visual masters.
An IMF Composition consists of an XML playlist (the Composition Playlist)
and a collection of MXF files (the Track Files). The Composition Playlist 
(CPL)
assembles the Track Files onto a timeline, which consists of multiple 
tracks.
The location of the Track Files referenced by the Composition Playlist is 
stored
in one or more XML documents called Asset Maps. More details at 
https://www.imfug.com/explainer.
The IMF standard was first introduced in 2013 and is managed by the SMPTE.

Header and build files.

CHANGE NOTES:

- fixed patchwork warnings
- updated patch notes
- added LGPL license
- removed imf_internal.h
- Improve error handling, including removing exit()
- Fix code style
- Allow custom I/O for all files (following DASH and HLS template)
- replace realloc with av_realloc_f to fix leaks

 libavformat/imf.h | 197 ++
 1 file changed, 197 insertions(+)
 create mode 100644 libavformat/imf.h

diff --git a/libavformat/imf.h b/libavformat/imf.h
new file mode 100644
index 00..59283a5d3a
--- /dev/null
+++ b/libavformat/imf.h
@@ -0,0 +1,197 @@
+/*
+ * Copyright (c) Sandflow Consulting LLC
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice, 
this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * 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
+ */
+
+/**
+ * Public header file for the processing of Interoperable Master Format (IMF) 
packages.
+ * 
+ * @author Pierre-Anthony Lemieux
+ * @author Valentin Noel
+ * @file
+ * @ingroup lavu_imf
+ */
+
+#ifndef AVFORMAT_IMF_H
+#define AVFORMAT_IMF_H
+
+#include "avformat.h"
+#include "libavformat/avio.h"
+#include "libavutil/rational.h"
+#include 
+
+#define IMF_UUID_FORMAT 
"urn:uuid:%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
+
+/**
+ * UUID as defined in IETF RFC 422
+ */
+typedef uint8_t UUID[16];
+
+/**
+ * IMF Composition Playlist Base Resource
+ */
+typedef struct IMFBaseResource {
+AVRational edit_rate; /**< BaseResourceType/EditRate */
+unsigned long entry_point; /**< BaseResourceType/EntryPoint */
+unsigned long duration; /**< BaseResourceType/Duration */
+unsigned long repeat_count; /**< BaseResourceType/RepeatCount */
+} IMFBaseResource;
+
+/**
+

[FFmpeg-devel] [PATCH v5 2/4] avformat/imf: CPL processor

2021-11-23 Thread pal
From: Pierre-Anthony Lemieux 

Signed-off-by: Pierre-Anthony Lemieux 
---

Notes:
Implements IMF Composition Playlist (CPL) parsing.

 libavformat/imf_cpl.c | 707 ++
 1 file changed, 707 insertions(+)
 create mode 100644 libavformat/imf_cpl.c

diff --git a/libavformat/imf_cpl.c b/libavformat/imf_cpl.c
new file mode 100644
index 00..6582db77db
--- /dev/null
+++ b/libavformat/imf_cpl.c
@@ -0,0 +1,707 @@
+/*
+ * Copyright (c) Sandflow Consulting LLC
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice, 
this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * 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
+ */
+
+/**
+ * Implements IMP CPL processing
+ *
+ * @author Pierre-Anthony Lemieux
+ * @file
+ * @ingroup lavu_imf
+ */
+
+#include "imf.h"
+#include "libavformat/mxf.h"
+#include "libavutil/bprint.h"
+#include "libavutil/error.h"
+#include 
+
+xmlNodePtr imf_xml_get_child_element_by_name(xmlNodePtr parent, const char 
*name_utf8)
+{
+xmlNodePtr cur_element;
+
+cur_element = xmlFirstElementChild(parent);
+while (cur_element) {
+if (xmlStrcmp(cur_element->name, name_utf8) == 0)
+return cur_element;
+cur_element = xmlNextElementSibling(cur_element);
+}
+return NULL;
+}
+
+int imf_xml_read_UUID(xmlNodePtr element, uint8_t uuid[16])
+{
+xmlChar *element_text = NULL;
+int scanf_ret;
+int ret = 0;
+
+element_text = xmlNodeListGetString(element->doc, 
element->xmlChildrenNode, 1);
+scanf_ret = sscanf(element_text,
+IMF_UUID_FORMAT,
+&uuid[0],
+&uuid[1],
+&uuid[2],
+&uuid[3],
+&uuid[4],
+&uuid[5],
+&uuid[6],
+&uuid[7],
+&uuid[8],
+&uuid[9],
+&uuid[10],
+&uuid[11],
+&uuid[12],
+&uuid[13],
+&uuid[14],
+&uuid[15]);
+if (scanf_ret != 16) {
+av_log(NULL, AV_LOG_ERROR, "Invalid UUID\n");
+ret = AVERROR_INVALIDDATA;
+}
+xmlFree(element_text);
+
+return ret;
+}
+
+int imf_xml_read_rational(xmlNodePtr element, AVRational *rational)
+{
+xmlChar *element_text = NULL;
+int ret = 0;
+
+element_text = xmlNodeListGetString(element->doc, 
element->xmlChildrenNode, 1);
+if (sscanf(element_text, "%i %i", &rational->num, &rational->den) != 2) {
+av_log(NULL, AV_LOG_ERROR, "Invalid rational number\n");
+ret = AVERROR_INVALIDDATA;
+}
+xmlFree(element_text);
+
+return ret;
+}
+
+int imf_xml_read_ulong(xmlNodePtr element, unsigned long *number)
+{
+xmlChar *element_text = NULL;
+int ret = 0;
+
+element_text = xmlNodeListGetString(element->doc, 
element->xmlChildrenNode, 1);
+if (sscanf(element_text, "%lu", number) != 1) {
+av_log(NULL, AV_LOG_ERROR, "Invalid unsigned long");
+ret = AVERROR_INVALIDDATA;
+}
+xmlFree(element_text);
+
+return ret;
+}
+
+static void imf_base_virtual_track_init(IMFBaseVirtualTrack *track)
+{
+memset(track->id_uuid, 0, sizeof(track->id_u

[FFmpeg-devel] [PATCH v5 3/4] avformat/imf: Demuxer implementation

2021-11-23 Thread pal
From: Pierre-Anthony Lemieux 

Signed-off-by: Pierre-Anthony Lemieux 
---

Notes:
Implements the IMF demuxer.

 libavformat/imfdec.c | 801 +++
 1 file changed, 801 insertions(+)
 create mode 100644 libavformat/imfdec.c

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
new file mode 100644
index 00..8e6174a441
--- /dev/null
+++ b/libavformat/imfdec.c
@@ -0,0 +1,801 @@
+/*
+ * Copyright (c) Sandflow Consulting LLC
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice, 
this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * 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
+ */
+
+/**
+ * Demuxes an IMF Composition
+ *
+ * References
+ * OV 2067-0:2018 - SMPTE Overview Document - Interoperable Master Format
+ * ST 2067-2:2020 - SMPTE Standard - Interoperable Master Format — Core 
Constraints
+ * ST 2067-3:2020 - SMPTE Standard - Interoperable Master Format — Composition 
Playlist
+ * ST 2067-5:2020 - SMPTE Standard - Interoperable Master Format — Essence 
Component
+ * ST 2067-20:2016 - SMPTE Standard - Interoperable Master Format — 
Application #2
+ * ST 2067-21:2020 - SMPTE Standard - Interoperable Master Format — 
Application #2 Extended
+ * ST 2067-102:2017 - SMPTE Standard - Interoperable Master Format — Common 
Image Pixel Color Schemes
+ * ST 429-9:2007 - SMPTE Standard - D-Cinema Packaging — Asset Mapping and 
File Segmentation
+ *
+ * @author Marc-Antoine Arnaud
+ * @author Valentin Noel
+ * @author Nicholas Vanderzwet
+ * @file
+ * @ingroup lavu_imf
+ */
+
+#include "imf.h"
+#include "internal.h"
+#include "libavutil/avstring.h"
+#include "libavutil/bprint.h"
+#include "libavutil/opt.h"
+#include "mxf.h"
+#include "url.h"
+#include 
+#include 
+
+#define MAX_BPRINT_READ_SIZE (UINT_MAX - 1)
+#define DEFAULT_ASSETMAP_SIZE 8 * 1024
+#define IMF_AVRATIONAL_FORMAT "%d/%d"
+#define IMF_AVRATIONAL_ARG(rational) rational.num, rational.den
+
+/**
+ * IMF Asset locator
+ */
+typedef struct IMFAssetLocator {
+UUID uuid;
+char *absolute_uri;
+} IMFAssetLocator;
+
+/**
+ * IMF Asset locator map
+ * Results from the parsing of one or more ASSETMAP XML files
+ */
+typedef struct IMFAssetLocatorMap {
+uint8_t asset_count;
+IMFAssetLocator **assets;
+} IMFAssetLocatorMap;
+
+typedef struct IMFVirtualTrackResourcePlaybackCtx {
+IMFAssetLocator *locator;
+IMFTrackFileResource *resource;
+AVFormatContext *ctx;
+} IMFVirtualTrackResourcePlaybackCtx;
+
+typedef struct IMFVirtualTrackPlaybackCtx {
+// Track index in playlist
+int32_t index;
+// Time counters
+AVRational current_timestamp;
+AVRational duration;
+// Resources
+unsigned int resource_count;
+IMFVirtualTrackResourcePlaybackCtx *resources;
+// Decoding cursors
+uint32_t current_resource_index;
+int64_t last_pts;
+} IMFVirtualTrackPlaybackCtx;
+
+typedef struct IMFContext {
+const AVClass *class;
+const char *base_url;
+char *asset_map_paths;
+AVIOInterruptCB *interrupt_callback;
+AVDictionary *avio_opts;
+IMFC

[FFmpeg-devel] [PATCH v5 4/4] avformat/imf: Tests and build files

2021-11-23 Thread pal
From: Pierre-Anthony Lemieux 

Signed-off-by: Pierre-Anthony Lemieux 
---

Notes:
Tests and build files for the IMF demuxer.

 MAINTAINERS  |   1 +
 configure|   3 +-
 doc/demuxers.texi|   6 +
 libavformat/Makefile |   2 +
 libavformat/allformats.c |   1 +
 libavformat/tests/imf.c  | 498 +++
 6 files changed, 510 insertions(+), 1 deletion(-)
 create mode 100644 libavformat/tests/imf.c

diff --git a/MAINTAINERS b/MAINTAINERS
index dcac46003e..7a6972fe1a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -433,6 +433,7 @@ Muxers/Demuxers:
   idroqdec.cMike Melanson
   iff.c Jaikrishnan Menon
   img2*.c   Michael Niedermayer
+  imf*.cMarc-Antoine Arnaud, Pierre-Anthony 
Lemieux, Valentin Noël
   ipmovie.c Mike Melanson
   ircam*Paul B Mahol
   iss.c Stefan Gehrer
diff --git a/configure b/configure
index d068b11073..ee39528835 100755
--- a/configure
+++ b/configure
@@ -298,7 +298,7 @@ External library support:
   --enable-libxvid enable Xvid encoding via xvidcore,
native MPEG-4/Xvid encoder exists [no]
   --enable-libxml2 enable XML parsing using the C library libxml2, 
needed
-   for dash demuxing support [no]
+   for dash and imf demuxing support [no]
   --enable-libzimg enable z.lib, needed for zscale filter [no]
   --enable-libzmq  enable message passing via libzmq [no]
   --enable-libzvbi enable teletext support via libzvbi [no]
@@ -3377,6 +3377,7 @@ hls_muxer_select="mpegts_muxer"
 hls_muxer_suggest="gcrypt openssl"
 image2_alias_pix_demuxer_select="image2_demuxer"
 image2_brender_pix_demuxer_select="image2_demuxer"
+imf_demuxer_deps="libxml2"
 ipod_muxer_select="mov_muxer"
 ismv_muxer_select="mov_muxer"
 ivf_muxer_select="av1_metadata_bsf vp9_superframe_bsf"
diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index cab8a7072c..655704d2c4 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -267,6 +267,12 @@ which streams to actually receive.
 Each stream mirrors the @code{id} and @code{bandwidth} properties from the
 @code{} as metadata keys named "id" and "variant_bitrate" 
respectively.
 
+@section imf
+
+Interoperable Master Format demuxer.
+
+This demuxer presents audio and video streams found in an IMF Composition.
+
 @section flv, live_flv, kux
 
 Adobe Flash Video Format demuxer.
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 3d6c8ef8f5..dda2bc9a47 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -285,6 +285,7 @@ OBJS-$(CONFIG_IMAGE_WEBP_PIPE_DEMUXER)+= img2dec.o 
img2.o
 OBJS-$(CONFIG_IMAGE_XBM_PIPE_DEMUXER) += img2dec.o img2.o
 OBJS-$(CONFIG_IMAGE_XPM_PIPE_DEMUXER) += img2dec.o img2.o
 OBJS-$(CONFIG_IMAGE_XWD_PIPE_DEMUXER) += img2dec.o img2.o
+OBJS-$(CONFIG_IMF_DEMUXER)   += imfdec.o imf_cpl.o
 OBJS-$(CONFIG_INGENIENT_DEMUXER) += ingenientdec.o rawdec.o
 OBJS-$(CONFIG_IPMOVIE_DEMUXER)   += ipmovie.o
 OBJS-$(CONFIG_IPU_DEMUXER)   += ipudec.o rawdec.o
@@ -694,6 +695,7 @@ TESTPROGS-$(CONFIG_FFRTMPCRYPT_PROTOCOL) += rtmpdh
 TESTPROGS-$(CONFIG_MOV_MUXER)+= movenc
 TESTPROGS-$(CONFIG_NETWORK)  += noproxy
 TESTPROGS-$(CONFIG_SRTP) += srtp
+TESTPROGS-$(CONFIG_IMF_DEMUXER)  += imf
 
 TOOLS = aviocat \
 ismindex\
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index cbfadcb639..91cd9a4c73 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -212,6 +212,7 @@ extern const AVInputFormat  ff_image2pipe_demuxer;
 extern const AVOutputFormat ff_image2pipe_muxer;
 extern const AVInputFormat  ff_image2_alias_pix_demuxer;
 extern const AVInputFormat  ff_image2_brender_pix_demuxer;
+extern const AVInputFormat  ff_imf_demuxer;
 extern const AVInputFormat  ff_ingenient_demuxer;
 extern const AVInputFormat  ff_ipmovie_demuxer;
 extern const AVOutputFormat ff_ipod_muxer;
diff --git a/libavformat/tests/imf.c b/libavformat/tests/imf.c
new file mode 100644
index 00..51bbbc579d
--- /dev/null
+++ b/libavformat/tests/imf.c
@@ -0,0 +1,498 @@
+/*
+ * Copyright (c) Sandflow Consulting LLC
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice, 
this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentatio

Re: [FFmpeg-devel] [PATCH v2] avformat/mov: add option max_stts_delta

2021-11-23 Thread Michael Niedermayer
On Tue, Nov 23, 2021 at 06:41:06PM +0530, Gyan Doshi wrote:
> Very high stts sample deltas may occasionally be intended but usually
> they are written in error or used to store a negative value for dts correction
> when treated as signed 32-bit integers.
> 
> This option lets the user set an upper limit, beyond which the delta
> is clamped to 1. Negative values of under 1 second are used to adjust
> dts.
> 
> Unit is the track time scale. Default is INT_MAX which maintains current 
> handling.
> ---
>  doc/demuxers.texi  |  6 ++
>  libavformat/isom.h |  1 +
>  libavformat/mov.c  | 14 +-
>  3 files changed, 16 insertions(+), 5 deletions(-)
> 
> diff --git a/doc/demuxers.texi b/doc/demuxers.texi
> index cab8a7072c..15078b9b1b 100644
> --- a/doc/demuxers.texi
> +++ b/doc/demuxers.texi
> @@ -713,6 +713,12 @@ specify.
>  
>  @item decryption_key
>  16-byte key, in hex, to decrypt files encrypted using ISO Common Encryption 
> (CENC/AES-128 CTR; ISO/IEC 23001-7).
> +
> +@item max_stts_delta
> +The sample offsets stored in a track's stts box are 32-bit unsigned 
> integers. However, very large values usually indicate
> +a value written by error or a storage of a small negative value as a way to 
> correct accumulated DTS delay.
> +Range is 0 to UINT_MAX. Default is INT_MAX.
> +
>  @end table
>  
>  @subsection Audible AAX
> diff --git a/libavformat/isom.h b/libavformat/isom.h
> index ef8f19b18c..625dea8421 100644
> --- a/libavformat/isom.h
> +++ b/libavformat/isom.h
> @@ -305,6 +305,7 @@ typedef struct MOVContext {
>  int32_t movie_display_matrix[3][3]; ///< display matrix from mvhd
>  int have_read_mfra_size;
>  uint32_t mfra_size;
> +uint32_t max_stts_delta;
>  } MOVContext;
>  
>  int ff_mp4_read_descr_len(AVIOContext *pb);
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index 451cb78bbf..bbda07ac42 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -3965,14 +3965,17 @@ static void mov_build_index(MOVContext *mov, AVStream 
> *st)
>  current_offset += sample_size;
>  stream_size += sample_size;
>  
> -/* A negative sample duration is invalid based on the spec,
> - * but some samples need it to correct the DTS. */
> -if (sc->stts_data[stts_index].duration < 0) {
> +/* STTS sample offsets are uint32 but some files store it as 
> int32
> + * with negative values used to correct DTS delays.
> +   There may be abnormally large values as well. */
> +if (sc->stts_data[stts_index].duration > 
> mov->max_stts_delta) {
> +// assume high delta is a negative correction if less 
> than 1 second
> +int32_t delta_magnitude = *((int32_t 
> *)&sc->stts_data[stts_index].duration);
>  av_log(mov->fc, AV_LOG_WARNING,
> -   "Invalid SampleDelta %d in STTS, at %d st:%d\n",
> +   "Correcting too large SampleDelta %u in STTS, at 
> %d st:%d.\n",
> sc->stts_data[stts_index].duration, stts_index,
> st->index);
> -dts_correction += sc->stts_data[stts_index].duration - 1;
> +dts_correction += (delta_magnitude < 0 && 
> FFABS(delta_magnitude) < sc->time_scale ? delta_magnitude - 1 : 0);
>  sc->stts_data[stts_index].duration = 1;
>  }
>  current_dts += sc->stts_data[stts_index].duration;
> @@ -8566,6 +8569,7 @@ static const AVOption mov_options[] = {
>  { "decryption_key", "The media decryption key (hex)", 
> OFFSET(decryption_key), AV_OPT_TYPE_BINARY, .flags = 
> AV_OPT_FLAG_DECODING_PARAM },
>  { "enable_drefs", "Enable external track support.", 
> OFFSET(enable_drefs), AV_OPT_TYPE_BOOL,
>  {.i64 = 0}, 0, 1, FLAGS },
> +{ "max_stts_delta", "treat offsets above this value as invalid", 
> OFFSET(max_stts_delta), AV_OPT_TYPE_INT, {.i64 = INT_MAX}, 0, UINT_MAX, 
> .flags = AV_OPT_FLAG_DECODING_PARAM },
>  
>  { NULL },
>  };

The stts is used in other places, the value parsed as unsigned will cause
problems there too

the cast is also fragile as it will break when someone tries to change it
to int64

FFABS(delta_magnitude) is also undefined for INT_MIN

also please select the default so that it works with all real world files

I have not yet seen an ambigous file, +6 month vs -10ms is quite clear
what where the largest values your files used ?

thx


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

Freedom in capitalist society always remains about the same as it was in
ancient Greek republics: Freedom for slave owners. -- Vladimir Lenin


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

To unsubscribe, 

Re: [FFmpeg-devel] [PATCH 01/11] avformat/rtpdec_rfc4175: use rawvideo for uyvy422

2021-11-23 Thread lance . lmwang
On Fri, Nov 12, 2021 at 06:22:06PM +0800, lance.lmw...@gmail.com wrote:
> From: Limin Wang 
> 
> Signed-off-by: Limin Wang 
> ---
>  libavformat/rtpdec_rfc4175.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/rtpdec_rfc4175.c b/libavformat/rtpdec_rfc4175.c
> index f50cad7..f13736b 100644
> --- a/libavformat/rtpdec_rfc4175.c
> +++ b/libavformat/rtpdec_rfc4175.c
> @@ -55,9 +55,11 @@ static int rfc4175_parse_format(AVStream *stream, 
> PayloadContext *data)
>  if (data->depth == 8) {
>  data->pgroup = 4;
>  pixfmt = AV_PIX_FMT_UYVY422;
> +stream->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
>  } else if (data->depth == 10) {
>  data->pgroup = 5;
>  pixfmt = AV_PIX_FMT_YUV422P10;
> +stream->codecpar->codec_id = AV_CODEC_ID_BITPACKED;
>  } else {
>  return AVERROR_INVALIDDATA;
>  }
> @@ -268,7 +270,7 @@ static int rfc4175_handle_packet(AVFormatContext *ctx, 
> PayloadContext *data,
>  const RTPDynamicProtocolHandler ff_rfc4175_rtp_handler = {
>  .enc_name   = "raw",
>  .codec_type = AVMEDIA_TYPE_VIDEO,
> -.codec_id   = AV_CODEC_ID_BITPACKED,
> +.codec_id   = AV_CODEC_ID_NONE,
>  .priv_data_size = sizeof(PayloadContext),
>  .parse_sdp_a_line   = rfc4175_parse_sdp_line,
>  .parse_packet   = rfc4175_handle_packet,
> -- 

Plan to push the patchset in two days. 

> 1.8.3.1
> 

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

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


Re: [FFmpeg-devel] [PATCH 01/11] avformat/rtpdec_rfc4175: use rawvideo for uyvy422

2021-11-23 Thread Lynne
23 Nov 2021, 23:33 by lance.lmw...@gmail.com:

> On Fri, Nov 12, 2021 at 06:22:06PM +0800, lance.lmw...@gmail.com wrote:
>
>> From: Limin Wang 
>>
>> Signed-off-by: Limin Wang 
>> ---
>>  libavformat/rtpdec_rfc4175.c | 4 +++-
>>  1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/libavformat/rtpdec_rfc4175.c b/libavformat/rtpdec_rfc4175.c
>> index f50cad7..f13736b 100644
>> --- a/libavformat/rtpdec_rfc4175.c
>> +++ b/libavformat/rtpdec_rfc4175.c
>> @@ -55,9 +55,11 @@ static int rfc4175_parse_format(AVStream *stream, 
>> PayloadContext *data)
>>  if (data->depth == 8) {
>>  data->pgroup = 4;
>>  pixfmt = AV_PIX_FMT_UYVY422;
>> +stream->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
>>  } else if (data->depth == 10) {
>>  data->pgroup = 5;
>>  pixfmt = AV_PIX_FMT_YUV422P10;
>> +stream->codecpar->codec_id = AV_CODEC_ID_BITPACKED;
>>  } else {
>>  return AVERROR_INVALIDDATA;
>>  }
>> @@ -268,7 +270,7 @@ static int rfc4175_handle_packet(AVFormatContext *ctx, 
>> PayloadContext *data,
>>  const RTPDynamicProtocolHandler ff_rfc4175_rtp_handler = {
>>  .enc_name   = "raw",
>>  .codec_type = AVMEDIA_TYPE_VIDEO,
>> -.codec_id   = AV_CODEC_ID_BITPACKED,
>> +.codec_id   = AV_CODEC_ID_NONE,
>>  .priv_data_size = sizeof(PayloadContext),
>>  .parse_sdp_a_line   = rfc4175_parse_sdp_line,
>>  .parse_packet   = rfc4175_handle_packet,
>> --
>>
>
> Plan to push the patchset in two days. 
>

This patchset was NAK'd because it breaks the API.
And I'm giving it another NAK.

The entire point of bitpacked is to serve as a generic codec
for bitpacked content, based on the input pixel format, whether
it'd be 10 bit or 12 or 14 bit, or even 9 bit. Absolutely no reason
to remove it. s210 is not an official name either.
So no, do not introduce an s210 encoder, or a decoder, or a
new pixel format, or even a new codec ID, extend what we
already have.
___
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/4] avutil/vulkan_functions: add EnumerateInstanceLayerProperties

2021-11-23 Thread Wu Jianhua
Signed-off-by: Wu Jianhua 
---
 libavutil/vulkan_functions.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavutil/vulkan_functions.h b/libavutil/vulkan_functions.h
index 85a9f943c8..96922d7286 100644
--- a/libavutil/vulkan_functions.h
+++ b/libavutil/vulkan_functions.h
@@ -45,6 +45,7 @@ typedef enum FFVulkanExtensions {
 #define FN_LIST(MACRO) 
  \
 /* Instance */ 
  \
 MACRO(0, 0, FF_VK_EXT_NO_FLAG,  
EnumerateInstanceExtensionProperties)\
+MACRO(0, 0, FF_VK_EXT_NO_FLAG,  
EnumerateInstanceLayerProperties)\
 MACRO(0, 0, FF_VK_EXT_NO_FLAG,  CreateInstance)
  \
 MACRO(1, 0, FF_VK_EXT_NO_FLAG,  DestroyInstance)   
  \

  \
-- 
2.25.1

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

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


[FFmpeg-devel] [PATCH v2 2/4] avutil/hwcontext_vulkan: check if created before destroying the device

2021-11-23 Thread Wu Jianhua
Signed-off-by: Wu Jianhua 
---
 libavutil/hwcontext_vulkan.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index f1e750cd3e..4ac1058181 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -1150,7 +1150,8 @@ static void vulkan_device_free(AVHWDeviceContext *ctx)
 FFVulkanFunctions *vk = &p->vkfn;
 AVVulkanDeviceContext *hwctx = ctx->hwctx;
 
-vk->DestroyDevice(hwctx->act_dev, hwctx->alloc);
+if (hwctx->act_dev)
+vk->DestroyDevice(hwctx->act_dev, hwctx->alloc);
 
 if (p->debug_ctx)
 vk->DestroyDebugUtilsMessengerEXT(hwctx->inst, p->debug_ctx,
-- 
2.25.1

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

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


[FFmpeg-devel] [PATCH v2 3/4] avutil/hwcontext_vulkan: check if created before destroying the instance

2021-11-23 Thread Wu Jianhua
Signed-off-by: Wu Jianhua 
---
 libavutil/hwcontext_vulkan.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index 4ac1058181..644ed947f8 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -1157,7 +1157,8 @@ static void vulkan_device_free(AVHWDeviceContext *ctx)
 vk->DestroyDebugUtilsMessengerEXT(hwctx->inst, p->debug_ctx,
   hwctx->alloc);
 
-vk->DestroyInstance(hwctx->inst, hwctx->alloc);
+if (hwctx->inst)
+vk->DestroyInstance(hwctx->inst, hwctx->alloc);
 
 if (p->libvulkan)
 dlclose(p->libvulkan);
-- 
2.25.1

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

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


[FFmpeg-devel] [PATCH v2 4/4] avutil/hwcontext_vulkan: fully support customizable validation layers

2021-11-23 Thread Wu Jianhua
Validation layer is an indispensable part of developing on Vulkan.

The following commands is on how to enable validation layers:

ffmpeg -init_hw_device 
vulkan=0,debug=1,validation_layers=VK_LAYER_LUNARG_monitor+VK_LAYER_LUNARG_api_dump

Signed-off-by: Wu Jianhua 
---
 libavutil/hwcontext_vulkan.c | 136 +--
 1 file changed, 113 insertions(+), 23 deletions(-)

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index 644ed947f8..75f9f90d70 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -146,6 +146,13 @@ typedef struct AVVkFrameInternal {
 }  
\
 } while(0)
 
+#define RELEASE_PROPS(props, count)
\
+if (props) {   
\
+for (int i = 0; i < count; i++)
\
+av_free((void *)((props)[i])); 
\
+av_free((void *)props);
\
+}
+
 static const struct {
 enum AVPixelFormat pixfmt;
 const VkFormat vkfmts[4];
@@ -511,15 +518,101 @@ static int check_extensions(AVHWDeviceContext *ctx, int 
dev, AVDictionary *opts,
 return 0;
 
 fail:
-if (extension_names)
-for (int i = 0; i < extensions_found; i++)
-av_free((void *)extension_names[i]);
-av_free(extension_names);
+RELEASE_PROPS(extension_names, extensions_found);
 av_free(user_exts_str);
 av_free(sup_ext);
 return err;
 }
 
+static int check_validation_layers(AVHWDeviceContext *ctx, AVDictionary *opts,
+   const char * const **dst, uint32_t *num)
+{
+static const char default_layer[] = { "VK_LAYER_KHRONOS_validation" };
+
+int found = 0, err = 0;
+VulkanDevicePriv *priv = ctx->internal->priv;
+FFVulkanFunctions *vk = &priv->vkfn;
+
+uint32_t sup_layer_count;
+VkLayerProperties *sup_layers;
+
+AVDictionaryEntry *user_layers;
+char *user_layers_str, *save, *token;
+
+const char **enabled_layers = NULL;
+uint32_t enabled_layers_count = 0;
+
+user_layers = av_dict_get(opts, "validation_layers", NULL, 0);
+if (!user_layers)
+return 0;
+
+user_layers_str = av_strdup(user_layers->value);
+if (!user_layers_str) {
+err = AVERROR(EINVAL);
+goto fail;
+}
+
+vk->EnumerateInstanceLayerProperties(&sup_layer_count, NULL);
+sup_layers = av_malloc_array(sup_layer_count, sizeof(VkLayerProperties));
+if (!sup_layers)
+return AVERROR(ENOMEM);
+vk->EnumerateInstanceLayerProperties(&sup_layer_count, sup_layers);
+
+av_log(ctx, AV_LOG_VERBOSE, "Supported validation layers:\n");
+for (int i = 0; i < sup_layer_count; i++) {
+av_log(ctx, AV_LOG_VERBOSE, "\t%s\n", sup_layers[i].layerName);
+if (!strcmp(default_layer, sup_layers[i].layerName))
+found = 1;
+}
+
+if (!found) {
+av_log(ctx, AV_LOG_ERROR, "Default layer\"%s\" isn't supported. Please 
"
+   "check if vulkan-validation-layers installed\n", default_layer);
+} else {
+av_log(ctx, AV_LOG_VERBOSE,
+   "Default validation layer %s is enabled\n", default_layer);
+ADD_VAL_TO_LIST(enabled_layers, enabled_layers_count, default_layer);
+}
+
+token = av_strtok(user_layers_str, "+", &save);
+while (token) {
+found = 0;
+if (!strcmp(default_layer, token)) {
+token = av_strtok(NULL, "+", &save);
+continue;
+}
+for (int j = 0; j < sup_layer_count; j++) {
+if (!strcmp(token, sup_layers[j].layerName)) {
+found = 1;
+break;
+}
+}
+if (found) {
+av_log(ctx, AV_LOG_VERBOSE, "Requested Validation Layer: %s\n", 
token);
+ADD_VAL_TO_LIST(enabled_layers, enabled_layers_count, token);
+} else {
+av_log(ctx, AV_LOG_ERROR,
+   "Validation Layer \"%s\" not support.\n", token);
+err = AVERROR(EINVAL);
+goto fail;
+}
+token = av_strtok(NULL, "+", &save);
+}
+
+*dst = enabled_layers;
+*num = enabled_layers_count;
+
+av_free(sup_layers);
+av_free(user_layers_str);
+return 0;
+
+fail:
+RELEASE_PROPS(enabled_layers, enabled_layers_count);
+av_free(sup_layers);
+av_free(user_layers_str);
+return err;
+}
+
 /* Creates a VkInstance */
 static int create_instance(AVHWDeviceContext *ctx, AVDictionary *opts)
 {
@@ -558,13 +651,16 @@ static int create_instance(AVHWDeviceContext *ctx, 
AVDictionary *opts)
 /* Check for present/missing extensions */
 err = check_extensions(ctx, 0, opts, &inst_props.ppEnabledExtensionNames,
&inst_props.enabledExtensionCount, debug_mod

Re: [FFmpeg-devel] [PATCH v2] avformat/mov: add option max_stts_delta

2021-11-23 Thread Gyan Doshi



On 2021-11-24 01:16 am, Michael Niedermayer wrote:

On Tue, Nov 23, 2021 at 06:41:06PM +0530, Gyan Doshi wrote:

Very high stts sample deltas may occasionally be intended but usually
they are written in error or used to store a negative value for dts correction
when treated as signed 32-bit integers.

This option lets the user set an upper limit, beyond which the delta
is clamped to 1. Negative values of under 1 second are used to adjust
dts.

Unit is the track time scale. Default is INT_MAX which maintains current 
handling.
---
  doc/demuxers.texi  |  6 ++
  libavformat/isom.h |  1 +
  libavformat/mov.c  | 14 +-
  3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index cab8a7072c..15078b9b1b 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -713,6 +713,12 @@ specify.
  
  @item decryption_key

  16-byte key, in hex, to decrypt files encrypted using ISO Common Encryption 
(CENC/AES-128 CTR; ISO/IEC 23001-7).
+
+@item max_stts_delta
+The sample offsets stored in a track's stts box are 32-bit unsigned integers. 
However, very large values usually indicate
+a value written by error or a storage of a small negative value as a way to 
correct accumulated DTS delay.
+Range is 0 to UINT_MAX. Default is INT_MAX.
+
  @end table
  
  @subsection Audible AAX

diff --git a/libavformat/isom.h b/libavformat/isom.h
index ef8f19b18c..625dea8421 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -305,6 +305,7 @@ typedef struct MOVContext {
  int32_t movie_display_matrix[3][3]; ///< display matrix from mvhd
  int have_read_mfra_size;
  uint32_t mfra_size;
+uint32_t max_stts_delta;
  } MOVContext;
  
  int ff_mp4_read_descr_len(AVIOContext *pb);

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 451cb78bbf..bbda07ac42 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3965,14 +3965,17 @@ static void mov_build_index(MOVContext *mov, AVStream 
*st)
  current_offset += sample_size;
  stream_size += sample_size;
  
-/* A negative sample duration is invalid based on the spec,

- * but some samples need it to correct the DTS. */
-if (sc->stts_data[stts_index].duration < 0) {
+/* STTS sample offsets are uint32 but some files store it as 
int32
+ * with negative values used to correct DTS delays.
+   There may be abnormally large values as well. */
+if (sc->stts_data[stts_index].duration > mov->max_stts_delta) {
+// assume high delta is a negative correction if less than 
1 second
+int32_t delta_magnitude = *((int32_t 
*)&sc->stts_data[stts_index].duration);
  av_log(mov->fc, AV_LOG_WARNING,
-   "Invalid SampleDelta %d in STTS, at %d st:%d\n",
+   "Correcting too large SampleDelta %u in STTS, at %d 
st:%d.\n",
 sc->stts_data[stts_index].duration, stts_index,
 st->index);
-dts_correction += sc->stts_data[stts_index].duration - 1;
+dts_correction += (delta_magnitude < 0 && FFABS(delta_magnitude) 
< sc->time_scale ? delta_magnitude - 1 : 0);
  sc->stts_data[stts_index].duration = 1;
  }
  current_dts += sc->stts_data[stts_index].duration;
@@ -8566,6 +8569,7 @@ static const AVOption mov_options[] = {
  { "decryption_key", "The media decryption key (hex)", 
OFFSET(decryption_key), AV_OPT_TYPE_BINARY, .flags = AV_OPT_FLAG_DECODING_PARAM },
  { "enable_drefs", "Enable external track support.", OFFSET(enable_drefs), 
AV_OPT_TYPE_BOOL,
  {.i64 = 0}, 0, 1, FLAGS },
+{ "max_stts_delta", "treat offsets above this value as invalid", 
OFFSET(max_stts_delta), AV_OPT_TYPE_INT, {.i64 = INT_MAX}, 0, UINT_MAX, .flags = 
AV_OPT_FLAG_DECODING_PARAM },
  
  { NULL },

  };

The stts is used in other places, the value parsed as unsigned will cause
problems there too

I see stts duration used in 3 places in mov.c

mov_read_stts(), which my earlier patch changed.

mov_build_index(), which this patch changes,

mov_read_trak() where frame rate is populated for CFR streams and is 
called very shortly after mov_build_index().
I don't think that can break for non-malformed files as the only 
duration entry in the stream is not likely to be > INT_MAX
In any case, after this patch, with default option value, it will see 
the same values as earlier.



the cast is also fragile as it will break when someone tries to change it
to int64


In what circumstances would that happen?

The syntax of stts sample_delta has been unchanged since the start.
I see  'unsigned int(32) sample_delta;' in the 2005 2nd ed.
Same in the 2015 5th ed.


FFABS(delta_magnitude) is also undefined for INT_MIN


Will add a check for that.


also please select t

[FFmpeg-devel] [PATCH V2 2/5] libavutil/hwcontext_vaapi: Add a new nv12 format map to support vulkan frame

2021-11-23 Thread Wenbin Chen
Vulkan will map nv12 to R8 and GR88, so add this map to vaapi to support
vulkan frame.

Signed-off-by: Wenbin Chen 
---
 libavutil/hwcontext_vaapi.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 75acc851d6..994b744e4d 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -992,6 +992,7 @@ static const struct {
 } vaapi_drm_format_map[] = {
 #ifdef DRM_FORMAT_R8
 DRM_MAP(NV12, 2, DRM_FORMAT_R8,  DRM_FORMAT_RG88),
+DRM_MAP(NV12, 2, DRM_FORMAT_R8,  DRM_FORMAT_GR88),
 #endif
 DRM_MAP(NV12, 1, DRM_FORMAT_NV12),
 #if defined(VA_FOURCC_P010) && defined(DRM_FORMAT_R16)
-- 
2.25.1

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

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


[FFmpeg-devel] [PATCH V2 3/5] libavutil/hwcontext_vulkan: Allocate vkFrame in one memory

2021-11-23 Thread Wenbin Chen
The vaapi can import external frame, but the planes of the external
frames should be in the same drm object. A new option "contiguous_planes"
is added to device. This flag tells device to allocate places in one
memory. When device is derived from vaapi this flag will be enabled.
A new flag frame_flag is also added to AVVulkanFramesContext. User
can use this flag to force enable or disable this behaviour.
A new variable "offset "is added to AVVKFrame. It describe describe the
offset from the memory currently bound to the VkImage.

Signed-off-by: Wenbin Chen 
---
 libavutil/hwcontext_vulkan.c | 62 ++--
 libavutil/hwcontext_vulkan.h | 22 +
 2 files changed, 82 insertions(+), 2 deletions(-)

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index f1e750cd3e..4100e8b0a2 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -103,6 +103,9 @@ typedef struct VulkanDevicePriv {
 /* Settings */
 int use_linear_images;
 
+/* allocate planes in a contiguous memory */
+int contiguous_planes;
+
 /* Nvidia */
 int dev_is_nvidia;
 } VulkanDevicePriv;
@@ -1266,6 +1269,11 @@ static int 
vulkan_device_create_internal(AVHWDeviceContext *ctx,
 if (opt_d)
 p->use_linear_images = strtol(opt_d->value, NULL, 10);
 
+opt_d = av_dict_get(opts, "contiguous_planes", NULL, 0);
+if (opt_d)
+p->contiguous_planes = strtol(opt_d->value, NULL, 10);
+
+
 hwctx->enabled_dev_extensions = dev_info.ppEnabledExtensionNames;
 hwctx->nb_enabled_dev_extensions = dev_info.enabledExtensionCount;
 
@@ -1410,8 +1418,10 @@ static int vulkan_device_derive(AVHWDeviceContext *ctx,
 return AVERROR_EXTERNAL;
 }
 
-if (strstr(vendor, "Intel"))
+if (strstr(vendor, "Intel")) {
+av_dict_set_int(&opts, "contiguous_planes", 1, 0);
 dev_select.vendor_id = 0x8086;
+}
 if (strstr(vendor, "AMD"))
 dev_select.vendor_id = 0x1002;
 
@@ -1634,8 +1644,12 @@ static int alloc_bind_mem(AVHWFramesContext *hwfc, 
AVVkFrame *f,
 AVHWDeviceContext *ctx = hwfc->device_ctx;
 VulkanDevicePriv *p = ctx->internal->priv;
 FFVulkanFunctions *vk = &p->vkfn;
+AVVulkanFramesContext *hwfctx = hwfc->hwctx;
 const int planes = av_pix_fmt_count_planes(hwfc->sw_format);
 VkBindImageMemoryInfo bind_info[AV_NUM_DATA_POINTERS] = { { 0 } };
+VkMemoryRequirements memory_requirements = { 0 };
+int mem_size = 0;
+int mem_size_list[AV_NUM_DATA_POINTERS] = { 0 };
 
 AVVulkanDeviceContext *hwctx = ctx->hwctx;
 
@@ -1663,6 +1677,19 @@ static int alloc_bind_mem(AVHWFramesContext *hwfc, 
AVVkFrame *f,
 req.memoryRequirements.size = FFALIGN(req.memoryRequirements.size,
   
p->props.properties.limits.minMemoryMapAlignment);
 
+if (hwfctx->contiguous_planes == AV_VK_FRAME_FLAG_CONTIGUOUS_MEMORY) {
+if (memory_requirements.size == 0) {
+memory_requirements = req.memoryRequirements;
+} else if (memory_requirements.memoryTypeBits != 
req.memoryRequirements.memoryTypeBits) {
+av_log(hwfc, AV_LOG_ERROR, "the param for each planes are not 
the same\n");
+return AVERROR(EINVAL);
+}
+
+mem_size_list[i] = req.memoryRequirements.size;
+mem_size += mem_size_list[i];
+continue;
+}
+
 /* In case the implementation prefers/requires dedicated allocation */
 use_ded_mem = ded_req.prefersDedicatedAllocation |
   ded_req.requiresDedicatedAllocation;
@@ -1684,6 +1711,29 @@ static int alloc_bind_mem(AVHWFramesContext *hwfc, 
AVVkFrame *f,
 bind_info[i].memory = f->mem[i];
 }
 
+if (hwfctx->contiguous_planes == AV_VK_FRAME_FLAG_CONTIGUOUS_MEMORY) {
+memory_requirements.size = mem_size;
+
+/* Allocate memory */
+if ((err = alloc_mem(ctx, &memory_requirements,
+f->tiling == VK_IMAGE_TILING_LINEAR ?
+VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT :
+VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
+(void *)(((uint8_t *)alloc_pnext)),
+&f->flags, &f->mem[0])))
+return err;
+
+f->size[0] = memory_requirements.size;
+
+for (int i = 0; i < planes; i++) {
+bind_info[i].sType  = VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO;
+bind_info[i].image  = f->img[i];
+bind_info[i].memory = f->mem[0];
+bind_info[i].memoryOffset = i == 0 ? 0 : mem_size_list[i-1];
+f->offset[i] = bind_info[i].memoryOffset;
+}
+}
+
 /* Bind the allocated memory to the images */
 ret = vk->BindImageMemory2(hwctx->act_dev, planes, bind_info);
 if (ret != VK_SUCCESS) {
@@ -2046,6 +2096,12 @@ 

[FFmpeg-devel] [PATCH V2 1/5] hwcontext_vaapi: Use PRIME_2 memory type for modifiers.

2021-11-23 Thread Wenbin Chen
From: Bas Nieuwenhuizen 

This way we can pass explicit modifiers in. Sometimes the
modifier matters for the number of memory planes that
libva accepts, in particular when dealing with
driver-compressed textures. Furthermore the driver might
not actually be able to determine the implicit modifier
if all the buffer-passing has used explicit modifier.
All these issues should be resolved by passing in the
modifier, and for that we switch to using the PRIME_2
memory type.

Tested with experimental radeonsi patches for modifiers
and kmsgrab. Also tested with radeonsi without the
patches to double-check it works without PRIME_2 support.

v2:
  Cache PRIME_2 support to avoid doing two calls every time on
  libva drivers that do not support it.

v3:
  Remove prime2_vas usage.

Signed-off-by: Bas Nieuwenhuizen 
---
 libavutil/hwcontext_vaapi.c | 158 ++--
 1 file changed, 114 insertions(+), 44 deletions(-)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 83e542876d..75acc851d6 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -79,6 +79,9 @@ typedef struct VAAPIFramesContext {
 unsigned int rt_format;
 // Whether vaDeriveImage works.
 int derive_works;
+// Caches whether VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2 is unsupported for
+// surface imports.
+int prime_2_import_unsupported;
 } VAAPIFramesContext;
 
 typedef struct VAAPIMapping {
@@ -1022,32 +1025,17 @@ static void vaapi_unmap_from_drm(AVHWFramesContext 
*dst_fc,
 static int vaapi_map_from_drm(AVHWFramesContext *src_fc, AVFrame *dst,
   const AVFrame *src, int flags)
 {
+VAAPIFramesContext *src_vafc = src_fc->internal->priv;
 AVHWFramesContext  *dst_fc =
 (AVHWFramesContext*)dst->hw_frames_ctx->data;
 AVVAAPIDeviceContext  *dst_dev = dst_fc->device_ctx->hwctx;
 const AVDRMFrameDescriptor *desc;
 const VAAPIFormatDescriptor *format_desc;
 VASurfaceID surface_id;
-VAStatus vas;
+VAStatus vas = VA_STATUS_SUCCESS;
+int use_prime2;
 uint32_t va_fourcc;
-int err, i, j, k;
-
-unsigned long buffer_handle;
-VASurfaceAttribExternalBuffers buffer_desc;
-VASurfaceAttrib attrs[2] = {
-{
-.type  = VASurfaceAttribMemoryType,
-.flags = VA_SURFACE_ATTRIB_SETTABLE,
-.value.type= VAGenericValueTypeInteger,
-.value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME,
-},
-{
-.type  = VASurfaceAttribExternalBufferDescriptor,
-.flags = VA_SURFACE_ATTRIB_SETTABLE,
-.value.type= VAGenericValueTypePointer,
-.value.value.p = &buffer_desc,
-}
-};
+int err, i, j;
 
 desc = (AVDRMFrameDescriptor*)src->data[0];
 
@@ -1083,35 +1071,117 @@ static int vaapi_map_from_drm(AVHWFramesContext 
*src_fc, AVFrame *dst,
 format_desc = vaapi_format_from_fourcc(va_fourcc);
 av_assert0(format_desc);
 
-buffer_handle = desc->objects[0].fd;
-buffer_desc.pixel_format = va_fourcc;
-buffer_desc.width= src_fc->width;
-buffer_desc.height   = src_fc->height;
-buffer_desc.data_size= desc->objects[0].size;
-buffer_desc.buffers  = &buffer_handle;
-buffer_desc.num_buffers  = 1;
-buffer_desc.flags= 0;
-
-k = 0;
-for (i = 0; i < desc->nb_layers; i++) {
-for (j = 0; j < desc->layers[i].nb_planes; j++) {
-buffer_desc.pitches[k] = desc->layers[i].planes[j].pitch;
-buffer_desc.offsets[k] = desc->layers[i].planes[j].offset;
-++k;
+use_prime2 = !src_vafc->prime_2_import_unsupported &&
+ desc->objects[0].format_modifier != DRM_FORMAT_MOD_INVALID;
+if (use_prime2) {
+VADRMPRIMESurfaceDescriptor prime_desc;
+VASurfaceAttrib prime_attrs[2] = {
+{
+.type  = VASurfaceAttribMemoryType,
+.flags = VA_SURFACE_ATTRIB_SETTABLE,
+.value.type= VAGenericValueTypeInteger,
+.value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2,
+},
+{
+.type  = VASurfaceAttribExternalBufferDescriptor,
+.flags = VA_SURFACE_ATTRIB_SETTABLE,
+.value.type= VAGenericValueTypePointer,
+.value.value.p = &prime_desc,
+}
+};
+prime_desc.fourcc = va_fourcc;
+prime_desc.width = src_fc->width;
+prime_desc.height = src_fc->height;
+prime_desc.num_objects = desc->nb_objects;
+for (i = 0; i < desc->nb_objects; ++i) {
+prime_desc.objects[i].fd = desc->objects[i].fd;
+prime_desc.objects[i].size = desc->objects[i].size;
+prime_desc.objects[i].drm_format_modifier =
+desc->objects[i].format_modifier;
 }
-}
-buffer_desc.num_planes = k;
 
-if (format_desc->chroma_planes

[FFmpeg-devel] [PATCH V2 4/5] libavutil/hwcontext_vulkan: Add hwupload and hwdownload support when using contiguous_planes flag.

2021-11-23 Thread Wenbin Chen
Add hwupload and hwdownload support to vulkan when frames are allocated
in one memory

Signed-off-by: Wenbin Chen 
---
 libavutil/hwcontext_vulkan.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index 4100e8b0a2..6421115385 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -2212,9 +2212,10 @@ static int vulkan_map_frame_to_mem(AVHWFramesContext 
*hwfc, AVFrame *dst,
const AVFrame *src, int flags)
 {
 VkResult ret;
-int err, mapped_mem_count = 0;
+int err, mapped_mem_count = 0, loop = 0;
 AVVkFrame *f = (AVVkFrame *)src->data[0];
 AVVulkanDeviceContext *hwctx = hwfc->device_ctx->hwctx;
+AVVulkanFramesContext *hwfctx = hwfc->hwctx;
 const int planes = av_pix_fmt_count_planes(hwfc->sw_format);
 VulkanDevicePriv *p = hwfc->device_ctx->internal->priv;
 FFVulkanFunctions *vk = &p->vkfn;
@@ -2241,7 +2242,9 @@ static int vulkan_map_frame_to_mem(AVHWFramesContext 
*hwfc, AVFrame *dst,
 dst->width  = src->width;
 dst->height = src->height;
 
-for (int i = 0; i < planes; i++) {
+loop = hwfctx->contiguous_planes == AV_VK_FRAME_FLAG_CONTIGUOUS_MEMORY ?
+   1 : planes;
+for (int i = 0; i < loop; i++) {
 ret = vk->MapMemory(hwctx->act_dev, f->mem[i], 0,
 VK_WHOLE_SIZE, 0, (void **)&dst->data[i]);
 if (ret != VK_SUCCESS) {
@@ -2252,6 +2255,11 @@ static int vulkan_map_frame_to_mem(AVHWFramesContext 
*hwfc, AVFrame *dst,
 }
 mapped_mem_count++;
 }
+if (hwfctx->contiguous_planes == AV_VK_FRAME_FLAG_CONTIGUOUS_MEMORY) {
+for (int i = 0; i < planes; i++) {
+dst->data[i] = dst->data[0] + f->offset[i];
+}
+}
 
 /* Check if the memory contents matter */
 if (((flags & AV_HWFRAME_MAP_READ) || !(flags & AV_HWFRAME_MAP_OVERWRITE)) 
&&
-- 
2.25.1

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

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


[FFmpeg-devel] [PATCH V2 5/5] libavutil/hwcontext_vulkan: specify the modifier to create VKImage

2021-11-23 Thread Wenbin Chen
When vulkan image exports to drm, the tilling need to be
VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT. Now add code to create vulkan
image using this format.

Now the following command line works:

ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 
-hwaccel_output_format \
vaapi -i input_1080p.264 -vf "hwmap=derive_device=vulkan,format=vulkan, \
scale_vulkan=1920:1080,hwmap=derive_device=vaapi,format=vaapi" -c:v h264_vaapi 
output.264

Signed-off-by: Wenbin Chen 
---
 libavutil/hwcontext_vulkan.c | 130 +--
 1 file changed, 124 insertions(+), 6 deletions(-)

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index 6421115385..4b951fb202 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -230,6 +230,28 @@ const VkFormat *av_vkfmt_from_pixfmt(enum AVPixelFormat p)
 return NULL;
 }
 
+static void *find_in_structure_list(VkBaseOutStructure *stru_list, 
VkStructureType sType) {
+if (!stru_list)
+return NULL;
+
+for(;stru_list;stru_list = stru_list->pNext)
+if (stru_list->sType == sType)
+return stru_list;
+
+return NULL;
+}
+
+static void append_to_structure_list(VkBaseOutStructure **stru_list, 
VkBaseOutStructure *added_stru) {
+VkBaseOutStructure *p;
+if (!*stru_list) {
+*stru_list = added_stru;
+return;
+}
+for(p = *stru_list; p->pNext; p = p->pNext);
+p->pNext = added_stru;
+return;
+}
+
 static int pixfmt_is_supported(AVHWDeviceContext *dev_ctx, enum AVPixelFormat 
p,
int linear)
 {
@@ -1979,6 +2001,10 @@ static void try_export_flags(AVHWFramesContext *hwfc,
 AVVulkanDeviceContext *dev_hwctx = hwfc->device_ctx->hwctx;
 VulkanDevicePriv *p = hwfc->device_ctx->internal->priv;
 FFVulkanFunctions *vk = &p->vkfn;
+const int has_modifiers = hwctx->tiling == 
VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT;
+int loop_count;
+VkImageDrmFormatModifierListCreateInfoEXT *modifier_info = 
find_in_structure_list(hwctx->create_pnext,
+
VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_LIST_CREATE_INFO_EXT);
 VkExternalImageFormatProperties eprops = {
 .sType = VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES_KHR,
 };
@@ -1986,9 +2012,18 @@ static void try_export_flags(AVHWFramesContext *hwfc,
 .sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2,
 .pNext = &eprops,
 };
+VkPhysicalDeviceImageDrmFormatModifierInfoEXT phy_dev_mod_info = {
+.sType = 
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_DRM_FORMAT_MODIFIER_INFO_EXT,
+.pNext = NULL,
+.pQueueFamilyIndices   = p->qfs,
+.queueFamilyIndexCount = p->num_qfs,
+.sharingMode   = p->num_qfs > 1 ? VK_SHARING_MODE_CONCURRENT :
+  VK_SHARING_MODE_EXCLUSIVE,
+};
 VkPhysicalDeviceExternalImageFormatInfo enext = {
 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO,
 .handleType = exp,
+.pNext = has_modifiers && modifier_info ? &phy_dev_mod_info : NULL,
 };
 VkPhysicalDeviceImageFormatInfo2 pinfo = {
 .sType  = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2,
@@ -2000,11 +2035,16 @@ static void try_export_flags(AVHWFramesContext *hwfc,
 .flags  = VK_IMAGE_CREATE_ALIAS_BIT,
 };
 
-ret = vk->GetPhysicalDeviceImageFormatProperties2(dev_hwctx->phys_dev,
-  &pinfo, &props);
-if (ret == VK_SUCCESS) {
-*iexp |= exp;
-*comp_handle_types |= 
eprops.externalMemoryProperties.compatibleHandleTypes;
+loop_count = has_modifiers && modifier_info ? 
modifier_info->drmFormatModifierCount : 1;
+for (int i = 0; i < loop_count; i++) {
+if (has_modifiers && modifier_info)
+phy_dev_mod_info.drmFormatModifier = 
modifier_info->pDrmFormatModifiers[i];
+ret = vk->GetPhysicalDeviceImageFormatProperties2(dev_hwctx->phys_dev,
+&pinfo, &props);
+if (ret == VK_SUCCESS) {
+*iexp |= exp;
+*comp_handle_types |= 
eprops.externalMemoryProperties.compatibleHandleTypes;
+}
 }
 }
 
@@ -2074,6 +2114,20 @@ fail:
 static void vulkan_frames_uninit(AVHWFramesContext *hwfc)
 {
 VulkanFramesPriv *fp = hwfc->internal->priv;
+AVVulkanFramesContext *hwctx = hwfc->hwctx;
+VkBaseOutStructure *structure_p_next,*structure_p = hwctx->create_pnext;
+VkImageDrmFormatModifierListCreateInfoEXT *modifier_info;
+while (structure_p) {
+structure_p_next = structure_p->pNext;
+switch (structure_p->sType) {
+case VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_LIST_CREATE_INFO_EXT:
+modifier_info = (VkImageDrmFormatModifierListCreateInfoEXT 
*)structure_p;
+av_freep(&modifier_info->pDrmFormatModifiers);
+

[FFmpeg-devel] [PATCH] libavcodec/h264: always set color description fields

2021-11-23 Thread Xiaolei Yu
Color description fields shall be inferred to be UNSPECIFIED if not present.
---
 libavcodec/h264_ps.c|  4 +++-
 libavcodec/h264_slice.c | 18 +++---
 2 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/libavcodec/h264_ps.c b/libavcodec/h264_ps.c
index e21c2b56ac..164e6ea0cc 100644
--- a/libavcodec/h264_ps.c
+++ b/libavcodec/h264_ps.c
@@ -378,7 +378,9 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, 
AVCodecContext *avctx,
 memset(sps->scaling_matrix4, 16, sizeof(sps->scaling_matrix4));
 memset(sps->scaling_matrix8, 16, sizeof(sps->scaling_matrix8));
 sps->scaling_matrix_present = 0;
-sps->colorspace = 2; //AVCOL_SPC_UNSPECIFIED
+sps->colorspace = AVCOL_SPC_UNSPECIFIED;
+sps->color_trc = AVCOL_TRC_UNSPECIFIED;
+sps->color_primaries = AVCOL_PRI_UNSPECIFIED;
 
 if (sps->profile_idc == 100 ||  // High profile
 sps->profile_idc == 110 ||  // High10 profile
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 89ea16a57f..b7f1dfc9ef 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -1103,17 +1103,13 @@ static int h264_init_ps(H264Context *h, const 
H264SliceContext *sl, int first_sl
 
 init_dimensions(h);
 
-if (sps->video_signal_type_present_flag) {
-h->avctx->color_range = sps->full_range > 0 ? AVCOL_RANGE_JPEG
-: AVCOL_RANGE_MPEG;
-if (sps->colour_description_present_flag) {
-if (h->avctx->colorspace != sps->colorspace)
-needs_reinit = 1;
-h->avctx->color_primaries = sps->color_primaries;
-h->avctx->color_trc   = sps->color_trc;
-h->avctx->colorspace  = sps->colorspace;
-}
-}
+h->avctx->color_range = sps->full_range > 0 ? AVCOL_RANGE_JPEG
+: AVCOL_RANGE_MPEG;
+if (h->avctx->colorspace != sps->colorspace)
+needs_reinit = 1;
+h->avctx->color_primaries = sps->color_primaries;
+h->avctx->color_trc   = sps->color_trc;
+h->avctx->colorspace  = sps->colorspace;
 
 if (h->sei.alternative_transfer.present &&
 
av_color_transfer_name(h->sei.alternative_transfer.preferred_transfer_characteristics)
 &&
-- 
2.33.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".