From patchwork Tue Mar 25 18:19:59 2014 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: 3889861 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3F60B9F39B for ; Tue, 25 Mar 2014 18:21:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2FA53201BA for ; Tue, 25 Mar 2014 18:21:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 262AE201F5 for ; Tue, 25 Mar 2014 18:21:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754762AbaCYSVJ (ORCPT ); Tue, 25 Mar 2014 14:21:09 -0400 Received: from mail-ee0-f50.google.com ([74.125.83.50]:63803 "EHLO mail-ee0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753721AbaCYSUq (ORCPT ); Tue, 25 Mar 2014 14:20:46 -0400 Received: by mail-ee0-f50.google.com with SMTP id c13so767150eek.37 for ; Tue, 25 Mar 2014 11:20:45 -0700 (PDT) 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=BA5GSazvJ+21j7BinTSGMc5ILn5lz0OOs5SPtdpyxIw=; b=DGmvWusqdFu/bWDetKObHDt2hRT37jVv1mYQXkIjgYY+acJoLE2wFUG4U8Xvt3RUUk S4rhNtUu5zRpo7MCOF1ofn1O5/chDityHm46mVNX4/LY4sVUcPQwAqt5FV/7usVeGREE bQDTCDe5R3z5pzFdNnhyB5GSaKMGAnfzExYd2WQK+Ld3/cCIvKkd7yqDXP5Yo1QtQN4d zNpENHdQlLPgbPU/joKzSgutua2DE5+C92G0EAJRc+rbVzEsjaKpBDhBnX5/vVTJrQKp zdrSA513jQAIcw2y4dMHa2NRXRwPXw6pbnbJnhmMw/K3mx0hk2DFc7cC3hESfZuVU0qC hzSA== X-Received: by 10.15.53.69 with SMTP id q45mr26030124eew.22.1395771645635; Tue, 25 Mar 2014 11:20:45 -0700 (PDT) Received: from neutrino.exnihilo (140-227.61-188.cust.bluewin.ch. [188.61.227.140]) by mx.google.com with ESMTPSA id 44sm41756278eek.30.2014.03.25.11.20.43 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Mar 2014 11:20:44 -0700 (PDT) From: =?UTF-8?q?Andr=C3=A9=20Roth?= To: LMML Cc: =?UTF-8?q?Andr=C3=A9=20Roth?= Subject: [PATCH 09/11] libdvbv5: add parser for CAT Date: Tue, 25 Mar 2014 19:19:59 +0100 Message-Id: <1395771601-3509-9-git-send-email-neolynx@gmail.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1395771601-3509-1-git-send-email-neolynx@gmail.com> References: <1395771601-3509-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.2 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/libdvbv5/cat.h | 51 ++++++++++++++++++++++++++++++ lib/libdvbv5/Makefile.am | 2 ++ lib/libdvbv5/descriptors.c | 2 ++ lib/libdvbv5/descriptors/cat.c | 72 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 127 insertions(+) create mode 100644 lib/include/libdvbv5/cat.h create mode 100644 lib/libdvbv5/descriptors/cat.c diff --git a/lib/include/libdvbv5/cat.h b/lib/include/libdvbv5/cat.h new file mode 100644 index 0000000..4c442a8 --- /dev/null +++ b/lib/include/libdvbv5/cat.h @@ -0,0 +1,51 @@ +/* + * 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 _CAT_H +#define _CAT_H + +#include +#include /* ssize_t */ + +#include + +#define DVB_TABLE_CAT 0x01 +#define DVB_TABLE_CAT_PID 0x0001 + +struct dvb_table_cat { + struct dvb_table_header header; + struct dvb_desc *descriptor; +} __attribute__((packed)); + +struct dvb_v5_fe_parms; + +#ifdef __cplusplus +extern "C" { +#endif + +void dvb_table_cat_init (struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, uint8_t *table, ssize_t *table_length); +void dvb_table_cat_free(struct dvb_table_cat *cat); +void dvb_table_cat_print(struct dvb_v5_fe_parms *parms, struct dvb_table_cat *t); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/libdvbv5/Makefile.am b/lib/libdvbv5/Makefile.am index 8f89531..0abe42d 100644 --- a/lib/libdvbv5/Makefile.am +++ b/lib/libdvbv5/Makefile.am @@ -39,6 +39,7 @@ otherinclude_HEADERS = \ ../include/libdvbv5/atsc_header.h \ ../include/libdvbv5/mgt.h \ ../include/libdvbv5/eit.h \ + ../include/libdvbv5/cat.h \ ../include/libdvbv5/atsc_eit.h \ ../include/libdvbv5/desc_service_location.h \ ../include/libdvbv5/mpeg_ts.h \ @@ -74,6 +75,7 @@ libdvbv5_la_SOURCES = \ descriptors/vct.c \ descriptors/mgt.c \ descriptors/eit.c \ + descriptors/cat.c \ descriptors/atsc_eit.c \ descriptors/desc_language.c \ descriptors/desc_network_name.c \ diff --git a/lib/libdvbv5/descriptors.c b/lib/libdvbv5/descriptors.c index e611876..ba83d41 100644 --- a/lib/libdvbv5/descriptors.c +++ b/lib/libdvbv5/descriptors.c @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -78,6 +79,7 @@ void dvb_desc_default_print(struct dvb_v5_fe_parms *parms, const struct dvb_desc const struct dvb_table_init dvb_table_initializers[] = { [DVB_TABLE_PAT] = { dvb_table_pat_init, sizeof(struct dvb_table_pat) }, + [DVB_TABLE_CAT] = { dvb_table_cat_init, sizeof(struct dvb_table_cat) }, [DVB_TABLE_PMT] = { dvb_table_pmt_init, sizeof(struct dvb_table_pmt) }, [DVB_TABLE_NIT] = { dvb_table_nit_init, sizeof(struct dvb_table_nit) }, [DVB_TABLE_SDT] = { dvb_table_sdt_init, sizeof(struct dvb_table_sdt) }, diff --git a/lib/libdvbv5/descriptors/cat.c b/lib/libdvbv5/descriptors/cat.c new file mode 100644 index 0000000..4069923 --- /dev/null +++ b/lib/libdvbv5/descriptors/cat.c @@ -0,0 +1,72 @@ +/* + * 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 + * + */ + +#include +#include +#include + +void dvb_table_cat_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, + ssize_t buflen, uint8_t *table, ssize_t *table_length) +{ + struct dvb_table_cat *cat = (void *)table; + struct dvb_desc **head_desc = &cat->descriptor; + const uint8_t *p = buf, *endbuf = buf + buflen - 4; + size_t size; + + if (buf[0] != DVB_TABLE_CAT) { + dvb_logerr("%s: invalid marker 0x%02x, sould be 0x%02x", __func__, buf[0], DVB_TABLE_CAT); + *table_length = 0; + return; + } + + if (*table_length > 0) { + /* find end of current lists */ + while (*head_desc != NULL) + head_desc = &(*head_desc)->next; + } + + size = offsetof(struct dvb_table_cat, descriptor); + if (p + size > endbuf) { + dvb_logerr("CAT table was truncated while filling dvb_table_cat. Need %zu bytes, but has only %zu.", + size, buflen); + return; + } + + memcpy(table, p, size); + p += size; + *table_length = sizeof(struct dvb_table_cat); + + size = endbuf - p; + dvb_parse_descriptors(parms, p, size, head_desc); +} + +void dvb_table_cat_free(struct dvb_table_cat *cat) +{ + dvb_free_descriptors((struct dvb_desc **) &cat->descriptor); + free(cat); +} + +void dvb_table_cat_print(struct dvb_v5_fe_parms *parms, struct dvb_table_cat *cat) +{ + dvb_log("cat"); + dvb_table_header_print(parms, &cat->header); + dvb_print_descriptors(parms, cat->descriptor); +} +