1//========================================================================= 2// FILENAME : tagutils-flc.c 3// DESCRIPTION : FLAC metadata reader 4//========================================================================= 5// Copyright (c) 2008- NETGEAR, Inc. All Rights Reserved. 6//========================================================================= 7 8/* 9 * This program is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation; either version 2 of the License, or 12 * (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program. If not, see <http://www.gnu.org/licenses/>. 21 */ 22 23static int 24_get_flctags(char *filename, struct song_metadata *psong) 25{ 26 FLAC__Metadata_SimpleIterator *iterator = 0; 27 FLAC__StreamMetadata *block; 28 unsigned int sec, ms; 29 int i; 30 int err = 0; 31 32 if(!(iterator = FLAC__metadata_simple_iterator_new())) 33 { 34 DPRINTF(E_FATAL, L_SCANNER, "Out of memory while FLAC__metadata_simple_iterator_new()\n"); 35 return -1; 36 } 37 38 if(!FLAC__metadata_simple_iterator_init(iterator, filename, true, true)) 39 { 40 DPRINTF(E_ERROR, L_SCANNER, "Cannot extract tag from %s\n", filename); 41 return -1; 42 } 43 44 do { 45 if(!(block = FLAC__metadata_simple_iterator_get_block(iterator))) 46 { 47 DPRINTF(E_ERROR, L_SCANNER, "Cannot extract tag from %s\n", filename); 48 err = -1; 49 goto _exit; 50 } 51 52 switch(block->type) 53 { 54 case FLAC__METADATA_TYPE_STREAMINFO: 55 sec = (unsigned int)(block->data.stream_info.total_samples / 56 block->data.stream_info.sample_rate); 57 ms = (unsigned int)(((block->data.stream_info.total_samples % 58 block->data.stream_info.sample_rate) * 1000) / 59 block->data.stream_info.sample_rate); 60 if ((sec == 0) && (ms == 0)) 61 break; /* Info is crap, escape div-by-zero. */ 62 psong->song_length = (sec * 1000) + ms; 63 psong->bitrate = (((uint64_t)(psong->file_size) * 1000) / (psong->song_length / 8)); 64 psong->samplerate = block->data.stream_info.sample_rate; 65 psong->channels = block->data.stream_info.channels; 66 break; 67 68 case FLAC__METADATA_TYPE_VORBIS_COMMENT: 69 for(i = 0; i < block->data.vorbis_comment.num_comments; i++) 70 { 71 vc_scan(psong, 72 (char*)block->data.vorbis_comment.comments[i].entry, 73 block->data.vorbis_comment.comments[i].length); 74 } 75 break; 76#if FLAC_API_VERSION_CURRENT >= 10 77 case FLAC__METADATA_TYPE_PICTURE: 78 psong->image_size = block->data.picture.data_length; 79 if((psong->image = malloc(psong->image_size))) 80 memcpy(psong->image, block->data.picture.data, psong->image_size); 81 else 82 DPRINTF(E_ERROR, L_SCANNER, "Out of memory [%s]\n", filename); 83 break; 84#endif 85 default: 86 break; 87 } 88 FLAC__metadata_object_delete(block); 89 } 90 while(FLAC__metadata_simple_iterator_next(iterator)); 91 92 _exit: 93 if(iterator) 94 FLAC__metadata_simple_iterator_delete(iterator); 95 96 return err; 97} 98 99static int 100_get_flcfileinfo(char *filename, struct song_metadata *psong) 101{ 102 psong->lossless = 1; 103 psong->vbr_scale = 1; 104 105 return 0; 106} 107