[vlc-devel] [PATCH] macosx: Improve new VLCRenderer classes
Marvin Scholz
epirat07 at gmail.com
Fri Jun 17 16:40:34 CEST 2016
This fixes some issues with the new renderer classes
including an important fix for delete renderer discovery
item deletion events not being handled at all.
---
modules/gui/macosx/VLCRendererDiscovery.h | 15 ++++-----
modules/gui/macosx/VLCRendererDiscovery.m | 38 +++++++++++++---------
modules/gui/macosx/VLCRendererItem.h | 28 +++++++----------
modules/gui/macosx/VLCRendererItem.m | 52 +++++++++++++------------------
4 files changed, 62 insertions(+), 71 deletions(-)
diff --git a/modules/gui/macosx/VLCRendererDiscovery.h b/modules/gui/macosx/VLCRendererDiscovery.h
index a7f8f6a..1dd834f 100644
--- a/modules/gui/macosx/VLCRendererDiscovery.h
+++ b/modules/gui/macosx/VLCRendererDiscovery.h
@@ -63,9 +63,11 @@
Initialize the class with a renderer name and (optional) longname retrieved with
the \c vlc_rd_get_names function.
+ \note In case the renderer discovery service creation fails, nil is returned.
+
\param name Renderer name as C string
\param longname Renderer longname as C string
-
+
\returns Initialized class that already created the underlying
\c vlc_renderer_discovery structure or nil on failure.
*/
@@ -89,11 +91,6 @@
*/
- (void)stopDiscovery;
-- (void)dealloc;
-
-/* This should never be called! */
-- (void)handleEvent:(const vlc_event_t *)event;
-
@end
#pragma mark Delegate Protocol
@@ -102,11 +99,11 @@
to be implemented by a \c VLCRendererDiscovery delegate.
*/
@protocol VLCRendererDiscoveryDelegate
-
@required
+
/**
Invoked when a \c VLCRendererItem was added
-
+
\param item The renderer item that was added
\param sender The \c VLCRendererDiscovery object that added the Item.
@@ -124,4 +121,4 @@
*/
- (void)removedRendererItem:(VLCRendererItem *)item from:(VLCRendererDiscovery *)sender;
- at end
\ No newline at end of file
+ at end
diff --git a/modules/gui/macosx/VLCRendererDiscovery.m b/modules/gui/macosx/VLCRendererDiscovery.m
index 502eb6a..96050e8d 100644
--- a/modules/gui/macosx/VLCRendererDiscovery.m
+++ b/modules/gui/macosx/VLCRendererDiscovery.m
@@ -28,6 +28,15 @@
#include <vlc_common.h>
#include <vlc_renderer_discovery.h>
+ at interface VLCRendererDiscovery ()
+{
+ intf_thread_t *p_intf;
+ vlc_renderer_discovery *p_rd;
+}
+
+- (void)handleEvent:(const vlc_event_t *)event;
+ at end
+
// C callback event handler function for vlc_event_manager
static void renderer_event_received(const vlc_event_t *p_event, void *user_data)
{
@@ -35,10 +44,7 @@ static void renderer_event_received(const vlc_event_t *p_event, void *user_data)
[target handleEvent:p_event];
}
- at implementation VLCRendererDiscovery {
- intf_thread_t *p_intf;
- vlc_renderer_discovery *p_rd;
-}
+ at implementation VLCRendererDiscovery
- (instancetype)initWithName:(const char*)name andLongname:(const char*)longname
{
@@ -46,19 +52,21 @@ - (instancetype)initWithName:(const char*)name andLongname:(const char*)longname
if (self) {
if (!name)
- return nil;
+ [NSException raise:NSInvalidArgumentException
+ format:@"name must not be nil"];
// Create renderer object
p_intf = getIntf();
p_rd = vlc_rd_new(VLC_OBJECT(p_intf), name);
- if (!p_rd) {
+ if (p_rd) {
+ _name = [NSString stringWithUTF8String:name];
+ _longName = (!longname) ? nil : [NSString stringWithUTF8String:longname];
+ _discoveryStarted = false;
+ } else {
msg_Err(p_intf, "Could not create '%s' renderer discovery service", name);
- return nil;
+ self = nil;
}
- _name = toNSStr(name);
- _longName = (!longname) ? nil : toNSStr(longname);
- _discoveryStarted = false;
}
return self;
}
@@ -119,13 +127,15 @@ - (void)handleEvent:(const vlc_event_t *)event
[_delegate addedRendererItem:item from:self];
return;
}
- if (event->type == vlc_RendererDiscoveryItemAdded) {
+ if (event->type == vlc_RendererDiscoveryItemRemoved) {
vlc_renderer_item *base_item = event->u.renderer_discovery_item_removed.p_item;
VLCRendererItem *result_item = nil;
- for (VLCRendererItem *i in _rendererItems) {
- if ([i isBaseItemEqualTo:base_item])
- result_item = i;
+ for (VLCRendererItem *item in _rendererItems) {
+ if (item.rendererItem == base_item) {
+ result_item = item;
+ return;
+ }
}
if (result_item) {
[_rendererItems removeObject:result_item];
diff --git a/modules/gui/macosx/VLCRendererItem.h b/modules/gui/macosx/VLCRendererItem.h
index e8ccca3..e46618a 100644
--- a/modules/gui/macosx/VLCRendererItem.h
+++ b/modules/gui/macosx/VLCRendererItem.h
@@ -38,7 +38,11 @@
a \c vlc_renderer_discovery event.
*/
- (instancetype)initWithRendererItem:(vlc_renderer_item*)item;
-- (void)dealloc;
+
+/**
+ The underlying \c vlc_renderer_item item
+ */
+ at property (readonly) vlc_renderer_item* rendererItem;
/**
The name of the renderer item
@@ -48,42 +52,32 @@
/**
The iconURI of the renderer item
*/
-- (NSURL*)iconURI;
+- (NSString*)iconURI;
/**
Flags indicating capabilities of the renderer item
-
+
Compare it to:
\li \c VLC_RENDERER_CAN_AUDIO
\li \c VLC_RENDERER_CAN_VIDEO
*/
-- (int)flags;
+- (int)capabilityFlags;
/**
Checks if the Item’s sout string is equivalent to the given
sout string. If output is YES, it's checked if it's an
output sout as well.
-
+
\param sout The sout c string to compare with
\param output Indicates wether to check if sout is an output
-
+
\return YES if souts match the given sout and output, NO otherwise
*/
- (bool)isSoutEqualTo:(const char*)sout asOutput:(bool)output;
/**
- Compares the address of the internal \c vlc_renderer_item to the address
- of the specified item.
-
- \param item Item to compare with
-
- \return YES if items have the same address, NO otherwise
- */
-- (bool)isBaseItemEqualTo:(vlc_renderer_item*)item;
-
-/**
Sets the passed playlist’s sout to the sout of the \c VLCRendererItem.
-
+
\param playlist The playlist for which to set the sout
*/
- (void)setSoutForPlaylist:(playlist_t*)playlist;
diff --git a/modules/gui/macosx/VLCRendererItem.m b/modules/gui/macosx/VLCRendererItem.m
index a89c2c3..8d4f894 100644
--- a/modules/gui/macosx/VLCRendererItem.m
+++ b/modules/gui/macosx/VLCRendererItem.m
@@ -27,73 +27,63 @@
#include <vlc_common.h>
#include <vlc_renderer_discovery.h>
-
- at implementation VLCRendererItem {
- vlc_renderer_item *renderer_item;
-}
+ at implementation VLCRendererItem
- (instancetype)initWithRendererItem:(vlc_renderer_item*)item
{
self = [super init];
if (self) {
if (!item)
- return nil;
- renderer_item = vlc_renderer_item_hold(item);
+ [NSException raise:NSInvalidArgumentException
+ format:@"item must not be nil"];
+ _rendererItem = vlc_renderer_item_hold(item);
}
return self;
}
- (void)dealloc
{
- vlc_renderer_item_release(renderer_item);
+ vlc_renderer_item_release(_rendererItem);
}
- (NSString*)name
{
- const char *name = vlc_renderer_item_name(renderer_item);
+ const char *name = vlc_renderer_item_name(_rendererItem);
if (!name)
return nil;
- return toNSStr(name);
+ return [NSString stringWithUTF8String:name];
}
-- (NSURL*)iconURI
+- (NSString*)iconURI
{
- const char *uri = vlc_renderer_item_icon_uri(renderer_item);
+ const char *uri = vlc_renderer_item_icon_uri(_rendererItem);
if (!uri)
return nil;
- return [NSURL URLWithString:toNSStr(uri)];
+ return [NSString stringWithUTF8String:uri];
}
-- (int)flags
+- (int)capabilityFlags
{
- return vlc_renderer_item_flags(renderer_item);
+ return vlc_renderer_item_flags(_rendererItem);
}
- (bool)isSoutEqualTo:(const char*)sout asOutput:(bool)output
{
- NSString *tmp_sout;
- if (!sout)
- sout = "";
- const char *psz_out = vlc_renderer_item_sout(renderer_item);
- if (likely(psz_out != NULL)) {
- if (output) {
- tmp_sout = [NSString stringWithFormat:@"#%s", psz_out];
- } else {
- tmp_sout = toNSStr(psz_out);
- }
- }
- return (strcmp(tmp_sout.UTF8String, sout) == 0);
-}
+ NSString *temp_sout;
+ NSString *prefix;
+ NSString *self_sout;
-- (bool)isBaseItemEqualTo:(vlc_renderer_item*)item
-{
- return renderer_item == item;
+ prefix = (output) ? @"#" : @"";
+ self_sout = [prefix stringByAppendingString:toNSStr(vlc_renderer_item_sout(_rendererItem))];
+ temp_sout = toNSStr(sout);
+
+ return [temp_sout isEqualToString:self_sout];
}
- (void)setSoutForPlaylist:(playlist_t*)playlist
{
NSString *sout;
- const char *item_sout = vlc_renderer_item_sout(renderer_item);
+ const char *item_sout = vlc_renderer_item_sout(_rendererItem);
if (!playlist || !item_sout)
return;
--
2.7.4 (Apple Git-66)
More information about the vlc-devel
mailing list