1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-26 19:01:44 +02:00
Commit Graph

62 Commits

Author SHA1 Message Date
Andreas Rheinhardt
4179c121c3 avcodec/movtextenc: Don't copy data around unnecessarily
Using av_bprint_init_for_buffer() avoids copying data
into the internal AVBPrint buffer (or worse: to allocate
a temporary buffer in case the internal buffer does not
suffice).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-02-22 01:45:31 +01:00
Anton Khirnov
08bebeb1be Revert "all: Don't set AVClass.item_name to its default value"
Some callers assume that item_name is always set, so this may be
considered an API break.

This reverts commit 0c6203c97a.
2024-01-20 10:34:48 +01:00
Andreas Rheinhardt
0c6203c97a all: Don't set AVClass.item_name to its default value
Unnecessary since acf63d5350adeae551d412db699f8ca03f7e76b9;
also avoids relocations.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-12-22 15:12:33 +01:00
Andreas Rheinhardt
48286d4d98 avcodec/codec_internal: Add macro to set AVCodec.long_name
It reduces typing: Before this patch, there were 105 codecs
whose long_name-definition exceeded the 80 char line length
limit. Now there are only nine of them.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-09-03 15:42:57 +02:00
Andreas Rheinhardt
21b23ceab3 avcodec: Make init-threadsafety the default
and remove FF_CODEC_CAP_INIT_THREADSAFE
All our native codecs are already init-threadsafe
(only wrappers for external libraries and hwaccels
are typically not marked as init-threadsafe yet),
so it is only natural for this to also be the default state.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-07-18 20:04:59 +02:00
Andreas Rheinhardt
4243da4ff4 avcodec/codec_internal: Use union for FFCodec decode/encode callbacks
This is possible, because every given FFCodec has to implement
exactly one of these. Doing so decreases sizeof(FFCodec) and
therefore decreases the size of the binary.
Notice that in case of position-independent code the decrease
is in .data.rel.ro, so that this translates to decreased
memory consumption.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-04-05 20:02:37 +02:00
Andreas Rheinhardt
20f9727018 avcodec/codec_internal: Add FFCodec, hide internal part of AVCodec
Up until now, codec.h contains both public and private parts
of AVCodec. This exposes the internals of AVCodec to users
and leads them into the temptation of actually using them
and forces us to forward-declare structures and types that
users can't use at all.

This commit changes this by adding a new structure FFCodec to
codec_internal.h that extends AVCodec, i.e. contains the public
AVCodec as first member; the private fields of AVCodec are moved
to this structure, leaving codec.h clean.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-03-21 01:33:09 +01:00
Andreas Rheinhardt
a688f3c13c avcodec/internal: Move FF_CODEC_CAP_* to a new header codec_internal.h
Also move FF_CODEC_TAGS_END as well as struct AVCodecDefault.
This reduces the amount of files that have to include internal.h
(which comes with quite a lot of indirect inclusions), as e.g.
most encoders don't need it. It is furthemore in preparation
for moving the private part of AVCodec out of the public codec.h.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-03-21 01:33:09 +01:00
Charlie Monroe
34aee50a7f avcodec/movtextenc: Check for existence of font name before using it
Fixes crashes if the font name is NULL (which it is if a \fn tag
is not followed by a font name).

Signed-off-by: Charlie Monroe <charlie@charliemonroe.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-12-11 17:15:38 +01:00
Andreas Rheinhardt
acdfc4bdfb avcodec/movtextenc: Simplify writing a single char
Reviewed-by: Philip Langdale <philipl@overt.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-12-02 07:31:43 +01:00
Andreas Rheinhardt
c4c9d096ae avcodec/movtextenc: Remove redundant byte count
Use the AVBPrint's len instead.

Reviewed-by: Philip Langdale <philipl@overt.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-12-02 07:31:09 +01:00
Andreas Rheinhardt
0bc3c070fb avcodec/movtextenc: Fix encoding of subtitles with multiple rects
The format of a mov_text (3GPP Timed Text) sample is:

uint16_t text_length;
uint8_t  text[text_length];
TextSampleModifierBox text_modifier;

