frameposition: In case sources have the same size as track, follow track size

For example if the size has been serialized in a file, but the user has
not personalized the size, we want that whenever the restriction caps
change the size, the video should take the size of the track
restriction caps.

We know need to keep track of the current positionner.size even if
setting through caps size changes.

https://bugzilla.gnome.org/show_bug.cgi?id=739527
This commit is contained in:
Thibault Saunier 2014-11-02 11:46:37 +01:00
parent 21807d6637
commit 08af3721bf
2 changed files with 56 additions and 6 deletions

View file

@ -76,7 +76,8 @@ _weak_notify_cb (GstFramePositionner * pos, GObject * old)
}
static void
gst_frame_positionner_update_properties (GstFramePositionner * pos)
gst_frame_positionner_update_properties (GstFramePositionner * pos,
gint old_track_width, gint old_track_height)
{
GstCaps *caps;
gint final_width;
@ -85,8 +86,20 @@ gst_frame_positionner_update_properties (GstFramePositionner * pos)
if (pos->capsfilter == NULL)
return;
final_width = (pos->width > 0) ? pos->width : pos->track_width;
final_height = (pos->height > 0) ? pos->height : pos->track_height;
if ((old_track_width && pos->width == old_track_width &&
old_track_width && pos->width == old_track_width) ||
(pos->width <= 0 && pos->height <= 0)) {
GST_DEBUG_OBJECT (pos, "FOLLOWING track size width old_track: %d -- pos: %d"
"height, old_track %d -- pos: %d",
old_track_width, pos->width, old_track_height, pos->height);
final_width = pos->track_width;
final_height = pos->track_height;
} else {
GST_DEBUG_OBJECT (pos, "Keeping previous sizes");
final_width = pos->width;
final_height = pos->height;
}
if (final_width == 0 && final_height == 0)
caps = gst_caps_new_empty_simple ("video/x-raw");
@ -115,6 +128,8 @@ gst_frame_positionner_update_properties (GstFramePositionner * pos)
g_object_notify (G_OBJECT (pos), "width");
g_object_notify (G_OBJECT (pos), "height");
pos->width = final_width;
pos->height = final_height;
gst_caps_unref (caps);
}
@ -122,6 +137,7 @@ static void
sync_properties_from_caps (GstFramePositionner * pos, GstCaps * caps)
{
gint width, height;
gint old_track_width, old_track_height;
width = height = 0;
@ -138,6 +154,9 @@ sync_properties_from_caps (GstFramePositionner * pos, GstCaps * caps)
pos->fps_n = -1;
}
old_track_width = pos->track_width;
old_track_height = pos->track_height;
pos->track_width = width;
pos->track_height = height;
@ -145,7 +164,8 @@ sync_properties_from_caps (GstFramePositionner * pos, GstCaps * caps)
GST_DEBUG_OBJECT (pos, "syncing framerate from caps : %d/%d", pos->fps_n,
pos->fps_d);
gst_frame_positionner_update_properties (pos);
gst_frame_positionner_update_properties (pos, old_track_width,
old_track_height);
}
static void
@ -358,11 +378,11 @@ gst_frame_positionner_set_property (GObject * object, guint property_id,
break;
case PROP_WIDTH:
framepositionner->width = g_value_get_int (value);
gst_frame_positionner_update_properties (framepositionner);
gst_frame_positionner_update_properties (framepositionner, 0, 0);
break;
case PROP_HEIGHT:
framepositionner->height = g_value_get_int (value);
gst_frame_positionner_update_properties (framepositionner);
gst_frame_positionner_update_properties (framepositionner, 0, 0);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);

View file

@ -1291,6 +1291,9 @@ check_frame_positionner_size (GESClip * clip, gint width, gint height)
real_width = g_value_get_int (&val_width);
real_height = g_value_get_int (&val_height);
assert_equals_int (real_width, width);
assert_equals_int (real_height, height);
return (width == real_width && height == real_height);
}
@ -1458,6 +1461,33 @@ GST_START_TEST (test_scaling)
/* Clip width was set to 0 so it has to use natural clip width */
/* Clip height was set to 0 so it has to use natural clip height */
fail_unless (check_frame_positionner_size (clip, 0, 0));
/**
* Our timeline : 320 * 240
*
* 0--------------0
* | width : 320 |
* | height: 240 |
* 0--------------2
*/
/* We set the restriction caps video size to the same as the video source
* size. */
caps = gst_caps_from_string ("video/x-raw,height=240,width=320");
ges_track_set_restriction_caps (trackv, caps);
gst_caps_unref (caps);
_set_track_element_width_height (GES_CONTAINER_CHILDREN (clip)->data, 320,
240);
/* As the video source as the same size as the track restriction caps, changing
* the track size through restriction caps should also change the video source
* size */
caps = gst_caps_from_string ("video/x-raw,height=1080,width=1920");
ges_track_set_restriction_caps (trackv, caps);
fail_unless (check_frame_positionner_size (clip, 1920, 1080));
gst_object_unref (timeline);
}
GST_END_TEST;