]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/libschroedingerdec.c
lavc: export the timestamps when decoding in AVFrame.pts
[ffmpeg] / libavcodec / libschroedingerdec.c
index d0077d8a013dc53b71076709621edf1e79b23cec..f173f92f043b68605bb88742ea5e587399498a7a 100644 (file)
 #include "internal.h"
 #include "libschroedinger.h"
 
-#undef NDEBUG
-#include <assert.h>
-
-
 #include <schroedinger/schro.h>
 #include <schroedinger/schrodebug.h>
 #include <schroedinger/schrovideoformat.h>
@@ -70,9 +66,6 @@ typedef struct SchroDecoderParams {
 
     /** end of sequence pulled */
     int eos_pulled;
-
-    /** decoded picture */
-    AVFrame dec_frame;
 } SchroDecoderParams;
 
 typedef struct SchroParseUnitContext {
@@ -202,8 +195,8 @@ static void libschroedinger_handle_first_access_unit(AVCodecContext *avctx)
         return;
     }
 
-    avctx->time_base.den = p_schro_params->format->frame_rate_numerator;
-    avctx->time_base.num = p_schro_params->format->frame_rate_denominator;
+    avctx->framerate.num = p_schro_params->format->frame_rate_numerator;
+    avctx->framerate.den = p_schro_params->format->frame_rate_denominator;
 }
 
 static int libschroedinger_decode_frame(AVCodecContext *avctx,
@@ -219,6 +212,7 @@ static int libschroedinger_decode_frame(AVCodecContext *avctx,
     SchroDecoder *decoder = p_schro_params->decoder;
     SchroBuffer *enc_buf;
     SchroFrame* frame;
+    AVFrame *avframe = data;
     int state;
     int go = 1;
     int outer = 1;
@@ -273,6 +267,8 @@ static int libschroedinger_decode_frame(AVCodecContext *avctx,
                 /* Decoder needs a frame - create one and push it in. */
                 frame = ff_create_schro_frame(avctx,
                                               p_schro_params->frame_format);
+                if (!frame)
+                    return AVERROR(ENOMEM);
                 schro_decoder_add_output_picture(decoder, frame);
                 break;
 
@@ -312,35 +308,34 @@ static int libschroedinger_decode_frame(AVCodecContext *avctx,
     framewithpts = ff_schro_queue_pop(&p_schro_params->dec_frame_queue);
 
     if (framewithpts && framewithpts->frame) {
-        if (p_schro_params->dec_frame.data[0])
-            avctx->release_buffer(avctx, &p_schro_params->dec_frame);
-        if (ff_get_buffer(avctx, &p_schro_params->dec_frame) < 0) {
+        if (ff_get_buffer(avctx, avframe, 0) < 0) {
             av_log(avctx, AV_LOG_ERROR, "Unable to allocate buffer\n");
             return AVERROR(ENOMEM);
         }
 
-        memcpy(p_schro_params->dec_frame.data[0],
+        memcpy(avframe->data[0],
                framewithpts->frame->components[0].data,
                framewithpts->frame->components[0].length);
 
-        memcpy(p_schro_params->dec_frame.data[1],
+        memcpy(avframe->data[1],
                framewithpts->frame->components[1].data,
                framewithpts->frame->components[1].length);
 
-        memcpy(p_schro_params->dec_frame.data[2],
+        memcpy(avframe->data[2],
                framewithpts->frame->components[2].data,
                framewithpts->frame->components[2].length);
 
         /* Fill frame with current buffer data from Schroedinger. */
-        p_schro_params->dec_frame.format  = -1; /* Unknown -1 */
-        p_schro_params->dec_frame.width   = framewithpts->frame->width;
-        p_schro_params->dec_frame.height  = framewithpts->frame->height;
-        p_schro_params->dec_frame.pkt_pts = framewithpts->pts;
-        p_schro_params->dec_frame.linesize[0] = framewithpts->frame->components[0].stride;
-        p_schro_params->dec_frame.linesize[1] = framewithpts->frame->components[1].stride;
-        p_schro_params->dec_frame.linesize[2] = framewithpts->frame->components[2].stride;
-
-        *(AVFrame*)data = p_schro_params->dec_frame;
+        avframe->pts = framewithpts->pts;
+#if FF_API_PKT_PTS
+FF_DISABLE_DEPRECATION_WARNINGS
+        avframe->pkt_pts = avframe->pts;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+        avframe->linesize[0] = framewithpts->frame->components[0].stride;
+        avframe->linesize[1] = framewithpts->frame->components[1].stride;
+        avframe->linesize[2] = framewithpts->frame->components[2].stride;
+
         *got_frame      = 1;
 
         /* Now free the frame resources. */
@@ -361,9 +356,6 @@ static av_cold int libschroedinger_decode_close(AVCodecContext *avctx)
     schro_decoder_free(p_schro_params->decoder);
     av_freep(&p_schro_params->format);
 
-    if (p_schro_params->dec_frame.data[0])
-        avctx->release_buffer(avctx, &p_schro_params->dec_frame);
-
     /* Free data in the output frame queue. */
     ff_schro_queue_free(&p_schro_params->dec_frame_queue,
                         libschroedinger_decode_frame_free);
@@ -389,13 +381,13 @@ static void libschroedinger_flush(AVCodecContext *avctx)
 
 AVCodec ff_libschroedinger_decoder = {
     .name           = "libschroedinger",
+    .long_name      = NULL_IF_CONFIG_SMALL("libschroedinger Dirac 2.2"),
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_DIRAC,
     .priv_data_size = sizeof(SchroDecoderParams),
     .init           = libschroedinger_decode_init,
     .close          = libschroedinger_decode_close,
     .decode         = libschroedinger_decode_frame,
-    .capabilities   = CODEC_CAP_DELAY,
+    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1,
     .flush          = libschroedinger_flush,
-    .long_name      = NULL_IF_CONFIG_SMALL("libschroedinger Dirac 2.2"),
 };