diff mbox series

[FFmpeg-devel,v4,04/18] avcodec/avcodec: Add av_get_subtitle_format_from_codecdesc function

Message ID MN2PR04MB5981822E377B62A8873676D6BAD79@MN2PR04MB5981.namprd04.prod.outlook.com
State New
Headers show
Series [FFmpeg-devel,v4,01/18] avutil/frame: Subtitle Filtering - Add AVMediaType property to AVFrame
Related show

Commit Message

Soft Works Sept. 11, 2021, 8:16 a.m. UTC
Introduce a single place for deriving an AVSubtitleType
from AV_CODEC_PROP_xxx

Signed-off-by: softworkz <softworkz@hotmail.com>
---
 libavcodec/avcodec.h |  8 ++++++++
 libavcodec/decode.c  |  5 +----
 libavcodec/utils.c   | 11 +++++++++++
 3 files changed, 20 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index b459c23ac7..0f71b42d61 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3059,6 +3059,14 @@  void avcodec_flush_buffers(AVCodecContext *avctx);
  */
 int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes);
 
+/**
+ * Return subtitle format from a codec descriptor
+ *
+ * @param codec_descriptor codec descriptor
+ * @return                 the subtitle type (e.g. bitmap, text)
+ */
+enum AVSubtitleType av_get_subtitle_format_from_codecdesc(const AVCodecDescriptor *codec_descriptor);
+
 /* memory */
 
 /**
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 643f9d6a30..dfec9711ed 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -841,10 +841,7 @@  int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
                                                  avctx->pkt_timebase, ms);
         }
 
-        if (avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB)
-            sub->format = 0;
-        else if (avctx->codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB)
-            sub->format = 1;
+        sub->format = av_get_subtitle_format_from_codecdesc(avctx->codec_descriptor);
 
         for (unsigned i = 0; i < sub->num_rects; i++) {
             if (avctx->sub_charenc_mode != FF_SUB_CHARENC_MODE_IGNORE &&
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index cfc07cbcb8..767dfabd1e 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -818,6 +818,17 @@  int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
     return FFMAX(0, duration);
 }
 
+enum AVSubtitleType av_get_subtitle_format_from_codecdesc(const AVCodecDescriptor *codec_descriptor)
+{
+    if(codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB)
+        return AV_SUBTITLE_FMT_BITMAP;
+
+    if(codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB)
+        return AV_SUBTITLE_FMT_ASS;
+
+    return AV_SUBTITLE_FMT_UNKNOWN;
+}
+
 int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
 {
     int duration = get_audio_frame_duration(par->codec_id, par->sample_rate,