Changeset 411 for libmpc/trunk/mpcchap/mpcchap.c
- Timestamp:
- 10/31/08 00:20:05 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libmpc/trunk/mpcchap/mpcchap.c
r408 r411 30 30 void Init_Tags ( void ); 31 31 int FinalizeTags ( FILE* fp, unsigned int Version, unsigned int flags ); 32 int addtag ( const char* key, size_t keylen, const char* value, size_t valuelen, int converttoutf8, int flags ); 32 int addtag ( const char* key, size_t keylen, const char* value, 33 size_t valuelen, int converttoutf8, int flags ); 33 34 #define TAG_NO_HEADER 1 34 35 #define TAG_NO_FOOTER 2 … … 39 40 #define atoll _atoi64 40 41 #endif 42 43 static const int Ptis[] = { PTI_TITLE, PTI_PERFORMER, PTI_SONGWRITER, PTI_COMPOSER, 44 PTI_ARRANGER, PTI_MESSAGE, PTI_GENRE}; 45 static char const * const APE_keys[] = {"Title", "Artist", "Songwriter", "Composer", 46 "Arranger", "Comment", "Genre"}; 41 47 42 48 static void usage(const char *exename) … … 77 83 int nchap = iniparser_getnsec(dict); 78 84 for (i = 0; i < nchap; i++) { 79 Init_Tags();80 int j, nitem, tag_len= 0;85 int j, nitem, ntags = 0, tag_len = 0; 86 mpc_uint16_t gain = 0, peak = 0; 81 87 char * chap_sec = iniparser_getsecname(dict, i); 82 88 mpc_int64_t chap_pos = atoll(chap_sec); 89 83 90 if (chap_pos > si->samples - si->beg_silence) 84 fprintf(stderr, "warning : chapter %i starts @ %lli after the end of the stream (%lli)\n", i + 1, chap_pos, si->samples - si->beg_silence); 91 fprintf(stderr, "warning : chapter %i starts @ %lli samples after the end of the stream (%lli)\n", 92 i + 1, chap_pos, si->samples - si->beg_silence); 93 94 Init_Tags(); 95 85 96 nitem = iniparser_getnkey(dict, i); 86 97 for (j = 0; j < nitem; j++) { … … 88 99 int key_len, item_len; 89 100 item_key = iniparser_getkeyname(dict, i, j, & item_value); 90 key_len = strlen(item_key); 91 item_len = strlen(item_value); 92 addtag(item_key, key_len, item_value, item_len, 0, 0); 93 tag_len += key_len + item_len; 101 if (strcmp(item_key, "gain") == 0) 102 gain = atoi(item_value); 103 else if (strcmp(item_key, "peak") == 0) 104 peak = atoi(item_value); 105 else { 106 key_len = strlen(item_key); 107 item_len = strlen(item_value); 108 addtag(item_key, key_len, item_value, item_len, 0, 0); 109 tag_len += key_len + item_len; 110 ntags++; 111 } 94 112 } 95 if (n item > 0) tag_len += 24 + nitem* 9;113 if (ntags > 0) tag_len += 24 + ntags * 9; 96 114 char block_header[12] = "CT"; 97 115 char sample_offset[10]; 98 116 int offset_size = encodeSize(chap_pos, sample_offset, MPC_FALSE); 99 tag_len = encodeSize(tag_len + offset_size + 2, block_header + 2, MPC_TRUE);117 tag_len = encodeSize(tag_len + 4 + offset_size + 2, block_header + 2, MPC_TRUE); 100 118 fwrite(block_header, 1, tag_len + 2, in_file); 101 119 fwrite(sample_offset, 1, offset_size, in_file); 120 sample_offset[0] = gain >> 8; 121 sample_offset[1] = gain & 0xFF; 122 sample_offset[2] = peak >> 8; 123 sample_offset[3] = peak & 0xFF; 124 fwrite(sample_offset, 1, 4, in_file); 102 125 FinalizeTags(in_file, TAG_VERSION, TAG_NO_FOOTER | TAG_NO_PREAMBLE); 103 126 } … … 115 138 mpc_status add_chaps_cue(char * mpc_file, char * chap_file, mpc_demux * demux, mpc_streaminfo * si) 116 139 { 117 int Ptis[7] = { PTI_TITLE, PTI_PERFORMER, PTI_SONGWRITER, PTI_COMPOSER,118 PTI_ARRANGER, PTI_MESSAGE, PTI_GENRE};119 char * APE_keys[7] = {"Title", "Artist", "Songwriter", "Composer",120 "Arranger", "Comment", "Genre"};121 122 140 Cd *cd = 0; 123 141 int nchap, format = UNKNOWN; … … 155 173 156 174 if (chap_pos > si->samples - si->beg_silence) 157 fprintf(stderr, "warning : chapter %i starts @ %lli after the end of the stream (%lli)\n", i, chap_pos, si->samples - si->beg_silence); 175 fprintf(stderr, "warning : chapter %i starts @ %lli samples after the end of the stream (%lli)\n", 176 i, chap_pos, si->samples - si->beg_silence); 158 177 159 178 Init_Tags(); … … 168 187 169 188 for (j = 0; j < (sizeof(Ptis) / sizeof(*Ptis)); j++) { 170 char * item_key = APE_keys[j], * item_value;189 char const * item_key = APE_keys[j], * item_value; 171 190 item_value = cdtext_get (Ptis[j], cdtext); 172 191 if (item_value != 0) { … … 183 202 char sample_offset[10]; 184 203 int offset_size = encodeSize(chap_pos, sample_offset, MPC_FALSE); 185 tag_len = encodeSize(tag_len + offset_size + 2, block_header + 2, MPC_TRUE);204 tag_len = encodeSize(tag_len + 4 + offset_size + 2, block_header + 2, MPC_TRUE); 186 205 fwrite(block_header, 1, tag_len + 2, in_file); 187 206 fwrite(sample_offset, 1, offset_size, in_file); 207 fwrite("\0\0\0\0", 1, 4, in_file); // put unknow chapter gain / peak 188 208 FinalizeTags(in_file, TAG_VERSION, TAG_NO_FOOTER | TAG_NO_PREAMBLE); 189 209 } … … 201 221 { 202 222 int i; 203 unsigned int tag_size;204 223 FILE * out_file; 205 char * tag;224 mpc_chap_info * chap; 206 225 207 226 if (chap_nb <= 0) … … 213 232 214 233 for (i = 0; i < chap_nb; i++) { 215 fprintf(out_file, "[%lli]\n", mpc_demux_chap(demux, i, &tag, &tag_size)); 216 if (tag_size > 0) { 234 chap = mpc_demux_chap(demux, i); 235 fprintf(out_file, "[%lli]\ngain=%i\npeak=%i\n", chap->sample, chap->gain, chap->peak); 236 if (chap->tag_size > 0) { 217 237 int item_count, j; 238 char const * tag = chap->tag; 218 239 item_count = tag[8] | (tag[9] << 8) | (tag[10] << 16) | (tag[11] << 24); 219 240 tag += 24;
Note: See TracChangeset
for help on using the changeset viewer.