From patchwork Fri May 18 18:15:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 9015 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:155:0:0:0:0:0 with SMTP id c82-v6csp5605603jad; Fri, 18 May 2018 11:15:21 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo02cLwf8yqbASHgCJoYjcNRwI9Q+XW9B239UdYqOxY4YAyXFCxtEgDFCcmjdltk/1PLMQe X-Received: by 2002:a1c:63c5:: with SMTP id x188-v6mr5620882wmb.61.1526667321889; Fri, 18 May 2018 11:15:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526667321; cv=none; d=google.com; s=arc-20160816; b=nhLQEov8aLRWTRg08LHRzevCidSydJx2JcOZBQUCgzmhedKRY9cBhi2PNtcvfAkNxq VC/7hSv7QjF1wvoXjHhzNvpXOPkhWAoSDbIrgbH821GIIDB8eyFLpfj5/B9x87ZvE1QS KpiareeBxxS2VNoKMdxIJmmmZXrjfZCM4ODKln8jnXEoxyTswnO6eRM9/ZuaUOgG6TfX vuZ3Jfmd+VkybIBkunpcTGjrQ4PfpuHuYiEiex6kaGM62Oler7xKjp+sR1gH7tdDCWiO yL1o7TttLr6NhdzJHPG0lAB2/YV/u7NPR57GPcnJYbtUeaaEFsjtrudC8r8CLfbirvU9 zGRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=rMezLvv2U9z9L5VrddSjGBthoOOuQhWunl9kueuQJN4=; b=gRFizQLTRTLvSSMbXgygFzNGsN2jCJRGUJ45L9u50bkczaLRGu2P1q5sH+sl8jIp1y bcu0992rT4gu3TXs1/cqN022u18Xvx/6TxkRfuCyz3MKn2UGx9BjHQMQqwEh6c3R4K+9 FL8a0jZdNc/gUZRXFTcR9WT3weaUiw3VLSuVQphOLO3w9IF1E/g0fxYPO8PQ2sqD4ctj FFanBzunogx45TQ5NJOPY06s9rqiFEDB61Ind4sPgLDTKCc5a0sEkaqRsEDC9koRt18V Hvn9nN1SVvnYN59Q2QfdfhwmmzibSRbVptjlnXxTICzdEexVfgrM8O0hHmH6T3WMGAnk Lmag== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@tmm1-net.20150623.gappssmtp.com header.s=20150623 header.b=PlFtmDqA; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 198-v6si5971593wmw.86.2018.05.18.11.15.21; Fri, 18 May 2018 11:15:21 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@tmm1-net.20150623.gappssmtp.com header.s=20150623 header.b=PlFtmDqA; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D6C2D689FC8; Fri, 18 May 2018 21:14:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl0-f42.google.com (mail-pl0-f42.google.com [209.85.160.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 20DB7688290 for ; Fri, 18 May 2018 21:14:34 +0300 (EEST) Received: by mail-pl0-f42.google.com with SMTP id w19-v6so5025667plq.4 for ; Fri, 18 May 2018 11:15:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tmm1-net.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=VqNY/AJD0ryDapXGBXyb0ttAHzjFo23i/EruDYJbsmE=; b=PlFtmDqAEf9oi8i7ea6crEVYet3w2JfyoeVa3JpFrreUkwJK8Z4+HJFsAU42QUsAwl OB77A8J+XFwvh9T5RSRL+H04nL2x6Pm9+IB7cpCoGwY4rOiWZ0BUuMYB3UKHMDao6R6E SF+GCdOK/OuFhCBTMT4UjbuWoUpd0Kf38ztN/OugkShWkM/eUVt+WBgf2xYd4Kx/PJkN XQtiZzPRqZzEC7aLCuYV5OT119l/mjV+ToucuaUh7YBVU3dxb4TLOXgbNnX5U48BZB7J rSdyF+4+8wA4s4mnvyHFL6OQlzisponHHaI4M/7NNInlxPvWOy1USpmqbriFDVSdA2h8 V1Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=VqNY/AJD0ryDapXGBXyb0ttAHzjFo23i/EruDYJbsmE=; b=HrbNozYg5IWohSrdjc+3ymt2HASlL7b4Mv/Mo2wrBVj58LR4Ars9tBwwMIoQZdY3N4 R9I9kUdeUsHc6LCMAhndKowGji02JdaEz7q7Om6n8yJVHkbtJlC2sHWKuUCsmua9O94v ZhcSDx3p8+qNM9zA+ITn91IihkCDa+lbyHUmpWQiC4qwYUO8X65LIAz7ML/HXAXQ1Vft 8RCQbknDGFBcr1yXrM3HhWfGWFEM+dMTXEguFrgeH/UwBEY1KstLOYmSvMobyLl9ONr8 d/lDnlks0VxdRlBgu6Q8a8jj+ORHy/+Kv4jhfA3L+UUnX/itX83MIS0leJJ9CCRKAEn9 vE6w== X-Gm-Message-State: ALKqPwe1JF83NtgEf9VdardqQDfi9TOSB1KXP8GO7kyKz4yCPTygz95G aSv81wi2pOqq0am7psxiHyDW/zGc X-Received: by 2002:a17:902:2702:: with SMTP id c2-v6mr10332735plb.297.1526667312053; Fri, 18 May 2018 11:15:12 -0700 (PDT) Received: from localhost.localdomain (c-69-181-54-242.hsd1.ca.comcast.net. [69.181.54.242]) by smtp.gmail.com with ESMTPSA id 185-v6sm13638991pfu.13.2018.05.18.11.15.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 18 May 2018 11:15:11 -0700 (PDT) From: Aman Gupta To: ffmpeg-devel@ffmpeg.org Date: Fri, 18 May 2018 11:15:05 -0700 Message-Id: <20180518181506.88903-2-ffmpeg@tmm1.net> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180518181506.88903-1-ffmpeg@tmm1.net> References: <20180518181506.88903-1-ffmpeg@tmm1.net> Subject: [FFmpeg-devel] [PATCH v4 2/3] avformat/mpegts: keep track of PMT details in AVProgram/AVStream 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: Aman Gupta MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Aman Gupta With these fields, the user has enough information to detect PMT changes and switch to new streams when the PMT is updated with new ES pids. To do so, the user would monitor the AVProgram they're interested in for changes to pmt_version. If the version changes, they would iterate over the program's streams to find new streams added with the updated version number. If new versions of streams are found, then the user would first try to replace existing streams where stream_identifier matched. If stream_identifier is not available, then the user would compare pmt_stream_idx instead to replace the stream that was previously at the same position within the PMT. Signed-off-by: Aman Gupta --- libavformat/mpegts.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index fc9bb3940e..229202e09d 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -330,12 +330,23 @@ static void set_pmt_found(MpegTSContext *ts, unsigned int programid) p->pmt_found = 1; } -static void set_pcr_pid(AVFormatContext *s, unsigned int programid, unsigned int pid) +static void update_av_program_info(AVFormatContext *s, unsigned int programid, + unsigned int pid, int version) { int i; for (i = 0; i < s->nb_programs; i++) { - if (s->programs[i]->id == programid) { - s->programs[i]->pcr_pid = pid; + AVProgram *program = s->programs[i]; + if (program->id == programid) { + int old_pcr_pid = program->pcr_pid, + old_version = program->pmt_version; + program->pcr_pid = pid; + program->pmt_version = version; + + if (old_version != -1 && old_version != version) { + av_log(s, AV_LOG_DEBUG, + "detected PMT change on program %d (version=%d/%d, pcr_pid=0x%x/0x%x)\n", + programid, old_version, version, old_pcr_pid, pid); + } break; } } @@ -2036,7 +2047,7 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len return; pcr_pid &= 0x1fff; add_pid_to_pmt(ts, h->id, pcr_pid); - set_pcr_pid(ts->stream, h->id, pcr_pid); + update_av_program_info(ts->stream, h->id, pcr_pid, h->version); av_log(ts->stream, AV_LOG_TRACE, "pcr_pid=0x%x\n", pcr_pid); @@ -2078,7 +2089,7 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len set_pmt_found(ts, h->id); - for (;;) { + for (i = 0; ; i++) { st = 0; pes = NULL; stream_type = get8(&p, p_end); @@ -2099,6 +2110,9 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len if (!pes->st) goto out; pes->st->id = pes->pid; + pes->st->program_num = h->id; + pes->st->pmt_version = h->version; + pes->st->pmt_stream_idx = i; } st = pes->st; } else if (is_pes_stream(stream_type, prog_reg_desc)) { @@ -2110,6 +2124,9 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len if (!st) goto out; st->id = pes->pid; + st->program_num = h->id; + st->pmt_version = h->version; + st->pmt_stream_idx = i; } } else { int idx = ff_find_stream_index(ts->stream, pid); @@ -2120,6 +2137,9 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len if (!st) goto out; st->id = pid; + st->program_num = h->id; + st->pmt_version = h->version; + st->pmt_stream_idx = i; st->codecpar->codec_type = AVMEDIA_TYPE_DATA; if (stream_type == 0x86 && prog_reg_desc == AV_RL32("CUEI")) { mpegts_find_stream_type(st, stream_type, SCTE_types);