From patchwork Thu Oct 3 12:43:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Delannoy X-Patchwork-Id: 15495 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 4ED724481EB for ; Thu, 3 Oct 2019 17:05:37 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 38B896880EB; Thu, 3 Oct 2019 17:05:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D22CF688092 for ; Thu, 3 Oct 2019 17:05:30 +0300 (EEST) Received: by mail-wm1-f43.google.com with SMTP id y21so2424087wmi.0 for ; Thu, 03 Oct 2019 07:05:30 -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=exb7dv6K70rzn/BfOR2ww77OhoufhC1rigDhJ4PjhiE=; b=ZO0AzwdT2jSPLdPPFNe6QX6vTA8M7Bx51KNaJTrDQ53YkDGaKFtw+T7J+1VEIOzEEc 7kfnAnZNVmPRq1y/dyLl7hTCanHvBg2WIhFTP+1snducrsFlTOUU3+0StDdVFItYKWya 7MwJKwbYgf+r99oYX70S2m9e5A2MMLbr/N+neEXP0Rzf8jUHm0sb31kiyMiI4Y3+9hxJ KMHO0JGV5M7f1uTDLjVkglIVd37Qyz/eXOETcnkGcXkTJXZ5us4gu8IbUtMsxQSD37jJ Sc6Gp1JoQ7LTF2VMSg5F4mUu88+WNsLmz/SQBRo7KHfxdzr/1752M6gON453s/4jMr+D SWxQ== 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=exb7dv6K70rzn/BfOR2ww77OhoufhC1rigDhJ4PjhiE=; b=PmcUfWyylP9h7H7WFGbYGNkY/ODYMY8syJgiv4xeAyJcfFK6i+arHyJSyuByGutPLA /QkEdIPdD7A8/4P9sUVFka0JXftXYE5Pd5I10BHhm8iaU9WFyCFRk0TULI4BxBB9Tt8N E7wTd3FntFq9eJW3OQMfY52vNBbGkjzVtEpWxLy2yIIaTC71Bdqjn0KOC9AcKTUo59vD T6Tw6P99vfhE0WJQE00JJ8ZW8vwOZ05kcAc0NRieGkmzBEijosB1H0E5BZY6fM6HYOQw Zx0vuJk7+hii7/tWDu+N0XOGGUjNpKXrA08UgtWDMPBJJLmzyrL4lQwyA0I2UyrWxGCL NcRA== X-Gm-Message-State: APjAAAXYlr6i6gZo+USXtNq3Vl8Sh5EoJQG9gDOL+w7ziSFEDE8hs72r HzdWTx2psN6r7kmzYZSO7e2+aPzi X-Google-Smtp-Source: APXvYqxBfAVw1gr4OgsyylErs2wT8liOZwP2ZRee0YoOSfxOIBB8IaD4TwisLSxVapOJhhPJGNqYPw== X-Received: by 2002:a1c:9e0b:: with SMTP id h11mr6769772wme.144.1570111211237; Thu, 03 Oct 2019 07:00:11 -0700 (PDT) Received: from tvty-lt-28.localdomain (host.251.54.23.62.rev.coltfrance.com. [62.23.54.251]) by smtp.gmail.com with ESMTPSA id t13sm8097376wra.70.2019.10.03.07.00.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Oct 2019 07:00:09 -0700 (PDT) Received: by tvty-lt-28.localdomain (Postfix, from userid 1001) id 6ACF7B6001B; Thu, 3 Oct 2019 14:43:57 +0200 (CEST) From: Anthony Delannoy To: ffmpeg-devel@ffmpeg.org Date: Thu, 3 Oct 2019 14:43:51 +0200 Message-Id: <20191003124352.31565-2-anthony.2lannoy@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003124352.31565-1-anthony.2lannoy@gmail.com> References: <20191003124352.31565-1-anthony.2lannoy@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] avformat/mpegts: add support for NIT extraction X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Anthony Delannoy Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- libavformat/mpegts.c | 45 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index 587ed33327..5a3e71d9ab 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -169,7 +169,7 @@ struct MpegTSContext { MpegTSFilter *pids[NB_PID_MAX]; int current_pid; - AVStream *epg_stream; + AVStream *epg_stream, *nit_stream; }; #define MPEGTS_OPTIONS \ @@ -2426,6 +2426,46 @@ out: av_free(mp4_descr[i].dec_config_descr); } +static void nit_cb(MpegTSFilter *filter, const uint8_t *section, int section_len) +{ + MpegTSContext *ts = filter->u.section_filter.opaque; + const uint8_t *p, *p_end; + SectionHeader h1, *h = &h1; + + if (!ts->nit_stream) { + ts->nit_stream = avformat_new_stream(ts->stream, NULL); + if (!ts->nit_stream) + return; + ts->nit_stream->id = NIT_PID; + ts->nit_stream->codecpar->codec_type = AVMEDIA_TYPE_DATA; + ts->nit_stream->codecpar->codec_id = AV_CODEC_ID_NIT; + } + + if (ts->nit_stream->discard == AVDISCARD_ALL) + return; + + p_end = section + section_len - 4; + p = section; + + if (parse_section_header(h, &p, p_end) < 0) + return; + if (h->tid != NIT_TID && h->tid != ONIT_TID) + return; + + av_log(ts->stream, AV_LOG_TRACE, "NIT: tid received = %.02x\n", h->tid); + + /** + * In case we receive a packet before mpegts context is fully + * initialized. + */ + if (!ts->pkt) + return; + + new_data_packet(section, section_len, ts->pkt); + ts->pkt->stream_index = ts->nit_stream->index; + ts->stop_parse = 1; +} + static void pat_cb(MpegTSFilter *filter, const uint8_t *section, int section_len) { MpegTSContext *ts = filter->u.section_filter.opaque; @@ -2468,6 +2508,7 @@ static void pat_cb(MpegTSFilter *filter, const uint8_t *section, int section_len if (sid == 0x0000) { /* NIT info */ + // XXX for now we only use default NIT_PID } else { MpegTSFilter *fil = ts->pids[pmt_pid]; program = av_new_program(ts->stream, sid); @@ -3043,6 +3084,7 @@ static int mpegts_read_header(AVFormatContext *s) mpegts_open_section_filter(ts, SDT_PID, sdt_cb, ts, 1); mpegts_open_section_filter(ts, PAT_PID, pat_cb, ts, 1); mpegts_open_section_filter(ts, EIT_PID, eit_cb, ts, 1); + mpegts_open_section_filter(ts, NIT_PID, nit_cb, ts, 1); handle_packets(ts, probesize / ts->raw_packet_size); /* if could not find service, enable auto_guess */ @@ -3301,6 +3343,7 @@ MpegTSContext *avpriv_mpegts_parse_open(AVFormatContext *s) mpegts_open_section_filter(ts, SDT_PID, sdt_cb, ts, 1); mpegts_open_section_filter(ts, PAT_PID, pat_cb, ts, 1); mpegts_open_section_filter(ts, EIT_PID, eit_cb, ts, 1); + mpegts_open_section_filter(ts, NIT_PID, nit_cb, ts, 1); return ts; }