<commit_before>/*****************************************************************************
 * vlc_input.h: Core input structures
 *****************************************************************************
 * Copyright (C) 1999-2006 the VideoLAN team
 * $Id$
 *
 * Authors: <NAME> <<EMAIL>>
 *          <NAME> <<EMAIL>>
 *
 * 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.
 *****************************************************************************/

#if !defined( __LIBVLC__ )
  #error You are not libvlc or one of its plugins. You cannot include this file
#endif

/* __ is need because conflict with <vlc/input.h> */
#ifndef _VLC__INPUT_H
#define _VLC__INPUT_H 1

#include <vlc_es.h>
#include <vlc_meta.h>
#include <vlc_epg.h>
#include <vlc_events.h>

#include <string.h>                                     /* strcasestr() */

struct vlc_meta_t;

/*****************************************************************************
 * input_item_t: Describes an input and is used to spawn input_thread_t objects
 *****************************************************************************/
struct info_t
{
    char *psz_name;            /**< Name of this info */
    char *psz_value;           /**< Value of the info */
};

struct info_category_t
{
    char   *psz_name;      /**< Name of this category */
    int    i_infos;        /**< Number of infos in the category */
    struct info_t **pp_infos;     /**< Pointer to an array of infos */
};

struct input_item_t
{
    VLC_GC_MEMBERS
    int        i_id;                 /**< Identifier of the item */

    char       *psz_name;            /**< text describing this item */
    char       *psz_uri;             /**< mrl of this item */
    bool  b_fixed_name;        /**< Can the interface change the name ?*/

    int        i_options;            /**< Number of input options */
    char       **ppsz_options;       /**< Array of input options */
    uint8_t    *optflagv;            /**< Some flags of input options */
    unsigned   optflagc;

    mtime_t    i_duration;           /**< Duration in milliseconds*/

    uint8_t    i_type;               /**< Type (file, disc, ...) */

    int        i_categories;         /**< Number of info categories */
    info_category_t **pp_categories; /**< Pointer to the first info category */

    int         i_es;                /**< Number of es format descriptions */
    es_format_t **es;                /**< Es formats */

    input_stats_t *p_stats;          /**< Statistics */
    int           i_nb_played;       /**< Number of times played */

    vlc_meta_t *p_meta;

    vlc_event_manager_t event_manager;

    vlc_mutex_t lock;                 /**< Lock for the item */
};

#define ITEM_TYPE_UNKNOWN       0
#define ITEM_TYPE_FILE          1
#define ITEM_TYPE_DIRECTORY     2
#define ITEM_TYPE_DISC          3
#define ITEM_TYPE_CDDA          4
#define ITEM_TYPE_CARD          5
#define ITEM_TYPE_NET           6
#define ITEM_TYPE_PLAYLIST      7
#define ITEM_TYPE_NODE          8
#define ITEM_TYPE_NUMBER        9

static inline void input_ItemCopyOptions( input_item_t *p_parent,
                                          input_item_t *p_child )
{
    int i;
    for( i = 0 ; i< p_parent->i_options; i++ )
    {
        char *psz_option= strdup( p_parent->ppsz_options[i] );
        if( !strcmp( psz_option, "meta-file" ) )
        {
            free( psz_option );
            continue;
        }
        p_child->i_options++;
        p_child->ppsz_options = (char **)realloc( p_child->ppsz_options,
                                                  p_child->i_options *
                                                  sizeof( char * ) );
        p_child->ppsz_options[p_child->i_options-1] = psz_option;
        p_child->optflagc++;
        p_child->optflagv = (uint8_t *)realloc( p_child->optflagv,
                                                p_child->optflagc );
        p_child->optflagv[p_child->optflagc - 1] = p_parent->optflagv[i];
    }
}

static inline void input_item_SetName( input_item_t *p_item, const char *psz_name )
{
    free( p_item->psz_name );
    p_item->psz_name = strdup( psz_name );
}

/* This won't hold the item, but can tell to interested third parties
 * Like the playlist, that there is a new sub item. With this design
 * It is not the input item's responsability to keep all the ref of
 * the input item children. */
