]> git.sesse.net Git - vlc/blobdiff - modules/codec/avcodec/video.c
Add avparser packetizer for VP9 handling
[vlc] / modules / codec / avcodec / video.c
index b1a2b035a6f3afb0d6aefe62ffcde170e733ecc0..381fe62a4a0c2e1efa4553b1b6b5a07537ba8cc5 100644 (file)
@@ -267,8 +267,6 @@ int InitVideoDec( decoder_t *p_dec, AVCodecContext *p_context,
     if( ( p_dec->p_sys = p_sys = calloc( 1, sizeof(decoder_sys_t) ) ) == NULL )
         return VLC_ENOMEM;
 
-    p_context->codec_type = AVMEDIA_TYPE_VIDEO;
-    p_context->codec_id = p_codec->id;
     p_sys->p_context = p_context;
     p_sys->p_codec = p_codec;
     p_sys->p_ff_pic = avcodec_alloc_frame();
@@ -277,7 +275,8 @@ int InitVideoDec( decoder_t *p_dec, AVCodecContext *p_context,
     vlc_sem_init( &p_sys->sem_mt, 0 );
 
     /* ***** Fill p_context with init values ***** */
-    p_context->codec_tag = ffmpeg_CodecTag( p_dec->fmt_in.i_original_fourcc ?: p_dec->fmt_in.i_codec );
+    p_context->codec_tag = ffmpeg_CodecTag( p_dec->fmt_in.i_original_fourcc ?
+                                p_dec->fmt_in.i_original_fourcc : p_dec->fmt_in.i_codec );
 
     /*  ***** Get configuration of ffmpeg plugin ***** */
     p_context->workaround_bugs =
@@ -455,6 +454,10 @@ int InitVideoDec( decoder_t *p_dec, AVCodecContext *p_context,
     }
 
     p_dec->pf_decode_video = DecodeVideo;
+
+    if ( p_dec->fmt_in.i_codec == VLC_CODEC_VP9 )
+        p_dec->b_need_packetized = true;
+
     return VLC_SUCCESS;
 }
 
@@ -756,7 +759,7 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
         else
         {
             p_pic = (picture_t *)p_sys->p_ff_pic->opaque;
-            decoder_LinkPicture( p_dec, p_pic );
+            picture_Hold( p_pic );
         }
 
         if( !p_dec->fmt_in.video.i_sar_num || !p_dec->fmt_in.video.i_sar_den )
@@ -794,7 +797,7 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
         }
         else
         {
-            decoder_DeletePicture( p_dec, p_pic );
+            picture_Release( p_pic );
         }
     }
 
@@ -821,11 +824,13 @@ void EndVideoDec( decoder_t *p_dec )
 
     wait_mt( p_sys );
 
+    ffmpeg_CloseCodec( p_dec );
+
     if( p_sys->p_ff_pic )
         avcodec_free_frame( &p_sys->p_ff_pic );
 
     if( p_sys->p_va )
-        vlc_va_Delete( p_sys->p_va );
+        vlc_va_Delete( p_sys->p_va, p_sys->p_context );
 
     vlc_sem_destroy( &p_sys->sem_mt );
 }
@@ -961,8 +966,7 @@ static int lavc_va_GetFrame(struct AVCodecContext *ctx, AVFrame *frame,
     decoder_sys_t *sys = dec->p_sys;
     vlc_va_t *va = sys->p_va;
 
-    if (vlc_va_Setup(va, &ctx->hwaccel_context, &dec->fmt_out.video.i_chroma,
-                     ctx->coded_width, ctx->coded_height))
+    if (vlc_va_Setup(va, ctx, &dec->fmt_out.video.i_chroma))
     {
         msg_Err(dec, "hardware acceleration setup failed");
         return -1;
@@ -988,18 +992,11 @@ static int lavc_va_GetFrame(struct AVCodecContext *ctx, AVFrame *frame,
     return 0;
 }
 
-typedef struct
-{
-    decoder_t *decoder;
-    picture_t *picture;
-} lavc_pic_ref_t;
-
 static void lavc_dr_ReleaseFrame(void *opaque, uint8_t *data)
 {
-    lavc_pic_ref_t *ref = opaque;
+    picture_t *picture = opaque;
 
-    decoder_UnlinkPicture(ref->decoder, ref->picture);
-    free(ref);
+    picture_Release(picture);
     (void) data;
 }
 
@@ -1062,32 +1059,25 @@ static picture_t *lavc_dr_GetFrame(struct AVCodecContext *ctx,
     /* Allocate buffer references */
     for (int i = 0; i < pic->i_planes; i++)
     {
-        lavc_pic_ref_t *ref = malloc(sizeof (*ref));
-        if (ref == NULL)
-            goto error;
-        ref->decoder = dec;
-        ref->picture = pic;
-        decoder_LinkPicture(dec, pic);
-
         uint8_t *data = pic->p[i].p_pixels;
         int size = pic->p[i].i_pitch * pic->p[i].i_lines;
 
         frame->buf[i] = av_buffer_create(data, size, lavc_dr_ReleaseFrame,
-                                         ref, 0);
+                                         picture_Hold(pic), 0);
         if (unlikely(frame->buf[i] == NULL))
         {
-            lavc_dr_ReleaseFrame(ref, data);
+            lavc_dr_ReleaseFrame(pic, data);
             goto error;
         }
     }
-    decoder_UnlinkPicture(dec, pic);
+    picture_Release(pic);
     (void) flags;
     return pic;
 error:
     for (unsigned i = 0; frame->buf[i] != NULL; i++)
         av_buffer_unref(&frame->buf[i]);
 no_dr:
-    decoder_DeletePicture(dec, pic);
+    picture_Release(pic);
     return NULL;
 }
 
@@ -1156,9 +1146,7 @@ static int ffmpeg_va_GetFrameBuf( struct AVCodecContext *p_context, AVFrame *p_f
     vlc_va_t *p_va = p_sys->p_va;
 
     /* hwaccel_context is not present in old ffmpeg version */
-    if( vlc_va_Setup( p_va,
-                &p_context->hwaccel_context, &p_dec->fmt_out.video.i_chroma,
-                p_context->coded_width, p_context->coded_height ) )
+    if( vlc_va_Setup( p_va, p_context, &p_dec->fmt_out.video.i_chroma ) )
     {
         msg_Err( p_dec, "vlc_va_Setup failed" );
         return -1;
@@ -1233,7 +1221,7 @@ static picture_t *ffmpeg_dr_GetFrameBuf(struct AVCodecContext *p_context)
 
 no_dr:
     if (p_pic)
-        decoder_DeletePicture( p_dec, p_pic );
+        picture_Release( p_pic );
 
     return NULL;
 }
@@ -1304,7 +1292,7 @@ static void ffmpeg_ReleaseFrameBuf( struct AVCodecContext *p_context,
     if( p_sys->p_va )
         vlc_va_Release( p_sys->p_va, p_ff_pic->opaque, p_ff_pic->data[0] );
     else if( p_ff_pic->opaque )
-        decoder_UnlinkPicture( p_dec, (picture_t*)p_ff_pic->opaque);
+        picture_Release( (picture_t*)p_ff_pic->opaque);
     else if( p_ff_pic->type == FF_BUFFER_TYPE_INTERNAL )
         /* We can end up here without the AVFrame being allocated by
          * avcodec_default_get_buffer() if VA is used and the frame is
@@ -1325,7 +1313,7 @@ static enum PixelFormat ffmpeg_GetFormat( AVCodecContext *p_context,
     vlc_va_t *p_va = p_sys->p_va;
 
     if( p_va != NULL )
-        vlc_va_Delete( p_va );
+        vlc_va_Delete( p_va, p_context );
 
     /* Enumerate available formats */
     bool can_hwaccel = false;
@@ -1364,9 +1352,7 @@ static enum PixelFormat ffmpeg_GetFormat( AVCodecContext *p_context,
         /* We try to call vlc_va_Setup when possible to detect errors when
          * possible (later is too late) */
         if( p_context->width > 0 && p_context->height > 0
-         && vlc_va_Setup( p_va, &p_context->hwaccel_context,
-                          &p_dec->fmt_out.video.i_chroma,
-                          p_context->width, p_context->height ) )
+         && vlc_va_Setup( p_va, p_context, &p_dec->fmt_out.video.i_chroma ) )
         {
             msg_Err( p_dec, "acceleration setup failure" );
             break;
@@ -1385,7 +1371,7 @@ static enum PixelFormat ffmpeg_GetFormat( AVCodecContext *p_context,
         return pi_fmt[i];
     }
 
-    vlc_va_Delete( p_va );
+    vlc_va_Delete( p_va, p_context );
 
 end:
     /* Fallback to default behaviour */