Add pull mode to mpegpsdemux and report duration reading first and last PTS. Some random cleanups.

This commit is contained in:
Josep Torra 2009-02-02 23:12:07 +01:00
parent 18e2ffa484
commit c8eb591688
4 changed files with 899 additions and 143 deletions

View file

@ -190,6 +190,17 @@
#define MPEG_MUX_RATE_MULT 50 #define MPEG_MUX_RATE_MULT 50
/* sync:4 == 00xx ! pts:3 ! 1 ! pts:15 ! 1 | pts:15 ! 1 */
#define READ_TS(data, target, lost_sync_label) \
if ((*data & 0x01) != 0x01) goto lost_sync_label; \
target = ((guint64) (*data++ & 0x0E)) << 29; \
target |= ((guint64) (*data++ )) << 22; \
if ((*data & 0x01) != 0x01) goto lost_sync_label; \
target |= ((guint64) (*data++ & 0xFE)) << 14; \
target |= ((guint64) (*data++ )) << 7; \
if ((*data & 0x01) != 0x01) goto lost_sync_label; \
target |= ((guint64) (*data++ & 0xFE)) >> 1;
/* some extra GstFlowReturn values used internally */ /* some extra GstFlowReturn values used internally */
#define GST_FLOW_NEED_MORE_DATA -100 #define GST_FLOW_NEED_MORE_DATA -100
#define GST_FLOW_LOST_SYNC -101 #define GST_FLOW_LOST_SYNC -101

File diff suppressed because it is too large Load diff

View file