Yet in case our encoder receives an AVSubtitle with multiple
ASS AVSubtitleRects, it creates something like this:
uint16_t text_length;
uint8_t  text[text_length_1];
TextSampleModifierBox text_modifier_1;
uint8_t  text[text_length_2];
TextSampleModifierBox text_modifier_2;
...

where text_length is the sum of all the text_length_*.
This commit fixes this by writing the TextSampleModifierBoxes only
after all the rects have been written.

Reviewed-by: Philip Langdale <philipl@overt.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-12-02 07:29:02 +01:00
Andreas Rheinhardt
f8e5e1c523 avcodec/movtextenc: Check for too long subtitles
Reviewed-by: Philip Langdale <philipl@overt.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-12-02 07:28:47 +01:00
Andreas Rheinhardt
0b934f8f17 avcodec/movtextenc: Reset AVBPrint at the beginning, not end of encoding
This avoids abusing a variable called length for the return value
and ensures that the AVBPrint is always reset before using it;
previously this has been forgotten in some error paths.

Reviewed-by: Philip Langdale <philipl@overt.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-12-02 07:28:35 +01:00
Andreas Rheinhardt
bb89a2f64f avcodec/movtextenc: Fix infinite loop due to variable truncation
Regression since af043b839c.
Fixes ticket #9409.

Reviewed-by: Philip Langdale <philipl@overt.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-12-02 07:27:46 +01:00
Andreas Rheinhardt
5ad436fcb9 avcodec/ass_split: Rename ff_ass_split_dialog2->ff_ass_split_dialog
Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-08 00:13:57 +02:00
Andreas Rheinhardt
2934a4b9a5 Remove unnecessary avassert.h inclusions
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-07-22 15:02:30 +02:00
Andreas Rheinhardt
2a4cedace4 avcodec/movtextenc, srtenc, webvttenc: Mark encoders as init-threadsafe
They all rely on ff_ass_split(), which does not have any static state.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-05-02 05:14:42 +02:00
Andreas Rheinhardt
a247ac640d avcodec: Constify AVCodecs
Given that the AVCodec.next pointer has now been removed, most of the
AVCodecs are not modified at all any more and can therefore be made
const (as this patch does); the only exceptions are the very few codecs
for external libraries that have a init_static_data callback.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 10:43:15 -03:00
Andreas Rheinhardt
6c497ac93b avcodec/(movtext|srt|ttml|webvtt)enc: Reindent after previous commit
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 10:43:04 -03:00
Andreas Rheinhardt
1f63665ca5 avcodec: Remove deprecated ASS with inline timing
Deprecated in 22ebbda637.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 10:43:04 -03:00
Andreas Rheinhardt
1c9e53d70b avcodec/movtextenc: Check for too many styles
The counter for the number of styles is written on two bytes, ergo
anything > UINT16_MAX is invalid. This also fixes a compiler warning
because of a tautologically true check on 64bit systems.

Reviewed-by: Philip Langdale <philipl@overt.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-02-24 07:50:39 +01:00
Andreas Rheinhardt
2134667227 avcodec/movtextenc: Cleanup generically on init failure
Reviewed-by: Philip Langdale <philipl@overt.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-10-19 21:45:22 +02:00
Andreas Rheinhardt
eab812d6d6 avcodec/movtextenc: Remove redundant function parameters
It makes no sense to call the functions to write styl, hlit or hclr boxes
with a different box name than "styl", "hlit" or "hclr". Therefore this
commit inlines these values in the functions, removes the function
parameter containing the box's name and removes the (non obsolete) box
names from the list of boxes.

Reviewed-by: Philip Langdale <philipl@overt.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-10-19 21:42:55 +02:00
Andreas Rheinhardt
82c636313d avcodec/movtextenc: Simplify writing to AVBPrint
The mov_text encoder uses an AVBPrint to assemble the subtitles;
yet mov_text subtitles are not pure text; they also have a binary
portion that was mostly handled as follows:

    uint32_t size = /* calculation */;
    size = AV_RB32(&size);
    av_bprint_append_data(bprint, (const char*)&size, 4);

