Commit 86b9ae0f authored by Carola Nitz's avatar Carola Nitz

This introduced some out of bounds crashes and the addressed issue couldn't

be reproduced without this commit

Revert "VLCMedialist: moved _mediaObjects modification and readaccess to a queue"

This reverts commit 3cad0391.
parent b1b04183
...@@ -79,7 +79,6 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use ...@@ -79,7 +79,6 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
id <VLCMediaListDelegate,NSObject> __weak delegate; ///< Delegate object id <VLCMediaListDelegate,NSObject> __weak delegate; ///< Delegate object
/* We need that private copy because of Cocoa Bindings, that need to be working on first thread */ /* We need that private copy because of Cocoa Bindings, that need to be working on first thread */
NSMutableArray *_mediaObjects; ///< Private copy of media objects. NSMutableArray *_mediaObjects; ///< Private copy of media objects.
dispatch_queue_t _serialMediaObjectsQueue; ///< Queue for accessing and modifying the mediaobjects
} }
@end @end
...@@ -92,7 +91,6 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use ...@@ -92,7 +91,6 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
// Initialize internals to defaults // Initialize internals to defaults
_mediaObjects = [[NSMutableArray alloc] init]; _mediaObjects = [[NSMutableArray alloc] init];
_serialMediaObjectsQueue = dispatch_queue_create("org.videolan.serialMediaObjectsQueue", DISPATCH_QUEUE_SERIAL);
[self initInternalMediaList]; [self initInternalMediaList];
} }
...@@ -155,9 +153,7 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use ...@@ -155,9 +153,7 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
- (void)insertMedia:(VLCMedia *)media atIndex: (NSUInteger)index - (void)insertMedia:(VLCMedia *)media atIndex: (NSUInteger)index
{ {
// Add the media object to our cache // Add the media object to our cache
dispatch_async(_serialMediaObjectsQueue, ^{ [_mediaObjects insertObject:media atIndex:index];
[_mediaObjects insertObject:media atIndex:index];
});
// Add it to libvlc's medialist // Add it to libvlc's medialist
libvlc_media_list_insert_media(p_mlist, [media libVLCMediaDescriptor], (int)index); libvlc_media_list_insert_media(p_mlist, [media libVLCMediaDescriptor], (int)index);
...@@ -165,25 +161,21 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use ...@@ -165,25 +161,21 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
- (void)removeMediaAtIndex:(NSUInteger)index - (void)removeMediaAtIndex:(NSUInteger)index
{ {
dispatch_async(_serialMediaObjectsQueue, ^{ if (index >= [_mediaObjects count])
if (index >= [_mediaObjects count]) return;
return;
//remove from cached Media
[_mediaObjects removeObjectAtIndex:index];
});
//remove from cached Media
[_mediaObjects removeObjectAtIndex:index];
// Remove it from libvlc's medialist // Remove it from libvlc's medialist
libvlc_media_list_remove_index(p_mlist, (int)index); libvlc_media_list_remove_index(p_mlist, (int)index);
} }
- (VLCMedia *)mediaAtIndex:(NSUInteger)index - (VLCMedia *)mediaAtIndex:(NSUInteger)index
{ {
__block VLCMedia *media; if (index >= [_mediaObjects count])
dispatch_sync(_serialMediaObjectsQueue, ^{ return nil;
media = index >= [_mediaObjects count] ? nil : [_mediaObjects objectAtIndex:index];
}); return [_mediaObjects objectAtIndex:index];
return media;
} }
- (NSInteger)indexOfMedia:(VLCMedia *)media - (NSInteger)indexOfMedia:(VLCMedia *)media
...@@ -205,11 +197,7 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use ...@@ -205,11 +197,7 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
- (NSInteger)count - (NSInteger)count
{ {
__block NSInteger count; return [_mediaObjects count];
dispatch_sync(_serialMediaObjectsQueue, ^{
count = [_mediaObjects count];
});
return count;
} }
- (void)insertObject:(VLCMedia *)object inMediaAtIndex:(NSUInteger)i - (void)insertObject:(VLCMedia *)object inMediaAtIndex:(NSUInteger)i
...@@ -244,14 +232,12 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use ...@@ -244,14 +232,12 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
libvlc_media_list_retain( p_mlist ); libvlc_media_list_retain( p_mlist );
libvlc_media_list_lock( p_mlist ); libvlc_media_list_lock( p_mlist );
_mediaObjects = [[NSMutableArray alloc] initWithCapacity:libvlc_media_list_count(p_mlist)]; _mediaObjects = [[NSMutableArray alloc] initWithCapacity:libvlc_media_list_count(p_mlist)];
_serialMediaObjectsQueue = dispatch_queue_create("org.videolan.serialMediaObjectsQueue", NULL);
NSUInteger count = libvlc_media_list_count(p_mlist); NSUInteger count = libvlc_media_list_count(p_mlist);
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
libvlc_media_t * p_md = libvlc_media_list_item_at_index(p_mlist, i); libvlc_media_t * p_md = libvlc_media_list_item_at_index(p_mlist, i);
dispatch_async(_serialMediaObjectsQueue, ^{ [_mediaObjects addObject:[VLCMedia mediaWithLibVLCMediaDescriptor:p_md]];
[_mediaObjects addObject:[VLCMedia mediaWithLibVLCMediaDescriptor:p_md]]; libvlc_media_release(p_md);
libvlc_media_release(p_md);
});
} }
[self initInternalMediaList]; [self initInternalMediaList];
libvlc_media_list_unlock(p_mlist); libvlc_media_list_unlock(p_mlist);
...@@ -288,23 +274,19 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use ...@@ -288,23 +274,19 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
for (NSDictionary *args in arrayOfArgs) { for (NSDictionary *args in arrayOfArgs) {
NSInteger index = [args[@"index"] intValue]; NSInteger index = [args[@"index"] intValue];
VLCMedia *tempMedia = args[@"media"]; VLCMedia *tempMedia = args[@"media"];
__block VLCMedia *foundMedia; VLCMedia *foundMedia;
//we have two instances of VLCMedia. One from the event and the one we added to _mediaObjects, hence check them to avoid duplication //we have two instances of VLCMedia. One from the event and the one we added to _mediaObjects, hence themcheck to avoid duplication
dispatch_sync(_serialMediaObjectsQueue, ^{
for (VLCMedia *media in _mediaObjects) { for (VLCMedia *media in _mediaObjects) {
if ([tempMedia.url isEqual:media.url]){ if ([tempMedia.url isEqual:media.url]){
foundMedia = media; foundMedia = media;
break;
}
} }
}); }
if (!foundMedia) { if (!foundMedia) {
// In case we found Media on the network we don't have a cached copy yet // In case we found Media on the network we don't have a cached copy yet
foundMedia = tempMedia; foundMedia = tempMedia;
dispatch_sync(_serialMediaObjectsQueue, ^{ index >= [_mediaObjects count] ? [_mediaObjects addObject:foundMedia] : [_mediaObjects insertObject:foundMedia atIndex:index];
index >= [_mediaObjects count] ? [_mediaObjects addObject:foundMedia] : [_mediaObjects insertObject:foundMedia atIndex:index];
});
} }
if (delegate && [delegate respondsToSelector:@selector(mediaList:mediaAdded:atIndex:)]) if (delegate && [delegate respondsToSelector:@selector(mediaList:mediaAdded:atIndex:)])
[delegate mediaList:self mediaAdded:foundMedia atIndex:index]; [delegate mediaList:self mediaAdded:foundMedia atIndex:index];
...@@ -315,9 +297,7 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use ...@@ -315,9 +297,7 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
- (void)mediaListItemRemoved:(NSNumber *)index - (void)mediaListItemRemoved:(NSNumber *)index
{ {
[self willChange:NSKeyValueChangeRemoval valuesAtIndexes:[NSIndexSet indexSetWithIndex:[index intValue]] forKey:@"media"]; [self willChange:NSKeyValueChangeRemoval valuesAtIndexes:[NSIndexSet indexSetWithIndex:[index intValue]] forKey:@"media"];
dispatch_async(_serialMediaObjectsQueue, ^{ [_mediaObjects removeObjectAtIndex:[index intValue]];
[_mediaObjects removeObjectAtIndex:[index intValue]];
});
[self didChange:NSKeyValueChangeRemoval valuesAtIndexes:[NSIndexSet indexSetWithIndex:[index intValue]] forKey:@"media"]; [self didChange:NSKeyValueChangeRemoval valuesAtIndexes:[NSIndexSet indexSetWithIndex:[index intValue]] forKey:@"media"];
// Post the notification // Post the notification
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment