From patchwork Mon May 4 18:22:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19498 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 0E3C944AD26 for ; Mon, 4 May 2020 21:23:31 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EC28568BEA0; Mon, 4 May 2020 21:23:30 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0FBCF68BE85 for ; Mon, 4 May 2020 21:23:24 +0300 (EEST) Received: by mail-wr1-f46.google.com with SMTP id f13so204766wrm.13 for ; Mon, 04 May 2020 11:23:24 -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=LO9C6Js+V/CQRmdbnngN4EX4kK3iUWkNxV+ldk+SMcU=; b=oGq9/02BtY+id+AgSqago2CZcufno5mhI3UQZwi+nLbIM9B4pEvrDLMu1iHWnTKC8e tObfwI6hl3zvjXg+ePwckKRvXr5HqAETCsK2+PHE4InJxx1/znUcaFR5YwF3TTSKBQ6v Hu03wVsMTWwzl/bNojN2/5/Hp/3Ke44WHpHU1+Lq1fdUBd0wbl9Lbr9UOO1hvwoTNq4c EJnXbZmPatvuodVquQr3q+wJUMX+JwrKMf3x/txrTYWdBPzQ1YTZi/wcLMtOCxBaPl0Q 8yDRUgcEMmwR5pa6TZ145rgG0fXMqL21wjd8JPV1iHMIAtm8TzsamJvT9N0w0g5BKXPd SAlg== 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=LO9C6Js+V/CQRmdbnngN4EX4kK3iUWkNxV+ldk+SMcU=; b=IYkalAHVAMhlgISy7CpWPmeHRrgc05loGRqNWos/ZQ5Su0st7sYEhQ9e5bz2Hd555O fuTdxxfmZs+RTOzKZtS/ZrkvEt4g/R5Jx4c/UC7Hy39sNby6qGJ585wTKUaUF1INAUYX Vr0LuU1V0+s4hkJzeuz4N5F24nMWGiG8DUf4kABEsuDU0yALtX1lS5DahEfe0udnlCug IbWIUNgAJIN7RzEfF9zNgq5Mov6WA4JayrApWHF5FhLsG+O+lkuTAGBt7IQBI7yLFfpr 02X0nOw7a+jMAs8y1d+LlqbpI1i2MTFH9lImaPl83PF7Io1KGBuS/dhAJ5kua1QQ0utf ZiOA== X-Gm-Message-State: AGi0PuaTC37mTPOiHZsEIL5y8izXTgD5cBhMcgOyW2YW17jXVG050Yit FUJmVjFfJZADCAcP3iLBt0sPjnGe X-Google-Smtp-Source: APiQypKYAYFzoJBAfeadHGgHpChUVC7JkuwWpJ60n/9qSr7favcrER4xcZcafE6g8YE3zm/NUEVuRA== X-Received: by 2002:a05:6000:85:: with SMTP id m5mr337744wrx.281.1588616602598; Mon, 04 May 2020 11:23:22 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id u188sm358595wmg.37.2020.05.04.11.23.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 May 2020 11:23:21 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 4 May 2020 20:22:44 +0200 Message-Id: <20200504182250.26141-4-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200504182250.26141-1-andreas.rheinhardt@gmail.com> References: <20200504182250.26141-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/10] avformat/aviobuf, nutenc: Move ff_puv_v, ff_get_v_length to nutenc.c 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" and make it static again. These functions have been moved from nutenc to aviobuf and internal.h in f8280ff4c00eeaa245085fa9691035203abd168c in order to use them in a forthcoming patch in utils.c. Said patch never happened, so this commit moves them back and makes them static, effectively reverting said commit as well as f8280ff4c00eeaa245085fa9691035203abd168c (which added the ff-prefix to these functions). Signed-off-by: Andreas Rheinhardt --- libavformat/aviobuf.c | 20 ----- libavformat/internal.h | 10 --- libavformat/nutenc.c | 172 ++++++++++++++++++++++++----------------- 3 files changed, 99 insertions(+), 103 deletions(-) diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index 85c01c938a..eb0387bdf7 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -432,26 +432,6 @@ PUT_STR16(be, 1) #undef PUT_STR16 -int ff_get_v_length(uint64_t val) -{ - int i = 1; - - while (val >>= 7) - i++; - - return i; -} - -void ff_put_v(AVIOContext *bc, uint64_t val) -{ - int i = ff_get_v_length(val); - - while (--i > 0) - avio_w8(bc, 128 | (uint8_t)(val >> (7*i))); - - avio_w8(bc, val & 127); -} - void avio_wl64(AVIOContext *s, uint64_t val) { avio_wl32(s, (uint32_t)(val & 0xffffffff)); diff --git a/libavformat/internal.h b/libavformat/internal.h index 6786b732ac..45a4149c5a 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -289,16 +289,6 @@ void ff_sdp_write_media(char *buff, int size, AVStream *st, int idx, int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt, AVFormatContext *src, int interleave); -/** - * Get the length in bytes which is needed to store val as v. - */ -int ff_get_v_length(uint64_t val); - -/** - * Put val using a variable number of bytes. - */ -void ff_put_v(AVIOContext *bc, uint64_t val); - /** * Read a whole line of text from AVIOContext. Stop reading after reaching * either a \\n, a \\0 or EOF. The returned string is always \\0-terminated, diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c index c1606651fe..ca433038d4 100644 --- a/libavformat/nutenc.c +++ b/libavformat/nutenc.c @@ -277,11 +277,37 @@ static void build_frame_code(AVFormatContext *s) nut->frame_code['N'].flags = FLAG_INVALID; } +/** + * Get the length in bytes which is needed to store val as v. + */ +static int get_v_length(uint64_t val) +{ + int i = 1; + + while (val >>= 7) + i++; + + return i; +} + +/** + * Put val using a variable number of bytes. + */ +static void put_v(AVIOContext *bc, uint64_t val) +{ + int i = get_v_length(val); + + while (--i > 0) + avio_w8(bc, 128 | (uint8_t)(val >> (7*i))); + + avio_w8(bc, val & 127); +} + static void put_tt(NUTContext *nut, AVRational *time_base, AVIOContext *bc, uint64_t val) { val *= nut->time_base_count; val += time_base - nut->time_base; - ff_put_v(bc, val); + put_v(bc, val); } /** * Store a string as vb. @@ -290,13 +316,13 @@ static void put_str(AVIOContext *bc, const char *string) { size_t len = strlen(string); - ff_put_v(bc, len); + put_v(bc, len); avio_write(bc, string, len); } static void put_s(AVIOContext *bc, int64_t val) { - ff_put_v(bc, 2 * FFABS(val) - (val > 0)); + put_v(bc, 2 * FFABS(val) - (val > 0)); } static void put_packet(NUTContext *nut, AVIOContext *bc, AVIOContext *dyn_bc, @@ -309,7 +335,7 @@ static void put_packet(NUTContext *nut, AVIOContext *bc, AVIOContext *dyn_bc, if (forw_ptr > 4096) ffio_init_checksum(bc, ff_crc04C11DB7_update, 0); avio_wb64(bc, startcode); - ff_put_v(bc, forw_ptr); + put_v(bc, forw_ptr); if (forw_ptr > 4096) avio_wl32(bc, ffio_get_checksum(bc)); @@ -326,16 +352,16 @@ static void write_mainheader(NUTContext *nut, AVIOContext *bc) tmp_head_idx; int64_t tmp_match; - ff_put_v(bc, nut->version); + put_v(bc, nut->version); if (nut->version > 3) - ff_put_v(bc, nut->minor_version = 1); - ff_put_v(bc, nut->avf->nb_streams); - ff_put_v(bc, nut->max_distance); - ff_put_v(bc, nut->time_base_count); + put_v(bc, nut->minor_version = 1); + put_v(bc, nut->avf->nb_streams); + put_v(bc, nut->max_distance); + put_v(bc, nut->time_base_count); for (i = 0; i < nut->time_base_count; i++) { - ff_put_v(bc, nut->time_base[i].num); - ff_put_v(bc, nut->time_base[i].den); + put_v(bc, nut->time_base[i].num); + put_v(bc, nut->time_base[i].den); } tmp_pts = 0; @@ -379,25 +405,25 @@ static void write_mainheader(NUTContext *nut, AVIOContext *bc) if (j != tmp_mul - tmp_size) tmp_fields = 6; - ff_put_v(bc, tmp_flags); - ff_put_v(bc, tmp_fields); + put_v(bc, tmp_flags); + put_v(bc, tmp_fields); if (tmp_fields > 0) put_s(bc, tmp_pts); - if (tmp_fields > 1) ff_put_v(bc, tmp_mul); - if (tmp_fields > 2) ff_put_v(bc, tmp_stream); - if (tmp_fields > 3) ff_put_v(bc, tmp_size); - if (tmp_fields > 4) ff_put_v(bc, 0 /*tmp_res*/); - if (tmp_fields > 5) ff_put_v(bc, j); - if (tmp_fields > 6) ff_put_v(bc, tmp_match); - if (tmp_fields > 7) ff_put_v(bc, tmp_head_idx); + if (tmp_fields > 1) put_v(bc, tmp_mul); + if (tmp_fields > 2) put_v(bc, tmp_stream); + if (tmp_fields > 3) put_v(bc, tmp_size); + if (tmp_fields > 4) put_v(bc, 0 /*tmp_res*/); + if (tmp_fields > 5) put_v(bc, j); + if (tmp_fields > 6) put_v(bc, tmp_match); + if (tmp_fields > 7) put_v(bc, tmp_head_idx); } - ff_put_v(bc, nut->header_count - 1); + put_v(bc, nut->header_count - 1); for (i = 1; i < nut->header_count; i++) { - ff_put_v(bc, nut->header_len[i]); + put_v(bc, nut->header_len[i]); avio_write(bc, nut->header[i], nut->header_len[i]); } // flags had been effectively introduced in version 4 if (nut->version > 3) - ff_put_v(bc, nut->flags); + put_v(bc, nut->flags); } static int write_streamheader(AVFormatContext *avctx, AVIOContext *bc, @@ -406,14 +432,14 @@ static int write_streamheader(AVFormatContext *avctx, AVIOContext *bc, NUTContext *nut = avctx->priv_data; AVCodecParameters *par = st->codecpar; - ff_put_v(bc, i); + put_v(bc, i); switch (par->codec_type) { - case AVMEDIA_TYPE_VIDEO: ff_put_v(bc, 0); break; - case AVMEDIA_TYPE_AUDIO: ff_put_v(bc, 1); break; - case AVMEDIA_TYPE_SUBTITLE: ff_put_v(bc, 2); break; - default: ff_put_v(bc, 3); break; + case AVMEDIA_TYPE_VIDEO: put_v(bc, 0); break; + case AVMEDIA_TYPE_AUDIO: put_v(bc, 1); break; + case AVMEDIA_TYPE_SUBTITLE: put_v(bc, 2); break; + default: put_v(bc, 3); break; } - ff_put_v(bc, 4); + put_v(bc, 4); if (par->codec_tag) { avio_wl32(bc, par->codec_tag); @@ -422,34 +448,34 @@ static int write_streamheader(AVFormatContext *avctx, AVIOContext *bc, return AVERROR(EINVAL); } - ff_put_v(bc, nut->stream[i].time_base - nut->time_base); - ff_put_v(bc, nut->stream[i].msb_pts_shift); - ff_put_v(bc, nut->stream[i].max_pts_distance); - ff_put_v(bc, par->video_delay); + put_v(bc, nut->stream[i].time_base - nut->time_base); + put_v(bc, nut->stream[i].msb_pts_shift); + put_v(bc, nut->stream[i].max_pts_distance); + put_v(bc, par->video_delay); avio_w8(bc, 0); /* flags: 0x1 - fixed_fps, 0x2 - index_present */ - ff_put_v(bc, par->extradata_size); + put_v(bc, par->extradata_size); avio_write(bc, par->extradata, par->extradata_size); switch (par->codec_type) { case AVMEDIA_TYPE_AUDIO: - ff_put_v(bc, par->sample_rate); - ff_put_v(bc, 1); - ff_put_v(bc, par->channels); + put_v(bc, par->sample_rate); + put_v(bc, 1); + put_v(bc, par->channels); break; case AVMEDIA_TYPE_VIDEO: - ff_put_v(bc, par->width); - ff_put_v(bc, par->height); + put_v(bc, par->width); + put_v(bc, par->height); if (st->sample_aspect_ratio.num <= 0 || st->sample_aspect_ratio.den <= 0) { - ff_put_v(bc, 0); - ff_put_v(bc, 0); + put_v(bc, 0); + put_v(bc, 0); } else { - ff_put_v(bc, st->sample_aspect_ratio.num); - ff_put_v(bc, st->sample_aspect_ratio.den); + put_v(bc, st->sample_aspect_ratio.num); + put_v(bc, st->sample_aspect_ratio.den); } - ff_put_v(bc, 0); /* csp type -- unknown */ + put_v(bc, 0); /* csp type -- unknown */ break; default: break; @@ -480,12 +506,12 @@ static int write_globalinfo(NUTContext *nut, AVIOContext *bc) while ((t = av_dict_get(s->metadata, "", t, AV_DICT_IGNORE_SUFFIX))) count += add_info(dyn_bc, t->key, t->value); - ff_put_v(bc, 0); //stream_if_plus1 - ff_put_v(bc, 0); //chapter_id - ff_put_v(bc, 0); //timestamp_start - ff_put_v(bc, 0); //length + put_v(bc, 0); //stream_if_plus1 + put_v(bc, 0); //chapter_id + put_v(bc, 0); //timestamp_start + put_v(bc, 0); //length - ff_put_v(bc, count); + put_v(bc, count); dyn_size = avio_close_dyn_buf(dyn_bc, &dyn_buf); avio_write(bc, dyn_buf, dyn_size); @@ -521,12 +547,12 @@ static int write_streaminfo(NUTContext *nut, AVIOContext *bc, int stream_id) { dyn_size = avio_close_dyn_buf(dyn_bc, &dyn_buf); if (count) { - ff_put_v(bc, stream_id + 1); //stream_id_plus1 - ff_put_v(bc, 0); //chapter_id - ff_put_v(bc, 0); //timestamp_start - ff_put_v(bc, 0); //length + put_v(bc, stream_id + 1); //stream_id_plus1 + put_v(bc, 0); //chapter_id + put_v(bc, 0); //timestamp_start + put_v(bc, 0); //length - ff_put_v(bc, count); + put_v(bc, count); avio_write(bc, dyn_buf, dyn_size); } @@ -547,15 +573,15 @@ static int write_chapter(NUTContext *nut, AVIOContext *bc, int id) if (ret < 0) return ret; - ff_put_v(bc, 0); // stream_id_plus1 + put_v(bc, 0); // stream_id_plus1 put_s(bc, id + 1); // chapter_id put_tt(nut, nut->chapter[id].time_base, bc, ch->start); // chapter_start - ff_put_v(bc, ch->end - ch->start); // chapter_len + put_v(bc, ch->end - ch->start); // chapter_len while ((t = av_dict_get(ch->metadata, "", t, AV_DICT_IGNORE_SUFFIX))) count += add_info(dyn_bc, t->key, t->value); - ff_put_v(bc, count); + put_v(bc, count); dyn_size = avio_close_dyn_buf(dyn_bc, &dyn_buf); avio_write(bc, dyn_buf, dyn_size); @@ -572,11 +598,11 @@ static int write_index(NUTContext *nut, AVIOContext *bc) { put_tt(nut, nut->max_pts_tb, bc, nut->max_pts); - ff_put_v(bc, nut->sp_count); + put_v(bc, nut->sp_count); for (i=0; isp_count; i++) { av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pos_cmp, (void**)next_node); - ff_put_v(bc, (next_node[1]->pos >> 4) - (dummy.pos>>4)); + put_v(bc, (next_node[1]->pos >> 4) - (dummy.pos>>4)); dummy.pos = next_node[1]->pos; } @@ -597,12 +623,12 @@ static int write_index(NUTContext *nut, AVIOContext *bc) { for (; jsp_count && (nus->keyframe_pts[j] != AV_NOPTS_VALUE) == flag; j++) n++; - ff_put_v(bc, 1 + 2*flag + 4*n); + put_v(bc, 1 + 2 * flag + 4 * n); for (k= j - n; k<=j && ksp_count; k++) { if (nus->keyframe_pts[k] == AV_NOPTS_VALUE) continue; av_assert0(nus->keyframe_pts[k] > last_pts); - ff_put_v(bc, nus->keyframe_pts[k] - last_pts); + put_v(bc, nus->keyframe_pts[k] - last_pts); last_pts = nus->keyframe_pts[k]; } } @@ -862,7 +888,7 @@ static int write_sm_data(AVFormatContext *s, AVIOContext *bc, AVPacket *pkt, int } put_s(dyn_bc, -2); put_str(dyn_bc, "bin"); - ff_put_v(dyn_bc, pkt->side_data[i].size); + put_v(dyn_bc, pkt->side_data[i].size); avio_write(dyn_bc, data, pkt->side_data[i].size); sm_data_count++; break; @@ -877,7 +903,7 @@ static int write_sm_data(AVFormatContext *s, AVIOContext *bc, AVPacket *pkt, int put_str(dyn_bc, "ChannelLayout"); put_s(dyn_bc, -2); put_str(dyn_bc, "u64"); - ff_put_v(bc, 8); + put_v(bc, 8); avio_write(dyn_bc, data, 8); data+=8; sm_data_count++; } @@ -916,7 +942,7 @@ static int write_sm_data(AVFormatContext *s, AVIOContext *bc, AVPacket *pkt, int } fail: - ff_put_v(bc, sm_data_count); + put_v(bc, sm_data_count); dyn_size = avio_close_dyn_buf(dyn_bc, &dyn_buf); avio_write(bc, dyn_buf, dyn_size); av_freep(&dyn_buf); @@ -1002,7 +1028,7 @@ static int nut_write_packet(AVFormatContext *s, AVPacket *pkt) if (ret < 0) goto fail; put_tt(nut, nus->time_base, dyn_bc, pkt->dts); - ff_put_v(dyn_bc, sp_pos != INT64_MAX ? (nut->last_syncpoint_pos - sp_pos) >> 4 : 0); + put_v(dyn_bc, sp_pos != INT64_MAX ? (nut->last_syncpoint_pos - sp_pos) >> 4 : 0); if (nut->flags & NUT_BROADCAST) { put_tt(nut, nus->time_base, dyn_bc, @@ -1060,18 +1086,18 @@ static int nut_write_packet(AVFormatContext *s, AVPacket *pkt) continue; if (flags & FLAG_STREAM_ID) - length += ff_get_v_length(pkt->stream_index); + length += get_v_length(pkt->stream_index); if (data_size % fc->size_mul != fc->size_lsb) continue; if (flags & FLAG_SIZE_MSB) - length += ff_get_v_length(data_size / fc->size_mul); + length += get_v_length(data_size / fc->size_mul); if (flags & FLAG_CHECKSUM) length += 4; if (flags & FLAG_CODED_PTS) - length += ff_get_v_length(coded_pts); + length += get_v_length(coded_pts); if ( (flags & FLAG_CODED) && nut->header_len[best_header_idx] > nut->header_len[fc->header_idx] + 1) { @@ -1103,13 +1129,13 @@ static int nut_write_packet(AVFormatContext *s, AVPacket *pkt) ffio_init_checksum(bc, ff_crc04C11DB7_update, 0); avio_w8(bc, frame_code); if (flags & FLAG_CODED) { - ff_put_v(bc, (flags ^ needed_flags) & ~(FLAG_CODED)); + put_v(bc, (flags ^ needed_flags) & ~(FLAG_CODED)); flags = needed_flags; } - if (flags & FLAG_STREAM_ID) ff_put_v(bc, pkt->stream_index); - if (flags & FLAG_CODED_PTS) ff_put_v(bc, coded_pts); - if (flags & FLAG_SIZE_MSB ) ff_put_v(bc, data_size / fc->size_mul); - if (flags & FLAG_HEADER_IDX) ff_put_v(bc, header_idx = best_header_idx); + if (flags & FLAG_STREAM_ID) put_v(bc, pkt->stream_index); + if (flags & FLAG_CODED_PTS) put_v(bc, coded_pts); + if (flags & FLAG_SIZE_MSB ) put_v(bc, data_size / fc->size_mul); + if (flags & FLAG_HEADER_IDX) put_v(bc, header_idx = best_header_idx); if (flags & FLAG_CHECKSUM) avio_wl32(bc, ffio_get_checksum(bc)); else ffio_get_checksum(bc);