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;