00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef VLC_MEDIA_LIBRARY_H
00029 # define VLC_MEDIA_LIBRARY_H
00030
00031 # ifdef __cplusplus
00032 extern "C" {
00033 # endif
00034
00035 #include <vlc_common.h>
00036 #include <vlc_playlist.h>
00037
00038
00039
00040
00041
00042 #define ML_PERSON_ARTIST "Artist"
00043 #define ML_PERSON_ALBUM_ARTIST "Album Artist"
00044 #define ML_PERSON_ENCODER "Encoder"
00045 #define ML_PERSON_PUBLISHER "Publisher"
00046
00047
00048 #define ml_priv( gc, t ) ((t *)(((char *)(gc)) - offsetof(t, ml_gc_data)))
00049
00050
00051
00052
00053
00054
00055
00056 typedef enum
00057 {
00058 ML_ALBUM = 1,
00059 ML_ALBUM_ID,
00060 ML_ALBUM_COVER,
00061
00062 ML_ARTIST,
00063
00064 ML_ARTIST_ID,
00065
00066 ML_COMMENT,
00067 ML_COUNT_MEDIA,
00068 ML_COUNT_ALBUM,
00069 ML_COUNT_PEOPLE,
00070 ML_COVER,
00071 ML_DURATION,
00072 ML_DISC_NUMBER,
00073 ML_EXTRA,
00074 ML_FIRST_PLAYED,
00075 ML_FILESIZE,
00076 ML_GENRE,
00077 ML_ID,
00078 ML_IMPORT_TIME,
00079 ML_LANGUAGE,
00080 ML_LAST_PLAYED,
00081 ML_LAST_SKIPPED,
00082 ML_ORIGINAL_TITLE,
00083 ML_PEOPLE,
00084 ML_PEOPLE_ID,
00085 ML_PEOPLE_ROLE,
00086 ML_PLAYED_COUNT,
00087 ML_PREVIEW,
00088 ML_SKIPPED_COUNT,
00089 ML_SCORE,
00090 ML_TITLE,
00091 ML_TRACK_NUMBER,
00092 ML_TYPE,
00093 ML_URI,
00094 ML_VOTE,
00095 ML_YEAR,
00096 ML_DIRECTORY,
00097 ML_MEDIA,
00098 ML_MEDIA_SPARSE,
00099 ML_MEDIA_EXTRA,
00100
00101
00102 ML_LIMIT = -1,
00103 ML_SORT_DESC = -2,
00104 ML_SORT_ASC = -3,
00105 ML_DISTINCT = -4,
00106 ML_END = -42
00107 } ml_select_e;
00108
00109
00110 typedef enum
00111 {
00112 ML_UNKNOWN = 0,
00113 ML_AUDIO = 1 << 0,
00114 ML_VIDEO = 1 << 1,
00115 ML_STREAM = 1 << 2,
00116 ML_NODE = 1 << 3,
00117 ML_REMOVABLE = 1 << 4,
00118 } ml_type_e;
00119
00120
00121 typedef enum {
00122 ML_TYPE_INT,
00123 ML_TYPE_PSZ,
00124 ML_TYPE_TIME,
00125 ML_TYPE_MEDIA,
00126 } ml_result_type_e;
00127
00128
00129 typedef enum
00130 {
00131 ML_SET_DATABASE,
00132
00133
00134
00135 ML_INIT_DATABASE,
00136 ML_ADD_INPUT_ITEM,
00137 ML_ADD_PLAYLIST_ITEM,
00138 ML_ADD_MONITORED,
00139 ML_DEL_MONITORED,
00140 ML_GET_MONITORED,
00141 } ml_control_e;
00142
00143
00144 typedef enum
00145 {
00146 ML_OP_NONE = 0,
00147 ML_OP_AND,
00148 ML_OP_OR,
00149 ML_OP_NOT,
00150 ML_OP_SPECIAL
00151
00152 } ml_op_e;
00153
00154
00155 typedef enum
00156 {
00157 ML_COMP_NONE = 0,
00158 ML_COMP_LESSER,
00159 ML_COMP_LESSER_OR_EQUAL,
00160 ML_COMP_EQUAL,
00161 ML_COMP_GREATER_OR_EQUAL,
00162 ML_COMP_GREATER,
00163 ML_COMP_HAS,
00164 ML_COMP_STARTS_WITH,
00165 ML_COMP_ENDS_WITH,
00166 } ml_comp_e;
00167
00168
00169
00170
00171
00172 typedef struct media_library_t media_library_t;
00173 typedef struct media_library_sys_t media_library_sys_t;
00174
00175 typedef struct ml_media_t ml_media_t;
00176 typedef struct ml_result_t ml_result_t;
00177 typedef struct ml_element_t ml_element_t;
00178 typedef struct ml_person_t ml_person_t;
00179 typedef struct ml_ftree_t ml_ftree_t;
00180
00181
00182 typedef struct ml_gc_object_t
00183 {
00184 vlc_spinlock_t spin;
00185 bool pool;
00186 uintptr_t refs;
00187 void (*pf_destructor) (struct ml_gc_object_t *);
00188 } ml_gc_object_t;
00189
00190 #define ML_GC_MEMBERS ml_gc_object_t ml_gc_data;
00191
00192
00193 struct media_library_t
00194 {
00195 VLC_COMMON_MEMBERS
00196
00197 module_t *p_module;
00198 media_library_sys_t *p_sys;
00199
00200
00201 struct
00202 {
00203
00204 int ( * pf_Find ) ( media_library_t *p_media_library,
00205 vlc_array_t *p_result_array,
00206 va_list args );
00207
00208
00209 int ( * pf_FindAdv ) ( media_library_t *p_media_library,
00210 vlc_array_t *p_result_array,
00211 ml_select_e selected_type,
00212 const char *psz_lvalue,
00213 ml_ftree_t *tree );
00214
00215
00216 int ( * pf_Update ) ( media_library_t *p_media_library,
00217 ml_select_e selected_type,
00218 const char *psz_lvalue,
00219 ml_ftree_t *where,
00220 vlc_array_t *changes );
00221
00222
00223 int ( * pf_Delete ) ( media_library_t *p_media_library,
00224 vlc_array_t *p_array );
00225
00226
00227 int ( * pf_Control ) ( media_library_t *p_media_library,
00228 int i_query, va_list args );
00229
00230
00231 input_item_t* ( * pf_InputItemFromMedia ) (
00232 media_library_t *p_media_library, int i_media );
00233
00234
00235 ml_media_t* ( * pf_GetMedia ) (
00236 media_library_t *p_media_library, int i_media,
00237 ml_select_e select, bool reload );
00238 } functions;
00239 };
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252 struct ml_media_t
00253 {
00254 ML_GC_MEMBERS
00255 vlc_mutex_t lock;
00256 bool b_sparse;
00257 ml_type_e i_type;
00258 int8_t i_vote;
00259 int16_t i_disc_number;
00260 int16_t i_track_number;
00261 int16_t i_year;
00262 int32_t i_id;
00263 int32_t i_score;
00264 int32_t i_album_id;
00265 int32_t i_played_count;
00266 int32_t i_skipped_count;
00267 int32_t i_bitrate;
00268 int32_t i_samplerate;
00269 int32_t i_bpm;
00270 char *psz_uri;
00271 char *psz_title;
00272 char *psz_orig_title;
00273 char *psz_album;
00274 char *psz_cover;
00275 char *psz_genre;
00276 char *psz_preview;
00277 char *psz_comment;
00278 char *psz_language;
00279 char *psz_extra;
00280 ml_person_t *p_people;
00281
00282
00283 int64_t i_filesize;
00284 mtime_t i_duration;
00285 mtime_t i_last_played;
00286 mtime_t i_last_skipped;
00287 mtime_t i_first_played;
00288 mtime_t i_import_time;
00289
00290 };
00291
00292
00293
00294
00295
00296
00297 struct ml_result_t
00298 {
00299 int32_t id;
00300 ml_result_type_e type;
00301 union
00302 {
00303
00304 int i;
00305 char *psz;
00306 mtime_t time;
00307
00308
00309 ml_media_t *p_media;
00310 } value;
00311 };
00312
00313
00314
00315
00316
00317
00318 struct ml_element_t
00319 {
00320 ml_select_e criteria;
00321 union
00322 {
00323 int i;
00324 char* str;
00325 } value;
00326 union
00327 {
00328 int i;
00329 char* str;
00330 } lvalue;
00331 };
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344 struct ml_ftree_t
00345 {
00346 ml_op_e op;
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357 ml_ftree_t *left;
00358 ml_ftree_t *right;
00359 ml_select_e criteria;
00360
00361
00362 ml_comp_e comp;
00363 union
00364 {
00365 int i;
00366 char *str;
00367 } value;
00368 union
00369 {
00370 int i;
00371 char *str;
00372 } lvalue;
00373
00374
00375 };
00376
00377
00378
00379
00380
00381 struct ml_person_t
00382 {
00383 char *psz_role;
00384 char *psz_name;
00385 int i_id;
00386 ml_person_t *p_next;
00387 };
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400 VLC_EXPORT( media_library_t*, ml_Hold, ( vlc_object_t* p_this ) );
00401 #define ml_Hold( a ) ml_Hold( VLC_OBJECT(a) )
00402
00403
00404
00405
00406
00407 VLC_EXPORT( void, ml_Release, ( vlc_object_t* p_this ) );
00408 #define ml_Release(a) ml_Release( VLC_OBJECT(a) )
00409
00410
00411
00412
00413
00414
00415
00416 VLC_EXPORT( media_library_t*, ml_Create, ( vlc_object_t *p_this, char* psz_name ) );
00417
00418
00419
00420
00421
00422 VLC_EXPORT( void, ml_Destroy, ( vlc_object_t* p_this ) );
00423
00424
00425
00426
00427
00428
00429
00430
00431 static inline int ml_ControlVa( media_library_t *p_media_library,
00432 ml_control_e i_type, va_list args )
00433 {
00434 return p_media_library->functions.pf_Control( p_media_library,
00435 i_type,
00436 args );
00437 }
00438
00439
00440
00441
00442
00443
00444 #define ml_Control( a, b, args... ) __ml_Control( a, b, ## args )
00445 static inline int __ml_Control( media_library_t *p_media_library,
00446 ml_control_e i_type, ... )
00447 {
00448 va_list args;
00449 int returned;
00450
00451 va_start( args, i_type );
00452 returned = ml_ControlVa( p_media_library, i_type, args );
00453 va_end( args );
00454
00455 return returned;
00456 }
00457
00458
00459
00460
00461
00462
00463 static inline int ml_AttributeIsString( ml_select_e meta )
00464 {
00465 switch( meta )
00466 {
00467
00468 case ML_ALBUM:
00469 case ML_ARTIST:
00470 case ML_COMMENT:
00471 case ML_COVER:
00472 case ML_EXTRA:
00473 case ML_GENRE:
00474 case ML_LANGUAGE:
00475 case ML_PREVIEW:
00476 case ML_PEOPLE:
00477 case ML_PEOPLE_ROLE:
00478 case ML_ORIGINAL_TITLE:
00479 case ML_TITLE:
00480 case ML_URI:
00481 return 1;
00482
00483
00484 case ML_ALBUM_ID:
00485 case ML_ARTIST_ID:
00486 case ML_DURATION:
00487 case ML_DISC_NUMBER:
00488 case ML_COUNT_MEDIA:
00489 case ML_COUNT_ALBUM:
00490 case ML_COUNT_PEOPLE:
00491 case ML_FILESIZE:
00492 case ML_FIRST_PLAYED:
00493 case ML_ID:
00494 case ML_IMPORT_TIME:
00495 case ML_LAST_PLAYED:
00496 case ML_LIMIT:
00497 case ML_PLAYED_COUNT:
00498 case ML_PEOPLE_ID:
00499 case ML_SCORE:
00500 case ML_SKIPPED_COUNT:
00501 case ML_TRACK_NUMBER:
00502 case ML_TYPE:
00503 case ML_VOTE:
00504 case ML_YEAR:
00505 return 0;
00506
00507
00508 default:
00509 return -1;
00510 }
00511 }
00512
00513
00514
00515
00516
00517
00518 static inline void ml_gc_incref( ml_media_t* p_media )
00519 {
00520 ml_gc_object_t* p_gc = &p_media->ml_gc_data;
00521 if( p_gc == NULL )
00522 return;
00523
00524 vlc_spin_lock (&p_gc->spin);
00525 ++p_gc->refs;
00526 vlc_spin_unlock (&p_gc->spin);
00527 }
00528
00529
00530
00531
00532
00533 static inline void ml_gc_decref( ml_media_t* p_media )
00534 {
00535
00536 unsigned refs;
00537 bool pool;
00538 ml_gc_object_t* p_gc = &p_media->ml_gc_data;
00539 if( p_gc == NULL )
00540 return;
00541
00542 vlc_spin_lock (&p_gc->spin);
00543 refs = --p_gc->refs;
00544 pool = p_gc->pool;
00545 vlc_spin_unlock (&p_gc->spin);
00546
00547 if( refs == 0 && pool == false )
00548 {
00549 vlc_spin_destroy (&p_gc->spin);
00550 p_gc->pf_destructor (p_gc);
00551 }
00552 }
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563 static inline void ml_FreePeople( ml_person_t *p_person )
00564 {
00565 if( p_person == NULL )
00566 return;
00567 ml_FreePeople( p_person->p_next );
00568 free( p_person->psz_name );
00569 free( p_person->psz_role );
00570 free( p_person );
00571 }
00572
00573
00574
00575
00576
00577
00578 static inline void ml_FreeMediaContent( ml_media_t *p_media )
00579 {
00580 free( p_media->psz_uri );
00581 free( p_media->psz_title );
00582 free( p_media->psz_orig_title );
00583 free( p_media->psz_cover );
00584 free( p_media->psz_comment );
00585 free( p_media->psz_extra );
00586 free( p_media->psz_genre );
00587 free( p_media->psz_album );
00588 free( p_media->psz_preview );
00589 free( p_media->psz_language );
00590 ml_FreePeople( p_media->p_people );
00591 p_media->b_sparse = true;
00592 p_media->i_id = 0;
00593 p_media->i_type = ML_UNKNOWN;
00594 p_media->i_album_id = 0;
00595 p_media->i_disc_number = 0;
00596 p_media->i_track_number = 0;
00597 p_media->i_year = 0;
00598 p_media->i_vote = 0;
00599 p_media->i_score = 0;
00600 p_media->i_filesize = 0;
00601 p_media->i_duration = 0;
00602 p_media->i_played_count = 0;
00603 p_media->i_last_played = 0;
00604 p_media->i_skipped_count = 0;
00605 p_media->i_last_skipped = 0;
00606 p_media->i_first_played = 0;
00607 p_media->i_import_time = 0;
00608 p_media->i_bitrate = 0;
00609 p_media->i_samplerate = 0;
00610 p_media->i_bpm = 0;
00611 }
00612
00613
00614
00615
00616
00617
00618 static inline void ml_FreeResult( ml_result_t *p_result )
00619 {
00620 if( p_result )
00621 {
00622 switch( p_result->type )
00623 {
00624 case ML_TYPE_PSZ:
00625 free( p_result->value.psz );
00626 break;
00627 case ML_TYPE_MEDIA:
00628 ml_gc_decref( p_result->value.p_media );
00629 break;
00630 default:
00631 break;
00632 }
00633 free( p_result );
00634 }
00635 }
00636
00637
00638
00639
00640
00641
00642 static inline void ml_FreeElement( ml_element_t *p_elt )
00643 {
00644 if( p_elt )
00645 {
00646 if( ml_AttributeIsString( p_elt->criteria ) )
00647 {
00648 free( p_elt->value.str );
00649 }
00650 if( p_elt->criteria == ML_PEOPLE )
00651 {
00652 free( p_elt->lvalue.str );
00653 }
00654 free( p_elt );
00655 }
00656 }
00657
00658
00659
00660
00661
00662
00663
00664 static inline void ml_DestroyResultArray( vlc_array_t *p_result_array )
00665 {
00666 for( int i = 0; i < vlc_array_count( p_result_array ); i++ )
00667 {
00668 ml_FreeResult( ( ml_result_t* ) vlc_array_item_at_index(
00669 p_result_array, i ) );
00670 }
00671 }
00672
00673
00674
00675
00676
00677
00678
00679
00680 #define ml_LockMedia( a ) vlc_mutex_lock( &a->lock )
00681 #define ml_UnlockMedia( a ) vlc_mutex_unlock( &a->lock )
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691 VLC_EXPORT( ml_media_t*, media_New, ( media_library_t* p_ml, int id,
00692 ml_select_e select, bool reload ) );
00693
00694
00695
00696 static inline int ml_CopyPersons( ml_person_t** a, ml_person_t* b );
00697
00698
00699
00700
00701
00702
00703
00704
00705 static inline int ml_CopyMedia( ml_media_t *b, ml_media_t *a )
00706 {
00707 if( !a || !b ) return VLC_EGENERIC;
00708 if( a == b ) return VLC_SUCCESS;
00709 ml_LockMedia( a );
00710 ml_LockMedia( b );
00711 b->b_sparse = a->b_sparse;
00712 b->i_id = a->i_id;
00713 b->i_type = a->i_type;
00714 b->i_album_id = a->i_album_id;
00715 b->i_disc_number = a->i_disc_number;
00716 b->i_track_number = a->i_track_number;
00717 b->i_year = a->i_year;
00718 b->i_vote = a->i_vote;
00719 b->i_score = a->i_score;
00720 b->i_filesize = a->i_filesize;
00721 b->i_duration = a->i_duration;
00722 b->i_played_count = a->i_played_count;
00723 b->i_last_played = a->i_last_played;
00724 b->i_skipped_count = a->i_skipped_count;
00725 b->i_last_skipped = a->i_last_skipped;
00726 b->i_first_played = a->i_first_played;
00727 b->i_import_time = a->i_import_time;
00728 b->i_bitrate = a->i_bitrate;
00729 b->i_samplerate = a->i_samplerate;
00730 b->i_bpm = a->i_bpm;
00731 free( b->psz_uri );
00732 if( a->psz_uri )
00733 b->psz_uri = strdup( a->psz_uri );
00734 free( b->psz_title );
00735 if( a->psz_title )
00736 b->psz_title = strdup( a->psz_title );
00737 free( b->psz_orig_title );
00738 if( a->psz_orig_title )
00739 b->psz_orig_title = strdup( a->psz_orig_title );
00740 free( b->psz_album );
00741 if( a->psz_album )
00742 b->psz_album = strdup( a->psz_album );
00743 free( b->psz_cover );
00744 if( a->psz_cover )
00745 b->psz_cover = strdup( a->psz_cover );
00746 free( b->psz_genre );
00747 if( a->psz_genre )
00748 b->psz_genre = strdup( a->psz_genre );
00749 free( b->psz_comment );
00750 if( a->psz_comment )
00751 b->psz_comment = strdup( a->psz_comment );
00752 free( b->psz_extra );
00753 if( a->psz_extra )
00754 b->psz_extra = strdup( a->psz_extra );
00755 free( b->psz_preview );
00756 if( a->psz_preview )
00757 b->psz_preview = strdup( a->psz_preview );
00758 free( b->psz_language );
00759 if( a->psz_language )
00760 b->psz_language = strdup( a->psz_language );
00761 ml_FreePeople( b->p_people );
00762 if( a->p_people ) ml_CopyPersons( &( b->p_people ), a->p_people );
00763 ml_UnlockMedia( b );
00764 ml_UnlockMedia( a );
00765 return VLC_SUCCESS;
00766 }
00767
00768
00769
00770
00771 #define ml_FreeFindTree( tree ) ml_GenericFreeFindTree( tree, true )
00772 #define ml_ShallowFreeFindTree( tree ) ml_GenericFreeFindTree( tree, false )
00773
00774
00775
00776
00777
00778 static inline void ml_GenericFreeFindTree( ml_ftree_t* tree, bool freestrings )
00779 {
00780 if( tree == NULL )
00781 return;
00782 if( tree->left )
00783 {
00784 ml_GenericFreeFindTree( tree->left, freestrings );
00785 free( tree->left );
00786 }
00787 if( tree->right )
00788 {
00789 ml_GenericFreeFindTree( tree->right, freestrings );
00790 free( tree->right );
00791 }
00792 if( tree->op == ML_OP_NONE && ml_AttributeIsString( tree->criteria )
00793 && freestrings == true)
00794 {
00795 free( tree->value.str );
00796 if( tree->criteria == ML_PEOPLE )
00797 free( tree->lvalue.str );
00798 }
00799 }
00800
00801
00802
00803
00804
00805
00806 static inline int ml_FtreeHasOp( ml_ftree_t* tree )
00807 {
00808 if( tree == NULL )
00809 return 0;
00810 if( tree->criteria > 0 && tree->op == ML_OP_NONE )
00811 return 1;
00812 else
00813 return ml_FtreeHasOp( tree->left ) + ml_FtreeHasOp( tree->right );
00814 }
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829 VLC_EXPORT( ml_ftree_t*, ml_OpConnectChilds, ( ml_op_e op, ml_ftree_t* left,
00830 ml_ftree_t* right ) );
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841 VLC_EXPORT( ml_ftree_t*, ml_FtreeSpec, ( ml_ftree_t* tree,
00842 ml_select_e crit,
00843 int limit,
00844 char* sort ) );
00845
00846
00847
00848
00849
00850
00851 static inline ml_ftree_t* ml_FtreeFastAnd( ml_ftree_t* left,
00852 ml_ftree_t* right )
00853 {
00854 if( ml_FtreeHasOp( left ) == 0 )
00855 {
00856 return ml_OpConnectChilds( ML_OP_NONE, left, right );
00857 }
00858 else
00859 {
00860 return ml_OpConnectChilds( ML_OP_AND, left, right );
00861 }
00862 }
00863 #define ml_FtreeAnd( left, right ) ml_OpConnectChilds( ML_OP_AND, left, right )
00864 #define ml_FtreeOr( left, right ) ml_OpConnectChilds( ML_OP_OR, left, right )
00865 #define ml_FtreeNot( left ) ml_OpConnectChilds( ML_OP_NOT, left, NULL )
00866
00867 #define ml_FtreeSpecAsc( tree, str ) ml_FtreeSpec( tree, ML_SORT_ASC, 0, str )
00868 #define ml_FtreeSpecDesc( tree, str ) ml_FtreeSpec( tree, ML_SORT_DESC, 0, str )
00869 #define ml_FtreeSpecLimit( tree, limit ) ml_FtreeSpec( tree, ML_LIMIT, limit, NULL )
00870 #define ml_FtreeSpecDistinct( tree ) ml_FtreeSpec( tree, ML_DISTINCT, 0, NULL )
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883 static inline input_item_t* ml_CreateInputItem(
00884 media_library_t *p_media_library, int i_media_id )
00885 {
00886 return p_media_library->functions.pf_InputItemFromMedia( p_media_library,
00887 i_media_id );
00888 }
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898 static inline int __ml_Find( media_library_t *p_media_library,
00899 vlc_array_t *p_result_array, ... )
00900 {
00901 va_list args;
00902 int returned;
00903
00904 va_start( args, p_result_array );
00905 returned = p_media_library->functions.pf_Find( p_media_library,
00906 p_result_array, args );
00907 va_end( args );
00908
00909 return returned;
00910 }
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923 static inline int ml_FindAdv( media_library_t *p_media_library,
00924 vlc_array_t *p_result_array,
00925 ml_select_e result_type,
00926 char* psz_lvalue,
00927 ml_ftree_t *tree )
00928 {
00929 return p_media_library->functions.pf_FindAdv( p_media_library,
00930 p_result_array,
00931 result_type,
00932 psz_lvalue,
00933 tree );
00934 }
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944 static inline int __ml_GetValue( media_library_t *p_media_library,
00945 ml_result_t *p_result,
00946 va_list args )
00947 {
00948 vlc_array_t *p_result_array = vlc_array_new();
00949 int i_ret = p_media_library->functions.pf_Find( p_media_library,
00950 p_result_array,
00951 args );
00952 if( i_ret != VLC_SUCCESS )
00953 goto exit;
00954 if( vlc_array_count( p_result_array ) > 0 )
00955 memcpy( p_result,
00956 ( ml_result_t* ) vlc_array_item_at_index( p_result_array, 0 ),
00957 sizeof( ml_result_t) );
00958 else
00959 i_ret = VLC_EGENERIC;
00960
00961 exit:
00962
00963 vlc_array_destroy( p_result_array );
00964 return i_ret;
00965 }
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975 #define ml_GetInt( ml, ... ) __ml_GetInt( ml, __VA_ARGS__, ML_LIMIT, 1, ML_END )
00976 static inline int __ml_GetInt( media_library_t *p_media_library, ... )
00977 {
00978 va_list args;
00979 va_start( args, p_media_library );
00980 ml_result_t result;
00981 int i_ret = __ml_GetValue( p_media_library, &result, args );
00982 va_end( args );
00983 if( i_ret != VLC_SUCCESS )
00984 return i_ret;
00985 else
00986 return result.value.i;
00987 }
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998 #define ml_FindPsz( ml, ... ) __ml_GetPsz( ml, __VA_ARGS__, ML_LIMIT, 1, ML_END )
00999 static inline char* __ml_GetPsz( media_library_t *p_media_library, ... )
01000 {
01001 va_list args;
01002 va_start( args, p_media_library );
01003 ml_result_t result;
01004 int i_ret = __ml_GetValue( p_media_library, &result, args );
01005 va_end( args );
01006 if( i_ret != VLC_SUCCESS )
01007 return NULL;
01008 else
01009 return result.value.psz;
01010 }
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021 static inline int ml_Update( media_library_t *p_media_library,
01022 ml_select_e selected_type,
01023 const char* psz_lvalue,
01024 ml_ftree_t *where,
01025 vlc_array_t *changes )
01026 {
01027 return p_media_library->functions.pf_Update( p_media_library,
01028 selected_type, psz_lvalue,
01029 where, changes );
01030 }
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040 VLC_EXPORT( int, ml_UpdateSimple, ( media_library_t *p_media_library,
01041 ml_select_e selected_type,
01042 const char* psz_lvalue,
01043 int id, ... ) );
01044 #define ml_UpdateSimple( ml, sel, lval, id, ... ) \
01045 ml_UpdateSimple( ml, sel, lval, id, __VA_ARGS__, ML_END )
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056 static inline int
01057 ml_DeleteSimple( media_library_t *p_media_library, int id )
01058 {
01059 vlc_array_t* p_where = vlc_array_new();
01060 ml_element_t* p_find = (ml_element_t *) calloc( 1, sizeof( ml_element_t ) );
01061 p_find->criteria = ML_ID;
01062 p_find->value.i = id;
01063 vlc_array_append( p_where, p_find );
01064 int i_return = p_media_library->functions.pf_Delete( p_media_library,
01065 p_where );
01066 free( p_find );
01067 vlc_array_destroy( p_where );
01068 return i_return;
01069 }
01070
01071
01072
01073
01074
01075
01076
01077 static inline int
01078 ml_Delete( media_library_t *p_media_library, vlc_array_t* p_array )
01079 {
01080 return p_media_library->functions.pf_Delete( p_media_library,
01081 p_array );
01082 }
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097 static inline int ml_CreateAppendPersonAdv( ml_person_t **pp_person,
01098 const char* psz_role, const char* psz_name, int i_id )
01099 {
01100 if( i_id == 0 || !( psz_name && *psz_name && psz_role && *psz_role ) )
01101 return VLC_SUCCESS;
01102 if( !pp_person )
01103 return VLC_EGENERIC;
01104 if( *pp_person != NULL )
01105 return ml_CreateAppendPersonAdv( &((**pp_person).p_next),
01106 psz_role, psz_name, i_id);
01107 *pp_person = ( ml_person_t * ) calloc( 1, sizeof( ml_person_t ) );
01108 (*pp_person)->psz_name = (psz_name && *psz_name) ? strdup( psz_name ): NULL;
01109 (*pp_person)->psz_role = (psz_role && *psz_role) ? strdup( psz_role ): NULL;
01110 (*pp_person)->i_id = i_id;
01111 (*pp_person)->p_next = NULL;
01112 return VLC_SUCCESS;
01113 }
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124 static inline int ml_CreateAppendPerson( ml_person_t **pp_person,
01125 ml_person_t *p_personfrom )
01126 {
01127 return ml_CreateAppendPersonAdv( pp_person,
01128 p_personfrom->psz_role,
01129 p_personfrom->psz_name,
01130 p_personfrom->i_id );
01131 }
01132
01133
01134
01135
01136
01137
01138
01139
01140 static inline int ml_CopyPersons( ml_person_t** a, ml_person_t* b )
01141 {
01142 int i_ret;
01143 while( b )
01144 {
01145 i_ret = ml_CreateAppendPerson( a, b );
01146 if( i_ret != VLC_SUCCESS )
01147 return i_ret;
01148 b = b->p_next;
01149 }
01150 return VLC_SUCCESS;
01151 }
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161 VLC_EXPORT( ml_person_t*, ml_GetPersonsFromMedia, ( media_library_t* p_ml,
01162 ml_media_t* p_media,
01163 const char *psz_role ) );
01164
01165
01166 #define ml_GetAlbumArtistsFromMedia( a, b ) ml_GetPersonsFromMedia( a, b, ML_PERSON_ALBUM_ARTIST );
01167 #define ml_GetArtistsFromMedia( a, b ) ml_GetPersonsFromMedia( a, b, ML_PERSON_ARTIST );
01168 #define ml_GetEncodersFromMedia( a, b ) ml_GetPersonsFromMedia( a, b, ML_PERSON_ENCODER );
01169 #define ml_GetPublishersFromMedia( a, b ) ml_GetPersonsFromMedia( a, b, ML_PERSON_PUBLISHER );
01170
01171
01172
01173
01174
01175
01176
01177 VLC_EXPORT( void, ml_DeletePersonTypeFromMedia, ( ml_media_t* p_media,
01178 const char *psz_role ) );
01179
01180
01181
01182
01183
01184
01185
01186
01187 VLC_EXPORT( void, ml_PlaySmartPlaylistBasedOn, ( media_library_t* p_ml,
01188 ml_ftree_t* p_tree ) );
01189
01190
01191
01192
01193
01194
01195
01196
01197
01198
01199 #define ml_GetAlbumById( a, id ) ml_GetPsz( a, ML_ALBUM, ML_ID, id )
01200 #define ml_GetArtistById( a, id ) ml_GetPsz( a, ML_PEOPLE, ML_PERSON_ARTIST, ML_ID, id )
01201 #define ml_GetCoverUriById( a, id ) ml_GetPsz( a, ML_COVER, ML_ID, id )
01202 #define ml_GetEncoderById( a, id ) ml_GetPsz( a, ML_PEOPLE, ML_PERSON_ENCODER, ML_ID, id )
01203 #define ml_GetExtraById( a, id ) ml_GetPsz( a, ML_EXTRA, ML_ID, id )
01204 #define ml_GetGenreById( a, id ) ml_GetPsz( a, ML_GENRE, ML_ID, id )
01205 #define ml_GetOriginalTitleById( a, id ) ml_GetPsz( a, ML_ORIGINAL_TITLE, ML_ID, id )
01206 #define ml_GetPublisherById( a, id ) ml_GetPsz( a, ML_PEOPLE, ML_PERSON_PUBLISHER, ML_ID, id )
01207 #define ml_GetTitleById( a, id ) ml_GetPsz( a, ML_TITLE, ML_ID, id )
01208 #define ml_GetUriById( a, id ) ml_GetPsz( a, ML_URI, ML_ID, id )
01209
01210 #define ml_GetAlbumIdById( a, id ) ml_GetInt( a, ML_ALBUM_ID, ML_ID, id )
01211 #define ml_GetArtistIdById( a, id ) ml_GetInt( a, ML_PEOPLE_ID, ML_PERSON_ARTIST, ML_ID, id )
01212 #define ml_GetDurationById( a, id ) ml_GetInt( a, ML_DURATION, ML_ID, id )
01213 #define ml_GetEncoderIdById( a, id ) ml_GetInt( a, ML_PEOPLE_ID, ML_PERSON_ENCODER, ML_ID, id )
01214 #define ml_GetLastPlayedById( a, id ) ml_GetInt( a, ML_LAST_PLAYED, ML_ID, id )
01215 #define ml_GetPlayedCountById( a, id ) ml_GetInt( a, ML_PLAYED_COUNT, ML_ID, id )
01216 #define ml_GetPublisherIdById( a, id ) ml_GetInt( a, ML_PEOPLE_ID, ML_PERSON_PUBLISHER, ML_ID, id )
01217 #define ml_GetScoreById( a, id ) ml_GetInt( a, ML_SCORE, ML_ID, id )
01218 #define ml_GetTrackNumberById( a, id ) ml_GetInt( a, ML_TRACK_NUMBER, ML_ID, id )
01219 #define ml_GetTypeById( a, id ) ml_GetInt( a, ML_TYPE, ML_ID, id )
01220 #define ml_GetYearById( a, id ) ml_GetInt( a, ML_YEAR, ML_ID, id )
01221 #define ml_GetVoteById( a, id ) ml_GetInt( a, ML_VOTE, ML_ID, id )
01222
01223
01224 #define ml_GetAlbumId( a, b ) ml_GetInt( a, ML_ALBUM_ID, ML_ALBUM, b )
01225
01226
01227 #define ml_GetArtistId( a, b ) ml_GetInt( a, ML_PERSON_ID, ML_PERSON_ARTIST, ML_PERSON, ML_PERSON_ARTIST, b )
01228 #define ml_GetEncoderId( a, b ) ml_GetInt( a, ML_PERSON_ID, ML_PERSON_ENCODER, ML_PERSON, ML_PERSON_ENCODER, b )
01229 #define ml_GetPublisherId( a, b ) ml_GetInt( a, ML_PERSON_ID, ML_PERSON_PUBLISHER, ML_PERSON, ML_PERSON_PUBLISHER, b )
01230
01231
01232 #define ml_GetMediaCount( a, ... ) __ml_GetInt( a, ML_COUNT_MEDIA, __VA_ARGS__, ML_END )
01233 #define ml_GetAlbumCount( a, ... ) __ml_GetInt( a, ML_COUNT_ALBUM, __VA_ARGS__, ML_END )
01234 #define ml_GetPeopleCount( a, ... ) __ml_GetInt( a, ML_COUNT_PEOPLE, __VA_ARGS__, ML_END )
01235
01236 #define ml_Find( a, b, ... ) __ml_Find( a, b, __VA_ARGS__, ML_END )
01237
01238 #define ml_FindAlbum( a, b, ... ) __ml_Find( a, b, ML_ALBUM, __VA_ARGS__, ML_END )
01239 #define ml_FindArtist( a, b, ... ) __ml_Find( a, b, ML_PERSON, ML_PERSON_ARTIST, __VA_ARGS__, ML_END )
01240 #define ml_FindEncoder( a, b, ... ) __ml_Find( a, b, ML_PERSON, ML_PERSON_ENCODER, __VA_ARGS__, ML_END )
01241 #define ml_FindGenre( a, b, ... ) __ml_Find( a, b, ML_GENRE, __VA_ARGS__, ML_END )
01242 #define ml_FindMedia( a, b, ... ) __ml_Find( a, b, ML_MEDIA, __VA_ARGS__, ML_END )
01243 #define ml_FindOriginalTitle( a, b, ... ) __ml_Find( a, b, ML_ORIGINAL_TITLE, __VA_ARGS__, ML_END )
01244 #define ml_FindPublisher( a, b, ... ) __ml_Find( a, b, ML_PERSON, ML_PERSON_PUBLISHER, __VA_ARGS__, ML_END )
01245 #define ml_FindTitle( a, b, ... ) __ml_Find( a, b, ML_TITLE, __VA_ARGS__, ML_END )
01246 #define ml_FindType( a, b, ... ) __ml_Find( a, b, ML_TYPE, __VA_ARGS__, ML_END )
01247 #define ml_FindUri( a, b, ... ) __ml_Find( a, b, ML_URI, __VA_ARGS__, ML_END )
01248 #define ml_FindYear( a, b, ... ) __ml_Find( a, b, ML_YEAR, __VA_ARGS__, ML_END )
01249
01250 #define ml_FindAllAlbums( a, b ) ml_FindAlbum( a, b, ML_DISTINCT )
01251 #define ml_FindAllArtists( a, b ) ml_FindArtist( a, b, ML_DISTINCT )
01252 #define ml_FindAllGenres( a, b ) ml_FindGenre( a, b, ML_DISTINCT )
01253 #define ml_FindAllMedias( a, b ) ml_FindMedia( a, b, ML_DISTINCT )
01254 #define ml_FindAllOriginalTitles( a, b ) ml_FindOriginalTitle( a, b, ML_DISTINCT )
01255 #define ml_FindAllPublishers( a, b, ... ) ml_FindPublisher( a, b, ML_DISTINCT )
01256 #define ml_FindAllTitles( a, b ) ml_FindTitle( a, b, ML_DISTINCT )
01257 #define ml_FindAllTypes( a, b ) ml_FindType( a, b, ML_DISTINCT )
01258 #define ml_FindAllUris( a, b ) ml_FindUri( a, b, ML_DISTINCT )
01259 #define ml_FindAllYears( a, b ) ml_FindYear( a, b, ML_DISTINCT )
01260
01261 #define ml_FindAlbumAdv( a, b, c ) ml_FindAdv( a, b, ML_ALBUM, NULL, c )
01262 #define ml_FindArtistAdv( a, b, c ) ml_FindAdv( a, b, ML_PERSON, ML_PERSON_ARTIST, c )
01263 #define ml_FindEncoderAdv( a, b, c ) ml_FindAdv( a, b, ML_PERSON, ML_PERSON_ENCODER, c )
01264 #define ml_FindGenreAdv( a, b, c ) ml_FindAdv( a, b, ML_GENRE, NULL, c )
01265 #define ml_FindMediaAdv( a, b, c ) ml_FindAdv( a, b, ML_MEDIA, NULL, c )
01266 #define ml_FindOriginalTitleAdv( a, b, c ) ml_FindAdv( a, b, ML_ORIGINAL_TITLE,NULL, c )
01267 #define ml_FindPublisherAdv( a, b, c ) ml_FindAdv( a, b, ML_PUBLISHER, ML_PERSON_PUBLISHER, c )
01268 #define ml_FindTitleAdv( a, b, c ) ml_FindAdv( a, b, ML_TITLE, NULL, c )
01269 #define ml_FindTypeAdv( a, b, c ) ml_FindAdv( a, b, ML_TYPE, NULL, c )
01270 #define ml_FindUriAdv( a, b, c ) ml_FindAdv( a, b, ML_URI, NULL, c )
01271 #define ml_FindYearAdv( a, b, c ) ml_FindAdv( a, b, ML_YEAR, NULL, c )
01272
01273
01274
01275 #ifdef __cplusplus
01276 }
01277 #endif
01278
01279 #endif