mpegtsmux: more header clarifications and remove some redundant fields

This commit is contained in:
Mark Nauwelaerts 2012-06-05 18:03:10 +02:00 committed by Sebastian Dröge
parent 38bb55c472
commit 4cc905409e
5 changed files with 67 additions and 31 deletions

View file

@ -253,7 +253,6 @@ tsmux_program_new (TsMux * mux)
program->pgm_number = mux->next_pgm_no++; program->pgm_number = mux->next_pgm_no++;
program->pmt_pid = mux->next_pmt_pid++; program->pmt_pid = mux->next_pmt_pid++;
program->pcr_stream = NULL; program->pcr_stream = NULL;
program->last_pcr = -1;
program->streams = g_array_sized_new (FALSE, TRUE, sizeof (TsMuxStream *), 1); program->streams = g_array_sized_new (FALSE, TRUE, sizeof (TsMuxStream *), 1);
@ -312,7 +311,6 @@ tsmux_program_add_stream (TsMuxProgram * program, TsMuxStream * stream)
g_return_if_fail (program != NULL); g_return_if_fail (program != NULL);
g_return_if_fail (stream != NULL); g_return_if_fail (stream != NULL);
program->nb_streams++;
g_array_append_val (program->streams, stream); g_array_append_val (program->streams, stream);
program->pmt_changed = TRUE; program->pmt_changed = TRUE;
} }
@ -1005,7 +1003,7 @@ tsmux_write_pmt (TsMux * mux, TsMuxProgram * program)
tsmux_put16 (&pos, 0xFCFC); tsmux_put16 (&pos, 0xFCFC);
/* Write out the entries */ /* Write out the entries */
for (i = 0; i < program->nb_streams; i++) { for (i = 0; i < program->streams->len; i++) {
TsMuxStream *stream = g_array_index (program->streams, TsMuxStream *, i); TsMuxStream *stream = g_array_index (program->streams, TsMuxStream *, i);
guint16 es_info_len; guint16 es_info_len;
@ -1043,7 +1041,7 @@ tsmux_write_pmt (TsMux * mux, TsMuxProgram * program)
tsmux_put32 (&pos, crc); tsmux_put32 (&pos, crc);
TS_DEBUG ("PMT for program %d has %d streams, is %u bytes", TS_DEBUG ("PMT for program %d has %d streams, is %u bytes",
program->pgm_number, program->nb_streams, pmt->pi.stream_avail); program->pgm_number, program->streams->len, pmt->pi.stream_avail);
pmt->pi.pid = program->pmt_pid; pmt->pi.pid = program->pmt_pid;
program->pmt_changed = FALSE; program->pmt_changed = FALSE;

View file

@ -111,47 +111,61 @@ struct TsMuxSection {
/* Information for the streams associated with one program */ /* Information for the streams associated with one program */
struct TsMuxProgram { struct TsMuxProgram {
TsMuxSection pmt; TsMuxSection pmt;
/* PMT version */
guint8 pmt_version; guint8 pmt_version;
/* trigger for writing PMT */
gboolean pmt_changed; gboolean pmt_changed;
/* interval between PMT in MPEG PTS clock time */
guint pmt_interval; guint pmt_interval;
/* last time PMT written in MPEG PTS clock time */
gint64 last_pmt_ts; gint64 last_pmt_ts;
guint16 pgm_number; /* program ID for the PAT */ /* program ID for the PAT */
guint16 pmt_pid; /* PID to write the PMT */ guint16 pgm_number;
/* PID to write the PMT */
guint16 pmt_pid;
TsMuxStream *pcr_stream; /* Stream which carries the PCR */ /* stream which carries the PCR */
gint64 last_pcr; TsMuxStream *pcr_stream;
GArray *streams; /* Array of TsMuxStream pointers */ /* programs TsMuxStream's */
guint nb_streams; GArray *streams;
}; };
struct TsMux { struct TsMux {
/* TsMuxStream* array of all streams */
guint nb_streams; guint nb_streams;
GList *streams; /* TsMuxStream* array of all streams */ GList *streams;
/* TsMuxProgram* array of all programs */
guint nb_programs; guint nb_programs;
GList *programs; /* TsMuxProgram* array of all programs */ GList *programs;
guint16 transport_id;
/* next auto-generated misc id */
guint16 next_pgm_no; guint16 next_pgm_no;
guint16 next_pmt_pid; guint16 next_pmt_pid;
guint16 next_stream_pid; guint16 next_stream_pid;
TsMuxSection pat; TsMuxSection pat;
/* PAT transport_stream_id */
guint16 transport_id;
/* PAT version */
guint8 pat_version; guint8 pat_version;
/* trigger writing PAT */
gboolean pat_changed; gboolean pat_changed;
/* interval between PAT in MPEG PTS clock time */
guint pat_interval; guint pat_interval;
/* last time PAT written in MPEG PTS clock time */
gint64 last_pat_ts; gint64 last_pat_ts;
/* temp packet buffer */
guint8 packet_buf[TSMUX_PACKET_LENGTH]; guint8 packet_buf[TSMUX_PACKET_LENGTH];
/* callback to write finished packet */
TsMuxWriteFunc write_func; TsMuxWriteFunc write_func;
void *write_func_data; void *write_func_data;
/* Scratch space for writing ES_info descriptors */ /* scratch space for writing ES_info descriptors */
guint8 es_info_buf[TSMUX_MAX_ES_INFO_LENGTH]; guint8 es_info_buf[TSMUX_MAX_ES_INFO_LENGTH];
gint64 new_pcr; gint64 new_pcr;
}; };

View file

@ -127,18 +127,26 @@ struct TsMuxPacketInfo {
guint16 pid; guint16 pid;
guint32 flags; guint32 flags;
gboolean packet_start_unit_indicator;
/* continuity counter */
guint8 packet_count;
/* payload bytes available
* (including PES header if applicable) */
guint stream_avail;
/* optional PCR */
guint64 pcr; guint64 pcr;
/* following not really actively used */
guint64 opcr; guint64 opcr;
guint8 splice_countdown; guint8 splice_countdown;
guint8 private_data_len; guint8 private_data_len;
guint8 private_data[256]; guint8 private_data[256];
guint8 packet_count; /* continuity counter */
guint stream_avail; /* Number of payload bytes available */
gboolean packet_start_unit_indicator;
}; };
static inline void static inline void

View file

@ -102,8 +102,10 @@ struct TsMuxStreamBuffer
gint64 pts; gint64 pts;
gint64 dts; gint64 dts;
/* data represents random access point */
gboolean random_access; gboolean random_access;
/* user_data for release function */
void *user_data; void *user_data;
}; };
@ -178,8 +180,8 @@ tsmux_stream_new (guint16 pid, TsMuxStreamType stream_type)
break; break;
} }
stream->last_pts = -1; // stream->last_pts = -1;
stream->last_dts = -1; // stream->last_dts = -1;
stream->pcr_ref = 0; stream->pcr_ref = 0;
stream->last_pcr = -1; stream->last_pcr = -1;

