From patchwork Fri May 18 23:09:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: rshaffer@tunein.com X-Patchwork-Id: 9017 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:155:0:0:0:0:0 with SMTP id c82-v6csp5841940jad; Fri, 18 May 2018 16:10:06 -0700 (PDT) X-Google-Smtp-Source: AB8JxZotKd1jeCVDmzU5JhES2QFlryR30ZXJlfI+s9aagJuLflS+2S8CDJFJ1WeW2LY3meWnIsUI X-Received: by 2002:a1c:e704:: with SMTP id e4-v6mr5443628wmh.119.1526685006484; Fri, 18 May 2018 16:10:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526685006; cv=none; d=google.com; s=arc-20160816; b=MJCzh9RphHLvnYbLLUPJwGn3jC9btOXyfl2CBTlNLYkMarMIP76NI4dn/nmHlzsm7B EK8MZCb6LB3uFUxDoIbo2oJxQvuevZgAnnhGBJjGXGDr6ReuVWarOHxBqeUT9ilZrpOV WOlJknsNKgksAZL8pECfp32H7Dd9sR+ONCNUXZh0iuUCiJC/uz0rYNNiYKy8dSftVA8z eApFAZmrei1NFMAhWhV1kw1ejqDYr+S0ywQ2DfryH2JReCnlHVcm85KDSmXU17Tobk69 V2yzNjCpBQ1rksv4V6W3oFIquSxJqW4Y7lO9y75R4SSl8BSWU89HAM/EBBUii83GzwhY wkGQ== 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=6arOSJOEjHKxmrs697nOopnUbESKY4YIQDAEuseS6s0=; b=XwShT3LUftqfNVA9JsgNZK5VGqMfHmR4Syygy9gZjr9HtIaJWGBrU4rhHUZMMV1Zcn p/vR0NppLKgB1W94Dq+EqFEcnCMgDXVLNP2FW+eTPl7tNXLEO7gofna/mWiIxMzXI6h7 FdaRWtUr+13/BKPIICsTJIQss+HlpzAZBO7gu2oJeAP2z844Ru2tAvj2GMoJnPC81Wu6 Hy9GFj38XTrxEomyzwjF3vJo8JAD4fA8/iF22/Rwo8pZFQ4NUNlD+e5Yy5rNrAQY4R1y RuTK932JkHfvZmffnTUX+XhYw7lg0gjdW/vcxMsvP3xvfnBVIbZFNjXuIciiagzgn7N+ 4mbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@tunein-com.20150623.gappssmtp.com header.s=20150623 header.b=D+pTK1qp; 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 f18-v6si175756wrq.39.2018.05.18.16.10.05; Fri, 18 May 2018 16:10:06 -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=@tunein-com.20150623.gappssmtp.com header.s=20150623 header.b=D+pTK1qp; 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 9C22C68A44B; Sat, 19 May 2018 02:09:23 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt0-f170.google.com (mail-qt0-f170.google.com [209.85.216.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 83F5068A437 for ; Sat, 19 May 2018 02:09:17 +0300 (EEST) Received: by mail-qt0-f170.google.com with SMTP id f1-v6so12397229qtj.6 for ; Fri, 18 May 2018 16:09:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tunein-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PbzeSwcfkHWajrDdZYFQQHP9hJScO5QA3yqftqt8fxE=; b=D+pTK1qpdFPFUY9kqKUx7hZEqX6q5g8hxd1H6MfMrYPnVTVxQLN1LqxwDWQYeuYoET fBVgeiZ0bh2tcwL3pOpqdUWN48IFMnyzvyWb+YG0LSrWFr0f7B9PWmpnYJ3ieUxr1MzH gquJmZOH9T9m2/s1jVoCxYm7TEx1S5/BJBA2XCZsZCHByVcEsBmTKSCEDWNth0SRMtAw cEZ645SqjpeENOleTLRb2Iwo7P+bIFEk3U9+l2++pZzEzZwPOP9V8qMg30SrizbIwl6f ajZ+7GBrDi6T9RuttxXtSjuQ9A7BJbpp7iLojqvfBlRpXGWazlMBSY/T6nzo4ffbnXKU Slyg== 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; bh=PbzeSwcfkHWajrDdZYFQQHP9hJScO5QA3yqftqt8fxE=; b=YV8ygSEmx/xtZx0wu+tVWFv8PicXwxMRqQjJtj6PGHzzmoCLs8b0PZrUig2LDHynMY 0YRpXNP8epQ9saKm7VnG9TEee7Y/K+19S2yEDrcsxHMOva7G96qiJIMh13mtvaCWv0J7 w7eB7UnOjp1xHPMWIKIwJVQCD5mXxq1R7VCH7GkYG8AjzwtLYKK4TQGSibMLHincvtpg lhXPl+f+ZKSQvDGh2Ri+JNCMsiveakUq/6FizPRb2blQgxzjhT6qSYPT0OpQBLiVul4M qYphERqgChyGf2gLRZty8mdBiuWGJwKEb59OtWQ7+D9+FatrASunIC1OTq6h9NB/E4b+ edcQ== X-Gm-Message-State: ALKqPweFHl8VbBGGoQ2xv0YrZSQjFxY017LSGyJwQoA9mP8HQbnUn+QK sIcO0xj9zJq6FekjTW5EMKjsfzrj2LI= X-Received: by 2002:ac8:3969:: with SMTP id t38-v6mr11276664qtb.75.1526684995693; Fri, 18 May 2018 16:09:55 -0700 (PDT) Received: from 000984.tunein.corp ([38.140.202.59]) by smtp.gmail.com with ESMTPSA id w22-v6sm6248834qtg.60.2018.05.18.16.09.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 18 May 2018 16:09:55 -0700 (PDT) From: rshaffer@tunein.com To: ffmpeg-devel@ffmpeg.org Date: Fri, 18 May 2018 16:09:51 -0700 Message-Id: <20180518230951.13276-1-rshaffer@tunein.com> X-Mailer: git-send-email 2.15.1 (Apple Git-101) In-Reply-To: <20180518210847.5824fc06@debian> References: <20180518210847.5824fc06@debian> Subject: [FFmpeg-devel] [PATCH v2] avformat/hls: Properly expose intercepted ID3 tags to the API. 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: Richard Shaffer MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Richard Shaffer The HLS demuxer will process any ID3 tags at the beginning of a segment in order to obtain timestamp data. However, when this data was parsed on a second or subsequent segment, the updated metadata would be discarded. This change preserves the data and also sets the AVSTREAM_EVENT_FLAG_METADATA_UPDATED event flag when appropriate. --- Changes in this version: * Only set metadata updated flag if we have non-timestamp metadata. * Fix clearing of metadata updated flag in hls_read_header. * Specifically cast operands to unsigned when using bitwise operators. (This last one is almost certainly pedantic, but it doesn't hurt anything.) libavformat/hls.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/libavformat/hls.c b/libavformat/hls.c index 3d4f7f2647..342a022975 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -982,18 +982,8 @@ static void parse_id3(AVFormatContext *s, AVIOContext *pb, } /* Check if the ID3 metadata contents have changed */ -static int id3_has_changed_values(struct playlist *pls, AVDictionary *metadata, - ID3v2ExtraMetaAPIC *apic) +static int id3_has_changed_values(struct playlist *pls, ID3v2ExtraMetaAPIC *apic) { - AVDictionaryEntry *entry = NULL; - AVDictionaryEntry *oldentry; - /* check that no keys have changed values */ - while ((entry = av_dict_get(metadata, "", entry, AV_DICT_IGNORE_SUFFIX))) { - oldentry = av_dict_get(pls->id3_initial, entry->key, NULL, AV_DICT_MATCH_CASE); - if (!oldentry || strcmp(oldentry->value, entry->value) != 0) - return 1; - } - /* check if apic appeared */ if (apic && (pls->ctx->nb_streams != 2 || !pls->ctx->streams[1]->attached_pic.data)) return 1; @@ -1019,6 +1009,19 @@ static void handle_id3(AVIOContext *pb, struct playlist *pls) int64_t timestamp = AV_NOPTS_VALUE; parse_id3(pls->ctx, pb, &metadata, ×tamp, &apic, &extra_meta); + ff_id3v2_parse_priv_dict(&metadata, &extra_meta); + av_dict_copy(&pls->ctx->metadata, metadata, 0); + /* + * If we've handled any ID3 metadata here, it's not going to be seen by the + * sub-demuxer. In the case that we got here because of an IO call during + * hls_read_header, this will be cleared. Otherwise, it provides the + * necessary hint to hls_read_packet that there is new metadata. Note that + * we only set the update flag if we have metadata other than a timestamp. + */ + if (av_dict_count(metadata) > (timestamp == AV_NOPTS_VALUE ? 0 : 1)) { + pls->ctx->event_flags = (unsigned)pls->ctx->event_flags | + (unsigned)AVFMT_EVENT_FLAG_METADATA_UPDATED; + } if (timestamp != AV_NOPTS_VALUE) { pls->id3_mpegts_timestamp = timestamp; @@ -1037,12 +1040,10 @@ static void handle_id3(AVIOContext *pb, struct playlist *pls) /* demuxer not yet opened, defer picture attachment */ pls->id3_deferred_extra = extra_meta; - ff_id3v2_parse_priv_dict(&metadata, &extra_meta); - av_dict_copy(&pls->ctx->metadata, metadata, 0); pls->id3_initial = metadata; } else { - if (!pls->id3_changed && id3_has_changed_values(pls, metadata, apic)) { + if (!pls->id3_changed && id3_has_changed_values(pls, apic)) { avpriv_report_missing_feature(pls->ctx, "Changing ID3 metadata in HLS audio elementary stream"); pls->id3_changed = 1; } @@ -1939,8 +1940,16 @@ static int hls_read_header(AVFormatContext *s) * Copy any metadata from playlist to main streams, but do not set * event flags. */ - if (pls->n_main_streams) + if (pls->n_main_streams) { av_dict_copy(&pls->main_streams[0]->metadata, pls->ctx->metadata, 0); + /* + * If we've intercepted metadata, we will have set this event flag. + * Clear it to avoid confusion, since otherwise we will flag it as + * new metadata on the next call to hls_read_packet. + */ + pls->ctx->event_flags = (unsigned)pls->ctx->event_flags & + ~(unsigned)AVFMT_EVENT_FLAG_METADATA_UPDATED; + } add_metadata_from_renditions(s, pls, AVMEDIA_TYPE_AUDIO); add_metadata_from_renditions(s, pls, AVMEDIA_TYPE_VIDEO);