From patchwork Mon Mar 29 08:42:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26633 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 B7D4C44AD8A for ; Mon, 29 Mar 2021 11:42:30 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 78727680A2D; Mon, 29 Mar 2021 11:42:30 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-oln040092071087.outbound.protection.outlook.com [40.92.71.87]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8E460680282 for ; Mon, 29 Mar 2021 11:42:27 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oI5tJdt50toTukH9Samt78CSaflmNsgmULsUYfkBl02/RznoqSJx+4cZbqUF/fACwEDFX6AaoxtIQ5jEi6jmJmyN3htyGVCpbAdwdujbH8ULgffDy+w7oM98v3V+ep21QGJYp6/sBfJS0XRYfRul7dQcnMpAq3743UGDr+dQFUiVlKcIPEYIFMWaqJRfdJIy5d1d7ZLlP2ulY33FoqKUdHVbbqOzghknjtvWlwmCj9hMNhUIF2ZsdNvBgoyuqYaOmjAR2G4+eBk9K9tgPDJQ53QlqA445t5mlrm+frpE506aWRb9JivULQxl6YV8PxB5rLdbaWnyDiymbzm8CkVRBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DnYhgJoNQY0luybZnLN9hPnoZ96Nf1zJrha5/CZC0FA=; b=Ijnzno4PT4WlH4pGpVzrVoas7lyIjvW6bekc4NwivTQRN5eW71yop8wVUyhd0Gzg3EQB0IlUI8zAx26yqxhizz7bZHFqGgsRcMPsDeZA38STcMwY9affgcX5OX6iQOcv6USzoMOO19goom2x6Hr0eT8F3VcSyle0+7etxQ8/l+LDegnlYr2naRC7cag4uy2RQMzdaBdXQFdLXnYmYWO4t23G4vxdZ3pYhALZQy+sHhUsRiU25MsyPOttLDo22JR7h+wjAiepeuYRGmTbPBrILNJxXEISxoFvOtowEOd4DoQKHcnlCsPd9PnG//8WRW/9MSeCqLDeyxDbnyJ8FyWoEQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DnYhgJoNQY0luybZnLN9hPnoZ96Nf1zJrha5/CZC0FA=; b=mnnTrcNPTMU5sjAHlRLP6IZ9Ag2Ntth8SaMNtKFZqdpi7P4nv1MrPm3gn0Cvdzps+1y5Pulwm9MLWQhYBFZf9oW2hDCkaPs0CXXXDUwm8/7v6w0Bt734t8SQe0aVvGChH1Ui9F1q+Hif75WVpa37Nw4cIBLmIluAF0KK+N2cnEejsEBdhAz01EBXiv0Z+TQsy/avkhNBGZoP5rhfEDD8iYNUKy2GNdTJ/yiIez/+FvOx2dqVPR49Uml/6y9WJ/m83rPu0vr55G9yuTwJGV7b9lWktNceWHO+0vmbdnZD6rIrq1E9d74tl2mE9Rv77Sv1J7tV58NJFdANiK/nJEe8pQ== Received: from VE1EUR03FT009.eop-EUR03.prod.protection.outlook.com (2a01:111:e400:7e09::4a) by VE1EUR03HT054.eop-EUR03.prod.protection.outlook.com (2a01:111:e400:7e09::461) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.29; Mon, 29 Mar 2021 08:42:25 +0000 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com (2a01:111:e400:7e09::49) by VE1EUR03FT009.mail.protection.outlook.com (2a01:111:e400:7e09::92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25 via Frontend Transport; Mon, 29 Mar 2021 08:42:25 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:58E96555FA7FA3CC0C7F46B8ADD15EC11AC114E17838B38BAAE5989D37470440; UpperCasedChecksum:288B09DA668AB495CD6AB5A547EC9AFD3995B05FEDCEB31DD7449DB315D4BBFD; SizeAsReceived:7408; Count:46 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::8128:5de5:4e94:9a21]) by HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::8128:5de5:4e94:9a21%3]) with mapi id 15.20.3977.033; Mon, 29 Mar 2021 08:42:25 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 29 Mar 2021 10:42:00 +0200 Message-ID: X-Mailer: git-send-email 2.27.0 X-TMN: [QjnqCcW82TDzuzkQkVVXSsPBeGq+U6zJ] X-ClientProxiedBy: AM4PR0302CA0023.eurprd03.prod.outlook.com (2603:10a6:205:2::36) To HE1PR0301MB2154.eurprd03.prod.outlook.com (2603:10a6:3:2a::22) X-Microsoft-Original-Message-ID: <20210329084203.402250-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.137.96) by AM4PR0302CA0023.eurprd03.prod.outlook.com (2603:10a6:205:2::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25 via Frontend Transport; Mon, 29 Mar 2021 08:42:25 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 46 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 08181d0b-e8a0-4d78-db06-08d8f28e93eb X-MS-Exchange-SLBlob-MailProps: 7MJMDUNTCtyG7JLNmMoDcXgSrFf0WyM42Qv9vboBcPG4FLzemNFklXW9wWrmbuyTrxd4wZqU1qW30ozO6n4wFrd6vU7OTAUKmbTLiyVJATV9lRn9kwe6b0pGdazWxhK/4PPQWPh4ynB9GZ5BjM0N5osXw6YkRehSt28ZweKV5wXQcuv2WP8ZQ+0IX2TvBySUM0FMN+1ak9lOkhv/xIJkGGFLHgkIRq6CpMKEShZKsjBk2MF9kxC4Xlni4DUu9PJs9brGE09MppPpdtPIrCBzGAgFjyaaILX1o+2OqZnA5Yd3BrqR+rKABxtg4iFuAVzmUF2XRzps2d2lA3R6Xry9FLp06RmtDkjw2R48yHJ+mb7iSPIAI4f30jaD6EPyGkptDvlM3jrnAiNaXc31mS2pe0S8Iv4Er2Tqwb3wFeH5yzBhMZzpNk5HQmIY0AOAnPXfIjkzI5chQOEpzYUFgPPoZn3kpRUycb8e3Yq9ZgxxF9EG576hn+m33SMCdC6n9NVcW6KTbumz0YrnjxYmQsu9S2zGEe6BVjblWMcy24GT+MrN4NFf6IvH7dKiVqojbd7rg+6TzGLof/fepL6BzWQO3SJAzR0vBcc9T/yhq3D4g7j9BMAexyfFHqLUk6o2/w5VyjC3GVd2zdXJ8QUw0s08g0RDaFIaFNZUow3WYJZBT5VWiJDlm2mJQnQBvnZchLH7TVXF8uiy6+CdxATkxHLUlRQGOlIDmiwGN5lquQgBUFvwr+OVbwQYtA== X-MS-TrafficTypeDiagnostic: VE1EUR03HT054: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WI8RNPJvZc/cB8y03//rs/h/q0lzgetLHQ0rxdhKwkjutTtx+8Xr4WzEUAoprhCJ4KytVrXds20uhlN6o3cUXpcoggQDO/LJMaqAWC6XLzTtQiYgZR7Ls5tYaZqPnsqMyNP54JGf/iF4U+D4bigsm/0HPduDyd8uZzdTOoE8FDlITyCjPER2Qps6/i6swNuvXOHKLNgNu+ajbX3JVz/+8qAbwwWmMbigC6BSTVBr9QDQTvUTJTE7dpigZ3I1yClxjW8A7Zt+B5bry71/vqAwSzw4ZL+0q+QV64yteGfgWA7N82p7xYRMZypqcpxw6oDMRIUGFN//2i8EFm8hhuISDFw7i0miTphzYtx9e9GB+B0JWnSgD8vqxYcYd5CWx/LZyKhftU+mBxlg0xIy7ktBoA== X-MS-Exchange-AntiSpam-MessageData: UzqlPeUDTETVyH0qzPJU+FVaK4O0kvZYxq0XAzp6192iFxbW72h1akoUcogH+ywc52IG3JPmfq7JXKYQdXpCTgxJ8tQlmMRXJ3Fi23P9p7VT2aqE5fjKEXdzvRN5E3tZT3hPm9WaO+iQeIfd6N2SZQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 08181d0b-e8a0-4d78-db06-08d8f28e93eb X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2021 08:42:25.8438 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: VE1EUR03FT009.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1EUR03HT054 Subject: [FFmpeg-devel] [PATCH 1/4] avformat: Add and use helper function to add attachment streams 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" All instances of adding attached pictures to a stream or adding a stream and an attached packet to said stream have several things in common like setting the index and flags of the packet, setting the stream disposition etc. This commit therefore factors this out. Signed-off-by: Andreas Rheinhardt --- I always pondered factoring this out; James' proposal made me do it. libavformat/apetag.c | 10 +--------- libavformat/flac_picture.c | 17 ++++------------- libavformat/id3v2.c | 21 ++++++--------------- libavformat/internal.h | 13 +++++++++++++ libavformat/matroskadec.c | 15 +++------------ libavformat/mov.c | 25 +++++++------------------ libavformat/utils.c | 30 ++++++++++++++++++++++++++++++ libavformat/wtvdec.c | 12 ++---------- 8 files changed, 66 insertions(+), 77 deletions(-) diff --git a/libavformat/apetag.c b/libavformat/apetag.c index 23ee6b516d..6f82fbe202 100644 --- a/libavformat/apetag.c +++ b/libavformat/apetag.c @@ -79,20 +79,12 @@ static int ape_tag_read_field(AVFormatContext *s) av_dict_set(&st->metadata, key, filename, 0); if ((id = ff_guess_image2_codec(filename)) != AV_CODEC_ID_NONE) { - int ret; - - ret = av_get_packet(s->pb, &st->attached_pic, size); + int ret = ff_add_attached_pic(s, st, s->pb, NULL, size); if (ret < 0) { av_log(s, AV_LOG_ERROR, "Error reading cover art.\n"); return ret; } - - st->disposition |= AV_DISPOSITION_ATTACHED_PIC; - st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = id; - - st->attached_pic.stream_index = st->index; - st->attached_pic.flags |= AV_PKT_FLAG_KEY; } else { if ((ret = ff_get_extradata(s, st->codecpar, s->pb, size)) < 0) return ret; diff --git a/libavformat/flac_picture.c b/libavformat/flac_picture.c index f15cfa877a..96e14f76c9 100644 --- a/libavformat/flac_picture.c +++ b/libavformat/flac_picture.c @@ -160,20 +160,11 @@ int ff_flac_parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size, int tr if (AV_RB64(data->data) == PNGSIG) id = AV_CODEC_ID_PNG; - st = avformat_new_stream(s, NULL); - if (!st) { - RETURN_ERROR(AVERROR(ENOMEM)); - } - - av_packet_unref(&st->attached_pic); - st->attached_pic.buf = data; - st->attached_pic.data = data->data; - st->attached_pic.size = len; - st->attached_pic.stream_index = st->index; - st->attached_pic.flags |= AV_PKT_FLAG_KEY; + ret = ff_add_attached_pic(s, NULL, NULL, &data, 0); + if (ret < 0) + RETURN_ERROR(ret); - st->disposition |= AV_DISPOSITION_ATTACHED_PIC; - st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st = s->streams[s->nb_streams - 1]; st->codecpar->codec_id = id; st->codecpar->width = width; st->codecpar->height = height; diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c index f33b7ba93a..863709abbf 100644 --- a/libavformat/id3v2.c +++ b/libavformat/id3v2.c @@ -1142,34 +1142,25 @@ int ff_id3v2_parse_apic(AVFormatContext *s, ID3v2ExtraMeta *extra_meta) for (cur = extra_meta; cur; cur = cur->next) { ID3v2ExtraMetaAPIC *apic; AVStream *st; + int ret; if (strcmp(cur->tag, "APIC")) continue; apic = &cur->data.apic; - if (!(st = avformat_new_stream(s, NULL))) - return AVERROR(ENOMEM); - - st->disposition |= AV_DISPOSITION_ATTACHED_PIC; - st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + ret = ff_add_attached_pic(s, NULL, NULL, &apic->buf, 0); + if (ret < 0) + return ret; + st = s->streams[s->nb_streams - 1]; st->codecpar->codec_id = apic->id; - if (AV_RB64(apic->buf->data) == PNGSIG) + if (AV_RB64(st->attached_pic.data) == PNGSIG) st->codecpar->codec_id = AV_CODEC_ID_PNG; if (apic->description[0]) av_dict_set(&st->metadata, "title", apic->description, 0); av_dict_set(&st->metadata, "comment", apic->type, 0); - - av_packet_unref(&st->attached_pic); - st->attached_pic.buf = apic->buf; - st->attached_pic.data = apic->buf->data; - st->attached_pic.size = apic->buf->size - AV_INPUT_BUFFER_PADDING_SIZE; - st->attached_pic.stream_index = st->index; - st->attached_pic.flags |= AV_PKT_FLAG_KEY; - - apic->buf = NULL; } return 0; diff --git a/libavformat/internal.h b/libavformat/internal.h index 8631694d00..b3c5d8a1d5 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -669,6 +669,19 @@ int ff_framehash_write_header(AVFormatContext *s); */ int ff_read_packet(AVFormatContext *s, AVPacket *pkt); +/** + * Add an attached pic to an AVStream. + * + * @param st if set, the stream to add the attached pic to; + * if unset, a new stream will be added to s. + * @param pb AVIOContext to read data from if buf is unset. + * @param buf if set, it contains the data and size information to be used + * for the attached pic; if unset, data is read from pb. + * @param size the size of the data to read if buf is unset. + */ +int ff_add_attached_pic(AVFormatContext *s, AVStream *st, AVIOContext *pb, + AVBufferRef **buf, int size); + /** * Interleave an AVPacket per dts so it can be muxed. * diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 1dc188c946..e8c76f9cfb 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -3007,18 +3007,9 @@ static int matroska_read_header(AVFormatContext *s) attachments[j].stream = st; if (st->codecpar->codec_id != AV_CODEC_ID_NONE) { - AVPacket *pkt = &st->attached_pic; - - st->disposition |= AV_DISPOSITION_ATTACHED_PIC; - st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; - - av_packet_unref(pkt); - pkt->buf = attachments[j].bin.buf; - attachments[j].bin.buf = NULL; - pkt->data = attachments[j].bin.data; - pkt->size = attachments[j].bin.size; - pkt->stream_index = st->index; - pkt->flags |= AV_PKT_FLAG_KEY; + res = ff_add_attached_pic(s, st, NULL, &attachments[j].bin.buf, 0); + if (res < 0) + goto fail; } else { st->codecpar->codec_type = AVMEDIA_TYPE_ATTACHMENT; if (ff_alloc_extradata(st->codecpar, attachments[j].bin.size)) diff --git a/libavformat/mov.c b/libavformat/mov.c index cb818ebe0e..097aa2bfb2 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -196,17 +196,16 @@ static int mov_read_covr(MOVContext *c, AVIOContext *pb, int type, int len) return 0; } - st = avformat_new_stream(c->fc, NULL); - if (!st) - return AVERROR(ENOMEM); sc = av_mallocz(sizeof(*sc)); if (!sc) return AVERROR(ENOMEM); - st->priv_data = sc; - - ret = av_get_packet(pb, &st->attached_pic, len); - if (ret < 0) + ret = ff_add_attached_pic(c->fc, NULL, pb, NULL, len); + if (ret < 0) { + av_free(sc); return ret; + } + st = c->fc->streams[c->fc->nb_streams - 1]; + st->priv_data = sc; if (st->attached_pic.size >= 8 && id != AV_CODEC_ID_BMP) { if (AV_RB64(st->attached_pic.data) == 0x89504e470d0a1a0a) { @@ -215,13 +214,6 @@ static int mov_read_covr(MOVContext *c, AVIOContext *pb, int type, int len) id = AV_CODEC_ID_MJPEG; } } - - st->disposition |= AV_DISPOSITION_ATTACHED_PIC; - - st->attached_pic.stream_index = st->index; - st->attached_pic.flags |= AV_PKT_FLAG_KEY; - - st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = id; return 0; @@ -7229,11 +7221,8 @@ static void mov_read_chapters(AVFormatContext *s) goto finish; } - if (av_get_packet(sc->pb, &st->attached_pic, sample->size) < 0) + if (ff_add_attached_pic(s, st, sc->pb, NULL, sample->size) < 0) goto finish; - - st->attached_pic.stream_index = st->index; - st->attached_pic.flags |= AV_PKT_FLAG_KEY; } } else { st->codecpar->codec_type = AVMEDIA_TYPE_DATA; diff --git a/libavformat/utils.c b/libavformat/utils.c index 88f6f18f1f..2bd7dd8ec7 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -474,6 +474,36 @@ int avformat_queue_attached_pictures(AVFormatContext *s) return 0; } +int ff_add_attached_pic(AVFormatContext *s, AVStream *st, AVIOContext *pb, + AVBufferRef **buf, int size) +{ + AVPacket *pkt; + int ret; + + if (!st && !(st = avformat_new_stream(s, NULL))) + return AVERROR(ENOMEM); + pkt = &st->attached_pic; + if (buf) { + av_assert1(*buf); + av_packet_unref(pkt); + pkt->buf = *buf; + pkt->data = (*buf)->data; + pkt->size = (*buf)->size - AV_INPUT_BUFFER_PADDING_SIZE; + *buf = NULL; + } else { + ret = av_get_packet(pb, pkt, size); + if (ret < 0) + return ret; + } + st->disposition |= AV_DISPOSITION_ATTACHED_PIC; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + + pkt->stream_index = st->index; + pkt->flags |= AV_PKT_FLAG_KEY; + + return 0; +} + static int update_stream_avctx(AVFormatContext *s) { int i, ret; diff --git a/libavformat/wtvdec.c b/libavformat/wtvdec.c index 7def9d2348..e67e03a033 100644 --- a/libavformat/wtvdec.c +++ b/libavformat/wtvdec.c @@ -434,7 +434,6 @@ static void get_attachment(AVFormatContext *s, AVIOContext *pb, int length) char description[1024]; unsigned int filesize; AVStream *st; - int ret; int64_t pos = avio_tell(pb); avio_get_str16le(pb, INT_MAX, mime, sizeof(mime)); @@ -447,19 +446,12 @@ static void get_attachment(AVFormatContext *s, AVIOContext *pb, int length) if (!filesize) goto done; - st = avformat_new_stream(s, NULL); - if (!st) + if (ff_add_attached_pic(s, NULL, pb, NULL, filesize) < 0) goto done; + st = s->streams[s->nb_streams - 1]; av_dict_set(&st->metadata, "title", description, 0); - st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = AV_CODEC_ID_MJPEG; st->id = -1; - ret = av_get_packet(pb, &st->attached_pic, filesize); - if (ret < 0) - goto done; - st->attached_pic.stream_index = st->index; - st->attached_pic.flags |= AV_PKT_FLAG_KEY; - st->disposition |= AV_DISPOSITION_ATTACHED_PIC; done: avio_seek(pb, pos + length, SEEK_SET); } From patchwork Mon Mar 29 08:42:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26635 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 17FF144AD8A for ; Mon, 29 Mar 2021 11:43:00 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E42A3680856; Mon, 29 Mar 2021 11:42:59 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-oln040092070051.outbound.protection.outlook.com [40.92.70.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 471C86806EB for ; Mon, 29 Mar 2021 11:42:48 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i3goCmZKs6zyZzXpvY1DeLXPl0zXttm/denC95e3qLrBolX7AadYZTOCd5kXw4LwDjc0AN4Mz4GuwtqIc6XjMZiLxWU5dbiT+YU99xGwAPRzmIlYZnQLedxGSiLQi4H0t78F4oS36t13y5FegadX1La4gzxU5r4HmOuYlci6NKoRqHIQzcKqC6CFXyaf3cxtsccXxnV5YXK8HTsUI7A/cJBZHmre2cCg1vn0M9kPX0B7uPhwS/g718oXKgg5MH2A+LIGqQCLfnDeh9nmFKoRM+pawLqyUr8nyw6lE8gb+JKcenPDZDJyYIaBIMdZGQfgqqcxc+wHhfPy8hiYr8nLCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qmwE7dIvyF542RWhKJXGbRQxXpbb5B3TlFcvBSYAVtM=; b=co5zX/JSiS0y7DYaxYeb5eKpNtUzNQJ+YBu5UARWJbVrhGK7maRTfo3hVllCuJJs3L8BM8hpmDnX3F2epDy+RwHGWr2kVxedCY2n+/3I2yB4+THxVM+1keEpkkhHpyx+XEdXA3pyic7+0zFC4JnDhcLtseYXOxa+VHfQ+gDJaoEm0cKAS4KucL0fTGY6XN3EKpbV8nkUNsyho7Rcr37Z8b+/4ORYcyPuHWJhkjk82kF02YVNrThtHiQFblX3QLzAgon5TExxJ7n8Lzm25xbT9F9U0iruPtxGQWwWURLOtg6Kj4h+uscXIRQ7KC+RjvL0rp+4134Y8DHQo/UtR33GUw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qmwE7dIvyF542RWhKJXGbRQxXpbb5B3TlFcvBSYAVtM=; b=gCv3adL/WPph89QaGk3DTLPQp/A+00Q3Fmob4KHDjcrUIuYVXgEBGt17qFtgGs5qpP+IIJkDZRAw3cWLTf2eZU6WOwyK3WTV9ulEbz/ZHAlugeJTZIqyI08psT5TBGUzRzyHS0KjAzI01EUGYMe/AvKzQORVpVcNUUEjNKPFRZ5VLMKgdOtMFcoPnrC+MwOKGYWUbN+Ile66gx+8y7drhkJDDPKqTn98k72YSI8bjeLWf1yLKo625xwxG09BwFyWfvHkyfkR1LdyTYAG3lHh4HzPLrkRtoT89Tbog/l7TXHYdiRYPtnSxDG1HaEZwlDWnqmEd6F3u+qRdftq8AnSUQ== Received: from VE1EUR03FT009.eop-EUR03.prod.protection.outlook.com (2a01:111:e400:7e09::46) by VE1EUR03HT037.eop-EUR03.prod.protection.outlook.com (2a01:111:e400:7e09::358) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.29; Mon, 29 Mar 2021 08:42:39 +0000 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com (2a01:111:e400:7e09::49) by VE1EUR03FT009.mail.protection.outlook.com (2a01:111:e400:7e09::92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25 via Frontend Transport; Mon, 29 Mar 2021 08:42:39 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:71503DF93C0201D4AC21B2554FD0C051AB1E761FE4D0453F5934EEE51BA97A58; UpperCasedChecksum:F62F4F9E8ED1BB785AAF57A24A30A357E4E7174A47AC6DDA7769504EDC2DB662; SizeAsReceived:7522; Count:48 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::8128:5de5:4e94:9a21]) by HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::8128:5de5:4e94:9a21%3]) with mapi id 15.20.3977.033; Mon, 29 Mar 2021 08:42:39 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 29 Mar 2021 10:42:01 +0200 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210329084203.402250-1-andreas.rheinhardt@outlook.com> References: <20210329084203.402250-1-andreas.rheinhardt@outlook.com> X-TMN: [W2FZEVbZ5XTWyfgg0OWoPC2mjjB46846] X-ClientProxiedBy: AM4PR0302CA0023.eurprd03.prod.outlook.com (2603:10a6:205:2::36) To HE1PR0301MB2154.eurprd03.prod.outlook.com (2603:10a6:3:2a::22) X-Microsoft-Original-Message-ID: <20210329084203.402250-2-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.137.96) by AM4PR0302CA0023.eurprd03.prod.outlook.com (2603:10a6:205:2::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25 via Frontend Transport; Mon, 29 Mar 2021 08:42:38 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 48 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: a95df66c-8854-4c39-f0f7-08d8f28e9c24 X-MS-Exchange-SLBlob-MailProps: 7MJMDUNTCtyG7JLNmMoDcXgSrFf0WyM4OOjnFjhQ/BhBRH0qHdws4cmTlO7z0pbNA9Q8ZSZZtF+ZExvoqXjko7UL/bBJET/J9lO8X5N415F3W5d688V6sGdgG9X1JCDkURDO0DECzawypxlrIckT543sMqpIf9FPykvo+Avv21VfB4Xp73tSCU5pdr7i4TGToiM+mL8cclila6RrY/jonRwar06tCdPBLB2OtzAOC8BcVhZZLLvPRU9gDOyuXV0fmCoMMY5ZQr/SMZuttuv7WV6RjYGIF2foqdhzt1epjKpi1H5CBKuq3rfHxqdj6YB82y0kOWHrYFP8dATYt4KACtzOsXVXEIzRmZv3/gWNRrd1ArTTkWKmQF3pIpwFTwHj+BRISrIC7BH5/75Iv+SF5O+xUezYYgiynd2/0vhmoGnMoWb4rbFyn8qOV2mXk91sWLH8QcodsAfqqA/VEG9ZqXbas/Oi5wzloABNZTSCHNecaa7wg6f0BuXV5Kz0iupguWBc4VoWPgh7mNzel+e5zaUpeutoWtxRz+1gYYzsHrjhT3WHLuDRV+YBgeLhBlyu/9RskFt2YIyR5o0E36cPOuqBZaamgy/3e8Tupr3fRrpZUPfxgiSu+zP79iJqJDDXE0Ia4TUKCsuZR1q0S5kxltVMqoorwpaTWTgwohjkL+G2Dekv0lPGuvCnMqsfCS8EGNIqebBk6vteyzDh9EXToXRVfEzG7He+G8djAyv1KWxZ7A10KWsF+A== X-MS-TrafficTypeDiagnostic: VE1EUR03HT037: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: anXHLhd6qMy2CtLLHVS3YeP6aicb/+XhNKts3j4SREFe8mzxH7JTjvZADuTi6bi+aZn38mKjIiUzEihvlU5z4iwIKPnSGM8DjVFuiSBG7nAKETjIM15bgfxw9t4gUlOWrkMFvT2Vfi5XDNycYS7okmAAkl9S/UVxfI72L4IBHlIy/JgWU7J568VnAbM9WfRGTWSKKGCA8MjSu/zG+q6niiExb6Kg9TrGpsXngppLZhk9kRb5pbLGZdp2JxfyVDCiNAeLnV/uXxYtnc983ZV9mecDi1V0pyPsPz83hXY6Sf/DIoxyOfmfB2xR/imHpo2N8hM29SXcIv9QkEpx8m1nrNsQj5MNm88exaIYrXSzTdZUePH4U+Bc4io0h8AVCZEvdpILePCmVhDFh1HJxnuRDw== X-MS-Exchange-AntiSpam-MessageData: T7lZ+KWS++CiFpBxF1dM7z1PgoLYqQXEZvpxNW7+5CDGMU/vc1D6sT6QBvCKArSJ8A9kR2y+WgJcbWilDR9u/nVSLXeeqIuHWr0y8P8EYVFUuGHLkP+DDwQWCt1ScChjrLfHsMWfR2uW/yk9lAdVOA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: a95df66c-8854-4c39-f0f7-08d8f28e9c24 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2021 08:42:39.4438 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: VE1EUR03FT009.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1EUR03HT037 Subject: [FFmpeg-devel] [PATCH 2/4] avformat/asf: Factor common code out 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" Both function to read attached pictures coincide since e83f27a21a6d2f602b55e541ef66e365400e9827 (save for some log messages in case av_dict_set failed). Signed-off-by: Andreas Rheinhardt --- How nice it would be if there were consensus on which of the demuxers is better! libavformat/asf.c | 117 +++++++++++++++++++++++++++++++++++++++++ libavformat/asf.h | 10 ++++ libavformat/asfdec_f.c | 109 +------------------------------------- libavformat/asfdec_o.c | 114 +-------------------------------------- 4 files changed, 129 insertions(+), 221 deletions(-) diff --git a/libavformat/asf.c b/libavformat/asf.c index f1f171e6f6..204355abab 100644 --- a/libavformat/asf.c +++ b/libavformat/asf.c @@ -19,6 +19,7 @@ */ #include "asf.h" +#include "id3v2.h" const ff_asf_guid ff_asf_header = { 0x30, 0x26, 0xB2, 0x75, 0x8E, 0x66, 0xCF, 0x11, 0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C @@ -170,3 +171,119 @@ const AVMetadataConv ff_asf_metadata_conv[] = { // { "Year" , "date" }, TODO: conversion year<->date { 0 } }; + +/* MSDN claims that this should be "compatible with the ID3 frame, APIC", + * but in reality this is only loosely similar */ +static int asf_read_picture(AVFormatContext *s, int len) +{ + AVPacket pkt = { 0 }; + const CodecMime *mime = ff_id3v2_mime_tags; + enum AVCodecID id = AV_CODEC_ID_NONE; + char mimetype[64]; + uint8_t *desc = NULL; + AVStream *st = NULL; + int ret, type, picsize, desc_len; + + /* type + picsize + mime + desc */ + if (len < 1 + 4 + 2 + 2) { + av_log(s, AV_LOG_ERROR, "Invalid attached picture size: %d.\n", len); + return AVERROR_INVALIDDATA; + } + + /* picture type */ + type = avio_r8(s->pb); + len--; + if (type >= FF_ARRAY_ELEMS(ff_id3v2_picture_types) || type < 0) { + av_log(s, AV_LOG_WARNING, "Unknown attached picture type: %d.\n", type); + type = 0; + } + + /* picture data size */ + picsize = avio_rl32(s->pb); + len -= 4; + + /* picture MIME type */ + len -= avio_get_str16le(s->pb, len, mimetype, sizeof(mimetype)); + while (mime->id != AV_CODEC_ID_NONE) { + if (!strncmp(mime->str, mimetype, sizeof(mimetype))) { + id = mime->id; + break; + } + mime++; + } + if (id == AV_CODEC_ID_NONE) { + av_log(s, AV_LOG_ERROR, "Unknown attached picture mimetype: %s.\n", + mimetype); + return 0; + } + + if (picsize >= len) { + av_log(s, AV_LOG_ERROR, "Invalid attached picture data size: %d >= %d.\n", + picsize, len); + return AVERROR_INVALIDDATA; + } + + /* picture description */ + desc_len = (len - picsize) * 2 + 1; + desc = av_malloc(desc_len); + if (!desc) + return AVERROR(ENOMEM); + len -= avio_get_str16le(s->pb, len - picsize, desc, desc_len); + + ret = av_get_packet(s->pb, &pkt, picsize); + if (ret < 0) + goto fail; + + st = avformat_new_stream(s, NULL); + if (!st) { + ret = AVERROR(ENOMEM); + goto fail; + } + + st->disposition |= AV_DISPOSITION_ATTACHED_PIC; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = id; + st->attached_pic = pkt; + st->attached_pic.stream_index = st->index; + st->attached_pic.flags |= AV_PKT_FLAG_KEY; + + if (*desc) { + if (av_dict_set(&st->metadata, "title", desc, AV_DICT_DONT_STRDUP_VAL) < 0) + av_log(s, AV_LOG_WARNING, "av_dict_set failed.\n"); + } else + av_freep(&desc); + + if (av_dict_set(&st->metadata, "comment", ff_id3v2_picture_types[type], 0) < 0) + av_log(s, AV_LOG_WARNING, "av_dict_set failed.\n"); + + return 0; + +fail: + av_freep(&desc); + av_packet_unref(&pkt); + return ret; +} + +static int get_id3_tag(AVFormatContext *s, int len) +{ + ID3v2ExtraMeta *id3v2_extra_meta = NULL; + + ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta, len); + if (id3v2_extra_meta) { + ff_id3v2_parse_apic(s, id3v2_extra_meta); + ff_id3v2_parse_chapters(s, id3v2_extra_meta); + ff_id3v2_free_extra_meta(&id3v2_extra_meta); + } + return 0; +} + +int ff_asf_handle_byte_array(AVFormatContext *s, const char *name, + int val_len) +{ + if (!strcmp(name, "WM/Picture")) // handle cover art + return asf_read_picture(s, val_len); + else if (!strcmp(name, "ID3")) // handle ID3 tag + return get_id3_tag(s, val_len); + + return 1; +} diff --git a/libavformat/asf.h b/libavformat/asf.h index bce820efae..01cc4f7a46 100644 --- a/libavformat/asf.h +++ b/libavformat/asf.h @@ -104,6 +104,16 @@ extern const ff_asf_guid ff_asf_mutex_language; extern const AVMetadataConv ff_asf_metadata_conv[]; +/** + * Handles both attached pictures as well as id3 tags. + * + * @return Returns < 0 on error, 1 if the type of the byte array + * is unsupported by this function and 0 otherwise. + */ +int ff_asf_handle_byte_array(AVFormatContext *s, const char *name, + int val_len); + + #define ASF_PACKET_FLAG_ERROR_CORRECTION_PRESENT 0x80 //1000 0000 diff --git a/libavformat/asfdec_f.c b/libavformat/asfdec_f.c index 2fae528f4d..27162e9559 100644 --- a/libavformat/asfdec_f.c +++ b/libavformat/asfdec_f.c @@ -33,7 +33,6 @@ #include "avformat.h" #include "avio_internal.h" #include "avlanguage.h" -#include "id3v2.h" #include "internal.h" #include "riff.h" #include "asf.h" @@ -219,107 +218,6 @@ static int get_value(AVIOContext *pb, int type, int type2_size) } } -/* MSDN claims that this should be "compatible with the ID3 frame, APIC", - * but in reality this is only loosely similar */ -static int asf_read_picture(AVFormatContext *s, int len) -{ - AVPacket pkt = { 0 }; - const CodecMime *mime = ff_id3v2_mime_tags; - enum AVCodecID id = AV_CODEC_ID_NONE; - char mimetype[64]; - uint8_t *desc = NULL; - AVStream *st = NULL; - int ret, type, picsize, desc_len; - - /* type + picsize + mime + desc */ - if (len < 1 + 4 + 2 + 2) { - av_log(s, AV_LOG_ERROR, "Invalid attached picture size: %d.\n", len); - return AVERROR_INVALIDDATA; - } - - /* picture type */ - type = avio_r8(s->pb); - len--; - if (type >= FF_ARRAY_ELEMS(ff_id3v2_picture_types) || type < 0) { - av_log(s, AV_LOG_WARNING, "Unknown attached picture type: %d.\n", type); - type = 0; - } - - /* picture data size */ - picsize = avio_rl32(s->pb); - len -= 4; - - /* picture MIME type */ - len -= avio_get_str16le(s->pb, len, mimetype, sizeof(mimetype)); - while (mime->id != AV_CODEC_ID_NONE) { - if (!strncmp(mime->str, mimetype, sizeof(mimetype))) { - id = mime->id; - break; - } - mime++; - } - if (id == AV_CODEC_ID_NONE) { - av_log(s, AV_LOG_ERROR, "Unknown attached picture mimetype: %s.\n", - mimetype); - return 0; - } - - if (picsize >= len) { - av_log(s, AV_LOG_ERROR, "Invalid attached picture data size: %d >= %d.\n", - picsize, len); - return AVERROR_INVALIDDATA; - } - - /* picture description */ - desc_len = (len - picsize) * 2 + 1; - desc = av_malloc(desc_len); - if (!desc) - return AVERROR(ENOMEM); - len -= avio_get_str16le(s->pb, len - picsize, desc, desc_len); - - ret = av_get_packet(s->pb, &pkt, picsize); - if (ret < 0) - goto fail; - - st = avformat_new_stream(s, NULL); - if (!st) { - ret = AVERROR(ENOMEM); - goto fail; - } - st->disposition |= AV_DISPOSITION_ATTACHED_PIC; - st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; - st->codecpar->codec_id = id; - st->attached_pic = pkt; - st->attached_pic.stream_index = st->index; - st->attached_pic.flags |= AV_PKT_FLAG_KEY; - - if (*desc) - av_dict_set(&st->metadata, "title", desc, AV_DICT_DONT_STRDUP_VAL); - else - av_freep(&desc); - - av_dict_set(&st->metadata, "comment", ff_id3v2_picture_types[type], 0); - - return 0; - -fail: - av_freep(&desc); - av_packet_unref(&pkt); - return ret; -} - -static void get_id3_tag(AVFormatContext *s, int len) -{ - ID3v2ExtraMeta *id3v2_extra_meta = NULL; - - ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta, len); - if (id3v2_extra_meta) { - ff_id3v2_parse_apic(s, id3v2_extra_meta); - ff_id3v2_parse_chapters(s, id3v2_extra_meta); - } - ff_id3v2_free_extra_meta(&id3v2_extra_meta); -} - static void get_tag(AVFormatContext *s, const char *key, int type, int len, int type2_size) { ASFContext *asf = s->priv_data; @@ -345,13 +243,8 @@ static void get_tag(AVFormatContext *s, const char *key, int type, int len, int value[len]=0; break; case ASF_BYTE_ARRAY: - if (!strcmp(key, "WM/Picture")) { // handle cover art - asf_read_picture(s, len); - } else if (!strcmp(key, "ID3")) { // handle ID3 tag - get_id3_tag(s, len); - } else { + if (ff_asf_handle_byte_array(s, key, len) > 0) av_log(s, AV_LOG_VERBOSE, "Unsupported byte array in tag %s.\n", key); - } goto finish; case ASF_BOOL: case ASF_DWORD: diff --git a/libavformat/asfdec_o.c b/libavformat/asfdec_o.c index 34ae541934..6cfcd8b088 100644 --- a/libavformat/asfdec_o.c +++ b/libavformat/asfdec_o.c @@ -20,19 +20,15 @@ */ #include "libavutil/attributes.h" -#include "libavutil/avstring.h" -#include "libavutil/bswap.h" #include "libavutil/common.h" #include "libavutil/dict.h" #include "libavutil/internal.h" #include "libavutil/mathematics.h" -#include "libavutil/opt.h" #include "libavutil/time_internal.h" #include "avformat.h" #include "avio_internal.h" #include "avlanguage.h" -#include "id3v2.h" #include "internal.h" #include "riff.h" #include "asf.h" @@ -356,110 +352,6 @@ static int asf_set_metadata(AVFormatContext *s, const uint8_t *name, return 0; } -/* MSDN claims that this should be "compatible with the ID3 frame, APIC", - * but in reality this is only loosely similar */ -static int asf_read_picture(AVFormatContext *s, int len) -{ - AVPacket pkt = { 0 }; - const CodecMime *mime = ff_id3v2_mime_tags; - enum AVCodecID id = AV_CODEC_ID_NONE; - char mimetype[64]; - uint8_t *desc = NULL; - AVStream *st = NULL; - int ret, type, picsize, desc_len; - - /* type + picsize + mime + desc */ - if (len < 1 + 4 + 2 + 2) { - av_log(s, AV_LOG_ERROR, "Invalid attached picture size: %d.\n", len); - return AVERROR_INVALIDDATA; - } - - /* picture type */ - type = avio_r8(s->pb); - len--; - if (type >= FF_ARRAY_ELEMS(ff_id3v2_picture_types) || type < 0) { - av_log(s, AV_LOG_WARNING, "Unknown attached picture type: %d.\n", type); - type = 0; - } - - /* picture data size */ - picsize = avio_rl32(s->pb); - len -= 4; - - /* picture MIME type */ - len -= avio_get_str16le(s->pb, len, mimetype, sizeof(mimetype)); - while (mime->id != AV_CODEC_ID_NONE) { - if (!strncmp(mime->str, mimetype, sizeof(mimetype))) { - id = mime->id; - break; - } - mime++; - } - if (id == AV_CODEC_ID_NONE) { - av_log(s, AV_LOG_ERROR, "Unknown attached picture mimetype: %s.\n", - mimetype); - return 0; - } - - if (picsize >= len) { - av_log(s, AV_LOG_ERROR, "Invalid attached picture data size: %d >= %d.\n", - picsize, len); - return AVERROR_INVALIDDATA; - } - - /* picture description */ - desc_len = (len - picsize) * 2 + 1; - desc = av_malloc(desc_len); - if (!desc) - return AVERROR(ENOMEM); - len -= avio_get_str16le(s->pb, len - picsize, desc, desc_len); - - ret = av_get_packet(s->pb, &pkt, picsize); - if (ret < 0) - goto fail; - - st = avformat_new_stream(s, NULL); - if (!st) { - ret = AVERROR(ENOMEM); - goto fail; - } - - st->disposition |= AV_DISPOSITION_ATTACHED_PIC; - st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; - st->codecpar->codec_id = id; - st->attached_pic = pkt; - st->attached_pic.stream_index = st->index; - st->attached_pic.flags |= AV_PKT_FLAG_KEY; - - if (*desc) { - if (av_dict_set(&st->metadata, "title", desc, AV_DICT_DONT_STRDUP_VAL) < 0) - av_log(s, AV_LOG_WARNING, "av_dict_set failed.\n"); - } else - av_freep(&desc); - - if (av_dict_set(&st->metadata, "comment", ff_id3v2_picture_types[type], 0) < 0) - av_log(s, AV_LOG_WARNING, "av_dict_set failed.\n"); - - return 0; - -fail: - av_freep(&desc); - av_packet_unref(&pkt); - return ret; -} - -static void get_id3_tag(AVFormatContext *s, int len) -{ - ID3v2ExtraMeta *id3v2_extra_meta = NULL; - - ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta, len); - if (id3v2_extra_meta) { - ff_id3v2_parse_apic(s, id3v2_extra_meta); - ff_id3v2_parse_chapters(s, id3v2_extra_meta); - } - ff_id3v2_free_extra_meta(&id3v2_extra_meta); -} - static int process_metadata(AVFormatContext *s, const uint8_t *name, uint16_t name_len, uint16_t val_len, uint16_t type, AVDictionary **met) { @@ -472,11 +364,7 @@ static int process_metadata(AVFormatContext *s, const uint8_t *name, uint16_t na asf_read_value(s, name, val_len, type, met); break; case ASF_BYTE_ARRAY: - if (!strcmp(name, "WM/Picture")) // handle cover art - asf_read_picture(s, val_len); - else if (!strcmp(name, "ID3")) // handle ID3 tag - get_id3_tag(s, val_len); - else + if (ff_asf_handle_byte_array(s, name, val_len) > 0) asf_read_value(s, name, val_len, type, met); break; case ASF_GUID: From patchwork Mon Mar 29 08:42:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26634 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 2B34844AD8A for ; Mon, 29 Mar 2021 11:42:45 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 187ED687ED3; Mon, 29 Mar 2021 11:42:45 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-oln040092072019.outbound.protection.outlook.com [40.92.72.19]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 14640680856 for ; Mon, 29 Mar 2021 11:42:41 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lawAvUXQWXp4uKqhNa1Cv+/9DT5O8UMwl7mzhXxwiNCruh+osQwNbXou3KoNtOGskrg9lTq6te9B2fbOScz+ZgSPFN3CeXFuSVUeGMyXp8ACSEHenKPa0zdfWNHp7Ir8A4oWbeSVx5mjNJbR7Ih9dLnC0CKn6kQusmaF3RzXmzbnD328OYDdK3jyz4TnHlOnqgWZw1fzF2ym9wXbil5tlPIgEVo1lGU2IDEVW435IRR9ls6FUeWBh6mryBufDqlJ7gsT2Ycj7p9ja9cY05XJ3RHkJWrO2krM+L4wsYoNG48bm/wX0Z8UaMJN1YFM/ZDklBFuGRI2gpiSq/dXzx0vqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Q0cbs/5Ds7xnhhsOYTmXGCQDgjdAKr7l65zkMcuLwXs=; b=P3iWsWR4YN5yHFdn0BJgpXQklS3QkILK5AfpDfLNcPcPwMw+lJ7EBiguSAm3AwaA5Z4l/Roc0VU2GQe32QAIxExQzwcvphUZhC6ixv5EGti76ZDMT5vld8hW7yhfiOzNgdqdP6L/kB4jX7X5b7zwqiLFeHZgU6eFQ5jqoSBSPuhGydo2lJp573XKYCFowjTvWG8nxnia1A+HdTHZ5OrNDGwB3TWSoz4pO5VbA27rw9EzUUqo3Qwv+6lMm+2/NdcrHXNjsVeZClwuZpPIvHlaPtiPwBq/Y+LCaIZ+XVowIOuHa86ZCrh+1kOfjTPqn4V7FXeoJr4NmV6k9/+t9WFV4A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Q0cbs/5Ds7xnhhsOYTmXGCQDgjdAKr7l65zkMcuLwXs=; b=gHs0K9arGTMcAmxLEcK2/cRhb3qYQ3lwrKI8Qo64kQUv/42vZvS3i2ZVqMxNeAHhX4HPYdbxgDSs3jEcsWn96RTAd0oUrMAPPdaeIefqedJ5yRpZoR+o6LmbatJzcga0JB6IwN0dwm8rPECI06ldD1Qv0coxyqkarW6YWqlfMdTYkMRDfbma3KDA8YHc87Z//n7Qmx3AaNNo+zj5U92r6HVX9kvtLEag0Ew9jt7M8SAiHiLey7q3PMUccuZpSVWEn0JN6BjXXBb/aBwLG65w56D4rAoyn8X+L79jCFeZmvEAMm3PduQb/UgBJ5Q8IMh3Jg8V7Q2GOSGdtt5X3jfPww== Received: from VE1EUR03FT009.eop-EUR03.prod.protection.outlook.com (2a01:111:e400:7e09::4d) by VE1EUR03HT210.eop-EUR03.prod.protection.outlook.com (2a01:111:e400:7e09::501) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.29; Mon, 29 Mar 2021 08:42:40 +0000 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com (2a01:111:e400:7e09::49) by VE1EUR03FT009.mail.protection.outlook.com (2a01:111:e400:7e09::92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25 via Frontend Transport; Mon, 29 Mar 2021 08:42:40 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:B2BE1164976668DF08F18CBAFCB715F638DF3E182F5C6431084C51C4FBE399AA; UpperCasedChecksum:D0BB135E486C72B406CC0A7F80D48691847F6CF19ECC552CAF8728A90E7570FE; SizeAsReceived:7550; Count:48 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::8128:5de5:4e94:9a21]) by HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::8128:5de5:4e94:9a21%3]) with mapi id 15.20.3977.033; Mon, 29 Mar 2021 08:42:40 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 29 Mar 2021 10:42:02 +0200 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210329084203.402250-1-andreas.rheinhardt@outlook.com> References: <20210329084203.402250-1-andreas.rheinhardt@outlook.com> X-TMN: [DGjMc1gFpy0gnN2QAZw4cv0CONtcwwZf] X-ClientProxiedBy: AM4PR0302CA0023.eurprd03.prod.outlook.com (2603:10a6:205:2::36) To HE1PR0301MB2154.eurprd03.prod.outlook.com (2603:10a6:3:2a::22) X-Microsoft-Original-Message-ID: <20210329084203.402250-3-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.137.96) by AM4PR0302CA0023.eurprd03.prod.outlook.com (2603:10a6:205:2::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25 via Frontend Transport; Mon, 29 Mar 2021 08:42:39 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 48 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 7517c3c1-0bc8-4981-4021-08d8f28e9c7d X-MS-Exchange-SLBlob-MailProps: mBRmoEB1kyJI6Ri+2w4enS83RnwDVX5nnwKtGTcU8PYCTbNoJ0hpflOqHrF12JaJ9EV5bclrHVEgi/ZLH20HETIM1hSPktjlSmSApwF4wA81Q4eoBsMP/W0caLrqg77+UqqNF7nt0hG2ei4lHFC697lKCCu22c/uRpfKUUdFZLkVvXXMJsrKxWBXrbQCgttgCppDGqga+UYFjOUIx4dFDCMjmtdCT20FVeu9wQZOkfV0Xaueyn+mLfyvrfeFIJC3DeeteIWh3DFVVlhy+RxcXlFl9RxD4JfrzHc4fNcGQ+lsVwnifkJ6qJo8MQnj5IJ7Dz3kyfnnMoT92sdzRekFflGBZcq9pSfyniVXnyIFoDElVaRDXZGP6eu+pVB64X6ICcJP4POGQOXsk2chnm/VgjMRiuWGZwTIuwfFgE53wp0jXvum4nxbcXVxOoswrAJj11wBBSZ6fonponZy0G31TwIcvOjxDt1UALUyCuu1QPpSCQDCrIkt6VzA9ae/m2sWZvVgLJwIK1se91JtICgVo8GVz27f1KpGx+NIWMEbuQn21XPbtwsS0+8MZK+/2T2wPt5WAAJoOYqe4VG9hXx+Or7ZSyv/mmER/BMCcuR1Uoh7YRAIf10ZKa3T1q1ucshvpfHzysQHWEUIjnJwMF2fwbbuNa0PRER5wFfVDnf7QZUXMkZvvJGMMPIlC5oP9i3jUDGPmGd6FeQNlUzHDWxIilPOzSdHWdGRWH7GIA72BnjRFeE/4kfOirNkpM0uphxxVPpmf8z2/pE= X-MS-TrafficTypeDiagnostic: VE1EUR03HT210: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: on2jBA2UyOgJoq0blHOjlN9iZe7zbE7/QfDWeX9w9pDPC/S4VjlPhXLVhVptCpBM7bIC40QpXtzkbR4AzaqPdbjII1IX3NaH6ZMiyn2AoTfJcmMH1iOCWi4QhMPGmhZ3mlQ8E4ad47SpGZB1veCztAWQGo2DBrkuTDU2FEhR/SmN7Hs0VBkJewCUaIc3YBMdUglOxle/dinmgWcTB7dwJQOxuFGZUs1I/7dOsZrT1ef0npXl0UpZx0uMgiQexSLP5h69dds8fYpH/LLMQkB6+LG6T+NuFIuS3cOkgt7pBp5ciZI4bhcIQDwzX/QhdVPsIUHHW3UlInuEDuAVzezPwYiucPG5iXz4xw45X4SZ/wkSYJfx8Gz7a5E/6LVVa/YJvSfo3G3c3u/VbMQdyFbkzg== X-MS-Exchange-AntiSpam-MessageData: DEFyjRRUu7j7u/lNsH53tnWvELUdD28qVdojy6JM7CC+oFimwGVVgX7/prk7U5Jd9kKAgxvBjY8FkBuVnh/oL6hZ7Woi5lHUHm7Is36wucejKvfAnU7b+ndyZFndJZvDqQHE5lJF/o5ktnZwCQjIWg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7517c3c1-0bc8-4981-4021-08d8f28e9c7d X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2021 08:42:40.0805 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: VE1EUR03FT009.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1EUR03HT210 Subject: [FFmpeg-devel] [PATCH 3/4] avformat/utils: Free new streams in ff_add_attached_pic on error 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 --- mov chapter tracks are not compatible with this. libavformat/internal.h | 3 +++ libavformat/utils.c | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/libavformat/internal.h b/libavformat/internal.h index b3c5d8a1d5..a6987619f7 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -678,6 +678,9 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt); * @param buf if set, it contains the data and size information to be used * for the attached pic; if unset, data is read from pb. * @param size the size of the data to read if buf is unset. + * + * @return 0 on success, < 0 on error. On error, this function removes + * the stream it has added (if any). */ int ff_add_attached_pic(AVFormatContext *s, AVStream *st, AVIOContext *pb, AVBufferRef **buf, int size); diff --git a/libavformat/utils.c b/libavformat/utils.c index 2bd7dd8ec7..67302907b8 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -474,9 +474,10 @@ int avformat_queue_attached_pictures(AVFormatContext *s) return 0; } -int ff_add_attached_pic(AVFormatContext *s, AVStream *st, AVIOContext *pb, +int ff_add_attached_pic(AVFormatContext *s, AVStream *st0, AVIOContext *pb, AVBufferRef **buf, int size) { + AVStream *st = st0; AVPacket *pkt; int ret; @@ -493,7 +494,7 @@ int ff_add_attached_pic(AVFormatContext *s, AVStream *st, AVIOContext *pb, } else { ret = av_get_packet(pb, pkt, size); if (ret < 0) - return ret; + goto fail; } st->disposition |= AV_DISPOSITION_ATTACHED_PIC; st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; @@ -502,6 +503,10 @@ int ff_add_attached_pic(AVFormatContext *s, AVStream *st, AVIOContext *pb, pkt->flags |= AV_PKT_FLAG_KEY; return 0; +fail: + if (!st0) + ff_free_stream(s, st); + return ret; } static int update_stream_avctx(AVFormatContext *s) From patchwork Mon Mar 29 08:45:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26637 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 ADC1E448EB7 for ; Mon, 29 Mar 2021 11:46:01 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 808CE688179; Mon, 29 Mar 2021 11:46:01 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-oln040092072088.outbound.protection.outlook.com [40.92.72.88]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8F32C680C76 for ; Mon, 29 Mar 2021 11:45:54 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SkK1YvpE83mETp9QBR37DC5una0i3mDSENcirQPh9iyUFpAhSltcXQ8tjf6SLKrJG3SO5W7uCIQZBRdFCqWsC7LCVtFU+WlEfc1Ipg8V82l4s6yofTE07AN1EhCoA6znxTrpIKTM2KzRNK8eL46M9e3XTU5ZlhZuHqjJG5uOvDeZboc6xeaGC60GmBoPsaU1INtZZ+NTmoilTplN323lilDFADHlgc1NxFru89AVB+/kpkQpN3KPeXIsq3k0ZJDrRj6CyjywkTgg9Hh0O/O95su1V9rkEr55aKj/GZ7im/iPXFPByjzTv9OegyH8MFZk9o1mpptQ8X/QDvC3NDDkOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HsTv1+436AeazzcEGxCfCf94HAqYU4TL/5lqiYkeW2E=; b=jI3NQ0eF29YPJOFR5LXuSBzgA9n/oN+C9ejC6qz1TnnYlciamx+dRIzX1NGx8sDR8+pxFGaxP2sfBwqK6+Ey11HwslcAa7uR/SwDEMnkrQ23tEitZeCG7GEoF4+PyCecHCmXzHMMO2BJ+JfFe+R/wjuddSiG/RPQLnzbU5IiP6eUcTsg8YbOu82d0LW50I3KpwifEVsGjyc9BY+hkG1vZ93lgXpzxzpkdfqTqmfp1rtWZN56wth3m//cnjlud/SVYPcWs0Yetll+Nz9neOSCG4SYAfWu4WWtZQNnGlc6TPWCC99fDXfHZsxSZAlH96sRMHQYgRbEA6+V0nmIQI221g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HsTv1+436AeazzcEGxCfCf94HAqYU4TL/5lqiYkeW2E=; b=YQJ+1avUM3s0gB1Eb5v8bAjUII8EnP1Q100IgaJXpkoNSsKsnGVd5ReRBUiqWcae+nuSUocl3elq0/yPv3pleozNX+xhAKgPwSOzOI6rwu8UY12HkO6BB3Iuss/tj2t3XC3F8CwfaUhCt46WgGw8OAKchX5sd348x3Koqg1sEW/6rfF3v9FJlpzWGtyDBDsGgN6jYgcJWdUqB+bLGEUWSXCeahfhufu2JdMHewPvcOMTurgRiw3wVEnh+BM9IIPGZRAP6+/KFw7llznG1S0sjK19C94MCcRneh3a/BUAnMeBbxO8JGwpQRvabWRR/awiQE977a+0xXcRnLARIZwHUg== Received: from VE1EUR03FT009.eop-EUR03.prod.protection.outlook.com (2a01:111:e400:7e09::47) by VE1EUR03HT014.eop-EUR03.prod.protection.outlook.com (2a01:111:e400:7e09::123) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.29; Mon, 29 Mar 2021 08:45:53 +0000 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com (2a01:111:e400:7e09::49) by VE1EUR03FT009.mail.protection.outlook.com (2a01:111:e400:7e09::92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.25 via Frontend Transport; Mon, 29 Mar 2021 08:45:53 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:5DB10946FD7DEB2991CFCA09B6DCF14305A9792E0E5002A3BF3660A5C0C206E8; UpperCasedChecksum:B29642EE5F4280DAE1D88CF4EB7F5814282306263D2C093A826D66617B46F637; SizeAsReceived:7607; Count:48 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::8128:5de5:4e94:9a21]) by HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::8128:5de5:4e94:9a21%3]) with mapi id 15.20.3977.033; Mon, 29 Mar 2021 08:45:53 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 29 Mar 2021 10:45:41 +0200 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-TMN: [7Xlz7fGrCvy+qK+gAP3en9WY1m0UktoR] X-ClientProxiedBy: AM0PR04CA0030.eurprd04.prod.outlook.com (2603:10a6:208:122::43) To HE1PR0301MB2154.eurprd03.prod.outlook.com (2603:10a6:3:2a::22) X-Microsoft-Original-Message-ID: <20210329084541.402405-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.137.96) by AM0PR04CA0030.eurprd04.prod.outlook.com (2603:10a6:208:122::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.26 via Frontend Transport; Mon, 29 Mar 2021 08:45:53 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 48 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 5f99f2b7-651e-43ef-1810-08d8f28f0fdf X-MS-Exchange-SLBlob-MailProps: NS9Gj58uCj1xck0MJhTzH1vF95/KKvym4k8OiDyX94s/MjDVrv1qu0q5iP0PUoj989A8uYPlk0CrsZYUZmCTke+NLpb1FCcLyTzExntms4Hf7Sf1k4xbJIKiKQxWf7aAx8nWZTOSxqKJGW+SMJ40XkR50/vWr0JIhW7uocjQfxD2FrIVnvZ/lTHjt2NRjp2CdU/ZtYhGy9QER6X8pYbEwkUPTkpj4hPLit3/Js7jhVCVU6ztkUxyhE2/CL1dDlDtWPAJV/2uD6XeUn5mcxgvVFI+mWgXjpJtTIXETkxilxTig1rj1sQ9LxvFnN8TemEasrUtZ80R3Vanbt3IBwZnu7aY/7gque0ZvPqLKO4NBMYWd8RSd97HXWFeWHJu0FGI8qlFjpx8BtpTQdBEmzDcVmGJxotM7P60dYDlN5KOvfVSnJRRQkYtC6vOYtlwlhallLqUvQGBg8hcTE2IwgOOn/dKnVWHfxJ9vi3rkXXRiGNvCY6CN7+js5VHj8vbrICslQuGn11d/L60+3s+YNS51t1L4DiVfuSWr+8IMZOJ89rCMw+xk+WO/jOPLuZKsPPLcs7xzZ9+9cBsP2SZVI/kYyQUIiSPXTM4BWq57Dn095XzpEdA5BaRHsZZEdvhxyrfkjV9ytEdVXjupl23nugPFR/ZFPT6wh8GYBvadiIFt6LAok22iDPGdMInTPQgkqd8GiWpazAueW7YqKyi5z3ltg== X-MS-TrafficTypeDiagnostic: VE1EUR03HT014: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bKscopWqwUV1C9EzJ0xOCKH4pmBDngRC0Fc7XKUbf10s1747oQIfpQeN0YWqHNnfu7KRuhvFcSkQMWDZNbYkWZm0WKuP4PjKIdNeIHNYIAc8lToaUkrxKdFQ6I8H9HwUJeudcaJCwvHqIAAxTAm7auQwPmQ/PtnW+dOIYN0K0bII8EUdiwm0VIPSV1a5xsIppT4xDD6mI2ToElFBRYVPIw5iIb6slxopeb6uIBraGUnVZIR2DkiVZix/VV/Ew9Ipx6XUiD6qWooLYGSKA4iMs9OnGpeeWTLFB3YrcT55ZO87FUYF33LLShXxeXHc4nAX88UZ5mdOAtK/I3hEakMUZ6zf8Z98PPpjMfydjfk52+xS+nmW4ZDE/PWjcFHRzHEmBWfyKFQX4odwpOvJd2I/cQ== X-MS-Exchange-AntiSpam-MessageData: KY/mlqoYYqU8V1IcIz12+O04DNGrJAc+n7Iw9TJ2QG6dBBf26k+IUToZxRAfJ/4aiSPmjM+0qA5lOWbSZb3eJhDGZ4T+eMR0AvtucnriaL7W2svGCLLsOboGE2004DEe4rGrPiFpEdUjgjj9U/qLBQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5f99f2b7-651e-43ef-1810-08d8f28f0fdf X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2021 08:45:53.6257 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: VE1EUR03FT009.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1EUR03HT014 Subject: [FFmpeg-devel] [PATCH 4/4] avformat/asf: Use ff_add_attached_pic() to read attached pics 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" Also removes a stack packet. Signed-off-by: Andreas Rheinhardt --- libavformat/asf.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/libavformat/asf.c b/libavformat/asf.c index 204355abab..cef0f9f646 100644 --- a/libavformat/asf.c +++ b/libavformat/asf.c @@ -20,6 +20,7 @@ #include "asf.h" #include "id3v2.h" +#include "internal.h" const ff_asf_guid ff_asf_header = { 0x30, 0x26, 0xB2, 0x75, 0x8E, 0x66, 0xCF, 0x11, 0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C @@ -176,7 +177,6 @@ const AVMetadataConv ff_asf_metadata_conv[] = { * but in reality this is only loosely similar */ static int asf_read_picture(AVFormatContext *s, int len) { - AVPacket pkt = { 0 }; const CodecMime *mime = ff_id3v2_mime_tags; enum AVCodecID id = AV_CODEC_ID_NONE; char mimetype[64]; @@ -230,22 +230,12 @@ static int asf_read_picture(AVFormatContext *s, int len) return AVERROR(ENOMEM); len -= avio_get_str16le(s->pb, len - picsize, desc, desc_len); - ret = av_get_packet(s->pb, &pkt, picsize); + ret = ff_add_attached_pic(s, NULL, s->pb, NULL, picsize); if (ret < 0) goto fail; + st = s->streams[s->nb_streams - 1]; - st = avformat_new_stream(s, NULL); - if (!st) { - ret = AVERROR(ENOMEM); - goto fail; - } - - st->disposition |= AV_DISPOSITION_ATTACHED_PIC; - st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = id; - st->attached_pic = pkt; - st->attached_pic.stream_index = st->index; - st->attached_pic.flags |= AV_PKT_FLAG_KEY; if (*desc) { if (av_dict_set(&st->metadata, "title", desc, AV_DICT_DONT_STRDUP_VAL) < 0) @@ -260,7 +250,6 @@ static int asf_read_picture(AVFormatContext *s, int len) fail: av_freep(&desc); - av_packet_unref(&pkt); return ret; }