mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 12:11:13 +00:00
Added a test application. Added some EXIF tags. Fixed a muxer bug.
Original commit message from CVS: Added a test application. Added some EXIF tags. Fixed a muxer bug.
This commit is contained in:
parent
9adb4f7870
commit
334b512629
11 changed files with 1422 additions and 108 deletions
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
|||
2007-12-13 Edgard Lima <edgard.lima@indt.org.br>
|
||||
|
||||
* configure.ac:
|
||||
* ext/metadata/Makefile.am:
|
||||
* ext/metadata/gstmetadatamux.c:
|
||||
* ext/metadata/gstmetadataparse.c:
|
||||
* ext/metadata/metadataexif.c:
|
||||
* ext/metadata/metadatatags.c:
|
||||
* ext/metadata/test/Makefile:
|
||||
* ext/metadata/test/MetadataEditorMain.glade:
|
||||
* ext/metadata/test/metadata_editor.c:
|
||||
Added a test application. Added some EXIF tags. Fixed a muxer bug.
|
||||
|
||||
2007-12-13 Sebastian Dröge <slomo@circular-chaos.org>
|
||||
|
||||
* gst/videoparse/gstvideoparse.c: (gst_video_parse_init),
|
||||
|
|
2
common
2
common
|
@ -1 +1 @@
|
|||
Subproject commit fb7ab03319930496e922173d54f6dfccfff6f357
|
||||
Subproject commit ea5f2cfab1a164a5d285fe745343cbe0a476a904
|
|
@ -515,7 +515,7 @@ AG_GST_CHECK_FEATURE(METADATA, [METADATA muxer and demuxer], metadata, [
|
|||
], HAVE_XMP="no")
|
||||
if test x$HAVE_EXIF = xyes; then
|
||||
METADATA_CFLAGS="-DHAVE_EXIF $EXIF_CFLAGS $METADATA_CFLAGS"
|
||||
METADATA_LIBS="$EXIF_LIBS $METADATA_LIBS"
|
||||
METADATA_LIBS="$EXIF_LIBS $METADATA_LIBS -lm"
|
||||
HAVE_METADATA="yes"
|
||||
fi
|
||||
if test x$HAVE_IPTC = xyes; then
|
||||
|
|
|
@ -30,6 +30,5 @@ noinst_HEADERS = gstmetadataparse.h \
|
|||
metadataxmp.h \
|
||||
metadataparseutil.h \
|
||||
metadatatypes.h \
|
||||
gstmetadatamux.h \
|
||||
metadatatags.h
|
||||
gstmetadatamux.h
|
||||
|
||||
|
|
|
@ -776,7 +776,6 @@ gst_metadata_update_segment (GstMetadataMux * filter, guint8 ** buf,
|
|||
if (*size == 0)
|
||||
goto done;
|
||||
|
||||
/* calculate the new position off injected chunks */
|
||||
for (i = 0; i < inject_len; ++i) {
|
||||
if (inject[i].type == type) {
|
||||
inject[i].size = *size;
|
||||
|
@ -1351,6 +1350,7 @@ gst_metadata_mux_strip_push_buffer (GstMetadataMux * filter,
|
|||
MetadataChunk *inject = filter->mux_data.inject_chunks.chunk;
|
||||
const gsize strip_len = filter->mux_data.strip_chunks.len;
|
||||
const gsize inject_len = filter->mux_data.inject_chunks.len;
|
||||
gboolean buffer_reallocated = FALSE;
|
||||
|
||||
guint32 size_buf_in = GST_BUFFER_SIZE (*buf);
|
||||
|
||||
|
@ -1422,24 +1422,27 @@ gst_metadata_mux_strip_push_buffer (GstMetadataMux * filter,
|
|||
|
||||
guint8 *data;
|
||||
|
||||
if (injected_bytes + prepend_size > striped_bytes) {
|
||||
GstBuffer *new_buf =
|
||||
gst_buffer_new_and_alloc (GST_BUFFER_SIZE (*buf) + injected_bytes +
|
||||
prepend_size - striped_bytes);
|
||||
if (!buffer_reallocated) {
|
||||
buffer_reallocated = TRUE;
|
||||
if (injected_bytes + prepend_size > striped_bytes) {
|
||||
GstBuffer *new_buf =
|
||||
gst_buffer_new_and_alloc (GST_BUFFER_SIZE (*buf) + injected_bytes +
|
||||
prepend_size - striped_bytes);
|
||||
|
||||
memcpy (GST_BUFFER_DATA (new_buf), GST_BUFFER_DATA (*buf),
|
||||
GST_BUFFER_SIZE (*buf));
|
||||
memcpy (GST_BUFFER_DATA (new_buf), GST_BUFFER_DATA (*buf),
|
||||
GST_BUFFER_SIZE (*buf));
|
||||
|
||||
gst_buffer_unref (*buf);
|
||||
*buf = new_buf;
|
||||
gst_buffer_unref (*buf);
|
||||
*buf = new_buf;
|
||||
|
||||
} else if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_READONLY)) {
|
||||
GstBuffer *new_buf = gst_buffer_copy (*buf);
|
||||
} else if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_READONLY)) {
|
||||
GstBuffer *new_buf = gst_buffer_copy (*buf);
|
||||
|
||||
gst_buffer_unref (*buf);
|
||||
*buf = new_buf;
|
||||
GST_BUFFER_FLAG_UNSET (*buf, GST_BUFFER_FLAG_READONLY);
|
||||
GST_BUFFER_SIZE (*buf) += injected_bytes + prepend_size - striped_bytes;
|
||||
gst_buffer_unref (*buf);
|
||||
*buf = new_buf;
|
||||
GST_BUFFER_FLAG_UNSET (*buf, GST_BUFFER_FLAG_READONLY);
|
||||
GST_BUFFER_SIZE (*buf) += injected_bytes + prepend_size - striped_bytes;
|
||||
}
|
||||
}
|
||||
|
||||
data = GST_BUFFER_DATA (*buf);
|
||||
|
@ -1469,24 +1472,27 @@ inject:
|
|||
guint8 *data;
|
||||
guint32 striped_so_far;
|
||||
|
||||
if (injected_bytes + prepend_size > striped_bytes) {
|
||||
GstBuffer *new_buf =
|
||||
gst_buffer_new_and_alloc (GST_BUFFER_SIZE (*buf) + injected_bytes +
|
||||
prepend_size - striped_bytes);
|
||||
if (!buffer_reallocated) {
|
||||
buffer_reallocated = TRUE;
|
||||
if (injected_bytes + prepend_size > striped_bytes) {
|
||||
GstBuffer *new_buf =
|
||||
gst_buffer_new_and_alloc (GST_BUFFER_SIZE (*buf) + injected_bytes +
|
||||
prepend_size - striped_bytes);
|
||||
|
||||
memcpy (GST_BUFFER_DATA (new_buf), GST_BUFFER_DATA (*buf),
|
||||
GST_BUFFER_SIZE (*buf));
|
||||
memcpy (GST_BUFFER_DATA (new_buf), GST_BUFFER_DATA (*buf),
|
||||
GST_BUFFER_SIZE (*buf));
|
||||
|
||||
gst_buffer_unref (*buf);
|
||||
*buf = new_buf;
|
||||
gst_buffer_unref (*buf);
|
||||
*buf = new_buf;
|
||||
|
||||
} else if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_READONLY)) {
|
||||
GstBuffer *new_buf = gst_buffer_copy (*buf);
|
||||
} else if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_READONLY)) {
|
||||
GstBuffer *new_buf = gst_buffer_copy (*buf);
|
||||
|
||||
gst_buffer_unref (*buf);
|
||||
*buf = new_buf;
|
||||
GST_BUFFER_FLAG_UNSET (*buf, GST_BUFFER_FLAG_READONLY);
|
||||
GST_BUFFER_SIZE (*buf) += injected_bytes + prepend_size - striped_bytes;
|
||||
gst_buffer_unref (*buf);
|
||||
*buf = new_buf;
|
||||
GST_BUFFER_FLAG_UNSET (*buf, GST_BUFFER_FLAG_READONLY);
|
||||
GST_BUFFER_SIZE (*buf) += injected_bytes + prepend_size - striped_bytes;
|
||||
}
|
||||
}
|
||||
|
||||
data = GST_BUFFER_DATA (*buf);
|
||||
|
@ -1515,7 +1521,7 @@ inject:
|
|||
size_buf_in - buf_off);
|
||||
memcpy (data + buf_off, inject[i].data, inject[i].size);
|
||||
injected_bytes += inject[i].size;
|
||||
size_buf_in += injected_bytes;
|
||||
size_buf_in += inject[i].size;
|
||||
} else {
|
||||
/* segment is after size (segments are sorted) */
|
||||
break;
|
||||
|
|
|
@ -1312,6 +1312,7 @@ gst_metadata_parse_strip_push_buffer (GstMetadataParse * filter,
|
|||
MetadataChunk *inject = filter->parse_data.inject_chunks.chunk;
|
||||
const gsize strip_len = filter->parse_data.strip_chunks.len;
|
||||
const gsize inject_len = filter->parse_data.inject_chunks.len;
|
||||
gboolean buffer_reallocated = FALSE;
|
||||
|
||||
guint32 size_buf_in = GST_BUFFER_SIZE (*buf);
|
||||
|
||||
|
@ -1383,24 +1384,27 @@ gst_metadata_parse_strip_push_buffer (GstMetadataParse * filter,
|
|||
|
||||
guint8 *data;
|
||||
|
||||
if (injected_bytes + prepend_size > striped_bytes) {
|
||||
GstBuffer *new_buf =
|
||||
gst_buffer_new_and_alloc (GST_BUFFER_SIZE (*buf) + injected_bytes +
|
||||
prepend_size - striped_bytes);
|
||||
if (!buffer_reallocated) {
|
||||
buffer_reallocated = TRUE;
|
||||
if (injected_bytes + prepend_size > striped_bytes) {
|
||||
GstBuffer *new_buf =
|
||||
gst_buffer_new_and_alloc (GST_BUFFER_SIZE (*buf) + injected_bytes +
|
||||
prepend_size - striped_bytes);
|
||||
|
||||
memcpy (GST_BUFFER_DATA (new_buf), GST_BUFFER_DATA (*buf),
|
||||
GST_BUFFER_SIZE (*buf));
|
||||
memcpy (GST_BUFFER_DATA (new_buf), GST_BUFFER_DATA (*buf),
|
||||
GST_BUFFER_SIZE (*buf));
|
||||
|
||||
gst_buffer_unref (*buf);
|
||||
*buf = new_buf;
|
||||
gst_buffer_unref (*buf);
|
||||
*buf = new_buf;
|
||||
|
||||
} else if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_READONLY)) {
|
||||
GstBuffer *new_buf = gst_buffer_copy (*buf);
|
||||
} else if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_READONLY)) {
|
||||
GstBuffer *new_buf = gst_buffer_copy (*buf);
|
||||
|
||||
gst_buffer_unref (*buf);
|
||||
*buf = new_buf;
|
||||
GST_BUFFER_FLAG_UNSET (*buf, GST_BUFFER_FLAG_READONLY);
|
||||
GST_BUFFER_SIZE (*buf) += injected_bytes + prepend_size - striped_bytes;
|
||||
gst_buffer_unref (*buf);
|
||||
*buf = new_buf;
|
||||
GST_BUFFER_FLAG_UNSET (*buf, GST_BUFFER_FLAG_READONLY);
|
||||
GST_BUFFER_SIZE (*buf) += injected_bytes + prepend_size - striped_bytes;
|
||||
}
|
||||
}
|
||||
|
||||
data = GST_BUFFER_DATA (*buf);
|
||||
|
@ -1430,24 +1434,27 @@ inject:
|
|||
guint8 *data;
|
||||
guint32 striped_so_far;
|
||||
|
||||
if (injected_bytes + prepend_size > striped_bytes) {
|
||||
GstBuffer *new_buf =
|
||||
gst_buffer_new_and_alloc (GST_BUFFER_SIZE (*buf) + injected_bytes +
|
||||
prepend_size - striped_bytes);
|
||||
if (!buffer_reallocated) {
|
||||
buffer_reallocated = TRUE;
|
||||
if (injected_bytes + prepend_size > striped_bytes) {
|
||||
GstBuffer *new_buf =
|
||||
gst_buffer_new_and_alloc (GST_BUFFER_SIZE (*buf) + injected_bytes +
|
||||
prepend_size - striped_bytes);
|
||||
|
||||
memcpy (GST_BUFFER_DATA (new_buf), GST_BUFFER_DATA (*buf),
|
||||
GST_BUFFER_SIZE (*buf));
|
||||
memcpy (GST_BUFFER_DATA (new_buf), GST_BUFFER_DATA (*buf),
|
||||
GST_BUFFER_SIZE (*buf));
|
||||
|
||||
gst_buffer_unref (*buf);
|
||||
*buf = new_buf;
|
||||
gst_buffer_unref (*buf);
|
||||
*buf = new_buf;
|
||||
|
||||
} else if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_READONLY)) {
|
||||
GstBuffer *new_buf = gst_buffer_copy (*buf);
|
||||
} else if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_READONLY)) {
|
||||
GstBuffer *new_buf = gst_buffer_copy (*buf);
|
||||
|
||||
gst_buffer_unref (*buf);
|
||||
*buf = new_buf;
|
||||
GST_BUFFER_FLAG_UNSET (*buf, GST_BUFFER_FLAG_READONLY);
|
||||
GST_BUFFER_SIZE (*buf) += injected_bytes + prepend_size - striped_bytes;
|
||||
gst_buffer_unref (*buf);
|
||||
*buf = new_buf;
|
||||
GST_BUFFER_FLAG_UNSET (*buf, GST_BUFFER_FLAG_READONLY);
|
||||
GST_BUFFER_SIZE (*buf) += injected_bytes + prepend_size - striped_bytes;
|
||||
}
|
||||
}
|
||||
|
||||
data = GST_BUFFER_DATA (*buf);
|
||||
|
@ -1476,7 +1483,7 @@ inject:
|
|||
size_buf_in - buf_off);
|
||||
memcpy (data + buf_off, inject[i].data, inject[i].size);
|
||||
injected_bytes += inject[i].size;
|
||||
size_buf_in += injected_bytes;
|
||||
size_buf_in += inject[i].size;
|
||||
} else {
|
||||
/* segment is after size (segments are sorted) */
|
||||
break;
|
||||
|
|
|
@ -75,6 +75,8 @@ metadatamux_exif_create_chunk_from_tag_list (guint8 ** buf, guint32 * size,
|
|||
|
||||
#include <libexif/exif-data.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
typedef struct _tag_MEUserData
|
||||
{
|
||||
|
@ -95,37 +97,55 @@ exif_data_foreach_content_func (ExifContent * content, void *callback_data);
|
|||
|
||||
static void exif_content_foreach_entry_func (ExifEntry * entry, void *);
|
||||
|
||||
const gchar *
|
||||
/* *INDENT-OFF* */
|
||||
static MapIntStr mappedTags[] = {
|
||||
{EXIF_TAG_MAKE, /*EXIF_FORMAT_ASCII,*/ GST_TAG_DEVICE_MAKE, G_TYPE_STRING},
|
||||
{EXIF_TAG_MODEL, /*EXIF_FORMAT_ASCII,*/ GST_TAG_DEVICE_MODEL, G_TYPE_STRING},
|
||||
{EXIF_TAG_SOFTWARE, /*EXIF_FORMAT_ASCII,*/ GST_TAG_CREATOR_TOOL, G_TYPE_STRING},
|
||||
{EXIF_TAG_X_RESOLUTION, /*EXIF_FORMAT_RATIONAL,*/ GST_TAG_IMAGE_XRESOLUTION, G_TYPE_FLOAT}, /* inches */
|
||||
{EXIF_TAG_Y_RESOLUTION, /*EXIF_FORMAT_RATIONAL,*/ GST_TAG_IMAGE_YRESOLUTION, G_TYPE_FLOAT}, /* inches */
|
||||
{EXIF_TAG_EXPOSURE_TIME, /*EXIF_FORMAT_RATIONAL,*/ GST_TAG_CAPTURE_EXPOSURE_TIME, G_TYPE_FLOAT},
|
||||
{EXIF_TAG_FNUMBER, /*EXIF_FORMAT_RATIONAL,*/ GST_TAG_CAPTURE_FNUMBER, G_TYPE_FLOAT},
|
||||
{EXIF_TAG_EXPOSURE_PROGRAM, /*EXIF_FORMAT_SHORT,*/ GST_TAG_CAPTURE_EXPOSURE_PROGRAM, G_TYPE_UINT},
|
||||
{EXIF_TAG_BRIGHTNESS_VALUE, /*EXIF_FORMAT_SRATIONAL,*/ GST_TAG_CAPTURE_BRIGHTNESS, G_TYPE_FLOAT},
|
||||
{EXIF_TAG_WHITE_BALANCE, /*EXIF_FORMAT_SHORT,*/ GST_TAG_CAPTURE_WHITE_BALANCE, G_TYPE_UINT},
|
||||
{EXIF_TAG_DIGITAL_ZOOM_RATIO, /*EXIF_FORMAT_RATIONAL,*/ GST_TAG_CAPTURE_DIGITAL_ZOOM, G_TYPE_FLOAT},
|
||||
{EXIF_TAG_GAIN_CONTROL, /*EXIF_FORMAT_SHORT,*/ GST_TAG_CAPTURE_GAIN, G_TYPE_UINT},
|
||||
{EXIF_TAG_CONTRAST, /*EXIF_FORMAT_SHORT,*/ GST_TAG_CAPTURE_CONTRAST, G_TYPE_INT},
|
||||
{EXIF_TAG_SATURATION, /*EXIF_FORMAT_SHORT,*/ GST_TAG_CAPTURE_SATURATION, G_TYPE_INT},
|
||||
{0, NULL, G_TYPE_NONE}
|
||||
};
|
||||
/* *INDENT-ON* */
|
||||
|
||||
static const gchar *
|
||||
metadataparse_exif_get_tag_from_exif (ExifTag exif, GType * type)
|
||||
{
|
||||
/* FIXEME: sorted with binary search */
|
||||
static MapIntStr array[] = {
|
||||
{EXIF_TAG_MAKE, GST_TAG_DEVICE_MAKE, G_TYPE_STRING},
|
||||
{EXIF_TAG_MODEL, GST_TAG_DEVICE_MODEL, G_TYPE_STRING},
|
||||
{EXIF_TAG_SOFTWARE, GST_TAG_CREATOR_TOOL, G_TYPE_STRING},
|
||||
{EXIF_TAG_X_RESOLUTION, GST_TAG_IMAGE_XRESOLUTION, G_TYPE_FLOAT}, /* asure inches */
|
||||
{EXIF_TAG_Y_RESOLUTION, GST_TAG_IMAGE_YRESOLUTION, G_TYPE_FLOAT}, /* asure inches */
|
||||
{EXIF_TAG_EXPOSURE_TIME, GST_TAG_CAPTURE_EXPOSURE_TIME, G_TYPE_FLOAT},
|
||||
{EXIF_TAG_FNUMBER, GST_TAG_CAPTURE_FNUMBER, G_TYPE_FLOAT},
|
||||
{EXIF_TAG_EXPOSURE_PROGRAM, GST_TAG_CAPTURE_EXPOSURE_PROGRAM, G_TYPE_UINT},
|
||||
{EXIF_TAG_BRIGHTNESS_VALUE, GST_TAG_CAPTURE_BRIGHTNESS, G_TYPE_FLOAT},
|
||||
{EXIF_TAG_WHITE_BALANCE, GST_TAG_CAPTURE_WHITE_BALANCE, G_TYPE_UINT},
|
||||
{EXIF_TAG_DIGITAL_ZOOM_RATIO, GST_TAG_CAPTURE_DIGITAL_ZOOM, G_TYPE_FLOAT},
|
||||
{EXIF_TAG_GAIN_CONTROL, GST_TAG_CAPTURE_GAIN, G_TYPE_UINT},
|
||||
{EXIF_TAG_CONTRAST, GST_TAG_CAPTURE_CONTRAST, G_TYPE_UINT},
|
||||
{EXIF_TAG_SATURATION, GST_TAG_CAPTURE_SATURATION, G_TYPE_UINT},
|
||||
{0, NULL, G_TYPE_NONE, G_TYPE_UINT}
|
||||
};
|
||||
int i = 0;
|
||||
|
||||
while (array[i].exif) {
|
||||
if (exif == array[i].exif)
|
||||
while (mappedTags[i].exif) {
|
||||
if (exif == mappedTags[i].exif)
|
||||
break;
|
||||
++i;
|
||||
}
|
||||
|
||||
*type = array[i].type;
|
||||
return array[i].str;
|
||||
*type = mappedTags[i].type;
|
||||
return mappedTags[i].str;
|
||||
|
||||
}
|
||||
|
||||
static ExifTag
|
||||
metadataparse_exif_get_exif_from_tag (const gchar * tag, GType * type)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
while (mappedTags[i].exif) {
|
||||
if (0 == strcmp (mappedTags[i].str, tag))
|
||||
break;
|
||||
++i;
|
||||
}
|
||||
|
||||
*type = mappedTags[i].type;
|
||||
return mappedTags[i].exif;
|
||||
|
||||
}
|
||||
|
||||
|
@ -180,6 +200,31 @@ exif_data_foreach_content_func (ExifContent * content, void *user_data)
|
|||
user_data);
|
||||
}
|
||||
|
||||
#if 0
|
||||
static gboolean
|
||||
exif_fast_mdc (glong n, glong d, gulong * m)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
|
||||
static const int a[] =
|
||||
{ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 39, 41, 43, 47, 49, 53, 0 };
|
||||
int i = 0;
|
||||
|
||||
*m = 1;
|
||||
|
||||
while (a[i] <= n && a[i] <= d) {
|
||||
while ((n % a[i] == 0) && (d % a[i]) == 0) {
|
||||
*m *= a[i];
|
||||
ret = TRUE;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
exif_content_foreach_entry_func (ExifEntry * entry, void *user_data)
|
||||
{
|
||||
|
@ -223,65 +268,83 @@ exif_content_foreach_entry_func (ExifEntry * entry, void *user_data)
|
|||
case G_TYPE_FLOAT:
|
||||
{
|
||||
gfloat f_value;
|
||||
ExifRational v_rat;
|
||||
|
||||
switch (entry->format) {
|
||||
case EXIF_FORMAT_RATIONAL:
|
||||
v_rat = exif_get_rational (entry->data, byte_order);
|
||||
if (v_rat.numerator == 0)
|
||||
case EXIF_FORMAT_SRATIONAL:
|
||||
{
|
||||
ExifSRational v_srat;
|
||||
|
||||
v_srat = exif_get_srational (entry->data, byte_order);
|
||||
if (v_srat.denominator == 0)
|
||||
f_value = 0.0f;
|
||||
else
|
||||
f_value = (float) v_rat.numerator / (float) v_rat.denominator;
|
||||
if (v_rat.numerator == 0xFFFFFFFF) {
|
||||
if (entry->tag == GST_TAG_CAPTURE_BRIGHTNESS) {
|
||||
f_value = (float) v_srat.numerator / (float) v_srat.denominator;
|
||||
if (v_srat.numerator == 0xFFFFFFFF) {
|
||||
if (entry->tag == EXIF_TAG_BRIGHTNESS_VALUE) {
|
||||
f_value = 100.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case EXIF_FORMAT_RATIONAL:
|
||||
{
|
||||
ExifRational v_rat;
|
||||
|
||||
v_rat = exif_get_rational (entry->data, byte_order);
|
||||
if (v_rat.denominator == 0)
|
||||
f_value = 0.0f;
|
||||
else
|
||||
f_value = (float) v_rat.numerator / (float) v_rat.denominator;
|
||||
if (meudata->resolution_unit == 3) {
|
||||
/* converts from cm to inches */
|
||||
if (entry->tag == EXIF_TAG_X_RESOLUTION
|
||||
|| entry->tag == EXIF_TAG_Y_RESOLUTION) {
|
||||
f_value *= 0.4f;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
GST_ERROR ("Unexpected Tag Type");
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
if (meudata->resolution_unit == 3) {
|
||||
/* converts from cm to inches */
|
||||
if (entry->tag == EXIF_TAG_X_RESOLUTION
|
||||
|| entry->tag == EXIF_TAG_Y_RESOLUTION) {
|
||||
f_value *= 0.4f;
|
||||
}
|
||||
}
|
||||
gst_tag_list_add (meudata->taglist, meudata->mode, tag, f_value, NULL);
|
||||
}
|
||||
break;
|
||||
case G_TYPE_INT:
|
||||
/* fall through */
|
||||
case G_TYPE_UINT:
|
||||
{
|
||||
ExifShort v_short;
|
||||
gint value;
|
||||
|
||||
switch (entry->format) {
|
||||
case EXIF_FORMAT_SHORT:
|
||||
v_short = exif_get_short (entry->data, byte_order);
|
||||
value = exif_get_short (entry->data, byte_order);
|
||||
break;
|
||||
default:
|
||||
GST_ERROR ("Unexpected Tag Type");
|
||||
GST_ERROR ("Unexpected Exif Tag Type (%s - %s)",
|
||||
tag, exif_format_get_name (entry->format));
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
if (entry->tag == EXIF_TAG_CONTRAST ||
|
||||
entry->tag == EXIF_TAG_SATURATION) {
|
||||
switch (v_short) {
|
||||
switch (value) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
v_short = -67;
|
||||
value = -67; /* -100-34 /2 */
|
||||
break;
|
||||
case 2:
|
||||
v_short = 66;
|
||||
value = 67; /* 100+34 /2 */
|
||||
break;
|
||||
default:
|
||||
GST_ERROR ("Unexpected value");
|
||||
break;
|
||||
}
|
||||
}
|
||||
gst_tag_list_add (meudata->taglist, meudata->mode, tag, v_short, NULL);
|
||||
gst_tag_list_add (meudata->taglist, meudata->mode, tag, value, NULL);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -313,6 +376,188 @@ done:
|
|||
*
|
||||
*/
|
||||
|
||||
static ExifRational
|
||||
float_to_rational (gfloat f)
|
||||
{
|
||||
ExifRational r;
|
||||
int i = 6; /* precision */
|
||||
|
||||
r.denominator = 1;
|
||||
|
||||
while (i--) {
|
||||
if (f == floorf (f)) {
|
||||
break;
|
||||
}
|
||||
f *= 10.0f;
|
||||
r.denominator *= 10;
|
||||
}
|
||||
|
||||
r.numerator = f;
|
||||
|
||||
if (!(r.numerator & 0x1 || r.denominator & 0x1)) {
|
||||
/* divide both by 2 */
|
||||
r.numerator >>= 1;
|
||||
r.denominator >>= 1;
|
||||
}
|
||||
if (r.numerator % 5 == 0 && r.denominator % 5 == 0) {
|
||||
r.numerator /= 5;
|
||||
r.denominator /= 5;
|
||||
}
|
||||
|
||||
return r;
|
||||
|
||||
}
|
||||
|
||||
static ExifSRational
|
||||
float_to_srational (gfloat f)
|
||||
{
|
||||
ExifSRational sr;
|
||||
int i = 6; /* precision */
|
||||
|
||||
sr.denominator = 1;
|
||||
|
||||
while (i--) {
|
||||
if (f == floorf (f)) {
|
||||
break;
|
||||
}
|
||||
f *= 10.0f;
|
||||
sr.denominator *= 10;
|
||||
}
|
||||
|
||||
sr.numerator = f;
|
||||
|
||||
if (!(sr.numerator & 0x1 || sr.denominator & 0x1)) {
|
||||
/* divide both by 2 */
|
||||
sr.numerator >>= 1;
|
||||
sr.denominator >>= 1;
|
||||
}
|
||||
if (sr.numerator % 5 == 0 && sr.denominator % 5 == 0) {
|
||||
sr.numerator /= 5;
|
||||
sr.denominator /= 5;
|
||||
}
|
||||
|
||||
return sr;
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
metadataexif_for_each_tag_in_list (const GstTagList * list, const gchar * tag,
|
||||
gpointer user_data)
|
||||
{
|
||||
ExifData *ed = (ExifData *) user_data;
|
||||
ExifTag exif_tag;
|
||||
GType type;
|
||||
ExifEntry *entry = NULL;
|
||||
const ExifByteOrder byte_order = exif_data_get_byte_order (ed);
|
||||
|
||||
exif_tag = metadataparse_exif_get_exif_from_tag (tag, &type);
|
||||
|
||||
if (!exif_tag)
|
||||
goto done;
|
||||
|
||||
entry = exif_data_get_entry (ed, exif_tag);
|
||||
|
||||
if (entry)
|
||||
exif_entry_ref (entry);
|
||||
else {
|
||||
entry = exif_entry_new ();
|
||||
exif_content_add_entry (ed->ifd[EXIF_IFD_0], entry);
|
||||
exif_entry_initialize (entry, exif_tag);
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case G_TYPE_STRING:
|
||||
{
|
||||
gchar *value = NULL;
|
||||
|
||||
if (gst_tag_list_get_string (list, tag, &value)) {
|
||||
entry->components = strlen (value) + 1;
|
||||
entry->size = exif_format_get_size (entry->format) * entry->components;
|
||||
entry->data = value;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case G_TYPE_FLOAT:
|
||||
{
|
||||
gfloat value;
|
||||
|
||||
gst_tag_list_get_float (list, tag, &value);
|
||||
|
||||
switch (entry->format) {
|
||||
case EXIF_FORMAT_SRATIONAL:
|
||||
{
|
||||
ExifSRational sr;
|
||||
|
||||
sr = float_to_srational (value);
|
||||
if (entry->tag == EXIF_TAG_BRIGHTNESS_VALUE) {
|
||||
if (value == 100.0f) {
|
||||
sr.numerator = 0xFFFFFFFF;
|
||||
sr.denominator = 1;
|
||||
}
|
||||
}
|
||||
|
||||
exif_set_srational (entry->data, byte_order, sr);
|
||||
}
|
||||
break;
|
||||
case EXIF_FORMAT_RATIONAL:
|
||||
{
|
||||
ExifRational r;
|
||||
|
||||
r = float_to_rational (value);
|
||||
exif_set_rational (entry->data, byte_order, r);
|
||||
if (entry->tag == EXIF_TAG_X_RESOLUTION ||
|
||||
entry->tag == EXIF_TAG_Y_RESOLUTION) {
|
||||
ExifEntry *unit_entry = NULL;
|
||||
|
||||
if ((unit_entry =
|
||||
exif_data_get_entry (ed, EXIF_TAG_RESOLUTION_UNIT))) {
|
||||
ExifShort vsh = exif_get_short (unit_entry->data, byte_order);
|
||||
|
||||
if (vsh != 2) /* inches */
|
||||
exif_set_short (unit_entry->data, byte_order, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case G_TYPE_UINT:
|
||||
case G_TYPE_INT:
|
||||
{
|
||||
gint value;
|
||||
ExifShort v_short;
|
||||
|
||||
if (G_TYPE_UINT == type) {
|
||||
gst_tag_list_get_uint (list, tag, &value);
|
||||
} else {
|
||||
gst_tag_list_get_int (list, tag, &value);
|
||||
}
|
||||
if (entry->tag == EXIF_TAG_CONTRAST || entry->tag == EXIF_TAG_SATURATION) {
|
||||
if (value < -33)
|
||||
value = 1; /* low */
|
||||
else if (value < 34)
|
||||
value = 0; /* normal */
|
||||
else
|
||||
value = 2; /* high */
|
||||
}
|
||||
v_short = value;
|
||||
exif_set_short (entry->data, byte_order, v_short);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
if (entry)
|
||||
exif_entry_unref (entry);
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
metadatamux_exif_create_chunk_from_tag_list (guint8 ** buf, guint32 * size,
|
||||
const GstTagList * taglist)
|
||||
|
@ -344,7 +589,7 @@ metadatamux_exif_create_chunk_from_tag_list (guint8 ** buf, guint32 * size,
|
|||
exif_data_fix (ed);
|
||||
}
|
||||
|
||||
/* FIXME: consider individual tags */
|
||||
gst_tag_list_foreach (taglist, metadataexif_for_each_tag_in_list, ed);
|
||||
|
||||
exif_data_save_data (ed, buf, size);
|
||||
|
||||
|
|
|
@ -172,12 +172,18 @@ metadata_tags_register (void)
|
|||
GST_TAG_CAPTURE_GAIN, "", NULL);
|
||||
/**
|
||||
from -100 to 100
|
||||
[-100, -34] - soft
|
||||
[-33, 33] - normal
|
||||
[34, 100] - hard
|
||||
*** exif is just 0, 1, 2 (normal, soft and hard)
|
||||
*/
|
||||
gst_tag_register (GST_TAG_CAPTURE_CONTRAST, GST_TAG_FLAG_META, G_TYPE_INT,
|
||||
GST_TAG_CAPTURE_CONTRAST, "", NULL);
|
||||
/**
|
||||
from -100 to 100
|
||||
[-100, -34] - low
|
||||
[-33, 33] - normal
|
||||
[34, 100] - high
|
||||
*** exif is just 0, 1, 2 (normal, low and high)
|
||||
*/
|
||||
gst_tag_register (GST_TAG_CAPTURE_SATURATION, GST_TAG_FLAG_META, G_TYPE_INT,
|
||||
|
|
16
ext/metadata/test/Makefile
Normal file
16
ext/metadata/test/Makefile
Normal file
|
@ -0,0 +1,16 @@
|
|||
|
||||
CC=gcc
|
||||
CFLAGS=-c -Wall -g3 -O0 `pkg-config --cflags gstreamer-0.10 libglade-2.0 gtk+-2.0`
|
||||
CLIBS=-lgstinterfaces-0.10 -Wl -export-dynamic `pkg-config --libs gstreamer-0.10 libglade-2.0 gtk+-2.0`
|
||||
|
||||
all: metadata_editor
|
||||
|
||||
metadata_editor: metadata_editor.o
|
||||
$(CC) $(CLIBS) metadata_editor.o -o metadata_editor
|
||||
|
||||
metadata_editor.o: metadata_editor.c
|
||||
$(CC) $(CFLAGS) metadata_editor.c
|
||||
|
||||
clean:
|
||||
rm -rf *.o metadata_editor
|
||||
|
141
ext/metadata/test/MetadataEditorMain.glade
Normal file
141
ext/metadata/test/MetadataEditorMain.glade
Normal file
|
@ -0,0 +1,141 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
|
||||
<!--Generated with glade3 3.2.0 on Wed Dec 12 14:07:03 2007 by edlima@feisty-laptop-->
|
||||
<glade-interface>
|
||||
<widget class="GtkWindow" id="windowMain">
|
||||
<property name="width_request">800</property>
|
||||
<property name="height_request">600</property>
|
||||
<property name="events">GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||
<property name="title" translatable="yes">Metadata Editor</property>
|
||||
<signal name="configure_event" handler="on_windowMain_configure_event"/>
|
||||
<signal name="delete_event" handler="on_windowMain_delete_event"/>
|
||||
<child>
|
||||
<widget class="GtkVPaned" id="vpanedMain">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||
<child>
|
||||
<widget class="GtkDrawingArea" id="drawingMain">
|
||||
<property name="width_request">200</property>
|
||||
<property name="height_request">100</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||
<signal name="expose_event" handler="on_drawingMain_expose_event"/>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="resize">False</property>
|
||||
<property name="shrink">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkVBox" id="vboxMain">
|
||||
<property name="visible">True</property>
|
||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||
<child>
|
||||
<widget class="GtkScrolledWindow" id="scrolledwindow">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
|
||||
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
|
||||
<child>
|
||||
<widget class="GtkTreeView" id="treeMain">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||
<property name="headers_clickable">True</property>
|
||||
<property name="rules_hint">True</property>
|
||||
<property name="enable_search">False</property>
|
||||
<property name="hover_expand">True</property>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkVBox" id="vboxEditBnt">
|
||||
<property name="visible">True</property>
|
||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||
<child>
|
||||
<widget class="GtkHBox" id="hboxEdit">
|
||||
<property name="visible">True</property>
|
||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||
<child>
|
||||
<widget class="GtkEntry" id="entryTag">
|
||||
<property name="width_request">300</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkEntry" id="entryValue">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkHButtonBox" id="hbuttonboxBnt">
|
||||
<property name="visible">True</property>
|
||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||
<property name="homogeneous">True</property>
|
||||
<property name="layout_style">GTK_BUTTONBOX_SPREAD</property>
|
||||
<child>
|
||||
<widget class="GtkButton" id="buttonInsert">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||
<property name="label" translatable="yes">Insert</property>
|
||||
<signal name="clicked" handler="on_buttonInsert_clicked"/>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkButton" id="buttonSaveFile">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||
<property name="label" translatable="yes">Save File</property>
|
||||
<signal name="clicked" handler="on_buttonSaveFile_clicked"/>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="shrink">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
</glade-interface>
|
881
ext/metadata/test/metadata_editor.c
Normal file
881
ext/metadata/test/metadata_editor.c
Normal file
|
@ -0,0 +1,881 @@
|
|||
/*
|
||||
* GStreamer
|
||||
* Copyright 2007 Edgard Lima <edgard.lima@indt.org.br>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* GNU Lesser General Public License Version 2.1 (the "LGPL"), in
|
||||
* which case the following provisions apply instead of the ones
|
||||
* mentioned above:
|
||||
*
|
||||
* 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 <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <glade/glade-xml.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <gst/interfaces/xoverlay.h>
|
||||
#include <gdk/gdkx.h>
|
||||
|
||||
/*
|
||||
* Global constants
|
||||
*/
|
||||
|
||||
enum
|
||||
{
|
||||
COL_TAG = 0,
|
||||
COL_VALUE,
|
||||
NUM_COLS
|
||||
};
|
||||
|
||||
#define ENC_ERROR (-1)
|
||||
#define ENC_DONE (0)
|
||||
#define ENC_UNKNOWN (1)
|
||||
|
||||
|
||||
/*
|
||||
* functions prototypes
|
||||
*/
|
||||
|
||||
/* gstreamer related functions */
|
||||
|
||||
static void me_gst_cleanup_elements ();
|
||||
static int
|
||||
me_gst_setup_view_pipeline (const gchar * filename, GdkWindow * window);
|
||||
static int
|
||||
me_gst_setup_encode_pipeline (const gchar * src_file, const gchar * dest_file,
|
||||
gint * encode_status);
|
||||
|
||||
/* ui related functions */
|
||||
|
||||
static void ui_refresh ();
|
||||
|
||||
/*
|
||||
* Global Vars
|
||||
*/
|
||||
|
||||
GstElement *gst_source = NULL;
|
||||
GstElement *gst_metadata_demux = NULL;
|
||||
GstElement *gst_metadata_mux = NULL;
|
||||
GstElement *gst_image_dec = NULL;
|
||||
GstElement *gst_video_scale = NULL;
|
||||
GstElement *gst_video_convert = NULL;
|
||||
GstElement *gst_video_sink = NULL;
|
||||
GstElement *gst_file_sink = NULL;
|
||||
GstElement *gst_pipeline = NULL;
|
||||
|
||||
GstTagList *tag_list = NULL;
|
||||
|
||||
GladeXML *ui_glade_xml = NULL;
|
||||
GtkWidget *ui_main_window = NULL;
|
||||
GtkWidget *ui_drawing = NULL;
|
||||
GtkWidget *ui_tree = NULL;
|
||||
|
||||
GtkEntry *ui_entry_insert_tag = NULL;
|
||||
GtkEntry *ui_entry_insert_value = NULL;
|
||||
|
||||
GString *filename = NULL;
|
||||
|
||||
/*
|
||||
* Helper functions
|
||||
*/
|
||||
|
||||
static void
|
||||
insert_tag_on_tree (const GstTagList * list, const gchar * tag,
|
||||
gpointer user_data)
|
||||
{
|
||||
gchar *str = NULL;
|
||||
GtkTreeView *tree_view = NULL;
|
||||
GtkTreeStore *tree_store = NULL;
|
||||
GtkTreeIter iter;
|
||||
|
||||
tree_view = GTK_TREE_VIEW (user_data);
|
||||
|
||||
if (gst_tag_get_type (tag) == G_TYPE_STRING) {
|
||||
if (!gst_tag_list_get_string_index (list, tag, 0, &str))
|
||||
g_assert_not_reached ();
|
||||
} else {
|
||||
str = g_strdup_value_contents (gst_tag_list_get_value_index (list, tag, 0));
|
||||
}
|
||||
|
||||
tree_store = GTK_TREE_STORE (gtk_tree_view_get_model (tree_view));
|
||||
gtk_tree_store_append (tree_store, &iter, NULL);
|
||||
gtk_tree_store_set (tree_store, &iter, COL_TAG, tag, COL_VALUE, str, -1);
|
||||
|
||||
if (str)
|
||||
g_free (str);
|
||||
|
||||
}
|
||||
|
||||
static gboolean
|
||||
change_tag_list (GstTagList ** list, const gchar * tag, const gchar * value)
|
||||
{
|
||||
GType type;
|
||||
gboolean ret = FALSE;
|
||||
|
||||
if (list == NULL || tag == NULL || value == NULL)
|
||||
goto done;
|
||||
|
||||
if (!gst_tag_exists (tag)) {
|
||||
fprintf (stderr, "%s is not a GStreamer registered tag\n", tag);
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (*list == NULL)
|
||||
*list = gst_tag_list_new ();
|
||||
|
||||
type = gst_tag_get_type (tag);
|
||||
|
||||
switch (type) {
|
||||
case G_TYPE_STRING:
|
||||
gst_tag_list_add (*list, GST_TAG_MERGE_REPLACE, tag, value, NULL);
|
||||
ret = TRUE;
|
||||
break;
|
||||
case G_TYPE_FLOAT:
|
||||
{
|
||||
gfloat fv = (gfloat) g_strtod (value, NULL);
|
||||
|
||||
gst_tag_list_add (*list, GST_TAG_MERGE_REPLACE, tag, fv, NULL);
|
||||
ret = TRUE;
|
||||
}
|
||||
break;
|
||||
case G_TYPE_INT:
|
||||
/* fall through */
|
||||
case G_TYPE_UINT:
|
||||
{
|
||||
gint iv = atoi (value);
|
||||
|
||||
gst_tag_list_add (*list, GST_TAG_MERGE_REPLACE, tag, iv, NULL);
|
||||
ret = TRUE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
fprintf (stderr, "This app still doesn't handle type (%s)(%ld)\n",
|
||||
g_type_name (type), type);
|
||||
break;
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* UI handling functions (mapped by glade)
|
||||
*/
|
||||
|
||||
gboolean
|
||||
on_windowMain_configure_event (GtkWidget * widget, GdkEventConfigure * event,
|
||||
gpointer user_data)
|
||||
{
|
||||
GstXOverlay *xoverlay;
|
||||
|
||||
if (gst_video_sink) {
|
||||
|
||||
xoverlay = GST_X_OVERLAY (gst_video_sink);
|
||||
|
||||
if (xoverlay != NULL && GST_IS_X_OVERLAY (xoverlay)) {
|
||||
gst_x_overlay_expose (xoverlay);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
on_drawingMain_expose_event (GtkWidget * widget, GdkEventExpose * event,
|
||||
gpointer data)
|
||||
{
|
||||
if (gst_video_sink) {
|
||||
gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (gst_video_sink),
|
||||
GDK_WINDOW_XWINDOW (widget->window));
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
on_windowMain_delete_event (GtkWidget * widget, GdkEvent * event,
|
||||
gpointer user_data)
|
||||
{
|
||||
gst_element_set_state (gst_pipeline, GST_STATE_NULL);
|
||||
gst_element_get_state (gst_pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
|
||||
gtk_main_quit ();
|
||||
}
|
||||
|
||||
void
|
||||
on_buttonInsert_clicked (GtkButton * button, gpointer user_data)
|
||||
{
|
||||
GtkTreeStore *store = NULL;
|
||||
GtkTreeIter iter;
|
||||
const gchar *tag = gtk_entry_get_text (ui_entry_insert_tag);
|
||||
const gchar *value = gtk_entry_get_text (ui_entry_insert_value);
|
||||
|
||||
if (tag && value && tag[0] != '\0') {
|
||||
|
||||
/* insert just new tags (the ones already in list should be modified) */
|
||||
if (gst_tag_list_get_tag_size (tag_list, tag)) {
|
||||
fprintf (stderr, "%s tag is already in the list try to modify it\n", tag);
|
||||
} else {
|
||||
if (change_tag_list (&tag_list, tag, value)) {
|
||||
/* just add to ui_tree if it has been added to tag_list */
|
||||
store =
|
||||
GTK_TREE_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (ui_tree)));
|
||||
gtk_tree_store_append (store, &iter, NULL);
|
||||
gtk_tree_store_set (store, &iter, COL_TAG, tag, COL_VALUE, value, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
on_buttonSaveFile_clicked (GtkButton * button, gpointer user_data)
|
||||
{
|
||||
|
||||
GString *src_file = NULL;
|
||||
gint enc_status = ENC_UNKNOWN;
|
||||
|
||||
gst_element_set_state (gst_pipeline, GST_STATE_NULL);
|
||||
gst_element_get_state (gst_pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
|
||||
|
||||
src_file = g_string_new (filename->str);
|
||||
|
||||
g_string_prepend (filename, "_new_");
|
||||
remove (filename->str);
|
||||
|
||||
ui_refresh ();
|
||||
|
||||
if (me_gst_setup_encode_pipeline (src_file->str, filename->str, &enc_status)) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (tag_list && gst_metadata_mux) {
|
||||
GstTagSetter *setter = GST_TAG_SETTER (gst_metadata_mux);
|
||||
|
||||
if (setter) {
|
||||
gst_element_set_state (gst_pipeline, GST_STATE_READY);
|
||||
gst_element_get_state (gst_pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
|
||||
|
||||
gst_tag_setter_merge_tags (setter, tag_list, GST_TAG_MERGE_REPLACE);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
gst_element_set_state (gst_pipeline, GST_STATE_PLAYING);
|
||||
gst_element_get_state (gst_pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
|
||||
|
||||
/* wait until finished */
|
||||
gtk_main ();
|
||||
|
||||
gst_element_set_state (gst_pipeline, GST_STATE_NULL);
|
||||
gst_element_get_state (gst_pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
|
||||
|
||||
if (enc_status == ENC_DONE) {
|
||||
|
||||
/* view new file */
|
||||
if (tag_list) {
|
||||
gst_tag_list_free (tag_list);
|
||||
tag_list = NULL;
|
||||
}
|
||||
|
||||
me_gst_setup_view_pipeline (filename->str, ui_drawing->window);
|
||||
|
||||
gst_element_set_state (gst_pipeline, GST_STATE_PLAYING);
|
||||
gst_element_get_state (gst_pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
|
||||
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
if (src_file)
|
||||
g_string_free (src_file, TRUE);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* UI handling functions
|
||||
*/
|
||||
|
||||
void
|
||||
on_cell_edited (GtkCellRendererText * renderer, gchar * str_path,
|
||||
gchar * new_text, gpointer user_data)
|
||||
{
|
||||
GtkTreePath *path = NULL;
|
||||
GtkTreeIter iter;
|
||||
GtkTreeModel *model = NULL;
|
||||
const guint32 col_index = (guint32) user_data;
|
||||
const gchar *tag = gtk_entry_get_text (ui_entry_insert_tag);
|
||||
|
||||
path = gtk_tree_path_new_from_string (str_path);
|
||||
model = gtk_tree_view_get_model (GTK_TREE_VIEW (ui_tree));
|
||||
|
||||
if (change_tag_list (&tag_list, tag, new_text)) {
|
||||
|
||||
if (gtk_tree_model_get_iter (model, &iter, path)) {
|
||||
gtk_tree_store_set (GTK_TREE_STORE (model), &iter, col_index, new_text,
|
||||
-1);
|
||||
gtk_entry_set_text (ui_entry_insert_value, new_text);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (path)
|
||||
gtk_tree_path_free (path);
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
on_tree_selection_changed (GtkTreeSelection * selection, gpointer data)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
GtkTreeModel *model;
|
||||
|
||||
if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
|
||||
gchar *tag;
|
||||
gchar *value;
|
||||
|
||||
gtk_tree_model_get (model, &iter, COL_TAG, &tag, -1);
|
||||
gtk_tree_model_get (model, &iter, COL_VALUE, &value, -1);
|
||||
|
||||
gtk_entry_set_text (ui_entry_insert_tag, tag);
|
||||
gtk_entry_set_text (ui_entry_insert_value, value);
|
||||
|
||||
g_free (value);
|
||||
g_free (tag);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* UI helper functions
|
||||
*/
|
||||
|
||||
static int
|
||||
ui_add_columns (GtkTreeView * tree_view, const gchar * title, gint col_index,
|
||||
gboolean editable)
|
||||
{
|
||||
GtkCellRenderer *renderer;
|
||||
GtkTreeViewColumn *tree_col;
|
||||
int ret = 0;
|
||||
|
||||
renderer = gtk_cell_renderer_text_new ();
|
||||
|
||||
if (editable) {
|
||||
g_object_set (renderer, "editable", TRUE, NULL);
|
||||
g_signal_connect (G_OBJECT (renderer), "edited",
|
||||
G_CALLBACK (on_cell_edited), (gpointer) col_index);
|
||||
}
|
||||
|
||||
if ((tree_col = gtk_tree_view_column_new_with_attributes (title, renderer,
|
||||
"text", col_index, NULL))) {
|
||||
gtk_tree_view_append_column (tree_view, tree_col);
|
||||
} else {
|
||||
fprintf (stderr, "UI: could not create column %s\n", title);
|
||||
ret = -201;
|
||||
goto done;
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
ui_setup_tree_view (GtkTreeView * tree_view)
|
||||
{
|
||||
int ret = 0;
|
||||
GtkTreeStore *tree_store = NULL;
|
||||
GtkTreeSelection *select;
|
||||
|
||||
if ((ret = ui_add_columns (tree_view, "tag", COL_TAG, FALSE)))
|
||||
goto done;
|
||||
|
||||
if ((ret = ui_add_columns (tree_view, "value", COL_VALUE, TRUE)))
|
||||
goto done;
|
||||
|
||||
tree_store = gtk_tree_store_new (NUM_COLS, G_TYPE_STRING, G_TYPE_STRING);
|
||||
|
||||
gtk_tree_view_set_model (tree_view, GTK_TREE_MODEL (tree_store));
|
||||
|
||||
select = gtk_tree_view_get_selection (tree_view);
|
||||
gtk_tree_selection_set_mode (select, GTK_SELECTION_SINGLE);
|
||||
g_signal_connect (G_OBJECT (select), "changed",
|
||||
G_CALLBACK (on_tree_selection_changed), NULL);
|
||||
|
||||
done:
|
||||
|
||||
if (tree_store)
|
||||
g_object_unref (tree_store);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
ui_refresh ()
|
||||
{
|
||||
GtkTreeStore *store =
|
||||
GTK_TREE_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (ui_tree)));
|
||||
gtk_tree_store_clear (store);
|
||||
if (filename)
|
||||
gtk_window_set_title (GTK_WINDOW (ui_main_window), filename->str);
|
||||
}
|
||||
|
||||
static int
|
||||
ui_create ()
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
ui_glade_xml = glade_xml_new ("MetadataEditorMain.glade", NULL, NULL);
|
||||
|
||||
if (!ui_glade_xml) {
|
||||
fprintf (stderr, "glade_xml_new failed\n");
|
||||
ret = -101;
|
||||
goto done;
|
||||
}
|
||||
|
||||
ui_main_window = glade_xml_get_widget (ui_glade_xml, "windowMain");
|
||||
|
||||
ui_drawing = glade_xml_get_widget (ui_glade_xml, "drawingMain");
|
||||
|
||||
ui_tree = glade_xml_get_widget (ui_glade_xml, "treeMain");
|
||||
|
||||
ui_entry_insert_tag =
|
||||
GTK_ENTRY (glade_xml_get_widget (ui_glade_xml, "entryTag"));
|
||||
|
||||
ui_entry_insert_value =
|
||||
GTK_ENTRY (glade_xml_get_widget (ui_glade_xml, "entryValue"));
|
||||
|
||||
if (!(ui_main_window && ui_drawing && ui_tree && ui_entry_insert_tag
|
||||
&& ui_entry_insert_value)) {
|
||||
fprintf (stderr, "Some widgets couldn't be created\n");
|
||||
ret = -105;
|
||||
goto done;
|
||||
}
|
||||
|
||||
glade_xml_signal_autoconnect (ui_glade_xml);
|
||||
|
||||
ui_setup_tree_view (GTK_TREE_VIEW (ui_tree));
|
||||
|
||||
ui_refresh ();
|
||||
|
||||
gtk_widget_show_all (ui_main_window);
|
||||
|
||||
done:
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* GStreamer functions
|
||||
*/
|
||||
|
||||
|
||||
static gboolean
|
||||
me_gst_bus_callback_encode (GstBus * bus, GstMessage * message, gpointer data)
|
||||
{
|
||||
gint *encode_status = (gint *) data;
|
||||
|
||||
fflush (stdout);
|
||||
|
||||
switch (GST_MESSAGE_TYPE (message)) {
|
||||
case GST_MESSAGE_ERROR:
|
||||
{
|
||||
GError *err;
|
||||
gchar *debug;
|
||||
|
||||
gst_message_parse_error (message, &err, &debug);
|
||||
fprintf (stderr, "Error: %s\n", err->message);
|
||||
g_error_free (err);
|
||||
g_free (debug);
|
||||
|
||||
*encode_status = ENC_ERROR;
|
||||
gtk_main_quit ();
|
||||
}
|
||||
break;
|
||||
case GST_MESSAGE_TAG:
|
||||
{
|
||||
/* ignore, we alredy have the tag list */
|
||||
}
|
||||
break;
|
||||
case GST_MESSAGE_EOS:
|
||||
{
|
||||
*encode_status = ENC_DONE;
|
||||
gtk_main_quit ();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* unhandled message */
|
||||
break;
|
||||
}
|
||||
|
||||
/* we want to be notified again the next time there is a message
|
||||
* on the bus, so returning TRUE (FALSE means we want to stop watching
|
||||
* for messages on the bus and our callback should not be called again)
|
||||
*/
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
me_gst_bus_callback_view (GstBus * bus, GstMessage * message, gpointer data)
|
||||
{
|
||||
switch (GST_MESSAGE_TYPE (message)) {
|
||||
case GST_MESSAGE_ERROR:
|
||||
{
|
||||
GError *err;
|
||||
gchar *debug;
|
||||
|
||||
gst_message_parse_error (message, &err, &debug);
|
||||
fprintf (stderr, "Error: %s\n", err->message);
|
||||
g_error_free (err);
|
||||
g_free (debug);
|
||||
|
||||
gtk_main_quit ();
|
||||
}
|
||||
break;
|
||||
case GST_MESSAGE_TAG:
|
||||
{
|
||||
if (tag_list == NULL)
|
||||
gst_message_parse_tag (message, &tag_list);
|
||||
else {
|
||||
GstTagList *tl = NULL;
|
||||
GstTagList *ntl = NULL;
|
||||
|
||||
gst_message_parse_tag (message, &tl);
|
||||
if (tl) {
|
||||
ntl = gst_tag_list_merge (tag_list, tl, GST_TAG_MERGE_PREPEND);
|
||||
if (ntl) {
|
||||
gst_tag_list_free (tag_list);
|
||||
tag_list = ntl;
|
||||
gst_tag_list_free (tl);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* remove whole chunk tags */
|
||||
gst_tag_list_remove_tag (tag_list, "exif");
|
||||
gst_tag_list_remove_tag (tag_list, "iptc");
|
||||
gst_tag_list_remove_tag (tag_list, "xmp");
|
||||
}
|
||||
break;
|
||||
case GST_MESSAGE_EOS:
|
||||
if (tag_list) {
|
||||
gst_tag_list_foreach (tag_list, insert_tag_on_tree, ui_tree);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* unhandled message */
|
||||
break;
|
||||
}
|
||||
|
||||
/* we want to be notified again the next time there is a message
|
||||
* on the bus, so returning TRUE (FALSE means we want to stop watching
|
||||
* for messages on the bus and our callback should not be called again)
|
||||
*/
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
me_gst_cleanup_elements ()
|
||||
{
|
||||
/* when adding an element to pipeline rember to set it to NULL or add extra ref */
|
||||
|
||||
if (gst_source) {
|
||||
gst_object_unref (gst_source);
|
||||
gst_source = NULL;
|
||||
}
|
||||
if (gst_metadata_demux) {
|
||||
gst_object_unref (gst_metadata_demux);
|
||||
gst_metadata_demux = NULL;
|
||||
}
|
||||
if (gst_metadata_mux) {
|
||||
gst_object_unref (gst_metadata_mux);
|
||||
gst_metadata_mux = NULL;
|
||||
}
|
||||
if (gst_image_dec) {
|
||||
gst_object_unref (gst_image_dec);
|
||||
gst_image_dec = NULL;
|
||||
}
|
||||
if (gst_video_scale) {
|
||||
gst_object_unref (gst_video_scale);
|
||||
gst_video_scale = NULL;
|
||||
}
|
||||
if (gst_video_convert) {
|
||||
gst_object_unref (gst_video_convert);
|
||||
gst_video_convert = NULL;
|
||||
}
|
||||
if (gst_video_sink) {
|
||||
gst_object_unref (gst_video_sink);
|
||||
gst_video_sink = NULL;
|
||||
}
|
||||
if (gst_file_sink) {
|
||||
gst_object_unref (gst_file_sink);
|
||||
gst_file_sink = NULL;
|
||||
}
|
||||
|
||||
if (gst_pipeline) {
|
||||
gst_element_set_state (gst_pipeline, GST_STATE_NULL);
|
||||
gst_element_get_state (gst_pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
|
||||
gst_object_unref (gst_pipeline);
|
||||
gst_pipeline = NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* dummy function that looks the file extension */
|
||||
static gboolean
|
||||
is_png (const gchar * filename)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
guint32 len;
|
||||
|
||||
if (!filename)
|
||||
goto done;
|
||||
|
||||
if ((len = strlen (filename)) < 4) /* at least ".png" */
|
||||
goto done;
|
||||
|
||||
if (0 == strcasecmp (filename + (len - 4), ".png"))
|
||||
ret = TRUE;
|
||||
|
||||
done:
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
static int
|
||||
me_gst_setup_encode_pipeline (const gchar * src_file, const gchar * dest_file,
|
||||
gint * encode_status)
|
||||
{
|
||||
int ret = 0;
|
||||
GstBus *bus = NULL;
|
||||
gboolean linked;
|
||||
|
||||
*encode_status = ENC_ERROR;
|
||||
|
||||
me_gst_cleanup_elements ();
|
||||
|
||||
/* create elements */
|
||||
gst_source = gst_element_factory_make ("filesrc", NULL);
|
||||
gst_metadata_demux = gst_element_factory_make ("metadataparse", NULL);
|
||||
gst_metadata_mux = gst_element_factory_make ("metadatamux", NULL);
|
||||
gst_file_sink = gst_element_factory_make ("filesink", NULL);
|
||||
|
||||
|
||||
if (!(gst_source && gst_metadata_demux && gst_metadata_mux && gst_file_sink)) {
|
||||
fprintf (stderr, "An element couldn't be created for ecoding\n");
|
||||
ret = -300;
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
||||
/* create gst_pipeline */
|
||||
gst_pipeline = gst_pipeline_new (NULL);
|
||||
|
||||
if (NULL == gst_pipeline) {
|
||||
fprintf (stderr, "Pipeline couldn't be created\n");
|
||||
ret = -305;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* set elements's properties */
|
||||
g_object_set (gst_source, "location", src_file, NULL);
|
||||
g_object_set (gst_file_sink, "location", dest_file, NULL);
|
||||
|
||||
/* adding and linking elements */
|
||||
gst_bin_add_many (GST_BIN (gst_pipeline), gst_source, gst_metadata_demux,
|
||||
gst_metadata_mux, gst_file_sink, NULL);
|
||||
|
||||
linked =
|
||||
gst_element_link_many (gst_source, gst_metadata_demux, gst_metadata_mux,
|
||||
gst_file_sink, NULL);
|
||||
|
||||
/* now element are owned by pipeline (for videosink we keep a extra ref) */
|
||||
gst_source = gst_metadata_demux = gst_file_sink = NULL;
|
||||
gst_object_ref (gst_metadata_mux);
|
||||
|
||||
if (!linked) {
|
||||
fprintf (stderr, "Elements couldn't be linked\n");
|
||||
ret = -310;
|
||||
goto done;
|
||||
}
|
||||
|
||||
*encode_status = ENC_UNKNOWN;
|
||||
|
||||
/* adding message bus */
|
||||
bus = gst_pipeline_get_bus (GST_PIPELINE (gst_pipeline));
|
||||
gst_bus_add_watch (bus, me_gst_bus_callback_encode, encode_status);
|
||||
gst_object_unref (bus);
|
||||
|
||||
done:
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
static int
|
||||
me_gst_setup_view_pipeline (const gchar * filename, GdkWindow * window)
|
||||
{
|
||||
int ret = 0;
|
||||
GstBus *bus = NULL;
|
||||
gboolean linked;
|
||||
|
||||
me_gst_cleanup_elements ();
|
||||
|
||||
/* create elements */
|
||||
gst_source = gst_element_factory_make ("filesrc", NULL);
|
||||
gst_metadata_demux = gst_element_factory_make ("metadataparse", NULL);
|
||||
/* let's do a dummy stuff to avoid decodebin */
|
||||
if (is_png (filename))
|
||||
gst_image_dec = gst_element_factory_make ("pngdec", NULL);
|
||||
else
|
||||
gst_image_dec = gst_element_factory_make ("jpegdec", NULL);
|
||||
gst_video_scale = gst_element_factory_make ("videoscale", NULL);
|
||||
gst_video_convert = gst_element_factory_make ("ffmpegcolorspace", NULL);
|
||||
gst_video_sink = gst_element_factory_make ("ximagesink", NULL);
|
||||
|
||||
if (!(gst_source && gst_metadata_demux && gst_image_dec && gst_video_scale
|
||||
&& gst_video_convert && gst_video_sink)) {
|
||||
fprintf (stderr, "An element couldn't be created for viewing\n");
|
||||
ret = -400;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* create gst_pipeline */
|
||||
gst_pipeline = gst_pipeline_new (NULL);
|
||||
|
||||
if (NULL == gst_pipeline) {
|
||||
fprintf (stderr, "Pipeline couldn't be created\n");
|
||||
ret = -405;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* set elements's properties */
|
||||
g_object_set (gst_source, "location", filename, NULL);
|
||||
g_object_set (gst_video_sink, "force-aspect-ratio", TRUE, NULL);
|
||||
|
||||
|
||||
/* adding and linking elements */
|
||||
gst_bin_add_many (GST_BIN (gst_pipeline), gst_source, gst_metadata_demux,
|
||||
gst_image_dec, gst_video_scale, gst_video_convert, gst_video_sink, NULL);
|
||||
|
||||
linked = gst_element_link_many (gst_source, gst_metadata_demux, gst_image_dec,
|
||||
gst_video_scale, gst_video_convert, gst_video_sink, NULL);
|
||||
|
||||
/* now element are owned by pipeline (for videosink we keep a extra ref) */
|
||||
gst_source = gst_metadata_demux = gst_image_dec = gst_video_scale =
|
||||
gst_video_convert = NULL;
|
||||
gst_object_ref (gst_video_sink);
|
||||
|
||||
if (window)
|
||||
gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (gst_video_sink),
|
||||
GDK_WINDOW_XWINDOW (window));
|
||||
|
||||
if (!linked) {
|
||||
fprintf (stderr, "Elements couldn't be linked\n");
|
||||
ret = -410;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* adding message bus */
|
||||
bus = gst_pipeline_get_bus (GST_PIPELINE (gst_pipeline));
|
||||
gst_bus_add_watch (bus, me_gst_bus_callback_view, NULL);
|
||||
gst_object_unref (bus);
|
||||
|
||||
|
||||
done:
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf (stderr, "Give the name of a jpeg file as argument\n");
|
||||
ret = -5;
|
||||
goto done;
|
||||
}
|
||||
|
||||
gst_init (&argc, &argv);
|
||||
gtk_init (&argc, &argv);
|
||||
|
||||
/* filename for future usage (title and file name to be created) */
|
||||
if (filename)
|
||||
g_string_free (filename, TRUE);
|
||||
filename = g_string_new (argv[1]);
|
||||
|
||||
/* create UI */
|
||||
if ((ret = ui_create ())) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* create pipeline */
|
||||
me_gst_setup_view_pipeline (argv[1], ui_drawing->window);
|
||||
|
||||
gst_element_set_state (gst_pipeline, GST_STATE_PLAYING);
|
||||
|
||||
gtk_main ();
|
||||
|
||||
done:
|
||||
|
||||
me_gst_cleanup_elements ();
|
||||
|
||||
if (tag_list) {
|
||||
gst_tag_list_free (tag_list);
|
||||
tag_list = NULL;
|
||||
}
|
||||
|
||||
if (filename) {
|
||||
g_string_free (filename, TRUE);
|
||||
filename = NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
Loading…
Reference in a new issue