FFmpeg  4.3.8
pthread_frame.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 /**
20  * @file
21  * Frame multithreading support functions
22  * @see doc/multithreading.txt
23  */
24 
25 #include "config.h"
26 
27 #include <stdatomic.h>
28 #include <stdint.h>
29 
30 #include "avcodec.h"
31 #include "hwconfig.h"
32 #include "internal.h"
33 #include "pthread_internal.h"
34 #include "thread.h"
35 #include "version.h"
36 
37 #include "libavutil/avassert.h"
38 #include "libavutil/buffer.h"
39 #include "libavutil/common.h"
40 #include "libavutil/cpu.h"
41 #include "libavutil/frame.h"
42 #include "libavutil/internal.h"
43 #include "libavutil/log.h"
44 #include "libavutil/mem.h"
45 #include "libavutil/opt.h"
46 #include "libavutil/thread.h"
47 
48 enum {
49  ///< Set when the thread is awaiting a packet.
51  ///< Set before the codec has called ff_thread_finish_setup().
53  /**
54  * Set when the codec calls get_buffer().
55  * State is returned to STATE_SETTING_UP afterwards.
56  */
58  /**
59  * Set when the codec calls get_format().
60  * State is returned to STATE_SETTING_UP afterwards.
61  */
63  ///< Set after the codec has called ff_thread_finish_setup().
65 };
66 
67 /**
68  * Context used by codec threads and stored in their AVCodecInternal thread_ctx.
69  */
70 typedef struct PerThreadContext {
72 
75  pthread_cond_t input_cond; ///< Used to wait for a new packet from the main thread.
76  pthread_cond_t progress_cond; ///< Used by child threads to wait for progress to change.
77  pthread_cond_t output_cond; ///< Used by the main thread to wait for frames to finish.
78 
79  pthread_mutex_t mutex; ///< Mutex used to protect the contents of the PerThreadContext.
80  pthread_mutex_t progress_mutex; ///< Mutex used to protect frame progress values and progress_cond.
81 
82  AVCodecContext *avctx; ///< Context used to decode packets passed to this thread.
83 
84  AVPacket avpkt; ///< Input packet (for decoding) or output (for encoding).
85 
86  AVFrame *frame; ///< Output frame (for decoding) or input (for encoding).
87  int got_frame; ///< The output of got_picture_ptr from the last avcodec_decode_video() call.
88  int result; ///< The result of the last codec decode/encode() call.
89 
91 
92  /**
93  * Array of frames passed to ff_thread_release_buffer().
94  * Frames are released after all threads referencing them are finished.
95  */
99 
100  AVFrame *requested_frame; ///< AVFrame the codec passed to get_buffer()
101  int requested_flags; ///< flags passed to get_buffer() for requested_frame
102 
103  const enum AVPixelFormat *available_formats; ///< Format array for get_format()
104  enum AVPixelFormat result_format; ///< get_format() result
105 
106  int die; ///< Set when the thread should exit.
107 
110 
111  atomic_int debug_threads; ///< Set if the FF_DEBUG_THREADS option is set.
113 
114 /**
115  * Context stored in the client AVCodecInternal thread_ctx.
116  */
117 typedef struct FrameThreadContext {
118  PerThreadContext *threads; ///< The contexts for each thread.
119  PerThreadContext *prev_thread; ///< The last thread submit_packet() was called on.
120 
121  pthread_mutex_t buffer_mutex; ///< Mutex used to protect get/release_buffer().
122  /**
123  * This lock is used for ensuring threads run in serial when hwaccel
124  * is used.
125  */
130 
131  int next_decoding; ///< The next context to submit a packet to.
132  int next_finished; ///< The next context to return output from.
133 
134  int delaying; /**<
135  * Set for the first N packets, where N is the number of threads.
136  * While it is set, ff_thread_en/decode_frame won't return any results.
137  */
138 
139  /* hwaccel state is temporarily stored here in order to transfer its ownership
140  * to the next decoding thread without the need for extra synchronization */
145 
146 #define THREAD_SAFE_CALLBACKS(avctx) \
147 ((avctx)->thread_safe_callbacks || (avctx)->get_buffer2 == avcodec_default_get_buffer2)
148 
149 static void async_lock(FrameThreadContext *fctx)
150 {
152  while (fctx->async_lock)
153  pthread_cond_wait(&fctx->async_cond, &fctx->async_mutex);
154  fctx->async_lock = 1;
156 }
157 
159 {
161  av_assert0(fctx->async_lock);
162  fctx->async_lock = 0;
165 }
166 
167 /**
168  * Codec worker thread.
169  *
170  * Automatically calls ff_thread_finish_setup() if the codec does
171  * not provide an update_thread_context method, or if the codec returns
172  * before calling it.
173  */
175 {
176  PerThreadContext *p = arg;
177  AVCodecContext *avctx = p->avctx;
178  const AVCodec *codec = avctx->codec;
179 
181  while (1) {
182  while (atomic_load(&p->state) == STATE_INPUT_READY && !p->die)
184 
185  if (p->die) break;
186 
187  if (!codec->update_thread_context && THREAD_SAFE_CALLBACKS(avctx))
188  ff_thread_finish_setup(avctx);
189 
190  /* If a decoder supports hwaccel, then it must call ff_get_format().
191  * Since that call must happen before ff_thread_finish_setup(), the
192  * decoder is required to implement update_thread_context() and call
193  * ff_thread_finish_setup() manually. Therefore the above
194  * ff_thread_finish_setup() call did not happen and hwaccel_serializing
195  * cannot be true here. */
197 
198  /* if the previous thread uses hwaccel then we take the lock to ensure
199  * the threads don't run concurrently */
200  if (avctx->hwaccel) {
202  p->hwaccel_serializing = 1;
203  }
204 
205  av_frame_unref(p->frame);
206  p->got_frame = 0;
207  p->result = codec->decode(avctx, p->frame, &p->got_frame, &p->avpkt);
208 
209  if ((p->result < 0 || !p->got_frame) && p->frame->buf[0]) {
211  av_log(avctx, AV_LOG_ERROR, "A frame threaded decoder did not "
212  "free the frame on failure. This is a bug, please report it.\n");
213  av_frame_unref(p->frame);
214  }
215 
216  if (atomic_load(&p->state) == STATE_SETTING_UP)
217  ff_thread_finish_setup(avctx);
218 
219  if (p->hwaccel_serializing) {
220  /* wipe hwaccel state to avoid stale pointers lying around;
221  * the state was transferred to FrameThreadContext in
222  * ff_thread_finish_setup(), so nothing is leaked */
223  avctx->hwaccel = NULL;
224  avctx->hwaccel_context = NULL;
225  avctx->internal->hwaccel_priv_data = NULL;
226 
227  p->hwaccel_serializing = 0;
229  }
230  av_assert0(!avctx->hwaccel);
231 
232  if (p->async_serializing) {
233  p->async_serializing = 0;
234 
235  async_unlock(p->parent);
236  }
237 
239 
241 
245  }
247 
248  return NULL;
249 }
250 
251 /**
252  * Update the next thread's AVCodecContext with values from the reference thread's context.
253  *
254  * @param dst The destination context.
255  * @param src The source context.
256  * @param for_user 0 if the destination is a codec thread, 1 if the destination is the user's thread
257  * @return 0 on success, negative error code on failure
258  */
260 {
261  int err = 0;
262 
263  if (dst != src && (for_user || !(src->codec_descriptor->props & AV_CODEC_PROP_INTRA_ONLY))) {
264  dst->time_base = src->time_base;
265  dst->framerate = src->framerate;
266  dst->width = src->width;
267  dst->height = src->height;
268  dst->pix_fmt = src->pix_fmt;
269  dst->sw_pix_fmt = src->sw_pix_fmt;
270 
271  dst->coded_width = src->coded_width;
272  dst->coded_height = src->coded_height;
273 
274  dst->has_b_frames = src->has_b_frames;
275  dst->idct_algo = src->idct_algo;
276 
279 
280  dst->profile = src->profile;
281  dst->level = src->level;
282 
284  dst->ticks_per_frame = src->ticks_per_frame;
285  dst->color_primaries = src->color_primaries;
286 
287  dst->color_trc = src->color_trc;
288  dst->colorspace = src->colorspace;
289  dst->color_range = src->color_range;
291 
292  dst->channels = src->channels;
293  dst->sample_rate = src->sample_rate;
294  dst->sample_fmt = src->sample_fmt;
295  dst->channel_layout = src->channel_layout;
296 
297  if (!!dst->hw_frames_ctx != !!src->hw_frames_ctx ||
298  (dst->hw_frames_ctx && dst->hw_frames_ctx->data != src->hw_frames_ctx->data)) {
300 
301  if (src->hw_frames_ctx) {
303  if (!dst->hw_frames_ctx)
304  return AVERROR(ENOMEM);
305  }
306  }
307 
308  dst->hwaccel_flags = src->hwaccel_flags;
309 
310  if (!!dst->internal->pool != !!src->internal->pool ||
311  (dst->internal->pool && dst->internal->pool->data != src->internal->pool->data)) {
312  av_buffer_unref(&dst->internal->pool);
313 
314  if (src->internal->pool) {
315  dst->internal->pool = av_buffer_ref(src->internal->pool);
316  if (!dst->internal->pool)
317  return AVERROR(ENOMEM);
318  }
319  }
320  }
321 
322  if (for_user) {
323 #if FF_API_CODED_FRAME
325  dst->coded_frame = src->coded_frame;
327 #endif
328  } else {
329  if (dst->codec->update_thread_context)
330  err = dst->codec->update_thread_context(dst, src);
331  }
332 
333  return err;
334 }
335 
336 /**
337  * Update the next thread's AVCodecContext with values set by the user.
338  *
339  * @param dst The destination context.
340  * @param src The source context.
341  * @return 0 on success, negative error code on failure
342  */
344 {
345  dst->flags = src->flags;
346 
347  dst->draw_horiz_band= src->draw_horiz_band;
348  dst->get_buffer2 = src->get_buffer2;
349 
350  dst->opaque = src->opaque;
351  dst->debug = src->debug;
352  dst->debug_mv = src->debug_mv;
353 
354  dst->slice_flags = src->slice_flags;
355  dst->flags2 = src->flags2;
357 
359  dst->skip_idct = src->skip_idct;
360  dst->skip_frame = src->skip_frame;
361 
362  dst->frame_number = src->frame_number;
365 
366  if (src->slice_count && src->slice_offset) {
367  if (dst->slice_count < src->slice_count) {
368  int err = av_reallocp_array(&dst->slice_offset, src->slice_count,
369  sizeof(*dst->slice_offset));
370  if (err < 0)
371  return err;
372  }
373  memcpy(dst->slice_offset, src->slice_offset,
374  src->slice_count * sizeof(*dst->slice_offset));
375  }
376  dst->slice_count = src->slice_count;
377  return 0;
378 }
379 
380 /// Releases the buffers that this decoding thread was the last user of.
382 {
383  FrameThreadContext *fctx = p->parent;
384 
385  while (p->num_released_buffers > 0) {
386  AVFrame *f;
387 
389 
390  // fix extended data in case the caller screwed it up
394  f->extended_data = f->data;
395  av_frame_unref(f);
396 
398  }
399 }
400 
401 static int submit_packet(PerThreadContext *p, AVCodecContext *user_avctx,
402  AVPacket *avpkt)
403 {
404  FrameThreadContext *fctx = p->parent;
405  PerThreadContext *prev_thread = fctx->prev_thread;
406  const AVCodec *codec = p->avctx->codec;
407  int ret;
408 
409  if (!avpkt->size && !(codec->capabilities & AV_CODEC_CAP_DELAY))
410  return 0;
411 
413 
414  ret = update_context_from_user(p->avctx, user_avctx);
415  if (ret) {
417  return ret;
418  }
420  (p->avctx->debug & FF_DEBUG_THREADS) != 0,
421  memory_order_relaxed);
422 
424 
425  if (prev_thread) {
426  int err;
427  if (atomic_load(&prev_thread->state) == STATE_SETTING_UP) {
428  pthread_mutex_lock(&prev_thread->progress_mutex);
429  while (atomic_load(&prev_thread->state) == STATE_SETTING_UP)
430  pthread_cond_wait(&prev_thread->progress_cond, &prev_thread->progress_mutex);
431  pthread_mutex_unlock(&prev_thread->progress_mutex);
432  }
433 
434  err = update_context_from_thread(p->avctx, prev_thread->avctx, 0);
435  if (err) {
437  return err;
438  }
439 
440  /* transfer hwaccel state stashed from previous thread, if any */
441  av_assert0(!p->avctx->hwaccel);
442  FFSWAP(const AVHWAccel*, p->avctx->hwaccel, fctx->stash_hwaccel);
445  }
446 
447  av_packet_unref(&p->avpkt);
448  ret = av_packet_ref(&p->avpkt, avpkt);
449  if (ret < 0) {
451  av_log(p->avctx, AV_LOG_ERROR, "av_packet_ref() failed in submit_packet()\n");
452  return ret;
453  }
454 
458 
459  /*
460  * If the client doesn't have a thread-safe get_buffer(),
461  * then decoding threads call back to the main thread,
462  * and it calls back to the client here.
463  */
464 
465  if (!p->avctx->thread_safe_callbacks && (
469  int call_done = 1;
471  while (atomic_load(&p->state) == STATE_SETTING_UP)
473 
474  switch (atomic_load_explicit(&p->state, memory_order_acquire)) {
475  case STATE_GET_BUFFER:
477  break;
478  case STATE_GET_FORMAT:
480  break;
481  default:
482  call_done = 0;
483  break;
484  }
485  if (call_done) {
488  }
490  }
491  }
492 
493  fctx->prev_thread = p;
494  fctx->next_decoding++;
495 
496  return 0;
497 }
498 
500  AVFrame *picture, int *got_picture_ptr,
501  AVPacket *avpkt)
502 {
503  FrameThreadContext *fctx = avctx->internal->thread_ctx;
504  int finished = fctx->next_finished;
505  PerThreadContext *p;
506  int err;
507 
508  /* release the async lock, permitting blocked hwaccel threads to
509  * go forward while we are in this function */
510  async_unlock(fctx);
511 
512  /*
513  * Submit a packet to the next decoding thread.
514  */
515 
516  p = &fctx->threads[fctx->next_decoding];
517  err = submit_packet(p, avctx, avpkt);
518  if (err)
519  goto finish;
520 
521  /*
522  * If we're still receiving the initial packets, don't return a frame.
523  */
524 
525  if (fctx->next_decoding > (avctx->thread_count-1-(avctx->codec_id == AV_CODEC_ID_FFV1)))
526  fctx->delaying = 0;
527 
528  if (fctx->delaying) {
529  *got_picture_ptr=0;
530  if (avpkt->size) {
531  err = avpkt->size;
532  goto finish;
533  }
534  }
535 
536  /*
537  * Return the next available frame from the oldest thread.
538  * If we're at the end of the stream, then we have to skip threads that
539  * didn't output a frame/error, because we don't want to accidentally signal
540  * EOF (avpkt->size == 0 && *got_picture_ptr == 0 && err >= 0).
541  */
542 
543  do {
544  p = &fctx->threads[finished++];
545 
546  if (atomic_load(&p->state) != STATE_INPUT_READY) {
548  while (atomic_load_explicit(&p->state, memory_order_relaxed) != STATE_INPUT_READY)
551  }
552 
553  av_frame_move_ref(picture, p->frame);
554  *got_picture_ptr = p->got_frame;
555  picture->pkt_dts = p->avpkt.dts;
556  err = p->result;
557 
558  /*
559  * A later call with avkpt->size == 0 may loop over all threads,
560  * including this one, searching for a frame/error to return before being
561  * stopped by the "finished != fctx->next_finished" condition.
562  * Make sure we don't mistakenly return the same frame/error again.
563  */
564  p->got_frame = 0;
565  p->result = 0;
566 
567  if (finished >= avctx->thread_count) finished = 0;
568  } while (!avpkt->size && !*got_picture_ptr && err >= 0 && finished != fctx->next_finished);
569 
570  update_context_from_thread(avctx, p->avctx, 1);
571 
572  if (fctx->next_decoding >= avctx->thread_count) fctx->next_decoding = 0;
573 
574  fctx->next_finished = finished;
575 
576  /* return the size of the consumed packet if no error occurred */
577  if (err >= 0)
578  err = avpkt->size;
579 finish:
580  async_lock(fctx);
581  return err;
582 }
583 
584 void ff_thread_report_progress(ThreadFrame *f, int n, int field)
585 {
586  PerThreadContext *p;
587  atomic_int *progress = f->progress ? (atomic_int*)f->progress->data : NULL;
588 
589  if (!progress ||
590  atomic_load_explicit(&progress[field], memory_order_relaxed) >= n)
591  return;
592 
593  p = f->owner[field]->internal->thread_ctx;
594 
595  if (atomic_load_explicit(&p->debug_threads, memory_order_relaxed))
596  av_log(f->owner[field], AV_LOG_DEBUG,
597  "%p finished %d field %d\n", progress, n, field);
598 
600 
601  atomic_store_explicit(&progress[field], n, memory_order_release);
602 
605 }
606 
607 void ff_thread_await_progress(ThreadFrame *f, int n, int field)
608 {
609  PerThreadContext *p;
610  atomic_int *progress = f->progress ? (atomic_int*)f->progress->data : NULL;
611 
612  if (!progress ||
613  atomic_load_explicit(&progress[field], memory_order_acquire) >= n)
614  return;
615 
616  p = f->owner[field]->internal->thread_ctx;
617 
618  if (atomic_load_explicit(&p->debug_threads, memory_order_relaxed))
619  av_log(f->owner[field], AV_LOG_DEBUG,
620  "thread awaiting %d field %d from %p\n", n, field, progress);
621 
623  while (atomic_load_explicit(&progress[field], memory_order_relaxed) < n)
626 }
627 
629  PerThreadContext *p = avctx->internal->thread_ctx;
630 
631  if (!(avctx->active_thread_type&FF_THREAD_FRAME)) return;
632 
633  if (avctx->hwaccel && !p->hwaccel_serializing) {
635  p->hwaccel_serializing = 1;
636  }
637 
638  /* this assumes that no hwaccel calls happen before ff_thread_finish_setup() */
639  if (avctx->hwaccel &&
641  p->async_serializing = 1;
642 
643  async_lock(p->parent);
644  }
645 
646  /* save hwaccel state for passing to the next thread;
647  * this is done here so that this worker thread can wipe its own hwaccel
648  * state after decoding, without requiring synchronization */
650  p->parent->stash_hwaccel = avctx->hwaccel;
653 
656  av_log(avctx, AV_LOG_WARNING, "Multiple ff_thread_finish_setup() calls\n");
657  }
658 
660 
663 }
664 
665 /// Waits for all threads to finish.
666 static void park_frame_worker_threads(FrameThreadContext *fctx, int thread_count)
667 {
668  int i;
669 
670  async_unlock(fctx);
671 
672  for (i = 0; i < thread_count; i++) {
673  PerThreadContext *p = &fctx->threads[i];
674 
675  if (atomic_load(&p->state) != STATE_INPUT_READY) {
677  while (atomic_load(&p->state) != STATE_INPUT_READY)
680  }
681  p->got_frame = 0;
682  }
683 
684  async_lock(fctx);
685 }
686 
687 void ff_frame_thread_free(AVCodecContext *avctx, int thread_count)
688 {
689  FrameThreadContext *fctx = avctx->internal->thread_ctx;
690  const AVCodec *codec = avctx->codec;
691  int i, j;
692 
693  park_frame_worker_threads(fctx, thread_count);
694 
695  if (fctx->prev_thread && fctx->prev_thread != fctx->threads)
696  if (update_context_from_thread(fctx->threads->avctx, fctx->prev_thread->avctx, 0) < 0) {
697  av_log(avctx, AV_LOG_ERROR, "Final thread update failed\n");
699  fctx->threads->avctx->internal->is_copy = 1;
700  }
701 
702  for (i = 0; i < thread_count; i++) {
703  PerThreadContext *p = &fctx->threads[i];
704 
706  p->die = 1;
709 
710  if (p->thread_init)
711  pthread_join(p->thread, NULL);
712  p->thread_init=0;
713 
714  if (codec->close && p->avctx)
715  codec->close(p->avctx);
716 
718  av_frame_free(&p->frame);
719  }
720 
721  for (i = 0; i < thread_count; i++) {
722  PerThreadContext *p = &fctx->threads[i];
723 
729  av_packet_unref(&p->avpkt);
730 
731  for (j = 0; j < p->released_buffers_allocated; j++)
734 
735  if (p->avctx) {
736  if (codec->priv_class)
738  av_freep(&p->avctx->priv_data);
739 
741  }
742 
743  if (p->avctx) {
745  av_freep(&p->avctx->internal);
747  }
748 
749  av_freep(&p->avctx);
750  }
751 
752  av_freep(&fctx->threads);
757 
758  /* if we have stashed hwaccel state, move it to the user-facing context,
759  * so it will be freed in avcodec_close() */
760  av_assert0(!avctx->hwaccel);
761  FFSWAP(const AVHWAccel*, avctx->hwaccel, fctx->stash_hwaccel);
762  FFSWAP(void*, avctx->hwaccel_context, fctx->stash_hwaccel_context);
763  FFSWAP(void*, avctx->internal->hwaccel_priv_data, fctx->stash_hwaccel_priv);
764 
765  av_freep(&avctx->internal->thread_ctx);
766 
767  if (avctx->priv_data && avctx->codec && avctx->codec->priv_class)
768  av_opt_free(avctx->priv_data);
769  avctx->codec = NULL;
770 }
771 
773 {
774  int thread_count = avctx->thread_count;
775  const AVCodec *codec = avctx->codec;
777  FrameThreadContext *fctx;
778  int i, err = 0;
779 
780  if (!thread_count) {
781  int nb_cpus = av_cpu_count();
782 #if FF_API_DEBUG_MV
783  if ((avctx->debug & (FF_DEBUG_VIS_QP | FF_DEBUG_VIS_MB_TYPE)) || avctx->debug_mv)
784  nb_cpus = 1;
785 #endif
786  // use number of cores + 1 as thread count if there is more than one
787  if (nb_cpus > 1)
788  thread_count = avctx->thread_count = FFMIN(nb_cpus + 1, MAX_AUTO_THREADS);
789  else
790  thread_count = avctx->thread_count = 1;
791  }
792 
793  if (thread_count <= 1) {
794  avctx->active_thread_type = 0;
795  return 0;
796  }
797 
798  avctx->internal->thread_ctx = fctx = av_mallocz(sizeof(FrameThreadContext));
799  if (!fctx)
800  return AVERROR(ENOMEM);
801 
802  fctx->threads = av_mallocz_array(thread_count, sizeof(PerThreadContext));
803  if (!fctx->threads) {
804  av_freep(&avctx->internal->thread_ctx);
805  return AVERROR(ENOMEM);
806  }
807 
812 
813  fctx->async_lock = 1;
814  fctx->delaying = 1;
815 
816  if (codec->type == AVMEDIA_TYPE_VIDEO)
817  avctx->delay = src->thread_count - 1;
818 
819  for (i = 0; i < thread_count; i++) {
821  PerThreadContext *p = &fctx->threads[i];
822 
828 
829  p->frame = av_frame_alloc();
830  if (!p->frame) {
831  av_freep(&copy);
832  err = AVERROR(ENOMEM);
833  goto error;
834  }
835 
836  p->parent = fctx;
837  p->avctx = copy;
838 
839  if (!copy) {
840  err = AVERROR(ENOMEM);
841  goto error;
842  }
843 
844  *copy = *src;
845 
846  copy->internal = av_malloc(sizeof(AVCodecInternal));
847  if (!copy->internal) {
848  copy->priv_data = NULL;
849  err = AVERROR(ENOMEM);
850  goto error;
851  }
852  *copy->internal = *src->internal;
853  copy->internal->thread_ctx = p;
854  copy->internal->last_pkt_props = &p->avpkt;
855 
856  copy->delay = avctx->delay;
857 
858  if (codec->priv_data_size) {
859  copy->priv_data = av_mallocz(codec->priv_data_size);
860  if (!copy->priv_data) {
861  err = AVERROR(ENOMEM);
862  goto error;
863  }
864 
865  if (codec->priv_class) {
866  *(const AVClass **)copy->priv_data = codec->priv_class;
867  err = av_opt_copy(copy->priv_data, src->priv_data);
868  if (err < 0)
869  goto error;
870  }
871  }
872 
873  if (i)
874  copy->internal->is_copy = 1;
875 
876  if (codec->init)
877  err = codec->init(copy);
878 
879  if (err) goto error;
880 
881  if (!i)
882  update_context_from_thread(avctx, copy, 1);
883 
884  atomic_init(&p->debug_threads, (copy->debug & FF_DEBUG_THREADS) != 0);
885 
887  p->thread_init= !err;
888  if(!p->thread_init)
889  goto error;
890  }
891 
892  return 0;
893 
894 error:
895  ff_frame_thread_free(avctx, i+1);
896 
897  return err;
898 }
899 
901 {
902  int i;
903  FrameThreadContext *fctx = avctx->internal->thread_ctx;
904 
905  if (!fctx) return;
906 
908  if (fctx->prev_thread) {
909  if (fctx->prev_thread != &fctx->threads[0])
911  }
912 
913  fctx->next_decoding = fctx->next_finished = 0;
914  fctx->delaying = 1;
915  fctx->prev_thread = NULL;
916  for (i = 0; i < avctx->thread_count; i++) {
917  PerThreadContext *p = &fctx->threads[i];
918  // Make sure decode flush calls with size=0 won't return old frames
919  p->got_frame = 0;
920  av_frame_unref(p->frame);
921  p->result = 0;
922 
924 
925  if (avctx->codec->flush)
926  avctx->codec->flush(p->avctx);
927  }
928 }
929 
931 {
932  PerThreadContext *p = avctx->internal->thread_ctx;
934  (avctx->codec->update_thread_context || !THREAD_SAFE_CALLBACKS(avctx))) {
935  return 0;
936  }
937  return 1;
938 }
939 
941 {
942  PerThreadContext *p = avctx->internal->thread_ctx;
943  int err;
944 
945  f->owner[0] = f->owner[1] = avctx;
946 
947  if (!(avctx->active_thread_type & FF_THREAD_FRAME))
948  return ff_get_buffer(avctx, f->f, flags);
949 
950  if (atomic_load(&p->state) != STATE_SETTING_UP &&
951  (avctx->codec->update_thread_context || !THREAD_SAFE_CALLBACKS(avctx))) {
952  av_log(avctx, AV_LOG_ERROR, "get_buffer() cannot be called after ff_thread_finish_setup()\n");
953  return -1;
954  }
955 
957  atomic_int *progress;
958  f->progress = av_buffer_alloc(2 * sizeof(*progress));
959  if (!f->progress) {
960  return AVERROR(ENOMEM);
961  }
962  progress = (atomic_int*)f->progress->data;
963 
964  atomic_init(&progress[0], -1);
965  atomic_init(&progress[1], -1);
966  }
967 
969  if (THREAD_SAFE_CALLBACKS(avctx)) {
970  err = ff_get_buffer(avctx, f->f, flags);
971  } else {
973  p->requested_frame = f->f;
974  p->requested_flags = flags;
975  atomic_store_explicit(&p->state, STATE_GET_BUFFER, memory_order_release);
977 
978  while (atomic_load(&p->state) != STATE_SETTING_UP)
980 
981  err = p->result;
982 
984 
985  }
986  if (!THREAD_SAFE_CALLBACKS(avctx) && !avctx->codec->update_thread_context)
987  ff_thread_finish_setup(avctx);
988  if (err)
990 
992 
993  return err;
994 }
995 
997 {
998  enum AVPixelFormat res;
999  PerThreadContext *p = avctx->internal->thread_ctx;
1000  if (!(avctx->active_thread_type & FF_THREAD_FRAME) || avctx->thread_safe_callbacks ||
1002  return ff_get_format(avctx, fmt);
1003  if (atomic_load(&p->state) != STATE_SETTING_UP) {
1004  av_log(avctx, AV_LOG_ERROR, "get_format() cannot be called after ff_thread_finish_setup()\n");
1005  return -1;
1006  }
1008  p->available_formats = fmt;
1011 
1012  while (atomic_load(&p->state) != STATE_SETTING_UP)
1014 
1015  res = p->result_format;
1016 
1018 
1019  return res;
1020 }
1021 
1023 {
1024  int ret = thread_get_buffer_internal(avctx, f, flags);
1025  if (ret < 0)
1026  av_log(avctx, AV_LOG_ERROR, "thread_get_buffer() failed\n");
1027  return ret;
1028 }
1029 
1031 {
1032  PerThreadContext *p = avctx->internal->thread_ctx;
1033  FrameThreadContext *fctx;
1034  AVFrame *dst;
1035  int ret = 0;
1036  int can_direct_free = !(avctx->active_thread_type & FF_THREAD_FRAME) ||
1037  THREAD_SAFE_CALLBACKS(avctx);
1038 
1039  if (!f->f)
1040  return;
1041 
1042  if (avctx->debug & FF_DEBUG_BUFFERS)
1043  av_log(avctx, AV_LOG_DEBUG, "thread_release_buffer called on pic %p\n", f);
1044 
1046  f->owner[0] = f->owner[1] = NULL;
1047 
1048  // when the frame buffers are not allocated, just reset it to clean state
1049  if (can_direct_free || !f->f->buf[0]) {
1050  av_frame_unref(f->f);
1051  return;
1052  }
1053 
1054  fctx = p->parent;
1056 
1059  sizeof(*p->released_buffers));
1060  if (tmp) {
1062  p->released_buffers = tmp;
1063  }
1064 
1065  if (!tmp || !tmp[p->released_buffers_allocated]) {
1066  ret = AVERROR(ENOMEM);
1067  goto fail;
1068  }
1070  }
1071 
1073  av_frame_move_ref(dst, f->f);
1074 
1075  p->num_released_buffers++;
1076 
1077 fail:
1079 
1080  // make sure the frame is clean even if we fail to free it
1081  // this leaks, but it is better than crashing
1082  if (ret < 0) {
1083  av_log(avctx, AV_LOG_ERROR, "Could not queue a frame for freeing, this will leak\n");
1084  memset(f->f->buf, 0, sizeof(f->f->buf));
1085  if (f->f->extended_buf)
1086  memset(f->f->extended_buf, 0, f->f->nb_extended_buf * sizeof(*f->f->extended_buf));
1087  av_frame_unref(f->f);
1088  }
1089 }
static int thread_get_buffer_internal(AVCodecContext *avctx, ThreadFrame *f, int flags)
enum AVPixelFormat(* get_format)(struct AVCodecContext *s, const enum AVPixelFormat *fmt)
callback to negotiate the pixelFormat
Definition: avcodec.h:778
int caps_internal
Internal hwaccel capabilities.
Definition: avcodec.h:2559
Set when the codec calls get_format().
Definition: pthread_frame.c:62
pthread_cond_t progress_cond
Used by child threads to wait for progress to change.
Definition: pthread_frame.c:76
#define NULL
Definition: coverity.c:32
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition: decode.c:1279
const struct AVCodec * codec
Definition: avcodec.h:535
AVRational framerate
Definition: avcodec.h:2069
#define AV_CODEC_PROP_INTRA_ONLY
Codec uses only intra compression.
Definition: codec_desc.h:72
const AVCodecDescriptor * codec_descriptor
AVCodecDescriptor.
Definition: avcodec.h:2090
static av_always_inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
Definition: os2threads.h:112
static void copy(const float *p1, float *p2, const int length)
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
Definition: buffer.c:125
This structure describes decoded (raw) audio or video data.
Definition: frame.h:300
#define pthread_mutex_lock(a)
Definition: ffprobe.c:62
static av_always_inline int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
Definition: os2threads.h:192
#define atomic_store(object, desired)
Definition: stdatomic.h:85
Context used by codec threads and stored in their AVCodecInternal thread_ctx.
Definition: pthread_frame.c:70
int av_cpu_count(void)
Definition: cpu.c:267
AVFrame * requested_frame
AVFrame the codec passed to get_buffer()
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:714
atomic_int state
Definition: pthread_frame.c:90
AVPacket * last_pkt_props
Properties (timestamps+side data) extracted from the last packet passed for decoding.
Definition: internal.h:144
static int submit_packet(PerThreadContext *p, AVCodecContext *user_avctx, AVPacket *avpkt)
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
AVFrame * f
Definition: thread.h:35
Memory handling functions.
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:491
Set when the codec calls get_buffer().
Definition: pthread_frame.c:57
void(* flush)(struct AVCodecContext *)
Flush buffers.
Definition: codec.h:305
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:1161
int nb_extended_buf
Number of elements in extended_buf.
Definition: frame.h:509
int size
Definition: packet.h:356
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
Definition: avcodec.h:905
Set when the thread is awaiting a packet.
Definition: pthread_frame.c:50
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:736
void * stash_hwaccel_context
const AVHWAccel * stash_hwaccel
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition: frame.c:583
enum AVMediaType type
Definition: codec.h:203
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:1757
static void error(const char *err)
pthread_cond_t input_cond
Used to wait for a new packet from the main thread.
Definition: pthread_frame.c:75
intptr_t atomic_int
Definition: stdatomic.h:55
void ff_thread_await_progress(ThreadFrame *f, int n, int field)
Wait for earlier decoding threads to finish reference pictures.
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition: avcodec.h:1690
int profile
profile
Definition: avcodec.h:1859
enum AVPixelFormat * available_formats
Format array for get_format()
AVCodec.
Definition: codec.h:190
static av_always_inline int pthread_cond_destroy(pthread_cond_t *cond)
Definition: os2threads.h:144
AVPacket avpkt
Input packet (for decoding) or output (for encoding).
Definition: pthread_frame.c:84
void(* draw_horiz_band)(struct AVCodecContext *s, const AVFrame *src, int offset[AV_NUM_DATA_POINTERS], int y, int type, int height)
If non NULL, &#39;draw_horiz_band&#39; is called by the libavcodec decoder to draw a horizontal band...
Definition: avcodec.h:761
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:649
enum AVDiscard skip_frame
Skip decoding for selected frames.
Definition: avcodec.h:2004
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: codec.h:75
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
int export_side_data
Bit set of AV_CODEC_EXPORT_DATA_* flags, which affects the kind of metadata exported in frame...
Definition: avcodec.h:2354
enum AVPixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum AVPixelFormat *fmt)
Definition: decode.c:1067
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1194
#define av_malloc(s)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:190
void * hwaccel_context
Hardware accelerator context.
Definition: avcodec.h:1702
AVOptions.
#define f(width, name)
Definition: cbs_vp9.c:255
static attribute_align_arg void * frame_worker_thread(void *arg)
Codec worker thread.
void * thread_ctx
Definition: internal.h:135
Multithreading support functions.
#define THREAD_SAFE_CALLBACKS(avctx)
pthread_mutex_t hwaccel_mutex
This lock is used for ensuring threads run in serial when hwaccel is used.
static void finish(void)
Definition: movenc.c:345
int requested_flags
flags passed to get_buffer() for requested_frame
int next_decoding
The next context to submit a packet to.
static av_always_inline int pthread_cond_signal(pthread_cond_t *cond)
Definition: os2threads.h:152
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition: avcodec.h:1750
void ff_thread_finish_setup(AVCodecContext *avctx)
If the codec defines update_thread_context(), call this when they are ready for the next thread to st...
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate, or free an array.
Definition: mem.c:198
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Definition: avcodec.h:1168
Context stored in the client AVCodecInternal thread_ctx.
AVCodecContext * avctx
Context used to decode packets passed to this thread.
Definition: pthread_frame.c:82
#define av_log(a,...)
#define FF_CODEC_CAP_ALLOCATE_PROGRESS
Definition: internal.h:75
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
Definition: avpacket.c:614
int die
Set when the thread should exit.
int ff_thread_decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, AVPacket *avpkt)
Submit a new frame to a decoding thread.
int slice_count
slice count
Definition: avcodec.h:880
Libavcodec version macros.
#define src
Definition: vp8dsp.c:254
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
int has_b_frames
Size of the frame reordering buffer in the decoder.
Definition: avcodec.h:816
PerThreadContext * prev_thread
The last thread submit_packet() was called on.
void ff_frame_thread_free(AVCodecContext *avctx, int thread_count)
void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
Wrapper around release_buffer() frame-for multithreaded codecs.
#define atomic_load(object)
Definition: stdatomic.h:93
int is_copy
Whether the parent AVCodecContext is a copy of the context which had init() called on it...
Definition: internal.h:123
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
int active_thread_type
Which multithreading methods are in use by the codec.
Definition: avcodec.h:1804
int capabilities
Codec capabilities.
Definition: codec.h:209
int result
The result of the last codec decode/encode() call.
Definition: pthread_frame.c:88
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
const char * arg
Definition: jacosubdec.c:66
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:606
simple assert() macros that are a bit more flexible than ISO C assert().
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:237
#define fail()
Definition: checkasm.h:123
reference-counted frame API
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:1237
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate, or free an array through a pointer to a pointer.
Definition: mem.c:206
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
Definition: codec_desc.h:54
common internal API header
#define HWACCEL_CAP_ASYNC_SAFE
Definition: hwconfig.h:26
pthread_cond_t output_cond
Used by the main thread to wait for frames to finish.
Definition: pthread_frame.c:77
int(* update_thread_context)(struct AVCodecContext *dst, const struct AVCodecContext *src)
Copy necessary context variables from a previous thread context to the current one.
Definition: codec.h:251
AVFrame ** released_buffers
Array of frames passed to ff_thread_release_buffer().
Definition: pthread_frame.c:96
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition: avcodec.h:1796
#define FFMIN(a, b)
Definition: common.h:96
AVBufferRef ** extended_buf
For planar audio which requires more than AV_NUM_DATA_POINTERS AVBufferRef pointers, this array will hold all the references which cannot fit into AVFrame.buf.
Definition: frame.h:505
int width
picture width / height.
Definition: avcodec.h:699
int idct_algo
IDCT algorithm, see FF_IDCT_* below.
Definition: avcodec.h:1729
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames...
Definition: avcodec.h:2226
int priv_data_size
Definition: codec.h:238
void ff_thread_report_progress(ThreadFrame *f, int n, int field)
Notify later decoding threads when part of their reference picture is ready.
#define atomic_load_explicit(object, order)
Definition: stdatomic.h:96
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:1140
static av_always_inline int pthread_join(pthread_t thread, void **value_ptr)
Definition: os2threads.h:94
static av_always_inline int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
Definition: os2threads.h:104
int level
level
Definition: avcodec.h:1982
#define FF_DEBUG_BUFFERS
Definition: avcodec.h:1633
int64_t reordered_opaque
opaque 64-bit number (generally a PTS) that will be reordered and output in AVFrame.reordered_opaque
Definition: avcodec.h:1683
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
Definition: avcodec.h:658
pthread_t thread
Definition: pthread_frame.c:73
#define pthread_mutex_unlock(a)
Definition: ffprobe.c:66
#define FF_DEBUG_THREADS
Definition: avcodec.h:1634
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
Definition: avcodec.h:1785
int got_frame
The output of got_picture_ptr from the last avcodec_decode_video() call.
Definition: pthread_frame.c:87
static int update_context_from_user(AVCodecContext *dst, AVCodecContext *src)
Update the next thread&#39;s AVCodecContext with values set by the user.
pthread_mutex_t buffer_mutex
Mutex used to protect get/release_buffer().
AVBufferRef * progress
Definition: thread.h:39
pthread_mutex_t progress_mutex
Mutex used to protect frame progress values and progress_cond.
Definition: pthread_frame.c:80
#define attribute_align_arg
Definition: internal.h:62
static av_always_inline int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
Definition: os2threads.h:80
int(* decode)(struct AVCodecContext *, void *outdata, int *outdata_size, struct AVPacket *avpkt)
Definition: codec.h:282
pthread_cond_t async_cond
int avcodec_default_get_buffer2(AVCodecContext *s, AVFrame *frame, int flags)
The default callback for AVCodecContext.get_buffer2().
Definition: decode.c:1649
Libavcodec external API header.
enum AVMediaType codec_type
Definition: avcodec.h:534
enum AVCodecID codec_id
Definition: avcodec.h:536
AVBufferRef * av_buffer_alloc(int size)
Allocate an AVBuffer of the given size using av_malloc().
Definition: buffer.c:67
int sample_rate
samples per second
Definition: avcodec.h:1186
enum AVDiscard skip_idct
Skip IDCT/dequantization for selected frames.
Definition: avcodec.h:1997
int debug
debug
Definition: avcodec.h:1611
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
main external API structure.
Definition: avcodec.h:526
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:605
uint8_t * data
The data buffer.
Definition: buffer.h:89
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1854
int slice_flags
slice flags
Definition: avcodec.h:1004
AVCodecContext * owner[2]
Definition: thread.h:36
int coded_height
Definition: avcodec.h:714
Describe the class of an AVClass context structure.
Definition: log.h:67
int(* init)(struct AVCodecContext *)
Definition: codec.h:267
int(* get_buffer2)(struct AVCodecContext *s, AVFrame *frame, int flags)
This callback is called at the beginning of each frame to get data buffer(s) for it.
Definition: avcodec.h:1341
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:1154
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:1147
enum AVPixelFormat result_format
get_format() result
int delaying
Set for the first N packets, where N is the number of threads.
refcounted data buffer API
enum AVPixelFormat ff_thread_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Wrapper around get_format() for frame-multithreaded codecs.
#define atomic_store_explicit(object, desired, order)
Definition: stdatomic.h:90
static void async_unlock(FrameThreadContext *fctx)
PerThreadContext * threads
The contexts for each thread.
static void async_lock(FrameThreadContext *fctx)
AVBufferRef * pool
Definition: internal.h:133
#define MAX_AUTO_THREADS
struct FrameThreadContext * parent
Definition: pthread_frame.c:71
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:554
#define flags(name, subs,...)
Definition: cbs_av1.c:576
const AVClass * priv_class
AVClass for the private context.
Definition: codec.h:216
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:314
int64_t pkt_dts
DTS copied from the AVPacket that triggered returning this frame.
Definition: frame.h:409
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1610
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:84
common internal api header.
_fmutex pthread_mutex_t
Definition: os2threads.h:53
common internal and external API header
if(ret< 0)
Definition: vf_mcdeint.c:279
int released_buffers_allocated
Definition: pthread_frame.c:98
void * hwaccel_priv_data
hwaccel-specific private data
Definition: internal.h:162
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:93
static int update_context_from_thread(AVCodecContext *dst, AVCodecContext *src, int for_user)
Update the next thread&#39;s AVCodecContext with values from the reference thread&#39;s context.
int av_opt_copy(void *dst, const void *src)
Copy options from src object into dest object.
Definition: opt.c:1768
static av_always_inline int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
Definition: os2threads.h:133
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:1776
int caps_internal
Internal codec capabilities.
Definition: codec.h:310
enum AVDiscard skip_loop_filter
Skip loop filtering for selected frames.
Definition: avcodec.h:1990
int thread_safe_callbacks
Set by the client if its custom get_buffer() callback can be called synchronously from another thread...
Definition: avcodec.h:1814
void * priv_data
Definition: avcodec.h:553
int(* close)(struct AVCodecContext *)
Definition: codec.h:283
void ff_thread_flush(AVCodecContext *avctx)
Wait for decoding threads to finish and reset internal state.
AVFrame * frame
Output frame (for decoding) or input (for encoding).
Definition: pthread_frame.c:86
int ff_thread_can_start_frame(AVCodecContext *avctx)
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:85
static av_always_inline int pthread_cond_broadcast(pthread_cond_t *cond)
Definition: os2threads.h:162
int channels
number of audio channels
Definition: avcodec.h:1187
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:561
pthread_mutex_t mutex
Mutex used to protect the contents of the PerThreadContext.
Definition: pthread_frame.c:79
int flags2
AV_CODEC_FLAG2_*.
Definition: avcodec.h:613
static void park_frame_worker_threads(FrameThreadContext *fctx, int thread_count)
Waits for all threads to finish.
pthread_mutex_t async_mutex
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: packet.h:354
int * slice_offset
slice offsets in the frame in bytes
Definition: avcodec.h:896
int frame_number
Frame counter, set by libavcodec.
Definition: avcodec.h:1217
atomic_int debug_threads
Set if the FF_DEBUG_THREADS option is set.
static void release_delayed_buffers(PerThreadContext *p)
Releases the buffers that this decoding thread was the last user of.
#define atomic_init(obj, value)
Definition: stdatomic.h:33
#define av_freep(p)
int hwaccel_flags
Bit set of AV_HWACCEL_FLAG_* flags, which affect hardware accelerated decoding (if active)...
Definition: avcodec.h:2287
#define FFSWAP(type, a, b)
Definition: common.h:99
int debug_mv
debug motion vectors
Definition: avcodec.h:2157
int next_finished
The next context to return output from.
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:347
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
This structure stores compressed data.
Definition: packet.h:332
int delay
Codec delay.
Definition: avcodec.h:682
int ff_frame_thread_init(AVCodecContext *avctx)
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:2076
void * opaque
Private data of the user, can be used to carry app specific stuff.
Definition: avcodec.h:568
void * av_mallocz_array(size_t nmemb, size_t size)
Allocate a memory block for an array with av_mallocz().
Definition: mem.c:190
static uint8_t tmp[11]
Definition: aes_ctr.c:26