[vlc-commits] packetizer: hevc: rework storage

Francois Cartegnie git at videolan.org
Tue Jan 16 21:55:31 CET 2018


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Jan 16 19:00:12 2018 +0100| [23be3d9a4654c1e18d13c30ddedf463ee1f1562f] | committer: Francois Cartegnie

packetizer: hevc: rework storage

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=23be3d9a4654c1e18d13c30ddedf463ee1f1562f
---

 modules/packetizer/hevc.c | 154 +++++++++++++++++++++++++---------------------
 1 file changed, 84 insertions(+), 70 deletions(-)

diff --git a/modules/packetizer/hevc.c b/modules/packetizer/hevc.c
index 6f7c4b945b..9e22003144 100644
--- a/modules/packetizer/hevc.c
+++ b/modules/packetizer/hevc.c
@@ -85,9 +85,15 @@ struct decoder_sys_t
     } frame, pre, post;
 
     uint8_t  i_nal_length_size;
-    hevc_video_parameter_set_t    *rgi_p_decvps[HEVC_VPS_ID_MAX + 1];
-    hevc_sequence_parameter_set_t *rgi_p_decsps[HEVC_SPS_ID_MAX + 1];
-    hevc_picture_parameter_set_t  *rgi_p_decpps[HEVC_PPS_ID_MAX + 1];
+
+    struct
+    {
+        block_t *p_nal;
+        void *p_decoded;
+    } rg_vps[HEVC_VPS_ID_MAX + 1],
+      rg_sps[HEVC_SPS_ID_MAX + 1],
+      rg_pps[HEVC_PPS_ID_MAX + 1];
+
     const hevc_video_parameter_set_t    *p_active_vps;
     const hevc_sequence_parameter_set_t *p_active_sps;
     const hevc_picture_parameter_set_t  *p_active_pps;
@@ -253,20 +259,26 @@ static void Close(vlc_object_t *p_this)
 
     for(unsigned i=0;i<=HEVC_PPS_ID_MAX; i++)
     {
-        if(p_sys->rgi_p_decpps[i])
-            hevc_rbsp_release_pps(p_sys->rgi_p_decpps[i]);
+        if(p_sys->rg_pps[i].p_decoded)
+            hevc_rbsp_release_pps(p_sys->rg_pps[i].p_decoded);
+        if(p_sys->rg_pps[i].p_nal)
+            block_Release(p_sys->rg_pps[i].p_nal);
     }
 
     for(unsigned i=0;i<=HEVC_SPS_ID_MAX; i++)
     {
-        if(p_sys->rgi_p_decsps[i])
-            hevc_rbsp_release_sps(p_sys->rgi_p_decsps[i]);
+        if(p_sys->rg_sps[i].p_decoded)
+            hevc_rbsp_release_sps(p_sys->rg_sps[i].p_decoded);
+        if(p_sys->rg_sps[i].p_nal)
+            block_Release(p_sys->rg_sps[i].p_nal);
     }
 
     for(unsigned i=0;i<=HEVC_VPS_ID_MAX; i++)
     {
-        if(p_sys->rgi_p_decvps[i])
-            hevc_rbsp_release_vps(p_sys->rgi_p_decvps[i]);
+        if(p_sys->rg_vps[i].p_decoded)
+            hevc_rbsp_release_vps(p_sys->rg_vps[i].p_decoded);
+        if(p_sys->rg_vps[i].p_nal)
+            block_Release(p_sys->rg_vps[i].p_nal);
     }
 
     hevc_release_sei_pic_timing( p_sys->p_timing );
