copy: Don't modify fmt_out until success is ensured
authorHugo Beauzée-Luyssen <hugo@beauzee.fr>
Fri, 8 Dec 2017 10:41:56 +0000 (11:41 +0100)
committerHugo Beauzée-Luyssen <hugo@beauzee.fr>
Fri, 8 Dec 2017 13:01:48 +0000 (14:01 +0100)
modules/packetizer/copy.c

index 7c02cfc..2ffa58c 100644 (file)
@@ -90,9 +90,6 @@ static int Open( vlc_object_t *p_this )
         p_dec->pf_packetize = Packetize;
     p_dec->pf_flush = Flush;
 
         p_dec->pf_packetize = Packetize;
     p_dec->pf_flush = Flush;
 
-    /* Create the output format */
-    es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in );
-
     p_dec->p_sys = p_sys = malloc( sizeof(*p_sys) );
     if (unlikely(p_sys == NULL))
         return VLC_ENOMEM;
     p_dec->p_sys = p_sys = malloc( sizeof(*p_sys) );
     if (unlikely(p_sys == NULL))
         return VLC_ENOMEM;
@@ -108,10 +105,11 @@ static int Open( vlc_object_t *p_this )
         break;
     }
 
         break;
     }
 
+    vlc_fourcc_t fcc = p_dec->fmt_out.i_codec;
     /* Fix the value of the fourcc for audio */
     if( p_dec->fmt_in.i_cat == AUDIO_ES )
     {
     /* Fix the value of the fourcc for audio */
     if( p_dec->fmt_in.i_cat == AUDIO_ES )
     {
-        vlc_fourcc_t fcc = vlc_fourcc_GetCodecAudio( p_dec->fmt_in.i_codec,
+        fcc = vlc_fourcc_GetCodecAudio( p_dec->fmt_in.i_codec,
                                                      p_dec->fmt_in.audio.i_bitspersample );
         if( !fcc )
         {
                                                      p_dec->fmt_in.audio.i_bitspersample );
         if( !fcc )
         {
@@ -119,9 +117,12 @@ static int Open( vlc_object_t *p_this )
             free( p_sys );
             return VLC_EGENERIC;
         }
             free( p_sys );
             return VLC_EGENERIC;
         }
-        p_dec->fmt_out.i_codec = fcc;
     }
 
     }
 
+    /* Create the output format */
+    es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in );
+    p_dec->fmt_out.i_codec = fcc;
+
     return VLC_SUCCESS;
 }
 
     return VLC_SUCCESS;
 }