Add comment support to stb_vorbis
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Audino · committed by Audino · parent 052dce1 · 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
2a0cff1- Tree
332ccce- Author
Audino <Audino>- Committer
Audino <Audino>- Parent
052dce1
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;772 unmodified lines1553 f->valid_bits = 0;1554 return x;1555 }1556 1557+static int get32_packet(vorb *f)1558+{1559+ uint32 x;1560+ x = get8_packet(f);1561+ x += get8_packet(f) << 8;1562+ x += get8_packet(f) << 16;1563+ x += (uint32) get8_packet(f) << 24;1564+ return x;1565+}1566+1567 static void flush_packet(vorb *f)1568 {1569 while (get8_packet_raw(f) != EOP);1570 }2084 unmodified lines3655 if (!(x & 1)) return error(f, VORBIS_invalid_first_page);3656 3657 // second packet!3658 if (!start_page(f)) return FALSE;3634-3659+ 3660 if (!start_packet(f)) return FALSE;3661+3662+ if (!next_segment(f)) return FALSE;3663+3664+ if (get8_packet(f) != VORBIS_packet_comment) return error(f, VORBIS_invalid_setup);3665+ for (i=0; i < 6; ++i) header[i] = get8_packet(f);3666+ if (!vorbis_validate(header)) return error(f, VORBIS_invalid_setup);3667+ //file vendor3668+ len = get32_packet(f);3669+ f->vendor = (char*)setup_malloc(f, sizeof(char) * (len+1));3670+ for(i=0; i < len; ++i) {3671+ f->vendor[i] = get8_packet(f);3672+ }3673+ f->vendor[len] = (char)NULL;3674+ //user comments3675+ f->comment_list_length = get32_packet(f);3676+ f->comment_list = (char**)setup_malloc(f, sizeof(char*) * (f->comment_list_length));3677+ 3678+ for(i=0; i < f->comment_list_length; ++i) {3679+ len = get32_packet(f);3680+ f->comment_list[i] = (char*)setup_malloc(f, sizeof(char) * (len+1));3681+3682+ for(j=0; j < len; ++j) {3683+ f->comment_list[i][j] = get8_packet(f);3684+ }3685+ f->comment_list[i][len] = (char)NULL;3686+ }3687+3688+ // framing_flag3689+ x = get8_packet(f);3690+ if (!(x & 1)) return error(f, VORBIS_invalid_setup);3691+3692+ 3693+ skip(f, f->bytes_in_seg);3694+ f->bytes_in_seg = 0;3695+3696 do {3697 len = next_segment(f);3698 skip(f, len);3699 f->bytes_in_seg = 0;508 unmodified lines4208 4209 static void vorbis_deinit(stb_vorbis *p)4210 {4211 int i,j;4212+4213+ setup_free(p, p->vendor);4214+ for (i=0; i < p->comment_list_length; ++i) {4215+ setup_free(p, p->comment_list[i]);4216+ }4217+ setup_free(p, p->comment_list);4218+4219 if (p->residue_config) {4220 for (i=0; i < p->residue_count; ++i) {4221 Residue *r = p->residue_config+i;4222 if (r->classdata) {91 unmodified lines4314 d.max_frame_size = f->blocksize_1 >> 1;4315 return d;4316 }4317 4318+stb_vorbis_comment stb_vorbis_get_comment(stb_vorbis *f)4319+{4320+ stb_vorbis_comment d;4321+ d.vendor = f->vendor;4322+ d.comment_list_length = f->comment_list_length;4323+ d.comment_list = f->comment_list;4324+ return d;4325+}4326+4327 int stb_vorbis_get_error(stb_vorbis *f)4328 {4329 int e = f->error;4330 f->error = VORBIS__no_error;1248 unmodified lines