From patchwork Fri Apr 19 23:41:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 12833 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 E08424494CF for ; Sat, 20 Apr 2019 02:50:51 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CA5F968AB22; Sat, 20 Apr 2019 02:50:51 +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 58BC168AAC3 for ; Sat, 20 Apr 2019 02:50:45 +0300 (EEST) Received: by mail-wm1-f66.google.com with SMTP id n25so7748715wmk.4 for ; Fri, 19 Apr 2019 16:50:45 -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=MXHWHNEBvhGYdrHuS7ERjJjL3ci+/g6TSJQwCO2THmw=; b=L1bfQh0P3bEvazcZQPKZS3trSkuGNdaYtu4eVu3MGm2Z0EL5jkh1r6dx+5v0Bymk+2 NtNXd43XFgpsqnpH2L1jPaVB26MGZ4bq7AMA4vB72bIUQwk53aS9cGJ//W2h/sg8u+hx i88+JZBmwcQv/2MU9Jp0D0mYg703KnxJuhEvAMLvvn+/VNneifpAIXLkje/D7omkrE7p NK73FTPAndACLIWyyCDYw42Mpsd4tr21rxt6AzD4uIxGyIT5Rlmtp9zRfwD/STfD8mJr JShjWzOtDsaN5CBXP7h5EQu98EHLP8svWzhxEqeuUCQl5tEq34et9lRLUBx1ORE6gM6a oyDg== 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=MXHWHNEBvhGYdrHuS7ERjJjL3ci+/g6TSJQwCO2THmw=; b=V9avBtTvTObmjabzRWBDFu2wtEIggiC80yln9OpSkvlM75xzmexqKsp8Q0JIlTZPQh 2kxeqkKVSA1FwupbiTHuFGG1/uIBxMUN2Af7+IPKitB0x4GRo2CYwnOtJe5nLXOL96kJ cZ77kHCPFcDSP8Jty52PFMRYbcpRWGquc5vUl2yf1Jsi7WfezlxSaK8ze/jG8EsfyF9M 4njpOMK3DXSxhxZRc/FHgQrH7ARu6uKCG/kV//Ic4bvmkT93VgngL7bDyco95/PI7Nuk fJAMOkQiRwSISK1bC+62UHZNLNyUMGIaxHGm1q9onaBIdorXCfTVcpfUv+ytf/qqoTMr d+Jw== X-Gm-Message-State: APjAAAWEU5B9bZT7dhoxtaosY2idw0Ix+Rz2D91PH0yRyeHER1jI4T/Z hzun5b0qStvcRmMODdEPDICW6BHL X-Google-Smtp-Source: APXvYqw200AiZMqWIEvMH7WjOpZFKxY8rGl/DjwdvfdxHlGMq0aad7bCxOydqtGC1ag3lLSMiGAkiA== X-Received: by 2002:a1c:6342:: with SMTP id x63mr4246038wmb.58.1555717844521; Fri, 19 Apr 2019 16:50:44 -0700 (PDT) Received: from localhost.localdomain (ipbcc08c44.dynamic.kabel-deutschland.de. [188.192.140.68]) by smtp.gmail.com with ESMTPSA id t14sm6002395wmi.16.2019.04.19.16.50.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Apr 2019 16:50:43 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 20 Apr 2019 01:41:07 +0200 Message-Id: <20190419234110.32980-12-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190419234110.32980-1-andreas.rheinhardt@gmail.com> References: <20190402133305.3328-1-andreas.rheinhardt@googlemail.com> <20190419234110.32980-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 12/15] avformat/matroskaenc: Cosmetics and typo 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" Fixes intendation, whitespace, a typo and renames a variable (dyn_bc->cluster_bc) to make its meaning clearer and to bring it more in line with the naming of similar variables. Signed-off-by: Andreas Rheinhardt --- libavformat/matroskaenc.c | 103 +++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 52 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index d9a7ca9ad1..15164bd87c 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -119,9 +119,8 @@ typedef struct mkv_attachments { #define MAX_TRACKS 126 typedef struct MatroskaMuxContext { - const AVClass *class; + const AVClass *class; int mode; - AVIOContext *dyn_bc; AVIOContext *tags_bc; ebml_master tags; AVIOContext *info_bc; @@ -130,6 +129,7 @@ typedef struct MatroskaMuxContext { ebml_master tracks_master; ebml_master segment; int64_t segment_offset; + AVIOContext *cluster_bc; ebml_master cluster; int64_t cluster_pos; ///< file offset of the current cluster int64_t cluster_pts; @@ -159,8 +159,8 @@ typedef struct MatroskaMuxContext { int64_t last_track_timestamp[MAX_TRACKS]; - int64_t* stream_durations; - int64_t* stream_duration_offsets; + int64_t *stream_durations; + int64_t *stream_duration_offsets; int allow_raw_vfw; } MatroskaMuxContext; @@ -320,7 +320,7 @@ static ebml_master start_ebml_master(AVIOContext *pb, uint32_t elementid, put_ebml_id(pb, elementid); put_ebml_size_unknown(pb, bytes); - return (ebml_master) {avio_tell(pb), bytes }; + return (ebml_master) { avio_tell(pb), bytes }; } static void end_ebml_master(AVIOContext *pb, ebml_master master) @@ -341,10 +341,10 @@ static int start_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, Matros if ((ret = avio_open_dyn_buf(dyn_cp)) < 0) return ret; - put_ebml_id(pb, elementid); - *master = (ebml_master) { avio_tell(pb), bytes }; - if (mkv->write_crc) - put_ebml_void(*dyn_cp, 6); /* Reserve space for CRC32 so position/size calculations using avio_tell() take it into account */ + put_ebml_id(pb, elementid); + *master = (ebml_master) { avio_tell(pb), bytes }; + if (mkv->write_crc) + put_ebml_void(*dyn_cp, 6); /* Reserve space for CRC32 so position/size calculations using avio_tell() take it into account */ return 0; } @@ -355,31 +355,30 @@ static void end_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, Matrosk uint8_t *buf, crc[4]; int size, skip = 0; - size = avio_close_dyn_buf(*dyn_cp, &buf); - put_ebml_num(pb, size, master.sizebytes); - if (mkv->write_crc) { - skip = 6; /* Skip reserved 6-byte long void element from the dynamic buffer. */ - AV_WL32(crc, av_crc(av_crc_get_table(AV_CRC_32_IEEE_LE), UINT32_MAX, buf + skip, size - skip) ^ UINT32_MAX); - put_ebml_binary(pb, EBML_ID_CRC32, crc, sizeof(crc)); - } - avio_write(pb, buf + skip, size - skip); + size = avio_close_dyn_buf(*dyn_cp, &buf); + put_ebml_num(pb, size, master.sizebytes); + if (mkv->write_crc) { + skip = 6; /* Skip reserved 6-byte long void element from the dynamic buffer. */ + AV_WL32(crc, av_crc(av_crc_get_table(AV_CRC_32_IEEE_LE), UINT32_MAX, buf + skip, size - skip) ^ UINT32_MAX); + put_ebml_binary(pb, EBML_ID_CRC32, crc, sizeof(crc)); + } + avio_write(pb, buf + skip, size - skip); av_free(buf); *dyn_cp = NULL; } /** -* Complete ebml master whithout destroying the buffer, allowing for later updates +* Complete ebml master without destroying the buffer, allowing for later updates */ static void end_ebml_master_crc32_preliminary(AVIOContext *pb, AVIOContext **dyn_cp, MatroskaMuxContext *mkv, - ebml_master master) + ebml_master master) { - - uint8_t *buf; - int size = avio_get_dyn_buf(*dyn_cp, &buf); + uint8_t *buf; + int size = avio_get_dyn_buf(*dyn_cp, &buf); put_ebml_num(pb, size, master.sizebytes); - avio_write(pb, buf, size); + avio_write(pb, buf, size); } static void put_xiph_size(AVIOContext *pb, int size) @@ -393,8 +392,8 @@ static void put_xiph_size(AVIOContext *pb, int size) */ static void mkv_free(MatroskaMuxContext *mkv) { uint8_t* buf; - if (mkv->dyn_bc) { - avio_close_dyn_buf(mkv->dyn_bc, &buf); + if (mkv->cluster_bc) { + avio_close_dyn_buf(mkv->cluster_bc, &buf); av_free(buf); } if (mkv->info_bc) { @@ -1569,9 +1568,9 @@ static int mkv_write_simpletag(AVIOContext *pb, AVDictionaryEntry *t) return 0; } -static int mkv_write_tag_targets(AVFormatContext *s, - uint32_t elementid, unsigned int uid, - ebml_master *tags, ebml_master* tag) +static int mkv_write_tag_targets(AVFormatContext *s, uint32_t elementid, + unsigned int uid, ebml_master *tags, + ebml_master* tag) { AVIOContext *pb; MatroskaMuxContext *mkv = s->priv_data; @@ -1586,7 +1585,7 @@ static int mkv_write_tag_targets(AVFormatContext *s, } pb = mkv->tags_bc; - *tag = start_ebml_master(pb, MATROSKA_ID_TAG, 0); + *tag = start_ebml_master(pb, MATROSKA_ID_TAG, 0); targets = start_ebml_master(pb, MATROSKA_ID_TAGTARGETS, 0); if (elementid) put_ebml_uint(pb, elementid, uid); @@ -1884,13 +1883,13 @@ static int mkv_write_header(AVFormatContext *s) goto fail; } ebml_header = start_ebml_master(pb, EBML_ID_HEADER, MAX_EBML_HEADER_SIZE); - put_ebml_uint (pb, EBML_ID_EBMLVERSION , 1); - put_ebml_uint (pb, EBML_ID_EBMLREADVERSION , 1); - put_ebml_uint (pb, EBML_ID_EBMLMAXIDLENGTH , 4); - put_ebml_uint (pb, EBML_ID_EBMLMAXSIZELENGTH , 8); - put_ebml_string (pb, EBML_ID_DOCTYPE , s->oformat->name); - put_ebml_uint (pb, EBML_ID_DOCTYPEVERSION , version); - put_ebml_uint (pb, EBML_ID_DOCTYPEREADVERSION , 2); + put_ebml_uint (pb, EBML_ID_EBMLVERSION , 1); + put_ebml_uint (pb, EBML_ID_EBMLREADVERSION , 1); + put_ebml_uint (pb, EBML_ID_EBMLMAXIDLENGTH , 4); + put_ebml_uint (pb, EBML_ID_EBMLMAXSIZELENGTH , 8); + put_ebml_string(pb, EBML_ID_DOCTYPE , s->oformat->name); + put_ebml_uint (pb, EBML_ID_DOCTYPEVERSION , version); + put_ebml_uint (pb, EBML_ID_DOCTYPEREADVERSION, 2); end_ebml_master(pb, ebml_header); mkv->segment = start_ebml_master(pb, MATROSKA_ID_SEGMENT, 0); @@ -1973,7 +1972,7 @@ static int mkv_write_header(AVFormatContext *s) pb = s->pb; // initialize stream_duration fields - mkv->stream_durations = av_mallocz(s->nb_streams * sizeof(int64_t)); + mkv->stream_durations = av_mallocz(s->nb_streams * sizeof(int64_t)); mkv->stream_duration_offsets = av_mallocz(s->nb_streams * sizeof(int64_t)); if (!mkv->stream_durations || !mkv->stream_duration_offsets) { ret = AVERROR(ENOMEM); @@ -2256,12 +2255,12 @@ static void mkv_start_new_cluster(AVFormatContext *s, AVPacket *pkt) { MatroskaMuxContext *mkv = s->priv_data; - end_ebml_master_crc32(s->pb, &mkv->dyn_bc, mkv, mkv->cluster); + end_ebml_master_crc32(s->pb, &mkv->cluster_bc, mkv, mkv->cluster); mkv->cluster_pos = -1; - av_log(s, AV_LOG_DEBUG, - "Starting new cluster at offset %" PRIu64 " bytes, " - "pts %" PRIu64 ", dts %" PRIu64 "\n", - avio_tell(s->pb), pkt->pts, pkt->dts); + av_log(s, AV_LOG_DEBUG, + "Starting new cluster at offset %" PRIu64 " bytes, " + "pts %" PRIu64 ", dts %" PRIu64 "\n", + avio_tell(s->pb), pkt->pts, pkt->dts); avio_flush(s->pb); } @@ -2401,13 +2400,13 @@ static int mkv_write_packet_internal(AVFormatContext *s, AVPacket *pkt, int add_ if (mkv->cluster_pos == -1) { mkv->cluster_pos = avio_tell(s->pb); - ret = start_ebml_master_crc32(s->pb, &mkv->dyn_bc, mkv, &mkv->cluster, MATROSKA_ID_CLUSTER, 0); + ret = start_ebml_master_crc32(s->pb, &mkv->cluster_bc, mkv, &mkv->cluster, MATROSKA_ID_CLUSTER, 0); if (ret < 0) return ret; - put_ebml_uint(mkv->dyn_bc, MATROSKA_ID_CLUSTERTIMECODE, FFMAX(0, ts)); + put_ebml_uint(mkv->cluster_bc, MATROSKA_ID_CLUSTERTIMECODE, FFMAX(0, ts)); mkv->cluster_pts = FFMAX(0, ts); } - pb = mkv->dyn_bc; + pb = mkv->cluster_bc; relative_packet_pos = avio_tell(pb); @@ -2477,7 +2476,7 @@ static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt) // start a new cluster every 5 MB or 5 sec, or 32k / 1 sec for streaming or // after 4k and on a keyframe - cluster_size = avio_tell(mkv->dyn_bc); + cluster_size = avio_tell(mkv->cluster_bc); if (mkv->is_dash && codec_type == AVMEDIA_TYPE_VIDEO) { // WebM DASH specification states that the first block of every cluster @@ -2537,11 +2536,11 @@ static int mkv_write_flush_packet(AVFormatContext *s, AVPacket *pkt) if (!pkt) { if (mkv->cluster_pos != -1) { - end_ebml_master_crc32(s->pb, &mkv->dyn_bc, mkv, mkv->cluster); + end_ebml_master_crc32(s->pb, &mkv->cluster_bc, mkv, mkv->cluster); mkv->cluster_pos = -1; - av_log(s, AV_LOG_DEBUG, - "Flushing cluster at offset %" PRIu64 " bytes\n", - avio_tell(s->pb)); + av_log(s, AV_LOG_DEBUG, + "Flushing cluster at offset %" PRIu64 " bytes\n", + avio_tell(s->pb)); avio_flush(s->pb); } return 1; @@ -2567,8 +2566,8 @@ static int mkv_write_trailer(AVFormatContext *s) } } - if (mkv->dyn_bc) { - end_ebml_master_crc32(pb, &mkv->dyn_bc, mkv, mkv->cluster); + if (mkv->cluster_bc) { + end_ebml_master_crc32(pb, &mkv->cluster_bc, mkv, mkv->cluster); } ret = mkv_write_chapters(s);