]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/hevc_parser.c
libopenh264dec: Export the decoded profile and level in AVCodecContext
[ffmpeg] / libavcodec / hevc_parser.c
index b68ceb985e29e883dcbddf96921ea4694bce8484..5129e3a9c1e46142a0a1c45a9e3175831268e077 100644 (file)
@@ -22,7 +22,8 @@
 
 #include "libavutil/common.h"
 
-#include "golomb.h"
+#include "golomb_legacy.h"
+#include "hevc.h"
 #include "hevcdec.h"
 #include "h2645_parse.h"
 #include "parser.h"
@@ -48,6 +49,7 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal,
 
     HEVCPPS *pps;
     HEVCSPS *sps;
+    HEVCWindow *ow;
     unsigned int pps_id;
 
     get_bits1(gb);          // first slice in pic
@@ -55,18 +57,19 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal,
         get_bits1(gb);      // no output of prior pics
 
     pps_id = get_ue_golomb_long(gb);
-    if (pps_id >= MAX_PPS_COUNT || !ctx->ps.pps_list[pps_id]) {
+    if (pps_id >= HEVC_MAX_PPS_COUNT || !ctx->ps.pps_list[pps_id]) {
         av_log(avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id);
         return AVERROR_INVALIDDATA;
     }
     pps = (HEVCPPS*)ctx->ps.pps_list[pps_id]->data;
     sps = (HEVCSPS*)ctx->ps.sps_list[pps->sps_id]->data;
+    ow  = &sps->output_window;
 
     /* export the stream parameters */
     s->coded_width  = sps->width;
     s->coded_height = sps->height;
-    s->width        = sps->output_width;
-    s->height       = sps->output_height;
+    s->width        = sps->width  - ow->left_offset - ow->right_offset;
+    s->height       = sps->height - ow->top_offset  - ow->bottom_offset;
     s->format       = sps->pix_fmt;
     avctx->profile  = sps->ptl.general_ptl.profile_idc;
     avctx->level    = sps->ptl.general_ptl.level_idc;
@@ -92,25 +95,25 @@ static int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf,
 
         /* ignore everything except parameter sets and VCL NALUs */
         switch (nal->type) {
-        case NAL_VPS: ff_hevc_decode_nal_vps(&nal->gb, avctx, &ctx->ps);    break;
-        case NAL_SPS: ff_hevc_decode_nal_sps(&nal->gb, avctx, &ctx->ps, 1); break;
-        case NAL_PPS: ff_hevc_decode_nal_pps(&nal->gb, avctx, &ctx->ps);    break;
-        case NAL_TRAIL_R:
-        case NAL_TRAIL_N:
-        case NAL_TSA_N:
-        case NAL_TSA_R:
-        case NAL_STSA_N:
-        case NAL_STSA_R:
-        case NAL_BLA_W_LP:
-        case NAL_BLA_W_RADL:
-        case NAL_BLA_N_LP:
-        case NAL_IDR_W_RADL:
-        case NAL_IDR_N_LP:
-        case NAL_CRA_NUT:
-        case NAL_RADL_N:
-        case NAL_RADL_R:
-        case NAL_RASL_N:
-        case NAL_RASL_R: hevc_parse_slice_header(s, nal, avctx); break;
+        case HEVC_NAL_VPS: ff_hevc_decode_nal_vps(&nal->gb, avctx, &ctx->ps);    break;
+        case HEVC_NAL_SPS: ff_hevc_decode_nal_sps(&nal->gb, avctx, &ctx->ps, 1); break;
+        case HEVC_NAL_PPS: ff_hevc_decode_nal_pps(&nal->gb, avctx, &ctx->ps);    break;
+        case HEVC_NAL_TRAIL_R:
+        case HEVC_NAL_TRAIL_N:
+        case HEVC_NAL_TSA_N:
+        case HEVC_NAL_TSA_R:
+        case HEVC_NAL_STSA_N:
+        case HEVC_NAL_STSA_R:
+        case HEVC_NAL_BLA_W_LP:
+        case HEVC_NAL_BLA_W_RADL:
+        case HEVC_NAL_BLA_N_LP:
+        case HEVC_NAL_IDR_W_RADL:
+        case HEVC_NAL_IDR_N_LP:
+        case HEVC_NAL_CRA_NUT:
+        case HEVC_NAL_RADL_N:
+        case HEVC_NAL_RADL_R:
+        case HEVC_NAL_RASL_N:
+        case HEVC_NAL_RASL_R: hevc_parse_slice_header(s, nal, avctx); break;
         }
     }
 
@@ -138,19 +141,19 @@ static int hevc_find_frame_end(AVCodecParserContext *s, const uint8_t *buf,
 
         nut = (pc->state64 >> 2 * 8 + 1) & 0x3F;
         // Beginning of access unit
-        if ((nut >= NAL_VPS && nut <= NAL_AUD) || nut == NAL_SEI_PREFIX ||
+        if ((nut >= HEVC_NAL_VPS && nut <= HEVC_NAL_AUD) || nut == HEVC_NAL_SEI_PREFIX ||
             (nut >= 41 && nut <= 44) || (nut >= 48 && nut <= 55)) {
             if (pc->frame_start_found) {
                 pc->frame_start_found = 0;
                 return i - 5;
             }
-        } else if (nut <= NAL_RASL_R ||
-                   (nut >= NAL_BLA_W_LP && nut <= NAL_CRA_NUT)) {
+        } else if (nut <= HEVC_NAL_RASL_R ||
+                   (nut >= HEVC_NAL_BLA_W_LP && nut <= HEVC_NAL_CRA_NUT)) {
             int first_slice_segment_in_pic_flag = buf[i] >> 7;
             if (first_slice_segment_in_pic_flag) {
                 if (!pc->frame_start_found) {
                     pc->frame_start_found = 1;
-                    s->key_frame = nut >= NAL_BLA_W_LP && nut <= NAL_CRA_NUT;
+                    s->key_frame = nut >= HEVC_NAL_BLA_W_LP && nut <= HEVC_NAL_CRA_NUT;
                 } else { // First slice of next frame found
                     pc->frame_start_found = 0;
                     return i - 5;
@@ -205,7 +208,7 @@ static int hevc_split(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
         state = (state << 8) | buf[i];
         if (((state >> 8) & 0xFFFFFF) == START_CODE) {
             int nut = (state >> 1) & 0x3F;
-            if (nut >= NAL_VPS && nut <= NAL_PPS)
+            if (nut >= HEVC_NAL_VPS && nut <= HEVC_NAL_PPS)
                 has_ps = 1;
             else if (has_ps)
                 return i - 3;