summaryrefslogtreecommitdiff
path: root/libavcodec/movtextenc.c
Commit message (Collapse)AuthorAge
* avcodec: Make init-threadsafety the defaultAndreas Rheinhardt2022-07-18
| | | | | | | | | | | 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>
* avcodec/codec_internal: Use union for FFCodec decode/encode callbacksAndreas Rheinhardt2022-04-05
| | | | | | | | | | | 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>
* avcodec/codec_internal: Add FFCodec, hide internal part of AVCodecAndreas Rheinhardt2022-03-21
| | | | | | | | | | | | | | | | 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>
* avcodec/internal: Move FF_CODEC_CAP_* to a new header codec_internal.hAndreas Rheinhardt2022-03-21
| | | | | | | | | | 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>
* avcodec/movtextenc: Check for existence of font name before using itCharlie Monroe2021-12-11
| | | | | | | | 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>
* avcodec/movtextenc: Simplify writing a single charAndreas Rheinhardt2021-12-02
| | | | | Reviewed-by: Philip Langdale <philipl@overt.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/movtextenc: Remove redundant byte countAndreas Rheinhardt2021-12-02
| | | | | | | Use the AVBPrint's len instead. Reviewed-by: Philip Langdale <philipl@overt.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/movtextenc: Fix encoding of subtitles with multiple rectsAndreas Rheinhardt2021-12-02
| | | | | | | | | | | | | | | | | | | | | | | | 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>
* avcodec/movtextenc: Check for too long subtitlesAndreas Rheinhardt2021-12-02
| | | | | Reviewed-by: Philip Langdale <philipl@overt.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/movtextenc: Reset AVBPrint at the beginning, not end of encodingAndreas Rheinhardt2021-12-02
| | | | | | | | | 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>
* avcodec/movtextenc: Fix infinite loop due to variable truncationAndreas Rheinhardt2021-12-02
| | | | | | | | Regression since af043b839c38e850af1184fd6be691f8475c048e. Fixes ticket #9409. Reviewed-by: Philip Langdale <philipl@overt.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/ass_split: Rename ff_ass_split_dialog2->ff_ass_split_dialogAndreas Rheinhardt2021-08-08
| | | | | Reviewed-by: James Almer <jamrial@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* Remove unnecessary avassert.h inclusionsAndreas Rheinhardt2021-07-22
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/movtextenc, srtenc, webvttenc: Mark encoders as init-threadsafeAndreas Rheinhardt2021-05-02
| | | | | | They all rely on ff_ass_split(), which does not have any static state. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec: Constify AVCodecsAndreas Rheinhardt2021-04-27
| | | | | | | | | | 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>
* avcodec/(movtext|srt|ttml|webvtt)enc: Reindent after previous commitAndreas Rheinhardt2021-04-27
| | | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec: Remove deprecated ASS with inline timingAndreas Rheinhardt2021-04-27
| | | | | | | Deprecated in 22ebbda637257a432c99330ca4c6024665418f0e. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/movtextenc: Check for too many stylesAndreas Rheinhardt2021-02-24
| | | | | | | | | 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>
* avcodec/movtextenc: Cleanup generically on init failureAndreas Rheinhardt2020-10-19
| | | | | Reviewed-by: Philip Langdale <philipl@overt.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/movtextenc: Remove redundant function parametersAndreas Rheinhardt2020-10-19
| | | | | | | | | | | 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>
* avcodec/movtextenc: Simplify writing to AVBPrintAndreas Rheinhardt2020-10-19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* avcodec/movtextenc: Fix undefined left shifts outside the range of intAndreas Rheinhardt2020-10-19
| | | | | Reviewed-by: Philip Langdale <philipl@overt.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/movtextenc: Fix memleak on (re)allocation errorAndreas Rheinhardt2020-10-19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* avcodec/movtextenc: Don't presume every style to have a fontAndreas Rheinhardt2020-10-19
| | | | | | | | | 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>
* avcodec/movtextenc: Reset array counter after freeing arrayAndreas Rheinhardt2020-10-19
| | | | | | | | | 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>
* avcodec/movtextenc: Fix potential use of uninitialized valueAndreas Rheinhardt2020-10-19
| | | | | | | | | | 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>
* avcodec/movtextenc: cosmeticsAndriy Gelman2020-10-15
| | | | | | Change pointer position. Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
* avcodec/movtextenc: fix writing to bytestream on BE archesAndriy Gelman2020-10-15
| | | | | | | | | | | | | | | | | | 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>
* lavc/movtextenc: return more meaningful error codesJohn Stebbins2020-04-10
| | | | Signed-off-by: Philip Langdale <philipl@overt.org>
* lavc/movtextenc: handle changes to hilight alphaJohn Stebbins2020-04-10
| | | | Signed-off-by: Philip Langdale <philipl@overt.org>
* lavc/movtextenc: add option to scale fontsize with heightJohn Stebbins2020-04-10
| | | | | | | 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>
* lavc/movtextenc: add font name handlingJohn Stebbins2020-04-10
| | | | | | | 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>
* lavc/movtextenc: simplify initialization of new style recordJohn Stebbins2020-04-10
| | | | Signed-off-by: Philip Langdale <philipl@overt.org>
* lavc/movtextenc: handle cancel overrides callbackJohn Stebbins2020-04-10
| | | | Signed-off-by: Philip Langdale <philipl@overt.org>
* lavc/movtextenc: add font size tag handlingJohn Stebbins2020-04-10
| | | | Signed-off-by: Philip Langdale <philipl@overt.org>
* lavc/movtextenc: add alpha tag handlingJohn Stebbins2020-04-10
| | | | Signed-off-by: Philip Langdale <philipl@overt.org>
* lavc/movtextenc: add color tag handlingJohn Stebbins2020-04-10
| | | | Signed-off-by: Philip Langdale <philipl@overt.org>
* lavc/movtextenc: init style record from ASS dialog styleJohn Stebbins2020-04-10
| | | | Signed-off-by: Philip Langdale <philipl@overt.org>
* lavc/movtextenc: fix unclosed style recordsJohn Stebbins2020-04-10
| | | | | | The last record at the end of each dialog was never closed Signed-off-by: Philip Langdale <philipl@overt.org>
* lavc/movtextenc: simplify style record updatesJohn Stebbins2020-04-10
| | | | | | Makes style update code easier to extend for style types not yet handled Signed-off-by: Philip Langdale <philipl@overt.org>
* lavc/movtextenc: keep values in native byte order till writtenJohn Stebbins2020-04-10
| | | | Signed-off-by: Philip Langdale <philipl@overt.org>
* lavc/movtextenc: use correct color component orderJohn Stebbins2020-04-10
| | | | Signed-off-by: Philip Langdale <philipl@overt.org>
* movtextenc: fix handling of utf-8 subtitlesPhilip Langdale2018-03-29
| | | | | | | | | 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.
* avcodec/movtextenc: Ignore unmatched closing style tagsPhilip Langdale2017-04-23
| | | | | | | | 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
* lavc: reindent a few decoders after previous commitsClément Bœsch2016-02-26
|
* lavc: deprecate decoded ass subtitles with timingsClément Bœsch2016-02-26
|
* lavc: allow subtitle text format to be ASS without timingClément Bœsch2016-02-26
|
* Merge commit '059a934806d61f7af9ab3fd9f74994b838ea5eba'Michael Niedermayer2015-07-27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * commit '059a934806d61f7af9ab3fd9f74994b838ea5eba': lavc: Consistently prefix input buffer defines Conflicts: doc/examples/decoding_encoding.c libavcodec/4xm.c libavcodec/aac_adtstoasc_bsf.c libavcodec/aacdec.c libavcodec/aacenc.c libavcodec/ac3dec.h libavcodec/asvenc.c libavcodec/avcodec.h libavcodec/avpacket.c libavcodec/dvdec.c libavcodec/ffv1enc.c libavcodec/g2meet.c libavcodec/gif.c libavcodec/h264.c libavcodec/h264_mp4toannexb_bsf.c libavcodec/huffyuvdec.c libavcodec/huffyuvenc.c libavcodec/jpeglsenc.c libavcodec/libxvid.c libavcodec/mdec.c libavcodec/motionpixels.c libavcodec/mpeg4videodec.c libavcodec/mpegvideo.c libavcodec/noise_bsf.c libavcodec/nuv.c libavcodec/nvenc.c libavcodec/options.c libavcodec/parser.c libavcodec/pngenc.c libavcodec/proresenc_kostya.c libavcodec/qsvdec.c libavcodec/svq1enc.c libavcodec/tiffenc.c libavcodec/truemotion2.c libavcodec/utils.c libavcodec/utvideoenc.c libavcodec/vc1dec.c libavcodec/wmalosslessdec.c libavformat/adxdec.c libavformat/aiffdec.c libavformat/apc.c libavformat/apetag.c libavformat/avidec.c libavformat/bink.c libavformat/cafdec.c libavformat/flvdec.c libavformat/id3v2.c libavformat/isom.c libavformat/matroskadec.c libavformat/mov.c libavformat/mpc.c libavformat/mpc8.c libavformat/mpegts.c libavformat/mvi.c libavformat/mxfdec.c libavformat/mxg.c libavformat/nutdec.c libavformat/oggdec.c libavformat/oggparsecelt.c libavformat/oggparseflac.c libavformat/oggparseopus.c libavformat/oggparsespeex.c libavformat/omadec.c libavformat/rawdec.c libavformat/riffdec.c libavformat/rl2.c libavformat/rmdec.c libavformat/rtpdec_latm.c libavformat/rtpdec_mpeg4.c libavformat/rtpdec_qdm2.c libavformat/rtpdec_svq3.c libavformat/sierravmd.c libavformat/smacker.c libavformat/smush.c libavformat/spdifenc.c libavformat/takdec.c libavformat/tta.c libavformat/utils.c libavformat/vqf.c libavformat/westwood_vqa.c libavformat/xmv.c libavformat/xwma.c libavformat/yop.c Merged-by: Michael Niedermayer <michael@niedermayer.cc>
* movtextenc.c: Add support for text highlightingNiklesh2015-07-21
| | | | | | This patch takes care of the secondary color changes in ASS through highlight and hilightcolor boxes. Signed-off-by: Niklesh <niklesh.lalwani@iitb.ac.in>
* movtextenc.c: Reorganize the code for easier maintenanceNiklesh2015-07-21
| | | | | | This patch reorganizes the code to make it easier to add support for different text modifier boxes and other styles in the future. Signed-off-by: Niklesh <niklesh.lalwani@iitb.ac.in>