[xiph-commits] r10391 - trunk/xiph-rtp
lu_zero at svn.xiph.org
lu_zero at svn.xiph.org
Wed Nov 16 14:56:32 PST 2005
Author: lu_zero
Date: 2005-11-16 14:56:29 -0800 (Wed, 16 Nov 2005)
New Revision: 10391
Modified:
trunk/xiph-rtp/vorbisrtp-client.c
Log:
Some fixes, the codebook isn't parsed correctly
Modified: trunk/xiph-rtp/vorbisrtp-client.c
===================================================================
--- trunk/xiph-rtp/vorbisrtp-client.c 2005-11-16 08:48:23 UTC (rev 10390)
+++ trunk/xiph-rtp/vorbisrtp-client.c 2005-11-16 22:56:29 UTC (rev 10391)
@@ -55,18 +55,6 @@
#define MAX(x,y) (((x) > (y)) ? (x) : (y))
#define MIN(x,y) (((x) < (y)) ? (x) : (y))
-
-
-
-int _ilog(unsigned int v){
- int ret=0;
- while(v){
- ret++;
- v>>=1;
- }
- return(ret);
-}
-
typedef struct ogg_context {
ogg_packet op;
ogg_stream_state os;
@@ -82,21 +70,123 @@
int frag;
float **pcm;
unsigned int timestamp;
- //
int modes;
long blocksizes[2];
int param_blockflag[64];
} ogg_context_t;
-/*
-int pkt_granulepos( ogg_context_t *ogg )
+int _ilog(unsigned int v){
+ int ret=0;
+ while(v){
+ ret++;
+ v>>=1;
+ }
+ return(ret);
+}
+
+int
+dump_packet_raw (unsigned char *data, const int len, FILE * out)
{
- ogg_packet *op = ogg->op;
- vorbis_info *vi = ogg->vi;
-
+ int i, j, n;
+
+ i = 0;
+ while (i < len)
+ {
+ fprintf (out, " %04x ", i);
+ n = MIN (8, len - i);
+ for (j = 0; j < n; j++)
+ fprintf (out, " %02x", data[i + j]);
+ fprintf (out, " ");
+ n = MIN (16, len - i);
+ for (j = 8; j < 16; j++)
+ fprintf (out, " %02x", data[i + j]);
+ fprintf (out, " ");
+ for (j = 0; j < n; j++)
+ fprintf (out, "%c", isprint (data[i + j]) ? data[i + j] : '.');
+ fprintf (out, "\n");
+ i += 16;
+ }
+
+ return 0;
}
-*/
-long _book_maptype1_quantvals(int entries, int dim){
+
+int
+dump_packet_rtp (unsigned char *data, const int len, FILE * out)
+{
+ int V, P, X, CC, M, PT;
+ unsigned short sequence;
+ unsigned int timestamp, ssrc;
+ unsigned int ident;
+ int F, VDT, pkts;
+ int i, offset, length;
+
+ /* parse RTP header */
+ V = (data[0] & 0xc0) >> 6;
+ P = (data[0] & 0x40) >> 5;
+ X = (data[0] & 0x20) >> 4;
+ CC = (data[0] & 0x0f);
+ M = (data[1] & 0x80) >> 7;
+ PT = (data[1] & 0x7F);
+ sequence = ntohs (((unsigned short *) data)[1]);
+ timestamp = ntohl (((unsigned int *) data)[1]);
+ ssrc = ntohl (((unsigned int *) data)[2]);
+
+ fprintf (out, "RTP packet V:%d P:%d X:%d M:%d PT:%d", V, P, X, M, PT);
+ fprintf (out, " seq %d", sequence);
+ fprintf (out, " timestamp: %u\n", timestamp);
+ fprintf (out, " ssrc: 0x%08x", ssrc);
+ if (CC)
+ for (i = 0; i < CC; i++)
+ fprintf (out, " csrc: 0x%08x",
+ ntohl (((unsigned int *) data)[3 + i]));
+ else
+ fprintf (out, " no csrc");
+ fprintf (out, "\n");
+ /* offset to payload header */
+ offset = (3 + CC) * 4;
+
+ /* parse Vorbis payload header */
+ ident = data[offset++]<<16;
+ ident += data[offset++]<<8;
+ ident += data[offset++];
+ F = (data[offset] & 0xc0) >> 6;
+ VDT = (data[offset] & 0x30) >> 4;
+ pkts = (data[offset] & 0x0F);
+ offset++;
+
+ fprintf(out,"ident %06x, frag type %d, data type %d, pkts %d, size %d\n",
+ ident,F,VDT,pkts,len-4*(CC+3));
+
+ for (i = 0; i < pkts; i++)
+ {
+ if (offset >= len)
+ {
+ fprintf (stderr, "payload length overflow. corrupt packet?\n");
+ return -1;
+ }
+ length = data[offset++]<<8;
+ length += data[offset++];
+ fprintf (out, " data: %d bytes in block %d\n", length, i);
+ offset += length;
+ }
+ if (pkts == 0)
+ {
+ length = data[offset++]<<8;
+ length += data [offset++];
+ fprintf (out, " data: %d bytes in fragment\n", length);
+ offset += length;
+ }
+
+ if (len - offset > 0)
+ fprintf (out, " %d unused bytes at the end of the packet!\n",
+ len - offset);
+
+ return 0;
+}
+
+long
+maptype_quantvals(int entries, int dim)
+{
long vals=floor(pow((float)entries,1.f/dim));
/* the above *should* be reliable, but we'll not assume that FP is
@@ -124,18 +214,6 @@
}
}
-long pkt_blocksize(ogg_context_t *ogg)
-{
- int mode;
- oggpack_buffer opb;
- oggpack_readinit(&opb,ogg->op.packet,ogg->op.bytes);
-
- oggpack_read(&opb,1);
-
- mode = oggpack_read(&opb,_ilog(ogg->modes));
- return ogg->blocksizes[ogg->param_blockflag[mode]];
-}
-
int cfg_parse( ogg_context_t *ogg )
{
oggpack_buffer opb;
@@ -149,7 +227,7 @@
num = oggpack_read(&opb,8)+1;
for(;num>0;num--)
{
- int entries, quantvals, maptype, q_quant, dim;
+ int entries, quantvals=0, maptype, q_quant, dim;
oggpack_read(&opb,24);
dim = oggpack_read(&opb,16);
entries = oggpack_read(&opb,24);
@@ -183,8 +261,7 @@
switch (maptype){
case 1:
- quantvals =
- _book_maptype1_quantvals(entries,dim);
+ quantvals = maptype_quantvals(entries,dim);
break;
case 2:
@@ -231,111 +308,34 @@
return 0; //FIXME add some checks and return -1 on failure
}
-int
-dump_packet_raw (unsigned char *data, const int len, FILE * out)
-{
- int i, j, n;
- i = 0;
- while (i < len)
- {
- fprintf (out, " %04x ", i);
- n = MIN (8, len - i);
- for (j = 0; j < n; j++)
- fprintf (out, " %02x", data[i + j]);
- fprintf (out, " ");
- n = MIN (16, len - i);
- for (j = 8; j < 16; j++)
- fprintf (out, " %02x", data[i + j]);
- fprintf (out, " ");
- for (j = 0; j < n; j++)
- fprintf (out, "%c", isprint (data[i + j]) ? data[i + j] : '.');
- fprintf (out, "\n");
- i += 16;
- }
-
- return 0;
-}
-
-int
-dump_packet_rtp (unsigned char *data, const int len, FILE * out)
+long pkt_blocksize(ogg_context_t *ogg)
{
- int V, P, X, CC, M, PT;
- unsigned short sequence;
- unsigned int timestamp, ssrc;
- unsigned int ident;
- int F, VDT, pkts;
- int i, offset, length;
+ int mode;
+ oggpack_buffer opb;
+ oggpack_readinit(&opb,ogg->op.packet,ogg->op.bytes);
- /* parse RTP header */
- V = (data[0] & 0xc0) >> 6;
- P = (data[0] & 0x40) >> 5;
- X = (data[0] & 0x20) >> 4;
- CC = (data[0] & 0x0f);
- M = (data[1] & 0x80) >> 7;
- PT = (data[1] & 0x7F);
- sequence = ntohs (((unsigned short *) data)[1]);
- timestamp = ntohl (((unsigned int *) data)[1]);
- ssrc = ntohl (((unsigned int *) data)[2]);
+ oggpack_read(&opb,1);
- fprintf (out, "RTP packet V:%d P:%d X:%d M:%d PT:%d", V, P, X, M, PT);
- fprintf (out, " seq %d", sequence);
- fprintf (out, " timestamp: %u\n", timestamp);
- fprintf (out, " ssrc: 0x%08x", ssrc);
- if (CC)
- for (i = 0; i < CC; i++)
- fprintf (out, " csrc: 0x%08x",
- ntohl (((unsigned int *) data)[3 + i]));
- else
- fprintf (out, " no csrc");
- fprintf (out, "\n");
- /* offset to payload header */
- offset = (3 + CC) * 4;
+ {
+ int modebits=0;
+ int v=ogg->modes;
+ while(v>1){
+ modebits++;
+ v>>=1;
+ }
- /* parse Vorbis payload header */
- ident = data[offset++]<<16;
- ident += data[offset++]<<8;
- ident += data[offset++];
- F = (data[offset] & 0xc0) >> 6;
- VDT = (data[offset] & 0x30) >> 4;
- pkts = (data[offset] & 0x0F);
- offset++;
-
- fprintf(out,"ident %06x, frag type %d, data type %d, pkts %d, size %d\n",
- ident,F,VDT,pkts,len-4*(CC+3));
-
- for (i = 0; i < pkts; i++)
- {
- if (offset >= len)
- {
- fprintf (stderr, "payload length overflow. corrupt packet?\n");
- return -1;
+ mode = oggpack_read(&opb,modebits);
}
- length = data[offset++]<<8;
- length += data[offset++];
- fprintf (out, " data: %d bytes in block %d\n", length, i);
- offset += length;
- }
- if (pkts == 0)
- {
- length = data[offset++]<<8;
- length += data [offset++];
- fprintf (out, " data: %d bytes in fragment\n", length);
- offset += length;
- }
-
- if (len - offset > 0)
- fprintf (out, " %d unused bytes at the end of the packet!\n",
- len - offset);
-
- return 0;
+ return ogg->blocksizes[ogg->param_blockflag[mode]];
}
+
int
cfg_repack(ogg_context_t *ogg, FILE* out)
{
ogg_packet id,co,cb;
- char comment[] =
+ unsigned char comment[] =
/* Example
* {3,118,111,114,98,105,115,
29,0,0,0,
@@ -387,8 +387,22 @@
ogg->vi.rate+=id.packet[12+1]<<8;
ogg->vi.rate+=id.packet[12+2]<<8;
ogg->vi.rate+=id.packet[12+3]<<24;
+
+ cfg_parse(ogg);
+
#if CHECK
- fprintf(stderr,"parsed rate: %ld\n",ogg->vi.rate);
+ fprintf(stderr,"parsed: rate %ld, blocksizes %ld %ld\n ",
+ ogg->vi.rate,
+ ogg->blocksizes[0],
+ ogg->blocksizes[1]
+ );
+ {
+ int i;
+ for (i=0;i<ogg->modes;i++)
+ fprintf(stderr," %d ", ogg->param_blockflag[i]);
+ fprintf(stderr,"\n");
+ }
+
vorbis_info_init(&ogg->vi);
vorbis_comment_init(&ogg->vc);
if(vorbis_synthesis_headerin(&ogg->vi,&ogg->vc,&id)<0){
@@ -403,7 +417,7 @@
/* error case; not a vorbis header */
fprintf(stderr,"Not valid setup\n");
} else fprintf(stderr," Valid setup\n");
- fprintf(stderr,"decoded rate: %ld\n",ogg->vi.rate);
+ fprintf(stderr,"decoded: rate %ld\n",ogg->vi.rate);
#endif
/* start the ogg*/
ogg_stream_init(&ogg->os,rand());
@@ -518,7 +532,7 @@
ogg->curr_bs = vorbis_packet_blocksize(&ogg->vi,op);
if(ogg->prev_bs)
op->granulepos += (ogg->curr_bs + ogg->prev_bs)/4;
- fprintf(stderr,"gp %lld, ss %ld, pno %lld\n", op->granulepos, (ogg->curr_bs + ogg->prev_bs)/4, op->packetno);
+ fprintf(stderr,"gp %lld, d_bs %ld, p_bs %ld, pno %lld\n", op->granulepos, ogg->curr_bs, pkt_blocksize(ogg), op->packetno);
ogg->prev_bs = ogg->curr_bs;
#else
if (i == 0)
More information about the commits
mailing list