<commit_before>/**********************************************************\

  Auto-generated FBVLC.cpp

  This file contains the auto-generated main plugin object
  implementation for the FireBreathed VLC project

\**********************************************************/

#include "FBVLCAPI.h"

#include "FBVLC.h"

///////////////////////////////////////////////////////////////////////////////
/// @fn FBVLC::StaticInitialize()
///
/// @brief  Called from PluginFactory::globalPluginInitialize()
///
/// @see FB::FactoryBase::globalPluginInitialize
///////////////////////////////////////////////////////////////////////////////
void FBVLC::StaticInitialize()
{
    // Place one-time initialization stuff here; As of FireBreath 1.4 this should only
    // be called once per process
}

///////////////////////////////////////////////////////////////////////////////
/// @fn FBVLC::StaticInitialize()
///
/// @brief  Called from PluginFactory::globalPluginDeinitialize()
///
/// @see FB::FactoryBase::globalPluginDeinitialize
///////////////////////////////////////////////////////////////////////////////
void FBVLC::StaticDeinitialize()
{
    // Place one-time deinitialization stuff here. As of FireBreath 1.4 this should
    // always be called just before the plugin library is unloaded
}

///////////////////////////////////////////////////////////////////////////////
/// @brief  FBVLC constructor.  Note that your API is not available
///         at this point, nor the window.  For best results wait to use
///         the JSAPI object until the onPluginReady method is called
///////////////////////////////////////////////////////////////////////////////
FBVLC::FBVLC()
    :m_libvlc(0), m_media_width(0), m_media_height(0)
{
}

///////////////////////////////////////////////////////////////////////////////
/// @brief  FBVLC destructor.
///////////////////////////////////////////////////////////////////////////////
FBVLC::~FBVLC()
{
    // This is optional, but if you reset m_api (the shared_ptr to your JSAPI
    // root object) and tell the host to free the retained JSAPI objects then
    // unless you are holding another shared_ptr reference to your JSAPI object
    // they will be released here.
    releaseRootJSAPI();
    m_host->freeRetainedObjects();
}

unsigned FBVLC::video_format_cb(char *chroma,
                                unsigned *width, unsigned *height,
                                unsigned *pitches, unsigned *lines)
{
    FB::PluginWindow* w = GetWindow();
    if ( w ) {
        float src_aspect = (float)(*width) / (*height);
        float dst_aspect = (float)w->getWindowWidth()/w->getWindowHeight();
        if ( src_aspect > dst_aspect ) {
            (*width)  = w->getWindowWidth();
            (*height) = static_cast<unsigned>( (*width) / src_aspect );
        }
        else {
            (*height) = w->getWindowHeight();
            (*width)  = static_cast<unsigned>( (*height) * src_aspect );
        }
    }

    m_media_width  = (*width);
    m_media_height = (*height);

    memcpy(chroma, DEF_CHROMA, sizeof(DEF_CHROMA)-1);
    (*pitches) = m_media_width * DEF_PIXEL_BYTES;
    (*lines)   = m_media_height;

    m_frame_buf.resize( m_media_width * m_media_height * DEF_PIXEL_BYTES );

    return 1;
}

void FBVLC::video_cleanup_cb()
{
    m_frame_buf.resize(0);
    m_media_width  = 0;
    m_media_height = 0;
}

void* FBVLC::video_lock_cb(void **planes)
{
    (*planes) = &m_frame_buf[0];
    return 0;
}

void FBVLC::video_unlock_cb(void* /*picture*/, void *const * /*planes*/)
{
}

void FBVLC::video_display_cb(void * /*picture*/)
{
    FB::PluginWindow* w = GetWindow();
    if ( w ) {
        w->InvalidateWindow();
    }
}

