+ Ogg_LogicalStreamDelete( p_demux, p_ogg->pp_stream[i_stream] );
+ free( p_ogg->pp_stream );
+
+ /* Reinit p_ogg */
+ p_ogg->i_bitrate = 0;
+ p_ogg->i_streams = 0;
+ p_ogg->pp_stream = NULL;
+
+ /* */
+ if( p_ogg->p_meta )
+ vlc_meta_Delete( p_ogg->p_meta );
+ p_ogg->p_meta = NULL;
+}
+
+/**
+ * This function delete and release all data associated to a logical_stream_t
+ */
+static void Ogg_LogicalStreamDelete( demux_t *p_demux, logical_stream_t *p_stream )
+{
+ if( p_stream->p_es )
+ es_out_Del( p_demux->out, p_stream->p_es );
+
+ ogg_stream_clear( &p_stream->os );
+ free( p_stream->p_headers );
+
+ es_format_Clean( &p_stream->fmt_old );
+ es_format_Clean( &p_stream->fmt );
+
+ if ( p_stream->idx != NULL)
+ {
+ oggseek_index_entries_free( p_stream->idx );
+ }
+
+ free( p_stream );
+}
+/**
+ * This function check if a we need to reset a decoder in case we are
+ * reusing an old ES
+ */
+static bool Ogg_IsVorbisFormatCompatible( const es_format_t *p_new, const es_format_t *p_old )
+{
+ unsigned pi_new_size[XIPH_MAX_HEADER_COUNT];
+ void *pp_new_data[XIPH_MAX_HEADER_COUNT];
+ unsigned i_new_count;
+ if( xiph_SplitHeaders(pi_new_size, pp_new_data, &i_new_count, p_new->i_extra, p_new->p_extra ) )
+ i_new_count = 0;
+
+ unsigned pi_old_size[XIPH_MAX_HEADER_COUNT];
+ void *pp_old_data[XIPH_MAX_HEADER_COUNT];
+ unsigned i_old_count;
+ if( xiph_SplitHeaders(pi_old_size, pp_old_data, &i_old_count, p_old->i_extra, p_old->p_extra ) )
+ i_old_count = 0;
+
+ bool b_match = i_new_count == i_old_count;
+ for( unsigned i = 0; i < i_new_count && b_match; i++ )
+ {
+ /* Ignore vorbis comment */
+ if( i == 1 )
+ continue;
+ if( pi_new_size[i] != pi_old_size[i] ||
+ memcmp( pp_new_data[i], pp_old_data[i], pi_new_size[i] ) )
+ b_match = false;
+ }
+
+ for( unsigned i = 0; i < i_new_count; i++ )
+ free( pp_new_data[i] );
+ for( unsigned i = 0; i < i_old_count; i++ )
+ free( pp_old_data[i] );
+ return b_match;
+}
+
+static bool Ogg_IsOpusFormatCompatible( const es_format_t *p_new,
+ const es_format_t *p_old )
+{
+ unsigned pi_new_size[XIPH_MAX_HEADER_COUNT];
+ void *pp_new_data[XIPH_MAX_HEADER_COUNT];
+ unsigned i_new_count;
+ if( xiph_SplitHeaders(pi_new_size, pp_new_data, &i_new_count, p_new->i_extra, p_new->p_extra ) )
+ i_new_count = 0;
+ unsigned pi_old_size[XIPH_MAX_HEADER_COUNT];
+ void *pp_old_data[XIPH_MAX_HEADER_COUNT];
+ unsigned i_old_count;
+ if( xiph_SplitHeaders(pi_old_size, pp_old_data, &i_old_count, p_old->i_extra, p_old->p_extra ) )
+ i_old_count = 0;
+ bool b_match = false;
+ if( i_new_count == i_old_count && i_new_count > 0 )