Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QSV Overlay Filter: Copy side data from input to output frame #44

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/APIchanges
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ libavutil: 2021-04-27

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the FFmpeg mailing list, "Xiang, Haihao" wrote (reply to this):

On Thu, 2022-11-03 at 11:41 +0000, softworkz wrote:
> From: softworkz <[email protected]>
> 
> Signed-off-by: softworkz <[email protected]>
> Signed-off-by: Anton Khirnov <[email protected]>
> ---
>  doc/APIchanges      |  4 +++
>  libavutil/frame.c   | 67 +++++++++++++++++++++++++++------------------
>  libavutil/frame.h   | 32 ++++++++++++++++++++++
>  libavutil/version.h |  2 +-
>  4 files changed, 78 insertions(+), 27 deletions(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 3c86f24285..e88cf7b4aa 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -14,6 +14,10 @@ libavutil:     2021-04-27
>  
>  API changes, most recent first:
>  
> +2022-05-26 - xxxxxxxxx - lavu 57.41.100 - frame.h
> +  Add av_frame_remove_all_side_data(), av_frame_copy_side_data(),
> +  AV_FRAME_TRANSFER_SD_COPY, and AV_FRAME_TRANSFER_SD_FILTER.
> +  
>  2022-10-30 - xxxxxxxxxx - lavu 57.40.100 - channel_layout.h
>    Add AV_CH_LAYOUT_CUBE and AV_CHANNEL_LAYOUT_CUBE.
>  
> diff --git a/libavutil/frame.c b/libavutil/frame.c
> index de4ad1f94d..8eb0e1ec95 100644
> --- a/libavutil/frame.c
> +++ b/libavutil/frame.c
> @@ -276,9 +276,45 @@ FF_ENABLE_DEPRECATION_WARNINGS
>      return AVERROR(EINVAL);
>  }
>  
> +void av_frame_remove_all_side_data(AVFrame *frame)
> +{
> +    wipe_side_data(frame);
> +}
> +
> +int av_frame_copy_side_data(AVFrame* dst, const AVFrame* src, int flags)
> +{
> +    for (unsigned i = 0; i < src->nb_side_data; i++) {
> +        const AVFrameSideData *sd_src = src->side_data[i];
> +        AVFrameSideData *sd_dst;
> +        if ((flags & AV_FRAME_TRANSFER_SD_FILTER) &&
> +            sd_src->type == AV_FRAME_DATA_PANSCAN &&
> +            (src->width != dst->width || src->height != dst->height))
> +            continue;
> +        if (flags & AV_FRAME_TRANSFER_SD_COPY) {
> +            sd_dst = av_frame_new_side_data(dst, sd_src->type,
> +                                            sd_src->size);
> +            if (!sd_dst) {
> +                wipe_side_data(dst);
> +                return AVERROR(ENOMEM);
> +            }
> +            memcpy(sd_dst->data, sd_src->data, sd_src->size);
> +        } else {
> +            AVBufferRef *ref = av_buffer_ref(sd_src->buf);
> +            sd_dst = av_frame_new_side_data_from_buf(dst, sd_src->type, ref);
> +            if (!sd_dst) {
> +                av_buffer_unref(&ref);
> +                wipe_side_data(dst);
> +                return AVERROR(ENOMEM);
> +            }
> +        }
> +        av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0);
> +    }
> +    return 0;
> +}
> +
>  static int frame_copy_props(AVFrame *dst, const AVFrame *src, int force_copy)
>  {
> -    int ret, i;
> +    int ret;
>  
>      dst->key_frame              = src->key_frame;
>      dst->pict_type              = src->pict_type;
> @@ -319,31 +355,10 @@ FF_ENABLE_DEPRECATION_WARNINGS
>  
>      av_dict_copy(&dst->metadata, src->metadata, 0);
>  
> -    for (i = 0; i < src->nb_side_data; i++) {
> -        const AVFrameSideData *sd_src = src->side_data[i];
> -        AVFrameSideData *sd_dst;
> -        if (   sd_src->type == AV_FRAME_DATA_PANSCAN
> -            && (src->width != dst->width || src->height != dst->height))
> -            continue;
> -        if (force_copy) {
> -            sd_dst = av_frame_new_side_data(dst, sd_src->type,
> -                                            sd_src->size);
> -            if (!sd_dst) {
> -                wipe_side_data(dst);
> -                return AVERROR(ENOMEM);
> -            }
> -            memcpy(sd_dst->data, sd_src->data, sd_src->size);
> -        } else {
> -            AVBufferRef *ref = av_buffer_ref(sd_src->buf);
> -            sd_dst = av_frame_new_side_data_from_buf(dst, sd_src->type, ref);
> -            if (!sd_dst) {
> -                av_buffer_unref(&ref);
> -                wipe_side_data(dst);
> -                return AVERROR(ENOMEM);
> -            }
> -        }
> -        av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0);
> -    }
> +    if ((ret = av_frame_copy_side_data(dst, src,
> +            (force_copy ? AV_FRAME_TRANSFER_SD_COPY : 0) |
> +            AV_FRAME_TRANSFER_SD_FILTER) < 0))
> +        return ret;
>  
>      ret = av_buffer_replace(&dst->opaque_ref, src->opaque_ref);
>      ret |= av_buffer_replace(&dst->private_ref, src->private_ref);
> diff --git a/libavutil/frame.h b/libavutil/frame.h
> index e60a82f6c0..5a3362fb55 100644
> --- a/libavutil/frame.h
> +++ b/libavutil/frame.h
> @@ -861,6 +861,30 @@ int av_frame_copy(AVFrame *dst, const AVFrame *src);
>   */
>  int av_frame_copy_props(AVFrame *dst, const AVFrame *src);
>  
> +
> +/**
> + * Copy side data, rather than creating new references.
> + */
> +#define AV_FRAME_TRANSFER_SD_COPY      (1 << 0)
> +/**
> + * Filter out side data that does not match dst properties.
> + */
> +#define AV_FRAME_TRANSFER_SD_FILTER    (1 << 1)
> +
> +/**
> + * Copy all side-data from src to dst.
> + *
> + * @param dst a frame to which the side data should be copied.
> + * @param src a frame from which to copy the side data.
> + * @param flags a combination of AV_FRAME_TRANSFER_SD_*
> + *
> + * @return 0 on success, a negative AVERROR on error.
> + *
> + * @note This function will create new references to side data buffers in
> src,
> + * unless the AV_FRAME_TRANSFER_SD_COPY flag is passed.
> + */
> +int av_frame_copy_side_data(AVFrame* dst, const AVFrame* src, int flags);
> +
>  /**
>   * Get the buffer reference a given data plane is stored in.
>   *
> @@ -913,6 +937,14 @@ AVFrameSideData *av_frame_get_side_data(const AVFrame
> *frame,
>   */
>  void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType
> type);
>  
> +/**
> + * Remove and free all side data instances.
> + *
> + * @param frame from which to remove all side data.
> + */
> +void av_frame_remove_all_side_data(AVFrame *frame);
> +
> +
>  
>  /**
>   * Flags for frame cropping.
> diff --git a/libavutil/version.h b/libavutil/version.h
> index 2df788e529..b913f9d6c5 100644
> --- a/libavutil/version.h
> +++ b/libavutil/version.h
> @@ -79,7 +79,7 @@
>   */
>  
>  #define LIBAVUTIL_VERSION_MAJOR  57
> -#define LIBAVUTIL_VERSION_MINOR  40
> +#define LIBAVUTIL_VERSION_MINOR  41
>  #define LIBAVUTIL_VERSION_MICRO 100
>  
>  #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \


>>> Patchset LGTM, I'll push this patchset if no more comment or objection. 
 
>> Can you wait a few days on this? I'd like to take a look at #1.

Hi Andreas,

Do you have any other thought about this patchset ? I'd like to merge this
patchset to fix qsv overlay.

BRs
Haihao




_______________________________________________
ffmpeg-devel mailing list
[email protected]
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
[email protected] with subject "unsubscribe".

API changes, most recent first:

2022-05-26 - xxxxxxxxx - lavu 57.41.100 - frame.h
Add av_frame_remove_all_side_data(), av_frame_copy_side_data(),
AV_FRAME_TRANSFER_SD_COPY, and AV_FRAME_TRANSFER_SD_FILTER.

2022-10-30 - xxxxxxxxxx - lavu 57.40.100 - channel_layout.h
Add AV_CH_LAYOUT_CUBE and AV_CHANNEL_LAYOUT_CUBE.

Expand Down
67 changes: 41 additions & 26 deletions libavutil/frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,45 @@ FF_ENABLE_DEPRECATION_WARNINGS
return AVERROR(EINVAL);
}

void av_frame_remove_all_side_data(AVFrame *frame)
{
wipe_side_data(frame);
}

int av_frame_copy_side_data(AVFrame* dst, const AVFrame* src, int flags)
{
for (unsigned i = 0; i < src->nb_side_data; i++) {
const AVFrameSideData *sd_src = src->side_data[i];
AVFrameSideData *sd_dst;
if ((flags & AV_FRAME_TRANSFER_SD_FILTER) &&
sd_src->type == AV_FRAME_DATA_PANSCAN &&
(src->width != dst->width || src->height != dst->height))
continue;
if (flags & AV_FRAME_TRANSFER_SD_COPY) {
sd_dst = av_frame_new_side_data(dst, sd_src->type,
sd_src->size);
if (!sd_dst) {
wipe_side_data(dst);
return AVERROR(ENOMEM);
}
memcpy(sd_dst->data, sd_src->data, sd_src->size);
} else {
AVBufferRef *ref = av_buffer_ref(sd_src->buf);
sd_dst = av_frame_new_side_data_from_buf(dst, sd_src->type, ref);
if (!sd_dst) {
av_buffer_unref(&ref);
wipe_side_data(dst);
return AVERROR(ENOMEM);
}
}
av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0);
}
return 0;
}

