-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Il 15/04/2010 01:30, Conrad Parker wrote:> >> But how can I know the size of each speex frame into a multiframe payload? > > use speex_bit_read_from() just once on the packet, then call > speex_decode() once for each frame. > > Conrad.Thanks for the reply, Conrad. What is not clear for me (and I didn't found it on the manual) is how to decode a multi-frame payload. Once have called speex_bits_read_from, I need a way to know how many speex frames there are, how can I do this? I try to use speex_bits_remaining, but after some cycles it returns always 4. UINT DecodePayload( char* payload, UINT payload_len ) { speex_bits_reset(&spx_bits_); speex_bits_read_from(&spx_bits_, payload, payload_len); UINT nbBytes = speex_bits_remaining(&spx_bits_); while (nbBytes>0) { speex_decode(spx_state_, &spx_bits_, spx_dec_frame_); nbBytes = speex_bits_remaining(&spx_bits_); // Save the speex frame into the buffer DecOutBuffer_.Write(spx_dec_frame_, spx_frame_size_); } } Any suggestion? Thanks, Daniele. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (MingW32) iEYEARECAAYFAkvG1HUACgkQ/l+kMioSZwi/JgCfarhEpOljEFU3/zLrXO1BL+dq TqUAn2P1YMuqbNz3K80pvP0fJ0JTCFos =arZ0 -----END PGP SIGNATURE-----
On 15 April 2010 17:55, Daniele Barzotti <daniele.barzotti at eurocomtel.com> wrote:> -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Il 15/04/2010 01:30, Conrad Parker wrote: >> >>> But how can I know the size of each speex frame into a multiframe payload? >> >> use speex_bit_read_from() just once on the packet, then call >> speex_decode() once for each frame. >> >> Conrad. > > Thanks for the reply, Conrad. > What is not clear for me (and I didn't found it on the manual) is how to > decode a multi-frame payload. > Once have called speex_bits_read_from, I need a way to know how many > speex frames there are, how can I do this? > > I try to use speex_bits_remaining, but after some cycles it returns > always 4. > > UINT DecodePayload( char* payload, UINT payload_len ) > { > ?speex_bits_reset(&spx_bits_); > ?speex_bits_read_from(&spx_bits_, payload, payload_len); > ?UINT nbBytes = speex_bits_remaining(&spx_bits_); > > ?while (nbBytes>0) > ?{ > ? ?speex_decode(spx_state_, &spx_bits_, spx_dec_frame_); > ? ?nbBytes = speex_bits_remaining(&spx_bits_); > > ? ?// Save the speex frame into the buffer > ? ?DecOutBuffer_.Write(spx_dec_frame_, spx_frame_size_); > ?} > } > > Any suggestion?I think speex_decode() updates the number of bits remaining; here's what I use: http://git.xiph.org/?p=libfishsound.git;a=blob;f=src/libfishsound/speex.c;h=ac435cba37354d85c2852ce4c7c6305490c0d585;hb=HEAD#l342 but the number of frames in a packet is up to your application. For an Ogg stream it will be a field in the speex_header, for RTP using SDP it is calculated from ptime according to section 5.6 of RFC5574: http://tools.ietf.org/rfc/rfc5574.txt Without SDP, section 3.5 states: "The Speex decoder [SPEEX] can detect the bit-rate from the payload and is responsible for detecting the 20 msec boundaries between each frame." but I don't know how that translates into libspeex calls. Jean-Marc? Conrad.
Il 15/04/2010 11:17, Conrad Parker wrote:> > but the number of frames in a packet is up to your application. > > "The Speex decoder [SPEEX] can detect the bit-rate from the payload > and is responsible for detecting the 20 msec boundaries between each > frame."Hi, reading more careful the speex_decode() help ( http://www.speex.org/docs/api/speex-api-reference/group__Codec.html#g0ac60440b73e560fcfbca4f9e497d993 ), it should be enough to test the return value: 0 for no error, -1 for end of stream, -2 corrupt stream. UINT DecodePayload( char* payload, UINT payload_len ) { speex_bits_reset(&spx_bits_); speex_bits_read_from(&spx_bits_, payload, payload_len); UINT nbBytes = speex_bits_remaining(&spx_bits_); while (nbBytes>0) { if ( speex_decode(spx_state_, &spx_bits_, spx_dec_frame_) != 0 ) break; nbBytes = speex_bits_remaining(&spx_bits_); // Save the speex frame into the buffer DecOutBuffer_.Write(spx_dec_frame_, spx_frame_size_); } } Daniele.