Here AV_RB32() is a no-op on big-endian systems and a LE-BE swap
on little-endian systems, making the output endian-independent.

Yet this is ugly and unclean: On LE systems, the variable size from
the snippet above won't contain the correct value any more. Furthermore,
using this pattern leads to lots of small writes to the AVBPrint.

This commit therefore changes this to using a temporary buffer instead:

    uint8_t buf[4];
    AV_WB32(buf, /* size calculation */);
    av_bprint_append_data(bprint, buf, 4);

This method also allows to use bigger buffers holding more than one
element, saving calls to av_bprint_append_data() and reducing codesize.

Reviewed-by: Philip Langdale <philipl@overt.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-10-19 21:41:46 +02:00
Andreas Rheinhardt
2f9fc35028 avcodec/movtextenc: Fix undefined left shifts outside the range of int
Reviewed-by: Philip Langdale <philipl@overt.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-10-19 21:40:28 +02:00
Andreas Rheinhardt
9a731e9fec avcodec/movtextenc: Fix memleak on (re)allocation error
Up until now, the mov_text encoder used the dynamic array API for its
list of style attributes; it used the (horrible) av_dynarray_add() which
works with an array of pointers; on error it frees its array but not
the buffers referenced by the pointers said array contains. It also
returns no error code, encouraging not to check for errors.

These properties imply that this function may only be used if the buffers
referenced by the list either need not be freed at all or if they are
freed by other means (i.e. if the list contains non-ownership pointers).

In this case, the style attributes are owned by the pointers of the
dynamic list. Ergo the old style attributes leak on a subsequent
reallocation failure. But given that the (re)allocation isn't checked
for success, the style attribute intended to be added to the list also
leaks because the only pointer to it gets overwritten in the belief that
it is now owned by the list.

This commit fixes this by switching to av_fast_realloc() and an array
containing the styles directly instead of pointers to individually
allocated style attributes. The current style attributes are now no longer
individually allocated, instead they are part of the context.

Furthermore, av_fast_realloc() allows to easily distinguish between
valid and allocated elements, thereby allowing to reuse the array
(which up until now has always been freed after processing an
AVSubtitleRect).

Reviewed-by: Philip Langdale <philipl@overt.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-10-19 21:37:42 +02:00
Andreas Rheinhardt
0dd7b8232d avcodec/movtextenc: Don't presume every style to have a font
Fixes segfaults in the absence of fonts; this can happen because the
file didn't contain any or because the allocation of the font-string
failed.

Reviewed-by: Philip Langdale <philipl@overt.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-10-19 21:37:15 +02:00
Andreas Rheinhardt
8d4431955c avcodec/movtextenc: Reset array counter after freeing array
Otherwise the mov_text encoder can segfault when given subtitles with more
than one AVSubtitleRect if one of the first nb_rects - 1 rects contained
a style attribute.

Reviewed-by: Philip Langdale <philipl@overt.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-10-19 21:36:57 +02:00
Andreas Rheinhardt
56b3726ed2 avcodec/movtextenc: Fix potential use of uninitialized value
Background colour was never initialized if no style was available.
Use a sane default of zero (i.e. completely transparent).

Fixes Coverity issue #1461471.

Reviewed-by: Philip Langdale <philipl@overt.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-10-19 21:36:17 +02:00
Andriy Gelman
2b5e18a953 avcodec/movtextenc: cosmetics
Change pointer position.

Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
2020-10-15 22:30:13 -04:00
Andriy Gelman
d4c46dc328 avcodec/movtextenc: fix writing to bytestream on BE arches
Fixes fate-binsub-movtextenc on PPC64

Currently tags are written in reverse order on BE arches. This is fixed
by using MKBETAG() and AV_RB32() to be arch agnostics.

Also s->font_count is of type int. On BE arches with 32bit int,
count = AV_RB16(&s->font_count) will read two most significant bytes
instead of the least significant bytes. This is fixed by assigning
s->font_count to count first.

