From patchwork Sat Jul 7 11:20:56 2018 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: 10512853 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 58D9F603D7 for ; Sat, 7 Jul 2018 11:21:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B3D82884A for ; Sat, 7 Jul 2018 11:21:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3F80E28874; Sat, 7 Jul 2018 11:21:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B90E52884A for ; Sat, 7 Jul 2018 11:21:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753862AbeGGLVP (ORCPT ); Sat, 7 Jul 2018 07:21:15 -0400 Received: from mail-ed1-f46.google.com ([209.85.208.46]:39228 "EHLO mail-ed1-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753552AbeGGLVK (ORCPT ); Sat, 7 Jul 2018 07:21:10 -0400 Received: by mail-ed1-f46.google.com with SMTP id w14-v6so10451465eds.6 for ; Sat, 07 Jul 2018 04:21:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=l7xUUNWjdGqoaTLzmsmIsVJahY1J/qojsVPZcx6z2u8=; b=V7TysLd51OBeGl9WmzU/M1SD7F4MTfg0Jntn8neIQE0qs7qkgE5AqsvB74Mq2PER9D HHL28ZfHEgIg57ddhf4z6QmPny6Fl+90ibsXwuxjBAmkc87YNclZ95tvTGt73lXXvWI6 P0FedLXi27WidGzHklrVqsUMqvcVrDeOICsK/U4lKWcyN7RuXtb0F9NjGXP1f0ustBe2 UDrm+KKUw/DeWpJUA6KlE8VWGKyPuWWlIbbijuufP2W02fC2qcBbQ/9u+atmGZexktOa MONkQoi+ZdzqhuEhx0z4P4k8Y0htu60UI6Mb2OYSN2XXUnV9FHGLdKh13JISCgnp+iEU dH4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=l7xUUNWjdGqoaTLzmsmIsVJahY1J/qojsVPZcx6z2u8=; b=oe+3c7sezj3Vyi0KNfuoai8H2tmI7D/azNFxd32twmbYQItPNzgQTCUMyka9/aTi3g 6RVUfz4vS2Vb18O22EF+fNQChXpF5YSbLE2CAgRDv1uMj2iy7bhBxncDSFOGztnHGPxT slO/GBWAuVeGg4gNWzpL0pFjhf5GutnelHF6VopYssOSeo9usL+MCVZ9kyGDwM+X/ZeP Z24YbAPTNqyG7xYjI1SgubrLsoWx1c6Juir6o/5IbZ8aud2sxpjsyfRe54faGUCje8iW 3q8B3yLIlK5zA4MgjIRSd7XDyfVn+G7fUHxyF1x8ZAP3WMixbE0VRKZMWrVO03V6Y0Eg U+hQ== X-Gm-Message-State: APt69E2OpjqGQsZBdorwwjIJTVpEnAvHEYax4rLhu9njw+tfg7991VW/ GYDUu4lCpZchzFRp7j3SapAY8A== X-Google-Smtp-Source: AAOMgpcjog3zGgBFCuhd8lCv5jiJF131gBhR+PIPa7hyEwjS5qgs9iJpU6gJ+W/pImvg9FrHLCuHWw== X-Received: by 2002:a50:af45:: with SMTP id g63-v6mr15187464edd.30.1530962469073; Sat, 07 Jul 2018 04:21:09 -0700 (PDT) Received: from localhost.localdomain (247.88.107.92.dynamic.wline.res.cust.swisscom.ch. [92.107.88.247]) by smtp.gmail.com with ESMTPSA id q2-v6sm2239641edl.42.2018.07.07.04.21.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 Jul 2018 04:21:08 -0700 (PDT) From: =?UTF-8?q?Andr=C3=A9=20Roth?= To: linux-media@vger.kernel.org Cc: =?UTF-8?q?Andr=C3=A9=20Roth?= Subject: [PATCH 3/4] libdvbv5: fix parsing EIT extended event descriptor Date: Sat, 7 Jul 2018 13:20:56 +0200 Message-Id: <20180707112057.7235-3-neolynx@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180707112057.7235-1-neolynx@gmail.com> References: <20180707112057.7235-1-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-Virus-Scanned: ClamAV using ClamSMTP correctly parse, print and free the extended event descriptor list of description/item pairs. also fixes a typo in short event descriptor. Signed-off-by: André Roth --- lib/include/libdvbv5/desc_event_extended.h | 9 +++ lib/libdvbv5/descriptors/desc_event_extended.c | 83 ++++++++++++++++++++------ lib/libdvbv5/descriptors/desc_event_short.c | 2 +- 3 files changed, 74 insertions(+), 20 deletions(-) diff --git a/lib/include/libdvbv5/desc_event_extended.h b/lib/include/libdvbv5/desc_event_extended.h index 7e6ac9cd..46ef3276 100644 --- a/lib/include/libdvbv5/desc_event_extended.h +++ b/lib/include/libdvbv5/desc_event_extended.h @@ -39,6 +39,12 @@ #include +struct dvb_desc_event_extended_item { + char *description; + char *description_emph; + char *item; + char *item_emph; +}; /** * @struct dvb_desc_event_extended @@ -58,6 +64,7 @@ * The emphasis text is the one that uses asterisks. For example, in the text: * "the quick *fox* jumps over the lazy table" the emphasis would be "fox". */ + struct dvb_desc_event_extended { uint8_t type; uint8_t length; @@ -74,6 +81,8 @@ struct dvb_desc_event_extended { unsigned char language[4]; char *text; char *text_emph; + struct dvb_desc_event_extended_item *items; + int num_items; } __attribute__((packed)); struct dvb_v5_fe_parms; diff --git a/lib/libdvbv5/descriptors/desc_event_extended.c b/lib/libdvbv5/descriptors/desc_event_extended.c index 200657ad..624ac01c 100644 --- a/lib/libdvbv5/descriptors/desc_event_extended.c +++ b/lib/libdvbv5/descriptors/desc_event_extended.c @@ -22,57 +22,102 @@ #include #include +#ifdef ENABLE_NLS +# include "gettext.h" +# include +# define _(string) dgettext(LIBDVBV5_DOMAIN, string) +#else +# define _(string) string +#endif + int dvb_desc_event_extended_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, struct dvb_desc *desc) { struct dvb_desc_event_extended *event = (struct dvb_desc_event_extended *) desc; - uint8_t len; /* the length of the string in the input data */ - uint8_t len1; /* the lenght of the output strings */ - - /*dvb_hexdump(parms, "event extended desc: ", buf - 2, desc->length + 2);*/ + uint8_t len, size_items; + const uint8_t *buf_start; + int first = 1; + struct dvb_desc_event_extended_item *item; event->ids = buf[0]; + event->language[0] = buf[1]; event->language[1] = buf[2]; event->language[2] = buf[3]; event->language[3] = '\0'; - uint8_t items = buf[4]; + size_items = buf[4]; buf += 5; - int i; - for (i = 0; i < items; i++) { - dvb_logwarn("dvb_desc_event_extended: items not implemented"); - uint8_t desc_len = *buf; + event->items = NULL; + event->num_items = 0; + buf_start = buf; + while (buf - buf_start < size_items) { + if (first) { + first = 0; + event->num_items = 1; + event->items = calloc(sizeof(struct dvb_desc_event_extended_item), event->num_items); + if (!event->items) { + dvb_logerr(_("%s: out of memory"), __func__); + return -1; + } + item = event->items; + } else { + event->num_items++; + event->items = realloc(event->items, sizeof(struct dvb_desc_event_extended_item) * (event->num_items)); + item = event->items + (event->num_items - 1); + } + len = *buf; buf++; + item->description = NULL; + item->description_emph = NULL; + dvb_parse_string(parms, &item->description, &item->description_emph, buf, len); + buf += len; - buf += desc_len; - - uint8_t item_len = *buf; + len = *buf; buf++; - - buf += item_len; + item->item = NULL; + item->item_emph = NULL; + dvb_parse_string(parms, &item->item, &item->item_emph, buf, len); + buf += len; } - event->text = NULL; - event->text_emph = NULL; + len = *buf; - len1 = len; buf++; - dvb_parse_string(parms, &event->text, &event->text_emph, buf, len1); - buf += len; + + if (len) { + event->text = NULL; + event->text_emph = NULL; + dvb_parse_string(parms, &event->text, &event->text_emph, buf, len); + buf += len; + } + return 0; } void dvb_desc_event_extended_free(struct dvb_desc *desc) { struct dvb_desc_event_extended *event = (struct dvb_desc_event_extended *) desc; + int i; free(event->text); free(event->text_emph); + for (i = 0; i < event->num_items; i++) { + free(event->items[i].description); + free(event->items[i].description_emph); + free(event->items[i].item); + free(event->items[i].item_emph); + } + free(event->items); } void dvb_desc_event_extended_print(struct dvb_v5_fe_parms *parms, const struct dvb_desc *desc) { const struct dvb_desc_event_extended *event = (const struct dvb_desc_event_extended *) desc; + int i; dvb_loginfo("| '%s'", event->text); + for (i = 0; i < event->num_items; i++) { + dvb_loginfo("| description '%s'", event->items[i].description); + dvb_loginfo("| item '%s'", event->items[i].item); + } } diff --git a/lib/libdvbv5/descriptors/desc_event_short.c b/lib/libdvbv5/descriptors/desc_event_short.c index 3bdcb89b..881e6d45 100644 --- a/lib/libdvbv5/descriptors/desc_event_short.c +++ b/lib/libdvbv5/descriptors/desc_event_short.c @@ -68,6 +68,6 @@ void dvb_desc_event_short_print(struct dvb_v5_fe_parms *parms, const struct dvb_ const struct dvb_desc_event_short *event = (const struct dvb_desc_event_short *) desc; dvb_loginfo("| name '%s'", event->name); dvb_loginfo("| language '%s'", event->language); - dvb_loginfo("| sescription '%s'", event->text); + dvb_loginfo("| description '%s'", event->text); }