@@ -332,56 +344,56 @@ static bool InsertXPS(decoder_t *p_dec, uint8_t i_nal_type, uint8_t i_id,
                       const block_t *p_nalb)
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
-    bool b_active = false;
+    void **pp_decoded;
+    block_t **pp_nal;
 
     switch(i_nal_type)
     {
         case HEVC_NAL_VPS:
             if(i_id > HEVC_VPS_ID_MAX)
                 return false;
+            pp_decoded = &p_sys->rg_vps[i_id].p_decoded;
+            pp_nal = &p_sys->rg_vps[i_id].p_nal;
             break;
         case HEVC_NAL_SPS:
             if(i_id > HEVC_SPS_ID_MAX)
                 return false;
+            pp_decoded = &p_sys->rg_sps[i_id].p_decoded;
+            pp_nal = &p_sys->rg_sps[i_id].p_nal;
             break;
         case HEVC_NAL_PPS:
             if(i_id > HEVC_PPS_ID_MAX)
                 return false;
+            pp_decoded = &p_sys->rg_pps[i_id].p_decoded;
+            pp_nal = &p_sys->rg_pps[i_id].p_nal;
             break;
         default:
             return false;
     }
 
     /* Free associated decoded version */
-    if(i_nal_type == HEVC_NAL_SPS && p_sys->rgi_p_decsps[i_id])
-    {
-        hevc_rbsp_release_sps(p_sys->rgi_p_decsps[i_id]);
-        if(p_sys->p_active_sps == p_sys->rgi_p_decsps[i_id])
-        {
-           p_sys->p_active_sps = NULL;
-           b_active = true;
-        }
-        p_sys->rgi_p_decsps[i_id] = NULL;
-    }
-    else if(i_nal_type == HEVC_NAL_PPS && p_sys->rgi_p_decpps[i_id])
+    if(*pp_decoded)
     {
-        hevc_rbsp_release_pps(p_sys->rgi_p_decpps[i_id]);
-        if(p_sys->p_active_pps == p_sys->rgi_p_decpps[i_id])
+        switch(i_nal_type)
         {
-            p_sys->p_active_pps = NULL;
-            b_active = true;
+            case HEVC_NAL_VPS:
+                hevc_rbsp_release_vps(*pp_decoded);
+                break;
+            case HEVC_NAL_SPS:
+                hevc_rbsp_release_sps(*pp_decoded);
+                break;
+            case HEVC_NAL_PPS:
+                hevc_rbsp_release_pps(*pp_decoded);
+                break;
         }
-        p_sys->rgi_p_decpps[i_id] = NULL;
+        *pp_decoded = NULL;
     }
-    else if(i_nal_type == HEVC_NAL_VPS && p_sys->rgi_p_decvps[i_id])
+
+    /* Free raw stored version */
+    if(*pp_nal)
     {
-        hevc_rbsp_release_vps(p_sys->rgi_p_decvps[i_id]);
-        if(p_sys->p_active_vps == p_sys->rgi_p_decvps[i_id])
-        {
-           p_sys->p_active_vps = NULL;
-           b_active = true;
-        }
-        p_sys->rgi_p_decvps[i_id] = NULL;
+        block_Release(*pp_nal);
+        *pp_nal = NULL;
     }
 
     const uint8_t *p_buffer = p_nalb->p_buffer;
