gst/mpegtsparse/: pat-info is now a signal not a GObject property that gets notified.

Original commit message from CVS:
patch by: Alessandro Decina
* gst/mpegtsparse/mpegtspacketizer.c:
* gst/mpegtsparse/mpegtspacketizer.h:
* gst/mpegtsparse/mpegtsparse.c:
* gst/mpegtsparse/mpegtsparse.h:
pat-info is now a signal not a GObject property that
gets notified.
pat-info, pmt-info now instead of passing a GObject as
a parameter, pass a GstStructure.
New signals: nit-info, sdt-info, eit-info for DVB SI information
* sys/dvb/camconditionalaccess.c:
* sys/dvb/camconditionalaccess.h:
* sys/dvb/camdevice.c:
* sys/dvb/camdevice.h:
* sys/dvb/camswclient.c:
* sys/dvb/camswclient.h:
* sys/dvb/camutils.c:
* sys/dvb/camutils.h:
Cam code now uses the pmt GstStructure passed from mpegtsparse
signals rather than the GObject.
* sys/dvb/dvbbasebin.c:
Use new signals in mpegtsparse and use GstStructures as per
mpegtsparse's modified API.
This commit is contained in:
Alessandro Decina 2007-11-23 17:53:37 +00:00 committed by Zaheer Abbas Merali
parent 1cb35c7574
commit 50841996be
14 changed files with 898 additions and 254 deletions

View file

@ -1,3 +1,30 @@
2007-11-23 Zaheer Abbas Merali <zaheerabbas at merali dot org>
patch by: Alessandro Decina
* gst/mpegtsparse/mpegtspacketizer.c:
* gst/mpegtsparse/mpegtspacketizer.h:
* gst/mpegtsparse/mpegtsparse.c:
* gst/mpegtsparse/mpegtsparse.h:
pat-info is now a signal not a GObject property that
gets notified.
pat-info, pmt-info now instead of passing a GObject as
a parameter, pass a GstStructure.
New signals: nit-info, sdt-info, eit-info for DVB SI information
* sys/dvb/camconditionalaccess.c:
* sys/dvb/camconditionalaccess.h:
* sys/dvb/camdevice.c:
* sys/dvb/camdevice.h:
* sys/dvb/camswclient.c:
* sys/dvb/camswclient.h:
* sys/dvb/camutils.c:
* sys/dvb/camutils.h:
Cam code now uses the pmt GstStructure passed from mpegtsparse
signals rather than the GObject.
* sys/dvb/dvbbasebin.c:
Use new signals in mpegtsparse and use GstStructures as per
mpegtsparse's modified API.
2007-11-23 Edgard Lima <edgard.lima@indt.org.br>
* ext/metadata/Makefile.am:

View file

