+static void Ogg_ExtractXiphMeta( demux_t *p_demux, const uint8_t *p_headers, int i_headers, int i_skip, bool b_has_num_headers )
+{
+ demux_sys_t *p_ogg = p_demux->p_sys;
+
+ if (b_has_num_headers)
+ {
+ if (i_headers <= 0)
+ return;
+ /* number of headers on a byte, we're interested in the second header, so should be at least 2 to go on */
+ if (*p_headers++ < 2)
+ return;
+ --i_headers;
+ }
+
+ if( i_headers <= 2 )
+ return;
+
+ /* Skip first packet */
+ const int i_tmp = GetWBE( &p_headers[0] );
+ if( i_tmp > i_headers-2 )
+ return;
+ p_headers += 2 + i_tmp;
+ i_headers -= 2 + i_tmp;
+
+ if( i_headers <= 2 )
+ return;
+
+ /* */
+ int i_comment = GetWBE( &p_headers[0] );
+ const uint8_t *p_comment = &p_headers[2];
+ if( i_comment > i_headers - 2 )
+ return;
+
+ if( i_comment <= i_skip )
+ return;
+
+ /* TODO how to handle multiple comments properly ? */
+ vorbis_ParseComment( &p_ogg->p_meta, &p_comment[i_skip], i_comment - i_skip );
+}
+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, false );
+ break;
+ case VLC_CODEC_THEORA:
+ Ogg_ExtractXiphMeta( p_demux, p_headers, i_headers, 1+6, false );
+ break;
+ case VLC_CODEC_SPEEX:
+ Ogg_ExtractXiphMeta( p_demux, p_headers, i_headers, 0, false );
+ break;
+
+ /* N headers with the 2° one being the comments */
+ case VLC_CODEC_KATE:
+ /* 1 byte for header type, 7 bit for magic, 1 reserved zero byte */
+ Ogg_ExtractXiphMeta( p_demux, p_headers, i_headers, 1+7+1, true );
+ 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;
+}