opencaster-3.2.2/0000755000175000017500000000000012236446074013117 5ustar debiandebianopencaster-3.2.2/Makefile0000755000175000017500000000035312214326456014560 0ustar debiandebianSUBDIRS = libs tools subdirs: $(SUBDIRS) $(SUBDIRS): $(MAKE) -C $@ .PHONY: subdirs $(SUBDIRS) all: subdirs install: all @for T in $(SUBDIRS); do make -C $$T $@; done clean: @for T in $(SUBDIRS); do make -C $$T $@; done opencaster-3.2.2/libs/0000755000175000017500000000000012214326456014045 5ustar debiandebianopencaster-3.2.2/libs/Makefile0000755000175000017500000000036512214326456015514 0ustar debiandebianSUBDIRS = sectioncrc dvbobjects subdirs: $(SUBDIRS) $(SUBDIRS): $(MAKE) -C $@ .PHONY: subdirs $(SUBDIRS) all: subdirs install: all @for T in $(SUBDIRS); do make -C $$T $@; done clean: @for T in $(SUBDIRS); do make -C $$T $@; done opencaster-3.2.2/libs/dvbobjects/0000755000175000017500000000000012214326456016172 5ustar debiandebianopencaster-3.2.2/libs/dvbobjects/sectioncrc.py.c0000755000175000017500000000260212214326456021124 0ustar debiandebian/* sectioncrc.py.c -- MPEG-2 checksum calculation, Python Module Copyright (C) 2001 Oleg Tchekoulaev, GMD This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include "../sectioncrc/sectioncrc.c" unsigned int sectioncrc( unsigned char*, unsigned int ); static PyObject* do_sectioncrc( PyObject*, PyObject* ); static PyMethodDef methods [] = { { "sectioncrc", do_sectioncrc, METH_VARARGS }, {NULL, NULL} }; void init_crc32(void) { Py_InitModule( "_crc32", methods ); } static PyObject* do_sectioncrc( PyObject *self, PyObject *args ) { unsigned int c; char *buf; int len; if( !PyArg_ParseTuple( args, "s#", &buf, &len ) ) return NULL; c = sectioncrc( buf, len ); return Py_BuildValue( "I", c ); } opencaster-3.2.2/libs/dvbobjects/Makefile0000755000175000017500000000035212214326456017635 0ustar debiandebian #DESTDIR ?= /usr/local/bin #INSTHOME ?= /usr all: ./setup.py build install: all ./setup.py install --root=$(INSTHOME) #install: all # ./setup.py install clean: ./setup.py clean rm -rf build/* -include $(wildcard *.d) dummy opencaster-3.2.2/libs/dvbobjects/dvbobjects/0000755000175000017500000000000012220025244020303 5ustar debiandebianopencaster-3.2.2/libs/dvbobjects/dvbobjects/DVB/0000755000175000017500000000000012214326456020732 5ustar debiandebianopencaster-3.2.2/libs/dvbobjects/dvbobjects/DVB/Descriptors.py0000755000175000017500000010126712214403441023605 0ustar debiandebian#! /usr/bin/env python # # Copyright (C) 2004-2013 Lorenzo Pallara, l.pallara@avalpa.com # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.utils import * from dvbobjects.utils.MJD import * from dvbobjects.MPEG.Descriptor import Descriptor ###################################################################### class short_event_descriptor(Descriptor): descriptor_tag = 0x4D def bytes(self): assert len(self.ISO639_language_code) == 3 fmt = "!%dsB%dsB%ds" % ( len(self.ISO639_language_code), len(self.event_name), len(self.text), ) return pack(fmt, self.ISO639_language_code, len(self.event_name), self.event_name, len(self.text), self.text, ) ###################################################################### class content_user_loop_item(DVBobject): def pack(self): fmt = "!BB" return pack(fmt, ((self.content_nibble_level_1 & 0xF) << 4)| ((self.content_nibble_level_2 & 0xF)), ((self.user_nibble_level_1 & 0xF) << 4)| ((self.user_nibble_level_2 & 0xF)) ) class content_descriptor(Descriptor): descriptor_tag = 0x54 def bytes(self): data_bytes = string.join( map(lambda x: x.pack(), self.content_user_loop), "") fmt = "!%ds" % len(data_bytes) return pack(fmt, data_bytes, ) ###################################################################### class parental_rating_descriptor(Descriptor): descriptor_tag = 0x55 def bytes(self): assert len(self.country_code) == 3 fmt = "!%dsB" % ( len(self.country_code), ) return pack(fmt, self.country_code, self.rating, ) ###################################################################### class dts_registration_descriptor(Descriptor): descriptor_tag = 0x05 def bytes(self): fmt = "!L" return pack(fmt, self.format_identifier, ) #DTS format_identifier is 0x44545331 ("DTS1") for frame size 512; #DTS format_identifier is 0x44545332 ("DTS2") for frame size 1 024; #DTS format_identifier is 0x44545333 ("DTS3") for frame size 2 048. ###################################################################### class teletext_descriptor(Descriptor): descriptor_tag = 0x56 def bytes(self): data_bytes = string.join( map(lambda x: x.pack(), self.teletext_descriptor_loop), "") fmt = "!%ds" % len(data_bytes) return pack(fmt, data_bytes, ) class teletext_descriptor_loop_item(DVBobject): def pack(self): assert len(self.ISO639_language_code) == 3 fmt = "!%dsBB" % len(self.ISO639_language_code) return pack(fmt, self.ISO639_language_code, (self.type << 3) | (self.magazine_number & 0x07), self.page_number, ) ###################################################################### class vbi_data_descriptor_loop_item(DVBobject): def pack(self): fmt = "!B" return pack(fmt, 0x3F & ((self.field_parity & 0x01) >> 5) | (self.line_offset & 0x1F), ) class vbi_data_descriptor(Descriptor): descriptor_tag = 0x45 def bytes(self): data_bytes = string.join( map(lambda x: x.pack(), self.vbi_data_descriptor_loop), "") fmt = "!BB%ds" % len(data_bytes) return pack(fmt, self.data_service_id, len(data_bytes), data_bytes, ) ###################################################################### class stream_identifier_descriptor(Descriptor): descriptor_tag = 0x52 def bytes(self): fmt = "!B" return pack(fmt, self.component_tag, ) ###################################################################### class bouquet_name_descriptor(Descriptor): descriptor_tag = 0x71 def bytes(self): fmt = "!%ds" % len(self.bouquet_name) return pack(fmt, self.bouquet_name) ###################################################################### class data_broadcast_id_descriptor(Descriptor): descriptor_tag = 0x66 def bytes(self): if (self.data_broadcast_ID == 0x000A): # DVB-SSU oui_data_bytes = string.join( map(lambda x: x.pack(), self.OUI_info_loop), "") oui_data_length = len(oui_data_bytes); FMT = "!HB%ds%ds" % (oui_data_length,len(self.private_data_bytes)) return pack(FMT, self.data_broadcast_ID, oui_data_length, oui_data_bytes, self.private_data_bytes, ) else: FMT = "!H%ds" % len(self.ID_selector_bytes) return pack(FMT, self.data_broadcast_ID, self.ID_selector_bytes, ) ###################################################################### class local_time_offset_loop_item(DVBobject): def pack(self): FMT = "!%dsBBBHBBBBB" % len(self.ISO_639_language_code) return pack(FMT, self.ISO_639_language_code, ((self.country_region_id & 0x3F) << 2) | 0x2 | (self.local_time_offset_polarity & 0x1), self.local_time_offset_hour, self.local_time_offset_minute, MJD_convert(self.year_of_change, self.month_of_change, self.day_of_change), self.hour_of_change, self.minute_of_change, self.second_of_change, self.next_time_offset_hour, self.next_time_offset_minute, ) ###################################################################### class local_time_offset_descriptor(Descriptor): descriptor_tag = 0x58 def bytes(self): lt_bytes = string.join( map(lambda x: x.pack(), self.local_time_offset_loop), "") FMT = "!%ds" % len(lt_bytes) return pack(FMT, lt_bytes ) ###################################################################### class _broadcast_id_descriptor(Descriptor): descriptor_tag = 0x66 def bytes(self): FMT = "!H%ds" % len(self.ID_selector_bytes) return pack(FMT, self.data_broadcast_ID, self.ID_selector_bytes, ) ###################################################################### class application_signalling_descriptor(Descriptor): descriptor_tag = 0x6F application_type = -1 def bytes(self): if (self.application_type == -1): fmt = "!" return pack(fmt) else: FMT = "!HB" return pack(FMT, self.application_type, 0xE0 | (self.AIT_version & 0x1F), ) ###################################################################### class network_descriptor(Descriptor): descriptor_tag = 0x40 def bytes(self): fmt = "!%ds" % len(self.network_name) return pack(fmt, self.network_name, ) ###################################################################### class service_descriptor(Descriptor): descriptor_tag = 0x48 def bytes(self): fmt = "!BB%dsB%ds" % (len(self.service_provider_name), len(self.service_name)) return pack(fmt, self.service_type, len(self.service_provider_name), self.service_provider_name, len(self.service_name), self.service_name, ) ###################################################################### class transport_stream_terrestrial_descriptor(Descriptor): descriptor_tag = 0x5a def bytes(self): fmt = "!LBBBL" return pack(fmt, self.center_frequency, (self.bandwidth << 5) | 0x1f, (self.constellation << 6) | (self.hierarchy_information << 3)| (self.code_rate_HP_stream), (self.code_rate_LP_stream << 5) | (self.guard_interval << 3) | (self.transmission_mode << 1) | self.other_frequency_flag, 0xffffffff, ) ###################################################################### class transport_stream_sat_descriptor(Descriptor): descriptor_tag = 0x43 def bytes(self): fmt = "!LHBL" return pack(fmt, self.frequency, self.orbital_position, (self.west_east_flag << 7) | (self.polarization << 5) | self.modulation, (self.symbol_rate << 4)| self.FEC_inner, ) ####################################################################### class transport_stream_cable_descriptor(Descriptor): descriptor_tag = 0x44 def bytes(self): fmt = "!LHBL" return pack(fmt, self.frequency, (self.FEC_outer) | 0xFFF0, (self.modulation), (self.symbol_rate << 4)| (self.FEC_inner), ) ###################################################################### class service_descriptor_loop_item(DVBobject): def pack(self): fmt = "!HB" return pack(fmt, self.service_ID, self.service_type, ) class service_list_descriptor(Descriptor): descriptor_tag = 0x41 def bytes(self): dvb_service_bytes = string.join( map(lambda x: x.pack(), self.dvb_service_descriptor_loop), "") FMT = "!%ds" % len(dvb_service_bytes) return pack(FMT, dvb_service_bytes, ) ###################################################################### class registration_descriptor(Descriptor): descriptor_tag = 0x05 def bytes(self): fmt = "!%ds" % len(self.format_identifier) return pack(fmt, self.format_identifier ) ###################################################################### class lcn_service_descriptor_loop_item(DVBobject): def pack(self): fmt = "!HH" return pack(fmt, self.service_ID, ((self.visible_service_flag << 15) | 0x7C00 | self.logical_channel_number), ) class logical_channel_descriptor(Descriptor): descriptor_tag = 0x83 def bytes(self): lcn_service_bytes = string.join( map(lambda x: x.pack(), self.lcn_service_descriptor_loop), "") FMT = "!%ds" % len(lcn_service_bytes) return pack(FMT, lcn_service_bytes, ) #################################################################### class logical_channel_descriptor_v2(Descriptor): descriptor_tag = 0x87 def bytes(self): lcn_service_bytes = string.join( map(lambda x: x.pack(), self.lcn_service_descriptor_loop), "") FMT = "!BB%ds%dsB%ds" % (len(self.channel_list_name), len(self.country_code), len(lcn_service_bytes)) return pack(FMT, self.channel_list_id, len(self.channel_list_name), self.channel_list_name, self.country_code, len(lcn_service_bytes), lcn_service_bytes, ) ###################################################################### class component_descriptor(Descriptor): descriptor_tag = 0x50 def bytes(self): fmt = "!BBB%ds%ds" % ( len(self.ISO_639_language_code), len(self.text_char), ) return pack(fmt, 0xF0 | (self.stream_content), self.component_type, self.component_tag, self.ISO_639_language_code, self.text_char, ) ###################################################################### class PDC_descriptor(Descriptor): descriptor_tag = 0x69 def bytes(self): fmt = "!BH" return pack(fmt, (0xF0) | (self.day >> 1), (self.day << 15) | (self.month << 11) | (self.hour << 6) | (self.minute), ) # # Copyright (C) 2004 Andreas Berger, berger@ftw.at # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA class ip_mac_platform_name_descriptor(Descriptor): descriptor_tag = 0x0c def bytes(self): fmt = "!3s%ds" % len(self.text_char_bytes) return pack(fmt, self.ISO_639_language_code, self.text_char_bytes ) class ip_mac_platform_provider_name_descriptor(Descriptor): descriptor_tag = 0x0d def bytes(self): fmt = "!3s%ds" % len(self.text_char_bytes) return pack(fmt, self.ISO_639_language_code, self.text_char_bytes ) class target_serial_number_descriptor(Descriptor): descriptor_tag = 0x08 def bytes(self): fmt = "!%ds" % len(serial_data_bytes) return pack(fmt, self.serial_data_bytes ) class target_smartcard_descriptor(Descriptor): descriptor_tag = 0x06 def bytes(self): fmt = "!I%ds" % len(self.private_data_bytes) return pack(fmt, self.super_CA_system_id, self.private_data_bytes ) class subtitling_data_descriptor_loop_item(DVBobject): def pack(self): fmt = "!%dsBHH" % len(self.ISO_639_language_code) return pack(fmt, self.ISO_639_language_code, self.subtitling_type, self.composition_page_id, self.ancillary_page_id, ) class subtitling_descriptor(Descriptor): descriptor_tag = 0x59 def bytes(self): data_bytes = string.join( map(lambda x: x.pack(), self.subtitling_data_descriptor_loop), "") fmt = "!B%ds" % len(data_bytes) return pack(fmt, len(data_bytes), data_bytes, ) class target_MAC_address_descriptor(Descriptor): descriptor_tag = 0x07 def bytes(self): fmt = "!6s%ds" % len(self.mac_addr_bytes) return pack(fmt, self.mac_addr_mask, self.mac_addr_bytes ) class target_MAC_address_range_descriptor(Descriptor): descriptor_tag = 0x0e def bytes(self): fmt = "!6s%ds" % len(self.mac_addr_bytes) return pack(fmt, self.mac_addr_mask, self.mac_addr_bytes ) class target_IP_address_descriptor(Descriptor): descriptor_tag = 0x09 def bytes(self): fmt = "!I%dI" % len(self.IPv4_addr_bytes) return pack(fmt, self.IPv4_addr_mask, self.IPv4_addr_bytes ) class target_IP_slash_descriptor(Descriptor): descriptor_tag = 0x0f def bytes(self): fmt = "!4BB" return pack(fmt, self.IPv4_addr[0], self.IPv4_addr[1], self.IPv4_addr[2], self.IPv4_addr[3], self.IPv4_slash_mask ) class target_IP_source_slash_descriptor(Descriptor): descriptor_tag = 0x10 def bytes(self): fmt = "!%ds" % len(self.IPv4_source_dest_bytes) return pack(fmt, self.IPv4_source_dest_bytes ) class target_IPv6_address_descriptor(Descriptor): descriptor_tag = 0x0a def bytes(self): fmt = "!7s%ds" % len(self.IPv6_address_bytes) return pack(fmt, self.IPv6_address_mask, self.IPv6_address_bytes ) class target_IPv6_slash_descriptor(Descriptor): descriptor_tag = 0x11 def bytes(self): fmt = "!%ds" % len(self.IPv6_bytes) return pack(fmt, self.IPv6_bytes ) class target_IPv6_source_slash_descriptor(Descriptor): descriptor_tag = 0x12 def bytes(self): fmt = "!%ds" % len(self.IPv6_source_dest_bytes) return pack(fmt, self.IPv6_source_dest_bytes ) class ip_mac_stream_location_descriptor(Descriptor): descriptor_tag = 0x13 def bytes(self): fmt = "!HHHHB" return pack(fmt, self.network_id, self.original_network_id, self.transport_stream_id, self.service_id, self.component_tag ) class isp_access_mode_descriptor(Descriptor): descriptor_tag = 0x14 def bytes(self): fmt = "!B" return pack(fmt, self.access_mode ) class telephone_descriptor(Descriptor): descriptor_tag = 0x57 def bytes(self): fmt = "!BBBB%ds%ds%ds%ds%ds" % (len(country_prefix_bytes), len(international_area_code_bytes), len(operator_code_bytes), len(national_area_code_bytes), len(core_number_bytes)) return pack(fmt, (0x03 << 7) & 0xC0 | (self.foreign_availability << 5) & 0x20 | self.connection_type & 0x1F, (0x01 << 7) & 0x80 | (self.country_prefix_length << 5) & 0x60 | (self.international_area_code << 4) & 0x1C | self.operator_code_length & 0x07, (0x01 << 7) & 0x80 | (self.national_area_code_length << 4) & 0x70 | self.core_number_length & 0x0F, country_prefix_bytes, international_area_code_bytes, operator_code_bytes, national_area_code_bytes, core_number_bytes ) class private_data_specifier_descriptor(Descriptor): descriptor_tag = 0x5f def bytes(self): fmt = "!I" return pack(fmt, self.private_data_specifier ) class time_slice_fec_identifier_descriptor(Descriptor): descriptor_tag = 0x77 def bytes(self): time_slice_fec_id = 0x00; fmt = "!BBB" return pack(fmt, (self.time_slicing << 7) & 0x80 | (self.mpe_fec << 5) & 0x60 | (0x03 << 3) | self.frame_size & 0x07, self.max_burst_duration, (self.max_average_rate << 4) & 0xF0 | time_slice_fec_id & 0x0F, ) # FIXME: move this class to another file, it's no descriptor class platform_id_data2(DVBobject): def pack(self): fmt = "!BBBBB" return pack(fmt, (self.platform_id >> 16) & 0xFF, (self.platform_id >> 8) & 0xFF, self.platform_id & 0xFF, self.action_type & 0xFF, (0x03 << 6) & 0xC0 | (0x00 << 5) & 0x20 | 0x01 & 0x1F ) # FIXME: move this class to another file, it's no descriptor class ip_mac_notification_info(DVBobject): def pack(self): # pack platform id data loop pid_bytes = string.join( map(lambda x: x.pack(), self.platform_id_data_loop), "") platform_id_data_length = len(pid_bytes); fmt = "!B%ds%ds" % (platform_id_data_length, len(self.private_data_bytes)) return pack(fmt, platform_id_data_length, pid_bytes, self.private_data_bytes ) # FIXME: move this class to another file, it's no descriptor class platform_name(DVBobject): def pack(self): platform_name_length = len(self.text_char_bytes) fmt = "!3sB%ds" % platform_name_length return pack(fmt, self.ISO_639_language_code, platform_name_length, self.text_char_bytes ) # FIXME: move these classes to another file, they are no exactly descriptors class platform_id_data(DVBobject): def pack(self): pn_bytes = string.join( map(lambda x: x.pack(), self.platform_name_loop), "") platform_name_loop_length = len(pn_bytes) fmt = "!BBBB%ds" % platform_name_loop_length return pack(fmt, (self.platform_id >> 16) & 0xFF, (self.platform_id >> 8) & 0xFF, self.platform_id & 0xFF, platform_name_loop_length, pn_bytes ) class OUI_data(DVBobject): def pack(self): fmt = "!HBB%ds" % len(self.selector_bytes) return pack(fmt, self.OUI >> 8, self.OUI & 0xFF, len(self.selector_bytes), self.selector_bytes, ) class OUI_info_loop_item(DVBobject): def pack(self): fmt = "!HBBBB%ds" % len(self.selector_bytes) return pack(fmt, self.OUI >> 8, self.OUI & 0xFF, 0xF0 | self.update_type & 0xF, 0xC0 | (self.update_versioning_flag & 0x1) << 5 | self.update_version & 0x1F, len(self.selector_bytes), self.selector_bytes, ) class compatibility_descriptor_loop_item(DVBobject): def pack(self): number_descriptors = len(self.compatibility_descriptor_subloop) compatibility_descriptor_subloop_bytes = string.join( map(lambda x: x.pack(), self.compatibility_descriptor_subloop), "") fmt = "!BBBBBBHHB%ds" % len(compatibility_descriptor_subloop_bytes) return pack(fmt, self.descriptor_type, 9 + len(compatibility_descriptor_subloop_bytes), self.specifier_type, (self.specifier_data >> 16) & 0xFF, (self.specifier_data >> 8) & 0xFF, self.specifier_data & 0xFF, self.model, self.version, number_descriptors, compatibility_descriptor_subloop_bytes, ) class compatibility_descriptor(DVBobject): def pack(self): number_descriptors = len(self.compatibility_descriptor_loop) compatibility_descriptor_loop_bytes = string.join( map(lambda x: x.pack(), self.compatibility_descriptor_loop), "") fmt = "!H%ds" % len(compatibility_descriptor_loop_bytes) return pack(fmt, number_descriptors, compatibility_descriptor_loop_bytes, ) class linkage_descriptor(Descriptor): descriptor_tag = 0x4A; def bytes(self): if (self.linkage_type == 0x0B): # pack platform id data loop pid_bytes = string.join( map(lambda x: x.pack(), self.platform_id_data_loop), "") platform_id_data_length = len(pid_bytes); fmt = "!BBBBBBBB%ds%ds" % (platform_id_data_length, len(self.private_data_bytes)) return pack(fmt, (self.transport_stream_id >> 8) & 0xFF, self.transport_stream_id & 0xFF, (self.original_network_id >> 8) & 0xFF, self.original_network_id & 0xFF, (self.service_id >> 8) & 0xFF, self.service_id & 0xFF, self.linkage_type, platform_id_data_length, pid_bytes, self.private_data_bytes ) elif (self.linkage_type == 0x09): # pack oui data loop oui_data_bytes = string.join( map(lambda x: x.pack(), self.OUI_loop), "") oui_data_length = len(oui_data_bytes); fmt = "!BBBBBBBB%ds%ds" % (oui_data_length, len(self.private_data_bytes)) return pack(fmt, (self.transport_stream_id >> 8) & 0xFF, self.transport_stream_id & 0xFF, (self.original_network_id >> 8) & 0xFF, self.original_network_id & 0xFF, (self.service_id >> 8) & 0xFF, self.service_id & 0xFF, self.linkage_type, oui_data_length, oui_data_bytes, self.private_data_bytes ) elif (self.linkage_type == 0x0A): fmt = "!BBBBBBBB%ds" % len(self.private_data_bytes) return pack(fmt, (self.transport_stream_id >> 8) & 0xFF, self.transport_stream_id & 0xFF, (self.original_network_id >> 8) & 0xFF, self.original_network_id & 0xFF, (self.service_id >> 8) & 0xFF, self.service_id & 0xFF, self.linkage_type, self.table_type, self.private_data_bytes ) else: fmt = "!BBBBBBB%ds" % len(self.private_data_bytes) # we care only for some linkage_type, other linkage descriptors # have to be implemented according to ETSI EN 300 468 standard return pack(fmt, (self.transport_stream_id >> 8) & 0xFF, self.transport_stream_id & 0xFF, (self.original_network_id >> 8) & 0xFF, self.original_network_id & 0xFF, (self.service_id >> 8) & 0xFF, self.service_id & 0xFF, self.linkage_type, self.private_data_bytes ) class terrestrial_delivery_system_descriptor(Descriptor): descriptor_tag = 0x5a def bytes(self): fmt = "!LBBBL" priority = 1 timeslice_ind = 1 mpe_fec_ind = 1 return pack(fmt, self.center_frequency & 0xFFFFFFFF, (self.bandwidth << 5) & 0xE0 | (self.priority << 4) & 0x10 | (self.timeslice_ind << 3) & 0x08 | (self.mpe_fec_ind << 2) & 0x04 | 0x03, (self.constellation << 6) | (self.hierarchy_information << 3)| (self.code_rate_HP_stream), (self.code_rate_LP_stream << 5) | (self.guard_interval << 3) | (self.transmission_mode << 1) | (self.other_frequency_flag), 0xffffffff, ) ###################################################################### class crid_descriptor_loop_item(DVBobject): def pack(self): if (self.location == 0x0): fmt = "!BB%ds" % len(self.crid) return pack(fmt, (self.type & 0x3F) << 2 | (self.location), len(self.crid), self.crid, ) else: fmt = "!BH" return pack(fmt, (self.type & 0x3F) << 2 | (self.location & 0x3), self.crid_ref, ) class content_identifier_descriptor(Descriptor): descriptor_tag = 0x76 def bytes(self): crid_bytes = string.join( map(lambda x: x.pack(), self.crid_descriptor_loop), "") FMT = "!%ds" % len(crid_bytes) return pack(FMT, crid_bytes, ) class ssu_location_descriptor(Descriptor): descriptor_tag = 0x03 def bytes(self): if (self.data_broadcast_id == 0x000A): FMT = "!HH%ds" % len(self.private_data_bytes) return pack(FMT, self.data_broadcast_id, self.association_tag, self.private_data_bytes, ) else: FMT = "!H%ds" % len(self.private_data_bytes) return pack(FMT, self.data_broadcast_id, self.private_data_bytes, ) class scheduling_descriptor(Descriptor): descriptor_tag = 0x01 def bytes(self): FMT = "!HBBBHBBBBBBB%ds" % len(self.private_data_bytes) return pack(FMT, MJD_convert(self.year_of_start_date_time, self.month_of_start_date_time, self.day_of_start_date_time), self.hour_of_start_date_time, self.minute_of_start_date_time, self.second_of_start_date_time, MJD_convert(self.year_of_end_date_time, self.month_of_end_date_time, self.day_of_end_date_time), self.hour_of_end_date_time, self.minute_of_end_date_time, self.second_of_end_date_time, self.final_availability << 7 | self.Periodicity_flag << 6 | self.period_unit << 4 | self.duration_unit << 2 | self.estimated_cycle_time_unit, self.Period, self.Duration, self.estimated_cycle_time, self.private_data_bytes, ) ###################################################################### class default_authority_descriptor(Descriptor): descriptor_tag = 0x73 def bytes(self): fmt = "!%ds" % len(self.authority) return pack(fmt, self.authority, ) ###################################################################### class extended_event_loop_item(DVBobject): def pack(self): fmt = "!B%dsB%ds" % (len(self.item_description), len(self.item)) return pack(fmt, len(self.item_description), self.item_description, len(self.item), self.item, ) class extended_event_descriptor(Descriptor): descriptor_tag = 0x4E def bytes(self): item_bytes = string.join( map(lambda x: x.pack(), self.extended_event_loop), "") assert len(self.ISO639_language_code) == 3 FMT = "!B%dsB%dsB%ds" % (len(self.ISO639_language_code), len(item_bytes), len(self.text)) return pack(FMT, (self.descriptor_number & 0xF) << 4 | (self.last_descriptor_number & 0xF), self.ISO639_language_code, len(item_bytes), item_bytes, len(self.text), self.text, ) ###################################################################### class ac3_descriptor(Descriptor): descriptor_tag = 0x6A def bytes(self): fmt = "!B" flags_flag = 0 flags = "" if self.component_type_flag == 1: flags = pack("!B", self.component_type) flags_flag = 1 if self.bsid_flag == 1: flags = flags + pack("!B", self.bsid) flags_flag = 1 if self.mainid_flag == 1: flags = flags + pack("!B", self.mainid) flags_flag = 1 if self.asvc_flag == 1: flags = flags + pack("!B", self.asvc) flags_flag = 1 if flags_flag == 0 : fmt = (fmt + "%ds") % len(self.additional_info) return pack(fmt, (self.component_type_flag & 0x1) << 7 | (self.bsid_flag & 0x1) << 6 | (self.mainid_flag & 0x1) << 5 | (self.asvc_flag & 0x1) << 4, self.additional_info ) else : fmt = (fmt + "%ds%ds") % (len(flags), len(self.additional_info)) return pack(fmt, (self.component_type_flag & 0x1) << 7 | (self.bsid_flag & 0x1) << 6 | (self.mainid_flag & 0x1) << 5 | (self.asvc_flag & 0x1) << 4, flags, self.additional_info ) ###################################################################### class dts_audio_stream_descriptor(Descriptor): descriptor_tag = 0x7B def bytes(self): fmt = "!BBBBB%ds" % len(self.additional_info) return pack(fmt, ((self.sample_rate_code & 0xF) << 4) | ((self.bit_rate_code >> 2) & 0xF), ((self.bit_rate_code & 0x3) << 6) | ((self.nblks >> 1) & 0x3F), ((self.nblks & 0x1) << 7) | ((self.fsize >> 7) & 0x7F), ((self.fsize & 0x7F) << 1) | ((self.surround_mode >> 5) & 0x1), ((self.surround_mode & 0x1F) << 3) | ((self.lfe_flag & 0x1) << 2) | (self.extendend_surround_flag & 0x3), self.additional_info ) ###################################################################### class ISO_639_language_descriptor(Descriptor): descriptor_tag = 0x0A def bytes(self): fmt = "!%dsB" % ( len(self.ISO_639_language_code), ) return pack(fmt, self.ISO_639_language_code, self.Audio_type, ) ###################################################################### class supplementary_audio_descriptor(Descriptor): descriptor_tag = 0x7F; def bytes(self): descriptor_tag_extension = 0x06; fmt = "!BB%ds%ds" % (len(self.ISO_639_language_code),len(self.private_data_bytes)) return pack(fmt, descriptor_tag_extension, (self.mix_type & 0x1) << 7 | (self.editorial_classification & 0x1F) << 2 | 0x3, self.ISO_639_language_code, self.private_data_bytes, ) ###################################################################### class private_data_descriptor(Descriptor): descriptor_tag = 0x0F def bytes(self): fmt = "!" return pack(fmt) ###################################################################### class bouquet_descriptor(Descriptor): descriptor_tag = 0x47 def bytes(self): fmt = "!%ds" % len(self.bouquet_name) return pack( fmt, self.bouquet_name, ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/DVB/DataCarousel.py0000755000175000017500000001342612214326456023664 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright 2000-2001, GMD, Sankt Augustin # -- German National Research Center for Information Technology # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import os import string from dvbobjects.utils import * from dvbobjects.DSMCC.Message import * import dvbobjects.DSMCC.BIOP from Loops import * ###################################################################### class SuperGroup(DownloadServerInitiate): def __init__(self, PATH, transactionId, version): self.groups = [] self.PATH = PATH self.transactionId = transactionId self.version_number = version def addGroup(self, group): self.groups.append(group) def generate(self, output_dir, SRG_IOR = None): for group in self.groups: group.generate(output_dir) if SRG_IOR <> None: self.privateData = dvbobjects.DSMCC.BIOP.ServiceGatewayInfo( srg_ior = SRG_IOR, ) else: self.privateData = GroupInfoIndication(self) sec_file = open("%s/DSI.sec" % output_dir, "wb") sec_file.write(self.pack()) sec_file.close() ###################################################################### class Group(DownloadInfoIndication): def __init__(self, PATH, transactionId, version, downloadId, blockSize): self.modules = [] self.descriptors = [] self.PATH = PATH self.downloadId = downloadId self.transactionId = transactionId self.version_number = version self.blockSize = blockSize def addModule(self, mod): self.modules.append(mod) def getGroupInfo(self): return GroupInfo( groupId = self.transactionId, groupSize = self.groupSize, groupCompatibility = self.compatibilityDescriptor, descriptors = self.descriptors, ) def generate(self, output_dir): self.groupSize = 0 for module in self.modules: module.downloadId = self.downloadId module.generate( output_dir, self.transactionId, self.blockSize, ) self.groupSize = self.groupSize + module.moduleSize self.__mii = mii = ModuleInfoIndication(self) self.moduleInfoIndication = mii path = os.path.basename(self.PATH) stem = os.path.splitext(path)[0] sec_file = open("%s/%s.sec" % (output_dir, stem), "wb") sec_file.write(self.pack()) sec_file.close() ###################################################################### class Module(DVBobject): assocTag = None # i.e. NO Object Carousel descriptors = [] def generate(self, output_dir, transactionId, blockSize): lastBlockNumber = -1 self.moduleSize = os.stat(self.INPUT)[6] last_section_number = ((self.moduleSize - 1) / blockSize) % 256 tmp = ((((self.moduleSize - 1) / blockSize) / 256) * 256) - 1 input = open(self.INPUT, "rb") while 1: data = input.read(blockSize) if not data: break lastBlockNumber = lastBlockNumber + 1 if tmp >= lastBlockNumber: block = DownloadDataBlock( moduleId = self.moduleId, moduleVersion = self.moduleVersion, downloadId = self.downloadId, data_block = data, blockNumber = lastBlockNumber, section_number = lastBlockNumber % 256, last_section_number = 0xFF, ) else: block = DownloadDataBlock( moduleId = self.moduleId, moduleVersion = self.moduleVersion, downloadId = self.downloadId, data_block = data, blockNumber = lastBlockNumber, section_number = lastBlockNumber % 256, last_section_number = last_section_number, ) ofn = self.__outputFilename( self.INPUT, output_dir, block.blockNumber) open(ofn, "wb").write(block.pack()) def __outputFilename(self, input_path, output_dir, blockNumber): input_basename = os.path.basename(input_path) input_stem = os.path.splitext(input_basename)[0] output_basename = "%s_%06d.%s" % ( input_stem, blockNumber, "sec", ) output_path = os.path.join( output_dir, output_basename) return output_path def getModuleInfo(self): if self.assocTag <> None: moduleInfo = dvbobjects.DSMCC.BIOP.ModuleInfo( assocTag = self.assocTag, userInfo = self.descriptors, ) else: moduleInfo = "" modInfo = ModuleInfo( moduleId = self.moduleId, moduleSize = self.moduleSize, moduleVersion = self.moduleVersion, descriptors = self.descriptors, moduleInfo = moduleInfo, ) return modInfo opencaster-3.2.2/libs/dvbobjects/dvbobjects/DVB/__init__.py0000755000175000017500000000157112214326456023052 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright 2000-2001, GMD, Sankt Augustin # -- German National Research Center for Information Technology # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA opencaster-3.2.2/libs/dvbobjects/dvbobjects/DVB/Loops.py0000755000175000017500000001335312214326456022410 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright 2000-2001, GMD, Sankt Augustin # -- German National Research Center for Information Technology # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.utils import * from dvbobjects.MPEG.Descriptor import Descriptor ###################################################################### class GroupInfoIndication(DVBobject): privateData = "" def __init__(self, superGroup): self.numberOfGroups = len(superGroup.groups) self.groupInfos = [] for group in superGroup.groups: self.groupInfos.append(group.getGroupInfo()) def pack(self): infos = string.join(map(lambda i: i.pack(), self.groupInfos), "") FMT = ("!" "H" # NumberOfGroups "%ds" # group infos "H%ds" # privateData ) % (len(infos), len(self.privateData)) return pack(FMT, len(self.groupInfos), infos, len(self.privateData), self.privateData, ) ###################################################################### class GroupInfo(DVBobject): def pack(self): self.groupInfo = string.join(map(lambda d: d.pack(), self.descriptors), "") FMT = ("!" "L" # groupId "L" # groupSize "H%ds" # groupCompatibility "H%ds" # groupInfo ) % ( len(self.groupCompatibility), len(self.groupInfo), ) return pack(FMT, self.groupId, self.groupSize, len(self.groupCompatibility), self.groupCompatibility, len(self.groupInfo), self.groupInfo, ) ###################################################################### class ModuleInfoIndication(DVBobject): def __init__(self, group): self.numberOfModules = len(group.modules) self.moduleInfos = [] for module in group.modules: self.moduleInfos.append(module.getModuleInfo()) def pack(self): infos = string.join(map(lambda i: i.pack(), self.moduleInfos), "") FMT = ("!" "H" # NumberOfModules "%ds" # module infos ) % len(infos) return pack(FMT, len(self.moduleInfos), infos, ) ###################################################################### class ModuleInfo(DVBobject): def pack(self): if self.moduleInfo: moduleInfoBytes = self.moduleInfo.pack() elif self.moduleInfo == "" and len(self.descriptors) == 0: moduleInfoBytes = "" else: moduleInfoBytes = string.join( map(lambda d: d.pack(), self.descriptors), "") FMT = ("!" "H" # moduleId "L" # moduleSize "B" # moduleVersion "B%ds" # moduleInfo ) % ( len(moduleInfoBytes), ) return pack(FMT, self.moduleId, self.moduleSize, self.moduleVersion, len(moduleInfoBytes), moduleInfoBytes, ) ################################################################### class name_descriptor(Descriptor): descriptor_tag = 0x02 def bytes(self): self.name_length = len(self.name) fmt ="!%ds" % self.name_length return pack(fmt, self.name, ) ################################################################### class compressed_descriptor(Descriptor): descriptor_tag = 0x09 def bytes(self): compression_method = 0x08 sizeFile = "%s.size" % self.name items = string.split(open(sizeFile).readline()) original_size = eval(items[0]) # print("module size %d" % original_size) fmt ="!BL" return pack(fmt, compression_method, original_size, ) ################################################################### class crc32_descriptor(Descriptor): descriptor_tag = 0x05 def bytes(self): fmt = "!L" return pack(fmt, self.calc_crc32) ################################################################### class ssu_module_type_descriptor(Descriptor): descriptor_tag = 0x0A def bytes(self): fmt = "!B" return pack(fmt, self.module_type) opencaster-3.2.2/libs/dvbobjects/dvbobjects/utils/0000755000175000017500000000000012214326456021457 5ustar debiandebianopencaster-3.2.2/libs/dvbobjects/dvbobjects/utils/ByteParity.py0000755000175000017500000000330612214326456024132 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright © 2009-2013 Lorenzo Pallara l.pallara@avalpa.com # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA from numpy import * oddParity = array([ 0x80, 0x01, 0x02, 0x83, 0x04, 0x85, 0x86, 0x07, 0x08, 0x89, 0x8a, 0x0b, 0x8c, 0x0d, 0x0e, 0x8f, 0x10, 0x91, 0x92, 0x13, 0x94, 0x15, 0x16, 0x97, 0x98, 0x19, 0x1a, 0x9b, 0x1c, 0x9d, 0x9e, 0x1f, 0x20, 0xa1, 0xa2, 0x23, 0xa4, 0x25, 0x26, 0xa7, 0xa8, 0x29, 0x2a, 0xab, 0x2c, 0xad, 0xae, 0x2f, 0xb0, 0x31, 0x32, 0xb3, 0x34, 0xb5, 0xb6, 0x37, 0x38, 0xb9, 0xba, 0x3b, 0xbc, 0x3d, 0x3e, 0xbf, 0x40, 0xc1, 0xc2, 0x43, 0xc4, 0x45, 0x46, 0xc7, 0xc8, 0x49, 0x4a, 0xcb, 0x4c, 0xcd, 0xce, 0x4f, 0xd0, 0x51, 0x52, 0xd3, 0x54, 0xd5, 0xd6, 0x57, 0x58, 0xd9, 0xda, 0x5b, 0xdc, 0x5d, 0x5e, 0xdf, 0xe0, 0x61, 0x62, 0xe3, 0x64, 0xe5, 0xe6, 0x67, 0x68, 0xe9, 0xea, 0x6b, 0xec, 0x6d, 0x6e, 0xef, 0x70, 0xf1, 0xf2, 0x73, 0xf4, 0x75, 0x76, 0xf7, 0xf8, 0x79, 0x7a, 0xfb, 0x7c, 0xfd, 0xfe, 0x7f, ]) def oddparity(byte): byte = byte & 0x7F return oddParity[byte] opencaster-3.2.2/libs/dvbobjects/dvbobjects/utils/ByteInvert.py0000755000175000017500000000465612214326456024142 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright © 2009-2103 Lorenzo Pallara # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA from numpy import * inverted = array([ 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4, 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC, 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2, 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA, 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6, 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE, 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1, 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9, 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5, 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD, 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3, 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB, 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7, 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF ]) def invert(byte): byte = byte & 0xFF return inverted[byte] opencaster-3.2.2/libs/dvbobjects/dvbobjects/utils/MJD.py0000755000175000017500000000204112214326456022443 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright © 2005-2013 Lorenzo Pallara l.pallara@avalpa.com # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA from math import floor def MJD_convert(year, month, day): if (month == 1) or (month == 2): l = 1 else: l = 0 return 14956 + day + (floor((year - l) * 365.25)) + (floor((month + 1 + l * 12) * 30.6001)) opencaster-3.2.2/libs/dvbobjects/dvbobjects/utils/DVBobject.py0000755000175000017500000000644412214326456023646 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright 2000-2001, GMD, Sankt Augustin # -- German National Research Center for Information Technology # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string import pprint ###################################################################### def CDR(s, alignment = 4, gap_byte = 0xFF): """If necessary, append to 's' a trailing NUL byte and fill with 'gap_byte' until properly aligned. """ if len(s) % alignment == 0 and s[-1] in ("\x00", "\xFF"): return s s = s + "\x00" while len(s) % alignment: s = s + chr(gap_byte) return s ###################################################################### class DVBobject: """The base class for many protocol data units. Basically it provides functionality similar to a C-struct. Members are set via keyword arguments either in the constructor or via the set() method. Other (rather static) attributes can be defined as (sub-)class attributes. Subclasses must implement a 'pack()' method which returns the properly packed byte string. Attributes may come from the following sources: 1. (Static) class attributes; 2. Keyword arguments given in the constructor; 3. Keyword arguments given in the 'set()' method; 4. Direct assignment to instance attributes (NOT recommended). """ # # Default attribute value. # Subclasses can do that, too! # ISO_639_language_code = "deu" def __init__(self, **kwargs): """Initialize instance attributes from keyword arguments. """ apply(self.set, (), kwargs) def set(self, **kwargs): """Add (more) instance attributes from keyword arguments. """ for k, v in kwargs.items(): setattr(self, k, v) def __repr__(self): """Used for debugging.""" def hilite(s): return "### %s ###" % s return pprint.pformat( (hilite(self.__class__.__name__), self.__dict__)) def dump(self): """Print a simple hexdump of this object to stdout. """ BYTES_PER_LINE = 16 bytes = self.pack() i = 0 for byte in bytes: if i % BYTES_PER_LINE == 0: if i: print # start on a fresh line... print "%04x " % i, print "%02X" % ord(byte), i = i+1 print # dump is done => NL def test(self): """Used for debugging.""" if not self.__dict__: self.sample() self.dump() print self opencaster-3.2.2/libs/dvbobjects/dvbobjects/utils/crc32.py0000755000175000017500000000026412214326456022752 0ustar debiandebian#! /usr/bin/env python def CRC_32(data): return 0xFFFFFFFF try: import _crc32 CRC_32 = _crc32.sectioncrc except ImportError: print "### WRONG CRC32!!!" pass opencaster-3.2.2/libs/dvbobjects/dvbobjects/utils/SpecFile.py0000755000175000017500000001005512214326456023527 0ustar debiandebian#! /usr/bin/env python # # Copyright © 2000-2001, GMD, Sankt Augustin # -- German National Research Center for Information Technology # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.utils import * ###################################################################### class SuperGroupSpec(DVBobject): def read(self, filename): self.PATH = filename file = open(filename) items = string.split(file.readline()) self.transactionId = eval(items[0]) self.version = eval(items[1]) fn = items[1] if fn == "None": self.srg_ior = None else: self.srg_ior = open(items[2]).read() self.groups = [] while (1): line = file.readline() if not line: break group = GroupSpec() #print repr(line) group.read(line) self.groups.append(group) def write(self, outputDir): specFile = "%s/DSI.spec" % outputDir dsi = open(specFile, "wb") dsi.write("0x%08X 0x%08X %s\n" % ( int(self.transactionId), self.version, self.srg_ior, )) for group in self.groups: group.write(dsi, outputDir) def addGroup(self, **kwargs): group = apply(GroupSpec, [], kwargs) try: self.groups.append(group) except AttributeError: self.groups = [group] def addModule(self, **kwargs): curr = self.groups[-1] apply(GroupSpec.addModule, (curr,), kwargs) ###################################################################### class GroupSpec(DVBobject): def read(self, specline): items = string.split(specline) self.PATH=items[0] #print repr(items[0]) diiSpecFile = open(items[0]) self.transactionId = eval(items[1]) self.version = eval(items[2]) self.downloadId = eval(items[3]) if len(items) == 6: self.assocTag = eval(items[4]) self.blockSize = eval(items[5]) else: self.assocTag = None self.blockSize = eval(items[6]) self.modules = [] while 1: line = diiSpecFile.readline() if not line: break mod = ModuleSpec() mod.read(line) self.modules.append(mod) def write(self, specFile, outputDir): specFile.write( "%s 0x%08X 0x%08X 0x%08X 0x%04X %4d\n" % ( "%s/DII.spec" % outputDir, int(self.transactionId), self.version, self.downloadId, self.assocTag, self.blockSize, )) def addModule(self, **kwargs): mod = apply(ModuleSpec, (), kwargs) try: self.modules.append(mod) except AttributeError: self.modules = [mod] ###################################################################### class ModuleSpec(DVBobject): def read(self, specline): items = string.split(specline) #print repr(items[0]) #print repr(items[1]) self.INPUT = items[0] self.tableid = eval(items[1]) self.moduleId = eval(items[2]) self.moduleVersion = eval(items[3]) ###################################################################### opencaster-3.2.2/libs/dvbobjects/dvbobjects/utils/Hamming.py0000755000175000017500000000202612214326456023414 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright © 2009-2013 Lorenzo Pallara l.pallara@avalpa.com # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA from numpy import * ham84 = array([0x15, 0x02, 0x49, 0x5E, 0x64, 0x73, 0x38, 0x2F, 0xD0, 0xC7, 0x8C, 0x9B, 0xA1, 0xB6, 0xFD, 0xEA ]) def hamming84(nibble): nibble = nibble & 0xF return ham84[nibble] opencaster-3.2.2/libs/dvbobjects/dvbobjects/utils/__init__.py0000755000175000017500000000172612214326456023601 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright © 2000-2001, GMD, Sankt Augustin # -- German National Research Center for Information Technology # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA from struct import pack, unpack, calcsize from DVBobject import DVBobject, CDR import crc32 opencaster-3.2.2/libs/dvbobjects/dvbobjects/PSI/0000755000175000017500000000000012220025305020734 5ustar debiandebianopencaster-3.2.2/libs/dvbobjects/dvbobjects/PSI/ATSC_EIT.py0000755000175000017500000000471012215267372022566 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright © 2005-2013 Lorenzo Pallara l.pallara@avalpa.com # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.MPEG.Section import Section from dvbobjects.utils.MJD import * from dvbobjects.ATSC.Descriptors import * from dvbobjects.ATSC.Loops import * ###################################################################### class event_information_section(Section): table_id = 0xCB section_max_size = 4093 def pack_section_body(self): self.table_id_extension = self.source_id self.protocol_version = 0 self.num_events_in_section = len(self.event_loop) # pack event_loop el_bytes = string.join( map(lambda x: x.pack(), self.event_loop), "") fmt = "!BB%ds" % len(el_bytes) return pack(fmt, self.protocol_version, self.num_events_in_section, el_bytes, ) ###################################################################### class event_loop_item(DVBobject): def pack(self): # pack event_descriptor_loop event_descriptors_bytes = string.join( map(lambda x: x.pack(), self.descriptor_loop), "") title_text_bytes = self.title_text.pack() fmt = "!HLBHB%dsH%ds" % (len(title_text_bytes), len(event_descriptors_bytes)) return pack(fmt, (0x3 << 14) | (self.event_id & 0x3FFF), self.start_time, (0x3 << 6) | ((self.ETM_location & 0x3) << 4) | ((self.length_in_seconds >> 16) & 0xF), (self.length_in_seconds & 0xFFFF), len(title_text_bytes), title_text_bytes, (0xF << 12) | (len(event_descriptors_bytes) & 0x0FFF), event_descriptors_bytes, ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/PSI/TOT.py0000755000175000017500000000326112214326456021777 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright © 2009-2013 Lorenzo Pallara l.pallara@avalpa.com # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.utils import * from dvbobjects.utils.DVBobject import * from dvbobjects.utils.MJD import * from dvbobjects.MPEG.Section import Section from dvbobjects.utils import * from dvbobjects.DVB.Descriptors import * ###################################################################### class time_offset_section(DVBobject): def pack(self): date = MJD_convert(self.year, self.month, self.day) # pack service_stream_loop tl_bytes = string.join( map(lambda x: x.pack(), self.descriptor_loop), "") fmt = "!BHHBBBH%ds" % len(tl_bytes) data = pack(fmt, 0x73, 0x7000 | ((len(tl_bytes) + 11) & 0xFFF), date, self.hour, self.minute, self.second, 0xF000 | (len(tl_bytes) & 0xFFF), tl_bytes ) return data + self.crc_32(data) def crc_32(self, data): crc = crc32.CRC_32(data) return pack("!L", crc) opencaster-3.2.2/libs/dvbobjects/dvbobjects/PSI/SDT.py0000755000175000017500000000541712214326456021770 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright © 2004-2013 Lorenzo Pallara l.pallara@avalpa.com # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.MPEG.Section import Section from dvbobjects.utils import * from dvbobjects.DVB.Descriptors import * ###################################################################### class service_description_section(Section): table_id = 0x42 section_max_size = 1024 def pack_section_body(self): self.table_id_extension = self.transport_stream_id self.private_indicator = 1 # pack service_stream_loop sl_bytes = string.join( map(lambda x: x.pack(), self.service_loop), "") fmt = "!HB%ds" % len(sl_bytes) return pack(fmt, self.original_network_id, 0xFF, sl_bytes, ) ###################################################################### class service_description_other_ts_section(Section): table_id = 0x46 section_max_size = 1024 def pack_section_body(self): self.table_id_extension = self.transport_stream_id self.private_indicator = 1 # pack service_stream_loop sl_bytes = string.join( map(lambda x: x.pack(), self.service_loop), "") fmt = "!HB%ds" % len(sl_bytes) return pack(fmt, self.original_network_id, 0xFF, sl_bytes, ) ###################################################################### class service_loop_item(DVBobject): def pack(self): # pack service_descriptor_loop sdl_bytes = string.join( map(lambda x: x.pack(), self.service_descriptor_loop), "") fmt = "!HBH%ds" % len(sdl_bytes) return pack(fmt, self.service_ID, 0xFC | (self.EIT_schedule_flag << 1) | (self.EIT_present_following_flag), (self.running_status << 13) | (self.free_CA_mode << 12) | (len(sdl_bytes) & 0x0FFF), sdl_bytes, ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/PSI/MGT.py0000755000175000017500000000454512214326456021766 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright 2010-2013 Lorenzo Pallara l.pallara@avalpa.com # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.MPEG.Section import Section from dvbobjects.utils import * ###################################################################### class master_guide_section(Section): table_id = 0xC7 section_max_size = 4096 def pack_section_body(self): # pack tables_loop tl_bytes = string.join( map(lambda x: x.pack(), self.tables_loop), "") # pack descriptors_loop dl_bytes = string.join( map(lambda x: x.pack(), self.descriptors_loop), "") self.table_id_extension = 0 self.private_indicator = 1 fmt = "!BH%dsH%ds" % (len(tl_bytes), len(dl_bytes)) return pack(fmt, self.ATSC_protocol_version, len(self.tables_loop), tl_bytes, 0xF000 | (len(dl_bytes) & 0x0FFF), dl_bytes, ) ###################################################################### class table_loop_item(DVBobject): def pack(self): # pack transport_descriptor_loop dl_bytes = string.join( map(lambda x: x.pack(), self.descriptors_loop), "") fmt = "!HHBLH%ds" % len(dl_bytes) return pack(fmt, self.table_type, 0xE000 | (self.table_type_pid & 0x1FFF), 0xE0 | (self.table_type_version_number & 0x1F), self.number_bytes, 0xF000 | (len(dl_bytes) & 0x0FFF), dl_bytes, ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/PSI/ECM.py0000755000175000017500000000337112214326456021737 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright © 2008-2013, Lorenzo Pallara l.pallara@avalpa.com # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.MPEG.Section import Section from dvbobjects.utils import * ###################################################################### class entitlement_control_message_section(Section): table_id = 0x80 section_max_size = 1024 def pack_section_body(self): # pack program_loop_item pl_bytes = string.join( map(lambda x: x.pack(), self.ecm_loop), "") self.table_id_extension = 0xFFFF fmt = "!%ds" % (len(pl_bytes)) return pack(fmt, pl_bytes ) ###################################################################### class ecm_loop_item(DVBobject): def pack(self): # pack program_loop_item fmt = "!HHHHHHHH" return pack(fmt, self.cw1_1, self.cw1_2, self.cw1_3, self.cw1_4, self.cw2_1, self.cw2_2, self.cw2_3, self.cw2_4, ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/PSI/CAT.py0000755000175000017500000000261012214326456021735 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright © 2008, Lorenzo Pallara # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.MPEG.Section import Section from dvbobjects.utils import * ###################################################################### class conditional_access_section(Section): table_id = 0x01 section_max_size = 1024 def pack_section_body(self): # pack ca_descriptor_loop pl_bytes = string.join( map(lambda x: x.pack(), self.ca_descriptor_loop), "") self.table_id_extension = 0xFFFF fmt = "!%ds" % (len(pl_bytes)) return pack(fmt, pl_bytes ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/PSI/NIT.py0000755000175000017500000000460212214326456021763 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright © 2004-2013 Lorenzo Pallara l.pallara@avalpa.com # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.MPEG.Section import Section from dvbobjects.utils import * from dvbobjects.DVB.Descriptors import * ###################################################################### class network_information_section(Section): table_id = 0x40 section_max_size = 1024 def pack_section_body(self): # pack network_descriptor_loop ndl_bytes = string.join( map(lambda x: x.pack(), self.network_descriptor_loop), "") # pack transport_stream_loop tsl_bytes = string.join( map(lambda x: x.pack(), self.transport_stream_loop), "") self.table_id_extension = self.network_id self.private_indicator = 1 fmt = "!H%dsH%ds" % (len(ndl_bytes), len(tsl_bytes)) return pack(fmt, 0xF000 | (len(ndl_bytes) & 0x0FFF), ndl_bytes, 0xF000 | (len(tsl_bytes) & 0x0FFF), tsl_bytes, ) ###################################################################### class transport_stream_loop_item(DVBobject): def pack(self): # pack transport_descriptor_loop tdl_bytes = string.join( map(lambda x: x.pack(), self.transport_descriptor_loop), "") fmt = "!HHH%ds" % len(tdl_bytes) return pack(fmt, self.transport_stream_id, self.original_network_id, 0xF000 | (len(tdl_bytes) & 0x0FFF), tdl_bytes, ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/PSI/ETT.py0000755000175000017500000000270612215631157021766 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright 2013 Lorenzo Pallara l.pallara@avalpa.com # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.MPEG.Section import Section from dvbobjects.ATSC.Loops import * from dvbobjects.utils.MJD import * ###################################################################### class extended_text_table_section(Section): table_id = 0xCC section_max_size = 4093 def pack_section_body(self): self.table_id_extension = self.ETT_table_id_extension self.protocol_version = 0 extended_text_message_bytes = self.extended_text_message.pack() fmt = "!BL%ds" % len(extended_text_message_bytes) return pack(fmt, self.protocol_version, self.ETM_id, extended_text_message_bytes, ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/PSI/EIT.py0000755000175000017500000000512312214326456021751 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright © 2005-2013 Lorenzo Pallara l.pallara@avalpa.com # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.MPEG.Section import Section from dvbobjects.utils.MJD import * from dvbobjects.DVB.Descriptors import * EIT_ACTUAL_TS_PRESENT_FOLLOWING = 0x4E EIT_ANOTHER_TS_PRESENT_FOLLOWING = 0x4F EIT_ACTUAL_TS = 0x50 #to 0x5F EIT_ANOTHER_TS = 0x60 #to 0x6F EIT_ACTUAL_TS_SCHEDULE14 = 0x50 EIT_ACTUAL_TS_SCHEDULE58 = 0x51 ###################################################################### class event_information_section(Section): section_max_size = 4096 def pack_section_body(self): self.table_id_extension = self.service_id self.last_table_id = self.table_id # pack event_loop el_bytes = string.join( map(lambda x: x.pack(), self.event_loop), "") fmt = "!HHBB%ds" % len(el_bytes) return pack(fmt, self.transport_stream_id, self.original_network_id, self.segment_last_section_number, self.last_table_id, el_bytes, ) ###################################################################### class event_loop_item(DVBobject): def pack(self): # pack event_descriptor_loop edl_bytes = string.join( map(lambda x: x.pack(), self.event_descriptor_loop), "") # convert to MJD date = MJD_convert(self.start_year, self.start_month, self.start_day) fmt = "!HHBBBBBBH%ds" % len(edl_bytes) return pack(fmt, self.event_id, date, self.start_hours, self.start_minutes, self.start_seconds, self.duration_hours, self.duration_minutes, self.duration_seconds, (self.running_status << 13) | (self.free_CA_mode << 12) | (len(edl_bytes) & 0x0FFF), edl_bytes, ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/PSI/BAT.py0000755000175000017500000000464312214326456021744 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright © 2004-2013 Lorenzo Pallara l.pallara@avalpa.com # Copyright © 2010 Andreas Regel # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.MPEG.Section import Section from dvbobjects.utils import * from dvbobjects.DVB.Descriptors import * ###################################################################### class bouquet_association_section(Section): table_id = 0x4A section_max_size = 1024 def pack_section_body(self): # pack bouquet_descriptor_loop bdl_bytes = string.join( map(lambda x: x.pack(), self.bouquet_descriptor_loop), "") # pack transport_stream_loop tsl_bytes = string.join( map(lambda x: x.pack(), self.transport_stream_loop), "") self.table_id_extension = self.bouquet_id self.private_indicator = 1 fmt = "!H%dsH%ds" % (len(bdl_bytes), len(tsl_bytes)) return pack(fmt, 0xF000 | (len(bdl_bytes) & 0x0FFF), bdl_bytes, 0xF000 | (len(tsl_bytes) & 0x0FFF), tsl_bytes, ) ###################################################################### class transport_stream_loop_item(DVBobject): def pack(self): # pack transport_descriptor_loop tdl_bytes = string.join( map(lambda x: x.pack(), self.transport_descriptor_loop), "") fmt = "!HHH%ds" % len(tdl_bytes) return pack(fmt, self.transport_stream_id, self.original_network_id, 0xF000 | (len(tdl_bytes) & 0x0FFF), tdl_bytes, ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/PSI/PMT.py0000755000175000017500000000472412214326456021776 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright © 2000-2001, GMD, Sankt Augustin # -- German National Research Center for Information Technology # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.MPEG.Section import Section from dvbobjects.utils import * from dvbobjects.DVB.Descriptors import * from dvbobjects.MPEG.Descriptors import * ###################################################################### class program_map_section(Section): table_id = 0x2 section_max_size = 1024 def pack_section_body(self): # pack program_info_descriptor_loop pidl_bytes = string.join( map(lambda x: x.pack(), self.program_info_descriptor_loop), "") # pack stream_loop pl_bytes = string.join( map(lambda x: x.pack(), self.stream_loop), "") self.table_id_extension = self.program_number self.private_indicator = 0 fmt = "!HH%ds%ds" % (len(pidl_bytes), len(pl_bytes)) return pack(fmt, 0xE000 | (self.PCR_PID & 0x1FFF), 0xF000 | (len(pidl_bytes) & 0x0FFF), pidl_bytes, pl_bytes, ) ###################################################################### class stream_loop_item(DVBobject): def pack(self): # pack elementary_stream_info_descriptor_loop esidl_bytes = string.join( map(lambda x: x.pack(), self.element_info_descriptor_loop), "") fmt = "!BHH%ds" % len(esidl_bytes) return pack(fmt, self.stream_type, 0xE000 | (self.elementary_PID & 0x1FFF), 0xF000 | (len(esidl_bytes) & 0x0FFF), esidl_bytes, ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/PSI/TDT.py0000755000175000017500000000243412214326456021765 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright © 2005-2013 Lorenzo Pallara l.pallara@avalpa.com # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.utils import * from dvbobjects.utils.DVBobject import * from dvbobjects.utils.MJD import * ###################################################################### class time_date_section(DVBobject): def pack(self): date = MJD_convert(self.year, self.month, self.day) fmt = "!BHHBBB" return pack(fmt, 0x70, 0x7005, date, self.hour, self.minute, self.second, ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/PSI/TVCT.py0000755000175000017500000000466512214326456022122 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright 2010-2013 Lorenzo Pallara l.pallara@avalpa.com # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.utils import * from dvbobjects.MPEG.Section import Section from dvbobjects.utils.DVBobject import * ###################################################################### class terrestrial_virtual_channel_section(Section): table_id = 0xC8 section_max_size = 1024 def pack_section_body(self): self.table_id_extension = self.transport_stream_id # pack event_loop cl_bytes = string.join( map(lambda x: x.pack(), self.channels_loop), "") adl_bytes = string.join( map(lambda x: x.pack(), self.additional_descriptors_loop), "") fmt = "!BB%dsH%ds" % (len(cl_bytes), len(adl_bytes)) return pack(fmt, self.ATSC_protocol_version, len(self.channels_loop), cl_bytes, 0xFC00 | (len(adl_bytes) & 0x3FF), adl_bytes ) ###################################################################### class channel_loop_item(DVBobject): def pack(self): assert len(self.short_name) == 14 #bytes -> 7*16 bit, 7 utf-16 chars # pack event_descriptor_loop dl_bytes = string.join( map(lambda x: x.pack(), self.descriptors_loop), "") fmt = "!%dsLLHHBBHH%ds" % (len(self.short_name), len(dl_bytes)) return pack(fmt, self.short_name, 0xF0000000 | ((self.major_channel_number & 0x3FF) << 18) | ((self.minor_channel_number & 0x3FF) << 8) | (self.modulation_mode & 0xFF), self.carrier_frequency, self.channel_TSID, self.program_number, (self.ETM_location << 6) | (self.access_controlled << 5) | (self.hidden << 4) | 0xC | (self.hide_guide << 1) | 0x1, 0xC0 | self.service_type, self.source_id, 0xFC00 | (len(dl_bytes) & 0x3FF), dl_bytes ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/PSI/SIT.py0000755000175000017500000000432012214326456021765 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright 2011-2013 Lorenzo Pallara l.pallara@avalpa.com # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.MPEG.Section import Section from dvbobjects.utils import * from dvbobjects.DVB.Descriptors import * ###################################################################### class selection_information_section(Section): table_id = 0x7F section_max_size = 4092 def pack_section_body(self): self.table_id_extension = 0xFFFF self.private_indicator = 1 self.section_number = 0 self.last_section_number = 0 ti_bytes = string.join( map(lambda x: x.pack(), self.transmission_info_loop), "") sl_bytes = string.join( map(lambda x: x.pack(), self.service_loop), "") fmt = "!H%ds%ds" % (len(ti_bytes), len(sl_bytes)) return pack(fmt, 0xF000 | len(ti_bytes), ti_bytes, sl_bytes ) ###################################################################### class service_loop_item(DVBobject): def pack(self): sdl_bytes = string.join( map(lambda x: x.pack(), self.service_descriptor_loop), "") fmt = "!HH%ds" % len(sdl_bytes) return pack(fmt, self.service_ID, 0x8000 | (self.running_status << 13) | (len(sdl_bytes) & 0x0FFF), sdl_bytes, ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/PSI/EMM.py0000755000175000017500000000317512214326456021753 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright © 2008-2013, Lorenzo Pallara l.pallara@avalpa.com # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.MPEG.Section import Section from dvbobjects.utils import * ###################################################################### class entitlement_management_message_section(Section): table_id = 0x8F section_max_size = 1024 def pack_section_body(self): # pack program_loop_item pl_bytes = string.join( map(lambda x: x.pack(), self.emm_loop), "") self.table_id_extension = 0xFFFF fmt = "!%ds" % (len(pl_bytes)) return pack(fmt, pl_bytes ) ###################################################################### class emm_loop_item(DVBobject): def pack(self): # pack program_loop_item fmt = "!H" return pack(fmt, self.test, ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/PSI/UNT.py0000755000175000017500000000546012214326456022002 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright 2009-2013 Lorenzo Pallara l.pallara@avalpa.com # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.MPEG.Section import Section from dvbobjects.utils import * from dvbobjects.DVB.Descriptors import * ###################################################################### class update_notification_section(Section): table_id = 0x4B section_max_size = 4096 def pack_section_body(self): self.table_id_extension = self.action_type << 8 | ((self.OUI >> 16) ^ ((self.OUI >> 8) & 0xFF) ^ (self.OUI & 0xFF)) # pack common_descriptor_loop common_bytes = string.join( map(lambda x: x.pack(), self.common_descriptor_loop), "") # pack compatibility_descriptor_loop compatibility_bytes = string.join( map(lambda x: x.pack(), self.compatibility_descriptor_loop), "") fmt = "!HBBH%ds%ds" % (len(common_bytes), len(compatibility_bytes)) return pack(fmt, self.OUI >> 8, self.OUI & 0xFF, self.processing_order, 0xF000 | len(common_bytes), common_bytes, compatibility_bytes, ) ###################################################################### class unt_compatibility_descriptor_loop_item(DVBobject): def pack(self): # pack target_descriptor_loop tdl_bytes = string.join( map(lambda x: x.pack(), self.target_descriptor_loop), "") # pack operational descriptor_loop odl_bytes = string.join( map(lambda x: x.pack(), self.operational_descriptor_loop), "") fmt = "!%dsHH%dsH%ds" % (len(self.compatibility_descriptor), len(tdl_bytes), len(odl_bytes)) return pack(fmt, self.compatibility_descriptor, len(tdl_bytes) + len(odl_bytes), 0xF000 | len(tdl_bytes), tdl_bytes, 0xF000 | len(odl_bytes), odl_bytes, ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/PSI/__init__.py0000755000175000017500000000170412214326456023070 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright © 2000-2001, GMD, Sankt Augustin # -- German National Research Center for Information Technology # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA """Package PSI (Program Specific Information). Extends package DVB . """ opencaster-3.2.2/libs/dvbobjects/dvbobjects/PSI/PAT.py0000755000175000017500000000333412214326456021756 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright © 2004-2013, Lorenzo Pallara l.pallara@avalpa.com # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.MPEG.Section import Section from dvbobjects.utils import * ###################################################################### class program_association_section(Section): table_id = 0x00 section_max_size = 1024 def pack_section_body(self): # pack program_loop_item pl_bytes = string.join( map(lambda x: x.pack(), self.program_loop), "") self.table_id_extension = self.transport_stream_id # ??? self.private_indicator = 0 fmt = "!%ds" % (len(pl_bytes)) return pack(fmt, pl_bytes ) ###################################################################### class program_loop_item(DVBobject): def pack(self): # pack program_loop_item fmt = "!HH" return pack(fmt, self.program_number, 0xE000 | (self.PID & 0x1FFF), ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/PSI/INT.py0000755000175000017500000000544012214326456021764 0ustar debiandebian#! /usr/bin/env python # Copyright 2007 Andreas Berger # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.MPEG.Section import Section from dvbobjects.utils import * from dvbobjects.DVB.Descriptors import * ###################################################################### class ip_mac_notification_section(Section): table_id = 0x4c section_max_size = 4096 def pack_section_body(self): self.action_type = 0x01 self.platform_id_hash = ( (self.platform_id>>16) & 0xff ) ^ ( (self.platform_id>>8) & 0xff ) ^ ( self.platform_id & 0xff ) # pack platform descriptor loop pdl_bytes = string.join( map(lambda x: x.pack(), self.platform_descriptor_loop), "") # pack associaton_loop al_bytes = string.join( map(lambda x: x.pack(), self.association_loop), "") pdl_bytes_length = len(pdl_bytes) self.table_id_extension = self.action_type << 8 | self.platform_id_hash fmt = "!BBBBBB%ds%ds" % (len(pdl_bytes), len(al_bytes)) return pack(fmt, (self.platform_id >> 16) & 0xFF, (self.platform_id >> 8) & 0xFF, self.platform_id & 0xFF, self.processing_order, 0xF0 << 8 | (pdl_bytes_length >> 8) & 0x0F, pdl_bytes_length & 0xFF, pdl_bytes, al_bytes ) class association_loop_item(DVBobject): def pack(self): # pack target descriptor loop tdl_bytes = string.join( map(lambda x: x.pack(), self.target_descriptor_loop), "") # pack operational descriptor loop odl_bytes = string.join( map(lambda x: x.pack(), self.operational_descriptor_loop), "") tdl_bytes_length = len(tdl_bytes) odl_bytes_length = len(odl_bytes) fmt = "!BB%dsBB%ds" % (tdl_bytes_length, odl_bytes_length) return pack(fmt, 0xF0 << 8 | (tdl_bytes_length >> 8) & 0x0F, tdl_bytes_length & 0xFF, tdl_bytes, 0xF0 << 8 | (odl_bytes_length >> 8) & 0x0F, odl_bytes_length & 0xFF, odl_bytes ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/HBBTV/0000755000175000017500000000000012214326455021163 5ustar debiandebianopencaster-3.2.2/libs/dvbobjects/dvbobjects/HBBTV/Descriptors.py0000755000175000017500000001432412214326455024045 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library and contains the main HbbTV descriptors (see the list below) # # Copyright 2000-2001, GMD, Sankt Augustin # -- German National Research Center for Information Technology # # Copyright 2010, mediatvcom, Claude Vanderm # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #Below are listed the HbbTV available, and missing descriptor of this release. #Based on HbbTV specification (ETSI-TS 102 796) version 1.1.1 # #available hbbtv descriptors: | optional missing descriptors: #application_descriptor() | application_icons_descriptor() #application_name_descriptor() #transport_protocol_descriptor() #simple_application_location_descriptor() #application_usage_descriptor() #simple_application_boundary_descriptor() #external_application_authorisation_descriptor() import string from dvbobjects.utils import * from dvbobjects.MPEG.Descriptor import Descriptor ###################################################################### class application_descriptor(Descriptor): descriptor_tag = 0x00 application_profiles_length = 5 def bytes(self): tp_labels = string.join( map(lambda label, self=self: pack("!B", label), self.transport_protocol_labels), "") self.flags = ( 0x00 | (self.service_bound_flag << 7) | (self.visibility << 5) | 0x1F ) fmt = "!BH5B%ds" % len(tp_labels) return pack(fmt, self.application_profiles_length, self.application_profile, self.version_major, self.version_minor, self.version_micro, self.flags, self.application_priority, tp_labels, ) ###################################################################### class application_name_descriptor(Descriptor): descriptor_tag = 0x01 def bytes(self): fmt = "!3sB%ds" % len(self.application_name) return pack(fmt, self.ISO_639_language_code, len(self.application_name), self.application_name, ) ###################################################################### class transport_protocol_descriptor(Descriptor): descriptor_tag = 0x02 def bytes(self): if self.protocol_id == 0x0001: fmt = "!HBBB" return pack(fmt, self.protocol_id, self.transport_protocol_label, 0x7F | (self.remote_connection << 7), self.component_tag, ) if self.protocol_id == 0x0003: URL_extension_count = 0 for url in self.URL_extensions: URL_extension_count = URL_extension_count + 1 fmt = "!HBB%dsB" % len(self.URL_base) result = pack(fmt, self.protocol_id, self.transport_protocol_label, len(self.URL_base), self.URL_base, URL_extension_count ) for url in self.URL_extensions: result = result + pack( "!B%ds" % len(url), len(url), url, ) return result ###################################################################### class simple_application_location_descriptor(Descriptor): descriptor_tag = 0x15 def bytes(self): fmt = "!%ds" % len(self.initial_path_bytes) return pack(fmt, self.initial_path_bytes ) ###################################################################### class application_usage_descriptor(Descriptor): descriptor_tag = 0x16 def bytes(self): fmt = "!B" return pack(fmt, self.usage_type ) ###################################################################### class simple_application_boundary_descriptor(Descriptor): descriptor_tag = 0x17 def bytes(self): boundary_extension_count = 0 for boundary_extension in self.boundary_extensions: boundary_extension_count = boundary_extension_count + 1 fmt = "!B" result = pack(fmt, boundary_extension_count ) for boundary_extension in self.boundary_extensions: result = result + pack("!B%ds" % len(boundary_extension), len(boundary_extension), boundary_extension, ) return result ###################################################################### class external_application_authorisation_descriptor(Descriptor): descriptor_tag = 0x05 def bytes(self): result = "" for y in range(len(self.application_identifiers)): i=0 fmt = "!LHB" result = result + pack(fmt, self.application_identifiers[y][i], #organisation_id, self.application_identifiers[y][i+1], # application_id, self.application_priority[y] ) return result opencaster-3.2.2/libs/dvbobjects/dvbobjects/HBBTV/__init__.py0000755000175000017500000000150012214326455023273 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA """Package HbbTv Extends packages DVB and DSMCC. """ opencaster-3.2.2/libs/dvbobjects/dvbobjects/MHP/0000755000175000017500000000000012214326455020742 5ustar debiandebianopencaster-3.2.2/libs/dvbobjects/dvbobjects/MHP/Descriptors.py0000755000175000017500000002166012214326455023625 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright 2000-2001, GMD, Sankt Augustin # -- German National Research Center for Information Technology # # Copyright 2010, LIFIA - Facultad de Informatica - Univ. Nacional de La Plata # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.utils import * from dvbobjects.MPEG.Descriptor import Descriptor ###################################################################### # Common constants. # application_type DVB_J_application_type = 0x0001 DVB_HTML_application_type = 0x0002 # application_control_code DVB_J_AUTOSTART = 0x01 # protocol_id MHP_OC_protocol_id = 0x0001 ###################################################################### class application_descriptor(Descriptor): descriptor_tag = 0x00 application_profiles_length = 5 def bytes(self): tp_labels = string.join( map(lambda label, self=self: pack("!B", label), self.transport_protocol_labels), "") self.flags = ( 0x00 | (self.service_bound_flag << 7) | (self.visibility << 5) | 0x1F ) fmt = "!BH5B%ds" % len(tp_labels) return pack(fmt, self.application_profiles_length, self.application_profile, self.version_major, self.version_minor, self.version_micro, self.flags, self.application_priority, tp_labels, ) ###################################################################### class application_name_descriptor(Descriptor): descriptor_tag = 0x01 def bytes(self): fmt = "!3sB%ds" % len(self.application_name) return pack(fmt, self.ISO_639_language_code, len(self.application_name), self.application_name, ) ###################################################################### class transport_protocol_descriptor(Descriptor): descriptor_tag = 0x02 def bytes(self): fmt = "!HBBB" return pack(fmt, self.protocol_id, self.transport_protocol_label, 0x7F | (self.remote_connection << 7), self.component_tag, ) ###################################################################### class transport_ic_protocol_descriptor(Descriptor): descriptor_tag = 0x02 protocol_id = 0x03 def bytes(self): URL_extension_count = 0 for url in self.URL_extensions: URL_extension_count = URL_extension_count + 1 fmt = "!HBB%dsB" % len(self.URL_base) result = pack(fmt, self.protocol_id, self.transport_protocol_label, len(self.URL_base), self.URL_base, URL_extension_count ) for url in self.URL_extensions: result = result + pack( "!B%ds" % len(url), len(url), url, ) return result ###################################################################### class application_storage_descriptor(Descriptor): descriptor_tag = 0x10 def bytes(self): fmt = "!BBLB" return pack(fmt, self.storage_property, 0x1F | (self.not_launchable_from_broadcast << 7) | (self.launchable_completely_from_cache << 6) | (self.is_launchable_with_older_version << 5), 0x80000000 | (self.version), self.priority, ) ###################################################################### class dvb_html_application_descriptor(Descriptor): descriptor_tag = 0x08 def bytes(self): #TODO add applications_ids fmt = "!BH%ds" % len(self.parameter) return pack(fmt, 1 ,1 , self.parameter) ###################################################################### class dvb_html_application_location_descriptor(Descriptor): descriptor_tag = 0x09 def bytes(self): fmt = "!B%ds%ds" % ( len(self.physical_root), len(self.initial_path), ) return pack(fmt, len(self.physical_root), self.physical_root, self.initial_path, ) ###################################################################### class dvb_j_application_descriptor(Descriptor): descriptor_tag = 0x03 def bytes(self): result = "" for param in self.parameters: result = result + pack( "!B%ds" % len(param), len(param), param, ) return result ###################################################################### class dvb_simple_application_location_descriptor(Descriptor): descriptor_tag = 0x15 def bytes(self): fmt = "!%ds" % ( len(self.path) ) return pack(fmt, self.path, ) ###################################################################### class dvb_j_application_location_descriptor(Descriptor): descriptor_tag = 0x04 def bytes(self): fmt = "!B%dsB%ds%ds" % ( len(self.base_directory), len(self.class_path_extension), len(self.initial_class), ) return pack(fmt, len(self.base_directory), self.base_directory, len(self.class_path_extension), self.class_path_extension, self.initial_class, ) ###################################################################### class ginga_ncl_application_descriptor(Descriptor): descriptor_tag = 0x06 def bytes(self): result = "" for param in self.parameters: result = result + pack( "!B%ds" % len(param), len(param), param, ) return result ###################################################################### class ginga_ncl_application_location_descriptor(Descriptor): descriptor_tag = 0x07 def bytes(self): fmt = "!B%dsB%ds%ds" % ( len(self.base_directory), len(self.class_path_extension), len(self.initial_class), ) return pack(fmt, len(self.base_directory), self.base_directory, len(self.class_path_extension), self.class_path_extension, self.initial_class, ) ###################################################################### class content_type_descriptor(Descriptor): descriptor_tag = 0x72 def bytes(self): return self.content_type def sample(self): self.content_type = "image/png" ### # The following two should be somewhere else ###################################################################### # INCOMPLETE class additional_ginga_j_info(DVBobject): def __init__(self, transmission_format, document_resolution, organization_id, application_id, carousel_id): self.transmission_format = transmission_format self.document_resolution = document_resolution self.organization_id = organization_id self.application_id = application_id self.carousel_id = carousel_id def bytes(self): fmt = "!BLHLB" return pack( fmt, (self.transmission_format << 6) | 0x20 | (self.document_resolution << 1), self.organization_id, self.application_id, self.carousel_id, 0x1F ) ###################################################################### class ait_identifier_info(DVBobject): def __init__(self, application_type, ait_version): self.application_type = application_type self.ait_version = ait_version def bytes(self): return pack ("!HB", self.application_type, 0xE0 | self.ait_version ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/MHP/AIT.py0000755000175000017500000000467612214326455021751 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright 2000-2001, GMD, Sankt Augustin # -- German National Research Center for Information Technology # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.MPEG.Section import Section from dvbobjects.utils import * ###################################################################### class application_information_section(Section): table_id = 0x74 section_max_size = 1024 def pack_section_body(self): self.private_indicator = 1 # pack common_descriptor_loop cdl_bytes = string.join( map(lambda x: x.pack(), self.common_descriptor_loop), "") # pack applicaton_loop apl_bytes = string.join( map(lambda x: x.pack(), self.application_loop), "") self.table_id_extension = self.application_type # ??? fmt = "!H%dsH%ds" % (len(cdl_bytes), len(apl_bytes)) return pack(fmt, 0xF000 | (len(cdl_bytes) & 0x0FFF), cdl_bytes, 0xF000 | (len(apl_bytes) & 0x0FFF), apl_bytes, ) ###################################################################### class application_loop_item(DVBobject): def pack(self): # pack application_descriptors_loop adl_bytes = string.join( map(lambda x: x.pack(), self.application_descriptors_loop), "") fmt = "!LHBH%ds" % len(adl_bytes) return pack(fmt, self.organisation_id, self.application_id, self.application_control_code, 0xF000 | (len(adl_bytes) & 0x0FFF), adl_bytes, ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/MHP/__init__.py0000755000175000017500000000171112214326455023056 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright 2000-2001, GMD, Sankt Augustin # -- German National Research Center for Information Technology # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA """Package MHP (Multimedia Home Platform). Extends packages DVB and DSMCC. """ opencaster-3.2.2/libs/dvbobjects/dvbobjects/MPEG/0000755000175000017500000000000012214326455021046 5ustar debiandebianopencaster-3.2.2/libs/dvbobjects/dvbobjects/MPEG/Descriptor.py0000755000175000017500000000254412214326455023546 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright 2000-2001, GMD, Sankt Augustin # -- German National Research Center for Information Technology # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA from dvbobjects.utils import * ###################################################################### class Descriptor(DVBobject): """The base class for all Descriptors. Subclasses must implement a bytes() method, that returns the descriptor body bytes. """ def pack(self): bytes = self.bytes() return pack("!BB%ds" % len(bytes), self.descriptor_tag, len(bytes), bytes, ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/MPEG/Section.py0000755000175000017500000000631212214326455023031 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright 2000-2001, GMD, Sankt Augustin # -- German National Research Center for Information Technology # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA from dvbobjects.utils import * ###################################################################### class Section(DVBobject): """The base class of many PSI/SI Sections. It implements the general layout of all(?) PSI/SI sections with 'syntax_indicator' == 1. Constant Attributes: - 'section_syntax_indicator' = 1, - 'current_next_indicator' = 1. Attributes to be provided by subclasses: - 'table_id' - 'table_id_extension' Attributes to be provided by other means (e.g. using 'set()'): - 'version_number' - 'section_number' - 'last_section_number' Computed Attributes: - 'section_length' - 'crc_32' Subclasses must implement a 'pack_section_body()' method. """ section_max_size = 4096 section_syntax_indicator = 1 private_indicator = 0 current_next_indicator = 1 def __sanity_check(self): assert self.section_syntax_indicator == 1 assert self.current_next_indicator in (0, 1) assert 0 <= self.table_id <= 0xff assert 0 <= self.table_id_extension <= 0xffff assert 0 <= self.section_length <= self.section_max_size - 3 assert 0 <= self.section_number <= 0xFF assert 0 <= self.last_section_number <= 0xFF def pack(self): body = self.pack_section_body() self.section_length = ( 5 # section header rest + len(body) # section body + 4 # CRC32 ) length_info_16 = ( 0xB000 | (self.section_syntax_indicator<<15) | (self.private_indicator << 14) | (self.section_length) ) version_info_8 = ( 0xC0 | ((self.version_number & 0x01f) << 1) | (self.current_next_indicator) ) self.__sanity_check() data = pack("!BHHBBB", self.table_id, length_info_16, self.table_id_extension, version_info_8, self.section_number, self.last_section_number, ) + body return data + self.crc_32(data) def crc_32(self, data): crc = crc32.CRC_32(data) return pack("!L", crc) opencaster-3.2.2/libs/dvbobjects/dvbobjects/MPEG/Descriptors.py0000755000175000017500000001170612214326455023731 0ustar debiandebian#! /usr/bin/env python # # Copyright (C) 2004-2013 Lorenzo Pallara, l.pallara@avalpa.com # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.utils import * from dvbobjects.MPEG.Descriptor import Descriptor ###################################################################### class STD_descriptor(Descriptor): descriptor_tag = 0x11 def bytes(self): fmt = "!B" return pack(fmt, 0xFE | self.leal_valid_flag, ) ###################################################################### class video_stream_descriptor(Descriptor): descriptor_tag = 0x2 def bytes(self): if self.MPEG_1_only_flag == 0: fmt = "!B" return pack(fmt, (self.multiple_frame_rate_flag & 0x1) << 7 | (self.frame_rate_code & 0x3) << 3 | (self.MPEG_1_only_flag & 0x1) << 2 | (self.constrained_parameter_flag & 0x1) << 1 | (self.still_picture_flag & 0x1), ) else : fmt = "!BBB" return pack(fmt, (self.multiple_frame_rate_flag & 0x1) << 7 | (self.frame_rate_core & 0xF) << 3 | (self.MPEG_1_only_flag & 0x1) << 2 | (self.constrained_parameter_flag & 0x1) << 1 | (self.still_picture_flag & 0x1), profile_and_level_indication, (chroma_format & 0x3) << 6 | (frame_rate_extension_flag & 0x1) << 5 | 0x1F, ) ###################################################################### class audio_stream_descriptor(Descriptor): descriptor_tag = 0x3 def bytes(self): fmt = "!B" return pack(fmt, (self.free_format_flag & 0x1) << 7 | (self.ID & 0x1) << 6 | (self.layer & 0x3) << 4 | (self.variable_rate_audio_indicator & 0x1) << 3, ) ###################################################################### class association_tag_descriptor(Descriptor): descriptor_tag = 0x14 def bytes(self): if self.use == 0: fmt = "!HHBLL%ds" % (len(self.private_data)) return pack(fmt, self.association_tag, self.use, self.selector_lenght, self.transaction_id, self.timeout, self.private_data, ) else: fmt = "!HHB%ds%ds" % ( len(self.selector_lenght), len(self.privatedata) ) return pack(fmt, self.association_tag, self.use, self.selector_lenght, self.selector_bytes, self.privatedata, ) ###################################################################### class graphics_constraints_descriptor(Descriptor): descriptor_tag = 0x14 def bytes(self): gc_bytes = string.join( map(lambda byte, self=self: pack("!B", byte), self.graphics_configuration_bytes), "") fmt = "!B%ds" % (len(gc_bytes)) return pack(fmt, 0xF8 | (self.can_run_without_visible_ui << 2) | (self.handles_configuration_changed << 1) | (self.handles_externally_controlled_video), gc_bytes, ) ###################################################################### class DTS_registration_descriptor(Descriptor): descriptor_tag = 0x05 def bytes (self): fmt = "!%ds" % (len(self.format_identifier)) return pack(fmt, self.format_identifier) ###################################################################### class carousel_identifier_descriptor(Descriptor): descriptor_tag = 0x13 def bytes(self): if self.format_ID: fmt = "!LBBHHHBLBB%ds%ds" % (len(self.object_key_data) , len(self.private_data)) return pack(fmt, self.carousel_ID, self.format_ID, self.module_version, self.module_ID, self.block_size, self.module_size, self.compression_method, self.original_size, self.timeout, len(self.object_key_data), self.object_key_data, self.private_data, ) else : fmt = "!LB%ds" % (len(self.private_data)) return pack(fmt, self.carousel_ID, self.format_ID, self.private_data, ) ###################################################################### class ca_descriptor(Descriptor): descriptor_tag = 0x9 def bytes(self): fmt = "!HH" return pack(fmt, self.CA_system_ID, 0xE000 | (self.CA_PID & 0x1FFF), ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/MPEG/EBUTeletext.py0000755000175000017500000001546112214326455023564 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright 2009-2013, Lorenzo Pallara l.pallara@avalpa.com # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.utils import * from dvbobjects.utils.Hamming import * from dvbobjects.utils.ByteParity import * from dvbobjects.utils.ByteInvert import * ###################################################################### class EBUTeletext(DVBobject): """The class for EBU Teletext data units, NB. they are not sections """ def pack(self): if (self.data_unit_id == 0xFF): # return pack("!BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", return pack("BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", 0xFF, 0x2C, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ) b3 = self.row & 0x1 b2 = (self.magazine >> 2) & 0x01 b1 = (self.magazine >> 1) & 0x01 b0 = self.magazine & 0x1 hamming1 = invert(hamming84((b3 << 3) | (b2 << 2) | (b1 << 1) | b0)) b3 = (self.row >> 4) & 0x01 b2 = (self.row >> 3) & 0x01 b1 = (self.row >> 2) & 0x01 b0 = (self.row >> 1) & 0x01 hamming2 = invert(hamming84((b3 << 3) | (b2 << 2) | (b1 << 1) | b0)) payload = "" if (self.row == 0) : for i in range(0, len(self.chars)): #temp1 = ord(self.chars[i]) #temp2 = oddparity(temp1) #temp3 = invert(temp2) #temp4 = temp3 & 0xFF #payload += pack("B", temp4) #payload += pack("!B", invert(oddparity(ord(self.chars[i])))) payload += pack("B", invert(oddparity(ord(self.chars[i])))) assert len(payload) == 32 hamming3 = invert(hamming84(self.page & 0xF)) hamming4 = invert(hamming84((self.page >> 4) & 0xF)) hamming5 = invert(hamming84(self.subpage & 0xF)) b3 = self.erase_page & 0x1 b2 = (self.subpage >> 6 ) & 0x1 b1 = (self.subpage >> 5 ) & 0x1 b0 = (self.subpage >> 4 ) & 0x1 hamming6 = invert(hamming84((b3 << 3) | (b2 << 2) | (b1 << 1) | b0)) b3 = (self.subpage >> 10 ) & 0x1 b2 = (self.subpage >> 9 ) & 0x1 b1 = (self.subpage >> 8 ) & 0x1 b0 = (self.subpage >> 7 ) & 0x1 hamming7 = invert(hamming84((b3 << 3) | (b2 << 2) | (b1 << 1) | b0)) b3 = self.subtitle & 0x1 b2 = self.newsflash & 0x1 b1 = (self.subpage >> 12 ) & 0x1 b0 = (self.subpage >> 11 ) & 0x1 hamming8 = invert(hamming84((b3 << 3) | (b2 << 2) | (b1 << 1) | b0)) b3 = self.inhibit_display & 0x1 b2 = self.interrupted_sequence & 0x1 b1 = self.update_indicator & 0x1 b0 = self.suppress_header & 0x1 hamming9 = invert(hamming84((b3 << 3) | (b2 << 2) | (b1 << 1) | b0)) b3 = self.country_code & 0x1 b2 = (self.country_code >> 1) & 0x1 b1 = (self.country_code >> 2) & 0x1 b0 = self.magazine_serial & 0x1 hamming10 = invert(hamming84((b3 << 3) | (b2 << 2) | (b1 << 1) | b0)) # return pack("!BBBBBBBBBBBBBB", return pack("BBBBBBBBBBBBBB", self.data_unit_id, #0x02 non-subtile or 0x03 for subtitles 0x2C, # 44 bytes 0x01 << 6 | (self.field_parity & 0x01) << 5 | self.line_offset & 0x1F, 0xE4, # frame coding EBU Teletext hamming1, hamming2, hamming3, hamming4, hamming5, hamming6, hamming7, hamming8, hamming9, hamming10 ) + payload elif (self.row == 27) : link1bytes = self.link1.pack() link2bytes = self.link2.pack() link3bytes = self.link3.pack() link4bytes = self.link4.pack() link5bytes = self.link5.pack() link6bytes = self.link6.pack() crc = 0x0000 # not used # fmt = "!BBBBBBB%ds%ds%ds%ds%ds%dsBH" % (len(link1bytes), len(link2bytes), len(link3bytes), len(link4bytes), len(link5bytes), len(link6bytes)) fmt = "BBBBBBB%ds%ds%ds%ds%ds%dsBH" % (len(link1bytes), len(link2bytes), len(link3bytes), len(link4bytes), len(link5bytes), len(link6bytes)) return pack(fmt, self.data_unit_id, #0x02 non-subtile or 0x03 for subtitles 0x2C, # 44 bytes 0x01 << 6 | (self.field_parity & 0x01) << 5 | self.line_offset & 0x1F, 0xE4, # frame coding EBU Teletext hamming1, hamming2, invert(hamming84(self.designation_code)), # designation code allows 2^4 = 16 different pages more link1bytes, link2bytes, link3bytes, link4bytes, link5bytes, link6bytes, invert(hamming84(0xE)), # LC crc ) else : for i in range(0, len(self.chars)): # payload += pack("!B", invert(oddparity(ord(self.chars[i])))) payload += pack("B", invert(oddparity(ord(self.chars[i])))) assert len(payload) == 40 # return pack("!BBBBBB", return pack("BBBBBB", self.data_unit_id, #0x02 non-subtile or 0x03 for subtitles 0x2C, # 44 bytes 0x01 << 6 | (self.field_parity & 0x01) << 5 | self.line_offset & 0x1F, 0xE4, # frame coding EBU Teletext hamming1, hamming2, ) + payload # 40 characters of a line, a page is 24 lines ###################################################################### class EBUTeletextUnits(DVBobject): def pack(self): # pack unit_loop pl_bytes = string.join( map(lambda x: x.pack(), self.unit_loop), "") fmt = "!%ds" % (len(pl_bytes)) return pack(fmt, pl_bytes ) class EBUTeletextLink(DVBobject): def pack(self): hamming1 = invert(hamming84(self.page & 0xF)) hamming2 = invert(hamming84((self.page >> 4) & 0xF)) hamming3 = invert(hamming84(self.subpage & 0xF)) b3 = not (self.magazine & 0x1) b2 = (self.subpage >> 6 ) & 0x1 b1 = (self.subpage >> 5 ) & 0x1 b0 = (self.subpage >> 4 ) & 0x1 hamming4 = invert(hamming84((b3 << 3) | (b2 << 2) | (b1 << 1) | b0)) b3 = (self.subpage >> 10 ) & 0x1 b2 = (self.subpage >> 9 ) & 0x1 b1 = (self.subpage >> 8 ) & 0x1 b0 = (self.subpage >> 7 ) & 0x1 hamming5 = invert(hamming84((b3 << 3) | (b2 << 2) | (b1 << 1) | b0)) b3 = not ((self.magazine >> 1) & 0x1) b2 = not ((self.magazine >> 2) & 0x1) b1 = (self.subpage >> 12 ) & 0x1 b0 = (self.subpage >> 11 ) & 0x1 hamming6 = invert(hamming84((b3 << 3) | (b2 << 2) | (b1 << 1) | b0)) # fmt = "!BBBBBB" fmt = "BBBBBB" return pack(fmt, hamming1, hamming2, hamming3, hamming4, hamming5, hamming6, ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/MPEG/__init__.py0000755000175000017500000000157212214326455023167 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright © 2000-2001, GMD, Sankt Augustin # -- German National Research Center for Information Technology # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA opencaster-3.2.2/libs/dvbobjects/dvbobjects/MPEG/DVBH_Descriptors.py0000755000175000017500000002416712214326455024541 0ustar debiandebian#! /usr/bin/env python # # Copyright (C) 2004 Andreas Berger, berger@ftw.at # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.utils import * from dvbobjects.MPEG.Descriptor import Descriptor class ip_mac_platform_name_descriptor(Descriptor): descriptor_tag = 0x0c def bytes(self): fmt = "!3s%ds" % len(self.text_char_bytes) return pack(fmt, self.ISO_639_language_code, self.text_char_bytes ) class ip_mac_platform_provider_name_descriptor(Descriptor): descriptor_tag = 0x0d def bytes(self): fmt = "!3s%ds" % len(self.text_char_bytes) return pack(fmt, self.ISO_639_language_code, self.text_char_bytes ) class target_serial_number_descriptor(Descriptor): descriptor_tag = 0x08 def bytes(self): fmt = "!%ds" % len(serial_data_bytes) return pack(fmt, self.serial_data_bytes ) class target_smartcard_descriptor(Descriptor): descriptor_tag = 0x06 def bytes(self): fmt = "!I%ds" % len(self.private_data_bytes) return pack(fmt, self.super_CA_system_id, self.private_data_bytes ) class target_MAC_address_descriptor(Descriptor): descriptor_tag = 0x07 def bytes(self): fmt = "!6s%ds" % len(self.mac_addr_bytes) return pack(fmt, self.mac_addr_mask, self.mac_addr_bytes ) class target_MAC_address_range_descriptor(Descriptor): descriptor_tag = 0x0e def bytes(self): fmt = "!6s%ds" % len(self.mac_addr_bytes) return pack(fmt, self.mac_addr_mask, self.mac_addr_bytes ) class target_IP_address_descriptor(Descriptor): descriptor_tag = 0x09 def bytes(self): fmt = "!I%ds" % len(self.IPv4_addr_bytes) return pack(fmt, self.IPv4_addr_mask, self.IPv4_addr_bytes ) class target_IP_slash_descriptor(Descriptor): descriptor_tag = 0x0f def bytes(self): fmt = "!4BB" return pack(fmt, self.IPv4_addr[0], self.IPv4_addr[1], self.IPv4_addr[2], self.IPv4_addr[3], self.IPv4_slash_mask ) class target_IP_source_slash_descriptor(Descriptor): descriptor_tag = 0x10 def bytes(self): fmt = "!%ds" % len(self.IPv4_source_dest_bytes) return pack(fmt, self.IPv4_source_dest_bytes ) class target_IPv6_address_descriptor(Descriptor): descriptor_tag = 0x0a def bytes(self): fmt = "!7s%ds" % len(self.IPv6_address_bytes) return pack(fmt, self.IPv6_address_mask, self.IPv6_address_bytes ) class target_IPv6_slash_descriptor(Descriptor): descriptor_tag = 0x11 def bytes(self): fmt = "!%ds" % len(self.IPv6_bytes) return pack(fmt, self.IPv6_bytes ) class target_IPv6_source_slash_descriptor(Descriptor): descriptor_tag = 0x12 def bytes(self): fmt = "!%ds" % len(self.IPv6_source_dest_bytes) return pack(fmt, self.IPv6_source_dest_bytes ) class ip_mac_stream_location_descriptor(Descriptor): descriptor_tag = 0x13 def bytes(self): fmt = "!HHHHB" return pack(fmt, self.network_id, self.original_network_id, self.transport_stream_id, self.service_id, self.component_tag ) class isp_access_mode_descriptor(Descriptor): descriptor_tag = 0x14 def bytes(self): fmt = "!B" return pack(fmt, self.access_mode ) class telephone_descriptor(Descriptor): descriptor_tag = 0x57 def bytes(self): fmt = "!BBBB%ds%ds%ds%ds%ds" % (len(country_prefix_bytes), len(international_area_code_bytes), len(operator_code_bytes), len(national_area_code_bytes), len(core_number_bytes)) return pack(fmt, (0x03 << 7) & 0xC0 | (self.foreign_availability << 5) & 0x20 | self.connection_type & 0x1F, (0x01 << 7) & 0x80 | (self.country_prefix_length << 5) & 0x60 | (self.international_area_code << 4) & 0x1C | self.operator_code_length & 0x07, (0x01 << 7) & 0x80 | (self.national_area_code_length << 4) & 0x70 | self.core_number_length & 0x0F, country_prefix_bytes, international_area_code_bytes, operator_code_bytes, national_area_code_bytes, core_number_bytes ) class private_data_specifier_descriptor(Descriptor): descriptor_tag = 0x5f def bytes(self): fmt = "!I" return pack(fmt, self.private_data_specifier ) class time_slice_fec_identifier_descriptor(Descriptor): descriptor_tag = 0x77 def bytes(self): time_slice_fec_id = 0x00; fmt = "!BBB" return pack(fmt, (self.time_slicing << 7) & 0x80 | (self.mpe_fec << 5) & 0x60 | (0x03 << 3) & 0x18 | self.frame_size & 0x07, self.max_burst_duration, (self.max_average_rate << 4) & 0xF0 | time_slice_fec_id & 0x0F, ) # FIXME: move this class to another file, it's no descriptor class platform_id_data2(DVBobject): def pack(self): fmt = "!BBBBB" return pack(fmt, (self.platform_id >> 16) & 0xFF, (self.platform_id >> 8) & 0xFF, self.platform_id & 0xFF, self.action_type & 0xFF, (0x03 << 6) & 0xC0 | (0x00 << 5) & 0x20 | 0x01 & 0x1F ) # FIXME: move this class to another file, it's no descriptor class ip_mac_notification_info(DVBobject): def pack(self): # pack platform id data loop pid_bytes = string.join( map(lambda x: x.pack(), self.platform_id_data_loop), "") platform_id_data_length = len(pid_bytes); fmt = "!B%ds%ds" % (platform_id_data_length, len(self.private_data_bytes)) return pack(fmt, platform_id_data_length, pid_bytes, self.private_data_bytes ) # FIXME: move this class to another file, it's no descriptor class platform_name(DVBobject): def pack(self): platform_name_length = len(self.text_char_bytes) fmt = "!3sB%ds" % platform_name_length return pack(fmt, self.ISO_639_language_code, platform_name_length, self.text_char_bytes ) # FIXME: move this class to another file, it's no descriptor class platform_id_data(DVBobject): def pack(self): pn_bytes = string.join( map(lambda x: x.pack(), self.platform_name_loop), "") platform_name_loop_length = len(pn_bytes) fmt = "!BBBB%ds" % platform_name_loop_length return pack(fmt, (self.platform_id >> 16) & 0xFF, (self.platform_id >> 8) & 0xFF, self.platform_id & 0xFF, platform_name_loop_length, pn_bytes ) class linkage_descriptor(Descriptor): descriptor_tag = 0x4A; def bytes(self): if (self.linkage_type == 0x0B): # pack platform id data loop pid_bytes = string.join( map(lambda x: x.pack(), self.platform_id_data_loop), "") platform_id_data_length = len(pid_bytes); fmt = "!BBBBBBBB%ds%ds" % (platform_id_data_length, len(self.private_data_bytes)) return pack(fmt, (self.transport_stream_id >> 8) & 0xFF, self.transport_stream_id & 0xFF, (self.original_network_id >> 8) & 0xFF, self.original_network_id & 0xFF, (self.service_id >> 8) & 0xFF, self.service_id & 0xFF, self.linkage_type, platform_id_data_length, pid_bytes, self.private_data_bytes ) else: fmt = "!BBBBBBB%ds" # we care only for linkage_type = 0x0B, other linkage descriptors # have to be implemented according to ETSI EN 300 468 standard return pack(fmt, (self.transport_stream_id >> 8) & 0xFF, self.transport_stream_id & 0xFF, (self.original_network_id >> 8) & 0xFF, self.original_network_id & 0xFF, (self.service_id >> 8) & 0xFF, self.service_id & 0xFF, self.linkage_type, private_data_bytes ) class terrestrial_delivery_system_descriptor(Descriptor): descriptor_tag = 0x5a def bytes(self): fmt = "!LBBBL" return pack(fmt, self.center_frequency & 0xFFFFFFFF, (self.bandwidth << 5) & 0xE0 | (self.priority << 4) & 0x10 | (self.timeslice_ind << 3) & 0x08 | (self.mpe_fec_ind << 2) & 0x04 | 0x03, (self.constellation << 6) | (self.hierarchy_information << 3)| (self.code_rate_HP_stream), (self.code_rate_LP_stream << 5) | (self.guard_interval << 3) | (self.transmission_mode << 1) | (self.other_frequency_flag), 0xffffffff, ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/SBTVD/0000755000175000017500000000000012214326456021201 5ustar debiandebianopencaster-3.2.2/libs/dvbobjects/dvbobjects/SBTVD/SDTT.py0000644000175000017500000001412312214326456022332 0ustar debiandebian# # Copyright 2010, LIFIA - Facultad de Informatica - Univ. Nacional de La Plata # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.utils.DVBobject import * from dvbobjects.MPEG.Descriptor import * from dvbobjects.MPEG.Section import Section from dvbobjects.utils.MJD import * # @author Ignacio Jaureguiberry # TODO Lots of testing, most classes needs to be modified # so that they work with default values. # TODO Clean up a bit. # # SDTT as defined in ARIB STD-B21 - ver 4.6-E1 - Table 12-1 # class software_download_trigger_table(Section): table_id = 0xC3 def pack_section_body(self): self.table_id_extension = (self.maker_id << 8) | (self.model_id & 0xff) content_bytes = string.join( map(lambda x: x.pack(), self.contents), "" ) fmt = ("!" "H" # transport_stream_id: 16 bits "H" # original_network_id: 16 "H" # service_id: 16 "B" # number_of_contents: 8 "%ds" # contents() % len(content_bytes)) return pack (fmt, self.transport_stream_id, self.original_network_id, self.service_id, len(self.contents), # number of contents, should be length in bytes instead of qty.?? content_bytes) class sdtt_content_loop_item(DVBobject): def pack(self): schedule_loop_bytes = string.join( map(lambda x: x.pack(), self.schedule_loop_items), "" ) descriptor_loop_bytes = string.join( map(lambda x: x.pack(), self.descriptors), "" ) fmt = ("!" "H" # group: 4 bits, target_version: 12 "H" # new_version: 12, download_level: 2, version_indicator: 2 "H" # content_descriptor_length: 12, reserved: 4 "H" # schedule_descriptor_length: 12, schedule_timeshift_information: 4 "%ds" # loop: start_time: 40, duration: 24 "%ds" # loop: descriptors % (len(schedule_loop_bytes),len(descriptor_loop_bytes))) return pack(fmt, (self.group << 12) | (self.target_version), (self.new_version << 4) | (self.download_level << 2) | self.version_indicator, ( (len(schedule_loop_bytes)+len(descriptor_loop_bytes)) << 4) | 0x0F, ( (len(schedule_loop_bytes)) << 4) | self.schedule_timeshift_information, schedule_loop_bytes, descriptor_loop_bytes) class sdtt_schedule_loop_item(DVBobject): def pack(self): fmt = ("!HBBBBBB") return pack(fmt, int(MJD_convert(self.start_year, self.start_month, self.start_day)), self.start_hour, self.start_minute, self.start_second, self.duration_hours, self.duration_minutes, self.duration_seconds, ) class download_content_descriptor(Descriptor): descriptor_tag = 0xC9 def has(self, bytes): if len(bytes) > 0: return 1 return 0 def bytes(self): # TODO clean up... if self.compatibility_descriptor_bytes == None: self.compatibility_descriptor_bytes = "\000\000" if self.modules_info_bytes == None: self.modules_info_bytes = "" if len(self.text_data) > 0 and len(self.text_ISO639_lang) == 3: text_data_bytes = pack( "3sB%ds" % len(self.text_data), self.text_ISO639_lang, len(self.text_data), self.text_data ) else: text_data_bytes = "" fmt = ("!" "B" # reboot:1, add_on:1, compatibility_flag=1, module_info_flag=1, text_info_flag=1, reserved=3 "L" # component_size:32 "L" # download_id: 32 "L" # time_out_value_DII: 32 "BH" # leak_rate: 22, reserved: 2 "B" # component_tag: 8 "H%ds" # compatibility_descriptor: if compatibility_flag=1 "%ds" # modules_info: if module_info_flag=1 "B" # private_data_length: 8 "%ds" # private_data_bytes "%ds" # text_data_bytes: if text_info_flag=1 % (len(self.compatibility_descriptor_bytes), len (self.modules_info_bytes), len (self.privateData), len (text_data_bytes) )) return pack( fmt, (self.reboot << 7) | (self.add_on << 6) | (self.has(self.compatibility_descriptor_bytes)) << 5 | (self.has(self.modules_info_bytes)) << 4 | (self.has(text_data_bytes)) << 3 | 0x07, # 3x1 bit for reserved field. self.component_size, # sum of data sizes transmitted by the carousel in bytes. self.download_id, # same as the one transmitted in DII/DDB self.time_out_value_DII, # timeout value in ms for all DII sections of the carousel. self.leak_rate >> 14, ((self.leak_rate << 2) | 0x3)&0xFFFF, # leak_rate. # TODO CHECK its ok... self.component_tag, len(self.compatibility_descriptor_bytes), self.compatibility_descriptor_bytes, self.modules_info_bytes, len(self.privateData), self.privateData, text_data_bytes ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/SBTVD/Descriptors.py0000755000175000017500000001277712214326456024075 0ustar debiandebian#! /usr/bin/env python # # Copyright (C) 2010 Robson Tovo , # Marco Casaroli # LIFIA - Facultad de Informatica - Univ. Nacional de La Plata # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.utils import * from dvbobjects.utils.MJD import * from dvbobjects.MPEG.Descriptor import Descriptor ###################################################################### class tds_frequency_item(DVBobject): def pack(self): self.freq7 = (self.freq * 7) + 1 fmt = "!H" return pack(fmt, self.freq7) class terrestrial_delivery_system_descriptor(Descriptor): descriptor_tag = 0xfa def bytes(self): frequency_bytes = string.join( map(lambda x: x.pack(), self.frequencies), "") fmt = "!H%ds" % len(frequency_bytes) return pack(fmt, ((self.area_code & 0xFFF) << 4) | ((self.guard_interval & 0x3) << 2) | (self.transmission_mode & 0x3), frequency_bytes) ###################################################################### # As specified by ARIB class partial_reception_descriptor(Descriptor): descriptor_tag = 0xfb def bytes(self): sid_pack = string.join(map (lambda x: pack("!H", x), self.service_ids), "") fmt = "!%ds" % (len(sid_pack)) return pack(fmt, sid_pack) ###################################################################### # As specified by ARIB class system_management_descriptor(Descriptor): descriptor_tag = 0xfe def bytes(self): sys_man_id = ( (self.broadcasting_flag << 14) | (self.broadcasting_identifier << 8) | (self.additional_broadcasting_identification) ) additional_id_info_pack = string.join( map (lambda x: pack("!B", x), self.additional_identification_bytes), "" ) fmt = "!H%ds" % len(additional_id_info_pack) return pack(fmt, sys_man_id, additional_id_info_pack) ###################################################################### class data_component_descriptor(Descriptor): descriptor_tag = 0xfd def bytes(self): fmt = "!H%ds" % len(self.additional_data_component_info) return pack(fmt, self.data_component_id, self.additional_data_component_info, ) ###################################################################### class service_id_loop_item(DVBobject): def pack(self): fmt = "!H" return pack(fmt, self.service_id) class transmission_type_loop_item(DVBobject): def pack(self): num_of_service = len(self.service_id_loop) service_id_loop_cat = string.join( map( lambda x: x.pack(), self.service_id_loop ), "" ) fmt = "!BB%ds" % len(service_id_loop_cat) return pack(fmt, self.transmission_type_info, num_of_service, service_id_loop_cat, ) class transport_stream_information_descriptor(Descriptor): descriptor_tag = 0xcd def bytes(self): name_len = len(self.ts_name) ts_type_count = len(self.transmission_type_loop) transmission_type_loop_cat = string.join( map( lambda x: x.pack(), self.transmission_type_loop ), "" ) fmt = "!BB%ds%ds" % (name_len, len(transmission_type_loop_cat)) return pack(fmt, self.remote_control_key_id, (name_len << 2) | ts_type_count, self.ts_name, transmission_type_loop_cat ) ###################################################################### class video_decode_control_descriptor(Descriptor): descriptor_tag = 0xc8 def bytes(self): return pack("!B", (self.still_picture_flag << 7) | (self.sequence_end_code_flag << 6) | (self.video_encode_format << 2) | 0x03 ) ###################################################################### class ts_loop_item(DVBobject): #tx_type_info # svc_loop = [] def pack(self): svc_bytes = "".join(map(lambda x: chr(x>>8 & 0xFF) + chr(x&0xFF), self.svc_loop)) fmt = "!BB%ds" % len(svc_bytes) return pack(fmt, self.tx_type_info, len(self.svc_loop), svc_bytes) class ts_info_descriptor(Descriptor): descriptor_tag = 0xcd # rc_key # tsname #ts_loop = [] def pack(self): ts_loop_bytes = "".join(map(lambda x: x.pack(), self.ts_loop)) fmt = "!BBBB%ds%ds" % (len(self.tsname), len(ts_loop_bytes)) # print len(ts_loop_bytes) return pack(fmt, self.descriptor_tag, len(self.tsname) + len(ts_loop_bytes) + 2, self.rc_key, len(self.tsname)<<2 | len(self.ts_loop) & 3, self.tsname, ts_loop_bytes) opencaster-3.2.2/libs/dvbobjects/dvbobjects/SBTVD/__init__.py0000755000175000017500000000157112214326456023321 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright 2000-2001, GMD, Sankt Augustin # -- German National Research Center for Information Technology # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA opencaster-3.2.2/libs/dvbobjects/dvbobjects/__init__.py0000755000175000017500000000000012214326456022421 0ustar debiandebianopencaster-3.2.2/libs/dvbobjects/dvbobjects/ATSC/0000755000175000017500000000000012220025244021035 5ustar debiandebianopencaster-3.2.2/libs/dvbobjects/dvbobjects/ATSC/Descriptors.py0000755000175000017500000000451712220024314023717 0ustar debiandebian#! /usr/bin/env python # # Copyright (C) 2013 Lorenzo Pallara, l.pallara@avalpa.com # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.utils import * from dvbobjects.utils.MJD import * from dvbobjects.MPEG.Descriptor import Descriptor ###################################################################### class rated_dimension_loop_item(DVBobject): def pack(self): fmt = "!BB" return pack(fmt, self.rating_dimension_j, 0xF0 | self.rating_value & 0xF ) ###################################################################### class rating_region_loop_item(DVBobject): def pack(self): self.rated_dimensions = len(self.rated_dimension_loop) data_bytes = string.join( map(lambda x: x.pack(), self.rated_dimension_loop), "") rating_description_bytes = self.rating_description_text.pack() fmt = "!BB%dsB%ds" % (len(data_bytes), len(rating_description_bytes)) return pack(fmt, self.rating_region, self.rated_dimensions, data_bytes, len(rating_description_bytes), rating_description_bytes ) ###################################################################### class content_advisory_descriptor(Descriptor): descriptor_tag = 0x87 def bytes(self): self.rating_region_count = len(self.rating_region_loop) data_bytes = string.join( map(lambda x: x.pack(), self.rating_region_loop), "") fmt = "!B%ds" % len(data_bytes) return pack(fmt, (0x3 << 6) | (self.rating_region_count & 0x3F), data_bytes, ) ###################################################################### class AC3_audio_stream_descriptor(Descriptor): descriptor_tag = 0x81 opencaster-3.2.2/libs/dvbobjects/dvbobjects/ATSC/__init__.py0000755000175000017500000000150412215056713023162 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright 2013, l.pallara@avalpa.com Lorenzo Pallara # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA opencaster-3.2.2/libs/dvbobjects/dvbobjects/ATSC/Loops.py0000755000175000017500000000375712215270667022541 0ustar debiandebian#! /usr/bin/env python # # Copyright (C) 2013 Lorenzo Pallara, l.pallara@avalpa.com # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.utils import * ###################################################################### class segment_loop_item(DVBobject): def pack(self): fmt = "!BBB%ds" % len(self.compressed_string) return pack(fmt, self.compression_type, self.mode, len(self.compressed_string), self.compressed_string, ) ###################################################################### class string_loop_item(DVBobject): def pack(self): assert len(self.ISO639_language_code) == 3 data_bytes = string.join( map(lambda x: x.pack(), self.segment_loop), "") self.number_segments = len(self.segment_loop) fmt = "!%dsB%ds" % (len(self.ISO639_language_code), len(data_bytes)) return pack(fmt, self.ISO639_language_code, self.number_segments, data_bytes ) ###################################################################### class multiple_string_structure(DVBobject): def pack(self): data_bytes = string.join( map(lambda x: x.pack(), self.string_loop), "") self.number_strings = len(self.string_loop) fmt = "!B%ds" % len(data_bytes) return pack(fmt, self.number_strings, data_bytes, ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/DSMCC/0000755000175000017500000000000012214326455021147 5ustar debiandebianopencaster-3.2.2/libs/dvbobjects/dvbobjects/DSMCC/Descriptors.py0000755000175000017500000001515012214326455024027 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright 2000-2001, GMD, Sankt Augustin # -- German National Research Center for Information Technology # # Copyright 2010, LIFIA - Facultad de Informatica - Univ. Nacional de La Plata # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.utils import * from dvbobjects.MPEG.Descriptor import Descriptor ###################################################################### class data_broadcast_descriptor(Descriptor): descriptor_tag = 0x64 data_broadcast_id = 0x0007 text_chars = "" def bytes(self): self.selector_length = len(self.selector_bytes) self.text_length = len(self.text_chars) FMT = "!HBB%ds%dsB%ds" % ( self.selector_length, 3, # ISO_639_language_code self.text_length, ) return pack( FMT, self.data_broadcast_id, self.component_tag, self.selector_length, self.selector_bytes, self.ISO_639_language_code, self.text_length, self.text_chars, ) def sample(self): self.set( component_tag = 0x11, selector_bytes = "012345", text_chars = "abcde", ) ###################################################################### class object_carousel_info(DVBobject): carousel_type_id = 0x02 transaction_id = 0xFFFFFFFF time_out_value_DSI = 0xFFFFFFFF time_out_value_DII = 0xFFFFFFFF leak_rate = 0x00 def pack(self): obj_loop_bytes = "" for obj_name_chars in self.object_names: object_name_length = len(obj_name_chars) obj_bytes = pack( "!3sB%ds" % object_name_length, self.ISO_639_language_code, object_name_length, obj_name_chars, ) obj_loop_bytes = obj_loop_bytes + obj_bytes obj_loop_length = len(obj_loop_bytes) FMT = "!B4L%ds" % obj_loop_length return pack( FMT, (self.carousel_type_id << 6 | 0x63), self.transaction_id, self.time_out_value_DSI, self.time_out_value_DII, (0x0C000000 | self.leak_rate), obj_loop_bytes, ) def sample(self): self.set( object_names = ["aaa", "bbbbbb"] ) ###################################################################### class stream_event_descriptor(Descriptor): descriptor_tag = 0x1a reserved = 0x0L # TODO Check: Shouldn't this be 0xFFFFFFFEL? def bytes(self): self.text_length = len(self.private_data) FMT = "!HLL%ds" % self.text_length return pack( FMT, self.event_id, self.reserved | ( self.eventNPT >> 32), # 31 bits reserved, 1 bit NPT_reference self.eventNPT & 0xFFFFFFFF, # 32 bits NPT_reference self.private_data, ) ###################################################################### class stream_event_do_it_now_descriptor(stream_event_descriptor): eventNPT = 0x0 ###################################################################### class stream_event_ginga_descriptor(stream_event_descriptor): eventNPT = 0x0 command_tag = 0x0 sequence = 0x0 finalFlag = 0x0 payload = "" FCS = 0x00 # TODO calculate FCS. def bytes(self): FMT = ("!" "B" # private data length "B" # command_tag "B" # sequence_number: 7b, final_flag: 1b "%ds"# private data payload "B" # FCS ) % (len(self.payload)) self.private_data = pack(FMT, 3+len(self.payload), self.command_tag, ((self.sequence_number & 0x7F) << 1) | (self.final_flag & 0x01), self.payload, self.FCS ) # call superclass implementation. return stream_event_descriptor.bytes(self) ###################################################################### class npt_reference_descriptor(Descriptor): descriptor_tag = 0x01 def bytes(self): self.text_length = len(self.private_data) FMT = ( "!" "B" # post_continuity_indicator: 1b, content_id: 7b "B" # reserved: 7b, STC_reference: 1b - most significant bit "L" # STC_reference: 32b "L" # reserved: 31b, NPT_reference: 1b - most significant bit "L" # NPT_reference: 32b "H" # scale_numerator : 16b "H")# scale_denominator: 16b return pack( FMT, (self.post_continuity_indicator << 7) | (self.content_id & 0x7F), # 1 bit postcontdesc, 7 bits contentId 0xFE | ( self.STC_reference >> 32), # 31 bits reserved, 1 bit STC_reference self.STC_reference & 0xFFFFFFFF, # 32 bits STC_reference 0xFFFFFFFE | ( self.NPT_reference >> 32), # 31 bits reserved, 1 bit NPT_reference self.NPT_reference & 0xFFFFFFFF, # 32 bits NPT_reference self.scale_numerator, self.scale_denominator ) ###################################################################### class npt_endpoint_descriptor(Descriptor): descriptor_tag = 0x02 def bytes(self): self.text_length = len(self.private_data) FMT = ( "!" "H" # reserved: 15b, NPT_start: 1b - most significant bit "L" # NPT_start: 32b "L" # reserved: 31b, NPT_stop : 1b - most significant bit "L")# NPT_stop : 32b return pack( FMT, 0xFFFE | ( self.NPT_start >> 32), # 15 bits reserved, 1 bit NPT_start self.NPT_start & 0xFFFFFFFF, # 32 bits STC_reference 0xFFFFFFFE | ( self.NPT_stop >> 32), # 31 bits reserved, 1 bit NPT_stop self.NPT_stop & 0xFFFFFFFF # 32 bits NPT_stop ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/DSMCC/STEO.py0000755000175000017500000000342612214326455022303 0ustar debiandebian#! /usr/bin/env python # # Copyright (C) 2006-2013 Lorenzo Pallara, l.pallara@avalpa.com # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import os import string from dvbobjects.DSMCC.BIOP.Tap import * from dvbobjects.utils import * ############################### class Event_names(DVBobject): def pack(self): result = pack("!H", self.eventnames_count) for name in self.event_name_loop: name = name + "\x00" result = result + pack( "!B%ds" % len(name), len(name), name, ) return result ############################### class Event_ids(DVBobject): def pack(self): result = pack("!B", self.eventids_count) for id in self.event_id_loop: result = result + pack("!H", id) return result ############################### class Taps(DVBobject): def pack(self): result = pack("!B", self.taps_count) for tap in self.tap_loop: result = result + tap.pack() return result ############################### opencaster-3.2.2/libs/dvbobjects/dvbobjects/DSMCC/STE.py0000755000175000017500000000300012214326455022150 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright 2006-2013 Lorenzo Pallara # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import string from dvbobjects.MPEG.Section import Section from dvbobjects.DSMCC.Descriptors import * ###################################################################### class stream_event_section(Section): table_id = 0x3d section_max_size = 4096 def pack_section_body(self): self.table_id_extension = self.event_id self.segment_last_section_number = self.last_section_number self.last_table_id = self.table_id # pack event_loop stel_bytes = string.join( map(lambda x: x.pack(), self.stream_event_descriptor_loop), "") fmt = "!%ds" % len(stel_bytes) return pack(fmt, stel_bytes, ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/DSMCC/BIOP/0000755000175000017500000000000012214326455021700 5ustar debiandebianopencaster-3.2.2/libs/dvbobjects/dvbobjects/DSMCC/BIOP/Tap.py0000755000175000017500000001157412214326455023011 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright 2000-2001, GMD, Sankt Augustin # -- German National Research Center for Information Technology # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA from dvbobjects.utils import * ###################################################################### class _tap(DVBobject): BIOP_DELIVERY_PARA_USE = 0x0016 BIOP_OBJECT_USE = 0x0017 BIOP_ES_USE = 0x0018 BIOP_PROGRAM_USE = 0x0019 STR_NPT_USE = 0x000B STR_STATUS_AND_EVENT_USE = 0x000C STR_EVENT_USE = 0x000D STR_STATUS_USE = 0x000E id = 0x0000 # MHP ###################################################################### class object_tap(_tap): use = _tap.BIOP_OBJECT_USE selector = "" # MHP ??? def pack(self): assert self.selector == "" # MHP ??? FMT = ( "!" "H" # id "H" # use "H" # assocTag "B" # selector_length ) return pack( FMT, self.id, self.use, self.assocTag, len(self.selector), ) ###################################################################### class elementary_stream_tap(_tap): use = _tap.BIOP_ES_USE selector = "" # MHP ??? def pack(self): assert self.selector == "" # MHP ??? FMT = ( "!" "H" # id "H" # use "H" # assocTag "B" # selector_length ) return pack( FMT, self.id, self.use, self.assocTag, len(self.selector), ) ###################################################################### class program_use_tap(_tap): use = _tap.BIOP_PROGRAM_USE selector = "" # MHP ??? def pack(self): assert self.selector == "" # MHP ??? FMT = ( "!" "H" # id "H" # use "H" # assocTag "B" # selector_length ) return pack( FMT, self.id, self.use, self.assocTag, len(self.selector), ) ###################################################################### class str_event_use_tap(_tap): use = _tap.STR_EVENT_USE selector = "" # MHP ??? def pack(self): assert self.selector == "" # MHP ??? FMT = ( "!" "H" # id "H" # use "H" # assocTag "B" # selector_length ) return pack( FMT, self.id, self.use, self.assocTag, len(self.selector), ) ###################################################################### class delivery_para_tap(_tap): use = _tap.BIOP_DELIVERY_PARA_USE selector_length = 0x0A # MHP selector_type = 0x0001 # MHP def pack(self): FMT = ( "!" "H" # id "H" # use "H" # assocTag "B" # selector_length "H" # selector_type "L" # transaction_id "L" # timeout ) return pack( FMT, self.id, self.use, self.assocTag, self.selector_length, self.selector_type, int(self.transactionId), int(self.timeout), ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/DSMCC/BIOP/Binding.py0000755000175000017500000000666012214326455023637 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright 2000-2001, GMD, Sankt Augustin # -- German National Research Center for Information Technology # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA from dvbobjects.utils import * BINDING_TYPE_NOBJECT = 0x01 BINDING_TYPE_NCONTEXT = 0x02 ###################################################################### class Binding(DVBobject): nameComponents_count = 1 # DVB def __init__(self, **kwargs): # Initialize SuperClass apply(DVBobject.__init__, (self,), kwargs) assert self.bindingType in ( # DVB BINDING_TYPE_NOBJECT, BINDING_TYPE_NCONTEXT) def pack(self): ior = self.IOR.pack() FMT = ( "!" "B" # nameComponents_count "B%ds" # id "B%ds" # kind "B" # bindingType "%ds" # IOP::IOR() "H%ds" # objectInfo ) % ( len(self.nameId), len(self.nameKind), len(ior), len(self.objectInfo), ) return pack( FMT, self.nameComponents_count, len(self.nameId), self.nameId, len(self.nameKind), self.nameKind, self.bindingType, ior, len(self.objectInfo), self.objectInfo, ) def __repr__(self): """Overrides DVBobject.__repr_, which is noooiiisy""" loc = self.IOR.profile.objectLocation mod = loc.moduleId key = loc.objectKey return `(self.nameId, (mod, key), )` ###################################################################### class ObjectFileBinding(Binding): bindingType = BINDING_TYPE_NOBJECT nameKind = CDR("fil") def __init__(self, **kwargs): # Initialize SuperClass apply(Binding.__init__, (self,), kwargs) self.objectInfo = pack("!LL", 0, self.contentSize) ###################################################################### class ObjectStreamEventBinding(Binding): bindingType = BINDING_TYPE_NOBJECT nameKind = CDR("ste") objectInfo = "" def __init__(self, **kwargs): # Initialize SuperClass apply(Binding.__init__, (self,), kwargs) ###################################################################### class ContextBinding(Binding): bindingType = BINDING_TYPE_NCONTEXT nameKind = CDR("dir") # MHP objectInfo = "" # MHP def __init__(self, **kwargs): # Initialize SuperClass apply(Binding.__init__, (self,), kwargs) opencaster-3.2.2/libs/dvbobjects/dvbobjects/DSMCC/BIOP/ModuleInfo.py0000755000175000017500000000500112214326455024312 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright 2000-2001, GMD, Sankt Augustin # -- German National Research Center for Information Technology # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA from dvbobjects.utils import * import Tap import string ###################################################################### class ModuleInfo(DVBobject): ModuleTimeOut = 0xFFFFFFFF BlockTimeOut = 0xFFFFFFFF # MinBlockTime = 0x000061a8 MinBlockTime = 0x00000001 userInfo = "" def __init__(self, **kwargs): # Initialize SuperClass apply(DVBobject.__init__, (self,), kwargs) self.taps = [ Tap.object_tap( assocTag = self.assocTag, ) ] def pack(self): assert len(self.taps) >= 1 # MHP taps_bytes = string.join(map(lambda t: t.pack(), self.taps), "") user_info_bytes = string.join(map(lambda ui: ui.pack(), self.userInfo), "") FMT =("!" "L" # ModuleTimeOut "L" # BlockTimeOut "L" # MinBlockTime "B" # taps_count "%ds" # taps "B" "%ds" # userInfo ) % ( len(taps_bytes), len(user_info_bytes), ) return pack(FMT, self.ModuleTimeOut, self.BlockTimeOut, self.MinBlockTime, len(self.taps), taps_bytes, len(user_info_bytes), user_info_bytes, ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/DSMCC/BIOP/IOP.py0000755000175000017500000001221112214326455022701 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright 2000-2001, GMD, Sankt Augustin # -- German National Research Center for Information Technology # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA from dvbobjects.utils import * from dvbobjects.DSMCC.BIOP import Tap ###################################################################### class IOR(DVBobject): def __init__(self, **kwargs): apply(DVBobject.__init__, (self,), kwargs) # Hard coded; TBD... objectLocation = BIOP_ObjectLocation( carouselId = self.carouselId, moduleId = self.moduleId, objectKey = self.objectKey, ) tap = Tap.delivery_para_tap( assocTag = self.assocTag, transactionId = self.transactionId, timeout = self.timeout, ) connBinder = DSM_ConnBinder( tap = tap, ) self.profile = BIOPProfileBody( objectLocation = objectLocation, connBinder = connBinder, ) def pack(self): taggedProfiles_count = 1 # MHP / TBD assert len(self.type_id) == 4, `self.type_id` profile_bytes = self.profile.pack() FMT = ("!" "L%ds" # type_id "L" # taggedProfiles_count "%ds" # IOP::taggedProfile() ) % ( len(self.type_id), len(profile_bytes), ) ior_bytes = pack( FMT, len(self.type_id), self.type_id, taggedProfiles_count, profile_bytes, ) return ior_bytes ###################################################################### class BIOPProfileBody(DVBobject): profileId_tag = 0x49534F06 profile_data_byte_order = 0x00 def __init__(self, **kwargs): # Initialize SuperClass apply(DVBobject.__init__, (self,), kwargs) def pack(self): profile_data = ( self.objectLocation.pack() + self.connBinder.pack() ) lite_component_count = 2 profile_data_length = len(profile_data) + 2 FMT = ("!" "L" # profileId_tag "L" # profile_data_length "B" # profile_data_byte_order "B" # lite_component_count "%ds" # profile_data ) % ( len(profile_data), ) return pack( FMT, self.profileId_tag, profile_data_length, self.profile_data_byte_order, lite_component_count, profile_data, ) ###################################################################### class BIOP_ObjectLocation(DVBobject): componentId_tag = 0x49534F50 biop_version_major = 0x01 biop_version_minor = 0x00 def pack(self): FMT = ( "!" "L" # componentId_tag "B" # component_data_length "L" # carouselId "H" # moduleId "B" # major version "B" # minor version "B" # objectKey length "L" # objectKey ) return pack( FMT, self.componentId_tag, calcsize(FMT) - 5, self.carouselId, self.moduleId, self.biop_version_major, self.biop_version_minor, 4, self.objectKey, ) ###################################################################### class DSM_ConnBinder(DVBobject): componentId_tag = 0x49534F40 def pack(self): taps_count = 1 taps_bytes = self.tap.pack() FMT = ( "!" "L" # componentId_tag "B" # component_data_length "B" # taps_count "%ds" # taps_bytes ) % len(taps_bytes) return pack( FMT, self.componentId_tag, calcsize(FMT) - 5, # component_data_length taps_count, taps_bytes, ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/DSMCC/BIOP/__init__.py0000755000175000017500000000221712214326455024016 0ustar debiandebian# This file is part of the dvbobjects library. # # Copyright 2000-2001, GMD, Sankt Augustin # -- German National Research Center for Information Technology # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA from Message import ServiceGatewayMessage, DirectoryMessage, FileMessage, StreamEventMessage from Message import ServiceGatewayInfo from Tap import delivery_para_tap, object_tap from Binding import ContextBinding, ObjectFileBinding, ObjectStreamEventBinding from ModuleInfo import ModuleInfo import IOP opencaster-3.2.2/libs/dvbobjects/dvbobjects/DSMCC/BIOP/Message.py0000755000175000017500000001701612214326455023646 0ustar debiandebian# This file is part of the dvbobjects library. # # Copyright 2000-2001, GMD, Sankt Augustin # -- German National Research Center for Information Technology # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import os import string from dvbobjects.utils import * from dvbobjects.MHP.Descriptors import content_type_descriptor ###################################################################### class Message(DVBobject): magic = "BIOP" # ISO biop_version_major = 0x01 # ISO biop_version_minor = 0x00 # ISO byte_order = 0x00 # DVB message_type = 0x00 # ISO serviceContextList = "" # MHP def pack(self): # sanity check assert self.byte_order == 0x00 # DVB assert len(self.objectKind) == 0x04, `self.objectKind` # DVB MessageSubHeader_FMT = ( "!" "B" "L" # objectKey "L" "%ds" # objectKind "H" "%ds" # objectInfo "B" "%ds" # serviceContextList ) % ( len(self.objectKind), len(self.objectInfo), len(self.serviceContextList), ) MessageSubHeader = pack( MessageSubHeader_FMT, 4, self.objectKey, len(self.objectKind), self.objectKind, len(self.objectInfo), self.objectInfo, len(self.serviceContextList), self.serviceContextList, ) messageBody = self.messageBody() message_size = ( len(MessageSubHeader) + 4 # messageBody_length field + len(messageBody) ) MessageHeader = pack ( "!" "4s" # magic "B" # biop_version_major "B" # biop_version_minor "B" # byte_order "B" # message_type "L" # message_size , # end of FMT ;-) self.magic, self.biop_version_major, self.biop_version_minor, self.byte_order, self.message_type, message_size, # computed ) FMT = ("!" "%ds" # MessageHeader "%ds" # MessageSubHeader "L" # messageBody_length "%ds" # messageBody ) % ( len(MessageHeader), len(MessageSubHeader), len(messageBody) ) return pack( FMT, # see above MessageHeader, MessageSubHeader, len(messageBody), # messageBody messageBody, ) ###################################################################### class FileMessage(Message): objectKind = CDR("fil") # DVB def __init__(self, **kwargs): # Initialize SuperClass apply(Message.__init__, (self,), kwargs) # Initialize standard attributes self.set( objectInfo = pack("!LL", 0, self.contentSize), ) # Maybe we're playing MHP... try: content_type = self.content_type except AttributeError: content_type = None # i.e: UNKNOWN # if we know a content_type, add descriptor... if content_type: ctd = content_type_descriptor(content_type=content_type) self.objectInfo = self.objectInfo + ctd.pack() def messageBody(self): # Retrieve the file message body (i.e. file content) content = open(self.PATH).read() content_length = len(content) assert content_length == self.contentSize, self.PATH return pack("!L%ds" % content_length, content_length, content, ) ###################################################################### class StreamEventMessage(Message): objectKind = CDR("ste") # DVB objectInfo = "" def __init__(self, **kwargs): # Initialize SuperClass apply(Message.__init__, (self,), kwargs) info_t = pack("!BLLBBB" , 0, 0, 0, 0, 0, 1) # Hard coded DSM::Stream::Info_T.pack() for do it now event_names = open(self.PATH + "/.ename").read() self.objectInfo = info_t + event_names def messageBody(self): # stream event do it now: BIOP.program_use_tap (id undefined) + eventIds taps = open(self.PATH + "/.tap").read() event_ids = open(self.PATH + "/.eid").read() return taps + event_ids ###################################################################### class DirectoryMessage(Message): objectKind = CDR("dir") # DVB objectInfo = "" # MHP def __init__(self, **kwargs): # Initialize SuperClass apply(Message.__init__, (self,), kwargs) self.bindings_count = len(self.bindings) assert self.bindings_count < 512 # MHP def messageBody(self): separator = "" # for debugging bindings = "%s%s%s" % ( separator, string.join(map(lambda binding: binding.pack(), self.bindings), separator), separator) FMT = ( "!" "H" # bindings_count "%ds" # bindings ) % (len(bindings)) messageBody = pack( FMT, len(self.bindings), bindings, ) return messageBody ###################################################################### class ServiceGatewayMessage(DirectoryMessage): objectKind = CDR("srg") # DVB ###################################################################### class ServiceGatewayInfo(DVBobject): userInfo = "" # MHP def pack(self): FMT = ("!" "%ds" # IOP::IOR "B" # downloadTaps_count "B" # serviceContextList_count "H%ds" # userInfo ) % ( len(self.srg_ior), len(self.userInfo), ) return pack(FMT, self.srg_ior, # IOP::IOR 0, # downloadTaps_count 0, # serviceContextList_count len(self.userInfo), self.userInfo, ) opencaster-3.2.2/libs/dvbobjects/dvbobjects/DSMCC/__init__.py0000755000175000017500000000157112214326455023267 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright 2000-2001, GMD, Sankt Augustin # -- German National Research Center for Information Technology # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA opencaster-3.2.2/libs/dvbobjects/dvbobjects/DSMCC/Message.py0000755000175000017500000001621012214326455023110 0ustar debiandebian#! /usr/bin/env python # This file is part of the dvbobjects library. # # Copyright 2000-2001, GMD, Sankt Augustin # -- German National Research Center for Information Technology # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA from dvbobjects.utils import * from dvbobjects.MPEG.Section import Section ###################################################################### class TransactionId(DVBobject): originator = 0x02 # DVB def __init__(self, **kwargs): # Initialize SuperClass apply(DVBobject.__init__, (self,), kwargs) # debugging self.HEX = "0x%08X" % self.__int__() self.originator = self.originator def __int__(self): return ( self.originator << 30 | (self.version << 16) | (self.identification << 1) | (self.updateFlag & 0x1) ) ###################################################################### class DSMCCmessage(Section): private_indicator = 0 protocolDiscriminator = 0x11 # DSMCC dsmccType = 0x03 # DSMCC U-N Message adaptationLength = 0x00 # ??? compatibilityDescriptor = "" # DVB privateData = None def __init__(self, **kwargs): # Initialize SuperClass apply(Section.__init__, (self,), kwargs) # debugging def pack_section_body(self): messageBody = self.pack_message_body() messageLength = len(messageBody) # +- something FMT = ("!" # Network Byte Order "B" # protocolDiscriminator "B" # dsmccType "H" # messageId "L" # transactionId "B" # reserved "B" # adaptationLength "H" # messageLength "%ds" # messageBody ) % messageLength return pack(FMT, self.protocolDiscriminator, self.dsmccType, self.messageId, self.transactionId, 0xFF, # reserved self.adaptationLength, messageLength, messageBody, ) ###################################################################### class DownloadServerInitiate(DSMCCmessage): # DSI # MPEG Section attributes version_number = 0 section_number = 0 last_section_number = 0 table_id = 0x3B # DSMCC messageId = 0x1006 # DSMCC serverId = "\xFF" * 20 # DVB / MHP def __init__(self, **kwargs): # Initialize SuperClass apply(DSMCCmessage.__init__, (self,), kwargs) # debugging def pack_message_body(self): self.table_id_extension = (0x0000FFFF & int(self.transactionId)) privateDataBytes = self.privateData.pack() FMT = ("!" # Network Byte Order "%ds" # serverId "H%ds" # compatibilityDescriptor() "H%ds" # privateDataBytes ) % ( len(self.serverId), len(self.compatibilityDescriptor), len(privateDataBytes), ) return pack( FMT, self.serverId, len(self.compatibilityDescriptor), self.compatibilityDescriptor, len(privateDataBytes), privateDataBytes, ) ###################################################################### class DownloadInfoIndication(DSMCCmessage): # DII # MPEG Section attributes version_number = 0 section_number = 0 last_section_number = 0 table_id = 0x3B # DSMCC messageId = 0x1002 # DSMCC windowSize = 0 # DVB ackPeriod = 0 # DVB tCDownloadWindow = 0 # DVB tCDownloadScenario = 0 # ??? def __init__(self, **kwargs): # Initialize SuperClass apply(DSMCCmessage.__init__, (self,), kwargs) # debugging def pack_message_body(self): self.table_id_extension = (0x0000FFFF & int(self.transactionId)) if self.privateData == None: privateDataBytes = "" miiBytes = self.moduleInfoIndication.pack() fmt = ("!" # Network Byte Order "L" # downloadId "H" # blockSize "B" # windowSize "B" # ackPeriod "L" # tCDownloadWindow "L" # tCDownloadScenario "H%ds" # compatibilityDescriptor "%ds" # miiBytes "H%ds" # privateDataBytes ) % ( len(self.compatibilityDescriptor), len(miiBytes), len(privateDataBytes), ) return pack(fmt, self.downloadId, self.blockSize, self.windowSize, self.ackPeriod, self.tCDownloadWindow, self.tCDownloadScenario, len(self.compatibilityDescriptor), self.compatibilityDescriptor, miiBytes, len(privateDataBytes), privateDataBytes, ) ###################################################################### class DownloadDataBlock(DSMCCmessage): # DDB table_id = 0x3C # DSMCC messageId = 0x1003 # DSMCC def pack_message_body(self): # section attributes self.table_id_extension = self.moduleId self.version_number = self.moduleVersion % 32 # override transactionId with downloadId # i.e. dsmccMessageHeader := dsmccDownloadHeader self.transactionId = self.downloadId fmt ="!HBBH%ds" % len(self.data_block) return pack(fmt, self.moduleId, self.moduleVersion, 0xFF, self.blockNumber, self.data_block ) opencaster-3.2.2/libs/dvbobjects/setup.py0000755000175000017500000000163112220025274017677 0ustar debiandebian#! /usr/bin/env python from distutils.core import setup, Extension import sys # from an original source code by Joachim Kaeber (kaeber@gmd.de) _ext_modules = None if sys.platform in ['linux2', 'solaris2', 'win32']: _ext_modules = [ Extension('dvbobjects.utils._crc32', [ 'sectioncrc.py.c'] ), ] setup( name = "dvbobjects", version = "0.1", description = "Python Package for dvb transport stream data generation (PAT, PMT, NIT, Object Carousel, ...)", author = "Lorenzo Pallara", author_email = "l.pallara@avalpa.com", url = "", packages = [ 'dvbobjects', 'dvbobjects.ATSC', 'dvbobjects.DSMCC', 'dvbobjects.DSMCC.BIOP', 'dvbobjects.DVB', 'dvbobjects.MHP', 'dvbobjects.HBBTV', 'dvbobjects.PSI', 'dvbobjects.MPEG', 'dvbobjects.SBTVD', 'dvbobjects.utils', ], ext_modules = _ext_modules ) opencaster-3.2.2/libs/sectioncrc/0000755000175000017500000000000012214326456016201 5ustar debiandebianopencaster-3.2.2/libs/sectioncrc/sectioncrc.c0000755000175000017500000001076312214326456020513 0ustar debiandebian/* sectioncrc.c -- MPEG-2 checksum calculation, Python Module Copyright (C) 2001 Oleg Tchekoulaev, GMD This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* crctab taken from cksum.c by Q. Frank Xia, qx@math.columbia.edu. */ #include static uint32_t const crctab[256] = { 0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, 0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9, 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75, 0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, 0x709f7b7a, 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039, 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58, 0xbaea46ef, 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d, 0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49, 0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95, 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, 0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0, 0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072, 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, 0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca, 0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde, 0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1, 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba, 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, 0xbb60adfc, 0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6, 0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a, 0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e, 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2, 0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34, 0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637, 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, 0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f, 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53, 0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, 0x3f9b762c, 0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff, 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e, 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b, 0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3, 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, 0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71, 0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3, 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, 0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c, 0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8, 0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e, 0x18197087, 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec, 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, 0x2056cd3a, 0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0, 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c, 0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18, 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, 0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662, 0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4}; uint32_t sectioncrc( unsigned char *buf, unsigned int len ) { unsigned char *p; uint32_t crc; crc = 0xffffffff; p = buf; while( len-- ) { crc = (crc<<8) ^ crctab[((crc>>24) ^ *(p++)) & 0xFF]; } return crc; } opencaster-3.2.2/libs/sectioncrc/Makefile0000755000175000017500000000041112214326456017640 0ustar debiandebianC = gcc CFLAGS = -g -MD -Wall -I. -I../../include OBJ = sectioncrc.o all: $(OBJ) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LFLAGS) install: all clean: rm -f $(OBJS) core* *~ *.d *.o -include $(wildcard *.d) dummy opencaster-3.2.2/libs/sectioncrc/sectioncrc.h0000755000175000017500000000161012214326456020507 0ustar debiandebian/* sectioncrc.h -- MPEG-2 checksum calculation Copyright (C) 2001 Oleg Tchekoulaev, GMD This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include uint32_t sectioncrc( unsigned char*, unsigned int ); opencaster-3.2.2/tools/0000755000175000017500000000000012220026472014244 5ustar debiandebianopencaster-3.2.2/tools/tsloop/0000755000175000017500000000000012214326444015571 5ustar debiandebianopencaster-3.2.2/tools/tsloop/Makefile0000755000175000017500000000062312214326444017235 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = tsloop.o TARGET = tsloop DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/tsloop/tsloop.c0000644000175000017500000000714112214326444017260 0ustar debiandebian/* * Copyright (C) 2005-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #define TS_PACKET_SIZE 188 #define MAX_PID 8192 int main(int argc, char *argv[]) { int open_file; int byte_read; int fd_ts; /* File descriptor of ts file */ unsigned short pid; unsigned char adaptation_field; unsigned char packet[TS_PACKET_SIZE]; unsigned char pid_cc_table[MAX_PID]; /* PID table for the continuity counter of the TS packets */ unsigned char previous_cc_table[MAX_PID]; /* two packets can have the same continuity counter under some conditions... */ /* Open first ts file */ if (argc >= 2) { open_file = 1; fd_ts = open(argv[open_file], O_RDONLY); if (fd_ts < 0) { fprintf(stderr, "Can't find file %s\n", argv[open_file]); return 2; } } else { fprintf(stderr, "Usage: 'tsloop filename1.ts filename2.ts ... filenameN.ts'\n"); return 2; } /* Start to process the file */ memset(pid_cc_table, 0x10, MAX_PID); memset(previous_cc_table, 0x10, MAX_PID); while(1) { /* read packets */ byte_read = 0; byte_read = read(fd_ts, packet, TS_PACKET_SIZE); if (byte_read < TS_PACKET_SIZE) { open_file %= argc - 1; open_file += 1; close(fd_ts); memset(previous_cc_table, 0x10, MAX_PID); fd_ts = open(argv[open_file], O_RDONLY); if (fd_ts < 0) { fprintf(stderr, "Can't find file %s\n", argv[open_file]); return 2; } byte_read = read(fd_ts, packet, TS_PACKET_SIZE); if (byte_read <= 0) { return 2; } } /* check packets cc */ memcpy(&pid, packet + 1, 2); pid = ntohs(pid); pid = pid & 0x1fff; if (pid < MAX_PID) { if (pid_cc_table[pid] == 0x10) { fprintf(stderr, "new pid entry %d\n", pid); pid_cc_table[pid] = packet[3] & 0x0f; /* new stream to track cc */ previous_cc_table[pid] = packet[3] & 0x0f; } else { adaptation_field = (packet[3] & 0x30) >> 4; if (adaptation_field == 0x0 || adaptation_field == 0x2) { /* reserved, no increment */ packet[3] = (pid_cc_table[pid] | (packet[3] & 0xf0)); } else if ((adaptation_field == 0x1) && ((packet[3] & 0x0f) == previous_cc_table[pid])) { /* double packet accepted only once */ packet[3] = (pid_cc_table[pid] | (packet[3] & 0xf0)); previous_cc_table[pid] = 0x10; } else if ((adaptation_field == 0x3) && ((packet[3] & 0x0f) == previous_cc_table[pid])) { /* double packet accepted only once */ packet[3] = (pid_cc_table[pid] | (packet[3] & 0xf0)); previous_cc_table[pid] = 0x10; } else { /* increase the cc and restamp */ previous_cc_table[pid] = packet[3] & 0x0f; pid_cc_table[pid] = (pid_cc_table[pid] + 1) % 0x10; packet[3] = (pid_cc_table[pid] | (packet[3] & 0xf0)); } } } /* write packets */ write(STDOUT_FILENO, packet, TS_PACKET_SIZE); } } opencaster-3.2.2/tools/tsfilter/0000755000175000017500000000000012214326444016105 5ustar debiandebianopencaster-3.2.2/tools/tsfilter/Makefile0000755000175000017500000000062712214326444017555 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = tsfilter.o TARGET = tsfilter DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/tsfilter/tsfilter.c0000644000175000017500000000543312214326444020112 0ustar debiandebian/* * Copyright (C) 2004-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #define TS_PACKET_SIZE 188 #define MAX_PID 8192 void Usage(void) { fprintf(stderr, "Usage: 'tsfilter filename.ts +pid1 +pid2 ... +pidn [buffer_size_in_packets]'\n"); fprintf(stderr, "+pid keeps 'pid' packets\n"); } int main(int argc, char *argv[]) { int byte_read; int fd_ts; /* File descriptor of ts file */ unsigned short pid; unsigned int i; unsigned char* packet_buffer; unsigned char* current_packet; unsigned int buffer_size; unsigned char pid_table[MAX_PID]; /* valid PID table */ /* Parse input arguments */ buffer_size = 0; memset(pid_table, 0, MAX_PID); if (argc >= 2) { fd_ts = open(argv[1], O_RDONLY); if (fd_ts < 0) { fprintf(stderr, "Can't find file %s\n", argv[1]); return 2; } } else { Usage(); return 2; } i = 2; while (i < argc) { if (argv[i][0] == '+') { pid = atoi(&(argv[i][1])); if ( pid < MAX_PID) { fprintf(stderr, "keep pid %d\n", pid); pid_table[pid] = 1; i++; } else { fprintf(stderr, "pid range should be from 0 to %d\n", MAX_PID); return 2; } } else { buffer_size = atoi(&(argv[i][0])); i++; } } if (buffer_size == 0) { buffer_size = 1; } /* Allocate packet buffer */ buffer_size *= TS_PACKET_SIZE; packet_buffer = malloc(buffer_size); if (packet_buffer == NULL) { fprintf(stderr, "Out of memory\n"); return 2; } /* Start to process the file */ byte_read = 1; while(byte_read) { /* read packets */ byte_read = read(fd_ts, packet_buffer, buffer_size); /* filter packets on their pids */ for (i = 0; i < buffer_size; i+=TS_PACKET_SIZE) { current_packet = packet_buffer+i; memcpy(&pid, current_packet + 1, 2); pid = ntohs(pid); pid = pid & 0x1fff; if (pid < MAX_PID) { if (pid_table[pid] == 1) { write(STDOUT_FILENO, current_packet, TS_PACKET_SIZE); } } } } return 0; } opencaster-3.2.2/tools/tsnullshaper/0000755000175000017500000000000012214326444016775 5ustar debiandebianopencaster-3.2.2/tools/tsnullshaper/Makefile0000644000175000017500000000064412214326444020441 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc -lrt OBJS = tsnullshaper.o TARGET = tsnullshaper DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/tsnullshaper/tsnullshaper.c0000644000175000017500000002353212214326444021672 0ustar debiandebian/* * Copyright (C) 2004-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #include #include #define TS_PACKET_SIZE 188 #define MAX_PID 8192 typedef struct queue { int fd; char* name; long long int time; int repeat_time; int mandatory; struct queue* next; } fd_queue; fd_queue* g_fd_count_queue = 0; /* cicular queue */ fd_queue* g_fd_count_queue_last = 0; /* add cache circular queue */ fd_queue* g_fd_time_queue = 0; /* time based queue */ fd_queue* g_fd_time_queue_last = 0; /* add cache time based queue */ struct timespec g_start_time; /* nsec difference between timespec */ long long int usecDiff(struct timespec* time_stop, struct timespec* time_start) { long long int temp = 0; long long int utemp = 0; if (time_stop && time_start) { if (time_stop->tv_nsec >= time_start->tv_nsec) { utemp = time_stop->tv_nsec - time_start->tv_nsec; temp = time_stop->tv_sec - time_start->tv_sec; } else { utemp = time_stop->tv_nsec + 1000000000 - time_start->tv_nsec; temp = time_stop->tv_sec - 1 - time_start->tv_sec; } if (temp >= 0 && utemp >= 0) { temp = (temp * 1000000000) + utemp; } else { fprintf(stderr, "start time %ld.%ld is after stop time %ld.%ld\n", time_start->tv_sec, time_start->tv_nsec, time_stop->tv_sec, time_stop->tv_nsec); temp = -1; } } else { fprintf(stderr, "memory is garbaged?\n"); temp = -1; } return temp / 1000; } int enqueue_time_fd(int fd, char* name, int repeat_time) { fd_queue* fd_new_queue; fd_new_queue = (fd_queue*) malloc(sizeof(fd_queue)); fd_new_queue->fd = fd; fd_new_queue->time = 0; fd_new_queue->mandatory = 1; fd_new_queue->name = name; fd_new_queue->repeat_time = repeat_time; fd_new_queue->next = 0; if (g_fd_time_queue == 0) { g_fd_time_queue = fd_new_queue; g_fd_time_queue_last = fd_new_queue; } else { g_fd_time_queue_last->next = fd_new_queue; g_fd_time_queue_last = fd_new_queue; } return (fd < 0); } int enqueue_fd(int fd, char* name, int mandatory) { fd_queue* fd_new_queue; fd_new_queue = (fd_queue*) malloc(sizeof(fd_queue)); fd_new_queue->fd = fd; fd_new_queue->mandatory = mandatory; fd_new_queue->name = name; if (g_fd_count_queue == 0) { fd_new_queue->next = fd_new_queue; g_fd_count_queue = fd_new_queue; g_fd_count_queue_last = fd_new_queue; } else { fd_new_queue->next = g_fd_count_queue; g_fd_count_queue_last->next = fd_new_queue; g_fd_count_queue_last = fd_new_queue; } return (fd < 0); } void choose_fd(fd_queue* chosen_fd) { fd_queue* fd_queue_temp; fd_queue* fd_queue_temp_choice = 0; long long int min_time = 0; long long int current_time = 0; struct timespec time; time.tv_sec = 0; time.tv_nsec = 0; if (chosen_fd != 0) { chosen_fd->fd = -1; /* check first time queue */ clock_gettime(CLOCK_MONOTONIC, &time); current_time = usecDiff(&time, &g_start_time); if (current_time < 0) { /* there something fishy with the time measure ... */ fprintf(stderr, "time measure overflow, get new starting time\n"); fprintf(stderr, "start time %ld.%ld is after stop time %ld.%ld, current_time is %lld\n", g_start_time.tv_sec, g_start_time.tv_nsec, time.tv_sec, time.tv_nsec, current_time); clock_gettime(CLOCK_MONOTONIC, &g_start_time); fd_queue_temp = g_fd_time_queue; while(fd_queue_temp != 0) { fd_queue_temp->time = 0; fd_queue_temp = fd_queue_temp->next; } } else { fd_queue_temp = g_fd_time_queue; fd_queue_temp_choice = 0; while(fd_queue_temp != 0) { if (current_time >= fd_queue_temp->time) { if (fd_queue_temp_choice == 0) { fd_queue_temp_choice = fd_queue_temp; min_time = fd_queue_temp->time; } else if (min_time > fd_queue_temp->time) { fd_queue_temp_choice = fd_queue_temp; min_time = fd_queue_temp->time; } } fd_queue_temp = fd_queue_temp->next; } if (fd_queue_temp_choice != 0) { fd_queue_temp_choice->time += fd_queue_temp_choice->repeat_time * 1000; *chosen_fd = *fd_queue_temp_choice; } } /* get from normal queue if no founds */ if (g_fd_count_queue != 0 && chosen_fd->fd == -1) { *chosen_fd = *g_fd_count_queue; g_fd_count_queue = g_fd_count_queue->next; } } } void Usage (void) { fprintf(stderr, "Usage: 'tsnullshaper input.ts [b:packets_buffer] +file1.ts +file2.ts +file3.ts ... t:1000 filex.ts ... s: ip.ts'\n"); fprintf(stderr, "'+file.ts' replace null packets from input.ts with packets from another file.ts\n"); fprintf(stderr, "'t:m_secs file.ts' replace a null packet from input.ts with a packet from file.ts every m_secs milliseconds of REAL TIME, this packet has priority on +file.ts packets\n"); fprintf(stderr, "'s:file.ts' try to read from the file.ts, if fails move to next\n"); fprintf(stderr, "'b:packets_buffer' sets how many packets to use for buffering\n"); fprintf(stderr, "It was chosen to use REAL TIME instead of PCR LOGICAL TIME so it was possibile to manage TS without PCR\n"); fprintf(stderr, "This suits anyway PSI insertion case that is not so time strict\n"); } int main(int argc, char *argv[]) { int fd; fd_set set; u_short pid; int buffer_size; int fd_input_ts; /* File descriptor of ts input file */ int repeat_time; int bytes_read; struct timeval tv; unsigned int i; fd_queue chosen_fd; unsigned char* packet_buffer; unsigned char* current_packet; unsigned char pid_cc_table[MAX_PID]; /* PID table for the continuity counter of the TS packets */ /* Parse command line */ buffer_size = 0; if (argc >= 2) { fd_input_ts = open(argv[1], O_RDONLY); if (fd_input_ts < 0) { fprintf(stderr, "Can't find file %s\n", argv[1]); return 2; } } else { Usage(); return 2; } i = 2; while (i < argc) { if (argv[i][0] == '+') { fd = open(&(argv[i][1]), O_RDONLY); if (fd < 0) { fprintf(stderr, "can't find file %s\n", &(argv[i][1])); return 2; } else { if (enqueue_fd(fd, &(argv[i][1]), 1)) { return 2; } } i++; } else if (argv[i][0] == 's' && argv[i][1] == ':') { fd = open(&(argv[i][2]), O_RDONLY); if (fd < 0) { fprintf(stderr, "can't find file %s\n", &(argv[i][1])); return 2; } else { if (enqueue_fd(fd, &(argv[i][2]), 0)) { return 2; } } i++; } else if (argv[i][0] == 't' && argv[i][1] == ':') { repeat_time = atoi(&(argv[i][2])); fd = open(argv[i+1], O_RDONLY); if (repeat_time > 0 && fd >= 0) { if(enqueue_time_fd(fd, argv[i+1], repeat_time)) { return 2; } } else if (repeat_time < 0){ fprintf(stderr, "specified time is not positive\n"); return 2; } else if (fd < 0) { fprintf(stderr, "can't find file %s\n", argv[i+1]); return 2; } i+=2; } else if (argv[i][0] == 'b' && argv[i][1] == ':') { buffer_size = atoi(&(argv[i][2])); if (buffer_size <= 0) { fprintf(stderr, "buffer size is not valid\n"); return 2; } i+=1; } else { Usage(); return 2; } } /* Start to process the input */ memset(pid_cc_table, 0x10, MAX_PID); if (buffer_size <= 0) buffer_size = 1; buffer_size *= TS_PACKET_SIZE; packet_buffer = malloc(buffer_size); if (packet_buffer == NULL) { fprintf(stderr, "Out of memory!\n"); return 2; } tv.tv_sec = 0; tv.tv_usec = 0; g_start_time.tv_sec = 0; g_start_time.tv_nsec = 0; clock_gettime(CLOCK_MONOTONIC, &g_start_time); while(1) { /* Read packets */ read(fd_input_ts, packet_buffer, buffer_size); /* Check for nulls */ for(i = 0; i < buffer_size; i += TS_PACKET_SIZE) { current_packet = packet_buffer + i; /* check if it's a null packet */ memcpy(&pid, current_packet + 1, 2); pid = ntohs(pid); pid = pid & 0x1fff; if (pid == 8191) { /* replace */ choose_fd(&chosen_fd); if (chosen_fd.fd >= 0) { if (chosen_fd.mandatory) { bytes_read = read(chosen_fd.fd, current_packet, TS_PACKET_SIZE); if (bytes_read < TS_PACKET_SIZE) { close(chosen_fd.fd); chosen_fd.fd = open(chosen_fd.name, O_RDONLY); bytes_read = read(chosen_fd.fd, current_packet, TS_PACKET_SIZE); } } else { FD_ZERO(&set); FD_SET(chosen_fd.fd,&set); if (select(chosen_fd.fd + 1, &set, NULL, NULL, &tv) > 0) { bytes_read = read(chosen_fd.fd, current_packet, TS_PACKET_SIZE); if (bytes_read < TS_PACKET_SIZE) { close(chosen_fd.fd); chosen_fd.fd = open(chosen_fd.name, O_RDONLY); bytes_read = read(chosen_fd.fd, current_packet, TS_PACKET_SIZE); } } } } /* check packets cc */ memcpy(&pid, current_packet + 1, 2); pid = ntohs(pid); pid = pid & 0x1fff; if (pid < MAX_PID) { if (pid_cc_table[pid] == 0x10) { pid_cc_table[pid] = current_packet[3] & 0x0f; /* new stream to track cc */ } else { pid_cc_table[pid] = (pid_cc_table[pid] + 1) % 0x10; /* check last cc for this pid, increase and restamp */ current_packet[3] = (pid_cc_table[pid] | (current_packet[3] & 0xf0)); } } } } /* Write packets */ write(STDOUT_FILENO, packet_buffer, buffer_size); } return 0; } opencaster-3.2.2/tools/ts2pes/0000755000175000017500000000000012214326444015471 5ustar debiandebianopencaster-3.2.2/tools/ts2pes/Makefile0000644000175000017500000000062312214326444017132 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = ts2pes.o TARGET = ts2pes DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/ts2pes/ts2pes.c0000644000175000017500000000623012214326444017056 0ustar debiandebian/* * Copyright (C) 2004-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #define TS_PACKET_SIZE 188 #define MAX_PID 8192 int main(int argc, char *argv[]) { int byte_read; int fd_ts; /* File descriptor of ts file */ int ts_header_size; unsigned char temp; unsigned short pid; unsigned short payload_pid; unsigned int i; unsigned char* packet_buffer; unsigned char* current_packet; unsigned int buffer_size; /* Open ts file */ buffer_size = 0; if (argc >= 3) { fd_ts = open(argv[1], O_RDONLY); payload_pid = atoi(argv[2]); if (argc > 3) { buffer_size = atoi(argv[3]); } } else { fprintf(stderr, "Usage: 'ts2pes filename.ts payload_pid [buffer_size_in_packets]'\n"); return 2; } if (fd_ts < 0) { fprintf(stderr, "Can't find file %s\n", argv[1]); return 2; } if (payload_pid < 2 || payload_pid > MAX_PID-2) { fprintf(stderr, "Invalid PID, range is [2..8190]\n"); } if (buffer_size <= 0) { if (argv[3] != 0) { fprintf(stderr, "Buffer size is not valid\n"); return 2; } else { buffer_size = 1; } } buffer_size *= TS_PACKET_SIZE; packet_buffer = malloc(buffer_size); if (packet_buffer == NULL) { fprintf(stderr, "Out of memory\n"); return 2; } /* Start to process the file */ byte_read = 1; while(byte_read) { /* read packets */ byte_read = read(fd_ts, packet_buffer, buffer_size); /* check packets pid */ for (i = 0; i < buffer_size && byte_read; i+=TS_PACKET_SIZE) { current_packet = packet_buffer+i; memcpy(&pid, current_packet + 1, 2); pid = ntohs(pid); pid = pid & 0x1fff; if (pid == payload_pid) { /* got the pid we are interested into */ ts_header_size = 4; /* check adaptation field */ temp = (current_packet[3] >> 4) & 0x03; if (temp == 0) { ts_header_size = TS_PACKET_SIZE; /* jump the packet, is invalid ?*/ fprintf(stderr, "invalid packet!\n"); } else if (temp == 1) { ; /* just payload */ } else if (temp == 2) { ts_header_size = TS_PACKET_SIZE; /* only adaptation field */ /* fprintf(stderr, "adapatation field only?\n"); */ } else if (temp == 3) { ts_header_size += current_packet[4] + 1; /* jump the adaptation field */ } write(STDOUT_FILENO, current_packet + ts_header_size, TS_PACKET_SIZE - ts_header_size); } } } return 0; } opencaster-3.2.2/tools/m2ts2cbrts/0000755000175000017500000000000012220026061016243 5ustar debiandebianopencaster-3.2.2/tools/m2ts2cbrts/m2ts2cbrts.c0000644000175000017500000001256412217230457020440 0ustar debiandebian/* * Copyright (C) 2011-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place- Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #define TS_PACKET_SIZE 188 #define TS_EXTRA_HEADER 4 #define MAX_PID 8191 #define SYSTEM_CLOCK_FREQUENCY 27000000 int main(int argc, char *argv[]) { int fd_ts; unsigned short pid; int byte_read; unsigned long long int pcr_base = 0ll; unsigned long long int input_ts_packet_count = 0ll; unsigned long long int new_pcr = 0ll; unsigned long long int new_pcr_index = 0ll; unsigned long long int old_pcr = 0ll; unsigned long long int old_pcr_index = 0ll; unsigned char null_output_ts_packet[TS_PACKET_SIZE]; unsigned char input_ts_packet[TS_EXTRA_HEADER + TS_PACKET_SIZE]; unsigned long long int ibits = 0ll; unsigned long long int obits = 0ll; unsigned long long int fcounter = 0ll; unsigned long long int ucounter = 0ll; unsigned long long int last_ucounter = 0ll; unsigned long long int ts_packet_output = 0ll; /* Parse args */ if (argc > 1) { fd_ts = open(argv[1], O_RDONLY); } else { fprintf(stderr, "Usage: 'm2ts2cbrts input.ts [output_bit_rate]'\n"); fprintf(stderr, "adds empty packets to input.ts to reach uniform output_bit/s, default is 48mbps\n"); return 2; } if (fd_ts < 0) { fprintf(stderr, "Can't find file %s\n", argv[1]); return 2; } if (argc > 2) { obits = atol(argv[2]); if (obits == 0) { fprintf(stderr, "0 output_bit/s?\n"); return 2; } } else { obits = 48000000L; } fprintf(stderr, "output bps is %llu\n", obits); /* Init null packet */ memset(null_output_ts_packet, 0, TS_PACKET_SIZE); null_output_ts_packet[0] = 0x47; null_output_ts_packet[1] = 0x1F; null_output_ts_packet[2] = 0xFF; null_output_ts_packet[3] = 0x10; /* Init counters */ fcounter = 0; ucounter = 0; last_ucounter = 0; old_pcr = 0; old_pcr_index = 0; input_ts_packet_count = 0; ibits = obits; /* until ibit is guessed it's equal to output */ byte_read = 1; while (byte_read) { /* read a packet */ byte_read = read(fd_ts, input_ts_packet, TS_EXTRA_HEADER + TS_PACKET_SIZE); memcpy(&pid, input_ts_packet + 5, 2); pid = ntohs(pid); pid = pid & 0x1fff; if (pid < MAX_PID) { pcr_base = (input_ts_packet[0] & 0x3F) << 24; pcr_base += input_ts_packet[1] << 16; pcr_base += input_ts_packet[2] << 8; pcr_base += input_ts_packet[3]; if (old_pcr_index == 0) { old_pcr = pcr_base; old_pcr_index = input_ts_packet_count * TS_PACKET_SIZE; write(STDOUT_FILENO, input_ts_packet + TS_EXTRA_HEADER, TS_PACKET_SIZE); input_ts_packet_count++; } else { /* we can guess a bit rate comparing a previous pcr */ new_pcr = pcr_base; new_pcr_index = input_ts_packet_count * TS_PACKET_SIZE; if (new_pcr < old_pcr) { new_pcr += 0x40000000; ibits = (((double)(new_pcr_index - old_pcr_index)) * 8 * SYSTEM_CLOCK_FREQUENCY) / ((double)(new_pcr - old_pcr)); new_pcr -= 0x40000000; } else { ibits = (((double)(new_pcr_index - old_pcr_index)) * 8 * SYSTEM_CLOCK_FREQUENCY) / ((double)(new_pcr - old_pcr)); } if (ibits > obits) { fprintf(stderr, "at %llu: output bit rate %llu is smaller then input bit rate %llu\n", new_pcr_index, obits, ibits); return 2; } if (ibits != obits){ /* fprintf(stderr, "%llu: pid %d, new pcr is %llu, pcr delta is %llu, instant ts bit rate is %.10f\n", new_pcr_index, pid, new_pcr, new_pcr - old_pcr, (((double)(new_pcr_index - old_pcr_index)) * 8 * SYSTEM_CLOCK_FREQUENCY) / ((double)(new_pcr - old_pcr)) ); */ fcounter += TS_PACKET_SIZE * 8 * obits; ucounter = TS_PACKET_SIZE * 8 * ibits; while ( ucounter + (TS_PACKET_SIZE * 8 * ibits) < fcounter) { write(STDOUT_FILENO, null_output_ts_packet, TS_PACKET_SIZE); ts_packet_output++; last_ucounter = ucounter; ucounter += TS_PACKET_SIZE * 8 * ibits; if (last_ucounter > ucounter) { last_ucounter = last_ucounter - fcounter; fcounter = 0; ucounter = last_ucounter + TS_PACKET_SIZE * 8 * ibits; } } /* fprintf(stderr, "generated null bits for time %llu\n", fcounter-ucounter); */ fcounter = fcounter - ucounter; ucounter = 0; last_ucounter = 0; } write(STDOUT_FILENO, input_ts_packet + TS_EXTRA_HEADER, TS_PACKET_SIZE); input_ts_packet_count++; old_pcr = new_pcr; old_pcr_index = new_pcr_index; } } else { write(STDOUT_FILENO, input_ts_packet + TS_EXTRA_HEADER, TS_PACKET_SIZE); input_ts_packet_count++; } } return 0; } opencaster-3.2.2/tools/m2ts2cbrts/Makefile0000644000175000017500000000063312217230427017716 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = m2ts2cbrts.o TARGET = m2ts2cbrts DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/esaudio2pes/0000755000175000017500000000000012214326444016474 5ustar debiandebianopencaster-3.2.2/tools/esaudio2pes/esaudio2pes.c0000644000175000017500000001622612214326444021072 0ustar debiandebian/* * Copyright (C) 2004-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #include #define PES_HEADER_SIZE 14 #define PES_HEADER_SIZE_WITH_AD 31 #define PACK_AUDIO_FRAME_INCREASE 8 #define PACK_AUDIO_FRAME_INCREASE_WITH_AD 25 #define ES_HEADER_SIZE 4 #define PTS_MAX 8589934592LL void stamp_ts (unsigned long long int ts, unsigned char* buffer) { if (buffer) { buffer[0] = ((ts >> 29) & 0x0F) | 0x01; buffer[1] = (ts >> 22) & 0xFF; buffer[2] = ((ts >> 14) & 0xFF ) | 0x01; buffer[3] = (ts >> 7) & 0xFF; buffer[4] = ((ts << 1) & 0xFF ) | 0x01; } } int main(int argc, char *argv[]) { int bframe; int byte_read; FILE* file_es; int ismpeg2; int iseac3; int isdts; int AD_fade_value = -1; unsigned long long int pts = 0LL; unsigned long long int pts_limit = 0ll; unsigned long long int frame_number = 0ll; unsigned char stream_id = 192; /* usual value */ unsigned char pes_header[PES_HEADER_SIZE_WITH_AD]; unsigned char* es_frame; unsigned short es_frame_size; unsigned short pes_frame_size; unsigned int sample_rate; unsigned int samples_per_frame; unsigned long long int pts_offset = 0ll; /* Open pes file */ if (argc > 4) { file_es = fopen(argv[1], "rb"); samples_per_frame = atoi(argv[2]); sample_rate = atoi(argv[3]); es_frame_size = atoi(argv[4]); AD_fade_value = atoi(argv[5]); if (es_frame_size <= 0) { fprintf(stderr, "audio_frame_size suggested is not valid\n"); return 2; } pes_frame_size = es_frame_size + PACK_AUDIO_FRAME_INCREASE; if (AD_fade_value >= 0) { pes_frame_size = es_frame_size + PACK_AUDIO_FRAME_INCREASE_WITH_AD; unsigned char ad = (unsigned char) AD_fade_value; fprintf(stderr, "AD fade value is %u\n", ad); } es_frame = malloc(es_frame_size); if (!es_frame) { fprintf(stderr, "Out of memory\n"); return 2; } } else { fprintf(stderr, "Usage: 'esaudio2pes audio.es samples_per_frame sample_rate frame_size_without_padding AD_fade_value [pts_offset] [pts_limit] [stream_id]'\n"); fprintf(stderr, "pts_offset can be used to set a pts different from zero to synch audio to the first video pts\n"); fprintf(stderr, "pts_limit can be used to limit time length to force audio to end before the last video pts\n"); fprintf(stderr, "Example for mpeg layer 2 audio with frame size 768 and sample rate 48000: esaudio2pes audio.es 1152 48000 768 -1\n"); fprintf(stderr, "Example for ac3 audio with frame size 384 and sample rate 48000: esaudio2pes audio.es 1536 48000 384 -1\n"); fprintf(stderr, "Example for dts audio with nblck 15 e short 31, samples are 16*32: esaudio2pes audio.es 512 48000 2012 -1\n"); fprintf(stderr, "valid id for audio are 110xxxxx, default is 192\n"); return 2; } if (argc > 6) { pts_offset = atol(argv[6]); } if (argc > 7) { pts_limit = atol(argv[7]); } if (argc > 8) { stream_id = atoi(argv[8]); } if (file_es == 0) { fprintf(stderr, "Can't find file %s\n", argv[1]); return 2; } /* Init. default pack header */ pes_header[0] = 0x00; pes_header[1] = 0x00; pes_header[2] = 0x01; pes_header[3] = stream_id; pes_frame_size = htons(pes_frame_size); memcpy(pes_header + 4, &pes_frame_size, 2); pes_frame_size = ntohs(pes_frame_size); pes_header[6] = 0x81; /* no scrambling, no priority, no alignment defined, no copyright, copy */ pes_header[7] = 0x80; /* pts, no escr, no es rate, no dsm trick, no extension flag, no additional copy info, no crc flag */ pes_header[8] = 0x05; /* pts */ if (AD_fade_value >= 0) { pes_header[7] = 0x81; /* pts, no escr, no es rate, no dsm trick, yes extension flag, no additional copy info, no crc flag */ pes_header[8] = 0x16; /* pts and AD */ pes_header[14] = 0x8E; /* pes private data, reserved */ pes_header[15] = 0xF8; /* AD */ pes_header[16] = 0x44; /* AD */ pes_header[17] = 0x54; /* AD */ pes_header[18] = 0x47; /* AD */ pes_header[19] = 0x41; /* AD */ pes_header[20] = 0x44; /* AD */ pes_header[21] = 0x31; /* AD */ pes_header[22] = (unsigned char) AD_fade_value; /* AD fade value*/ pes_header[23] = 0x00; /* AD pan value*/ pes_header[24] = 0xFF; /* AD */ pes_header[25] = 0xFF; /* AD */ pes_header[26] = 0xFF; /* AD */ pes_header[27] = 0xFF; /* AD */ pes_header[28] = 0xFF; /* AD */ pes_header[29] = 0xFF; /* AD */ pes_header[30] = 0xFF; /* AD */ } byte_read = fread(es_frame, 1, ES_HEADER_SIZE, file_es); bframe = 1; int padding = 0; pts = pts_offset; frame_number = 1; isdts = (es_frame[0] == 0x7F) && (es_frame[1] == 0xFE) && (es_frame[2] == 0x80) && (es_frame[3] == 0x01); if (isdts) { ismpeg2 = 0; } else { ismpeg2 = (es_frame[0] == 0xFF) && ((es_frame[1] >> 5)== 0x07); } iseac3 = -1; while(byte_read) { if ( (ismpeg2 && es_frame[0] == 0xFF && (es_frame[1] >> 5) == 0x07) || (!ismpeg2 && (es_frame[0] == 0x0B) && (es_frame[1] == 0x77)) || (isdts && (es_frame[0] == 0x7F) && (es_frame[1] == 0xFE) && (es_frame[2] == 0x80) && (es_frame[3] == 0x01)) ) { byte_read = fread(es_frame + ES_HEADER_SIZE, 1, es_frame_size - ES_HEADER_SIZE, file_es); stamp_ts (pts % PTS_MAX, pes_header + 9); pes_header[9] &= 0x0F; pes_header[9] |= 0x20; /* check for padding */ if (ismpeg2 && (((es_frame[2] & 0x3) >> 1) > 0)) { /* check layer */ int layer = es_frame[1] & 0x6 >> 1; if (layer == 2) { padding = 4; } else { padding = 1; } } else { padding = 0; } pts = pts_offset + ((frame_number * samples_per_frame * 90000) / sample_rate); if (padding) { pes_frame_size = htons(pes_frame_size + padding); memcpy(pes_header + 4, &pes_frame_size, 2); pes_frame_size = ntohs(pes_frame_size) - padding; } else { pes_frame_size = htons(pes_frame_size); memcpy(pes_header + 4, &pes_frame_size, 2); pes_frame_size = ntohs(pes_frame_size); } if (AD_fade_value >= 0) { fwrite(pes_header, 1, PES_HEADER_SIZE_WITH_AD, stdout); } else { fwrite(pes_header, 1, PES_HEADER_SIZE, stdout); } frame_number++; fwrite(es_frame, 1, es_frame_size, stdout); if (padding) { fread(es_frame,1, padding, file_es); fwrite(es_frame,1, padding, stdout); } byte_read = fread(es_frame, 1, ES_HEADER_SIZE, file_es); } else { fprintf(stderr, "Critical: sync byte missing, corrupted ES or frame size changed\n"); byte_read = 0; } if (pts_limit > 0ll && pts >= pts_limit) { byte_read = 0; } } return 0; } opencaster-3.2.2/tools/esaudio2pes/Makefile0000644000175000017500000000063512214326444020140 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = esaudio2pes.o TARGET = esaudio2pes DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/tsororts/0000755000175000017500000000000012232257151016146 5ustar debiandebianopencaster-3.2.2/tools/tsororts/tsororts.c0000644000175000017500000000677012232257151020223 0ustar debiandebian/* * Copyright (C) 2009-2013 Lorenzo Pallara, l.pallara@avalpa.com * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #define MULTICAST #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define TS_PACKET_SIZE 188 int main(int argc, char *argv[]) { int input1_file; int input2_file; int input3_file; int byte_read1; int byte_read2; int byte_read3; int index1; int index2; unsigned char ts_packet1[TS_PACKET_SIZE]; unsigned char ts_packet2[TS_PACKET_SIZE]; unsigned char ts_packet3[TS_PACKET_SIZE]; if (argc >= 4) { input1_file = open(argv[1], O_RDONLY); if (input1_file < 0) { fprintf(stderr, "Can't open file %s\n", argv[1]); return 0; } input2_file = open(argv[2], O_RDONLY); if (input2_file < 0) { fprintf(stderr, "Can't open file %s\n", argv[2]); return 0; } input3_file = open(argv[3], O_RDONLY); if (input3_file < 0) { fprintf(stderr, "Can't open file %s\n", argv[3]); return 0; } } else { fprintf(stderr, "Usage: 'tsororts inputfile1.ts inputfile2.ts inputfile3.ts > output.ts'\n"); fprintf(stderr, "ts packets are read from inputfile3.ts if they are not immediatly available from inputfile1.ts or inputfile2.ts'\n"); return 0; } fcntl (input1_file, F_SETFL, fcntl (input1_file, F_GETFL, 0) | O_NONBLOCK); fcntl (input2_file, F_SETFL, fcntl (input2_file, F_GETFL, 0) | O_NONBLOCK); index1 = 0; index2 = 0; while (1) { byte_read1 = read(input1_file, ts_packet1 + index1, TS_PACKET_SIZE - index1); byte_read2 = read(input2_file, ts_packet2 + index2, TS_PACKET_SIZE - index2); if (byte_read1 > 0) { index1 += byte_read1; if (index1 == TS_PACKET_SIZE) { write(STDOUT_FILENO, ts_packet1, TS_PACKET_SIZE); index1 = 0; } } if (byte_read2 > 0) { index2 += byte_read2; if (index2 == TS_PACKET_SIZE) { write(STDOUT_FILENO, ts_packet2, TS_PACKET_SIZE); index2 = 0; } } if (byte_read1 <= 0 && byte_read2 <= 0 && index1 == 0 && index2 == 0) { byte_read3 = read(input3_file, ts_packet3, TS_PACKET_SIZE); if (byte_read3 == 0) { close(input3_file); input3_file = open(argv[3], O_RDONLY); if (input3_file < 0) { fprintf(stderr, "Can't open file %s\n", argv[2]); return 0; } else { byte_read3 = read(input3_file, ts_packet3, TS_PACKET_SIZE); if (byte_read3 > 0) { write(STDOUT_FILENO, ts_packet3, TS_PACKET_SIZE); } } } else { write(STDOUT_FILENO, ts_packet3, TS_PACKET_SIZE); } } } return 0; } opencaster-3.2.2/tools/tsororts/Makefile0000644000175000017500000000062712214326444017615 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = tsororts.o TARGET = tsororts DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/eitsecfilter/0000755000175000017500000000000012232256710016731 5ustar debiandebianopencaster-3.2.2/tools/eitsecfilter/Makefile0000644000175000017500000000063712214326444020401 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = eitsecfilter.o TARGET = eitsecfilter DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/eitsecfilter/eitsecfilter.c0000644000175000017500000001101312232256710021553 0ustar debiandebian/* * Copyright (C) 2010-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #include #include #include #ifndef PATH_MAX #define PATH_MAX 4096 #endif #define SECTION_MAX_SIZE 4096 #define SECTION_HEADER_SIZE 3 unsigned char g_section[SECTION_MAX_SIZE+1]; /* +1 to handle a special case, see later in the code */ unsigned char g_section_head[SECTION_HEADER_SIZE]; unsigned char* get_section(unsigned short* section_size, int fd) { unsigned short temp = 0; unsigned char* section = 0; if (section_size) { /* Read first bytes */ *section_size = 0; if (read(fd, g_section_head, SECTION_HEADER_SIZE)) { /* Parse datagram section size */ memcpy(&temp, g_section_head + 1, 2); temp = ntohs(temp); temp &= 0x0FFF; *section_size = temp; /* Read all the section */ if (*section_size <= (SECTION_MAX_SIZE - SECTION_HEADER_SIZE)) { memcpy(g_section, g_section_head, SECTION_HEADER_SIZE); read(fd, g_section + SECTION_HEADER_SIZE, *section_size); section = g_section; *section_size += SECTION_HEADER_SIZE; } else { fprintf(stderr, "Section too big skipped\n"); } } } return section; } void Usage (void) { fprintf(stderr, "Usage: 'eitsecfilter file.sec +onid tsid sid +onid tsid sid [...]\n"); } typedef struct Locator { unsigned short onid; unsigned short tsid; unsigned short sid; } Locator; #define MAX_LOCATORS 1024 int main(int argc, char *argv[]) { unsigned short a_section_size; unsigned char *a_section; int fd_sec; int fd_output; int i = 0; unsigned int onid; unsigned int tsid; unsigned int sid; unsigned int locators_num; char path[PATH_MAX]; char old_path[PATH_MAX]; Locator locator_table[MAX_LOCATORS]; memset(locator_table, 0, sizeof(Locator) * MAX_LOCATORS); if (argc >= 2) { fd_sec = open(argv[1], O_RDONLY); if (fd_sec < 0) { fprintf(stderr, "Can't find file %s\n", argv[1]); return 2; } } else { Usage(); return 2; } i = 2; locators_num = 0; while (i < argc) { if (argv[i][0] == '+') { locator_table[locators_num].onid = atoi(&(argv[i][1])); locator_table[locators_num].tsid = atoi(argv[i+1]); locator_table[locators_num].sid = atoi(argv[i+2]); locators_num++; i+=3; } } while(1) { a_section = get_section(&a_section_size, fd_sec); if (a_section_size <= 0 || a_section == 0) { return 0; } memcpy(&onid, a_section + 10, 2); onid = ntohs(onid); memcpy(&tsid, a_section + 8, 2); tsid = ntohs(tsid); memcpy(&sid, a_section + 3, 2); sid = ntohs(sid); for (i = 0; i < locators_num; i++) { if (locator_table[i].onid == onid && locator_table[i].tsid == tsid && locator_table[i].sid == sid) { if (a_section[0] == 0x4e) { /* p/f -> 0 is present, 1 is following */ if (a_section[6] == 0) { snprintf(path, PATH_MAX, "p.%d.%d.%d.sec", onid, tsid, sid); } else { snprintf(path, PATH_MAX, "f.%d.%d.%d.sec", onid, tsid, sid); } fd_output = open(path, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); } else { /* scheduled */ snprintf(path, PATH_MAX, "sc.%d.%d.%d.%d.sec", onid, tsid, sid, a_section[0]); if (a_section[6] == 0) { snprintf(old_path, PATH_MAX, "old_sc.%d.%d.%d.%d.sec", onid, tsid, sid, a_section[0]); rename(path, old_path); fd_output = open(path, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); } else { fd_output = open(path, O_CREAT|O_WRONLY|O_APPEND, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); } } if (fd_output >= 0) { write(fd_output, a_section, a_section_size); close(fd_output); } } } } return 0; } opencaster-3.2.2/tools/mpe2sec/0000755000175000017500000000000012232257463015613 5ustar debiandebianopencaster-3.2.2/tools/mpe2sec/sectioncrc.c0000644000175000017500000001054312214326444020112 0ustar debiandebian/* sectioncrc.c -- MPEG-2 checksum calculation, Python Module Copyright (C) 2001 Oleg Tchekoulaev, GMD This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #include /* crctab taken from cksum.c by Q. Frank Xia, qx@math.columbia.edu. */ static unsigned long const crctab[256] = { 0x0, 0x04C11DB7, 0x09823B6E, 0x0D4326D9, 0x130476DC, 0x17C56B6B, 0x1A864DB2, 0x1E475005, 0x2608EDB8, 0x22C9F00F, 0x2F8AD6D6, 0x2B4BCB61, 0x350C9B64, 0x31CD86D3, 0x3C8EA00A, 0x384FBDBD, 0x4C11DB70, 0x48D0C6C7, 0x4593E01E, 0x4152FDA9, 0x5F15ADAC, 0x5BD4B01B, 0x569796C2, 0x52568B75, 0x6A1936C8, 0x6ED82B7F, 0x639B0DA6, 0x675A1011, 0x791D4014, 0x7DDC5DA3, 0x709F7B7A, 0x745E66CD, 0x9823B6E0, 0x9CE2AB57, 0x91A18D8E, 0x95609039, 0x8B27C03C, 0x8FE6DD8B, 0x82A5FB52, 0x8664E6E5, 0xBE2B5B58, 0xBAEA46EF, 0xB7A96036, 0xB3687D81, 0xAD2F2D84, 0xA9EE3033, 0xA4AD16EA, 0xA06C0B5D, 0xD4326D90, 0xD0F37027, 0xDDB056FE, 0xD9714B49, 0xC7361B4C, 0xC3F706FB, 0xCEB42022, 0xCA753D95, 0xF23A8028, 0xF6FB9D9F, 0xFBB8BB46, 0xFF79A6F1, 0xE13EF6F4, 0xE5FFEB43, 0xE8BCCD9A, 0xEC7DD02D, 0x34867077, 0x30476DC0, 0x3D044B19, 0x39C556AE, 0x278206AB, 0x23431B1C, 0x2E003DC5, 0x2AC12072, 0x128E9DCF, 0x164F8078, 0x1B0CA6A1, 0x1FCDBB16, 0x018AEB13, 0x054BF6A4, 0x0808D07D, 0x0CC9CDCA, 0x7897AB07, 0x7C56B6B0, 0x71159069, 0x75D48DDE, 0x6B93DDDB, 0x6F52C06C, 0x6211E6B5, 0x66D0FB02, 0x5E9F46BF, 0x5A5E5B08, 0x571D7DD1, 0x53DC6066, 0x4D9B3063, 0x495A2DD4, 0x44190B0D, 0x40D816BA, 0xACA5C697, 0xA864DB20, 0xA527FDF9, 0xA1E6E04E, 0xBFA1B04B, 0xBB60ADFC, 0xB6238B25, 0xB2E29692, 0x8AAD2B2F, 0x8E6C3698, 0x832F1041, 0x87EE0DF6, 0x99A95DF3, 0x9D684044, 0x902B669D, 0x94EA7B2A, 0xE0B41DE7, 0xE4750050, 0xE9362689, 0xEDF73B3E, 0xF3B06B3B, 0xF771768C, 0xFA325055, 0xFEF34DE2, 0xC6BCF05F, 0xC27DEDE8, 0xCF3ECB31, 0xCBFFD686, 0xD5B88683, 0xD1799B34, 0xDC3ABDED, 0xD8FBA05A, 0x690CE0EE, 0x6DCDFD59, 0x608EDB80, 0x644FC637, 0x7A089632, 0x7EC98B85, 0x738AAD5C, 0x774BB0EB, 0x4F040D56, 0x4BC510E1, 0x46863638, 0x42472B8F, 0x5C007B8A, 0x58C1663D, 0x558240E4, 0x51435D53, 0x251D3B9E, 0x21DC2629, 0x2C9F00F0, 0x285E1D47, 0x36194D42, 0x32D850F5, 0x3F9B762C, 0x3B5A6B9B, 0x0315D626, 0x07D4CB91, 0x0A97ED48, 0x0E56F0FF, 0x1011A0FA, 0x14D0BD4D, 0x19939B94, 0x1D528623, 0xF12F560E, 0xF5EE4BB9, 0xF8AD6D60, 0xFC6C70D7, 0xE22B20D2, 0xE6EA3D65, 0xEBA91BBC, 0xEF68060B, 0xD727BBB6, 0xD3E6A601, 0xDEA580D8, 0xDA649D6F, 0xC423CD6A, 0xC0E2D0DD, 0xCDA1F604, 0xC960EBB3, 0xBD3E8D7E, 0xB9FF90C9, 0xB4BCB610, 0xB07DABA7, 0xAE3AFBA2, 0xAAFBE615, 0xA7B8C0CC, 0xA379DD7B, 0x9B3660C6, 0x9FF77D71, 0x92B45BA8, 0x9675461F, 0x8832161A, 0x8CF30BAD, 0x81B02D74, 0x857130C3, 0x5D8A9099, 0x594B8D2E, 0x5408ABF7, 0x50C9B640, 0x4E8EE645, 0x4A4FFBF2, 0x470CDD2B, 0x43CDC09C, 0x7B827D21, 0x7F436096, 0x7200464F, 0x76C15BF8, 0x68860BFD, 0x6C47164A, 0x61043093, 0x65C52D24, 0x119B4BE9, 0x155A565E, 0x18197087, 0x1CD86D30, 0x029F3D35, 0x065E2082, 0x0B1D065B, 0x0FDC1BEC, 0x3793A651, 0x3352BBE6, 0x3E119D3F, 0x3AD08088, 0x2497D08D, 0x2056CD3A, 0x2D15EBE3, 0x29D4F654, 0xC5A92679, 0xC1683BCE, 0xCC2B1D17, 0xC8EA00A0, 0xD6AD50A5, 0xD26C4D12, 0xDF2F6BCB, 0xDBEE767C, 0xE3A1CBC1, 0xE760D676, 0xEA23F0AF, 0xEEE2ED18, 0xF0A5BD1D, 0xF464A0AA, 0xF9278673, 0xFDE69BC4, 0x89B8FD09, 0x8D79E0BE, 0x803AC667, 0x84FBDBD0, 0x9ABC8BD5, 0x9E7D9662, 0x933EB0BB, 0x97FFAD0C, 0xAFB010B1, 0xAB710D06, 0xA6322BDF, 0xA2F33668, 0xBCB4666D, 0xB8757BDA, 0xB5365D03, 0xB1F740B4 }; unsigned long sectioncrc( unsigned char *buf, unsigned int len ) { unsigned char *p; uint32_t crc; crc = 0xffffffff; p = buf; while( len-- ) { crc = (crc<<8) ^ crctab[((crc>>24) ^ *(p++))]; } return crc; } opencaster-3.2.2/tools/mpe2sec/Makefile0000644000175000017500000000063112214326444017247 0ustar debiandebianCC = gcc CFLAGS += -g -O2 -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) OBJS = mpe.o sectioncrc.o TARGET = mpe2sec DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/mpe2sec/mpe.c0000644000175000017500000001217112232257463016542 0ustar debiandebian#include #include #include #include #include #include #include #include #include #include #include #include #include #include "sectioncrc.h" /* pre 2.4.6 compatibility */ #define OTUNSETNOCSUM (('T'<< 8) | 200) #define OTUNSETDEBUG (('T'<< 8) | 201) #define OTUNSETIFF (('T'<< 8) | 202) #define OTUNSETPERSIST (('T'<< 8) | 203) #define OTUNSETOWNER (('T'<< 8) | 204) static int persist = 0; static int stuff = 0; static char padding[184]; static char ip_device[IFNAMSIZ]; static char s[180]; static const char *Id = "$Id: mpe.c 25 2011-10-13 15:35:18Z jfbcable $"; const MPE_HEADER_LEN=12; int tun_fd = -1; #ifdef IFF_TUN int tun_open(char *dev) { struct ifreq ifr; int fd; if ((fd = open("/dev/net/tun", O_RDWR)) < 0) { perror("open tun"); return -1; } memset(&ifr, 0, sizeof(ifr)); ifr.ifr_flags = IFF_TUN; if(persist == 0) ifr.ifr_flags |= IFF_NO_PI; if (*dev) strncpy(ifr.ifr_name, dev, IFNAMSIZ); else { fprintf(stderr, "device name not supplied\n"); return -1; } if (ioctl(fd, TUNSETIFF, (void *) &ifr) < 0) { if (errno == EBADFD) { /* Try old ioctl */ if (ioctl(fd, OTUNSETIFF, (void *) &ifr) < 0) { perror("new nor old ioctl worked\n"); close(fd); return -1; } } else { perror("other error\n"); close(fd); return -1; } } strncpy(dev, ifr.ifr_name, IFNAMSIZ); return fd; } #else int tun_open(char *dev) { char tunname[14]; int i, fd, err; if( *dev ) { sprintf(tunname, "/dev/%s", dev); return open(tunname, O_RDWR); } sprintf(tunname, "/dev/tun"); err = 0; for(i=0; i < 255; i++){ sprintf(tunname + 8, "%d", i); /* Open device */ if( (fd=open(tunname, O_RDWR)) > 0 ) { strcpy(dev, tunname + 5); return fd; } else if (errno != ENOENT) err = errno; else if (i) /* don't try all 256 devices */ break; } if (err) errno = err; perror("no /dev/tun* available\n"); return -1; } #endif void send_mpe(int fd, unsigned char *buf, size_t len) { unsigned char *mpe_header = buf; unsigned char *ip_datagram = &buf[MPE_HEADER_LEN]; unsigned long crc; unsigned long i; unsigned short section_len = len - 3 + 4; // table id and section len not in, crc in! mpe_header[0] = 0x3e; mpe_header[1] = ((section_len >> 8) & 0x0f) | 0xb0; mpe_header[2] = section_len & 0xff; mpe_header[3] = 0; mpe_header[4] = 0; mpe_header[5] = 0xc1; mpe_header[6] = 0; mpe_header[7] = 0; mpe_header[8] = 0; mpe_header[9] = 0; mpe_header[10] = 0; mpe_header[11] = 0; if ((ip_datagram[16] & 0xe0) == 0xe0) { /* multicast */ mpe_header[3] = ip_datagram[19]; mpe_header[4] = ip_datagram[18]; mpe_header[8] = ip_datagram[17] & 0x7f; mpe_header[9] = 0x5e; mpe_header[10] = 0; mpe_header[11] = 1; } crc = htonl(sectioncrc(buf, len)); memcpy(&buf[len], &crc, 4); len += 4; write(fd, buf, len); if (stuff) { unsigned long stuff_count = 184 - (len % 184) - 1; /* one less for TS packet pointer */ if (stuff_count > 0) { write(fd, padding, stuff_count); } } } void usage(char **argv) { fprintf(stderr, "usage %s [-p] [-s] devname\n", argv[0]); fprintf(stderr, "Create a tun device and send DVB/MPE DSM-CC sections to stdout.\n"); fprintf(stderr, "-p don't create or configure the tun device\n"); fprintf(stderr, "-s stuff sections to multiple of 184 bytes using 0xff octets\n"); fprintf(stderr, "Project home page http://code.google.com/p/dvb-mpe-encode\n"); fprintf(stderr, "Example:\nmpe dvb0 | sec2ts 430 | DtPlay 1000000\n"); exit(1); } void exit_program(int sig) { fprintf(stderr, "stopping %s\n", ip_device); sprintf(s, "ifdown %s", ip_device); system(s); close(tun_fd); exit(0); } int main(int argc, char **argv) { int n = 1; if (argc < 2) usage(argv); if (argc > 4) usage(argv); while(argv[n][0] == '-') { if (strcmp(argv[n], "-p") == 0) persist = 1; if (strcmp(argv[n], "-s") == 0) { stuff = 1; memset(padding, 0xff, sizeof(padding)); } n++; } strcpy(ip_device, argv[n]); tun_fd = tun_open (ip_device); if (tun_fd == -1) usage(argv); (void) signal(SIGINT, exit_program); (void) signal(SIGQUIT, exit_program); if(persist==0) { sprintf(s, "ifup %s", ip_device); system(s); } while (1) { unsigned char buf[4100]; unsigned char *mpe_header = buf; unsigned char *tun_header = &buf[MPE_HEADER_LEN]; int n = read(tun_fd, tun_header, sizeof(buf)); //write(2, tun_header, n); send_mpe(1, mpe_header, n + MPE_HEADER_LEN); } } opencaster-3.2.2/tools/mpe2sec/sectioncrc.h0000644000175000017500000000157112214326444020120 0ustar debiandebian/* sectioncrc.h -- MPEG-2 checksum calculation Copyright (C) 2001 Oleg Tchekoulaev, GMD This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ unsigned long sectioncrc( unsigned char*, unsigned int ); opencaster-3.2.2/tools/tstdt/0000755000175000017500000000000012214326444015413 5ustar debiandebianopencaster-3.2.2/tools/tstdt/tstdt.c0000644000175000017500000001066012214326444016724 0ustar debiandebian/* * Copyright (C) 2005-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #include #include #include "../../libs/sectioncrc/sectioncrc.c" #define TS_PACKET_SIZE 188 #define MAX_PIDS 8192 #define TDT_PID 20 #define TDT_TABLE_ID 0x70 #define TOT_TABLE_ID 0x73 void Usage (void) { fprintf(stderr, "Usage: 'tstdt input.ts [b:buffer_size] [t:start_time_stamp] '\n"); fprintf(stderr, "'replace tdt packet with another tdt packe of the current time' \n"); fprintf(stderr, "'b:buffer_size' set size of the internal buffer to many packets as buffer_size\n"); fprintf(stderr, "'t:start_time_stamp' start the generated time from this GM timestamp for replay purposes\n"); } int main(int argc, char *argv[]) { unsigned int i; time_t tim; time_t baseline = 0; time_t start_time_stamp = 0; struct tm * now; unsigned short l; unsigned short MJD; unsigned char hour; unsigned char minute; unsigned char second; u_short pid; int buffer_size; int fd_ts; /* File descriptor of ts input file */ unsigned char* packet_buffer; unsigned char* current_packet; /* Open ts files */ if (argc < 2) { Usage(); return 2; } fd_ts = open(argv[1], O_RDONLY); if (fd_ts < 0) { fprintf(stderr, "Can't find file %s\n", argv[1]); return 2; } buffer_size = 0; if (argc == 3) { if (argv[2][0] == 'b' && argv[2][1] == ':') { buffer_size = atoi(&(argv[2][2])); } if (argv[2][0] == 't' && argv[2][1] == ':') { start_time_stamp = (time_t) atoi(&(argv[2][2])); baseline = time(NULL); } } if (buffer_size <= 0) { buffer_size = 1; } buffer_size *= TS_PACKET_SIZE; packet_buffer = malloc(buffer_size); if (packet_buffer == NULL) { fprintf(stderr, "Out of memory!\n"); return 2; } /* Start to process the input */ int bytes = 1; unsigned int crc = 0; unsigned short temp = 0; unsigned short section_size = 0; while(bytes != 0) { /* Read packets */ bytes = read(fd_ts, packet_buffer, buffer_size); /* Check if it's a tdt packet */ for (i = 0; i < buffer_size; i += TS_PACKET_SIZE) { current_packet = packet_buffer + i; memcpy(&pid, current_packet + 1, 2); pid = ntohs(pid); pid = pid & 0x1fff; if (pid == TDT_PID) { tim = time(NULL); if (start_time_stamp) { tim = start_time_stamp + (tim - baseline); } now = gmtime(&tim); if (now != NULL) { /* convert date into modified julian */ if ((now->tm_mon + 1 == 1) || (now->tm_mon + 1 == 2)) { l = 1; } else { l = 0; } MJD = 14956 + now->tm_mday + (unsigned short)((now->tm_year - l) * 365.25f) + (unsigned short)((now->tm_mon + 1 + 1 + l * 12) * 30.6001f); MJD = htons(MJD); memcpy(current_packet + 8, &MJD, 2); /* convert time */ hour = (now->tm_hour / 10) << 4 | (now->tm_hour % 10); minute = (now->tm_min / 10) << 4 | (now->tm_min % 10); second = (now->tm_sec / 10) << 4 | (now->tm_sec %10); current_packet[10] = hour; current_packet[11] = minute; current_packet[12] = second; } if (current_packet[5] == TOT_TABLE_ID) { memcpy(&temp, current_packet + 6, 2); temp = ntohs(temp); temp &= 0x0FFF; section_size = temp + 3; crc = sectioncrc(current_packet + 5, section_size - 4); current_packet[5 + section_size - 4] = (crc >> 24) & 0xFF; current_packet[5 + section_size - 3] = (crc >> 16) & 0xFF; current_packet[5 + section_size - 2] = (crc >> 8) & 0xFF; current_packet[5 + section_size - 1] = crc & 0xFF; } } } /* Write packets */ if (bytes != 0) { write(STDOUT_FILENO, packet_buffer, buffer_size); } } return 0; } opencaster-3.2.2/tools/tstdt/Makefile0000644000175000017500000000062112214326444017052 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = tstdt.o TARGET = tstdt DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/txt2pes/0000755000175000017500000000000012214326444015662 5ustar debiandebianopencaster-3.2.2/tools/txt2pes/Makefile0000644000175000017500000000057512214326444017331 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include $(CPPFLAGS) LDFLAGS += -lc OBJS = txt2pes.o TARGET = txt2pes DESTDIR = /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/txt2pes/txt2pes.c0000644000175000017500000000717612214326444017452 0ustar debiandebian/* * Copyright (C) 2009-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #define _BSD_SOURCE 1 #include #include #include #include #include #include #include #include #include #include #include #define EBU_UNIT_SIZE 46 void stamp_ts (unsigned long long int ts, unsigned char* buffer) { if (buffer) { buffer[0] = ((ts >> 29) & 0x0F) | 0x21; buffer[1] = (ts >> 22) & 0xFF; buffer[2] = ((ts >> 14) & 0xFF ) | 0x01; buffer[3] = (ts >> 7) & 0xFF; buffer[4] = ((ts << 1) & 0xFF ) | 0x01; } } int main(int argc, char *argv[]) { unsigned long long int pts_stamp = 3600; unsigned char* pes_packet; int byte_read = 0; int file_es = 0; int packet_index = 0; int txtunitperpes = 0; int pts_increment = 3600; /* Parse args */ if (argc > 2) { file_es = open(argv[1], O_RDONLY); txtunitperpes = atoi(argv[2]); } if (argc > 3 ) { pts_stamp = strtoull(argv[3],0,0); } if (argc > 4) { pts_increment = atoi(argv[4]); } if (file_es == 0) { fprintf(stderr, "Usage: 'txt2pes txt.es txt_units_per_pes_packet [pts_offset [pts_increment]] > pes'\n"); fprintf(stderr, "txt_unit_per_pes_packet increase bit rate, minimum is 1, max is 24\n"); fprintf(stderr, "Default pts_offset and increment is 3600, means 2 fields or 1 frame\n"); fprintf(stderr, "txt.es is 46 byte units of ebu teletext coding\n"); return 2; } unsigned short pes_size = ((txtunitperpes + 1) * EBU_UNIT_SIZE); pes_packet = malloc(pes_size); fprintf(stderr, "pes packet size without 6 byte header is %d\n", pes_size - 6); /* Set some init. values */ memset(pes_packet, 0xFF, pes_size); pes_packet[0] = 0x00; pes_packet[1] = 0x00; pes_packet[2] = 0x01; /* prefix */ pes_packet[3] = 0xBD; /* data txt */ unsigned short temp = htons(pes_size - 6); memcpy(pes_packet + 4, &temp, sizeof(unsigned short)); pes_packet[6] = 0x8F; pes_packet[7] = 0x80; /* flags */ pes_packet[8] = 0x24; /* header size */ /* 31 0xFF stuffing is here */ pes_packet[45] = 0x10; /* ebu teletext */ packet_index = EBU_UNIT_SIZE; /* Process the es txt file */ byte_read = 1; while (byte_read) { /* byte_read = read(file_es, pes_packet + packet_index, 1); if (pes_packet[packet_index] == 0x10) { byte_read = read(file_es, pes_packet + packet_index, EBU_UNIT_SIZE); } else { byte_read = read(file_es, pes_packet + packet_index + 1, EBU_UNIT_SIZE - 1); } */ byte_read = read(file_es, pes_packet + packet_index, EBU_UNIT_SIZE); if (byte_read != 0) { packet_index += EBU_UNIT_SIZE; if (packet_index == pes_size) { stamp_ts(pts_stamp, pes_packet + 9); write(STDOUT_FILENO, pes_packet, pes_size); pts_stamp += pts_increment; packet_index = EBU_UNIT_SIZE; } } else { close(file_es); file_es = open(argv[1], O_RDONLY); byte_read = 1; } } if(pes_packet) { free(pes_packet); } return 0; } opencaster-3.2.2/tools/tscbrmuxer/0000755000175000017500000000000012214326444016447 5ustar debiandebianopencaster-3.2.2/tools/tscbrmuxer/Makefile0000644000175000017500000000063312214326444020111 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = tscbrmuxer.o TARGET = tscbrmuxer DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/tscbrmuxer/tscbrmuxer.c0000644000175000017500000001553412214326444021021 0ustar debiandebian/* * Copyright (C) 2005-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #include #define TS_PACKET_SIZE 188 #define MAX_PID 8192 typedef struct list { int fd; char close_fd; char* filename; double bps; double output_packets; /* will take thousend of years to overflown at 100mbps */ struct list* next; } fd_list; fd_list* g_fd_list = 0; fd_list* g_fd_list_last = 0; int enqueue_fd(int fd, char* filename, int bps, char close_fd) { fd_list* fd_new_list; fd_new_list = (fd_list*) malloc(sizeof(fd_list)); fd_new_list->fd = fd; fd_new_list->bps = bps; fd_new_list->filename = filename; fd_new_list->output_packets = 0; fd_new_list->next = 0; fd_new_list->close_fd = close_fd; if (g_fd_list == 0) { g_fd_list = fd_new_list; g_fd_list_last = fd_new_list; } else { g_fd_list_last->next = fd_new_list; g_fd_list_last = fd_new_list; } return (fd < 0); } fd_list* choose_fd(void) { int not_chosen = 1; double min = 0; double temp = 0; fd_list* fd_list_index; fd_list* result; fd_list_index = g_fd_list; while(fd_list_index != 0) { /* search the min */ temp = (fd_list_index->output_packets * TS_PACKET_SIZE * 8) / fd_list_index->bps; if (not_chosen || temp < min) { min = temp; result = fd_list_index; not_chosen = 0; } fd_list_index = fd_list_index->next; } result->output_packets++; return result; } void Usage (void) { fprintf(stderr, "Usage: 'tscbrmuxer b:bitrate_pat pat.ts b:bitrate_cat cat.ts b:pmt1_bitrate pmt1.ts b:nit_bitrate nit.ts ... where bitrate in 'b:bitrate file.ts' is in bit per second\n"); fprintf(stderr, "Usage: 'o:bitrate null.ts can be used to specify final output ts bit rate, must be the last parameter\n"); fprintf(stderr, "Usage: 'c:bitrate file.ts can be used to specify that when the file.ts ends the mux stops\n"); } int main(int argc, char *argv[]) { int fd; int bps; int byte_read; unsigned short pid; unsigned char adaptation_field; double output_bitrate; unsigned int i; unsigned char ts_packet[TS_PACKET_SIZE]; fd_list* chosen_fd; unsigned char pid_cc_table[MAX_PID]; /* PID table for the continuity counter of the TS packets */ unsigned char previous_cc_table[MAX_PID]; /* two packets can have the same continuity counter under some conditions... */ memset(pid_cc_table, 0x10, MAX_PID); memset(previous_cc_table, 0x10, MAX_PID); /* Parse command line */ if (argc < 3) { Usage(); return 2; } i = 1; while (i < argc) { if (argv[i][0] == 'b' && argv[i][1] == ':') { bps = atoi(&(argv[i][2])); fd = open(argv[i+1], O_RDONLY); if (bps > 0 && fd >= 0) { if(enqueue_fd(fd, argv[i+1], bps, 0)) return 2; } else if (bps < 0){ fprintf(stderr, "specified bps is not positive\n"); return 2; } else if (fd < 0) { fprintf(stderr, "can't find file %s\n", argv[i+1]); return 2; } output_bitrate += bps; i+=2; } else if (argv[i][0] == 'c' && argv[i][1] == ':') { bps = atoi(&(argv[i][2])); fd = open(argv[i+1], O_RDONLY); if (bps > 0 && fd >= 0) { if(enqueue_fd(fd, argv[i+1], bps, 1)) return 2; } else if (bps < 0){ fprintf(stderr, "specified bps is not positive\n"); return 2; } else if (fd < 0) { fprintf(stderr, "can't find file %s\n", argv[i+1]); return 2; } output_bitrate += bps; i+=2; } else if (argv[i][0] == 'o' && argv[i][1] == ':') { bps = atoi(&(argv[i][2])); if (bps <= output_bitrate) { fprintf(stderr, "total bitrate is less or equale than sum of current bitrates\n"); return 2; } fd = open(argv[i+1], O_RDONLY); if (bps > 0 && fd >= 0) { if(enqueue_fd(fd, argv[i+1], bps - output_bitrate, 0)) return 2; output_bitrate = bps; } else if (bps < 0){ fprintf(stderr, "specified bps is not positive\n"); return 2; } else if (fd < 0) { fprintf(stderr, "can't find file %s\n", argv[i+1]); return 2; } i = argc; } else { Usage(); return 2; } } fprintf(stderr, "output bitrate: %f\n", output_bitrate); /* mux them */ while(1) { chosen_fd = choose_fd(); /* read packet */ byte_read = 0; byte_read = read(chosen_fd->fd, ts_packet, TS_PACKET_SIZE); if (byte_read < TS_PACKET_SIZE) { close(chosen_fd->fd); if (chosen_fd->close_fd) { return 0; } chosen_fd->fd = open(chosen_fd->filename, O_RDONLY); if (chosen_fd->fd < 0) { fprintf(stderr, "Can't find file %s\n", chosen_fd->filename); return 2; } byte_read = read(chosen_fd->fd, ts_packet, TS_PACKET_SIZE); if (byte_read == TS_PACKET_SIZE) { memcpy(&pid, ts_packet + 1, 2); pid = ntohs(pid); pid = pid & 0x1fff; previous_cc_table[pid] = 0x10; } } /* check packets cc */ memcpy(&pid, ts_packet + 1, 2); pid = ntohs(pid); pid = pid & 0x1fff; if (pid < MAX_PID) { if (pid_cc_table[pid] == 0x10) { fprintf(stderr, "new pid entry %d\n", pid); pid_cc_table[pid] = ts_packet[3] & 0x0f; /* new stream to track cc */ previous_cc_table[pid] = ts_packet[3] & 0x0f; } else { adaptation_field = (ts_packet[3] & 0x30) >> 4; if (adaptation_field == 0x0 || adaptation_field == 0x2) { /* reserved, no increment */ ts_packet[3] = (pid_cc_table[pid] | (ts_packet[3] & 0xf0)); } else if ((adaptation_field == 0x1) && ((ts_packet[3] & 0x0f) == previous_cc_table[pid])) { /* double packet accepted only once */ ts_packet[3] = (pid_cc_table[pid] | (ts_packet[3] & 0xf0)); previous_cc_table[pid] = 0x10; } else if ((adaptation_field == 0x3) && ((ts_packet[3] & 0x0f) == previous_cc_table[pid])) { /* double packet accepted only once */ ts_packet[3] = (pid_cc_table[pid] | (ts_packet[3] & 0xf0)); previous_cc_table[pid] = 0x10; } else { /* increase the cc and restamp */ previous_cc_table[pid] = ts_packet[3] & 0x0f; pid_cc_table[pid] = (pid_cc_table[pid] + 1) % 0x10; ts_packet[3] = (pid_cc_table[pid] | (ts_packet[3] & 0xf0)); } } } /* write packet */ write(STDOUT_FILENO, ts_packet, TS_PACKET_SIZE); } return 0; } opencaster-3.2.2/tools/tsudpsend/0000755000175000017500000000000012214326444016262 5ustar debiandebianopencaster-3.2.2/tools/tsudpsend/Makefile0000644000175000017500000000063612214326444017727 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc -lrt OBJS = tsudpsend.o TARGET = tsudpsend DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/tsudpsend/tsudpsend.c0000644000175000017500000001204712214326444020443 0ustar debiandebian/* * Copyright (C) 2008-2013, Lorenzo Pallara l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #define MULTICAST #include #include #include #include #include #include #include #include #include #include #include #define TS_PACKET_SIZE 188 long long int usecDiff(struct timespec* time_stop, struct timespec* time_start) { long long int temp = 0; long long int utemp = 0; if (time_stop && time_start) { if (time_stop->tv_nsec >= time_start->tv_nsec) { utemp = time_stop->tv_nsec - time_start->tv_nsec; temp = time_stop->tv_sec - time_start->tv_sec; } else { utemp = time_stop->tv_nsec + 1000000000 - time_start->tv_nsec; temp = time_stop->tv_sec - 1 - time_start->tv_sec; } if (temp >= 0 && utemp >= 0) { temp = (temp * 1000000000) + utemp; } else { fprintf(stderr, "start time %ld.%ld is after stop time %ld.%ld\n", time_start->tv_sec, time_start->tv_nsec, time_stop->tv_sec, time_stop->tv_nsec); temp = -1; } } else { fprintf(stderr, "memory is garbaged?\n"); temp = -1; } return temp / 1000; } int main (int argc, char *argv[]) { int sockfd; int len; int sent; int ret; int is_multicast; int transport_fd; unsigned char option_ttl; char start_addr[4]; struct sockaddr_in addr; unsigned long int packet_size; char* tsfile; unsigned char* send_buf; unsigned int bitrate; unsigned long long int packet_time; unsigned long long int real_time; struct timespec time_start; struct timespec time_stop; struct timespec nano_sleep_packet; memset(&addr, 0, sizeof(addr)); memset(&time_start, 0, sizeof(time_start)); memset(&time_stop, 0, sizeof(time_stop)); memset(&nano_sleep_packet, 0, sizeof(nano_sleep_packet)); if(argc < 5 ) { fprintf(stderr, "Usage: %s file.ts ipaddr port bitrate [ts_packet_per_ip_packet] [udp_packet_ttl]\n", argv[0]); fprintf(stderr, "ts_packet_per_ip_packet default is 7\n"); fprintf(stderr, "bit rate refers to transport stream bit rate\n"); fprintf(stderr, "zero bitrate is 100.000.000 bps\n"); return 0; } else { tsfile = argv[1]; addr.sin_family = AF_INET; addr.sin_addr.s_addr = inet_addr(argv[2]); addr.sin_port = htons(atoi(argv[3])); bitrate = atoi(argv[4]); if (bitrate <= 0) { bitrate = 100000000; } if (argc >= 6) { packet_size = strtoul(argv[5], 0, 0) * TS_PACKET_SIZE; } else { packet_size = 7 * TS_PACKET_SIZE; } } sockfd = socket(AF_INET, SOCK_DGRAM, 0); if(sockfd < 0) { perror("socket(): error "); return 0; } if (argc >= 7) { option_ttl = atoi(argv[6]); is_multicast = 0; memcpy(start_addr, argv[2], 3); start_addr[3] = 0; is_multicast = atoi(start_addr); is_multicast = (is_multicast >= 224) || (is_multicast <= 239); if (is_multicast) { ret = setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &option_ttl, sizeof(option_ttl)); } else { ret = setsockopt(sockfd, IPPROTO_IP, IP_TTL, &option_ttl, sizeof(option_ttl)); } if(ret < 0) { perror("ttl configuration fail"); } } transport_fd = open(tsfile, O_RDONLY); if(transport_fd < 0) { fprintf(stderr, "can't open file %s\n", tsfile); close(sockfd); return 0; } int completed = 0; send_buf = malloc(packet_size); packet_time = 0; real_time = 0; nano_sleep_packet.tv_nsec = 665778; /* 1 packet at 100mbps*/ clock_gettime(CLOCK_MONOTONIC, &time_start); while (!completed) { clock_gettime(CLOCK_MONOTONIC, &time_stop); real_time = usecDiff(&time_stop, &time_start); while (real_time * bitrate > packet_time * 1000000 && !completed) { /* theorical bits against sent bits */ len = read(transport_fd, send_buf, packet_size); if(len < 0) { fprintf(stderr, "ts file read error \n"); completed = 1; } else if (len == 0) { fprintf(stderr, "ts sent done\n"); completed = 1; } else { sent = sendto(sockfd, send_buf, len, 0, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)); if(sent <= 0) { perror("send(): error "); completed = 1; } else { packet_time += packet_size * 8; } } } nanosleep(&nano_sleep_packet, 0); } close(transport_fd); close(sockfd); free(send_buf); return 0; } opencaster-3.2.2/tools/tspcrrestamp/0000755000175000017500000000000012214326444017000 5ustar debiandebianopencaster-3.2.2/tools/tspcrrestamp/tspcrrestamp.c0000644000175000017500000002330412214326444021675 0ustar debiandebian/* * Copyright (C) 2011-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #define TS_HEADER_SIZE 4 #define TS_PACKET_SIZE 188 #define MAX_PID 8192 #define TIME_STAMP_SIZE 5 #define SYSTEM_CLOCK_FREQUENCY 27000000 const long long unsigned system_frequency = 27000000; void stamp_ts (unsigned long long int ts, unsigned char* buffer) { if (buffer) { buffer[0] = ((ts >> 29) & 0x0F) | 0x01; buffer[1] = (ts >> 22) & 0xFF; buffer[2] = ((ts >> 14) & 0xFF ) | 0x01; buffer[3] = (ts >> 7) & 0xFF; buffer[4] = ((ts << 1) & 0xFF ) | 0x01; } } unsigned long long parse_timestamp(unsigned char *buf) { unsigned long long a1; unsigned long long a2; unsigned long long a3; unsigned long long ts; a1 = (buf[0] & 0x0F) >> 1; a2 = ((buf[1] << 8) | buf[2]) >> 1; a3 = ((buf[3] << 8) | buf[4]) >> 1; ts = (a1 << 30) | (a2 << 15) | a3; return ts; } int main(int argc, char *argv[]) { int fd_ts; /* File descriptor of ts file */ u_short pid; int byte_read; int pcr_ext = 0; unsigned int i; /* unsigned int j; */ int ts_header_size = 0; unsigned char PTS_DTS_flag = 0; unsigned char pes_header_size = 0; unsigned int buffer_size = 0; unsigned char adapt = 0; unsigned char* packet_buffer = 0; unsigned char* current_packet = 0; unsigned char timestamp[TIME_STAMP_SIZE]; unsigned long long int time = 0; unsigned long long int trbits = 0; unsigned long long int pcr_base = 0; unsigned long long int ts_packet_count; unsigned long long int new_pcr = 0; unsigned long long int new_pcr_module = 0; unsigned long long int pcr_index_rounding = 0; unsigned long long int pcr_table[MAX_PID]; /* PCR table for the outgoing TS packets */ unsigned long long int pcr_index_table[MAX_PID];/* PCR index table for the TS packets */ unsigned long long int pts_time_table[MAX_PID]; unsigned short pts_pcr_reference[MAX_PID]; /* Open ts file */ buffer_size = 0; if (argc >= 3) fd_ts = open(argv[1], O_RDONLY); else { fprintf(stderr, "Usage: tspcrrestamp input.ts transport_rate_bit/s pes_pid1 pcr_pid1 pes_pid2 pcr_pid2 [...] pes_pidn pcr_pidn \n"); fprintf(stderr, "N.B: this tool will change the pcr values taking as reference the first pcr seen"); fprintf(stderr, "If pts/dts time in a given pes_pid goes backward the pcr in the reference pid is reset too"); return 2; } if (fd_ts < 0) { fprintf(stderr, "Can't find file %s\n", argv[1]); return 2; } trbits = atol(argv[2]); if (trbits == 0) { fprintf(stderr, "transport_rate is 0?\n"); return 2; } if (argv[3] != NULL) { buffer_size = atoi(argv[3]); if (buffer_size == 0) { fprintf(stderr, "buffer size is invalid\n"); return 2; } } else { buffer_size = 1; } /* Start to process the file */ buffer_size *= TS_PACKET_SIZE; packet_buffer = malloc(buffer_size); if (packet_buffer == NULL) { fprintf(stderr, "out of memory\n"); return 2; } memset(pcr_table, 0ll, MAX_PID*(sizeof(unsigned long long int))); memset(pcr_index_table, 0ll, MAX_PID*(sizeof(unsigned long long int))); memset(pts_time_table, 0ll, MAX_PID*(sizeof(unsigned long long int))); for (i = 0; i < MAX_PID; i++) { pts_pcr_reference[i] = MAX_PID; } for (i = 3; i < argc; i+=2) { pid = atoi(argv[i]); if (pid < MAX_PID && pid >= 0) { pts_pcr_reference[pid] = atoi(argv[i+1]); } fprintf(stderr,"pts of pid %d will reset pcr of pid %d\n", pid, pts_pcr_reference[pid]); } ts_packet_count = 0; pcr_index_rounding = 0ll; byte_read = 1; while(byte_read) { /* Read next packets */ byte_read = read(fd_ts, packet_buffer, buffer_size); for (i = 0; i < buffer_size; i += TS_PACKET_SIZE) { current_packet = packet_buffer + i; memcpy(&pid, current_packet + 1, 2); pid = ntohs(pid); pid = pid & 0x1fff; /* Check pcr */ if ((pid < MAX_PID) && (current_packet[3] & 0x20) && (current_packet[4] != 0) && (current_packet[5] & 0x10)) { /* there is PCR */ if (pcr_table[pid] == 0) { pcr_base = (((unsigned long long int)current_packet[6]) << 25) + (current_packet[7] << 17) + (current_packet[8] << 9) + (current_packet[9] << 1) + (current_packet[10] >> 7); pcr_ext = ((current_packet[10] & 1) << 8) + current_packet[11]; pcr_table[pid] = (pcr_base * 300 + pcr_ext); pcr_index_table[pid] = ts_packet_count; //fprintf(stderr, "%llu: pid %d, new pcr is %llu (%f sec)\n", // pcr_index_table[pid], fprintf(stderr, "pid %d start pcr is %llu (%f sec)\n", pid, pcr_table[pid], ((double)(pcr_table[pid]) / SYSTEM_CLOCK_FREQUENCY) ); } else { new_pcr = ((ts_packet_count - pcr_index_table[pid]) * TS_PACKET_SIZE) + 10; /* ts position in byte */ new_pcr *= 8; /* bits */ new_pcr *= SYSTEM_CLOCK_FREQUENCY; new_pcr /= trbits; new_pcr += pcr_table[pid]; new_pcr += pcr_index_rounding; new_pcr_module = new_pcr % 2576980377600ll; pcr_base = new_pcr_module / 300; pcr_ext = new_pcr_module % 300; current_packet[6] = (0xFF & (pcr_base >> 25)); current_packet[7] = (0xFF & (pcr_base >> 17)); current_packet[8] = (0xFF & (pcr_base >> 9)); current_packet[9] = (0xFF & (pcr_base >> 1)); current_packet[10] = ((0x1 & pcr_base) << 7) | 0x7E | ((0x100 & pcr_ext) >> 8); current_packet[11] = (0xFF & pcr_ext); /* max packet count = 454263790 */ /* multiplication will overflown but sum won't because is after div */ /* ((454263790 * 188) + 10) * 8 * 27000000 < 2^64 */ if (ts_packet_count * 2 >= 454263790) { ts_packet_count = 0; pcr_index_rounding = new_pcr; } /* 2^33 * 300 = 2576980377600 / 27000000 < 95444 secs at 100Mbps are < 6346010639 packets < 2^64 ts_packet_counter */ if (new_pcr >= 2576980377600ll ) { ts_packet_count = 0; pcr_index_rounding = (new_pcr - 2576980377600ll); } } } /* if (((ts_packet_count + 1) * TS_PACKET_SIZE) + 10 < ts_packet_count) { unsigned long long int min = 0ll; for (j = 0; j < MAX_PID; j++) { if (pcr_index_table[pid] > 0 && min == 0) { min = pcr_index_table[pid]; } else if (pcr_index_table[pid] > 0 && pcr_index_table[pid] < min) { min = pcr_index_table[pid]; } } unsigned long long int ts_packet_delta = (min - 10) / TS_PACKET_SIZE; ts_packet_count -= ts_packet_delta; for (j = 0; j < MAX_PID; j++) { pcr_index_table[pid] -= ts_packet_delta; pcr_table[pid] = pcr_index_table[pid] * 8 * SYSTEM_CLOCK_FREQUENCY / trbits; } } */ /* check PTS and DTS */ if (pid < MAX_PID) { if (pts_pcr_reference[pid] != MAX_PID) { adapt = (current_packet[3] >> 4) & 0x03; if (adapt == 0) { ts_header_size = TS_PACKET_SIZE; /* the packet is invalid ?*/ } else if (adapt == 1) { ts_header_size = TS_HEADER_SIZE; /* only payload */ } else if (adapt == 2) { ts_header_size = TS_PACKET_SIZE; /* only adaptation field */ } else if (adapt == 3) { ts_header_size = TS_HEADER_SIZE + current_packet[4] + 1; /* jump the adaptation field */ } else { ts_header_size = TS_PACKET_SIZE; /* not managed */ } } else { ts_header_size = TS_PACKET_SIZE; /* not interested into monitor this pid */ } pes_header_size = 0; time = 0; if (ts_header_size + 20 < TS_PACKET_SIZE && pid < MAX_PID) { if ( (current_packet[ts_header_size] == 0x00) && (current_packet[ts_header_size + 1] == 0x00) && (current_packet[ts_header_size + 2] == 0x01) && ( ((current_packet[ts_header_size + 3] >> 4) == 0x0E) || ((current_packet[ts_header_size + 3] >> 5) == 0x05) || ((current_packet[ts_header_size + 3] >> 5) == 0x06) ) ){ /* pes packet prefix code for PES video and audio */ PTS_DTS_flag = current_packet[ts_header_size + 7] >> 6; pes_header_size = current_packet[ts_header_size + 8]; if (PTS_DTS_flag > 1 && pes_header_size) { memcpy(timestamp, current_packet + ts_header_size + 9, TIME_STAMP_SIZE); time = parse_timestamp(timestamp); //fprintf(stderr, "Pid %d Presentation Time Stamp is: %llu, %llu.%04llu sec.\n", pid, time, time / (system_frequency / 300), (time % (system_frequency / 300)) / ((system_frequency / 300) / 10000)); if (pes_header_size > 5 && PTS_DTS_flag > 2) { memcpy(timestamp, current_packet + ts_header_size + 14, TIME_STAMP_SIZE); time = parse_timestamp(timestamp); //fprintf(stderr, "Pid %d Decode Time Stamp is: %llu, %llu.%04llu sec.\n", pid, time, time / (system_frequency / 300), (time % (system_frequency / 300)) / ((system_frequency / 300) / 10000)); } if (time < pts_time_table[pid]) { /* pts loop or encoder crashed and time restarted */ pcr_table[pid] = 0; /* reset pcr table */ } pts_time_table[pid] = time; } } } } ts_packet_count++; } /* write packets out */ write(STDOUT_FILENO, packet_buffer, buffer_size); } return 0; } opencaster-3.2.2/tools/tspcrrestamp/Makefile0000644000175000017500000000063712214326444020446 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = tspcrrestamp.o TARGET = tspcrrestamp DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/oc2sec/0000755000175000017500000000000012214326444015427 5ustar debiandebianopencaster-3.2.2/tools/oc2sec/Makefile0000644000175000017500000000035412214326444017071 0ustar debiandebianFILE2MOD = file2mod.py MOD2SEC = mod2sec.py OCUPDATE = oc-update.sh DESTDIR ?= /usr/local/bin/ all: install: install -m 755 $(FILE2MOD) $(DESTDIR) install -m 755 $(MOD2SEC) $(DESTDIR) install -m 755 $(OCUPDATE) $(DESTDIR) opencaster-3.2.2/tools/oc2sec/mod2sec.py0000755000175000017500000000651512214326444017347 0ustar debiandebian#! /usr/bin/env python # Copyright 2000-2001, GMD, Sankt Augustin # -- German National Research Center for Information Technology # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import sys import getopt from dvbobjects.utils import * from dvbobjects.utils.SpecFile import * from dvbobjects.DVB.DataCarousel import * from dvbobjects.DVB.Loops import * ###################################################################### def BuildCarousel(INPUT_DIR, OUTPUT_DIR): spec = SuperGroupSpec() spec.read("%s/DSI.spec" % INPUT_DIR) # DVB assert 0x0000 <= spec.transactionId & 0x0000FFFF <= 0x0001 dsi = SuperGroup( PATH=spec.PATH, transactionId = spec.transactionId, version = spec.version, ) for group in spec.groups: dii = Group( PATH = group.PATH, transactionId = group.transactionId, downloadId = group.downloadId, blockSize = group.blockSize, version = group.version, ) # DVB assert 0x0001 <= group.transactionId & 0x0000FFFF <= 0xFFFF for mod in group.modules: if os.path.exists("%s.size" % mod.INPUT): # print("Compressing %s") % mod.INPUT m = Module(INPUT="%s" % mod.INPUT, moduleVersion= mod.moduleVersion, moduleId = mod.moduleId, assocTag = group.assocTag, descriptors = [compressed_descriptor(name = mod.INPUT)], ) else: m = Module(INPUT="%s" % mod.INPUT, moduleVersion= mod.moduleVersion, moduleId = mod.moduleId, assocTag = group.assocTag, ) dii.addModule(m) dsi.addGroup(dii) dsi.generate(OUTPUT_DIR, spec.srg_ior) if spec.srg_ior == None: print dsi ###################################################################### OPTIONS = "h" LONG_OPTIONS = [ "help", ] def Usage(return_code = 1): print ("Usage: %s" " [option...]" " " " ") % ( sys.argv[0]) sys.exit(return_code) def CheckArgs(): try: opts, args = getopt.getopt( sys.argv[1:], OPTIONS, LONG_OPTIONS) except getopt.error: Usage() for opt_name, opt_val in opts: if opt_name in ['-h', '--help']: Usage(0) if len(args) <> 2: Usage() INPUT_DIR, OUTPUT_DIR = args BuildCarousel(INPUT_DIR, OUTPUT_DIR) ###################################################################### if __name__ == '__main__': CheckArgs() opencaster-3.2.2/tools/oc2sec/file2mod.py0000755000175000017500000003067312214326444017516 0ustar debiandebian#! /usr/bin/env python # # Copyright 2000-2001, GMD, Sankt Augustin # -- German National Research Center for Information Technology # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import sys import os import re import getopt import pprint import string from stat import ST_SIZE from dvbobjects.utils import * from dvbobjects.utils.SpecFile import * from dvbobjects.DSMCC import BIOP from dvbobjects.DVB.DataCarousel import TransactionId ###################################################################### TIMEOUT = 0xFFFFFFFF TABLE_ID = 0x3C MAX_MODULE_SIZE = 1024 * 64 DEBUG = 0 OPTIONS = "h" LONG_OPTIONS = [ "help" ] ###################################################################### class ModuleBuilder: def __init__(self, OUTPUT_DIR, MODULE_ID): self.module_id = MODULE_ID filename = "%s/%04d.mod" % (OUTPUT_DIR, self.module_id) self.name = filename # needed for debug if DEBUG: print "NEW MODULE: %s" % filename self.__file = open(filename, "wb") self.size = 0 def hasRoom(self, requestedSize): if self.size == 0: # Anything goes... return 1 elif self.size + requestedSize <= MAX_MODULE_SIZE: # Module isn't empty, but still have space return 1 else: # Start new module return 0 def write(self, bytes): msgSize = len(bytes) if DEBUG: print "ADD (mod %d, size %d+%d=%d)" % ( self.module_id, self.size, msgSize, self.size+msgSize) self.__file.write(bytes) self.size = self.size + msgSize ###################################################################### class ObjectCarouselBuilder: # Build an object carousel with 1 DII, this limits the number of modules to something a bit more than 100 def __init__(self, OUTPUT_DIR, CAROUSEL_ID, DOWNLOAD_ID, ASSOC_TAG, MODULE_VERSION, BLOCK_SIZE, UPDATE_FLAG, COMPRESS_MODE): self.MODULE_ID = 2 # The builder generate modules files and specification files # specification files are for informations not included in the modules files themself self.DSI_TransactionId = TransactionId( version = MODULE_VERSION, identification = 0, updateFlag = UPDATE_FLAG, ) self.DII_TransactionId = TransactionId( version = MODULE_VERSION, identification = 1, updateFlag = UPDATE_FLAG, ) self.__SPECdii = open("%s/DII.spec" % OUTPUT_DIR, "w") self.__spec = SuperGroupSpec( transactionId = self.DSI_TransactionId, version = MODULE_VERSION, srg_ior = "%s/SRG_IOR" % OUTPUT_DIR, ) self.__spec.addGroup( transactionId = self.DII_TransactionId, version = MODULE_VERSION, downloadId = DOWNLOAD_ID, assocTag = ASSOC_TAG, blockSize = BLOCK_SIZE, ) # Output variables self.OUTPUT_DIR = OUTPUT_DIR self.DOWNLOAD_ID = DOWNLOAD_ID self.CAROUSEL_ID = CAROUSEL_ID self.ASSOC_TAG = ASSOC_TAG self.MODULE_VERSION = MODULE_VERSION self.COMPRESS_MODE = COMPRESS_MODE self.UPDATE_FLAG = UPDATE_FLAG self.BLOCK_SIZE = BLOCK_SIZE # currently open modules indexed by type self.__ModByType = { 'sgw': 0, 'dir': 0, 'fil': 0, 'ste': 0, 'solo': 0, } self.__TypeInUse = { 'sgw': 0, 'dir': 0, 'fil': 0, 'ste': 0, 'solo': 0, } self.__ModById = {} # Table of Contents, for debugging self.TOC = [] def genSpec(self): self.__spec.write(self.OUTPUT_DIR) def addDirectory(self, node): self.__addNode(node, "dir") def addSGW(self, node): self.__addNode(node, "sgw") def addFile(self, node): self.__addNode(node, "fil") def addSoloFile(self, node): self.__addNode(node, "solo") def addStreamEvent(self, node): self.__addNode(node, "ste") def __addNode(self, node, type): msg = node.message() msgBytes = msg.pack() msgSize = len(msgBytes) if (type == 'solo'): self.__ModByType[type] = self.__nextModule(self.MODULE_ID) self.__ModByType[type].write(msgBytes) filename = "%s/%04d.mod.solo" % (OUTPUT_DIR, self.__ModByType[type].module_id) out = open(filename, "wb") out.close() modid = str(self.__ModByType[type].module_id) elif (type == 'sgw'): self.__ModByType[type] = self.__nextModule(1) self.__ModByType[type].write(msgBytes) modid = str(self.__ModByType[type].module_id) else: if not self.__TypeInUse[type]: self.__ModByType[type] = self.__nextModule(self.MODULE_ID) self.__TypeInUse[type] = 1 if self.__ModByType[type].hasRoom(msgSize): self.__ModByType[type].write(msgBytes) else: self.__ModByType[type] = self.__nextModule(self.MODULE_ID) self.__ModByType[type].write(msgBytes) modid = str(self.__ModByType[type].module_id) node.bind( carouselId = self.CAROUSEL_ID, moduleId = int(modid), assoc_tag = self.ASSOC_TAG, DII_TransactionId = self.DII_TransactionId, ) self.TOC.append(( int(modid), msg.objectKey, os.path.basename(msg.PATH), msg.objectKind, msgSize, )) def __nextModule(self, modid): mod = ModuleBuilder(self.OUTPUT_DIR, int(modid)) if (int(modid) > 1): # id 1 is reserved for sgw self.MODULE_ID = mod.module_id + 1 self.__SPECdii.write("%s 0x%02X 0x%04X 0x%02X\n" % ( mod.name, TABLE_ID, mod.module_id, self.MODULE_VERSION)) self.__spec.addModule( tableId = TABLE_ID, moduleId = mod.module_id, moduleVersion = self.MODULE_VERSION, ) return mod ###################################################################### class FSNode(DVBobject): # superclass for FSDirectory, FSSteam and FSFile. def __init__(self, KEY_SERIAL_NUMBER): self.KEY = KEY_SERIAL_NUMBER def IOR(self, carouselId, moduleId, key, assoc_tag, DII_TransactionId): iop = BIOP.IOP.IOR( PATH = self.PATH, # for debugging type_id = self.MessageClass.objectKind, carouselId = carouselId, moduleId = moduleId, objectKey = key, assocTag = assoc_tag, transactionId = DII_TransactionId, timeout = TIMEOUT, ) return iop def _checkBinding(self): try: raise "Already Bound", self._binding except AttributeError: pass ###################################################################### class FSFile(FSNode): # A File in a File System destined for an Object Carousel. MessageClass = BIOP.FileMessage BindingClass = BIOP.ObjectFileBinding def __init__(self, path, KEY_SERIAL_NUMBER): FSNode.__init__(self, KEY_SERIAL_NUMBER) assert(len(path) > 0) self.PATH = path self.contentSize = os.stat(path)[ST_SIZE] def bind(self, carouselId, moduleId, assoc_tag, DII_TransactionId): self._checkBinding() filename = os.path.basename(self.PATH) self._binding = self.BindingClass( nameId = filename + "\x00", IOR = self.IOR(carouselId, moduleId, self.KEY, assoc_tag, DII_TransactionId), contentSize = self.contentSize, ) def binding(self): return self._binding def message(self): msg = self.MessageClass( PATH = self.PATH, objectKey = self.KEY, contentSize = self.contentSize, ) return msg def shipMessage(self, theObjectCarouselBuilder, isSolo): if (isSolo == 1): theObjectCarouselBuilder.addSoloFile(self) else: theObjectCarouselBuilder.addFile(self) ###################################################################### class FSStreamEvent(FSNode): # A Directory in a File System destined to genereate a StreamEvent Object for Object Carousel. MessageClass = BIOP.StreamEventMessage BindingClass = BIOP.ObjectStreamEventBinding def __init__(self, path, KEY_SERIAL_NUMBER): FSNode.__init__(self, KEY_SERIAL_NUMBER) assert(len(path) > 0) self.PATH = path def bind(self, carouselId, moduleId, assoc_tag, DII_TransactionId): self._checkBinding() filename = os.path.basename(self.PATH) self._binding = self.BindingClass( nameId = filename + "\x00", IOR = self.IOR(carouselId, moduleId, self.KEY, assoc_tag, DII_TransactionId), ) def binding(self): return self._binding def message(self): msg = self.MessageClass( PATH = self.PATH, objectKey = self.KEY, ) return msg def shipMessage(self, theObjectCarouselBuilder): theObjectCarouselBuilder.addStreamEvent(self) ###################################################################### class FSDir(FSNode, ObjectCarouselBuilder):# A Directory in a File System destined for an Object Carousel. MessageClass = BIOP.DirectoryMessage BindingClass = BIOP.ContextBinding def __init__(self, path, KEY_SERIAL_NUMBER): FSNode.__init__(self, KEY_SERIAL_NUMBER) assert(len(path) > 0) self.PATH = path self.bindings = [] self.visitKEY = KEY_SERIAL_NUMBER def bind(self, carouselId, moduleId, assoc_tag, DII_TransactionId): self._checkBinding() filename = os.path.basename(self.PATH) self._binding = self.BindingClass( nameId = filename + "\x00", IOR = self.IOR(carouselId, moduleId, self.KEY, assoc_tag, DII_TransactionId), ) def binding(self): return self._binding def message(self): msg = self.MessageClass( PATH = self.PATH, objectKey = self.KEY, bindings = self.bindings, ) return msg def visit(self, theObjectCarouselBuilder): #Depth first visit #REJECT_EXT = ['.pyc', '.o', '.so'] #SINGLE_MODULE_EXT = ['.jpg', '.png', '.gif', '.solo'] SINGLE_MODULE_EXT = ['.solo'] #REJECT_FN = ['x', 'tmp'] #REJECT_FN = [] EVENT_EXT = ['.event'] assert os.path.isdir(self.PATH), self.PATH try: ls = os.listdir(self.PATH) except: print self.PATH raise ls.sort() for filename in ls: path = os.path.join(self.PATH, filename) # if os.path.splitext(filename)[1] in REJECT_EXT: # continue if os.path.isfile(path): self.visitKEY = self.visitKEY + 1 obj = FSFile(path, self.visitKEY) if (os.path.splitext(filename)[1] in SINGLE_MODULE_EXT) and (theObjectCarouselBuilder.COMPRESS_MODE == 2): obj.shipMessage(theObjectCarouselBuilder, 1) else: obj.shipMessage(theObjectCarouselBuilder, 0) if DEBUG: print obj.message() print elif os.path.isdir(path): if os.path.splitext(filename)[1] in EVENT_EXT: self.visitKEY = self.visitKEY + 1 obj = FSStreamEvent(path, self.visitKEY) obj.shipMessage(theObjectCarouselBuilder) if DEBUG: print obj.message() print else: self.visitKEY = self.visitKEY + 1 obj = FSDir(path, self.visitKEY) obj.visit(theObjectCarouselBuilder) self.visitKEY = obj.visitKEY if DEBUG: print obj.message() print else: continue self.bindings.append(obj.binding()) # THIS directory (i.e. self) is complete, so... self.shipMessage(theObjectCarouselBuilder) if DEBUG: print self.message() print def shipMessage(self, theObjectCarouselBuilder): theObjectCarouselBuilder.addDirectory(self) ###################################################################### class FSRoot(FSDir): #A Directory in a File System destined as Service Gateway for an Object Carousel MessageClass = BIOP.ServiceGatewayMessage def shipMessage(self, theObjectCarouselBuilder): theObjectCarouselBuilder.addSGW(self) ###################################################################### if __name__ == '__main__': try: opts, args = getopt.getopt(sys.argv[1:], OPTIONS, LONG_OPTIONS) except getopt.error: print ("Usage: %s" " " " " " download_id" " carousel_id" " association_tag" " version" " [block_size update_flag compress_mode]" ) % ( sys.argv[0]) sys.exit(1) INPUT_DIR, OUTPUT_DIR, CAROUSEL_ID, DOWNLOAD_ID, ASSOC_TAG, MODULE_VERSION, BLOCK_SIZE, UPDATE_FLAG, COMPRESS_MODE = args root = FSRoot(INPUT_DIR, 0) theObjectCarouselBuilder = ObjectCarouselBuilder(OUTPUT_DIR, int(CAROUSEL_ID), int(DOWNLOAD_ID), int(ASSOC_TAG, 16), int(MODULE_VERSION, 16), int(BLOCK_SIZE), int(UPDATE_FLAG), int(COMPRESS_MODE)) root.visit(theObjectCarouselBuilder) out = open("%s/SRG_IOR" % OUTPUT_DIR, "wb") out.write(root.binding().IOR.pack()) out.close() theObjectCarouselBuilder.genSpec() if DEBUG: print root.binding().IOR pprint.pprint(theObjectCarouselBuilder.TOC) opencaster-3.2.2/tools/oc2sec/oc-update.sh0000755000175000017500000001155012214326444017651 0ustar debiandebian#!/bin/bash if [ $# -lt 5 ] then /bin/echo "Usage:" /bin/echo "oc-update.sh object_carousel_directory association_tag module_version dsmcc_pid carousel_id [compress_mode] [padding_on] [clean_off] [DDB_size] [update_flag] [mount_frequency]" /bin/echo " - carousel_directory: the directory to marshal in an object carousel" /bin/echo " - association_tag aka common tag, referenced by PMTs and AITs, every carousel has one" /bin/echo " - modules_version, all the modules will have the same version, you need to change this to notify to the box files are changed, goes from 0 to 15" /bin/echo " - pid, referenced by PMTs using this carousel" /bin/echo " - carousel_id, referenced by PMTs using this carousel, every carousel has its own, it is an alternative for association_tag, they have the same function" /bin/echo " - compress_mode, 0: don't compress, 1:compress all, 2:smart compress, file with .solo extension are set in an uncompressed module alone to allow use cases like quick image file update, default is 2" /bin/echo " - padding_on, every section is padded, was useful with some buggy decoder, waste bandwidth, default off, unsupported since OpenCaster 2.4.8" /bin/echo " - clean_off, don't delete temp file, default off, used for debug" /bin/echo " - DDB_size, Use custom size for DDB payload, default = max = 4066" /bin/echo " - sets the Update flag in the TransactionID of DSI and DII to the value given (0 or 1)" /bin/echo " - mount_frequency, set how often insert DII/DSI/SGW to speed up carousel mount, default is twice per carousel period" /bin/echo /bin/echo "Example:" /bin/echo "oc-update.sh ocdir1 0xB 5 2003 7 2 0 0 4066 0 2" /bin/echo " carousel_directory: ocdir1" /bin/echo " association_tag: 0xB (11)" /bin/echo " modules_version: 0x5 (5)" /bin/echo " pid: 2001" /bin/echo " carousel_id: 7" /bin/echo " smart compress the carousel" /bin/echo " don't pad" /bin/echo " delete temp files" /bin/echo " use 4066 bytes for DDB size (usual and maximum size)" /bin/echo " sets update flag to 0 in DSI/DII" /bin/echo " insert DSI/DII/SGW twice per carousel length" exit 65 fi #Parameters passing OCDIR=$1 ASSOCIATION_TAG=$2 MODULE_VERSION=$3 PID=$4 CAROUSEL_ID=$5 COMPRESS_MODE="2" PAD_ON="0" NO_DELETE_TEMP="0" BLOCK_SIZE="4066" UPDATE_FLAG="0" MOUNT_PERIOD="2" if [ $# -gt 5 ] then COMPRESS_MODE=$6 fi if [ $# -gt 6 ] then PAD_ON=$ fi if [ $# -gt 7 ] then NO_DELETE_TEMP=$8 fi if [ $# -gt 8 ] then BLOCK_SIZE=$9 fi if [ $# -gt 9 ] then UPDATE_FLAG=${10} fi if [ $# -gt 10 ] then MOUNT_PERIOD=${11} fi #Generate temp directories TEMP_DIR_MOD=`/bin/mktemp -d` TEMP_DIR_SEC=`/bin/mktemp -d` #Generate the modules from the directory, the modules are stored into a tmp directory TEMP_DIR_MOD /usr/local/bin/file2mod.py $OCDIR $TEMP_DIR_MOD $CAROUSEL_ID $CAROUSEL_ID $ASSOCIATION_TAG $MODULE_VERSION $BLOCK_SIZE $UPDATE_FLAG $COMPRESS_MODE #Compress all modules if [ "$COMPRESS_MODE" = "1" ] then for file in $TEMP_DIR_MOD/*.mod do /usr/bin/du --apparent-size --block-size 1 $file > $file.size /usr/local/bin/zpipe < $file > $file.z /bin/mv $file.z $file done fi #Compress only "not solo" modules (.jpg, .gif, .png and .solo) if [ "$COMPRESS_MODE" = "2" ] then for file in $TEMP_DIR_MOD/*.mod do if [ ! -f $file.solo ] then /usr/bin/du --apparent-size --block-size 1 $file > $file.size /usr/local/bin/zpipe < $file > $file.z /bin/mv $file.z $file else /bin/rm $file.solo fi done fi #Generate sections from modules, the sections are stored into a tmp directory TEMP_DIR_SEC /usr/local/bin/mod2sec.py $TEMP_DIR_MOD $TEMP_DIR_SEC # Check if it is necessary to pad every sections or not, unluckly we have found some decoders having buggy section filtering that needed this if [ "$PAD_ON" = "1" ] then echo "UNSUPPORTED SINCE 2.4.8" else # All the single section files are enqueued in a single file, padding will occur only at the end of the last section # DSI, DII and sgw are repeated more frequently file_number=0 for file in $TEMP_DIR_SEC/*.sec do let file_number=$file_number+1 done echo "total carousel section number is $file_number" period=$(($file_number/$MOUNT_PERIOD)) echo "carousel head period is every $period section" counter=-1 for file in $TEMP_DIR_SEC/*.sec do /bin/cat $file >> $TEMP_DIR_SEC/temp_sec let counter=$counter-1 #echo "counter is $counter" if [ $counter -lt 0 ]; then let counter=$period /bin/cat $TEMP_DIR_SEC/DSI.sec >> $TEMP_DIR_SEC/temp_sec /bin/cat $TEMP_DIR_SEC/DII.sec >> $TEMP_DIR_SEC/temp_sec /bin/cat $TEMP_DIR_SEC/0001_000000.sec >> $TEMP_DIR_SEC/temp_sec # SGW is 1 section of module id 1 fi done /usr/local/bin/sec2ts $PID < $TEMP_DIR_SEC/temp_sec > $OCDIR.ts fi # Delete temp files if [ "$NO_DELETE_TEMP" = "0" ] then /bin/rm -rf $TEMP_DIR_MOD /bin/rm -rf $TEMP_DIR_SEC else /bin/echo "Modules generated in $TEMP_DIR_MOD were not deleted" /bin/echo "Sections generated in $TEMP_DIR_SEC were not deleted" fi opencaster-3.2.2/tools/Makefile0000755000175000017500000000147012220026471015710 0ustar debiandebianSUBDIRS = oc2sec sec2ts zpipe \ tsfilter tsloop tsmodder tsnullfiller tsnullshaper \ tspcrmeasure tspidmapper esaudio2pes esaudioinfo \ esvideompeg2pes esvideompeg2info pes2es pesaudio2ts \ pesvideo2ts pesinfo tsstamp \ ts2pes mpe2sec tscbrmuxer mpeg2videovbv tstdt i13942ts \ tsvbr2cbr tsfixcc tsudpreceive tsudpsend dsmcc-receive \ tspcrstamp tstcpreceive tstcpsend tstimeout \ tstimedwrite tsinputswitch tsdoubleoutput pes2txt \ tsoutputswitch tsccc txt2pes ts2sec \ pesdata2ts tsmask tsorts tsororts tspcrrestamp \ eitsecfilter eitsecmapper m2ts2cbrts \ ts2m2ts tsdiscont eitsecactualtoanother subdirs: $(SUBDIRS) $(SUBDIRS): $(MAKE) -C $@ .PHONY: subdirs $(SUBDIRS) all: subdirs install: all @for T in $(SUBDIRS); do make -C $$T $@; done clean: @for T in $(SUBDIRS); do make -C $$T $@; done opencaster-3.2.2/tools/esvideompeg2info/0000755000175000017500000000000012214326443017515 5ustar debiandebianopencaster-3.2.2/tools/esvideompeg2info/Makefile0000644000175000017500000000064712214326443021164 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = esvideompeg2info.o TARGET = esvideompeg2info DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/esvideompeg2info/esvideompeg2info.c0000644000175000017500000002137412214326443023135 0ustar debiandebian/* * Copyright (C) 2004-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #include #define ES_HEADER_SIZE 4 #define HEADER_MAX_SIZE 64 /* MPEG VIDEO */ const char* picture_coding[8] = { "forbidden", "I-Frame", "P-Frame", "B-Frame", "invalid", "reserved", "reserved", "reserved", }; const char* profile[8] = { "reserved", "High", "Spatially Scalable", "SNR Scalable", "Main", "Simple", "reserved", "reserved", }; const char* level[16] = { "reserved", "reserved", "reserved", "reserved", "High", "reserved", "High 1440", "reserved", "Main", "reserved", "Low", "reserved", "reserved", "reserved", "reserved", "reserved", }; const char* aspect_ratio[16] = { "forbidden", "1:1", "4:3", "16:9", "2.21:1", "reserved", "reserved", "reserved", "reserved", "reserved", "reserved", "reserved", "reserved", "reserved", "reserved", "reserved", }; const char* frame_rate[16] = { "forbidden", "23.9", "24", "25", "29.9", "30", "50", "59.9", "60", "reserved", "reserved", "reserved", "reserved", "reserved", "reserved", "reserved", }; const float frame_sec[16] = { 1.0, 1/23.9, 1/24.0, 1/25.0, 1/29.9, 1/30.0, 1/50.0, 1/59.9, 1/60.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, }; int main(int argc, char *argv[]) { int byte_read; int byte_count; int bitrated; float frames; unsigned int picture_time; unsigned char picture_type; unsigned int vbv_delay; int drop; int hour; int min; int sec; int pictures; int closed; int broken; int horizontal_size; int vertical_size; int aspect_ratioed; int frame_rated; int max_frame_size; int frame_size; int vbv_buffer_size; int constrained; int frame_counter; double max_bps; double current_bps; double average_bps; unsigned long int gop_count; unsigned long long int total_byte_count; unsigned long long int previous_byte_count; FILE* file_es; unsigned char es_header[HEADER_MAX_SIZE]; /* Open es file */ if (argc > 1) { file_es = fopen(argv[1], "rb"); } else { fprintf(stderr, "Example: esvideompeg2info video.es\n"); return 2; } if (file_es == 0) { fprintf(stderr, "Can't find file %s\n", argv[1]); return 2; } /* Start to process the file */ byte_count = 0; total_byte_count = 0; frame_counter = 0; gop_count = 0; max_bps = 0; frame_size = 0; max_frame_size = 0; previous_byte_count = 0; current_bps = 0; average_bps = 0; byte_read = fread(es_header, 1, ES_HEADER_SIZE, file_es); while(byte_read) { byte_count += byte_read; total_byte_count += byte_read; /* Search headers */ if (es_header[0] == 0x00 && es_header[1] == 0x00 && es_header[2] == 0x01 && es_header[3] == 0x00) { /* Picture start header */ frame_counter++; frame_size = total_byte_count - previous_byte_count; if (frame_size > max_frame_size) { max_frame_size = frame_size; } previous_byte_count = total_byte_count; fprintf(stdout, "frame size: %d\n", frame_size); fprintf(stdout, "Postion %llu, picture %d start header: ", total_byte_count, frame_counter); byte_read = fread(es_header, 1, 4, file_es); picture_time = (es_header[0] << 2) | ((es_header[1] & 0xC0) >> 6); fprintf(stdout, "temporal reference: %u, ", picture_time); picture_type = (es_header[1] & 0x38) >> 3; fprintf(stdout, "picture coding type: %s, ", picture_coding[picture_type]); vbv_delay = ((es_header[1] & 0x07) << 13 ) | (es_header[2] << 5) | ((es_header[3] & 0xf8) >> 3) ; fprintf(stdout, "vbv delay: %u\n", vbv_delay); frames++; byte_read += fread(es_header, 1, ES_HEADER_SIZE, file_es); } else if (es_header[0] == 0x00 && es_header[1] == 0x00 && es_header[2] == 0x01 && es_header[3] == 0xB3) { /* Sequence video header */ byte_read = fread(es_header, 1, 8, file_es); horizontal_size = (es_header[0] << 4) | ((es_header[1] & 0xF0) >> 4); vertical_size = ((es_header[1] & 0x0F) << 8) | es_header[2]; aspect_ratioed = (es_header[3] & 0xF0) >> 4; frame_rated = (es_header[3] & 0x0F); fprintf(stdout, "Sequence header: format: %dx%d, %s, %sfps, ", horizontal_size, vertical_size, aspect_ratio[aspect_ratioed], frame_rate[frame_rated]); bitrated = ((es_header[4] << 10) | (es_header[5] << 2) | ((es_header[6] & 0xC0) >> 6)) * 400; if (bitrated > 1000000) { fprintf(stdout, "bitrate: %0.2fMbs, ", (float) bitrated / 1000000.0); } else if (bitrated > 1000) { fprintf(stdout, "bitrate: %0.2fKbs, ", (float) bitrated / 1000.0); } else { fprintf(stdout, "bitrate: %dbs, ", bitrated); } vbv_buffer_size = ((es_header[6] & 0x1F) << 5) | ((es_header[7] & 0xF8) >> 3); fprintf(stdout, "vbv buffer size: %d, ", vbv_buffer_size); constrained = (es_header[7] & 0x04) >> 2; fprintf(stdout, "constrained: %s\n", constrained ? "yes":"no"); if (es_header[7] & 0x02) { byte_read += fread(es_header, 1, 64, file_es); /* intra quantiser matrix */ if (es_header[63] & 0x01) { byte_read += fread(es_header, 1, 64, file_es); /* there is also non-intra quantiser matrix */ } } else if (es_header[7] & 0x01) { byte_read += fread(es_header, 1, 64, file_es); /* non-intra quantiser matrix */ } /* read next start code */ byte_read += fread(es_header, 1, ES_HEADER_SIZE, file_es); if (es_header[0] == 0x00 && es_header[1] == 0x00 && es_header[2] == 0x01 && es_header[3] == 0xB5) { /* Sequence extension */ byte_read += fread(es_header, 1, 6, file_es); fprintf(stdout, "Sequence header extension: profile is %s, level is %s\n", profile[es_header[0] & 0x07], level[(es_header[1] & 0xF0) >> 4]); byte_read += fread(es_header, 1, ES_HEADER_SIZE, file_es); } } else if (es_header[0] == 0x00 && es_header[1] == 0x00 && es_header[2] == 0x01 && es_header[3] == 0xB7) { /* Sequence End Code header */ fprintf(stdout, "Sequence End Code header\n"); byte_read = fread(es_header, 1, ES_HEADER_SIZE, file_es); } else if (es_header[0] == 0x00 && es_header[1] == 0x00 && es_header[2] == 0x01 && es_header[3] == 0xB8) { /* GOP video header */ gop_count += 1; fprintf(stdout, "GOP header: "); if (byte_count > ES_HEADER_SIZE) { fprintf(stdout, "measured size: %d bytes, ", byte_count); if ((frames * frame_sec[frame_rated]) > 0) { current_bps = (byte_count * 8) / (frames * frame_sec[frame_rated]); } fprintf(stdout, "bitrate from measured size (formula has rounds): %fbps, ", current_bps); if (current_bps > max_bps) { max_bps = current_bps; } average_bps = ((average_bps * (gop_count - 1)) + current_bps) / gop_count; byte_count = 0; frames = 0; } byte_read = fread(es_header, 1, 4, file_es); drop = ((es_header[0] & 0x80) > 0); fprintf(stdout, "drop: %s, ", drop ? "yes":"no"); hour = ((es_header[0] & 0x7C) >> 2); min = ((es_header[0] & 0x3) << 4) | ((es_header[1] & 0xF0) >> 4); sec = ((es_header[1] & 0x7) << 3) | ((es_header[2] & 0xE0) >> 5); pictures = ((es_header[2] & 0x1F) << 1) | ((es_header[3] & 0x80) >> 7); fprintf(stdout, "time code: %02d:%02d:%02d pictures:%02d, ", hour, min, sec, pictures); closed = ((es_header[3] & 0x40) > 0); fprintf(stdout, "closed: %s, ", closed ? "yes":"no"); broken = ((es_header[3] & 0x20) > 0); fprintf(stdout, "broken: %s\n", broken ? "yes":"no"); byte_read += fread(es_header, 1, ES_HEADER_SIZE, file_es); } else { es_header[0] = es_header[1]; es_header[1] = es_header[2]; es_header[2] = es_header[3]; byte_read = fread(es_header + 3, 1, 1, file_es); } } // fprintf(stdout, "maximum bit rate was:%f\n", max_bps); fprintf(stdout, "maximum frame size was:%d bytes\n", max_frame_size); // fprintf(stdout, "average bit rate is: %f\n", average_bps); return 0; } opencaster-3.2.2/tools/pes2txt/0000755000175000017500000000000012214326444015662 5ustar debiandebianopencaster-3.2.2/tools/pes2txt/Makefile0000644000175000017500000000062512214326444017325 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = pes2txt.o TARGET = pes2txt DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/pes2txt/pes2txt.c0000644000175000017500000000451112214326444017440 0ustar debiandebian/* * Copyright (C) 2008-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #include #define PES_HEADER_SIZE 4 int main(int argc, char *argv[]) { int byte_read; int first_found; FILE* file_pes; unsigned char pes_header[PES_HEADER_SIZE]; unsigned char byte; /* Open pes file */ if (argc > 1) { file_pes = fopen(argv[1], "rb"); } else { fprintf(stderr, "Usage: 'pes2txt filename.pes > txt_units'\n"); return 2; } if (file_pes == 0) { fprintf(stderr, "Can't find file %s\n", argv[1]); return 2; } /* Start to process the file */ first_found = 0; byte_read = fread(pes_header, 1, 4, file_pes); while(byte_read) { /* Skip headers */ if ((pes_header[0] == 0x00) && (pes_header[1] == 0x00) && (pes_header[2] == 0x01) && (pes_header[3] == 0xBD)) { first_found = 1; // fprintf(stderr, "header: %02x %02x %02x %02x, ", pes_header[0], pes_header[1], pes_header[2], pes_header[3]); fseek(file_pes, 4, SEEK_CUR); /* get header size */ fread(&byte, 1, 1, file_pes); // fprintf(stderr, "length: %d\n", byte); fseek(file_pes, byte + 1, SEEK_CUR); /* skip header and ebu byte*/ byte_read = fread(pes_header, 1, PES_HEADER_SIZE, file_pes); } else { if (first_found) { fwrite(pes_header, 1, 1, stdout); } pes_header[0] = pes_header[1]; pes_header[1] = pes_header[2]; pes_header[2] = pes_header[3]; byte_read = fread(pes_header+3, 1, 1, file_pes); } } fwrite(pes_header, 1, 3, stdout); return 0; } opencaster-3.2.2/tools/tsstamp/0000755000175000017500000000000012214326444015744 5ustar debiandebianopencaster-3.2.2/tools/tsstamp/Makefile0000644000175000017500000000062512214326444017407 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = tsstamp.o TARGET = tsstamp DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/tsstamp/tsstamp.c0000644000175000017500000003062612214326444017612 0ustar debiandebian/* * Copyright (C) 2004-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #define TS_HEADER_SIZE 4 #define TS_PACKET_SIZE 188 #define MAX_PID 8192 #define SYSTEM_CLOCK_FREQUENCY 27000000 #define PACK_HEADER_SIZE 4 #define TIME_STAMP_SIZE 5 const long long unsigned system_frequency = 27000000; void stamp_ts (unsigned long long int ts, unsigned char* buffer) { if (buffer) { buffer[0] = ((ts >> 29) & 0x0F) | 0x01; buffer[1] = (ts >> 22) & 0xFF; buffer[2] = ((ts >> 14) & 0xFF ) | 0x01; buffer[3] = (ts >> 7) & 0xFF; buffer[4] = ((ts << 1) & 0xFF ) | 0x01; } } unsigned long long parse_timestamp(unsigned char *buf) { unsigned long long a1; unsigned long long a2; unsigned long long a3; unsigned long long ts; a1 = (buf[0] & 0x0F) >> 1; a2 = ((buf[1] << 8) | buf[2]) >> 1; a3 = ((buf[3] << 8) | buf[4]) >> 1; ts = (a1 << 30) | (a2 << 15) | a3; return ts; } int main(int argc, char *argv[]) { int fd_ts; /* File descriptor of ts file */ u_short pid; int byte_read; int pusi = 0; int pcr_ext = 0; int ts_header_size = 0; unsigned int i; unsigned int buffer_size; unsigned char adapt = 0; unsigned char timestamp[TIME_STAMP_SIZE]; unsigned char pes_header_size = 0; unsigned char* packet_buffer; unsigned char* current_packet; unsigned long long time = 0; unsigned long long int trbits = 0; unsigned long long int pcr_base = 0; unsigned long long int ts_packet_count; unsigned long long int new_pcr = 0; unsigned long long int new_pcr_index = 0; unsigned long long int pcr_table[MAX_PID]; /* PCR table for the outgoing TS packets */ unsigned long long int pcr_index_table[MAX_PID];/* PCR index table for the TS packets */ unsigned long long int pts_table[MAX_PID]; /* PTS last value */ unsigned long long int pts_delta_table[MAX_PID]; /* PTS delta increment */ unsigned char pts_index_table[MAX_PID];/* PTS index table for the TS packets */ /* Open ts file */ buffer_size = 0; if (argc >= 3) fd_ts = open(argv[1], O_RDONLY); else { fprintf(stderr, "Usage: tsstamp input.ts transport_rate_bit/s\n"); fprintf(stderr, "N.B: this tool will change the pcr/pts/dts values to fix loop conditions and jitter after multiplexing\n"); return 2; } if (fd_ts < 0) { fprintf(stderr, "Can't find file %s\n", argv[1]); return 2; } trbits = atol(argv[2]); if (trbits == 0) { fprintf(stderr, "transport_rate is 0?\n"); return 2; } if (argv[3] != NULL) { buffer_size = atoi(argv[3]); if (buffer_size == 0) { fprintf(stderr, "buffer size is invalid\n"); return 2; } } else { buffer_size = 1; } /* Start to process the file */ buffer_size *= TS_PACKET_SIZE; packet_buffer = malloc(buffer_size); if (packet_buffer == NULL) { fprintf(stderr, "out of memory\n"); return 2; } memset(pcr_table, 0, MAX_PID*(sizeof(long long int))); memset(pcr_index_table, 0, MAX_PID*(sizeof(long long int))); memset(pts_delta_table, 0, MAX_PID*(sizeof(long long int))); memset(pts_table, 0, MAX_PID*(sizeof(long long int))); memset(pts_index_table, 0, MAX_PID*(sizeof(unsigned char))); ts_packet_count = 0; byte_read = 1; while(byte_read) { /* Read next packets */ byte_read = read(fd_ts, packet_buffer, buffer_size); for (i = 0; i < buffer_size; i += TS_PACKET_SIZE) { current_packet = packet_buffer + i; memcpy(&pid, current_packet + 1, 2); pid = ntohs(pid); pid = pid & 0x1fff; pusi = current_packet[1] & 0x40; /* Check pcr */ if ((pid < MAX_PID) && (current_packet[3] & 0x20) && (current_packet[4] != 0) && (current_packet[5] & 0x10) && pusi) { /* there is PCR */ new_pcr_index = (ts_packet_count * TS_PACKET_SIZE) + 10; if (pcr_index_table[pid] != 0) { new_pcr = new_pcr_index - pcr_index_table[pid]; new_pcr *= 8; new_pcr *= SYSTEM_CLOCK_FREQUENCY; new_pcr /= trbits; new_pcr += pcr_table[pid]; /* fprintf(stderr, "pid %d: stamping pcr %llu, pcr_delta is %llu\n", pid, new_pcr, new_pcr - pcr_table[pid]); */ /* pcr_base = ((ts_packet[6] << 25) | (ts_packet[7] << 17) | (ts_packet[8] << 9) | (ts_packet[9] << 1)) + (ts_packet[10] >> 7); pcr_ext = ((ts_packet[10] & 1) << 8) | ts_packet[11]; */ /* fprintf(stderr, "%llu: pid %d, new pcr is %llu, pcr delta is %llu, (%f ms), indices delta is %llu bytes,( %f ms), pcr accuracy is %.10f, instant ts bit rate is %.10f\n", new_pcr_index, pid, new_pcr, new_pcr - pcr_table[pid], ((double)((new_pcr - pcr_table[pid]) * 1000)) / SYSTEM_CLOCK_FREQUENCY, new_pcr_index - pcr_index_table[pid], ((double)((new_pcr_index - pcr_index_table[pid]) * 8 * 1000)) / trbits, (((double) (new_pcr - pcr_table[pid])) / SYSTEM_CLOCK_FREQUENCY) - (((double)(new_pcr_index - pcr_index_table[pid])) * 8 / trbits), (((double)(new_pcr_index - pcr_index_table[pid])) * 8 * SYSTEM_CLOCK_FREQUENCY) / ((double)(new_pcr - pcr_table[pid])) ); */ pcr_base = new_pcr / 300; pcr_ext = new_pcr % 300; current_packet[6] = (0xFF & (pcr_base >> 25)); current_packet[7] = (0xFF & (pcr_base >> 17)); current_packet[8] = (0xFF & (pcr_base >> 9)); current_packet[9] = (0xFF & (pcr_base >> 1)); current_packet[10] = ((0x1 & pcr_base) << 7) | 0x7E | ((0x100 & pcr_ext) >> 8); current_packet[11] = (0xFF & pcr_ext); pcr_table[pid] = new_pcr; } pcr_index_table[pid] = new_pcr_index; } /* check PTS and DTS */ adapt = (current_packet[3] >> 4) & 0x03; if (adapt == 0) { ts_header_size = TS_PACKET_SIZE; /* the packet is invalid ?*/ ; } else if (adapt == 1) { ts_header_size = TS_HEADER_SIZE; /* only payload */ } else if (adapt == 2) { ts_header_size = TS_PACKET_SIZE; /* only adaptation field */ } else if (adapt == 3) { ts_header_size = TS_HEADER_SIZE + current_packet[4] + 1; /* jump the adaptation field */ } else { ts_header_size = TS_PACKET_SIZE; /* not managed */ } /* check the time difference between first two pts and ... */ pes_header_size = 0; time = 0; if (ts_header_size + 20 < TS_PACKET_SIZE && pid < MAX_PID && pusi) { if ((current_packet[ts_header_size] == 0x00) && (current_packet[ts_header_size + 1] == 0x00) && (current_packet[ts_header_size + 2] == 0x01)) { pes_header_size = current_packet[ts_header_size + 8]; if ((current_packet[ts_header_size + 3] >> 4) == 0x0E) { /* PES video stream */ memcpy(timestamp, current_packet + ts_header_size + 9, TIME_STAMP_SIZE); time = parse_timestamp(timestamp); // fprintf(stderr, "Pid %d old Video Presentation Time Stamp is: %llu, %llu.%04llu sec.\n", pid, time, time / (system_frequency / 300), (time % (system_frequency / 300)) / ((system_frequency / 300) / 10000)); if (pes_header_size > 5) { memcpy(timestamp, current_packet + ts_header_size + 14, TIME_STAMP_SIZE); time = parse_timestamp(timestamp); // fprintf(stderr, "Pid %d old Video Decode Time Stamp is: %llu, %llu.%04llu sec.\n", pid, time, time / (system_frequency / 300), (time % (system_frequency / 300)) / ((system_frequency / 300) / 10000)); } if (pts_index_table[pid] == 0) { if (pes_header_size > 5) { /* if there are both dts and pts, get dts */ memcpy(timestamp, current_packet + ts_header_size + 14, TIME_STAMP_SIZE); time = parse_timestamp(timestamp); } else { /* othewise they are the same */ memcpy(timestamp, current_packet + ts_header_size + 9, TIME_STAMP_SIZE); time = parse_timestamp(timestamp); } pts_index_table[pid] = 1; pts_table[pid] = time; } else if (pts_index_table[pid] == 1) { if (pes_header_size > 5) { /* if there are both dts and pts, get dts */ memcpy(timestamp, current_packet + ts_header_size + 14, TIME_STAMP_SIZE); time = parse_timestamp(timestamp); } else { /* othewise they are the same */ memcpy(timestamp, current_packet + ts_header_size + 9, TIME_STAMP_SIZE); time = parse_timestamp(timestamp); } pts_index_table[pid] = 2; pts_delta_table[pid] = time - pts_table[pid]; pts_table[pid] = time; } else { if (pes_header_size > 5) { /* if there are both dts and pts */ memcpy(timestamp, current_packet + ts_header_size + 9, TIME_STAMP_SIZE); time = parse_timestamp(timestamp); memcpy(timestamp, current_packet + ts_header_size + 14, TIME_STAMP_SIZE); time -= parse_timestamp(timestamp); pts_table[pid] += pts_delta_table[pid]; /* dts goes up 1 step */ stamp_ts(pts_table[pid], current_packet + ts_header_size + 14); current_packet[ts_header_size + 14] &= 0x0F; current_packet[ts_header_size + 14] |= 0x10; /* pts goes up the same gap there was before */ stamp_ts(pts_table[pid] + time, current_packet + ts_header_size + 9); current_packet[ts_header_size + 9] &= 0x0F; current_packet[ts_header_size + 9] |= 0x30; } else { pts_table[pid] += pts_delta_table[pid]; stamp_ts(pts_table[pid], current_packet + ts_header_size + 9); current_packet[ts_header_size + 9] &= 0x0F; current_packet[ts_header_size + 9] |= 0x20; } } memcpy(timestamp, current_packet + ts_header_size + 9, TIME_STAMP_SIZE); time = parse_timestamp(timestamp); // fprintf(stderr, "Pid %d new Video Presentation Time Stamp is: %llu, %llu.%04llu sec.\n", pid, time, time / (system_frequency / 300), (time % (system_frequency / 300)) / ((system_frequency / 300) / 10000)); if (pes_header_size > 5) { memcpy(timestamp, current_packet + ts_header_size + 14, TIME_STAMP_SIZE); time = parse_timestamp(timestamp); // fprintf(stderr, "Pid %d new Video Decode Time Stamp is: %llu, %llu.%04llu sec.\n", pid, time, time / (system_frequency / 300), (time % (system_frequency / 300)) / ((system_frequency / 300) / 10000)); } } else if (((current_packet[ts_header_size + 3] >> 5) == 0x05) || ((current_packet[ts_header_size + 3] >> 5) == 0x06) ) { /* PES audio stream */ memcpy(timestamp, current_packet + ts_header_size + 9, TIME_STAMP_SIZE); time = parse_timestamp(timestamp); // fprintf(stderr, "Pid %d old Audio Presentation Time Stamp is: %llu, %llu.%04llu sec.\n", pid, time, time / (system_frequency / 300), (time % (system_frequency / 300)) / ((system_frequency / 300) / 10000)); if (pts_index_table[pid] == 0) { pts_index_table[pid] = 1; memcpy(timestamp, current_packet + ts_header_size + 9, TIME_STAMP_SIZE); time = parse_timestamp(timestamp); pts_table[pid] = time; } else if (pts_index_table[pid] == 1) { pts_index_table[pid] = 2; memcpy(timestamp, current_packet + ts_header_size + 9, TIME_STAMP_SIZE); time = parse_timestamp(timestamp); pts_delta_table[pid] = time - pts_table[pid]; pts_table[pid] = time; } else { pts_table[pid] += pts_delta_table[pid]; stamp_ts(pts_table[pid], current_packet + ts_header_size + 9); current_packet[ts_header_size + 9] &= 0x0F; current_packet[ts_header_size + 9] |= 0x20; } memcpy(timestamp, current_packet + ts_header_size + 9, TIME_STAMP_SIZE); time = parse_timestamp(timestamp); // fprintf(stderr, "Pid %d new Audio Presentation Time Stamp is: %llu, %llu.%04llu sec.\n", pid, time, time / (system_frequency / 300), (time % (system_frequency / 300)) / ((system_frequency / 300) / 10000)); } } } ts_packet_count++; } /* write packets out */ write(STDOUT_FILENO, packet_buffer, buffer_size); } return 0; } opencaster-3.2.2/tools/tsccc/0000755000175000017500000000000012214326444015350 5ustar debiandebianopencaster-3.2.2/tools/tsccc/Makefile0000755000175000017500000000062112214326444017012 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = tsccc.o TARGET = tsccc DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/tsccc/tsccc.c0000644000175000017500000000601612214326444016616 0ustar debiandebian/* * Copyright (C) 2009-2013 Lorenzo Pallara, lpallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #define TS_PACKET_SIZE 188 #define MAX_PID 8191 int main(int argc, char *argv[]) { int open_file; int byte_read; int fd_ts; /* File descriptor of ts file */ unsigned short pid; unsigned int adaptation_field; unsigned char packet[TS_PACKET_SIZE]; unsigned char pid_cc_table[MAX_PID]; /* PID table for the continuity counter of the TS packets */ unsigned char repeated_cc_table[MAX_PID]; unsigned long long position = 0; /* Open first ts file */ if (argc >= 2) { open_file = 1; fd_ts = open(argv[open_file], O_RDONLY); if (fd_ts < 0) { fprintf(stderr, "Can't find file %s\n", argv[open_file]); return 2; } } else { fprintf(stderr, "Usage: 'tsccc filename.ts '\n"); fprintf(stderr, "Tsccc check continuity counter errors and warnings\n"); return 2; } /* Start to process the file */ memset(pid_cc_table, 0x10, MAX_PID); memset(repeated_cc_table, 0, MAX_PID); while(1) { /* read packets */ byte_read = 0; byte_read = read(fd_ts, packet, TS_PACKET_SIZE); if (byte_read < TS_PACKET_SIZE) { return 0; } /* check cc */ memcpy(&pid, packet + 1, 2); pid = ntohs(pid); pid = pid & 0x1fff; if (pid < MAX_PID) { adaptation_field = (packet[3] & 0x30) >> 4; if (pid_cc_table[pid] == 0x10) { fprintf(stderr, "new pid entry %d\n", pid); } else { if (((pid_cc_table[pid] + 1) % 16) != (packet[3] & 0xF)) { if (adaptation_field == 0x0 || adaptation_field == 0x2) { /* reserved, no increment */ ; } else if ((adaptation_field == 0x1) && ((packet[3] & 0x0f) == pid_cc_table[pid]) && (!repeated_cc_table[pid])) { /* double packet accepted only once */ repeated_cc_table[pid] = 1; } else if ((adaptation_field == 0x3) && ((packet[3] & 0x0f) == pid_cc_table[pid]) && (!repeated_cc_table[pid])) { /* double packet accepted only once */ repeated_cc_table[pid] = 1; } else { fprintf(stdout, "cc warning at pid %d packet: %llu, expected %d, found %d\n", pid, position, ((pid_cc_table[pid] + 1) % 0xF), (packet[3] & 0xF)); } } } pid_cc_table[pid] = packet[3] & 0xF; } position++; } } opencaster-3.2.2/tools/tspcrstamp/0000755000175000017500000000000012214326444016451 5ustar debiandebianopencaster-3.2.2/tools/tspcrstamp/Makefile0000644000175000017500000000063312214326444020113 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = tspcrstamp.o TARGET = tspcrstamp DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/tspcrstamp/tspcrstamp.c0000644000175000017500000001346012214326444021021 0ustar debiandebian/* * Copyright (C) 2008-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #define TS_HEADER_SIZE 4 #define TS_PACKET_SIZE 188 #define MAX_PID 8192 #define SYSTEM_CLOCK_FREQUENCY 27000000 void stamp_ts (unsigned long long int ts, unsigned char* buffer) { if (buffer) { buffer[0] = ((ts >> 29) & 0x0F) | 0x01; buffer[1] = (ts >> 22) & 0xFF; buffer[2] = ((ts >> 14) & 0xFF ) | 0x01; buffer[3] = (ts >> 7) & 0xFF; buffer[4] = ((ts << 1) & 0xFF ) | 0x01; } } unsigned long long parse_timestamp(unsigned char *buf) { unsigned long long a1; unsigned long long a2; unsigned long long a3; unsigned long long ts; a1 = (buf[0] & 0x0F) >> 1; a2 = ((buf[1] << 8) | buf[2]) >> 1; a3 = ((buf[3] << 8) | buf[4]) >> 1; ts = (a1 << 30) | (a2 << 15) | a3; return ts; } int main(int argc, char *argv[]) { int fd_ts; /* File descriptor of ts file */ u_short pid; int byte_read; int pcr_ext = 0; unsigned int i; /* unsigned int j; */ unsigned int buffer_size; unsigned char* packet_buffer; unsigned char* current_packet; unsigned long long int trbits = 0; unsigned long long int pcr_base = 0; unsigned long long int ts_packet_count; unsigned long long int new_pcr = 0; unsigned long long int new_pcr_module = 0; unsigned long long int pcr_index_rounding = 0; unsigned long long int pcr_table[MAX_PID]; /* PCR table for the outgoing TS packets */ unsigned long long int pcr_index_table[MAX_PID];/* PCR index table for the TS packets */ /* Open ts file */ buffer_size = 0; if (argc >= 3) fd_ts = open(argv[1], O_RDONLY); else { fprintf(stderr, "Usage: tspcrstamp input.ts transport_rate_bit/s\n"); fprintf(stderr, "N.B: this tool will change the pcr values to fix jitter after multiplexing\n"); return 2; } if (fd_ts < 0) { fprintf(stderr, "Can't find file %s\n", argv[1]); return 2; } trbits = atol(argv[2]); if (trbits == 0) { fprintf(stderr, "transport_rate is 0?\n"); return 2; } if (argv[3] != NULL) { buffer_size = atoi(argv[3]); if (buffer_size == 0) { fprintf(stderr, "buffer size is invalid\n"); return 2; } } else { buffer_size = 1; } /* Start to process the file */ buffer_size *= TS_PACKET_SIZE; packet_buffer = malloc(buffer_size); if (packet_buffer == NULL) { fprintf(stderr, "out of memory\n"); return 2; } memset(pcr_table, 0ll, MAX_PID*(sizeof(unsigned long long int))); memset(pcr_index_table, 0ll, MAX_PID*(sizeof(unsigned long long int))); ts_packet_count = 0; //pcr_index_rounding = 2576980370000ll; pcr_index_rounding = 0ll; byte_read = 1; while(byte_read) { /* Read next packets */ byte_read = read(fd_ts, packet_buffer, buffer_size); for (i = 0; i < buffer_size; i += TS_PACKET_SIZE) { current_packet = packet_buffer + i; memcpy(&pid, current_packet + 1, 2); pid = ntohs(pid); pid = pid & 0x1fff; /* Check pcr */ if ((pid < MAX_PID) && (current_packet[3] & 0x20) && (current_packet[4] != 0) && (current_packet[5] & 0x10)) { /* there is PCR */ new_pcr = (ts_packet_count * TS_PACKET_SIZE) + 10; /* ts position in byte */ new_pcr *= 8; /* bits */ new_pcr *= SYSTEM_CLOCK_FREQUENCY; new_pcr /= trbits; new_pcr += pcr_index_rounding; new_pcr_module = new_pcr % 2576980377600ll; pcr_base = new_pcr_module / 300; pcr_ext = new_pcr_module % 300; current_packet[6] = (0xFF & (pcr_base >> 25)); current_packet[7] = (0xFF & (pcr_base >> 17)); current_packet[8] = (0xFF & (pcr_base >> 9)); current_packet[9] = (0xFF & (pcr_base >> 1)); current_packet[10] = ((0x1 & pcr_base) << 7) | 0x7E | ((0x100 & pcr_ext) >> 8); current_packet[11] = (0xFF & pcr_ext); /* max packet count = 454263790 */ /* multiplication will overflown but sum won't because is after div */ /* ((454263790 * 188) + 10) * 8 * 27000000 < 2^64 */ if (ts_packet_count * 2 >= 454263790) { ts_packet_count = 0; pcr_index_rounding = new_pcr; } /* 2^33 * 300 = 2576980377600 / 27000000 < 95444 secs at 100Mbps are < 6346010639 packets < 2^64 ts_packet_counter */ if (new_pcr >= 2576980377600ll ) { ts_packet_count = 0; pcr_index_rounding = (new_pcr - 2576980377600ll); } } /* if (((ts_packet_count + 1) * TS_PACKET_SIZE) + 10 < ts_packet_count) { unsigned long long int min = 0ll; for (j = 0; j < MAX_PID; j++) { if (pcr_index_table[pid] > 0 && min == 0) { min = pcr_index_table[pid]; } else if (pcr_index_table[pid] > 0 && pcr_index_table[pid] < min) { min = pcr_index_table[pid]; } } unsigned long long int ts_packet_delta = (min - 10) / TS_PACKET_SIZE; ts_packet_count -= ts_packet_delta; for (j = 0; j < MAX_PID; j++) { pcr_index_table[pid] -= ts_packet_delta; pcr_table[pid] = pcr_index_table[pid] * 8 * SYSTEM_CLOCK_FREQUENCY / trbits; } } */ ts_packet_count++; } /* write packets out */ write(STDOUT_FILENO, packet_buffer, buffer_size); } return 0; } opencaster-3.2.2/tools/pes2es/0000755000175000017500000000000012214326444015452 5ustar debiandebianopencaster-3.2.2/tools/pes2es/Makefile0000644000175000017500000000062312214326444017113 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = pes2es.o TARGET = pes2es DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/pes2es/pes2es.c0000644000175000017500000000534012214326444017021 0ustar debiandebian/* * Copyright (C) 2004-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #include #define PES_HEADER_SIZE 4 int main(int argc, char *argv[]) { int byte_read; int first_found; unsigned char stream_id; FILE* file_pes; unsigned char pes_header[PES_HEADER_SIZE]; unsigned char byte; unsigned char length; /* Open pes file */ if (argc > 2) { file_pes = fopen(argv[1], "rb"); stream_id = atoi(argv[2]); } else { fprintf(stderr, "Usage: 'pes2es filename.pes stream_id_header_to_skip'\n"); fprintf(stderr, "Example for audio: 'pes2es filename.pes 192', 192 is 0xc0 \n"); fprintf(stderr, "Example for video: 'pes2es filename.pes 224', 224 is 0xe0\n"); return 2; } if (file_pes == 0) { fprintf(stderr, "Can't find file %s\n", argv[1]); return 2; } /* Start to process the file */ first_found = 0; byte_read = fread(pes_header, 1, 4, file_pes); while(byte_read) { /* Skip headers */ if ((pes_header[0] == 0x00) && (pes_header[1] == 0x00) && (pes_header[2] == 0x01) && (pes_header[3] == stream_id)) { first_found = 1; // fprintf(stderr, "header: %02x %02x %02x %02x, ", pes_header[0], pes_header[1], pes_header[2], pes_header[3]); // fseek(file_pes, 4, SEEK_CUR); /* get header size */ int i = 0; for (i = 0; i < 4; i++) { fread(&byte, 1, 1, file_pes); } fread(&length, 1, 1, file_pes); // fprintf(stderr, "length: %d\n", byte); // fseek(file_pes, byte, SEEK_CUR); /* skip header */ for (i = 0; i < length; i++) { fread(&byte, 1, 1, file_pes); } byte_read = fread(pes_header, 1, PES_HEADER_SIZE, file_pes); } else { if (first_found) { fwrite(pes_header, 1, 1, stdout); } pes_header[0] = pes_header[1]; pes_header[1] = pes_header[2]; pes_header[2] = pes_header[3]; byte_read = fread(pes_header+3, 1, 1, file_pes); } } fwrite(pes_header, 1, 3, stdout); return 0; } opencaster-3.2.2/tools/tsmodder/0000755000175000017500000000000012214326444016072 5ustar debiandebianopencaster-3.2.2/tools/tsmodder/tsmodder.c0000644000175000017500000001155212214326444020063 0ustar debiandebian/* * Copyright (C) 2004-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #define TS_PACKET_SIZE 188 #define MAX_PID 8192 void Usage (void) { fprintf(stderr, "Usage: 'tsmodder input.ts [b:buffer_size] +0 pat.ts +pid pmt.ts +pid nit.ts ... '\n"); fprintf(stderr, "'+pid file.ts' change the packets with 'pid' with the packets from the file.ts\n"); fprintf(stderr, "'b:buffer_size' set size of the internal buffer to many packets as buffer_size\n"); } int main(int argc, char *argv[]) { unsigned int i; u_short pid; int input_read; int buffer_size; int fd_ts; /* File descriptor of ts input file */ unsigned char* packet_buffer; unsigned char* current_packet; unsigned char adaptation_field; int pid_table[MAX_PID]; char* pid_table_filename[MAX_PID]; unsigned char pid_cc_table[MAX_PID]; /* PID table for the continuity counter of the TS packets */ unsigned char previous_cc_table[MAX_PID]; /* two packets can have the same continuity counter under some conditions... */ int byte_read; /* Open ts files */ for (i = 0; i < MAX_PID; i++) { pid_table[i] = -1; pid_table_filename[i] = 0; } memset(pid_cc_table, 0x10, MAX_PID); memset(previous_cc_table, 0x10, MAX_PID); if (argc <= 2) { Usage(); return 2; } fd_ts = open(argv[1], O_RDONLY); if (fd_ts < 0) { fprintf(stderr, "Can't find file %s\n", argv[1]); return 2; } buffer_size = 0; i = 2; while (i> 4; if (adaptation_field == 0x0 || adaptation_field == 0x2) { /* reserved, no increment */ current_packet[3] = (pid_cc_table[pid] | (current_packet[3] & 0xf0)); } else if ((adaptation_field == 0x1) && ((current_packet[3] & 0x0f) == previous_cc_table[pid])) { /* double packet accepted only once */ current_packet[3] = (pid_cc_table[pid] | (current_packet[3] & 0xf0)); previous_cc_table[pid] = 0x10; } else if ((adaptation_field == 0x3) && ((current_packet[3] & 0x0f) == previous_cc_table[pid])) { /* double packet accepted only once */ current_packet[3] = (pid_cc_table[pid] | (current_packet[3] & 0xf0)); previous_cc_table[pid] = 0x10; } else { /* increase the cc and restamp */ previous_cc_table[pid] = current_packet[3] & 0x0f; pid_cc_table[pid] = (pid_cc_table[pid] + 1) % 0x10; current_packet[3] = (pid_cc_table[pid] | (current_packet[3] & 0xf0)); } } } } /* Write packets */ if (input_read) { write(STDOUT_FILENO, packet_buffer, buffer_size); } } return 0; } opencaster-3.2.2/tools/tsmodder/Makefile0000644000175000017500000000062712214326444017537 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = tsmodder.o TARGET = tsmodder DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/ts2sec/0000755000175000017500000000000012214326443015453 5ustar debiandebianopencaster-3.2.2/tools/ts2sec/ts2sec.c0000644000175000017500000001461112214326443017025 0ustar debiandebian/* * Copyright (C) 2008-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. * Last modification : * Frederic Delagree, Frederic.delagree@orange.com, 4 April 2012 * Take into account the value of pointer_field value into section. */ #include #include #include #include #include #include #include #include #define TS_PACKET_SIZE 188 #define MAX_TABLE_LEN 4096 #define MAX_PID 8192 #define SECTION_HEADER_SIZE 3 #include "../../libs/sectioncrc/sectioncrc.c" unsigned char section[MAX_TABLE_LEN]; int section_len = 0; /* use this to output sections with padding for test and development void add_payload(unsigned char* buffer, int size) { write(STDOUT_FILENO, buffer, size); } */ void add_payload(unsigned char* buffer, int size) { unsigned short section_header_len = 0; unsigned int payload = 0; unsigned int crc = 0; int written = 0; while (size > 0) { while (section_len < SECTION_HEADER_SIZE) { /* current section is without a complete header */ /* get header bytes */ section[section_len] = buffer[0]; section_len += 1; buffer += 1; size -= 1; /* check if it is header or padding */ if (section_len == SECTION_HEADER_SIZE) { if(section[0] == 0xFF) { section[0] = section[1]; section[1] = section[2]; section_len = 2; } } /* chek if there is more payload */ if (size <= 0) { return; } } /* get section size from the header */ memcpy(§ion_header_len, section + 1, 2); section_header_len = ntohs(section_header_len); section_header_len &= 0x0FFF; section_header_len += SECTION_HEADER_SIZE; /* add payload without padding */ if (section_header_len - section_len >= size) { payload = size; } else { payload = section_header_len - section_len; } memcpy(section + section_len, buffer, payload); section_len += payload; buffer+= payload; size -= payload; /* output the section only if completed */ if (section_len == section_header_len) { if (section_len >= 4) { crc = sectioncrc(section, section_len - 4); if ( (section[section_len - 4] == ((crc >> 24) & 0xFF)) && (section[section_len - 3] == ((crc >> 16) & 0xFF)) && (section[section_len - 2] == ((crc >> 8) & 0xFF)) && (section[section_len - 1] == (crc & 0xFF)) ) { written = write(STDOUT_FILENO, section, section_len); if (written != section_len ) { fprintf(stderr, "warning: written %d bytes instead of %d\n", written, section_len); } } else { fprintf(stderr, "crc failed: %x %x %x %x %x %x %x %x\n", section[section_len - 4], ((crc >> 24) & 0xFF), section[section_len - 3], ((crc >> 16) & 0xFF), section[section_len - 2], ((crc >> 8) & 0xFF), section[section_len - 1], (crc & 0xFF) ); } section_len = 0; } else { section_len = 0; size = 0; } } } } int main(int argc, char *argv[]) { int byte_read; int fd_ts; /* File descriptor of ts file */ int ts_header_size; unsigned char adapt_field; unsigned short pid; unsigned short payload_pid; unsigned char current_packet[TS_PACKET_SIZE]; int pusi = 0; /* Open ts file */ if (argc >= 3) { fd_ts = open(argv[1], O_RDONLY); payload_pid = atoi(argv[2]); } else { fprintf(stderr, "Usage: 'ts2sec filename.ts payload_pid > sections'\n"); fprintf(stderr, "the tool manages corrupted ts, only complete sections are output\n"); return 2; } if (fd_ts < 0) { fprintf(stderr, "Can't find file %s\n", argv[1]); return 2; } if (payload_pid > MAX_PID-2) { fprintf(stderr, "Invalid PID, range is [0..8190]\n"); } /* Start to process the file */ byte_read = 1; while(byte_read) { /* read a ts packet */ byte_read = read(fd_ts, current_packet, TS_PACKET_SIZE); /* check packet pid */ memcpy(&pid, current_packet + 1, 2); pid = ntohs(pid); pid = pid & 0x1fff; if (pid == payload_pid && byte_read > 0) { /* got the pid we are looking for */ /* check for sync byte */ if (current_packet[0] != 0x47) { fprintf(stderr, "missing sync byte, quitting\n"); return 0; } /* check for pusi */ pusi = (current_packet[1] & 0x40); /* check adaptation field size */ ts_header_size = 4; adapt_field = (current_packet[3] >> 4) & 0x03; if (adapt_field == 0) { ts_header_size = TS_PACKET_SIZE; /* jump the packet, is invalid ? */ fprintf(stderr, "invalid packet!\n"); } else if (adapt_field == 1) { /* fprintf(stderr, "regular case\n"); */ ; /* regular case */ } else if (adapt_field == 2) { /* fprintf(stderr, "adapt_field == 2\n"); */ ts_header_size = TS_PACKET_SIZE; /* this packet has only adaptation field */ /* fprintf(stderr, "adapatation field only?\n"); */ } else if (adapt_field == 3) { /* fprintf(stderr, "adapt_field == 3\n"); */ ts_header_size += current_packet[ts_header_size] + 1; /* fprintf(stderr, "adaptation field shouldn't be set for sections\n"); */ } if (ts_header_size < TS_PACKET_SIZE) { if (pusi) { /* fprintf(stderr, "new section, payload starts at %d,tid=%d\n", current_packet[ts_header_size],current_packet[ts_header_size+current_packet[ts_header_size]+1]); */ if (current_packet[ts_header_size] > 0 ) add_payload(current_packet + ts_header_size+1, current_packet[ts_header_size] ); add_payload(current_packet + ts_header_size + 1 +current_packet[ts_header_size], TS_PACKET_SIZE - ts_header_size - 1 -current_packet[ts_header_size]); /* add_payload(current_packet + ts_header_size + 1, TS_PACKET_SIZE - ts_header_size - 1); */ } else { add_payload(current_packet + ts_header_size, TS_PACKET_SIZE - ts_header_size); } } } } return 0; } opencaster-3.2.2/tools/ts2sec/Makefile0000644000175000017500000000062312214326443017114 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = ts2sec.o TARGET = ts2sec DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/tstcpsend/0000755000175000017500000000000012214326443016257 5ustar debiandebianopencaster-3.2.2/tools/tstcpsend/Makefile0000644000175000017500000000063612214326443017724 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc -lrt OBJS = tstcpsend.o TARGET = tstcpsend DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/tstcpsend/tstcpsend.c0000644000175000017500000001153512214326443020437 0ustar debiandebian/* * Copyright (C) 2009-2013, Lorenzo Pallara l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include #include #include #include #define TS_PACKET_SIZE 188 long long int usecDiff(struct timespec* time_stop, struct timespec* time_start) { long long int temp = 0; long long int utemp = 0; if (time_stop && time_start) { if (time_stop->tv_nsec >= time_start->tv_nsec) { utemp = time_stop->tv_nsec - time_start->tv_nsec; temp = time_stop->tv_sec - time_start->tv_sec; } else { utemp = time_stop->tv_nsec + 1000000000 - time_start->tv_nsec; temp = time_stop->tv_sec - 1 - time_start->tv_sec; } if (temp >= 0 && utemp >= 0) { temp = (temp * 1000000000) + utemp; } else { fprintf(stderr, "start time %ld.%ld is after stop time %ld.%ld\n", time_start->tv_sec, time_start->tv_nsec, time_stop->tv_sec, time_stop->tv_nsec); temp = -1; } } else { fprintf(stderr, "memory is garbaged?\n"); temp = -1; } return temp / 1000; } int main (int argc, char *argv[]) { int sockfd; int len; int rc; int sent; int transport_fd; struct sockaddr_in addr; unsigned long int packet_size; char* tsfile; unsigned char* send_buf; unsigned int bitrate; unsigned long long int packet_time; unsigned long long int real_time; struct timespec time_start; struct timespec time_stop; struct timespec nano_sleep_packet; memset(&addr, 0, sizeof(addr)); memset(&time_start, 0, sizeof(time_start)); memset(&time_stop, 0, sizeof(time_stop)); memset(&nano_sleep_packet, 0, sizeof(nano_sleep_packet)); if(argc < 5 ) { fprintf(stderr, "Usage: %s file.ts ipaddr port bitrate [ts_packet_per_ip_packet]\n", argv[0]); fprintf(stderr, "ts_packet_per_ip_packet default is 7\n"); fprintf(stderr, "bit rate refers to transport stream bit rate\n"); fprintf(stderr, "zero bitrate is 100.000.000 bps\n"); return 0; } else { tsfile = argv[1]; addr.sin_family = AF_INET; addr.sin_addr.s_addr = inet_addr(argv[2]); addr.sin_port = htons(atoi(argv[3])); bitrate = atoi(argv[4]); if (bitrate <= 0) { bitrate = 100000000; } if (argc >= 6) { packet_size = strtoul(argv[5], 0, 0) * TS_PACKET_SIZE; } else { packet_size = 7 * TS_PACKET_SIZE; } } sockfd = socket(AF_INET, SOCK_STREAM, 0); if(sockfd < 0) { fprintf(stderr, "socket(): error "); return 0; } transport_fd = open(tsfile, O_RDONLY); if(transport_fd < 0) { fprintf(stderr, "can't open file %s\n", tsfile); close(sockfd); return 0; } rc = connect(sockfd, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)); if(rc < 0) { fprintf(stderr, "connect() error\n"); close(transport_fd); close(sockfd); return 0; } else { fprintf(stderr, "connect successful\n"); } int completed = 0; send_buf = malloc(packet_size); packet_time = 0; real_time = 0; nano_sleep_packet.tv_nsec = 665778; /* 1 packet at 100mbps*/ clock_gettime(CLOCK_MONOTONIC, &time_start); while (!completed) { clock_gettime(CLOCK_MONOTONIC, &time_stop); real_time = usecDiff(&time_stop, &time_start); if (real_time * bitrate > packet_time * 1000000) { /* theorical bits against sent bits */ len = read(transport_fd, send_buf, packet_size); if(len < 0) { fprintf(stderr, "ts file read error \n"); completed = 1; } else if (len == 0) { fprintf(stderr, "ts sent done\n"); completed = 1; } else { sent = send(sockfd, send_buf, len, 0); /* write(STDOUT_FILENO, send_buf, len); */ if(sent <= 0) { fprintf(stderr, "send(): error "); completed = 1; } else { /* if (sent != len) { fprintf(stderr, "sent failed to send the whole packet, sent %d bytes\n", sent); } */ packet_time += packet_size * 8; } } } else { nanosleep(&nano_sleep_packet, 0); } } close(transport_fd); close(sockfd); free(send_buf); return 0; } opencaster-3.2.2/tools/tsoutputswitch/0000755000175000017500000000000012232257151017400 5ustar debiandebianopencaster-3.2.2/tools/tsoutputswitch/Makefile0000644000175000017500000000064312214326444021045 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = tsoutputswitch.o TARGET = tsoutputswitch DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/tsoutputswitch/tsoutputswitch.c0000644000175000017500000001031412232257151022674 0ustar debiandebian/* * Copyright (C) 2008-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #define MULTICAST #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define TS_PACKET_SIZE 188 int main(int argc, char *argv[]) { int input_file; int output_file1; int output_file2; int byte_read; unsigned char choice; int port; unsigned char packet[TS_PACKET_SIZE]; if (argc >= 5) { input_file = open(argv[1], O_RDONLY); if (input_file < 0) { fprintf(stderr, "Can't open file %s\n", argv[1]); return 0; } output_file1 = open(argv[2], O_WRONLY); if (output_file1 < 0) { fprintf(stderr, "Can't open file %s\n", argv[2]); return 0; } output_file2 = open(argv[3], O_WRONLY); if (output_file2 < 0) { fprintf(stderr, "Can't open file %s\n", argv[3]); return 0; } port = atoi(argv[4]); if (port < 0) { fprintf(stderr, "Can't open port %s\n", argv[4]); return 0; } } else { fprintf(stderr, "Usage: 'tsoutputswitch inputfile.ts outputfile1.ts outputfile2.ts port'\n"); fprintf(stderr, "0 output on outputfile1 \n"); fprintf(stderr, "1 output on outputfile2 \n"); fprintf(stderr, "2 output on both \n"); fprintf(stderr, "N.B. if they are not fifo the file size will increase\n"); fprintf(stderr, "Default is 0\n"); return 0; } int listen_sd; listen_sd = socket(AF_INET, SOCK_DGRAM, 0); if(listen_sd < 0) { fprintf(stderr, "secsocket - socket() error\n"); exit(-1); } else { fprintf(stderr, "secsocket - socket() is OK\n"); } int flags; flags = fcntl(listen_sd,F_GETFL,0); fcntl(listen_sd, F_SETFL, flags | O_NONBLOCK); int reuse = 1; if (setsockopt(listen_sd, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse, sizeof(reuse)) < 0) { fprintf(stderr, "setting SO_REUSEADDR failed\n"); close(listen_sd); exit(-1); } struct sockaddr_in addr; memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = INADDR_ANY; addr.sin_port = htons(port); int result = bind(listen_sd, (struct sockaddr *)&addr, sizeof(addr)); if(result < 0) { fprintf(stderr, "secsocket - bind() error\n"); close(listen_sd); exit(-1); } else { // fprintf(stderr, "secsocket - bind() is OK\n"); } byte_read = 1; choice = 0; int new_choice = 0; unsigned char received = 0; while(byte_read) { if (recv(listen_sd, &received, 1, 0) > 0) { fprintf (stderr, "received %d\n", received - 48); new_choice = received - 48; } byte_read = read(input_file, packet, TS_PACKET_SIZE); if (byte_read > 0) { if (new_choice != choice) { close(output_file1); output_file1 = open(argv[2], O_WRONLY); if (output_file1 < 0) { fprintf(stderr, "Can't open file %s\n", argv[2]); return 0; } close(output_file2); output_file2 = open(argv[3], O_WRONLY); if (output_file2 < 0) { fprintf(stderr, "Can't open file %s\n", argv[3]); return 0; } choice = new_choice; } if (choice == 0 || choice == 2) { write(output_file1, packet, TS_PACKET_SIZE); } if (choice == 1 || choice == 2) { write(output_file2, packet, TS_PACKET_SIZE); } } } close(input_file); close(output_file1); close(output_file2); close(listen_sd); return 0; } opencaster-3.2.2/tools/sec2ts/0000755000175000017500000000000012214326444015454 5ustar debiandebianopencaster-3.2.2/tools/sec2ts/Makefile0000644000175000017500000000062312214326444017115 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = sec2ts.o TARGET = sec2ts DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/sec2ts/sec2ts.c0000644000175000017500000002025312214326444017025 0ustar debiandebian/* * Copyright (C) 2004-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. * * Stuff option added by julian.cable@bbc.co.uk * and by Guislain Bonnard guislain.bonnard@quadrille.fr> * */ #define _BSD_SOURCE 1 #include #include #include #include #include #include #include #include #include #include #include #include #define DEFAULT_PID 0x200 #define TS_HEADER_MAX_SIZE 5 #define TS_PACKET_SIZE 188 #define SECTION_MAX_SIZE 4096 #define SECTION_HEADER_SIZE 3 u_char g_section[SECTION_MAX_SIZE+1]; /* +1 to handle a special case, see later in the code */ u_char g_section_head[SECTION_HEADER_SIZE]; u_short stuff = 0; u_char* get_section(u_short* section_size, int fd) { u_short temp = 0; u_char* section = 0; if (section_size) { /* Read first bytes */ *section_size = 0; if (read(fd, g_section_head, SECTION_HEADER_SIZE)) { /* Parse datagram section size */ memcpy(&temp, g_section_head + 1, 2); temp = ntohs(temp); temp &= 0x0FFF; *section_size = temp; /* Read all the section */ if (*section_size <= (SECTION_MAX_SIZE - SECTION_HEADER_SIZE)) { memcpy(g_section, g_section_head, SECTION_HEADER_SIZE); read(fd, g_section + SECTION_HEADER_SIZE, *section_size); section = g_section; *section_size += SECTION_HEADER_SIZE; /* now see if we should add stuffing */ if (stuff) { u_short residue = *section_size % 184; /* first TS packet has one octet of overhead */ if(residue != 183) { u_short num_stuff_octets = 183 - residue; u_char* stuff_ptr = &g_section[*section_size]; memset(stuff_ptr, 0xff, num_stuff_octets); *section_size += num_stuff_octets; } } } else { fprintf(stderr, "Section too big skipped\n"); } } else { fprintf(stderr, "No more sections\n"); } } return section; } int main(int argc, char *argv[]) { int not_finished; int fd_in; FILE* fd_out; int ts_bytes; /* TS packet output counter */ int section_bytes; /* Section output counter */ int ts_needtopad; /* Set if necessary to pad to end a packet */ int ts_padded_did_not_output_next_header; /* Set if packet header wasn't written after padding */ u_short pid; /* Pid for the TS packets */ u_short temp; /* Temp */ u_short section_size; /* Section size */ u_short section_size_next; /* Section size next section */ u_char *section_next; /* Next section */ u_char *section; /* Current section */ u_char ts_header[TS_HEADER_MAX_SIZE]; /* TS packet header */ u_char section_memory[SECTION_MAX_SIZE + 1]; /* Current section body */ u_char ts_header_size; /* Current size of the ts header */ u_char ts_continuity_counter; /* Continuity counter */ /* Set pid and fd */ fd_in = STDIN_FILENO; fd_out = stdout; if (argc > 1) { if (argc > 2) { if(strcmp(argv[2], "-s") == 0) { stuff = 1; } } pid = atoi(argv[1]); if (pid < 8192) { pid = htons(pid); } else { fprintf(stdout, "Usage: 'sec2ts pid [-s]', where pid is bounded from 1 to 8191 and as default is %d\n", DEFAULT_PID); fprintf(stdout, "-s tells sec2ts to start sections on TS packet boundaries\n"); fprintf(stdout, "Sections come from stdin and ts packets will go out from stdout.\n"); return 2; } } else { pid = htons(DEFAULT_PID); } /* Set TS packet fixed header byte */ ts_header[0] = 0x47; /* sync byte */ ts_continuity_counter = 0x0; ts_bytes = 0; section = 0; section_next = 0; ts_needtopad = 0; ts_padded_did_not_output_next_header = 0; /* Write the first TS valid packet header */ memcpy(ts_header + 1, &pid, 2); /* pid */ ts_header[1] |= 0x40; /* payload unit start indicator */ ts_header[3] = ts_continuity_counter | 0x10; /* continuity counter, no scrambling, only payload */ ts_continuity_counter = (ts_continuity_counter + 1) % 0x10; /* inc. continuity counter */ ts_header[4] = 0x0; /* point field */ ts_header_size = TS_HEADER_MAX_SIZE; fwrite(ts_header, 1, ts_header_size, fd_out); ts_bytes = ts_header_size; /* Start to process sections */ not_finished = 1; if(stuff){ section_next = 1; } else { section_next = get_section(§ion_size_next, fd_in); } while (not_finished) { if (section_next != 0 && !stuff) { memcpy(section_memory, section_next, SECTION_MAX_SIZE + 1); section = section_memory; section_size = section_size_next; section_next = get_section(§ion_size_next, fd_in); } else if(section_next != 0 && stuff) { section = get_section(§ion_size, fd_in); } else { section = 0; section_size = 0; section_next = 0; section_size_next = 0; } /* Pack the section */ if (section) { if (ts_padded_did_not_output_next_header) { fwrite(ts_header, 1, ts_header_size, fd_out); ts_bytes = ts_header_size; ts_padded_did_not_output_next_header = 0; } /* Check if padding is necessary */ if (TS_PACKET_SIZE - ts_bytes > section_size) { ts_needtopad = 1; } /* Output is section framed in TS packets */ section_bytes = 0; while (section_bytes < section_size ) { if (section_bytes < section_size) { for (; ts_bytes < TS_PACKET_SIZE && section_bytes < section_size; ts_bytes++, section_bytes++) fwrite(section + section_bytes, 1, 1, fd_out); } if (ts_bytes == TS_PACKET_SIZE) { fflush(fd_out); memcpy(ts_header + 1, &pid, 2); /* pid */ if ((section_size - section_bytes) < (TS_PACKET_SIZE - TS_HEADER_MAX_SIZE)) { if (section_next != 0) { ts_header_size = TS_HEADER_MAX_SIZE; /* then next packet starts a new section */ ts_header[1] |= 0x40; /* set payload unit start indicator */ ts_header[4] = section_size - section_bytes; /* pointer field */ } else { ts_header_size = TS_HEADER_MAX_SIZE - 1 ; /* then next packet is the last */ ts_header[1] &= 0xBF; /* clear set payload unit start indicator */ } } else { ts_header_size = TS_HEADER_MAX_SIZE - 1; /* section will go over the next packet */ if ((section_size - section_bytes) == (TS_PACKET_SIZE - TS_HEADER_MAX_SIZE)) { /* and finish exactly at the end of it! */ /* we need to introduce a 1 byte ! */ *(section+section_size) = 0xff; section_size++; } } ts_header[3] = ts_continuity_counter | 0x10; /* continuity counter, no scrambling, only payload */ ts_continuity_counter = (ts_continuity_counter + 1) % 0x10; /* inc. continuity counter */ fwrite(ts_header, 1, ts_header_size, fd_out); ts_bytes = ts_header_size; } } } else { ts_needtopad = 1; not_finished = 0; } /* Padding */ if (ts_needtopad) { temp = 0xffff; for ( ; ts_bytes < TS_PACKET_SIZE; ts_bytes++) fwrite(&temp, 1, 1, fd_out); ts_needtopad = 0; fflush(fd_out); memcpy(ts_header + 1, &pid, 2); /* pid */ if (section_next != 0) { ts_header[1] |= 0x40; /* payload unit start indicator */ ts_header[4] = 0x0; /* point field */ ts_header_size = TS_HEADER_MAX_SIZE; } else { ts_header[1] &= 0xBF; /* clear payload unit start indicator */ ts_header_size = TS_HEADER_MAX_SIZE - 1; } ts_header[3] = ts_continuity_counter | 0x10; /* continuity counter, no scrambling, only payload */ ts_continuity_counter = (ts_continuity_counter + 1) % 0x10; /* inc. continuity counter */ ts_padded_did_not_output_next_header = 1; } } return 0; } opencaster-3.2.2/tools/tstimedwrite/0000755000175000017500000000000012214326444016775 5ustar debiandebianopencaster-3.2.2/tools/tstimedwrite/Makefile0000644000175000017500000000064412214326444020441 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc -lrt OBJS = tstimedwrite.o TARGET = tstimedwrite DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/tstimedwrite/tstimedwrite.c0000644000175000017500000000736112214326444021674 0ustar debiandebian/* * Copyright (C) 2008-2013, Lorenzo Pallara l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #define MULTICAST #include #include #include #include #include #include #include #include #include #include #include #define TS_PACKET_SIZE 188 long long int usecDiff(struct timespec* time_stop, struct timespec* time_start) { long long int temp = 0; long long int utemp = 0; if (time_stop && time_start) { if (time_stop->tv_nsec >= time_start->tv_nsec) { utemp = time_stop->tv_nsec - time_start->tv_nsec; temp = time_stop->tv_sec - time_start->tv_sec; } else { utemp = time_stop->tv_nsec + 1000000000 - time_start->tv_nsec; temp = time_stop->tv_sec - 1 - time_start->tv_sec; } if (temp >= 0 && utemp >= 0) { temp = (temp * 1000000000) + utemp; } else { fprintf(stderr, "start time %ld.%ld is after stop time %ld.%ld\n", time_start->tv_sec, time_start->tv_nsec, time_stop->tv_sec, time_stop->tv_nsec); temp = -1; } } else { fprintf(stderr, "memory is garbaged?\n"); temp = -1; } return temp / 1000; } int main (int argc, char *argv[]) { char* tsfile; unsigned int bitrate; unsigned char write_buf[TS_PACKET_SIZE]; int transport_fd; int written; int len; unsigned long long int packet_time; unsigned long long int real_time; struct timespec time_start; struct timespec time_stop; struct timespec nano_sleep_packet; memset(&time_start, 0, sizeof(time_start)); memset(&time_stop, 0, sizeof(time_stop)); memset(&nano_sleep_packet, 0, sizeof(nano_sleep_packet)); if(argc < 3 ) { fprintf(stderr, "Usage: %s file.ts bitrate > output.ts\n", argv[0]); fprintf(stderr, "zero bitrate is set to default 100.000.000 bps\n"); return 0; } else { tsfile = argv[1]; bitrate = atoi(argv[2]); if (bitrate <= 0) { bitrate = 100000000; } } transport_fd = open(tsfile, O_RDONLY); if(transport_fd < 0) { fprintf(stderr, "can't open file %s\n", tsfile); return 0; } int completed = 0; packet_time = 0; real_time = 0; nano_sleep_packet.tv_nsec = 665778; /* 1 ts packet at 100 mbps*/ clock_gettime(CLOCK_MONOTONIC, &time_start); while (!completed) { clock_gettime(CLOCK_MONOTONIC, &time_stop); real_time = usecDiff(&time_stop, &time_start); while (real_time * bitrate > packet_time * 1000000) { /* theorical bits against written bits */ len = read(transport_fd, write_buf, TS_PACKET_SIZE); if(len < 0) { fprintf(stderr, "ts file read error \n"); completed = 1; } else if (len == 0) { fprintf(stderr, "ts sent done\n"); completed = 1; } else { written = write(STDOUT_FILENO, write_buf, len); if(written <= 0) { perror("send(): error "); completed = 1; } else { packet_time += TS_PACKET_SIZE * 8; } } } nanosleep(&nano_sleep_packet, 0); } close(transport_fd); return 0; } opencaster-3.2.2/tools/tsmask/0000755000175000017500000000000012214326444015553 5ustar debiandebianopencaster-3.2.2/tools/tsmask/Makefile0000755000175000017500000000062312214326444017217 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = tsmask.o TARGET = tsmask DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/tsmask/tsmask.c0000644000175000017500000000543512214326444017230 0ustar debiandebian/* * Copyright (C) 2009-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #define TS_PACKET_SIZE 188 #define MAX_PID 8192 void Usage(void) { fprintf(stderr, "Usage: 'tsmask filename.ts -pid1 -pid2 ... -pidn [buffer_size_in_packets]'\n"); fprintf(stderr, "-pid removes 'pid' packets\n"); } int main(int argc, char *argv[]) { int byte_read; int fd_ts; /* File descriptor of ts file */ unsigned short pid; unsigned int i; unsigned char* packet_buffer; unsigned char* current_packet; unsigned int buffer_size; unsigned char pid_table[MAX_PID]; /* valid PID table */ /* Parse input arguments */ buffer_size = 0; memset(pid_table, 0, MAX_PID); if (argc >= 2) { fd_ts = open(argv[1], O_RDONLY); if (fd_ts < 0) { fprintf(stderr, "Can't find file %s\n", argv[1]); return 2; } } else { Usage(); return 2; } i = 2; while (i < argc) { if (argv[i][0] == '-') { pid = atoi(&(argv[i][1])); if ( pid < MAX_PID) { fprintf(stderr, "remove pid %d\n", pid); pid_table[pid] = 1; i++; } else { fprintf(stderr, "pid range should be from 0 to %d\n", MAX_PID); return 2; } } else { buffer_size = atoi(&(argv[i][0])); i++; } } if (buffer_size == 0) { buffer_size = 1; } /* Allocate packet buffer */ buffer_size *= TS_PACKET_SIZE; packet_buffer = malloc(buffer_size); if (packet_buffer == NULL) { fprintf(stderr, "Out of memory\n"); return 2; } /* Start to process the file */ byte_read = 1; while(byte_read) { /* read packets */ byte_read = read(fd_ts, packet_buffer, buffer_size); /* filter packets on their pids */ for (i = 0; i < buffer_size; i+=TS_PACKET_SIZE) { current_packet = packet_buffer+i; memcpy(&pid, current_packet + 1, 2); pid = ntohs(pid); pid = pid & 0x1fff; if (pid < MAX_PID) { if (pid_table[pid] == 0) { write(STDOUT_FILENO, current_packet, TS_PACKET_SIZE); } } } } return 0; } opencaster-3.2.2/tools/pesaudio2ts/0000755000175000017500000000000012232256710016511 5ustar debiandebianopencaster-3.2.2/tools/pesaudio2ts/Makefile0000644000175000017500000000063512214326444020157 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = pesaudio2ts.o TARGET = pesaudio2ts DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/pesaudio2ts/pesaudio2ts.c0000644000175000017500000004611312232256710021124 0ustar debiandebian/* * Copyright (C) 2009-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #define _BSD_SOURCE 1 #include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef PATH_MAX #define PATH_MAX 4096 #endif #define MAX_PID 8192 #define PTS_TIME 90000LL #define PES_HEADER_SIZE 4 #define TS_HEADER_SIZE 4 #define TS_PACKET_SIZE 188 #define TS_PACKET_BODY (TS_PACKET_SIZE - TS_HEADER_SIZE) #define SYSTEM_CLOCK_FREQUENCY 27000000 #define PTS_MAX 8589934592LL #define PACK_HEADER_SIZE 4 #define TIME_STAMP_SIZE 5 #define MAX_FD 256 const long long unsigned system_frequency = 27000000; int ts_payload; /* TS packet payload counter */ u_short pid; /* Pid for the TS packets */ u_char ts_continuity_counter; /* Continuity counter */ u_char ts_packet[TS_PACKET_SIZE]; /* TS packet */ u_char look_ahead_buffer[PES_HEADER_SIZE]; u_char look_ahead_size; unsigned char null_ts_packet[TS_PACKET_SIZE]; unsigned long long int pts_offset = 0LL; unsigned long long int pts_step = 3600LL; unsigned long long int pts = 0ll; /* PTS last value */ /* unsigned long long int pts_delta = 0; */ /*PTS delta increment */ unsigned long long int frame_number = 0ll; unsigned char pts_index = 0; /* PTS index table for the TS packets */ int frame_size = 0; int pes_frame_size = 0; int sample_rate = 0; int sample_per_frame = 1152; unsigned long long ts_packets = 0; unsigned long long bitrate = 0; unsigned long long parse_timestamp(unsigned char *buf) { unsigned long long a1; unsigned long long a2; unsigned long long a3; unsigned long long ts; a1 = (buf[0] & 0x0F) >> 1; a2 = ((buf[1] << 8) | buf[2]) >> 1; a3 = ((buf[3] << 8) | buf[4]) >> 1; ts = (a1 << 30) | (a2 << 15) | a3; return ts; } void stamp_ts (unsigned long long int ts, unsigned char* buffer) { if (buffer) { buffer[0] = ((ts >> 29) & 0x0F) | 0x01; buffer[1] = (ts >> 22) & 0xFF; buffer[2] = ((ts >> 14) & 0xFF ) | 0x01; buffer[3] = (ts >> 7) & 0xFF; buffer[4] = ((ts << 1) & 0xFF ) | 0x01; } } void restamp_and_output(void) { unsigned char adapt = 0; unsigned char timestamp[TIME_STAMP_SIZE]; int ts_header_size = 0; unsigned long long time = 0; adapt = (ts_packet[3] >> 4) & 0x03; if (adapt == 0) { ts_header_size = TS_PACKET_SIZE; /* the packet is invalid ?*/ } else if (adapt == 1) { ts_header_size = TS_HEADER_SIZE; /* only payload */ } else if (adapt == 2) { ts_header_size = TS_PACKET_SIZE; /* only adaptation field */ } else if (adapt == 3) { ts_header_size = TS_HEADER_SIZE + ts_packet[4] + 1; /* jump the adaptation field */ } else { ts_header_size = TS_PACKET_SIZE; /* not managed */ } if (ts_header_size < TS_PACKET_SIZE - 9 - TIME_STAMP_SIZE) { if ((ts_packet[ts_header_size] == 0x00) && (ts_packet[ts_header_size + 1] == 0x00) && (ts_packet[ts_header_size + 2] == 0x01) && ((ts_packet[ts_header_size + 3] >> 5) == 0x06)) { if (pes_frame_size == (ts_packet[ts_header_size + 4] << 8 | ts_packet[ts_header_size + 5])) { memcpy(timestamp, ts_packet + ts_header_size + 9, TIME_STAMP_SIZE); time = parse_timestamp(timestamp); /* fprintf(stderr, "Pid %d old Audio Presentation Time Stamp is: %llu, %llu.%04llu sec.\n", pid, time, time / (system_frequency / 300), (time % (system_frequency / 300)) / ((system_frequency / 300) / 10000)); */ if (pts_index == 0) { pts_index = 1; memcpy(timestamp, ts_packet + ts_header_size + 9, TIME_STAMP_SIZE); time = parse_timestamp(timestamp); pts = time; frame_number = 1; } else if (pts_index == 1) { pts_index = 2; memcpy(timestamp, ts_packet + ts_header_size + 9, TIME_STAMP_SIZE); time = parse_timestamp(timestamp); pts = time; frame_number = 2; } else { pts = pts_offset + ((frame_number * sample_per_frame * PTS_TIME) / sample_rate); stamp_ts(pts % PTS_MAX, ts_packet + ts_header_size + 9); frame_number++; ts_packet[ts_header_size + 9] &= 0x0F; ts_packet[ts_header_size + 9] |= 0x20; } memcpy(timestamp, ts_packet + ts_header_size + 9, TIME_STAMP_SIZE); time = parse_timestamp(timestamp); /* fprintf(stderr, "Pid %d new Audio Presentation Time Stamp is: %llu, %llu.%04llu sec.\n", pid, time, time / (system_frequency / 300), (time % (system_frequency / 300)) / ((system_frequency / 300) / 10000)); */ } else { /* fprintf(stderr, "pesaudio2ts warning: error in audio payload\n"); */ } } } write(STDOUT_FILENO, ts_packet, TS_PACKET_SIZE); ts_packets++; } void send_current_packet(void) { int i; u_char temp; if (TS_HEADER_SIZE + ts_payload == TS_PACKET_SIZE) { /* filled case */ ts_packet[3] = ts_continuity_counter | 0x10; /* continuity counter, no scrambling, only payload */ ts_continuity_counter = (ts_continuity_counter + 1) % 0x10; /* inc. continuity counter */ restamp_and_output(); ts_payload = 0; } else if (TS_HEADER_SIZE + ts_payload + 1 == TS_PACKET_SIZE) { /* payload too big: two packets are necessary */ temp = ts_packet[TS_HEADER_SIZE + ts_payload - 1]; /* copy the exceeding byte */ ts_payload--; send_current_packet(); memcpy(ts_packet + 1, &pid, 2); /* pid, no pusu */ ts_packet[4] = temp; ts_payload = 1; send_current_packet(); } else { /* padding is necessary */ ts_packet[3] = ts_continuity_counter | 0x30; /* continuity counter, no scrambling, adaptation field and payload */ ts_continuity_counter = (ts_continuity_counter + 1) % 0x10; /* inc. continuity counter */ for (i = 0; i < ts_payload; i++) { /* move the payload at the end */ ts_packet[TS_PACKET_SIZE - 1 - i] = ts_packet[TS_HEADER_SIZE + ts_payload - 1 - i]; } ts_packet[4] = TS_PACKET_SIZE - ts_payload - TS_HEADER_SIZE - 1; /* point to the first payload byte */ ts_packet[5] = 0x00; /* no options */ for ( i = TS_HEADER_SIZE + 2 ; i < TS_PACKET_SIZE - ts_payload; i++) { /* pad the packet */ ts_packet[i] = 0xFF; } restamp_and_output(); ts_payload = 0; } } FILE* openStream(char* argv[], int open_counter, FILE* file_pes[]) { FILE* result = NULL; struct stat file_stat; /* fprintf(stderr, "pesaudio2ts: opening %s... ", argv[6 + open_counter]); */ if (lstat(argv[6 + open_counter], &file_stat) == 0) { if (!S_ISFIFO(file_stat.st_mode)) { result = fopen(argv[6 + open_counter], "rb"); file_pes[open_counter] = result; /* fprintf(stderr, "open\n"); */ } else { result = file_pes[open_counter]; /* fprintf(stderr, "is a fifo\n"); */ } } return result; } void closeStream(char* argv[], int open_counter, FILE* file_pes[]) { struct stat file_stat; /* fprintf(stderr, "pesaudio2ts: closing %s... ", argv[6 + open_counter]); */ if (lstat(argv[6 + open_counter], &file_stat) == 0) { if (!S_ISFIFO(file_stat.st_mode)) { fclose(file_pes[open_counter]); /* fprintf(stderr, "closed\n"); */ } else { /* fprintf(stderr, "is fifo\n"); */ } } else { fclose(file_pes[open_counter]); /* fprintf(stderr, "closed but now is missing\n"); */ } } int main(int argc, char *argv[]) { int i; int loop_on = 0; int byte_read; int total_bytes = 0; unsigned long long left_packet = 0; int open_counter = 0; char filelength[PATH_MAX]; FILE* file_pes[MAX_FD]; FILE* current_file_pes; memset(file_pes, 0, sizeof(FILE*) * MAX_FD); /* Parse args */ pid = MAX_PID; current_file_pes = 0; if (argc >= 7) { pid = atoi(argv[1]); sample_per_frame = atoi(argv[2]); sample_rate = atoi(argv[3]); frame_size = atoi(argv[4]); /* es frame size */ if (argv[4][2] == ':') { pts_step = atoi(argv[4]+3); } loop_on = atoi(argv[5]) > 0; current_file_pes = fopen(argv[6], "r"); file_pes[0] = current_file_pes; snprintf(filelength, PATH_MAX, "%s.length", argv[6]); if (current_file_pes == NULL) { /* fprintf(stderr, "pesaudio2ts: failed to open file %s\n", argv[6]); */ return 0; } if (pid >= MAX_PID) { /* fprintf(stderr, "pesaudio2ts: pid has to be smaller than %d\n", MAX_PID); */ return 0; } else { pid = htons(pid); } } pts_offset = pts_step; /* fifo are all open at the begin */ for (i = 7; i < argc; i++) { struct stat file_stat; if (lstat(argv[i], &file_stat) == 0) { /* take stats of the real file not of the symbolic link */ if (S_ISFIFO(file_stat.st_mode)) { file_pes[i - 6] = fopen(argv[i], "rb"); if (file_pes[i - 6] == NULL) { /* fprintf(stderr, "pesaudio2ts: failed to open %s\n", argv[i]); */ return 0; } else { /* fprintf(stderr, "pesaudio2ts: opens also fifo %s\n", argv[i]); */ } } else { file_pes[i - 6] = NULL; } } else { file_pes[i - 6] = NULL; } } if (argc < 6) { fprintf(stderr, "Usage: 'pesaudio2ts pid sample_per_frame sample_rate es_frame_size[:video_pts_step] loop_on input1.pes [input2.pes ... ]', where pid is bounded from 1 to 8191\n"); fprintf(stderr, "if loop_on is 1 after the last input.pes will start again from the first, video synch works only with mpeg2 video files\n"); fprintf(stderr, "loop_on ends if the first file is missing\n"); fprintf(stderr, "input*.pes.length is scan for a pts value, if present the value is used to adjust single pes length adding null packets to sync at that pts\n"); return 0; } /* Init null packet */ memset(null_ts_packet, 0, TS_PACKET_SIZE); null_ts_packet[0] = 0x47; null_ts_packet[1] = 0x1F; null_ts_packet[2] = 0xFF; null_ts_packet[3] = 0x10; /* Need to output some null packets to synch to the first pts */ pes_frame_size = frame_size + 8; /* only payload */ frame_size += 14; /* pes header */ frame_size = ((frame_size / TS_PACKET_BODY) + ((frame_size % TS_PACKET_BODY) != 0) + ((frame_size % TS_PACKET_BODY) == 183)) * TS_PACKET_SIZE; /* ts encapsulation */ bitrate = sample_rate * frame_size * 8 / sample_per_frame; /* fprintf(stderr, "pesaudio2ts: ts bit rate is %llu bps\n", bitrate); */ int packets_to_start = (pts_offset * bitrate) / (PTS_TIME * 8 * TS_PACKET_SIZE);/* packets to pts */ packets_to_start -= (frame_size / TS_PACKET_SIZE) + 1 ; /* the first audio frame needs to be there at pts */ /* fprintf(stderr, "output %d null packets to sync\n", packets_to_start); */ i = 0; for (i = 0; i < packets_to_start; i++) { write(STDOUT_FILENO, null_ts_packet, TS_PACKET_SIZE); ts_packets++; } /* Set some init. values */ left_packet = 0; ts_payload = 0; look_ahead_size = 0; ts_continuity_counter = 0x0; ts_packet[0] = 0x47; /* sync byte */ memcpy(ts_packet + 1, &pid, 2); /* pid */ ts_packet[1] |= 0x40; /* payload unit start indicator */ byte_read = 1; /* Process the PES file */ byte_read = fread(look_ahead_buffer + look_ahead_size, 1, PES_HEADER_SIZE, current_file_pes); if (byte_read > 0) { total_bytes += byte_read; } else if (byte_read == 0){ /* fprintf(stderr, "pesaudio2ts: audio read was zero at the start\n"); */ } look_ahead_size = byte_read; int head_missing = 0; while (!head_missing) { while ((byte_read || look_ahead_size) && !head_missing) { /* Fill the look ahead buffer */ if (look_ahead_size < PES_HEADER_SIZE && current_file_pes != NULL) { byte_read = fread(look_ahead_buffer + look_ahead_size, 1, 1, current_file_pes); if (byte_read > 0) { total_bytes += byte_read; } else { /* fprintf(stderr, "pesaudio2ts: audio read was %d in the processing, look_ahead is %d\n", byte_read, look_ahead_size); */ } if (byte_read <= 0 && loop_on) { closeStream(argv, open_counter, file_pes); current_file_pes = NULL; open_counter++; /* fprintf(stderr, "pesaudio2ts %s total bytes was %d\n", filelength, total_bytes); */ total_bytes = 0; /* it is necesseary to set next pts time to a multiple of pts frame rate, frame rate is assumed 25fps */ /* it also assume audio ends before video */ unsigned long long next_pts = pts_offset + ((frame_number * sample_per_frame * PTS_TIME) / sample_rate); unsigned long long next_pts_rounded_to_next_video_frame = 0; /* NB. this is the pes length of the file just closed */ /* fprintf(stderr, "Audio: looking for end file %s\n", filelength); */ FILE* file = fopen(filelength, "r"); if (file != 0) { fscanf (file, "%llu", &next_pts_rounded_to_next_video_frame); fclose(file); next_pts_rounded_to_next_video_frame += pts_offset; } else { /* fprintf(stderr, "pesaudio2ts warning: missed %s file\n", filelength); */ next_pts_rounded_to_next_video_frame = ((next_pts / pts_step) + 1) * pts_step; } if (argc >= 6 + open_counter) { current_file_pes = openStream(argv, open_counter, file_pes); if (current_file_pes == NULL) { /* fprintf(stderr, "pesaudio2ts: failed to open %s\n", argv[6 + open_counter]); */ } else { snprintf(filelength, PATH_MAX, "%s.length", argv[6 + open_counter]); } } if (current_file_pes == NULL) { open_counter = 0; current_file_pes = openStream(argv, open_counter, file_pes); if (current_file_pes == NULL) { /* fprintf(stderr, "pesaudio2ts: failed to open %s\n", argv[6 + open_counter]); */ } else { snprintf(filelength, PATH_MAX, "%s.length", argv[6]); } } if (current_file_pes != NULL) { fprintf(stderr, "pesaudio2ts sync: %s new presented audio frame will be at %llu, %llu.%04llu sec., last presented audio frame was at %llu, %llu.%04llu sec.\n", argv[6 + open_counter], next_pts_rounded_to_next_video_frame % PTS_MAX, (next_pts_rounded_to_next_video_frame % PTS_MAX) / PTS_TIME, ((next_pts_rounded_to_next_video_frame % PTS_MAX) % PTS_TIME) / (PTS_TIME / 10000), next_pts % PTS_MAX, (next_pts % PTS_MAX) / PTS_TIME, ((next_pts % PTS_MAX) % PTS_TIME) / (PTS_TIME / 10000)); } /* int null_packets = (((next_pts_rounded_to_next_video_frame - next_pts) * bitrate) + left_packet) / (PTS_TIME * 8 * TS_PACKET_SIZE); left_packet = ((next_pts_rounded_to_next_video_frame - next_pts) * bitrate + left_packet) % (PTS_TIME * 8 * TS_PACKET_SIZE); fprintf(stderr, "need to output %d null packets to sync\n", null_packets); fprintf(stderr, "left %llu byte left to next round to sync\n", left_packet); */ /* expected overflown after 6.4 years at 1mbps */ int null_packets = (left_packet + (next_pts_rounded_to_next_video_frame * bitrate)) / (PTS_TIME * 8 * TS_PACKET_SIZE); /* packets to next pts */ null_packets -= ts_packets; /* packets sent */ null_packets -= (frame_size / TS_PACKET_SIZE) + 1 ; /* + 1 the first audio frame packets needs to be there at the next pts */ /* null_packets -= 1 ; // the first audio frame packet needs to be there at the next pts */ left_packet = (left_packet + (next_pts_rounded_to_next_video_frame * bitrate)) % (PTS_TIME * 8 * TS_PACKET_SIZE); /* fprintf(stderr, "need to output %d null packets to sync\n", null_packets); */ int i = 0; /* fprintf(stderr, "sending on output %d null packets, frame size is %d packets, left packet is %llu\n", null_packets, (frame_size / TS_PACKET_SIZE), left_packet); */ for (i = 0; i < null_packets; i++) { write(STDOUT_FILENO, null_ts_packet, TS_PACKET_SIZE); ts_packets++; } /* fprintf(stderr, "sent on output %d null packets, frame size is %d packets, left packet is %llu\n", null_packets, (frame_size / TS_PACKET_SIZE), left_packet); */ if (current_file_pes != NULL) { byte_read = fread(look_ahead_buffer + look_ahead_size, 1, 1, current_file_pes); if (byte_read > 0) { total_bytes += byte_read; frame_number = 0; pts_offset = next_pts_rounded_to_next_video_frame; } else { fprintf(stderr, "pesaudio2ts: audio read was %d at the begin, look ahead is %d\n", byte_read, look_ahead_size); head_missing = 1; } } else { byte_read = 0; fprintf(stderr, "pesaudio2ts: first file of the loop is missing\n"); head_missing = 1; } } look_ahead_size += byte_read; } /* PES header detected? */ if (look_ahead_size == PES_HEADER_SIZE && look_ahead_buffer[0] == 0x00 && look_ahead_buffer[1] == 0x00 && look_ahead_buffer[2] == 0x01 && look_ahead_buffer[3] == 0xC0 ) { // (((look_ahead_buffer[3] >> 4) == 0x0E) || ((look_ahead_buffer[3] >> 5) == 0x06))) { /* Send current packet if there's anything ready */ if (ts_payload) { send_current_packet(); } /* Set pusu for the next packet */ memcpy(ts_packet + 1, &pid, 2); /* pid */ ts_packet[1] |= 0x40; /* payload unit start indicator */ } /* Fill the current packet */ if (look_ahead_size > 0 && ((!loop_on) || (loop_on && byte_read > 0))) { /* Move a packet from the lookahead to the current packet */ ts_packet[TS_HEADER_SIZE + ts_payload] = look_ahead_buffer[0]; ts_payload++; for (i = 0; i < PES_HEADER_SIZE-1; i++){ look_ahead_buffer[i] = look_ahead_buffer[i + 1]; } look_ahead_size--; /* Send the packet if it's filled */ if (TS_HEADER_SIZE + ts_payload == TS_PACKET_SIZE) { send_current_packet(); /* Unset pusu for the next packet */ memcpy(ts_packet + 1, &pid, 2); /* pid */ } } /* Send the last packet with the last bytes if any */ if (byte_read == 0 && look_ahead_size == 0 && ts_payload) { send_current_packet(); } } /* try to re-open and block if fifo and on-loop */ for (i = 6; i < argc && loop_on; i++) { struct stat file_stat; if (lstat(argv[i], &file_stat) == 0) { if (S_ISFIFO(file_stat.st_mode)) { fclose(file_pes[i - 6]); } } } for (i = 6; i < argc && loop_on; i++) { struct stat file_stat; if (lstat(argv[i], &file_stat) == 0) { /* take stats of the real file not of the symbolic link */ if (S_ISFIFO(file_stat.st_mode)) { file_pes[i - 6] = fopen(argv[i], "rb"); if (file_pes[i - 6] == NULL) { /* fprintf(stderr, "pesaudio2ts: failed to open %s\n", argv[i]); */ return 0; } else { /* fprintf(stderr, "pesaudio2ts: re-opens fifo %s\n", argv[i]); */ if (i == 6) { head_missing = 0; } } } else { file_pes[i - 6] = NULL; } } else { file_pes[i - 6] = NULL; } } if (!loop_on) { head_missing = 1; } current_file_pes = file_pes[0]; /* if (!head_missing) { byte_read = fread(look_ahead_buffer + look_ahead_size, 1, PES_HEADER_SIZE, current_file_pes); if (byte_read > 0) { total_bytes += byte_read; look_ahead_size = byte_read; } } */ } return 0; } opencaster-3.2.2/tools/esaudioinfo/0000755000175000017500000000000012214326444016556 5ustar debiandebianopencaster-3.2.2/tools/esaudioinfo/Makefile0000644000175000017500000000063512214326444020222 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = esaudioinfo.o TARGET = esaudioinfo DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/esaudioinfo/esaudioinfo.c0000644000175000017500000003210312214326444021226 0ustar debiandebian/* * Copyright (C) 2008-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #include #define ES_HEADER_SIZE 4 #define HEADER_MAX_SIZE 8 /* MPEG AUDIO */ const char* audio_version[4] = { "MPEG Version 2.5", "Reserved", "MPEG Version 2 (ISO/IEC 13818-3)", "MPEG Version 1 (ISO/IEC 11172-3)" }; const char* audio_layer[4] = { "Reserved", "Layer III", "Layer II", "Layer I", }; const char* protection[2] = { "Protected by CRC (16bit crc follows header)", "Not protected", }; const char* bit_rate_audio[4][4][16] = { { /* version 2.5 */ {"wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", }, {"free", "32", "16", "24", "32", "40", "48", "56", "64", "80", "96", "112", "128", "144", "160", "bad", }, /* layer 3 */ {"free", "32", "16", "24", "32", "40", "48", "56", "64", "80", "96", "112", "128", "144", "160", "bad", }, /* layer 2 */ {"free", "32", "48", "56", "64", "80", "96", "112", "128", "144", "160", "176", "192", "224", "256", "bad", }, /* layer 1 */ }, { /* wrong */ {"wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", }, {"wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", }, {"wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", }, {"wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", }, }, { /* version 2*/ {"wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", }, {"free", "32", "16", "24", "32", "40", "48", "56", "64", "80", "96", "112", "128", "144", "160", "bad", }, /* layer 3 */ {"free", "32", "16", "24", "32", "40", "48", "56", "64", "80", "96", "112", "128", "144", "160", "bad", }, /* layer 2 */ {"free", "32", "48", "56", "64", "80", "96", "112", "128", "144", "160", "176", "192", "224", "256", "bad", }, /* layer 1 */ }, { /* version 1 */ {"wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", "wrong", }, {"free", "32", "40", "48", "56", "64", "80", "96", "112", "128", "160", "192", "224", "256", "320", "bad",} , /* layer 3 */ {"free", "32", "48", "56", "64", "80", "96", "112", "128", "160", "192", "224", "256", "320", "384", "bad",} , /* layer 2 */ {"free", "32", "64", "96", "128", "160", "192", "224", "256", "288", "320", "352", "384", "416", "448", "bad", }, /* layer 1 */ }, }; const char* sampling[4][4] = { /* mpeg 2.5 */ {"11025", "12000", "8000", "reserved",}, /* wrong */ {"wrong", "wrong", "wrong", "wrong", }, /* mpeg 2 */ {"22050", "24000", "16000", "reserved",}, /* mpeg 1 */ {"44100", "48000", "32000", "reserved",}, }; const char* padded[2] = { "Frame is not padded", "Frame is padded with one extra slot", }; const char* channel_mode[4] = { "Stereo", "Joint stereo (Stereo)", "Dual channel (Stereo)", "Single channel (Mono)", }; const char* copyright[2] = { "Audio is not copyrighted", "Audio is copyrighted", }; const char* original[2] = { "Copy of original media", "Original media", }; const char* emphasis[4] = { "None", "50/15 ms", "Reserved", "CCIT J.17", }; /* AC3 audio */ const char* ac3sampling[4] = {"48000", "32000", "44100", "reserved"}; const char* eac3sampling[4] = {"24000", "22400", "16000", "reserved"}; unsigned int frame_size_code[38][3] = { /* 32000, 44100, 48000 */ {96, 69, 64}, {96, 70, 64}, {120, 87, 80}, {120, 88, 80}, {144, 104, 96}, {144, 105, 96}, {168, 121, 112}, {168, 122, 112}, {192, 139, 128}, {192, 140, 128}, {240, 174, 160}, {240, 175, 160}, {288, 208, 192}, {288, 209, 192}, {336, 243, 224}, {336, 244, 224}, {384, 278, 256}, {384, 279, 256}, {480, 348, 320}, {480, 349, 320}, {576, 417, 384}, {576, 418, 384}, {672, 487, 448}, {672, 488, 448}, {768, 557, 512}, {768, 558, 512}, {960, 696, 640}, {960, 697, 640}, {1152, 835, 768}, {1152, 836, 768}, {1344, 975, 896}, {1344, 976, 896}, {1536, 1114, 1024}, {1536, 1115, 1024}, {1728, 1253, 1152}, {1728, 1254, 1152}, {1920, 1393, 1280}, {1920, 1394, 1280} }; /* DTS audio */ const char* amode[16] = { "A", "A + B (dual mono)", "L + R (stereo)", "(L+R) + (L-R) (sum and difference)", "LT + RT (left and right total)", "C + L + R", "L + R + S", "C + L + R + S", "L + R + SL + SR", "C + L + R + SL + SR", "CL + CR + L + R + SL + SR", "C + L + R + LR + RR + OV", "CF + CR + LF + RF + LR + RR", "CL + C + CR + L + R + SL + SR", "CL + CR + L + R + SL1 + SL2 + SR1 + SR2", "CL + C + CR + L + R + SL + S + SR" }; const char* sfreq[16] = { "invalid", "8 KHz", "16 KHz", "32 KHz", "invalid", "invalid", "11025 Hz", "22050 Hz", "44100 Hz", "invalid", "invalid", "12 KHz", "24 KHz", "48 KHz", "96 KHz", "192 KHz", }; const char* rate[32] = { "invalid", "invalid", "invalid", "invalid", "invalid", "128 kbps", "192 kbps", "224 kbps", "256 kbps", "320 kbps", "384 kbps", "448 kbps", "512 kbps", "576 kbps", "640 kbps", "768 kbps", "960 kbps", "1024 kbps", "1152 kbps", "1280 kbps", "1344 kbps", "1408 kbps", "1411.2 kbps", "1472 kbps", "1536 kbps", "1920 kbps", "2048 kbps", "3072 kbps", "3840 kbps", "open", "variable", "lossless", }; int main(int argc, char *argv[]) { int byte_read; int byte_count; int version; int layer; int bitrated; int sampled; int pad; int framelength; int ismpeg2; int iseac3; int isdts; int packet_counter; unsigned long long int total_byte_count; FILE* file_es; unsigned char es_header[HEADER_MAX_SIZE]; /* Open es file */ if (argc > 1) { file_es = fopen(argv[1], "rb"); } else { fprintf(stderr, "Usage: 'esaudioinfo audio.es'\n"); fprintf(stderr, "Prints info about sampling and frame size\n"); fprintf(stderr, "Supports: mpeg2 audio layer 1,2,3\n"); fprintf(stderr, "Supports: ac3 and enhanced-ac3\n"); fprintf(stderr, "Supports: dts\n"); return 2; } if (file_es == 0) { fprintf(stderr, "Can't find file %s\n", argv[1]); return 2; } /* Start to process the file */ byte_count = 0; total_byte_count = 0LL; packet_counter = 0; byte_read = fread(es_header, 1, ES_HEADER_SIZE, file_es); isdts = (es_header[0] == 0x7F) && (es_header[1] == 0xFE) && (es_header[2] == 0x80) && (es_header[3] == 0x01); if (isdts) { ismpeg2 = 0; } else { ismpeg2 = (es_header[0] == 0xFF) && ((es_header[1] >> 5)== 0x07); } iseac3 = -1; while(byte_read) { byte_count += byte_read; total_byte_count += byte_read; /* Search headers */ if ( ismpeg2 && (es_header[0] == 0xFF) && ((es_header[1] >> 5)== 0x07)) { /* Audio header tentative */ packet_counter++; if (byte_count > ES_HEADER_SIZE) { fprintf(stdout, "audio frame size from stream measured: %d bytes, %d bits\n\n", byte_count, byte_count * 8); byte_count = 0; } fprintf(stdout, "audio header packet %d, position:%llu\n", packet_counter, total_byte_count); version = (es_header[1] & 0x18) >> 3; fprintf(stdout, "audio version: %s\n", audio_version[version]); layer = (es_header[1] & 0x6) >> 1; fprintf(stdout, "audio layer: %s\n", audio_layer[layer]); fprintf(stdout, "protection bit: %s\n", protection[es_header[1] & 0x1]); bitrated = (es_header[2] & 0xF0) >> 4; fprintf(stdout, "bit rate index: %skbps\n", bit_rate_audio[version][layer][bitrated]); sampled = (es_header[2] & 0x0C) >> 2; fprintf(stdout, "sampling rate: %sHz\n", sampling[version][sampled]); pad = (es_header[2] & 0x3) >> 1; fprintf(stdout, "padding: %s\n", padded[pad]); if ((sampling[version][sampled][0] != 'w') && (sampling[version][sampled][0] != 'r') && (bit_rate_audio[version][layer][bitrated][0] != 'w') && (bit_rate_audio[version][layer][bitrated][0] != 'r')) { if (layer == 0x3) { framelength = 12 * atoi(bit_rate_audio[version][layer][bitrated]) * 1000; framelength /= atoi(sampling[version][sampled]); framelength += pad; framelength *= 4; } else { framelength = 144 * atoi(bit_rate_audio[version][layer][bitrated]) * 1000; framelength /= atoi(sampling[version][sampled]); framelength += pad; } } else { framelength = 0; } fprintf(stdout, "audio frame from headers (formula can have rounds): %d bytes, %d bits\n", framelength, framelength * 8); fprintf(stdout, "channel mode: %s\n", channel_mode[(es_header[3] & 0xC0) >> 6]); fprintf(stdout, "copyrights: %s\n", copyright[(es_header[3] & 0x08) >> 3]); fprintf(stdout, "original: %s\n", original[(es_header[3] & 0x04) >> 2]); fprintf(stdout, "emphasis: %s\n", emphasis[es_header[3] & 0x03]); byte_read = fread(es_header, 1, ES_HEADER_SIZE, file_es); } else if (!ismpeg2 && !isdts && (es_header[0] == 0x0B) && (es_header[1] == 0x77)) { packet_counter++; if (byte_count > ES_HEADER_SIZE) { fprintf(stdout, "audio frame size from stream measured: %d bytes, %d bits\n\n", byte_count, byte_count * 8); byte_count = 0; } /* is it possibile to decide if it is ac3 or ac3-enhanced better then this ? how? doing crc? */ if (iseac3 < 0) { if (((es_header[2] >> 3) & 0x07) == 0) { iseac3 = 1; } else { iseac3 = 0; } } if (iseac3) { unsigned int frame_size = 0; unsigned char fs_cod = 0; frame_size = ((es_header[2] & 0x07) << 8) + es_header[3]; fprintf(stdout, "eac3 frame size is %d byte\n", frame_size * 2); byte_read = fread(es_header, 1, 1, file_es); byte_count++; total_byte_count++; fs_cod = es_header[0] >> 6; if (fs_cod != 0x03) { fprintf(stdout, "eac3 sampling rate is %s\n", ac3sampling[fs_cod]); } else { fs_cod = (es_header[0] >> 4) & 0x03; fprintf(stdout, "eac3 sampling rate is %s\n", eac3sampling[fs_cod]); } } else { unsigned char frame_code = 0; unsigned char sampling = 0; byte_read = fread(es_header, 1, 1, file_es); byte_count++; total_byte_count++; sampling = es_header[0] >> 6; fprintf(stdout, "ac3 sampling rate is %s\n", ac3sampling[sampling]); frame_code = es_header[0] & 0x3F; fprintf(stdout, "ac3 frame size is %d byte\n", frame_size_code[frame_code][2 - sampling] * 2); } byte_read = fread(es_header, 1, ES_HEADER_SIZE, file_es); } else if (isdts && (es_header[0] == 0x7F) && (es_header[1] == 0xFE) && (es_header[2] == 0x80) && (es_header[3] == 0x01)) { packet_counter++; if (byte_count > ES_HEADER_SIZE) { fprintf(stdout, "audio frame size from stream measured: %d bytes, %d bits\n\n", byte_count, byte_count * 8); byte_count = 0; } byte_read = fread(es_header, 1, 6, file_es); byte_count += 6; total_byte_count += 6; fprintf(stdout, "ftype: %d\n", (es_header[0] >> 7) & 0x1); fprintf(stdout, "frame short: %d\n", (es_header[0] >> 2) & 0x1F); fprintf(stdout, "cpf crc: %d\n", (es_header[0] >> 1) & 0x1); fprintf(stdout, "nblks: %d\n", ((es_header[0] & 0x1) << 6) | (es_header[1] >> 2)) ; fprintf(stdout, "fsize: %d\n", ((es_header[1] & 0x3) << 12) | (es_header[2] << 4) | (es_header[3] >> 4)); unsigned int temp = ((es_header[3] & 0xF) << 2) | ((es_header[4] >> 6) & 0x3); fprintf(stdout, "amode: %s\n", amode[temp]); temp = (es_header[4] >> 2) & 0xF; fprintf(stdout, "sfreq: %s\n", sfreq[temp]); temp = ((es_header[4] & 0x3) << 3)| ((es_header[5] >> 5) & 0x1F); fprintf(stdout, "rate: %s\n", rate[temp]); byte_read = fread(es_header, 1, ES_HEADER_SIZE, file_es); } else { es_header[0] = es_header[1]; es_header[1] = es_header[2]; es_header[2] = es_header[3]; byte_read = fread(es_header + 3, 1, 1, file_es); } } return 0; } opencaster-3.2.2/tools/tstimeout/0000755000175000017500000000000012232257151016304 5ustar debiandebianopencaster-3.2.2/tools/tstimeout/Makefile0000644000175000017500000000063112214326444017746 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = tstimeout.o TARGET = tstimeout DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/tstimeout/tstimeout.c0000644000175000017500000000562412232257151020514 0ustar debiandebian/* * Copyright (C) 2009-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #define MULTICAST #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define TS_PACKET_SIZE 188 int main(int argc, char *argv[]) { int input_file; int result; int stable; int backup_file; int byte_read; int timeout; int index; fd_set set; struct timeval tv; unsigned char ts_packet[TS_PACKET_SIZE]; if (argc >= 4) { input_file = open(argv[1], O_RDONLY); if (input_file < 0) { fprintf(stderr, "Can't open file %s\n", argv[1]); return 0; } backup_file = open(argv[2], O_RDONLY); if (backup_file < 0) { fprintf(stderr, "Can't open file %s\n", argv[2]); return 0; } timeout = atoi(argv[3]); if (timeout == 0) { fprintf(stderr, "Timeout has to be bigger than 0\n"); return 0; } } else { fprintf(stderr, "Usage: 'tstimeout inputfile.ts backupfile.ts timeout_in_ms'\n"); return 0; } fcntl (input_file, F_SETFL, fcntl (input_file, F_GETFL, 0) | O_NONBLOCK); index = 0; tv.tv_sec = timeout/1000; tv.tv_usec = (timeout%1000) * 1000; stable = 1; while (1) { FD_ZERO(&set); FD_SET(input_file,&set); if (stable) { tv.tv_sec = timeout/1000; tv.tv_usec = (timeout%1000) * 1000; } else { tv.tv_sec = 0LL; tv.tv_usec = 0LL; } result = select(input_file+ 1, &set, NULL, NULL, &tv); if (result > 0) { if (FD_ISSET(input_file, &set)) { byte_read = read(input_file, ts_packet + index, TS_PACKET_SIZE - index); if (byte_read > 0) { stable = 1; index += byte_read; if (index == TS_PACKET_SIZE) { write(STDOUT_FILENO, ts_packet, TS_PACKET_SIZE); index = 0; } } } } else { stable = 0; read(backup_file, ts_packet, TS_PACKET_SIZE); write(STDOUT_FILENO, ts_packet, TS_PACKET_SIZE); } } close(input_file); return 0; } opencaster-3.2.2/tools/tscrypt/0000755000175000017500000000000012214326443015760 5ustar debiandebianopencaster-3.2.2/tools/tscrypt/Makefile0000644000175000017500000000064512214326443017425 0ustar debiandebianCC = gcc CFLAGS += -g -O2 -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -ldvbcsa OBJS = tscrypt.o TARGET = tscrypt DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/tscrypt/tscrypt.c0000644000175000017500000000503112214326443017633 0ustar debiandebian/* * Copyright (C) 2009-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #include #include //#include "dvbcsa_pv.h" #define CW_SIZE 16 /* 8 bytes odd and 8 bytes even */ #define TS_PACKET_SIZE 188 #define TS_PAYLOAD_SIZE 184 unsigned char cw[CW_SIZE]; void read_cw(char* filename) { int fd_cw; /* File descriptor of a control word file */ /* Check for new cws */ fd_cw = open(filename, O_RDONLY); if (fd_cw < 0) { fprintf(stderr, "Can't find file %s\n", filename); exit(2); } int byte_read = read(fd_cw, cw, CW_SIZE); close(fd_cw); if (byte_read <= 0) { fprintf(stderr, "Can't read file %s\n", filename); exit(2); } } void Usage() { fprintf(stderr, "Usage: tscrypt input.ts file.cw > crypted.ts \n"); fprintf(stderr, "file.cw is 16 byte, 8 bytes of even word and 8 bytes of odd word \n"); exit(2); } int main(int argc, char *argv[]) { int fd_ts; int byte_read; int adaptation_field = 0; unsigned char packet[TS_PACKET_SIZE]; struct dvbcsa_key_s *key = dvbcsa_key_alloc(); if (argc >= 3) { fd_ts = open(argv[1], O_RDONLY); read_cw(argv[2]); } else { Usage(); } if (fd_ts < 0) { fprintf(stderr, "Can't find file %s\n", argv[2]); return 2; } dvbcsa_key_set(cw, key); byte_read = 1; while(byte_read) { byte_read = read(fd_ts, packet, TS_PACKET_SIZE); adaptation_field = (packet[3] & 0x30) >> 4; if (adaptation_field == 1) { // payload only, in OpenCaster pcr is without payload dvbcsa_encrypt(key, packet + 4, TS_PAYLOAD_SIZE); packet[3] |= 0x80; // set encryption into header for odd cw } write(STDOUT_FILENO, packet, TS_PACKET_SIZE); } dvbcsa_key_free(key); return 0; } opencaster-3.2.2/tools/tsfixcc/0000755000175000017500000000000012214326444015714 5ustar debiandebianopencaster-3.2.2/tools/tsfixcc/tsfixcc.c0000644000175000017500000000465712214326444017537 0ustar debiandebian/* * Copyright (C) 2008-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #define TS_PACKET_SIZE 188 #define MAX_PID 8192 int main(int argc, char *argv[]) { int open_file; int byte_read; int fd_ts; /* File descriptor of ts file */ unsigned short pid; unsigned char packet[TS_PACKET_SIZE]; unsigned char pid_cc_table[MAX_PID]; /* PID table for the continuity counter of the TS packets */ /* Open first ts file */ if (argc >= 2) { open_file = 1; fd_ts = open(argv[open_file], O_RDONLY); if (fd_ts < 0) { fprintf(stderr, "Can't find file %s\n", argv[open_file]); return 2; } } else { fprintf(stderr, "Usage: 'tsfixcc filename.ts > filenamefixed.ts'\n"); fprintf(stderr, "Tsfixcc increases countinuity counter of every packet following each other without adapatation field parsing'\n"); fprintf(stderr, "Useful to link ts of sections in a single ts'\n"); return 2; } /* Start to process the file */ memset(pid_cc_table, 0x10, MAX_PID); while(1) { /* read packets */ byte_read = 0; byte_read = read(fd_ts, packet, TS_PACKET_SIZE); if (byte_read < TS_PACKET_SIZE) { return 0; } /* stamp packet cc */ memcpy(&pid, packet + 1, 2); pid = ntohs(pid); pid = pid & 0x1fff; if (pid < MAX_PID) { if (pid_cc_table[pid] == 0x10) { fprintf(stderr, "new pid entry %d\n", pid); pid_cc_table[pid] = 0; } else { pid_cc_table[pid] = (pid_cc_table[pid] + 1) % 0x10; } packet[3] = (pid_cc_table[pid] | (packet[3] & 0xf0)); } /* write packet */ write(STDOUT_FILENO, packet, TS_PACKET_SIZE); } } opencaster-3.2.2/tools/tsfixcc/Makefile0000755000175000017500000000062512214326444017362 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = tsfixcc.o TARGET = tsfixcc DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/tsudpreceive/0000755000175000017500000000000012232257151016751 5ustar debiandebianopencaster-3.2.2/tools/tsudpreceive/tsudpreceive.c0000644000175000017500000000573512232257151021631 0ustar debiandebian/* * Copyright (C) 2008-2013, Lorenzo Pallara l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #define MULTICAST #include #include #include #include #include #include #include #include #include #include #include #define UDP_MAXIMUM_SIZE 65535 /* theoretical maximum size */ int main(int argc, char* argv[]) { int sockfd; struct sockaddr_in addr; #ifdef ip_mreqn struct ip_mreqn mgroup;XXX #else /* according to http://lists.freebsd.org/pipermail/freebsd-current/2007-December/081080.html in bsd it is also possible to simply use ip_mreq instead of ip_mreqn (same as in Linux), so we are using this instead */ struct ip_mreq mgroup; #endif int reuse; unsigned int addrlen; int len; unsigned char udp_packet[UDP_MAXIMUM_SIZE]; if (argc != 3) { fprintf(stderr, "Usage: %s ip_addr port > output.ts\n", argv[0]); return 0; } else { memset((char *) &mgroup, 0, sizeof(mgroup)); mgroup.imr_multiaddr.s_addr = inet_addr(argv[1]); #ifdef ip_mreqn mgroup.imr_address.s_addr = INADDR_ANY; #else /* this is called 'interface' here */ mgroup.imr_interface.s_addr = INADDR_ANY; #endif memset((char *) &addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(atoi(argv[2])); addr.sin_addr.s_addr = inet_addr(argv[1]); addrlen = sizeof(addr); } sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd < 0) { perror("socket(): error "); return 0; } reuse = 1; if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse, sizeof(reuse)) < 0) { perror("setsockopt() SO_REUSEADDR: error "); } if (bind(sockfd, (struct sockaddr*)&addr, sizeof(addr)) < 0) { perror("bind(): error"); close(sockfd); return 0; } if (setsockopt(sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&mgroup, sizeof(mgroup)) < 0) { perror("setsockopt() IPPROTO_IP: error "); close(sockfd); return 0; } while(1) { len = recvfrom(sockfd, udp_packet, UDP_MAXIMUM_SIZE, 0, (struct sockaddr *) &addr,&addrlen); if (len < 0) { perror("recvfrom(): error "); } else { write(STDOUT_FILENO, udp_packet, len); } } } opencaster-3.2.2/tools/tsudpreceive/Makefile0000644000175000017500000000063712214326444020421 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = tsudpreceive.o TARGET = tsudpreceive DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/dsmcc-receive/0000755000175000017500000000000012232256710016760 5ustar debiandebianopencaster-3.2.2/tools/dsmcc-receive/table.c0000644000175000017500000000506612214326444020224 0ustar debiandebian/* * table.c */ /* * Copyright (C) 2008, Lorenzo Pallara * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include #include #include #include #include "dsmcc.h" #include "carousel.h" #include "biop.h" #include "utils.h" #include "table.h" #define SECTION_HEADER_SIZE 3 int read_dsmcc_tables(struct carousel *car, unsigned char* buffer) { int result = 0; u_char section_head[SECTION_HEADER_SIZE]; u_short temp = 0; int section_size = 0; int found = 0; verbose("reading dsmcc tables\n"); while (!found) { if (read(STDIN_FILENO, section_head, SECTION_HEADER_SIZE)) { /* Parse datagram section size */ memcpy(&temp, section_head + 1, 2); temp = ntohs(temp); temp &= 0x0FFF; section_size = temp; fprintf(stderr, "section size is %d\n", section_size); /* Read all the section */ if (section_size <= (MAX_TABLE_LEN - SECTION_HEADER_SIZE)) { memcpy(buffer, section_head, SECTION_HEADER_SIZE); read(STDIN_FILENO, buffer + SECTION_HEADER_SIZE, section_size); result = section_size; if (buffer[0] & 0x3F) { found = 1; } } else { fprintf(stderr, "found section too big, size is %d, skipped, section_size\n", section_size); } } else { found = 1; result = -1; } } /* hexdump(buffer, result); */ verbose("reading dsmcc table done\n"); return result; } void add_dsmcc_pid(struct carousel *car, uint16_t pid) { ; } int read_dsi_dii_tables(struct carousel *car, unsigned char* buffer) { int found = 0; int result = 0; while(!found) { result = read_dsmcc_tables(car, buffer); if (result > 0) { if (buffer[0] & 0x3B) { found = 1; } } else { found = 1; } } verbose("reading dsi dii table done\n"); return result; } opencaster-3.2.2/tools/dsmcc-receive/assoc.c0000644000175000017500000000334212214326444020240 0ustar debiandebian/* * assoc.c * * maps stream_id_descriptors to elementary_PID numbers */ /* * Copyright (C) 2005, Simon Kilvington * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include "assoc.h" #include "utils.h" void init_assoc(struct assoc *a) { a->nassocs = 0; a->pids = NULL; a->sids = NULL; return; } void add_assoc(struct assoc *a, uint16_t elementary_pid, uint16_t stream_id) { a->nassocs ++; a->pids = safe_realloc(a->pids, a->nassocs * sizeof(uint16_t)); a->sids = safe_realloc(a->sids, a->nassocs * sizeof(uint16_t)); a->pids[a->nassocs - 1] = elementary_pid; a->sids[a->nassocs - 1] = stream_id; return; } uint16_t stream2pid(struct assoc *a, uint16_t stream_id) { unsigned int i; for(i=0; inassocs; i++) { if(a->sids[i] == stream_id) return a->pids[i]; } error("Unknown PID for association tag 0x%x", stream_id); return 0; } void clean_assoc(struct assoc *a) { if (a != 0) { if (a->pids != 0) { safe_free(a->pids); } if (a->sids != 0) { safe_free(a->sids); } } } opencaster-3.2.2/tools/dsmcc-receive/utils.h0000644000175000017500000000267312214326444020303 0ustar debiandebian/* * utils.h */ /* * Copyright (C) 2005, Simon Kilvington * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef __UTILS_H__ #define __UTILS_H__ #include #include #include #ifndef MAX #define MAX(a, b) ((a) > (b) ? (a) : (b)) #endif void increase_verbose(void); void set_verbose(int verbose); char *skip_ws(char *); char hex_digit(uint8_t); void *safe_malloc(size_t); void *safe_realloc(void *, size_t); void safe_free(void *); void hexdump(unsigned char *, size_t); void error(char *, ...); void fatal(char *, ...); /* in rb-download.c */ void verbose(char *, ...); void vverbose(char *, ...); void vhexdump(unsigned char *, size_t); int timeval_subtract (struct timeval *result,struct timeval *x,struct timeval *y); #endif /* __UTILS_H__ */ opencaster-3.2.2/tools/dsmcc-receive/Makefile0000644000175000017500000000101612214326444020420 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc -lz OBJS= dsmcc-receive.o \ carousel.o \ module.o \ dsmcc.o \ biop.o \ filter.o \ fs.o \ table.o \ assoc.o \ util.o TARGET = dsmcc-receive DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/dsmcc-receive/dsmcc.h0000644000175000017500000001036212214326444020226 0ustar debiandebian/* * dsmcc.h * * data types for ISO/IEC 13818-6 DSM-CC specs * * all values are big endian */ /* * Copyright (C) 2005, Simon Kilvington * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef __DSMCC_H__ #define __DSMCC_H__ #include /* * header for all DSM-CC messages */ struct dsmccMessageHeader { uint8_t protocolDiscriminator; /* 0x11 */ uint8_t dsmccType; uint16_t messageId; uint32_t transactionId; /* downloadId for dsmccDownloadDataHeader */ uint8_t reserved; /* 0xff */ uint8_t adaptionLength; uint16_t messageLength; /* includes adaptionLength */ /* dsmccAdaptionHeader, if adaptionLength > 0 */ /* (messageLength - adaptionLength) bytes of message data */ } __attribute__((__packed__)); /* protocolDiscriminator */ #define DSMCC_PROTOCOL 0x11 /* dsmccType values we are interested in */ #define DSMCC_TYPE_DOWNLOAD 0x03 /* messageId values for DSMCC_TYPE_DOWNLOAD we are interested in */ /* control messages - have a dsmccMessageHeader */ #define DSMCC_MSGID_DII 0x1002 /* DownloadInfoIndication */ #define DSMCC_MSGID_DSI 0x1006 /* DownloadServerInitiate */ /* data messages - have a dsmccDownloadDataHeader */ #define DSMCC_MSGID_DDB 0x1003 /* DownloadDataBlock */ /* helper function */ unsigned char *dsmccMessage(struct dsmccMessageHeader *); /* * CompatibilityDescriptor * used in various messages */ struct CompatibilityDescriptor { uint16_t compatibilityDescriptorLength; /* uint8_t data[compatibilityDescriptorLength] */ } __attribute__((__packed__)); /* * DownloadInfoIndication message * preceeded by a dsmccMessageHeader * the transactionId is used as a version number, * if it changes the data has changed and must be downloaded again */ struct DownloadInfoIndication { uint32_t downloadId; /* to match DDB messages */ uint16_t blockSize; uint8_t windowSize; uint8_t ackPeriod; uint32_t tCDownloadWindow; uint32_t tCDownloadScenario; struct CompatibilityDescriptor compatibilityDescriptor; /* uint16_t numberOfModules */ /* struct DIIModule module[numberOfModules] */ /* unit16_t privateDataLength */ /* uint8_t privateDataByte[privateDataLength] */ } __attribute__((__packed__)); struct DIIModule { uint16_t moduleId; uint32_t moduleSize; uint8_t moduleVersion; uint8_t moduleInfoLength; /* uint8_t moduleInfoByte[moduleInfoLength] */ } __attribute__((__packed__)); /* helper functions */ uint16_t DII_numberOfModules(struct DownloadInfoIndication *); struct DIIModule *DII_module(struct DownloadInfoIndication *, uint16_t); /* * DownloadDataBlock message * preceeded by a dsmccDownloadDataHeader * (same as a dsmccMessageHeader except the transactionId is called downloadId) */ struct DownloadDataBlock { uint16_t moduleId; uint8_t moduleVersion; uint8_t reserved; /* 0xff */ uint16_t blockNumber; /* starts at 0 */ /* uint8_t blockDataByte[N] size determined by header.messageLength */ } __attribute__((__packed__)); /* helper functions */ uint32_t DDB_blockDataLength(struct dsmccMessageHeader *); unsigned char *DDB_blockDataByte(struct DownloadDataBlock *); /* * DownloadServerInitiate message * preceeded by a dsmccMessageHeader */ struct DownloadServerInitiate { /* ETSI say serverId should be 20 0xff bytes */ uint8_t serverId[20]; /* ETSI say the compatibilityDescriptorLength should be 0 */ struct CompatibilityDescriptor compatibilityDescriptor; /* ETSI say the privateData is a BIOP::ServiceGatewayInfo */ uint16_t privateDataLength; /* uint8_t privateDataByte[privateDataLength] */ } __attribute__((__packed__)); /* helper */ unsigned char *DSI_privateDataByte(struct DownloadServerInitiate *); #endif /* __DSMCC_H__ */ opencaster-3.2.2/tools/dsmcc-receive/table.h0000644000175000017500000000210212214326444020215 0ustar debiandebian/* * table.h */ /* * Copyright (C) 2005, Simon Kilvington * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef __TABLE_H__ #define __TABLE_H__ #include #include "module.h" #define MAX_TABLE_LEN 4096 int read_dsmcc_tables(struct carousel *, unsigned char*); int read_dsi_dii_tables(struct carousel *, unsigned char*); void add_dsmcc_pid(struct carousel *, uint16_t); #endif /* __TABLE_H__ */ opencaster-3.2.2/tools/dsmcc-receive/dsmcc.c0000644000175000017500000000627512214326444020231 0ustar debiandebian/* * dsmcc.c * * helper functions for handling data types for ISO/IEC 13818-6 DSM-CC specs */ /* * Copyright (C) 2005, Simon Kilvington * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include "dsmcc.h" #include "utils.h" /* * return a ptr to the message following the dsmccMessageHeader */ unsigned char * dsmccMessage(struct dsmccMessageHeader *hdr) { unsigned char *byte = (unsigned char *) hdr; unsigned int offset; offset = sizeof(struct dsmccMessageHeader); offset += hdr->adaptionLength; return &byte[offset]; } /* * return the numberOfModules field in a DownloadInfoIndication */ uint16_t DII_numberOfModules(struct DownloadInfoIndication *dii) { unsigned char *byte = (unsigned char *) dii; unsigned int offset; offset = sizeof(struct DownloadInfoIndication); offset += ntohs(dii->compatibilityDescriptor.compatibilityDescriptorLength); /* uint16_t numberOfModules */ return (byte[offset] << 8) + byte[offset + 1]; } /* * return info for module n in a DownloadInfoIndication * numbering starts at 0 */ struct DIIModule * DII_module(struct DownloadInfoIndication *dii, uint16_t n) { unsigned char *byte = (unsigned char *) dii; unsigned int offset; struct DIIModule *mod; /* assert */ if(n >= DII_numberOfModules(dii)) fatal("DII_module: index too large"); /* offset to first module */ offset = sizeof(struct DownloadInfoIndication); offset += ntohs(dii->compatibilityDescriptor.compatibilityDescriptorLength); offset += sizeof(uint16_t); /* numberOfModules */ /* find the module we want */ while(n != 0) { n --; mod = (struct DIIModule *) &byte[offset]; offset += sizeof(struct DIIModule); offset += mod->moduleInfoLength; } return (struct DIIModule *) &byte[offset]; } /* * returns the number of bytes of data in the DDB block */ uint32_t DDB_blockDataLength(struct dsmccMessageHeader *hdr) { uint32_t length; length = ntohs(hdr->messageLength); length -= hdr->adaptionLength; length -= sizeof(struct DownloadDataBlock); return length; } /* * returns a ptr to the data bytes in the DDB block */ unsigned char * DDB_blockDataByte(struct DownloadDataBlock *ddb) { return ((unsigned char *) ddb) + sizeof(struct DownloadDataBlock); } /* * returns a ptr to the private data bytes in the DSI block */ unsigned char * DSI_privateDataByte(struct DownloadServerInitiate *dsi) { /* assert */ if(dsi->compatibilityDescriptor.compatibilityDescriptorLength != 0) fatal("Unexpected DSI format"); return ((unsigned char *) dsi) + sizeof(struct DownloadServerInitiate); } opencaster-3.2.2/tools/dsmcc-receive/filter.c0000644000175000017500000000033712214326444020416 0ustar debiandebian#include #include #include #include #include #include #include #include "filter.h" void closePidFiltering (int filter_id) { ; } opencaster-3.2.2/tools/dsmcc-receive/dsmcc-receive.c0000644000175000017500000000615312214326444021644 0ustar debiandebian/* * Copyright (C) 2008-2013, Lorenzo Pallara l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #define _BSD_SOURCE 1 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "carousel.h" #include "utils.h" #include "table.h" void usage(char *); int main(int argc, char *argv[]) { char* directory = 0; int cachesize = 0; int result = 0; int pid = 0; int component_tag = 0; if (argc != 5) { usage(argv[0]); return 0; } else { directory = argv[1]; cachesize = atoi(argv[2]); pid = atoi(argv[3]); component_tag = atoi(argv[4]); } struct carousel a_carousel; a_carousel.timeout = 60; /* 1 minute, not used for dsmcc-receive */ a_carousel.service_id = 1; /* not used for dsmcc-receive */ a_carousel.carousel_id = 0; /* not used for dsmcc-receive */ a_carousel.npids = 0; a_carousel.pids = NULL; a_carousel.got_dsi = 0; a_carousel.nmodules = 0; a_carousel.modules = NULL; a_carousel.stop = 0; a_carousel.completed = 0; a_carousel.current_pid = pid; /* not used for dsmcc-receive */ add_dsmcc_pid(&a_carousel, pid); /* a carousel can be received from multiple PIDs, add the first we have found, this must carry DSI table or won't load */ init_assoc(&(a_carousel.assoc)); add_assoc(&(a_carousel.assoc), pid, component_tag); /* set the mapping between stream_id_descriptors and elementary_PIDs, not used for dsmcc-receive */ set_verbose(1); /* 1, 2, 3 */ fprintf(stdout, "info: loading carousel on directory %s\n", directory); /* * the file structure will be: * directory/services/ * this is a symlink to the root of the carousel * the actual carousel files and directories are stored under: * directory/carousels/// * where is the PID the carousel was downloaded from * and is the Carousel ID */ result = load_carousel(directory, &(a_carousel), cachesize); clean_assoc(&(a_carousel.assoc)); fprintf(stdout, "info: load carousel done\n"); return result; } void usage(char *prog_name) { fatal("Usage: %s output_directory cache_size pid component_tag < file.sec", prog_name); } opencaster-3.2.2/tools/dsmcc-receive/biop.h0000644000175000017500000000620012214326444020062 0ustar debiandebian/* * biop.h * * BIOP data types from ISO/IEC 13818-6 */ /* * Copyright (C) 2005, Simon Kilvington * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef __BIOP_H__ #define __BIOP_H__ #include #include "carousel.h" #include "assoc.h" struct BIOPVersion { uint8_t major; uint8_t minor; } __attribute__((__packed__)); struct BIOPMessageHeader { char magic[4]; /* 'BIOP' */ struct BIOPVersion biop_version; /* 1.0 */ uint8_t byte_order; /* 0 = big endian */ uint8_t message_type; /* should be 0 */ uint32_t message_size; /* not including this header */ } __attribute__((__packed__)); /* magic header value */ #define BIOP_MAGIC_STR "BIOP" #define BIOP_MAGIC_LEN 4 /* version we are expecting */ #define BIOP_VSN_MAJOR 1 #define BIOP_VSN_MINOR 0 /* byte order */ #define BIOP_BIGENDIAN 0 /* message type we are expecting */ #define BIOP_MSG_TYPE 0 /* objectKind types */ #define BIOP_DIR "dir" #define BIOP_FILE "fil" #define BIOP_STREAM "str" #define BIOP_SERVICEGATEWAY "srg" #define BIOP_STREAMEVENT "ste" /* IOP::IOR profileId_tag values */ #define TAG_BIOP 0x49534f06 #define TAG_LITE_OPTIONS 0x49534f05 /* BIOP::ObjectLocation tag */ #define TAG_ObjectLocation 0x49534f50 /* DSM::ConnBinder tag */ #define TAG_ConnBinder 0x49534f40 /* use types */ #define BIOP_DELIVERY_PARA_USE 0x0016 /* selector_type we are expecting */ #define SELECTOR_TYPE_MESSAGE_LEN 0x0a #define SELECTOR_TYPE_MESSAGE 0x0001 /* data type to hold a sequence */ struct biop_sequence { uint32_t size; unsigned char *data; }; /* data type to hold an IOP::IOR object reference */ struct biop_iop_ior { uint16_t association_tag; /* maps to an elementary_PID */ uint32_t carousel_id; uint16_t module_id; struct biop_sequence key; }; /* functions */ bool process_biop(char* paramDir, struct carousel *, struct module *, struct BIOPMessageHeader *, uint32_t); void process_biop_dir(char* paramDir, uint8_t, char *, struct carousel *, unsigned char *, uint32_t); uint32_t process_iop_ior(uint8_t, unsigned char *, struct biop_iop_ior *); uint16_t process_biop_service_gateway_info(char* paramDir, uint16_t, struct assoc *, unsigned char *, uint16_t); uint16_t biop_uint16(uint8_t, uint16_t); uint32_t biop_uint32(uint8_t, uint32_t); uint32_t biop_sequence255(unsigned char *, struct biop_sequence *); uint32_t biop_sequence65535(uint8_t, unsigned char *, struct biop_sequence *); uint32_t biop_sequence(uint8_t, unsigned char *, struct biop_sequence *); uint32_t biop_align32(uint32_t); #endif opencaster-3.2.2/tools/dsmcc-receive/fs.c0000644000175000017500000002117512232256710017542 0ustar debiandebian/* * fs.c * * file system interactions * files get stored under a directory named after their carousel ID * the filename includes the module ID and the object key * when we download a directory we create a directory in our carousel directory * and fill it with sym links to the actual files and dirs it contains * (the sym links maybe dangling if we have not downloaded all the files yet) * * we also create a symlink that points to the Service Gateway dir */ /* * Copyright (C) 2005, Simon Kilvington * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include #include "fs.h" #include "biop.h" #include "utils.h" #ifndef PATH_MAX #define PATH_MAX 4096 #endif static char _carousel_root[PATH_MAX]; char * make_carousel_root(char * paramDir, uint16_t elementary_pid, uint32_t carousel_id) { /* make the hierarchy */ snprintf(_carousel_root, sizeof(_carousel_root), "%s/%s", paramDir, CAROUSELS_DIR); if(mkdir(_carousel_root, 0755) < 0 && errno != EEXIST) fatal("Unable to create carousel directory '%s': %s", _carousel_root, strerror(errno)); snprintf(_carousel_root, sizeof(_carousel_root), "%s/%s/%u", paramDir, CAROUSELS_DIR, elementary_pid); if(mkdir(_carousel_root, 0755) < 0 && errno != EEXIST) fatal("Unable to create carousel directory '%s': %s", _carousel_root, strerror(errno)); snprintf(_carousel_root, sizeof(_carousel_root), "%s/%s/%u/%u", paramDir, CAROUSELS_DIR, elementary_pid, carousel_id); if(mkdir(_carousel_root, 0755) < 0 && errno != EEXIST) fatal("Unable to create carousel directory '%s': %s", _carousel_root, strerror(errno)); return _carousel_root; } void save_file(char* paramDir, char *kind, uint16_t elementary_pid, uint32_t carousel_id, uint16_t module_id, char *key, uint32_t key_size, char *file, uint32_t file_size, uint8_t module_version) { char *root; char *ascii_key; char filename[PATH_MAX]; FILE *f; /* make sure the carousel directory exists */ root = make_carousel_root(paramDir, elementary_pid, carousel_id); /* BBC use numbers as object keys, so convert to a text value we can use as a file name */ ascii_key = convert_key(key, key_size); /* construct the file name */ snprintf(filename, sizeof(filename), "%s/%s-%u-%s", root, kind, module_id, ascii_key); if((f = fopen(filename, "wb")) == NULL) fatal("Unable to create file '%s': %s", filename, strerror(errno)); if(fwrite(file, 1, file_size, f) != file_size) fatal("Unable to write to file '%s'", filename); fclose(f); verbose("Created file '%s'\n", filename); snprintf(filename, sizeof(filename), "%s/%s-%u-%s.version", root, kind, module_id, ascii_key); if((f = fopen(filename, "wb")) == NULL) fatal("Unable to create file '%s': %s", filename, strerror(errno)); if(fwrite(&module_version, 1, 1, f) != 1) fatal("Unable to write to file '%s'", filename); fclose(f); return; } /* * creates the symlink services/ * it points to the given Service Gateway object */ void make_service_root(char* paramDir, uint16_t service_id, char *kind, uint16_t elementary_pid, uint32_t carousel_id, uint16_t module_id, char *key, uint32_t key_size) { char dirname[PATH_MAX]; char *ascii_key; char realfile[PATH_MAX]; char linkfile[PATH_MAX]; /* make sure the services directory exists */ snprintf(dirname, sizeof(dirname), "%s", paramDir); if(mkdir(dirname, 0755) < 0 && errno != EEXIST) fatal("Unable to create services directory '%s': %s", dirname, strerror(errno)); snprintf(dirname, sizeof(dirname), "%s/%s", paramDir, SERVICES_DIR); if(mkdir(dirname, 0755) < 0 && errno != EEXIST) fatal("Unable to create services directory '%s': %s", dirname, strerror(errno)); /* BBC use numbers as object keys, so convert to a text value we can use as a file name */ ascii_key = convert_key(key, key_size); /* create a symlink to the Service Gateway dir */ if (paramDir[0] == '/') { snprintf(realfile, sizeof(realfile), "../../%s/%s/%u/%u/%s-%u-%s", paramDir+1, CAROUSELS_DIR, elementary_pid, carousel_id, kind, module_id, ascii_key); } else { snprintf(realfile, sizeof(realfile), "../../%s/%s/%u/%u/%s-%u-%s", paramDir, CAROUSELS_DIR, elementary_pid, carousel_id, kind, module_id, ascii_key); } snprintf(linkfile, sizeof(linkfile), "%s/%u", dirname, service_id); /* * linkfile may already exist if we get an update to an existing module * if linkfile already exists, symlink will not update it * so delete it first to make sure the link gets updated */ unlink(linkfile); if(symlink(realfile, linkfile) < 0 && errno != EEXIST) fatal("Unable to create link '%s' to '%s': %s", linkfile, realfile, strerror(errno)); verbose("Added service root '%s' -> '%s'\n", linkfile, realfile); return; } /* * returns a ptr to the directory name * the name will be overwritten by the next call to this routine */ static char _dirname[PATH_MAX]; char * make_dir(char* paramDir, char *kind, uint16_t elementary_pid, uint32_t carousel_id, uint16_t module_id, char *key, uint32_t key_size, uint8_t module_version) { char *root; char *ascii_key; FILE *f; char filename[PATH_MAX]; /* make sure the carousel directory exists */ root = make_carousel_root(paramDir, elementary_pid, carousel_id); /* BBC use numbers as object keys, so convert to a text value we can use as a file name */ ascii_key = convert_key(key, key_size); snprintf(_dirname, sizeof(_dirname), "%s/%s-%u-%s", root, kind, module_id, ascii_key); /* may already exist if we get an updated version of it */ if(mkdir(_dirname, 0755) < 0 && errno != EEXIST) fatal("Unable to create directory '%s': %s", _dirname, strerror(errno)); verbose("Created directory '%s'\n", _dirname); snprintf(filename, sizeof(filename), "%s/%s-%u-%s.version", root, kind, module_id, ascii_key); if((f = fopen(filename, "wb")) == NULL) fatal("Unable to create file '%s': %s", filename, strerror(errno)); if(fwrite(&module_version, 1, 1, f) != 1) fatal("Unable to write to file '%s'", filename); fclose(f); return _dirname; } /* * adds a sym link to the real file to the given directory * the real file may not exist if it has not been downloaded yet */ void add_dir_entry(char* paramDir, char *dir, char *entry, uint32_t entry_size, char *kind, uint16_t elementary_pid, uint32_t carousel_id, uint16_t module_id, char *key, uint32_t key_size) { char *ascii_key; char realfile[PATH_MAX]; char linkfile[PATH_MAX]; /* BBC use numbers as object keys, so convert to a text value we can use as a file name */ ascii_key = convert_key(key, key_size); if (paramDir[0] == '/') { snprintf(realfile, sizeof(realfile), "../../../../../%s/%s/%u/%u/%s-%u-%s", paramDir + 1, CAROUSELS_DIR, elementary_pid, carousel_id, kind, module_id, ascii_key); } else { snprintf(realfile, sizeof(realfile), "../../../../../%s/%s/%u/%u/%s-%u-%s", paramDir, CAROUSELS_DIR, elementary_pid, carousel_id, kind, module_id, ascii_key); } snprintf(linkfile, sizeof(linkfile), "%s/%.*s", dir, entry_size, entry); /* * linkfile may already exist if we get an update to an existing module * if linkfile already exists, symlink will not update it * so delete it first to make sure the link gets updated */ unlink(linkfile); if(symlink(realfile, linkfile) < 0) fatal("Unable to create link '%s' to '%s': %s", linkfile, realfile, strerror(errno)); verbose("Added directory entry '%s' -> '%s'\n", linkfile, realfile); return; } /* * BBC use numbers as object keys, ITV/C4 use ascii strings * we want an ascii string we can use as a filename * returns a static string that will be overwritten by the next call to this function */ static char _ascii_key[PATH_MAX]; char * convert_key(char *key, uint32_t size) { uint32_t i; /* assert */ if(sizeof(_ascii_key) < (size * 2) + 1) fatal("objectKey too long"); /* convert to a string of hex byte values */ for(i=0; i> 4) & 0x0f); _ascii_key[(i * 2) + 1] = hex_digit(key[i] & 0x0f); } _ascii_key[size * 2] = '\0'; return _ascii_key; } opencaster-3.2.2/tools/dsmcc-receive/assoc.h0000644000175000017500000000222612214326444020245 0ustar debiandebian/* * assoc.h * * maps stream_id_descriptors to elementary_PID numbers */ /* * Copyright (C) 2005, Simon Kilvington * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef __ASSOC_H__ #define __ASSOC_H__ #include struct assoc { unsigned int nassocs; uint16_t *pids; uint16_t *sids; }; void init_assoc(struct assoc *); void add_assoc(struct assoc *, uint16_t, uint16_t); void clean_assoc(struct assoc *); uint16_t stream2pid(struct assoc *, uint16_t); #endif /* __ASSOC_H__ */ opencaster-3.2.2/tools/dsmcc-receive/module.h0000644000175000017500000000630212214326444020421 0ustar debiandebian/* * module.h */ /* * Copyright (C) 2005, Simon Kilvington * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef __MODULE_H__ #define __MODULE_H__ #include #include #include #include #include "dsmcc.h" #include "assoc.h" /* PIDs we are reading */ struct pid_fds { uint16_t pid; /* DVB programme ID */ bool dsidii_only; /* true if receive only dsidii */ int filterid; /* id of the current open filter if any */ }; /* data about each module */ struct module { uint16_t module_id; uint32_t download_id; uint8_t version; uint16_t block_size; uint16_t nblocks; uint32_t blocks_left; /* number of blocks left to download */ bool *got_block; /* which blocks we have downloaded so far */ uint32_t size; /* size of the file */ unsigned char *data; /* the actual file data */ }; /* the whole carousel */ struct carousel { unsigned int timeout; /* timeout for the DVB devices */ pid_t downloader; /* ID of the process downloading the carousel */ uint16_t network_id; /* Original Network ID */ uint16_t service_id; /* Service ID we are downloading the carousel from */ uint32_t carousel_id; /* Carousel ID we are downloading */ uint16_t boot_pid; /* PID containing DSI */ uint16_t audio_pid; /* PID of default audio stream for this service_id */ uint8_t audio_type; /* type ID of default audio stream */ uint16_t video_pid; /* PID of default video stream for this service_id */ uint8_t video_type; /* type ID of default video stream */ uint16_t current_pid; /* PID we downloaded the last table from */ struct assoc assoc; /* map stream_id's to elementary_pid's */ int32_t npids; /* PIDs we are reading data from */ struct pid_fds *pids; /* array, npids in length */ bool got_dsi; /* true if we have downloaded the DSI */ bool completed; /* true if all the carousel has been retrived and versions are consistent */ uint32_t nmodules; /* modules we have/are downloading */ struct module *modules; /* array, nmodules in length */ bool stop; /* set to true to stop the carousel loading */ bool used; /* set to true if in use */ }; /* functions */ struct module *find_module(struct carousel *, uint16_t, uint8_t, uint32_t); struct module *add_module(struct carousel *, struct DownloadInfoIndication *, struct DIIModule *); void delete_module(struct carousel *, uint32_t); void free_module(struct module *); void download_block(char* paramDir, struct carousel *, struct module *, uint16_t, unsigned char *, uint32_t); int uncompress_module(struct module *); #endif /* __MODULE_H__ */ opencaster-3.2.2/tools/dsmcc-receive/fs.h0000644000175000017500000000265412214326444017552 0ustar debiandebian/* * fs.h * * file system interactions */ /* * Copyright (C) 2005, Simon Kilvington * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef __FS_H__ #define __FS_H__ /* directories */ #define SERVICES_DIR "services" #define CAROUSELS_DIR "carousels" char *make_carousel_root(char *, uint16_t, uint32_t); void save_file(char*, char *, uint16_t, uint32_t, uint16_t, char *, uint32_t, char *, uint32_t, uint8_t); void make_service_root(char *, uint16_t, char *, uint16_t, uint32_t, uint16_t, char *, uint32_t); char *make_dir(char *,char *, uint16_t, uint32_t, uint16_t, char *, uint32_t, uint8_t); void add_dir_entry(char *, char *, char *, uint32_t, char *, uint16_t, uint32_t, uint16_t, char *, uint32_t); char *convert_key(char *, uint32_t); #endif /* __FS_H__ */ opencaster-3.2.2/tools/dsmcc-receive/carousel.h0000644000175000017500000000237312214326444020755 0ustar debiandebian/* * carousel.h */ /* * Copyright (C) 2005, Simon Kilvington * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef __CAROUSEL_H__ #define __CAROUSEL_H__ #include #include "module.h" #include "dsmcc.h" /* functions */ int load_carousel(char* paramDir, struct carousel *, int cache_size); int process_dii(struct carousel *, struct DownloadInfoIndication *, uint32_t); void process_dsi(char* paramDir, struct carousel *, struct DownloadServerInitiate *); int process_ddb(char* paramDir, struct carousel *, struct DownloadDataBlock *, uint32_t, uint32_t); #endif /* __CAROUSEL_H__ */ opencaster-3.2.2/tools/dsmcc-receive/carousel.c0000644000175000017500000001627212214326444020753 0ustar debiandebian/* * carousel.c */ /* * Copyright (C) 2008-2013, Lorenzo Pallara l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include "carousel.h" #include "table.h" #include "dsmcc.h" #include "biop.h" #include "utils.h" int load_carousel(char* paramDir, struct carousel *car, int cache_size) { int result = 3; int processed; int index; int completed_modules; int i = 0; unsigned char table[MAX_TABLE_LEN]; /* no modules yet */ car->nmodules = 0; car->modules = NULL; /* tables cached */ unsigned char* used_slot = safe_malloc(sizeof(unsigned char) * cache_size); unsigned char* cached = safe_malloc(MAX_TABLE_LEN * cache_size); memset(used_slot, 0, cache_size); /* see what the next DSMCC table is */ do { struct dsmccMessageHeader *dsmcc; if (!car->completed) { if(read_dsmcc_tables(car, table) < 0) { fatal("Unable to read PID"); result = 1; // timeout car->stop = 1; } } else { // dsmcc can update itself, keep on reading for dii/dsi changes until we get a complete file system of the same version if(read_dsi_dii_tables(car, table) < 0) { fatal("Unable to read PID"); result = 1; // timeout car->stop = 1; } } if (!car->stop) { dsmcc = (struct dsmccMessageHeader *) &table[8]; if(dsmcc->protocolDiscriminator == DSMCC_PROTOCOL && dsmcc->dsmccType == DSMCC_TYPE_DOWNLOAD) { if(ntohs(dsmcc->messageId) == DSMCC_MSGID_DII) { processed = process_dii(car, (struct DownloadInfoIndication *) dsmccMessage(dsmcc), ntohl(dsmcc->transactionId)); if (processed) { verbose("Checking cached tables"); unsigned char* cached_table; for (index = 0; index < cache_size; index++) { if (used_slot[index] == 1) { cached_table = cached + (index * MAX_TABLE_LEN); dsmcc = (struct dsmccMessageHeader *) &cached_table[8]; processed = process_ddb(paramDir, car, (struct DownloadDataBlock *) dsmccMessage(dsmcc), ntohl(dsmcc->transactionId), DDB_blockDataLength(dsmcc)); if (processed) { verbose("DDB processed from cache index: %d", index); used_slot[index] = 0; } } } car->completed = 0; } else if (car->nmodules > 0) { verbose("Check if all modules are completed, modules number is %d", car->nmodules); completed_modules = 0; for (i = 0; i < car->nmodules; i++) { if ((car->modules[i]).blocks_left == 0) { completed_modules++; } verbose("module id %d, blocks_left %d", (car->modules[i]).module_id, (car->modules[i]).blocks_left); } verbose("completed are %d", completed_modules); /* remove this to make it run endless */ if (completed_modules == car->nmodules) { car->completed= 1; verbose("carousels completed, check dii update"); } } } else if(ntohs(dsmcc->messageId) == DSMCC_MSGID_DSI) { process_dsi(paramDir, car, (struct DownloadServerInitiate *) dsmccMessage(dsmcc)); } else if(ntohs(dsmcc->messageId) == DSMCC_MSGID_DDB) { processed = process_ddb(paramDir, car, (struct DownloadDataBlock *) dsmccMessage(dsmcc), ntohl(dsmcc->transactionId), DDB_blockDataLength(dsmcc)); if (!processed) { for (index = 0; index < cache_size; index++) { if (used_slot[index] == 0) { verbose("DDB not processed, adding to cache, index is: %d", index); memcpy(cached + (index * MAX_TABLE_LEN), table, MAX_TABLE_LEN); used_slot[index] = 1; index = cache_size; } } } } else { error("Unknown DSMCC messageId: 0x%x", ntohs(dsmcc->messageId)); } } } } while(!car->stop); verbose("Carousel stopped, doing cleanings "); for (i = 0; i < car->npids; i++) { if (car->pids[i].filterid >= 0) { closePidFiltering(car->pids[i].filterid); } } verbose("descriptor closed "); for (i = 0; i < car->nmodules; i++) { safe_free(car->modules[i].got_block); safe_free(car->modules[i].data); } verbose("modules block free "); safe_free(car->modules); verbose("modules free "); safe_free(car->pids); verbose("pid free "); safe_free(used_slot); safe_free(cached); verbose("cache free "); return result; } int process_dii(struct carousel *car, struct DownloadInfoIndication *dii, uint32_t transactionId) { unsigned int nmodules; unsigned int i; int processed = 0; verbose("DownloadInfoIndication "); vverbose("transactionId: %u, ", transactionId); vverbose("downloadId: %u, ", ntohl(dii->downloadId)); nmodules = DII_numberOfModules(dii); vverbose("numberOfModules: %u, ", nmodules); for(i=0; imoduleId)); vverbose(" moduleVersion: %u", mod->moduleVersion); vverbose(" moduleSize: %u", ntohl(mod->moduleSize)); if(find_module(car, ntohs(mod->moduleId), mod->moduleVersion, ntohl(dii->downloadId)) == NULL) { vverbose("Adding module %u", i); add_module(car, dii, mod); processed = 1; } } return processed; } void process_dsi(char* paramDir, struct carousel *car, struct DownloadServerInitiate *dsi) { uint16_t elementary_pid; verbose("DownloadServerInitiate"); /* only download DSI from boot pid */ /* if((car->current_pid != car->boot_pid) || car->got_dsi) return; */ if(car->got_dsi) return; /* actually should check for an updated version */ car->got_dsi = 1; elementary_pid = process_biop_service_gateway_info(paramDir, car->service_id, &car->assoc, DSI_privateDataByte(dsi), ntohs(dsi->privateDataLength)); // make sure we are downloading data from the PID the DSI refers to // add_dsmcc_pid(car, elementary_pid); return; } int process_ddb(char* paramDir, struct carousel *car, struct DownloadDataBlock *ddb, uint32_t downloadId, uint32_t blockLength) { unsigned char *block; struct module *mod; int processed = 0; verbose("DownloadDataBlock "); vverbose("downloadId: %u", downloadId); verbose("moduleId: %u", ntohs(ddb->moduleId)); vverbose("moduleVersion: %u", ddb->moduleVersion); verbose("blockNumber: %u", ntohs(ddb->blockNumber)); vverbose("blockLength: %u", blockLength); block = DDB_blockDataByte(ddb); vhexdump(block, blockLength); if((mod = find_module(car, ntohs(ddb->moduleId), ddb->moduleVersion, downloadId)) != NULL) { download_block(paramDir, car, mod, ntohs(ddb->blockNumber), block, blockLength); processed = 1; } return processed; } opencaster-3.2.2/tools/dsmcc-receive/filter.h0000644000175000017500000000005312214326444020416 0ustar debiandebian void closePidFiltering (int filter_id); opencaster-3.2.2/tools/dsmcc-receive/module.c0000644000175000017500000001235212214326444020416 0ustar debiandebian/* * module.c */ /* * Copyright (C) 2005, Simon Kilvington * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include "dsmcc.h" #include "carousel.h" #include "biop.h" #include "utils.h" /* * returns NULL if the module does not exist * if this is an update to a module we already have, the old one is deleted */ struct module * find_module(struct carousel *car, uint16_t module_id, uint8_t version, uint32_t download_id) { unsigned int i; for(i=0; inmodules; i++) { if(car->modules[i].module_id == module_id && car->modules[i].download_id == download_id) { /* spot on */ if(car->modules[i].version == version) { return &car->modules[i]; } /* is it an update to one we already have */ else if(car->modules[i].version != version) { delete_module(car, i); return NULL; } } } return NULL; } struct module * add_module(struct carousel *car, struct DownloadInfoIndication *dii, struct DIIModule *diimod) { struct module *mod; car->nmodules ++; car->modules = safe_realloc(car->modules, car->nmodules * sizeof(struct module)); mod = &car->modules[car->nmodules - 1]; mod->module_id = ntohs(diimod->moduleId); mod->download_id = ntohl(dii->downloadId); mod->version = diimod->moduleVersion; mod->block_size = ntohs(dii->blockSize); mod->nblocks = (ntohl(diimod->moduleSize) + mod->block_size - 1) / mod->block_size; mod->blocks_left = mod->nblocks; mod->got_block = safe_malloc(mod->nblocks * sizeof(bool)); bzero(mod->got_block, mod->nblocks * sizeof(bool)); mod->size = ntohl(diimod->moduleSize); mod->data = safe_malloc(mod->size); verbose("add_module: nmodules=%u module=%u size=%u", car->nmodules, mod->module_id, mod->size); return mod; } void delete_module(struct carousel *car, uint32_t num) { uint32_t size; free_module(&car->modules[num]); size = ((car->nmodules - 1) - num) * sizeof(struct module); if(size > 0) memmove(&car->modules[num], &car->modules[num + 1], size); car->nmodules --; return; } void free_module(struct module *mod) { safe_free(mod->data); safe_free(mod->got_block); return; } void download_block(char* paramDir, struct carousel *car, struct module *mod, uint16_t block, unsigned char *data, uint32_t length) { /* assert */ if(block >= mod->nblocks) { error("download_block: moduleId=%u block=%u nblocks=%u", mod->module_id, block, mod->nblocks); return; } /* have we already got it */ if(mod->got_block[block]) return; mod->got_block[block] = true; memcpy(mod->data + (block * mod->block_size), data, length); mod->blocks_left --; verbose("download_block: module=%u block=%u left=%u", mod->module_id, block, mod->blocks_left); /* have we got it all yet */ if(mod->blocks_left == 0) { verbose("got module %u (size=%u)", mod->module_id, mod->size); /* if it doesn't start with 'BIOP' assume it is compressed */ if(strncmp(mod->data, BIOP_MAGIC_STR, BIOP_MAGIC_LEN) != 0) { vhexdump(mod->data, mod->size); uncompress_module(mod); verbose("uncompressed size=%u", mod->size); } if(process_biop(paramDir, car, mod, (struct BIOPMessageHeader *) mod->data, mod->size)) { /* we can free the data now, keep got_block so we don't download it again */ safe_free(mod->data); /* delete_module may safe_free it again */ mod->data = NULL; } else { /* failed to process it, try downloading it again */ mod->blocks_left = mod->nblocks; /* assumes false == 0 */ bzero(mod->got_block, mod->nblocks * sizeof(bool)); } } return; } /* * uncompress in blocks of this size * this is also the minimum size of an uncompressed file */ #define CHUNK_SIZE (4 * 1024) int uncompress_module(struct module *mod) { int ret; z_stream strm; unsigned char *out = NULL; unsigned int out_size = 0; /* init zlib state */ strm.zalloc = Z_NULL; strm.zfree = Z_NULL; strm.opaque = Z_NULL; strm.avail_in = 0; strm.next_in = Z_NULL; ret = inflateInit(&strm); if(ret != Z_OK) return ret; strm.avail_in = mod->size; strm.next_in = mod->data; /* decompress until ouput buffer not full */ do { out = safe_realloc(out, out_size + CHUNK_SIZE); strm.avail_out = CHUNK_SIZE; strm.next_out = out + out_size; ret = inflate(&strm, Z_NO_FLUSH); if(ret != Z_OK && ret != Z_STREAM_END) { inflateEnd(&strm); safe_free(out); return ret; } out_size += CHUNK_SIZE - strm.avail_out; } while(strm.avail_out == 0); /* clean up */ inflateEnd(&strm); /* swap compressed with uncompressed data */ safe_free(mod->data); mod->data = out; mod->size = out_size; return Z_OK; } opencaster-3.2.2/tools/dsmcc-receive/util.c0000644000175000017500000001105412214326444020104 0ustar debiandebian/* * util.c */ /* * Copyright (C) 2005, Simon Kilvington * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include "utils.h" #include "carousel.h" static int _verbose = 0; void increase_verbose() { _verbose++; } void set_verbose(int level) { _verbose = level; } /* * move str to the next non-white space character (or the end of the string) */ char * skip_ws(char *str) { if(str == NULL) return NULL; while(*str != '\0' && isspace((int) *str)) str ++; return str; } /* * returns a single ASCII char for the values 0-15 */ char hex_digit(uint8_t val) { /* assert */ if(val > 0xf) fatal("Not a single hex digit"); return (val < 10) ? '0' + val : 'a' + (val - 10); } /* * I don't want to double the size of my code just to deal with malloc failures * if you've run out of memory you're fscked anyway, me trying to recover is not gonna help... */ void * safe_malloc(size_t nbytes) { void *buf; if((buf = malloc(nbytes)) == NULL) fatal("Out of memory"); return buf; } /* * safe_realloc(NULL, n) == safe_malloc(n) */ void * safe_realloc(void *oldbuf, size_t nbytes) { void *newbuf; if(oldbuf == NULL) return safe_malloc(nbytes); if((newbuf = realloc(oldbuf, nbytes)) == NULL) fatal("Out of memory"); return newbuf; } /* * safe_free(NULL) is okay */ void safe_free(void *buf) { if(buf != NULL) free(buf); return; } void error(char *message, ...) { va_list ap; va_start(ap, message); vfprintf(stderr, message, ap); fprintf(stderr, "\n"); va_end(ap); return; } void fatal(char *message, ...) { va_list ap; va_start(ap, message); vfprintf(stderr, message, ap); fprintf(stderr, "\n"); va_end(ap); } /* number of bytes per line */ #define HEXDUMP_WIDTH 16 void hexdump(unsigned char *data, size_t nbytes) { size_t nout; int i; nout = 0; while(nout < nbytes) { /* byte offset at start of line */ if((nout % HEXDUMP_WIDTH) == 0) printf("0x%.8x ", nout); /* the byte value in hex */ printf("%.2x ", data[nout]); /* the ascii equivalent at the end of the line */ if((nout % HEXDUMP_WIDTH) == (HEXDUMP_WIDTH - 1)) { printf(" "); for(i=HEXDUMP_WIDTH-1; i>=0; i--) printf("%c", isprint(data[nout - i]) ? data[nout - i] : '.'); printf("\n"); } nout ++; } /* the ascii equivalent if we haven't just done it */ if((nout % HEXDUMP_WIDTH) != 0) { /* pad to the start of the ascii equivalent */ for(i=(nout % HEXDUMP_WIDTH); i=0; i--) printf("%c", isprint(data[nout - i]) ? data[nout - i] : '.'); printf("\n"); } return; } void verbose(char *message, ...) { va_list ap; if(_verbose > 0) { va_start(ap, message); vprintf(message, ap); printf("\n"); va_end(ap); } return; } void vverbose(char *message, ...) { va_list ap; if(_verbose > 1) { va_start(ap, message); vprintf(message, ap); printf("\n"); va_end(ap); } return; } void vhexdump(unsigned char *data, size_t nbytes) { if(_verbose > 2) hexdump(data, nbytes); return; } int timeval_subtract (struct timeval *result,struct timeval *x,struct timeval *y) { /* Perform the carry for the later subtraction by updating y. */ if (x->tv_usec < y->tv_usec) { int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1; y->tv_usec -= 1000000 * nsec; y->tv_sec += nsec; } if (x->tv_usec - y->tv_usec > 1000000) { int nsec = (x->tv_usec - y->tv_usec) / 1000000; y->tv_usec += 1000000 * nsec; y->tv_sec -= nsec; } /* Compute the time remaining to wait. tv_usec is certainly positive. */ result->tv_sec = x->tv_sec - y->tv_sec; result->tv_usec = x->tv_usec - y->tv_usec; /* Return 1 if result is negative. */ return x->tv_sec < y->tv_sec; } opencaster-3.2.2/tools/dsmcc-receive/biop.c0000644000175000017500000003037612214326444020070 0ustar debiandebian/* * biop.c */ /* * Copyright (C) 2005, Simon Kilvington * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include "biop.h" #include "fs.h" #include "assoc.h" #include "table.h" #include "utils.h" /* * split the module into separate BIOP messages * returns false if the format is invalid */ bool process_biop(char* paramDir, struct carousel *car, struct module *mod, struct BIOPMessageHeader *data, uint32_t size) { uint32_t bytes_left; unsigned char *subhdr; struct biop_sequence key; struct biop_sequence kind; struct biop_sequence info; struct biop_sequence service_context; struct biop_sequence body; struct biop_sequence file; char *dirname; vverbose("Whole BIOP, size=%u", size); vhexdump((unsigned char *) data, size); /* * we may get 0, 1 or more BIOP messages in a single block * (Channel 4 sends us modules that uncompress to 0 bytes) */ bytes_left = size; while(bytes_left != 0) { /* assert */ if(bytes_left < sizeof(struct BIOPMessageHeader) || strncmp(data->magic, BIOP_MAGIC_STR, BIOP_MAGIC_LEN) != 0 || data->biop_version.major != BIOP_VSN_MAJOR || data->biop_version.minor != BIOP_VSN_MINOR || data->message_type != BIOP_MSG_TYPE) { error("Invalid BIOP header"); return false; } size = biop_uint32(data->byte_order, data->message_size); vverbose("BIOP message_size=%u", size); if(bytes_left < sizeof(struct BIOPMessageHeader) + size) { error("Not enough BIOP data"); return false; } /* process MessageSubHeader */ subhdr = ((unsigned char *) data) + sizeof(struct BIOPMessageHeader); vhexdump(subhdr, size); subhdr += biop_sequence255(subhdr, &key); vverbose("objectKey:"); vhexdump(key.data, key.size); subhdr += biop_sequence(data->byte_order, subhdr, &kind); vverbose("objectKind: '%.*s'", kind.size, kind.data); subhdr += biop_sequence65535(data->byte_order, subhdr, &info); vverbose("objectInfo:"); vhexdump(info.data, info.size); subhdr += biop_sequence255(subhdr, &service_context); vverbose("serviceContextList:"); vhexdump(service_context.data, service_context.size); subhdr += biop_sequence(data->byte_order, subhdr, &body); vverbose("messageBody: %u bytes", body.size); /* decode the message body, based on the objectKind field */ if(strcmp(kind.data, BIOP_DIR) == 0) { /* a directory */ verbose("DSM::Directory"); dirname = make_dir(paramDir, kind.data, car->current_pid, mod->download_id, mod->module_id, key.data, key.size, mod->version); process_biop_dir(paramDir, data->byte_order, dirname, car, body.data, body.size); } else if(strcmp(kind.data, BIOP_SERVICEGATEWAY) == 0) { /* the service gateway is the root directory */ verbose("DSM::ServiceGateway"); dirname = make_dir(paramDir, kind.data, car->current_pid, mod->download_id, mod->module_id, key.data, key.size, mod->version); process_biop_dir(paramDir, data->byte_order, dirname, car, body.data, body.size); } else if(strcmp(kind.data, BIOP_FILE) == 0) { /* a file */ verbose("DSM::File"); (void) biop_sequence(data->byte_order, body.data, &file); vhexdump(file.data, file.size); save_file(paramDir, kind.data, car->current_pid, mod->download_id, mod->module_id, key.data, key.size, file.data, file.size, mod->version); } else if(strcmp(kind.data, BIOP_STREAM) == 0) { /* a stream */ verbose("DSM::Stream"); vhexdump(body.data, body.size); /* * just save it for now * could parse the Taps to make it easier for the browser */ save_file(paramDir, kind.data, car->current_pid, mod->download_id, mod->module_id, key.data, key.size, body.data, body.size, mod->version); } else if(strcmp(kind.data, BIOP_STREAMEVENT) == 0) { /* a stream event */ verbose("BIOP::StreamEvent"); vhexdump(body.data, body.size); /* * just save it for now * could parse it to make it easier for the browser */ save_file(paramDir, kind.data, car->current_pid, mod->download_id, mod->module_id, key.data, key.size, body.data, body.size, mod->version); } else { error("Ignoring unknown BIOP object: '%.*s'", kind.size, kind.data); } /* move onto the next */ data = (struct BIOPMessageHeader *) (((unsigned char *) data) + sizeof(struct BIOPMessageHeader) + size); bytes_left -= sizeof(struct BIOPMessageHeader) + size; } return true; } /* * process the DSM::Directory message body */ void process_biop_dir(char* paramDir, uint8_t byte_order, char *dirname, struct carousel *car, unsigned char *data, uint32_t size) { uint16_t nbindings; uint16_t i; uint8_t nnames; uint8_t j; struct biop_sequence name; struct biop_sequence kind; uint8_t type; struct biop_iop_ior ior; struct biop_sequence info; uint16_t pid; nbindings = biop_uint16(byte_order, *((uint16_t *) data)); data += 2; vverbose("binding_count: %u", nbindings); for(i=0; iassoc, ior.association_tag); /* * is the PID on the MUX we are currently tuned to * some BBC apps have links to files on different MUXes * eg 'games' on BBC1 */ if(pid != 0) add_dsmcc_pid(car, pid); add_dir_entry(paramDir, dirname, name.data, name.size, kind.data, pid, ior.carousel_id, ior.module_id, ior.key.data, ior.key.size); /* objectInfo */ data += biop_sequence65535(byte_order, data, &info); vverbose(" objectInfo:"); vhexdump(info.data, info.size); } return; } /* * returns the elementary_pid that maps to the association_tag in the IOP::IOR */ uint16_t process_biop_service_gateway_info(char* paramDir, uint16_t service_id, struct assoc *assoc, unsigned char *data, uint16_t size) { struct biop_iop_ior ior; uint16_t elementary_pid; verbose("BIOP::ServiceGatewayInfo"); vhexdump(data, size); data += process_iop_ior(BIOP_BIGENDIAN, data, &ior); elementary_pid = stream2pid(assoc, ior.association_tag); make_service_root(paramDir, service_id, BIOP_SERVICEGATEWAY, elementary_pid, ior.carousel_id, ior.module_id, ior.key.data, ior.key.size); return elementary_pid; } /* * process an IOP::IOR data structure * stores the results in ior * returns the size in bytes */ uint32_t process_iop_ior(uint8_t byte_order, unsigned char *data, struct biop_iop_ior *ior) { unsigned char *start = data; struct biop_sequence type; uint32_t nprofiles; uint32_t i; uint32_t tag; struct biop_sequence profile; uint8_t profile_bo; uint8_t taps_count; uint32_t transaction_id; vverbose("IOP::IOR"); /* typeId - "dir\0", "fil\0", etc */ data += biop_sequence(byte_order, data, &type); vverbose(" typeId: '%.*s'", type.size, type.data); nprofiles = biop_uint32(byte_order, *((uint32_t *) data)); data += 4; vverbose(" taggedProfiles_count: %u", nprofiles); for(i=0; icarousel_id = biop_uint32(profile_bo, *((uint32_t *) profile.data)); profile.data += 4; vverbose(" carouselId: %u", ior->carousel_id); /* moduleId */ ior->module_id = biop_uint16(profile_bo, *((uint16_t *) profile.data)); profile.data += 2; vverbose(" moduleId: %u", ior->module_id); /* BIOP version */ if(profile.data[0] != BIOP_VSN_MAJOR || profile.data[1] != BIOP_VSN_MINOR) fatal("Expecting BIOP version 1.0"); profile.data += 2; /* objectKey */ profile.data += biop_sequence255(profile.data, &ior->key); vverbose(" objectKey: '%.*s'", ior->key.size, ior->key.data); vhexdump(ior->key.data, ior->key.size); /* DSM::ConnBinder */ if(biop_uint32(profile_bo, *((uint32_t *) profile.data)) != TAG_ConnBinder) fatal("Expecting DSM::ConnBinder"); profile.data += 4; vverbose(" DSM::ConnBinder"); /* component_data_length = *profile.data */ profile.data += 1; taps_count = *profile.data; profile.data += 1; vverbose(" taps_count: %u", taps_count); if(taps_count > 0) { vverbose(" BIOP::Tap"); /* id = biop_uint16(profile_bo, *((uint16_t *) profile.data)) */ profile.data += 2; if(biop_uint16(profile_bo, *((uint16_t *) profile.data)) != BIOP_DELIVERY_PARA_USE) fatal("Expecting BIOP_DELIVERY_PARA_USE"); profile.data += 2; vverbose(" use: BIOP_DELIVERY_PARA_USE"); ior->association_tag = biop_uint16(profile_bo, *((uint16_t *) profile.data)); profile.data += 2; vverbose(" association_tag: %u", ior->association_tag); if(*profile.data != SELECTOR_TYPE_MESSAGE_LEN) fatal("Expecting selector_length %u", SELECTOR_TYPE_MESSAGE_LEN); profile.data += 1; if(biop_uint16(profile_bo, *((uint16_t *) profile.data)) != SELECTOR_TYPE_MESSAGE) fatal("Expecting selector_type MESSAGE"); profile.data += 2; transaction_id = biop_uint32(profile_bo, *((uint32_t *) profile.data)); profile.data += 4; vverbose(" transaction_id: %u", transaction_id); } } else if(tag == TAG_LITE_OPTIONS) { fatal("TAG_LITE_OPTIONS not implemented"); } else { fatal("Unknown IOP::IOR profileId_tag (0x%x)", tag); } } return (data - start); } /* * convert to the correct byte order */ uint16_t biop_uint16(uint8_t byte_order, uint16_t raw) { uint8_t *p = (uint8_t *) &raw; uint16_t val; if(byte_order == BIOP_BIGENDIAN) val = (p[0] << 8) + p[1]; else val = (p[1] << 8) + p[0]; return val; } /* * convert to the correct byte order */ uint32_t biop_uint32(uint8_t byte_order, uint32_t raw) { uint8_t *p = (uint8_t *) &raw; uint32_t val; if(byte_order == BIOP_BIGENDIAN) val = (p[0] << 24) + (p[1] << 16) + (p[2] << 8) + p[3]; else val = (p[3] << 24) + (p[2] << 16) + (p[1] << 8) + p[0]; return val; } /* * returns the number of bytes including the size field */ uint32_t biop_sequence255(unsigned char *raw, struct biop_sequence *out) { out->size = raw[0]; out->data = &raw[1]; return 1 + out->size; } /* * returns the number of bytes including the size field */ uint32_t biop_sequence65535(uint8_t byte_order, unsigned char *raw, struct biop_sequence *out) { out->size = biop_uint16(byte_order, *((uint16_t *) raw)); out->data = &raw[2]; return 2 + out->size; } /* * returns the number of bytes including the size field */ uint32_t biop_sequence(uint8_t byte_order, unsigned char *raw, struct biop_sequence *out) { out->size = biop_uint32(byte_order, *((uint32_t *) raw)); out->data = &raw[4]; return 4 + out->size; } /* * returns the number of bytes needed to round size upto the next 4 byte boundary */ uint32_t biop_align32(uint32_t size) { return (size % 4) != 0 ? (4 - (size % 4)) : 0; } opencaster-3.2.2/tools/eitsecmapper/0000755000175000017500000000000012214326444016732 5ustar debiandebianopencaster-3.2.2/tools/eitsecmapper/eitsecmapper.c0000644000175000017500000001053412214326444021562 0ustar debiandebian/* * Copyright (C) 2010-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #include #include "../../libs/sectioncrc/sectioncrc.c" #define SECTION_MAX_SIZE 4096 #define SECTION_HEADER_SIZE 3 unsigned char g_section[SECTION_MAX_SIZE+1]; /* +1 to handle a special case, see later in the code */ unsigned char g_section_head[SECTION_HEADER_SIZE]; unsigned char* get_section(unsigned short* section_size, int fd) { unsigned short temp = 0; unsigned char* section = 0; if (section_size) { /* Read first bytes */ *section_size = 0; if (read(fd, g_section_head, SECTION_HEADER_SIZE)) { /* Parse datagram section size */ memcpy(&temp, g_section_head + 1, 2); temp = ntohs(temp); temp &= 0x0FFF; *section_size = temp; /* Read all the section */ if (*section_size <= (SECTION_MAX_SIZE - SECTION_HEADER_SIZE)) { memcpy(g_section, g_section_head, SECTION_HEADER_SIZE); read(fd, g_section + SECTION_HEADER_SIZE, *section_size); section = g_section; *section_size += SECTION_HEADER_SIZE; } else { fprintf(stderr, "Section too big skipped\n"); } } } return section; } void Usage (void) { fprintf(stderr, "Usage: 'eitsecmapper onid tsid sid to onid2 tsid2 sid2 and [...]\n"); } typedef struct Locator { unsigned short onid; unsigned short tsid; unsigned short sid; } Locator; #define MAX_LOCATORS 1024 int main(int argc, char *argv[]) { unsigned short a_section_size; unsigned char *a_section; int fd_sec; int i = 0; unsigned int crc; unsigned int onid; unsigned int tsid; unsigned int sid; unsigned int locators_num; Locator locator_table[MAX_LOCATORS]; Locator locator_table_map[MAX_LOCATORS]; memset(locator_table, 0, sizeof(Locator) * MAX_LOCATORS); memset(locator_table_map, 0, sizeof(Locator) * MAX_LOCATORS); if (argc >= 2) { fd_sec = open(argv[1], O_RDONLY); if (fd_sec < 0) { fprintf(stderr, "Can't find file %s\n", argv[1]); return 2; } } else { Usage(); return 2; } i = 2; locators_num = 0; while (i < argc && locators_num < MAX_LOCATORS) { locator_table[locators_num].onid = atoi(argv[i]); locator_table[locators_num].tsid = atoi(argv[i+1]); locator_table[locators_num].sid = atoi(argv[i+2]); locator_table_map[locators_num].onid = atoi(argv[i+4]); locator_table_map[locators_num].tsid = atoi(argv[i+5]); locator_table_map[locators_num].sid = atoi(argv[i+6]); locators_num++; i+=8; } while(1) { a_section = get_section(&a_section_size, fd_sec); if (a_section_size <= 0 || a_section == 0) { return 0; } memcpy(&onid, a_section + 10, 2); onid = ntohs(onid); memcpy(&tsid, a_section + 8, 2); tsid = ntohs(tsid); memcpy(&sid, a_section + 3, 2); sid = ntohs(sid); for (i = 0; i < locators_num; i++) { if (locator_table[i].onid == onid && locator_table[i].tsid == tsid && locator_table[i].sid == sid) { onid = htons(locator_table_map[i].onid); memcpy(a_section + 10, &onid, 2); tsid = htons(locator_table_map[i].tsid); memcpy(a_section + 8, &tsid, 2); sid = htons(locator_table_map[i].sid); memcpy(a_section + 3, &sid, 2); crc = sectioncrc(a_section, a_section_size - 4); a_section[a_section_size - 4] = (crc >> 24) & 0xFF; a_section[a_section_size - 3] = (crc >> 16) & 0xFF; a_section[a_section_size - 2] = (crc >> 8) & 0xFF; a_section[a_section_size - 1] = crc & 0xFF; i = locators_num; } } write(STDOUT_FILENO, a_section, a_section_size); } return 0; } opencaster-3.2.2/tools/eitsecmapper/Makefile0000644000175000017500000000063712214326444020400 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = eitsecmapper.o TARGET = eitsecmapper DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/tspidmapper/0000755000175000017500000000000012214326444016601 5ustar debiandebianopencaster-3.2.2/tools/tspidmapper/Makefile0000644000175000017500000000063612214326444020246 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = tspidmapper.o TARGET = tspidmapper DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/tspidmapper/tspidmapper.c0000644000175000017500000000603212214326444021276 0ustar debiandebian/* * Copyright (C) 2004-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #define TS_PACKET_SIZE 188 #define MAX_PID 8192 int main(int argc, char *argv[]) { unsigned int i; u_short temp; int byte_read; int fd_ts; /* File descriptor of ts file */ u_short pid; unsigned int buffer_size; u_short pid_map_table[MAX_PID]; /* PID map table for the TS packets */ unsigned char* packet_buffer; unsigned char* current_packet; /* Open ts file */ buffer_size = 0; if (argc >= 5) fd_ts = open(argv[1], O_RDONLY); else { fprintf(stderr, "Usage: 'tspidmapper input.ts [b:buffer_size_in_packets] PID1 to PID2 and PID3 to PID4 and ... '\n"); return 2; } if (fd_ts < 0) { fprintf(stderr, "Can't find file %s\n", argv[1]); return 2; } for (i = 0; i < MAX_PID; i++) { pid_map_table[i] = MAX_PID; } if ((argv[2] != 0) && (argv[2][0] == 'b') && (argv[2][1] == ':')) { buffer_size = atoi(&(argv[2][2])); if (buffer_size == 0) { fprintf(stderr, "invalid buffer size\n"); return 2; } i = 3; } else { i = 2; } for (; i < argc ; i+=4 ) { temp = atoi(argv[i]); if (temp < MAX_PID) { pid_map_table[temp] = atoi(argv[i+2]); fprintf(stderr, "Change %d to %d\n", temp, pid_map_table[temp]); } } if (buffer_size == 0) buffer_size = 1; /* Start to process the file */ buffer_size *= TS_PACKET_SIZE; packet_buffer = malloc(buffer_size); if (packet_buffer == NULL) { fprintf(stderr, "out of memory\n"); return 2; } byte_read = 1; while(byte_read) { /* Read next packets */ byte_read = read(fd_ts, packet_buffer, buffer_size); /* change pid */ for (i = 0; i < buffer_size; i += TS_PACKET_SIZE) { current_packet = packet_buffer + i; memcpy(&pid, current_packet + 1, 2); pid = ntohs(pid); pid = pid & 0x1fff; if (pid < MAX_PID) { if (pid_map_table[pid] != MAX_PID) { memcpy(&temp, current_packet + 1, 2); temp = ntohs(temp); temp = temp & 0xe000; temp = (pid_map_table[pid] & 0x1fff) | temp; temp = htons(temp); memcpy(current_packet + 1, &temp, 2); } } } /* Write packet buffer */ if (byte_read) write(STDOUT_FILENO, packet_buffer, buffer_size); } return 0; } opencaster-3.2.2/tools/tsdoubleoutput/0000755000175000017500000000000012232257151017351 5ustar debiandebianopencaster-3.2.2/tools/tsdoubleoutput/Makefile0000644000175000017500000000064312214326444021016 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = tsdoubleoutput.o TARGET = tsdoubleoutput DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/tsdoubleoutput/tsdoubleoutput.c0000644000175000017500000000442512232257151022624 0ustar debiandebian/* * Copyright (C) 2009-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #define MULTICAST #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define TS_PACKET_SIZE 188 int main(int argc, char *argv[]) { int input_file; int output_file1; int output_file2; int byte_read; unsigned char packet[TS_PACKET_SIZE]; if (argc >= 4) { input_file = open(argv[1], O_RDONLY); if (input_file < 0) { fprintf(stderr, "Can't open file %s\n", argv[1]); return 0; } output_file1 = open(argv[2], O_WRONLY); if (output_file1 < 0) { fprintf(stderr, "Can't open file %s\n", argv[2]); return 0; } output_file2 = open(argv[3], O_WRONLY); if (output_file2 < 0) { fprintf(stderr, "Can't open file %s\n", argv[3]); return 0; } } else { fprintf(stderr, "Usage: 'tsdoubleoutput inputfile.ts outputfile1.ts outputfile2.ts'\n"); fprintf(stderr, "N.B. files must exist, touch them if needed'\n"); return 0; } byte_read = 1; while(byte_read) { byte_read = read(input_file, packet, TS_PACKET_SIZE); write(output_file1, packet, TS_PACKET_SIZE); write(output_file2, packet, TS_PACKET_SIZE); } close(input_file); close(output_file1); close(output_file2); return 0; } opencaster-3.2.2/tools/oddparity/0000755000175000017500000000000012214326444016250 5ustar debiandebianopencaster-3.2.2/tools/oddparity/oddparity.c0000644000175000017500000000307112214326444020414 0ustar debiandebian/* * Copyright (C) 2009-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #define _BSD_SOURCE 1 #include #include #include #include #include #include #include #include #include #include int main(int argc, char *argv[]) { unsigned char byte = 0; unsigned char paritybyte = 0; unsigned char parity = 0; fprintf(stdout, "{ "); for (byte = 0; byte < 127; byte++) { parity = ((byte & 0x01) + ((byte >> 1) & 0x01) + ((byte >> 2) & 0x01) + ((byte >> 3) & 0x01) + ((byte >> 4) & 0x01) + ((byte >> 5) & 0x01) + ((byte >> 6) & 0x01) ); if ((parity % 2) == 0) { paritybyte = 0x80 | byte; } else { paritybyte = byte; } fprintf(stdout, "0x%02x, ", paritybyte); } fprintf(stdout, " }\n"); return 0; } opencaster-3.2.2/tools/oddparity/Makefile0000644000175000017500000000063112214326444017710 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = oddparity.o TARGET = oddparity DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/ip2sec/0000755000175000017500000000000012214326444015436 5ustar debiandebianopencaster-3.2.2/tools/ip2sec/Makefile0000644000175000017500000000070312214326444017076 0ustar debiandebianCC = gcc CFLAGS += -g -O2 -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lpcap OBJS = ip2sec.o ../../libs/sectioncrc/sectioncrc.o TARGET = ip2sec DESTDIR = /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/ip2sec/ip2sec.c0000644000175000017500000001112112214326444016763 0ustar debiandebian/* * Copyright (C) 2004-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. * * co-author Guislain Bonnard guislain.bonnard@quadrille.fr> * */ #define _BSD_SOURCE 1 #include #include #include #include #include #include #include "../../libs/sectioncrc/sectioncrc.h" #define MPE_IP_MTU 4080 #define SECTION_HEADER_SIZE 3 // Section header #define SECTION_MPE_HEADER_SIZE 12 // MPE Section Header, contains section header #define SECTION_MAX_SIZE 4096 static char ethernet_capture_device[] = "eth0"; void got_packet(u_char *args, const struct pcap_pkthdr *header,const u_char *packet){ const struct ether_header *ethernet; /* Cast to ethernet struct */ u_short temp; /* Temp */ u_long crc32; /* crc32 */ int size_ethernet = sizeof(struct ether_header); /* Size of ethernet struct */ u_short datagram_section_size; /* Current datagram section size */ u_char datagram_section[SECTION_MPE_HEADER_SIZE + MPE_IP_MTU];/* Datagram temp buffer */ /* Check its length and type */ if ((packet == NULL) || (header->len > MPE_IP_MTU) || (header->len <= size_ethernet)) { ethernet = 0; } else { ethernet = (struct ether_header*)(packet); /* cast to ethernet */ if (htons(ethernet->ether_type) != ETHERTYPE_IP ) ethernet = 0; /* not interested in this kind of traffic */ } /* Encapsulate IP in a section and output it */ if (ethernet) { /* Parse datagram section size */ datagram_section_size = (header->len - size_ethernet) + SECTION_MPE_HEADER_SIZE; /* ip packet + mpe header */ temp = htons (datagram_section_size + sizeof(crc32) - SECTION_HEADER_SIZE); /* add crc32 at section body, sub first section head bytes */ memcpy(datagram_section + 1, &temp, 2); datagram_section[1] |= 0xb0; /* datagram section lenght, reserved, syntax, no private */ /* Set section header fixed bytes */ datagram_section[0] = 0x3e; /* dsmcc section private data table id */ datagram_section[5] = 0xc1; /* reserved, no scrambling for payload and no scrambling for access */ datagram_section[6] = 0; /* start section, not used */ datagram_section[7] = 0; /* finish section, not used */ /* Parse ethernet header into section header */ datagram_section[11] = ethernet->ether_dhost[0]; datagram_section[10] = ethernet->ether_dhost[1]; datagram_section[9] = ethernet->ether_dhost[2]; datagram_section[8] = ethernet->ether_dhost[3]; datagram_section[4] = ethernet->ether_dhost[4]; datagram_section[3] = ethernet->ether_dhost[5]; /* Build section body */ memcpy(datagram_section + SECTION_MPE_HEADER_SIZE, packet + size_ethernet, datagram_section_size - SECTION_MPE_HEADER_SIZE); /* Output section and crc32 */ fwrite(datagram_section, 1, datagram_section_size, stdout); crc32 = sectioncrc(datagram_section, datagram_section_size); crc32 = htonl(crc32); fwrite(&crc32, 1, sizeof(crc32), stdout); fflush(stdout); } } int main(int argc, char *argv[]) { char* capture_device; /* The selected capture device */ pcap_t *handle; /* Session handle */ const char* filterExp; struct bpf_program fp; /* The compiled filter expression */ bpf_u_int32 mask; /* Our netmask */ bpf_u_int32 net; /* Our IP */ char errbuf[PCAP_ERRBUF_SIZE]; /* Error buffer */ /* Check args */ if (argc > 1){ capture_device = argv[1]; filterExp = argv[2]; } else{ capture_device = ethernet_capture_device; filterExp = NULL; } /* Open the device for capture in promiscuos mode */ pcap_lookupnet(capture_device, &net, &mask, errbuf); handle = pcap_open_live(capture_device, BUFSIZ, 1, 0, errbuf); if (pcap_compile(handle, &fp, filterExp, 0, net) == -1) { fprintf(stderr,"Filter compile failed.\n"); } if (pcap_setfilter(handle, &fp) == -1) { fprintf(stderr,"Filter set failed.\n"); } pcap_loop(handle, -1, got_packet, NULL); return 0; } opencaster-3.2.2/tools/tsnullfiller/0000755000175000017500000000000012214326444016770 5ustar debiandebianopencaster-3.2.2/tools/tsnullfiller/tsnullfiller.c0000644000175000017500000001061112214326444021652 0ustar debiandebian/* * Copyright (C) 2004-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #define TS_PACKET_SIZE 188 #define MAX_PID 8192 #define SYSTEM_CLOCK_FREQUENCY 27000000 int main(int argc, char *argv[]) { int fd_ts; int byte_read; unsigned int i; unsigned int input_buffer_size; unsigned int output_buffer_size; unsigned long long int ibits; unsigned long long int obits; unsigned long long int icounter; unsigned long long int ocounter; unsigned long long int last_ocounter; unsigned char* input_packet_buffer; unsigned char* output_packet_buffer; unsigned char* current_input_packet; unsigned char* current_output_packet; unsigned char null_ts_packet[TS_PACKET_SIZE]; /* Parse args */ input_buffer_size = 0; if (argc >= 4) fd_ts = open(argv[1], O_RDONLY); else { fprintf(stderr, "Usage: 'tsnullfiller input.ts output_bit/s input_bit/s [packet_buffer]'\n"); fprintf(stderr, "adds empty packets to input.ts to reach output_bit/s\n"); return 2; } if (fd_ts < 0) { fprintf(stderr, "Can't find file %s\n", argv[1]); return 2; } obits = atol(argv[2]); if (obits == 0) { fprintf(stderr, "0 output_bit/s?\n"); return 2; } ibits = atol(argv[3]); if (ibits == 0) { fprintf(stderr, "0 input_bit/s?\n"); return 2; } if (obits <= ibits) { fprintf(stderr, "output rate has to be bigger\n"); return 2; } if (argv[4] != NULL) { input_buffer_size = atoi(argv[4]); if (input_buffer_size == 0) { fprintf(stderr, "buffer size is not valid\n"); return 2; } } else { input_buffer_size = 1; } output_buffer_size = (input_buffer_size * obits / ibits) + 1; /* be sure to have space for null packets */ input_buffer_size *= TS_PACKET_SIZE; output_buffer_size *= TS_PACKET_SIZE; input_packet_buffer = malloc(input_buffer_size); output_packet_buffer = malloc(output_buffer_size); if (input_packet_buffer == NULL || output_packet_buffer == NULL) { fprintf(stderr, "Out of memory\n"); return 2; } /* Init null packet */ memset(null_ts_packet, 0, TS_PACKET_SIZE); null_ts_packet[0] = 0x47; null_ts_packet[1] = 0x1F; null_ts_packet[2] = 0xFF; null_ts_packet[3] = 0x10; /* Start to process the file */ icounter = 0; ocounter = 0; byte_read = 1; while(byte_read) { /* Read next packets */ byte_read = read(fd_ts, input_packet_buffer, input_buffer_size); /* Generate output buffer */ current_input_packet = input_packet_buffer; current_output_packet = output_packet_buffer; for (i = 0; i < input_buffer_size; i += TS_PACKET_SIZE) { current_input_packet = input_packet_buffer + i; /* copy ts packet */ memcpy(current_output_packet, current_input_packet, TS_PACKET_SIZE); current_output_packet += TS_PACKET_SIZE; /* increase bits counters */ icounter += TS_PACKET_SIZE * 8; ocounter += TS_PACKET_SIZE * 8; /* generate null packets if there's time */ while (((ocounter + TS_PACKET_SIZE * 8) * ibits) <= (icounter * obits)) { /* copy null packet */ memcpy(current_output_packet, null_ts_packet, TS_PACKET_SIZE); current_output_packet += TS_PACKET_SIZE; /* increase bit counter */ last_ocounter = ocounter; ocounter += TS_PACKET_SIZE * 8; if (last_ocounter > ocounter) { /* manage zeroed counter */ last_ocounter = last_ocounter - icounter; icounter = 0; ocounter = last_ocounter + TS_PACKET_SIZE * 8; } } } /* Write output packets */ write(STDOUT_FILENO, output_packet_buffer, current_output_packet-output_packet_buffer); } return 0; } opencaster-3.2.2/tools/tsnullfiller/Makefile0000644000175000017500000000063712214326444020436 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = tsnullfiller.o TARGET = tsnullfiller DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/tsorts/0000755000175000017500000000000012232257151015605 5ustar debiandebianopencaster-3.2.2/tools/tsorts/tsorts.c0000644000175000017500000000543412232257151017315 0ustar debiandebian/* * Copyright (C) 2009-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #define MULTICAST #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define TS_PACKET_SIZE 188 int main(int argc, char *argv[]) { int input1_file; int input2_file; int byte_read; int index; unsigned char ts_packet[TS_PACKET_SIZE]; if (argc >= 3) { input1_file = open(argv[1], O_RDONLY); if (input1_file < 0) { fprintf(stderr, "Can't open file %s\n", argv[1]); return 0; } input2_file = open(argv[2], O_RDONLY); if (input2_file < 0) { fprintf(stderr, "Can't open file %s\n", argv[2]); return 0; } } else { fprintf(stderr, "Usage: 'tsorts inputfile1.ts inputfile2.ts > output.ts'\n"); fprintf(stderr, "ts packets are read from inputfile2.ts if they are not immediatly available from inputfile1.ts'\n"); return 0; } fcntl (input1_file, F_SETFL, fcntl (input1_file, F_GETFL, 0) | O_NONBLOCK); index = 0; while (1) { byte_read = read(input1_file, ts_packet + index, TS_PACKET_SIZE - index); if (byte_read > 0) { index += byte_read; if (index == TS_PACKET_SIZE) { write(STDOUT_FILENO, ts_packet, TS_PACKET_SIZE); index = 0; } } else if (byte_read <= 0 && index == 0) { byte_read = read(input2_file, ts_packet, TS_PACKET_SIZE); if (byte_read == 0) { close(input2_file); input2_file = open(argv[2], O_RDONLY); if (input2_file < 0) { fprintf(stderr, "Can't open file %s\n", argv[2]); return 0; } else { byte_read = read(input2_file, ts_packet, TS_PACKET_SIZE); if (byte_read > 0) { write(STDOUT_FILENO, ts_packet, TS_PACKET_SIZE); } } } else { write(STDOUT_FILENO, ts_packet, TS_PACKET_SIZE); } } } return 0; } opencaster-3.2.2/tools/tsorts/Makefile0000644000175000017500000000062312214326444017250 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = tsorts.o TARGET = tsorts DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/zpipe/0000755000175000017500000000000012214326444015400 5ustar debiandebianopencaster-3.2.2/tools/zpipe/Makefile0000644000175000017500000000063412214326444017043 0ustar debiandebianCC = gcc CFLAGS += -g -O2 -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lz OBJS = zpipe.o TARGET = zpipe DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/zpipe/zpipe.c0000644000175000017500000001426312214326444016701 0ustar debiandebian/* zpipe.c: example of proper use of zlib's inflate() and deflate() Not copyrighted -- provided to the public domain Version 1.4 11 December 2005 Mark Adler */ /* Version history: 1.0 30 Oct 2004 First version 1.1 8 Nov 2004 Add void casting for unused return values Use switch statement for inflate() return values 1.2 9 Nov 2004 Add assertions to document zlib guarantees 1.3 6 Apr 2005 Remove incorrect assertion in inf() 1.4 11 Dec 2005 Add hack to avoid MSDOS end-of-line conversions Avoid some compiler warnings for input and output buffers */ #include #include #include #include "zlib.h" #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__) # include # include # define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) #else # define SET_BINARY_MODE(file) #endif #define CHUNK 16384 /* Compress from file source to file dest until EOF on source. def() returns Z_OK on success, Z_MEM_ERROR if memory could not be allocated for processing, Z_STREAM_ERROR if an invalid compression level is supplied, Z_VERSION_ERROR if the version of zlib.h and the version of the library linked do not match, or Z_ERRNO if there is an error reading or writing the files. */ int def(FILE *source, FILE *dest, int level) { int ret, flush; unsigned have; z_stream strm; unsigned char in[CHUNK]; unsigned char out[CHUNK]; /* allocate deflate state */ strm.zalloc = Z_NULL; strm.zfree = Z_NULL; strm.opaque = Z_NULL; ret = deflateInit(&strm, level); if (ret != Z_OK) return ret; /* compress until end of file */ do { strm.avail_in = fread(in, 1, CHUNK, source); if (ferror(source)) { (void)deflateEnd(&strm); return Z_ERRNO; } flush = feof(source) ? Z_FINISH : Z_NO_FLUSH; strm.next_in = in; /* run deflate() on input until output buffer not full, finish compression if all of source has been read in */ do { strm.avail_out = CHUNK; strm.next_out = out; ret = deflate(&strm, flush); /* no bad return value */ assert(ret != Z_STREAM_ERROR); /* state not clobbered */ have = CHUNK - strm.avail_out; if (fwrite(out, 1, have, dest) != have || ferror(dest)) { (void)deflateEnd(&strm); return Z_ERRNO; } } while (strm.avail_out == 0); assert(strm.avail_in == 0); /* all input will be used */ /* done when last data in file processed */ } while (flush != Z_FINISH); assert(ret == Z_STREAM_END); /* stream will be complete */ /* clean up and return */ (void)deflateEnd(&strm); return Z_OK; } /* Decompress from file source to file dest until stream ends or EOF. inf() returns Z_OK on success, Z_MEM_ERROR if memory could not be allocated for processing, Z_DATA_ERROR if the deflate data is invalid or incomplete, Z_VERSION_ERROR if the version of zlib.h and the version of the library linked do not match, or Z_ERRNO if there is an error reading or writing the files. */ int inf(FILE *source, FILE *dest) { int ret; unsigned have; z_stream strm; unsigned char in[CHUNK]; unsigned char out[CHUNK]; /* allocate inflate state */ strm.zalloc = Z_NULL; strm.zfree = Z_NULL; strm.opaque = Z_NULL; strm.avail_in = 0; strm.next_in = Z_NULL; ret = inflateInit(&strm); if (ret != Z_OK) return ret; /* decompress until deflate stream ends or end of file */ do { strm.avail_in = fread(in, 1, CHUNK, source); if (ferror(source)) { (void)inflateEnd(&strm); return Z_ERRNO; } if (strm.avail_in == 0) break; strm.next_in = in; /* run inflate() on input until output buffer not full */ do { strm.avail_out = CHUNK; strm.next_out = out; ret = inflate(&strm, Z_NO_FLUSH); assert(ret != Z_STREAM_ERROR); /* state not clobbered */ switch (ret) { case Z_NEED_DICT: ret = Z_DATA_ERROR; /* and fall through */ case Z_DATA_ERROR: case Z_MEM_ERROR: (void)inflateEnd(&strm); return ret; } have = CHUNK - strm.avail_out; if (fwrite(out, 1, have, dest) != have || ferror(dest)) { (void)inflateEnd(&strm); return Z_ERRNO; } } while (strm.avail_out == 0); /* done when inflate() says it's done */ } while (ret != Z_STREAM_END); /* clean up and return */ (void)inflateEnd(&strm); return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR; } /* report a zlib or i/o error */ void zerr(int ret) { fputs("zpipe: ", stderr); switch (ret) { case Z_ERRNO: if (ferror(stdin)) fputs("error reading stdin\n", stderr); if (ferror(stdout)) fputs("error writing stdout\n", stderr); break; case Z_STREAM_ERROR: fputs("invalid compression level\n", stderr); break; case Z_DATA_ERROR: fputs("invalid or incomplete deflate data\n", stderr); break; case Z_MEM_ERROR: fputs("out of memory\n", stderr); break; case Z_VERSION_ERROR: fputs("zlib version mismatch!\n", stderr); } } /* compress or decompress from stdin to stdout */ int main(int argc, char **argv) { int ret; /* avoid end-of-line conversions */ SET_BINARY_MODE(stdin); SET_BINARY_MODE(stdout); /* do compression if no arguments */ if (argc == 1) { ret = def(stdin, stdout, Z_DEFAULT_COMPRESSION); if (ret != Z_OK) zerr(ret); return ret; } /* do decompression if -d specified */ else if (argc == 2 && strcmp(argv[1], "-d") == 0) { ret = inf(stdin, stdout); if (ret != Z_OK) zerr(ret); return ret; } /* otherwise, report usage */ else { fputs("zpipe usage: zpipe [-d] < source > dest\n", stderr); return 1; } } opencaster-3.2.2/tools/eitsecactualtoanother/0000755000175000017500000000000012214326444020643 5ustar debiandebianopencaster-3.2.2/tools/eitsecactualtoanother/Makefile0000644000175000017500000000066112214326444022306 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = eitsecactualtoanother.o TARGET = eitsecactualtoanother DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/eitsecactualtoanother/eitsecactualtoanother.c0000644000175000017500000000614312214326444025405 0ustar debiandebian/* * Copyright (C) 2011-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #include #include "../../libs/sectioncrc/sectioncrc.c" #define SECTION_MAX_SIZE 4096 #define SECTION_HEADER_SIZE 3 unsigned char g_section[SECTION_MAX_SIZE+1]; /* +1 to handle a special case, see later in the code */ unsigned char g_section_head[SECTION_HEADER_SIZE]; unsigned char* get_section(unsigned short* section_size, int fd) { unsigned short temp = 0; unsigned char* section = 0; if (section_size) { /* Read first bytes */ *section_size = 0; if (read(fd, g_section_head, SECTION_HEADER_SIZE)) { /* Parse datagram section size */ memcpy(&temp, g_section_head + 1, 2); temp = ntohs(temp); temp &= 0x0FFF; *section_size = temp; /* Read all the section */ if (*section_size <= (SECTION_MAX_SIZE - SECTION_HEADER_SIZE)) { memcpy(g_section, g_section_head, SECTION_HEADER_SIZE); read(fd, g_section + SECTION_HEADER_SIZE, *section_size); section = g_section; *section_size += SECTION_HEADER_SIZE; } else { fprintf(stderr, "Section too big skipped\n"); } } } return section; } void Usage (void) { fprintf(stderr, "Usage: 'eitsecactualtoanother inputeit.sec > outputeit.sec \n"); } int main(int argc, char *argv[]) { unsigned short a_section_size; unsigned char *a_section; int fd_sec; unsigned int crc; if (argc >= 2) { fd_sec = open(argv[1], O_RDONLY); if (fd_sec < 0) { fprintf(stderr, "Can't find file %s\n", argv[1]); return 2; } } else { Usage(); return 2; } while(1) { a_section = get_section(&a_section_size, fd_sec); if (a_section_size <= 0 || a_section == 0) { return 0; } if (a_section[0] == 0x4E) { a_section[0] = 0x4F; a_section[13] = 0x4F; } else if (a_section[0] >= 0x50 && a_section[0] <= 0x5F) { a_section[0] = 0x60 | (a_section[0] & 0xF) ; a_section[13] = 0x60 | (a_section[13] & 0xF) ; } crc = sectioncrc(a_section, a_section_size - 4); a_section[a_section_size - 4] = (crc >> 24) & 0xFF; a_section[a_section_size - 3] = (crc >> 16) & 0xFF; a_section[a_section_size - 2] = (crc >> 8) & 0xFF; a_section[a_section_size - 1] = crc & 0xFF; write(STDOUT_FILENO, a_section, a_section_size); } return 0; } opencaster-3.2.2/tools/pesdata2ts/0000755000175000017500000000000012214326444016323 5ustar debiandebianopencaster-3.2.2/tools/pesdata2ts/Makefile0000644000175000017500000000060312214326444017762 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include $(CPPFLAGS) LDFLAGS += -lc OBJS = pesdata2ts.o TARGET = pesdata2ts DESTDIR = /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/pesdata2ts/pesdata2ts.c0000644000175000017500000001217412220024107020532 0ustar debiandebian/* * Copyright (C) 2009-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #define _BSD_SOURCE 1 #include #include #include #include #include #include #include #include #include #include #define MAX_PID 8192 #define PES_HEADER_SIZE 4 #define TS_HEADER_SIZE 4 #define TS_PACKET_SIZE 188 int ts_payload; /* TS packet payload counter */ u_short pid; /* Pid for the TS packets */ u_char ts_continuity_counter; /* Continuity counter */ u_char ts_packet[TS_PACKET_SIZE]; /* TS packet */ u_char look_ahead_buffer[PES_HEADER_SIZE]; u_char look_ahead_size; void send_current_packet(void) { int i; u_char temp; if (TS_HEADER_SIZE + ts_payload == TS_PACKET_SIZE) { /* filled case */ ts_packet[3] = ts_continuity_counter | 0x10; /* continuity counter, no scrambling, only payload */ ts_continuity_counter = (ts_continuity_counter + 1) % 0x10; /* inc. continuity counter */ write(STDOUT_FILENO, ts_packet, TS_PACKET_SIZE); ts_payload = 0; } else if (TS_HEADER_SIZE + ts_payload + 1 == TS_PACKET_SIZE) { /* payload too big: two packets are necessary */ temp = ts_packet[TS_HEADER_SIZE + ts_payload - 1]; /* copy the exceeding byte */ ts_payload--; send_current_packet(); memcpy(ts_packet + 1, &pid, 2); /* pid, no pusu */ ts_packet[4] = temp; ts_payload = 1; send_current_packet(); } else { /* padding is necessary */ ts_packet[3] = ts_continuity_counter | 0x30; /* continuity counter, no scrambling, adaptation field and payload */ ts_continuity_counter = (ts_continuity_counter + 1) % 0x10; /* inc. continuity counter */ for (i = 0; i < ts_payload; i++) { /* move the payload at the end */ ts_packet[TS_PACKET_SIZE - 1 - i] = ts_packet[TS_HEADER_SIZE + ts_payload - 1 - i]; } ts_packet[4] = TS_PACKET_SIZE - ts_payload - TS_HEADER_SIZE - 1; /* point to the first payload byte */ ts_packet[5] = 0x00; /* no options */ for ( i = TS_HEADER_SIZE + 2 ; i < TS_PACKET_SIZE - ts_payload; i++) { /* pad the packet */ ts_packet[i] = 0xFF; } write(STDOUT_FILENO, ts_packet, TS_PACKET_SIZE); ts_payload = 0; } } int main(int argc, char *argv[]) { int i; int byte_read; FILE* file_pes; /* pes stream */ /* Parse args */ pid = MAX_PID; file_pes = 0; if (argc > 2) { file_pes = fopen(argv[1], "rb"); pid = atoi(argv[2]); } if (file_pes == 0 || pid >= MAX_PID ) { fprintf(stderr, "Usage: 'pesdata2ts file.pes pid > file.ts', where pid is bounded from 1 to 8191\n"); return 2; } else { pid = htons(pid); } /* Set some init. values */ ts_payload = 0; look_ahead_size = 0; ts_continuity_counter = 0x0; ts_packet[0] = 0x47; /* sync byte */ memcpy(ts_packet + 1, &pid, 2); /* pid */ ts_packet[1] |= 0x40; /* payload unit start indicator */ byte_read = 1; /* Process the PES file */ byte_read = fread(look_ahead_buffer + look_ahead_size, 1, PES_HEADER_SIZE, file_pes); look_ahead_size = byte_read; while (byte_read || look_ahead_size) { /* Fill the look ahead buffer */ if (look_ahead_size < PES_HEADER_SIZE) { byte_read = fread(look_ahead_buffer + look_ahead_size, 1, 1, file_pes); look_ahead_size += byte_read; } /* PES header detected? */ if (look_ahead_size == PES_HEADER_SIZE && look_ahead_buffer[0] == 0x00 && look_ahead_buffer[1] == 0x00 && look_ahead_buffer[2] == 0x01 && look_ahead_buffer[3] == 0xBD) { /* Send current packet if there's anything ready */ if (ts_payload) { send_current_packet(); } /* Set pusu for the next packet */ memcpy(ts_packet + 1, &pid, 2); /* pid */ ts_packet[1] |= 0x40; /* payload unit start indicator */ } /* Fill the current packet */ if (look_ahead_size > 0) { /* Move a packet from the lookahead to the current packet */ ts_packet[TS_HEADER_SIZE + ts_payload] = look_ahead_buffer[0]; ts_payload++; for (i = 0; i < PES_HEADER_SIZE-1; i++){ look_ahead_buffer[i] = look_ahead_buffer[i + 1]; } look_ahead_size--; /* Send the packet if it's filled */ if (TS_HEADER_SIZE + ts_payload == TS_PACKET_SIZE) { send_current_packet(); /* Unset pusu for the next packet */ memcpy(ts_packet + 1, &pid, 2); /* pid */ } } /* Send the last packet with the last bytes if any */ if (byte_read == 0 && look_ahead_size == 0 && ts_payload) { send_current_packet(); } } return 0; } opencaster-3.2.2/tools/i13942ts/0000755000175000017500000000000012214326444015453 5ustar debiandebianopencaster-3.2.2/tools/i13942ts/i13942ts.c0000644000175000017500000000470512214326444017027 0ustar debiandebian/* * Copyright (C) 2004-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #define _BSD_SOURCE 1 #include #include #include #include #include #include #include #include #include #include #define I1394_HEADER_SIZE 4 #define CIP_HEADER_SIZE 8 #define SP_HEADER_SIZE 4 #define TS_PACKET_SIZE 188 int main(int argc, char *argv[]) { int byte_read = 0; FILE* file_i1394 = 0; int data_length = 0; unsigned char fmt = 0; unsigned short dbs_fn_qpc_sph = 0; unsigned char CIP_header[CIP_HEADER_SIZE]; unsigned char SP_header[SP_HEADER_SIZE]; unsigned char ts_packet[TS_PACKET_SIZE]; unsigned char i1394_header[I1394_HEADER_SIZE]; file_i1394 = 0; if (argc > 1) { file_i1394 = fopen(argv[1], "rb"); } if (file_i1394 == 0) { fprintf(stderr, "Usage: 'i13942ts file.iso', where .iso is a ieee1394-6 dump\n"); return 2; } /* Process the i1394 file */ byte_read = fread(i1394_header, 1, I1394_HEADER_SIZE, file_i1394); while (byte_read) { byte_read = fread(CIP_header, 1, CIP_HEADER_SIZE, file_i1394); data_length = (htonl(*(unsigned long*)i1394_header) >> 16); dbs_fn_qpc_sph = (htonl(*(unsigned long*)CIP_header) >> 10) & 0x3fff; fmt = (htonl(*(unsigned long*)(CIP_header + 4)) >> 24) & 0x3f; if (fmt == 0x20 && dbs_fn_qpc_sph == 0x01b1) { data_length -= CIP_HEADER_SIZE; for ( ; data_length > TS_PACKET_SIZE; data_length -= TS_PACKET_SIZE + SP_HEADER_SIZE) { fread(SP_header, 1, SP_HEADER_SIZE, file_i1394); fread(ts_packet, 1, TS_PACKET_SIZE, file_i1394); fwrite(ts_packet, 1, TS_PACKET_SIZE, stdout); } } byte_read = fread(i1394_header, 1, I1394_HEADER_SIZE, file_i1394); } return 0; } opencaster-3.2.2/tools/i13942ts/Makefile0000644000175000017500000000061012214326444017110 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) OBJS = i13942ts.o TARGET = i13942ts DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/esvideompeg2pes/0000755000175000017500000000000012214326444017352 5ustar debiandebianopencaster-3.2.2/tools/esvideompeg2pes/Makefile0000644000175000017500000000064512214326444021017 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = esvideompeg2pes.o TARGET = esvideompeg2pes DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/esvideompeg2pes/esvideompeg2pes.c0000644000175000017500000002406712214326444022630 0ustar debiandebian/* * Copyright (C) 2004-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #include #define PES_HEADER_SIZE 19 #define SYSTEM_CLOCK 90000.0 #define ES_HEADER_SIZE 4 #define ES_HEADER_MAX_SIZE ES_HEADER_SIZE * 2 #define HEADER_BUFFER_MAX_SIZE 1024 #define PTS_MAX 8589934592LL const float frame_rate[16] = { -1.0, 23.9, 24.0, 25.0, 29.9, 30.0, 50.0, 59.9, 60.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, }; const int pts_steps[16] = { -1, -1, // not supported 3750, 3600, 3003, 3000, 1800, -1, // not supported 1500, -1, -1, -1, -1, -1, -1, -1, }; void stamp_ts (unsigned long long int ts, unsigned char* buffer) { if (buffer) { buffer[0] = ((ts >> 29) & 0x0F) | 0x01; buffer[1] = (ts >> 22) & 0xFF; buffer[2] = ((ts >> 14) & 0xFF ) | 0x01; buffer[3] = (ts >> 7) & 0xFF; buffer[4] = ((ts << 1) & 0xFF ) | 0x01; } } int main(int argc, char *argv[]) { int bframe; int read_fps; int skip_next_header; int bitrate; int firstframe; int byte_read; FILE* file_es; unsigned int time_reference = 0; unsigned long long int dts; unsigned long long int dts_base; unsigned long long int pts; unsigned long long int pts_limit = 0ll; unsigned long long int pts_first_gop = 0ll; unsigned long long int pts_a_gop = 0ll; unsigned long long int frame_counter = 0; unsigned char stream_id = 224; unsigned char pes_header[PES_HEADER_SIZE]; unsigned char es_header[ES_HEADER_SIZE + 8]; unsigned int pts_step = 0; unsigned char header_buffer[HEADER_BUFFER_MAX_SIZE]; unsigned int header_buffer_size = 0; /* Open pes file */ if (argc > 1) { file_es = fopen(argv[1], "rb"); } if (argc > 2) { pts_limit = atol(argv[2]); } if (argc > 3) { stream_id = atoi(argv[3]); } if (argc < 2){ fprintf(stderr, "Usage: 'esvideompeg2pes video.es [pts_limit] [stream_id]] '\n"); fprintf(stderr, "Video stream id default is 224\n"); return 2; } if (file_es == 0) { fprintf(stderr, "Can't find file %s\n", argv[1]); return 2; } /* Init. default pack header */ pes_header[0] = 0x00; pes_header[1] = 0x00; pes_header[2] = 0x01; pes_header[3] = stream_id; pes_header[4] = 0x00; pes_header[5] = 0x00; pes_header[6] = 0x80; /* no scrambling, no priority, no alignment defined, no copyright, no copy */ pes_header[7] = 0xC0; /* pts and dts, no escr, no es rate, no dsm trick, no extension flag, no additional copy info, no crc flag */ pes_header[8] = 0x0A; /* pts and dts size*/ /* Start the process */ bframe = 1; firstframe = 1; skip_next_header = 0; read_fps = 0; /* get stream info, output first pes header */ byte_read = fread(es_header, 1, ES_HEADER_SIZE, file_es); if (es_header[0] == 0x00 && es_header[1] == 0x00 && es_header[2] == 0x01 && es_header[3] == 0xB3) { byte_read = fread(es_header + ES_HEADER_SIZE, 1, 8, file_es); if ((es_header[ES_HEADER_SIZE + 3] & 0x0F) < 16) { if (frame_rate[es_header[ES_HEADER_SIZE + 3] & 0x0F] < 0.0) { fprintf(stderr, "invalid fps into sequence video header\n"); exit(2); } else { pts_step = pts_steps[es_header[ES_HEADER_SIZE + 3] & 0x0F]; if (pts_step < 0) { fprintf(stderr, "%f fps are not supported\n", frame_rate[es_header[ES_HEADER_SIZE + 3] & 0x0F]); } else { fprintf(stderr, "pts step is %d\n", pts_step); } } } else { fprintf(stderr, "invalid fps into sequence video header\n"); exit(2); } bitrate = ((es_header[ES_HEADER_SIZE + 4] << 10) | (es_header[ES_HEADER_SIZE + 5] << 2) | ((es_header[ES_HEADER_SIZE + 6] & 0xC0) >> 6)) * 400; fprintf(stderr, "bit per second are: %d\n", bitrate); dts = 0; dts_base = 0; pts = pts_step; pes_header[7] = 0xC0; /* pts and dts, no escr, no es rate, no dsm trick, no extension flag, no additional copy info, no crc flag */ pes_header[8] = 0x0A; /* pts and dts size*/ stamp_ts(pts % PTS_MAX, pes_header + 9); pes_header[9] &= 0x0F; pes_header[9] |= 0x30; stamp_ts(dts % PTS_MAX, pes_header + 14); pes_header[14] &= 0x0F; pes_header[14] |= 0x10; fwrite(pes_header, 1, PES_HEADER_SIZE, stdout); frame_counter++; fwrite(es_header, 1, ES_HEADER_SIZE + 8, stdout); byte_read = fread(es_header, 1, ES_HEADER_SIZE, file_es); } else { fprintf(stderr, "elementary stream video should start with a sequence video header\n"); exit(2); } /* skip nex start header */ while(byte_read) { if (es_header[0] == 0x00 && es_header[1] == 0x00 && es_header[2] == 0x01 && es_header[3] == 0x00) { /* pes header already written, just count dts */ fwrite(es_header, 1, ES_HEADER_SIZE, stdout); dts += pts_step; byte_read = 0; } else { fwrite(es_header, 1, 1, stdout); es_header[0] = es_header[1]; es_header[1] = es_header[2]; es_header[2] = es_header[3]; byte_read = fread(es_header + 3, 1, 1, file_es); } } byte_read = fread(es_header, 1, ES_HEADER_SIZE, file_es); while(byte_read) { if (es_header[0] == 0x00 && es_header[1] == 0x00 && es_header[2] == 0x01 && es_header[3] == 0x00) { fread(es_header + ES_HEADER_SIZE, 1, ES_HEADER_SIZE, file_es); time_reference = (es_header[4] << 2) | ((es_header[5] & 0xC0) >> 6 ); bframe = (es_header[5] & 0x38) >> 3; bframe = (bframe == 0x03); pts = dts_base + (time_reference * pts_step) + pts_step; if (!bframe) { pes_header[7] = 0xC0; /* pts and dts, no escr, no es rate, no dsm trick, no extension flag, no additional copy info, no crc flag */ pes_header[8] = 0x0A; /* pts and dts size*/ stamp_ts(pts % PTS_MAX, pes_header + 9); pes_header[9] &= 0x0F; pes_header[9] |= 0x30; stamp_ts(dts % PTS_MAX, pes_header + 14); pes_header[14] &= 0x0F; pes_header[14] |= 0x10; fwrite(pes_header, 1, PES_HEADER_SIZE, stdout); frame_counter++; } else { pes_header[7] = 0x80; /* pts only, no escr, no es rate, no dsm trick, no extension flag, no additional copy info, no crc flag */ pes_header[8] = 0x05; /* pts size*/ stamp_ts(pts % PTS_MAX, pes_header + 9); pes_header[9] &= 0x0F; pes_header[9] |= 0x30; fwrite(pes_header, 1, PES_HEADER_SIZE - 5, stdout); frame_counter++; } fwrite(es_header, 1, ES_HEADER_MAX_SIZE, stdout); dts += pts_step; byte_read = fread(es_header, 1, ES_HEADER_SIZE, file_es); } else if (es_header[0] == 0x00 && es_header[1] == 0x00 && es_header[2] == 0x01 && es_header[3] == 0xB3) { /* need to know the time reference, look for the next start header*/ memcpy(header_buffer, es_header, ES_HEADER_SIZE); header_buffer_size = ES_HEADER_SIZE; byte_read = fread(header_buffer + header_buffer_size, 1, ES_HEADER_SIZE, file_es); header_buffer_size += ES_HEADER_SIZE; while(byte_read && header_buffer_size < HEADER_BUFFER_MAX_SIZE - 4) { if (header_buffer[header_buffer_size - 4] == 0x00 && header_buffer[header_buffer_size - 3] == 0x00 && header_buffer[header_buffer_size - 2] == 0x01 && header_buffer[header_buffer_size - 1] == 0x00) { byte_read = fread(header_buffer + header_buffer_size, 1, 2, file_es); header_buffer_size += 2; time_reference = (header_buffer[header_buffer_size - 2] << 2) | ((header_buffer[header_buffer_size - 1] & 0xC0) >> 6 ); /* fprintf(stderr, "temporal reference is %d\n", time_reference); */ byte_read = 0; } else { byte_read = fread(header_buffer + header_buffer_size, 1, 1, file_es); header_buffer_size += 1; } } if (header_buffer_size >= HEADER_BUFFER_MAX_SIZE - 4) { fprintf(stderr, "elementary stream header too verbose or corrupted, out of lookahead parser buffer\n"); exit(2); } dts_base = dts; pts = dts_base + (time_reference * pts_step) + pts_step; byte_read = 1; if (pts_limit > 0ll && pts_first_gop > 0ll && pts_a_gop > 0ll && pts > pts_first_gop) { if (pts - pts_first_gop + pts_a_gop >= pts_limit - pts_first_gop) { byte_read = 0; } } if (byte_read) { pes_header[7] = 0xC0; /* pts and dts, no escr, no es rate, no dsm trick, no extension flag, no additional copy info, no crc flag */ pes_header[8] = 0x0A; /* pts and dts size*/ stamp_ts(pts % PTS_MAX, pes_header + 9); pes_header[9] &= 0x0F; pes_header[9] |= 0x30; stamp_ts(dts % PTS_MAX, pes_header + 14); pes_header[14] &= 0x0F; pes_header[14] |= 0x10; fwrite(pes_header, 1, PES_HEADER_SIZE, stdout); frame_counter++; if (pts_first_gop == 0ll && pts > pts_step) { pts_first_gop = dts; /* fprintf(stderr, "first gop pts length is %llu\n", pts_first_gop); */ } else if (pts_first_gop > 0 && pts_a_gop == 0ll) { pts_a_gop = dts - pts_first_gop; /* fprintf(stderr, "a gop pts length is %llu\n", pts_a_gop); */ } fwrite(header_buffer, 1, header_buffer_size, stdout); header_buffer_size = 0; dts += pts_step; byte_read = fread(es_header, 1, ES_HEADER_SIZE, file_es); } } else { fwrite(es_header, 1, 1, stdout); es_header[0] = es_header[1]; es_header[1] = es_header[2]; es_header[2] = es_header[3]; byte_read = fread(es_header + 3, 1, 1, file_es); } } return 0; } opencaster-3.2.2/tools/ts2m2ts/0000755000175000017500000000000012214326444015567 5ustar debiandebianopencaster-3.2.2/tools/ts2m2ts/Makefile0000644000175000017500000000062512214326444017232 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = ts2m2ts.o TARGET = ts2m2ts DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/ts2m2ts/ts2m2ts.c0000644000175000017500000000600112214326444017246 0ustar debiandebian/* * Copyright (C) 2011-2013, Lorenzo Pallara l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include #include #include #include #include #include #define TS_PACKET_SIZE 188 #define TS_EXTRA_HEADER 4 #define MAX_PID 8191 #define SYSTEM_CLOCK_FREQUENCY 2700000 int main (int argc, char *argv[]) { int len = 0; char* tsfile = 0; unsigned short pid = MAX_PID; int transport_fd = -1; unsigned int bitrate = 48000000; int completed = 1; unsigned char copyright_bits = 0; unsigned char output_packet[TS_EXTRA_HEADER + TS_PACKET_SIZE]; unsigned long long int ts_packet_count = 0; unsigned long long int timestamp = 0; unsigned long long int temp = 0; unsigned long long int carriage = 0; if(argc < 3 ) { fprintf(stderr, "Usage: %s file.ts bitrate_in_bps [copyright_bits_as_integer] > file.m2ts \n", argv[0]); return 0; } else { tsfile = argv[1]; bitrate = atoi(argv[2]); if (argc > 3) { copyright_bits = atoi(argv[3]); } } transport_fd = open(tsfile, O_RDONLY); if(transport_fd < 0) { fprintf(stderr, "can't open file %s\n", tsfile); return 0; } completed = 0; ts_packet_count = 0; while (!completed) { len = read(transport_fd, output_packet + TS_EXTRA_HEADER, TS_PACKET_SIZE); if(len < 0) { fprintf(stderr, "ts file read error \n"); completed = 1; } else if (len == 0) { completed = 1; } else { memcpy(&pid, output_packet + TS_EXTRA_HEADER + 1, 2); pid = ntohs(pid); pid = pid & 0x1fff; if (pid < MAX_PID) { /* drop null packets */ temp = ts_packet_count * TS_PACKET_SIZE * 8 * SYSTEM_CLOCK_FREQUENCY; temp /= bitrate; temp += carriage; timestamp = temp; output_packet[0] = ((copyright_bits & 0x03) << 6) | ((timestamp >> 24) & 0x3F); output_packet[1] = (timestamp >> 16) & 0xFF; output_packet[2] = (timestamp >> 8) & 0xFF; output_packet[3] = timestamp & 0xFF; write(STDOUT_FILENO, output_packet, TS_EXTRA_HEADER + TS_PACKET_SIZE); } /* manage overflown */ if (ts_packet_count * 2 >= 454263790) { ts_packet_count = 0; carriage = timestamp; } ts_packet_count++; } } close(transport_fd); return 0; } opencaster-3.2.2/tools/tspcrmeasure/0000755000175000017500000000000012214326444016766 5ustar debiandebianopencaster-3.2.2/tools/tspcrmeasure/Makefile0000644000175000017500000000064012214326444020426 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = tspcrmeasure.o TARGET = tspcrmeasure DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/tspcrmeasure/tspcrmeasure.c0000644000175000017500000001015612214326444021652 0ustar debiandebian/* * Copyright (C) 2004-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #define TS_PACKET_SIZE 188 #define MAX_PID 8192 #define SYSTEM_CLOCK_FREQUENCY 27000000 int main(int argc, char *argv[]) { int fd_ts; /* File descriptor of ts file */ u_short pid; int byte_read; unsigned int pcr_ext = 0; unsigned int ibits = 0; unsigned long long int pcr_base = 0; unsigned long long int ts_packet_count; unsigned long long int new_pcr = 0; unsigned long long int new_pcr_index = 0; unsigned long long int pid_pcr_table[MAX_PID]; /* PCR table for the TS packets */ unsigned long long int pid_pcr_index_table[MAX_PID]; /* PCR index table for the TS packets */ unsigned char ts_packet[TS_PACKET_SIZE];/* TS packet */ /* Open ts file */ if (argc == 3) fd_ts = open(argv[1], O_RDONLY); else { fprintf(stderr, "Usage: 'tspcrmeasure input.ts expected_bit/s'\n"); return 2; } if (fd_ts < 0) { fprintf(stderr, "Can't find file %s\n", argv[1]); return 2; } ibits = atoi(argv[2]); if (ibits == 0) { fprintf(stderr, "Expected bit/s is zero\n"); return 2; } /* Start to process the file */ memset(pid_pcr_table, 0, MAX_PID*(sizeof(unsigned long long int))); memset(pid_pcr_index_table, 0, MAX_PID*(sizeof(unsigned long long int))); ts_packet_count = 0; byte_read = 1; while(byte_read) { /* Read next packet */ byte_read = read(fd_ts, ts_packet, TS_PACKET_SIZE); /* check packet */ memcpy(&pid, ts_packet + 1, 2); pid = ntohs(pid); pid = pid & 0x1fff; if (pid < MAX_PID) { if ((ts_packet[3] & 0x20) && (ts_packet[4] != 0) && (ts_packet[5] & 0x10)) { /* there is a pcr field */ pcr_base = (((unsigned long long int)ts_packet[6]) << 25) + (ts_packet[7] << 17) + (ts_packet[8] << 9) + (ts_packet[9] << 1) + (ts_packet[10] >> 7); pcr_ext = ((ts_packet[10] & 1) << 8) + ts_packet[11]; if (pid_pcr_table[pid] == 0) { pid_pcr_table[pid] = pcr_base * 300 + pcr_ext; pid_pcr_index_table[pid] = (ts_packet_count * TS_PACKET_SIZE) + 10; fprintf(stdout, "%llu: pid %d, new pcr is %llu (%f sec)\n", pid_pcr_index_table[pid], pid, pid_pcr_table[pid], ((double)(pid_pcr_table[pid]) / SYSTEM_CLOCK_FREQUENCY) ); } else { new_pcr = pcr_base * 300 + pcr_ext; new_pcr_index = (ts_packet_count * TS_PACKET_SIZE) + 10; fprintf(stdout, "%llu: pid %d, new pcr is %llu (%f sec), pcr delta is %llu, (%f ms), indices delta is %llu bytes,( %f ms), pcr accuracy is %.10f, instant ts bit rate is %.10f\n", new_pcr_index, pid, new_pcr, ((double)(new_pcr) / SYSTEM_CLOCK_FREQUENCY), new_pcr - pid_pcr_table[pid], ((double)((new_pcr - pid_pcr_table[pid]) * 1000)) / SYSTEM_CLOCK_FREQUENCY, new_pcr_index - pid_pcr_index_table[pid], ((double)((new_pcr_index - pid_pcr_index_table[pid]) * 8 * 1000)) / ibits, (((double) (new_pcr - pid_pcr_table[pid])) / SYSTEM_CLOCK_FREQUENCY) - (((double)(new_pcr_index - pid_pcr_index_table[pid])) * 8 / ibits), (((double)(new_pcr_index - pid_pcr_index_table[pid])) * 8 * SYSTEM_CLOCK_FREQUENCY) / ((double)(new_pcr - pid_pcr_table[pid])) ); pid_pcr_table[pid] = new_pcr; pid_pcr_index_table[pid] = new_pcr_index; } } ts_packet_count++; } } return 0; } opencaster-3.2.2/tools/tsdiscont/0000755000175000017500000000000012214326444016263 5ustar debiandebianopencaster-3.2.2/tools/tsdiscont/Makefile0000644000175000017500000000063112214326444017723 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = tsdiscont.o TARGET = tsdiscont DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/tsdiscont/tsdiscont.c0000600000175000017500000001040712215024006020421 0ustar debiandebian/* * Copyright (C) 2009-2013 Lorenzo Pallara, l.pallara@avalpa.com * Copyright (C) 2011 Shane Andrusiak, blendz@shaw.ca * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #define TS_HEADER_SIZE 4 #define TS_PACKET_SIZE 188 #define MAX_PID 8192 #define PACK_HEADER_SIZE 4 #define TIME_STAMP_SIZE 5 int main(int argc, char *argv[]) { int fd_ts; u_short pid; int byte_read; int tsdiscont = 0; int haspcr = 0; int firstpcr = 0; int ts_header_size = 0; unsigned int i; unsigned int buffer_size; unsigned char adapt = 0; unsigned char* packet_buffer; unsigned char* current_packet; unsigned long long int ts_packet_count; /* Open ts file */ buffer_size = 0; if (argc >= 2) fd_ts = open(argv[1], O_RDONLY); else { fprintf(stderr, "Usage: tsdiscont inputfile.ts > outputfile.ts\n"); fprintf(stderr, "N.B: this tool will check for and fix discontinuity problems\n"); fprintf(stderr, "If discontinuity is found on packet without pcr it is set to 0\n"); fprintf(stderr, "If discontinuity is not found on first pcr packet it is set to 1\n"); return 2; } if (fd_ts < 0) { fprintf(stderr, "Can't find file %s\n", argv[1]); return 2; } buffer_size = 1; /* Start to process the file */ buffer_size *= TS_PACKET_SIZE; packet_buffer = malloc(buffer_size); if (packet_buffer == NULL) { fprintf(stderr, "out of memory\n"); return 2; } ts_packet_count = 0; byte_read = 1; while(byte_read) { /* Read next packets */ byte_read = read(fd_ts, packet_buffer, buffer_size); for (i = 0; i < buffer_size; i += TS_PACKET_SIZE) { current_packet = packet_buffer + i; memcpy(&pid, current_packet + 1, 2); pid = ntohs(pid); pid = pid & 0x1fff; if ((pid < MAX_PID) && (current_packet[3] & 0x20) && (current_packet[4] != 0) && (current_packet[5] & 0x10)) { haspcr=1; if(!firstpcr){ tsdiscont = (current_packet[5] & 0x80) >> 7; fprintf(stderr,"PID: %d, Pos: %lld - First Pcr Discont : %X\n",pid, ts_packet_count,tsdiscont); if(!tsdiscont){ current_packet[5] = current_packet[5] | 0x80; fprintf(stderr,"PID: %d, Pos: %lld - Fixed first pcr discontinuity flag\n",pid, ts_packet_count); } firstpcr=1; } }else{ haspcr=0; } tsdiscont = 0; adapt = (current_packet[3] >> 4) & 0x03; if (adapt == 0) { /* the packet is invalid ?*/ ts_header_size = TS_PACKET_SIZE; fprintf(stderr,"PID: %d, Pos: %lld - Invalid packet found\n",pid, ts_packet_count); } else if (adapt == 1) { /* only payload , we can skip this*/ ts_header_size = TS_HEADER_SIZE; } else if (adapt == 2) { /* only adaptation field , if we have pcr, check flag*/ tsdiscont = (current_packet[5] & 0x80) >> 7; ts_header_size = TS_PACKET_SIZE; } else if (adapt == 3) { /* adapt and payload */ tsdiscont = (current_packet[5] & 0x80) >> 7; ts_header_size = TS_HEADER_SIZE + current_packet[4] + 1; } else { /* hmmmm */ ts_header_size = TS_PACKET_SIZE; fprintf(stderr,"PID: %d, Pos: %lld - Invalid adaptation field flag found : %X\n",pid, ts_packet_count,adapt); } if(tsdiscont){ if(haspcr){ fprintf(stderr,"PID: %d, Pos: %lld - discontinuity found with pcr : %X\n",pid, ts_packet_count,adapt); }else{ fprintf(stderr,"PID: %d, Pos: %lld - Fixing discontinuity found WITHOUT pcr : %X\n",pid, ts_packet_count,adapt); current_packet[5] = current_packet[5] & 0x7F; } } ts_packet_count++; } write(STDOUT_FILENO, packet_buffer, buffer_size); } return 0; } opencaster-3.2.2/tools/pesinfo/0000755000175000017500000000000012214326443015713 5ustar debiandebianopencaster-3.2.2/tools/pesinfo/pesinfo.c0000644000175000017500000001205112214326443017521 0ustar debiandebian/* * Copyright (C) 2004-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #include #define PACK_HEADER_SIZE 4 #define TIME_STAMP_SIZE 5 const long long unsigned system_frequency = 27000000; unsigned long long parse_timestamp(unsigned char *buf) { unsigned long long a1; unsigned long long a2; unsigned long long a3; unsigned long long ts; a1 = (buf[0] & 0x0F) >> 1; a2 = ((buf[1] << 8) | buf[2]) >> 1; a3 = ((buf[3] << 8) | buf[4]) >> 1; ts = (a1 << 30) | (a2 << 15) | a3; return ts; } int main(int argc, char *argv[]) { int byte_read; FILE* file_pes; unsigned short pes_size; long long unsigned time; unsigned char pes_header[PACK_HEADER_SIZE]; unsigned char timestamp[TIME_STAMP_SIZE]; unsigned char byte; /* Open pes file */ if (argc > 1) { file_pes = fopen(argv[1], "rb"); } else { fprintf(stderr, "Usage: 'pesinfo filename.pes'\n"); return 2; } if (file_pes == 0) { fprintf(stderr, "Can't find file %s\n", argv[1]); return 2; } /* Start to process the file */ byte_read = fread(pes_header, 1, 4, file_pes); while(byte_read) { /* Check headers */ byte_read = 0; if ((pes_header[0] == 0x00) && (pes_header[1] == 0x00) && (pes_header[2] == 0x01)) { if ((pes_header[3] >> 4) == 0x0E) { fprintf(stdout, "pes header: %02x %02x %02x %02x, ", pes_header[0], pes_header[1], pes_header[2], pes_header[3]); fprintf(stdout, "video stream number %d, ", pes_header[3] & 0x0F); fread(&pes_size, 1, 2, file_pes); /* get pack size */ pes_size = ntohs(pes_size); fprintf(stdout, "pes size %d, ", pes_size); fseek(file_pes, 2, SEEK_CUR); /* get header size */ fread(&byte, 1, 1, file_pes); fprintf(stdout, "header length: %d, ", byte); fread(timestamp, 1, TIME_STAMP_SIZE, file_pes); time = parse_timestamp(timestamp); fprintf(stdout, "Presentation Time Stamp is: %llu, %llu.%04llu sec.", time, time / (system_frequency / 300), (time % (system_frequency / 300)) / ((system_frequency / 300) / 10000)); if (byte > 5) { byte_read = fread(timestamp, 1, TIME_STAMP_SIZE, file_pes); time = parse_timestamp(timestamp); fprintf(stdout, ", Decode Time Stamp is: %llu, %llu.%04llu sec.\n", time, time / (system_frequency / 300), (time % (system_frequency / 300)) / ((system_frequency / 300) / 10000)); } else { fprintf(stdout, "\n"); } byte_read = fread(pes_header, 1, 4, file_pes); } else if ((pes_header[3] >> 5) == 0x06) { fprintf(stdout, "pes header: %02x %02x %02x %02x, ", pes_header[0], pes_header[1], pes_header[2], pes_header[3]); fprintf(stdout, "audio stream number %d, ", pes_header[3] & 0x1F); fread(&pes_size, 1, 2, file_pes); /* get pack size */ pes_size = ntohs(pes_size); fprintf(stdout, "pes size %d, ", pes_size); fseek(file_pes, 2, SEEK_CUR); /* get header size */ fread(&byte, 1, 1, file_pes); fprintf(stdout, "header length: %d, ", byte); fread(timestamp, 1, TIME_STAMP_SIZE, file_pes); time = parse_timestamp(timestamp); fprintf(stdout, "Presentation Time Stamp is: %llu, %llu.%04llu sec.\n", time, time / (system_frequency / 300), (time % (system_frequency / 300)) / ((system_frequency / 300) / 10000)); byte_read = fread(pes_header, 1, 4, file_pes); } else if (pes_header[3] == 0xBD) { fprintf(stdout, "pes header: %02x %02x %02x %02x, ", pes_header[0], pes_header[1], pes_header[2], pes_header[3]); fread(&pes_size, 1, 2, file_pes); /* get pack size */ pes_size = ntohs(pes_size); fprintf(stdout, "pes size %d, ", pes_size); fseek(file_pes, 2, SEEK_CUR); /* get header size */ fread(&byte, 1, 1, file_pes); fprintf(stdout, "header length: %d, ", byte); fread(timestamp, 1, TIME_STAMP_SIZE, file_pes); time = parse_timestamp(timestamp); fprintf(stdout, "Presentation Time Stamp is: %llu, %llu.%04llu sec.\n", time, time / (system_frequency / 300), (time % (system_frequency / 300)) / ((system_frequency / 300) / 10000)); byte_read = fread(pes_header, 1, 4, file_pes); } } if (byte_read == 0) { pes_header[0] = pes_header[1]; pes_header[1] = pes_header[2]; pes_header[2] = pes_header[3]; byte_read = fread(pes_header+3, 1, 1, file_pes); } } return 0; } opencaster-3.2.2/tools/pesinfo/Makefile0000644000175000017500000000062512214326443017356 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = pesinfo.o TARGET = pesinfo DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/pesvideo2ts/0000755000175000017500000000000012232256710016516 5ustar debiandebianopencaster-3.2.2/tools/pesvideo2ts/Makefile0000644000175000017500000000063512214326443020163 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = pesvideo2ts.o TARGET = pesvideo2ts DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/pesvideo2ts/pesvideo2ts.c0000644000175000017500000006640112232256710021140 0ustar debiandebian/* * Copyright (C) 2004-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #define _BSD_SOURCE 1 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef PATH_MAX #define PATH_MAX 4096 #endif #define MAX_PID 8192 #define TS_HEADER_SIZE 4 #define TS_PACKET_SIZE 188 #define PES_HEADER_SIZE 19 /* check also for pts and dts */ #define PCR_DELTA 39 /* ms */ #define SYSTEM_CLOCK 90000.0 #define PTS_MAX 8589934592LL #define TIME_STAMP_SIZE 5 #define PACK_HEADER_SIZE 4 #define MAX_FD 256 const long long unsigned system_frequency = 27000000; int ts_payload; /* TS packet payload counter */ unsigned short pid; /* Pid for the TS packets */ unsigned char ts_continuity_counter; /* Continuity counter */ unsigned char ts_packet[TS_PACKET_SIZE]; /* TS packet */ unsigned char look_ahead_buffer[PES_HEADER_SIZE]; unsigned char null_ts_packet[TS_PACKET_SIZE]; unsigned char pcr_ts_packet[TS_PACKET_SIZE]; unsigned char look_ahead_size; int frame_rate = 0; unsigned long long last_frame_index = 0L; unsigned long long last_frame_popped = 0L; unsigned long long old_pcr = 0L; unsigned long long frames = 0L; /* frames counter */ int vbv_buffer_size = 0L; /* size of the video buffer verifier in bit */ unsigned long long es_input_bytes = 0; /* input bytes of the elementary stream */ unsigned long long es_input_bytes_old = 0; /* input bytes of the elementary stream at previous analysis */ unsigned long long ts_output_bytes = 0; /* output bytes of the transport stream */ int es_bitrate = 0; /* bitrate of the input elementary stream */ int ts_bitrate = 0; /* bitrate of the output transport stream */ int vbv_max = 0; /* video buffer verifier maximum size */ int vbv_current_size = 0; /* video buffer verifier current size */ int first_frame_ts_size = 0; unsigned long long int pts; /* PTS last value */ unsigned long long int pts_delta; /* PTS delta increment */ unsigned char pts_index; /* PTS index for the TS packets */ int first_pts = 0; char filename[PATH_MAX]; int pcr_repetition_rate = PCR_DELTA; typedef struct queue { unsigned long long size; struct queue* next; } queue; queue* g_head_queue = 0; queue* g_tail_queue = 0; unsigned long long pop_frame(void){ int result; queue* temp; if (g_head_queue) { result = g_head_queue->size; temp = g_head_queue->next; free(g_head_queue); g_head_queue = temp; } else { result = 0; } return result; } void enqueue_frame(unsigned long long size) { queue* new_queue; new_queue = (queue*) malloc(sizeof(queue)); new_queue->size = size; new_queue->next = 0; if (g_head_queue == 0) { /* first element */ g_head_queue = new_queue; g_tail_queue = new_queue; } else { g_tail_queue->next = new_queue; /* last element on tail */ g_tail_queue = new_queue; } } void emulate_vbv_tick(void) { if (frames > 0) { /* first frame was sent on output, second frame header found on input */ if (last_frame_popped == 0 && g_head_queue != 0) { /* first frame is flushed as soon as received */ /* fprintf(stderr, "vbv size before frame %llu is %d\n", last_frame_popped + 1, vbv_current_size); */ vbv_current_size -= pop_frame() * 8; last_frame_popped = 1; /* fprintf(stderr, "vbv size after frame %llu is %d\n", last_frame_popped, vbv_current_size); */ } else { /* others frames are flushed at the receiver every 1/fps after the first frame receiving time */ /* if output time is bigger then first frame time + frames * frame rate, it's time to flush a frame */ if (frame_rate == 24 || frame_rate == 25 || frame_rate == 50 || frame_rate == 30 || frame_rate == 60) { if (ts_output_bytes >= (first_frame_ts_size + (((1.0 / frame_rate) * ts_bitrate * (last_frame_popped + 1)) / 8)) ) { /* fprintf(stderr, "vbv size before frame %llu is %d\n", last_frame_popped + 1, vbv_current_size); */ vbv_current_size -= pop_frame() * 8; last_frame_popped++; /* fprintf(stderr, "vbv size after frame %llu is %d\n", last_frame_popped, vbv_current_size); */ } } else if (frame_rate == 23 || frame_rate == 29 || frame_rate == 59) { /* fprintf(stderr, "output bytes are %llu, evaluation is %f\n", ts_output_bytes, (first_frame_ts_size + ((f_frame_rate * ts_bitrate * (last_frame_popped + 1)) / 8))); */ if (ts_output_bytes >= (first_frame_ts_size + ((1001.0 * ts_bitrate * (last_frame_popped + 1)) / (8 * (frame_rate + 1) * 1000.0)))) { /* fprintf(stderr, "vbv size before frame %llu is %d\n", last_frame_popped + 1, vbv_current_size); */ vbv_current_size -= pop_frame() * 8; last_frame_popped++; /* fprintf(stderr, "vbv size after frame %llu is %d\n", last_frame_popped, vbv_current_size); */ } } } } } void send_pcr_packet() { unsigned long long pcr_base; unsigned long long pcr_ext; unsigned long long new_pcr; new_pcr = ((ts_output_bytes + 10) * 8 * system_frequency) / ts_bitrate; /* fprintf(stderr, "pcr is %llu, time is %llu.%04llu sec\n", new_pcr, new_pcr / system_frequency, (new_pcr % system_frequency) / (system_frequency / 10000)); */ if (new_pcr > 2576980377600ll) { new_pcr -= 2576980377600ll; if (frame_rate == 24 || frame_rate == 25 || frame_rate == 50 || frame_rate == 30 || frame_rate == 60) { /* fprintf(stderr, "ts_output_bytes before %llu\n", ts_output_bytes); fprintf(stderr, "vbv evaluation before %llu\n", (unsigned long long)(first_frame_ts_size + (((1.0 / frame_rate) * ts_bitrate * (last_frame_popped + 1)) / 8))); fprintf(stderr, "pcr loop\n"); */ unsigned long long vbv_diff = ts_output_bytes - (first_frame_ts_size + (((1.0 / frame_rate) * ts_bitrate * (last_frame_popped + 1)) / 8)); /* adjust the vbv fullness to the new ts_output_bytes value */ ts_output_bytes = (((new_pcr * ts_bitrate) + (80ll * system_frequency)) / (system_frequency * 8)) - 20; last_frame_popped = 1; first_frame_ts_size = ts_output_bytes - vbv_diff - (((1.0 / frame_rate) * ts_bitrate * 2) / 8); emulate_vbv_tick(); /* fprintf(stderr, "ts_output_bytes after %llu\n", ts_output_bytes); fprintf(stderr, "vbv evaluation after %llu\n",(unsigned long long)(first_frame_ts_size + (((1.0 / frame_rate) * ts_bitrate * (last_frame_popped + 1)) / 8))); */ } else if (frame_rate == 23 || frame_rate == 29 || frame_rate == 59) { float f_frame_rate = (frame_rate + 1 ) * 1000; /* fprintf(stderr, "ts_output_bytes before %llu\n", ts_output_bytes); fprintf(stderr, "vbv evaluation before %llu\n", (unsigned long long)(first_frame_ts_size + (((f_frame_rate / 1001) * ts_bitrate * (last_frame_popped + 1)) / 8))); fprintf(stderr, "pcr loop\n"); */ unsigned long long vbv_diff = ts_output_bytes - (first_frame_ts_size + (((f_frame_rate / 1001) * ts_bitrate * (last_frame_popped + 1)) / 8)); /* adjust the vbv fullness to the new ts_output_bytes value */ ts_output_bytes = (((new_pcr * ts_bitrate) + (80ll * system_frequency)) / (system_frequency * 8)) - 20; last_frame_popped = 1; first_frame_ts_size = ts_output_bytes - vbv_diff - (((f_frame_rate / 1001) * ts_bitrate * 2) / 8); emulate_vbv_tick(); /* fprintf(stderr, "ts_output_bytes after %llu\n", ts_output_bytes); fprintf(stderr, "vbv evaluation after %llu\n",(unsigned long long)(first_frame_ts_size + (((f_frame_rate / 1001) * ts_bitrate * (last_frame_popped + 1)) / 8))); */ } } /* marshal pcr */ pcr_base = new_pcr / 300; pcr_ext = new_pcr % 300; pcr_ts_packet[6] = (0xFF & (pcr_base >> 25)); pcr_ts_packet[7] = (0xFF & (pcr_base >> 17)); pcr_ts_packet[8] = (0xFF & (pcr_base >> 9)); pcr_ts_packet[9] = (0xFF & (pcr_base >> 1)); pcr_ts_packet[10] = ((0x1 & pcr_base) << 7) | 0x7E | ((0x100 & pcr_ext) >> 8); pcr_ts_packet[11] = (0xFF & pcr_ext); pcr_ts_packet[3] = ts_continuity_counter | 0x20; /* continuity counter, no scrambling, only adaptation field */ ts_continuity_counter = (ts_continuity_counter + 1) % 0x10; /* inc. continuity counter */ write(STDOUT_FILENO, pcr_ts_packet, TS_PACKET_SIZE); ts_output_bytes += TS_PACKET_SIZE; } void stamp_ts (unsigned long long int ts, unsigned char* buffer) { if (buffer) { buffer[0] = ((ts >> 29) & 0x0F) | 0x01; buffer[1] = (ts >> 22) & 0xFF; buffer[2] = ((ts >> 14) & 0xFF ) | 0x01; buffer[3] = (ts >> 7) & 0xFF; buffer[4] = ((ts << 1) & 0xFF ) | 0x01; } } unsigned long long parse_timestamp(unsigned char *buf) { unsigned long long a1; unsigned long long a2; unsigned long long a3; unsigned long long ts; a1 = (buf[0] & 0x0F) >> 1; a2 = ((buf[1] << 8) | buf[2]) >> 1; a3 = ((buf[3] << 8) | buf[4]) >> 1; ts = (a1 << 30) | (a2 << 15) | a3; return ts; } void restamp_ptsdts_and_output(void) { /* check PTS and DTS */ unsigned char adapt = (ts_packet[3] >> 4) & 0x03; unsigned long long time = 0; unsigned long long int dts; unsigned char timestamp[TIME_STAMP_SIZE]; int ts_header_size = 0; int pes_header_size = 0; int first_packet_of_an_iframe = 0; if (adapt == 0) { ts_header_size = TS_PACKET_SIZE; /* the packet is invalid ?*/ ; } else if (adapt == 1) { ts_header_size = TS_HEADER_SIZE; /* only payload */ } else if (adapt == 2) { ts_header_size = TS_PACKET_SIZE; /* only adaptation field */ } else if (adapt == 3) { ts_header_size = TS_HEADER_SIZE + ts_packet[4] + 1; /* jump the adaptation field */ } else { ts_header_size = TS_PACKET_SIZE; /* not managed */ } /* check the time difference between first two pts and offset all the others */ time = 0; if (ts_header_size + 20 < TS_PACKET_SIZE) { if ((ts_packet[ts_header_size] == 0x00) && (ts_packet[ts_header_size + 1] == 0x00) && (ts_packet[ts_header_size + 2] == 0x01)) { pes_header_size = ts_packet[ts_header_size + 8]; if ((ts_packet[ts_header_size + 3] >> 4) == 0x0E) { /* PES video stream */ memcpy(timestamp, ts_packet + ts_header_size + 9, TIME_STAMP_SIZE); time = parse_timestamp(timestamp); /* fprintf(stderr, "Old Video Presentation Time Stamp is: %llu, %llu.%04llu sec.\n", time, time / (system_frequency / 300), (time % (system_frequency / 300)) / ((system_frequency / 300) / 10000)); */ if (pes_header_size > 5) { memcpy(timestamp, ts_packet + ts_header_size + 14, TIME_STAMP_SIZE); time = parse_timestamp(timestamp); /* fprintf(stderr, "Old Video Decode Time Stamp is: %llu, %llu.%04llu sec.\n", time, time / (system_frequency / 300), (time % (system_frequency / 300)) / ((system_frequency / 300) / 10000)); */ } if (pts_index == 0) { if (pes_header_size > 5) { /* if there are both dts and pts, get dts */ memcpy(timestamp, ts_packet + ts_header_size + 14, TIME_STAMP_SIZE); time = parse_timestamp(timestamp); } else { /* othewise they are the same */ memcpy(timestamp, ts_packet + ts_header_size + 9, TIME_STAMP_SIZE); time = parse_timestamp(timestamp); } pts_index = 1; pts = time; } else if (pts_index == 1) { if (pes_header_size > 5) { /* if there are both dts and pts, get dts */ memcpy(timestamp, ts_packet + ts_header_size + 14, TIME_STAMP_SIZE); time = parse_timestamp(timestamp); } else { /* othewise they are the same */ memcpy(timestamp, ts_packet + ts_header_size + 9, TIME_STAMP_SIZE); time = parse_timestamp(timestamp); } pts_index = 2; pts_delta = time - pts; pts = time; } else { if (pes_header_size > 5) { /* if there are both dts and pts */ memcpy(timestamp, ts_packet + ts_header_size + 9, TIME_STAMP_SIZE); time = parse_timestamp(timestamp); memcpy(timestamp, ts_packet + ts_header_size + 14, TIME_STAMP_SIZE); time -= parse_timestamp(timestamp); pts += pts_delta; /* dts goes up 1 step */ dts = pts; stamp_ts(dts % PTS_MAX, ts_packet + ts_header_size + 14); ts_packet[ts_header_size + 14] &= 0x0F; ts_packet[ts_header_size + 14] |= 0x30; /* pts goes up the same gap there was before */ stamp_ts((pts + time) % PTS_MAX, ts_packet + ts_header_size + 9); ts_packet[ts_header_size + 9] &= 0x0F; ts_packet[ts_header_size + 9] |= 0x20; first_packet_of_an_iframe = ((ts_packet[ts_header_size + 25] & 0x38) >> 3) == 1; } else { memcpy(timestamp, ts_packet + ts_header_size + 9, TIME_STAMP_SIZE); time = parse_timestamp(timestamp); pts += pts_delta; stamp_ts(pts % PTS_MAX, ts_packet + ts_header_size + 9); ts_packet[ts_header_size + 9] &= 0x0F; ts_packet[ts_header_size + 9] |= 0x20; } } memcpy(timestamp, ts_packet + ts_header_size + 9, TIME_STAMP_SIZE); time = parse_timestamp(timestamp); if (first_pts) { fprintf(stderr, "pesvideo2ts sync: %s new presented video frame is at: %llu, %llu.%04llu sec.", filename, time, time / (system_frequency / 300), (time % (system_frequency / 300)) / ((system_frequency / 300) / 10000)); } if (pes_header_size > 5) { memcpy(timestamp, ts_packet + ts_header_size + 14, TIME_STAMP_SIZE); time = parse_timestamp(timestamp); if (first_pts) { fprintf(stderr, ", decode time stamp is at: %llu, %llu.%04llu sec.\n", time, time / (system_frequency / 300), (time % (system_frequency / 300)) / ((system_frequency / 300) / 10000)); } } else { if (first_pts) { fprintf(stderr, "\n"); } } if (first_pts) { first_pts = 0; } } } } write(STDOUT_FILENO, ts_packet, TS_PACKET_SIZE); } void send_current_packet(unsigned long long es_payload) { int i; unsigned char temp; if (TS_HEADER_SIZE + ts_payload == TS_PACKET_SIZE) { /* payload fits */ ts_packet[3] = ts_continuity_counter | 0x10; /* continuity counter, no scrambling, only payload */ ts_continuity_counter = (ts_continuity_counter + 1) % 0x10; /* inc. continuity counter */ restamp_ptsdts_and_output(); ts_output_bytes += TS_PACKET_SIZE; ts_payload = 0; vbv_current_size += es_payload * 8; } else if (TS_HEADER_SIZE + ts_payload + 1 == TS_PACKET_SIZE) { /* payload too big: two packets are necessary */ temp = ts_packet[TS_HEADER_SIZE + ts_payload - 1]; /* copy the exceeding byte */ ts_payload--; send_current_packet(es_payload - 1); /* ts payload is es payload because pes header can't occuer at the end of the pes... */ memcpy(ts_packet + 1, &pid, 2); /* pid, no pusu */ ts_packet[4] = temp; ts_payload = 1; send_current_packet(1); } else { /* payload too small: padding is necessary */ ts_packet[3] = ts_continuity_counter | 0x30; /* continuity counter, no scrambling, adaptation field and payload */ ts_continuity_counter = (ts_continuity_counter + 1) % 0x10; /* inc. continuity counter */ for (i = 0; i < ts_payload; i++) { /* move the payload at the end */ ts_packet[TS_PACKET_SIZE - 1 - i] = ts_packet[TS_HEADER_SIZE + ts_payload - 1 - i]; } ts_packet[4] = TS_PACKET_SIZE - ts_payload - TS_HEADER_SIZE - 1; /* point to the first payload byte */ ts_packet[5] = 0x00; /* no options */ for ( i = TS_HEADER_SIZE + 2 ; i < TS_PACKET_SIZE - ts_payload; i++) { /* pad the packet */ ts_packet[i] = 0xFF; } restamp_ptsdts_and_output(); ts_output_bytes += TS_PACKET_SIZE; ts_payload = 0; vbv_current_size += es_payload * 8; } /* emulate vbv on the receiver */ emulate_vbv_tick(); /* check if it is time for a pcr packet */ if ( (ts_output_bytes + TS_PACKET_SIZE - old_pcr) * 8 * 1000 > pcr_repetition_rate * ts_bitrate ) { send_pcr_packet(); old_pcr = ts_output_bytes; emulate_vbv_tick(); } /* vbv control: check if the receiver video buffer can receiver the next packet, if it can't output null packets until a frame is flushed */ while (vbv_current_size + ((TS_PACKET_SIZE - TS_HEADER_SIZE) * 8) > vbv_max) { write(STDOUT_FILENO, null_ts_packet, TS_PACKET_SIZE); ts_output_bytes += TS_PACKET_SIZE; emulate_vbv_tick(); if ( (ts_output_bytes + TS_PACKET_SIZE - old_pcr) * 8 * 1000 > pcr_repetition_rate * ts_bitrate ) { send_pcr_packet(); old_pcr = ts_output_bytes; emulate_vbv_tick(); } } } FILE* openStream(char* argv[], int open_counter, FILE* file_pes[]) { FILE* result = NULL; struct stat file_stat; /* fprintf(stderr, "pesvideo2ts: opening %s... ", argv[6 + open_counter]); */ if (lstat(argv[6 + open_counter], &file_stat) == 0) { if (!S_ISFIFO(file_stat.st_mode)) { result = fopen(argv[6 + open_counter], "rb"); file_pes[open_counter] = result; /* fprintf(stderr, "open\n"); */ } else { result = file_pes[open_counter]; /* fprintf(stderr, "is a fifo\n"); */ } } return result; } void closeStream(char* argv[], int open_counter, FILE* file_pes[]) { struct stat file_stat; /* fprintf(stderr, "pesvideo2ts: closing %s... ", argv[6 + open_counter]); */ if (lstat(argv[6 + open_counter], &file_stat) == 0) { if (!S_ISFIFO(file_stat.st_mode)) { fclose(file_pes[open_counter]); /* fprintf(stderr, "closed\n"); */ } else { /* fprintf(stderr, "is a fifo\n"); */ } } else { fclose(file_pes[open_counter]); /* fprintf(stderr, "closed but now is missing\n"); */ } } int main(int argc, char *argv[]) { int i = 0; int open_counter = 0; int loop_on = 0; int byte_read = 0; int total_bytes = 0; FILE* current_file_pes = NULL; pid = MAX_PID; FILE* file_pes[MAX_FD]; memset(file_pes, 0, sizeof(FILE*) * MAX_FD); if (argc >= 7) { pid = atoi(argv[1]); frame_rate = atoi(argv[2]); if (argv[2][2] == ':') { pcr_repetition_rate = atoi(argv[2]+3); pcr_repetition_rate -= 1; // stay under } fprintf(stderr, "frame rate is %d\n", frame_rate); if (argv[3][0] == 'b') { vbv_max = atoi(argv[3]+1); } else { vbv_max = atoi(argv[3]) * 16 * 1024; // bits } fprintf(stderr, "vbv size in bit is %d\n", vbv_max); ts_bitrate = atoi(argv[4]); loop_on = atoi(argv[5]) > 0; file_pes[0] = fopen(argv[6], "rb"); if (file_pes[0] == NULL) { fprintf(stderr, "pesvideo2ts: failed to open %s\n", argv[6]); return 0; } else { snprintf(filename, PATH_MAX, "%s", argv[6]); current_file_pes = file_pes[0]; } if (pid >= MAX_PID) { fprintf(stderr, "pesvideo2ts: pid has to be smaller than %d\n", MAX_PID); } } /* fifo are all open at the begin */ for (i = 7; i < argc; i++) { struct stat file_stat; if (lstat(argv[i], &file_stat) == 0) { if (S_ISFIFO(file_stat.st_mode)) { file_pes[i - 6] = fopen(argv[i], "rb"); if (file_pes[i - 6] == NULL) { fprintf(stderr, "pesvideo2ts: failed to open %s\n", argv[i]); return 0; } else { fprintf(stderr, "pesvideo2ts: opens also fifo %s\n", argv[i]); } } else { file_pes[i - 6] = NULL; } } else { file_pes[i - 6] = NULL; } } if (argc < 7) { fprintf(stderr, "Usage: 'pesvideo2ts pid es_framerate[:pcr_rate] es_video_vbv ts_video_bitrate loop_on input1.pes [input2.pes ... input%d.pes]'\n", MAX_FD); fprintf(stderr, " where pid is bounded from 1 to 8191\n"); fprintf(stderr, " es_framerate is elementary stream frame rate\n"); fprintf(stderr, " pcr_rate is pcr insertion repetetion in milliseconds\n"); fprintf(stderr, " es_video_vbv is elementary stream vbv size example: 112 are vbv units (16 * 1024 bit), b1024 is 1024 bit \n"); fprintf(stderr, " ts_video_bitrate is the output bitrate desired\n"); fprintf(stderr, " if loop_on is 1 input file are read on loop, works only for mpeg2 video files\n"); fprintf(stderr, " if the first file of the loop is missing the loop ends\n"); fprintf(stderr, " more than 1 file is only for mpeg2 videos\n"); fprintf(stderr, " input files can be changed at runtime if not fifo\n"); /* this limit comes from linux system calls, I am not sure but aix or freebsd won't have it */ fprintf(stderr, "framerate available are 23, 24, 25, 29, 30, 50, 59 and 60\n"); fprintf(stderr, "29 is actually 30000÷1001 as from standard and so on\n"); return 0; } /* Set some init. values */ pid = htons(pid); ts_payload = 0; look_ahead_size = 0; ts_continuity_counter = 0x0; ts_packet[0] = 0x47; /* sync byte */ memcpy(ts_packet + 1, &pid, 2); /* pid */ ts_packet[1] |= 0x40; /* payload unit start indicator */ byte_read = 1; /* Init null packet */ memset(null_ts_packet, 0, TS_PACKET_SIZE); null_ts_packet[0] = 0x47; null_ts_packet[1] = 0x1F; null_ts_packet[2] = 0xFF; null_ts_packet[3] = 0x10; /* PCR packet setup */ memset(pcr_ts_packet, 0xFF, TS_PACKET_SIZE); pcr_ts_packet[0] = 0x47; memcpy(pcr_ts_packet + 1, &pid, 2); /* pid */ pcr_ts_packet[3] = 0x20; /* only adaptation field, cc starts from zero */ pcr_ts_packet[4] = 183; /* again because there is only adaptation field */ pcr_ts_packet[5] = 0x10; /* there is only pcr */ ts_output_bytes = 0; /* Set the pcr as the first packets helps decoder to learn the new time as soon as possible */ /* also minimize the distance from a previous pcr */ send_pcr_packet(); /* Process the PES file */ byte_read = fread(look_ahead_buffer, 1, PES_HEADER_SIZE, current_file_pes); if (byte_read > 0) { total_bytes += byte_read; } es_input_bytes = byte_read; look_ahead_size = byte_read; last_frame_index = 0; int head_missing = 0; while (!head_missing) { /* first file, aka head, was complety read and loop mode is off or it was deleted*/ if (look_ahead_size == 0 && loop_on == 0 && byte_read == 0) { head_missing = 1; } while ((byte_read || look_ahead_size) && !head_missing) { /* Fill the look ahead buffer */ if (look_ahead_size < PES_HEADER_SIZE && current_file_pes != NULL) { /*fprintf(stderr, "1: look_ahead_size is %d\n", look_ahead_size); */ byte_read = fread(look_ahead_buffer + look_ahead_size, 1, 1, current_file_pes); if (byte_read > 0) { total_bytes += byte_read; } /* else { fprintf(stderr, "pesvideo2ts: warning: processing read was %d, look ahead is %d\n", byte_read, look_ahead_size); } */ if (byte_read <= 0 && loop_on) { /* try to get bytes from the next file on the list */ closeStream(argv, open_counter, file_pes); current_file_pes = NULL; open_counter++; /* fprintf(stderr, "pesvideo2ts: %s total bytes %d\n", filename, total_bytes); */ if (argc >= 7 + open_counter) { current_file_pes = openStream(argv, open_counter, file_pes); if (current_file_pes != NULL) { snprintf(filename, PATH_MAX, "%s", argv[6 + open_counter]); } /* else { fprintf(stderr, "pesvideo2ts: failed to open %s\n", argv[6 + open_counter]); } */ } if (current_file_pes == NULL) { open_counter = 0; current_file_pes = openStream(argv, open_counter, file_pes); if (current_file_pes != NULL) { snprintf(filename, PATH_MAX, "%s", argv[6 + open_counter]); } /* else { fprintf(stderr, "pesvideo2ts failed to open %s\n", argv[6 + open_counter]); } */ } total_bytes = 0; if (current_file_pes != NULL) { byte_read = fread(look_ahead_buffer + look_ahead_size, 1, 1, current_file_pes); if (byte_read > 0) { total_bytes += byte_read; first_pts = 1; } else { /* fprintf(stderr, "pesvideo2ts: restarting read was %d, look ahead is %d\n", byte_read, look_ahead_size); */ head_missing = 1; } } else { fprintf(stderr, "pesvideo2ts: first file of the loop is missing\n"); byte_read = 0; head_missing = 1; } } look_ahead_size += byte_read; es_input_bytes += byte_read; /* it will overflown at 100mbps after countless years */ } /* PES header detected? */ /* fprintf(stderr, "look_ahead_size is %d\n", look_ahead_size); */ if (look_ahead_size == PES_HEADER_SIZE && look_ahead_buffer[0] == 0x00 && look_ahead_buffer[1] == 0x00 && look_ahead_buffer[2] == 0x01 && ((look_ahead_buffer[3] == 0xE0) || ((look_ahead_buffer[3] >> 5) == 0x06))) { /* decrease pts header from elementary stream frame size byte counts */ /* fprintf(stderr, "es_input_bytes is %llu, byte is %d\n", es_input_bytes, look_ahead_buffer[8]); */ es_input_bytes -= (9 + look_ahead_buffer[8]); /* we learned the previous frame size so we enqueue it */ if (es_input_bytes > 0) { enqueue_frame(es_input_bytes - last_frame_index); /* fprintf(stderr, "frame %llu size is %llu\n", frames, es_input_bytes - last_frame_index); */ /* get the output size of the first frame */ if (first_frame_ts_size == 0) { first_frame_ts_size = ts_output_bytes; /* ts_offset = (ts_output_bytes * 8 * SYSTEM_CLOCK) / ts_bitrate; fprintf(stderr, "pts offset is %llu\n", ts_offset); */ } } if (frames == 0) { frames++; } last_frame_index = es_input_bytes; /* Send current packet if there's anything ready */ if (ts_payload) { send_current_packet(es_input_bytes - es_input_bytes_old); es_input_bytes_old = es_input_bytes; } /* Set pusu for the next packet */ memcpy(ts_packet + 1, &pid, 2); /* pid */ ts_packet[1] |= 0x40; /* payload unit start indicator */ } /* Fill the current packet */ if (look_ahead_size > 0 && ((loop_on && byte_read > 0) || (!loop_on)) ) { /* Move a packet from the lookahead to the current packet */ ts_packet[TS_HEADER_SIZE + ts_payload] = look_ahead_buffer[0]; ts_payload++; for (i = 0; i < PES_HEADER_SIZE-1; i++){ look_ahead_buffer[i] = look_ahead_buffer[i + 1]; } look_ahead_size--; /* Send the packet if it's filled */ if (TS_HEADER_SIZE + ts_payload == TS_PACKET_SIZE) { send_current_packet(es_input_bytes - es_input_bytes_old); es_input_bytes_old = es_input_bytes; /* Unset pusu for the next packet */ memcpy(ts_packet + 1, &pid, 2); /* pid */ } } /* Send the last packet with the last bytes if any */ if (byte_read == 0 && look_ahead_size == 0 && ts_payload) { send_current_packet(es_input_bytes - es_input_bytes_old); es_input_bytes_old = es_input_bytes; } } /* if are processing fifo and we are on loop, let's block */ for (i = 6; i < argc && loop_on; i++) { struct stat file_stat; if (lstat(argv[i], &file_stat) == 0) { if (S_ISFIFO(file_stat.st_mode)) { fclose(file_pes[i - 6]); } } } for (i = 6; i < argc && loop_on; i++) { struct stat file_stat; if (lstat(argv[i], &file_stat) == 0) { if (S_ISFIFO(file_stat.st_mode)) { file_pes[i - 6] = fopen(argv[i], "rb"); if (file_pes[i - 6] == NULL) { fprintf(stderr, "pesvideo2ts: failed to re-open %s\n", argv[i]); return 0; } else { fprintf(stderr, "pesvideo2ts: re-opens fifo %s\n", argv[i]); if (i == 6) { head_missing = 0; } } } else { file_pes[i - 6] = NULL; } } else { file_pes[i - 6] = NULL; } } current_file_pes = file_pes[0]; if (!head_missing) { first_pts = 1; } } return 0; } opencaster-3.2.2/tools/tstcpreceive/0000755000175000017500000000000012214326444016751 5ustar debiandebianopencaster-3.2.2/tools/tstcpreceive/Makefile0000644000175000017500000000063712214326444020417 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = tstcpreceive.o TARGET = tstcpreceive DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/tstcpreceive/tstcpreceive.c0000644000175000017500000000540212214326444021616 0ustar debiandebian/* * Copyright (C) 2004-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #define SERVER_PORT 12345 #define TS_PACKET_SIZE 188 #define BUF_SIZE TS_PACKET_SIZE * 7 int main(int argc, char *argv[]) { int i; int j; int port; int rc; int listen_sd; int accept_sd; char buffer[BUF_SIZE]; char ts_packet[TS_PACKET_SIZE]; struct sockaddr_in addr; if(argc >= 2) { port = atoi(argv[1]); } else { fprintf(stderr, "Usage: %s port\n", argv[0]); return 0; } listen_sd = socket(AF_INET, SOCK_STREAM, 0); if(listen_sd < 0) { fprintf(stderr, "socket() error\n"); return 0; } int reuse = 1; if (setsockopt(listen_sd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) < 0) { perror("setsockopt() SO_REUSEADDR: error "); } /* if (setsockopt(listen_sd, SOL_SOCKET, SO_REUSEPORT, &reuse, sizeof(reuse)) < 0) { perror("setsockopt() SO_REUSEPORT: error "); } */ fprintf(stderr, "Binding the socket...\n"); memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl(INADDR_ANY); addr.sin_port = htons(port); rc = bind(listen_sd, (struct sockaddr *)&addr, sizeof(addr)); if(rc < 0) { fprintf(stderr, "bind() error\n"); close(listen_sd); return 0; } rc = listen(listen_sd, 1); if(rc < 0) { fprintf(stderr, "listen() error\n"); close(listen_sd); return 0; } accept_sd = accept(listen_sd, NULL, NULL); if(accept_sd < 0) { fprintf(stderr, "accept() error\n"); close(listen_sd); return 0; } rc = 1; j = 0; i = 0; while (rc > 0) { rc = recv(accept_sd, buffer, BUF_SIZE, 0); for (i = 0; i < rc; i++) { ts_packet[j] = buffer[i]; j++; if (j == TS_PACKET_SIZE) { write(STDOUT_FILENO, ts_packet, TS_PACKET_SIZE); j = 0; } } } close(accept_sd); close(listen_sd); return 0; } opencaster-3.2.2/tools/mpeg2videovbv/0000755000175000017500000000000012214326444017030 5ustar debiandebianopencaster-3.2.2/tools/mpeg2videovbv/Makefile0000644000175000017500000000061512214326444020472 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = vbv.o TARGET = vbv DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/mpeg2videovbv/plot.p0000644000175000017500000000011512214326444020164 0ustar debiandebianplot "vbvData.dat" using 1:2 title 'vbv buffer (kbits)' with lines pause -1 opencaster-3.2.2/tools/mpeg2videovbv/vbv.c0000644000175000017500000002261312214326444017775 0ustar debiandebian/* * Copyright (C) 2004-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #define _BSD_SOURCE 1 #include #include #include #include #include #include #include #include #include #include #define ES_HEADER_SIZE 4 #define HEADER_MAX_SIZE 64 const int rmax [4][5] = { { -1, 80000000, -1, -1, 100000000}, /* Mbps */ { -1, 60000000, -1, 60000000, 80000000}, { 15000000, 15000000, 15000000, -1, 20000000}, { -1, 4000000, 4000000, -1, -1}, }; const int profile[8] = { -1, 4, /* High */ 3, /* Spatially Scalable */ 2, /* SNR Scalable */ 1, /* Main */ 0, /* Low */ -1, -1, }; const int level[16] = { -1, -1, -1, -1, 0, /* High */ -1, 1, /* High 1440 */ -1, 2, /* Main */ -1, 3, /* Low */ -1, -1, -1, -1, -1, }; const double frame_sec[16] = { 1.0, 1/23.9, 1/24.0, 1/25.0, 1/29.9, 1/30.0, 1/50.0, 1/59.9, 1/60.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, }; typedef struct queue { long long int index; int value; struct queue* next; } queue; queue* g_queue = 0; int pop_frame(void){ int result; queue* temp; if (g_queue) { result = g_queue->value; temp = g_queue->next; free(g_queue); g_queue = temp; } else { result = 0; } return result; } void enqueue_frame(long long int index, int value) { queue* new_queue; queue* temp; new_queue = (queue*) malloc(sizeof(queue)); new_queue->index = index; new_queue->value = value; new_queue->next = 0; if (g_queue == 0) { /* unique element */ g_queue = new_queue; } else if (g_queue->index > new_queue->index) { /* smallest element */ new_queue->next = g_queue; g_queue = new_queue; } else { /* other element */ temp = g_queue; while ((temp->next != 0) && (temp->next->index < new_queue->index)) { temp = temp->next; } new_queue->next = temp->next; temp->next = new_queue; } } int main(int argc, char *argv[]) { double flush_delta_time = 0.; /* mesaure time between 2 buffer flushes */ double es_frame_rate = -1.; /* es frame rate */ int temporal_reference = -1; /* temporal_reference of the current frame into the current GOP */ int frame_size = 0; /* current frame size */ int error_reported = 0; /* set if error is already reported for this frame */ int error_counter = 0; /* count errors */ long int total_frames = 0L; /* frames counter */ long int popped_frames = 0L; /* popped_frames */ long int flush_delta_byte = 0L; /* delta byte counter between 2 buffer flushes */ int GOP_size = 0; /* current GOP size */ int GOP_frames = 0; /* current GOP number of frames */ int es_profile = -1; /* es profile */ int es_level = -1; /* es level */ int leakmethod = -1; /* leak or vbv_dealy ?*/ double rbx = -1; /* isntantaneous bit rate */ double res = -1; /* nominal bit rate */ double real_rbx = -1; /* real bit rate from GOP size measure */ FILE* file_es = 0; /* es input */ FILE* file_output = 0; /* data output */ int byte_read = 0; /* byte read at every cycle */ int vbv_delay = -1; /* vide buffer verifier delay */ int vbv_buffer_size = -1; /* size of the video buffer verifier in bit */ int vbv_current_size = 0; /* current fillness of the video buffer verifier in bit */ unsigned char es_header[HEADER_MAX_SIZE]; /* es header parsing buffer */ /* Parse args */ file_es = 0; if (argc > 1) { file_es = fopen(argv[1], "rb"); file_output = fopen("vbvData.dat", "w+"); } if (file_es == 0 ) { fprintf(stderr, "Usage: 'vbv videofile.es'\n"); return 2; } /* Process ES file */ byte_read = fread(es_header, 1, ES_HEADER_SIZE, file_es); while(byte_read) { /* Update counters */ GOP_size += byte_read; frame_size += byte_read; vbv_current_size += byte_read * 8; flush_delta_byte += byte_read; /* Get the current time and flush the buffer if necessary */ if (rbx != -1) { flush_delta_time = flush_delta_byte * 8 / rbx; if (flush_delta_time >= es_frame_rate) { vbv_current_size -= pop_frame() * 8; fprintf(file_output, "%ld\t%d\n", popped_frames, vbv_current_size / 1000); popped_frames++; error_reported = 0; flush_delta_byte = (flush_delta_time - es_frame_rate) * rbx / 8; } } /* Check the buffer status */ if (leakmethod != -1 && vbv_buffer_size != -1) { if (vbv_current_size > vbv_buffer_size) { if (error_reported == 0) { fprintf(stdout, "Overrun at frame %ld\n", total_frames); error_counter++; } vbv_current_size = vbv_buffer_size; error_reported = 1; } else if (vbv_current_size < 0) { if (error_reported == 0) { fprintf(stdout, "Underrun at frame %ld\n", total_frames); error_counter++; } vbv_current_size = 0; error_reported = 1; } } /* Check headers */ if (es_header[0] == 0x00 && es_header[1] == 0x00 && es_header[2] == 0x01 && es_header[3] == 0x00) { /* Picture start header */ if (total_frames > 0) { frame_size -= ES_HEADER_SIZE; enqueue_frame(total_frames + temporal_reference, frame_size); error_reported = 0; /* * I know, I know, tempral reference sometimes there is not, * complain with yout encoder or write field/frame interlaced/progressive management ;-) * */ frame_size = ES_HEADER_SIZE; } byte_read = fread(es_header, 1, 4, file_es); temporal_reference = (es_header[0] << 2) | ((es_header[1] & 0xC0) >> 6); vbv_delay = ((es_header[1] & 0x07) << 13 ) | (es_header[2] << 5) | ((es_header[3] & 0xf8) >> 3) ; if (vbv_delay == 0xFFFF) { /* rbx is fixed */ if (es_profile != -1 && es_level != -1 && res != -1 ) { if (es_level == 2 || es_level == 3) { /* ML or LL */ rbx = rmax[es_level][es_profile]; } else { /* HL or H-14 */ rbx = rmax[es_level][es_profile]; if (rbx < 1.05 * res) rbx = 1.05 * res; } leakmethod = 1; } } else { if (es_profile != -1 && es_level != -1 && res != -1 ) { rbx = res; /* * * rbx should be a linear interpolation between bytes and time passed and vbv_delay value as * shown in 13818-2 annex C, as a matter of fact encoders make it plain simple compliant to the nominal * bit rate and the buffer fillness to be standard without giving any futher real bit rate hint. * * */ if (rbx > rmax[es_level][es_profile]) { rbx = rmax[es_level][es_profile] ; } leakmethod = 0; } } GOP_frames++; total_frames++; byte_read += fread(es_header, 1, ES_HEADER_SIZE, file_es); } else if (es_header[0] == 0x00 && es_header[1] == 0x00 && es_header[2] == 0x01 && es_header[3] == 0xB3) { /* Sequence video header */ byte_read = fread(es_header, 1, 8, file_es); es_frame_rate = frame_sec[(es_header[3] & 0x0F)]; res = ((es_header[4] << 10) | (es_header[5] << 2) | ((es_header[6] & 0xC0) >> 6)) * 400; if (rbx == -1) { rbx = res; /* best guess until now and maybe the only one ... */ } vbv_buffer_size = 16 * 1024 * (((es_header[6] & 0x1F) << 5) | ((es_header[7] & 0xF8) >> 3)); if (es_header[7] & 0x02) { byte_read += fread(es_header, 1, 64, file_es); /* intra quantiser matrix */ if (es_header[63] & 0x01) { byte_read += fread(es_header, 1, 64, file_es); /* there is also non-intra quantiser matrix */ } } else if (es_header[7] & 0x01) { byte_read += fread(es_header, 1, 64, file_es); /* non-intra quantiser matrix */ } byte_read += fread(es_header, 1, ES_HEADER_SIZE, file_es); if (es_header[0] == 0x00 && es_header[1] == 0x00 && es_header[2] == 0x01 && es_header[3] == 0xB5) { /* Sequence extension */ byte_read += fread(es_header, 1, 6, file_es); es_profile = profile[es_header[0] & 0x07]; es_level = level[(es_header[1] & 0xF0) >> 4]; byte_read += fread(es_header, 1, ES_HEADER_SIZE, file_es); } } else if (es_header[0] == 0x00 && es_header[1] == 0x00 && es_header[2] == 0x01 && es_header[3] == 0xB8) { /* GOP video header */ if (GOP_size > ES_HEADER_SIZE) { /* it's the second header so we have a GOP between them */ if (es_frame_rate != -1) { real_rbx = (GOP_size * 8) / (GOP_frames * es_frame_rate); } GOP_size = 0; GOP_frames = 0; } byte_read = fread(es_header, 1, ES_HEADER_SIZE, file_es); } else { /* 1 byte step */ es_header[0] = es_header[1]; es_header[1] = es_header[2]; es_header[2] = es_header[3]; byte_read = fread(es_header + 3, 1, 1, file_es); } } fprintf(stdout, "check done, found %d errors.\n", error_counter); fclose(file_output); return 0; } opencaster-3.2.2/tools/tsinputswitch/0000755000175000017500000000000012232257151017177 5ustar debiandebianopencaster-3.2.2/tools/tsinputswitch/Makefile0000644000175000017500000000064112214326444020642 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = tsinputswitch.o TARGET = tsinputswitch DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/tsinputswitch/tsinputswitch.c0000644000175000017500000001015012232257151022270 0ustar debiandebian/* * Copyright (C) 2008-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. */ #define MULTICAST #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define TS_PACKET_SIZE 188 int main(int argc, char *argv[]) { int input_file1; int input_file2; int byte_read; unsigned char choice; int port; unsigned char packet[TS_PACKET_SIZE]; if (argc >= 5) { input_file1 = open(argv[1], O_RDONLY); if (input_file1 < 0) { fprintf(stderr, "Can't open file %s\n", argv[1]); return 0; } input_file2 = open(argv[2], O_RDONLY); if (input_file2 < 0) { fprintf(stderr, "Can't open file %s\n", argv[2]); return 0; } port = atoi(argv[3]); if (port <= 0) { fprintf(stderr, "Can't open port %s\n", argv[3]); return 0; } choice = atoi(argv[4]); if (choice < 0) { fprintf(stderr, "Default choice is %d\n", choice); return 0; } } else { fprintf(stderr, "Usage: 'tsinputswitch inputfile1.ts inputfile2.ts port default'\n"); fprintf(stderr, "0 output from inputfile1, read and discard input from inputfile2\n"); fprintf(stderr, "1 output from inputfile2, read and discard input from inputfil1\n"); fprintf(stderr, "2 output from inputfile1, stop reading input from inputfile2\n"); fprintf(stderr, "3 output from inputfile2, stop reading input from inputfile1\n"); fprintf(stderr, "Default: 0\n"); return 0; } int listen_sd; listen_sd = socket(AF_INET, SOCK_DGRAM, 0); if(listen_sd < 0) { fprintf(stderr, "secsocket - socket() error\n"); exit(-1); } else { fprintf(stderr, "secsocket - socket() is OK\n"); } int flags; flags = fcntl(listen_sd,F_GETFL,0); fcntl(listen_sd, F_SETFL, flags | O_NONBLOCK); int reuse = 1; if (setsockopt(listen_sd, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse, sizeof(reuse)) < 0) { fprintf(stderr, "setting SO_REUSEADDR failed\n"); close(listen_sd); exit(-1); } struct sockaddr_in addr; memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = INADDR_ANY; addr.sin_port = htons(port); int result = bind(listen_sd, (struct sockaddr *)&addr, sizeof(addr)); if(result < 0) { fprintf(stderr, "secsocket - bind() error\n"); close(listen_sd); exit(-1); } else { // fprintf(stderr, "secsocket - bind() is OK\n"); } byte_read = 1; choice = 0; unsigned char received = 0; while(byte_read) { if (recv(listen_sd, &received, 1, 0) > 0) { fprintf (stderr, "received %d\n", received - 48); choice = received - 48; } if (choice == 0) { byte_read = read(input_file2, packet, TS_PACKET_SIZE); byte_read = read(input_file1, packet, TS_PACKET_SIZE); } else if (choice == 1) { byte_read = read(input_file1, packet, TS_PACKET_SIZE); byte_read = read(input_file2, packet, TS_PACKET_SIZE); } else if (choice == 2) { byte_read = read(input_file1, packet, TS_PACKET_SIZE); } else if (choice == 3) { byte_read = read(input_file2, packet, TS_PACKET_SIZE); } if (byte_read > 0) { write(STDOUT_FILENO, packet, TS_PACKET_SIZE); } } close(input_file1); close(input_file2); close(listen_sd); return 0; } opencaster-3.2.2/tools/tsvbr2cbr/0000755000175000017500000000000012214326444016162 5ustar debiandebianopencaster-3.2.2/tools/tsvbr2cbr/Makefile0000644000175000017500000000063112214326444017622 0ustar debiandebianC = gcc CFLAGS += -g -MD -Wall -I. -I../../include -D_FILE_OFFSET_BITS=64 $(CPPFLAGS) LDFLAGS += -lc OBJS = tsvbr2cbr.o TARGET = tsvbr2cbr DESTDIR ?= /usr/local/bin/ all: $(TARGET) .c.o: $(CC) $(CFLAGS) -c $< -o $@ $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) install: all install -m 755 $(TARGET) $(DESTDIR) clean: rm -f $(TARGET) $(OBJS) core* *~ *.d -include $(wildcard *.d) dummy opencaster-3.2.2/tools/tsvbr2cbr/tsvbr2cbr.c0000644000175000017500000001672612214326443020252 0ustar debiandebian/* * Copyright (C) 2004-2013 Lorenzo Pallara, l.pallara@avalpa.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include #define TS_PACKET_SIZE 188 #define MAX_PID 8192 #define SYSTEM_CLOCK_FREQUENCY 27000000 #define OUTPUT_BUFFER_IN_PACKETS 2127 // 40mbps maximum dvb stream, pcr maximum 40ms -> 200Kbytes buffer, let's take 400K ;-) unsigned char null_ts_packet[TS_PACKET_SIZE]; u_char ts_packet[TS_PACKET_SIZE];/* TS packet */ unsigned char output_packet_buffer[OUTPUT_BUFFER_IN_PACKETS * TS_PACKET_SIZE]; unsigned char* current_output_packet = 0; unsigned long long int ibits; unsigned long long int obits; unsigned long long int fcounter; unsigned long long int ucounter; unsigned long long int last_ucounter; unsigned long long int ts_packet_output; void fill_buffer(void) { /* copy ts packet from input to output buffer */ memcpy(current_output_packet, ts_packet, TS_PACKET_SIZE); current_output_packet += TS_PACKET_SIZE; if (current_output_packet >= output_packet_buffer + TS_PACKET_SIZE * OUTPUT_BUFFER_IN_PACKETS) { fprintf(stderr, "buffer too small\n"); exit(2); } } unsigned long long flush_buffer(void) { unsigned char* output_packet = 0; unsigned long long result = 0; for (output_packet = output_packet_buffer; output_packet < current_output_packet; output_packet += TS_PACKET_SIZE) { /* write input packet out */ write(STDOUT_FILENO, output_packet, TS_PACKET_SIZE); ts_packet_output++; /* increase counters, every input packet generate free time and consume some*/ fcounter += TS_PACKET_SIZE * 8 * obits; ucounter += TS_PACKET_SIZE * 8 * ibits; /* generate null packets if there's time */ while ( ucounter + (TS_PACKET_SIZE * 8 * ibits) <= fcounter) { /* write null packets */ write(STDOUT_FILENO, null_ts_packet, TS_PACKET_SIZE); ts_packet_output++; /* increase output bit counter */ last_ucounter = ucounter; ucounter += TS_PACKET_SIZE * 8 * ibits; if (last_ucounter > ucounter) { /* manage zeroed counter */ last_ucounter = last_ucounter - fcounter; fcounter = 0; ucounter = last_ucounter + TS_PACKET_SIZE * 8 * ibits; } } } /* empty buffer */ fprintf(stderr, "wasted time %llu\n", (fcounter-ucounter) / SYSTEM_CLOCK_FREQUENCY); current_output_packet = output_packet_buffer; result = (fcounter - ucounter) / SYSTEM_CLOCK_FREQUENCY; fcounter = fcounter - ucounter; ucounter = 0; last_ucounter = 0; return result; } int main(int argc, char *argv[]) { int fd_ts; u_short pid; int byte_read; unsigned long long int pcr_base = 0ll; unsigned long long int pcr_ext = 0ll; unsigned long long int ts_packet_count = 0ll; ts_packet_output = 0ll; unsigned long long int new_pcr = 0ll; unsigned long long int new_pcr_index = 0ll; unsigned long long int pid_pcr_table[MAX_PID]; /* PCR table for the TS packets */ unsigned long long int pid_pcr_index_table[MAX_PID]; /* PCR index table for the TS packets */ /* Parse args */ if (argc >= 3) { fd_ts = open(argv[1], O_RDONLY); } else { fprintf(stderr, "Usage: 'tsvbcr2cbr input.ts output_bit/s'\n"); fprintf(stderr, "adds empty packets to input.ts to reach uniform output_bit/s, it needs to read head a pcr to guess bit rate\n"); fprintf(stderr, "input.ts should be a single program transport stream with only a video elementary stream and valid pcrs\n"); return 2; } if (fd_ts < 0) { fprintf(stderr, "Can't find file %s\n", argv[1]); return 2; } obits = atol(argv[2]); if (obits == 0) { fprintf(stderr, "0 output_bit/s?\n"); return 2; } /* Init null packet */ memset(null_ts_packet, 0, TS_PACKET_SIZE); null_ts_packet[0] = 0x47; null_ts_packet[1] = 0x1F; null_ts_packet[2] = 0xFF; null_ts_packet[3] = 0x10; /* Init counters */ fcounter = 0; ucounter = 0; last_ucounter = 0; byte_read = 1; memset(pid_pcr_table, 0, MAX_PID * (sizeof(long long int))); memset(pid_pcr_index_table, 0, MAX_PID * (sizeof(long long int))); ts_packet_count = 0; current_output_packet = output_packet_buffer; ibits = obits; /* until ibit is guessed it's equal to output */ while (byte_read) { /* read a packet */ byte_read = read(fd_ts, ts_packet, TS_PACKET_SIZE); /* check packet PCR */ memcpy(&pid, ts_packet + 1, 2); pid = ntohs(pid); pid = pid & 0x1fff; if (pid < MAX_PID) { /* valid packet */ if ((ts_packet[3] & 0x20) && (ts_packet[4] != 0) && (ts_packet[5] & 0x10)) { /* there is a pcr field */ pcr_base = (ts_packet[6] << 25) & 0x1FFFFFFFFll; pcr_base += (ts_packet[7] << 17) & 0x1FFFFFFll; pcr_base += (ts_packet[8] << 9) & 0x1FFFFll; pcr_base += (ts_packet[9] << 1) & 0x1FFll; pcr_base += ((ts_packet[10] & 0x80) >> 7) & 0x1ll; pcr_ext = ((ts_packet[10] & 0x01) << 8) & 0x1FFll; pcr_ext += ts_packet[11]; if (pid_pcr_table[pid] == 0) { /* it's a new pcr pid */ pid_pcr_table[pid] = pcr_base * 300ll + pcr_ext; pid_pcr_index_table[pid] = (ts_packet_count * TS_PACKET_SIZE) + 10; } else { /* we can guess a bit rate comparing a previous pcr pid */ new_pcr = pcr_base * 300ll + pcr_ext; new_pcr_index = (ts_packet_count * TS_PACKET_SIZE) + 10; fprintf(stderr, "%llu: pid %d, new pcr is %llu, pcr delta is %llu, (%f ms), indices delta is %llu bytes,( %f ms), instant ts bit rate is %.10f\n", new_pcr_index, pid, new_pcr, new_pcr - pid_pcr_table[pid], ((double)((new_pcr - pid_pcr_table[pid]) * 1000)) / SYSTEM_CLOCK_FREQUENCY, new_pcr_index - pid_pcr_index_table[pid], ((double)((new_pcr_index - pid_pcr_index_table[pid]) * 8 * 1000)) / ibits, (((double)(new_pcr_index - pid_pcr_index_table[pid])) * 8 * SYSTEM_CLOCK_FREQUENCY) / ((double)(new_pcr - pid_pcr_table[pid])) ); ibits = (((double)(new_pcr_index - pid_pcr_index_table[pid])) * 8 * SYSTEM_CLOCK_FREQUENCY) / ((double)(new_pcr - pid_pcr_table[pid])); if (ibits > obits) { fprintf(stderr, "at %llu: output bit rate %llu is smaller then input bit rate %llu\n", new_pcr_index, obits, ibits); return 2; } flush_buffer(); /* new_pcr = (((ts_packet_output * TS_PACKET_SIZE) + 10) * 8 * SYSTEM_CLOCK_FREQUENCY) / obits; fprintf(stderr, "new computed pcr is %llu\n" ,new_pcr); pcr_base = new_pcr / 300; pcr_ext = new_pcr % 300; ts_packet[6] = (0xFF & (pcr_base >> 25)); ts_packet[7] = (0xFF & (pcr_base >> 17)); ts_packet[8] = (0xFF & (pcr_base >> 9)); ts_packet[9] = (0xFF & (pcr_base >> 1)); ts_packet[10] = ((0x1 & pcr_base) << 7) | 0x7E | ((0x100 & pcr_ext) >> 8); ts_packet[11] = (0xFF & pcr_ext); */ pid_pcr_table[pid] = new_pcr; pid_pcr_index_table[pid] = new_pcr_index; } } } fill_buffer(); ts_packet_count++; } return 0; } opencaster-3.2.2/INSTALL0000644000175000017500000000152312214326456014146 0ustar debiandebianOpenCaster Lorenzo Pallara l.pallara@avalpa.com ============================= ==How to compile and install== The procedure is tested on a Debian Linux 7.0 i686 32bit architecture, it is reported to work also on 32bit armhf architecure. Packages usually required but not installed by default are: binutils, gcc, libc6-dev, libgomp1, linux-libc-dev, make, python-dev, and zlib1g-dev, these are mostly development libraries needed to compile OpenCaster. You can install/upgrade/verify the packages typing as root on a Debian with the following command: apt-get install --no-install-recommends binutils gcc libc6-dev libgomp1 linux-libc-dev make python-dev zlib1g-dev python-dateutil To build the package you need to type make into OpenCaster directory. To install the tools in the system you need to type make install with root privileges. opencaster-3.2.2/COPYING0000644000175000017500000004325412214326456014157 0ustar debiandebian GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. opencaster-3.2.2/README0000644000175000017500000000665112214326456014004 0ustar debiandebianOpenCaster ==Contact== Lorenzo Pallara (l.pallara@avalpa.com) ==Introduction== This package is a collection of softwares for Linux system to play out and multiplex MPEG2 transport stream format Use-cases: MHP, MHEG5, HbbTv and others interactive tv standards object carousel broadcast Playout of locally stored, offline encoded audio and video for non-live tv and radio stations Multiplexing of input multicasted UDP transport stream to output multicasted UDP transport stream VOD system based on mpeg2 transport stream over IP or over DVB for walled garden network like hotels with coax or ethernet. DVB-SSU update Data casting Teletext generator IP encapsualtor PSI/SI generator EPG generator ==Integration== OpenCaster output has been successfully integrated with a long list of dvb products, among them there are products by Cisco/Scientific Atlanta, Ericsson/Tandberg, Dektec, Eurotek, Harmonic/Scopus, MainConcept, Mitan, Screen Service, Adtec, Wellav, Arris, Sr-Systems, Deltacast, ... ==Manual== Avalpa Broadcast Server manual is available here: http://www.avalpa.com/the-key-values/15-free-software/33-opencaster ==Test== OpenCaster has been tested with Rohde & Schwarz DVM100L, Rohde & Schwarz DVM 400, Dektec StreamXpert and a countless number of set top boxes, digital receivers and television sets ==Technical features== - PSI generation (PAT, PMT, NIT, SDT, TDT, AIT, TOT, ...) - EPG/EIT generation - Object and data carousel generation and receivement (MHP, MHEG5, HbbTv, DVB-SSU, DSMCC, ...) - third party software AC-3, MPEG2 audio, MPEG2 video and H264 video encoders support - Audio Description generation support - IP encapsulation (MPE) - Teletext generation - CBR transport stream muxing - PCR stamping - Null packet replacement - PID filtering - PID remapping - Null packet insertion - Video buffer verifier - PCR timing verifier - PES headers analyzer - MPEG2 video and MPEG2/AC-3 audio ES header analyzer - M2TS file generation from TS file ==Demo== A demonstration transport stream is available at this address:http://www.avalpa.com/the-key-values/15-free-software/59-opencaster-demo-roll ==Handy tables== DVB-T modulations: Modulation Coding rate Guard interval 1/4 1/8 1/16 1/32 QPSK 1/2 4.976 5.529 5.855 6.032 2/3 6.635 7.373 7.806 8.043 3/4 7.465 8.294 8.782 9.048 5/6 8.294 9.216 9.758 10.053 7/8 8.709 9.676 10.246 10.556 16-QAM 1/2 9.953 11.059 11.709 12.064 2/3 13.271 14.745 15.612 16.086 3/4 14.929 16.588 17.564 18.096 5/6 16.588 18.431 19.516 20.107 7/8 17.418 19.353 20.491 21.112 64-QAM 1/2 14.929 16.588 17.564 18.096 2/3 19.906 22.118 23.419 24.128 3/4 22.394 24.882 26.346 27.144 5/6 24.882 27.647 29.273 30.160 7/8 26.126 29.029 30.737 31.668 channel to frequency table: 21 474 22 482 23 490 24 498 25 506 26 514 27 522 28 530 29 538 30 546 31 554 32 562 33 570 34 578 35 586 36 594 37 602 38 610 39 618 40 626 41 634 42 642 43 650 44 658 45 666 46 674 47 682 48 690 49 698 50 706 51 714 52 722 53 730 54 738 55 746 56 754 57 762 58 770 59 778 60 786 61 794 62 802 63 810 64 818 65 826 66 834 67 842 68 850 69 858 mpeg audio layer 2 suggested bit rates: 56 kbps -> 1 pes packet -> 1 ts packet 112 kbps -> 1 pes packet -> 2 ts packets 160 kbps -> 1 pes packet -> 3 ts packets 224 kbps -> 1 pes packet -> 4 ts packets all the others fall in the middle and are not a wise choice opencaster-3.2.2/CHANGES0000644000175000017500000004317112220025171014100 0ustar debiandebian21/09/2013 Change log author: Lorenzo Pallara (l.pallara@avalpa.com) Change log OpenCaster 3.2.1: - tools/*: m2ts2ts renamed m2ts2cbrts - tools/tsprinter: removed - libs/dvbobjects/*: added support for ATSC EIT - tutorials/*: removed tutorials from main packet, they are avilable on a support download from http://www.avalpa.com - extra/*: removed, they are now part of support download from http://www.avalpa.com Change log OpenCaster 3.2: - tools/mpe2sec/: added suppor for 64bit (by Julian Cable julian.cable@bbc.co.uk) - libs/dvbobjects/*: added more dvb-ssu descriptors support (by Andreas Regel andreas.regel@ttgoerler.de) - libs/dvbobjects/*: added BAT support (by Andreas Regel andreas.regel@ttgoerler.de) - libs/dvbobjects/*: removed duplicated descriptor ISO_639_language_descriptor - libs/dvbobjects/*: added application_recording_descriptor (by Jesper Gustin jesperg@opera.com) - tools/txt2pes.c: fixed compatibility issue - tools/tsdiscont: added to fix some discontiuity issues (by Shane Andrusiak, blendz@shaw.ca) - tools/tsstamp: added pusi check Change log OpenCaster 3.1.4: - tutorials/*: capitalized ISO639 language codes - tutorials/hbbtv-http: fixed small typo - tutorials/firsttime: bug fix for localtime - libs/dvbobjects/dvbobjects/DSMCC/Message.py compatibility fix for mythtv Change log OpenCaster 3.1.3: - tools/pesvideo2ts: source code cosmetics - extras/x264: added patch for x264 to output format required by OpenCaster - tutorials/hbbtv-dsmcc: added descriptor required by some receiveres Change log OpenCaster 3.1.2 - tutorial/eitfilter: bug fix for services without scheduled events - tools/oc-update.sh: improved carousel head cache chances on some decoders - libs/: allows application_signaling with empty subfields Change log OpenCaster 3.1.1: - tools/*: fix overflow on CLOCK_MONOTONIC functions Change log OpenCaster 3.1: - tutorials: added .srt to teletext subtitles example, documentation coming soon - libs/: bug fix for multiplex txt pages in pmt descriptor - tools/esaudio2pes: added support for DTS, still on test - tools/esaudioinfo: added support for DTS, still on test - libs: added DVB descriptors for DTS - libs: bug fixes to support python 2.6 - tools/* replaced gettimeofday with clock_gettime to enforce CLOCK_MONOTIC - tools/eitsecactualtoanother: added - tools/tstdt: added start time option for replay - tools/tstcpsend: bug fix on init. value - tutorials: removed some useless file - libs: added SIT table - tutorials: added SIT example Change log OpenCaster 3.0: - tools/pesvideo2ts: generalized vbv, command line supports vbv size in bit, now it broadcasts h264 video (join is on test) - tools/pesvideo2ts: added 24 fps support - tools/ts2m2ts: added generate m2ts from ts - tools/m2ts2ts: added generate ts from m2ts - tools/pesinfo: prints also video pes size - tools/esvideo2pes renamed tools/esvideompeg2pes - tools/esvideoinfo renamed tools/esvideompeg2info - tools/vbv renamed tools/videompeg2vbv - tutorials: renamed with a meaningful name Change log OpenCaster 2.5.1: - libs/dvbobjects: removed default value for segment_last_section_number in EIT generation - tools/tspcrrestamp: rewritten, multicast multiplexing should recover better in network downs - tools/tsccc: doesn't check anymore for null packets cc errors - tutorials/OCtutorial14: TOT example manages DST with iCalendar RFC - tutorials/OCtutorial12/13: removed as not supported anymore Change log OpenCaster 2.5: - tutorials/[mhp]: now include new Avalpa's Wizard xlet - tools/oc-update.sh: introduced new "smart compress" option, improved carousel optimization, check details inside - tools/file2mod.y: introduced new "smart compress" option, improved carousel optimization, check details inside Change log OpenCaster 2.4.7 - tools/eitsecfilter: fix deprecated include for Change log OpenCaster 2.4.6.1: - tutorials/: some bug fixes Change log OpenCaster 2.4.6: - libs/dvbobjects/HBBTV: Added HbbTv support by Claude Vanderm (claude.vanderm@mediatv.com) - tools/eitsecfilter: save eit section on different file names ready for remuxing and playout - tools/eitsecmapper: replace onid and tsid on eit section files - tools/tsprinter: outputs a transport stream over a pc parallel port pins (max 2.1mbps 1 cpu 1GHZ 100%, ts packet jitter is high, use only for data) - tools/tsmodder: bug fix on ts input loop - tools/dvbobjects: bug fix for ATSC descriptors and tutorial - tools/ts2sec: added crc32 check, discard invalid sections - tools/pesaudio2ts: support fps other than 25 fps - tools/pesvideo2ts: support fps other than 25 fps - tools/pesclock: discontinued - tools/oc2sec: help changed, module version was not reported as hex - tools/tsstamp: header bug fix by (blendz@shaw.ca) - tools/tsmask: command line bug fix by (kailife.forge@gmail.com) - tutorials/: added tutorials for HbbTV - tutorials/: added tutorial for epg filtering and muxing - libs/dvbobjecs: added content descriptor - libs/dvbobjecs: bug fix registration_descriptor - libs/dvbobjecs/DVB/DataCarousel: bug fix for more than 256 modules by Robert Antosiak (robert.antosiak@digitaltv-labs.com) Change log OpenCaster 2.4.5: - tools/esvideo2pes: bug fix, now support fps other than 25 fps Change log OpenCaster 2.4.4: - tools/pesvideo2ts: added option to change pcr repetition rate - libs/dvbobjects: transaction id update flag bug fix (by tdv team at lifia.info.unlp.edu.ar) - libs/dvbobjects: added descriptors for SDBT (by tdv team at lifia.info.unlp.edu.ar) - tutorials: data change, some TS7900HD firmware versions doesn't seem to support remount of the same carousel Change log OpenCaster 2.4.3: - tools/pesaudio2ts: bug fix on exit without loop, support for audio description generation - tools/esaudio2pes: support for audio description generation - tools/dvbobjects: bug fix for language descriptor, added support for audio description generation - tools/esvideoinfo: detects end_sequence - tools/pesdata2ts: bug fix ( was not using write) - tools/dvbobjects: added some ATSC descriptors still not tested - tools/tsmodder: now stop at the end of input file Change log OpenCaster 2.4.2: - libs/dvbobjects: added simple application descriptor for HbbTV Ait - libs/dvbobjects: added descriptors for SDBT (by Marco Casaroli ) - libs/dvbobjects: fixed transport stream terrestiral dellivery (by Keith Goodyer ) - tools/sec2ts: patch by Guislain Bonnard - tools/ip2sec: patch by Guislain Bonnard - tools/tstdt: now manages also tot - tools/totrestamp: removed - tools/tscbrmuxer: added option to stop muxing - libs/dvbobjects: fixed reserverd bits of tdt - tools/esaudio2pes: command line bug fix on large pts skip - tools/pes2es: removed seek, can be used in fifo Change log OpenCaster 2.4.1: - tools/tstdt: now manages also tot - tools/totrestamp: removed - tools/tscbrmuxer: added option to stop muxing - libs/dvbobjects: fixed reserverd bits of tdt - tools/esaudio2pes: command line bug fix on large pts skip - tools/pes2es: removed seek, can be used in fifo Change log OpenCaster 2.4: - tools/tspcrrestamp: added, this tool allows re-stamping of input transport streams - tools/tsorts : added, this tool allows re-multiplexing of input transport streams - tools/tscrypt: support crypting using libdvbcsa, the build of this tool is disabled by default because libdvbcsa is needed, tested with biss-e cam Change log OpenCaster 2.3.5: - missing 1 byte in oddParity teletext array - added tscbrmuxer user friendly input option o:total_bitrate Change log OpenCaster 2.3.4: - pretty printing bug fix fper pesaudio2ts Change log OpenCaster 2.3.3: - added EPG mnemonics Change log OpenCaster 2.3.2: - libs/dvbobjects: bug fix for tools/esaudio2pes wrong input parameter parsing Change log OpenCaster 2.3.1: - libs/dvbobjects: bug fix for dvb-ssu Change log OpenCaster 2.3: - tools/tsudpsend: bug fix for some bitrates - tools/tstimedwrite: bug fix for some bitrates - tools/pesclock: bug fix, shows only on some libc/kernel config - tools/tsmodder: now loops on replacement input files - tools/tspcrstamp: bug fix on initial pcr value - libs/dvbobjects: added some descriptors for SBTVD standard (by Robson Tovo robson@tecsysbrasil.com.br) - libs/dvbobjects: fixed reserved values different from standards - libs/dvbobjects: bug fix, minBlockTime had to be greater than zero some samsung lcd models concerned about it - libs/dvbobjects: added descriptors for dts, application storage and lcn v2 (by a.roszak@adbglobal.com) - manual: removed manual, Avalpa Broadcast Server manual is now available for download - extras: removed Change log OpenCaster 2.2: - tools/pesaudio2ts : added sample_per_frame option - tools/esaudio2pes: added sample_per_frame option - libs/dvbobjects: improved ac3 descriptor - tools/sec2ts: added padding options (by Julian Cable julian.cable@bbc.co.uk) Change log OpenCaster 2.1: - tools/ip2sec: removed - tools/mpe2sec: add (by Julian Cable julian.cable@bbc.co.uk) - tools/tsccc: continuity counter check - tools/txt2pes: txt encapsulation support - tools/esaudioinfo: added ac3 minimum parsing - tools/pesdata2ts: data encapsulation tool for time stamped data (like subtitles) - libs/sectioncrc/sectioncrc.c: 64bit support (by Gil Pedersen ), janitoring (by Kurganov Yanis ) - libs/dvbobjects: time_slice_fec_identifier_descriptor fix (by Gil Pedersen ) - libs/dvbobjects: section stream event bug fix (by Gabriel Paduan gpaduan@yahoo.com.br) - libs/dvbobjects: added suport for DVB-SSU - libs/dvbobjects: added suport for teletext - OCtutorials: are added to the main package - OCtutorials: added tutorial for DVB-SSU - OCtutorials: added tutorial for teletext - manual: added to the main package Change log OpenCaster 2.0: - tools/tsinputswitch: added - tools/tstcpsend: added - tools/tstcpreceive: added - tools/pesclock: added (this deserved the major because enable OpenCaster to act as pes playout) - tools/tstimeout: added - tools/pesvideo2ts: fifo support - tools/pesaudio2ts: fifo support and synchornization with extrenal video file length - tools/esvideo2pes: video length output file added, added math to manage pts/dts round up - tools/esaudio2pes: added math to manage pts round up - tools/ts2pes: reduced - tools/tspcrstamp: bug fix typo - tools/esvideoinfo: fixed parse error - tools/vbv: removed wrong second fprintf, fixed parse error - libs/dvbobjects/dvbobjects/* : some reserved bit were signalled wrong - libs/dvbobjects/dvbobjects/MPEG/Descriptors.py: larger network name size was used - libs/dvbobjects/dvbobjects/MPEG/Descriptors.py: descriptors added - libs/dvbobjects/dvbobjects/MPEG/EBUTeletext.py: added Change log OpenCaster 1.3: - tools/esvideo2pes: manage dynamic GOP, added limit to cut audio at the end - tools/esaudio2pes: pts increment is not constant, quaility improved, added limit to cut audio at the end - tools/pesvideo2ts: added pts restamp for loop - tools/pesaudio2ts: added pts restamp for loop - tools/tspcrstamp: added - tools/tstimedwrite: added - tools/tspcrmeasure: bug fix typo Change log OpenCaster 1.2: - libs/dvbobjects/dvbobjects/DVB/Descriptors.py: add AC3 and EPG descriptors by Antoni Roszak (a.roszak@osmosys.tv) - tools/oc2sec/oc-update.sh: bug fix on very big carousel temporary directory clean - tools/ts2sec: added - tools/tsudpreceive: added - tools/tsudpsend: added (enable IPTV output) - tools/dsmcc-receive: added - tools/tsstamp: changed usage print Change log OpenCaster 1.1: - libs/dvbobjects/dvbobjects/MPEG/DVBH_Descriptors.py: merged from fatcaps v0.5 by Andreas Berger (berger@ftw.au) - libs/dvbobjects/dvbobjects/PSI/INT.py: merged from fatcaps v0.5 Andreas Berger (berger@ftw.au) - libs/dvbobjects/dvbojects/MPEG/Descriptors.py: added data descriptors by Kovacs Balazs (basq@vendegvaro.hu) - tools/tscbrmuxer: bug fix on continuity counter for sections of a single ts packet - tools/tsloop: bug fix first packet repeated twice - libs/dvbobjects/dvbobjects/PSI/PAT.py: bug fix on private indicator - tools/oc-update.sh: dsmcc padding option continuity counter is broken fixed with tsfixcc - tools/tsfixcc: added, increase cc of very packet, doesn't account for adaptation field, to use only with sections - tools/tspcrmeasure: print bug fix on the first pcr byte - tools/esaudio2pes: support for audio frame padding Change log OpenCaster 1.0: - tools/esvideo2pes: bug fixed, was working if GOP had 2 B-frame - tools/pesvideo2ts: added a pcr packet at the begin - tools/tsstamp: added support for pts and dts restamp to manage loops (this deserved the major because enabled an easy use of video files and the manual examples to be written) Change log JustDVB-It 3.1: - bug fix on sec2ts ts section padding after notice by Fernando Martinze Navarro (FernandoMartinezNavarro@rohde-schwarz.com) Change log JustDVB-It 3.0: added support for mpeg2 elementary stream video input from ffmpeg added CAT, EMM, ECM sections started merging dvb-h funcionalities from fatcaps of amuse project, kudos to Andreas Berger (berger@ftw.at) - tools/pes2ts: renamed tools/pesaudio2ts - tools/tsvbr2cbr: added - tools/pesvideo2ts: added - added ffmpeg directory with sample .sh to generate audio/video input files from ffmpeg - added ffmpeg/encode.txt - added tools/tsstamp: PCR stamping tool - tools/tscbrmuxer: fix to manage small bit rate, needs refactoring Change log JustDVB-It 2.1: fixed interoperability issue with some old ADB boxes dsmcc client with last section number of modules multiple of 4066 improved modules update performance Change log JustDVB-It 2.0: SciTE help included Bluetop BSTC-12 DVB-ASI output: tested Dektec DTA110T DVB-T modulator support: tested MHEG5 DSMCC carousel generation: tested Fixed support for python 2.4, currently both python 2.3 and 2.4 are working properly Transport stream successfully tested against StreamAnalyzer of Panasonic from MHP KBD Sample configuration timings successfully tested against TR-101i 290 with Dektec StreamXpert Removed debug prints - extras/javasrc: added java source code of the example applications - extras/mainconcept: added a script to manage mainconcept output - bash-config/: added application storage option for MHP 1.1.2 - bash-config/: added Yambo 2.0 example applications - bash-config/: added Test ste example application SciTE help included - python-config/: new python only config, bash will phase out... - python-config/: it is possibile to specify module id for each file or only for some, check the .descriptors example - python-config/: added datacarousel example - tools/i3942ts: added - tools/tspcrmeasure: bug fix on print - tools/tsloop: cc fix - tools/zpipe: added - tools/DtPlay: removed, now it is necessary to get it from Dektec web site - tools/lib/DTAPI: removed, now it is necessary to get it from Dektec web site - libs/: added application storage descriptor (MHP 1.1.2) - libs/: added parental rating descriptor - libs/: added logical channel number descriptor - libs/: added support for compressed DSMCC modules added support for very large files (>2GB) - manual.txt: Video and audio multiplexing revisited, renamed readme.txt (people miss it...) Change log JustDVB-It 1.2: - dvbobjects/STE.py: addded Stream Event Descriptor Section - dvbobjects/STEO.py: addded Stream Event Object - dvbobjects/DSMCC: addded Stream Event Object with Do-It-Now support - config/: stream event example added - tools/tsnullshaper: added files loop to reduce latency Change log JustDVB-It 1.1.1: Just a very cosmetical fix Change log JustDVB-It 1.1: Fix a JustDvb-It bug about bad string termination thanks to IdWay support. Change log JustDVB-It 1.0: - DtRecord: removed, if u need it u can use the official from Dektec - EIT: bug fix - tstdt: added new, generates gmt time from server clock and restamp TDT packets - docs: manual.txt added - tools/tsloop: support multiple input, removed buffering, good for transport scheduling - config: shows an example of cbr muxing and multicarousel from MainConcept's input Change log JustDVB-It 0.5: - tools/tsnullshaper: bug fix - tools/oc2sec: buf fix on debug prints - tools/sec2ts: bug fix on .ts length - psi tables python look: same semantic different syntax - dvbobjects/dvbobjectsPMT.py: changed program_loop in stream_loop - config: added - tools/data2sec: renamed oc2sec - tools/esaudio2pes: added - tools/esaudioinfo: added - tools/esvideo2pes: added - tools/esvideoinfo: added - tools/pes2es: added - tools/pes2ts: added - tools/pesinfo: added - tools/ts2pes: added - tools/tscbrmuxer: added - tools/vbv: added Change log JustDVB-It 0.4: moved to kernel 2.6 everything can be run without root privileges new directories structure - tools/tsfilter: added new - tools/tspidmapper: modified input syntax - tools/data2sec: rearchitected - config/: added - extern/: removed - set-ups/: removed - drivers/dvbcharts: removed Chane log JustDVB-It 0.3.2: minor buf fixes Chane log JustDVB-It 0.3.1: minor buf fixes - tools/sec2tspackets: renamed sec2ts Change log JustDVB-It 0.3: - tools/ip2sec: added new - tools/tspidmapper: added new - tools/tspcrmeasure: added new - set-ups/iptrafficdemo: added new - tools/tsloop: enhanced with variable buffer support - tools/tsmodder: enhanced with variable buffer support - tools/tsfiller: enhanced with variable buffer support - tools/tsnullshaper: enhanced with variable buffer support, read packets to susbtitute only if they are read - extern/dvbasi/DtPlay-custom: DtPlay enhanced with variable buffer support - extern/dvbasi/DtRecord-custom: DtRecord enhanced with variable buffer support - extern/dvbasi/DtPlay: removed - extern/dvbasi/DtRecord: removed Change log JustDVB-It 0.2: - tools\tsnullshaper: added time insertion - tools\dvbdata: more bug fixes - tools\data2sec: added new MPEG and DVB descriptors, modules versioning from input parameters - set-ups\cindemo: added multiple application ait example and fixed time of tables insertion