Search
SailfishOS Open Build Service
>
Projects
>
home:abranson
:
branches:nemo:devel:hw:native-common
>
gstreamer1.0-plugins-good
> _service:tar_git:0002-qtmux-write-rotation-information-into-the-TKHD-matri.patch
Log In
Username
Password
Cancel
Overview
Repositories
Revisions
Requests
Users
Advanced
Attributes
Meta
File _service:tar_git:0002-qtmux-write-rotation-information-into-the-TKHD-matri.patch of Package gstreamer1.0-plugins-good
From 4dd4e99c420c4ccc771a6a87eb2ebecc57358723 Mon Sep 17 00:00:00 2001 From: Mohammed Hassan <mohammed.hassan@jolla.com> Date: Thu, 5 Mar 2015 17:12:13 +0200 Subject: [PATCH 2/2] qtmux: write rotation information into the TKHD matrix This patch handles the simple cases of 0, 90, 180 and 270 We simply catch the image orientation event and translate that into the corresponding transformation matrix. Based on the work of Andrew den Exter <andrew.den.exter@jollamobile.com> --- gst/isomp4/atoms.c | 31 +++++++++++++++++++++++++++++++ gst/isomp4/atoms.h | 2 ++ gst/isomp4/gstqtmux.c | 25 +++++++++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/gst/isomp4/atoms.c b/gst/isomp4/atoms.c index e0ec513..d8f0d9f 100644 --- a/gst/isomp4/atoms.c +++ b/gst/isomp4/atoms.c @@ -4350,6 +4350,37 @@ atom_trak_set_subtitle_type (AtomTRAK * trak, AtomsContext * context, return tx3g; } +void +atom_trak_set_video_transform (AtomTRAK * trak, gint rotation) +{ + switch (rotation) { + case 0: + trak->tkhd.matrix[0] = 1 << 16; + trak->tkhd.matrix[1] = 0; + trak->tkhd.matrix[3] = 0; + trak->tkhd.matrix[4] = 1 << 16; + break; + case 90: + trak->tkhd.matrix[0] = 0; + trak->tkhd.matrix[1] = 1 << 16; + trak->tkhd.matrix[3] = G_MAXUINT16 << 16; + trak->tkhd.matrix[4] = 0; + break; + case 180: + trak->tkhd.matrix[0] = G_MAXUINT16 << 16; + trak->tkhd.matrix[1] = 0; + trak->tkhd.matrix[3] = 0; + trak->tkhd.matrix[4] = G_MAXUINT16 << 16; + break; + case 270: + trak->tkhd.matrix[0] = 0; + trak->tkhd.matrix[1] = G_MAXUINT16 << 16; + trak->tkhd.matrix[3] = 1 << 16; + trak->tkhd.matrix[4] = 0; + break; + } +} + static void atom_mfhd_init (AtomMFHD * mfhd, guint32 sequence_number) { diff --git a/gst/isomp4/atoms.h b/gst/isomp4/atoms.h index b105a4d..c818b66 100644 --- a/gst/isomp4/atoms.h +++ b/gst/isomp4/atoms.h @@ -1051,6 +1051,8 @@ SampleTableEntryMP4V * atom_trak_set_video_type (AtomTRAK * trak, AtomsContext * SampleTableEntryTX3G * atom_trak_set_subtitle_type (AtomTRAK * trak, AtomsContext * context, SubtitleSampleEntry * entry); +void atom_trak_set_video_transform (AtomTRAK * trak, gint rotation); + SampleTableEntryTMCD * atom_trak_set_timecode_type (AtomTRAK * trak, AtomsContext * context, guint trak_timescale, GstVideoTimeCode * tc); diff --git a/gst/isomp4/gstqtmux.c b/gst/isomp4/gstqtmux.c index 5be830b..10a959f 100644 --- a/gst/isomp4/gstqtmux.c +++ b/gst/isomp4/gstqtmux.c @@ -5866,6 +5866,7 @@ gst_qt_mux_sink_event (GstCollectPads * pads, GstCollectData * data, GstTagMergeMode mode; gchar *code; GstQTPad *collect_pad; + gchar *orientation; GST_OBJECT_LOCK (qtmux); mode = gst_tag_setter_get_tag_merge_mode (setter); @@ -5912,6 +5913,30 @@ gst_qt_mux_sink_event (GstCollectPads * pads, GstCollectData * data, g_free (code); } + if (gst_tag_list_get_string (list, GST_TAG_IMAGE_ORIENTATION, &orientation)) { + GstQTPad *qtpad = gst_pad_get_element_private (pad); + g_assert (qtpad); + + if (qtpad->trak) { + gint rotation = -1; + if (strcmp(orientation, "rotate-0") == 0) + rotation = 0; + else if (strcmp(orientation, "rotate-90") == 0) + rotation = 90; + else if (strcmp(orientation, "rotate-180") == 0) + rotation = 180; + else if (strcmp(orientation, "rotate-270") == 0) + rotation = 270; + + if (rotation != -1) { + GST_DEBUG_OBJECT (qtmux, "setting rotation to %d", rotation); + atom_trak_set_video_transform (qtpad->trak, rotation); + } + } + + g_free (orientation); + } + gst_event_unref (event); event = NULL; ret = TRUE; -- 2.8.1