@@ -389,41 +401,43 @@ static bool InsertXPS(decoder_t *p_dec, uint8_t i_nal_type, uint8_t i_id,
     if( hxxx_strip_AnnexB_startcode( &p_buffer, &i_buffer ) )
     {
         /* Create decoded entries */
-        if(i_nal_type == HEVC_NAL_SPS)
-        {
-            p_sys->rgi_p_decsps[i_id] = hevc_decode_sps(p_buffer, i_buffer, true);
-            if(!p_sys->rgi_p_decsps[i_id])
-            {
-                msg_Err(p_dec, "Failed decoding SPS id %d", i_id);
-                return false;
-            }
-            if(b_active)
-                p_sys->p_active_sps = p_sys->rgi_p_decsps[i_id];
-        }
-        else if(i_nal_type == HEVC_NAL_PPS)
+        switch(i_nal_type)
         {
-            p_sys->rgi_p_decpps[i_id] = hevc_decode_pps(p_buffer, i_buffer, true);
-            if(!p_sys->rgi_p_decpps[i_id])
-            {
-                msg_Err(p_dec, "Failed decoding PPS id %d", i_id);
-                return false;
-            }
-            if(b_active)
-                p_sys->p_active_pps = p_sys->rgi_p_decpps[i_id];
+            case HEVC_NAL_SPS:
+                *pp_decoded = hevc_decode_sps(p_buffer, i_buffer, true);
+                if(!*pp_decoded)
+                {
+                    msg_Err(p_dec, "Failed decoding SPS id %d", i_id);
+                    return false;
+                }
+                break;
+            case HEVC_NAL_PPS:
+                *pp_decoded = hevc_decode_pps(p_buffer, i_buffer, true);
+                if(!*pp_decoded)
+                {
+                    msg_Err(p_dec, "Failed decoding PPS id %d", i_id);
+                    return false;
+                }
+                break;
+            case HEVC_NAL_VPS:
+                *pp_decoded = hevc_decode_vps(p_buffer, i_buffer, true);
+                if(!*pp_decoded)
+                {
+                    msg_Err(p_dec, "Failed decoding VPS id %d", i_id);
+                    return false;
+                }
+                break;
         }
-        else if(i_nal_type == HEVC_NAL_VPS)
+
+        *pp_nal = block_Duplicate((block_t *)p_nalb);
+        if(*pp_nal)
         {
-            p_sys->rgi_p_decvps[i_id] = hevc_decode_vps(p_buffer, i_buffer, true);
-            if(!p_sys->rgi_p_decvps[i_id])
-            {
-                msg_Err(p_dec, "Failed decoding VPS id %d", i_id);
-                return false;
-            }
-            if(b_active)
-                p_sys->p_active_vps = p_sys->rgi_p_decvps[i_id];
+            size_t off = p_nalb->i_buffer - i_buffer;
+            (*pp_nal)->p_buffer += off;
+            (*pp_nal)->i_buffer -= off;
         }
-        return true;
 
+        return true;
     }
 
     return false;
@@ -433,15 +447,15 @@ static bool XPSReady(decoder_sys_t *p_sys)
 {
     for(unsigned i=0;i<=HEVC_PPS_ID_MAX; i++)
     {
-        const hevc_picture_parameter_set_t *p_pps = p_sys->rgi_p_decpps[i];
+        const hevc_picture_parameter_set_t *p_pps = p_sys->rg_pps[i].p_decoded;
         if (p_pps)
         {
             uint8_t id_sps = hevc_get_pps_sps_id(p_pps);
-            const hevc_sequence_parameter_set_t *p_sps = p_sys->rgi_p_decsps[id_sps];
+            const hevc_sequence_parameter_set_t *p_sps = p_sys->rg_sps[id_sps].p_decoded;
             if(p_sps)
             {
                 uint8_t id_vps = hevc_get_sps_vps_id(p_sps);
-                if(p_sys->rgi_p_decvps[id_vps])
+                if(p_sys->rg_vps[id_vps].p_decoded)
                     return true;
             }
         }
@@ -516,9 +530,9 @@ static void GetXPSSet(uint8_t i_pps_id, void *priv,
     decoder_sys_t *p_sys = priv;
     *pp_sps = NULL;
     *pp_vps = NULL;
-    if((*pp_pps = p_sys->rgi_p_decpps[i_pps_id]))
-        if((*pp_sps = p_sys->rgi_p_decsps[hevc_get_pps_sps_id(*pp_pps)]))
-            *pp_vps = p_sys->rgi_p_decvps[hevc_get_sps_vps_id(*pp_sps)];
+    if((*pp_pps = p_sys->rg_pps[i_pps_id].p_decoded))
+        if((*pp_sps = p_sys->rg_sps[hevc_get_pps_sps_id(*pp_pps)].p_decoded))
+            *pp_vps = p_sys->rg_vps[hevc_get_sps_vps_id(*pp_sps)].p_decoded;
 }
 
 static void ParseStoredSEI( decoder_t *p_dec )



More information about the vlc-commits mailing list