[vlc-commits] windowsless mac: implement video output
Felix Paul Kühne
git at videolan.org
Mon Dec 31 18:34:58 CET 2012
npapi-vlc | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Mon Dec 31 18:34:17 2012 +0100| [8744425b1202526f4ee2066685e5abe061f81d36] | committer: Felix Paul Kühne
windowsless mac: implement video output
Note that the colors aren't quite correct yet
> http://git.videolan.org/gitweb.cgi/npapi-vlc.git/?a=commit;h=8744425b1202526f4ee2066685e5abe061f81d36
---
npapi/vlcplugin_base.cpp | 4 +--
npapi/vlcwindowless_mac.cpp | 58 ++++++++++++++++++++++++++++++++++++++++---
2 files changed, 56 insertions(+), 6 deletions(-)
diff --git a/npapi/vlcplugin_base.cpp b/npapi/vlcplugin_base.cpp
index 060607c..669539f 100644
--- a/npapi/vlcplugin_base.cpp
+++ b/npapi/vlcplugin_base.cpp
@@ -79,7 +79,7 @@ void VlcPluginBase::eventAsync(void *param)
void VlcPluginBase::event_callback(const libvlc_event_t* event,
NPVariant *npparams, uint32_t npcount)
{
-#if defined(XP_UNIX) || defined(XP_WIN)
+#if defined(XP_UNIX) || defined(XP_WIN) || defined (XP_MACOSX)
events.callback(event, npparams, npcount);
NPN_PluginThreadAsyncCall(getBrowser(), eventAsync, this);
#else
@@ -100,7 +100,7 @@ NPError VlcPluginBase::init(int argc, char* const argn[], char* const argv[])
/* locate VLC module path */
#ifdef XP_MACOSX
- ppsz_argv[ppsz_argc++] = "--vout=vout_macosx";
+ ppsz_argv[ppsz_argc++] = "--vout=vmem"; //vout_macosx";
#elif defined(XP_WIN)
HKEY h_key;
DWORD i_type, i_data = MAX_PATH + 1;
diff --git a/npapi/vlcwindowless_mac.cpp b/npapi/vlcwindowless_mac.cpp
index cb7d6ea..819d36f 100644
--- a/npapi/vlcwindowless_mac.cpp
+++ b/npapi/vlcwindowless_mac.cpp
@@ -55,7 +55,7 @@ void VlcWindowlessMac::drawBackground(NPCocoaEvent *cocoaEvent)
unsigned r = 0, g = 0, b = 0;
HTMLColor2RGB(get_options().get_bg_color().c_str(), &r, &g, &b);
- // draw a gray background
+ // draw background
CGContextAddRect(cgContext, CGRectMake(0, 0, windowWidth, windowHeight));
CGContextSetRGBFillColor(cgContext,r/255.,g/255.,b/255.,1.);
CGContextDrawPath(cgContext, kCGPathFill);
@@ -92,9 +92,6 @@ bool VlcWindowlessMac::handle_event(void *event)
}
if (eventType == NPCocoaEventDrawRect) {
- if (VlcPluginBase::playlist_isplaying() && VlcPluginBase::player_has_vout())
- return false;
-
CGContextRef cgContext = cocoaEvent->data.draw.context;
if (!cgContext) {
return false;
@@ -102,6 +99,59 @@ bool VlcWindowlessMac::handle_event(void *event)
drawBackground(cocoaEvent);
+ if(!VlcPluginBase::player_has_vout())
+ return true;
+
+ if (m_media_width == 0 || m_media_height == 0)
+ return true;
+
+ CGContextSaveGState(cgContext);
+
+ /* context is flipped */
+ CGContextTranslateCTM(cgContext, 0.0, npwindow.height);
+ CGContextScaleCTM(cgContext, 1., -1.);
+
+ /* Compute the position of the video */
+ float left = (npwindow.width - m_media_width) / 2.;
+ float top = (npwindow.height - m_media_height) / 2.;
+ static const size_t kComponentsPerPixel = 4;
+ static const size_t kBitsPerComponent = sizeof(unsigned char) * 8;
+
+
+ /* render frame */
+ CFDataRef dataRef = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault,
+ (const uint8_t *)&m_frame_buf[0],
+ sizeof(m_frame_buf[0]),
+ kCFAllocatorNull);
+ CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData(dataRef);
+ CGColorSpaceRef colorspace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGBLinear);
+ CGImageRef image = CGImageCreate(m_media_width,
+ m_media_height,
+ kBitsPerComponent,
+ kBitsPerComponent * kComponentsPerPixel,
+ kComponentsPerPixel * m_media_width,
+ colorspace,
+ kCGBitmapByteOrder16Big,
+ dataProvider,
+ NULL,
+ true,
+ kCGRenderingIntentPerceptual);
+ if (!image) {
+ CGColorSpaceRelease(colorspace);
+ CGImageRelease(image);
+ CGDataProviderRelease(dataProvider);
+ CGContextRestoreGState(cgContext);
+ return true;
+ }
+ CGRect rect = CGRectMake(left, top, m_media_width, m_media_height);
+ CGContextDrawImage(cgContext, rect, image);
+
+ CGColorSpaceRelease(colorspace);
+ CGImageRelease(image);
+ CGDataProviderRelease(dataProvider);
+
+ CGContextRestoreGState(cgContext);
+
return true;
}
More information about the vlc-commits
mailing list