+ 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_LogicalStreamResetEsFormat( demux_t *p_demux, logical_stream_t *p_stream )
+{
+ bool b_compatible = false;
+ if( !p_stream->fmt_old.i_cat || !p_stream->fmt_old.i_codec )
+ return true;
+
+ /* Only vorbis is supported */
+ if( p_stream->fmt.i_codec == VLC_CODEC_VORBIS )
+ b_compatible = Ogg_IsVorbisFormatCompatible( &p_stream->fmt, &p_stream->fmt_old );
+
+ if( !b_compatible )
+ msg_Warn( p_demux, "cannot reuse old stream, resetting the decoder" );
+
+ return !b_compatible;
+}
+static void Ogg_ExtractXiphMeta( demux_t *p_demux, const void *p_headers, unsigned i_headers, unsigned i_skip )
+{
+ demux_sys_t *p_ogg = p_demux->p_sys;
+
+ 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, i_headers, p_headers ) )
+ return;
+
+ /* TODO how to handle multiple comments properly ? */
+ if( i_count >= 2 && pi_size[1] > i_skip )
+ vorbis_ParseComment( &p_ogg->p_meta, (uint8_t*)pp_data[1] + i_skip, pi_size[1] - i_skip,
+ &p_ogg->i_attachments, &p_ogg->attachments );
+
+ for( unsigned i = 0; i < i_count; i++ )
+ free( pp_data[i] );
+}
+static void Ogg_ExtractMeta( demux_t *p_demux, vlc_fourcc_t i_codec, const uint8_t *p_headers, int i_headers )
+{
+ demux_sys_t *p_ogg = p_demux->p_sys;
+
+ switch( i_codec )
+ {
+ /* 3 headers with the 2° one being the comments */
+ case VLC_CODEC_VORBIS:
+ Ogg_ExtractXiphMeta( p_demux, p_headers, i_headers, 1+6 );
+ break;
+ case VLC_CODEC_THEORA:
+ Ogg_ExtractXiphMeta( p_demux, p_headers, i_headers, 1+6 );
+ break;
+ case VLC_CODEC_SPEEX:
+ Ogg_ExtractXiphMeta( p_demux, p_headers, i_headers, 0 );
+ break;
+
+ /* N headers with the 2° one being the comments */
+ case VLC_CODEC_KATE:
+ /* 1 byte for header type, 7 bytes for magic, 1 reserved zero byte */
+ Ogg_ExtractXiphMeta( p_demux, p_headers, i_headers, 1+7+1 );
+ break;
+
+ /* TODO */
+ case VLC_CODEC_FLAC:
+ msg_Warn( p_demux, "Ogg_ExtractMeta does not support %4.4s", (const char*)&i_codec );
+ break;
+
+ /* No meta data */
+ case VLC_CODEC_CMML: /* CMML is XML text, doesn't have Vorbis comments */
+ case VLC_CODEC_DIRAC:
+ default:
+ break;
+ }
+ if( p_ogg->p_meta )
+ p_demux->info.i_update |= INPUT_UPDATE_META;