Commit cc8b9eee authored by conrad's avatar conrad
Browse files

add oggz_comments_copy() API function, and use it in modify-headers example

to produce a new set of comments, and add a comment


git-svn-id: http://svn.annodex.net/liboggz/trunk@3363 8158c8cd-e7e1-0310-9fa4-c5954c97daef
parent c39f6928
......@@ -266,6 +266,19 @@ oggz_comment_generate(OGGZ * oggz, long serialno,
OggzStreamContent packet_type,
int FLAC_final_metadata_block);
/*
* Copy comments between two streams.
* \param src A OGGZ* handle
* \param src_serialno Identify a logical bitstream within \a src
* \param dest A OGGZ* handle (created with OGGZ_WRITE)
* \param dest_serialno Identify a logical bitstream within \a dest
* \retval OGGZ_ERR_BAD \a oggz is not a valid OGGZ* handle
* \retval OGGZ_ERR_INVALID Operation not suitable for \a dest
*/
int
oggz_comments_copy (OGGZ * src, long src_serialno,
OGGZ * dest, long dest_serialno);
/**
* Free a packet and its payload.
* \param packet A packet previously returned from a function such
......
......@@ -62,7 +62,6 @@ static int
read_packet (OGGZ * oggz, ogg_packet * op, long serialno, void * user_data)
{
MHData * mhdata = (MHData *)user_data;
ogg_packet * new_op = op;
int flush;
int ret;
......@@ -90,9 +89,17 @@ read_packet (OGGZ * oggz, ogg_packet * op, long serialno, void * user_data)
#endif
/* Do something with the packet data */
if (op->packetno == 1) {
oggz_comments_copy (mhdata->reader, serialno, mhdata->writer, serialno);
oggz_comment_add_byname (mhdata->writer, serialno,
"EDITOR", "modify-headers");
op = oggz_comment_generate (mhdata->writer, serialno,
oggz_stream_get_content (mhdata->reader, serialno),
0);
}
/* Feed the packet into the writer */
if ((ret = oggz_write_feed (mhdata->writer, new_op, serialno, flush, NULL)) != 0) {
if ((ret = oggz_write_feed (mhdata->writer, op, serialno, flush, NULL)) != 0) {
printf ("oggz_write_feed: %d\n", ret);
}
......
......@@ -79,7 +79,10 @@
oggz_comment_add_byname;
oggz_comment_remove;
oggz_comment_remove_byname;
oggz_comment_generate;
oggz_comments_copy;
oggz_packet_destroy;
local:
......
......@@ -484,6 +484,33 @@ oggz_comment_remove_byname (OGGZ * oggz, long serialno, char * name)
}
}
int
oggz_comments_copy (OGGZ * src, long src_serialno,
OGGZ * dest, long dest_serialno)
{
const OggzComment * comment;
if (src == NULL || dest == NULL) return OGGZ_ERR_BAD_OGGZ;
if (dest->flags & OGGZ_WRITE) {
if (OGGZ_CONFIG_WRITE) {
oggz_comment_set_vendor (dest, dest_serialno,
oggz_comment_get_vendor (src, src_serialno));
for (comment = oggz_comment_first (src, src_serialno); comment;
comment = oggz_comment_next (src, src_serialno, comment)) {
oggz_comment_add (dest, dest_serialno, comment);
}
} else {
return OGGZ_ERR_DISABLED;
}
} else {
return OGGZ_ERR_INVALID;
}
return 0;
}
/* Internal API */
int
oggz_comments_init (oggz_stream_t * stream)
......@@ -601,6 +628,9 @@ oggz_comments_encode (OGGZ * oggz, long serialno,
/* Vendor string */
vendor_length = strlen (stream->vendor);
actual_length = 4 + vendor_length;
#ifdef DEBUG
printf ("oggz_comments_encode: vendor = %s\n", stream->vendor);
#endif
/* user comment list length */
actual_length += 4;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment