From patchwork Thu Jan 5 18:06:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Soft Works X-Patchwork-Id: 2066 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp5467399vsb; Thu, 5 Jan 2017 10:06:40 -0800 (PST) X-Received: by 10.223.167.68 with SMTP id e4mr140615wrd.155.1483639600307; Thu, 05 Jan 2017 10:06:40 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y138si82706022wme.81.2017.01.05.10.06.39; Thu, 05 Jan 2017 10:06:40 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@hotmail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE dis=NONE) header.from=hotmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7318268A0EE; Thu, 5 Jan 2017 20:06:32 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from BAY004-OMC1S8.hotmail.com (bay004-omc1s8.hotmail.com [65.54.190.19]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 084AA68A0EE for ; Thu, 5 Jan 2017 20:06:25 +0200 (EET) Received: from NAM03-CO1-obe.outbound.protection.outlook.com ([65.54.190.60]) by BAY004-OMC1S8.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Thu, 5 Jan 2017 10:06:28 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=u2RoWvjzHier9jTiaazjTkabJsvyVPYzgc3Kj+jHd/8=; b=dkykmtagOUvzjNheQMaw0tYt/yEGM9si80dd3aHP44WdsXQVEEs+4LnEwBFQvYIM7ikHsnr2KLBTEtKR8m2cvdBk+rdugXK9AJ07dqtClh0BW02RBLsgz1g6Moxpa1nHKg4kp7aKdQ0rngBgRyZ2nrvSmVXmbY4xUgTVCatQ20/sh0Jk+iiRW0JhIBlhoZUaF4V94K/ZleP0IEq+PuCXorZ8NRKfXXkYVPdS+kTlRFlJFv3HZeVXBeuyID9b08P8Wwf0VWGCfgQDzfWlRlqnNslzR5JOQNMZmEij3wAeGt81Qdy0M86zFmmFQF92cgu4SeKpni4DCx+IDGUbfdgv5A== Received: from CO1NAM03FT056.eop-NAM03.prod.protection.outlook.com (10.152.80.56) by CO1NAM03HT141.eop-NAM03.prod.protection.outlook.com (10.152.80.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.803.8; Thu, 5 Jan 2017 18:06:27 +0000 Received: from MWHPR13MB1678.namprd13.prod.outlook.com (10.152.80.53) by CO1NAM03FT056.mail.protection.outlook.com (10.152.81.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.803.8 via Frontend Transport; Thu, 5 Jan 2017 18:06:28 +0000 Received: from MWHPR13MB1678.namprd13.prod.outlook.com ([10.171.144.16]) by MWHPR13MB1678.namprd13.prod.outlook.com ([10.171.144.16]) with mapi id 15.01.0829.007; Thu, 5 Jan 2017 18:06:27 +0000 From: Soft Works To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH 1/2] libavformat/avio: Add avio_get_dyn_buf function Thread-Index: AQHSZ35bmuKQqLOFIkuCA43tLBoyDQ== Date: Thu, 5 Jan 2017 18:06:27 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: ffmpeg.org; dkim=none (message not signed) header.d=none; ffmpeg.org; dmarc=none action=none header.from=hotmail.com; x-incomingtopheadermarker: OriginalChecksum:B7CDBB8C5B432081A5A701E6D82E48916C0C81E08C91CA7D0D37C31D82229240; UpperCasedChecksum:E8167CF1A71F4120EC5920EFE0DC90C53CB5B2F339B8AD4EA0846BA984519972; SizeAsReceived:7285; Count:37 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [rw0nSeLUsK7P9aruWWNj8yQt4EUGS4XZ] x-incomingheadercount: 37 x-eopattributedmessage: 0 x-microsoft-exchange-diagnostics: 1; CO1NAM03HT141; 7:0af0ugajZVIbyoguXmcSPBGaTluSZmjFptxOuXy9qjvARcgyen85TgLuvcn0BIjVzAf6NSliwhZJIfD53EUiaf/x0UiwvUuYFU1NbOCZot7YF3vaLCI5UB3JBZJevKJ6hhGNA4xSHvfDm9NFeO+PhzifVhsCJEuXKfW7CU6/gxhvCdlQSDBxkNH7MCVS0MnVumqNTalhV60NxyReEsXcPPdY2fLTD0CoCxClJCytKUukwfzwOqv7DKv5Son1GjG/oXUS4tlc3C9P/WdBZzGIV+jl6w6wIyHov1kMDKDX+LQUgfGp3cD0JZ75u9N/OPGqnOdL8RHfH9sOErz8Atlmcs5qIufHBDbTQAwfe7MLue01GTwsrwBRo3ghCSAhG0FGXilhxD6cGR6+2fUbWujhxhZkpo3sO1LOBGxYeptpnR2IQazfGGttFHYGgPctgNiw9A6QYlqR8Pwveta2q0HSnQ== x-forefront-antispam-report: EFV:NLI; SFV:NSPM; SFS:(10019020)(98900003); DIR:OUT; SFP:1102; SCL:1; SRVR:CO1NAM03HT141; H:MWHPR13MB1678.namprd13.prod.outlook.com; FPR:; SPF:None; LANG:en; x-ms-office365-filtering-correlation-id: 88ebb44b-24c2-48d0-e10e-08d4359591da x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(1601124038)(5061506270)(5061507270)(1603103113)(1603101340)(1601125047); SRVR:CO1NAM03HT141; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(444111334)(444112120)(432015012)(82015046); SRVR:CO1NAM03HT141; BCL:0; PCL:0; RULEID:; SRVR:CO1NAM03HT141; x-forefront-prvs: 0178184651 spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: hotmail.com X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Jan 2017 18:06:27.7661 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1NAM03HT141 X-OriginalArrivalTime: 05 Jan 2017 18:06:28.0983 (UTC) FILETIME=[70012870:01D2677E] Subject: [FFmpeg-devel] [PATCH 1/2] libavformat/avio: Add avio_get_dyn_buf function 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This commit adds the avio_get_dyn_buf function which allows accessing the content of a DynBuffer without destroying it. This is required in matroskaenc for preliminary writing (correct) mkv headers. Context for this change is fixing regression bug #5977. --- libavformat/avio.h | 12 ++++++++++++ libavformat/aviobuf.c | 17 +++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/libavformat/avio.h b/libavformat/avio.h index b1ce1d1..f2b9a6f 100644 --- a/libavformat/avio.h +++ b/libavformat/avio.h @@ -704,6 +704,18 @@ int avio_closep(AVIOContext **s); int avio_open_dyn_buf(AVIOContext **s); /** + * Return the written size and a pointer to the buffer. + * The AVIOContext stream is left intact. + * The buffer must NOT be freed. + * No padding is added to the buffer. + * + * @param s IO context + * @param pbuffer pointer to a byte buffer + * @return the length of the byte buffer + */ +int avio_get_dyn_buf(AVIOContext *s, uint8_t **pbuffer); + +/** * Return the written size and a pointer to the buffer. The buffer * must be freed with av_free(). * Padding of AV_INPUT_BUFFER_PADDING_SIZE is added to the buffer. diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index 134d627..bf7e5f8 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -1277,6 +1277,23 @@ int ffio_open_dyn_packet_buf(AVIOContext **s, int max_packet_size) return url_open_dyn_buf_internal(s, max_packet_size); } +int avio_get_dyn_buf(AVIOContext *s, uint8_t **pbuffer) +{ + DynBuffer *d; + + if (!s) { + *pbuffer = NULL; + return 0; + } + + avio_flush(s); + + d = s->opaque; + *pbuffer = d->buffer; + + return d->size; +} + int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer) { DynBuffer *d;