There is a standard template of gstreamer metadata already defined?

瘦欲@ 提交于 2021-02-08 10:43:13

问题


I'm writing a gstreamer-1.0 plugin in c. I would need to pass a parameter through the pipeline from one plugin to another by passing through other elements. I want to use metadata. I just have to transmit a "double" type variable and would like to avoid having to define a new metadata and its API. I tried to search a list of metadata already defined but have not found anything.

My question is: There is a metadata already defined that has these characteristics ?


回答1:


I'm not aware of any generic meta type that you could piggy back on, unfortunately. If you'd like to share with us what type of data you're trying to pass someone may be able to to suggest a workaround.

Here's a sample Meta API we ended up doing to pass a simple GstClockTime value.

gstmark.h

#ifndef __GST_MARK_H__
#define __GST_MARK_H__

#include <gst/gst.h>
#include <gst/gstmeta.h>

G_BEGIN_DECLS

typedef struct _GstMetaMarking GstMetaMarking;

struct _GstMetaMarking {
    GstMeta meta;
    GstClockTime in_timestamp;
};

GType gst_meta_marking_api_get_type (void);
const GstMetaInfo* gst_meta_marking_get_info (void);
#define GST_META_MARKING_GET(buf) ((GstMetaMarking *)gst_buffer_get_meta(buf,gst_meta_marking_api_get_type()))
#define GST_META_MARKING_ADD(buf) ((GstMetaMarking *)gst_buffer_add_meta(buf,gst_meta_marking_get_info(),(gpointer)NULL))

G_END_DECLS

#endif

gstmark.c

#include "gstmark.h"

GType
gst_meta_marking_api_get_type (void)
{
  static volatile GType type;
  static const gchar *tags[] = { NULL };

  if (g_once_init_enter (&type)) {
    GType _type = gst_meta_api_type_register ("GstMetaMarkingAPI", tags);
    g_once_init_leave (&type, _type);
  }
  return type;
}

gboolean
gst_meta_marking_init(GstMeta *meta, gpointer params, GstBuffer *buffer)
{
    GstMetaMarking* marking_meta = (GstMetaMarking*)meta;

    marking_meta->in_timestamp = GST_CLOCK_TIME_NONE;

    return TRUE;
}

gboolean
gst_meta_marking_transform (GstBuffer *dest_buf,
                             GstMeta *src_meta,
                             GstBuffer *src_buf,
                             GQuark type,
                             gpointer data) {
    GstMeta* dest_meta = GST_META_MARKING_ADD(dest_buf);

    GstMetaMarking* src_meta_marking = (GstMetaMarking*)src_meta;
    GstMetaMarking* dest_meta_marking = (GstMetaMarking*)dest_meta;

    dest_meta_marking->in_timestamp = src_meta_marking->in_timestamp;

    return TRUE;
}

void
gst_meta_marking_free (GstMeta *meta, GstBuffer *buffer) {
}

const GstMetaInfo *
gst_meta_marking_get_info (void)
{
  static const GstMetaInfo *meta_info = NULL;

  if (g_once_init_enter (&meta_info)) {
    const GstMetaInfo *meta =
        gst_meta_register (gst_meta_marking_api_get_type (), "GstMetaMarking",
        sizeof (GstMetaMarking), (GstMetaInitFunction)gst_meta_marking_init,
        (GstMetaFreeFunction)gst_meta_marking_free, (GstMetaTransformFunction) gst_meta_marking_transform);
    g_once_init_leave (&meta_info, meta);
  }
  return meta_info;
}

Then to add the metadata:

GstMetaMarking* meta = GST_META_MARKING_ADD(in);


来源:https://stackoverflow.com/questions/40630098/there-is-a-standard-template-of-gstreamer-metadata-already-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!