mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-05 15:08:53 +00:00
validate: Add a mock decryptor element.
This commit is contained in:
parent
e536b05e5a
commit
ab0be78469
5 changed files with 248 additions and 0 deletions
|
@ -4,6 +4,7 @@ built_source_make = gst-validate-enum-types.c
|
||||||
source_c = \
|
source_c = \
|
||||||
gst-validate-runner.c \
|
gst-validate-runner.c \
|
||||||
gst-validate-reporter.c \
|
gst-validate-reporter.c \
|
||||||
|
gst-validate-mockdecryptor.c \
|
||||||
gst-validate-monitor.c \
|
gst-validate-monitor.c \
|
||||||
gst-validate-element-monitor.c \
|
gst-validate-element-monitor.c \
|
||||||
gst-validate-bin-monitor.c \
|
gst-validate-bin-monitor.c \
|
||||||
|
|
181
validate/gst/validate/gst-validate-mockdecryptor.c
Normal file
181
validate/gst/validate/gst-validate-mockdecryptor.c
Normal file
|
@ -0,0 +1,181 @@
|
||||||
|
/* GStreamer
|
||||||
|
* Copyright (C) 2019 Igalia S.L
|
||||||
|
* Copyright (C) 2019 Metrological
|
||||||
|
* Author: Charlie Turner <cturner@igalia.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the
|
||||||
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||||
|
* Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "gst-validate-mockdecryptor.h"
|
||||||
|
|
||||||
|
#define CLEARKEY_SYSTEM_ID "78f32170-d883-11e0-9572-0800200c9a66"
|
||||||
|
#define WIDEVINE_SYSTEM_ID "edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"
|
||||||
|
|
||||||
|
GST_DEBUG_CATEGORY_STATIC (gst_mockdecryptor_debug);
|
||||||
|
#define GST_CAT_DEFAULT gst_mockdecryptor_debug
|
||||||
|
|
||||||
|
static GstStaticPadTemplate gst_mockdecryptor_sink_template =
|
||||||
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
||||||
|
GST_PAD_SINK,
|
||||||
|
GST_PAD_ALWAYS,
|
||||||
|
GST_STATIC_CAPS
|
||||||
|
("application/x-cenc, original-media-type=(string)video/x-h264, "
|
||||||
|
GST_PROTECTION_SYSTEM_ID_CAPS_FIELD "=(string)" WIDEVINE_SYSTEM_ID "; "
|
||||||
|
"application/x-cenc, original-media-type=(string)audio/mpeg, "
|
||||||
|
GST_PROTECTION_SYSTEM_ID_CAPS_FIELD "=(string)" WIDEVINE_SYSTEM_ID)
|
||||||
|
);
|
||||||
|
|
||||||
|
static GstStaticPadTemplate gst_mockdecryptor_src_template =
|
||||||
|
GST_STATIC_PAD_TEMPLATE ("src",
|
||||||
|
GST_PAD_SRC,
|
||||||
|
GST_PAD_ALWAYS,
|
||||||
|
GST_STATIC_CAPS ("video/webm; "
|
||||||
|
"audio/webm; "
|
||||||
|
"video/mp4; " "audio/mp4; " "audio/mpeg; " "video/x-h264"));
|
||||||
|
|
||||||
|
#define _mockdecryptor_do_init \
|
||||||
|
GST_DEBUG_CATEGORY_INIT (gst_mockdecryptor_debug, GST_MOCKDECRYPTOR_NAME, 0, "mock decryptor element");
|
||||||
|
#define gst_mockdecryptor_parent_class parent_class
|
||||||
|
G_DEFINE_TYPE_WITH_CODE (GstMockDecryptor, gst_mockdecryptor,
|
||||||
|
GST_TYPE_BASE_TRANSFORM, _mockdecryptor_do_init);
|
||||||
|
|
||||||
|
static GstCaps *gst_mockdecryptor_transform_caps (GstBaseTransform *,
|
||||||
|
GstPadDirection, GstCaps *, GstCaps *);
|
||||||
|
static GstFlowReturn gst_mockdecryptor_transform_in_place (GstBaseTransform *,
|
||||||
|
GstBuffer *);
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_mockdecryptor_class_init (GstMockDecryptorClass * klass)
|
||||||
|
{
|
||||||
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
||||||
|
GstBaseTransformClass *base_transform_class =
|
||||||
|
GST_BASE_TRANSFORM_CLASS (klass);
|
||||||
|
|
||||||
|
base_transform_class->transform_ip =
|
||||||
|
GST_DEBUG_FUNCPTR (gst_mockdecryptor_transform_in_place);
|
||||||
|
base_transform_class->transform_caps =
|
||||||
|
GST_DEBUG_FUNCPTR (gst_mockdecryptor_transform_caps);
|
||||||
|
base_transform_class->transform_ip_on_passthrough = FALSE;
|
||||||
|
|
||||||
|
gst_element_class_add_static_pad_template (element_class,
|
||||||
|
&gst_mockdecryptor_sink_template);
|
||||||
|
gst_element_class_add_static_pad_template (element_class,
|
||||||
|
&gst_mockdecryptor_src_template);
|
||||||
|
|
||||||
|
gst_element_class_set_metadata (element_class,
|
||||||
|
"Mock decryptor element for unit tests",
|
||||||
|
GST_ELEMENT_FACTORY_KLASS_DECRYPTOR,
|
||||||
|
"Use in unit tests", "Charlie Turner <cturner@igalia.com>");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_mockdecryptor_init (GstMockDecryptor * klass)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static GstCaps *
|
||||||
|
gst_mockdecryptor_transform_caps (GstBaseTransform * base,
|
||||||
|
GstPadDirection direction, GstCaps * caps, GstCaps * filter)
|
||||||
|
{
|
||||||
|
GstCaps *transformed_caps = NULL;
|
||||||
|
guint incoming_caps_size, size;
|
||||||
|
gint duplicate;
|
||||||
|
|
||||||
|
if (direction == GST_PAD_UNKNOWN)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
GST_DEBUG_OBJECT (base,
|
||||||
|
"direction: %s, caps: %" GST_PTR_FORMAT " filter: %" GST_PTR_FORMAT,
|
||||||
|
(direction == GST_PAD_SRC) ? "src" : "sink", caps, filter);
|
||||||
|
|
||||||
|
transformed_caps = gst_caps_new_empty ();
|
||||||
|
|
||||||
|
incoming_caps_size = gst_caps_get_size (caps);
|
||||||
|
for (guint i = 0; i < incoming_caps_size; ++i) {
|
||||||
|
GstStructure *incoming_structure = gst_caps_get_structure (caps, i);
|
||||||
|
GstStructure *outgoing_structure = NULL;
|
||||||
|
|
||||||
|
if (direction == GST_PAD_SINK) {
|
||||||
|
if (!gst_structure_has_field (incoming_structure, "original-media-type"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
outgoing_structure = gst_structure_copy (incoming_structure);
|
||||||
|
gst_structure_set_name (outgoing_structure,
|
||||||
|
gst_structure_get_string (outgoing_structure, "original-media-type"));
|
||||||
|
|
||||||
|
gst_structure_remove_fields (outgoing_structure, "protection-system",
|
||||||
|
"original-media-type", "encryption-algorithm", "encoding-scope",
|
||||||
|
"cipher-mode", NULL);
|
||||||
|
} else {
|
||||||
|
outgoing_structure = gst_structure_copy (incoming_structure);
|
||||||
|
|
||||||
|
/* Filter out the video related fields from the up-stream caps,
|
||||||
|
* because they are not relevant to the input caps of this element and
|
||||||
|
* can cause caps negotiation failures with adaptive bitrate streams.
|
||||||
|
*/
|
||||||
|
gst_structure_remove_fields (outgoing_structure, "base-profile",
|
||||||
|
"codec_data", "height", "framerate", "level", "pixel-aspect-ratio",
|
||||||
|
"profile", "rate", "width", NULL);
|
||||||
|
|
||||||
|
gst_structure_set (outgoing_structure,
|
||||||
|
"protection-system", G_TYPE_STRING, WIDEVINE_SYSTEM_ID,
|
||||||
|
"original-media-type", G_TYPE_STRING,
|
||||||
|
gst_structure_get_name (incoming_structure), NULL);
|
||||||
|
|
||||||
|
gst_structure_set_name (outgoing_structure, "application/x-cenc");
|
||||||
|
}
|
||||||
|
|
||||||
|
duplicate = FALSE;
|
||||||
|
size = gst_caps_get_size (transformed_caps);
|
||||||
|
|
||||||
|
for (guint index = 0; !duplicate && index < size; ++index) {
|
||||||
|
GstStructure *structure =
|
||||||
|
gst_caps_get_structure (transformed_caps, index);
|
||||||
|
if (gst_structure_is_equal (structure, outgoing_structure))
|
||||||
|
duplicate = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!duplicate)
|
||||||
|
gst_caps_append_structure (transformed_caps, outgoing_structure);
|
||||||
|
else
|
||||||
|
gst_structure_free (outgoing_structure);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter) {
|
||||||
|
GstCaps *intersection;
|
||||||
|
|
||||||
|
GST_DEBUG_OBJECT (base, "Using filter caps %" GST_PTR_FORMAT, filter);
|
||||||
|
intersection =
|
||||||
|
gst_caps_intersect_full (transformed_caps, filter,
|
||||||
|
GST_CAPS_INTERSECT_FIRST);
|
||||||
|
gst_caps_replace (&transformed_caps, intersection);
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_DEBUG_OBJECT (base, "returning %" GST_PTR_FORMAT, transformed_caps);
|
||||||
|
return transformed_caps;
|
||||||
|
}
|
||||||
|
|
||||||
|
static GstFlowReturn
|
||||||
|
gst_mockdecryptor_transform_in_place (GstBaseTransform * base,
|
||||||
|
GstBuffer * buffer)
|
||||||
|
{
|
||||||
|
/* We are a mock decryptor, just pass the encrypted buffers through... */
|
||||||
|
return GST_FLOW_OK;
|
||||||
|
}
|
61
validate/gst/validate/gst-validate-mockdecryptor.h
Normal file
61
validate/gst/validate/gst-validate-mockdecryptor.h
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
/* GStreamer
|
||||||
|
* Copyright (C) 2019 Igalia S.L
|
||||||
|
* Copyright (C) 2019 Metrological
|
||||||
|
* Author: Charlie Turner <cturner@igalia.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the
|
||||||
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||||
|
* Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __GST_MOCKDECRYPTOR_H__
|
||||||
|
#define __GST_MOCKDECRYPTOR_H__
|
||||||
|
|
||||||
|
typedef struct _GstMockDecryptor GstMockDecryptor;
|
||||||
|
typedef struct _GstMockDecryptorClass GstMockDecryptorClass;
|
||||||
|
|
||||||
|
#include <gst/gst.h>
|
||||||
|
#include <gst/video/video.h>
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
#define GST_TYPE_MOCKDECRYPTOR \
|
||||||
|
(gst_mockdecryptor_get_type ())
|
||||||
|
#define GST_MOCKDECRYPTOR(obj) \
|
||||||
|
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MOCKDECRYPTOR,GstMockDecryptor))
|
||||||
|
#define GST_MOCKDECRYPTOR_CLASS(klass) \
|
||||||
|
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_MOCKDECRYPTOR,GstMockDecryptorClass))
|
||||||
|
#define GST_IS_MOCKDECRYPTOR(obj) \
|
||||||
|
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MOCKDECRYPTOR))
|
||||||
|
#define GST_IS_MOCKDECRYPTOR_CLASS(klass) \
|
||||||
|
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MOCKDECRYPTOR))
|
||||||
|
#define GST_MOCKDECRYPTOR_GET_CLASS(obj) \
|
||||||
|
(G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_MOCKDECRYPTOR,GstMockDecryptorClass))
|
||||||
|
|
||||||
|
#define GST_MOCKDECRYPTOR_NAME "mockdecryptor"
|
||||||
|
struct _GstMockDecryptor
|
||||||
|
{
|
||||||
|
GstBaseTransform element;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _GstMockDecryptorClass
|
||||||
|
{
|
||||||
|
GstBaseTransformClass parent_class;
|
||||||
|
};
|
||||||
|
|
||||||
|
G_GNUC_INTERNAL GType gst_mockdecryptor_get_type (void);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
#endif /* __GST_MOCKDECRYPTOR_H__ */
|
|
@ -36,6 +36,7 @@
|
||||||
#include "gst-validate-override-registry.h"
|
#include "gst-validate-override-registry.h"
|
||||||
#include "gst-validate-runner.h"
|
#include "gst-validate-runner.h"
|
||||||
#include "gst-validate-reporter.h"
|
#include "gst-validate-reporter.h"
|
||||||
|
#include "gst-validate-mockdecryptor.h"
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY_STATIC (gst_validate_runner_debug);
|
GST_DEBUG_CATEGORY_STATIC (gst_validate_runner_debug);
|
||||||
#undef GST_CAT_DEFAULT
|
#undef GST_CAT_DEFAULT
|
||||||
|
@ -447,6 +448,9 @@ gst_validate_runner_init (GstValidateRunner * runner)
|
||||||
|
|
||||||
gst_tracing_register_hook (GST_TRACER (runner), "element-new",
|
gst_tracing_register_hook (GST_TRACER (runner), "element-new",
|
||||||
G_CALLBACK (do_element_new));
|
G_CALLBACK (do_element_new));
|
||||||
|
|
||||||
|
gst_element_register (NULL, GST_MOCKDECRYPTOR_NAME, GST_RANK_MARGINAL,
|
||||||
|
GST_TYPE_MOCKDECRYPTOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
gstvalidate_sources = [
|
gstvalidate_sources = [
|
||||||
'gst-validate-runner.c',
|
'gst-validate-runner.c',
|
||||||
'gst-validate-reporter.c',
|
'gst-validate-reporter.c',
|
||||||
|
'gst-validate-mockdecryptor.c',
|
||||||
'gst-validate-monitor.c',
|
'gst-validate-monitor.c',
|
||||||
'gst-validate-element-monitor.c',
|
'gst-validate-element-monitor.c',
|
||||||
'gst-validate-bin-monitor.c',
|
'gst-validate-bin-monitor.c',
|
||||||
|
|
Loading…
Reference in a new issue