validate: Totally hide media descriptor node types from the API

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1986>
This commit is contained in:
Thibault Saunier 2022-03-18 09:07:48 -03:00 committed by GStreamer Marge Bot
parent 2913ab9dbf
commit 692750efae
5 changed files with 122 additions and 85 deletions

View file

@ -74,6 +74,9 @@ G_GNUC_INTERNAL gboolean is_tty (void);
/* MediaDescriptor structures */
typedef struct _GstValidateMediaFileNode GstValidateMediaFileNode;
typedef struct _GstValidateMediaTagNode GstValidateMediaTagNode;
typedef struct
{
/* Children */
@ -170,4 +173,11 @@ typedef struct
gchar *str_close;
} GstValidateSegmentNode;
void gst_validate_filenode_free (GstValidateMediaFileNode *
filenode);
gboolean gst_validate_tag_node_compare (GstValidateMediaTagNode *
tnode, const GstTagList * tlist);
GstValidateMediaFileNode * gst_validate_media_descriptor_get_file_node (GstValidateMediaDescriptor *self);
#endif

View file

@ -230,7 +230,9 @@ on_start_element_cb (GMarkupParseContext * context,
const gchar ** attribute_values, gpointer user_data, GError ** error)
{
GstValidateMediaFileNode
* filenode = GST_VALIDATE_MEDIA_DESCRIPTOR (user_data)->filenode;
* filenode =
gst_validate_media_descriptor_get_file_node (GST_VALIDATE_MEDIA_DESCRIPTOR
(user_data));
GstValidateMediaDescriptorParserPrivate *priv =
GST_VALIDATE_MEDIA_DESCRIPTOR_PARSER (user_data)->priv;
@ -468,12 +470,13 @@ gboolean
g_return_val_if_fail (GST_IS_VALIDATE_MEDIA_DESCRIPTOR_PARSER (parser),
FALSE);
g_return_val_if_fail (((GstValidateMediaDescriptor *) parser)->filenode,
FALSE);
g_return_val_if_fail (gst_validate_media_descriptor_get_file_node (
(GstValidateMediaDescriptor *) parser), FALSE);
caps = gst_pad_query_caps (pad, NULL);
for (tmp = ((GstValidateMediaDescriptor *) parser)->filenode->streams; tmp;
tmp = tmp->next) {
for (tmp =
gst_validate_media_descriptor_get_file_node ((GstValidateMediaDescriptor
*) parser)->streams; tmp; tmp = tmp->next) {
GstValidateMediaStreamNode *streamnode = (GstValidateMediaStreamNode *)
tmp->data;
@ -499,11 +502,12 @@ gboolean
g_return_val_if_fail (GST_IS_VALIDATE_MEDIA_DESCRIPTOR_PARSER (parser),
FALSE);
g_return_val_if_fail (((GstValidateMediaDescriptor *) parser)->filenode,
FALSE);
g_return_val_if_fail (gst_validate_media_descriptor_get_file_node (
(GstValidateMediaDescriptor *) parser), FALSE);
for (tmp = ((GstValidateMediaDescriptor *) parser)->filenode->streams; tmp;
tmp = tmp->next) {
for (tmp =
gst_validate_media_descriptor_get_file_node ((GstValidateMediaDescriptor
*) parser)->streams; tmp; tmp = tmp->next) {
GstValidateMediaStreamNode *streamnode = (GstValidateMediaStreamNode *)
tmp->data;
@ -523,11 +527,13 @@ gboolean
g_return_val_if_fail (GST_IS_VALIDATE_MEDIA_DESCRIPTOR_PARSER (parser),
FALSE);
g_return_val_if_fail (((GstValidateMediaDescriptor *) parser)->filenode,
FALSE);
g_return_val_if_fail (gst_validate_media_descriptor_get_file_node (
(GstValidateMediaDescriptor *) parser), FALSE);
g_return_val_if_fail (GST_IS_STRUCTURE (taglist), FALSE);
tagsnode = ((GstValidateMediaDescriptor *) parser)->filenode->tags;
tagsnode =
gst_validate_media_descriptor_get_file_node ((GstValidateMediaDescriptor
*) parser)->tags;
for (tmptag = tagsnode->tags; tmptag; tmptag = tmptag->next) {
if (gst_validate_tag_node_compare ((GstValidateMediaTagNode *)
@ -549,10 +555,12 @@ gboolean
g_return_val_if_fail (GST_IS_VALIDATE_MEDIA_DESCRIPTOR_PARSER (parser),
FALSE);
g_return_val_if_fail (((GstValidateMediaDescriptor *) parser)->filenode,
FALSE);
g_return_val_if_fail (gst_validate_media_descriptor_get_file_node (
(GstValidateMediaDescriptor *) parser), FALSE);
tagsnode = ((GstValidateMediaDescriptor *) parser)->filenode->tags;
tagsnode =
gst_validate_media_descriptor_get_file_node ((GstValidateMediaDescriptor
*) parser)->tags;
for (tmptag = tagsnode->tags; tmptag; tmptag = tmptag->next) {
gchar *tag = NULL;

View file

@ -125,7 +125,9 @@ serialize_filenode (GstValidateMediaDescriptorWriter * writer)
GList *tmp, *tmp2;
GstValidateMediaTagsNode *tagsnode;
GstValidateMediaFileNode
* filenode = ((GstValidateMediaDescriptor *) writer)->filenode;
* filenode =
gst_validate_media_descriptor_get_file_node ((GstValidateMediaDescriptor
*) writer);
tmpstr = g_markup_printf_escaped ("<file duration=\"%" G_GUINT64_FORMAT
"\" frame-detection=\"%i\" skip-parsers=\"%i\" uri=\"%s\" seekable=\"%s\">\n",
@ -197,9 +199,10 @@ static
{
GList *tmp;
for (tmp = md->filenode->streams; tmp; tmp = tmp->next) {
GstValidateMediaStreamNode
* streamnode = (GstValidateMediaStreamNode *) tmp->data;
for (tmp = gst_validate_media_descriptor_get_file_node (md)->streams; tmp;
tmp = tmp->next) {
GstValidateMediaStreamNode *streamnode =
(GstValidateMediaStreamNode *) tmp->data;
if (streamnode->pad == pad) {
return streamnode;
@ -221,7 +224,9 @@ gst_validate_media_descriptor_writer_new (GstValidateRunner * runner,
g_object_new (GST_TYPE_VALIDATE_MEDIA_DESCRIPTOR_WRITER,
"validate-runner", runner, NULL);
fnode = ((GstValidateMediaDescriptor *) writer)->filenode;
fnode =
gst_validate_media_descriptor_get_file_node ((GstValidateMediaDescriptor
*) writer);
fnode->uri = g_strdup (uri);
fnode->duration = duration;
fnode->seekable = seekable;
@ -271,8 +276,8 @@ static gboolean
g_return_val_if_fail (GST_IS_VALIDATE_MEDIA_DESCRIPTOR_WRITER (writer),
FALSE);
g_return_val_if_fail (((GstValidateMediaDescriptor *) writer)->filenode,
FALSE);
g_return_val_if_fail (gst_validate_media_descriptor_get_file_node (
(GstValidateMediaDescriptor *) writer), FALSE);
snode = g_slice_new0 (GstValidateMediaStreamNode);
snode->frames = NULL;
@ -314,9 +319,10 @@ static gboolean
snode->str_close = g_markup_printf_escaped ("</stream>");
((GstValidateMediaDescriptor *) writer)->filenode->streams =
g_list_prepend (((GstValidateMediaDescriptor *) writer)->
filenode->streams, snode);
gst_validate_media_descriptor_get_file_node ((GstValidateMediaDescriptor *)
writer)->streams =
g_list_prepend (gst_validate_media_descriptor_get_file_node (
(GstValidateMediaDescriptor *) writer)->streams, snode);
if (gst_discoverer_stream_info_get_tags (info)) {
gst_validate_media_descriptor_writer_add_tags (writer, snode->id,
@ -398,8 +404,9 @@ _find_stream_id (GstPad * pad, GstEvent ** event,
const gchar *stream_id;
gst_event_parse_stream_start (*event, &stream_id);
for (tmp = ((GstValidateMediaDescriptor *) writer)->filenode->streams; tmp;
tmp = tmp->next) {
for (tmp =
gst_validate_media_descriptor_get_file_node ((GstValidateMediaDescriptor
*) writer)->streams; tmp; tmp = tmp->next) {
GstValidateMediaStreamNode *subnode =
(GstValidateMediaStreamNode *) tmp->data;
if (g_strcmp0 (subnode->id, stream_id) == 0) {
@ -614,7 +621,9 @@ _run_frame_analysis (GstValidateMediaDescriptorWriter * writer,
g_main_loop_run (writer->priv->loop);
filenode = ((GstValidateMediaDescriptor *) writer)->filenode;
filenode =
gst_validate_media_descriptor_get_file_node ((GstValidateMediaDescriptor
*) writer);
/* Segment are always prepended, let's reorder them. */
for (tmp = filenode->streams; tmp; tmp = tmp->next) {
GstValidateMediaStreamNode
@ -714,7 +723,8 @@ gst_validate_media_descriptor_writer_new_discover (GstValidateRunner * runner,
gst_validate_media_descriptor_writer_add_taglist (writer, tags);
if (GST_IS_DISCOVERER_CONTAINER_INFO (streaminfo)) {
((GstValidateMediaDescriptor *) writer)->filenode->caps =
gst_validate_media_descriptor_get_file_node ((GstValidateMediaDescriptor
*) writer)->caps =
gst_discoverer_stream_info_get_caps (GST_DISCOVERER_STREAM_INFO
(streaminfo));
@ -728,7 +738,8 @@ gst_validate_media_descriptor_writer_new_discover (GstValidateRunner * runner,
if (!GST_IS_DISCOVERER_AUDIO_INFO (info)
&& !GST_IS_DISCOVERER_AUDIO_INFO (info)
&& gst_discoverer_stream_info_get_next (streaminfo)) {
((GstValidateMediaDescriptor *) writer)->filenode->caps =
gst_validate_media_descriptor_get_file_node ((GstValidateMediaDescriptor
*) writer)->caps =
gst_discoverer_stream_info_get_caps (streaminfo);
streaminfo = gst_discoverer_stream_info_get_next (streaminfo);
}
@ -743,8 +754,11 @@ gst_validate_media_descriptor_writer_new_discover (GstValidateRunner * runner,
}
media_descriptor = (GstValidateMediaDescriptor *) writer;
if (streams == NULL && media_descriptor->filenode->caps)
writer->priv->raw_caps = gst_caps_copy (media_descriptor->filenode->caps);
if (streams == NULL
&& gst_validate_media_descriptor_get_file_node (media_descriptor)->caps)
writer->priv->raw_caps =
gst_caps_copy (gst_validate_media_descriptor_get_file_node
(media_descriptor)->caps);
gst_discoverer_stream_info_list_free (streams);
@ -774,11 +788,12 @@ gst_validate_media_descriptor_writer_add_tags (GstValidateMediaDescriptorWriter
g_return_val_if_fail (GST_IS_VALIDATE_MEDIA_DESCRIPTOR_WRITER (writer),
FALSE);
g_return_val_if_fail (((GstValidateMediaDescriptor *) writer)->filenode,
FALSE);
g_return_val_if_fail (gst_validate_media_descriptor_get_file_node (
(GstValidateMediaDescriptor *) writer), FALSE);
for (tmp = ((GstValidateMediaDescriptor *) writer)->filenode->streams; tmp;
tmp = tmp->next) {
for (tmp =
gst_validate_media_descriptor_get_file_node ((GstValidateMediaDescriptor
*) writer)->streams; tmp; tmp = tmp->next) {
GstValidateMediaStreamNode *subnode =
(GstValidateMediaStreamNode *) tmp->data;
if (g_strcmp0 (subnode->id, stream_id) == 0) {
@ -836,14 +851,15 @@ gst_validate_media_descriptor_writer_add_pad (GstValidateMediaDescriptorWriter *
g_return_val_if_fail (GST_IS_VALIDATE_MEDIA_DESCRIPTOR_WRITER (writer),
FALSE);
g_return_val_if_fail (((GstValidateMediaDescriptor *) writer)->filenode,
FALSE);
g_return_val_if_fail (gst_validate_media_descriptor_get_file_node (
(GstValidateMediaDescriptor *) writer), FALSE);
caps = gst_pad_get_current_caps (pad);
for (tmp = ((GstValidateMediaDescriptor *) writer)->filenode->streams; tmp;
tmp = tmp->next) {
GstValidateMediaStreamNode
* streamnode = (GstValidateMediaStreamNode *) tmp->data;
for (tmp =
gst_validate_media_descriptor_get_file_node ((GstValidateMediaDescriptor
*) writer)->streams; tmp; tmp = tmp->next) {
GstValidateMediaStreamNode *streamnode =
(GstValidateMediaStreamNode *) tmp->data;
if (streamnode->pad == pad) {
goto done;
@ -865,9 +881,10 @@ gst_validate_media_descriptor_writer_add_pad (GstValidateMediaDescriptorWriter *
snode->str_close = g_markup_printf_escaped ("</stream>");
((GstValidateMediaDescriptor *) writer)->filenode->streams =
g_list_prepend (((GstValidateMediaDescriptor *) writer)->
filenode->streams, snode);
gst_validate_media_descriptor_get_file_node ((GstValidateMediaDescriptor *)
writer)->streams =
g_list_prepend (gst_validate_media_descriptor_get_file_node (
(GstValidateMediaDescriptor *) writer)->streams, snode);
done:
if (caps != NULL)
@ -888,16 +905,20 @@ gboolean
g_return_val_if_fail (GST_IS_VALIDATE_MEDIA_DESCRIPTOR_WRITER (writer),
FALSE);
g_return_val_if_fail (((GstValidateMediaDescriptor *) writer)->filenode,
FALSE);
g_return_val_if_fail (gst_validate_media_descriptor_get_file_node (
(GstValidateMediaDescriptor *) writer), FALSE);
if (((GstValidateMediaDescriptor *) writer)->filenode->tags == NULL) {
if (gst_validate_media_descriptor_get_file_node ((GstValidateMediaDescriptor
*) writer)->tags == NULL) {
tagsnode = g_slice_new0 (GstValidateMediaTagsNode);
tagsnode->str_open = g_markup_printf_escaped ("<tags>");
tagsnode->str_close = g_markup_printf_escaped ("</tags>");
((GstValidateMediaDescriptor *) writer)->filenode->tags = tagsnode;
gst_validate_media_descriptor_get_file_node ((GstValidateMediaDescriptor *)
writer)->tags = tagsnode;
} else {
tagsnode = ((GstValidateMediaDescriptor *) writer)->filenode->tags;
tagsnode =
gst_validate_media_descriptor_get_file_node ((GstValidateMediaDescriptor
*) writer)->tags;
for (tmptag = tagsnode->tags; tmptag; tmptag = tmptag->next) {
if (gst_validate_tag_node_compare ((GstValidateMediaTagNode *)
tmptag->data, taglist)) {
@ -934,10 +955,12 @@ gst_validate_media_descriptor_writer_add_frame (GstValidateMediaDescriptorWriter
g_return_val_if_fail (GST_IS_VALIDATE_MEDIA_DESCRIPTOR_WRITER (writer),
FALSE);
g_return_val_if_fail (((GstValidateMediaDescriptor *) writer)->filenode,
FALSE);
g_return_val_if_fail (gst_validate_media_descriptor_get_file_node (
(GstValidateMediaDescriptor *) writer), FALSE);
filenode = ((GstValidateMediaDescriptor *) writer)->filenode;
filenode =
gst_validate_media_descriptor_get_file_node ((GstValidateMediaDescriptor
*) writer);
filenode->frame_detection = TRUE;
filenode->skip_parsers =
FLAG_IS_SET (writer,
@ -1004,8 +1027,8 @@ gst_validate_media_descriptor_writer_write (GstValidateMediaDescriptorWriter *
g_return_val_if_fail (GST_IS_VALIDATE_MEDIA_DESCRIPTOR_WRITER (writer),
FALSE);
g_return_val_if_fail (((GstValidateMediaDescriptor *) writer)->filenode,
FALSE);
g_return_val_if_fail (gst_validate_media_descriptor_get_file_node (
(GstValidateMediaDescriptor *) writer), FALSE);
serialized = serialize_filenode (writer);
@ -1025,8 +1048,8 @@ gst_validate_media_descriptor_writer_serialize (GstValidateMediaDescriptorWriter
{
g_return_val_if_fail (GST_IS_VALIDATE_MEDIA_DESCRIPTOR_WRITER (writer),
FALSE);
g_return_val_if_fail (((GstValidateMediaDescriptor *) writer)->filenode,
FALSE);
g_return_val_if_fail (gst_validate_media_descriptor_get_file_node (
(GstValidateMediaDescriptor *) writer), FALSE);
return serialize_filenode (writer);
}

View file

@ -27,7 +27,7 @@
struct _GstValidateMediaDescriptorPrivate
{
gpointer dummy;
GstValidateMediaFileNode *filenode;
};
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GstValidateMediaDescriptor,
@ -148,8 +148,8 @@ gst_validate_media_descriptor_dispose (GstValidateMediaDescriptor * self)
static void
gst_validate_media_descriptor_finalize (GstValidateMediaDescriptor * self)
{
if (self->filenode)
gst_validate_filenode_free (self->filenode);
if (self->priv->filenode)
gst_validate_filenode_free (self->priv->filenode);
G_OBJECT_CLASS (gst_validate_media_descriptor_parent_class)->finalize
(G_OBJECT (self));
@ -158,7 +158,8 @@ gst_validate_media_descriptor_finalize (GstValidateMediaDescriptor * self)
static void
gst_validate_media_descriptor_init (GstValidateMediaDescriptor * self)
{
self->filenode = g_slice_new0 (GstValidateMediaFileNode);
self->priv = gst_validate_media_descriptor_get_instance_private (self);
self->priv->filenode = g_slice_new0 (GstValidateMediaFileNode);
}
static void
@ -533,7 +534,7 @@ compare_streams (GstValidateMediaDescriptor * ref,
{
GstCaps *rcaps, *ccaps;
if (!stream_id_is_equal (ref->filenode->uri, rstream->id, cstream->id))
if (!stream_id_is_equal (ref->priv->filenode->uri, rstream->id, cstream->id))
return FALSE;
rcaps = caps_cleanup_parsing_fields (rstream->caps);
@ -567,7 +568,7 @@ gst_validate_media_descriptors_compare (GstValidateMediaDescriptor * ref,
{
GList *rstream_list;
GstValidateMediaFileNode
* rfilenode = ref->filenode, *cfilenode = compared->filenode;
* rfilenode = ref->priv->filenode, *cfilenode = compared->priv->filenode;
if (rfilenode->duration != cfilenode->duration) {
GST_VALIDATE_REPORT (ref, FILE_DURATION_INCORRECT,
@ -619,9 +620,9 @@ gboolean
gst_validate_media_descriptor_detects_frames (GstValidateMediaDescriptor * self)
{
g_return_val_if_fail (GST_IS_VALIDATE_MEDIA_DESCRIPTOR (self), FALSE);
g_return_val_if_fail (self->filenode, FALSE);
g_return_val_if_fail (self->priv->filenode, FALSE);
return self->filenode->frame_detection;
return self->priv->filenode->frame_detection;
}
/**
@ -636,9 +637,9 @@ gst_validate_media_descriptor_get_buffers (GstValidateMediaDescriptor * self,
GstCaps *pad_caps = gst_pad_get_current_caps (pad);
g_return_val_if_fail (GST_IS_VALIDATE_MEDIA_DESCRIPTOR (self), FALSE);
g_return_val_if_fail (self->filenode, FALSE);
g_return_val_if_fail (self->priv->filenode, FALSE);
for (tmpstream = self->filenode->streams;
for (tmpstream = self->priv->filenode->streams;
tmpstream; tmpstream = tmpstream->next) {
GstValidateMediaStreamNode
* streamnode = (GstValidateMediaStreamNode *) tmpstream->data;
@ -686,7 +687,7 @@ gst_validate_media_descriptor_has_frame_info (GstValidateMediaDescriptor * self)
{
GList *tmpstream;
for (tmpstream = self->filenode->streams;
for (tmpstream = self->priv->filenode->streams;
tmpstream; tmpstream = tmpstream->next) {
GstValidateMediaStreamNode
* streamnode = (GstValidateMediaStreamNode *) tmpstream->data;
@ -702,18 +703,18 @@ GstClockTime
gst_validate_media_descriptor_get_duration (GstValidateMediaDescriptor * self)
{
g_return_val_if_fail (GST_IS_VALIDATE_MEDIA_DESCRIPTOR (self), FALSE);
g_return_val_if_fail (self->filenode, FALSE);
g_return_val_if_fail (self->priv->filenode, FALSE);
return self->filenode->duration;
return self->priv->filenode->duration;
}
gboolean
gst_validate_media_descriptor_get_seekable (GstValidateMediaDescriptor * self)
{
g_return_val_if_fail (GST_IS_VALIDATE_MEDIA_DESCRIPTOR (self), FALSE);
g_return_val_if_fail (self->filenode, FALSE);
g_return_val_if_fail (self->priv->filenode, FALSE);
return self->filenode->seekable;
return self->priv->filenode->seekable;
}
/**
@ -724,7 +725,7 @@ gst_validate_media_descriptor_get_pads (GstValidateMediaDescriptor * self)
{
GList *ret = NULL, *tmp;
for (tmp = self->filenode->streams; tmp; tmp = tmp->next) {
for (tmp = self->priv->filenode->streams; tmp; tmp = tmp->next) {
GstValidateMediaStreamNode
* snode = (GstValidateMediaStreamNode *) tmp->data;
ret = g_list_append (ret, gst_pad_new (snode->padname, GST_PAD_UNKNOWN));
@ -732,3 +733,10 @@ gst_validate_media_descriptor_get_pads (GstValidateMediaDescriptor * self)
return ret;
}
GstValidateMediaFileNode *
gst_validate_media_descriptor_get_file_node (GstValidateMediaDescriptor * self)
{
return self->priv->filenode;
}

View file

@ -33,16 +33,6 @@ G_BEGIN_DECLS
#define GST_VALIDATE_UNKNOWN_BOOL - 1
typedef struct _GstValidateMediaFileNode GstValidateMediaFileNode;
typedef struct _GstValidateMediaTagNode GstValidateMediaTagNode;
GST_VALIDATE_API
void gst_validate_filenode_free (GstValidateMediaFileNode *
filenode);
GST_VALIDATE_API
gboolean gst_validate_tag_node_compare (GstValidateMediaTagNode *
tnode, const GstTagList * tlist);
GST_VALIDATE_API
GType gst_validate_media_descriptor_get_type (void);
@ -66,8 +56,6 @@ typedef struct
{
GstObject parent;
GstValidateMediaFileNode *filenode;
GMutex lock;
/*< private >*/