Blame include/oggz/oggz_comments.h

Packit a38265
/*
Packit a38265
   Copyright (C) 2003 Commonwealth Scientific and Industrial Research
Packit a38265
   Organisation (CSIRO) Australia
Packit a38265
Packit a38265
   Redistribution and use in source and binary forms, with or without
Packit a38265
   modification, are permitted provided that the following conditions
Packit a38265
   are met:
Packit a38265
Packit a38265
   - Redistributions of source code must retain the above copyright
Packit a38265
   notice, this list of conditions and the following disclaimer.
Packit a38265
Packit a38265
   - Redistributions in binary form must reproduce the above copyright
Packit a38265
   notice, this list of conditions and the following disclaimer in the
Packit a38265
   documentation and/or other materials provided with the distribution.
Packit a38265
Packit a38265
   - Neither the name of CSIRO Australia nor the names of its
Packit a38265
   contributors may be used to endorse or promote products derived from
Packit a38265
   this software without specific prior written permission.
Packit a38265
Packit a38265
   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit a38265
   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit a38265
   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
Packit a38265
   PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ORGANISATION OR
Packit a38265
   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
Packit a38265
   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
Packit a38265
   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
Packit a38265
   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
Packit a38265
   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
Packit a38265
   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Packit a38265
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit a38265
*/
Packit a38265
Packit a38265
#ifndef __OGGZ_COMMENT_H__
Packit a38265
#define __OGGZ_COMMENT_H__
Packit a38265
Packit a38265
/** \file
Packit a38265
 * Reading of comments.
Packit a38265
 *
Packit a38265
 * Vorbis, Speex and Theora bitstreams
Packit a38265
 * use a comment format called "Vorbiscomment", defined 
Packit a38265
 * here.
Packit a38265
 * Many standard comment names (such as TITLE, COPYRIGHT and GENRE) are
Packit a38265
 * defined in that document.
Packit a38265
 *
Packit a38265
 * The following general features of Vorbiscomment are relevant to this API:
Packit a38265
 * - Each stream has one comment packet, which occurs before any encoded
Packit a38265
 *   audio data in the stream.
Packit a38265
 * - When reading, Oggz will decode the comment block before calling
Packit a38265
 *   the second read() callback for each stream. Hence, retrieving comment
Packit a38265
 *   data is possible once the read() callback has been called a second time.
Packit a38265
 * - When writing, Oggz allows you to set up the comments in memory, and
Packit a38265
 *   provides a single function to generate a corresponding ogg_packet. 
Packit a38265
 *   It is your responsibility to then actually write that packet in sequence.
Packit a38265
 *
Packit a38265
 * Each comment block contains one Vendor string, which can be retrieved
Packit a38265
 * with oggz_comment_get_vendor().
Packit a38265
 *
Packit a38265
 * The rest of a comment block consists of \a name = \a value pairs, with
Packit a38265
 * the following restrictions:
Packit a38265
 * - Both the \a name and \a value must be non-empty
Packit a38265
 * - The \a name is case-insensitive and must consist of ASCII within the
Packit a38265
 *   range 0x20 to 0x7D inclusive, 0x3D ('=') excluded.
Packit a38265
 * - The \a name is not unique; multiple entries may exist with equivalent
Packit a38265
 *   \a name within a Vorbiscomment block.
Packit a38265
 * - The \a value may be any UTF-8 string.
Packit a38265
 *
Packit a38265
 * \section comments_get Reading comments
Packit a38265
 *
Packit a38265
 * Oggz contains API methods to iterate through all comments associated
Packit a38265
 * with the logical bitstreams of an OGGZ* handle (oggz_comment_first() and
Packit a38265
 * oggz_comment_next(), and to iterate through comments matching a
Packit a38265
 * particular name (oggz_comment_first_byname() and
Packit a38265
 * oggz_comment_next_byname()). Given that multiple comments may exist
Packit a38265
 * with the same \a name, you should not use
Packit a38265
 * oggz_comment_first_byname() as a simple "get" function.
Packit a38265
 *
Packit a38265
 * \section comments_set Writing comments
Packit a38265
 * 
Packit a38265
 * For writing, Oggz contains API methods for adding comments
Packit a38265
 * (oggz_comment_add() and oggz_comment_add_byname()),
Packit a38265
 * for removing comments
Packit a38265
 * (oggz_comment_remove() and oggz_comment_remove_byname())
Packit a38265
 * and for setting the vendor string (oggz_comment_set_vendor()).
Packit a38265
 */
