Commit ecdfb96f authored by Wim Taymans's avatar Wim Taymans
Browse files

video: move methods into separate files

Move different video functionalities into different files
parent ec4ca477
......@@ -2,7 +2,8 @@
ORC_SOURCE=videoblendorc
include $(top_srcdir)/common/orc.mak
glib_enum_headers = video.h colorbalance.h navigation.h
glib_enum_headers = video.h video-format.h video-color.h video-info.h \
colorbalance.h navigation.h
glib_enum_define = GST_VIDEO
glib_gen_prefix = gst_video
glib_gen_basename = video
......@@ -20,6 +21,11 @@ libgstvideo_@GST_API_VERSION@_la_SOURCES = \
colorbalancechannel.c \
navigation.c \
video.c \
video-event.c \
video-format.c \
video-color.c \
video-info.c \
video-frame.c \
gstvideosink.c \
gstvideofilter.c \
convertframe.c \
......@@ -39,6 +45,11 @@ libgstvideo_@GST_API_VERSION@include_HEADERS = \
colorbalancechannel.h \
navigation.h \
video.h \
video-event.h \
video-format.h \
video-color.h \
video-info.h \
video-frame.h \
gstvideosink.h \
gstvideofilter.h \
gstvideometa.h \
......
/* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
* Library <2002> Ronald Bultje <rbultje@ronald.bitfreak.net>
* Copyright (C) 2007 David A. Schleef <ds@schleef.org>
*
* 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., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <string.h>
#include <stdio.h>
#include "video-color.h"
typedef struct
{
const gchar *name;
GstVideoColorimetry color;
} ColorimetryInfo;
#define MAKE_COLORIMETRY(n,r,m,t,p) { GST_VIDEO_COLORIMETRY_ ##n, \
{ GST_VIDEO_COLOR_RANGE ##r, GST_VIDEO_COLOR_MATRIX_ ##m, \
GST_VIDEO_TRANSFER_ ##t, GST_VIDEO_COLOR_PRIMARIES_ ##p } }
#define GST_VIDEO_COLORIMETRY_NONAME NULL
#define DEFAULT_YUV_SD 0
#define DEFAULT_YUV_HD 1
#define DEFAULT_RGB 3
#define DEFAULT_GRAY 4
#define DEFAULT_UNKNOWN 5
static const ColorimetryInfo colorimetry[] = {
MAKE_COLORIMETRY (BT601, _16_235, BT601, BT709, BT470M),
MAKE_COLORIMETRY (BT709, _16_235, BT709, BT709, BT709),
MAKE_COLORIMETRY (SMPTE240M, _16_235, SMPTE240M, SMPTE240M, SMPTE240M),
MAKE_COLORIMETRY (NONAME, _0_255, RGB, UNKNOWN, UNKNOWN),
MAKE_COLORIMETRY (NONAME, _0_255, BT601, UNKNOWN, UNKNOWN),
MAKE_COLORIMETRY (NONAME, _UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN),
};
static const ColorimetryInfo *
gst_video_get_colorimetry (const gchar * s)
{
gint i;
for (i = 0; colorimetry[i].name; i++) {
if (g_str_equal (colorimetry[i].name, s))
return &colorimetry[i];
}
return NULL;
}
#define IS_EQUAL(ci,i) (((ci)->color.range == (i)->range) && \
((ci)->color.matrix == (i)->matrix) && \
((ci)->color.transfer == (i)->transfer) && \
((ci)->color.primaries == (i)->primaries))
#define IS_UNKNOWN(ci) (IS_EQUAL (&colorimetry[DEFAULT_UNKNOWN], ci))
/**
* gst_video_colorimetry_from_string
* @cinfo: a #GstVideoColorimetry
* @color: a colorimetry string
*
* Parse the colorimetry string and update @cinfo with the parsed
* values.
*
* Returns: #TRUE if @color points to valid colorimetry info.
*/
gboolean
gst_video_colorimetry_from_string (GstVideoColorimetry * cinfo,
const gchar * color)
{
const ColorimetryInfo *ci;
if ((ci = gst_video_get_colorimetry (color))) {
*cinfo = ci->color;
} else {
gint r, m, t, p;
if (sscanf (color, "%d:%d:%d:%d", &r, &m, &t, &p) == 4) {
cinfo->range = r;
cinfo->matrix = m;
cinfo->transfer = t;
cinfo->primaries = p;
}
}
return TRUE;
}
/**
* gst_video_colorimetry_to_string
* @cinfo: a #GstVideoColorimetry
*
* Make a string representation of @cinfo.
*
* Returns: a string representation of @cinfo.
*/
gchar *
gst_video_colorimetry_to_string (GstVideoColorimetry * cinfo)
{
gint i;
for (i = 0; colorimetry[i].name; i++) {
if (IS_EQUAL (&colorimetry[i], cinfo)) {
return g_strdup (colorimetry[i].name);
}
}
if (!IS_UNKNOWN (cinfo)) {
return g_strdup_printf ("%d:%d:%d:%d", cinfo->range, cinfo->matrix,
cinfo->transfer, cinfo->primaries);
}
return NULL;
}
/**
* gst_video_colorimetry_matches:
* @info: a #GstVideoInfo
* @color: a colorimetry string
*
* Check if the colorimetry information in @info matches that of the
* string @color.
*
* Returns: #TRUE if @color conveys the same colorimetry info as the color
* information in @info.
*/
gboolean
gst_video_colorimetry_matches (GstVideoColorimetry * cinfo, const gchar * color)
{
const ColorimetryInfo *ci;
if ((ci = gst_video_get_colorimetry (color)))
return IS_EQUAL (ci, cinfo);
return FALSE;
}
#if 0
typedef struct
{
GstVideoColorPrimaries primaries;
gdouble xW, yW;
gdouble xR, yR;
gdouble xG, yG;
gdouble xB, yB;
} PrimariesInfo;
#define WP_C 0.31006, 0.31616
#define WP_D65 0.31271, 0.32902
static const PrimariesInfo primaries[] = {
{GST_VIDEO_COLOR_PRIMARIES_UNKNOWN, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
{GST_VIDEO_COLOR_PRIMARIES_BT709, WP_D65, 0.64, 0.33, 0.30, 0.60, 0.15, 0.06},
{GST_VIDEO_COLOR_PRIMARIES_BT470M, WP_C, 0.67, 0.33, 0.21, 0.71, 0.14, 0.08},
{GST_VIDEO_COLOR_PRIMARIES_BT470BG, WP_D65, 0.64, 0.33, 0.29, 0.60, 0.15,
0.06},
{GST_VIDEO_COLOR_PRIMARIES_SMPTE170M, WP_D65, 0.63, 0.34, 0.31, 0.595, 0.155,
0.07},
{GST_VIDEO_COLOR_PRIMARIES_SMPTE240M, WP_D65, 0.63, 0.34, 0.31, 0.595, 0.155,
0.07},
{GST_VIDEO_COLOR_PRIMARIES_FILM, WP_C, 0.681, 0.319, 0.243, 0.692, 0.145,
0.049}
};
#endif
/* GStreamer
* Copyright (C) <2011> Wim Taymans <wim.taymans@gmail.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., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GST_VIDEO_COLOR_H__
#define __GST_VIDEO_COLOR_H__
#include <gst/gst.h>
G_BEGIN_DECLS
/**
* GstVideoColorRange:
* @GST_VIDEO_COLOR_RANGE_UNKNOWN: unknown range
* @GST_VIDEO_COLOR_RANGE_0_255: [0..255] for 8 bit components
* @GST_VIDEO_COLOR_RANGE_16_235: [16..235] for 8 bit components. Chroma has
* [16..240] range.
*
* Possible color range values. These constants are defined for 8 bit color
* values and can be scaled for other bit depths.
*/
typedef enum {
GST_VIDEO_COLOR_RANGE_UNKNOWN = 0,
GST_VIDEO_COLOR_RANGE_0_255,
GST_VIDEO_COLOR_RANGE_16_235
} GstVideoColorRange;
/**
* GstVideoColorMatrix:
* @GST_VIDEO_COLOR_MATRIX_UNKNOWN: unknown matrix
* @GST_VIDEO_COLOR_MATRIX_RGB: identity matrix
* @GST_VIDEO_COLOR_MATRIX_FCC: FCC color matrix
* @GST_VIDEO_COLOR_MATRIX_BT709: ITU-R BT.709 color matrix
* @GST_VIDEO_COLOR_MATRIX_BT601: ITU-R BT.601 color matrix
* @GST_VIDEO_COLOR_MATRIX_SMPTE240M: SMPTE 240M color matrix
*
* The color matrix is used to convert between Y'PbPr and
* non-linear RGB (R'G'B')
*/
typedef enum {
GST_VIDEO_COLOR_MATRIX_UNKNOWN = 0,
GST_VIDEO_COLOR_MATRIX_RGB,
GST_VIDEO_COLOR_MATRIX_FCC,
GST_VIDEO_COLOR_MATRIX_BT709,
GST_VIDEO_COLOR_MATRIX_BT601,
GST_VIDEO_COLOR_MATRIX_SMPTE240M
} GstVideoColorMatrix;
/**
* GstVideoTransferFunction:
* @GST_VIDEO_TRANSFER_UNKNOWN: unknown transfer function
* @GST_VIDEO_TRANSFER_GAMMA10: linear RGB, gamma 1.0 curve
* @GST_VIDEO_TRANSFER_GAMMA18: Gamma 1.8 curve
* @GST_VIDEO_TRANSFER_GAMMA20: Gamma 2.0 curve
* @GST_VIDEO_TRANSFER_GAMMA22: Gamma 2.2 curve
* @GST_VIDEO_TRANSFER_BT709: Gamma 2.2 curve with a linear segment in the lower
* range
* @GST_VIDEO_TRANSFER_SMPTE240M: Gamma 2.2 curve with a linear segment in the
* lower range
* @GST_VIDEO_TRANSFER_SRGB: Gamma 2.4 curve with a linear segment in the lower
* range
* @GST_VIDEO_TRANSFER_GAMMA28: Gamma 2.8 curve
* @GST_VIDEO_TRANSFER_LOG100: Logarithmic transfer characteristic
* 100:1 range
* @GST_VIDEO_TRANSFER_LOG316: Logarithmic transfer characteristic
* 316.22777:1 range
*
* The video transfer function defines the formula for converting between
* non-linear RGB (R'G'B') and linear RGB
*/
typedef enum {
GST_VIDEO_TRANSFER_UNKNOWN = 0,
GST_VIDEO_TRANSFER_GAMMA10,
GST_VIDEO_TRANSFER_GAMMA18,
GST_VIDEO_TRANSFER_GAMMA20,
GST_VIDEO_TRANSFER_GAMMA22,
GST_VIDEO_TRANSFER_BT709,
GST_VIDEO_TRANSFER_SMPTE240M,
GST_VIDEO_TRANSFER_SRGB,
GST_VIDEO_TRANSFER_GAMMA28,
GST_VIDEO_TRANSFER_LOG100,
GST_VIDEO_TRANSFER_LOG316
} GstVideoTransferFunction;
/**
* GstVideoColorPrimaries:
* @GST_VIDEO_COLOR_PRIMARIES_UNKNOWN: unknown color primaries
* @GST_VIDEO_COLOR_PRIMARIES_BT709: BT709 primaries
* @GST_VIDEO_COLOR_PRIMARIES_BT470M: BT470M primaries
* @GST_VIDEO_COLOR_PRIMARIES_BT470BG: BT470BG primaries
* @GST_VIDEO_COLOR_PRIMARIES_SMPTE170M: SMPTE170M primaries
* @GST_VIDEO_COLOR_PRIMARIES_SMPTE240M: SMPTE240M primaries
* @GST_VIDEO_COLOR_PRIMARIES_FILM: Generic film
*
* The color primaries define the how to transform linear RGB values to and from
* the CIE XYZ colorspace.
*/
typedef enum {
GST_VIDEO_COLOR_PRIMARIES_UNKNOWN = 0,
GST_VIDEO_COLOR_PRIMARIES_BT709,
GST_VIDEO_COLOR_PRIMARIES_BT470M,
GST_VIDEO_COLOR_PRIMARIES_BT470BG,
GST_VIDEO_COLOR_PRIMARIES_SMPTE170M,
GST_VIDEO_COLOR_PRIMARIES_SMPTE240M,
GST_VIDEO_COLOR_PRIMARIES_FILM
} GstVideoColorPrimaries;
/**
* GstVideoColorimetry:
* @range: the color range. This is the valid range for the samples.
* It is used to convert the samples to Y'PbPr values.
* @matrix: the color matrix. Used to convert between Y'PbPr and
* non-linear RGB (R'G'B')
* @transfer: the transfer function. used to convert between R'G'B' and RGB
* @primaries: color primaries. used to convert between R'G'B' and CIE XYZ
*
* Structure describing the color info.
*/
typedef struct {
GstVideoColorRange range;
GstVideoColorMatrix matrix;
GstVideoTransferFunction transfer;
GstVideoColorPrimaries primaries;
} GstVideoColorimetry;
/* predefined colorimetry */
#define GST_VIDEO_COLORIMETRY_BT601 "bt601"
#define GST_VIDEO_COLORIMETRY_BT709 "bt709"
#define GST_VIDEO_COLORIMETRY_SMPTE240M "smpte240m"
gboolean gst_video_colorimetry_matches (GstVideoColorimetry *cinfo, const gchar *color);
gboolean gst_video_colorimetry_from_string (GstVideoColorimetry *cinfo, const gchar *color);
gchar * gst_video_colorimetry_to_string (GstVideoColorimetry *cinfo);
G_END_DECLS
#endif /* __GST_VIDEO_COLOR_H__ */
/* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
* Library <2002> Ronald Bultje <rbultje@ronald.bitfreak.net>
* Copyright (C) 2007 David A. Schleef <ds@schleef.org>
*
* 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., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "video-event.h"
#define GST_VIDEO_EVENT_STILL_STATE_NAME "GstEventStillFrame"
/**
* gst_video_event_new_still_frame:
* @in_still: boolean value for the still-frame state of the event.
*
* Creates a new Still Frame event. If @in_still is %TRUE, then the event
* represents the start of a still frame sequence. If it is %FALSE, then
* the event ends a still frame sequence.
*
* To parse an event created by gst_video_event_new_still_frame() use
* gst_video_event_parse_still_frame().
*
* Returns: The new GstEvent
* Since: 0.10.26
*/
GstEvent *
gst_video_event_new_still_frame (gboolean in_still)
{
GstEvent *still_event;
GstStructure *s;
s = gst_structure_new (GST_VIDEO_EVENT_STILL_STATE_NAME,
"still-state", G_TYPE_BOOLEAN, in_still, NULL);
still_event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM, s);
return still_event;
}
/**
* gst_video_event_parse_still_frame:
* @event: A #GstEvent to parse
* @in_still: A boolean to receive the still-frame status from the event, or NULL
*
* Parse a #GstEvent, identify if it is a Still Frame event, and
* return the still-frame state from the event if it is.
* If the event represents the start of a still frame, the in_still
* variable will be set to TRUE, otherwise FALSE. It is OK to pass NULL for the
* in_still variable order to just check whether the event is a valid still-frame
* event.
*
* Create a still frame event using gst_video_event_new_still_frame()
*
* Returns: %TRUE if the event is a valid still-frame event. %FALSE if not
* Since: 0.10.26
*/
gboolean
gst_video_event_parse_still_frame (GstEvent * event, gboolean * in_still)
{
const GstStructure *s;
gboolean ev_still_state;
g_return_val_if_fail (event != NULL, FALSE);
if (GST_EVENT_TYPE (event) != GST_EVENT_CUSTOM_DOWNSTREAM)
return FALSE; /* Not a still frame event */
s = gst_event_get_structure (event);
if (s == NULL
|| !gst_structure_has_name (s, GST_VIDEO_EVENT_STILL_STATE_NAME))
return FALSE; /* Not a still frame event */
if (!gst_structure_get_boolean (s, "still-state", &ev_still_state))
return FALSE; /* Not a still frame event */
if (in_still)
*in_still = ev_still_state;
return TRUE;
}
#define GST_VIDEO_EVENT_FORCE_KEY_UNIT_NAME "GstForceKeyUnit"
/**
* gst_video_event_new_downstream_force_key_unit:
* @timestamp: the timestamp of the buffer that starts a new key unit
* @stream_time: the stream_time of the buffer that starts a new key unit
* @running_time: the running_time of the buffer that starts a new key unit
* @all_headers: %TRUE to produce headers when starting a new key unit
* @count: integer that can be used to number key units
*
* Creates a new downstream force key unit event. A downstream force key unit
* event can be sent down the pipeline to request downstream elements to produce
* a key unit. A downstream force key unit event must also be sent when handling
* an upstream force key unit event to notify downstream that the latter has been
* handled.
*
* To parse an event created by gst_video_event_new_downstream_force_key_unit() use
* gst_video_event_parse_downstream_force_key_unit().
*
* Returns: The new GstEvent
* Since: 0.10.36
*/
GstEvent *
gst_video_event_new_downstream_force_key_unit (GstClockTime timestamp,
GstClockTime stream_time, GstClockTime running_time, gboolean all_headers,
guint count)
{
GstEvent *force_key_unit_event;
GstStructure *s;
s = gst_structure_new (GST_VIDEO_EVENT_FORCE_KEY_UNIT_NAME,
"timestamp", G_TYPE_UINT64, timestamp,
"stream-time", G_TYPE_UINT64, stream_time,
"running-time", G_TYPE_UINT64, running_time,
"all-headers", G_TYPE_BOOLEAN, all_headers,
"count", G_TYPE_UINT, count, NULL);
force_key_unit_event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM, s);
return force_key_unit_event;
}
/**
* gst_video_event_new_upstream_force_key_unit:
* @running_time: the running_time at which a new key unit should be produced
* @all_headers: %TRUE to produce headers when starting a new key unit
* @count: integer that can be used to number key units
*
* Creates a new upstream force key unit event. An upstream force key unit event
* can be sent to request upstream elements to produce a key unit.
*
* @running_time can be set to request a new key unit at a specific
* running_time. If set to GST_CLOCK_TIME_NONE, upstream elements will produce a
* new key unit as soon as possible.
*
* To parse an event created by gst_video_event_new_downstream_force_key_unit() use
* gst_video_event_parse_downstream_force_key_unit().
*
* Returns: The new GstEvent
* Since: 0.10.36
*/
GstEvent *
gst_video_event_new_upstream_force_key_unit (GstClockTime running_time,
gboolean all_headers, guint count)
{
GstEvent *force_key_unit_event;
GstStructure *s;
s = gst_structure_new (GST_VIDEO_EVENT_FORCE_KEY_UNIT_NAME,
"running-time", GST_TYPE_CLOCK_TIME, running_time,
"all-headers", G_TYPE_BOOLEAN, all_headers,
"count", G_TYPE_UINT, count, NULL);
force_key_unit_event = gst_event_new_custom (GST_EVENT_CUSTOM_UPSTREAM, s);
return force_key_unit_event;
}
/**
* gst_video_event_is_force_key_unit:
* @event: A #GstEvent to check
*
* Checks if an event is a force key unit event. Returns true for both upstream
* and downstream force key unit events.
*
* Returns: %TRUE if the event is a valid force key unit event
* Since: 0.10.36
*/
gboolean
gst_video_event_is_force_key_unit (GstEvent * event)
{
const GstStructure *s;
g_return_val_if_fail (event != NULL, FALSE);
if (GST_EVENT_TYPE (event) != GST_EVENT_CUSTOM_DOWNSTREAM &&
GST_EVENT_TYPE (event) != GST_EVENT_CUSTOM_UPSTREAM)
return FALSE; /* Not a force key unit event */
s = gst_event_get_structure (event);
if (s == NULL
|| !gst_structure_has_name (s, GST_VIDEO_EVENT_FORCE_KEY_UNIT_NAME))
return FALSE;
return TRUE;
}
/**
* gst_video_event_parse_downstream_force_key_unit:
* @event: A #GstEvent to parse
* @timestamp: (out): A pointer to the timestamp in the event
* @stream_time: (out): A pointer to the stream-time in the event
* @running_time: (out): A pointer to the running-time in the event
* @all_headers: (out): A pointer to the all_headers flag in the event
* @count: (out): A pointer to the count field of the event
*
* Get timestamp, stream-time, running-time, all-headers and count in the force
* key unit event. See gst_video_event_new_downstream_force_key_unit() for a
* full description of the downstream force key unit event.
*
* Returns: %TRUE if the event is a valid downstream force key unit event.
* Since: 0.10.36
*/
gboolean
gst_video_event_parse_downstream_force_key_unit (GstEvent * event,
GstClockTime * timestamp, GstClockTime * stream_time,
GstClockTime * running_time, gboolean * all_headers, guint * count)
{
const GstStructure *s;
GstClockTime ev_timestamp, ev_stream_time, ev_running_time;
gboolean ev_all_headers;
guint ev_count;
g_return_val_if_fail (event != NULL, FALSE);
if (GST_EVENT_TYPE (event) != GST_EVENT_CUSTOM_DOWNSTREAM)
return FALSE; /* Not a force key unit event */
s = gst_event_get_structure (event);
if (s == NULL
|| !gst_structure_has_name (s, GST_VIDEO_EVENT_FORCE_KEY_UNIT_NAME))
return FALSE;
if (!gst_structure_get_clock_time (s, "timestamp", &ev_timestamp))
ev_timestamp = GST_CLOCK_TIME_NONE;
if (!gst_structure_get_clock_time (s, "stream-time", &ev_stream_time))
ev_stream_time = GST_CLOCK_TIME_NONE;
if (!gst_structure_get_clock_time (s, "running-time", &ev_running_time))
ev_running_time = GST_CLOCK_TIME_NONE;
if (!gst_structure_get_boolean (s, "all-headers", &ev_all_headers))
ev_all_headers = FALSE;
if (!gst_structure_get_uint (s, "count", &ev_count))
ev_count = 0;
if (timestamp)
*timestamp = ev_timestamp;
if (stream_time)
*stream_time = ev_stream_time;
if (running_time)
*running_time = ev_running_time;
if (all_headers)
*all_headers = ev_all_headers;
if (count)
*count = ev_count;
return TRUE;
}