The final change is modifying the type of len. On BE arches
the most significant byte of the int was written instead of the least
significant byte.

Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
2020-10-15 22:27:37 -04:00
John Stebbins
1d544e410e lavc/movtextenc: return more meaningful error codes
Signed-off-by: Philip Langdale <philipl@overt.org>
2020-04-10 15:58:04 -07:00
John Stebbins
ad3f6212ac lavc/movtextenc: handle changes to hilight alpha
Signed-off-by: Philip Langdale <philipl@overt.org>
2020-04-10 09:32:13 -07:00
John Stebbins
eeef870851 lavc/movtextenc: add option to scale fontsize with height
If the video dimensions are different than the ASS play_res then the
font sizes need to be adjusted to get the same apparent render size.

Signed-off-by: Philip Langdale <philipl@overt.org>
2020-04-10 09:32:13 -07:00
John Stebbins
1f8278ee24 lavc/movtextenc: add font name handling
Initializes the mov text sample description from the ASS header and
creates an mov font table from the fonts available in the ASS Styles.

Signed-off-by: Philip Langdale <philipl@overt.org>
2020-04-10 09:32:13 -07:00
John Stebbins
dbdbcbf384 lavc/movtextenc: simplify initialization of new style record
Signed-off-by: Philip Langdale <philipl@overt.org>
2020-04-10 09:32:13 -07:00
John Stebbins
bb8fd04665 lavc/movtextenc: handle cancel overrides callback
Signed-off-by: Philip Langdale <philipl@overt.org>
2020-04-10 09:32:13 -07:00
John Stebbins
848792be60 lavc/movtextenc: add font size tag handling
Signed-off-by: Philip Langdale <philipl@overt.org>
2020-04-10 09:32:13 -07:00
John Stebbins
2e79843e37 lavc/movtextenc: add alpha tag handling
Signed-off-by: Philip Langdale <philipl@overt.org>
2020-04-10 09:32:13 -07:00
John Stebbins
b847bd9582 lavc/movtextenc: add color tag handling
Signed-off-by: Philip Langdale <philipl@overt.org>
2020-04-10 09:32:13 -07:00
John Stebbins
37ab5e2e7b lavc/movtextenc: init style record from ASS dialog style
Signed-off-by: Philip Langdale <philipl@overt.org>
2020-04-10 09:32:13 -07:00
John Stebbins
a129cc9e29 lavc/movtextenc: fix unclosed style records
The last record at the end of each dialog was never closed

Signed-off-by: Philip Langdale <philipl@overt.org>
2020-04-10 09:32:13 -07:00
John Stebbins
1bf0df4c4f lavc/movtextenc: simplify style record updates
Makes style update code easier to extend for style types not yet handled

Signed-off-by: Philip Langdale <philipl@overt.org>
2020-04-10 09:32:13 -07:00
John Stebbins
15b81f5e6b lavc/movtextenc: keep values in native byte order till written
Signed-off-by: Philip Langdale <philipl@overt.org>
2020-04-10 09:32:13 -07:00
John Stebbins
32cf264d8f lavc/movtextenc: use correct color component order
Signed-off-by: Philip Langdale <philipl@overt.org>
2020-04-10 09:32:13 -07:00
Philip Langdale
af043b839c movtextenc: fix handling of utf-8 subtitles
See the earlier fix for movtextdec for details. The equivalent bug is
present on the encoder side as well.

We need to track the text length in 'characters' (which seems to really
mean codepoints) to ensure that styles are applied across the correct
ranges.
2018-03-29 20:46:47 -07:00
Philip Langdale
f95c81ce10 avcodec/movtextenc: Ignore unmatched closing style tags
The existing code will segfault if a closing tag shows up when there
was never an opening tag. This isn't a well formed style, but it's also
not a reason to crash.

Fixes: https://trac.ffmpeg.org/ticket/6303
2017-04-23 10:46:11 -07:00
Clément Bœsch
b5451d88cf lavc: reindent a few decoders after previous commits 2016-02-26 22:15:20 +01:00
Clément Bœsch
22ebbda637 lavc: deprecate decoded ass subtitles with timings 2016-02-26 21:53:34 +01:00