Commit d1c8352d authored by Francois Cartegnie's avatar Francois Cartegnie

demux: ogg: seek to keyframes (fix #3417, #9284)

This patch changes the way seeking is done.

Previously it was a dumb stream size based seeking, and was
very approximative with multi-streams or non fixed bitrate
stream.

There was some code in oggseek to bisect search for frames,
which i previously linked to opus seeking, but it was
not reusable by all codecs as the ogg spec says granule to
absolute time is one way only.

New code does bisect search using absolute time only, and
then tries to sync to a specific keyframe (if codec has any),
backward or forward by checking packets.

Bisect and backward searchs are disabled for non FASTSEEK inputs.
In that case, it just behaves like any other player and syncs
to the next keyframe.

DirectShow/OggDS has also been fixed.
parent 546da072
This diff is collapsed.
...@@ -26,6 +26,20 @@ ...@@ -26,6 +26,20 @@
* Definitions of structures and functions used by this plugin * Definitions of structures and functions used by this plugin
*****************************************************************************/ *****************************************************************************/
//#define OGG_DEMUX_DEBUG 1
#ifdef OGG_DEMUX_DEBUG
#define DemuxDebug(code) code
#else
#define DemuxDebug(code)
#endif
/* Some defines from OggDS http://svn.xiph.org/trunk/oggds/ */
#define PACKET_TYPE_HEADER 0x01
#define PACKET_TYPE_BITS 0x07
#define PACKET_LEN_BITS01 0xc0
#define PACKET_LEN_BITS2 0x02
#define PACKET_IS_SYNCPOINT 0x08
typedef struct oggseek_index_entry demux_index_entry_t; typedef struct oggseek_index_entry demux_index_entry_t;
typedef struct logical_stream_s typedef struct logical_stream_s
...@@ -57,6 +71,7 @@ typedef struct logical_stream_s ...@@ -57,6 +71,7 @@ typedef struct logical_stream_s
/* Misc */ /* Misc */
bool b_reinit; bool b_reinit;
bool b_oggds;
int i_granule_shift; int i_granule_shift;
/* Opus has a starting offset in the headers. */ /* Opus has a starting offset in the headers. */
...@@ -65,7 +80,7 @@ typedef struct logical_stream_s ...@@ -65,7 +80,7 @@ typedef struct logical_stream_s
int i_end_trim; int i_end_trim;
/* offset of first keyframe for theora; can be 0 or 1 depending on version number */ /* offset of first keyframe for theora; can be 0 or 1 depending on version number */
int64_t i_keyframe_offset; int8_t i_keyframe_offset;
/* keyframe index for seeking, created as we discover keyframes */ /* keyframe index for seeking, created as we discover keyframes */
demux_index_entry_t *idx; demux_index_entry_t *idx;
...@@ -131,4 +146,6 @@ struct demux_sys_t ...@@ -131,4 +146,6 @@ struct demux_sys_t
/* Length, if available. */ /* Length, if available. */
int64_t i_length; int64_t i_length;
DemuxDebug( bool b_seeked; )
}; };
This diff is collapsed.
...@@ -49,6 +49,16 @@ struct oggseek_index_entry ...@@ -49,6 +49,16 @@ struct oggseek_index_entry
int64_t i_pagepos_end; int64_t i_pagepos_end;
}; };
int64_t Ogg_GetKeyframeGranule ( logical_stream_t *p_stream, int64_t i_granule );
bool Ogg_IsKeyFrame ( logical_stream_t *, ogg_packet * );
int64_t Oggseek_GranuleToAbsTimestamp ( logical_stream_t *p_stream, int64_t i_granule,
bool b_presentation );
bool Oggseek_PacketPCRFixup ( logical_stream_t *p_stream, ogg_page *, ogg_packet * );
int Oggseek_BlindSeektoPosition ( demux_t *, logical_stream_t *, double f, bool );
int Oggseek_SeektoAbsolutetime ( demux_t *, logical_stream_t *, int64_t i_granulepos );
const demux_index_entry_t *OggSeek_IndexAdd ( logical_stream_t *, int64_t, int64_t );
const demux_index_entry_t *oggseek_theora_index_entry_add ( logical_stream_t *, const demux_index_entry_t *oggseek_theora_index_entry_add ( logical_stream_t *,
int64_t i_granule, int64_t i_granule,
int64_t i_pagepos ); int64_t i_pagepos );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment