/***************************************************************************** * ProcessHeaders: process Opus headers. *****************************************************************************/ static int ProcessHeaders( decoder_t *p_dec ) { ogg_packet oggpacket; unsigned pi_size[XIPH_MAX_HEADER_COUNT]; void *pp_data[XIPH_MAX_HEADER_COUNT]; unsigned i_count; if( xiph_SplitHeaders( pi_size, pp_data, &i_count, p_dec->fmt_in.i_extra, p_dec->fmt_in.p_extra) ) return VLC_EGENERIC; if( i_count < 2 ) return VLC_EGENERIC;; oggpacket.granulepos = -1; oggpacket.e_o_s = 0; oggpacket.packetno = 0; /* Take care of the initial Opus header */ oggpacket.b_o_s = 1; /* yes this actually is a b_o_s packet :) */ oggpacket.bytes = pi_size[0]; oggpacket.packet = pp_data[0]; int ret = ProcessInitialHeader( p_dec, &oggpacket ); if (ret != VLC_SUCCESS) msg_Err( p_dec, "initial Opus header is corrupted" ); return ret; }
/***************************************************************************** * ProcessHeaders: process Opus headers. *****************************************************************************/ static int ProcessHeaders( decoder_t *p_dec ) { ogg_packet oggpacket; unsigned pi_size[XIPH_MAX_HEADER_COUNT]; void *pp_data[XIPH_MAX_HEADER_COUNT]; unsigned i_count; int i_extra = p_dec->fmt_in.i_extra; uint8_t *p_extra = p_dec->fmt_in.p_extra; /* If we have no header (e.g. from RTP), make one. */ bool b_dummy_header = false; if( !i_extra ) { OpusHeader header; opus_prepare_header( p_dec->fmt_in.audio.i_channels, p_dec->fmt_in.audio.i_rate, &header ); if( opus_write_header( &p_extra, &i_extra, &header, opus_get_version_string() ) ) return VLC_ENOMEM; b_dummy_header = true; } if( xiph_SplitHeaders( pi_size, pp_data, &i_count, i_extra, p_extra ) ) { if( b_dummy_header ) free( p_extra ); return VLC_EGENERIC; } if( i_count < 2 ) { if( b_dummy_header ) free( p_extra ); return VLC_EGENERIC; } oggpacket.granulepos = -1; oggpacket.e_o_s = 0; oggpacket.packetno = 0; /* Take care of the initial Opus header */ oggpacket.b_o_s = 1; /* yes this actually is a b_o_s packet :) */ oggpacket.bytes = pi_size[0]; oggpacket.packet = pp_data[0]; int ret = ProcessInitialHeader( p_dec, &oggpacket ); if (ret != VLC_SUCCESS) msg_Err( p_dec, "initial Opus header is corrupted" ); if( b_dummy_header ) free( p_extra ); return ret; }
static int CreateDefaultHeader( decoder_t *p_dec ) { ogg_packet oggpacket; SpeexHeader *p_header = malloc( sizeof(SpeexHeader) ); if( !p_header ) return VLC_ENOMEM; const int rate = p_dec->fmt_in.audio.i_rate; const unsigned i_mode = (rate / 8000) >> 1; const SpeexMode *mode; int ret = VLC_SUCCESS; oggpacket.packet = NULL; switch( rate ) { case 8000: case 16000: case 32000: mode = speex_lib_get_mode( i_mode ); break; default: msg_Err( p_dec, "Unexpected rate %d", rate ); ret = VLC_EGENERIC; goto cleanup; } speex_init_header( p_header, rate, p_dec->fmt_in.audio.i_channels, mode ); p_header->frames_per_packet = 160 << i_mode; oggpacket.packet = (unsigned char *) speex_header_to_packet( p_header, (int *) &oggpacket.bytes ); if( !oggpacket.packet ) { ret = VLC_ENOMEM; goto cleanup; } oggpacket.b_o_s = 1; oggpacket.e_o_s = 0; oggpacket.granulepos = -1; oggpacket.packetno = 0; ret = ProcessInitialHeader( p_dec, &oggpacket ); if( ret != VLC_SUCCESS ) { msg_Err( p_dec, "default Speex header is corrupted" ); } cleanup: free( oggpacket.packet ); free( p_header ); return ret; }
/***************************************************************************** * ProcessHeaders: process Speex headers. *****************************************************************************/ static int ProcessHeaders( decoder_t *p_dec ) { decoder_sys_t *p_sys = p_dec->p_sys; ogg_packet oggpacket; unsigned pi_size[XIPH_MAX_HEADER_COUNT]; void *pp_data[XIPH_MAX_HEADER_COUNT]; unsigned i_count; if( xiph_SplitHeaders( pi_size, pp_data, &i_count, p_dec->fmt_in.i_extra, p_dec->fmt_in.p_extra) ) return VLC_EGENERIC; if( i_count < 2 ) goto error; oggpacket.granulepos = -1; oggpacket.e_o_s = 0; oggpacket.packetno = 0; /* Take care of the initial Vorbis header */ oggpacket.b_o_s = 1; /* yes this actually is a b_o_s packet :) */ oggpacket.bytes = pi_size[0]; oggpacket.packet = (unsigned char *)pp_data[0]; // sunqueen modify if( ProcessInitialHeader( p_dec, &oggpacket ) != VLC_SUCCESS ) { msg_Err( p_dec, "initial Speex header is corrupted" ); goto error; } /* The next packet in order is the comments header */ oggpacket.b_o_s = 0; oggpacket.bytes = pi_size[1]; oggpacket.packet = (unsigned char *)pp_data[1]; // sunqueen modify ParseSpeexComments( p_dec, &oggpacket ); if( p_sys->b_packetizer ) { p_dec->fmt_out.i_extra = p_dec->fmt_in.i_extra; p_dec->fmt_out.p_extra = xrealloc( p_dec->fmt_out.p_extra, p_dec->fmt_out.i_extra ); memcpy( p_dec->fmt_out.p_extra, p_dec->fmt_in.p_extra, p_dec->fmt_out.i_extra ); } for( unsigned i = 0; i < i_count; i++ ) free( pp_data[i] ); return VLC_SUCCESS; error: for( unsigned i = 0; i < i_count; i++ ) free( pp_data[i] ); return VLC_EGENERIC; }
/***************************************************************************** * ProcessHeaders: process Speex headers. *****************************************************************************/ static int ProcessHeaders( decoder_t *p_dec ) { decoder_sys_t *p_sys = p_dec->p_sys; ogg_packet oggpacket; unsigned pi_size[XIPH_MAX_HEADER_COUNT]; void *pp_data[XIPH_MAX_HEADER_COUNT]; unsigned i_count; if( xiph_SplitHeaders( pi_size, pp_data, &i_count, p_dec->fmt_in.i_extra, p_dec->fmt_in.p_extra) ) return VLC_EGENERIC; if( i_count < 2 ) return VLC_EGENERIC;; oggpacket.granulepos = -1; oggpacket.e_o_s = 0; oggpacket.packetno = 0; /* Take care of the initial Vorbis header */ oggpacket.b_o_s = 1; /* yes this actually is a b_o_s packet :) */ oggpacket.bytes = pi_size[0]; oggpacket.packet = pp_data[0]; if( ProcessInitialHeader( p_dec, &oggpacket ) != VLC_SUCCESS ) { msg_Err( p_dec, "initial Speex header is corrupted" ); return VLC_EGENERIC;; } /* The next packet in order is the comments header */ oggpacket.b_o_s = 0; oggpacket.bytes = pi_size[1]; oggpacket.packet = pp_data[1]; ParseSpeexComments( p_dec, &oggpacket ); if( p_sys->b_packetizer ) { void* p_extra = realloc( p_dec->fmt_out.p_extra, p_dec->fmt_in.i_extra ); if( unlikely( p_extra == NULL ) ) { return VLC_ENOMEM; } p_dec->fmt_out.p_extra = p_extra; p_dec->fmt_out.i_extra = p_dec->fmt_in.i_extra; memcpy( p_dec->fmt_out.p_extra, p_dec->fmt_in.p_extra, p_dec->fmt_out.i_extra ); } return VLC_SUCCESS; }