[vlc-commits] [Git][videolan/vlc][master] 9 commits: macosx: use calloc() instead of vlc_obj_calloc()
Steve Lhomme (@robUx4)
gitlab at videolan.org
Wed Nov 20 06:32:28 UTC 2024
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
a87ea97f by Alexandre Janniaux at 2024-11-20T06:14:27+00:00
macosx: use calloc() instead of vlc_obj_calloc()
vlc_obj_calloc() will destroy the sys pointer at the object destruction
but we still need it asynchronously from the main thread on exit
- - - - -
4202208f by Alexandre Janniaux at 2024-11-20T06:14:27+00:00
video_output: Makefile.am: silence deprecation for macosx.m
- - - - -
edb95c8e by Alexandre Janniaux at 2024-11-20T06:14:27+00:00
macosx: fix flickering during rendering
[sys->glView render] will already swap the underlying buffer, so
swapping it again creates flickering issues.
- - - - -
65c514f4 by Alexandre Janniaux at 2024-11-20T06:14:27+00:00
video_output: macosx: initialize private part explicitely
- - - - -
635fd8e2 by Alexandre Janniaux at 2024-11-20T06:14:27+00:00
video_output: macosx: set has_first_frame under lock
This can be read from the main thread during rendering.
- - - - -
003a7404 by Alexandre Janniaux at 2024-11-20T06:14:27+00:00
macosx: use dispatch_sync instead of performSelector
libdispatch doesn't require an intermediate function with fixed
parameters and can use a block instead, which is much easier to read.
It also handle reference counting correctly.
- - - - -
5b21284d by Alexandre Janniaux at 2024-11-20T06:14:27+00:00
macosx: remove superfluous (id) casts
container is already an id object and will perform dynamic lookup for
the called selector.
- - - - -
d60c7f8f by Alexandre Janniaux at 2024-11-20T06:14:27+00:00
macosx: use dispatch_async instead of performSelector
libdispatch doesn't require an intermediate function with fixed
parameters and can use a block instead, which is much easier to read.
It also handle reference counting correctly.
- - - - -
8ef285a4 by Alexandre Janniaux at 2024-11-20T06:14:27+00:00
macosx: use automatic -fobjc-arc reference counting
ARC allows automatic reference counting, and thus automatic memory
management, simplifying the whole code.
- - - - -
2 changed files:
- modules/video_output/Makefile.am
- modules/video_output/macosx.m
Changes:
=====================================
modules/video_output/Makefile.am
=====================================
@@ -58,7 +58,8 @@ libwindow_macosx_plugin_la_OBJCFLAGS = $(AM_OBJCFLAGS) \
libvout_macosx_plugin_la_SOURCES = video_output/macosx.m \
$(OPENGL_VOUT_COMMONSOURCES)
-libvout_macosx_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) -DHAVE_GL_CORE_SYMBOLS
+libvout_macosx_plugin_la_OBJCFLAGS = $(AM_OBJCFLAGS) -fobjc-arc
+libvout_macosx_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) -DHAVE_GL_CORE_SYMBOLS -DGL_SILENCE_DEPRECATION
libvout_macosx_plugin_la_LIBADD = libvlc_opengl.la
libvout_macosx_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(voutdir)' \
-Wl,-framework,OpenGL,-framework,Cocoa
=====================================
modules/video_output/macosx.m
=====================================
@@ -145,32 +145,35 @@ static int Open (vout_display_t *vd,
if (vd->cfg->window->type != VLC_WINDOW_TYPE_NSOBJECT)
return VLC_EGENERIC;
- vout_display_sys_t *sys = vlc_obj_calloc (vd, 1, sizeof(*sys));
+ vout_display_sys_t *sys = calloc(1, sizeof(*sys));
if (!sys)
return VLC_ENOMEM;
sys->cfg = *vd->cfg;
+ sys->has_first_frame = false;
+ sys->current = NULL;
+ sys->vgl = NULL;
+ sys->gl = NULL;
@autoreleasepool {
if (!CGDisplayUsesOpenGLAcceleration (kCGDirectMainDisplay))
msg_Err (vd, "no OpenGL hardware acceleration found. this can lead to slow output and unexpected results");
vd->sys = sys;
- sys->vgl = NULL;
- sys->gl = NULL;
/* Get the drawable object */
- id container = vd->cfg->window->handle.nsobject;
+ id container = (__bridge id)vd->cfg->window->handle.nsobject;
assert(container != nil);
/* This will be released in Close(), on
* main thread, after we are done using it. */
- sys->container = [container retain];
+ sys->container = container;
/* Get our main view*/
- [VLCOpenGLVideoView performSelectorOnMainThread:@selector(getNewView:)
- withObject:[NSValue valueWithPointer:&sys->glView]
- waitUntilDone:YES];
+ dispatch_sync(dispatch_get_main_queue(), ^{
+ sys->glView = [[VLCOpenGLVideoView alloc] init];
+ });
+
if (!sys->glView) {
msg_Err(vd, "Initialization of open gl view failed");
goto error;
@@ -181,18 +184,17 @@ static int Open (vout_display_t *vd,
/* We don't wait, that means that we'll have to be careful about releasing
* container.
* That's why we'll release on main thread in Close(). */
- if ([(id)container respondsToSelector:@selector(addVoutSubview:)])
- [(id)container performSelectorOnMainThread:@selector(addVoutSubview:)
- withObject:sys->glView
- waitUntilDone:NO];
+ if ([container respondsToSelector:@selector(addVoutSubview:)]) {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [container addVoutSubview: sys->glView];
+ });
+ }
else if ([container isKindOfClass:[NSView class]]) {
- NSView *parentView = container;
- [parentView performSelectorOnMainThread:@selector(addSubview:)
- withObject:sys->glView
- waitUntilDone:NO];
- [sys->glView performSelectorOnMainThread:@selector(setFrameToBoundsOfView:)
- withObject:[NSValue valueWithPointer:parentView]
- waitUntilDone:NO];
+ dispatch_async(dispatch_get_main_queue(), ^{
+ NSView *parentView = container;
+ [parentView addSubview:sys->glView];
+ [sys->glView setFrame:[parentView bounds]];
+ });
} else {
msg_Err(vd, "Invalid drawable-nsobject object. drawable-nsobject must either be an NSView or comply to the @protocol VLCVideoViewEmbedding.");
goto error;
@@ -274,18 +276,17 @@ static void Close(vout_display_t *vd)
vlc_object_delete(sys->gl);
}
- VLCOpenGLVideoView *glView = sys->glView;
- id<VLCVideoViewEmbedding> viewContainer = sys->container;
dispatch_async(dispatch_get_main_queue(), ^{
- if ([viewContainer respondsToSelector:@selector(removeVoutSubview:)]) {
+ if ([sys->container respondsToSelector:@selector(removeVoutSubview:)]) {
/* This will retain sys->glView */
- [viewContainer removeVoutSubview:sys->glView];
+ [sys->container removeVoutSubview:sys->glView];
}
/* release on main thread as explained in Open() */
- [viewContainer release];
- [glView removeFromSuperview];
- [glView release];
+ sys->container = nil;
+ [sys->glView removeFromSuperview];
+ sys->glView = nil;
+ free(sys);
});
}
}
@@ -320,11 +321,10 @@ static void PictureDisplay (vout_display_t *vd, picture_t *pic)
{
[sys->glView render];
vlc_gl_ReleaseCurrent(sys->gl);
- vlc_gl_Swap(sys->gl);
}
[sys->glView setVoutFlushing:NO];
+ sys->has_first_frame = true;
}
- sys->has_first_frame = true;
}
static void UpdatePlace (vout_display_t *vd, const vout_display_cfg_t *cfg)
@@ -417,13 +417,6 @@ static void OpenglSwap (vlc_gl_t *gl)
#define VLCAssertMainThread() assert([[NSThread currentThread] isMainThread])
-
-+ (void)getNewView:(NSValue *)value
-{
- id *ret = [value pointerValue];
- *ret = [[self alloc] init];
-}
-
/**
* Gets called by the Open() method.
*/
@@ -451,7 +444,6 @@ static void OpenglSwap (vlc_gl_t *gl)
return nil;
self = [super initWithFrame:NSMakeRect(0,0,10,10) pixelFormat:fmt];
- [fmt release];
if (!self)
return nil;
@@ -489,16 +481,6 @@ static void OpenglSwap (vlc_gl_t *gl)
- (void)dealloc
{
[NSNotificationCenter.defaultCenter removeObserver:self];
- [super dealloc];
-}
-
-/**
- * Gets called by the Open() method.
- */
-- (void)setFrameToBoundsOfView:(NSValue *)value
-{
- NSView *parentView = [value pointerValue];
- [self setFrame:[parentView bounds]];
}
/**
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/c0ed1769104fada5166a37464b00a7595874770c...8ef285a45c58e90331ee947a664623c0800eb4d3
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/c0ed1769104fada5166a37464b00a7595874770c...8ef285a45c58e90331ee947a664623c0800eb4d3
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list