h264: add decode_nalu() helper function.
authorGwenole Beauchesne <gwenole.beauchesne@intel.com>
Wed, 10 Oct 2012 08:35:20 +0000 (10:35 +0200)
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>
Fri, 16 Nov 2012 15:50:30 +0000 (16:50 +0100)
Split decode_buffer() into the core infrastructure that determines
the NAL units contained in the adapter and the actual function that
decodes the NAL unit.

gst-libs/gst/vaapi/gstvaapidecoder_h264.c

index a3af794..fc6cbf8 100644 (file)
@@ -2214,6 +2214,45 @@ scan_for_start_code(GstAdapter *adapter, guint ofs, guint size, guint32 *scp)
 }
 
 static GstVaapiDecoderStatus
+decode_nalu(GstVaapiDecoderH264 *decoder, GstH264NalUnit *nalu)
+{
+    GstVaapiDecoderStatus status;
+
+    switch (nalu->type) {
+    case GST_H264_NAL_SLICE_IDR:
+        /* fall-through. IDR specifics are handled in init_picture() */
+    case GST_H264_NAL_SLICE:
+        status = decode_slice(decoder, nalu);
+        break;
+    case GST_H264_NAL_SPS:
+        status = decode_sps(decoder, nalu);
+        break;
+    case GST_H264_NAL_PPS:
+        status = decode_pps(decoder, nalu);
+        break;
+    case GST_H264_NAL_SEI:
+        status = decode_sei(decoder, nalu);
+        break;
+    case GST_H264_NAL_SEQ_END:
+        status = decode_sequence_end(decoder);
+        break;
+    case GST_H264_NAL_AU_DELIMITER:
+        /* skip all Access Unit NALs */
+        status = GST_VAAPI_DECODER_STATUS_SUCCESS;
+        break;
+    case GST_H264_NAL_FILLER_DATA:
+        /* skip all Filler Data NALs */
+        status = GST_VAAPI_DECODER_STATUS_SUCCESS;
+        break;
+    default:
+        GST_WARNING("unsupported NAL unit type %d", nalu->type);
+        status = GST_VAAPI_DECODER_STATUS_ERROR_BITSTREAM_PARSER;
+        break;
+    }
+    return status;
+}
+
+static GstVaapiDecoderStatus
 decode_buffer(GstVaapiDecoderH264 *decoder, GstBuffer *buffer)
 {
     GstVaapiDecoderH264Private * const priv = decoder->priv;
@@ -2298,42 +2337,8 @@ decode_buffer(GstVaapiDecoderH264 *decoder, GstBuffer *buffer)
             );
         }
         status = get_status(result);
-        if (status != GST_VAAPI_DECODER_STATUS_SUCCESS) {
-            gst_buffer_unref(buffer);
-            break;
-        }
-
-        switch (nalu.type) {
-        case GST_H264_NAL_SLICE_IDR:
-            /* fall-through. IDR specifics are handled in init_picture() */
-        case GST_H264_NAL_SLICE:
-            status = decode_slice(decoder, &nalu);
-            break;
-        case GST_H264_NAL_SPS:
-            status = decode_sps(decoder, &nalu);
-            break;
-        case GST_H264_NAL_PPS:
-            status = decode_pps(decoder, &nalu);
-            break;
-        case GST_H264_NAL_SEI:
-            status = decode_sei(decoder, &nalu);
-            break;
-        case GST_H264_NAL_SEQ_END:
-            status = decode_sequence_end(decoder);
-            break;
-        case GST_H264_NAL_AU_DELIMITER:
-            /* skip all Access Unit NALs */
-            status = GST_VAAPI_DECODER_STATUS_SUCCESS;
-            break;
-        case GST_H264_NAL_FILLER_DATA:
-            /* skip all Filler Data NALs */
-            status = GST_VAAPI_DECODER_STATUS_SUCCESS;
-            break;
-        default:
-            GST_WARNING("unsupported NAL unit type %d", nalu.type);
-            status = GST_VAAPI_DECODER_STATUS_ERROR_BITSTREAM_PARSER;
-            break;
-        }
+        if (status == GST_VAAPI_DECODER_STATUS_SUCCESS)
+            status = decode_nalu(decoder, &nalu);
         gst_buffer_unref(buffer);
     } while (status == GST_VAAPI_DECODER_STATUS_SUCCESS);