From: RĂ©mi Denis-Courmont Date: Sun, 23 Aug 2009 17:15:39 +0000 (+0300) Subject: Use VLC object for meta writer and factor code X-Git-Tag: 1.1.0-ff~3997 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=7d1e5fe7fb99b75959fb0ed3a9c45e1c7d1ba74d;p=vlc Use VLC object for meta writer and factor code --- diff --git a/include/vlc_common.h b/include/vlc_common.h index 488057fdda..f7f45a86cd 100644 --- a/include/vlc_common.h +++ b/include/vlc_common.h @@ -342,9 +342,8 @@ typedef struct osd_menu_state_t osd_menu_state_t; typedef struct vlm_t vlm_t; typedef struct vlm_message_t vlm_message_t; -/* divers */ +/* misc */ typedef struct vlc_meta_t vlc_meta_t; -typedef struct meta_export_t meta_export_t; /* Stats */ typedef struct counter_t counter_t; diff --git a/include/vlc_meta.h b/include/vlc_meta.h index e5b11b89d3..11c03693d4 100644 --- a/include/vlc_meta.h +++ b/include/vlc_meta.h @@ -195,10 +195,13 @@ enum { ALBUM_ART_ALL }; -struct meta_export_t +typedef struct meta_export_t { + VLC_COMMON_MEMBERS input_item_t *p_item; const char *psz_file; -}; +} meta_export_t; + +VLC_EXPORT( int, input_item_WriteMeta, (vlc_object_t *, input_item_t *) ); #endif diff --git a/modules/gui/macosx/playlistinfo.m b/modules/gui/macosx/playlistinfo.m index dc316dcb31..fc902b5e2b 100644 --- a/modules/gui/macosx/playlistinfo.m +++ b/modules/gui/macosx/playlistinfo.m @@ -368,29 +368,8 @@ static VLCInfo *_o_sharedInstance = nil; - (IBAction)saveMetaData:(id)sender { - playlist_t * p_playlist = pl_Hold( VLCIntf ); - if( !p_item ) goto error; - meta_export_t p_export; - p_export.p_item = p_item; - - /* we can write meta data only in a file */ - vlc_mutex_lock( &p_item->lock ); - int i_type = p_item->i_type; - vlc_mutex_unlock( &p_item->lock ); - - if( i_type != ITEM_TYPE_FILE ) - goto error; - - char *psz_uri_orig = input_item_GetURI( p_item ); - char *psz_uri = psz_uri_orig; - if( !strncmp( psz_uri, "file://", 7 ) ) - psz_uri += 7; /* strlen("file://") = 7 */ - - p_export.psz_file = strndup( psz_uri, PATH_MAX ); - free( psz_uri_orig ); - #define utf8( o_blub ) \ [[o_blub stringValue] UTF8String] @@ -406,13 +385,8 @@ static VLCInfo *_o_sharedInstance = nil; input_item_SetDescription( p_item, utf8( o_description_txt ) ); input_item_SetLanguage( p_item, utf8( o_language_txt ) ); - PL_LOCK; - p_playlist->p_private = &p_export; - - module_t *p_mod = module_need( p_playlist, "meta writer", NULL, false ); - if( p_mod ) - module_unneed( p_playlist, p_mod ); - PL_UNLOCK; + playlist_t * p_playlist = pl_Hold( VLCIntf ); + input_item_WriteMeta( p_playlist, p_item ); var_SetBool( p_playlist, "intf-change", true ); [self updatePanelWithItem: p_item]; @@ -422,7 +396,6 @@ static VLCInfo *_o_sharedInstance = nil; return; error: - pl_Release( VLCIntf ); NSRunAlertPanel(_NS("Error while saving meta"), _NS("VLC was unable to save the meta data."), _NS("OK"), nil, nil); diff --git a/modules/gui/qt4/components/info_panels.cpp b/modules/gui/qt4/components/info_panels.cpp index 2ac9e5abb8..7edf3b7c6b 100644 --- a/modules/gui/qt4/components/info_panels.cpp +++ b/modules/gui/qt4/components/info_panels.cpp @@ -249,31 +249,9 @@ void MetaPanel::update( input_item_t *p_item ) **/ void MetaPanel::saveMeta() { - playlist_t *p_playlist; - - meta_export_t p_export; - p_export.p_item = p_input; - if( p_input == NULL ) return; - /* we can write meta data only in a file */ - vlc_mutex_lock( &p_input->lock ); - int i_type = p_input->i_type; - vlc_mutex_unlock( &p_input->lock ); - if( i_type == ITEM_TYPE_FILE ) - { - char *psz_uri_orig = input_item_GetURI( p_input ); - char *psz_uri = psz_uri_orig; - if( !strncmp( psz_uri, "file://", 7 ) ) - psz_uri += 7; /* strlen("file://") = 7 */ - - p_export.psz_file = strndup( psz_uri, PATH_MAX ); - free( psz_uri_orig ); - } - else - return; - /* now we read the modified meta data */ input_item_SetTitle( p_input, qtu( title_text->text() ) ); input_item_SetArtist( p_input, qtu( artist_text->text() ) ); @@ -286,14 +264,8 @@ void MetaPanel::saveMeta() input_item_SetPublisher( p_input, qtu( publisher_text->text() ) ); input_item_SetDescription( p_input, qtu( description_text->text() ) ); - p_playlist = pl_Hold( p_intf ); - PL_LOCK; - p_playlist->p_private = &p_export; - - module_t *p_mod = module_need( p_playlist, "meta writer", NULL, false ); - if( p_mod ) - module_unneed( p_playlist, p_mod ); - PL_UNLOCK; + playlist_t *p_playlist = pl_Hold( p_intf ); + input_item_WriteMeta( VLC_OBJECT(p_playlist), p_input ); pl_Release( p_intf ); /* Reset the status of the mode. No need to emit any signal because parent diff --git a/modules/meta_engine/taglib.cpp b/modules/meta_engine/taglib.cpp index 724fcfc50d..c499b51b41 100644 --- a/modules/meta_engine/taglib.cpp +++ b/modules/meta_engine/taglib.cpp @@ -514,8 +514,7 @@ static void WriteMetaToXiph( Ogg::XiphComment* tag, input_item_t* p_item ) static int WriteMeta( vlc_object_t *p_this ) { - playlist_t *p_playlist = (playlist_t *)p_this; - meta_export_t *p_export = (meta_export_t *)p_playlist->p_private; + meta_export_t *p_export = (meta_export_t *)p_this; input_item_t *p_item = p_export->p_item; FileRef f; diff --git a/src/input/meta.c b/src/input/meta.c index ad97c29675..77dfae3529 100644 --- a/src/input/meta.c +++ b/src/input/meta.c @@ -28,6 +28,8 @@ #include #include +#include + #include "input_internal.h" #include "../playlist/art.h" @@ -129,3 +131,44 @@ exit: free( psz_arturl ); } +int input_item_WriteMeta( vlc_object_t *obj, input_item_t *p_item ) +{ + meta_export_t *p_export = + vlc_custom_create( obj, sizeof( *p_export ), VLC_OBJECT_GENERIC, + "meta writer" ); + if( p_export == NULL ) + return VLC_ENOMEM; + vlc_object_attach( p_export, obj ); + p_export->p_item = p_item; + + int type; + vlc_mutex_lock( &p_item->lock ); + type = p_item->i_type; + vlc_mutex_unlock( &p_item->lock ); + if( type != ITEM_TYPE_FILE ) + { + char *psz_uri = input_item_GetURI( p_item ); + +#warning FIXME: function for URI->path conversion! + decode_URI( psz_uri ); + if( !strncmp( psz_uri, "file://", 7 ) ) + { + p_export->psz_file = strdup( psz_uri + 7 ); + free( psz_uri ); + } + else +#warning This should not happen! + p_export->psz_file = psz_uri; + } + else + { + vlc_object_release( p_export ); + return VLC_EGENERIC; + } + + module_t *p_mod = module_need( p_export, "meta writer", NULL, false ); + if( p_mod ) + module_unneed( p_export, p_mod ); + vlc_object_release( p_export ); + return VLC_SUCCESS; +} diff --git a/src/libvlccore.sym b/src/libvlccore.sym index b500402708..5d40e4af7c 100644 --- a/src/libvlccore.sym +++ b/src/libvlccore.sym @@ -205,6 +205,7 @@ input_item_SetDuration input_item_SetMeta input_item_SetName input_item_SetURI +input_item_WriteMeta input_MetaTypeToLocalizedString __input_Read input_SplitMRL