@ -22,8 +22,6 @@
*/
#include "mpegtspacketizer.h"
#include "flutspatinfo.h"
#include "flutspmtinfo.h"
GST_DEBUG_CATEGORY_STATIC (mpegts_packetizer_debug);
#define GST_CAT_DEFAULT mpegts_packetizer_debug
@ -139,7 +137,8 @@ mpegts_packetizer_parse_adaptation_field_control (MpegTSPacketizer * packetizer,
{
guint8 length;
length = *packet->data++;
length = *packet->data;
packet->data += 1;
if (packet->adaptation_field_control == 0x02) {
/* no payload, adaptation field of 183 bytes */
@ -154,8 +153,9 @@ mpegts_packetizer_parse_adaptation_field_control (MpegTSPacketizer * packetizer,
/* skip the adaptation field body for now */
if (packet->data + length > packet->data_end) {
GST_DEBUG ("PID %d afc length overflows the buffer %d",
packet->pid, length);
GST_DEBUG ("PID %d afc length %d overflows the buffer current %d max %d",
packet->pid, length, packet->data - packet->data_start,
packet->data_end - packet->data_start);
return FALSE;
}
@ -178,7 +178,7 @@ mpegts_packetizer_parse_packet (MpegTSPacketizer * packetizer,
packet->pid = GST_READ_UINT16_BE (data) & 0x1FFF;
data += 2;
packet->adaptation_field_control = *data >> 4 & 0x03;
packet->adaptation_field_control = (*data >> 4) & 0x03;
packet->continuity_counter = *data & 0x0F;
data += 1;
@ -236,21 +236,66 @@ not_applicable:
return TRUE;
}
GValueArray *
static gboolean
mpegts_packetizer_parse_descriptors (MpegTSPacketizer * packetizer,
guint8 ** buffer, guint8 * buffer_end, GValueArray * descriptors)
{
guint8 tag, length;
guint8 *data;
GValue value = { 0 };
GString *desc;
data = *buffer;
while (data < buffer_end) {
tag = *data++;
length = *data++;
if (data + length > buffer_end) {
GST_WARNING ("invalid descriptor length %d now at %d max %d",
length, data - *buffer, buffer_end - *buffer);
goto error;
}
/* include tag and length */
desc = g_string_new_len ((gchar *) data - 2, length + 2);
data += length;
g_value_init (&value, G_TYPE_GSTRING);
g_value_take_boxed (&value, desc);
g_value_array_append (descriptors, &value);
g_value_unset (&value);
}
if (data != buffer_end) {
GST_WARNING ("descriptors size %d expected %d",
data - *buffer, buffer_end - *buffer);
goto error;
}
*buffer = data;
return TRUE;
error:
return FALSE;
}
GstStructure *
mpegts_packetizer_parse_pat (MpegTSPacketizer * packetizer,
MpegTSPacketizerSection * section)
{
GstStructure *pat_info = NULL;
guint8 *data, *end;
guint16 transport_stream_id;
guint transport_stream_id;
guint8 tmp;
guint program_number;
guint16 pmt_pid;
MpegTSPatInfo *info;
GValueArray *pat;
guint pmt_pid;
GValue entries = { 0 };
GValue value = { 0 };
GstStructure *entry = NULL;
gchar *struct_name;
data = GST_BUFFER_DATA (section->buffer);
pat = g_value_array_new (0);
section->table_id = *data++;
section->section_length = GST_READ_UINT16_BE (data) & 0x0FFF;
@ -266,6 +311,9 @@ mpegts_packetizer_parse_pat (MpegTSPacketizer * packetizer,
/* skip section_number and last_section_number */
data += 2;
pat_info = gst_structure_new ("pat",
"transport-stream-id", G_TYPE_UINT, transport_stream_id, NULL);
g_value_init (&entries, GST_TYPE_LIST);
/* stop at the CRC */
end = GST_BUFFER_DATA (section->buffer) + GST_BUFFER_SIZE (section->buffer);
while (data < end - 4) {
@ -275,40 +323,50 @@ mpegts_packetizer_parse_pat (MpegTSPacketizer * packetizer,
pmt_pid = GST_READ_UINT16_BE (data) & 0x1FFF;
data += 2;
info = mpegts_pat_info_new (program_number, pmt_pid);
struct_name = g_strdup_printf ("program-%d", program_number);
entry = gst_structure_new (struct_name,
"program-number", G_TYPE_UINT, program_number,
"pid", G_TYPE_UINT, pmt_pid, NULL);
g_free (struct_name);
g_value_init (&value, G_TYPE_OBJECT);
g_value_take_object (&value, info);
g_value_array_append (pat, &value);
g_value_init (&value, GST_TYPE_STRUCTURE);
g_value_take_boxed (&value, entry);
gst_value_list_append_value (&entries, &value);
g_value_unset (&value);
}
gst_structure_set_value (pat_info, "programs", &entries);
g_value_unset (&entries);
if (data != end - 4) {
/* FIXME: check the CRC before parsing the packet */
GST_ERROR ("at the end of PAT data != end - 4");
g_value_array_free (pat);
gst_structure_free (pat_info);
return NULL;
}
return pat;
return pat_info;
}
GObject *
GstStructure *
mpegts_packetizer_parse_pmt (MpegTSPacketizer * packetizer,
MpegTSPacketizerSection * section)
{
MpegTSPmtInfo *pmt = NULL;
MpegTSPmtStreamInfo *stream_info;
GstStructure *pmt = NULL;
guint8 *data, *end;
guint16 program_number;
guint8 tmp;
guint16 pcr_pid;
guint pcr_pid;
guint program_info_length;
guint8 tag, length;
guint8 stream_type;
guint16 pid;
guint stream_info_length;
GValueArray *descriptors;
GValue stream_value = { 0 };
GValue programs = { 0 };
GstStructure *stream_info = NULL;
gchar *struct_name;
/* fixed header + CRC == 16 */
if (GST_BUFFER_SIZE (section->buffer) < 16) {
@ -340,35 +398,35 @@ mpegts_packetizer_parse_pmt (MpegTSPacketizer * packetizer,
program_info_length = GST_READ_UINT16_BE (data) & 0x0FFF;
data += 2;
/* check that the buffer is large enough to contain at least
* program_info_length bytes + CRC */
if (data + program_info_length + 4 > end) {
GST_WARNING ("PID %d invalid program info length %d "
"left %d", section->pid, program_info_length, end - data);
goto error;
}
struct_name = g_strdup_printf ("program-%d", program_number);
pmt = gst_structure_new (struct_name,
"program-number", G_TYPE_UINT, program_number,
"pcr-pid", G_TYPE_UINT, pcr_pid,
"version-number", G_TYPE_UINT, section->version_number, NULL);
g_free (struct_name);
pmt = mpegts_pmt_info_new (program_number, pcr_pid, section->version_number);
/* parse program level descriptors */
while (program_info_length > 0) {
tag = *data++;
length = *data++;
program_info_length -= 2;
if (length > program_info_length) {
GST_WARNING ("PID %d invalid descriptor length %d left %d",
section->pid, length, program_info_length);
if (program_info_length) {
/* check that the buffer is large enough to contain at least
* program_info_length bytes + CRC */
if (data + program_info_length + 4 > end) {
GST_WARNING ("PID %d invalid program info length %d "
"left %d", section->pid, program_info_length, end - data);
goto error;
}
mpegts_pmt_info_add_descriptor (pmt, (const gchar *) data - 2, 2 + length);
data += length;
program_info_length -= length;
descriptors = g_value_array_new (0);
if (!mpegts_packetizer_parse_descriptors (packetizer,
&data, data + program_info_length, descriptors)) {
g_value_array_free (descriptors);
goto error;
}
gst_structure_set (pmt, "descriptors", G_TYPE_VALUE_ARRAY, descriptors,
NULL);
g_value_array_free (descriptors);
}
g_assert (program_info_length == 0);
g_value_init (&programs, GST_TYPE_LIST);
/* parse entries, cycle until there's space for another entry (at least 5
* bytes) plus the CRC */
while (data <= end - 4 - 5) {
@ -383,45 +441,507 @@ mpegts_packetizer_parse_pmt (MpegTSPacketizer * packetizer,
if (data + stream_info_length + 4 > end) {
GST_WARNING ("PID %d invalid stream info length %d "
"left %d", section->pid, stream_info_length, end - data);
g_value_unset (&programs);
goto error;
}
GST_INFO ("PMT PID %d program_number %d pid %d",
section->pid, program_number, pid);
struct_name = g_strdup_printf ("pid-%d", pid);
stream_info = gst_structure_new (struct_name,
"pid", G_TYPE_UINT, pid, "stream-type", G_TYPE_UINT, stream_type, NULL);
g_free (struct_name);
stream_info = mpegts_pmt_stream_info_new (pid, stream_type);
/* parse stream level descriptors */
while (stream_info_length > 0) {
tag = *data++;
length = *data++;
stream_info_length -= 2;
if (length > stream_info_length) {
GST_WARNING ("PID %d invalid descriptor length %d left %d",
section->pid, length, stream_info_length);
g_object_unref (stream_info);
if (stream_info_length) {
descriptors = g_value_array_new (0);
if (!mpegts_packetizer_parse_descriptors (packetizer,
&data, data + stream_info_length, descriptors)) {
g_value_unset (&programs);
gst_structure_free (stream_info);
g_value_array_free (descriptors);
goto error;
}
mpegts_pmt_stream_info_add_descriptor (stream_info,
(const gchar *) data - 2, 2 + length);
data += length;
stream_info_length -= length;
gst_structure_set (stream_info,
"descriptors", G_TYPE_VALUE_ARRAY, descriptors, NULL);
g_value_array_free (descriptors);
}
/* adds a ref to stream_info */
mpegts_pmt_info_add_stream (pmt, stream_info);
g_object_unref (stream_info);
g_value_init (&stream_value, GST_TYPE_STRUCTURE);
g_value_take_boxed (&stream_value, stream_info);
gst_value_list_append_value (&programs, &stream_value);
g_value_unset (&stream_value);
}
gst_structure_set_value (pmt, "streams", &programs);
g_value_unset (&programs);
g_assert (data == end - 4);
return G_OBJECT (pmt);
return pmt;
error:
if (pmt)
g_object_unref (pmt);
gst_structure_free (pmt);
return NULL;
}
GstStructure *
mpegts_packetizer_parse_nit (MpegTSPacketizer * packetizer,
MpegTSPacketizerSection * section)
{
GstStructure *nit = NULL, *transport = NULL;
guint8 *data, *end, *entry_begin;
guint16 network_id, transport_stream_id, original_network_id;
guint tmp;
guint16 descriptors_loop_length, transport_stream_loop_length;
GValue transports = { 0 };
GValue transport_value = { 0 };
GValueArray *descriptors = NULL;
gchar *dbg_str;
/* fixed header + CRC == 16 */
if (GST_BUFFER_SIZE (section->buffer) < 23) {
GST_WARNING ("PID %d invalid NIT size %d",
section->pid, section->section_length);
goto error;
}
data = GST_BUFFER_DATA (section->buffer);
end = data + GST_BUFFER_SIZE (section->buffer);
section->table_id = *data++;
section->section_length = GST_READ_UINT16_BE (data) & 0x0FFF;
data += 2;
if (data + section->section_length != end) {
GST_WARNING ("PID %d invalid NIT section length %d expected %d",
section->pid, section->section_length, end - data);
goto error;
}
network_id = GST_READ_UINT16_BE (data);
data += 2;
tmp = *data++;
section->version_number = (tmp >> 1) & 0x1F;
section->current_next_indicator = tmp & 0x01;
/* skip section_number and last_section_number */
data += 2;
descriptors_loop_length = GST_READ_UINT16_BE (data) & 0x0FFF;
data += 2;
nit = gst_structure_new ("nit",
"network-id", G_TYPE_UINT, network_id,
"version-number", G_TYPE_UINT, section->version_number,
"current-next-indicator", G_TYPE_UINT, section->current_next_indicator,
NULL);
/* see if the buffer is large enough */
if (descriptors_loop_length) {
if (data + descriptors_loop_length > end - 4) {
GST_WARNING ("PID %d invalid NIT descriptors loop length %d",
section->pid, descriptors_loop_length);
gst_structure_free (nit);
goto error;
}
descriptors = g_value_array_new (0);
if (!mpegts_packetizer_parse_descriptors (packetizer,
&data, data + descriptors_loop_length, descriptors)) {
gst_structure_free (nit);
g_value_array_free (descriptors);
goto error;
}
gst_structure_set (nit, "descriptors", G_TYPE_VALUE_ARRAY, descriptors,
NULL);
g_value_array_free (descriptors);
}
transport_stream_loop_length = GST_READ_UINT16_BE (data) & 0x0FFF;
data += 2;
g_value_init (&transports, GST_TYPE_LIST);
/* read up to the CRC */
while (transport_stream_loop_length - 4 > 0) {
gchar *transport_name;
entry_begin = data;
if (transport_stream_loop_length < 10) {
/* each entry must be at least 6 bytes (+ 4bytes CRC) */
GST_WARNING ("PID %d invalid NIT entry size %d",
section->pid, transport_stream_loop_length);
goto error;
}
transport_stream_id = GST_READ_UINT16_BE (data);
data += 2;
original_network_id = GST_READ_UINT16_BE (data);
data += 2;
descriptors_loop_length = GST_READ_UINT16_BE (data) & 0x0FFF;
data += 2;
transport_name = g_strdup_printf ("transport-%d", transport_stream_id);
transport = gst_structure_new (transport_name,
"transport-stream-id", G_TYPE_UINT, transport_stream_id,
"original-network-id", G_TYPE_UINT, original_network_id, NULL);
g_free (transport_name);
if (descriptors_loop_length) {
if (data + descriptors_loop_length > end - 4) {
GST_WARNING ("PID %d invalid NIT entry %d descriptors loop length %d",
section->pid, transport_stream_id, descriptors_loop_length);
gst_structure_free (transport);
goto error;
}
descriptors = g_value_array_new (0);
if (!mpegts_packetizer_parse_descriptors (packetizer,
&data, data + descriptors_loop_length, descriptors)) {
gst_structure_free (transport);
g_value_array_free (descriptors);
goto error;
}
gst_structure_set (transport, "descriptors", G_TYPE_VALUE_ARRAY,
descriptors, NULL);
g_value_array_free (descriptors);
}
g_value_init (&transport_value, GST_TYPE_STRUCTURE);
g_value_take_boxed (&transport_value, transport);
gst_value_list_append_value (&transports, &transport_value);
g_value_unset (&transport_value);
transport_stream_loop_length -= data - entry_begin;
}
if (data != end - 4) {
GST_WARNING ("PID %d invalid NIT parsed %d length %d",
section->pid, data - GST_BUFFER_DATA (section->buffer),
GST_BUFFER_SIZE (section->buffer));
goto error;
}
gst_structure_set_value (nit, "transports", &transports);
g_value_unset (&transports);
dbg_str = gst_structure_to_string (nit);
GST_DEBUG ("NIT %s", dbg_str);
g_free (dbg_str);
return nit;
error:
if (nit)
gst_structure_free (nit);
if (GST_VALUE_HOLDS_LIST (&transports))
g_value_unset (&transports);
return NULL;
}
GstStructure *
mpegts_packetizer_parse_sdt (MpegTSPacketizer * packetizer,
MpegTSPacketizerSection * section)
{
GstStructure *sdt = NULL, *service = NULL;
guint8 *data, *end, *entry_begin;
guint16 transport_stream_id, original_network_id, service_id;
guint tmp;
guint sdt_info_length;
gboolean EIT_schedule, EIT_present_following;
guint8 running_status;
gboolean scrambled;
guint descriptors_loop_length;
GValue services = { 0 };
GValueArray *descriptors = NULL;
GValue service_value = { 0 };
gchar *dbg_str;
/* fixed header + CRC == 16 */
if (GST_BUFFER_SIZE (section->buffer) < 14) {
GST_WARNING ("PID %d invalid SDT size %d",
section->pid, section->section_length);
goto error;
}
data = GST_BUFFER_DATA (section->buffer);
end = data + GST_BUFFER_SIZE (section->buffer);
section->table_id = *data++;
section->section_length = GST_READ_UINT16_BE (data) & 0x0FFF;
data += 2;
if (data + section->section_length != end) {
GST_WARNING ("PID %d invalid SDT section length %d expected %d",
section->pid, section->section_length, end - data);
goto error;
}
transport_stream_id = GST_READ_UINT16_BE (data);
data += 2;
tmp = *data++;
section->version_number = (tmp >> 1) & 0x1F;
section->current_next_indicator = tmp & 0x01;
/* skip section_number and last_section_number */
data += 2;
original_network_id = GST_READ_UINT16_BE (data);
data += 2;
/* skip reserved byte */
data += 1;
sdt = gst_structure_new ("sdt",
"transport-stream-id", G_TYPE_UINT, transport_stream_id,
"version-number", G_TYPE_UINT, section->version_number,
"current-next-indicator", G_TYPE_UINT, section->current_next_indicator,
"original-network-id", G_TYPE_UINT, original_network_id, NULL);
sdt_info_length = section->section_length - 8;
g_value_init (&services, GST_TYPE_LIST);
/* read up to the CRC */
while (sdt_info_length - 4 > 0) {
gchar *service_name;
entry_begin = data;
if (sdt_info_length < 9) {
/* each entry must be at least 5 bytes (+4 bytes for the CRC) */
GST_WARNING ("PID %d invalid SDT entry size %d",
section->pid, sdt_info_length);
goto error;
}
service_id = GST_READ_UINT16_BE (data);
data += 2;
/* reserved */
data += 1;
tmp = GST_READ_UINT16_BE (data);
data += 2;
EIT_schedule = (tmp >> 15);
EIT_present_following = (tmp >> 14) & 0x01;
running_status = (tmp >> 5) & 0x03;
scrambled = (tmp >> 4) & 0x01;
descriptors_loop_length = tmp & 0x0FFF;
service_name = g_strdup_printf ("service-%d", service_id);
service = gst_structure_new (service_name, NULL);
g_free (service_name);
if (descriptors_loop_length) {
if (data + descriptors_loop_length > end - 4) {
GST_WARNING ("PID %d invalid SDT entry %d descriptors loop length %d",
section->pid, service_id, descriptors_loop_length);
gst_structure_free (service);
goto error;
}
descriptors = g_value_array_new (0);
if (!mpegts_packetizer_parse_descriptors (packetizer,
&data, data + descriptors_loop_length, descriptors)) {
gst_structure_free (service);
g_value_array_free (descriptors);
goto error;
}
gst_structure_set (service, "descriptors", G_TYPE_VALUE_ARRAY,
descriptors, NULL);
g_value_array_free (descriptors);
}
g_value_init (&service_value, GST_TYPE_STRUCTURE);
g_value_take_boxed (&service_value, service);
gst_value_list_append_value (&services, &service_value);
g_value_unset (&service_value);
sdt_info_length -= data - entry_begin;
}
if (data != end - 4) {
GST_WARNING ("PID %d invalid SDT parsed %d length %d",
section->pid, data - GST_BUFFER_DATA (section->buffer),
GST_BUFFER_SIZE (section->buffer));
goto error;
}
gst_structure_set_value (sdt, "services", &services);
g_value_unset (&services);
dbg_str = gst_structure_to_string (sdt);
g_free (dbg_str);
return sdt;
error:
if (sdt)
gst_structure_free (sdt);
if (GST_VALUE_HOLDS_LIST (&services))
g_value_unset (&services);
return NULL;
}
GstStructure *
mpegts_packetizer_parse_eit (MpegTSPacketizer * packetizer,
MpegTSPacketizerSection * section)
{
GstStructure *eit = NULL, *event = NULL;
guint service_id, last_table_id, segment_last_section_number;
guint transport_stream_id, original_network_id;
gboolean free_ca_mode;
guint event_id, running_status;
guint64 start_and_duration;
GstClockTime start_time, duration;
guint8 *data, *end;
guint16 descriptors_loop_length;
GValue events = { 0 };
GValue event_value = { 0 };
GValueArray *descriptors = NULL;
gchar *dbg_str, *event_name;
guint tmp;
/* fixed header + CRC == 16 */
if (GST_BUFFER_SIZE (section->buffer) < 18) {
GST_WARNING ("PID %d invalid EIT size %d",
section->pid, section->section_length);
goto error;
}
data = GST_BUFFER_DATA (section->buffer);
end = data + GST_BUFFER_SIZE (section->buffer);
section->table_id = *data++;
section->section_length = GST_READ_UINT16_BE (data) & 0x0FFF;
data += 2;
if (data + section->section_length != end) {
GST_WARNING ("PID %d invalid EIT section length %d expected %d",
section->pid, section->section_length, end - data);
goto error;
}
service_id = GST_READ_UINT16_BE (data);
data += 2;
tmp = *data++;
section->version_number = (tmp >> 1) & 0x1F;
section->current_next_indicator = tmp & 0x01;
/* skip section_number and last_section_number */
data += 2;
transport_stream_id = GST_READ_UINT16_BE (data);
data += 2;
original_network_id = GST_READ_UINT16_BE (data);
data += 2;
segment_last_section_number = *data;
data += 1;
last_table_id = *data;
data += 1;
eit = gst_structure_new ("eit",
"version-number", G_TYPE_UINT, section->version_number,
"current-next-indicator", G_TYPE_UINT, section->current_next_indicator,
"service-id", G_TYPE_UINT, service_id,
"transport-stream-id", G_TYPE_UINT, transport_stream_id,
"original-network-id", G_TYPE_UINT, original_network_id,
"segment-last-section-number", G_TYPE_UINT, segment_last_section_number,
"last-table-id", G_TYPE_UINT, last_table_id, NULL);
g_value_init (&events, GST_TYPE_LIST);
while (data < end - 4) {
/* 12 is the minimum entry size + CRC */
if (end - data < 12 + 4) {
GST_WARNING ("PID %d invalid EIT entry length %d",
section->pid, end - 4 - data);
gst_structure_free (eit);
goto error;
}
event_id = GST_READ_UINT16_BE (data);
data += 2;
start_and_duration = GST_READ_UINT64_BE (data);
start_time = start_and_duration >> 24;
duration = start_and_duration & 0xFFFFFF;
data += 8;
running_status = *data >> 5;
free_ca_mode = (*data >> 4) & 0x01;
descriptors_loop_length = GST_READ_UINT16_BE (data) & 0x0FFF;
data += 2;
event_name = g_strdup_printf ("event-%d", event_id);
/* FIXME: parse the date */
event = gst_structure_new (event_name,
"event-id", G_TYPE_UINT, event_id,
"start-time", G_TYPE_UINT, 0,
"duration", G_TYPE_UINT, 0,
"running-status", G_TYPE_UINT, running_status,
"free-ca-mode", G_TYPE_BOOLEAN, free_ca_mode, NULL);
g_free (event_name);
if (descriptors_loop_length) {
if (data + descriptors_loop_length > end - 4) {
GST_WARNING ("PID %d invalid EIT descriptors loop length %d",
section->pid, descriptors_loop_length);
gst_structure_free (event);
goto error;
}
descriptors = g_value_array_new (0);
if (!mpegts_packetizer_parse_descriptors (packetizer,
&data, data + descriptors_loop_length, descriptors)) {
gst_structure_free (event);
g_value_array_free (descriptors);
goto error;
}
gst_structure_set (event, "descriptors", G_TYPE_VALUE_ARRAY, descriptors,
NULL);
g_value_array_free (descriptors);
}
g_value_init (&event_value, GST_TYPE_STRUCTURE);
g_value_take_boxed (&event_value, event);
gst_value_list_append_value (&events, &event_value);
g_value_unset (&event_value);
}
if (data != end - 4) {
GST_WARNING ("PID %d invalid EIT parsed %d length %d",
section->pid, data - GST_BUFFER_DATA (section->buffer),
GST_BUFFER_SIZE (section->buffer));
goto error;
}
gst_structure_set_value (eit, "events", &events);
g_value_unset (&events);
dbg_str = gst_structure_to_string (eit);
GST_DEBUG ("EIT %s", dbg_str);
g_free (dbg_str);
return eit;
error:
if (eit)
gst_structure_free (eit);
if (GST_VALUE_HOLDS_LIST (&events))
g_value_unset (&events);
return NULL;
}
@ -611,6 +1131,7 @@ mpegts_packetizer_push_section (MpegTSPacketizer * packetizer,
* section_length */
if (gst_adapter_available (stream->section_adapter) >=
stream->section_length + 3) {
res = mpegts_packetizer_parse_section_header (packetizer,
stream, section);

View file

@ -97,9 +97,15 @@ void mpegts_packetizer_clear_packet (MpegTSPacketizer *packetizer,
gboolean mpegts_packetizer_push_section (MpegTSPacketizer *packetzer,
MpegTSPacketizerPacket *packet, MpegTSPacketizerSection *section);
GValueArray *mpegts_packetizer_parse_pat (MpegTSPacketizer *packetizer,
GstStructure *mpegts_packetizer_parse_pat (MpegTSPacketizer *packetizer,
MpegTSPacketizerSection *section);
GObject *mpegts_packetizer_parse_pmt (MpegTSPacketizer *packetizer,
GstStructure *mpegts_packetizer_parse_pmt (MpegTSPacketizer *packetizer,
MpegTSPacketizerSection *section);
GstStructure *mpegts_packetizer_parse_nit (MpegTSPacketizer *packetizer,
MpegTSPacketizerSection *section);
GstStructure *mpegts_packetizer_parse_sdt (MpegTSPacketizer *packetizer,
MpegTSPacketizerSection *section);
GstStructure *mpegts_packetizer_parse_eit (MpegTSPacketizer *packetizer,
MpegTSPacketizerSection *section);
G_END_DECLS

View file

@ -29,9 +29,6 @@
#include "mpegtsparse.h"
#include "mpegtsparsemarshal.h"
#include "flutspatinfo.h"
#include "flutspmtinfo.h"
#include "flutspmtstreaminfo.h"
GST_DEBUG_CATEGORY_STATIC (mpegts_parse_debug);
#define GST_CAT_DEFAULT mpegts_parse_debug
@ -49,7 +46,7 @@ typedef struct
gint program_number;
guint16 pmt_pid;
guint16 pcr_pid;
GObject *pmt_info;
GstStructure *pmt_info;
GHashTable *streams;
gint patcount;
gint selected;
@ -98,7 +95,11 @@ GST_STATIC_PAD_TEMPLATE ("program_%d", GST_PAD_SRC,
enum
{
SIGNAL_PAT,
SIGNAL_PMT,
SIGNAL_NIT,
SIGNAL_SDT,
SIGNAL_EIT,
/* FILL ME */
LAST_SIGNAL
};
@ -107,8 +108,7 @@ enum
{
ARG_0,
PROP_PROGRAM_NUMBERS,
PROP_PAT_INFO
/* FILL ME */
/* FILL ME */
};
static void mpegts_parse_set_property (GObject * object, guint prop_id,
@ -180,21 +180,26 @@ mpegts_parse_class_init (MpegTSParseClass * klass)
"Program Numbers",
"Colon separated list of programs", "", G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_PAT_INFO,
g_param_spec_value_array ("pat-info",
"GValueArray containing GObjects with properties",
"Array of GObjects containing information from the TS PAT "
"about all programs listed in the current Program Association "
"Table (PAT)",
g_param_spec_object ("flu-pat-streaminfo", "FluPATStreamInfo",
"Fluendo TS Demuxer PAT Stream info object",
MPEGTS_TYPE_PAT_INFO, G_PARAM_READABLE), G_PARAM_READABLE));
signals[SIGNAL_PAT] =
g_signal_new ("pat-info", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (MpegTSParseClass, pat_info), NULL, NULL,
g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, GST_TYPE_STRUCTURE);
signals[SIGNAL_PMT] =
g_signal_new ("pmt-info", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (MpegTSParseClass, pmt_info), NULL, NULL,
mpegts_parse_marshal_VOID__INT_OBJECT, G_TYPE_NONE, 2, G_TYPE_INT,
MPEGTS_TYPE_PMT_INFO);
g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, GST_TYPE_STRUCTURE);
signals[SIGNAL_NIT] =
g_signal_new ("nit-info", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (MpegTSParseClass, nit_info), NULL, NULL,
g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, GST_TYPE_STRUCTURE);
signals[SIGNAL_SDT] =
g_signal_new ("sdt-info", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (MpegTSParseClass, sdt_info), NULL, NULL,
g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, GST_TYPE_STRUCTURE);
signals[SIGNAL_EIT] =
g_signal_new ("eit-info", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (MpegTSParseClass, eit_info), NULL, NULL,
g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, GST_TYPE_STRUCTURE);
}
static gboolean
@ -213,6 +218,18 @@ mpegts_parse_reset (MpegTSParse * parse)
g_hash_table_insert (parse->psi_pids,
GINT_TO_POINTER (0), GINT_TO_POINTER (1));
/* NIT */
g_hash_table_insert (parse->psi_pids,
GINT_TO_POINTER (0x10), GINT_TO_POINTER (1));
/* SDT */
g_hash_table_insert (parse->psi_pids,
GINT_TO_POINTER (0x11), GINT_TO_POINTER (1));
/* EIT */
g_hash_table_insert (parse->psi_pids,
GINT_TO_POINTER (0x12), GINT_TO_POINTER (1));
/* pmt pids will be added and removed dinamically */
}
@ -254,8 +271,8 @@ mpegts_parse_finalize (GObject * object)
MpegTSParse *parse = GST_MPEGTS_PARSE (object);
g_free (parse->program_numbers);
if (parse->pat_info)
g_value_array_free (parse->pat_info);
if (parse->pat)
gst_structure_free (parse->pat);
g_hash_table_destroy (parse->programs);
g_hash_table_destroy (parse->psi_pids);
@ -288,9 +305,6 @@ mpegts_parse_get_property (GObject * object, guint prop_id,
case PROP_PROGRAM_NUMBERS:
g_value_set_string (value, parse->program_numbers);
break;
case PROP_PAT_INFO:
g_value_set_boxed (value, parse->pat_info);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@ -368,7 +382,7 @@ static void
mpegts_parse_free_program (MpegTSParseProgram * program)
{
if (program->pmt_info)
g_object_unref (program->pmt_info);
gst_structure_free (program->pmt_info);
g_hash_table_destroy (program->streams);
@ -714,30 +728,38 @@ mpegts_parse_is_psi_pid (MpegTSParse * parse, guint16 pid)
}
static void
mpegts_parse_apply_pat (MpegTSParse * parse, GValueArray * pat_info)
mpegts_parse_apply_pat (MpegTSParse * parse, GstStructure * pat_info)
{
GValue *value;
GValueArray *old_pat;
GObject *program_info;
gint program_number;
const GValue *value;
GstStructure *old_pat;
GstStructure *program_info;
guint program_number;
guint pid;
MpegTSParseProgram *program;
gint i;
GList *pads_to_add = NULL;
GList *pads_to_remove = NULL;
const GValue *programs;
gchar *dbg;
old_pat = parse->pat_info;
parse->pat_info = pat_info;
g_object_notify (G_OBJECT (parse), "pat-info");
old_pat = parse->pat;
parse->pat = pat_info;
dbg = gst_structure_to_string (pat_info);
GST_INFO_OBJECT (parse, "PAT %s", dbg);
g_free (dbg);
g_signal_emit (parse, signals[SIGNAL_PAT], 0, pat_info);
GST_OBJECT_LOCK (parse);
programs = gst_structure_get_value (pat_info, "programs");
/* activate the new table */
for (i = 0; i < pat_info->n_values; ++i) {
value = g_value_array_get_nth (pat_info, i);
for (i = 0; i < gst_value_list_get_size (programs); ++i) {
value = gst_value_list_get_value (programs, i);
program_info = g_value_get_object (value);
g_object_get (program_info,
"program-number", &program_number, "pid", &pid, NULL);
program_info = g_value_get_boxed (value);
gst_structure_get_uint (program_info, "program-number", &program_number);
gst_structure_get_uint (program_info, "pid", &pid);
program = mpegts_parse_get_program (parse, program_number);
if (program) {
@ -755,9 +777,6 @@ mpegts_parse_apply_pat (MpegTSParse * parse, GValueArray * pat_info)
program->patcount += 1;
} else {
GST_INFO_OBJECT (parse, "PAT adding program %d pmt_pid %d",
program_number, pid);
g_hash_table_insert (parse->psi_pids,
GINT_TO_POINTER ((gint) pid), GINT_TO_POINTER (1));
program = mpegts_parse_add_program (parse, program_number, pid);
@ -771,12 +790,13 @@ mpegts_parse_apply_pat (MpegTSParse * parse, GValueArray * pat_info)
if (old_pat) {
/* deactivate the old table */
for (i = 0; i < old_pat->n_values; ++i) {
value = g_value_array_get_nth (old_pat, i);
programs = gst_structure_get_value (old_pat, "programs");
for (i = 0; i < gst_value_list_get_size (programs); ++i) {
value = gst_value_list_get_value (programs, i);
program_info = g_value_get_object (value);
g_object_get (program_info,
"program-number", &program_number, "pid", &pid, NULL);
program_info = g_value_get_boxed (value);
gst_structure_get_uint (program_info, "program-number", &program_number);
gst_structure_get_uint (program_info, "pid", &pid);
program = mpegts_parse_get_program (parse, program_number);
if (program == NULL) {
@ -789,8 +809,12 @@ mpegts_parse_apply_pat (MpegTSParse * parse, GValueArray * pat_info)
/* the program has been referenced by the new pat, keep it */
continue;
GST_INFO_OBJECT (parse, "PAT removing program %d pmt_pid %d",
program_number, pid);
{
gchar *dbg = gst_structure_to_string (program_info);
GST_INFO_OBJECT (parse, "PAT removing program %s", dbg);
g_free (dbg);
}
if (program->active)
parse->pads_to_remove = g_list_append (parse->pads_to_remove,
@ -800,7 +824,7 @@ mpegts_parse_apply_pat (MpegTSParse * parse, GValueArray * pat_info)
g_hash_table_remove (parse->psi_pids, GINT_TO_POINTER ((gint) pid));
}
g_value_array_free (old_pat);
gst_structure_free (old_pat);
}
pads_to_add = parse->pads_to_add;
@ -814,39 +838,40 @@ mpegts_parse_apply_pat (MpegTSParse * parse, GValueArray * pat_info)
static void
mpegts_parse_apply_pmt (MpegTSParse * parse,
guint16 pmt_pid, GObject * pmt_info)
guint16 pmt_pid, GstStructure * pmt_info)
{
MpegTSParseProgram *program;
gint program_number;
guint program_number;
guint pcr_pid;
guint pid;
guint stream_type;
GValueArray *old_streams;
GValueArray *new_streams;
GValue *value;
GObject *stream;
GstStructure *stream;
gint i;
const GValue *old_streams;
const GValue *new_streams;
const GValue *value;
g_object_get (pmt_info, "program_number", &program_number,
"pcr-pid", &pcr_pid, "stream-info", &new_streams, NULL);
gst_structure_get_uint (pmt_info, "program-number", &program_number);
gst_structure_get_uint (pmt_info, "pcr-pid", &pcr_pid);
new_streams = gst_structure_get_value (pmt_info, "streams");
GST_OBJECT_LOCK (parse);
program = mpegts_parse_get_program (parse, program_number);
if (program) {
if (program->pmt_info) {
/* deactivate old pmt */
g_object_get (program->pmt_info, "stream-info", &old_streams, NULL);
old_streams = gst_structure_get_value (program->pmt_info, "streams");
for (i = 0; i < old_streams->n_values; ++i) {
value = g_value_array_get_nth (old_streams, i);
stream = g_value_get_object (value);
for (i = 0; i < gst_value_list_get_size (old_streams); ++i) {
value = gst_value_list_get_value (old_streams, i);
stream = g_value_get_boxed (value);
g_object_get (stream, "pid", &pid, "stream-type", &stream_type, NULL);
gst_structure_get_uint (stream, "pid", &pid);
gst_structure_get_uint (stream, "stream-type", &stream_type);
mpegts_parse_program_remove_stream (parse, program, (guint16) pid);
}
g_value_array_free (old_streams);
g_object_unref (program->pmt_info);
gst_structure_free (program->pmt_info);
}
} else {
/* no PAT?? */
@ -862,20 +887,46 @@ mpegts_parse_apply_pmt (MpegTSParse * parse,
program->pcr_pid = pcr_pid;
mpegts_parse_program_add_stream (parse, program, (guint16) pcr_pid, -1);
for (i = 0; i < new_streams->n_values; ++i) {
value = g_value_array_get_nth (new_streams, i);
stream = g_value_get_object (value);
for (i = 0; i < gst_value_list_get_size (new_streams); ++i) {
value = gst_value_list_get_value (new_streams, i);
stream = g_value_get_boxed (value);
g_object_get (stream, "pid", &pid, "stream-type", &stream_type, NULL);
GST_DEBUG_OBJECT (parse, "PMT program %d pid %d", program_number, pid);
mpegts_parse_program_add_stream (parse, program, (guint16) pid,
(guint8) stream_type);
gst_structure_get_uint (stream, "pid", &pid);
gst_structure_get_uint (stream, "stream-type", &stream_type);
mpegts_parse_program_add_stream (parse, program,
(guint16) pid, (guint8) stream_type);
}
GST_OBJECT_UNLOCK (parse);
g_value_array_free (new_streams);
{
gchar *dbg = gst_structure_to_string (pmt_info);
g_signal_emit (parse, signals[SIGNAL_PMT], 0, program_number, pmt_info);
GST_DEBUG_OBJECT (parse, "new pmt %s", dbg);
g_free (dbg);
}
g_signal_emit (parse, signals[SIGNAL_PMT], 0, pmt_info);
}
static void
mpegts_parse_apply_nit (MpegTSParse * parse,
guint16 pmt_pid, GstStructure * nit_info)
{
g_signal_emit (parse, signals[SIGNAL_NIT], 0, nit_info);
}
static void
mpegts_parse_apply_sdt (MpegTSParse * parse,
guint16 pmt_pid, GstStructure * sdt_info)
{
g_signal_emit (parse, signals[SIGNAL_SDT], 0, sdt_info);
}
static void
mpegts_parse_apply_eit (MpegTSParse * parse,
guint16 pmt_pid, GstStructure * eit_info)
{
g_signal_emit (parse, signals[SIGNAL_EIT], 0, eit_info);
}
static gboolean
@ -887,7 +938,7 @@ mpegts_parse_handle_psi (MpegTSParse * parse, MpegTSPacketizerSection * section)
case 0x00:
{
/* PAT */
GValueArray *pat_info;
GstStructure *pat_info;
pat_info = mpegts_packetizer_parse_pat (parse->packetizer, section);
if (pat_info)
@ -900,7 +951,7 @@ mpegts_parse_handle_psi (MpegTSParse * parse, MpegTSPacketizerSection * section)
case 0x02:
{
/* PMT */
GObject *pmt_info;
GstStructure *pmt_info;
pmt_info = mpegts_packetizer_parse_pmt (parse->packetizer, section);
if (pmt_info)
@ -910,6 +961,63 @@ mpegts_parse_handle_psi (MpegTSParse * parse, MpegTSPacketizerSection * section)
break;
}
case 0x40:
/* NIT, actual network */
case 0x41:
/* NIT, other network */
{
GstStructure *nit_info;
nit_info = mpegts_packetizer_parse_nit (parse->packetizer, section);
if (nit_info)
mpegts_parse_apply_nit (parse, section->pid, nit_info);
else
res = FALSE;
break;
}
case 0x42:
{
/* SDT */
GstStructure *sdt_info;
sdt_info = mpegts_packetizer_parse_sdt (parse->packetizer, section);
if (sdt_info)
mpegts_parse_apply_sdt (parse, section->pid, sdt_info);
else
res = FALSE;
break;
}
case 0x4E:
/* EIT, present/following */
case 0x50:
case 0x51:
case 0x52:
case 0x53:
case 0x54:
case 0x55:
case 0x56:
case 0x57:
case 0x58:
case 0x59:
case 0x5A:
case 0x5B:
case 0x5C:
case 0x5D:
case 0x5E:
case 0x5F:
/* EIT, schedule */
{
/* EIT */
GstStructure *eit_info;
eit_info = mpegts_packetizer_parse_eit (parse->packetizer, section);
if (eit_info)
mpegts_parse_apply_eit (parse, section->pid, eit_info);
else
res = FALSE;
break;
}
default:
break;
}

View file

@ -57,7 +57,7 @@ struct _MpegTSParse {
GHashTable *programs;
guint req_pads;
GValueArray *pat_info;
GstStructure *pat;
MpegTSPacketizer *packetizer;
GHashTable *psi_pids;
gboolean disposed;
@ -67,7 +67,11 @@ struct _MpegTSParseClass {
GstElementClass parent_class;
/* signals */
void (*pmt_info) (GObject *pmt_info);
void (*pat_info) (GstStructure *pat);
void (*pmt_info) (GstStructure *pmt);
void (*nit_info) (GstStructure *nit);
void (*sdt_info) (GstStructure *sdt);
void (*eit_info) (GstStructure *eit);
};
GType gst_mpegts_parse_get_type(void);

View file

@ -69,7 +69,7 @@ cam_conditional_access_destroy (CamConditionalAccess * cas)
}
static CamReturn
send_ca_pmt (CamConditionalAccess * cas, GObject * pmt,
send_ca_pmt (CamConditionalAccess * cas, GstStructure * pmt,
guint8 list_management, guint8 cmd_id)
{
CamReturn ret;
@ -107,7 +107,7 @@ send_ca_pmt (CamConditionalAccess * cas, GObject * pmt,
CamReturn
cam_conditional_access_set_pmt (CamConditionalAccess * cas,
GObject * pmt, CamConditionalAccessPmtFlag flag)
GstStructure * pmt, CamConditionalAccessPmtFlag flag)
{
return send_ca_pmt (cas, pmt, flag, 0x01 /* ok_descrambling */ );
}

View file

@ -50,6 +50,6 @@ CamConditionalAccess *cam_conditional_access_new ();
void cam_conditional_access_destroy (CamConditionalAccess *cas);
CamReturn cam_conditional_access_set_pmt (CamConditionalAccess *cas,
GObject *pmt, CamConditionalAccessPmtFlag flag);
GstStructure *pmt, CamConditionalAccessPmtFlag flag);
#endif /* CAM_CONDITIONAL_ACCESS_H */

View file

@ -202,7 +202,7 @@ cam_device_ready (CamDevice * device)
void
cam_device_set_pmt (CamDevice * device,
GObject * pmt, CamConditionalAccessPmtFlag flag)
GstStructure * pmt, CamConditionalAccessPmtFlag flag)
{
g_return_if_fail (device != NULL);
g_return_if_fail (device->state == CAM_DEVICE_STATE_OPEN);

View file

@ -64,6 +64,6 @@ void cam_device_close (CamDevice *device);
gboolean cam_device_ready (CamDevice *device);
void cam_device_poll (CamDevice *device);
void cam_device_set_pmt (CamDevice *device,
GObject *pmt, CamConditionalAccessPmtFlag flag);
GstStructure *pmt, CamConditionalAccessPmtFlag flag);
#endif /* CAM_DEVICE_H */

View file

@ -109,7 +109,7 @@ cam_sw_client_close (CamSwClient * client)
}
static void
send_ca_pmt (CamSwClient * client, GObject * pmt,
send_ca_pmt (CamSwClient * client, GstStructure * pmt,
guint8 list_management, guint8 cmd_id)
{
guint8 *buffer;
@ -144,7 +144,7 @@ send_ca_pmt (CamSwClient * client, GObject * pmt,
}
void
cam_sw_client_set_pmt (CamSwClient * client, GObject * pmt)
cam_sw_client_set_pmt (CamSwClient * client, GstStructure * pmt)
{
g_return_if_fail (client != NULL);
g_return_if_fail (pmt != NULL);
@ -154,7 +154,7 @@ cam_sw_client_set_pmt (CamSwClient * client, GObject * pmt)
}
void
cam_sw_client_update_pmt (CamSwClient * client, GObject * pmt)
cam_sw_client_update_pmt (CamSwClient * client, GstStructure * pmt)
{
g_return_if_fail (client != NULL);
g_return_if_fail (pmt != NULL);

View file

@ -47,7 +47,7 @@ void cam_sw_client_free (CamSwClient *sw_client);
gboolean cam_sw_client_open (CamSwClient *sw_client, const char *sock_path);
void cam_sw_client_close (CamSwClient *sw_client);
void cam_sw_client_set_pmt (CamSwClient *sw_client, GObject *pmt);
void cam_sw_client_update_pmt (CamSwClient *sw_client, GObject *pmt);
void cam_sw_client_set_pmt (CamSwClient *sw_client, GstStructure *pmt);
void cam_sw_client_update_pmt (CamSwClient *sw_client, GstStructure *pmt);
#endif /* CAM_SW_CLIENT_H */

View file

@ -210,7 +210,7 @@ write_ca_descriptors (guint8 * body, GValueArray * descriptors)
}
guint8 *
cam_build_ca_pmt (GObject * pmt, guint8 list_management, guint8 cmd_id,
cam_build_ca_pmt (GstStructure * pmt, guint8 list_management, guint8 cmd_id,
guint * size)
{
guint body_size = 0;
@ -218,20 +218,20 @@ cam_build_ca_pmt (GObject * pmt, guint8 list_management, guint8 cmd_id,
guint8 *body;
GList *lengths = NULL;
guint len = 0;
GValueArray *streams = NULL;
gint program_number;
const GValue *streams;
guint program_number;
guint version_number;
guint i;
GValue *value;
GObject *stream;
const GValue *value;
GstStructure *stream;
GValueArray *program_descriptors = NULL;
GValueArray *stream_descriptors = NULL;
g_object_get (pmt,
"program-number", &program_number,
"version-number", &version_number,
"stream-info", &streams, "descriptors", &program_descriptors, NULL);
gst_structure_get_uint (pmt, "program-number", &program_number);
gst_structure_get_uint (pmt, "version-number", &version_number);
streams = gst_structure_get_value (pmt, "streams");
value = gst_structure_get_value (pmt, "descriptors");
program_descriptors = g_value_get_boxed (value);
/* get the length of program level CA_descriptor()s */
len = get_ca_descriptors_length (program_descriptors);
if (len > 0)
@ -243,11 +243,12 @@ cam_build_ca_pmt (GObject * pmt, guint8 list_management, guint8 cmd_id,
/* get the length of stream level CA_descriptor()s */
if (streams != NULL) {
for (i = 0; i < streams->n_values; ++i) {
value = g_value_array_get_nth (streams, i);
stream = g_value_get_object (value);
for (i = 0; i < gst_value_list_get_size (streams); ++i) {
value = gst_value_list_get_value (streams, i);
stream = g_value_get_boxed (value);
g_object_get (stream, "descriptors", &stream_descriptors, NULL);
value = gst_structure_get_value (stream, "descriptors");
stream_descriptors = g_value_get_boxed (value);
len = get_ca_descriptors_length (stream_descriptors);
if (len > 0)
@ -257,30 +258,12 @@ cam_build_ca_pmt (GObject * pmt, guint8 list_management, guint8 cmd_id,
lengths = g_list_append (lengths, GINT_TO_POINTER (len));
body_size += 5 + len;
if (stream_descriptors) {
g_value_array_free (stream_descriptors);
stream_descriptors = NULL;
}
}
}
buffer = g_malloc0 (body_size);
body = buffer;
/*
guint length_field_len = cam_calc_length_field_size (body_size);
guint apdu_header_length = 3 + length_field_len;
guint8 *apdu = (buffer + buffer_size) - body_size - apdu_header_length;
apdu [0] = 0x9F;
apdu [1] = 0x80;
apdu [2] = 0x32;
g_print ("LEN %d %d", length_field_len, body_size);
cam_write_length_field (&apdu [3], body_size);
body += 4;
*/
*body++ = list_management;
GST_WRITE_UINT16_BE (body, program_number);
@ -302,16 +285,17 @@ cam_build_ca_pmt (GObject * pmt, guint8 list_management, guint8 cmd_id,
if (program_descriptors)
g_value_array_free (program_descriptors);
for (i = 0; i < streams->n_values; ++i) {
for (i = 0; i < gst_value_list_get_size (streams); ++i) {
guint stream_type;
guint stream_pid;
value = g_value_array_get_nth (streams, i);
stream = g_value_get_object (value);
value = gst_value_list_get_value (streams, i);
stream = g_value_get_boxed (value);
g_object_get (stream,
"stream-type", &stream_type,
"pid", &stream_pid, "descriptors", &stream_descriptors, NULL);
gst_structure_get_uint (stream, "stream-type", &stream_type);
gst_structure_get_uint (stream, "pid", &stream_pid);
value = gst_structure_get_value (stream, "descriptors");
stream_descriptors = g_value_get_boxed (value);
*body++ = stream_type;
GST_WRITE_UINT16_BE (body, stream_pid);
@ -325,16 +309,8 @@ cam_build_ca_pmt (GObject * pmt, guint8 list_management, guint8 cmd_id,
*body++ = cmd_id;
body = write_ca_descriptors (body, stream_descriptors);
}
if (stream_descriptors) {
g_value_array_free (stream_descriptors);
stream_descriptors = NULL;
}
}
if (streams)
g_value_array_free (streams);
*size = body_size;
return buffer;
}

View file

@ -54,6 +54,6 @@ typedef enum
guint8 cam_calc_length_field_size (guint length);
guint8 cam_write_length_field (guint8 *buff, guint length);
guint8 cam_read_length_field (guint8 *buff, guint *length);
guint8 *cam_build_ca_pmt (GObject *pmt, guint8 list_management, guint8 cmd_id, guint *size);
guint8 *cam_build_ca_pmt (GstStructure *pmt, guint8 list_management, guint8 cmd_id, guint *size);
#endif /* CAM_UTILS_H */

View file

@ -88,8 +88,8 @@ typedef struct
gint program_number;
guint16 pmt_pid;
guint16 pcr_pid;
GObject *pmt;
GObject *old_pmt;
GstStructure *pmt;
GstStructure *old_pmt;
gboolean selected;
gboolean pmt_active;
gboolean active;
@ -107,10 +107,10 @@ static gboolean dvb_base_bin_ts_pad_probe_cb (GstPad * pad,
GstBuffer * buf, gpointer user_data);
static GstStateChangeReturn dvb_base_bin_change_state (GstElement * element,
GstStateChange transition);
static void dvb_base_bin_pat_info_changed_cb (GstElement * mpegtsparse,
GParamSpec * pspec, DvbBaseBin * dvbbasebin);
static void dvb_base_bin_pat_info_cb (GstElement * mpegtsparse,
GstStructure * pat, DvbBaseBin * dvbbasebin);
static void dvb_base_bin_pmt_info_cb (GstElement * mpegtsparse,
guint program_number, GObject * pmt, DvbBaseBin * dvbbasebin);
GstStructure * pmt, DvbBaseBin * dvbbasebin);
static void dvb_base_bin_pad_added_cb (GstElement * mpegtsparse,
GstPad * pad, DvbBaseBin * dvbbasebin);
static void dvb_base_bin_pad_removed_cb (GstElement * mpegtsparse,
@ -310,7 +310,7 @@ dvb_base_bin_init (DvbBaseBin * dvbbasebin, DvbBaseBinClass * klass)
dvbbasebin->buffer_queue = gst_element_factory_make ("queue", NULL);
dvbbasebin->mpegtsparse = gst_element_factory_make ("mpegtsparse", NULL);
g_object_connect (dvbbasebin->mpegtsparse,
"signal::notify::pat-info", dvb_base_bin_pat_info_changed_cb, dvbbasebin,
"signal::pat-info", dvb_base_bin_pat_info_cb, dvbbasebin,
"signal::pmt-info", dvb_base_bin_pmt_info_cb, dvbbasebin,
"signal::pad-added", dvb_base_bin_pad_added_cb, dvbbasebin,
"signal::pad-removed", dvb_base_bin_pad_removed_cb, dvbbasebin, NULL);
@ -478,7 +478,7 @@ dvb_base_bin_reset_pmtlist (DvbBaseBin * dvbbasebin)
{
CamConditionalAccessPmtFlag flag;
GList *walk;
GObject *pmt;
GstStructure *pmt;
walk = dvbbasebin->pmtlist;
while (walk) {
@ -494,7 +494,7 @@ dvb_base_bin_reset_pmtlist (DvbBaseBin * dvbbasebin)
flag = CAM_CONDITIONAL_ACCESS_PMT_FLAG_MORE;
}
pmt = G_OBJECT (walk->data);
pmt = GST_STRUCTURE (walk->data);
cam_device_set_pmt (dvbbasebin->hwcam, pmt, flag);
walk = walk->next;
@ -615,25 +615,26 @@ dvb_base_bin_rebuild_filter (DvbBaseBin * dvbbasebin)
}
static void
dvb_base_bin_remove_pmt_streams (DvbBaseBin * dvbbasebin, GObject * pmt)
dvb_base_bin_remove_pmt_streams (DvbBaseBin * dvbbasebin, GstStructure * pmt)
{
GValueArray *streams;
gint program_number;
const GValue *streams;
guint program_number;
gint i;
GValue *value;
GObject *streamobj;
const GValue *value;
GstStructure *stream_info;
DvbBaseBinStream *stream;
guint pid;
guint stream_type;
g_object_get (pmt, "program-number", &program_number,
"stream-info", &streams, NULL);
gst_structure_get_uint (pmt, "program-number", &program_number);
streams = gst_structure_get_value (pmt, "streams");
for (i = 0; i < streams->n_values; ++i) {
value = g_value_array_get_nth (streams, i);
streamobj = g_value_get_object (value);
for (i = 0; i < gst_value_list_get_size (streams); ++i) {
value = gst_value_list_get_value (streams, i);
stream_info = g_value_get_boxed (value);
g_object_get (streamobj, "pid", &pid, "stream-type", &stream_type, NULL);
gst_structure_get_uint (stream_info, "pid", &pid);
gst_structure_get_uint (stream_info, "stream-type", &stream_type);
stream = dvb_base_bin_get_stream (dvbbasebin, (guint16) pid);
if (stream == NULL) {
@ -646,25 +647,26 @@ dvb_base_bin_remove_pmt_streams (DvbBaseBin * dvbbasebin, GObject * pmt)
}
static void
dvb_base_bin_add_pmt_streams (DvbBaseBin * dvbbasebin, GObject * pmt)
dvb_base_bin_add_pmt_streams (DvbBaseBin * dvbbasebin, GstStructure * pmt)
{
DvbBaseBinStream *stream;
GValueArray *streams;
gint program_number;
const GValue *streams;
guint program_number;
gint i;
GValue *value;
GObject *streamobj;
const GValue *value;
GstStructure *stream_info;
guint pid;
guint stream_type;
g_object_get (pmt, "program-number", &program_number,
"stream-info", &streams, NULL);
gst_structure_get_uint (pmt, "program-number", &program_number);
streams = gst_structure_get_value (pmt, "streams");
for (i = 0; i < streams->n_values; ++i) {
value = g_value_array_get_nth (streams, i);
streamobj = g_value_get_object (value);
for (i = 0; i < gst_value_list_get_size (streams); ++i) {
value = gst_value_list_get_value (streams, i);
stream_info = g_value_get_boxed (value);
g_object_get (streamobj, "pid", &pid, "stream-type", &stream_type, NULL);
gst_structure_get_uint (stream_info, "pid", &pid);
gst_structure_get_uint (stream_info, "stream-type", &stream_type);
GST_DEBUG ("filtering stream %d stream_type %d", pid, stream_type);
stream = dvb_base_bin_get_stream (dvbbasebin, (guint16) pid);
@ -702,7 +704,7 @@ dvb_base_bin_activate_program (DvbBaseBin * dvbbasebin,
guint16 old_pcr_pid;
old_pcr_pid = program->pcr_pid;
g_object_get (program->pmt, "pcr-pid", &pid, NULL);
gst_structure_get_uint (program->pmt, "pcr-pid", &pid);
program->pcr_pid = pid;
if (old_pcr_pid != G_MAXUINT16 && old_pcr_pid != program->pcr_pid)
dvb_base_bin_get_stream (dvbbasebin, old_pcr_pid)->usecount--;
@ -747,28 +749,27 @@ dvb_base_bin_deactivate_program (DvbBaseBin * dvbbasebin,
}
static void
dvb_base_bin_pat_info_changed_cb (GstElement * mpegtsparse,
GParamSpec * pspec, DvbBaseBin * dvbbasebin)
dvb_base_bin_pat_info_cb (GstElement * mpegtsparse,
GstStructure * pat_info, DvbBaseBin * dvbbasebin)
{
DvbBaseBinProgram *program;
DvbBaseBinStream *stream;
GValueArray *pat_info;
GValue *value;
GObject *program_info;
gint program_number;
const GValue *value;
GstStructure *program_info;
guint program_number;
guint pid;
guint16 old_pmt_pid;
guint old_pmt_pid;
gint i;
gboolean rebuild_filter = FALSE;
const GValue *programs;
g_object_get (mpegtsparse, "pat-info", &pat_info, NULL);
programs = gst_structure_get_value (pat_info, "programs");
for (i = 0; i < gst_value_list_get_size (programs); ++i) {
value = gst_value_list_get_value (programs, i);
program_info = g_value_get_boxed (value);
for (i = 0; i < pat_info->n_values; ++i) {
value = g_value_array_get_nth (pat_info, i);
program_info = g_value_get_object (value);
g_object_get (program_info, "program-number", &program_number,
"pid", &pid, NULL);
gst_structure_get_uint (program_info, "program-number", &program_number);
gst_structure_get_uint (program_info, "pid", &pid);
program = dvb_base_bin_get_program (dvbbasebin, program_number);
if (program == NULL)
@ -792,17 +793,18 @@ dvb_base_bin_pat_info_changed_cb (GstElement * mpegtsparse,
}
}
g_value_array_free (pat_info);
if (rebuild_filter)
dvb_base_bin_rebuild_filter (dvbbasebin);
}
static void
dvb_base_bin_pmt_info_cb (GstElement * mpegtsparse,
guint program_number, GObject * pmt, DvbBaseBin * dvbbasebin)
GstStructure * pmt, DvbBaseBin * dvbbasebin)
{
DvbBaseBinProgram *program;
guint program_number;
gst_structure_get_uint (pmt, "program-number", &program_number);
program = dvb_base_bin_get_program (dvbbasebin, program_number);
if (program == NULL) {
@ -812,7 +814,7 @@ dvb_base_bin_pmt_info_cb (GstElement * mpegtsparse,
}
program->old_pmt = program->pmt;
program->pmt = g_object_ref (pmt);
program->pmt = gst_structure_copy (pmt);
/* activate the program if it's selected and either it's not active or its pmt
* changed */
@ -820,7 +822,7 @@ dvb_base_bin_pmt_info_cb (GstElement * mpegtsparse,
dvb_base_bin_activate_program (dvbbasebin, program);
if (program->old_pmt) {
g_object_unref (program->old_pmt);
gst_structure_free (program->old_pmt);
program->old_pmt = NULL;
}
}