From patchwork Fri May 22 01:24:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19799 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 7FCBD44B9AF for ; Fri, 22 May 2020 04:24:45 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6271E68ABD5; Fri, 22 May 2020 04:24:45 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 94D4D68A646 for ; Fri, 22 May 2020 04:24:38 +0300 (EEST) Received: by mail-wm1-f66.google.com with SMTP id f134so7239419wmf.1 for ; Thu, 21 May 2020 18:24:38 -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:mime-version :content-transfer-encoding; bh=/stuEZkQoRMC5VXQlZJj+A9wFcU5PgofVrL1j1q0yWs=; b=X0IZM+iM5y+Ivgfp1aWkWq1fxV2fP1NR4yz2HNteZlVjQggn+78w0xC04JWWkLpB7p H1X5mquP6Sav3ZvZ0bEPf1SUF4GcYDoxn4z7eiJTSiGqpyuGb8ATSrZFuwH52Ev+ImZQ ZNJETKDG95x+bdgNGB5MOadjuiqbaps3pNwOR/1ER7v93Uqtaf+C3wDE5UGbbK+M0sM2 dP8ESWoQ7b/XbvwXa5lEcLTC17yLBduUKbftbS/0G/QVtMlbzwO2m3ZdkL1qdPlSyF6q B3v1pEgu61C/6VP6WVYSkby9N9LyUcGQ8qEdtpCmIHccm9y3LH1J0jhtFQGbqxzl+Kes vEng== 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:mime-version :content-transfer-encoding; bh=/stuEZkQoRMC5VXQlZJj+A9wFcU5PgofVrL1j1q0yWs=; b=PZQOJVDL4n3aqNQVfL/TLz6W9ux4Zb3yuPycnY+vH3y8W27au27E5jD6nGaQUYH7zM QJ4hEf3+QVhebSGS7AjlnhgCxt82CdmTWqqTbd83OHGszoEXnjqtQ+KuJmNFoGXA3vx3 9XVRRyo1sKnmntoL7Uj00Hs8LW54aZPUaHQBTO7LUKNg7A242jTKIf9s64dEJwIIj8u0 wAX4i+AJcg9rAeWTPowYYqviIQU+1+tsKWxD9nfLHpIXtWq9RU8ahb5vc6kVk56D6eT7 m79repp55tJwrwqZRsJAdmZ5ZLJ+9i9l5Ch6Ogkv7QxnhRbxqs2C9O8UfdK3uRaY1S/X Q4uQ== X-Gm-Message-State: AOAM532CL4aWg1BlHje0oSk0ng6vG/zzM8E0JxDYvkrtdo9WkUkvRD9P JJ/r+Zr/FeVoIjR245iJgkoLDeOw X-Google-Smtp-Source: ABdhPJzEp7fZGb9dajDVsnw8v1JEdnjpC+uJn+ruIKQTKhpmIofAKPS9y/vPlzJ4tRLpxjjjOm6ysw== X-Received: by 2002:a1c:d7:: with SMTP id 206mr350202wma.15.1590110677656; Thu, 21 May 2020 18:24:37 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id l19sm8548498wmj.14.2020.05.21.18.24.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 May 2020 18:24:36 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 22 May 2020 03:24:29 +0200 Message-Id: <20200522012431.29918-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] avformat/matroskaenc: Don't use stream side-data size 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" av_stream_get_side_data() tells the caller whether a stream has side data of a specific type; if present it can also tell the caller the size of the side data via an optional argument. The Matroska muxer always used this optional argument, although it doesn't really need the size, as the relevant side-data are not buffers, but structures. So change this. Furthermore, relying on the size also made the code susceptible to a quirk of av_stream_get_side_data(): It only sets the size argument if it found side data of the desired type. mkv_write_video_color() checks for side-data twice with the same variable for the size without resetting the size in between; if the second type of side-data isn't present, the size will still be what it was after the first call. This was not dangerous in practice, as the check for the existence of the second side-data compared the size with the expected size, so it would only be problematic if lots of elements were to be added to AVContentLightMetadata. Signed-off-by: Andreas Rheinhardt --- libavformat/matroskaenc.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index fccfee539a..f5968c17b4 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -835,7 +835,6 @@ static void mkv_write_video_color(AVIOContext *pb, const AVStream *st, * plus another byte to stay clear of the end. */ uint8_t colour[(2 + 1 + 8) * 18 + (2 + 1) + 1]; AVIOContext buf, *dyn_cp = &buf; - int side_data_size = 0; int colorinfo_size; const uint8_t *side_data; @@ -868,8 +867,8 @@ static void mkv_write_video_color(AVIOContext *pb, const AVStream *st, } side_data = av_stream_get_side_data(st, AV_PKT_DATA_CONTENT_LIGHT_LEVEL, - &side_data_size); - if (side_data_size) { + NULL); + if (side_data) { const AVContentLightMetadata *metadata = (const AVContentLightMetadata*)side_data; put_ebml_uint(dyn_cp, MATROSKA_ID_VIDEOCOLORMAXCLL, metadata->MaxCLL); @@ -877,8 +876,8 @@ static void mkv_write_video_color(AVIOContext *pb, const AVStream *st, } side_data = av_stream_get_side_data(st, AV_PKT_DATA_MASTERING_DISPLAY_METADATA, - &side_data_size); - if (side_data_size == sizeof(AVMasteringDisplayMetadata)) { + NULL); + if (side_data) { ebml_master meta_element = start_ebml_master( dyn_cp, MATROSKA_ID_VIDEOCOLORMASTERINGMETA, 10 * (2 + 1 + 8)); const AVMasteringDisplayMetadata *metadata = @@ -919,14 +918,13 @@ static void mkv_write_video_projection(AVFormatContext *s, AVIOContext *pb, const AVStream *st) { ebml_master projection; - int side_data_size = 0; uint8_t private[20]; const AVSphericalMapping *spherical = (const AVSphericalMapping *)av_stream_get_side_data(st, AV_PKT_DATA_SPHERICAL, - &side_data_size); + NULL); - if (!side_data_size) + if (!spherical) return; if (spherical->projection != AV_SPHERICAL_EQUIRECTANGULAR && @@ -1028,7 +1026,6 @@ static int mkv_write_stereo_mode(AVFormatContext *s, AVIOContext *pb, const AVDictionaryEntry *tag; MatroskaVideoStereoModeType format = MATROSKA_VIDEO_STEREOMODE_TYPE_NB; const AVStereo3D *stereo; - int side_data_size = 0; *h_width = 1; *h_height = 1; @@ -1052,8 +1049,8 @@ static int mkv_write_stereo_mode(AVFormatContext *s, AVIOContext *pb, } stereo = (const AVStereo3D*)av_stream_get_side_data(st, AV_PKT_DATA_STEREO3D, - &side_data_size); - if (side_data_size >= sizeof(AVStereo3D)) { + NULL); + if (stereo) { switch (stereo->type) { case AV_STEREO3D_2D: format = MATROSKA_VIDEO_STEREOMODE_TYPE_MONO; From patchwork Fri May 22 01:24:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19800 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 A1CD944BA89 for ; Fri, 22 May 2020 04:25:08 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8AF6868AD8B; Fri, 22 May 2020 04:25:08 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DBCB268AAA0 for ; Fri, 22 May 2020 04:25:01 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id g12so7359816wrw.1 for ; Thu, 21 May 2020 18:25:01 -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=oZeXpB5tLCgrqQpwrAY9LJnwsZXB+xL7gXblF7PW1po=; b=sScWDZWoUxq1mW7yEeYuy3ztFG3cXVS0CThqVN8mlxaGoIHy5aErFeSSpHAVpb/J/A corQM1sLQ428kN5xVrCiu1wgGRqHqH6CYpLHzpt1jrUZi3OdwqdhQpgNz1yAg7BX9AxB 1+fos+y2Ij/HfznOqPkRj2br8Fep71SoCXLbEbvyyJnZkQGVmH8RgIz/hh7yNfjBCz+1 cAsyD4p6xuhceXEZTZgVN5m+4P8LazKsPP5UNEr6BjmtNNhg5FMUo1efsLSrxmjbtsjA 8pCswGB+5ohpri646Im89yApRqBITUkNTbrLNh+Sd3akr+R3vXV4sdgJZM3zliGgdyTd h93A== 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=oZeXpB5tLCgrqQpwrAY9LJnwsZXB+xL7gXblF7PW1po=; b=kbSVb/5kwwGl63nAsNuRO1EThcF6TOvMqxYLU8nn1rwXk1PM0Y7sStPvgYeQt7VY71 zPptzh7GY/twQ+EalITgz9tiKa22n985ibwiJrRlPzzb6r67L9sdZxCXAILptk2UZGjW dIAuF5aVtmB/do737EqUbwqB2xulhVLK6tI3k+gKtrWe6yG7cB3mH+XeS3N57lPVxNI1 YXlA2aycsh3bqRyhrWeA9jh7K0VPnnFILHuWlEjjHi+KvLjUuPOpTYdbJT/wMUTGhjOs T/gUxqt+/qMhwy4oiWTGfuA7N7v20IVSA1MC/hi+YFGVEmhZkZZ9D32AzVPPkZSJyCOS gqKg== X-Gm-Message-State: AOAM533MRDuMMXnB61wrtul1k8onZVMdCff8SO2iEkgGcqncIWNdt6pW 5XPp9XylVxzbo8kijUrfYx1kiSrK X-Google-Smtp-Source: ABdhPJw/yEbLes7LX7nqEp1UvuM6x4eLKKn8Dc2qqwkqK4jaYc7dAFB7DS54x2IEn46SqH09KRMaoA== X-Received: by 2002:a5d:66c5:: with SMTP id k5mr1063109wrw.17.1590110701047; Thu, 21 May 2020 18:25:01 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id l19sm8548498wmj.14.2020.05.21.18.25.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 May 2020 18:25:00 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 22 May 2020 03:24:30 +0200 Message-Id: <20200522012431.29918-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200522012431.29918-1-andreas.rheinhardt@gmail.com> References: <20200522012431.29918-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] avformat/matroskaenc: Remove pointless casts 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" by using a const void * pointer as an intermediate. Signed-off-by: Andreas Rheinhardt --- Why is the side-data API (both the packet as well as the stream one) actually based around uint8_t * and not pointers to void despite side-data being mostly structures and not just buffers? libavformat/matroskaenc.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index f5968c17b4..9ad590cb93 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -836,7 +836,7 @@ static void mkv_write_video_color(AVIOContext *pb, const AVStream *st, uint8_t colour[(2 + 1 + 8) * 18 + (2 + 1) + 1]; AVIOContext buf, *dyn_cp = &buf; int colorinfo_size; - const uint8_t *side_data; + const void *side_data; ffio_init_context(dyn_cp, colour, sizeof(colour), 1, NULL, NULL, NULL, NULL); @@ -869,8 +869,7 @@ static void mkv_write_video_color(AVIOContext *pb, const AVStream *st, side_data = av_stream_get_side_data(st, AV_PKT_DATA_CONTENT_LIGHT_LEVEL, NULL); if (side_data) { - const AVContentLightMetadata *metadata = - (const AVContentLightMetadata*)side_data; + const AVContentLightMetadata *metadata = side_data; put_ebml_uint(dyn_cp, MATROSKA_ID_VIDEOCOLORMAXCLL, metadata->MaxCLL); put_ebml_uint(dyn_cp, MATROSKA_ID_VIDEOCOLORMAXFALL, metadata->MaxFALL); } @@ -880,8 +879,7 @@ static void mkv_write_video_color(AVIOContext *pb, const AVStream *st, if (side_data) { ebml_master meta_element = start_ebml_master( dyn_cp, MATROSKA_ID_VIDEOCOLORMASTERINGMETA, 10 * (2 + 1 + 8)); - const AVMasteringDisplayMetadata *metadata = - (const AVMasteringDisplayMetadata*)side_data; + const AVMasteringDisplayMetadata *metadata = side_data; if (metadata->has_primaries) { put_ebml_float(dyn_cp, MATROSKA_ID_VIDEOCOLOR_RX, av_q2d(metadata->display_primaries[0][0])); From patchwork Fri May 22 01:24:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19801 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 8FFB944BA89 for ; Fri, 22 May 2020 04:25:10 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 738B368AD8A; Fri, 22 May 2020 04:25:10 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E5E0768ACA6 for ; Fri, 22 May 2020 04:25:02 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id f5so62961wmh.2 for ; Thu, 21 May 2020 18:25:02 -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=CTL1op9AAoUbnSSkyN3eVA+H3UNiKdx43YRxqTbzmEM=; b=iJ0FEwRbHiUuWh3Ghsr1qlB/DB4XWeS5OJPCuYGTrZEEGYENCWWTs3u2HCVLH6teC4 2bI0rtfKBmuQlJ8l3Amnky+VB+v5xMx/XVNr9Ndrb/33MajRrlw0yXOo5w7eT7d5XCce o8SKhMDv4Y+JaNjX1UwaUbi2Ld7rIeaE8VNL+Cuejk2+8tgXCiljpMMo1RUyARCjH/Bt OQW5tiKafVbyx1RYi3Vv6NVuoOoCax/LLNJ4/ct6yLZsAUndCpzLwc5pknPnvEZ9NiF8 1XYG4HbocOQvmFarYIUo0tLTI/0Ta6PU7ai6YmVTjHMnUYuFQ1NWf8UwCim/3poMOSHw G05A== 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=CTL1op9AAoUbnSSkyN3eVA+H3UNiKdx43YRxqTbzmEM=; b=A0ZHmVzIKitOcVdHxpcTxO4FT/2L9Lnpw7UweDiINUfhC30wKdj39GS3/otJ0IsGBX Jpuo3Uyw1W6af9dr2l451CIPN+7iTZ2qtMLytqHJ7b6mP1KAWlHyeks4XLSgKpo4b7JY Bu5GyNRywwevRAcWvjbecXVxQAmq6TGo0WPRBnnJYINI1i9Z9BNcKkTP4P9iztMfBsIg AKnMPNeEoUoBfiKyuEGg1KYKOcfKYloKijklCCYK46xVGiwuK6wjeNJnfmmM2nKwR0H5 fyvs9+imRO9C9GziYzE7eR59wCbQ0aNajnWwABMJ/5sZQZS1F3NiijwI2p8ZjwO6PszY EEPQ== X-Gm-Message-State: AOAM530geiZysJ5WbT4tBSSaUoJSytgsqZQRQ3sfBl/mUmd9hTv/GrEl EGsGzlCH/km45b8/0judyRD40MUS X-Google-Smtp-Source: ABdhPJz7UgHj+n8hyx+VBMcnMD/fF+y4WSCWKQC0SYfx8CF1J6kZZhkc2K1BtHNBsmP6eGv+a9TzWw== X-Received: by 2002:a7b:cf22:: with SMTP id m2mr11779298wmg.82.1590110702061; Thu, 21 May 2020 18:25:02 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id l19sm8548498wmj.14.2020.05.21.18.25.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 May 2020 18:25:01 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 22 May 2020 03:24:31 +0200 Message-Id: <20200522012431.29918-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200522012431.29918-1-andreas.rheinhardt@gmail.com> References: <20200522012431.29918-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] avformat/utils: Set stream side-data size even without side-data 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Andreas Rheinhardt --- Was the earlier behaviour actually a bug (I think so) or is this new behaviour something that should be explicitly documented? Btw, the stream and packet side-data APIs differ in two more ways: av_packet_new_side_data() adds padding to the buffer and zeroes it whereas av_stream_new_side_data() does not. Should this be unified? libavformat/utils.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavformat/utils.c b/libavformat/utils.c index e6158d8058..b12aff5eb0 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -5507,6 +5507,8 @@ uint8_t *av_stream_get_side_data(const AVStream *st, return st->side_data[i].data; } } + if (size) + *size = 0; return NULL; }