Merge branch 'OggComment' of https://github.com/audinowho/stb into work2
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Sean Barrett · committed by Sean Barrett · parents 49cbedf, 2a0cff1 · Browse files · 1 file·+77 added−1 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+77 added−1 removed
- other:+77 added−1 removed
Provenance
- Commit
95ce252- Tree
88dbed0- Author
Sean Barrett <sean@nothings.org>- Committer
Sean Barrett <sean@nothings.org>- Parent 1
49cbedf- Parent 2
2a0cff1
1 file changed+77 added−1 removed
modified:stb_vorbis.c+77 added-1 removed
128 unmodified lines129 130 int max_frame_size;131 } stb_vorbis_info;132 133+typedef struct134+{135+ char *vendor;136+137+ int comment_list_length;138+ char **comment_list;139+} stb_vorbis_comment;140+141 // get general information about the file142 extern stb_vorbis_info stb_vorbis_get_info(stb_vorbis *f);143 144+// get ogg comments145+extern stb_vorbis_comment stb_vorbis_get_comment(stb_vorbis *f);146+147 // get the last error detected (clears it, too)148 extern int stb_vorbis_get_error(stb_vorbis *f);149 150 // close an ogg vorbis file and free all memory in use618 unmodified lines769 unsigned int setup_memory_required;770 unsigned int temp_memory_required;771 unsigned int setup_temp_memory_required;772 773+ char *vendor;774+ int comment_list_length;775+ char **comment_list;776+777 // input config778 #ifndef STB_VORBIS_NO_STDIO779 FILE *f;780 uint32 f_start;775 unmodified lines1556 f->valid_bits = 0;1557 return x;1558 }1559 1560+static int get32_packet(vorb *f)1561+{1562+ uint32 x;1563+ x = get8_packet(f);1564+ x += get8_packet(f) << 8;1565+ x += get8_packet(f) << 16;1566+ x += (uint32) get8_packet(f) << 24;1567+ return x;1568+}1569+1570 static void flush_packet(vorb *f)1571 {1572 while (get8_packet_raw(f) != EOP);1573 }2041 unmodified lines3615 if (!(x & 1)) return error(f, VORBIS_invalid_first_page);3616 3617 // second packet!3618 if (!start_page(f)) return FALSE;3594-3619+ 3620 if (!start_packet(f)) return FALSE;3621+3622+ if (!next_segment(f)) return FALSE;3623+3624+ if (get8_packet(f) != VORBIS_packet_comment) return error(f, VORBIS_invalid_setup);3625+ for (i=0; i < 6; ++i) header[i] = get8_packet(f);3626+ if (!vorbis_validate(header)) return error(f, VORBIS_invalid_setup);3627+ //file vendor3628+ len = get32_packet(f);3629+ f->vendor = (char*)setup_malloc(f, sizeof(char) * (len+1));3630+ for(i=0; i < len; ++i) {3631+ f->vendor[i] = get8_packet(f);3632+ }3633+ f->vendor[len] = (char)NULL;3634+ //user comments3635+ f->comment_list_length = get32_packet(f);3636+ f->comment_list = (char**)setup_malloc(f, sizeof(char*) * (f->comment_list_length));3637+ 3638+ for(i=0; i < f->comment_list_length; ++i) {3639+ len = get32_packet(f);3640+ f->comment_list[i] = (char*)setup_malloc(f, sizeof(char) * (len+1));3641+3642+ for(j=0; j < len; ++j) {3643+ f->comment_list[i][j] = get8_packet(f);3644+ }3645+ f->comment_list[i][len] = (char)NULL;3646+ }3647+3648+ // framing_flag3649+ x = get8_packet(f);3650+ if (!(x & 1)) return error(f, VORBIS_invalid_setup);3651+3652+ 3653+ skip(f, f->bytes_in_seg);3654+ f->bytes_in_seg = 0;3655+3656 do {3657 len = next_segment(f);3658 skip(f, len);3659 f->bytes_in_seg = 0;517 unmodified lines4177 4178 static void vorbis_deinit(stb_vorbis *p)4179 {4180 int i,j;4181+4182+ setup_free(p, p->vendor);4183+ for (i=0; i < p->comment_list_length; ++i) {4184+ setup_free(p, p->comment_list[i]);4185+ }4186+ setup_free(p, p->comment_list);4187+4188 if (p->residue_config) {4189 for (i=0; i < p->residue_count; ++i) {4190 Residue *r = p->residue_config+i;4191 if (r->classdata) {91 unmodified lines4283 d.max_frame_size = f->blocksize_1 >> 1;4284 return d;4285 }4286 4287+stb_vorbis_comment stb_vorbis_get_comment(stb_vorbis *f)4288+{4289+ stb_vorbis_comment d;4290+ d.vendor = f->vendor;4291+ d.comment_list_length = f->comment_list_length;4292+ d.comment_list = f->comment_list;4293+ return d;4294+}4295+4296 int stb_vorbis_get_error(stb_vorbis *f)4297 {4298 int e = f->error;4299 f->error = VORBIS__no_error;1253 unmodified lines