]> git.sesse.net Git - vlc/blob - mozilla/vlcplugin.cpp
* ALL: the build mechanism now uses automake. See HACKING for more details.
[vlc] / mozilla / vlcplugin.cpp
1 /*****************************************************************************
2  * vlcplugin.cpp: a VideoLAN Client plugin for Mozilla
3  *****************************************************************************
4  * Copyright (C) 2002 VideoLAN
5  * $Id: vlcplugin.cpp,v 1.2 2002/09/30 11:05:41 sam Exp $
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 <vlc/vlc.h>
28
29 #include <npapi.h>
30
31 #include "vlcpeer.h"
32 #include "vlcplugin.h"
33
34 /*****************************************************************************
35  * VlcPlugin constructor and destructor
36  *****************************************************************************/
37 VlcPlugin::VlcPlugin( NPP instance )
38 {
39     p_instance = instance; 
40     p_peer = NULL;
41 }
42
43
44 VlcPlugin::~VlcPlugin()
45 {
46     if( p_peer )
47     {
48         p_peer->Disable();
49         p_peer->Release();
50     }
51 }
52
53
54 /*****************************************************************************
55  * VlcPlugin methods
56  *****************************************************************************/
57 void VlcPlugin::SetInstance( NPP instance )
58 {
59     p_instance = instance;
60 }
61
62
63 NPP VlcPlugin::GetInstance()
64 {
65     return p_instance;
66 }
67
68
69 VlcIntf* VlcPlugin::GetPeer()
70 {
71     if( !p_peer )
72     {
73         p_peer = new VlcPeer( this );
74         if( p_peer == NULL ) 
75         {
76             return NULL;
77         }
78         
79         NS_ADDREF( p_peer );
80     }
81
82     NS_ADDREF( p_peer );
83     return p_peer;
84 }
85
86 void VlcPlugin::SetFileName(const char * filename)
87 {
88 #if 0
89     FILE * fh;
90     fh = fopen(filename, "rb");
91     if(!fh)
92     {
93         fprintf(stderr, "Error while opening %s.\n", filename);
94         return;
95     }
96     fseek(fh, 0, SEEK_END);
97     m_lSize = ftell(fh);
98     m_szSound = (char*) malloc(m_lSize);
99     if(!m_szSound)
100     {
101         fprintf(stderr, "Error while allocating memory.\n");
102         fclose(fh);
103         return;
104     }
105     rewind(fh);
106     long pos = 0;
107     do
108     {
109         pos += fread(m_szSound + pos, 1, m_lSize - pos, fh);
110         fprintf(stderr, "pos = %d\n", pos);
111     }
112     while (pos < m_lSize -1);
113     fclose (fh);
114     fprintf(stderr, "File loaded\n");
115 #endif
116     return; 
117 }
118