From nobody Sat May 10 05:27:52 2025 Delivered-To: importer2@patchew.org Received-SPF: pass (zohomail.com: domain of vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; envelope-from=linux-kernel-owner@vger.kernel.org; helo=vger.kernel.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1606216111; cv=none; d=zohomail.com; s=zohoarc; b=goYD+uRpcOHYDCBbOqaW64QxOGuN3kmVhY4uUeIR3ittALwLHp74GMFeonLojVwhd06KiFNt0reglFLXk8lRPIKLI7F0tuZNW8hyAlqJypocXmAJ04qFeHVZfC1cT00Oy4GWbPcaIJBdeIfYM4tz1tFyIrlVajhdNnP7K6AOI4Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606216111; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YaL3hXRDtvRGO3iPXdYKG7o5ezSTrMXMLMGHi2vYdiE=; b=Y94TeBvdGNorCOI5UpGBr9CdKlbTUO70glrodDDA9Zuq7Ku+CtsZh2cZtJ2OnI8WuUkZJHepx1cfUodNShv/GuHe5E8NMIqS0IoG3tejeCUUAerYkFnTqbhsYWk2+BjWE3We25jQky/7E8NVYxESBHkauammeiFhQ8GDP0+XHHQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mx.zohomail.com with SMTP id 1606216111264960.6805722324685; Tue, 24 Nov 2020 03:08:31 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732737AbgKXLHe (ORCPT ); Tue, 24 Nov 2020 06:07:34 -0500 Received: from mail.kernel.org ([198.145.29.99]:33780 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732448AbgKXLGf (ORCPT ); Tue, 24 Nov 2020 06:06:35 -0500 Received: from mail.kernel.org (ip5f5ad5c3.dynamic.kabel-deutschland.de [95.90.213.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F3B9220B1F; Tue, 24 Nov 2020 11:06:30 +0000 (UTC) Received: from mchehab by mail.kernel.org with local (Exim 4.94) (envelope-from ) id 1khW9V-000Fa2-0Y; Tue, 24 Nov 2020 12:06:29 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1606215991; bh=YlTEEhmthM6YyeVWr66Zz28hWTcdh7fEfKoV1W8zEsw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gbO+HR5fl81qiEsVfQP+cRpMPkXou6XlHPqyStI8jHh3AlHOqof/sitZX1CUarkk/ fSTCKt40XE8u8O294Xt5puI9GxqKr4GDXoNHdg2ho10oebTehNGDs0q6CTIGDFiZvK qVAoO4FOfiOGeXuSCpAQvuWOU78QY5ui39LhcUL0= From: Mauro Carvalho Chehab Cc: Mauro Carvalho Chehab , "Daniel W. S. Almeida" , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Subject: [PATCH 16/31] media: vidtv: add a PID entry for the NIT table Date: Tue, 24 Nov 2020 12:06:12 +0100 Message-Id: <31aaa4882400cef0b944e77a3b13efacb2ba5f7d.1606215584.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: Mauro Carvalho Chehab To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" On normal TS streams, the NIT table has its own entry at PAT, but not at PMT. While here, properly handle alloc problems when creating PMT entries. Signed-off-by: Mauro Carvalho Chehab --- .../media/test-drivers/vidtv/vidtv_channel.c | 8 ++-- drivers/media/test-drivers/vidtv/vidtv_mux.c | 2 +- drivers/media/test-drivers/vidtv/vidtv_psi.c | 43 +++++++++++++------ drivers/media/test-drivers/vidtv/vidtv_psi.h | 3 +- 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/drivers/media/test-drivers/vidtv/vidtv_channel.c b/drivers/med= ia/test-drivers/vidtv/vidtv_channel.c index d1d312566bc0..b7cf8caaeb40 100644 --- a/drivers/media/test-drivers/vidtv/vidtv_channel.c +++ b/drivers/media/test-drivers/vidtv/vidtv_channel.c @@ -45,6 +45,7 @@ static void vidtv_channel_encoder_destroy(struct vidtv_en= coder *e) } =20 #define ENCODING_ISO8859_15 "\x0b" +#define TS_NIT_PID 0x10 =20 /* * init an audio only channel with a s302m encoder @@ -296,6 +297,8 @@ vidtv_channel_pat_prog_cat_into_new(struct vidtv_mux *m) =20 cur_chnl =3D cur_chnl->next; } + /* Add the NIT table */ + vidtv_psi_pat_program_init(tail, 0, TS_NIT_PID); =20 return head; } @@ -473,7 +476,7 @@ int vidtv_channel_si_init(struct vidtv_mux *m) =20 vidtv_channel_pmt_match_sections(m->channels, m->si.pmt_secs, - m->si.pat->programs); + m->si.pat->num_pmt); =20 vidtv_channel_destroy_service_list(service_list); =20 @@ -500,12 +503,11 @@ int vidtv_channel_si_init(struct vidtv_mux *m) =20 void vidtv_channel_si_destroy(struct vidtv_mux *m) { - u16 num_programs =3D m->si.pat->programs; u32 i; =20 vidtv_psi_pat_table_destroy(m->si.pat); =20 - for (i =3D 0; i < num_programs; ++i) + for (i =3D 0; i < m->si.pat->num_pmt; ++i) vidtv_psi_pmt_table_destroy(m->si.pmt_secs[i]); =20 kfree(m->si.pmt_secs); diff --git a/drivers/media/test-drivers/vidtv/vidtv_mux.c b/drivers/media/t= est-drivers/vidtv/vidtv_mux.c index e0cc74e98632..0cf784c09024 100644 --- a/drivers/media/test-drivers/vidtv/vidtv_mux.c +++ b/drivers/media/test-drivers/vidtv/vidtv_mux.c @@ -175,7 +175,7 @@ static u32 vidtv_mux_push_si(struct vidtv_mux *m) =20 m->mux_buf_offset +=3D vidtv_psi_pat_write_into(pat_args); =20 - for (i =3D 0; i < m->si.pat->programs; ++i) { + for (i =3D 0; i < m->si.pat->num_pmt; ++i) { pmt_pid =3D vidtv_psi_pmt_get_pid(m->si.pmt_secs[i], m->si.pat); =20 diff --git a/drivers/media/test-drivers/vidtv/vidtv_psi.c b/drivers/media/t= est-drivers/vidtv/vidtv_psi.c index 02dd217bdbf6..5c887639b676 100644 --- a/drivers/media/test-drivers/vidtv/vidtv_psi.c +++ b/drivers/media/test-drivers/vidtv/vidtv_psi.c @@ -794,7 +794,7 @@ vidtv_psi_pat_table_update_sec_len(struct vidtv_psi_tab= le_pat *pat) length +=3D PAT_LEN_UNTIL_LAST_SECTION_NUMBER; =20 /* do not count the pointer */ - for (i =3D 0; i < pat->programs; ++i) + for (i =3D 0; i < pat->num_pat; ++i) length +=3D sizeof(struct vidtv_psi_table_pat_program) - sizeof(struct vidtv_psi_table_pat_program *); =20 @@ -931,7 +931,7 @@ vidtv_psi_pat_program_assign(struct vidtv_psi_table_pat= *pat, program =3D program->next; } =20 - pat->programs =3D program_count; + pat->num_pat =3D program_count; pat->program =3D p; =20 /* Recompute section length */ @@ -966,8 +966,6 @@ struct vidtv_psi_table_pat *vidtv_psi_pat_table_init(u1= 6 transport_stream_id) pat->header.section_id =3D 0x0; pat->header.last_section =3D 0x0; =20 - pat->programs =3D 0; - vidtv_psi_pat_table_update_sec_len(pat); =20 return pat; @@ -1488,22 +1486,43 @@ vidtv_psi_pmt_create_sec_for_each_pat_entry(struct = vidtv_psi_table_pat *pat, u16 pcr_pid) =20 { - struct vidtv_psi_table_pat_program *program =3D pat->program; + struct vidtv_psi_table_pat_program *program; struct vidtv_psi_table_pmt **pmt_secs; - u32 i =3D 0; + u32 i =3D 0, num_pmt =3D 0; =20 - /* a section for each program_id */ - pmt_secs =3D kcalloc(pat->programs, + /* + * The number of PMT entries is the number of PAT entries + * that contain service_id. That exclude special tables, like NIT + */ + program =3D pat->program; + while (program) { + if (program->service_id) + num_pmt++; + program =3D program->next; + } + + pmt_secs =3D kcalloc(num_pmt, sizeof(struct vidtv_psi_table_pmt *), GFP_KERNEL); if (!pmt_secs) return NULL; =20 - while (program) { - pmt_secs[i] =3D vidtv_psi_pmt_table_init(be16_to_cpu(program->service_id= ), pcr_pid); - ++i; - program =3D program->next; + for (program =3D pat->program; program; program =3D program->next) { + if (!program->service_id) + continue; + pmt_secs[i] =3D vidtv_psi_pmt_table_init(be16_to_cpu(program->service_id= ), + pcr_pid); + + if (!pmt_secs[i]) { + while (i > 0) { + i--; + vidtv_psi_pmt_table_destroy(pmt_secs[i]); + } + return NULL; + } + i++; } + pat->num_pmt =3D num_pmt; =20 return pmt_secs; } diff --git a/drivers/media/test-drivers/vidtv/vidtv_psi.h b/drivers/media/t= est-drivers/vidtv/vidtv_psi.h index 26b2c2f5774c..8f98bcaf6229 100644 --- a/drivers/media/test-drivers/vidtv/vidtv_psi.h +++ b/drivers/media/test-drivers/vidtv/vidtv_psi.h @@ -174,7 +174,8 @@ struct vidtv_psi_table_pat_program { */ struct vidtv_psi_table_pat { struct vidtv_psi_table_header header; - u16 programs; /* Included by libdvbv5, not part of the table and not actu= ally serialized */ + u16 num_pat; + u16 num_pmt; struct vidtv_psi_table_pat_program *program; } __packed; =20 --=20 2.28.0