/* Attempts to read an ID3 tag at the current location in stream and * consume it all. Returns -1 if no tag is found. Its up to caller * to recover. */ static int mp3_inputtag(snd_stream_t *stream) { mp3_priv_t *p = (mp3_priv_t *) stream->priv; int rc = -1; size_t remaining; size_t tagsize; /* FIXME: This needs some more work if we are to ever * look at the ID3 frame. This is because the Stream * may not be able to hold the complete ID3 frame. * We should consume the whole frame inside tagtype() * instead of outside of tagframe(). That would support * recovering when Stream contains less then 8-bytes (header) * and also when ID3v2 is bigger then Stream buffer size. * Need to pass in stream so that buffer can be * consumed as well as letting additional data to be * read in. */ remaining = p->Stream.bufend - p->Stream.next_frame; tagsize = mp3_tagsize(p->Stream.this_frame, remaining); if (tagsize != 0) { mad_stream_skip(&p->Stream, tagsize); rc = 0; } /* We know that a valid frame hasn't been found yet * so help libmad out and go back into frame seek mode. * This is true whether an ID3 tag was found or not. */ mad_stream_sync(&p->Stream); return rc; }
// Attempts to read an ID3 tag at the current location in stream and // consume it all. Returns SOX_EOF if no tag is found. Its up to // caller to recover. // Returns true if a tag was found and consumed. // bool MadDecoder::consumeId3Tag() { // FIXME: This needs some more work if we are to ever // look at the ID3 frame. This is because the Stream // may not be able to hold the complete ID3 frame. // We should consume the whole frame inside getId3TagSize() // instead of outside of tagframe(). That would support // recovering when Stream contains less then 8-bytes (header) // and also when ID3v2 is bigger then Stream buffer size. // Need to pass in stream so that buffer can be // consumed as well as letting additional data to be // read in. // bool result = false; size_t leftover = madStream_.bufend - madStream_.next_frame; size_t tagsize = getId3TagSize(madStream_.this_frame, leftover); if (tagsize > 0) { mad_stream_skip(&madStream_, tagsize); result = true; } /* We know that a valid frame hasn't been found yet * so help libmad out and go back into frame seek mode. * This is true whether an ID3 tag was found or not. */ mad_stream_sync(&madStream_); return result; }