diff mbox series

[FFmpeg-devel] avcodec/cbs_av1: add a function to return an upscaled frame width

Message ID 20200823233916.14262-1-jamrial@gmail.com
State New
Headers show
Series [FFmpeg-devel] avcodec/cbs_av1: add a function to return an upscaled frame width
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

James Almer Aug. 23, 2020, 11:39 p.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/cbs_av1.c | 12 ++++++++++++
 libavcodec/cbs_av1.h |  5 +++++
 2 files changed, 17 insertions(+)
diff mbox series

Patch

diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c
index 72ad18151e..726a2211da 100644
--- a/libavcodec/cbs_av1.c
+++ b/libavcodec/cbs_av1.c
@@ -1247,6 +1247,18 @@  static void cbs_av1_close(CodedBitstreamContext *ctx)
     av_buffer_unref(&priv->frame_header_ref);
 }
 
+int ff_cbs_av1_get_frame_width(const AV1RawFrameHeader *frame)
+{
+    int denom, frame_width = frame->frame_width_minus_1 + 1;
+
+    if (!frame->use_superres)
+        return frame_width;
+
+    denom = frame->coded_denom + AV1_SUPERRES_DENOM_MIN;
+
+    return (frame_width * AV1_SUPERRES_NUM + denom / 2) / denom;
+}
+
 const CodedBitstreamType ff_cbs_type_av1 = {
     .codec_id          = AV_CODEC_ID_AV1,
 
diff --git a/libavcodec/cbs_av1.h b/libavcodec/cbs_av1.h
index 704a231209..fa41af666f 100644
--- a/libavcodec/cbs_av1.h
+++ b/libavcodec/cbs_av1.h
@@ -445,4 +445,9 @@  typedef struct CodedBitstreamAV1Context {
 } CodedBitstreamAV1Context;
 
 
+/**
+ * Return the frame's width with superres upscaling applied, if any.
+ */
+int ff_cbs_av1_get_frame_width(const AV1RawFrameHeader *frame);
+
 #endif /* AVCODEC_CBS_AV1_H */