Commit cb6709c2 authored by Felix Paul Kühne's avatar Felix Paul Kühne

MediaThumbnailer: expand API to allow customized libvlc instances and optimize thumbnail targets

parent 2020c350
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#endif #endif
@class VLCMedia; @class VLCMedia;
@class VLCLibrary;
@protocol VLCMediaThumbnailerDelegate; @protocol VLCMediaThumbnailerDelegate;
@interface VLCMediaThumbnailer : NSObject { @interface VLCMediaThumbnailer : NSObject {
...@@ -44,11 +45,13 @@ ...@@ -44,11 +45,13 @@
} }
+ (VLCMediaThumbnailer *)thumbnailerWithMedia:(VLCMedia *)media andDelegate:(id<VLCMediaThumbnailerDelegate>)delegate; + (VLCMediaThumbnailer *)thumbnailerWithMedia:(VLCMedia *)media andDelegate:(id<VLCMediaThumbnailerDelegate>)delegate;
+ (VLCMediaThumbnailer *)thumbnailerWithMedia:(VLCMedia *)media delegate:(id<VLCMediaThumbnailerDelegate>)delegate andVLCLibrary:(VLCLibrary *)library;
- (void)fetchThumbnail; - (void)fetchThumbnail;
@property (readwrite, assign) id<VLCMediaThumbnailerDelegate> delegate; @property (readwrite, assign) id<VLCMediaThumbnailerDelegate> delegate;
@property (readwrite, retain) VLCMedia *media; @property (readwrite, retain) VLCMedia *media;
@property (readwrite, assign) CGImageRef thumbnail; @property (readwrite, assign) CGImageRef thumbnail;
@property (readwrite) void * libVLCinstance;
/** /**
* Thumbnail Height * Thumbnail Height
......
...@@ -104,6 +104,7 @@ static void * sharedInstance = nil; ...@@ -104,6 +104,7 @@ static void * sharedInstance = nil;
} }
unsigned argc = sizeof(lib_vlc_params)/sizeof(lib_vlc_params[0]); unsigned argc = sizeof(lib_vlc_params)/sizeof(lib_vlc_params[0]);
instance = libvlc_new(argc, lib_vlc_params); instance = libvlc_new(argc, lib_vlc_params);
libvlc_retain(instance);
NSAssert(instance, @"libvlc failed to initialize"); NSAssert(instance, @"libvlc failed to initialize");
} }
return self; return self;
......
...@@ -27,6 +27,9 @@ ...@@ -27,6 +27,9 @@
@interface VLCMediaThumbnailer () @interface VLCMediaThumbnailer ()
{
void * _internalLibVLCInstance;
}
- (void)didFetchThumbnail; - (void)didFetchThumbnail;
- (void)notifyDelegate; - (void)notifyDelegate;
- (void)fetchThumbnail; - (void)fetchThumbnail;
...@@ -47,7 +50,7 @@ static void *lock(void *opaque, void **pixels) ...@@ -47,7 +50,7 @@ static void *lock(void *opaque, void **pixels)
static const size_t kDefaultImageWidth = 320; static const size_t kDefaultImageWidth = 320;
static const size_t kDefaultImageHeight = 240; static const size_t kDefaultImageHeight = 240;
static const float kSnapshotPosition = 0.5; static const float kSnapshotPosition = 0.5;
static const long long kStandardStartTime = 30000; static const long long kStandardStartTime = 150000;
void unlock(void *opaque, void *picture, void *const *p_pixels) void unlock(void *opaque, void *picture, void *const *p_pixels)
{ {
...@@ -79,6 +82,19 @@ void unlock(void *opaque, void *picture, void *const *p_pixels) ...@@ -79,6 +82,19 @@ void unlock(void *opaque, void *picture, void *const *p_pixels)
id obj = [[[self class] alloc] init]; id obj = [[[self class] alloc] init];
[obj setMedia:media]; [obj setMedia:media];
[obj setDelegate:delegate]; [obj setDelegate:delegate];
[obj setLibVLCinstance:[VLCLibrary sharedInstance]];
return [obj autorelease];
}
+ (VLCMediaThumbnailer *)thumbnailerWithMedia:(VLCMedia *)media delegate:(id<VLCMediaThumbnailerDelegate>)delegate andVLCLibrary:(VLCLibrary *)library
{
id obj = [[[self class] alloc] init];
[obj setMedia:media];
[obj setDelegate:delegate];
if (library)
[obj setLibVLCinstance:library.instance];
else
[obj setLibVLCinstance:[VLCLibrary sharedInstance]];
return [obj autorelease]; return [obj autorelease];
} }
...@@ -91,9 +107,21 @@ void unlock(void *opaque, void *picture, void *const *p_pixels) ...@@ -91,9 +107,21 @@ void unlock(void *opaque, void *picture, void *const *p_pixels)
if (_thumbnail) if (_thumbnail)
CGImageRelease(_thumbnail); CGImageRelease(_thumbnail);
[_media release]; [_media release];
if (_internalLibVLCInstance)
libvlc_release(_internalLibVLCInstance);
[super dealloc]; [super dealloc];
} }
- (void)setLibVLCinstance:(void *)libVLCinstance
{
_internalLibVLCInstance = libVLCinstance;
libvlc_retain(_internalLibVLCInstance);
}
- (void *)libVLCinstance
{
return _internalLibVLCInstance;
}
- (void)fetchThumbnail - (void)fetchThumbnail
{ {
...@@ -165,12 +193,9 @@ void unlock(void *opaque, void *picture, void *const *p_pixels) ...@@ -165,12 +193,9 @@ void unlock(void *opaque, void *picture, void *const *p_pixels)
NSAssert(_data, @"Can't create data"); NSAssert(_data, @"Can't create data");
NSAssert(!_mp, @"We are already fetching a thumbnail"); NSAssert(!_mp, @"We are already fetching a thumbnail");
_mp = libvlc_media_player_new([VLCLibrary sharedInstance]); _mp = libvlc_media_player_new(self.libVLCinstance);
libvlc_media_add_option([_media libVLCMediaDescriptor], "no-audio"); libvlc_media_add_option([_media libVLCMediaDescriptor], "no-audio");
libvlc_media_add_option([_media libVLCMediaDescriptor], "avcodec-threads=1");
libvlc_media_add_option([_media libVLCMediaDescriptor], "avcodec-skip-frame=4");
libvlc_media_add_option([_media libVLCMediaDescriptor], "avcodec-skip-idct=2");
libvlc_media_player_set_media(_mp, [_media libVLCMediaDescriptor]); libvlc_media_player_set_media(_mp, [_media libVLCMediaDescriptor]);
libvlc_video_set_format(_mp, "RGBA", imageWidth, imageHeight, 4 * imageWidth); libvlc_video_set_format(_mp, "RGBA", imageWidth, imageHeight, 4 * imageWidth);
...@@ -223,7 +248,7 @@ void unlock(void *opaque, void *picture, void *const *p_pixels) ...@@ -223,7 +248,7 @@ void unlock(void *opaque, void *picture, void *const *p_pixels)
return; return;
} }
if (length < kStandardStartTime * 2 && _numberOfReceivedFrames < 3) { if (length < kStandardStartTime * 2 && _numberOfReceivedFrames < 3) {
libvlc_media_player_set_position(_mp, 0.1); libvlc_media_player_set_position(_mp, kSnapshotPosition);
return; return;
} }
if ((length > 1000 || position <= 0.0) && _numberOfReceivedFrames < 10) { if ((length > 1000 || position <= 0.0) && _numberOfReceivedFrames < 10) {
......
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