vlcplugin.cpp 3.24 KB
Newer Older
1
/*****************************************************************************
2
 * vlcplugin.cpp: a VLC plugin for Mozilla
3 4
 *****************************************************************************
 * Copyright (C) 2002 VideoLAN
Sam Hocevar's avatar
Sam Hocevar committed
5
 * $Id: vlcplugin.cpp,v 1.6 2003/10/23 17:04:39 sam Exp $
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 *
 * Authors: Samuel Hocevar <sam@zoy.org>
 *
 * 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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
Sam Hocevar's avatar
Sam Hocevar committed
27 28
#include "config.h"

29 30
#include <vlc/vlc.h>

Sam Hocevar's avatar
Sam Hocevar committed
31 32 33
#ifdef HAVE_MOZILLA_CONFIG_H
#   include <mozilla-config.h>
#endif
34 35
#include <nsISupports.h>
#include <nsMemory.h>
36 37
#include <npapi.h>

Sam Hocevar's avatar
Sam Hocevar committed
38 39 40 41 42 43
#if !defined(XP_MACOSX) && !defined(XP_UNIX) && !defined(XP_WIN)
#define XP_UNIX 1
#elif defined(XP_MACOSX)
#undef XP_UNIX
#endif

44 45 46 47
#include "vlcpeer.h"
#include "vlcplugin.h"

/*****************************************************************************
48
 * VlcPlugin constructor and destructor
49 50 51
 *****************************************************************************/
VlcPlugin::VlcPlugin( NPP instance )
{
52
    p_instance = instance;
53 54 55 56 57 58 59 60 61 62 63 64 65 66
    p_peer = NULL;
}


VlcPlugin::~VlcPlugin()
{
    if( p_peer )
    {
        p_peer->Disable();
        p_peer->Release();
    }
}


67 68 69
/*****************************************************************************
 * VlcPlugin methods
 *****************************************************************************/
70 71 72 73 74 75 76 77 78 79 80 81
void VlcPlugin::SetInstance( NPP instance )
{
    p_instance = instance;
}


NPP VlcPlugin::GetInstance()
{
    return p_instance;
}


82 83 84 85 86
VlcIntf* VlcPlugin::GetPeer()
{
    if( !p_peer )
    {
        p_peer = new VlcPeer( this );
87
        if( p_peer == NULL )
88 89 90
        {
            return NULL;
        }
91

92 93 94 95 96 97 98
        NS_ADDREF( p_peer );
    }

    NS_ADDREF( p_peer );
    return p_peer;
}

99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
void VlcPlugin::SetFileName(const char * filename)
{
#if 0
    FILE * fh;
    fh = fopen(filename, "rb");
    if(!fh)
    {
        fprintf(stderr, "Error while opening %s.\n", filename);
        return;
    }
    fseek(fh, 0, SEEK_END);
    m_lSize = ftell(fh);
    m_szSound = (char*) malloc(m_lSize);
    if(!m_szSound)
    {
        fprintf(stderr, "Error while allocating memory.\n");
        fclose(fh);
        return;
    }
    rewind(fh);
    long pos = 0;
    do
    {
        pos += fread(m_szSound + pos, 1, m_lSize - pos, fh);
        fprintf(stderr, "pos = %d\n", pos);
    }
    while (pos < m_lSize -1);
    fclose (fh);
    fprintf(stderr, "File loaded\n");
#endif
129
    return;
130 131
}