View file

@ -149,41 +149,55 @@ enum TsMuxStreamState {
TSMUX_STREAM_STATE_PACKET TSMUX_STREAM_STATE_PACKET
}; };
/* TsMuxStream receives elementary streams for parsing. /* TsMuxStream receives elementary streams for parsing */
* Via the write_bytes() method, it can output a PES stream piecemeal */
struct TsMuxStream { struct TsMuxStream {
TsMuxStreamState state; TsMuxStreamState state;
TsMuxPacketInfo pi; TsMuxPacketInfo pi;
TsMuxStreamType stream_type; TsMuxStreamType stream_type;
guint8 id; /* stream id */
guint8 id_extended; /* extended stream id (13818-1 Amdt 2) */ /* stream_id (13818-1) */
guint8 id;
/* extended stream id (13818-1 Amdt 2) */
guint8 id_extended;
gboolean is_video_stream; gboolean is_video_stream;
/* List of data buffers available for writing out */ /* data available for writing out
* and total sum of sizes */
GList *buffers; GList *buffers;
guint32 bytes_avail; guint32 bytes_avail;
/* Current data buffer being consumed */ /* current data buffer being consumed
* and amount already consumed */
TsMuxStreamBuffer *cur_buffer; TsMuxStreamBuffer *cur_buffer;
guint32 cur_buffer_consumed; guint32 cur_buffer_consumed;
/* helper to release collected buffers */
TsMuxStreamBufferReleaseFunc buffer_release; TsMuxStreamBufferReleaseFunc buffer_release;
/* optional fixed PES size for stream type */
guint16 pes_payload_size; guint16 pes_payload_size;
/* current PES payload size being written */
guint16 cur_pes_payload_size; guint16 cur_pes_payload_size;
/* ... of which already this much written */
guint16 pes_bytes_written; guint16 pes_bytes_written;
/* PTS/DTS to write if the flags in the packet info are set */ /* PTS/DTS to write if the flags in the packet info are set */
/* in MPEG PTS clock time */
gint64 pts; gint64 pts;
gint64 dts; gint64 dts;
gint64 last_pts; /* last ts written, or maybe next one ... ?! */
gint64 last_dts; gint64 last_dts;
gint64 last_pts;
/* count of programs using this as PCR */
gint pcr_ref; gint pcr_ref;
/* last time PCR written */
gint64 last_pcr; gint64 last_pcr;
/* audio parameters for stream
* (used in stream descriptor) */
gint audio_sampling; gint audio_sampling;
gint audio_channels; gint audio_channels;
gint audio_bitrate; gint audio_bitrate;