From 08f54a0d44f336abf448480b29b2b62fe2d34e55 Mon Sep 17 00:00:00 2001 From: iovar Date: Sat, 2 Feb 2008 06:03:31 +0000 Subject: updates to skeleton.c for bigendian architectures git-svn-id: https://recordmydesktop.svn.sourceforge.net/svnroot/recordmydesktop/trunk@485 f606c939-3180-4ac9-a4b8-4b8779d57d0a --- recordmydesktop/configure.ac | 4 +- recordmydesktop/src/skeleton.c | 132 +++++++++++++++++++++++++++++++---------- 2 files changed, 104 insertions(+), 32 deletions(-) diff --git a/recordmydesktop/configure.ac b/recordmydesktop/configure.ac index caf8b3e..3dba415 100644 --- a/recordmydesktop/configure.ac +++ b/recordmydesktop/configure.ac @@ -3,7 +3,7 @@ AC_PREREQ(2.59) AC_INIT(src/recordmydesktop.c) -AM_INIT_AUTOMAKE(recordmydesktop,0.3.7.1,) +AM_INIT_AUTOMAKE(recordmydesktop,0.3.7.2,) AC_CONFIG_SRCDIR([src/recordmydesktop.c]) AM_CONFIG_HEADER(config.h) @@ -15,7 +15,7 @@ AM_CONFIG_HEADER(config.h) AC_PROG_CC AC_CANONICAL_HOST - +AC_C_BIGENDIAN # Checks for header files. AC_HEADER_DIRENT diff --git a/recordmydesktop/src/skeleton.c b/recordmydesktop/src/skeleton.c index 02dd6bd..078d092 100644 --- a/recordmydesktop/src/skeleton.c +++ b/recordmydesktop/src/skeleton.c @@ -31,20 +31,87 @@ ******************************************************************************/ +/* This file depends on WORDS_BIGENDIAN being defined to 1 if the host + * processor stores words with the most significant byte first (like Motorola + * and SPARC, unlike Intel and VAX). + * On little endian systems, WORDS_BIGENDIAN should be undefined. + * + * When using GNU Autotools, the correct value will be written into config.h + * if the autoconf macro AC_C_BIGENDIAN is called in configure.ac. + */ +#include "config.h" + #include #include #include #include -#include +#include "skeleton.h" + +#ifdef WIN32 +#define snprintf _snprintf +#endif + +static unsigned short +_le_16 (unsigned short s) +{ + unsigned short ret=s; +#ifdef WORDS_BIGENDIAN + ret = (s>>8) & 0x00ffU; + ret += (s<<8) & 0xff00U; +#endif + return ret; +} + +static ogg_uint32_t +_le_32 (ogg_uint32_t i) +{ + ogg_uint32_t ret=i; +#ifdef WORDS_BIGENDIAN + ret = (i>>24); + ret += (i>>8) & 0x0000ff00; + ret += (i<<8) & 0x00ff0000; + ret += (i<<24); +#endif + return ret; +} + +static ogg_int64_t +_le_64 (ogg_int64_t l) +{ + ogg_int64_t ret=l; + unsigned char *ucptr = (unsigned char *)&ret; +#ifdef WORDS_BIGENDIAN + unsigned char temp; + + temp = ucptr [0] ; + ucptr [0] = ucptr [7] ; + ucptr [7] = temp ; + + temp = ucptr [1] ; + ucptr [1] = ucptr [6] ; + ucptr [6] = temp ; + + temp = ucptr [2] ; + ucptr [2] = ucptr [5] ; + ucptr [5] = temp ; + + temp = ucptr [3] ; + ucptr [3] = ucptr [4] ; + ucptr [4] = temp ; + +#endif + return (*(ogg_int64_t *)ucptr); +} /* write an ogg_page to a file pointer */ int write_ogg_page_to_file(ogg_page *og, FILE *out) { int written; written = fwrite(og->header,1, og->header_len, out); - written += fwrite(og->body,1, og->body_len, out); + if (written > 0) + written += fwrite(og->body,1, og->body_len, out); return written; } @@ -81,12 +148,12 @@ ogg_packet ogg_from_fishead(fishead_packet *fp) { memset(op.packet, 0, FISHEAD_SIZE); memcpy (op.packet, FISHEAD_IDENTIFIER, 8); /* identifier */ - *((ogg_uint16_t*)(op.packet+8)) = SKELETON_VERSION_MAJOR; /* version major */ - *((ogg_uint16_t*)(op.packet+10)) = SKELETON_VERSION_MINOR; /* version minor */ - *((ogg_int64_t*)(op.packet+12)) = (ogg_int64_t)fp->ptime_n; /* presentationtime numerator */ - *((ogg_int64_t*)(op.packet+20)) = (ogg_int64_t)fp->ptime_d; /* presentationtime denominator */ - *((ogg_int64_t*)(op.packet+28)) = (ogg_int64_t)fp->btime_n; /* basetime numerator */ - *((ogg_int64_t*)(op.packet+36)) = (ogg_int64_t)fp->btime_d; /* basetime denominator */ + *((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 */ @@ -109,13 +176,13 @@ ogg_packet ogg_from_fisbone(fisbone_packet *fp) { 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)) = FISBONE_MESSAGE_HEADER_OFFSET; /* offset of the message header fields */ - *((ogg_uint32_t*)(op.packet+12)) = fp->serial_no; /* serialno of the respective stream */ - *((ogg_uint32_t*)(op.packet+16)) = fp->nr_header_packet; /* number of header packets */ - *((ogg_int64_t*)(op.packet+20)) = fp->granule_rate_n; /* granulrate numerator */ - *((ogg_int64_t*)(op.packet+28)) = fp->granule_rate_d; /* granulrate denominator */ - *((ogg_int64_t*)(op.packet+36)) = fp->start_granule; /* start granule */ - *((ogg_uint32_t*)(op.packet+44)) = fp->preroll; /* preroll, for theora its 0 */ + *((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); @@ -131,15 +198,17 @@ 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 = *((ogg_uint16_t*)(op->packet+8)); /* version major */ - fp.version_minor = *((ogg_uint16_t*)(op->packet+10)); /* version minor */ - fp.ptime_n = *((ogg_int64_t*)(op->packet+12)); /* presentationtime numerator */ - fp.ptime_d = *((ogg_int64_t*)(op->packet+20)); /* presentationtime denominator */ - fp.btime_n = *((ogg_int64_t*)(op->packet+28)); /* basetime numerator */ - fp.btime_d = *((ogg_int64_t*)(op->packet+36)); /* basetime denominator */ + ; 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; @@ -150,14 +219,16 @@ fisbone_packet fisbone_from_ogg(ogg_packet *op) { fisbone_packet fp; + /* if (memcmp(op->packet, FISBONE_IDENTIFIER, 8)) - ; /* invalid value, what do we do? */ - fp.serial_no = *((ogg_uint32_t*)(op->packet+12)); /* serialno of the stream represented by this fisbone packet */ - fp.nr_header_packet = *((ogg_uint32_t*)(op->packet+16)); /* number of header packets */ - fp.granule_rate_n = *((ogg_int64_t*)(op->packet+20)); /* granulrate numerator */ - fp.granule_rate_d = *((ogg_int64_t*)(op->packet+28)); /* granulrate denominator */ - fp.start_granule = *((ogg_int64_t*)(op->packet+36)); /* start granule */ - fp.preroll = *((ogg_uint32_t*)(op->packet+44)); /* preroll, for theora its 0 */ + ; 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)); @@ -214,3 +285,4 @@ int flush_ogg_stream_to_file(ogg_stream_state *os, FILE *out) { return 0; } + -- cgit v1.2.3