From patchwork Mon Jun 17 03:42:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 13580 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 476A5447DA1 for ; Mon, 17 Jun 2019 06:51:49 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2F744689B11; Mon, 17 Jun 2019 06:51:49 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 73ACE6899F9 for ; Mon, 17 Jun 2019 06:51:42 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id p11so8253149wre.7 for ; Sun, 16 Jun 2019 20:51:42 -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=Fg4TG/TIjUFHaXP/lQenF4MoVE+EbzmaZyDzZnBlPLo=; b=p0beN6+2HOcXpHaooDx9XDgjberzQIVA9tzt3MFLRn3tWxPYeMFz7eduseA5iCldh1 H7iI/zv2wKRYKd/uH+ZuWEezq8AGvYfHmcnJ+yyr5FR4gEDXNVcX4HT0bbt+vkBiE1K9 A11RXFInqSUqv51RHFDTs+JZvou/VQsWL7wwZ+gzT76XllXKF7BUOrlOerzg2bVj+Mye oOgqVgSP+PmaOgPCskVzbjzEGX4JPXe/vJYosWUQ4DwPqiUM95Ci8GGC0JReWV4Bbbqp zhrlUUIobYXvkxzfbo8Ngcn+B0zgNLqJlNrnkUx7lTbISx7ILr1tLfuioccGSSyyQrpJ KEgw== 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=Fg4TG/TIjUFHaXP/lQenF4MoVE+EbzmaZyDzZnBlPLo=; b=p3YTLHJYQMI+/0ER2BjhOK2cYbZZkKRjVDllbahpo80umJLaz5nHDdNR6sF7yb8T6T QhhjiMAcsnO5fmLWXvjbaHtZJ7FbkXifg/VDnRmqFlO45cCQ8N6tnqA0OVMjcLI+xuqG yTSTd7IrDcq65uz12836Hc9lpCm2C6XjivLvK7YNOowma3vN2AOWps4gVLJxTj+MMGyL wpg4s8Sx7fXeFu36EDDWodGoQH5nDcUcbc4Kl9382GCM9yqEZ5cz5kO9jLJi+eS9KnQ7 MKDcLEsIur/JJcrgfTigYDGsscm/Jg3wuTqRKmy6T1icVS8LXQlhf/lzi8MGHPIAscZr nNRA== X-Gm-Message-State: APjAAAVm/ejdfqWGTpKgTw81icR5Wt2yBVYNcLZzc0jNH+pMx1uBHDmq 6Dd9ue6tcEM53Jk0U4rIilYHNz2D X-Google-Smtp-Source: APXvYqxIssC6u/aM+BoOW1gYF7a+OIZ354Fl1Zl3WY4FEttDAXOc3yE0F3vbqiKpndlAYNpsDVAQKw== X-Received: by 2002:adf:fec9:: with SMTP id q9mr856770wrs.241.1560743040423; Sun, 16 Jun 2019 20:44:00 -0700 (PDT) Received: from localhost.localdomain (ipbcc063db.dynamic.kabel-deutschland.de. [188.192.99.219]) by smtp.gmail.com with ESMTPSA id x83sm9632889wmb.42.2019.06.16.20.43.59 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 16 Jun 2019 20:44:00 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 17 Jun 2019 05:42:14 +0200 Message-Id: <20190617034223.21195-10-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190617034223.21195-1-andreas.rheinhardt@gmail.com> References: <20190617034223.21195-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 09/18] h264_metadata: Localize code for display orientation 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" The recent changes to h264_metadata (enabled by the recent changes to ff_cbs_write_packet) made it possible to add side_data to the output packet at any place, not only after the output packet has been written and the properties of the input packet copied. This means that one can now localize the code to add display orientation side-data to the packet to the place dealing with said display-orientation. Furthermore, the documentation of av_display_rotation_set states that the matrix will be fully overwritten by it, so there is no need to allocate it with av_mallocz. Signed-off-by: Andreas Rheinhardt --- That the display orientation code itself is very buggy has not been fixed yet. libavcodec/h264_metadata_bsf.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c index 18c5ae807d..f7ca1f0f09 100644 --- a/libavcodec/h264_metadata_bsf.c +++ b/libavcodec/h264_metadata_bsf.c @@ -289,8 +289,6 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) CodedBitstreamFragment *au = &ctx->access_unit; int err, i, j, has_sps; H264RawAUD aud; - uint8_t *displaymatrix_side_data = NULL; - size_t displaymatrix_side_data_size = 0; err = ff_bsf_get_packet_ref(bsf, pkt); if (err < 0) @@ -487,7 +485,7 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) continue; } - matrix = av_mallocz(9 * sizeof(int32_t)); + matrix = av_malloc(9 * sizeof(int32_t)); if (!matrix) { err = AVERROR(ENOMEM); goto fail; @@ -499,11 +497,17 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) av_display_matrix_flip(matrix, disp->hor_flip, disp->ver_flip); // If there are multiple display orientation messages in an - // access unit then ignore all but the first one. - av_freep(&displaymatrix_side_data); - - displaymatrix_side_data = (uint8_t*)matrix; - displaymatrix_side_data_size = 9 * sizeof(int32_t); + // access unit, then the last one added to the packet (i.e. + // the first one in the access unit) will prevail. + err = av_packet_add_side_data(pkt, AV_PKT_DATA_DISPLAYMATRIX, + (uint8_t*)matrix, + 9 * sizeof(int32_t)); + if (err < 0) { + av_log(bsf, AV_LOG_ERROR, "Failed to attach extracted " + "displaymatrix side data to packet.\n"); + av_freep(matrix); + goto fail; + } } } } @@ -583,24 +587,11 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) goto fail; } - if (displaymatrix_side_data) { - err = av_packet_add_side_data(pkt, AV_PKT_DATA_DISPLAYMATRIX, - displaymatrix_side_data, - displaymatrix_side_data_size); - if (err) { - av_log(bsf, AV_LOG_ERROR, "Failed to attach extracted " - "displaymatrix side data to packet.\n"); - goto fail; - } - displaymatrix_side_data = NULL; - } - ctx->done_first_au = 1; err = 0; fail: ff_cbs_fragment_reset(ctx->cbc, au); - av_freep(&displaymatrix_side_data); if (err < 0) av_packet_unref(pkt);