Packit a38265
Packit a38265
#include <oggz/oggz.h>
Packit a38265
Packit a38265
/**
Packit a38265
 * A comment.
Packit a38265
 */
Packit a38265
typedef struct {
Packit a38265
  /** The name of the comment, eg. "AUTHOR" */
Packit a38265
  char * name;
Packit a38265
Packit a38265
  /** The value of the comment, as UTF-8 */
Packit a38265
  char * value;
Packit a38265
} OggzComment;
Packit a38265
Packit a38265
#ifdef __cplusplus
Packit a38265
extern "C" {
Packit a38265
#endif
Packit a38265
Packit a38265
/**
Packit a38265
 * Retrieve the vendor string.
Packit a38265
 * \param oggz A OGGZ* handle
Packit a38265
 * \param serialno Identify a logical bitstream within \a oggz
Packit a38265
 * \returns A read-only copy of the vendor string.
Packit a38265
 * \retval NULL No vendor string is associated with \a oggz,
Packit a38265
 *              or \a oggz is NULL, or \a serialno does not identify an
Packit a38265
 *              existing logical bitstream in \a oggz.
Packit a38265
 */
Packit a38265
const char *
Packit a38265
oggz_comment_get_vendor (OGGZ * oggz, long serialno);
Packit a38265
Packit a38265
/**
Packit a38265
 * Set the vendor string
Packit a38265
 * \param oggz A OGGZ* handle
Packit a38265
 * \param serialno Identify a logical bitstream within \a oggz
Packit a38265
 * \param vendor_string The contents of the vendor string to add
Packit a38265
 * \retval 0 Success
Packit a38265
 * \retval OGGZ_ERR_BAD \a oggz is not a valid OGGZ* handle
Packit a38265
 * \retval OGGZ_ERR_INVALID Operation not suitable for this OGGZ
Packit a38265
 * \retval OGGZ_ERR_OUT_OF_MEMORY Out of memory
Packit a38265
 * \note The vendor string should identify the library used to produce
Packit a38265
 * the stream, e.g. libvorbis 1.0 used "Xiph.Org libVorbis I 20020717".
Packit a38265
 * If copying a bitstream it should be the same as the source.
Packit a38265
 */
Packit a38265
int
Packit a38265
oggz_comment_set_vendor (OGGZ * oggz, long serialno,
Packit a38265
			 const char * vendor_string);
Packit a38265
Packit a38265
/**
Packit a38265
 * Retrieve the first comment.
Packit a38265
 * \param oggz A OGGZ* handle
Packit a38265
 * \param serialno Identify a logical bitstream within \a oggz
Packit a38265
 * \returns A read-only copy of the first comment.
Packit a38265
 * \retval NULL No comments exist for this OGGZ* object, or \a serialno
Packit a38265
 *              does not identify an existing logical bitstream in \a oggz.
Packit a38265
 */
Packit a38265
const OggzComment *
Packit a38265
oggz_comment_first (OGGZ * oggz, long serialno);
Packit a38265
Packit a38265
/**
Packit a38265
 * Retrieve the next comment.
Packit a38265
 * \param oggz A OGGZ* handle
Packit a38265
 * \param serialno Identify a logical bitstream within \a oggz
Packit a38265
 * \param comment The previous comment.
Packit a38265
 * \returns A read-only copy of the comment immediately following the given
Packit a38265
 *          comment.
Packit a38265
 * \retval NULL \a serialno does not identify an existing
Packit a38265
 *              logical bitstream in \a oggz.
Packit a38265
 */
Packit a38265
const OggzComment *
Packit a38265
oggz_comment_next (OGGZ * oggz, long serialno, const OggzComment * comment);
Packit a38265
Packit a38265
/**
Packit a38265
 * Retrieve the first comment with a given name.
Packit a38265
 * \param oggz A OGGZ* handle
Packit a38265
 * \param serialno Identify a logical bitstream within \a oggz
Packit a38265
 * \param name the name of the comment to retrieve.
Packit a38265
 * \returns A read-only copy of the first comment matching the given \a name.
Packit a38265
 * \retval NULL No match was found, or \a serialno does not identify an
Packit a38265
 *              existing logical bitstream in \a oggz.
Packit a38265
 * \note If \a name is NULL, the behaviour is the same as for
Packit a38265
 *       oggz_comment_first()
Packit a38265
 */
Packit a38265
const OggzComment *
Packit a38265
oggz_comment_first_byname (OGGZ * oggz, long serialno, char * name);
Packit a38265
Packit a38265
/**
Packit a38265
 * Retrieve the next comment following and with the same name as a given
Packit a38265
 * comment.
Packit a38265
 * \param oggz A OGGZ* handle
Packit a38265
 * \param serialno Identify a logical bitstream within \a oggz
Packit a38265
 * \param comment A comment
Packit a38265
 * \returns A read-only copy of the next comment with the same name as
Packit a38265
 *          \a comment.
Packit a38265
 * \retval NULL No further comments with the same name exist for this
Packit a38265
 *              OGGZ* object, or \a serialno does not identify an existing
Packit a38265
 *              logical bitstream in \a oggz.
Packit a38265
 */
Packit a38265
const OggzComment *
Packit a38265
oggz_comment_next_byname (OGGZ * oggz, long serialno,
Packit a38265
                          const OggzComment * comment);
Packit a38265
Packit a38265
/**
Packit a38265
 * Add a comment
Packit a38265
 * \param oggz A OGGZ* handle (created with mode OGGZ_WRITE)
Packit a38265
 * \param serialno Identify a logical bitstream within \a oggz
Packit a38265
 * \param comment The comment to add
Packit a38265
 * \retval 0 Success
Packit a38265
 * \retval OGGZ_ERR_BAD \a oggz is not a valid OGGZ* handle
Packit a38265
 * \retval OGGZ_ERR_INVALID Operation not suitable for this OGGZ
Packit a38265
 * \retval OGGZ_ERR_OUT_OF_MEMORY Out of memory
Packit a38265
 */
Packit a38265
int
Packit a38265
oggz_comment_add (OGGZ * oggz, long serialno, OggzComment * comment);
Packit a38265
Packit a38265
/**
Packit a38265
 * Add a comment by name and value.
Packit a38265
 * \param oggz A OGGZ* handle (created with mode OGGZ_WRITE)
Packit a38265
 * \param serialno Identify a logical bitstream within \a oggz
Packit a38265
 * \param name The name of the comment to add
Packit a38265
 * \param value The contents of the comment to add
Packit a38265
 * \retval 0 Success
Packit a38265
 * \retval OGGZ_ERR_BAD \a oggz is not a valid OGGZ* handle
Packit a38265
 * \retval OGGZ_ERR_INVALID Operation not suitable for this OGGZ
Packit a38265
 * \retval OGGZ_ERR_OUT_OF_MEMORY Out of memory
Packit a38265
 */
Packit a38265
int
Packit a38265
oggz_comment_add_byname (OGGZ * oggz, long serialno,
Packit a38265
                         const char * name, const char * value);
Packit a38265
Packit a38265
/**
Packit a38265
 * Remove a comment
Packit a38265
 * \param oggz A OGGZ* handle (created with OGGZ_WRITE)
Packit a38265
 * \param serialno Identify a logical bitstream within \a oggz
Packit a38265
 * \param comment The comment to remove.
Packit a38265
 * \retval 1 Success: comment removed
Packit a38265
 * \retval 0 No-op: comment not found, nothing to remove
Packit a38265
 * \retval OGGZ_ERR_BAD \a oggz is not a valid OGGZ* handle
Packit a38265
 * \retval OGGZ_ERR_INVALID Operation not suitable for this OGGZ
Packit a38265
 * \retval OGGZ_ERR_BAD_SERIALNO \a serialno does not identify an existing
Packit a38265
 * logical bitstream in \a oggz.
Packit a38265
 */
Packit a38265
int
Packit a38265
oggz_comment_remove (OGGZ * oggz, long serialno, OggzComment * comment);
Packit a38265
Packit a38265
/**
Packit a38265
 * Remove all comments with a given name.
Packit a38265
 * \param oggz A OGGZ* handle (created with OGGZ_WRITE)
Packit a38265
 * \param serialno Identify a logical bitstream within \a oggz
Packit a38265
 * \param name The name of the comments to remove
Packit a38265
 * \retval ">= 0" The number of comments removed
Packit a38265
 * \retval OGGZ_ERR_BAD \a oggz is not a valid OGGZ* handle
Packit a38265
 * \retval OGGZ_ERR_INVALID Operation not suitable for this OGGZ
Packit a38265
 * \retval OGGZ_ERR_BAD_SERIALNO \a serialno does not identify an existing
Packit a38265
 * logical bitstream in \a oggz.
Packit a38265
 */
Packit a38265
int
Packit a38265
oggz_comment_remove_byname (OGGZ * oggz, long serialno, char * name);
Packit a38265
Packit a38265
/**
Packit a38265
 * Output a comment packet for the specified stream
Packit a38265
 * \param oggz A OGGZ* handle (created with OGGZ_WRITE)
Packit a38265
 * \param serialno Identify a logical bitstream within \a oggz
Packit a38265
 * \param FLAC_final_metadata_block Set this to zero unless the packet_type is
Packit a38265
 * FLAC, and there are no further metadata blocks to follow. See note below
Packit a38265
 * for details.
Packit a38265
 * \returns A comment packet for the stream. When no longer needed it
Packit a38265
 * should be freed with oggz_packet_destroy().
Packit a38265
 * \retval NULL content type does not support comments, not enough memory
Packit a38265
 * or comment was too long for FLAC
Packit a38265
 * \note FLAC streams may contain multiple metadata blocks of different types.
Packit a38265
 * When encapsulated in Ogg the first of these must be a Vorbis comment packet
Packit a38265
 * but PADDING, APPLICATION, SEEKTABLE, CUESHEET and PICTURE may follow.
Packit a38265
 * The last metadata block must have its first bit set to 1. Since liboggz does
Packit a38265
 * not know whether you will supply more metadata blocks you must tell it if
Packit a38265
 * this is the last (or only) metadata block by setting
Packit a38265
 * FLAC_final_metadata_block to 1.
Packit a38265
 * \n As FLAC metadata blocks are limited in size to 16MB minus 1 byte, this
Packit a38265
 * function will refuse to produce longer comment packets for FLAC.
Packit a38265
 * \n See http://flac.sourceforge.net/format.html for more details.
Packit a38265
 */
Packit a38265
ogg_packet *
Packit a38265
oggz_comments_generate(OGGZ * oggz, long serialno,
Packit a38265
                       int FLAC_final_metadata_block);
Packit a38265
  
Packit a38265
/*
Packit a38265
 * Copy comments between two streams.
Packit a38265
 * \param src A OGGZ* handle
Packit a38265
 * \param src_serialno Identify a logical bitstream within \a src
Packit a38265
 * \param dest A OGGZ* handle (created with OGGZ_WRITE)
Packit a38265
 * \param dest_serialno Identify a logical bitstream within \a dest
Packit a38265
 * \retval OGGZ_ERR_BAD \a oggz is not a valid OGGZ* handle
Packit a38265
 * \retval OGGZ_ERR_INVALID Operation not suitable for \a dest
Packit a38265
 */
Packit a38265
int
Packit a38265
oggz_comments_copy (OGGZ * src, long src_serialno,
Packit a38265
                    OGGZ * dest, long dest_serialno);
Packit a38265
Packit a38265
/**
Packit a38265
 * Free a packet and its payload.
Packit a38265
 * \param packet A packet previously returned from a function such
Packit a38265
 * as oggz_comment_generate(). User generated packets should not be passed.
Packit a38265
 */
Packit a38265
void oggz_packet_destroy (ogg_packet *packet);
Packit a38265
Packit a38265
#ifdef __cplusplus
Packit a38265
}
Packit a38265
#endif
Packit a38265
Packit a38265
#endif /* __OGGZ_COMMENTS_H__ */