From patchwork Sat Dec 28 15:45:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Roth?= X-Patchwork-Id: 3414131 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4F0D3C02DC for ; Sat, 28 Dec 2013 15:47:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 37BE320120 for ; Sat, 28 Dec 2013 15:47:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6967420122 for ; Sat, 28 Dec 2013 15:46:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755315Ab3L1Pqo (ORCPT ); Sat, 28 Dec 2013 10:46:44 -0500 Received: from mail-ea0-f181.google.com ([209.85.215.181]:42948 "EHLO mail-ea0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755282Ab3L1PqY (ORCPT ); Sat, 28 Dec 2013 10:46:24 -0500 Received: by mail-ea0-f181.google.com with SMTP id m10so4480661eaj.12 for ; Sat, 28 Dec 2013 07:46:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=RqkUdj4S6j0Ft+vP4HmhIGdQvQL+BSg/870vZ/X2Uu4=; b=tVeeNwoAItRL0kIwbMwLbBjyMANFBahMSNV83HfzsSFz508hodd7QKMNHJw0oaCITf tDUPpH0eefh1XpPi09ueBXs4Mjnrwry6Ce5Ehv7BGFeKoIW2LcEBu1iD7cfCZ4w0mnoh WHXOJhH49ny/yEPVaIrr2RK0dvDPjDpIbg1zLyDzvH1Wr5880AswJiY2hRVoW21GE1Ev YXfxhctjcFOAYaM2ptZjspKZrZJlf5/D3E2v3A/qRzW5UyI5XTw5yut6Sa1XsjkANJ5v 4fLP564TOy8qKEQCAJ5Eb2d6GUafMMQGuRvq97JH1ofY1oBGOIrY3ijl5w/Bd3IIB5+W yYTA== X-Received: by 10.14.0.201 with SMTP id 49mr2928056eeb.38.1388245582800; Sat, 28 Dec 2013 07:46:22 -0800 (PST) Received: from neutrino.exnihilo (140-227.61-188.cust.bluewin.ch. [188.61.227.140]) by mx.google.com with ESMTPSA id n1sm91594131eep.20.2013.12.28.07.46.21 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 28 Dec 2013 07:46:22 -0800 (PST) From: =?UTF-8?q?Andr=C3=A9=20Roth?= To: Linux Media Mailing List Cc: =?UTF-8?q?Andr=C3=A9=20Roth?= Subject: [PATCH 07/13] libdvbv5: MGT parser Date: Sat, 28 Dec 2013 16:45:55 +0100 Message-Id: <1388245561-8751-7-git-send-email-neolynx@gmail.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1388245561-8751-1-git-send-email-neolynx@gmail.com> References: <1388245561-8751-1-git-send-email-neolynx@gmail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: André Roth --- lib/include/descriptors/mgt.h | 82 ++++++++++++++++++++++++++++++ lib/libdvbv5/Makefile.am | 1 + lib/libdvbv5/descriptors.c | 1 + lib/libdvbv5/descriptors/mgt.c | 113 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 197 insertions(+) create mode 100644 lib/include/descriptors/mgt.h create mode 100644 lib/libdvbv5/descriptors/mgt.c diff --git a/lib/include/descriptors/mgt.h b/lib/include/descriptors/mgt.h new file mode 100644 index 0000000..4a68f2c --- /dev/null +++ b/lib/include/descriptors/mgt.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2011-2012 - Mauro Carvalho Chehab + * Copyright (c) 2013 - Andre Roth + * + * 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 version 2 + * of the License. + * + * 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 + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + */ + +#ifndef _MGT_H +#define _MGT_H + +#include +#include /* ssize_t */ + +#include "descriptors/header.h" +#include "descriptors.h" + +#define DVB_TABLE_MGT 0xC7 + +struct dvb_table_mgt_table { + uint16_t type; + union { + uint16_t bitfield; + struct { + uint16_t pid:13; + uint16_t one:3; + } __attribute__((packed)); + } __attribute__((packed)); + uint8_t type_version:5; + uint8_t one2:3; + uint32_t size; + union { + uint16_t bitfield2; + struct { + uint16_t desc_length:12; + uint16_t one3:4; + } __attribute__((packed)); + } __attribute__((packed)); + struct dvb_desc *descriptor; + struct dvb_table_mgt_table *next; +} __attribute__((packed)); + +struct dvb_table_mgt { + struct dvb_table_header header; + uint8_t protocol_version; + uint16_t tables; + struct dvb_table_mgt_table *table; + struct dvb_desc *descriptor; +} __attribute__((packed)); + + +#define dvb_mgt_transport_foreach( tran, mgt ) \ + for( struct dvb_table_mgt_transport *tran = mgt->transport; tran; tran = tran->next ) \ + +struct dvb_v5_fe_parms; + +#ifdef __cplusplus +extern "C" { +#endif + +void dvb_table_mgt_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, uint8_t *table, ssize_t *table_length); +void dvb_table_mgt_free(struct dvb_table_mgt *mgt); +void dvb_table_mgt_print(struct dvb_v5_fe_parms *parms, struct dvb_table_mgt *mgt); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/libdvbv5/Makefile.am b/lib/libdvbv5/Makefile.am index 795f30c..9d4b6b9 100644 --- a/lib/libdvbv5/Makefile.am +++ b/lib/libdvbv5/Makefile.am @@ -49,6 +49,7 @@ libdvbv5_la_SOURCES = \ descriptors/sdt.c ../include/descriptors/sdt.h \ descriptors/vct.c ../include/descriptors/vct.h \ descriptors/vct.c ../include/descriptors/vct.h \ + descriptors/mgt.c ../include/descriptors/mgt.h \ descriptors/desc_service_location.c ../include/descriptors/desc_service_location.h \ descriptors/mpeg_ts.c ../include/descriptors/mpeg_ts.h \ descriptors/mpeg_pes.c ../include/descriptors/mpeg_pes.h \ diff --git a/lib/libdvbv5/descriptors.c b/lib/libdvbv5/descriptors.c index 18884b0..bd1bc03 100644 --- a/lib/libdvbv5/descriptors.c +++ b/lib/libdvbv5/descriptors.c @@ -36,6 +36,7 @@ #include "descriptors/sdt.h" #include "descriptors/eit.h" #include "descriptors/vct.h" +#include "descriptors/mgt.h" #include "descriptors/desc_language.h" #include "descriptors/desc_network_name.h" #include "descriptors/desc_cable_delivery.h" diff --git a/lib/libdvbv5/descriptors/mgt.c b/lib/libdvbv5/descriptors/mgt.c new file mode 100644 index 0000000..272d9d7 --- /dev/null +++ b/lib/libdvbv5/descriptors/mgt.c @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2011-2012 - Mauro Carvalho Chehab + * Copyright (c) 2012 - Andre Roth + * + * 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 version 2 + * of the License. + * + * 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 + * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * + */ + +#include "descriptors/mgt.h" +#include "dvb-fe.h" + +void dvb_table_mgt_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, uint8_t *table, ssize_t *table_length) +{ + const uint8_t *p = buf; + struct dvb_table_mgt *mgt = (struct dvb_table_mgt *) table; + struct dvb_desc **head_desc; + struct dvb_table_mgt_table **head; + /*int desc_length;*/ + + if (*table_length > 0) { + /* find end of curent lists */ + head_desc = &mgt->descriptor; + while (*head_desc != NULL) + head_desc = &(*head_desc)->next; + head = &mgt->table; + while (*head != NULL) + head = &(*head)->next; + } else { + memcpy(table, p, sizeof(struct dvb_table_mgt) - sizeof(mgt->descriptor) - sizeof(mgt->table)); + *table_length = sizeof(struct dvb_table_mgt); + + mgt->descriptor = NULL; + mgt->table = NULL; + head_desc = &mgt->descriptor; + head = &mgt->table; + bswap16(mgt->tables); + } + p += sizeof(struct dvb_table_mgt) - sizeof(mgt->descriptor) - sizeof(mgt->table); + + /*dvb_parse_descriptors(parms, p, desc_length, head_desc);*/ + /*p += desc_length;*/ + int i = 0; + struct dvb_table_mgt_table *last = NULL; + while (i++ < mgt->tables && (uint8_t *) p < buf + buflen - 4) { + struct dvb_table_mgt_table *table = (struct dvb_table_mgt_table *) malloc(sizeof(struct dvb_table_mgt_table)); + memcpy(table, p, sizeof(struct dvb_table_mgt_table) - sizeof(table->descriptor) - sizeof(table->next)); + p += sizeof(struct dvb_table_mgt_table) - sizeof(table->descriptor) - sizeof(table->next); + + bswap16(table->type); + bswap16(table->bitfield); + bswap16(table->bitfield2); + bswap32(table->size); + table->descriptor = NULL; + table->next = NULL; + + if(!*head) + *head = table; + if(last) + last->next = table; + + /* get the descriptors for each table */ + struct dvb_desc **head_desc = &table->descriptor; + dvb_parse_descriptors(parms, p, table->desc_length, head_desc); + + p += table->desc_length; + last = table; + } +} + +void dvb_table_mgt_free(struct dvb_table_mgt *mgt) +{ + struct dvb_table_mgt_table *table = mgt->table; + dvb_free_descriptors((struct dvb_desc **) &mgt->descriptor); + while(table) { + dvb_free_descriptors((struct dvb_desc **) &table->descriptor); + struct dvb_table_mgt_table *tmp = table; + table = table->next; + free(tmp); + } + free(mgt); +} + +void dvb_table_mgt_print(struct dvb_v5_fe_parms *parms, struct dvb_table_mgt *mgt) +{ + dvb_log("MGT"); + dvb_table_header_print(parms, &mgt->header); + dvb_log("| protocol_version %d", mgt->protocol_version); + dvb_log("| tables %d", mgt->tables); + /*dvb_print_descriptors(parms, mgt->descriptor);*/ + const struct dvb_table_mgt_table *table = mgt->table; + uint16_t tables = 0; + while(table) { + dvb_log("|- type %04x %d", table->type, table->pid); + dvb_print_descriptors(parms, table->descriptor); + table = table->next; + tables++; + } + dvb_log("|_ %d tables", tables); +} +