]> git.sesse.net Git - vlc/blob - projects/mozilla/vlcplugin.cpp
mozilla: protect calls to libvlc_playlist_isplaying()
[vlc] / projects / mozilla / vlcplugin.cpp
1 /*****************************************************************************
2  * vlcplugin.cpp: a VLC plugin for Mozilla
3  *****************************************************************************
4  * Copyright (C) 2002-2009 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *          Damien Fouilleul <damienf.fouilleul@laposte.net>
9  *          Jean-Paul Saman <jpsaman@videolan.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 /*****************************************************************************
27  * Preamble
28  *****************************************************************************/
29 #include "config.h"
30
31 #ifdef HAVE_MOZILLA_CONFIG_H
32 #   include <mozilla-config.h>
33 #endif
34
35 #include "vlcplugin.h"
36 #include "control/npolibvlc.h"
37
38 #include <ctype.h>
39
40 /*****************************************************************************
41  * VlcPlugin constructor and destructor
42  *****************************************************************************/
43 VlcPlugin::VlcPlugin( NPP instance, uint16 mode ) :
44     i_npmode(mode),
45     b_stream(0),
46     b_autoplay(1),
47     b_toolbar(0),
48     psz_target(NULL),
49     libvlc_instance(NULL),
50     libvlc_log(NULL),
51     p_scriptClass(NULL),
52     p_browser(instance),
53     psz_baseURL(NULL)
54 #if XP_WIN
55     ,pf_wndproc(NULL)
56 #endif
57 #if XP_UNIX
58     ,i_width((unsigned)-1)
59     ,i_height((unsigned)-1)
60     ,i_tb_width(0)
61     ,i_tb_height(0)
62     ,i_last_position(0)
63     ,p_btnPlay(NULL)
64     ,p_btnPause(NULL)
65     ,p_btnStop(NULL)
66     ,p_btnMute(NULL)
67     ,p_btnUnmute(NULL)
68     ,p_btnFullscreen(NULL)
69     ,p_btnTime(NULL)
70     ,p_timeline(NULL)
71 #endif
72 {
73     memset(&npwindow, 0, sizeof(NPWindow));
74 }
75
76 static bool boolValue(const char *value) {
77     return ( !strcmp(value, "1") ||
78              !strcasecmp(value, "true") ||
79              !strcasecmp(value, "yes") );
80 }
81
82 NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
83 {
84     /* prepare VLC command line */
85     const char *ppsz_argv[32];
86     int ppsz_argc = 0;
87
88     /* locate VLC module path */
89 #ifdef XP_MACOSX
90     ppsz_argv[ppsz_argc++] = "--plugin-path=/Library/Internet\\ Plug-Ins/VLC\\ Plugin.plugin/Contents/MacOS/modules";
91     ppsz_argv[ppsz_argc++] = "--vout=macosx";
92 #elif defined(XP_WIN)
93     HKEY h_key;
94     DWORD i_type, i_data = MAX_PATH + 1;
95     char p_data[MAX_PATH + 1];
96     if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\VideoLAN\\VLC",
97                       0, KEY_READ, &h_key ) == ERROR_SUCCESS )
98     {
99          if( RegQueryValueEx( h_key, "InstallDir", 0, &i_type,
100                               (LPBYTE)p_data, &i_data ) == ERROR_SUCCESS )
101          {
102              if( i_type == REG_SZ )
103              {
104                  strcat( p_data, "\\plugins" );
105                  ppsz_argv[ppsz_argc++] = "--plugin-path";
106                  ppsz_argv[ppsz_argc++] = p_data;
107              }
108          }
109          RegCloseKey( h_key );
110     }
111     ppsz_argv[ppsz_argc++] = "--no-one-instance";
112
113 #endif /* XP_MACOSX */
114
115     /* common settings */
116     ppsz_argv[ppsz_argc++] = "-vv";
117     ppsz_argv[ppsz_argc++] = "--no-stats";
118     ppsz_argv[ppsz_argc++] = "--no-media-library";
119     ppsz_argv[ppsz_argc++] = "--ignore-config";
120     ppsz_argv[ppsz_argc++] = "--intf=dummy";
121     const char *progid = NULL;
122
123     /* parse plugin arguments */
124     for( int i = 0; i < argc ; i++ )
125     {
126         fprintf(stderr, "argn=%s, argv=%s\n", argn[i], argv[i]);
127
128         if( !strcmp( argn[i], "target" )
129          || !strcmp( argn[i], "mrl")
130          || !strcmp( argn[i], "filename")
131          || !strcmp( argn[i], "src") )
132         {
133             psz_target = argv[i];
134         }
135         else if( !strcmp( argn[i], "autoplay")
136               || !strcmp( argn[i], "autostart") )
137         {
138             b_autoplay = boolValue(argv[i]);
139         }
140         else if( !strcmp( argn[i], "fullscreen" ) )
141         {
142             if( boolValue(argv[i]) )
143             {
144                 ppsz_argv[ppsz_argc++] = "--fullscreen";
145             }
146             else
147             {
148                 ppsz_argv[ppsz_argc++] = "--no-fullscreen";
149             }
150         }
151         else if( !strcmp( argn[i], "mute" ) )
152         {
153             if( boolValue(argv[i]) )
154             {
155                 ppsz_argv[ppsz_argc++] = "--volume";
156                 ppsz_argv[ppsz_argc++] = "0";
157             }
158         }
159         else if( !strcmp( argn[i], "loop")
160               || !strcmp( argn[i], "autoloop") )
161         {
162             if( boolValue(argv[i]) )
163             {
164                 ppsz_argv[ppsz_argc++] = "--loop";
165             }
166             else
167             {
168                 ppsz_argv[ppsz_argc++] = "--no-loop";
169             }
170         }
171         else if( !strcmp( argn[i], "version")
172               || !strcmp( argn[i], "progid") )
173         {
174             progid = argv[i];
175         }
176         else if( !strcmp( argn[i], "toolbar" ) )
177         {
178 /* FIXME: Remove this when toolbar functionality has been implemented on\
179  * MacOS X and Win32 for Firefox/Mozilla/Safari. */
180 #ifdef XP_UNIX
181             b_toolbar = boolValue(argv[i]);
182 #endif
183         }
184     }
185
186     libvlc_exception_t ex;
187     libvlc_exception_init(&ex);
188
189     libvlc_instance = libvlc_new(ppsz_argc, ppsz_argv, &ex);
190     if( libvlc_exception_raised(&ex) )
191     {
192         libvlc_exception_clear(&ex);
193         return NPERR_GENERIC_ERROR;
194     }
195     libvlc_exception_clear(&ex);
196
197     /*
198     ** fetch plugin base URL, which is the URL of the page containing the plugin
199     ** this URL is used for making absolute URL from relative URL that may be
200     ** passed as an MRL argument
201     */
202     NPObject *plugin;
203
204     if( NPERR_NO_ERROR == NPN_GetValue(p_browser, NPNVWindowNPObject, &plugin) )
205     {
206         /*
207         ** is there a better way to get that info ?
208         */
209         static const char docLocHref[] = "document.location.href";
210         NPString script;
211         NPVariant result;
212
213         script.utf8characters = docLocHref;
214         script.utf8length = sizeof(docLocHref)-1;
215
216         if( NPN_Evaluate(p_browser, plugin, &script, &result) )
217         {
218             if( NPVARIANT_IS_STRING(result) )
219             {
220                 NPString &location = NPVARIANT_TO_STRING(result);
221
222                 psz_baseURL = static_cast<char*>(malloc(location.utf8length+1));
223                 if( psz_baseURL )
224                 {
225                     strncpy(psz_baseURL, location.utf8characters, location.utf8length);
226                     psz_baseURL[location.utf8length] = '\0';
227                 }
228             }
229             NPN_ReleaseVariantValue(&result);
230         }
231         NPN_ReleaseObject(plugin);
232     }
233
234     if( psz_target )
235     {
236         // get absolute URL from src
237         char *psz_absurl = getAbsoluteURL(psz_target);
238         psz_target = psz_absurl ? psz_absurl : strdup(psz_target);
239     }
240
241     /* assign plugin script root class */
242     /* new APIs */
243     p_scriptClass = RuntimeNPClass<LibvlcRootNPObject>::getClass();
244
245     return NPERR_NO_ERROR;
246 }
247
248 VlcPlugin::~VlcPlugin()
249 {
250     free(psz_baseURL);
251     free(psz_target);
252     if( libvlc_log )
253         libvlc_log_close(libvlc_log, NULL);
254     if( libvlc_instance )
255         libvlc_release(libvlc_instance);
256 }
257
258 /*****************************************************************************
259  * VlcPlugin methods
260  *****************************************************************************/
261
262 char *VlcPlugin::getAbsoluteURL(const char *url)
263 {
264     if( NULL != url )
265     {
266         // check whether URL is already absolute
267         const char *end=strchr(url, ':');
268         if( (NULL != end) && (end != url) )
269         {
270             // validate protocol header
271             const char *start = url;
272             char c = *start;
273             if( isalpha(c) )
274             {
275                 ++start;
276                 while( start != end )
277                 {
278                     c  = *start;
279                     if( ! (isalnum(c)
280                        || ('-' == c)
281                        || ('+' == c)
282                        || ('.' == c)
283                        || ('/' == c)) ) /* VLC uses / to allow user to specify a demuxer */
284                         // not valid protocol header, assume relative URL
285                         goto relativeurl;
286                     ++start;
287                 }
288                 /* we have a protocol header, therefore URL is absolute */
289                 return strdup(url);
290             }
291             // not a valid protocol header, assume relative URL
292         }
293
294 relativeurl:
295
296         if( psz_baseURL )
297         {
298             size_t baseLen = strlen(psz_baseURL);
299             char *href = static_cast<char*>(malloc(baseLen+strlen(url)+1));
300             if( href )
301             {
302                 /* prepend base URL */
303                 strcpy(href, psz_baseURL);
304
305                 /*
306                 ** relative url could be empty,
307                 ** in which case return base URL
308                 */
309                 if( '\0' == *url )
310                     return href;
311
312                 /*
313                 ** locate pathname part of base URL
314                 */
315
316                 /* skip over protocol part  */
317                 char *pathstart = strchr(href, ':');
318                 char *pathend;
319                 if( pathstart )
320                 {
321                     if( '/' == *(++pathstart) )
322                     {
323                         if( '/' == *(++pathstart) )
324                         {
325                             ++pathstart;
326                         }
327                     }
328                     /* skip over host part */
329                     pathstart = strchr(pathstart, '/');
330                     pathend = href+baseLen;
331                     if( ! pathstart )
332                     {
333                         // no path, add a / past end of url (over '\0')
334                         pathstart = pathend;
335                         *pathstart = '/';
336                     }
337                 }
338                 else
339                 {
340                     /* baseURL is just a UNIX path */
341                     if( '/' != *href )
342                     {
343                         /* baseURL is not an absolute path */
344                         free(href);
345                         return NULL;
346                     }
347                     pathstart = href;
348                     pathend = href+baseLen;
349                 }
350
351                 /* relative URL made of an absolute path ? */
352                 if( '/' == *url )
353                 {
354                     /* replace path completely */
355                     strcpy(pathstart, url);
356                     return href;
357                 }
358
359                 /* find last path component and replace it */
360                 while( '/' != *pathend)
361                     --pathend;
362
363                 /*
364                 ** if relative url path starts with one or more '../',
365                 ** factor them out of href so that we return a
366                 ** normalized URL
367                 */
368                 while( pathend != pathstart )
369                 {
370                     const char *p = url;
371                     if( '.' != *p )
372                         break;
373                     ++p;
374                     if( '\0' == *p  )
375                     {
376                         /* relative url is just '.' */
377                         url = p;
378                         break;
379                     }
380                     if( '/' == *p  )
381                     {
382                         /* relative url starts with './' */
383                         url = ++p;
384                         continue;
385                     }
386                     if( '.' != *p )
387                         break;
388                     ++p;
389                     if( '\0' == *p )
390                     {
391                         /* relative url is '..' */
392                     }
393                     else
394                     {
395                         if( '/' != *p )
396                             break;
397                         /* relative url starts with '../' */
398                         ++p;
399                     }
400                     url = p;
401                     do
402                     {
403                         --pathend;
404                     }
405                     while( '/' != *pathend );
406                 }
407                 /* skip over '/' separator */
408                 ++pathend;
409                 /* concatenate remaining base URL and relative URL */
410                 strcpy(pathend, url);
411             }
412             return href;
413         }
414     }
415     return NULL;
416 }
417
418 #if XP_UNIX
419 int  VlcPlugin::setSize(unsigned width, unsigned height)
420 {
421     int diff = (width != i_width) || (height != i_height);
422
423     i_width = width;
424     i_height = height;
425
426     /* return size */
427     return diff;
428 }
429
430 #define BTN_SPACE ((unsigned int)4)
431 void VlcPlugin::showToolbar()
432 {
433     const NPWindow& window = getWindow();
434     Window control = getControlWindow();
435     Window video = getVideoWindow();
436     Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
437     unsigned int i_height = 0, i_width = BTN_SPACE;
438
439     /* load icons */
440     if( !p_btnPlay )
441         XpmReadFileToImage( p_display, DATA_PATH "/mozilla/play.xpm",
442                             &p_btnPlay, NULL, NULL);
443     if( p_btnPlay )
444     {
445         i_height = __MAX( i_height, p_btnPlay->height );
446     }
447     if( !p_btnPause )
448         XpmReadFileToImage( p_display, DATA_PATH "/mozilla/pause.xpm",
449                             &p_btnPause, NULL, NULL);
450     if( p_btnPause )
451     {
452         i_height = __MAX( i_height, p_btnPause->height );
453     }
454     i_width += __MAX( p_btnPause->width, p_btnPlay->width );
455
456     if( !p_btnStop )
457         XpmReadFileToImage( p_display, DATA_PATH "/mozilla/stop.xpm",
458                             &p_btnStop, NULL, NULL );
459     if( p_btnStop )
460     {
461         i_height = __MAX( i_height, p_btnStop->height );
462         i_width += BTN_SPACE + p_btnStop->width;
463     }
464     if( !p_timeline )
465         XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_line.xpm",
466                             &p_timeline, NULL, NULL);
467     if( p_timeline )
468     {
469         i_height = __MAX( i_height, p_timeline->height );
470         i_width += BTN_SPACE + p_timeline->width;
471     }
472     if( !p_btnTime )
473         XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_icon.xpm",
474                             &p_btnTime, NULL, NULL);
475     if( p_btnTime )
476     {
477         i_height = __MAX( i_height, p_btnTime->height );
478         i_width += BTN_SPACE + p_btnTime->width;
479     }
480     if( !p_btnFullscreen )
481         XpmReadFileToImage( p_display, DATA_PATH "/mozilla/fullscreen.xpm",
482                             &p_btnFullscreen, NULL, NULL);
483     if( p_btnFullscreen )
484     {
485         i_height = __MAX( i_height, p_btnFullscreen->height );
486         i_width += BTN_SPACE + p_btnFullscreen->width;
487     }
488     if( !p_btnMute )
489         XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_max.xpm",
490                             &p_btnMute, NULL, NULL);
491     if( p_btnMute )
492     {
493         i_height = __MAX( i_height, p_btnMute->height );
494     }
495     if( !p_btnUnmute )
496         XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_mute.xpm",
497                             &p_btnUnmute, NULL, NULL);
498     if( p_btnUnmute )
499     {
500         i_height = __MAX( i_height, p_btnUnmute->height );
501     }
502     i_width += BTN_SPACE + __MAX( p_btnUnmute->width, p_btnMute->width );
503
504     setToolbarSize( i_width, i_height );
505
506     if( !p_btnPlay || !p_btnPause || !p_btnStop || !p_timeline ||
507         !p_btnTime || !p_btnFullscreen || !p_btnMute || !p_btnUnmute )
508         fprintf(stderr, "Error: some button images not found in %s\n", DATA_PATH );
509
510     /* reset panels position and size */
511     /* XXX  use i_width */
512     XResizeWindow( p_display, video, window.width, window.height - i_height);
513     XMoveWindow( p_display, control, 0, window.height - i_height );
514     XResizeWindow( p_display, control, window.width, i_height -1);
515
516     b_toolbar = 1; /* says toolbar is now shown */
517     redrawToolbar();
518 }
519
520 void VlcPlugin::hideToolbar()
521 {
522     const NPWindow& window = getWindow();
523     Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
524     Window control = getControlWindow();
525     Window video = getVideoWindow();
526
527     i_tb_width = i_tb_height = 0;
528
529     if( p_btnPlay )  XDestroyImage( p_btnPlay );
530     if( p_btnPause ) XDestroyImage( p_btnPause );
531     if( p_btnStop )  XDestroyImage( p_btnStop );
532     if( p_timeline ) XDestroyImage( p_timeline );
533     if( p_btnTime )  XDestroyImage( p_btnTime );
534     if( p_btnFullscreen ) XDestroyImage( p_btnFullscreen );
535     if( p_btnMute )  XDestroyImage( p_btnMute );
536     if( p_btnUnmute ) XDestroyImage( p_btnUnmute );
537
538     p_btnPlay = NULL;
539     p_btnPause = NULL;
540     p_btnStop = NULL;
541     p_timeline = NULL;
542     p_btnTime = NULL;
543     p_btnFullscreen = NULL;
544     p_btnMute = NULL;
545     p_btnUnmute = NULL;
546
547     /* reset panels position and size */
548     /* XXX  use i_width */
549     XResizeWindow( p_display, video, window.width, window.height );
550     XMoveWindow( p_display, control, 0, window.height-1 );
551     XResizeWindow( p_display, control, window.width, 1 );
552
553     b_toolbar = 0; /* says toolbar is now hidden */
554     redrawToolbar();
555 }
556
557 void VlcPlugin::redrawToolbar()
558 {
559     libvlc_media_player_t *p_md = NULL;
560     libvlc_exception_t ex;
561     float f_position = 0.0;
562     int is_playing = 0;
563     bool b_mute = false;
564     unsigned int dst_x, dst_y;
565     GC gc;
566     XGCValues gcv;
567     unsigned int i_tb_width, i_tb_height;
568
569     /* This method does nothing if toolbar is hidden. */
570     if( !b_toolbar )
571         return;
572
573     const NPWindow& window = getWindow();
574     Window control = getControlWindow();
575     Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
576
577     getToolbarSize( &i_tb_width, &i_tb_height );
578
579     /* get media instance */
580     libvlc_exception_init( &ex );
581     p_md = libvlc_playlist_get_media_player( getVLC(), &ex );
582     libvlc_exception_clear( &ex );
583     if( p_md )
584     {
585         /* get isplaying */
586         libvlc_playlist_lock( getVLC() );
587         is_playing = libvlc_playlist_isplaying( getVLC(), &ex );
588         libvlc_playlist_unlock( getVLC() );
589         libvlc_exception_clear( &ex );
590
591         /* get movie position in % */
592         if( is_playing == 1 )
593         {
594             f_position = libvlc_media_player_get_position( p_md, &ex ) * 100.0;
595             libvlc_exception_clear( &ex );
596         }
597         libvlc_media_player_release( p_md );
598     }
599
600     /* get mute info */
601     b_mute = libvlc_audio_get_mute( getVLC(), &ex );
602     libvlc_exception_clear( &ex );
603
604     gcv.foreground = BlackPixel( p_display, 0 );
605     gc = XCreateGC( p_display, control, GCForeground, &gcv );
606
607     XFillRectangle( p_display, control, gc,
608                     0, 0, window.width, i_tb_height );
609     gcv.foreground = WhitePixel( p_display, 0 );
610     XChangeGC( p_display, gc, GCForeground, &gcv );
611
612     /* position icons */
613     dst_x = BTN_SPACE;
614     dst_y = i_tb_height >> 1; /* baseline = vertical middle */
615
616     if( p_btnPause && (is_playing == 1) )
617     {
618         XPutImage( p_display, control, gc, p_btnPause, 0, 0, dst_x,
619                    dst_y - (p_btnPause->height >> 1),
620                    p_btnPause->width, p_btnPause->height );
621         dst_x += BTN_SPACE + p_btnPause->width;
622     }
623     else if( p_btnPlay )
624     {
625         XPutImage( p_display, control, gc, p_btnPlay, 0, 0, dst_x,
626                    dst_y - (p_btnPlay->height >> 1),
627                    p_btnPlay->width, p_btnPlay->height );
628         dst_x += BTN_SPACE + p_btnPlay->width;
629     }
630
631     if( p_btnStop )
632         XPutImage( p_display, control, gc, p_btnStop, 0, 0, dst_x,
633                    dst_y - (p_btnStop->height >> 1),
634                    p_btnStop->width, p_btnStop->height );
635
636     dst_x += BTN_SPACE + ( p_btnStop ? p_btnStop->width : 0 );
637
638     if( p_btnFullscreen )
639         XPutImage( p_display, control, gc, p_btnFullscreen, 0, 0, dst_x,
640                    dst_y - (p_btnFullscreen->height >> 1),
641                    p_btnFullscreen->width, p_btnFullscreen->height );
642
643     dst_x += BTN_SPACE + ( p_btnFullscreen ? p_btnFullscreen->width : 0 );
644
645     if( p_btnUnmute && b_mute )
646     {
647         XPutImage( p_display, control, gc, p_btnUnmute, 0, 0, dst_x,
648                    dst_y - (p_btnUnmute->height >> 1),
649                    p_btnUnmute->width, p_btnUnmute->height );
650
651         dst_x += BTN_SPACE + ( p_btnUnmute ? p_btnUnmute->width : 0 );
652     }
653     else if( p_btnMute )
654     {
655         XPutImage( p_display, control, gc, p_btnMute, 0, 0, dst_x,
656                    dst_y - (p_btnMute->height >> 1),
657                    p_btnMute->width, p_btnMute->height );
658
659         dst_x += BTN_SPACE + ( p_btnMute ? p_btnMute->width : 0 );
660     }
661
662     if( p_timeline )
663         XPutImage( p_display, control, gc, p_timeline, 0, 0, dst_x,
664                    dst_y - (p_timeline->height >> 1),
665                    (window.width-(dst_x+BTN_SPACE)), p_timeline->height );
666
667     if( f_position > 0 )
668         i_last_position = (int)( f_position *
669                         ( ((float)(window.width-(dst_x+BTN_SPACE))) / 100.0 ));
670
671     if( p_btnTime )
672         XPutImage( p_display, control, gc, p_btnTime,
673                    0, 0, (dst_x+i_last_position),
674                    dst_y - (p_btnTime->height >> 1),
675                    p_btnTime->width, p_btnTime->height );
676
677     XFreeGC( p_display, gc );
678 }
679
680 vlc_toolbar_clicked_t VlcPlugin::getToolbarButtonClicked( int i_xpos, int i_ypos )
681 {
682     unsigned int i_dest = BTN_SPACE;//(i_tb_height >> 1);
683     int is_playing = 0;
684     bool b_mute = false;
685     libvlc_exception_t ex;
686
687     fprintf( stderr, "ToolbarButtonClicked:: "
688                      "trying to match (%d,%d) (%d,%d)\n",
689              i_xpos, i_ypos, i_tb_height, i_tb_width );
690
691     if( i_ypos >= i_tb_width )
692         return clicked_Unknown;
693
694     /* Note: the order of testing is dependend on the original
695      * drawing positions of the icon buttons. Buttons are tested
696      * left to right.
697      */
698
699     /* get isplaying */
700     libvlc_exception_init( &ex );
701     libvlc_playlist_lock( getVLC() );
702     is_playing = libvlc_playlist_isplaying( getVLC(), &ex );
703     libvlc_playlist_unlock( getVLC() );
704     libvlc_exception_clear( &ex );
705
706     /* get mute info */
707     b_mute = libvlc_audio_get_mute( getVLC(), &ex );
708     libvlc_exception_clear( &ex );
709
710     /* is Pause of Play button clicked */
711     if( (is_playing != 1) &&
712         (i_xpos >= (BTN_SPACE>>1)) &&
713         (i_xpos <= i_dest + p_btnPlay->width + (BTN_SPACE>>1)) )
714         return clicked_Play;
715     else if( (i_xpos >= (BTN_SPACE>>1))  &&
716              (i_xpos <= i_dest + p_btnPause->width) )
717         return clicked_Pause;
718
719     /* is Stop button clicked */
720     if( is_playing != 1 )
721         i_dest += (p_btnPlay->width + (BTN_SPACE>>1));
722     else
723         i_dest += (p_btnPause->width + (BTN_SPACE>>1));
724
725     if( (i_xpos >= i_dest) &&
726         (i_xpos <= i_dest + p_btnStop->width + (BTN_SPACE>>1)) )
727         return clicked_Stop;
728
729     /* is Fullscreen button clicked */
730     i_dest += (p_btnStop->width + (BTN_SPACE>>1));
731     if( (i_xpos >= i_dest) &&
732         (i_xpos <= i_dest + p_btnFullscreen->width + (BTN_SPACE>>1)) )
733         return clicked_Fullscreen;
734
735     /* is Mute or Unmute button clicked */
736     i_dest += (p_btnFullscreen->width + (BTN_SPACE>>1));
737     if( !b_mute && (i_xpos >= i_dest) &&
738         (i_xpos <= i_dest + p_btnMute->width + (BTN_SPACE>>1)) )
739         return clicked_Mute;
740     else if( (i_xpos >= i_dest) &&
741              (i_xpos <= i_dest + p_btnUnmute->width + (BTN_SPACE>>1)) )
742         return clicked_Unmute;
743
744     /* is timeline clicked */
745     if( !b_mute )
746         i_dest += (p_btnMute->width + (BTN_SPACE>>1));
747     else
748         i_dest += (p_btnUnmute->width + (BTN_SPACE>>1));
749     if( (i_xpos >= i_dest) &&
750         (i_xpos <= i_dest + p_timeline->width + (BTN_SPACE>>1)) )
751         return clicked_timeline;
752
753     /* is time button clicked */
754     i_dest += (p_timeline->width + (BTN_SPACE>>1));
755     if( (i_xpos >= i_dest) &&
756         (i_xpos <= i_dest + p_btnTime->width + (BTN_SPACE>>1)) )
757         return clicked_Time;
758
759     return clicked_Unknown;
760 }
761 #undef BTN_SPACE
762 #endif