+ int i_header;
+
++ /* Some muxes, in particular the avformat mux, can mark given blocks
++ * as keyframes, to ensure that the stream starts with one.
++ * (This is particularly important for WebM streaming to certain
++ * browsers.) Store if we've ever seen any such keyframe blocks,
++ * and if so, the byte position of the start of the last one. */
++ bool b_has_keyframes;
++ int64_t i_last_keyframe_seen_pos;
++
+ /* circular buffer */
+ int i_buffer_size; /* buffer size, can't be reallocated smaller */
+ uint8_t *p_buffer; /* buffer */
+@@ -659,6 +677,16 @@ static int httpd_StreamCallBack( httpd_callback_sys_t *p_sys,
+ /* fprintf( stderr, "httpd_StreamCallBack: no data\n" ); */
+ return VLC_EGENERIC; /* wait, no data available */
+ }
++ if( cl->i_keyframe_wait_to_pass >= 0 )
++ {
++ if( stream->i_last_keyframe_seen_pos <= cl->i_keyframe_wait_to_pass )
++ /* still waiting for the next keyframe */
++ return VLC_EGENERIC;
++
++ /* seek to the new keyframe */
++ answer->i_body_offset = stream->i_last_keyframe_seen_pos;
++ cl->i_keyframe_wait_to_pass = -1;
++ }
+ if( answer->i_body_offset + stream->i_buffer_size <
+ stream->i_buffer_pos )
+ {
+@@ -712,11 +740,31 @@ static int httpd_StreamCallBack( httpd_callback_sys_t *p_sys,