From patchwork Mon May 25 19:42:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19864 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 70F88449D0B for ; Mon, 25 May 2020 22:43:18 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4C8DC6882F0; Mon, 25 May 2020 22:43:18 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E3229688079 for ; Mon, 25 May 2020 22:43:11 +0300 (EEST) Received: by mail-wr1-f44.google.com with SMTP id x14so12726372wrp.2 for ; Mon, 25 May 2020 12:43:11 -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:mime-version :content-transfer-encoding; bh=3eQcd0LzWj8wVe4l2H/rZ12opf/2Cq4Ji2SIsntBYQE=; b=EkLMBU2u5qHa6yBlSfR3SsIVhOltOrmYkH6QWEAaQub6eekd314FIjeYd+/a3ewuiF tLj4fitAkXe0nOR4VzotiNnNWR4oTxMQPx0TASe6rqVNSPerlxR8dGBmmS4ncvPW1JdR s6Got+JDFinhrzgYWiD5AYcn0fxlRCcmyYl5m9ZwLwBhCVvAdneT6w0ytAtoygIENlE8 c/YRGpmADpbsyYOPIx81j60EtpHPFr2kuU4mIE6sra2BQ4IrZpsQVx5ohijSp19LetUQ YLAnPqQbj7zG7zi+A9DLW7brv6iPsUGuCNTHE37AhWMIha1eRM5uBR78/gw+h4DpH/tD Fkbw== 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:mime-version :content-transfer-encoding; bh=3eQcd0LzWj8wVe4l2H/rZ12opf/2Cq4Ji2SIsntBYQE=; b=OdrlAoeEbC32RckgT7LndjAVrs11+hYqmFszYTHjGwjx99a6TqUVGt6Z183UsZykJA 38/W0jfxLbCDA02ln9zWkdsxDk/Ha4NNsvpGusd7ZOBaD4eDBjkBp6SEZf9LsK5PwYhm D796am/K50g6QOT4AelPUpe8Iik477AUki0G9kEnW+/FgbZ+gVLdEeiCJ3J8E2V+fetp 1JeMdvv6VRthKPP3HLJHalNMJnER2EXT7MNVJ7srQSVhHU1e45zzIRCQPxyB+ZyivsJN Ldu2vuiwRLp4544KGpLdOmv8Y2ukFAQoLqa+x8Sep5QigTeNzS1mrGelJfsJQ1LXdU+9 XIJQ== X-Gm-Message-State: AOAM530xAbbgnTTRS0+GjDdCdVyXn8g4hKED1BDeIfzLMco6nrBtIO98 hiVbQaiAI61zx9s7+9IyiUTcdw7U X-Google-Smtp-Source: ABdhPJwqKyhGnSIUrQSGDDBryH9FcefTc+D6wbIWFvXMkG/Vy/bWJ7ueGn3g2uY1HwM3tLXcYU86vg== X-Received: by 2002:adf:ef01:: with SMTP id e1mr15734902wro.28.1590435790756; Mon, 25 May 2020 12:43:10 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id l204sm9254368wmf.19.2020.05.25.12.43.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 May 2020 12:43:10 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 25 May 2020 21:42:59 +0200 Message-Id: <20200525194302.24515-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/4] avformat/hlsplaylist: Add const where appropriate 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 --- libavformat/hlsplaylist.c | 27 ++++++++++++++++----------- libavformat/hlsplaylist.h | 23 +++++++++++++---------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/libavformat/hlsplaylist.c b/libavformat/hlsplaylist.c index 43f9d281ba..7a89846369 100644 --- a/libavformat/hlsplaylist.c +++ b/libavformat/hlsplaylist.c @@ -35,8 +35,10 @@ void ff_hls_write_playlist_version(AVIOContext *out, int version) { avio_printf(out, "#EXT-X-VERSION:%d\n", version); } -void ff_hls_write_audio_rendition(AVIOContext *out, char *agroup, - const char *filename, char *language, int name_id, int is_default) { +void ff_hls_write_audio_rendition(AVIOContext *out, const char *agroup, + const char *filename, const char *language, + int name_id, int is_default) +{ if (!out || !agroup || !filename) return; @@ -48,8 +50,10 @@ void ff_hls_write_audio_rendition(AVIOContext *out, char *agroup, avio_printf(out, "URI=\"%s\"\n", filename); } -void ff_hls_write_subtitle_rendition(AVIOContext *out, char *sgroup, - const char *filename, char *language, int name_id, int is_default) { +void ff_hls_write_subtitle_rendition(AVIOContext *out, const char *sgroup, + const char *filename, const char *language, + int name_id, int is_default) +{ if (!out || !filename) return; @@ -61,10 +65,11 @@ void ff_hls_write_subtitle_rendition(AVIOContext *out, char *sgroup, avio_printf(out, "URI=\"%s\"\n", filename); } -void ff_hls_write_stream_info(AVStream *st, AVIOContext *out, - int bandwidth, const char *filename, char *agroup, - char *codecs, char *ccgroup, char *sgroup) { - +void ff_hls_write_stream_info(AVStream *st, AVIOContext *out, int bandwidth, + const char *filename, const char *agroup, + const char *codecs, const char *ccgroup, + const char *sgroup) +{ if (!out || !filename) return; @@ -112,7 +117,7 @@ void ff_hls_write_playlist_header(AVIOContext *out, int version, int allowcache, } } -void ff_hls_write_init_file(AVIOContext *out, char *filename, +void ff_hls_write_init_file(AVIOContext *out, const char *filename, int byterange_mode, int64_t size, int64_t pos) { avio_printf(out, "#EXT-X-MAP:URI=\"%s\"", filename); if (byterange_mode) { @@ -125,8 +130,8 @@ int ff_hls_write_file_entry(AVIOContext *out, int insert_discont, int byterange_mode, double duration, int round_duration, int64_t size, int64_t pos, //Used only if HLS_SINGLE_FILE flag is set - char *baseurl, //Ignored if NULL - char *filename, double *prog_date_time, + const char *baseurl /* Ignored if NULL */, + const char *filename, double *prog_date_time, int64_t video_keyframe_size, int64_t video_keyframe_pos, int iframe_mode) { if (!out || !filename) return AVERROR(EINVAL); diff --git a/libavformat/hlsplaylist.h b/libavformat/hlsplaylist.h index a124bdcffb..4348a26c75 100644 --- a/libavformat/hlsplaylist.h +++ b/libavformat/hlsplaylist.h @@ -37,24 +37,27 @@ typedef enum { } PlaylistType; void ff_hls_write_playlist_version(AVIOContext *out, int version); -void ff_hls_write_audio_rendition(AVIOContext *out, char *agroup, - const char *filename, char *language, int name_id, int is_default); -void ff_hls_write_subtitle_rendition(AVIOContext *out, char *sgroup, - const char *filename, char *language, int name_id, int is_default); -void ff_hls_write_stream_info(AVStream *st, AVIOContext *out, - int bandwidth, const char *filename, char *agroup, - char *codecs, char *ccgroup, char *sgroup); +void ff_hls_write_audio_rendition(AVIOContext *out, const char *agroup, + const char *filename, const char *language, + int name_id, int is_default); +void ff_hls_write_subtitle_rendition(AVIOContext *out, const char *sgroup, + const char *filename, const char *language, + int name_id, int is_default); +void ff_hls_write_stream_info(AVStream *st, AVIOContext *out, int bandwidth, + const char *filename, const char *agroup, + const char *codecs, const char *ccgroup, + const char *sgroup); void ff_hls_write_playlist_header(AVIOContext *out, int version, int allowcache, int target_duration, int64_t sequence, uint32_t playlist_type, int iframe_mode); -void ff_hls_write_init_file(AVIOContext *out, char *filename, +void ff_hls_write_init_file(AVIOContext *out, const char *filename, int byterange_mode, int64_t size, int64_t pos); int ff_hls_write_file_entry(AVIOContext *out, int insert_discont, int byterange_mode, double duration, int round_duration, int64_t size, int64_t pos, //Used only if HLS_SINGLE_FILE flag is set - char *baseurl, //Ignored if NULL - char *filename, double *prog_date_time, + const char *baseurl /* Ignored if NULL */, + const char *filename, double *prog_date_time, int64_t video_keyframe_size, int64_t video_keyframe_pos, int iframe_mode); void ff_hls_write_end_list (AVIOContext *out); From patchwork Mon May 25 19:43:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19865 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 726E5449D0B for ; Mon, 25 May 2020 22:43:42 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 534B9689248; Mon, 25 May 2020 22:43:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 97B5D6881BD for ; Mon, 25 May 2020 22:43:35 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id q11so5955231wrp.3 for ; Mon, 25 May 2020 12:43:35 -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=NY7eTaChGOaeYDRvO4UDRYN6t/diVcGzub97vc0/rjY=; b=P22CbbKKlX9yki1SePhm/TyvyiIOiYw9nm8P3tWRmvIX41+45GhMqz19zpsiNVklqj ddJ9A6Kvm2ofPf0WU4GM1zx/8HyZpfrQrFsY0O0AWviVdnq7/7gFJwis6nj4Yrx09RVA j8sq991iA5BIFhfc1cHmgeqtVUz7EBNmaq9McaUytK1dStBC22g2lJz96GXgqHRkbhUl zbLQGuqvt6dSQDM3QwNxByANuDf7NgVqa3uabLFtChC72J5k+TvkbHlugM/5L/4hcJcS jlXOaLO/khpEid4Sl6Oe/NiwNdOGy5KOpzYOhMlx+eLDksQo8xDqBMtZNidbZ3uyNrkX q30g== 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=NY7eTaChGOaeYDRvO4UDRYN6t/diVcGzub97vc0/rjY=; b=X09JUWPmzXP8B4D1FKWI4xUh3m36+SAUW5UNimjLkiL9+4osmIE+TOf4KYn7tS7LC2 QVDIFLNVveoyoQ0eSioY8IyMHYms6wQmJ5gV/CBc3r8mF0E81YgitVAApjQJgyvxNism etS13C0CoKcp/ryu7HcLO1AtrjpVXB3Q+qrWMlXDWKeujPOB2My9Ki6iDojSTpo95PUj mVcYBDIS0GuK0wVYX8lwhH66Lw1XI32zapnp7ciNrVE1I3z3WtG3/6rq8SjUdXQWLLq0 NSRmpEfrI+wSGNEjY5AHfrgWOZI/8u2EkCGdyaq2a9sP43EoVaCf8zSm88TyfTmMGMN2 g7yw== X-Gm-Message-State: AOAM5338NH/Z446mYusqIxURDVAKs1StLChwn9WCAyJW7VKaPPMtv9yH LPpbNh3bg9qE3JoTJ/+vwDBvas/v X-Google-Smtp-Source: ABdhPJxwHkHxFR5RpNkkdIMHUDYx2ApXHNiJA0xiJGbiSRc5IrRSSzI9EHLGqWucLI1WR1HCogHXbw== X-Received: by 2002:a5d:45c2:: with SMTP id b2mr15686334wrs.323.1590435814802; Mon, 25 May 2020 12:43:34 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id l204sm9254368wmf.19.2020.05.25.12.43.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 May 2020 12:43:34 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 25 May 2020 21:43:00 +0200 Message-Id: <20200525194302.24515-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200525194302.24515-1-andreas.rheinhardt@gmail.com> References: <20200525194302.24515-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/4] avformat/hlsenc: Don't unnecessarily duplicate baseurl string 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" Up until now, the HLS muxer duplicated a string for every VariantStream, although neither the original nor the copies are ever modified. So use the original directly and stop copying. Signed-off-by: Andreas Rheinhardt --- libavformat/hlsenc.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 1bc3cb210b..77e49b44b1 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -177,7 +177,6 @@ typedef struct VariantStream { char *agroup; /* audio group name */ char *sgroup; /* subtitle group name */ char *ccgroup; /* closed caption group name */ - char *baseurl; char *varname; // variant name } VariantStream; @@ -1525,7 +1524,7 @@ static int hls_window(AVFormatContext *s, int last, VariantStream *vs) ret = ff_hls_write_file_entry(byterange_mode ? hls->m3u8_out : vs->out, en->discont, byterange_mode, en->duration, hls->flags & HLS_ROUND_DURATIONS, - en->size, en->pos, vs->baseurl, + en->size, en->pos, hls->baseurl, en->filename, prog_date_time_p, en->keyframe_size, en->keyframe_pos, hls->flags & HLS_I_FRAMES_ONLY); if (ret < 0) { av_log(s, AV_LOG_WARNING, "ff_hls_write_file_entry get error\n"); @@ -1547,7 +1546,7 @@ static int hls_window(AVFormatContext *s, int last, VariantStream *vs) for (en = vs->segments; en; en = en->next) { ret = ff_hls_write_file_entry(hls->sub_m3u8_out, 0, byterange_mode, en->duration, 0, en->size, en->pos, - vs->baseurl, en->sub_filename, NULL, 0, 0, 0); + hls->baseurl, en->sub_filename, NULL, 0, 0, 0); if (ret < 0) { av_log(s, AV_LOG_WARNING, "ff_hls_write_file_entry get error\n"); } @@ -2581,7 +2580,6 @@ static void hls_deinit(AVFormatContext *s) av_freep(&vs->sgroup); av_freep(&vs->language); av_freep(&vs->ccgroup); - av_freep(&vs->baseurl); av_freep(&vs->varname); } @@ -2956,12 +2954,6 @@ static int hls_init(AVFormatContext *s) *p = '.'; } - if (hls->baseurl) { - vs->baseurl = av_strdup(hls->baseurl); - if (!vs->baseurl) - return AVERROR(ENOMEM); - } - if ((ret = hls_mux_init(s, vs)) < 0) return ret; From patchwork Mon May 25 19:43:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19866 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 5DE23449D0B for ; Mon, 25 May 2020 22:43:45 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4A7BC6898BD; Mon, 25 May 2020 22:43:45 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DC8996882F4 for ; Mon, 25 May 2020 22:43:36 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id i15so18055149wrx.10 for ; Mon, 25 May 2020 12:43:36 -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=MDwYHX/Hg0CN+nfeCYfjyex1T4velIDHkSZPKccnPBE=; b=nBzVE8iEwCtpap5vf4f91ADgpqtpGQE0IDJZswBuORRZiI5Zo+P0r2FafSbKGhQf87 P6HA83lsOv3K1pelgfdkvZal50xpxlv2G/a3vKjjokGW8Gc9Aq09Yhi3TvVYTjlZIXzD Su64URj7EO7gCcYa78UbJOG81/NVYCzCeB7QCWvPa5jNLopuyWyGp12uGOy1n/ApFSPb hG25+UT2QHbB4xsdEK2Zzzgu6zP2cobkR2y8GRcRx257GzZqh/c70vVVm/FvPE9T+cqL UrG1twKFNoBqaROdTsGWGKMj1Uct6PgLcluaDPXTIL90sfS1YauCYHTQeT1GsF7m/M2i 05QA== 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=MDwYHX/Hg0CN+nfeCYfjyex1T4velIDHkSZPKccnPBE=; b=ow7N8Uxt53urLq2GsU9uJ6p6xNcg4aAK9bzrQ5/qowFFmMHiLalhr66W5hIFwMiUl8 tLTy+wkYZrjrWOqZARktg3vJ20/hxlM7+yI81PCWv4bYDVkNTIru9BARVnwBY8vceVw5 e+CKuMN5d7MDGX2sDPmSdDl2P2wTPTh43MBLqJiBTGehs7H6DienEtV5Cb0gUQjFE54k 1+7ae68yImN7kY9ifgx3+mCqFEL4Sk06A4+3kqa89R9AGHNz6jZuhyMZ6jw++kD2XXe0 6UETGQjfplAEgMRLsJiBA3HeXnTGT1Kepo9taneqEsB+ItxNxV4J2g8BRah0aTB9Ww73 M1OQ== X-Gm-Message-State: AOAM532DkwSvWcebTXxLFSArrKJW972e9nkGNBBqmDz+Q9XmjcNCSjlG kLoCJ/16R0MuDKdH2M4Lad+iTGKL X-Google-Smtp-Source: ABdhPJzVzy9y4Olh0PPHFZX6U1x4B01KVLYweqECaczlEf7O+4MLkZwGa8bzgzhMfTtBpBjyZiKJQg== X-Received: by 2002:adf:ab1b:: with SMTP id q27mr9328152wrc.268.1590435816080; Mon, 25 May 2020 12:43:36 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id l204sm9254368wmf.19.2020.05.25.12.43.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 May 2020 12:43:35 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 25 May 2020 21:43:01 +0200 Message-Id: <20200525194302.24515-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200525194302.24515-1-andreas.rheinhardt@gmail.com> References: <20200525194302.24515-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/4] avformat/hlsenc: Avoid duplicating strings when parsing 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" Up until now, the HLS muxer uses av_strtok() to split an input string controlling parameters of the VariantStreams and then duplicates parts of this string containing parameters such as the language or the name of the VariantStream. But these parts are proper zero-terminated strings of their own that are never modified lateron, so one can simply use the substring as-is without creating a copy. This commit implements this. The same also happened for the string controlling the closed caption groups. Furthermore, add const to indicate that the pointers to these substrings are not used to modify them and also to indicate that these strings are not allocated on their own. Signed-off-by: Andreas Rheinhardt --- libavformat/hlsenc.c | 77 +++++++++++--------------------------------- 1 file changed, 19 insertions(+), 58 deletions(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 77e49b44b1..02bd5c3528 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -173,17 +173,17 @@ typedef struct VariantStream { unsigned int nb_streams; int m3u8_created; /* status of media play-list creation */ int is_default; /* default status of audio group */ - char *language; /* audio lauguage name */ - char *agroup; /* audio group name */ - char *sgroup; /* subtitle group name */ - char *ccgroup; /* closed caption group name */ - char *varname; // variant name + const char *language; /* audio lauguage name */ + const char *agroup; /* audio group name */ + const char *sgroup; /* subtitle group name */ + const char *ccgroup; /* closed caption group name */ + const char *varname; /* variant name */ } VariantStream; typedef struct ClosedCaptionsStream { - char *ccgroup; /* closed caption group name */ - char *instreamid; /* closed captions INSTREAM-ID */ - char *language; /* closed captions langauge */ + const char *ccgroup; /* closed caption group name */ + const char *instreamid; /* closed captions INSTREAM-ID */ + const char *language; /* closed captions langauge */ } ClosedCaptionsStream; typedef struct HLSContext { @@ -1290,8 +1290,8 @@ static int create_master_playlist(AVFormatContext *s, int ret, bandwidth; const char *m3u8_rel_name = NULL; const char *vtt_m3u8_rel_name = NULL; - char *ccgroup; - char *sgroup = NULL; + const char *ccgroup; + const char *sgroup = NULL; ClosedCaptionsStream *ccs; const char *proto = avio_find_protocol_name(hls->master_m3u8_url); int is_file_proto = proto && !strcmp(proto, "file"); @@ -1962,10 +1962,7 @@ static int parse_variant_stream_mapstring(AVFormatContext *s) char *end; varstr = NULL; if (av_strstart(keyval, "language:", &val)) { - av_free(vs->language); - vs->language = av_strdup(val); - if (!vs->language) - return AVERROR(ENOMEM); + vs->language = val; continue; } else if (av_strstart(keyval, "default:", &val)) { vs->is_default = (!av_strncasecmp(val, "YES", strlen("YES")) || @@ -1973,28 +1970,16 @@ static int parse_variant_stream_mapstring(AVFormatContext *s) hls->has_default_key = 1; continue; } else if (av_strstart(keyval, "name:", &val)) { - av_free(vs->varname); - vs->varname = av_strdup(val); - if (!vs->varname) - return AVERROR(ENOMEM); + vs->varname = val; continue; } else if (av_strstart(keyval, "agroup:", &val)) { - av_free(vs->agroup); - vs->agroup = av_strdup(val); - if (!vs->agroup) - return AVERROR(ENOMEM); + vs->agroup = val; continue; } else if (av_strstart(keyval, "sgroup:", &val)) { - av_free(vs->sgroup); - vs->sgroup = av_strdup(val); - if (!vs->sgroup) - return AVERROR(ENOMEM); + vs->sgroup = val; continue; } else if (av_strstart(keyval, "ccgroup:", &val)) { - av_free(vs->ccgroup); - vs->ccgroup = av_strdup(val); - if (!vs->ccgroup) - return AVERROR(ENOMEM); + vs->ccgroup = val; continue; } else if (av_strstart(keyval, "v:", &val)) { codec_type = AVMEDIA_TYPE_VIDEO; @@ -2085,20 +2070,11 @@ static int parse_cc_stream_mapstring(AVFormatContext *s) ccstr = NULL; if (av_strstart(keyval, "ccgroup:", &val)) { - av_free(ccs->ccgroup); - ccs->ccgroup = av_strdup(val); - if (!ccs->ccgroup) - return AVERROR(ENOMEM); + ccs->ccgroup = val; } else if (av_strstart(keyval, "instreamid:", &val)) { - av_free(ccs->instreamid); - ccs->instreamid = av_strdup(val); - if (!ccs->instreamid) - return AVERROR(ENOMEM); + ccs->instreamid = val; } else if (av_strstart(keyval, "language:", &val)) { - av_free(ccs->language); - ccs->language = av_strdup(val); - if (!ccs->language) - return AVERROR(ENOMEM); + ccs->language = val; } else { av_log(s, AV_LOG_ERROR, "Invalid keyval %s\n", keyval); return AVERROR(EINVAL); @@ -2162,9 +2138,7 @@ static int update_variant_stream_info(AVFormatContext *s) //by default, the first available ccgroup is mapped to the variant stream if (hls->nb_ccstreams) { - hls->var_streams[0].ccgroup = av_strdup(hls->cc_streams[0].ccgroup); - if (!hls->var_streams[0].ccgroup) - return AVERROR(ENOMEM); + hls->var_streams[0].ccgroup = hls->cc_streams[0].ccgroup; } for (i = 0; i < s->nb_streams; i++) @@ -2576,19 +2550,6 @@ static void hls_deinit(AVFormatContext *s) hls_free_segments(vs->old_segments); av_freep(&vs->m3u8_name); av_freep(&vs->streams); - av_freep(&vs->agroup); - av_freep(&vs->sgroup); - av_freep(&vs->language); - av_freep(&vs->ccgroup); - av_freep(&vs->varname); - } - - for (i = 0; i < hls->nb_ccstreams; i++) { - ClosedCaptionsStream *ccs = &hls->cc_streams[i]; - - av_freep(&ccs->ccgroup); - av_freep(&ccs->instreamid); - av_freep(&ccs->language); } ff_format_io_close(s, &hls->m3u8_out); From patchwork Mon May 25 19:43:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19867 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 2B611449D0B for ; Mon, 25 May 2020 22:43:46 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1063A689EA6; Mon, 25 May 2020 22:43:46 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F0D9768980D for ; Mon, 25 May 2020 22:43:37 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id x6so4485875wrm.13 for ; Mon, 25 May 2020 12:43:37 -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=7jfHPgvRRjTMZzZaIUNLP/1gOSpPQMebkaCO7/bOg6I=; b=jDfH8lFTY0L8yfYVDt658Z/SeineiLimzIm9zR/3orZ2n4hr3vXEZs9xqyyiQaX48S pN91fkNamx8NHkE4d4pdtRxMN71I8ZLBxYMPwDZkWHSqAe5+WBkkF5ZBSWhWMXXR0GGY 7/jCcmHCVO81JZX6eM1ZMMD08Ap3Xlit5dCmVHZXPfFlh1DHPYYLXG0ddyjWkZIMqiQf T9S16DOde4iCf2y4kl13yCPgKgh8bpE89psusxDR5yCUKdFmc+ARH1AYPz6o/NBpKeRm Fll6Api9VyqOfdYxn9ABWsMvin85MfwGCP0bQjZ4xiZr1bO+mRoXCZwUP5yikMQh/Quv Ia0A== 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=7jfHPgvRRjTMZzZaIUNLP/1gOSpPQMebkaCO7/bOg6I=; b=fqnn0IO7A/BQkDbahUl443nNPDYQ6Wpnu470Kzhrulh2qFvHIqMXaPYvv12LV/B4Ak ehJMfBJF/Juzc2eSfvkQpzIMQhE6RJg/yCupYBwyV3Jl+oge1TwEcCApx5e66y5/zSHn kWbQNrL8Vt4fJaRAqHsOKllg44KWaEpZbMDw+W48mPZ1LbACcHrVLpUyjw5uJ4Uwhh2T l//3HBYL3CvGo+7LOSDU2myXUdmaqvia2UQieile8Tb+Xd0hCkib0+bp/n5AScV0ExVT AH3wNhO84BA29XQDq6VGrbgb6wu78znmUGp/tF57wR2GKnWRBGn3ZbTHlfy8URMvmInV 9H1w== X-Gm-Message-State: AOAM532PcQ0iCLUCPvIKazYkZl3oNaVgfcUVY2NL5HJQnrRkTeMrl9ci WIMcGYd52Vyr0R+GO9EVdjCGBmpb X-Google-Smtp-Source: ABdhPJwj2DVJ+Zbw2OZH/Z5sAKvFBHrHRDbV2NCUpd6Y4xS61hq39ExCN5k8IqK2XpFqS0nZ+z1axw== X-Received: by 2002:a5d:548c:: with SMTP id h12mr11213007wrv.120.1590435817075; Mon, 25 May 2020 12:43:37 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id l204sm9254368wmf.19.2020.05.25.12.43.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 May 2020 12:43:36 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 25 May 2020 21:43:02 +0200 Message-Id: <20200525194302.24515-4-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200525194302.24515-1-andreas.rheinhardt@gmail.com> References: <20200525194302.24515-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/4] avformat/hlsenc, hlsplaylist: Cosmetics 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 --- libavformat/hlsenc.c | 5 ++--- libavformat/hlsplaylist.c | 22 ++++++++++++++-------- libavformat/hlsplaylist.h | 9 +++++---- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 02bd5c3528..18256cbf91 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -2137,9 +2137,8 @@ static int update_variant_stream_info(AVFormatContext *s) return AVERROR(ENOMEM); //by default, the first available ccgroup is mapped to the variant stream - if (hls->nb_ccstreams) { + if (hls->nb_ccstreams) hls->var_streams[0].ccgroup = hls->cc_streams[0].ccgroup; - } for (i = 0; i < s->nb_streams; i++) hls->var_streams[0].streams[i] = s->streams[i]; @@ -2320,7 +2319,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) vs->start_pts_from_audio = 0; } - if (vs->has_video) { + if (vs->has_video) { can_split = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ((pkt->flags & AV_PKT_FLAG_KEY) || (hls->flags & HLS_SPLIT_BY_TIME)); is_ref_pkt = (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) && (pkt->stream_index == vs->reference_stream_index); diff --git a/libavformat/hlsplaylist.c b/libavformat/hlsplaylist.c index 7a89846369..0e1dcc087f 100644 --- a/libavformat/hlsplaylist.c +++ b/libavformat/hlsplaylist.c @@ -28,7 +28,8 @@ #include "avformat.h" #include "hlsplaylist.h" -void ff_hls_write_playlist_version(AVIOContext *out, int version) { +void ff_hls_write_playlist_version(AVIOContext *out, int version) +{ if (!out) return; avio_printf(out, "#EXTM3U\n"); @@ -96,7 +97,8 @@ void ff_hls_write_stream_info(AVStream *st, AVIOContext *out, int bandwidth, void ff_hls_write_playlist_header(AVIOContext *out, int version, int allowcache, int target_duration, int64_t sequence, - uint32_t playlist_type, int iframe_mode) { + uint32_t playlist_type, int iframe_mode) +{ if (!out) return; ff_hls_write_playlist_version(out, version); @@ -118,7 +120,8 @@ void ff_hls_write_playlist_header(AVIOContext *out, int version, int allowcache, } void ff_hls_write_init_file(AVIOContext *out, const char *filename, - int byterange_mode, int64_t size, int64_t pos) { + int byterange_mode, int64_t size, int64_t pos) +{ avio_printf(out, "#EXT-X-MAP:URI=\"%s\"", filename); if (byterange_mode) { avio_printf(out, ",BYTERANGE=\"%"PRId64"@%"PRId64"\"", size, pos); @@ -127,12 +130,14 @@ void ff_hls_write_init_file(AVIOContext *out, const char *filename, } int ff_hls_write_file_entry(AVIOContext *out, int insert_discont, - int byterange_mode, - double duration, int round_duration, - int64_t size, int64_t pos, //Used only if HLS_SINGLE_FILE flag is set + int byterange_mode, double duration, + int round_duration, int64_t size, + int64_t pos /* Used only if HLS_SINGLE_FILE flag is set */, const char *baseurl /* Ignored if NULL */, const char *filename, double *prog_date_time, - int64_t video_keyframe_size, int64_t video_keyframe_pos, int iframe_mode) { + int64_t video_keyframe_size, int64_t video_keyframe_pos, + int iframe_mode) +{ if (!out || !filename) return AVERROR(EINVAL); @@ -181,7 +186,8 @@ int ff_hls_write_file_entry(AVIOContext *out, int insert_discont, return 0; } -void ff_hls_write_end_list (AVIOContext *out) { +void ff_hls_write_end_list(AVIOContext *out) +{ if (!out) return; avio_printf(out, "#EXT-X-ENDLIST\n"); diff --git a/libavformat/hlsplaylist.h b/libavformat/hlsplaylist.h index 4348a26c75..29487da3ed 100644 --- a/libavformat/hlsplaylist.h +++ b/libavformat/hlsplaylist.h @@ -53,12 +53,13 @@ void ff_hls_write_playlist_header(AVIOContext *out, int version, int allowcache, void ff_hls_write_init_file(AVIOContext *out, const char *filename, int byterange_mode, int64_t size, int64_t pos); int ff_hls_write_file_entry(AVIOContext *out, int insert_discont, - int byterange_mode, - double duration, int round_duration, - int64_t size, int64_t pos, //Used only if HLS_SINGLE_FILE flag is set + int byterange_mode, double duration, + int round_duration, int64_t size, + int64_t pos /* Used only if HLS_SINGLE_FILE flag is set */, const char *baseurl /* Ignored if NULL */, const char *filename, double *prog_date_time, - int64_t video_keyframe_size, int64_t video_keyframe_pos, int iframe_mode); + int64_t video_keyframe_size, int64_t video_keyframe_pos, + int iframe_mode); void ff_hls_write_end_list (AVIOContext *out); #endif /* AVFORMAT_HLSPLAYLIST_H_ */