X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fcodec%2Fopus.c;h=c05e27ed2ac428177e5ea2733fe7a01a55336d9a;hb=21e724fa751d51b0f10d63ad5467e216383c3fa4;hp=d4e5f88fc1cadc3d91fdd08995b379e9cfe6602e;hpb=7163c4b94a441b3bba7355a9bb117d048a33747b;p=vlc diff --git a/modules/codec/opus.c b/modules/codec/opus.c index d4e5f88fc1..c05e27ed2a 100644 --- a/modules/codec/opus.c +++ b/modules/codec/opus.c @@ -283,7 +283,7 @@ static int ProcessInitialHeader( decoder_t *p_dec, ogg_packet *p_oggpacket ) msg_Dbg( p_dec, "Opus audio with %d channels", p_header->channels); if((p_header->channels>2 && p_header->channel_mapping==0) || - (p_header->channels>8 && p_header->channel_mapping==1) || + p_header->channels>8 || p_header->channel_mapping>1) { msg_Err( p_dec, "Unsupported channel mapping" ); @@ -360,14 +360,15 @@ static void *ProcessPacket( decoder_t *p_dec, ogg_packet *p_oggpacket, *pp_block = NULL; /* To avoid being fed the same packet again */ - { - block_t *p_aout_buffer = DecodePacket( p_dec, p_oggpacket, - p_block->i_nb_samples, - (int)p_block->i_length ); + if( !p_block ) + return NULL; - block_Release( p_block ); - return p_aout_buffer; - } + block_t *p_aout_buffer = DecodePacket( p_dec, p_oggpacket, + p_block->i_nb_samples, + (int)p_block->i_length ); + + block_Release( p_block ); + return p_aout_buffer; } /***************************************************************************** @@ -386,6 +387,11 @@ static block_t *DecodePacket( decoder_t *p_dec, ogg_packet *p_oggpacket, if(spp>0)spp*=opus_packet_get_samples_per_frame(p_oggpacket->packet,48000); if(spp<120||spp>120*48)return NULL; + /* Since the information isn't always available at the demux level + * use the packet's sample number */ + if(!i_nb_samples) + i_nb_samples = spp; + block_t *p_aout_buffer=decoder_NewAudioBuffer( p_dec, spp ); if ( !p_aout_buffer ) { @@ -402,10 +408,12 @@ static block_t *DecodePacket( decoder_t *p_dec, ogg_packet *p_oggpacket, msg_Err( p_dec, "Error: corrupted stream?" ); return NULL; } + + p_aout_buffer->i_buffer = (i_nb_samples - i_end_trim) * + p_sys->header.channels * sizeof(float); + if( spp > i_nb_samples ) { - p_aout_buffer->i_buffer = (i_nb_samples - i_end_trim) * - p_sys->header.channels * sizeof(float); memmove(p_aout_buffer->p_buffer, p_aout_buffer->p_buffer + (spp - i_nb_samples)*p_sys->header.channels*sizeof(float), @@ -606,7 +614,10 @@ static int OpenEncoder(vlc_object_t *p_this) goto error; } - /* TODO: vbr, bitrate, fec */ + /* TODO: vbr, fec */ + + if( enc->fmt_out.i_bitrate ) + opus_multistream_encoder_ctl(sys->enc, OPUS_SET_BITRATE( enc->fmt_out.i_bitrate )); /* Buffer for incoming audio, since opus only accepts frame sizes that are multiples of 2.5ms */ @@ -630,7 +641,7 @@ static int OpenEncoder(vlc_object_t *p_this) /* Now that we have preskip, we can write the header to extradata */ if (opus_write_header((uint8_t **) &enc->fmt_out.p_extra, - &enc->fmt_out.i_extra, &header)) + &enc->fmt_out.i_extra, &header, opus_get_version_string())) { msg_Err(enc, "Failed to write header."); status = VLC_ENOMEM;