]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/frame_thread_encoder.c
avcodec/frame_thread_encoder: remove usage of avcodec_encode_video2()
[ffmpeg] / libavcodec / frame_thread_encoder.c
index 55756c4c5406ea599e17d190cc45dbdb74cd5f24..83229f620ac4b8297041a3cb110cc618d32afcff 100644 (file)
@@ -66,7 +66,7 @@ static void * attribute_align_arg worker(void *v){
     AVPacket *pkt = NULL;
 
     while (!atomic_load(&c->exit)) {
-        int got_packet, ret;
+        int got_packet = 0, ret;
         AVFrame *frame;
         Task task;
 
@@ -86,19 +86,20 @@ static void * attribute_align_arg worker(void *v){
         pthread_mutex_unlock(&c->task_fifo_mutex);
         frame = task.indata;
 
-        ret = avcodec_encode_video2(avctx, pkt, frame, &got_packet);
-        pthread_mutex_lock(&c->buffer_mutex);
-        av_frame_unref(frame);
-        pthread_mutex_unlock(&c->buffer_mutex);
-        av_frame_free(&frame);
+        ret = avctx->codec->encode2(avctx, pkt, frame, &got_packet);
         if(got_packet) {
             int ret2 = av_packet_make_refcounted(pkt);
             if (ret >= 0 && ret2 < 0)
                 ret = ret2;
+            pkt->pts = pkt->dts = frame->pts;
         } else {
             pkt->data = NULL;
             pkt->size = 0;
         }
+        pthread_mutex_lock(&c->buffer_mutex);
+        av_frame_unref(frame);
+        pthread_mutex_unlock(&c->buffer_mutex);
+        av_frame_free(&frame);
         pthread_mutex_lock(&c->finished_task_mutex);
         c->finished_tasks[task.index].outdata = pkt; pkt = NULL;
         c->finished_tasks[task.index].return_code = ret;
@@ -120,7 +121,7 @@ int ff_frame_thread_encoder_init(AVCodecContext *avctx, AVDictionary *options){
 
 
     if(   !(avctx->thread_type & FF_THREAD_FRAME)
-       || !(avctx->codec->capabilities & AV_CODEC_CAP_INTRA_ONLY))
+       || !(avctx->codec->capabilities & AV_CODEC_CAP_FRAME_THREADS))
         return 0;
 
     if(   !avctx->thread_count
@@ -209,8 +210,9 @@ int ff_frame_thread_encoder_init(AVCodecContext *avctx, AVDictionary *options){
             int ret = av_opt_copy(thread_avctx->priv_data, avctx->priv_data);
             if (ret < 0)
                 goto fail;
-        } else
+        } else if (avctx->codec->priv_data_size) {
             memcpy(thread_avctx->priv_data, avctx->priv_data, avctx->codec->priv_data_size);
+        }
         thread_avctx->thread_count = 1;
         thread_avctx->active_thread_type &= ~FF_THREAD_FRAME;