[vlc-devel] [PATCH] packetizer: initialize all callback fields and reorder some initialization

Zhao Zhili quinkblack at foxmail.com
Fri Jun 1 08:19:54 CEST 2018


A failed module probe may set the callback fileds point to that module.
---
 modules/packetizer/a52.c        |  2 ++
 modules/packetizer/avparser.c   |  2 ++
 modules/packetizer/copy.c       | 14 ++++++++------
 modules/packetizer/dts.c        |  2 ++
 modules/packetizer/flac.c       |  1 +
 modules/packetizer/h264.c       |  1 +
 modules/packetizer/hevc.c       |  1 +
 modules/packetizer/mlp.c        |  2 ++
 modules/packetizer/mpeg4audio.c |  2 ++
 modules/packetizer/mpeg4video.c |  2 ++
 modules/packetizer/mpegaudio.c  |  2 ++
 modules/packetizer/mpegvideo.c  |  1 +
 modules/packetizer/vc1.c        |  9 +++++----
 13 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/modules/packetizer/a52.c b/modules/packetizer/a52.c
index 269a291..dea3dc0 100644
--- a/modules/packetizer/a52.c
+++ b/modules/packetizer/a52.c
@@ -353,7 +353,9 @@ static int Open( vlc_object_t *p_this )
     p_dec->fmt_out.audio.i_rate = 0;
 
     /* Set callback */
+    p_dec->pf_decode    = NULL;
     p_dec->pf_packetize = PacketizeBlock;
     p_dec->pf_flush     = PacketizeFlush;
+    p_dec->pf_get_cc    = NULL;
     return VLC_SUCCESS;
 }
diff --git a/modules/packetizer/avparser.c b/modules/packetizer/avparser.c
index 5ec26f4..8fc0e73 100644
--- a/modules/packetizer/avparser.c
+++ b/modules/packetizer/avparser.c
@@ -126,8 +126,10 @@ int avparser_OpenPacketizer( vlc_object_t *p_this )
         av_parser_close( p_ctx );
         return VLC_ENOMEM;
     }
+    p_dec->pf_decode = NULL;
     p_dec->pf_packetize = Packetize;
     p_dec->pf_flush = FlushPacketizer;
+    p_dec->pf_get_cc = NULL;
     p_sys->p_parser_ctx = p_ctx;
     p_sys->p_codec_ctx = p_codec_ctx;
     p_sys->i_offset = 0;
diff --git a/modules/packetizer/copy.c b/modules/packetizer/copy.c
index b66a4b7..6253d6a 100644
--- a/modules/packetizer/copy.c
+++ b/modules/packetizer/copy.c
@@ -84,12 +84,6 @@ static int Open( vlc_object_t *p_this )
         return VLC_EGENERIC;
     }
 
-    if( p_dec->fmt_in.i_cat == SPU_ES )
-        p_dec->pf_packetize = PacketizeSub;
-    else
-        p_dec->pf_packetize = Packetize;
-    p_dec->pf_flush = Flush;
-
     p_dec->p_sys = p_sys = malloc( sizeof(*p_sys) );
     if (unlikely(p_sys == NULL))
         return VLC_ENOMEM;
@@ -119,6 +113,14 @@ static int Open( vlc_object_t *p_this )
         }
     }
 
+    p_dec->pf_decode = NULL;
+    if( p_dec->fmt_in.i_cat == SPU_ES )
+        p_dec->pf_packetize = PacketizeSub;
+    else
+        p_dec->pf_packetize = Packetize;
+    p_dec->pf_flush = Flush;
+    p_dec->pf_get_cc = NULL;
+
     /* Create the output format */
     es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in );
     p_dec->fmt_out.i_codec = fcc;
diff --git a/modules/packetizer/dts.c b/modules/packetizer/dts.c
index 12245c2..de7894c 100644
--- a/modules/packetizer/dts.c
+++ b/modules/packetizer/dts.c
@@ -364,7 +364,9 @@ static int Open( vlc_object_t *p_this )
     p_dec->fmt_out.audio = p_dec->fmt_in.audio;
 
     /* Set callback */
+    p_dec->pf_decode    = NULL;
     p_dec->pf_packetize = PacketizeBlock;
     p_dec->pf_flush     = PacketizeFlush;
+    p_dec->pf_get_cc    = NULL;
     return VLC_SUCCESS;
 }
diff --git a/modules/packetizer/flac.c b/modules/packetizer/flac.c
index bc9ab04..4f316f7 100644
--- a/modules/packetizer/flac.c
+++ b/modules/packetizer/flac.c
@@ -562,6 +562,7 @@ static int Open(vlc_object_t *p_this)
     p_dec->pf_decode    = NULL;
     p_dec->pf_packetize = Packetize;
     p_dec->pf_flush     = Flush;
+    p_dec->pf_get_cc    = NULL;
 
     return VLC_SUCCESS;
 }
diff --git a/modules/packetizer/h264.c b/modules/packetizer/h264.c
index 4f8a97d..8f5761e 100644
--- a/modules/packetizer/h264.c
+++ b/modules/packetizer/h264.c
@@ -453,6 +453,7 @@ static int Open( vlc_object_t *p_this )
     }
 
     /* CC are the same for H264/AVC in T35 sections (ETSI TS 101 154)  */
