meta: add timing metadata

This commit is contained in:
Wim Taymans 2011-02-28 10:05:47 +01:00
parent 3a29d34923
commit d96cacc66c
2 changed files with 80 additions and 1 deletions

View file

@ -108,6 +108,7 @@ gst_meta_get_info (const gchar * impl)
return info;
}
/* Memory metadata */
typedef struct
{
guint8 *data;
@ -205,3 +206,64 @@ gst_buffer_add_meta_memory (GstBuffer * buffer, gpointer data,
return (GstMetaMemory *) meta;
}
/* Timing metadata */
static void
meta_timing_copy (GstBuffer * copy, GstMetaTiming * meta, GstBuffer * buffer)
{
GstMetaTiming *timing;
GST_DEBUG ("copy called from buffer %p to %p, meta %p", buffer, copy, meta);
timing = gst_buffer_add_meta_timing (copy);
timing->pts = meta->pts;
timing->dts = meta->dts;
timing->duration = meta->duration;
timing->clock_rate = meta->clock_rate;
}
static void
meta_timing_sub (GstBuffer * sub, GstMetaTiming * meta, GstBuffer * buffer,
guint offset, guint size)
{
GstMetaTiming *timing;
GST_DEBUG ("sub called from buffer %p to %p, meta %p, %u-%u", buffer, sub,
meta, offset, size);
timing = gst_buffer_add_meta_timing (sub);
if (offset == 0) {
/* same offset, copy timestamps */
timing->pts = meta->pts;
timing->dts = meta->dts;
if (size == GST_BUFFER_SIZE (buffer)) {
/* same size, copy duration */
timing->duration = meta->duration;
} else {
/* else clear */
timing->duration = GST_CLOCK_TIME_NONE;
}
} else {
timing->pts = -1;
timing->dts = -1;
timing->duration = -1;
}
timing->clock_rate = meta->clock_rate;
}
const GstMetaInfo *
gst_meta_timing_get_info (void)
{
static const GstMetaInfo *meta_info = NULL;
if (meta_info == NULL) {
meta_info = gst_meta_register ("GstMetaTiming", "GstMetaTiming",
sizeof (GstMetaTiming),
(GstMetaInitFunction) NULL,
(GstMetaFreeFunction) NULL,
(GstMetaCopyFunction) meta_timing_copy,
(GstMetaSubFunction) meta_timing_sub,
(GstMetaSerializeFunction) NULL, (GstMetaDeserializeFunction) NULL);
}
return meta_info;
}

View file

@ -145,6 +145,7 @@ const GstMetaInfo * gst_meta_get_info (const gchar * impl);
/* default metadata */
/* memory metadata */
typedef struct _GstMetaMemory GstMetaMemory;
const GstMetaInfo *gst_meta_memory_get_info(void);
@ -169,10 +170,26 @@ struct _GstMetaMemory
#define gst_meta_memory_unmap(m,d,s) ((m)->munmap_func(m, d, s))
#define gst_buffer_get_meta_memory(b) ((GstMetaMemory*)gst_buffer_get_meta((b),GST_META_MEMORY_INFO))
GstMetaMemory * gst_buffer_add_meta_memory (GstBuffer *buffer, gpointer data,
GFreeFunc free_func,
gsize size, gsize offset);
/* timing metadata */
typedef struct _GstMetaTiming GstMetaTiming;
const GstMetaInfo *gst_meta_timing_get_info(void);
#define GST_META_TIMING_INFO (gst_meta_timing_get_info())
struct _GstMetaTiming {
GstMeta meta; /* common meta header */
GstClockTime dts; /* decoding timestamp */
GstClockTime pts; /* presentation timestamp */
GstClockTime duration; /* duration of the data */
GstClockTime clock_rate; /* clock rate for the above values */
};
#define gst_buffer_get_meta_timing(b) ((GstMetaTiming*)gst_buffer_get_meta((b),GST_META_TIMING_INFO))
#define gst_buffer_add_meta_timing(b) ((GstMetaTiming*)gst_buffer_add_meta((b),GST_META_TIMING_INFO,NULL))
G_END_DECLS