sys/osxvideo/osxvideosink.*: Handle video window resizing more correctly, avoiding crashes when embedding the window ...

Original commit message from CVS:
* sys/osxvideo/osxvideosink.h:
* sys/osxvideo/osxvideosink.m:
Handle video window resizing more correctly, avoiding crashes when
embedding the window and resizing it.
This commit is contained in:
Michael Smith 2008-11-20 23:59:07 +00:00
parent 9b372f1bbd
commit e6075940b1
3 changed files with 31 additions and 25 deletions

View file

@ -1,3 +1,10 @@
2008-11-20 Michael Smith <msmith@songbirdnest.com>
* sys/osxvideo/osxvideosink.h:
* sys/osxvideo/osxvideosink.m:
Handle video window resizing more correctly, avoiding crashes when
embedding the window and resizing it.
2008-11-20 Michael Smith <msmith@songbirdnest.com> 2008-11-20 Michael Smith <msmith@songbirdnest.com>
* gst/udp/gstmultiudpsink.c: * gst/udp/gstmultiudpsink.c:

View file

@ -73,9 +73,6 @@ struct _GstOSXVideoSink {
GstVideoSink videosink; GstVideoSink videosink;
GstOSXWindow *osxwindow; GstOSXWindow *osxwindow;
gint fps_n;
gint fps_d;
GstTask *event_task; GstTask *event_task;
GStaticRecMutex event_task_lock; GStaticRecMutex event_task_lock;

View file

@ -228,11 +228,12 @@ gst_osx_video_sink_osxwindow_new (GstOSXVideoSink * osxvideosink, gint width,
gint height) gint height)
{ {
NSRect rect; NSRect rect;
GstOSXWindow *osxwindow = NULL; GstOSXWindow *osxwindow = NULL;
g_return_val_if_fail (GST_IS_OSX_VIDEO_SINK (osxvideosink), NULL); g_return_val_if_fail (GST_IS_OSX_VIDEO_SINK (osxvideosink), NULL);
GST_DEBUG_OBJECT (osxvideosink, "Creating new OSX window");
osxwindow = g_new0 (GstOSXWindow, 1); osxwindow = g_new0 (GstOSXWindow, 1);
osxwindow->width = width; osxwindow->width = width;
@ -266,6 +267,7 @@ gst_osx_video_sink_osxwindow_new (GstOSXVideoSink * osxvideosink, gint width,
backing: NSBackingStoreBuffered backing: NSBackingStoreBuffered
defer: NO defer: NO
screen: nil]; screen: nil];
GST_DEBUG("VideoSinkWindow created, %p", osxwindow->win);
[osxwindow->win autorelease]; [osxwindow->win autorelease];
[NSApplication sharedApplication]; [NSApplication sharedApplication];
[osxwindow->win makeKeyAndOrderFront:NSApp]; [osxwindow->win makeKeyAndOrderFront:NSApp];
@ -303,8 +305,8 @@ gst_osx_video_sink_osxwindow_new (GstOSXVideoSink * osxvideosink, gint width,
nil); nil);
tmp = gst_structure_to_string (s); tmp = gst_structure_to_string (s);
GST_DEBUG_OBJECT (osxvideosink, "Sending message %s", GST_DEBUG_OBJECT (osxvideosink, "Sending message %s (with view %p)",
tmp); tmp, osxwindow->gstview);
g_free (tmp); g_free (tmp);
msg = gst_message_new_element (GST_OBJECT (osxvideosink), s); msg = gst_message_new_element (GST_OBJECT (osxvideosink), s);
@ -340,7 +342,6 @@ static void
gst_osx_video_sink_osxwindow_resize (GstOSXVideoSink * osxvideosink, gst_osx_video_sink_osxwindow_resize (GstOSXVideoSink * osxvideosink,
GstOSXWindow * osxwindow, guint width, guint height) GstOSXWindow * osxwindow, guint width, guint height)
{ {
NSSize size;
NSAutoreleasePool *subPool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *subPool = [[NSAutoreleasePool alloc] init];
g_return_if_fail (osxwindow != NULL); g_return_if_fail (osxwindow != NULL);
g_return_if_fail (GST_IS_OSX_VIDEO_SINK (osxvideosink)); g_return_if_fail (GST_IS_OSX_VIDEO_SINK (osxvideosink));
@ -348,11 +349,23 @@ gst_osx_video_sink_osxwindow_resize (GstOSXVideoSink * osxvideosink,
osxwindow->width = width; osxwindow->width = width;
osxwindow->height = height; osxwindow->height = height;
size.width = width; GST_DEBUG_OBJECT (osxvideosink, "Resizing window to (%d,%d)", width, height);
size.height = height; if (osxwindow->win) {
/* Call relevant cocoa function to resize window */ /* Call relevant cocoa function to resize window */
[osxwindow->win setContentSize:size]; NSSize size;
[subPool release]; size.width = width;
size.height = height;
NSLog(@"osxwindow->win = %@", osxwindow->win);
GST_DEBUG_OBJECT (osxvideosink, "Calling setContentSize on %p", osxwindow->win);
[osxwindow->win setContentSize:size];
}
else {
/* Directly resize the underlying view */
GST_DEBUG_OBJECT (osxvideosink, "Calling setVideoSize on %p", osxwindow->gstview);
[osxwindow->gstview setVideoSize:width :height];
}
[subPool release];
} }
static void static void
@ -374,7 +387,6 @@ gst_osx_video_sink_setcaps (GstBaseSink * bsink, GstCaps * caps)
GstStructure *structure; GstStructure *structure;
gboolean res, result = FALSE; gboolean res, result = FALSE;
gint video_width, video_height; gint video_width, video_height;
const GValue *framerate;
osxvideosink = GST_OSX_VIDEO_SINK (bsink); osxvideosink = GST_OSX_VIDEO_SINK (bsink);
@ -383,18 +395,13 @@ gst_osx_video_sink_setcaps (GstBaseSink * bsink, GstCaps * caps)
structure = gst_caps_get_structure (caps, 0); structure = gst_caps_get_structure (caps, 0);
res = gst_structure_get_int (structure, "width", &video_width); res = gst_structure_get_int (structure, "width", &video_width);
res &= gst_structure_get_int (structure, "height", &video_height); res &= gst_structure_get_int (structure, "height", &video_height);
framerate = gst_structure_get_value (structure, "framerate");
res &= (framerate != NULL);
if (!res) { if (!res) {
goto beach; goto beach;
} }
osxvideosink->fps_n = gst_value_get_fraction_numerator (framerate); GST_DEBUG_OBJECT (osxvideosink, "our format is: %dx%d video",
osxvideosink->fps_d = gst_value_get_fraction_denominator (framerate); video_width, video_height);
GST_DEBUG_OBJECT (osxvideosink, "our format is: %dx%d video at %d/%d fps",
video_width, video_height, osxvideosink->fps_n, osxvideosink->fps_d);
GST_VIDEO_SINK_WIDTH (osxvideosink) = video_width; GST_VIDEO_SINK_WIDTH (osxvideosink) = video_width;
GST_VIDEO_SINK_HEIGHT (osxvideosink) = video_height; GST_VIDEO_SINK_HEIGHT (osxvideosink) = video_height;
@ -451,8 +458,6 @@ gst_osx_video_sink_change_state (GstElement * element,
case GST_STATE_CHANGE_PLAYING_TO_PAUSED: case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
break; break;
case GST_STATE_CHANGE_PAUSED_TO_READY: case GST_STATE_CHANGE_PAUSED_TO_READY:
osxvideosink->fps_n = 0;
osxvideosink->fps_d = 0;
osxvideosink->sw_scaling_failed = FALSE; osxvideosink->sw_scaling_failed = FALSE;
GST_VIDEO_SINK_WIDTH (osxvideosink) = 0; GST_VIDEO_SINK_WIDTH (osxvideosink) = 0;
GST_VIDEO_SINK_HEIGHT (osxvideosink) = 0; GST_VIDEO_SINK_HEIGHT (osxvideosink) = 0;
@ -549,9 +554,6 @@ gst_osx_video_sink_init (GstOSXVideoSink * osxvideosink)
osxvideosink->osxwindow = NULL; osxvideosink->osxwindow = NULL;
osxvideosink->fps_n = 0;
osxvideosink->fps_d = 0;
osxvideosink->pixel_width = osxvideosink->pixel_height = 1; osxvideosink->pixel_width = osxvideosink->pixel_height = 1;
osxvideosink->sw_scaling_failed = FALSE; osxvideosink->sw_scaling_failed = FALSE;
osxvideosink->embed = FALSE; osxvideosink->embed = FALSE;