[vlc-devel] commit: Use VLC object for meta writer and factor code ( Rémi Denis-Courmont )
git version control
git at videolan.org
Sun Aug 23 19:33:34 CEST 2009
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Aug 23 20:15:39 2009 +0300| [7d1e5fe7fb99b75959fb0ed3a9c45e1c7d1ba74d] | committer: Rémi Denis-Courmont
Use VLC object for meta writer and factor code
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7d1e5fe7fb99b75959fb0ed3a9c45e1c7d1ba74d
---
include/vlc_common.h | 3 +-
include/vlc_meta.h | 7 +++-
modules/gui/macosx/playlistinfo.m | 31 +-------------------
modules/gui/qt4/components/info_panels.cpp | 32 +-------------------
modules/meta_engine/taglib.cpp | 3 +-
src/input/meta.c | 43 ++++++++++++++++++++++++++++
src/libvlccore.sym | 1 +
7 files changed, 55 insertions(+), 65 deletions(-)
diff --git a/include/vlc_common.h b/include/vlc_common.h
index 488057f..f7f45a8 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 e5b11b8..11c0369 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 dc316dc..fc902b5 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 2ac9e5a..7edf3b7 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 724fcfc..c499b51 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 ad97c29..77dfae3 100644
--- a/src/input/meta.c
+++ b/src/input/meta.c
@@ -28,6 +28,8 @@
#include <vlc_common.h>
#include <vlc_playlist.h>
+#include <vlc_url.h>
+
#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 b500402..5d40e4a 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
More information about the vlc-devel
mailing list