summaryrefslogtreecommitdiff
path: root/recordmydesktop/src
diff options
context:
space:
mode:
authoriovar <iovar@f606c939-3180-4ac9-a4b8-4b8779d57d0a>2008-08-31 11:11:21 +0000
committeriovar <iovar@f606c939-3180-4ac9-a4b8-4b8779d57d0a>2008-08-31 11:11:21 +0000
commitd83ac148bae39cbab91d1489cd043dec75402c80 (patch)
tree25ad92fa416921324867ad814db07e79659fbe23 /recordmydesktop/src
parentd7b54c9b79ac2753c104e940fb40344e688f01ab (diff)
updated skeleton.[h/c] from liboggz trunk, added AM_PROG_CC_C_O to configure.ac
git-svn-id: https://recordmydesktop.svn.sourceforge.net/svnroot/recordmydesktop/trunk@500 f606c939-3180-4ac9-a4b8-4b8779d57d0a
Diffstat (limited to 'recordmydesktop/src')
-rw-r--r--recordmydesktop/src/skeleton.c236
1 files changed, 122 insertions, 114 deletions
diff --git a/recordmydesktop/src/skeleton.c b/recordmydesktop/src/skeleton.c
index 078d092..77567db 100644
--- a/recordmydesktop/src/skeleton.c
+++ b/recordmydesktop/src/skeleton.c
@@ -1,35 +1,7 @@
-/******************************************************************************
-* skeleton.c *
-* author: Tahseen Mohammad *
-*******************************************************************************
-* Redistribution and use in source and binary forms, with or without *
-* modification, are permitted provided that the following conditions *
-* are met: *
-* *
-* - Redistributions of source code must retain the above copyright *
-* notice, this list of conditions and the following disclaimer. *
-* *
-* - Redistributions in binary form must reproduce the above copyright *
-* notice, this list of conditions and the following disclaimer in the *
-* documentation and/or other materials provided with the distribution. *
-* *
-* - Neither the name of the Xiph.org Foundation nor the names of its *
-* contributors may be used to endorse or promote products derived from *
-* this software without specific prior written permission. *
-* *
-* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
-* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
-* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
-* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR *
-* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
-* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
-* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
-* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
-* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
-* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
-******************************************************************************/
-
+/*
+ * skeleton.c
+ * author: Tahseen Mohammad
+ */
/* This file depends on WORDS_BIGENDIAN being defined to 1 if the host
* processor stores words with the most significant byte first (like Motorola
@@ -123,9 +95,9 @@ int add_message_header_field(fisbone_packet *fp,
/* size of both key and value + ': ' + CRLF */
int this_message_size = strlen(header_key) + strlen(header_value) + 4;
if (fp->message_header_fields == NULL) {
- fp->message_header_fields = _ogg_calloc(this_message_size, sizeof(char));
+ fp->message_header_fields = _ogg_calloc(this_message_size+1, sizeof(char));
} else {
- int new_size = (fp->current_header_size + this_message_size) * sizeof(char);
+ int new_size = (fp->current_header_size + this_message_size+1) * sizeof(char);
fp->message_header_fields = _ogg_realloc(fp->message_header_fields, new_size);
}
snprintf(fp->message_header_fields + fp->current_header_size,
@@ -139,109 +111,144 @@ int add_message_header_field(fisbone_packet *fp,
}
/* create a ogg_packet from a fishead_packet structure */
-ogg_packet ogg_from_fishead(fishead_packet *fp) {
+int ogg_from_fishead(fishead_packet *fp,ogg_packet *op) {
- ogg_packet op;
+ if (!fp || !op) return -1;
+
+ memset(op, 0, sizeof(*op));
+ op->packet = _ogg_calloc(FISHEAD_SIZE, sizeof(unsigned char));
+ if (!op->packet) return -1;
+
+ memset(op->packet, 0, FISHEAD_SIZE);
- memset(&op, 0, sizeof(op));
- op.packet = _ogg_calloc(FISHEAD_SIZE, sizeof(unsigned char));
- memset(op.packet, 0, FISHEAD_SIZE);
-
- memcpy (op.packet, FISHEAD_IDENTIFIER, 8); /* identifier */
- *((ogg_uint16_t*)(op.packet+8)) = _le_16 (SKELETON_VERSION_MAJOR); /* version major */
- *((ogg_uint16_t*)(op.packet+10)) = _le_16 (SKELETON_VERSION_MINOR); /* version minor */
- *((ogg_int64_t*)(op.packet+12)) = _le_64 (fp->ptime_n); /* presentationtime numerator */
- *((ogg_int64_t*)(op.packet+20)) = _le_64 (fp->ptime_d); /* presentationtime denominator */
- *((ogg_int64_t*)(op.packet+28)) = _le_64 (fp->btime_n); /* basetime numerator */
- *((ogg_int64_t*)(op.packet+36)) = _le_64 (fp->btime_d); /* basetime denominator */
+ memcpy (op->packet, FISHEAD_IDENTIFIER, 8); /* identifier */
+ *((ogg_uint16_t*)(op->packet+8)) = _le_16 (SKELETON_VERSION_MAJOR); /* version major */
+ *((ogg_uint16_t*)(op->packet+10)) = _le_16 (SKELETON_VERSION_MINOR); /* version minor */
+ *((ogg_int64_t*)(op->packet+12)) = _le_64 (fp->ptime_n); /* presentationtime numerator */
+ *((ogg_int64_t*)(op->packet+20)) = _le_64 (fp->ptime_d); /* presentationtime denominator */
+ *((ogg_int64_t*)(op->packet+28)) = _le_64 (fp->btime_n); /* basetime numerator */
+ *((ogg_int64_t*)(op->packet+36)) = _le_64 (fp->btime_d); /* basetime denominator */
/* TODO: UTC time, set to zero for now */
- op.b_o_s = 1; /* its the first packet of the stream */
- op.e_o_s = 0; /* its not the last packet of the stream */
- op.bytes = FISHEAD_SIZE; /* length of the packet in bytes */
+ op->b_o_s = 1; /* its the first packet of the stream */
+ op->e_o_s = 0; /* its not the last packet of the stream */
+ op->bytes = FISHEAD_SIZE; /* length of the packet in bytes */
- return op;
+ return 0;
}
/* create a ogg_packet from a fisbone_packet structure.
* call this method after the fisbone_packet is filled and all message header fields are added
* by calling add_message_header_field method.
*/
-ogg_packet ogg_from_fisbone(fisbone_packet *fp) {
+int ogg_from_fisbone(fisbone_packet *fp,ogg_packet *op) {
- ogg_packet op;
- int packet_size = FISBONE_SIZE + fp->current_header_size;
-
- memset (&op, 0, sizeof (op));
- op.packet = _ogg_calloc (packet_size, sizeof(unsigned char));
- memset (op.packet, 0, packet_size);
- memcpy (op.packet, FISBONE_IDENTIFIER, 8); /* identifier */
- *((ogg_uint32_t*)(op.packet+8)) = _le_32 (FISBONE_MESSAGE_HEADER_OFFSET); /* offset of the message header fields */
- *((ogg_uint32_t*)(op.packet+12)) = _le_32 (fp->serial_no); /* serialno of the respective stream */
- *((ogg_uint32_t*)(op.packet+16)) = _le_32 (fp->nr_header_packet); /* number of header packets */
- *((ogg_int64_t*)(op.packet+20)) = _le_64 (fp->granule_rate_n); /* granulrate numerator */
- *((ogg_int64_t*)(op.packet+28)) = _le_64 (fp->granule_rate_d); /* granulrate denominator */
- *((ogg_int64_t*)(op.packet+36)) = _le_64 (fp->start_granule); /* start granule */
- *((ogg_uint32_t*)(op.packet+44)) = _le_32 (fp->preroll); /* preroll, for theora its 0 */
- *(op.packet+48) = fp->granule_shift; /* granule shift */
- memcpy((op.packet+FISBONE_SIZE), fp->message_header_fields, fp->current_header_size);
-
- op.b_o_s = 0;
- op.e_o_s = 0;
- op.bytes = packet_size; /* size of the packet in bytes */
-
- return op;
+ int packet_size;
+
+ if (!fp || !op) return -1;
+
+ packet_size = FISBONE_SIZE + fp->current_header_size;
+
+ memset (op, 0, sizeof (*op));
+ op->packet = _ogg_calloc (packet_size, sizeof(unsigned char));
+ if (!op->packet) return -1;
+
+ memset (op->packet, 0, packet_size);
+ memcpy (op->packet, FISBONE_IDENTIFIER, 8); /* identifier */
+ *((ogg_uint32_t*)(op->packet+8)) = _le_32 (FISBONE_MESSAGE_HEADER_OFFSET); /* offset of the message header fields */
+ *((ogg_uint32_t*)(op->packet+12)) = _le_32 (fp->serial_no); /* serialno of the respective stream */
+ *((ogg_uint32_t*)(op->packet+16)) = _le_32 (fp->nr_header_packet); /* number of header packets */
+ *((ogg_int64_t*)(op->packet+20)) = _le_64 (fp->granule_rate_n); /* granulrate numerator */
+ *((ogg_int64_t*)(op->packet+28)) = _le_64 (fp->granule_rate_d); /* granulrate denominator */
+ *((ogg_int64_t*)(op->packet+36)) = _le_64 (fp->start_granule); /* start granule */
+ *((ogg_uint32_t*)(op->packet+44)) = _le_32 (fp->preroll); /* preroll, for theora its 0 */
+ *(op->packet+48) = fp->granule_shift; /* granule shift */
+ if (fp->message_header_fields)
+ memcpy((op->packet+FISBONE_SIZE), fp->message_header_fields, fp->current_header_size);
+
+
+ op->b_o_s = 0;
+ op->e_o_s = 0;
+ op->bytes = packet_size; /* size of the packet in bytes */
+
+ return 0;
+}
+
+/* fills up a fishead_packet from memory */
+static int fishead_from_data (const unsigned char * data, int len, fishead_packet *fp) {
+ if (!data) return -1;
+
+ if (memcmp(data, FISHEAD_IDENTIFIER, 8))
+ return -1;
+
+ fp->version_major = _le_16 (*((ogg_uint16_t*)(data+8))); /* version major */
+ fp->version_minor = _le_16 (*((ogg_uint16_t*)(data+10))); /* version minor */
+ fp->ptime_n = _le_64 (*((ogg_int64_t*)(data+12))); /* presentationtime numerator */
+ fp->ptime_d = _le_64 (*((ogg_int64_t*)(data+20))); /* presentationtime denominator */
+ fp->btime_n = _le_64 (*((ogg_int64_t*)(data+28))); /* basetime numerator */
+ fp->btime_d = _le_64 (*((ogg_int64_t*)(data+36))); /* basetime denominator */
+ memcpy(fp->UTC, data+44, 20);
+
+ return 0;
}
/* fills up a fishead_packet from a fishead ogg_packet of a skeleton bistream */
-fishead_packet fishead_from_ogg(ogg_packet *op) {
-
- fishead_packet fp;
-
- /*
- if (memcmp(op->packet, FISHEAD_IDENTIFIER, 8))
- ; invalid packet what do we do?
- */
-
- fp.version_major = _le_16 (*((ogg_uint16_t*)(op->packet+8))); /* version major */
- fp.version_minor = _le_16 (*((ogg_uint16_t*)(op->packet+10))); /* version minor */
- fp.ptime_n = _le_64 (*((ogg_int64_t*)(op->packet+12))); /* presentationtime numerator */
- fp.ptime_d = _le_64 (*((ogg_int64_t*)(op->packet+20))); /* presentationtime denominator */
- fp.btime_n = _le_64 (*((ogg_int64_t*)(op->packet+28))); /* basetime numerator */
- fp.btime_d = _le_64 (*((ogg_int64_t*)(op->packet+36))); /* basetime denominator */
- memcpy(fp.UTC, op->packet+44, 20);
-
- return fp;
+int fishead_from_ogg (ogg_packet *op, fishead_packet *fp) {
+ return fishead_from_data (op->packet, op->bytes, fp);
+}
+
+/* fills up a fishead_packet from a fishead ogg_page of a skeleton bistream */
+int fishead_from_ogg_page (const ogg_page *og, fishead_packet *fp) {
+ return fishead_from_data (og->body, og->body_len, fp);
+}
+
+/* fills up a fisbone_packet from memory */
+static int fisbone_from_data (const unsigned char * data, int len, fisbone_packet *fp) {
+
+ if (!fp) return -1;
+
+ if (memcmp(data, FISBONE_IDENTIFIER, 8))
+ return -1;
+
+ fp->serial_no = _le_32 (*((ogg_uint32_t*)(data+12))); /* serialno of the stream represented by this fisbone packet */
+ fp->nr_header_packet = _le_32 (*((ogg_uint32_t*)(data+16))); /* number of header packets */
+ fp->granule_rate_n = _le_64 (*((ogg_int64_t*)(data+20))); /* granulrate numerator */
+ fp->granule_rate_d = _le_64 (*((ogg_int64_t*)(data+28))); /* granulrate denominator */
+ fp->start_granule = _le_64 (*((ogg_int64_t*)(data+36))); /* start granule */
+ fp->preroll = _le_32 (*((ogg_uint32_t*)(data+44))); /* preroll, for theora its 0 */
+ fp->granule_shift = *(data+48); /* granule shift */
+ fp->current_header_size = len - FISBONE_SIZE;
+ fp->message_header_fields = _ogg_calloc(fp->current_header_size+1, sizeof(char));
+ if (!fp->message_header_fields) return -1;
+ memcpy(fp->message_header_fields, data+FISBONE_SIZE, fp->current_header_size);
+
+ return 0;
}
/* fills up a fisbone_packet from a fisbone ogg_packet of a skeleton bitstream */
-fisbone_packet fisbone_from_ogg(ogg_packet *op) {
+int fisbone_from_ogg (ogg_packet *op, fisbone_packet *fp) {
+ return fisbone_from_data (op->packet, op->bytes, fp);
+}
- fisbone_packet fp;
-
- /*
- if (memcmp(op->packet, FISBONE_IDENTIFIER, 8))
- ; invalid value, what do we do?
- */
- fp.serial_no = _le_32 (*((ogg_uint32_t*)(op->packet+12))); /* serialno of the stream represented by this fisbone packet */
- fp.nr_header_packet = _le_32 (*((ogg_uint32_t*)(op->packet+16))); /* number of header packets */
- fp.granule_rate_n = _le_64 (*((ogg_int64_t*)(op->packet+20))); /* granulrate numerator */
- fp.granule_rate_d = _le_64 (*((ogg_int64_t*)(op->packet+28))); /* granulrate denominator */
- fp.start_granule = _le_64 (*((ogg_int64_t*)(op->packet+36))); /* start granule */
- fp.preroll = _le_32 (*((ogg_uint32_t*)(op->packet+44))); /* preroll, for theora its 0 */
- fp.granule_shift = *(op->packet+48); /* granule shift */
- fp.current_header_size = op->bytes - FISBONE_SIZE;
- fp.message_header_fields = _ogg_calloc(fp.current_header_size+1, sizeof(char));
- memcpy(fp.message_header_fields, op->packet+FISBONE_SIZE, fp.current_header_size);
-
- return fp;
+/* fills up a fisbone_packet from a fisbone ogg_page of a skeleton bistream */
+int fisbone_from_ogg_page (const ogg_page *og, fisbone_packet *fp) {
+ return fisbone_from_data (og->body, og->body_len, fp);
+}
+
+int fisbone_clear(fisbone_packet *fp)
+{
+ if (!fp) return -1;
+ _ogg_free(fp->message_header_fields);
+ return 0;
}
int add_fishead_to_stream(ogg_stream_state *os, fishead_packet *fp) {
ogg_packet op;
+ int ret;
- op = ogg_from_fishead(fp);
+ ret = ogg_from_fishead(fp, &op);
+ if (ret<0) return ret;
ogg_stream_packetin(os, &op);
_ogg_free(op.packet);
@@ -251,8 +258,10 @@ int add_fishead_to_stream(ogg_stream_state *os, fishead_packet *fp) {
int add_fisbone_to_stream(ogg_stream_state *os, fisbone_packet *fp) {
ogg_packet op;
+ int ret;
- op = ogg_from_fisbone(fp);
+ ret = ogg_from_fisbone(fp, &op);
+ if (ret<0) return ret;
ogg_stream_packetin(os, &op);
_ogg_free(op.packet);
@@ -285,4 +294,3 @@ int flush_ogg_stream_to_file(ogg_stream_state *os, FILE *out) {
return 0;
}
-
© All Rights Reserved