diff --git a/gst-libs/gst/vaapi/gstvaapidecoder.c b/gst-libs/gst/vaapi/gstvaapidecoder.c
index d1bf5a1..eb9fdbb 100644
--- a/gst-libs/gst/vaapi/gstvaapidecoder.c
+++ b/gst-libs/gst/vaapi/gstvaapidecoder.c
@@ -929,6 +929,7 @@ gst_vaapi_decoder_ensure_context (GstVaapiDecoder * decoder,
     GstVaapiContextInfo * cip)
 {
   gst_vaapi_decoder_set_picture_size (decoder, cip->width, cip->height);
+  notify_codec_state_changed (decoder);
 
   cip->usage = GST_VAAPI_CONTEXT_USAGE_DECODE;
   if (decoder->context) {
diff --git a/gst/vaapi/gstvaapidecode.c b/gst/vaapi/gstvaapidecode.c
index b40dd97..b668a81 100644
--- a/gst/vaapi/gstvaapidecode.c
+++ b/gst/vaapi/gstvaapidecode.c
@@ -130,10 +130,10 @@ gst_vaapi_decoder_state_changed (GstVaapiDecoder * decoder,
 
   g_assert (decode->decoder == decoder);
 
-  if (!gst_vaapi_decode_input_state_replace (decode, codec_state))
-    return;
   if (!gst_vaapidecode_update_src_caps (decode))
     return;
+  if (!gst_vaapi_decode_input_state_replace (decode, codec_state))
+    return;
   if (!gst_video_decoder_negotiate (vdec))
     return;
   if (!gst_vaapi_plugin_base_set_caps (plugin, NULL, decode->srcpad_caps))
