From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 071BD4038A for ; Wed, 14 Feb 2024 18:26:14 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6C2D668D244; Wed, 14 Feb 2024 20:24:57 +0200 (EET) Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 480C368D227 for ; Wed, 14 Feb 2024 20:24:47 +0200 (EET) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=T0WvjFwq; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 27C524496 for ; Wed, 14 Feb 2024 19:24:43 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id raeI6xNdGVJt for ; Wed, 14 Feb 2024 19:24:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1707935078; bh=zW2vmhy06357JymYKbez0EYcPRCrRWzgpJJ+/wU2jsc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=T0WvjFwqQhrijQ/xnEWsLA6Ppqgrb3mwh5/NwtZC52KoZYiHTDVOhX6nTVPOj/yIJ z0zijWcrUvJUcxYfXzK2vtyYgGnFshIQG7sW3GRp51cFWtOHHgQTeH+kLWv1IFagtP B56YjZCvfYhpbZ6KYCFLpANQQnW86+qDtUrZcsklFaoWumyzpemTYZpE4Hn/413mXg AWl5SJ6E0Ib5YoEBZuWh03ut0LnC9pZZCfjeeNDuP/cPiJnKNFfU0e89STGRwzOlfr F3G10HluLiADvW0//4mMr7rgOd1oJeOykiBAZT0S5ghpt03D1j2AxVGyeUAk7tSufc kqCEyai2GMvwQ== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id BD4234D24 for ; Wed, 14 Feb 2024 19:24:38 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id AC47C3A1684 for ; Wed, 14 Feb 2024 19:24:38 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 14 Feb 2024 19:24:34 +0100 Message-ID: <20240214182435.31380-9-anton@khirnov.net> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240214182435.31380-1-anton@khirnov.net> References: <20240214182435.31380-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 09/10] fftools/ffmpeg: move subtitle helpers to ffmpeg_dec, their only user X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --- fftools/ffmpeg.c | 120 ------------------------------------------- fftools/ffmpeg.h | 3 -- fftools/ffmpeg_dec.c | 120 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+), 123 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 035210a8e9..3ee7b26d26 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -640,126 +640,6 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti first_report = 0; } -int copy_av_subtitle(AVSubtitle *dst, const AVSubtitle *src) -{ - int ret = AVERROR_BUG; - AVSubtitle tmp = { - .format = src->format, - .start_display_time = src->start_display_time, - .end_display_time = src->end_display_time, - .num_rects = 0, - .rects = NULL, - .pts = src->pts - }; - - if (!src->num_rects) - goto success; - - if (!(tmp.rects = av_calloc(src->num_rects, sizeof(*tmp.rects)))) - return AVERROR(ENOMEM); - - for (int i = 0; i < src->num_rects; i++) { - AVSubtitleRect *src_rect = src->rects[i]; - AVSubtitleRect *dst_rect; - - if (!(dst_rect = tmp.rects[i] = av_mallocz(sizeof(*tmp.rects[0])))) { - ret = AVERROR(ENOMEM); - goto cleanup; - } - - tmp.num_rects++; - - dst_rect->type = src_rect->type; - dst_rect->flags = src_rect->flags; - - dst_rect->x = src_rect->x; - dst_rect->y = src_rect->y; - dst_rect->w = src_rect->w; - dst_rect->h = src_rect->h; - dst_rect->nb_colors = src_rect->nb_colors; - - if (src_rect->text) - if (!(dst_rect->text = av_strdup(src_rect->text))) { - ret = AVERROR(ENOMEM); - goto cleanup; - } - - if (src_rect->ass) - if (!(dst_rect->ass = av_strdup(src_rect->ass))) { - ret = AVERROR(ENOMEM); - goto cleanup; - } - - for (int j = 0; j < 4; j++) { - // SUBTITLE_BITMAP images are special in the sense that they - // are like PAL8 images. first pointer to data, second to - // palette. This makes the size calculation match this. - size_t buf_size = src_rect->type == SUBTITLE_BITMAP && j == 1 ? - AVPALETTE_SIZE : - src_rect->h * src_rect->linesize[j]; - - if (!src_rect->data[j]) - continue; - - if (!(dst_rect->data[j] = av_memdup(src_rect->data[j], buf_size))) { - ret = AVERROR(ENOMEM); - goto cleanup; - } - dst_rect->linesize[j] = src_rect->linesize[j]; - } - } - -success: - *dst = tmp; - - return 0; - -cleanup: - avsubtitle_free(&tmp); - - return ret; -} - -static void subtitle_free(void *opaque, uint8_t *data) -{ - AVSubtitle *sub = (AVSubtitle*)data; - avsubtitle_free(sub); - av_free(sub); -} - -int subtitle_wrap_frame(AVFrame *frame, AVSubtitle *subtitle, int copy) -{ - AVBufferRef *buf; - AVSubtitle *sub; - int ret; - - if (copy) { - sub = av_mallocz(sizeof(*sub)); - ret = sub ? copy_av_subtitle(sub, subtitle) : AVERROR(ENOMEM); - if (ret < 0) { - av_freep(&sub); - return ret; - } - } else { - sub = av_memdup(subtitle, sizeof(*subtitle)); - if (!sub) - return AVERROR(ENOMEM); - memset(subtitle, 0, sizeof(*subtitle)); - } - - buf = av_buffer_create((uint8_t*)sub, sizeof(*sub), - subtitle_free, NULL, 0); - if (!buf) { - avsubtitle_free(sub); - av_freep(&sub); - return AVERROR(ENOMEM); - } - - frame->buf[0] = buf; - - return 0; -} - static void print_stream_maps(void) { av_log(NULL, AV_LOG_INFO, "Stream mapping:\n"); diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 1fdc835723..295f470a62 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -709,9 +709,6 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost, Scheduler *sch, unsigned sch_idx_enc); int init_complex_filtergraph(FilterGraph *fg); -int copy_av_subtitle(AVSubtitle *dst, const AVSubtitle *src); -int subtitle_wrap_frame(AVFrame *frame, AVSubtitle *subtitle, int copy); - /** * Get our axiliary frame data attached to the frame, allocating it * if needed. diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index bf41a44f1f..1cfa15b943 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -371,6 +371,126 @@ static int video_frame_process(DecoderPriv *dp, AVFrame *frame) return 0; } +static int copy_av_subtitle(AVSubtitle *dst, const AVSubtitle *src) +{ + int ret = AVERROR_BUG; + AVSubtitle tmp = { + .format = src->format, + .start_display_time = src->start_display_time, + .end_display_time = src->end_display_time, + .num_rects = 0, + .rects = NULL, + .pts = src->pts + }; + + if (!src->num_rects) + goto success; + + if (!(tmp.rects = av_calloc(src->num_rects, sizeof(*tmp.rects)))) + return AVERROR(ENOMEM); + + for (int i = 0; i < src->num_rects; i++) { + AVSubtitleRect *src_rect = src->rects[i]; + AVSubtitleRect *dst_rect; + + if (!(dst_rect = tmp.rects[i] = av_mallocz(sizeof(*tmp.rects[0])))) { + ret = AVERROR(ENOMEM); + goto cleanup; + } + + tmp.num_rects++; + + dst_rect->type = src_rect->type; + dst_rect->flags = src_rect->flags; + + dst_rect->x = src_rect->x; + dst_rect->y = src_rect->y; + dst_rect->w = src_rect->w; + dst_rect->h = src_rect->h; + dst_rect->nb_colors = src_rect->nb_colors; + + if (src_rect->text) + if (!(dst_rect->text = av_strdup(src_rect->text))) { + ret = AVERROR(ENOMEM); + goto cleanup; + } + + if (src_rect->ass) + if (!(dst_rect->ass = av_strdup(src_rect->ass))) { + ret = AVERROR(ENOMEM); + goto cleanup; + } + + for (int j = 0; j < 4; j++) { + // SUBTITLE_BITMAP images are special in the sense that they + // are like PAL8 images. first pointer to data, second to + // palette. This makes the size calculation match this. + size_t buf_size = src_rect->type == SUBTITLE_BITMAP && j == 1 ? + AVPALETTE_SIZE : + src_rect->h * src_rect->linesize[j]; + + if (!src_rect->data[j]) + continue; + + if (!(dst_rect->data[j] = av_memdup(src_rect->data[j], buf_size))) { + ret = AVERROR(ENOMEM); + goto cleanup; + } + dst_rect->linesize[j] = src_rect->linesize[j]; + } + } + +success: + *dst = tmp; + + return 0; + +cleanup: + avsubtitle_free(&tmp); + + return ret; +} + +static void subtitle_free(void *opaque, uint8_t *data) +{ + AVSubtitle *sub = (AVSubtitle*)data; + avsubtitle_free(sub); + av_free(sub); +} + +static int subtitle_wrap_frame(AVFrame *frame, AVSubtitle *subtitle, int copy) +{ + AVBufferRef *buf; + AVSubtitle *sub; + int ret; + + if (copy) { + sub = av_mallocz(sizeof(*sub)); + ret = sub ? copy_av_subtitle(sub, subtitle) : AVERROR(ENOMEM); + if (ret < 0) { + av_freep(&sub); + return ret; + } + } else { + sub = av_memdup(subtitle, sizeof(*subtitle)); + if (!sub) + return AVERROR(ENOMEM); + memset(subtitle, 0, sizeof(*subtitle)); + } + + buf = av_buffer_create((uint8_t*)sub, sizeof(*sub), + subtitle_free, NULL, 0); + if (!buf) { + avsubtitle_free(sub); + av_freep(&sub); + return AVERROR(ENOMEM); + } + + frame->buf[0] = buf; + + return 0; +} + static int process_subtitle(DecoderPriv *dp, AVFrame *frame) { const AVSubtitle *subtitle = (AVSubtitle*)frame->buf[0]->data; -- 2.42.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".