vlcplugin_base.h 5.34 KB
Newer Older
1
/*****************************************************************************
2
 * vlcplugin_base.h: a VLC plugin for Mozilla
3
 *****************************************************************************
4
 * Copyright (C) 2002-2012 VLC authors and VideoLAN
5 6 7 8 9
 * $Id$
 *
 * Authors: Samuel Hocevar <sam@zoy.org>
 *          Damien Fouilleul <damienf@videolan.org>
 *          Jean-Paul Saman <jpsaman@videolan.org>
10
 *          Sergey Radionov <rsatom@gmail.com>
11
 *          Cheng Sun <chengsun9@gmail.com>
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

/*******************************************************************************
 * Instance state information about the plugin.
 ******************************************************************************/
#ifndef __VLCPLUGIN_BASE_H__
#define __VLCPLUGIN_BASE_H__

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
34
#include "common.h"
35
#include "events.h"
36 37

#include <vector>
38
#include <set>
39

40
#include "../common/vlc_player_options.h"
41
#include "../common/vlc_player.h"
42

43 44
#define MAX_PARAMS 32

45 46 47 48 49 50 51 52 53 54 55 56
typedef enum vlc_toolbar_clicked_e {
    clicked_Unknown = 0,
    clicked_Play,
    clicked_Pause,
    clicked_Stop,
    clicked_timeline,
    clicked_Time,
    clicked_Fullscreen,
    clicked_Mute,
    clicked_Unmute
} vlc_toolbar_clicked_t;

57
class VlcPluginBase: private vlc_player_options, private vlc_player
58 59 60 61 62 63 64
{
protected:

public:
    VlcPluginBase( NPP, NPuint16_t );
    virtual ~VlcPluginBase();

65 66 67 68 69
    vlc_player& get_player()
    {
        return *static_cast<vlc_player*>(this);
    }

70 71 72 73 74
    vlc_player_options& get_options()
        { return *static_cast<vlc_player_options*>(this); }
    const vlc_player_options& get_options() const
        { return *static_cast<const vlc_player_options*>(this); }

75
    NPError             init(int argc, char* const argn[], char* const argv[]);
76

77
    VLC::MediaPlayer& getMD()
78
    {
79
        if( !is_open() )
80 81 82
        {
             libvlc_printerr("no mediaplayer");
        }
83
        return get_mp();
84
    }
85 86

    NPP                 getBrowser() { return p_browser; };
87
    char*               getAbsoluteURL(const char *url);
88 89

    NPWindow&           getWindow()  { return npwindow; };
90
    virtual void        setWindow(const NPWindow &window);
91

92
    NPClass*            getScriptClass() { return p_scriptClass; };
93 94 95 96 97 98 99 100 101

    NPuint16_t  i_npmode; /* either NP_EMBED or NP_FULL */

    /* plugin properties */
    int      b_stream;
    char *   psz_target;

    void playlist_play()
    {
102
        play();
103 104 105
    }
    void playlist_play_item(int idx)
    {
106
        play(idx);
107 108 109
    }
    void playlist_stop()
    {
110
        stop();
111 112 113
    }
    void playlist_next()
    {
114
        next();
115 116 117
    }
    void playlist_prev()
    {
118
        prev();
119 120 121
    }
    void playlist_pause()
    {
122
        pause();
123
    }
124 125
    void playlist_togglePause()
    {
126
        togglePause();
127
    }
128 129
    int playlist_isplaying()
    {
130
        return is_playing();
131
    }
132 133 134 135
    int playlist_currentitem()
    {
        return current_item();
    }
136 137
    int playlist_add( const char * mrl)
    {
138
        return add_item(mrl);
139 140 141 142
    }
    int playlist_add_extended_untrusted( const char *mrl, const char *,
                    int optc, const char **optv )
    {
143
        return add_item(mrl, optc, optv);
144 145 146
    }
    int playlist_delete_item( int idx)
    {
147
        return delete_item(idx);
148 149 150
    }
    void playlist_clear()
    {
151
        clear_items() ;
152 153 154
    }
    int  playlist_count()
    {
155
        return items_count();
156
    }
157
    bool playlist_select(int);
158 159 160 161 162 163 164 165 166

    void control_handler(vlc_toolbar_clicked_t);

    bool  player_has_vout();

    virtual bool create_windows() = 0;
    virtual bool resize_windows() = 0;
    virtual bool destroy_windows() = 0;

167 168
    virtual bool handle_event(void *event);

169 170 171 172
#if defined(XP_MACOSX)
    virtual NPError get_root_layer(void *value);
#endif

173
    virtual void toggle_fullscreen() = 0;
174 175 176 177 178
    virtual void set_fullscreen(int) = 0;
    virtual int get_fullscreen() = 0;

    virtual void set_toolbar_visible(bool) = 0;
    virtual bool get_toolbar_visible() = 0;
179

180
    virtual void update_controls() = 0;
181
    virtual void popup_menu() = 0;
182

183 184
    virtual void set_player_window() = 0;

185 186 187 188 189 190
    static bool canUseEventListener();

    EventObj events;
    void event_callback(const libvlc_event_t *, NPVariant *, uint32_t);

protected:
191
    // called after libvlc_media_player_new_from_media
192
    virtual void on_media_player_new()     {}
193
    // called before libvlc_media_player_release
194
    virtual void on_media_player_release() {}
195

196 197 198 199
    NPClass             *p_scriptClass;

    /* browser reference */
    NPP     p_browser;
200
    char    *psz_baseURL;
201 202 203 204 205

    /* display settings */
    NPWindow  npwindow;

    static void eventAsync(void *);
206 207 208

private:
    static std::set<VlcPluginBase*> _instances;
209 210 211
};

#endif