From patchwork Sun Sep 13 22:42:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?R=C3=A9mi_Achard?= X-Patchwork-Id: 22346 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 3966B44BB50 for ; Mon, 14 Sep 2020 01:42:36 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0EC9368BA98; Mon, 14 Sep 2020 01:42:36 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7107168B9A9 for ; Mon, 14 Sep 2020 01:42:29 +0300 (EEST) Received: by mail-wm1-f42.google.com with SMTP id l15so4724986wmh.1 for ; Sun, 13 Sep 2020 15:42:29 -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=TGANUepoQNoRuyvjP+Clmm0JeQGelyFA3ERVlcWq+2k=; b=qEH0+fBrOd/T+XhfZO7u0psmrMUjRnfsTwh30VdA0doui4LZ7jy6WIh6008AA3g7jj Yd9adsG9olPyJUt1Q1kM7Xg/cEQYtUdRVd/mvKRzaVm3/a7Q9wkQu/k+Hx6Aj27FILFg cRC4eXxSroM2o8WzXXbL0r/jtiwrOqo1I2sF1TETyrZMTy/+3/JYHwQ6Q3b6ix3P/0Qz 7qwSjUEkE+FDE0ZUSYZJpis+84vzY87awH2Sx4bqj4uDAoOG88KDZjSP2zVaLMnC9KHm HUnh2FrKtwaH4QsIWaVlwjrrywpx/hnztQQwfZwCLLgl9c1meFwEX6k2VGkV3DSh85pS x8AQ== 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=TGANUepoQNoRuyvjP+Clmm0JeQGelyFA3ERVlcWq+2k=; b=krNcts46PtDycXTuRTnXQOpepaH1jj3MJqbzRdNDMK8JL3QSDhGKsIFlugLCmR8iMQ 7J71B7oWw0gzF0NG0l4N2YhS6Jpu+XkAVSW9VYBkXPVkexBYZzAeoIMIZWoPDDLucDl0 T2VOE0fHvD8bAmhcW0+SnPUo0C2S2utD4zc+FCkvIZ6hftpzZYXSxWh3SWn05XQUp6a/ 5IqVy9AUBqDUsGJ8IEIT5n5c+RgWg/qBNy9yMK3jGbVfeJQfa8YrbOSqZX41+247KGkI CfZ67Tl5/yTRUvItycDr0lbZg9Eh70aUURTLy6muI7maC+rEQ4NCskmJA7WsKruioBCF ba+A== X-Gm-Message-State: AOAM533bwJhyERzMIDxUCkGvNQX9ohvrnaJby+USoatTFfAqkVKkdAov GdwlHDnLdo4GA9IrMRkyMysJsYP8+1c= X-Google-Smtp-Source: ABdhPJwwNqR+tncLqqlew9Dxx6JH2dRj7KrEvh0wfyZB1Wxe5Gkesrg7g1HUAzv6DW7EjUDB29/HqQ== X-Received: by 2002:a1c:8f:: with SMTP id 137mr12131295wma.158.1600036948521; Sun, 13 Sep 2020 15:42:28 -0700 (PDT) Received: from localhost.localdomain (host86-144-145-253.range86-144.btcentralplus.com. [86.144.145.253]) by smtp.gmail.com with ESMTPSA id v17sm18386649wrc.23.2020.09.13.15.42.27 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 Sep 2020 15:42:28 -0700 (PDT) From: =?utf-8?q?R=C3=A9mi_Achard?= To: ffmpeg-devel@ffmpeg.org Date: Sun, 13 Sep 2020 23:42:18 +0100 Message-Id: <20200913224218.60972-1-remiachard@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200913184510.85070-1-remiachard@gmail.com> References: <20200913184510.85070-1-remiachard@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/mxfdec: fix pixel format extraction for cinema j2k 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: =?utf-8?q?R=C3=A9mi_Achard?= Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- libavformat/mxf.h | 1 + libavformat/mxfdec.c | 32 +++++++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/libavformat/mxf.h b/libavformat/mxf.h index fc587f19f0..3fb3c6d74d 100644 --- a/libavformat/mxf.h +++ b/libavformat/mxf.h @@ -49,6 +49,7 @@ enum MXFMetadataSetType { TaggedValue, TapeDescriptor, AVCSubDescriptor, + JPEG2000PictureSubDescriptor, }; enum MXFFrameLayout { diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index 6f6e8d586c..c94876804c 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -325,9 +325,11 @@ static const uint8_t mxf_encrypted_essence_container[] = { 0x06,0x0e,0x2b,0x static const uint8_t mxf_random_index_pack_key[] = { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x11,0x01,0x00 }; static const uint8_t mxf_sony_mpeg4_extradata[] = { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x01,0x0e,0x06,0x06,0x02,0x02,0x01,0x00,0x00 }; static const uint8_t mxf_avid_project_name[] = { 0xa5,0xfb,0x7b,0x25,0xf6,0x15,0x94,0xb9,0x62,0xfc,0x37,0x17,0x49,0x2d,0x42,0xbf }; -static const uint8_t mxf_jp2k_rsiz[] = { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02,0x01,0x00 }; +static const uint8_t mxf_jp2k_rsiz[] = { 0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0a,0x04,0x01,0x06,0x03,0x01,0x00,0x00,0x00 }; static const uint8_t mxf_indirect_value_utf16le[] = { 0x4c,0x00,0x02,0x10,0x01,0x00,0x00,0x00,0x00,0x06,0x0e,0x2b,0x34,0x01,0x04,0x01,0x01 }; static const uint8_t mxf_indirect_value_utf16be[] = { 0x42,0x01,0x10,0x02,0x00,0x00,0x00,0x00,0x00,0x06,0x0e,0x2b,0x34,0x01,0x04,0x01,0x01 }; +static const uint8_t mxf_subdescriptor_array_smpte[] = { 0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x09,0x06,0x01,0x01,0x04,0x06,0x10,0x00,0x00 }; +static const uint8_t mxf_subdescriptor_array_interop[] = { 0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x02,0x06,0x01,0x01,0x04,0x06,0x10,0x00,0x00 }; #define IS_KLV_KEY(x, y) (!memcmp(x, y, sizeof(y))) @@ -855,15 +857,19 @@ static int mxf_read_cryptographic_context(void *arg, AVIOContext *pb, int tag, i static int mxf_read_strong_ref_array(AVIOContext *pb, UID **refs, int *count) { - *count = avio_rb32(pb); - av_free(*refs); - *refs = av_calloc(*count, sizeof(UID)); + int local_count; + + local_count = avio_rb32(pb); + *refs = av_realloc_array(*refs, *count + local_count, sizeof(UID)); + if (!*refs) { *count = 0; return AVERROR(ENOMEM); } avio_skip(pb, 4); /* useless size of objects, always 16 according to specs */ - avio_read(pb, (uint8_t *)*refs, *count * sizeof(UID)); + avio_read(pb, (uint8_t *)(*refs)[*count], local_count * sizeof(UID)); + *count += local_count; + return 0; } @@ -1272,6 +1278,11 @@ static int mxf_read_generic_descriptor(void *arg, AVIOContext *pb, int tag, int rsiz == FF_PROFILE_JPEG2000_DCINEMA_4K) descriptor->pix_fmt = AV_PIX_FMT_XYZ12; } + if (IS_KLV_KEY(uid, mxf_subdescriptor_array_smpte) + || IS_KLV_KEY(uid, mxf_subdescriptor_array_interop)) { + return mxf_read_strong_ref_array(pb, &descriptor->sub_descriptors_refs, + &descriptor->sub_descriptors_count); + } break; } return 0; @@ -2498,6 +2509,16 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) } } + if (st->codecpar->codec_id == AV_CODEC_ID_JPEG2000) { + MXFDescriptor *desc = NULL; + for (k = 0; k < descriptor->sub_descriptors_count; k++) { + if ((desc = mxf_resolve_strong_ref(mxf, &descriptor->sub_descriptors_refs[k], JPEG2000PictureSubDescriptor))) { + st->codecpar->format = desc->pix_fmt; + break; + } + } + } + if (st->codecpar->codec_id == AV_CODEC_ID_RAWVIDEO) { st->codecpar->format = descriptor->pix_fmt; if (st->codecpar->format == AV_PIX_FMT_NONE) { @@ -2753,6 +2774,7 @@ static const MXFMetadataReadTableEntry mxf_metadata_read_table[] = { { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x5c,0x00 }, mxf_read_generic_descriptor, sizeof(MXFDescriptor), Descriptor }, /* VANC/VBI - SMPTE 436M */ { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x5e,0x00 }, mxf_read_generic_descriptor, sizeof(MXFDescriptor), Descriptor }, /* MPEG2AudioDescriptor */ { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x64,0x00 }, mxf_read_generic_descriptor, sizeof(MXFDescriptor), Descriptor }, /* DC Timed Text Descriptor */ + { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x5a,0x00 }, mxf_read_generic_descriptor, sizeof(MXFDescriptor), JPEG2000PictureSubDescriptor }, /* JPEG2000PictureSubDescriptor */ { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x3A,0x00 }, mxf_read_track, sizeof(MXFTrack), Track }, /* Static Track */ { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x3B,0x00 }, mxf_read_track, sizeof(MXFTrack), Track }, /* Generic Track */ { { 0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x14,0x00 }, mxf_read_timecode_component, sizeof(MXFTimecodeComponent), TimecodeComponent },