Commit 17557ea6 authored by Clément Stenac's avatar Clément Stenac

* Makefile.am : Added src/playlist/item-ext.c and src/playlist/info.c

* src/playlist/item.c
  src/playlist/info.c
  src/playlist/item-ext.c
  src/playlist/group.c
  src/playlist/sort.c
  src/playlist/loadsave.c
  include/vlc_playlist.h
      - New playlist_info structures and accessors
        It works pretty like the old input_info (with categories)
        It provides modularity to the playlist
      - Removed ppsz_options and i_options from playlist_item
        (we use the special category Options)
      - Added a unique id to each playlist_item to be able to track the
        items accross playlist reorders
      - Simplified adding of items.
           - playlist_AddExt is removed
           - playlist_AddItem is still here and exported but should not be used
           - use playlist_Add( p_playlist, uri, name, duration, mode, pos )
             and use the accessors for all other things
      - Added setters for fields of the playlist_item structure
      - Introduced "item-change" and "playlist-current" playlist variables
        to give more flexibility than only intf-change

      At the moment, duration is still in the structure (easier to use, IMHO)

* src/input/input.c
  src/libvlc.c :
        playlist item options parsing changed

* include/vlc_common.h : added playlist_info structures
parent 051ce627
...@@ -317,6 +317,8 @@ SOURCES_libvlc_common = \ ...@@ -317,6 +317,8 @@ SOURCES_libvlc_common = \
src/playlist/loadsave.c \ src/playlist/loadsave.c \
src/playlist/group.c \ src/playlist/group.c \
src/playlist/item.c \ src/playlist/item.c \
src/playlist/item-ext.c \
src/playlist/info.c \
src/input/input.c \ src/input/input.c \
src/input/es_out.c \ src/input/es_out.c \
src/input/stream.c \ src/input/stream.c \
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* Collection of useful common types and macros definitions * Collection of useful common types and macros definitions
***************************************************************************** *****************************************************************************
* Copyright (C) 1998, 1999, 2000 VideoLAN * Copyright (C) 1998, 1999, 2000 VideoLAN
* $Id: vlc_common.h,v 1.96 2003/12/06 22:45:53 jpsaman Exp $ * $Id: vlc_common.h,v 1.97 2004/01/05 12:59:43 zorglub Exp $
* *
* Authors: Samuel Hocevar <sam@via.ecp.fr> * Authors: Samuel Hocevar <sam@via.ecp.fr>
* Vincent Seguin <seguin@via.ecp.fr> * Vincent Seguin <seguin@via.ecp.fr>
...@@ -190,6 +190,8 @@ typedef struct msg_subscription_t msg_subscription_t; ...@@ -190,6 +190,8 @@ typedef struct msg_subscription_t msg_subscription_t;
typedef struct playlist_t playlist_t; typedef struct playlist_t playlist_t;
typedef struct playlist_item_t playlist_item_t; typedef struct playlist_item_t playlist_item_t;
typedef struct playlist_group_t playlist_group_t; typedef struct playlist_group_t playlist_group_t;
typedef struct item_info_t item_info_t;
typedef struct item_info_category_t item_info_category_t;
/* Modules */ /* Modules */
typedef struct module_bank_t module_bank_t; typedef struct module_bank_t module_bank_t;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* vlc_playlist.h : Playlist functions * vlc_playlist.h : Playlist functions
***************************************************************************** *****************************************************************************
* Copyright (C) 1999, 2000, 2001, 2002 VideoLAN * Copyright (C) 1999, 2000, 2001, 2002 VideoLAN
* $Id: vlc_playlist.h,v 1.18 2003/12/03 21:58:42 sigmunau Exp $ * $Id: vlc_playlist.h,v 1.19 2004/01/05 12:59:43 zorglub Exp $
* *
* Authors: Samuel Hocevar <sam@zoy.org> * Authors: Samuel Hocevar <sam@zoy.org>
* *
...@@ -33,6 +33,29 @@ ...@@ -33,6 +33,29 @@
* @{ * @{
*/ */
/**
* Playlist info item
* \see playlist_item_t
*/
struct item_info_t
{
char * psz_name; /**< Name of this info */
char * psz_value; /**< Value of the info */
};
/**
* playlist item info category
* \see playlist_item_t
* \see item_info_t
*/
struct item_info_category_t
{
char * psz_name; /**< Name of this category */
int i_infos; /**< Number of infos in the category */
item_info_t **pp_infos; /**< Pointer to an array of infos */
};
/** /**
* playlist item * playlist item
* \see playlist_t * \see playlist_t
...@@ -41,23 +64,27 @@ struct playlist_item_t ...@@ -41,23 +64,27 @@ struct playlist_item_t
{ {
char * psz_name; /**< text describing this item */ char * psz_name; /**< text describing this item */
char * psz_uri; /**< mrl of this item */ char * psz_uri; /**< mrl of this item */
mtime_t i_duration; /**< A hint about the duration of this item */ mtime_t i_duration; /**< A hint about the duration of this
char ** ppsz_options; /**< options passed with the :foo=bar syntax */ * item, in miliseconds*/
int i_options; /**< number of items in the int i_categories; /**< Number of info categories */
* ppsz_options array */ item_info_category_t **pp_categories;
int i_type; /**< unused yet */ /**< Pointer to the first info category */
int i_status; /**< unused yet */ int i_status; /**< unused yet */
int i_nb_played; /**< How many times was this item played ? */
vlc_bool_t b_autodeletion; /**< Indicates whther this item is to vlc_bool_t b_autodeletion; /**< Indicates whther this item is to
* be deleted after playback. True mean * be deleted after playback. True mean
* that this item is to be deleted * that this item is to be deleted
* after playback, false otherwise */ * after playback, false otherwise */
vlc_bool_t b_enabled; /**< Indicates whether this item is to be vlc_bool_t b_enabled; /**< Indicates whether this item is to be
* played or skipped */ * played or skipped */
int i_group; /**< Which group does this item belongs to ? */
int i_group; /**< unused yet */ int i_id; /**< Unique id to track this item */
char * psz_author; /**< Author */
}; };
/**
* playlist group
* \see playlist_t
*/
struct playlist_group_t struct playlist_group_t
{ {
char * psz_name; /**< name of the group */ char * psz_name; /**< name of the group */
...@@ -89,9 +116,10 @@ struct playlist_t ...@@ -89,9 +116,10 @@ struct playlist_t
int i_groups; /**< How many groups are in the playlist */ int i_groups; /**< How many groups are in the playlist */
playlist_group_t ** pp_groups;/**< array of pointers to the playlist playlist_group_t ** pp_groups;/**< array of pointers to the playlist
* groups */ * groups */
int i_max_id; /**< Maximal group id given */ int i_last_group; /**< Maximal group id given */
input_thread_t * p_input; /**< the input thread ascosiated input_thread_t * p_input; /**< the input thread ascosiated
* with the current item */ * with the current item */
int i_last_id; /**< Last id to an item */
/*@}*/ /*@}*/
}; };
...@@ -120,10 +148,13 @@ void playlist_Destroy ( playlist_t * ); ...@@ -120,10 +148,13 @@ void playlist_Destroy ( playlist_t * );
#define playlist_Prev(p) playlist_Command(p,PLAYLIST_SKIP,-1) #define playlist_Prev(p) playlist_Command(p,PLAYLIST_SKIP,-1)
#define playlist_Skip(p,i) playlist_Command(p,PLAYLIST_SKIP,i) #define playlist_Skip(p,i) playlist_Command(p,PLAYLIST_SKIP,i)
#define playlist_Goto(p,i) playlist_Command(p,PLAYLIST_GOTO,i) #define playlist_Goto(p,i) playlist_Command(p,PLAYLIST_GOTO,i)
VLC_EXPORT( void, playlist_Command, ( playlist_t *, playlist_command_t, int ) ); VLC_EXPORT( void, playlist_Command, ( playlist_t *, playlist_command_t, int ) );
VLC_EXPORT( int, playlist_Add, ( playlist_t *, const char *, const char **, int, int, int ) );
VLC_EXPORT( int, playlist_AddExt, ( playlist_t *, const char *, const char *, mtime_t, const char **, int, int, int ) ); /* Item functions */
VLC_EXPORT( int, playlist_Add, ( playlist_t *, const char *, const char *, int, int ) );
/* For internal use. Do not use this one anymore */
VLC_EXPORT( int, playlist_AddItem, ( playlist_t *, playlist_item_t *, int, int ) ); VLC_EXPORT( int, playlist_AddItem, ( playlist_t *, playlist_item_t *, int, int ) );
VLC_EXPORT( int, playlist_Delete, ( playlist_t *, int ) ); VLC_EXPORT( int, playlist_Delete, ( playlist_t *, int ) );
VLC_EXPORT( int, playlist_Disable, ( playlist_t *, int ) ); VLC_EXPORT( int, playlist_Disable, ( playlist_t *, int ) );
...@@ -131,18 +162,47 @@ VLC_EXPORT( int, playlist_Enable, ( playlist_t *, int ) ); ...@@ -131,18 +162,47 @@ VLC_EXPORT( int, playlist_Enable, ( playlist_t *, int ) );
VLC_EXPORT( int, playlist_DisableGroup, ( playlist_t *, int ) ); VLC_EXPORT( int, playlist_DisableGroup, ( playlist_t *, int ) );
VLC_EXPORT( int, playlist_EnableGroup, ( playlist_t *, int ) ); VLC_EXPORT( int, playlist_EnableGroup, ( playlist_t *, int ) );
/* Basic item informations accessors */
VLC_EXPORT( int, playlist_SetGroup, (playlist_t *, int, int ) );
VLC_EXPORT( int, playlist_SetName, (playlist_t *, int, char * ) );
VLC_EXPORT( int, playlist_SetDuration, (playlist_t *, int, int ) );
/* Item search functions */
VLC_EXPORT( int, playlist_GetPositionById, (playlist_t *, int) );
VLC_EXPORT( playlist_item_t *, playlist_GetItemById, (playlist_t *, int) );
/* Group management functions */
VLC_EXPORT( playlist_group_t *, playlist_CreateGroup, (playlist_t *, char* ) ); VLC_EXPORT( playlist_group_t *, playlist_CreateGroup, (playlist_t *, char* ) );
VLC_EXPORT( int, playlist_DeleteGroup, (playlist_t *, int ) ); VLC_EXPORT( int, playlist_DeleteGroup, (playlist_t *, int ) );
VLC_EXPORT( char *, playlist_FindGroup, (playlist_t *, int ) ); VLC_EXPORT( char *, playlist_FindGroup, (playlist_t *, int ) );
VLC_EXPORT( int, playlist_GroupToId, (playlist_t *, char * ) ); VLC_EXPORT( int, playlist_GroupToId, (playlist_t *, char * ) );
/* Info functions */
VLC_EXPORT( char * , playlist_GetInfo, ( playlist_t * , int, const char *, const char *) );
VLC_EXPORT( char * , playlist_GetItemInfo, ( playlist_item_t * , const char *, const char *) );
VLC_EXPORT( item_info_category_t*, playlist_GetCategory, ( playlist_t *, int, const char *) );
VLC_EXPORT( item_info_category_t*, playlist_GetItemCategory, ( playlist_item_t *, const char *) );
VLC_EXPORT( item_info_category_t*, playlist_CreateCategory, ( playlist_t *, int, const char *) );
VLC_EXPORT( item_info_category_t*, playlist_CreateItemCategory, ( playlist_item_t *, const char *) );
VLC_EXPORT( int, playlist_AddInfo, (playlist_t *, int, const char * , const char *, const char *, ...) );
VLC_EXPORT( int, playlist_AddItemInfo, (playlist_item_t *, const char * , const char *, const char *, ...) );
/* Option functions */
VLC_EXPORT( int, playlist_AddOption, (playlist_t *, int, const char *, ...) );
VLC_EXPORT( int, playlist_AddItemOption, (playlist_item_t *, const char *, ...) );
/* Playlist sorting */
#define playlist_SortTitle(p, i) playlist_Sort( p, SORT_TITLE, i) #define playlist_SortTitle(p, i) playlist_Sort( p, SORT_TITLE, i)
#define playlist_SortAuthor(p, i) playlist_Sort( p, SORT_AUTHOR, i) #define playlist_SortAuthor(p, i) playlist_Sort( p, SORT_AUTHOR, i)
#define playlist_SortGroup(p, i) playlist_Sort( p, SORT_GROUP, i) #define playlist_SortGroup(p, i) playlist_Sort( p, SORT_GROUP, i)
VLC_EXPORT( int, playlist_Sort, ( playlist_t *, int, int) ); VLC_EXPORT( int, playlist_Sort, ( playlist_t *, int, int) );
VLC_EXPORT( int, playlist_Move, ( playlist_t *, int, int ) ); VLC_EXPORT( int, playlist_Move, ( playlist_t *, int, int ) );
/* Load/Save */
VLC_EXPORT( int, playlist_LoadFile, ( playlist_t *, const char * ) ); VLC_EXPORT( int, playlist_LoadFile, ( playlist_t *, const char * ) );
VLC_EXPORT( int, playlist_SaveFile, ( playlist_t *, const char * ) ); VLC_EXPORT( int, playlist_SaveFile, ( playlist_t *, const char * ) );
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* decoders. * decoders.
***************************************************************************** *****************************************************************************
* Copyright (C) 1998-2002 VideoLAN * Copyright (C) 1998-2002 VideoLAN
* $Id: input.c,v 1.271 2003/12/03 22:14:38 sigmunau Exp $ * $Id: input.c,v 1.272 2004/01/05 12:59:43 zorglub Exp $
* *
* Authors: Christophe Massiot <massiot@via.ecp.fr> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* *
...@@ -86,8 +86,9 @@ input_thread_t *__input_CreateThread( vlc_object_t *p_parent, ...@@ -86,8 +86,9 @@ input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
{ {
input_thread_t * p_input; /* thread descriptor */ input_thread_t * p_input; /* thread descriptor */
input_info_category_t * p_info; input_info_category_t * p_info;
item_info_category_t *p_cat;
vlc_value_t val; vlc_value_t val;
int i; int i,j;
/* Allocate descriptor */ /* Allocate descriptor */
p_input = vlc_object_create( p_parent, VLC_OBJECT_INPUT ); p_input = vlc_object_create( p_parent, VLC_OBJECT_INPUT );
...@@ -98,9 +99,21 @@ input_thread_t *__input_CreateThread( vlc_object_t *p_parent, ...@@ -98,9 +99,21 @@ input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
} }
/* Parse input options */ /* Parse input options */
for( i = 0; i < p_item->i_options; i++ ) for( i = 0 ; i < p_item->i_categories ; i++ )
{ {
ParseOption( p_input, p_item->ppsz_options[i] ); if( !strncmp( p_item->pp_categories[i]->psz_name, "Options", 7 ) )
{
msg_Dbg(p_input,"Parsing %i options for item",
p_item->pp_categories[i]->i_infos );
for( j = 0; j< p_item->pp_categories[i]->i_infos ; j++ )
{
msg_Dbg(p_input,"Option : %s",
p_item->pp_categories[i]->pp_infos[j]->psz_name);
ParseOption( p_input,
p_item->pp_categories[i]->pp_infos[j]->psz_value);
}
break;
}
} }
/* Create a few object variables we'll need later on */ /* Create a few object variables we'll need later on */
...@@ -789,15 +802,13 @@ static int InitThread( input_thread_t * p_input ) ...@@ -789,15 +802,13 @@ static int InitThread( input_thread_t * p_input )
FIND_PARENT ); FIND_PARENT );
if( p_playlist ) if( p_playlist )
{ {
vlc_mutex_lock( &p_playlist->object_lock ); playlist_SetDuration( p_playlist, -1 , i_length );
p_playlist->pp_items[ p_playlist->i_index ]->i_duration = i_length;
val.b_bool = VLC_TRUE; val.b_bool = VLC_TRUE;
vlc_mutex_unlock( &p_playlist->object_lock ); var_Set( p_playlist, "item-change", val );
var_Set( p_playlist, "intf-change", val );
vlc_object_release( p_playlist ); vlc_object_release( p_playlist );
} }
} }
/* get fps */ /* get fps */
if( demux_Control( p_input, DEMUX_GET_FPS, &f_fps ) || f_fps < 0.1 ) if( demux_Control( p_input, DEMUX_GET_FPS, &f_fps ) || f_fps < 0.1 )
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* libvlc.c: main libvlc source * libvlc.c: main libvlc source
***************************************************************************** *****************************************************************************
* Copyright (C) 1998-2002 VideoLAN * Copyright (C) 1998-2002 VideoLAN
* $Id: libvlc.c,v 1.106 2003/12/24 10:06:53 gbazin Exp $ * $Id: libvlc.c,v 1.107 2004/01/05 12:59:43 zorglub Exp $
* *
* Authors: Vincent Seguin <seguin@via.ecp.fr> * Authors: Vincent Seguin <seguin@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org> * Samuel Hocevar <sam@zoy.org>
...@@ -796,6 +796,7 @@ int VLC_AddTarget( int i_object, char const *psz_target, ...@@ -796,6 +796,7 @@ int VLC_AddTarget( int i_object, char const *psz_target,
char const **ppsz_options, int i_options, char const **ppsz_options, int i_options,
int i_mode, int i_pos ) int i_mode, int i_pos )
{ {
int i;
int i_err; int i_err;
playlist_t *p_playlist; playlist_t *p_playlist;
vlc_t *p_vlc = vlc_current_object( i_object ); vlc_t *p_vlc = vlc_current_object( i_object );
...@@ -821,9 +822,14 @@ int VLC_AddTarget( int i_object, char const *psz_target, ...@@ -821,9 +822,14 @@ int VLC_AddTarget( int i_object, char const *psz_target,
vlc_object_yield( p_playlist ); vlc_object_yield( p_playlist );
} }
i_err = playlist_Add( p_playlist, psz_target, ppsz_options, i_options, i_err = playlist_Add( p_playlist, psz_target, psz_target,
i_mode, i_pos ); i_mode, i_pos );
for( i = 0 ; i< i_options ; i++ )
{
playlist_AddOption( p_playlist, i_err , ppsz_options[i] );
}
vlc_object_release( p_playlist ); vlc_object_release( p_playlist );
if( i_object ) vlc_object_release( p_vlc ); if( i_object ) vlc_object_release( p_vlc );
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* playlist.c : Playlist groups management functions * playlist.c : Playlist groups management functions
***************************************************************************** *****************************************************************************
* Copyright (C) 1999-2001 VideoLAN * Copyright (C) 1999-2001 VideoLAN
* $Id: group.c,v 1.4 2003/12/11 11:30:37 zorglub Exp $ * $Id: group.c,v 1.5 2004/01/05 12:59:43 zorglub Exp $
* *
* Authors: Clment Stenac <zorglub@videolan.org> * Authors: Clment Stenac <zorglub@videolan.org>
* *
...@@ -61,7 +61,7 @@ playlist_group_t * playlist_CreateGroup(playlist_t * p_playlist, char *psz_name) ...@@ -61,7 +61,7 @@ playlist_group_t * playlist_CreateGroup(playlist_t * p_playlist, char *psz_name)
} }
p_group->psz_name = strdup( psz_name ); p_group->psz_name = strdup( psz_name );
p_group->i_id = ++p_playlist->i_max_id; p_group->i_id = ++p_playlist->i_last_group;
msg_Dbg(p_playlist,"Creating group %s with id %i at position %i", msg_Dbg(p_playlist,"Creating group %s with id %i at position %i",
p_group->psz_name, p_group->psz_name,
...@@ -110,7 +110,7 @@ int playlist_DeleteGroup( playlist_t *p_playlist, int i_id ) ...@@ -110,7 +110,7 @@ int playlist_DeleteGroup( playlist_t *p_playlist, int i_id )
} }
/** /**
* Find the name with the ID * Find the name of the group given its ID
* *
* \param p_playlist the playlist where to find the group * \param p_playlist the playlist where to find the group
* \param i_id the ID to search for * \param i_id the ID to search for
...@@ -124,14 +124,14 @@ char *playlist_FindGroup( playlist_t *p_playlist, int i_id ) ...@@ -124,14 +124,14 @@ char *playlist_FindGroup( playlist_t *p_playlist, int i_id )
if( p_playlist->pp_groups[i]->i_id == i_id ) if( p_playlist->pp_groups[i]->i_id == i_id )
{ {
if( p_playlist->pp_groups[i]->psz_name) if( p_playlist->pp_groups[i]->psz_name)
return strdup( p_playlist->pp_groups[i]->psz_name ); return strdup( p_playlist->pp_groups[i]->psz_name );
} }
} }
return NULL; return NULL;
} }
/** /**
* Find the Id with the given name * Find the Id of a group given its name
* *
* \param p_playlist the playlist where to find the group * \param p_playlist the playlist where to find the group
* \param char * the name to search for * \param char * the name to search for
......
/*****************************************************************************
* info.c : Playlist info management
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
* $Id: info.c,v 1.1 2004/01/05 12:59:43 zorglub Exp $
*
* Authors: Clment Stenac <zorglub@videolan.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.
*****************************************************************************/
#include <stdlib.h> /* free(), strtol() */
#include <stdio.h> /* sprintf() */
#include <string.h> /* strerror() */
#include <vlc/vlc.h>
#include <vlc/vout.h>
#include <vlc/sout.h>
#include "vlc_playlist.h"
/**
* Get one special info
*
* \param p_playlist the playlist to get the info from
* \param i_item the item on which we want the info ( -1 for current )
* \param psz_cat the category in which the info is stored
* \param psz_name the name of the info
* \return the info value if any, NULL else
*/
char * playlist_GetInfo( playlist_t *p_playlist, int i_item,
const char * psz_cat, const char *psz_name )
{
/* Check the existence of the playlist */
if( p_playlist == NULL)
{
return strdup("");
}
/* Get a correct item */
if( i_item >= 0 && i_item < p_playlist->i_size )
{
}
else if( p_playlist->i_size > 0 )
{
i_item = p_playlist->i_index;
}
else
{
return strdup("");
}
return playlist_GetItemInfo( p_playlist->pp_items[i_item] , psz_cat,
psz_name );
}
/**
* Get one special info, from an item (no need for p_playlist)
*
* \param p_item the item on which we want the info
* \param psz_cat the category in which the info is stored
* \param psz_name the name of the info
* \return the info value if any, NULL else
*/
char * playlist_GetItemInfo( playlist_item_t *p_item,
const char * psz_cat, const char *psz_name )
{
int i,j ;
for( i = 0 ; i< p_item->i_categories ; i++ )
{
if( !strcmp( p_item->pp_categories[i]->psz_name , psz_cat ) )
{
for( j = 0 ; j< p_item->pp_categories[i]->i_infos ; j++ )
{
if( !strcmp( p_item->pp_categories[i]->pp_infos[j]->psz_name,
psz_name ) )
{
return
strdup(p_item->pp_categories[i]->pp_infos[j]->psz_value );
}
}
}
}
return strdup("");
}
/**
* Get one info category. Creates it if it does not exist
*
* \param p_playlist the playlist to get the info from
* \param i_item the item on which we want the info ( -1 for current )
* \param psz_cat the category we want
* \return the info category.
*/
item_info_category_t *
playlist_GetCategory( playlist_t *p_playlist, int i_item,
const char * psz_cat )
{
int i;
/* Check the existence of the playlist */
if( p_playlist == NULL)
{
return NULL;
}
/* Get a correct item */
if( i_item >= 0 && i_item < p_playlist->i_size )
{
}
else if( p_playlist->i_size > 0 )
{
i_item = p_playlist->i_index;
}
else
{
return NULL;
}
return playlist_GetItemCategory( p_playlist->pp_items[i_item] , psz_cat );
}
/**
* Get one info category (no p_playlist). Creates it if it does not exist
*
* \param p_item the playlist to search categories in
* \param psz_cat the category we want
* \return the info category.
*/
item_info_category_t *playlist_GetItemCategory( playlist_item_t *p_item,
const char *psz_cat )
{
int i;
/* Search the category */
for( i = 0 ; i< p_item->i_categories ; i++ )
{
if( !strncmp( p_item->pp_categories[i]->psz_name , psz_cat,
strlen(psz_cat) ) )
{
return p_item->pp_categories[i];
}
}
/* We did not find the category, create it */
return playlist_CreateItemCategory( p_item, psz_cat );
}
/**
* Create one info category.
*
* \param p_playlist the playlist to get the info from
* \param i_item the item on which we want the info ( -1 for current )
* \param psz_cat the category we want to create
* \return the info category.
*/
item_info_category_t *
playlist_CreateCategory( playlist_t *p_playlist, int i_item,
const char * psz_cat )
{
playlist_item_t *p_item = NULL;
/* Check the existence of the playlist */
if( p_playlist == NULL)
{
return NULL;
}
/* Get a correct item */
if( i_item >= 0 && i_item < p_playlist->i_size )
{
p_item = p_playlist->pp_items[i_item];
}
else if( p_playlist->i_size > 0 )
{
p_item = p_playlist->pp_items[p_playlist->i_index];
}
else
{
return NULL;
}
return playlist_CreateItemCategory( p_item, psz_cat );
}
/**
* Create one info category for an item ( no p_playlist required )
*
* \param p_playlist the playlist to get the info from
* \param i_item the item on which we want the info ( -1 for current )
* \param psz_cat the category we want to create
* \return the info category.
*/
item_info_category_t *
playlist_CreateItemCategory( playlist_item_t *p_item, const char *psz_cat )
{
item_info_category_t *p_cat;
int i;
for( i = 0 ; i< p_item->i_categories ; i++)
{
if( !strcmp( p_item->pp_categories[i]->psz_name,psz_cat ) )
{
return p_item->pp_categories[i];
}
}
if( ( p_cat = malloc( sizeof( item_info_category_t) ) ) == NULL )
{
return NULL;
}