Inform the application about the media size, so it can adapt the UIView to the correct aspect ratio.

This commit is contained in:
Xavi Artigas 2013-05-14 18:11:04 +02:00
parent 52f8179003
commit eeb4755a3b
3 changed files with 51 additions and 0 deletions

View file

@ -2,6 +2,7 @@
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/interfaces/xoverlay.h> #include <gst/interfaces/xoverlay.h>
#include <gst/video/video.h>
GST_DEBUG_CATEGORY_STATIC (debug_category); GST_DEBUG_CATEGORY_STATIC (debug_category);
#define GST_CAT_DEFAULT debug_category #define GST_CAT_DEFAULT debug_category
@ -83,6 +84,37 @@ GST_DEBUG_CATEGORY_STATIC (debug_category);
} }
} }
static void check_media_size (GStreamerBackend *self) {
GstElement *video_sink;
GstPad *video_sink_pad;
GstCaps *caps;
GstVideoFormat fmt;
int width;
int height;
/* Retrieve the Caps at the entrance of the video sink */
g_object_get (self->pipeline, "video-sink", &video_sink, NULL);
video_sink_pad = gst_element_get_static_pad (video_sink, "sink");
caps = gst_pad_get_negotiated_caps (video_sink_pad);
if (gst_video_format_parse_caps(caps, &fmt, &width, &height)) {
int par_n, par_d;
if (gst_video_parse_caps_pixel_aspect_ratio (caps, &par_n, &par_d)) {
width = width * par_n / par_d;
}
GST_DEBUG ("Media size is %dx%d, notifying application", width, height);
if (self->ui_delegate && [self->ui_delegate respondsToSelector:@selector(mediaSizeChanged:height:)])
{
[self->ui_delegate mediaSizeChanged:width height:height];
}
}
gst_caps_unref(caps);
gst_object_unref (video_sink_pad);
gst_object_unref(video_sink);
}
/* Retrieve errors from the bus and show them on the UI */ /* Retrieve errors from the bus and show them on the UI */
static void error_cb (GstBus *bus, GstMessage *msg, GStreamerBackend *self) static void error_cb (GstBus *bus, GstMessage *msg, GStreamerBackend *self)
{ {
@ -109,6 +141,11 @@ static void state_changed_cb (GstBus *bus, GstMessage *msg, GStreamerBackend *se
gchar *message = g_strdup_printf("State changed to %s", gst_element_state_get_name(new_state)); gchar *message = g_strdup_printf("State changed to %s", gst_element_state_get_name(new_state));
[self setUIMessage:message]; [self setUIMessage:message];
g_free (message); g_free (message);
if (old_state == GST_STATE_READY && new_state == GST_STATE_PAUSED)
{
check_media_size(self);
}
} }
} }

View file

@ -11,4 +11,7 @@
* to the screen. */ * to the screen. */
-(void) gstreamerSetUIMessage:(NSString *)message; -(void) gstreamerSetUIMessage:(NSString *)message;
/* Called when the media size is first discovered or it changes */
-(void) mediaSizeChanged:(NSInteger)width height:(NSInteger)height;
@end @end

View file

@ -96,4 +96,15 @@
}); });
} }
-(void) mediaSizeChanged:(NSInteger)width height:(NSInteger)height
{
media_width = width;
media_height = height;
dispatch_async(dispatch_get_main_queue(), ^{
[self viewDidLayoutSubviews];
[video_view setNeedsLayout];
[video_view layoutIfNeeded];
});
}
@end @end