I'm trying to adapt decoder_example to to support more of an event driven
model. I'm building an RTSP client/server where the client will have a
function called everytime a new packet comes in. So, I want to queue
up these packets to be played.
My current attack is as follows (note this isn't very robust and I
realized that):
For first and second packet i grab all the header stuff in the same way
as decoder_example. From the third packet on, I send it to a bunch of
code:
float **pcm;
int samples;
buffer=ogg_sync_buffer(&oy,4096);
bytes = 4096;
buffer = memcpy (buffer, data, bytes);
ogg_sync_wrote(&oy,bytes);
ogg_sync_pageout(&oy,&og);
ogg_stream_pagein(&os,&og); /* can safely ignore errors at
this point */
/* we have a packet. Decode it */
if(vorbis_synthesis(&vb,&op)==0) /* test for success! */
vorbis_synthesis_blockin(&vd,&vb);
/*
**pcm is a multichannel float vector. In stereo, for
example, pcm[0] is left, and pcm[1] is right. samples is
the size of each channel. Convert the float values
(-1.<=range<=1.) to whatever PCM format and write it out */
while((samples=vorbis_synthesis_pcmout(&vd,&pcm))>0) {
int i,j;
int clipflag=0;
int bout=(samples<convsize?samples:convsize);
fprintf (stderr,
"\nhoebag, i made it the while loop");
/* convert floats to 16 bit signed ints (host order) and
interleave */
for(i=0;i<vi.channels;i++){
ogg_int16_t *ptr=convbuffer+i;
float *mono=pcm[i];
for(j=0;j<bout;j++){
#if 1
int val=mono[j]*32767.f;
#else /* optional dither */
int val=mono[j]*32767.f+drand48()-0.5f;
#endif
/* might as well guard against clipping */
if(val>32767){
val=32767;
clipflag=1;
}
if(val<-32768){
val=-32768;
clipflag=1;
}
*ptr=val;
ptr+=2;
}
}
if(clipflag)
fprintf(stderr,"Clipping in frame
%ld\n",(long)(vd.sequence));
write (mywav, convbuffer, 2*vi.channels*bout);
vorbis_synthesis_read(&vd,bout); /* tell libvorbis how
many samples we
actually consumed */
}
---
So, the first packets come in fine because I can retrieve the title, etc
properly. All of the packets come in correctly because I write them out
to disk and it is the same file as the original file. However, when I put
the packets through the above code, I lose a lot of information and the
mywav file is a small portion of what it should be.
If anyone has some ideas how I can solve this problem, I would appreciate
any help.
Thanks,
Wayne
--
Wayne Davis - wfdavis@seas.upenn.edu - PGP Key Available
--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to
'vorbis-dev-request@xiph.org'
containing only the word 'unsubscribe' in the body. No subject is
needed.
Unsubscribe messages sent to the list will be ignored/filtered.
At 01:58 AM 4/6/01 -0400, you wrote:>I'm trying to adapt decoder_example to to support more of an event driven >model. I'm building an RTSP client/server where the client will have a >function called everytime a new packet comes in. So, I want to queue >up these packets to be played.Note that there is an RTP spec (draft) for vorbis. This is completely different from that, and will have other problems (headers, for example). Anyway...> >My current attack is as follows (note this isn't very robust and I >realized that): > >For first and second packet i grab all the header stuff in the same way >as decoder_example. From the third packet on, I send it to a bunch of >code:There are 3 packets for headers, but from your description you are in fact getting all three. The following code is completely wrong if you're executing it for each incoming packet. If you already have a packet at this point, you shouldn't be calling any of the ogg_* functions. Presumably, you just have a data buffer.> > float **pcm; > int samples; > > buffer=ogg_sync_buffer(&oy,4096); > > bytes = 4096; > buffer = memcpy (buffer, data, bytes);^^^^^^ not actually wrong, merely strange. Also, are you sure you always have 4096 bytes in your buffer?> > ogg_sync_wrote(&oy,bytes); > > ogg_sync_pageout(&oy,&og);You MUST check that this succeeds (it WON'T always. This would be my first guess as to what's causing your problem.> ogg_stream_pagein(&os,&og); /* can safely ignore errors at > this point */ > > /* we have a packet. Decode it */No, you don't yet have a packet. This is my second guess as to what's causing a problem. You need to use ogg_stream_packetout() to get a packet first. The rest doesn't have any really obvious mistakes. You WILL NEED more return value checking (decoder_example has this). You should also check for error returns, which decoder_example mostly doesn't. Michael --- >8 ---- List archives: http://www.xiph.org/archives/ Ogg project homepage: http://www.xiph.org/ogg/ To unsubscribe from this list, send a message to 'vorbis-dev-request@xiph.org' containing only the word 'unsubscribe' in the body. No subject is needed. Unsubscribe messages sent to the list will be ignored/filtered.