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
id <VLCMediaListDelegate,NSObject> __weak delegate; ///< Delegate object
/* We need that private copy because of Cocoa Bindings, that need to be working on first thread */
NSMutableArray *_mediaObjects; ///< Private copy of media objects.
dispatch_queue_t _serialMediaObjectsQueue; ///< Queue for accessing and modifying the mediaobjects
}
@end
......@@ -92,7 +91,6 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
// Initialize internals to defaults
_mediaObjects = [[NSMutableArray alloc] init];
_serialMediaObjectsQueue = dispatch_queue_create("org.videolan.serialMediaObjectsQueue", DISPATCH_QUEUE_SERIAL);
[self initInternalMediaList];
}
......@@ -155,9 +153,7 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
- (void)insertMedia:(VLCMedia *)media atIndex: (NSUInteger)index
{
// 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
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
- (void)removeMediaAtIndex:(NSUInteger)index
{
dispatch_async(_serialMediaObjectsQueue, ^{
if (index >= [_mediaObjects count])
return;
//remove from cached Media
[_mediaObjects removeObjectAtIndex:index];
});
if (index >= [_mediaObjects count])
return;
//remove from cached Media
[_mediaObjects removeObjectAtIndex:index];
// Remove it from libvlc's medialist
libvlc_media_list_remove_index(p_mlist, (int)index);
}
- (VLCMedia *)mediaAtIndex:(NSUInteger)index
{
__block VLCMedia *media;
dispatch_sync(_serialMediaObjectsQueue, ^{
media = index >= [_mediaObjects count] ? nil : [_mediaObjects objectAtIndex:index];
});
return media;
if (index >= [_mediaObjects count])
return nil;
return [_mediaObjects objectAtIndex:index];
}
- (NSInteger)indexOfMedia:(VLCMedia *)media
......@@ -205,11 +197,7 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
- (NSInteger)count
{
__block NSInteger count;
dispatch_sync(_serialMediaObjectsQueue, ^{
count = [_mediaObjects count];
});
return count;
return [_mediaObjects count];
}
- (void)insertObject:(VLCMedia *)object inMediaAtIndex:(NSUInteger)i
......@@ -244,14 +232,12 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
libvlc_media_list_retain( p_mlist );
libvlc_media_list_lock( 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);
for (int i = 0; i < count; i++) {
libvlc_media_t * p_md = libvlc_media_list_item_at_index(p_mlist, i);
dispatch_async(_serialMediaObjectsQueue, ^{
[_mediaObjects addObject:[VLCMedia mediaWithLibVLCMediaDescriptor:p_md]];
libvlc_media_release(p_md);
});
[_mediaObjects addObject:[VLCMedia mediaWithLibVLCMediaDescriptor:p_md]];
libvlc_media_release(p_md);
}
[self initInternalMediaList];
libvlc_media_list_unlock(p_mlist);
......@@ -288,23 +274,19 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
for (NSDictionary *args in arrayOfArgs) {
NSInteger index = [args[@"index"] intValue];
VLCMedia *tempMedia = args[@"media"];
__block 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
dispatch_sync(_serialMediaObjectsQueue, ^{
for (VLCMedia *media in _mediaObjects) {
if ([tempMedia.url isEqual:media.url]){
foundMedia = media;
break;
}
VLCMedia *foundMedia;
//we have two instances of VLCMedia. One from the event and the one we added to _mediaObjects, hence themcheck to avoid duplication
for (VLCMedia *media in _mediaObjects) {
if ([tempMedia.url isEqual:media.url]){
foundMedia = media;
}
});
}
if (!foundMedia) {
// In case we found Media on the network we don't have a cached copy yet
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:)])
[delegate mediaList:self mediaAdded:foundMedia atIndex:index];
......@@ -315,9 +297,7 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
- (void)mediaListItemRemoved:(NSNumber *)index
{
[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"];
// 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