//libvlc events arrives from separate thread
void FBVLC::OnLibVlcEvent_proxy(const libvlc_event_t* e, void *param)
{
    FBVLC* fbvlc = static_cast<FBVLC*>(param);

    FBVLCAPIPtr api  = boost::static_pointer_cast<FBVLCAPI>( fbvlc->getRootJSAPI() );
    FB::BrowserHostPtr h = fbvlc->m_host;

    void (FBVLCAPI::*event_to_fire)(void) = 0;

    switch ( e->type ) {
    //case libvlc_MediaPlayerMediaChanged:
    case libvlc_MediaPlayerNothingSpecial:<commit_msg>fixed crash on plugin unload<commit_after>/**********************************************************\

  Auto-generated FBVLC.cpp

  This file contains the auto-generated main plugin object
  implementation for the FireBreathed VLC project

\**********************************************************/

#include "FBVLCAPI.h"

#include "FBVLC.h"

///////////////////////////////////////////////////////////////////////////////
/// @fn FBVLC::StaticInitialize()
///
/// @brief  Called from PluginFactory::globalPluginInitialize()
///
/// @see FB::FactoryBase::globalPluginInitialize
///////////////////////////////////////////////////////////////////////////////
void FBVLC::StaticInitialize()
{
    // Place one-time initialization stuff here; As of FireBreath 1.4 this should only
    // be called once per process
}

///////////////////////////////////////////////////////////////////////////////
/// @fn FBVLC::StaticInitialize()
///
/// @brief  Called from PluginFactory::globalPluginDeinitialize()
///
/// @see FB::FactoryBase::globalPluginDeinitialize
///////////////////////////////////////////////////////////////////////////////
void FBVLC::StaticDeinitialize()
{
    // Place one-time deinitialization stuff here. As of FireBreath 1.4 this should
    // always be called just before the plugin library is unloaded
}

///////////////////////////////////////////////////////////////////////////////
/// @brief  FBVLC constructor.  Note that your API is not available
///         at this point, nor the window.  For best results wait to use
///         the JSAPI object until the onPluginReady method is called
///////////////////////////////////////////////////////////////////////////////
FBVLC::FBVLC()
    :m_libvlc(0), m_media_width(0), m_media_height(0)
{
}

///////////////////////////////////////////////////////////////////////////////
/// @brief  FBVLC destructor.
///////////////////////////////////////////////////////////////////////////////
FBVLC::~FBVLC()
{
    // This is optional, but if you reset m_api (the shared_ptr to your JSAPI
    // root object) and tell the host to free the retained JSAPI objects then
    // unless you are holding another shared_ptr reference to your JSAPI object
    // they will be released here.
    releaseRootJSAPI();
    m_host->freeRetainedObjects();
}

unsigned FBVLC::video_format_cb(char *chroma,
                                unsigned *width, unsigned *height,
                                unsigned *pitches, unsigned *lines)
{
    FB::PluginWindow* w = GetWindow();
    if ( w ) {
        float src_aspect = (float)(*width) / (*height);
        float dst_aspect = (float)w->getWindowWidth()/w->getWindowHeight();
        if ( src_aspect > dst_aspect ) {
            (*width)  = w->getWindowWidth();
            (*height) = static_cast<unsigned>( (*width) / src_aspect );
        }
        else {
            (*height) = w->getWindowHeight();
            (*width)  = static_cast<unsigned>( (*height) * src_aspect );
        }
    }

    m_media_width  = (*width);
    m_media_height = (*height);

    memcpy(chroma, DEF_CHROMA, sizeof(DEF_CHROMA)-1);
    (*pitches) = m_media_width * DEF_PIXEL_BYTES;
    (*lines)   = m_media_height;

    m_frame_buf.resize( m_media_width * m_media_height * DEF_PIXEL_BYTES );

    return 1;
}

void FBVLC::video_cleanup_cb()
{
    m_frame_buf.resize(0);
    m_media_width  = 0;
    m_media_height = 0;
}

void* FBVLC::video_lock_cb(void **planes)
{
    (*planes) = m_frame_buf.empty()? 0 : &m_frame_buf[0];
    return 0;
}

void FBVLC::video_unlock_cb(void* /*picture*/, void *const * /*planes*/)
{
}

void FBVLC::video_display_cb(void * /*picture*/)
{
    FB::PluginWindow* w = GetWindow();
    if ( w ) {
        w->InvalidateWindow();
    }
}

//libvlc events arrives from separate thread
void FBVLC::OnLibVlcEvent_proxy(const libvlc_event_t* e, void *param)
{
    FBVLC* fbvlc = static_cast<FBVLC*>(param);

    FBVLCAPIPtr api  = boost::static_pointer_cast<FBVLCAPI>( fbvlc->getRootJSAPI() );
    FB::BrowserHostPtr h = fbvlc->m_host;

    void (FBVLCAPI::*event_to_fire)(void) = 0;

    switch ( e->type ) {
    //case libvlc_MediaPlayerMediaChanged:
    case libvlc_MediaPlayerNothingSpecial:
{'fraction_non_alphanumeric': 0.28275944524151125, 'fraction_numerical': 0.003706360593017695, 'mean_word_length': 1.819346140883047, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7068039', 'n_tokens_mistral': 2402, 'n_tokens_neox': 2304, 'n_words': 563}