+    p_dec->pf_decode = NULL;
     p_dec->pf_get_cc = GetCc;
     p_dec->pf_flush = PacketizeFlush;
 
diff --git a/modules/packetizer/hevc.c b/modules/packetizer/hevc.c
index d71a0bf..1e596cd 100644
--- a/modules/packetizer/hevc.c
+++ b/modules/packetizer/hevc.c
@@ -230,6 +230,7 @@ static int Open(vlc_object_t *p_this)
     {
         p_dec->pf_packetize = PacketizeAnnexB;
     }
+    p_dec->pf_decode = NULL;
     p_dec->pf_flush = PacketizeFlush;
     p_dec->pf_get_cc = GetCc;
 
diff --git a/modules/packetizer/mlp.c b/modules/packetizer/mlp.c
index 6f16e6c..829f2cc 100644
--- a/modules/packetizer/mlp.c
+++ b/modules/packetizer/mlp.c
@@ -492,8 +492,10 @@ static int Open( vlc_object_t *p_this )
     p_dec->fmt_out.audio.i_rate = 0;
 
     /* Set callback */
+    p_dec->pf_decode    = NULL;
     p_dec->pf_packetize = Packetize;
     p_dec->pf_flush     = Flush;
+    p_dec->pf_get_cc    = NULL;
     return VLC_SUCCESS;
 }
 
diff --git a/modules/packetizer/mpeg4audio.c b/modules/packetizer/mpeg4audio.c
index 9237853..6ece823 100644
--- a/modules/packetizer/mpeg4audio.c
+++ b/modules/packetizer/mpeg4audio.c
@@ -295,8 +295,10 @@ static int OpenPacketizer(vlc_object_t *p_this)
                                 p_dec->fmt_out.audio.i_rate : 48000, 1);
 
     /* Set callbacks */
+    p_dec->pf_decode = NULL;
     p_dec->pf_packetize = Packetize;
     p_dec->pf_flush = Flush;
+    p_dec->pf_get_cc = NULL;
 
     return VLC_SUCCESS;
 }
diff --git a/modules/packetizer/mpeg4video.c b/modules/packetizer/mpeg4video.c
index c95e913..0772d7d 100644
--- a/modules/packetizer/mpeg4video.c
+++ b/modules/packetizer/mpeg4video.c
@@ -166,8 +166,10 @@ static int Open( vlc_object_t *p_this )
     }
 
     /* Set callback */
+    p_dec->pf_decode = NULL;
     p_dec->pf_packetize = Packetize;
     p_dec->pf_flush = PacketizeFlush;
+    p_dec->pf_get_cc = NULL;
 
     return VLC_SUCCESS;
 }
diff --git a/modules/packetizer/mpegaudio.c b/modules/packetizer/mpegaudio.c
index ab01b5b..01dd493 100644
--- a/modules/packetizer/mpegaudio.c
+++ b/modules/packetizer/mpegaudio.c
@@ -644,8 +644,10 @@ static int Open( vlc_object_t *p_this )
     p_dec->fmt_out.audio.i_rate = 0; /* So end_date gets initialized */
 
     /* Set callback */
+    p_dec->pf_decode       = NULL;
     p_dec->pf_packetize    = DecodeBlock;
     p_dec->pf_flush        = Flush;
+    p_dec->pf_get_cc       = NULL;
 
     /* Start with the minimum size for a free bitrate frame */
     p_sys->i_free_frame_size = MPGA_HEADER_SIZE;
diff --git a/modules/packetizer/mpegvideo.c b/modules/packetizer/mpegvideo.c
index 318b3f7..fd4fdcc 100644
--- a/modules/packetizer/mpegvideo.c
+++ b/modules/packetizer/mpegvideo.c
@@ -257,6 +257,7 @@ static int Open( vlc_object_t *p_this )
     p_sys->i_cc_flags = 0;
     cc_Init( &p_sys->cc );
 
+    p_dec->pf_decode = NULL;
     p_dec->pf_packetize = Packetize;
     p_dec->pf_flush = PacketizeFlush;
     p_dec->pf_get_cc = GetCc;
diff --git a/modules/packetizer/vc1.c b/modules/packetizer/vc1.c
index 7ca438f..6e48162 100644
--- a/modules/packetizer/vc1.c
+++ b/modules/packetizer/vc1.c
@@ -146,10 +146,6 @@ static int Open( vlc_object_t *p_this )
     if( p_dec->fmt_in.i_codec !=  VLC_CODEC_VC1 )
         return VLC_EGENERIC;
 
-    p_dec->pf_packetize = Packetize;
-    p_dec->pf_flush = Flush;
-    p_dec->pf_get_cc = GetCc;
-
     /* Create the output format */
     es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in );
     p_dec->p_sys = p_sys = malloc( sizeof( decoder_sys_t ) );
@@ -200,6 +196,11 @@ static int Open( vlc_object_t *p_this )
     cc_Init( &p_sys->cc );
     cc_Init( &p_sys->cc_next );
 
+    p_dec->pf_decode = NULL;
+    p_dec->pf_packetize = Packetize;
+    p_dec->pf_flush = Flush;
+    p_dec->pf_get_cc = GetCc;
+
     return VLC_SUCCESS;
 }
 
-- 
2.9.5





More information about the vlc-devel mailing list