static inline void input_ItemAddSubItem( input_item_t *p_parent,
                                         input_item_t *p_child )
{
    vlc_event_t event;

    p_parent->i_type = ITEM_TYPE_PLAYLIST;

    /* Notify interested third parties */
    event.type = vlc_InputItemSubItemAdded;
    event.u.input_item_subitem_added.p_new_child = p_child;
    vlc_event_send( &p_parent->event_manager, &event );
}

/* Flags handled past input_ItemAddOpt() */
#define VLC_INPUT_OPTION_TRUSTED 0x2

/* Flags handled within input_ItemAddOpt() */
#define VLC_INPUT_OPTION_UNIQUE  0x100

VLC_EXPORT( int, input_ItemAddOpt, ( input_item_t *, const char *str, unsigned flags ) );

static inline
int input_ItemAddOption (input_item_t *item, const char *str)
{
    return input_ItemAddOpt (item, str, VLC_INPUT_OPTION_TRUSTED);
}


VLC_EXPORT( void, input_item_SetMeta, ( input_item_t *p_i, vlc_meta_type_t meta_type, const char *psz_val ));

static inline bool input_item_MetaMatch( input_item_t *p_i, vlc_meta_type_t meta_type, const char *psz )
{
    vlc_mutex_lock( &p_i->lock );
    if( !p_i->p_meta )
    {
        vlc_mutex_unlock( &p_i->lock );
        return false;
    }
    const char * meta = vlc_meta_Get( p_i->p_meta, meta_type );
    bool ret = meta && strcasestr( meta, psz );
    vlc_mutex_unlock( &p_i->lock );

    return ret;
}

