]> git.sesse.net Git - vlc/blob - mozilla/vlcplugin.cpp
backport of r13238
[vlc] / mozilla / vlcplugin.cpp
1 /*****************************************************************************
2  * vlcplugin.cpp: a VLC plugin for Mozilla
3  *****************************************************************************
4  * Copyright (C) 2002-2005 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include "config.h"
28
29 #include <vlc/vlc.h>
30
31 #ifdef HAVE_MOZILLA_CONFIG_H
32 #   include <mozilla-config.h>
33 #endif
34 #include <nsISupports.h>
35 #include <nsMemory.h>
36 #include <npapi.h>
37
38 #if !defined(XP_MACOSX) && !defined(XP_UNIX) && !defined(XP_WIN)
39 #define XP_UNIX 1
40 #elif defined(XP_MACOSX)
41 #undef XP_UNIX
42 #endif
43
44 #include "vlcpeer.h"
45 #include "vlcplugin.h"
46
47 /*****************************************************************************
48  * VlcPlugin constructor and destructor
49  *****************************************************************************/
50 VlcPlugin::VlcPlugin( NPP instance )
51 {
52     p_instance = instance;
53     p_peer = NULL;
54 }
55
56
57 VlcPlugin::~VlcPlugin()
58 {
59     if( p_peer )
60     {
61         p_peer->Disable();
62         p_peer->Release();
63     }
64 }
65
66
67 /*****************************************************************************
68  * VlcPlugin methods
69  *****************************************************************************/
70 void VlcPlugin::SetInstance( NPP instance )
71 {
72     p_instance = instance;
73 }
74
75
76 NPP VlcPlugin::GetInstance()
77 {
78     return p_instance;
79 }
80
81
82 VlcIntf* VlcPlugin::GetPeer()
83 {
84     if( !p_peer )
85     {
86         p_peer = new VlcPeer( this );
87         if( p_peer == NULL )
88         {
89             return NULL;
90         }
91
92         NS_ADDREF( p_peer );
93     }
94
95     NS_ADDREF( p_peer );
96     return p_peer;
97 }
98
99 void VlcPlugin::SetFileName(const char * filename)
100 {
101 #if 0
102     FILE * fh;
103     fh = fopen(filename, "rb");
104     if(!fh)
105     {
106         fprintf(stderr, "Error while opening %s.\n", filename);
107         return;
108     }
109     fseek(fh, 0, SEEK_END);
110     m_lSize = ftell(fh);
111     m_szSound = (char*) malloc(m_lSize);
112     if(!m_szSound)
113     {
114         fprintf(stderr, "Error while allocating memory.\n");
115         fclose(fh);
116         return;
117     }
118     rewind(fh);
119     long pos = 0;
120     do
121     {
122         pos += fread(m_szSound + pos, 1, m_lSize - pos, fh);
123         fprintf(stderr, "pos = %d\n", pos);
124     }
125     while (pos < m_lSize -1);
126     fclose (fh);
127     fprintf(stderr, "File loaded\n");
128 #endif
129     return;
130 }
131