From: Anton Khirnov <anton@khirnov.net>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 09/10] fftools/ffmpeg: move subtitle helpers to ffmpeg_dec, their only user
Date: Wed, 14 Feb 2024 19:24:34 +0100
Message-ID: <20240214182435.31380-9-anton@khirnov.net> (raw)
In-Reply-To: <20240214182435.31380-1-anton@khirnov.net>
---
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".
next prev parent reply other threads:[~2024-02-14 18:26 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-14 18:24 [FFmpeg-devel] [PATCH 01/10] fftools/ffmpeg_filter: stop taking display matrix from global side data Anton Khirnov
2024-02-14 18:24 ` [FFmpeg-devel] [PATCH 02/10] fftools/ffmpeg_filter: compute input trim start/end in demuxer Anton Khirnov
2024-02-14 18:24 ` [FFmpeg-devel] [PATCH 03/10] fftools/ffmpeg_filter: accept a name from its upstream input Anton Khirnov
2024-02-14 18:24 ` [FFmpeg-devel] [PATCH 04/10] fftools/ffmpeg_filter: pass sub2video canvas size through InputFilterOptions Anton Khirnov
2024-02-14 18:24 ` [FFmpeg-devel] [PATCH 05/10] fftools/ffmpeg_filter: pass autorotate/reinit flags " Anton Khirnov
2024-02-14 18:24 ` [FFmpeg-devel] [PATCH 06/10] fftools/ffmpeg_filter: pass framerate " Anton Khirnov
2024-02-14 18:24 ` [FFmpeg-devel] [PATCH 07/10] fftools/ffmpeg_filter: refactor setting input timebase Anton Khirnov
2024-02-15 1:58 ` Michael Niedermayer
2024-02-14 18:24 ` [FFmpeg-devel] [PATCH 08/10] fftools/ffmpeg_filter: drop unused InputFilterPriv.ist Anton Khirnov
2024-02-14 18:24 ` Anton Khirnov [this message]
2024-02-14 18:24 ` [FFmpeg-devel] [PATCH 10/10] fftools/ffmpeg: cosmetics, vertically align structs Anton Khirnov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240214182435.31380-9-anton@khirnov.net \
--to=anton@khirnov.net \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git