Commit 5395720e authored by Felix Paul Kühne's avatar Felix Paul Kühne

windowed mac plugin: show last frame if input is paused and don't show branding when buffering

parent 8a21163b
...@@ -45,6 +45,9 @@ ...@@ -45,6 +45,9 @@
@interface VLCPlaybackLayer : CALayer { @interface VLCPlaybackLayer : CALayer {
CGColorSpaceRef _colorspace; CGColorSpaceRef _colorspace;
VlcPluginMac *_cppPlugin; VlcPluginMac *_cppPlugin;
CGImageRef _lastFrame;
int _cached_width;
int _cached_height;
} }
@property (readwrite) VlcPluginMac * cppPlugin; @property (readwrite) VlcPluginMac * cppPlugin;
...@@ -268,7 +271,9 @@ void VlcPluginMac::update_controls() ...@@ -268,7 +271,9 @@ void VlcPluginMac::update_controls()
[controllerLayer setIsPlaying: playlist_isplaying()]; [controllerLayer setIsPlaying: playlist_isplaying()];
[controllerLayer setIsFullscreen:this->get_fullscreen()]; [controllerLayer setIsFullscreen:this->get_fullscreen()];
if (player_has_vout()) {
libvlc_state_t currentstate = libvlc_media_player_get_state(getMD());
if (currentstate == libvlc_Playing || currentstate == libvlc_Paused || currentstate == libvlc_Opening) {
[noMediaLayer setHidden: YES]; [noMediaLayer setHidden: YES];
[playbackLayer setHidden: NO]; [playbackLayer setHidden: NO];
} else { } else {
...@@ -444,6 +449,8 @@ bool VlcPluginMac::handle_event(void *event) ...@@ -444,6 +449,8 @@ bool VlcPluginMac::handle_event(void *event)
- (void)dealloc - (void)dealloc
{ {
CGColorSpaceRelease(_colorspace); CGColorSpaceRelease(_colorspace);
if (_lastFrame)
CGImageRelease(_lastFrame);
[super dealloc]; [super dealloc];
} }
...@@ -452,14 +459,26 @@ bool VlcPluginMac::handle_event(void *event) ...@@ -452,14 +459,26 @@ bool VlcPluginMac::handle_event(void *event)
if (!cgContext) if (!cgContext)
return; return;
if (![self cppPlugin]->playlist_isplaying() || ![self cppPlugin]->player_has_vout()) BOOL b_paused = !([self cppPlugin]->playlist_isplaying());
if ((!_lastFrame && b_paused) || ![self cppPlugin]->get_player().is_open()) {
NSLog(@"no last frame or no open player");
return; return;
}
float media_width = [self cppPlugin]->m_media_width; float media_width = [self cppPlugin]->m_media_width;
float media_height = [self cppPlugin]->m_media_height; float media_height = [self cppPlugin]->m_media_height;
if (media_width == 0. || media_height == 0.) if (media_width == 0. || media_height == 0.) {
if (_cached_height != 0 && _cached_width != 0) {
media_width = _cached_width;
media_height = _cached_height;
} else
return; return;
} else {
_cached_width = media_width;
_cached_height = media_height;
}
CGRect layerRect = self.bounds; CGRect layerRect = self.bounds;
float display_width = 0.; float display_width = 0.;
...@@ -494,14 +513,18 @@ bool VlcPluginMac::handle_event(void *event) ...@@ -494,14 +513,18 @@ bool VlcPluginMac::handle_event(void *event)
static const size_t kComponentsPerPixel = 4; static const size_t kComponentsPerPixel = 4;
static const size_t kBitsPerComponent = sizeof(unsigned char) * 8; static const size_t kBitsPerComponent = sizeof(unsigned char) * 8;
/* render frame */ if (!b_paused) {
/* fetch frame */
CFDataRef dataRef = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, CFDataRef dataRef = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault,
(const uint8_t *)&[self cppPlugin]->m_frame_buf[0], (const uint8_t *)&[self cppPlugin]->m_frame_buf[0],
sizeof([self cppPlugin]->m_frame_buf[0]), sizeof([self cppPlugin]->m_frame_buf[0]),
kCFAllocatorNull); kCFAllocatorNull);
CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData(dataRef); CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData(dataRef);
CGImageRef image = CGImageCreate(media_width, if (_lastFrame)
CGImageRelease(_lastFrame);
_lastFrame = CGImageCreate(media_width,
media_height, media_height,
kBitsPerComponent, kBitsPerComponent,
kBitsPerComponent * kComponentsPerPixel, kBitsPerComponent * kComponentsPerPixel,
...@@ -512,17 +535,17 @@ bool VlcPluginMac::handle_event(void *event) ...@@ -512,17 +535,17 @@ bool VlcPluginMac::handle_event(void *event)
NULL, NULL,
true, true,
kCGRenderingIntentPerceptual); kCGRenderingIntentPerceptual);
if (!image) {
CGImageRelease(image);
CGDataProviderRelease(dataProvider); CGDataProviderRelease(dataProvider);
if (!_lastFrame) {
CGImageRelease(_lastFrame);
CGContextRestoreGState(cgContext); CGContextRestoreGState(cgContext);
return; return;
} }
}
CGRect rect = CGRectMake(left, top, display_width, display_height); CGRect rect = CGRectMake(left, top, display_width, display_height);
CGContextDrawImage(cgContext, rect, image); CGContextDrawImage(cgContext, rect, _lastFrame);
CGImageRelease(image);
CGDataProviderRelease(dataProvider);
CGContextRestoreGState(cgContext); CGContextRestoreGState(cgContext);
} }
......
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