summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavi Artigas <xartigas@fluendo.com>2013-05-14 18:11:04 +0200
committerXavi Artigas <xartigas@fluendo.com>2013-05-14 18:11:04 +0200
commiteeb4755a3bfbb4998e8ec5060b70ab60fd4ba80f (patch)
tree4f384b807908f221b56b31e7b640ee494d465a00
parent52f8179003aaaa5e0dc6fd3286df8561a7afe3ac (diff)
Inform the application about the media size, so it can adapt the UIView to the correct aspect ratio.
-rw-r--r--gst-sdk/tutorials/xcode iOS/Tutorial 4/GStreamerBackend.m37
-rw-r--r--gst-sdk/tutorials/xcode iOS/Tutorial 4/GStreamerBackendDelegate.h3
-rw-r--r--gst-sdk/tutorials/xcode iOS/Tutorial 4/VideoViewController.m11
3 files changed, 51 insertions, 0 deletions
diff --git a/gst-sdk/tutorials/xcode iOS/Tutorial 4/GStreamerBackend.m b/gst-sdk/tutorials/xcode iOS/Tutorial 4/GStreamerBackend.m
index b15ef43..60758cc 100644
--- a/gst-sdk/tutorials/xcode iOS/Tutorial 4/GStreamerBackend.m
+++ b/gst-sdk/tutorials/xcode iOS/Tutorial 4/GStreamerBackend.m
@@ -2,6 +2,7 @@
#include <gst/gst.h>
#include <gst/interfaces/xoverlay.h>
+#include <gst/video/video.h>
GST_DEBUG_CATEGORY_STATIC (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 */
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));
[self setUIMessage:message];
g_free (message);
+
+ if (old_state == GST_STATE_READY && new_state == GST_STATE_PAUSED)
+ {
+ check_media_size(self);
+ }
}
}
diff --git a/gst-sdk/tutorials/xcode iOS/Tutorial 4/GStreamerBackendDelegate.h b/gst-sdk/tutorials/xcode iOS/Tutorial 4/GStreamerBackendDelegate.h
index 5586373..739461c 100644
--- a/gst-sdk/tutorials/xcode iOS/Tutorial 4/GStreamerBackendDelegate.h
+++ b/gst-sdk/tutorials/xcode iOS/Tutorial 4/GStreamerBackendDelegate.h
@@ -11,4 +11,7 @@
* to the screen. */
-(void) gstreamerSetUIMessage:(NSString *)message;
+/* Called when the media size is first discovered or it changes */
+-(void) mediaSizeChanged:(NSInteger)width height:(NSInteger)height;
+
@end
diff --git a/gst-sdk/tutorials/xcode iOS/Tutorial 4/VideoViewController.m b/gst-sdk/tutorials/xcode iOS/Tutorial 4/VideoViewController.m
index d4bc16d..6b4ae04 100644
--- a/gst-sdk/tutorials/xcode iOS/Tutorial 4/VideoViewController.m
+++ b/gst-sdk/tutorials/xcode iOS/Tutorial 4/VideoViewController.m
@@ -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