@ -50,14 +50,12 @@
#include "gstpesfilter.h" #include "gstpesfilter.h"
G_BEGIN_DECLS G_BEGIN_DECLS
#define GST_TYPE_FLUPS_DEMUX (gst_flups_demux_get_type()) #define GST_TYPE_FLUPS_DEMUX (gst_flups_demux_get_type())
#define GST_FLUPS_DEMUX(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_FLUPS_DEMUX,GstFluPSDemux)) #define GST_FLUPS_DEMUX(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_FLUPS_DEMUX,GstFluPSDemux))
#define GST_FLUPS_DEMUX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_FLUPS_DEMUX,GstFluPSDemuxClass)) #define GST_FLUPS_DEMUX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_FLUPS_DEMUX,GstFluPSDemuxClass))
#define GST_FLUPS_DEMUX_GET_CLASS(klass) (G_TYPE_INSTANCE_GET_CLASS((klass),GST_TYPE_FLUPS_DEMUX,GstFluPSDemuxClass)) #define GST_FLUPS_DEMUX_GET_CLASS(klass) (G_TYPE_INSTANCE_GET_CLASS((klass),GST_TYPE_FLUPS_DEMUX,GstFluPSDemuxClass))
#define GST_IS_FLUPS_DEMUX(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_FLUPS_DEMUX)) #define GST_IS_FLUPS_DEMUX(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_FLUPS_DEMUX))
#define GST_IS_FLUPS_DEMUX_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_FLUPS_DEMUX)) #define GST_IS_FLUPS_DEMUX_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_FLUPS_DEMUX))
typedef struct _GstFluPSStream GstFluPSStream; typedef struct _GstFluPSStream GstFluPSStream;
typedef struct _GstFluPSDemux GstFluPSDemux; typedef struct _GstFluPSDemux GstFluPSDemux;
typedef struct _GstFluPSDemuxClass GstFluPSDemuxClass; typedef struct _GstFluPSDemuxClass GstFluPSDemuxClass;
@ -65,76 +63,87 @@ typedef struct _GstFluPSDemuxClass GstFluPSDemuxClass;
#define GST_FLUPS_DEMUX_MAX_STREAMS 256 #define GST_FLUPS_DEMUX_MAX_STREAMS 256
#define GST_FLUPS_DEMUX_MAX_PSM 256 #define GST_FLUPS_DEMUX_MAX_PSM 256
typedef enum { typedef enum
{
GST_FLUPS_DEMUX_SYNC_AUTO = 0, GST_FLUPS_DEMUX_SYNC_AUTO = 0,
GST_FLUPS_DEMUX_SYNC_SCR = 1, GST_FLUPS_DEMUX_SYNC_SCR = 1,
GST_FLUPS_DEMUX_SYNC_DTS = 2 GST_FLUPS_DEMUX_SYNC_DTS = 2
} GstFluPSDemuxSync; } GstFluPSDemuxSync;
typedef enum { typedef enum
{
STATE_FLUPS_DEMUX_NEED_SYNC, STATE_FLUPS_DEMUX_NEED_SYNC,
STATE_FLUPS_DEMUX_SYNCED, STATE_FLUPS_DEMUX_SYNCED,
STATE_FLUPS_DEMUX_NEED_MORE_DATA, STATE_FLUPS_DEMUX_NEED_MORE_DATA,
} GstFluPSDemuxState; } GstFluPSDemuxState;
/* Information associated with a single FluPS stream. */ /* Information associated with a single FluPS stream. */
struct _GstFluPSStream { struct _GstFluPSStream
GstPad * pad; {
GstPad *pad;
gint id; gint id;
gint type; gint type;
gint size_bound; gint size_bound;
gboolean discont; gboolean discont;
gboolean notlinked; gboolean notlinked;
gboolean need_segment; gboolean need_segment;
}; };
struct _GstFluPSDemux { struct _GstFluPSDemux
GstElement parent; {
GstElement parent;
GstPad * sinkpad; GstPad *sinkpad;
gboolean random_access; /* If we operate in pull mode */
GstAdapter * adapter; GstAdapter *adapter;
GstAdapter * rev_adapter; GstAdapter *rev_adapter;
guint64 adapter_offset; guint64 adapter_offset;
guint32 last_sync_code; guint32 last_sync_code;
GstPESFilter filter; GstPESFilter filter;
gint64 mux_rate; gint64 mux_rate;
guint64 first_scr; guint64 first_scr;
guint64 first_dts; guint64 last_scr;
guint64 base_time; guint64 first_dts;
guint64 current_scr; guint64 base_time;
guint64 next_scr; guint64 current_scr;
guint64 bytes_since_scr; guint64 next_scr;
gint64 scr_adjust; guint64 bytes_since_scr;
guint64 scr_rate_n; gint64 scr_adjust;
guint64 scr_rate_d; guint64 scr_rate_n;
guint64 first_scr_offset; guint64 scr_rate_d;
guint64 last_scr_offset; guint64 first_scr_offset;
guint64 last_scr_offset;
gint16 psm[GST_FLUPS_DEMUX_MAX_PSM]; guint64 first_pts;
guint64 last_pts;
GstSegment sink_segment; gint16 psm[GST_FLUPS_DEMUX_MAX_PSM];
GstSegment src_segment;
GstSegment sink_segment;
GstSegment src_segment;
gboolean is_segment_open;
/* stream output */ /* stream output */
GstFluPSStream * current_stream; GstFluPSStream *current_stream;
guint64 next_pts; guint64 next_pts;
guint64 next_dts; guint64 next_dts;
GstFluPSStream ** streams; GstFluPSStream **streams;
gboolean need_no_more_pads; gboolean need_no_more_pads;
/* Indicates an MPEG-2 stream */ /* Indicates an MPEG-2 stream */
gboolean is_mpeg2_pack; gboolean is_mpeg2_pack;
/* Language codes event is stored when a dvd-lang-codes /* Language codes event is stored when a dvd-lang-codes
* custom event arrives from upstream */ * custom event arrives from upstream */
GstEvent * lang_codes; GstEvent *lang_codes;
}; };
struct _GstFluPSDemuxClass { struct _GstFluPSDemuxClass
{
GstElementClass parent_class; GstElementClass parent_class;
GstPadTemplate *sink_template; GstPadTemplate *sink_template;
@ -143,10 +152,9 @@ struct _GstFluPSDemuxClass {
GstPadTemplate *private_template; GstPadTemplate *private_template;
}; };
GType gst_flups_demux_get_type (void); GType gst_flups_demux_get_type (void);
gboolean gst_flups_demux_plugin_init (GstPlugin *plugin); gboolean gst_flups_demux_plugin_init (GstPlugin * plugin);
G_END_DECLS G_END_DECLS
#endif /* __GST_FLUPS_DEMUX_H__ */ #endif /* __GST_FLUPS_DEMUX_H__ */

View file

@ -97,17 +97,6 @@ gst_pes_filter_set_callbacks (GstPESFilter * filter,
filter->user_data = user_data; filter->user_data = user_data;
} }
/* sync:4 == 00xx ! pts:3 ! 1 ! pts:15 ! 1 | pts:15 ! 1 */
#define READ_TS(data, target, lost_sync_label) \
if ((*data & 0x01) != 0x01) goto lost_sync_label; \
target = ((guint64) (*data++ & 0x0E)) << 29; \
target |= ((guint64) (*data++ )) << 22; \
if ((*data & 0x01) != 0x01) goto lost_sync_label; \
target |= ((guint64) (*data++ & 0xFE)) << 14; \
target |= ((guint64) (*data++ )) << 7; \
if ((*data & 0x01) != 0x01) goto lost_sync_label; \
target |= ((guint64) (*data++ & 0xFE)) >> 1;
static gboolean static gboolean
gst_pes_filter_is_sync (guint32 sync) gst_pes_filter_is_sync (guint32 sync)
{ {