static int frame_copy_props(AVFrame *dst, const AVFrame *src, int force_copy)
{
int ret, i;
int ret;

dst->key_frame = src->key_frame;
dst->pict_type = src->pict_type;
Expand Down Expand Up @@ -319,31 +355,10 @@ FF_ENABLE_DEPRECATION_WARNINGS

av_dict_copy(&dst->metadata, src->metadata, 0);

for (i = 0; i < src->nb_side_data; i++) {
const AVFrameSideData *sd_src = src->side_data[i];
AVFrameSideData *sd_dst;
if ( sd_src->type == AV_FRAME_DATA_PANSCAN
&& (src->width != dst->width || src->height != dst->height))
continue;
if (force_copy) {
sd_dst = av_frame_new_side_data(dst, sd_src->type,
sd_src->size);
if (!sd_dst) {
wipe_side_data(dst);
return AVERROR(ENOMEM);
}
memcpy(sd_dst->data, sd_src->data, sd_src->size);
} else {
AVBufferRef *ref = av_buffer_ref(sd_src->buf);
sd_dst = av_frame_new_side_data_from_buf(dst, sd_src->type, ref);
if (!sd_dst) {
av_buffer_unref(&ref);
wipe_side_data(dst);
return AVERROR(ENOMEM);
}
}
av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0);
}
if ((ret = av_frame_copy_side_data(dst, src,
(force_copy ? AV_FRAME_TRANSFER_SD_COPY : 0) |
AV_FRAME_TRANSFER_SD_FILTER) < 0))
return ret;

ret = av_buffer_replace(&dst->opaque_ref, src->opaque_ref);
ret |= av_buffer_replace(&dst->private_ref, src->private_ref);
Expand Down
32 changes: 32 additions & 0 deletions libavutil/frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,30 @@ int av_frame_copy(AVFrame *dst, const AVFrame *src);
*/
int av_frame_copy_props(AVFrame *dst, const AVFrame *src);


/**
* Copy side data, rather than creating new references.
*/
#define AV_FRAME_TRANSFER_SD_COPY (1 << 0)
/**
* Filter out side data that does not match dst properties.
*/
#define AV_FRAME_TRANSFER_SD_FILTER (1 << 1)

/**
* Copy all side-data from src to dst.
*
* @param dst a frame to which the side data should be copied.
* @param src a frame from which to copy the side data.
* @param flags a combination of AV_FRAME_TRANSFER_SD_*
*
* @return 0 on success, a negative AVERROR on error.
*
* @note This function will create new references to side data buffers in src,
* unless the AV_FRAME_TRANSFER_SD_COPY flag is passed.
*/
int av_frame_copy_side_data(AVFrame* dst, const AVFrame* src, int flags);

/**
* Get the buffer reference a given data plane is stored in.
*
Expand Down Expand Up @@ -913,6 +937,14 @@ AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
*/
void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type);

/**
* Remove and free all side data instances.
*
* @param frame from which to remove all side data.
*/
void av_frame_remove_all_side_data(AVFrame *frame);



/**
* Flags for frame cropping.
Expand Down
2 changes: 1 addition & 1 deletion libavutil/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
*/

#define LIBAVUTIL_VERSION_MAJOR 57
#define LIBAVUTIL_VERSION_MINOR 40
#define LIBAVUTIL_VERSION_MINOR 41
#define LIBAVUTIL_VERSION_MICRO 100

#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
Expand Down