static public char[] vorbis_comment_query(ref vorbis_comment vc, ref char[] tag, int count) { int i; int found = 0; int taglen = tag.Length + 1; /* +1 for the = we append */ char[] fulltag = new char[taglen + 1]; Array.Copy(tag, 0, fulltag, 0, tag.Length); fulltag[tag.Length] = '='; for (i = 0; i < vc.comments; i++) { if (tagcompare(ref vc.user_comments[i], ref fulltag, taglen) != 0) { if (count == found) { char[] ret = new char[taglen - i]; Array.Copy(vc.user_comments, i, ret, 0, ret.Length); return(ret); } else { found++; } } } return(null); /* didn't find anything */ }
static public void vorbis_comment_add_tag(ref vorbis_comment vc, char[] tag, char[] contents) { char[] comment = new char[tag.Length + contents.Length + 2]; /* +2 for = and \0 */ Array.Copy(tag, 0, comment, 0, tag.Length); comment[tag.Length] = '='; Array.Copy(contents, 0, comment, tag.Length + 1, contents.Length); vorbis_comment_add(ref vc, ref comment); }
public static vorbis_comment ov_comment( IntPtr vf, int link ) { IntPtr result = INTERNAL_ov_comment(vf, link); vorbis_comment comment = (vorbis_comment)Marshal.PtrToStructure( result, typeof(vorbis_comment) ); return(comment); }
static public void vorbis_comment_add(ref vorbis_comment vc, ref char[] comment) { Array.Resize(ref vc.user_comments, vc.comments + 2); Array.Resize(ref vc.comment_lengths, vc.comments + 2); vc.comment_lengths[vc.comments] = comment.Length; vc.user_comments[vc.comments] = new char[vc.comment_lengths[vc.comments] + 1]; Array.Copy(comment, 0, vc.user_comments, vc.comments, comment.Length); vc.comments++; vc.user_comments[vc.comments] = null; }
static public int vorbis_comment_clear(ref vorbis_comment vc) { if (vc == null) { return(1); } vc.user_comments = null; vc.comment_lengths = null; vc.comments = 0; vc.vendor = null; return(0); }
public static vorbis_comment ov_comment( IntPtr vf, int link ) { IntPtr result = INTERNAL_ov_comment(vf, link); if (result == IntPtr.Zero) { throw new InvalidOperationException("Specified bitstream does not exist or the file has been initialized improperly."); } vorbis_comment comment = (vorbis_comment)Marshal.PtrToStructure( result, typeof(vorbis_comment) ); return(comment); }
static public int vorbis_comment_query_count(ref vorbis_comment vc, ref char[] tag) { int i; int count = 0; int taglen = tag.Length + 1; /* +1 for the = we append */ char[] fulltag = new char[taglen + 1]; Array.Copy(tag, 0, fulltag, 0, tag.Length); fulltag[tag.Length] = '='; for (i = 0; i < vc.comments; i++) { if (tagcompare(ref vc.user_comments[i], ref fulltag, taglen) != 0) { count++; } } return(count); }
/* The Vorbis header is in three packets; the initial small packet in the first page that identifies basic parameters, a second packet * with bitstream comments and a third packet that holds the codebook. */ static public int vorbis_synthesis_headerin(ref vorbis_info vi, ref vorbis_comment vc, ref Ogg.ogg_packet op) { Ogg.oggpack_buffer opb = new Ogg.oggpack_buffer(); Ogg.oggpack_readinit(ref opb, op.packet, op.bytes); /* Which of the three types of header is this? */ /* Also verify header-ness, vorbis */ { char[] buffer = new char[6]; int packtype = Ogg.oggpack_read(ref opb, 8); _v_readstring(ref opb, ref buffer, 6); if ( buffer[0] != 'v' || buffer[1] != 'o' || buffer[2] != 'r' || buffer[3] != 'b' || buffer[4] != 'i' || buffer[5] != 's' ) { /* not a vorbis header */ return(OV_ENOTVORBIS); } switch (packtype) { case 0x01: /* least significant *bit* is read first */ { if (op.b_o_s == 0) { /* Not the initial packet */ return(OV_EBADHEADER); } if (vi.rate != 0) { /* previously initialized info header */ return(OV_EBADHEADER); } } return(_vorbis_unpack_info(ref vi, ref opb)); case 0x03: /* least significant *bit* is read first */ { if (vi.rate == 0) { /* um... we didn't get the initial header */ return(OV_EBADHEADER); } } return(_vorbis_unpack_comment(ref vc, ref opb)); case 0x05: /* least significant *bit* is read first */ { if (vi.rate == 0 || vc.vendor == null) { /* um... we didn;t get the initial header or comments yet */ return(OV_EBADHEADER); } } return(_vorbis_unpack_books(ref vi, ref opb)); default: { /* Not a valid vorbis header type */ return(OV_EBADHEADER); } } } }
static public int vorbis_comment_init(ref vorbis_comment vc) { return(vorbis_comment_clear(ref vc)); }
static int _vorbis_unpack_comment(ref vorbis_comment vc, ref Ogg.oggpack_buffer opb) { int i; int vendorlen = Ogg.oggpack_read(ref opb, 32); if (vendorlen < 0) { goto err_out; } if (vendorlen > opb.storage - 8) { goto err_out; } vc.vendor = new char[vendorlen + 1]; _v_readstring(ref opb, ref vc.vendor, vendorlen); i = Ogg.oggpack_read(ref opb, 32); if (i < 0) { goto err_out; } if (i > ((opb.storage - Ogg.oggpack_bytes(ref opb) >> 2))) { goto err_out; } vc.comments = i; vc.user_comments = new char[vc.comments + 1][]; vc.comment_lengths = new int[vc.comments + 1]; for (i = 0; i < vc.comments; i++) { int len = Ogg.oggpack_read(ref opb, 32); if (len < 0) { goto err_out; } if (len > opb.storage - Ogg.oggpack_bytes(ref opb)) { goto err_out; } vc.comment_lengths[i] = len; vc.user_comments[i] = new char[len + 1]; _v_readstring(ref opb, ref vc.user_comments[i], len); } /* EOP check */ if (Ogg.oggpack_read(ref opb, 1) != 1) { goto err_out; } return(0); err_out: vorbis_comment_clear(ref vc); return(OV_EBADHEADER); }