]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/h264_sei.c
ape: Support _0000 files with nblock smaller than 64
[ffmpeg] / libavcodec / h264_sei.c
index 6fca2c32a9f6b74a816304f06bd6cb8a4d4ebc38..52ff2ff4bb086948926ae8a1e349d22eccb40a1d 100644 (file)
@@ -41,6 +41,7 @@ void ff_h264_reset_sei(H264Context *h)
     h->sei_cpb_removal_delay        = -1;
     h->sei_buffering_period_present =  0;
     h->sei_frame_packing_present    =  0;
+    h->sei_display_orientation_present = 0;
 }
 
 static int decode_picture_timing(H264Context *h)
@@ -199,20 +200,42 @@ static int decode_frame_packing_arrangement(H264Context *h)
     return 0;
 }
 
+static int decode_display_orientation(H264Context *h)
+{
+    h->sei_display_orientation_present = !get_bits1(&h->gb);
+
+    if (h->sei_display_orientation_present) {
+        h->sei_hflip = get_bits1(&h->gb);     // hor_flip
+        h->sei_vflip = get_bits1(&h->gb);     // ver_flip
+
+        h->sei_anticlockwise_rotation = get_bits(&h->gb, 16);
+        get_ue_golomb(&h->gb);  // display_orientation_repetition_period
+        skip_bits1(&h->gb);     // display_orientation_extension_flag
+    }
+
+    return 0;
+}
+
 int ff_h264_decode_sei(H264Context *h)
 {
     while (get_bits_left(&h->gb) > 16) {
         int size = 0;
         int type = 0;
         int ret  = 0;
+        int last = 0;
 
-        do
-            type += show_bits(&h->gb, 8);
-        while (get_bits(&h->gb, 8) == 255);
+        while (get_bits_left(&h->gb) >= 8 &&
+               (last = get_bits(&h->gb, 8)) == 255) {
+            type += 255;
+        }
+        type += last;
 
-        do
-            size += show_bits(&h->gb, 8);
-        while (get_bits(&h->gb, 8) == 255);
+        last = 0;
+        while (get_bits_left(&h->gb) >= 8 &&
+               (last = get_bits(&h->gb, 8)) == 255) {
+            size += 255;
+        }
+        size += last;
 
         if (size > get_bits_left(&h->gb) / 8) {
             av_log(h->avctx, AV_LOG_ERROR, "SEI type %d truncated at %d\n",
@@ -246,6 +269,11 @@ int ff_h264_decode_sei(H264Context *h)
             if (ret < 0)
                 return ret;
             break;
+        case SEI_TYPE_DISPLAY_ORIENTATION:
+            ret = decode_display_orientation(h);
+            if (ret < 0)
+                return ret;
+            break;
         default:
             av_log(h->avctx, AV_LOG_DEBUG, "unknown SEI type %d\n", type);
             skip_bits(&h->gb, 8 * size);