... add some debugging symbols in the mean time.
/* activate new pmt */
if (program->pmt_info)
gst_structure_free (program->pmt_info);
+
program->pmt_info = gst_structure_copy (pmt_info);
program->pmt_pid = pmt_pid;
program->pcr_pid = pcr_pid;
if (MPEGTS_BIT_IS_SET (base->known_psi, packet->pid))
retval = TRUE;
- /* check is it is a pes pid */
+ /* check if it is a pes pid */
if (MPEGTS_BIT_IS_SET (base->is_pes, packet->pid))
return FALSE;
{
MpegTSBaseProgram *program, *old_program;
guint program_number;
- gboolean deactivate_old_program = FALSE;
/* FIXME : not so sure this is valid anymore */
if (G_UNLIKELY (base->seen_pat == FALSE)) {
program = mpegts_base_new_program (base, program_number, pmt_pid);
g_hash_table_insert (base->programs,
GINT_TO_POINTER (program_number), program);
- deactivate_old_program = TRUE;
+
+ /* Desactivate the old program */
+ mpegts_base_deactivate_program (base, old_program);
+ mpegts_base_free_program (old_program);
} else
program = old_program;
/* First activate program */
mpegts_base_activate_program (base, program, pmt_pid, pmt_info);
- if (deactivate_old_program) {
- /* deactivate old pmt */ ;
- mpegts_base_deactivate_program (base, old_program);
- mpegts_base_free_program (old_program);
- }
-
/* if (program->pmt_info) */
/* gst_structure_free (program->pmt_info); */
/* program->pmt_info = NULL; */
}
mpegts_packetizer_push (base->packetizer, buf);
- while (((pret =
- mpegts_packetizer_next_packet (base->packetizer,
+ while (((pret = mpegts_packetizer_next_packet (base->packetizer,
&packet)) != PACKET_NEED_MORE) && res == GST_FLOW_OK) {
if (G_UNLIKELY (pret == PACKET_BAD))
/* bad header, skip the packet */
/* Find initial sync point */
for (i = 0; i < 10; i++) {
- GST_DEBUG ("Grabbing %d => %d",
- i * 50 * MPEGTS_MAX_PACKETSIZE, 50 * MPEGTS_MAX_PACKETSIZE);
+ GST_DEBUG ("Grabbing %d => %d", i * 50 * MPEGTS_MAX_PACKETSIZE,
+ 50 * MPEGTS_MAX_PACKETSIZE);
+
ret = gst_pad_pull_range (base->sinkpad, i * 50 * MPEGTS_MAX_PACKETSIZE,
50 * MPEGTS_MAX_PACKETSIZE, &buf);
if (G_UNLIKELY (ret != GST_FLOW_OK))
/*
- * mpegtspacketizer.c -
+ * mpegtspacketizer.c -
* Copyright (C) 2007, 2008 Alessandro Decina, Zaheer Merali
- *
+ *
* Authors:
* Zaheer Merali <zaheerabbas at merali dot org>
* Alessandro Decina <alessandro@nnva.org>
#define MAX_CONTINUITY 15
#define VERSION_NUMBER_UNSET 255
#define TABLE_ID_UNSET 0xFF
+#define PACKET_SYNC_BYTE 0x47
static gint
mpegts_packetizer_stream_subtable_compare (gconstpointer a, gconstpointer b)
/* include length */
desc = g_string_new_len ((gchar *) data - 2, length + 2);
data += length;
- /* G_TYPE_GSTING is a GBoxed type and is used so properly marshalled from python */
+ /* G_TYPE_GSTRING is a GBoxed type and is used so properly marshalled from python */
g_value_init (&value, G_TYPE_GSTRING);
g_value_take_boxed (&value, desc);
g_value_array_append (descriptors, &value);
program_number = GST_READ_UINT16_BE (data);
data += 2;
+ GST_DEBUG ("Parsing %d Program Map Table", program_number);
+
tmp = *data++;
section->version_number = (tmp >> 1) & 0x1F;
section->current_next_indicator = tmp & 0x01;
* bytes) plus the CRC */
while (data <= end - 4 - 5) {
stream_type = *data++;
+ GST_DEBUG ("Stream type 0x%02x found", stream_type);
pid = GST_READ_UINT16_BE (data) & 0x1FFF;
data += 2;
/* find first sync byte */
pos = -1;
for (i = 0; i < MPEGTS_MAX_PACKETSIZE; i++) {
- if (dest[i] == 0x47) {
+ if (dest[i] == PACKET_SYNC_BYTE) {
for (j = 0; j < 4; j++) {
guint packetsize = psizes[j];
/* check each of the packet size possibilities in turn */
- if (dest[i] == 0x47 && dest[i + packetsize] == 0x47 &&
- dest[i + packetsize * 2] == 0x47 &&
- dest[i + packetsize * 3] == 0x47) {
+ if (dest[i] == PACKET_SYNC_BYTE
+ && dest[i + packetsize] == PACKET_SYNC_BYTE
+ && dest[i + packetsize * 2] == PACKET_SYNC_BYTE
+ && dest[i + packetsize * 3] == PACKET_SYNC_BYTE) {
packetizer->know_packet_size = TRUE;
packetizer->packet_size = packetsize;
packetizer->caps = gst_caps_new_simple ("video/mpegts",
GST_DEBUG ("Flushing out %d bytes", pos);
gst_adapter_flush (packetizer->adapter, pos);
packetizer->offset += pos;
- } else if (!packetizer->know_packet_size) {
- /* drop invalid data and move to the next possible packets */
- gst_adapter_flush (packetizer->adapter, MPEGTS_MAX_PACKETSIZE);
}
+ } else {
+ /* drop invalid data and move to the next possible packets */
+ GST_DEBUG ("Could not determine packet size");
}
return packetizer->know_packet_size;
while ((avail = packetizer->adapter->size) >= packetizer->packet_size) {
packet->buffer = gst_adapter_take_buffer (packetizer->adapter,
packetizer->packet_size);
+
/* M2TS packets don't start with the sync byte, all other variants do */
if (packetizer->packet_size == MPEGTS_M2TS_PACKETSIZE) {
packet->data_start = GST_BUFFER_DATA (packet->buffer) + 4;
sub_buf = gst_buffer_create_sub (packet->buffer,
data - GST_BUFFER_DATA (packet->buffer), packet->data_end - data);
-
stream = packetizer->streams[packet->pid];
if (stream == NULL) {
stream = mpegts_packetizer_stream_new ();
if (packet->payload_unit_start_indicator) {
table_id = *data++;
- /* subtable_extension should be read from 4th and 5th bytes only if
+ /* subtable_extension should be read from 4th and 5th bytes only if
* section_syntax_indicator is 1 */
if ((data[0] & 0x80) == 0)
subtable_extension = 0;
* @is_multibyte: Location where information whether it's a multibyte encoding
* or not is stored
* @returns: Name of encoding or NULL of encoding could not be detected.
- *
+ *
* The returned string should be freed with g_free () when no longer needed.
*/
static gchar *
#include "payload_parsers.h"
#include "pesparse.h"
-/*
+/*
* tsdemux
*
* See TODO for explanations on improvements needed
#define TABLE_ID_UNSET 0xFF
/* Size of the pendingbuffers array. */
-#define TS_MAX_PENDING_BUFFERS 256
+#define TS_MAX_PENDING_BUFFERS 256
#define PCR_WRAP_SIZE_128KBPS (((gint64)1490)*(1024*1024))
/* small PCR for wrap detection */
MpegTSPacketizerPacket packet;
MpegTSPacketizerPacketReturn pret;
- while ((!done)
- && ((pret =
- mpegts_packetizer_next_packet (base->packetizer,
- &packet)) != PACKET_NEED_MORE)) {
+ while ((!done) &&
+ ((pret = mpegts_packetizer_next_packet (base->packetizer, &packet))
+ != PACKET_NEED_MORE)) {
+
if (G_UNLIKELY (pret == PACKET_BAD))
/* bad header, skip the packet */
goto next;
if (packet.payload != NULL && mpegts_base_is_psi (base, &packet)) {
MpegTSPacketizerSection section;
- based =
- mpegts_packetizer_push_section (base->packetizer, &packet, §ion);
+ based = mpegts_packetizer_push_section (base->packetizer, &packet,
+ §ion);
+
if (G_UNLIKELY (!based))
/* bad section data */
goto next;
GstTSDemux *demux = GST_TS_DEMUX (base);
guint16 pcr_pid = 0;
- while ((!done)
- && ((pret =
- mpegts_packetizer_next_packet (base->packetizer,
- &packet)) != PACKET_NEED_MORE)) {
+ while ((!done) &&
+ ((pret = mpegts_packetizer_next_packet (base->packetizer, &packet))
+ != PACKET_NEED_MORE)) {
if (G_UNLIKELY (pret == PACKET_BAD))
/* bad header, skip the packet */
goto next;
if (packet.payload != NULL && mpegts_base_is_psi (base, &packet)) {
MpegTSPacketizerSection section;
- based =
- mpegts_packetizer_push_section (base->packetizer, &packet, §ion);
+ based = mpegts_packetizer_push_section (base->packetizer, &packet,
+ §ion);
+
if (G_UNLIKELY (!based))
/* bad section data */
goto next;
GST_DEBUG ("Scanning for timestamps");
- /* Flush what remained from before */
- mpegts_packetizer_clear (base->packetizer);
+ /* Start scanning from now PAT offset */
- /* Start scanning from know PAT offset */
while (!done) {
- ret =
- gst_pad_pull_range (base->sinkpad, i * 50 * MPEGTS_MAX_PACKETSIZE,
+ ret = gst_pad_pull_range (base->sinkpad, i * 50 * MPEGTS_MAX_PACKETSIZE,
50 * MPEGTS_MAX_PACKETSIZE, &buf);
+
if (ret != GST_FLOW_OK)
goto beach;
+
mpegts_packetizer_push (base->packetizer, buf);
done = process_section (base);
i++;
done = FALSE;
i = 1;
-
*offset = base->seek_offset;
/* Search for the first PCRs */
}
mpegts_packetizer_clear (base->packetizer);
- /* Remove current program so we ensure looking for a PAT when scanning the
+ /* Remove current program so we ensure looking for a PAT when scanning
* for the final PCR */
gst_structure_free (base->pat);
base->pat = NULL;
if (G_UNLIKELY (!gst_pad_query_peer_duration (base->sinkpad, &format,
&total_bytes) || format != GST_FORMAT_BYTES)) {
GST_WARNING_OBJECT (base, "Couldn't get upstream size in bytes");
- ret = GST_FLOW_ERROR;
mpegts_packetizer_clear (base->packetizer);
- return ret;
+
+ return GST_FLOW_ERROR;
}
GST_DEBUG ("Upstream is %" G_GINT64_FORMAT " bytes", total_bytes);
GST_DEBUG ("Scanning for last sync point between:%" G_GINT64_FORMAT
" and the end:%" G_GINT64_FORMAT, scan_offset, total_bytes);
+
while ((!done) && (scan_offset < total_bytes)) {
- ret =
- gst_pad_pull_range (base->sinkpad,
- scan_offset, 50 * MPEGTS_MAX_PACKETSIZE, &buf);
+ ret = gst_pad_pull_range (base->sinkpad, scan_offset,
+ 50 * MPEGTS_MAX_PACKETSIZE, &buf);
+
if (ret != GST_FLOW_OK)
goto beach;
mpegts_packetizer_clear (base->packetizer);
- GST_DEBUG ("Searching PCR");
- ret =
- process_pcr (base, scan_offset - 50 * MPEGTS_MAX_PACKETSIZE, &final, 10,
- FALSE);
+ ret = process_pcr (base, scan_offset - 50 * MPEGTS_MAX_PACKETSIZE, &final,
+ 10, FALSE);
if (ret != GST_FLOW_OK) {
GST_DEBUG ("Problem getting last PCRs");
gst_segment_set_duration (&demux->segment, GST_FORMAT_TIME,
demux->last_pcr.gsttime - demux->first_pcr.gsttime);
demux->duration = demux->last_pcr.gsttime - demux->first_pcr.gsttime;
+
GST_DEBUG ("Done, duration:%" GST_TIME_FORMAT,
GST_TIME_ARGS (demux->duration));
for (i = 0; (i < 20) && (nbpcr < numpcr); i++) {
guint offset, size;
- ret =
- gst_pad_pull_range (base->sinkpad,
+ ret = gst_pad_pull_range (base->sinkpad,
initoff + i * 500 * base->packetsize, 500 * base->packetsize, &buf);
if (G_UNLIKELY (ret != GST_FLOW_OK))