static inline char * input_item_GetMeta( input_item_t *p_i, vlc_meta_type_t meta_type )
{
    char * psz = NULL;
    vlc_mutex_lock( &p_i->lock );

    if( !p_i->p_meta )
    {<commit_msg>Do not use a GNU extension in public headers<commit_after>/*****************************************************************************
 * vlc_input.h: Core input structures
 *****************************************************************************
 * Copyright (C) 1999-2006 the VideoLAN team
 * $Id$
 *
 * Authors: <NAME> <<EMAIL>>
 *          <NAME> <<EMAIL>>
 *
 * 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.
 *****************************************************************************/

#if !defined( __LIBVLC__ )
  #error You are not libvlc or one of its plugins. You cannot include this file
#endif

/* __ is need because conflict with <vlc/input.h> */
#ifndef _VLC__INPUT_H
#define _VLC__INPUT_H 1

#include <vlc_es.h>
#include <vlc_meta.h>
#include <vlc_epg.h>
#include <vlc_events.h>

#include <string.h>                                     /* strstr() */

struct vlc_meta_t;

/*****************************************************************************
 * input_item_t: Describes an input and is used to spawn input_thread_t objects
 *****************************************************************************/
struct info_t
{
    char *psz_name;            /**< Name of this info */
    char *psz_value;           /**< Value of the info */
};

struct info_category_t
{
    char   *psz_name;      /**< Name of this category */
    int    i_infos;        /**< Number of infos in the category */
    struct info_t **pp_infos;     /**< Pointer to an array of infos */
};

struct input_item_t
{
    VLC_GC_MEMBERS
    int        i_id;                 /**< Identifier of the item */

    char       *psz_name;            /**< text describing this item */
    char       *psz_uri;             /**< mrl of this item */
    bool  b_fixed_name;        /**< Can the interface change the name ?*/

    int        i_options;            /**< Number of input options */
    char       **ppsz_options;       /**< Array of input options */
    uint8_t    *optflagv;            /**< Some flags of input options */
    unsigned   optflagc;

    mtime_t    i_duration;           /**< Duration in milliseconds*/

    uint8_t    i_type;               /**< Type (file, disc, ...) */

    int        i_categories;         /**< Number of info categories */
    info_category_t **pp_categories; /**< Pointer to the first info category */

    int         i_es;                /**< Number of es format descriptions */
    es_format_t **es;                /**< Es formats */

    input_stats_t *p_stats;          /**< Statistics */
    int           i_nb_played;       /**< Number of times played */

    vlc_meta_t *p_meta;

    vlc_event_manager_t event_manager;

    vlc_mutex_t lock;                 /**< Lock for the item */
};

#define ITEM_TYPE_UNKNOWN       0
#define ITEM_TYPE_FILE          1
#define ITEM_TYPE_DIRECTORY     2
#define ITEM_TYPE_DISC          3
#define ITEM_TYPE_CDDA          4
#define ITEM_TYPE_CARD          5
#define ITEM_TYPE_NET           6
#define ITEM_TYPE_PLAYLIST      7
#define ITEM_TYPE_NODE          8
#define ITEM_TYPE_NUMBER        9

static inline void input_ItemCopyOptions( input_item_t *p_parent,
                                          input_item_t *p_child )
{
    int i;
    for( i = 0 ; i< p_parent->i_options; i++ )
    {
        char *psz_option= strdup( p_parent->ppsz_options[i] );
        if( !strcmp( psz_option, "meta-file" ) )
        {
            free( psz_option );
            continue;
        }
        p_child->i_options++;
        p_child->ppsz_options = (char **)realloc( p_child->ppsz_options,
                                                  p_child->i_options *
                                                  sizeof( char * ) );
        p_child->ppsz_options[p_child->i_options-1] = psz_option;
        p_child->optflagc++;
        p_child->optflagv = (uint8_t *)realloc( p_child->optflagv,
                                                p_child->optflagc );
        p_child->optflagv[p_child->optflagc - 1] = p_parent->optflagv[i];
    }
}

static inline void input_item_SetName( input_item_t *p_item, const char *psz_name )
{
    free( p_item->psz_name );
    p_item->psz_name = strdup( psz_name );
}

/* This won't hold the item, but can tell to interested third parties
 * Like the playlist, that there is a new sub item. With this design
 * It is not the input item's responsability to keep all the ref of
 * the input item children. */
static inline void input_ItemAddSubItem( input_item_t *p_parent,
                                         input_item_t *p_child )
{
    vlc_event_t event;

    p_parent->i_type = ITEM_TYPE_PLAYLIST;

    /* Notify interested third parties */
    event.type = vlc_InputItemSubItemAdded;
    event.u.input_item_subitem_added.p_new_child = p_child;
    vlc_event_send( &p_parent->event_manager, &event );
}

/* Flags handled past input_ItemAddOpt() */
#define VLC_INPUT_OPTION_TRUSTED 0x2

/* Flags handled within input_ItemAddOpt() */
#define VLC_INPUT_OPTION_UNIQUE  0x100

VLC_EXPORT( int, input_ItemAddOpt, ( input_item_t *, const char *str, unsigned flags ) );

static inline
int input_ItemAddOption (input_item_t *item, const char *str)
{
    return input_ItemAddOpt (item, str, VLC_INPUT_OPTION_TRUSTED);
}


VLC_EXPORT( void, input_item_SetMeta, ( input_item_t *p_i, vlc_meta_type_t meta_type, const char *psz_val ));

static inline bool input_item_MetaMatch( input_item_t *p_i, vlc_meta_type_t meta_type, const char *psz )
{
    vlc_mutex_lock( &p_i->lock );
    if( !p_i->p_meta )
    {
        vlc_mutex_unlock( &p_i->lock );
        return false;
    }
    const char * meta = vlc_meta_Get( p_i->p_meta, meta_type );
    bool ret = meta && strstr( meta, psz );
    vlc_mutex_unlock( &p_i->lock );

    return ret;
}

static inline char * input_item_GetMeta( input_item_t *p_i, vlc_meta_type_t meta_type )
{
    char * psz = NULL;
    vlc_mutex_lock( &p_i->lock );

    if( !p_i->p_meta )
    {
{'fraction_non_alphanumeric': 0.1495625713198935, 'fraction_numerical': 0.006542411563332066, 'mean_word_length': 2.515913345814389, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2928133', 'n_tokens_mistral': 4107, 'n_tokens_neox': 3980, 'n_words': 1168}