---
 libavcodec/hevc.c     | 17 +++++++++++++++++
 libavcodec/hevc.h     |  4 ++++
 libavcodec/hevc_sei.c | 17 +++++++++++++++++
 3 files changed, 38 insertions(+)

diff --git a/libavcodec/hevc.c b/libavcodec/hevc.c
index 49ed285..9b9328f 100644
--- a/libavcodec/hevc.c
+++ b/libavcodec/hevc.c
@@ -25,6 +25,7 @@
 
 #include "libavutil/attributes.h"
 #include "libavutil/common.h"
+#include "libavutil/display.h"
 #include "libavutil/internal.h"
 #include "libavutil/md5.h"
 #include "libavutil/opt.h"
@@ -2456,6 +2457,22 @@ static int set_side_data(HEVCContext *s)
             stereo->flags = AV_STEREO3D_FLAG_INVERT;
     }
 
+    if (s->sei_display_orientation_present && s->sei_anticlockwise_rotation) {
+        double angle = s->sei_anticlockwise_rotation * 360 / (1 << 16);
+        AVFrameSideData *rotation = av_frame_new_side_data(out,
+                                                           
AV_FRAME_DATA_DISPLAYMATRIX,
+                                                           sizeof(int32_t) * 3 
* 3);
+        uint8_t *display_matrix = av_display_angle_to_matrix(angle);
+
+        if (!rotation || !display_matrix) {
+            av_free(rotation);
+            av_free(display_matrix);
+            return AVERROR(ENOMEM);
+        }
+        memcpy(rotation->data, display_matrix, sizeof(int32_t) * 3 * 3);
+        av_free(display_matrix);
+    }
+
     return 0;
 }
 
diff --git a/libavcodec/hevc.h b/libavcodec/hevc.h
index 1197d08..ed2a937 100644
--- a/libavcodec/hevc.h
+++ b/libavcodec/hevc.h
@@ -861,6 +861,10 @@ typedef struct HEVCContext {
     int frame_packing_arrangement_type;
     int content_interpretation_type;
     int quincunx_subsampling;
+
+    /** display orientation */
+    int sei_display_orientation_present;
+    int sei_anticlockwise_rotation;
 } HEVCContext;
 
 int ff_hevc_decode_short_term_rps(HEVCContext *s, ShortTermRPS *rps,
diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
index b011596..3b52a96 100644
--- a/libavcodec/hevc_sei.c
+++ b/libavcodec/hevc_sei.c
@@ -71,6 +71,21 @@ static void 
decode_nal_sei_frame_packing_arrangement(HEVCContext *s)
     skip_bits1(gb);             // upsampled_aspect_ratio_flag
 }
 
+static void decode_nal_sei_display_orientation(HEVCContext *s)
+{
+    GetBitContext *gb = &s->HEVClc.gb;
+
+    s->sei_display_orientation_present = !get_bits1(gb);
+
+    if (s->sei_display_orientation_present) {
+        skip_bits1(gb);     // hor_flip
+        skip_bits1(gb);     // ver_flip
+
+        s->sei_anticlockwise_rotation = get_bits(gb, 16);
+        skip_bits1(gb);     // display_orientation_persistence_flag
+    }
+}
+
 static int decode_nal_sei_message(HEVCContext *s)
 {
     GetBitContext *gb = &s->HEVClc.gb;
@@ -94,6 +109,8 @@ static int decode_nal_sei_message(HEVCContext *s)
             decode_nal_sei_decoded_picture_hash(s);
         else if (payload_type == 45)
             decode_nal_sei_frame_packing_arrangement(s);
+        else if (payload_type == 47)
+            decode_nal_sei_display_orientation(s);
         else {
             av_log(s->avctx, AV_LOG_DEBUG, "Skipped PREFIX SEI %d\n", 
payload_type);
             skip_bits(gb, 8 * payload_size);
-- 
1.8.3.4 (Apple Git-47)

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to