Exemple #1
0
static long check_opus_header(DB_FILE *in, ogg_sync_state *oy, const off_t offset, char **vendor)
{
    ogg_stream_state os;
    ogg_page og;
    const int64_t serial = init_read_stream(in, oy, &os, &og, offset, OPUSNAME);
    if (serial <= OGGEDIT_EOF)
        return serial;

    ogg_packet op;
    const long pages = read_packet(in, oy, &os, &og, &op, 1);
    ogg_stream_clear(&os);
    if (pages <= OGGEDIT_EOF)
        return pages;

    if (op.bytes > strlen(TAGMAGIC) && !memcmp(op.packet, TAGMAGIC, strlen(TAGMAGIC)))
        *vendor = parse_vendor(&op, strlen(TAGMAGIC));
    free(op.packet);
    if (!*vendor)
        return OGGEDIT_CANNOT_PARSE_HEADERS;

#ifdef HAVE_OGG_STREAM_FLUSH_FILL
    if (op.bytes < MAXPAYLOAD * (pages-1))
        return 4; // prevent in-place write if the packet is weirdly split into too many pages
#else
    return 4; // not safe to pad without ogg_stream_flush_fill
#endif

    return op.bytes;
}
Exemple #2
0
static ptrdiff_t check_vorbis_headers(DB_FILE *in, ogg_sync_state *oy, const off_t offset, char **vendor, ogg_packet *codebooks)
{
    ogg_stream_state os;
    ogg_page og;
    const int64_t serial = init_read_stream(in, oy, &os, &og, offset, VORBISNAME);
    if (serial <= OGGEDIT_EOF)
        return serial;

    ogg_packet vc;
    int pages = read_packet(in, oy, &os, &og, &vc, 1);
    if (pages > OGGEDIT_EOF)
        pages = read_packet(in, oy, &os, &og, codebooks, pages);
    ogg_stream_clear(&os);
    if (pages <= OGGEDIT_EOF)
        return pages;

    if (vc.bytes > strlen(VCMAGIC) && !memcmp(vc.packet, VCMAGIC, strlen(VCMAGIC)) &&
        codebooks->bytes > strlen(CODEMAGIC) && !memcmp(codebooks->packet, CODEMAGIC, strlen(CODEMAGIC)))
        *vendor = parse_vendor(&vc, strlen(VCMAGIC));
    free(vc.packet);
    if (!*vendor)
        return OGGEDIT_CANNOT_PARSE_HEADERS;

#ifdef HAVE_OGG_STREAM_FLUSH_FILL
    if ((vc.bytes + codebooks->bytes) < MAXPAYLOAD * (pages-1))
        return 4; // prevent in-place write if the packets are split over too many pages
#else
    return 4; // not safe to pad without ogg_stream_flush_fill
#endif

    return vc.bytes;
}
int main()
{
    /*
     * Status of debugging work so far is that everything up to
     * decoding the tree from result is more-or-less working.
     * Possible places of errors:
     *   *) maybe no writes in the compressed file after the tree?
     *   *) maybe no reads from the compressed file after the tree?
     *
     * The best would be to manually search this guy.
     */
    BitStream *reader = init_read_stream("compressed_test.txt");
    BitStream *writer = init_write_stream("re-test.txt");
    huffman_decode_file(reader, writer);
    close_stream(reader);
    close_stream(writer);
}