Coverage Report

Created: 2025-11-16 06:56

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gstreamer/subprojects/gst-plugins-base/gst-libs/gst/video/gstvideocodecalphameta.c
Line
Count
Source
1
/* GStreamer
2
 * Copyright (C) 2021 Collabora Ltd.
3
 *   Author: Nicolas Dufresne <nicolas.dufresne@collabora.com>
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Library General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2 of the License, or (at your option) any later version.
9
 *
10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Library General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Library General Public
16
 * License along with this library; if not, write to the
17
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18
 * Boston, MA 02110-1301, USA.
19
 */
20
#ifdef HAVE_CONFIG_H
21
#include "config.h"
22
#endif
23
24
#include "gstvideocodecalphameta.h"
25
26
/**
27
 * SECTION:gstvideocodecalphameta
28
 * @title: GstVideoCodecAlphaMeta
29
 * @short_description: GstMeta that can carry an extra buffer holding  an
30
 * encoded a frame whith luma that can be used as an alpha channel.
31
 *
32
 * This meta is primarily for internal use in GStreamer elements to support
33
 * VP8/VP9 transparent video stored into WebM or Matroska containers, or
34
 * transparent static AV1 images. Nothing prevents you from using this meta
35
 * for custom purposes, but it generally can't be used to easily to add support
36
 * for alpha channels to CODECs or formats that don't support that out of the
37
 * box.
38
 *
39
 * Since: 1.20
40
 */
41
42
/**
43
 * gst_video_codec_alpha_meta_api_get_type:
44
 *
45
 * Returns: #GType for the #GstVideoCodecAlphaMeta structure.
46
 *
47
 * Since: 1.20
48
 */
49
GType
50
gst_video_codec_alpha_meta_api_get_type (void)
51
0
{
52
0
  static GType type = 0;
53
0
  static const gchar *tags[] = { GST_META_TAG_VIDEO_STR, NULL };
54
55
0
  if (g_once_init_enter (&type)) {
56
0
    GType _type =
57
0
        gst_meta_api_type_register ("GstVideoCodecAlphaMetaAPI", tags);
58
0
    g_once_init_leave (&type, _type);
59
0
  }
60
0
  return type;
61
0
}
62
63
static gboolean
64
gst_video_codec_alpha_meta_transform (GstBuffer * dest,
65
    GstMeta * meta, GstBuffer * buffer, GQuark type, gpointer data)
66
0
{
67
0
  GstVideoCodecAlphaMeta *dmeta, *smeta;
68
69
0
  smeta = (GstVideoCodecAlphaMeta *) meta;
70
71
0
  if (GST_META_TRANSFORM_IS_COPY (type)) {
72
0
    dmeta =
73
0
        (GstVideoCodecAlphaMeta *) gst_buffer_add_meta (dest,
74
0
        GST_VIDEO_CODEC_ALPHA_META_INFO, NULL);
75
76
0
    if (!dmeta)
77
0
      return FALSE;
78
79
0
    dmeta->buffer = gst_buffer_ref (smeta->buffer);
80
0
  }
81
0
  return TRUE;
82
0
}
83
84
static gboolean
85
gst_video_codec_alpha_meta_init (GstMeta * meta, gpointer params,
86
    GstBuffer * buffer)
87
0
{
88
0
  GstVideoCodecAlphaMeta *ca_meta = (GstVideoCodecAlphaMeta *) meta;
89
90
  /* the buffer ownership is transfered to the Meta */
91
0
  ca_meta->buffer = (GstBuffer *) params;
92
93
0
  return TRUE;
94
0
}
95
96
static void
97
gst_video_codec_alpha_meta_free (GstMeta * meta, GstBuffer * buffer)
98
0
{
99
0
  GstVideoCodecAlphaMeta *ca_meta = (GstVideoCodecAlphaMeta *) meta;
100
0
  gst_clear_buffer (&ca_meta->buffer);
101
0
}
102
103
/**
104
 * gst_video_codec_alpha_meta_get_info:
105
 *
106
 * Returns: #GstMetaInfo pointer that describes #GstVideoCodecAlphaMeta.
107
 *
108
 * Since: 1.20
109
 */
110
const GstMetaInfo *
111
gst_video_codec_alpha_meta_get_info (void)
112
0
{
113
0
  static const GstMetaInfo *info = NULL;
114
115
0
  if (g_once_init_enter ((GstMetaInfo **) & info)) {
116
0
    const GstMetaInfo *meta =
117
0
        gst_meta_register (GST_VIDEO_CODEC_ALPHA_META_API_TYPE,
118
0
        "GstVideoCodecAlphaMeta",
119
0
        sizeof (GstVideoCodecAlphaMeta),
120
0
        gst_video_codec_alpha_meta_init,
121
0
        gst_video_codec_alpha_meta_free,
122
0
        gst_video_codec_alpha_meta_transform);
123
0
    g_once_init_leave ((GstMetaInfo **) & info, (GstMetaInfo *) meta);
124
0
  }
125
126
0
  return info;
127
0
}
128
129
/**
130
 * gst_buffer_add_video_codec_alpha_meta:
131
 * @buffer: (transfer none): a #GstBuffer
132
 * @alpha_buffer: (transfer full): a #GstBuffer
133
 *
134
 * Attaches a #GstVideoCodecAlphaMeta metadata to @buffer with
135
 * the given alpha buffer.
136
 *
137
 * Returns: (transfer none): the #GstVideoCodecAlphaMeta on @buffer.
138
 *
139
 * Since: 1.20
140
 */
141
GstVideoCodecAlphaMeta *
142
gst_buffer_add_video_codec_alpha_meta (GstBuffer * buffer,
143
    GstBuffer * alpha_buffer)
144
0
{
145
0
  GstVideoCodecAlphaMeta *meta;
146
147
0
  g_return_val_if_fail (buffer != NULL, NULL);
148
0
  g_return_val_if_fail (alpha_buffer != NULL, NULL);
149
150
0
  meta =
151
0
      (GstVideoCodecAlphaMeta *) gst_buffer_add_meta (buffer,
152
0
      GST_VIDEO_CODEC_ALPHA_META_INFO, alpha_buffer);
153
154
0
  return meta;
155
0
}