FFmpeg
ffmpeg_dec.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 #include <stdbit.h>
20 
21 #include "libavutil/avassert.h"
22 #include "libavutil/avstring.h"
23 #include "libavutil/dict.h"
24 #include "libavutil/error.h"
25 #include "libavutil/log.h"
26 #include "libavutil/mem.h"
27 #include "libavutil/opt.h"
28 #include "libavutil/pixdesc.h"
29 #include "libavutil/pixfmt.h"
30 #include "libavutil/stereo3d.h"
31 #include "libavutil/time.h"
32 #include "libavutil/timestamp.h"
33 
34 #include "libavcodec/avcodec.h"
35 #include "libavcodec/codec.h"
36 
37 #include "ffmpeg.h"
38 
39 typedef struct DecoderPriv {
41 
43 
47 
48  // override output video sample aspect ratio with this value
50 
52 
53  // a combination of DECODER_FLAG_*, provided to dec_open()
54  int flags;
56 
61 
62  // pts/estimated duration of the last decoded frame
63  // * in decoder timebase for video,
64  // * in last_frame_tb (may change during decoding) for audio
70 
71  /* previous decoded subtitles */
74 
76  unsigned sch_idx;
77 
78  // this decoder's index in decoders or -1
79  int index;
80  void *log_parent;
81  char log_name[32];
82  char *parent_name;
83 
84  // user specified decoder multiview options manually
86 
87  struct {
89  unsigned out_idx;
90  } *views_requested;
92 
93  /* A map of view ID to decoder outputs.
94  * MUST NOT be accessed outside of get_format()/get_buffer() */
95  struct {
96  unsigned id;
97  uintptr_t out_mask;
98  } *view_map;
100 
101  struct {
103  const AVCodec *codec;
104  } standalone_init;
105 } DecoderPriv;
106 
108 {
109  return (DecoderPriv*)d;
110 }
111 
112 // data that is local to the decoder thread and not visible outside of it
113 typedef struct DecThreadContext {
117 
118 void dec_free(Decoder **pdec)
119 {
120  Decoder *dec = *pdec;
121  DecoderPriv *dp;
122 
123  if (!dec)
124  return;
125  dp = dp_from_dec(dec);
126 
128 
129  av_frame_free(&dp->frame);
131  av_packet_free(&dp->pkt);
132 
134 
135  for (int i = 0; i < FF_ARRAY_ELEMS(dp->sub_prev); i++)
136  av_frame_free(&dp->sub_prev[i]);
138 
140 
141  av_freep(&dp->parent_name);
142 
144  av_freep(&dp->view_map);
145 
146  av_freep(pdec);
147 }
148 
149 static const char *dec_item_name(void *obj)
150 {
151  const DecoderPriv *dp = obj;
152 
153  return dp->log_name;
154 }
155 
156 static const AVClass dec_class = {
157  .class_name = "Decoder",
158  .version = LIBAVUTIL_VERSION_INT,
159  .parent_log_context_offset = offsetof(DecoderPriv, log_parent),
160  .item_name = dec_item_name,
161 };
162 
163 static int decoder_thread(void *arg);
164 
165 static int dec_alloc(DecoderPriv **pdec, Scheduler *sch, int send_end_ts)
166 {
167  DecoderPriv *dp;
168  int ret = 0;
169 
170  *pdec = NULL;
171 
172  dp = av_mallocz(sizeof(*dp));
173  if (!dp)
174  return AVERROR(ENOMEM);
175 
176  dp->frame = av_frame_alloc();
177  if (!dp->frame)
178  goto fail;
179 
180  dp->pkt = av_packet_alloc();
181  if (!dp->pkt)
182  goto fail;
183 
184  dp->index = -1;
185  dp->dec.class = &dec_class;
188  dp->last_frame_tb = (AVRational){ 1, 1 };
190 
191  ret = sch_add_dec(sch, decoder_thread, dp, send_end_ts);
192  if (ret < 0)
193  goto fail;
194  dp->sch = sch;
195  dp->sch_idx = ret;
196 
197  *pdec = dp;
198 
199  return 0;
200 fail:
201  dec_free((Decoder**)&dp);
202  return ret >= 0 ? AVERROR(ENOMEM) : ret;
203 }
204 
206  const AVFrame *frame)
207 {
208  const int prev = dp->last_frame_tb.den;
209  const int sr = frame->sample_rate;
210 
211  AVRational tb_new;
212  int64_t gcd;
213 
214  if (frame->sample_rate == dp->last_frame_sample_rate)
215  goto finish;
216 
217  gcd = av_gcd(prev, sr);
218 
219  if (prev / gcd >= INT_MAX / sr) {
221  "Audio timestamps cannot be represented exactly after "
222  "sample rate change: %d -> %d\n", prev, sr);
223 
224  // LCM of 192000, 44100, allows to represent all common samplerates
225  tb_new = (AVRational){ 1, 28224000 };
226  } else
227  tb_new = (AVRational){ 1, prev / gcd * sr };
228 
229  // keep the frame timebase if it is strictly better than
230  // the samplerate-defined one
231  if (frame->time_base.num == 1 && frame->time_base.den > tb_new.den &&
232  !(frame->time_base.den % tb_new.den))
233  tb_new = frame->time_base;
234 
237  dp->last_frame_tb, tb_new);
239  dp->last_frame_tb, tb_new);
240 
241  dp->last_frame_tb = tb_new;
242  dp->last_frame_sample_rate = frame->sample_rate;
243 
244 finish:
245  return dp->last_frame_tb;
246 }
247 
249 {
250  AVRational tb_filter = (AVRational){1, frame->sample_rate};
251  AVRational tb;
252  int64_t pts_pred;
253 
254  // on samplerate change, choose a new internal timebase for timestamp
255  // generation that can represent timestamps from all the samplerates
256  // seen so far
257  tb = audio_samplerate_update(dp, frame);
258  pts_pred = dp->last_frame_pts == AV_NOPTS_VALUE ? 0 :
260 
261  if (frame->pts == AV_NOPTS_VALUE) {
262  frame->pts = pts_pred;
263  frame->time_base = tb;
264  } else if (dp->last_frame_pts != AV_NOPTS_VALUE &&
265  frame->pts > av_rescale_q_rnd(pts_pred, tb, frame->time_base,
266  AV_ROUND_UP)) {
267  // there was a gap in timestamps, reset conversion state
269  }
270 
271  frame->pts = av_rescale_delta(frame->time_base, frame->pts,
272  tb, frame->nb_samples,
274 
275  dp->last_frame_pts = frame->pts;
276  dp->last_frame_duration_est = av_rescale_q(frame->nb_samples,
277  tb_filter, tb);
278 
279  // finally convert to filtering timebase
280  frame->pts = av_rescale_q(frame->pts, tb, tb_filter);
281  frame->duration = frame->nb_samples;
282  frame->time_base = tb_filter;
283 }
284 
286 {
287  const int ts_unreliable = dp->flags & DECODER_FLAG_TS_UNRELIABLE;
288  const int fr_forced = dp->flags & DECODER_FLAG_FRAMERATE_FORCED;
289  int64_t codec_duration = 0;
290  // difference between this and last frame's timestamps
291  const int64_t ts_diff =
292  (frame->pts != AV_NOPTS_VALUE && dp->last_frame_pts != AV_NOPTS_VALUE) ?
293  frame->pts - dp->last_frame_pts : -1;
294 
295  // XXX lavf currently makes up frame durations when they are not provided by
296  // the container. As there is no way to reliably distinguish real container
297  // durations from the fake made-up ones, we use heuristics based on whether
298  // the container has timestamps. Eventually lavf should stop making up
299  // durations, then this should be simplified.
300 
301  // frame duration is unreliable (typically guessed by lavf) when it is equal
302  // to 1 and the actual duration of the last frame is more than 2x larger
303  const int duration_unreliable = frame->duration == 1 && ts_diff > 2 * frame->duration;
304 
305  // prefer frame duration for containers with timestamps
306  if (fr_forced ||
307  (frame->duration > 0 && !ts_unreliable && !duration_unreliable))
308  return frame->duration;
309 
310  if (dp->dec_ctx->framerate.den && dp->dec_ctx->framerate.num) {
311  int fields = frame->repeat_pict + 2;
312  AVRational field_rate = av_mul_q(dp->dec_ctx->framerate,
313  (AVRational){ 2, 1 });
314  codec_duration = av_rescale_q(fields, av_inv_q(field_rate),
315  frame->time_base);
316  }
317 
318  // prefer codec-layer duration for containers without timestamps
319  if (codec_duration > 0 && ts_unreliable)
320  return codec_duration;
321 
322  // when timestamps are available, repeat last frame's actual duration
323  // (i.e. pts difference between this and last frame)
324  if (ts_diff > 0)
325  return ts_diff;
326 
327  // try frame/codec duration
328  if (frame->duration > 0)
329  return frame->duration;
330  if (codec_duration > 0)
331  return codec_duration;
332 
333  // try average framerate
334  if (dp->framerate_in.num && dp->framerate_in.den) {
336  frame->time_base);
337  if (d > 0)
338  return d;
339  }
340 
341  // last resort is last frame's estimated duration, and 1
342  return FFMAX(dp->last_frame_duration_est, 1);
343 }
344 
346 {
347  DecoderPriv *dp = avctx->opaque;
348  AVFrame *output = NULL;
350  int err;
351 
352  if (input->format == output_format) {
353  // Nothing to do.
354  return 0;
355  }
356 
358  if (!output)
359  return AVERROR(ENOMEM);
360 
361  output->format = output_format;
362 
364  if (err < 0) {
365  av_log(avctx, AV_LOG_ERROR, "Failed to transfer data to "
366  "output frame: %d.\n", err);
367  goto fail;
368  }
369 
371  if (err < 0) {
373  goto fail;
374  }
375 
379 
380  return 0;
381 
382 fail:
384  return err;
385 }
386 
388  unsigned *outputs_mask)
389 {
390  if (frame->format == dp->hwaccel_pix_fmt) {
391  int err = hwaccel_retrieve_data(dp->dec_ctx, frame);
392  if (err < 0)
393  return err;
394  }
395 
396  frame->pts = frame->best_effort_timestamp;
397 
398  // forced fixed framerate
400  frame->pts = AV_NOPTS_VALUE;
401  frame->duration = 1;
402  frame->time_base = av_inv_q(dp->framerate_in);
403  }
404 
405  // no timestamp available - extrapolate from previous frame duration
406  if (frame->pts == AV_NOPTS_VALUE)
407  frame->pts = dp->last_frame_pts == AV_NOPTS_VALUE ? 0 :
409 
410  // update timestamp history
412  dp->last_frame_pts = frame->pts;
413  dp->last_frame_tb = frame->time_base;
414 
415  if (debug_ts) {
416  av_log(dp, AV_LOG_INFO,
417  "decoder -> pts:%s pts_time:%s "
418  "pkt_dts:%s pkt_dts_time:%s "
419  "duration:%s duration_time:%s "
420  "keyframe:%d frame_type:%d time_base:%d/%d\n",
421  av_ts2str(frame->pts),
422  av_ts2timestr(frame->pts, &frame->time_base),
423  av_ts2str(frame->pkt_dts),
424  av_ts2timestr(frame->pkt_dts, &frame->time_base),
425  av_ts2str(frame->duration),
426  av_ts2timestr(frame->duration, &frame->time_base),
427  !!(frame->flags & AV_FRAME_FLAG_KEY), frame->pict_type,
428  frame->time_base.num, frame->time_base.den);
429  }
430 
431  if (dp->sar_override.num)
432  frame->sample_aspect_ratio = dp->sar_override;
433 
434  if (dp->apply_cropping) {
435  // lavfi does not require aligned frame data
437  if (ret < 0) {
438  av_log(dp, AV_LOG_ERROR, "Error applying decoder cropping\n");
439  return ret;
440  }
441  }
442 
443  if (frame->opaque)
444  *outputs_mask = (uintptr_t)frame->opaque;
445 
446  return 0;
447 }
448 
450 {
451  int ret = AVERROR_BUG;
452  AVSubtitle tmp = {
453  .format = src->format,
454  .start_display_time = src->start_display_time,
455  .end_display_time = src->end_display_time,
456  .num_rects = 0,
457  .rects = NULL,
458  .pts = src->pts
459  };
460 
461  if (!src->num_rects)
462  goto success;
463 
464  if (!(tmp.rects = av_calloc(src->num_rects, sizeof(*tmp.rects))))
465  return AVERROR(ENOMEM);
466 
467  for (int i = 0; i < src->num_rects; i++) {
468  AVSubtitleRect *src_rect = src->rects[i];
469  AVSubtitleRect *dst_rect;
470 
471  if (!(dst_rect = tmp.rects[i] = av_mallocz(sizeof(*tmp.rects[0])))) {
472  ret = AVERROR(ENOMEM);
473  goto cleanup;
474  }
475 
476  tmp.num_rects++;
477 
478  dst_rect->type = src_rect->type;
479  dst_rect->flags = src_rect->flags;
480 
481  dst_rect->x = src_rect->x;
482  dst_rect->y = src_rect->y;
483  dst_rect->w = src_rect->w;
484  dst_rect->h = src_rect->h;
485  dst_rect->nb_colors = src_rect->nb_colors;
486 
487  if (src_rect->text)
488  if (!(dst_rect->text = av_strdup(src_rect->text))) {
489  ret = AVERROR(ENOMEM);
490  goto cleanup;
491  }
492 
493  if (src_rect->ass)
494  if (!(dst_rect->ass = av_strdup(src_rect->ass))) {
495  ret = AVERROR(ENOMEM);
496  goto cleanup;
497  }
498 
499  for (int j = 0; j < 4; j++) {
500  // SUBTITLE_BITMAP images are special in the sense that they
501  // are like PAL8 images. first pointer to data, second to
502  // palette. This makes the size calculation match this.
503  size_t buf_size = src_rect->type == SUBTITLE_BITMAP && j == 1 ?
505  src_rect->h * src_rect->linesize[j];
506 
507  if (!src_rect->data[j])
508  continue;
509 
510  if (!(dst_rect->data[j] = av_memdup(src_rect->data[j], buf_size))) {
511  ret = AVERROR(ENOMEM);
512  goto cleanup;
513  }
514  dst_rect->linesize[j] = src_rect->linesize[j];
515  }
516  }
517 
518 success:
519  *dst = tmp;
520 
521  return 0;
522 
523 cleanup:
525 
526  return ret;
527 }
528 
529 static void subtitle_free(void *opaque, uint8_t *data)
530 {
531  AVSubtitle *sub = (AVSubtitle*)data;
532  avsubtitle_free(sub);
533  av_free(sub);
534 }
535 
536 static int subtitle_wrap_frame(AVFrame *frame, AVSubtitle *subtitle, int copy)
537 {
538  AVBufferRef *buf;
539  AVSubtitle *sub;
540  int ret;
541 
542  if (copy) {
543  sub = av_mallocz(sizeof(*sub));
544  ret = sub ? copy_av_subtitle(sub, subtitle) : AVERROR(ENOMEM);
545  if (ret < 0) {
546  av_freep(&sub);
547  return ret;
548  }
549  } else {
550  sub = av_memdup(subtitle, sizeof(*subtitle));
551  if (!sub)
552  return AVERROR(ENOMEM);
553  memset(subtitle, 0, sizeof(*subtitle));
554  }
555 
556  buf = av_buffer_create((uint8_t*)sub, sizeof(*sub),
557  subtitle_free, NULL, 0);
558  if (!buf) {
559  avsubtitle_free(sub);
560  av_freep(&sub);
561  return AVERROR(ENOMEM);
562  }
563 
564  frame->buf[0] = buf;
565 
566  return 0;
567 }
568 
570 {
571  const AVSubtitle *subtitle = (AVSubtitle*)frame->buf[0]->data;
572  int ret = 0;
573 
575  AVSubtitle *sub_prev = dp->sub_prev[0]->buf[0] ?
576  (AVSubtitle*)dp->sub_prev[0]->buf[0]->data : NULL;
577  int end = 1;
578  if (sub_prev) {
579  end = av_rescale(subtitle->pts - sub_prev->pts,
580  1000, AV_TIME_BASE);
581  if (end < sub_prev->end_display_time) {
582  av_log(dp, AV_LOG_DEBUG,
583  "Subtitle duration reduced from %"PRId32" to %d%s\n",
584  sub_prev->end_display_time, end,
585  end <= 0 ? ", dropping it" : "");
586  sub_prev->end_display_time = end;
587  }
588  }
589 
590  av_frame_unref(dp->sub_prev[1]);
592 
593  frame = dp->sub_prev[0];
594  subtitle = frame->buf[0] ? (AVSubtitle*)frame->buf[0]->data : NULL;
595 
596  FFSWAP(AVFrame*, dp->sub_prev[0], dp->sub_prev[1]);
597 
598  if (end <= 0)
599  return 0;
600  }
601 
602  if (!subtitle)
603  return 0;
604 
605  ret = sch_dec_send(dp->sch, dp->sch_idx, 0, frame);
606  if (ret < 0)
608 
609  return ret == AVERROR_EOF ? AVERROR_EXIT : ret;
610 }
611 
612 static int fix_sub_duration_heartbeat(DecoderPriv *dp, int64_t signal_pts)
613 {
614  int ret = AVERROR_BUG;
615  AVSubtitle *prev_subtitle = dp->sub_prev[0]->buf[0] ?
616  (AVSubtitle*)dp->sub_prev[0]->buf[0]->data : NULL;
617  AVSubtitle *subtitle;
618 
619  if (!(dp->flags & DECODER_FLAG_FIX_SUB_DURATION) || !prev_subtitle ||
620  !prev_subtitle->num_rects || signal_pts <= prev_subtitle->pts)
621  return 0;
622 
624  ret = subtitle_wrap_frame(dp->sub_heartbeat, prev_subtitle, 1);
625  if (ret < 0)
626  return ret;
627 
628  subtitle = (AVSubtitle*)dp->sub_heartbeat->buf[0]->data;
629  subtitle->pts = signal_pts;
630 
631  return process_subtitle(dp, dp->sub_heartbeat);
632 }
633 
635  AVFrame *frame)
636 {
637  AVPacket *flush_pkt = NULL;
638  AVSubtitle subtitle;
639  int got_output;
640  int ret;
641 
642  if (pkt && (intptr_t)pkt->opaque == PKT_OPAQUE_SUB_HEARTBEAT) {
643  frame->pts = pkt->pts;
644  frame->time_base = pkt->time_base;
645  frame->opaque = (void*)(intptr_t)FRAME_OPAQUE_SUB_HEARTBEAT;
646 
647  ret = sch_dec_send(dp->sch, dp->sch_idx, 0, frame);
648  return ret == AVERROR_EOF ? AVERROR_EXIT : ret;
649  } else if (pkt && (intptr_t)pkt->opaque == PKT_OPAQUE_FIX_SUB_DURATION) {
651  AV_TIME_BASE_Q));
652  }
653 
654  if (!pkt) {
655  flush_pkt = av_packet_alloc();
656  if (!flush_pkt)
657  return AVERROR(ENOMEM);
658  }
659 
660  ret = avcodec_decode_subtitle2(dp->dec_ctx, &subtitle, &got_output,
661  pkt ? pkt : flush_pkt);
662  av_packet_free(&flush_pkt);
663 
664  if (ret < 0) {
665  av_log(dp, AV_LOG_ERROR, "Error decoding subtitles: %s\n",
666  av_err2str(ret));
667  dp->dec.decode_errors++;
668  return exit_on_error ? ret : 0;
669  }
670 
671  if (!got_output)
672  return pkt ? 0 : AVERROR_EOF;
673 
674  dp->dec.frames_decoded++;
675 
676  // XXX the queue for transferring data to consumers runs
677  // on AVFrames, so we wrap AVSubtitle in an AVBufferRef and put that
678  // inside the frame
679  // eventually, subtitles should be switched to use AVFrames natively
680  ret = subtitle_wrap_frame(frame, &subtitle, 0);
681  if (ret < 0) {
682  avsubtitle_free(&subtitle);
683  return ret;
684  }
685 
686  frame->width = dp->dec_ctx->width;
687  frame->height = dp->dec_ctx->height;
688 
689  return process_subtitle(dp, frame);
690 }
691 
693 {
694  AVCodecContext *dec = dp->dec_ctx;
695  const char *type_desc = av_get_media_type_string(dec->codec_type);
696  int ret;
697 
698  if (dec->codec_type == AVMEDIA_TYPE_SUBTITLE)
699  return transcode_subtitles(dp, pkt, frame);
700 
701  // With fate-indeo3-2, we're getting 0-sized packets before EOF for some
702  // reason. This seems like a semi-critical bug. Don't trigger EOF, and
703  // skip the packet.
704  if (pkt && pkt->size == 0)
705  return 0;
706 
707  if (pkt && (dp->flags & DECODER_FLAG_TS_UNRELIABLE)) {
710  }
711 
712  if (pkt) {
713  FrameData *fd = packet_data(pkt);
714  if (!fd)
715  return AVERROR(ENOMEM);
717  }
718 
719  ret = avcodec_send_packet(dec, pkt);
720  if (ret < 0 && !(ret == AVERROR_EOF && !pkt)) {
721  // In particular, we don't expect AVERROR(EAGAIN), because we read all
722  // decoded frames with avcodec_receive_frame() until done.
723  if (ret == AVERROR(EAGAIN)) {
724  av_log(dp, AV_LOG_FATAL, "A decoder returned an unexpected error code. "
725  "This is a bug, please report it.\n");
726  return AVERROR_BUG;
727  }
728  av_log(dp, AV_LOG_ERROR, "Error submitting %s to decoder: %s\n",
729  pkt ? "packet" : "EOF", av_err2str(ret));
730 
731  if (ret == AVERROR_EOF)
732  return ret;
733 
734  dp->dec.decode_errors++;
735  if (exit_on_error)
736  return ret;
737  }
738 
739  while (1) {
740  FrameData *fd;
741  unsigned outputs_mask = 1;
742  unsigned flags = 0;
743  if (!dp->dec.frames_decoded)
745 
747 
750  update_benchmark("decode_%s %s", type_desc, dp->parent_name);
751 
752  if (ret == AVERROR(EAGAIN)) {
753  av_assert0(pkt); // should never happen during flushing
754  return 0;
755  } else if (ret == AVERROR_EOF) {
756  return ret;
757  } else if (ret < 0) {
758  av_log(dp, AV_LOG_ERROR, "Decoding error: %s\n", av_err2str(ret));
759  dp->dec.decode_errors++;
760 
761  if (exit_on_error)
762  return ret;
763 
764  continue;
765  }
766 
767  if (frame->decode_error_flags || (frame->flags & AV_FRAME_FLAG_CORRUPT)) {
769  "corrupt decoded frame\n");
770  if (exit_on_error)
771  return AVERROR_INVALIDDATA;
772  }
773 
774  fd = frame_data(frame);
775  if (!fd) {
777  return AVERROR(ENOMEM);
778  }
779  fd->dec.pts = frame->pts;
780  fd->dec.tb = dec->pkt_timebase;
781  fd->dec.frame_num = dec->frame_num - 1;
783 
785 
786  frame->time_base = dec->pkt_timebase;
787 
788  if (dec->codec_type == AVMEDIA_TYPE_AUDIO) {
789  dp->dec.samples_decoded += frame->nb_samples;
790 
791  audio_ts_process(dp, frame);
792  } else {
793  ret = video_frame_process(dp, frame, &outputs_mask);
794  if (ret < 0) {
795  av_log(dp, AV_LOG_FATAL,
796  "Error while processing the decoded data\n");
797  return ret;
798  }
799  }
800 
801  dp->dec.frames_decoded++;
802 
803  for (int i = 0; i < stdc_count_ones(outputs_mask); i++) {
804  AVFrame *to_send = frame;
805  int pos;
806 
807  av_assert0(outputs_mask);
808  pos = stdc_trailing_zeros(outputs_mask);
809  outputs_mask &= ~(1U << pos);
810 
811  // this is not the last output and sch_dec_send() consumes the frame
812  // given to it, so make a temporary reference
813  if (outputs_mask) {
814  to_send = dp->frame_tmp_ref;
815  ret = av_frame_ref(to_send, frame);
816  if (ret < 0)
817  return ret;
818  }
819 
820  ret = sch_dec_send(dp->sch, dp->sch_idx, pos, to_send);
821  if (ret < 0) {
822  av_frame_unref(to_send);
823  return ret == AVERROR_EOF ? AVERROR_EXIT : ret;
824  }
825  }
826  }
827 }
828 
829 static int dec_open(DecoderPriv *dp, AVDictionary **dec_opts,
830  const DecoderOpts *o, AVFrame *param_out);
831 
833 {
834  DecoderOpts o;
835  const FrameData *fd;
836  char name[16];
837 
838  if (!pkt->opaque_ref)
839  return AVERROR_BUG;
840  fd = (FrameData *)pkt->opaque_ref->data;
841 
842  if (!fd->par_enc)
843  return AVERROR_BUG;
844 
845  memset(&o, 0, sizeof(o));
846 
847  o.par = fd->par_enc;
848  o.time_base = pkt->time_base;
849 
850  o.codec = dp->standalone_init.codec;
851  if (!o.codec)
853  if (!o.codec) {
855 
856  av_log(dp, AV_LOG_ERROR, "Cannot find a decoder for codec ID '%s'\n",
857  desc ? desc->name : "?");
859  }
860 
861  snprintf(name, sizeof(name), "dec%d", dp->index);
862  o.name = name;
863 
864  return dec_open(dp, &dp->standalone_init.opts, &o, NULL);
865 }
866 
867 static void dec_thread_set_name(const DecoderPriv *dp)
868 {
869  char name[16] = "dec";
870 
871  if (dp->index >= 0)
872  av_strlcatf(name, sizeof(name), "%d", dp->index);
873  else if (dp->parent_name)
874  av_strlcat(name, dp->parent_name, sizeof(name));
875 
876  if (dp->dec_ctx)
877  av_strlcatf(name, sizeof(name), ":%s", dp->dec_ctx->codec->name);
878 
880 }
881 
883 {
884  av_packet_free(&dt->pkt);
885  av_frame_free(&dt->frame);
886 
887  memset(dt, 0, sizeof(*dt));
888 }
889 
891 {
892  memset(dt, 0, sizeof(*dt));
893 
894  dt->frame = av_frame_alloc();
895  if (!dt->frame)
896  goto fail;
897 
898  dt->pkt = av_packet_alloc();
899  if (!dt->pkt)
900  goto fail;
901 
902  return 0;
903 
904 fail:
905  dec_thread_uninit(dt);
906  return AVERROR(ENOMEM);
907 }
908 
909 static int decoder_thread(void *arg)
910 {
911  DecoderPriv *dp = arg;
912  DecThreadContext dt;
913  int ret = 0, input_status = 0;
914 
915  ret = dec_thread_init(&dt);
916  if (ret < 0)
917  goto finish;
918 
920 
921  while (!input_status) {
922  int flush_buffers, have_data;
923 
924  input_status = sch_dec_receive(dp->sch, dp->sch_idx, dt.pkt);
925  have_data = input_status >= 0 &&
926  (dt.pkt->buf || dt.pkt->side_data_elems ||
927  (intptr_t)dt.pkt->opaque == PKT_OPAQUE_SUB_HEARTBEAT ||
928  (intptr_t)dt.pkt->opaque == PKT_OPAQUE_FIX_SUB_DURATION);
929  flush_buffers = input_status >= 0 && !have_data;
930  if (!have_data)
931  av_log(dp, AV_LOG_VERBOSE, "Decoder thread received %s packet\n",
932  flush_buffers ? "flush" : "EOF");
933 
934  // this is a standalone decoder that has not been initialized yet
935  if (!dp->dec_ctx) {
936  if (flush_buffers)
937  continue;
938  if (input_status < 0) {
939  av_log(dp, AV_LOG_ERROR,
940  "Cannot initialize a standalone decoder\n");
941  ret = input_status;
942  goto finish;
943  }
944 
945  ret = dec_standalone_open(dp, dt.pkt);
946  if (ret < 0)
947  goto finish;
948  }
949 
950  ret = packet_decode(dp, have_data ? dt.pkt : NULL, dt.frame);
951 
952  av_packet_unref(dt.pkt);
953  av_frame_unref(dt.frame);
954 
955  // AVERROR_EOF - EOF from the decoder
956  // AVERROR_EXIT - EOF from the scheduler
957  // we treat them differently when flushing
958  if (ret == AVERROR_EXIT) {
959  ret = AVERROR_EOF;
960  flush_buffers = 0;
961  }
962 
963  if (ret == AVERROR_EOF) {
964  av_log(dp, AV_LOG_VERBOSE, "Decoder returned EOF, %s\n",
965  flush_buffers ? "resetting" : "finishing");
966 
967  if (!flush_buffers)
968  break;
969 
970  /* report last frame duration to the scheduler */
971  if (dp->dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
973  dt.pkt->time_base = dp->last_frame_tb;
974  }
975 
977  } else if (ret < 0) {
978  av_log(dp, AV_LOG_ERROR, "Error processing packet in decoder: %s\n",
979  av_err2str(ret));
980  break;
981  }
982  }
983 
984  // EOF is normal thread termination
985  if (ret == AVERROR_EOF)
986  ret = 0;
987 
988  // on success send EOF timestamp to our downstreams
989  if (ret >= 0) {
990  float err_rate;
991 
992  av_frame_unref(dt.frame);
993 
994  dt.frame->opaque = (void*)(intptr_t)FRAME_OPAQUE_EOF;
997  dt.frame->time_base = dp->last_frame_tb;
998 
999  ret = sch_dec_send(dp->sch, dp->sch_idx, 0, dt.frame);
1000  if (ret < 0 && ret != AVERROR_EOF) {
1001  av_log(dp, AV_LOG_FATAL,
1002  "Error signalling EOF timestamp: %s\n", av_err2str(ret));
1003  goto finish;
1004  }
1005  ret = 0;
1006 
1007  err_rate = (dp->dec.frames_decoded || dp->dec.decode_errors) ?
1008  (float)dp->dec.decode_errors / (dp->dec.frames_decoded + dp->dec.decode_errors) : 0.f;
1009  if (err_rate > max_error_rate) {
1010  av_log(dp, AV_LOG_FATAL, "Decode error rate %g exceeds maximum %g\n",
1011  err_rate, max_error_rate);
1013  } else if (err_rate)
1014  av_log(dp, AV_LOG_VERBOSE, "Decode error rate %g\n", err_rate);
1015  }
1016 
1017 finish:
1018  dec_thread_uninit(&dt);
1020 
1021  return ret;
1022 }
1023 
1025  SchedulerNode *src)
1026 {
1027  DecoderPriv *dp = dp_from_dec(d);
1028  unsigned out_idx = 0;
1029  int ret;
1030 
1031  if (dp->multiview_user_config) {
1032  if (!vs || vs->type == VIEW_SPECIFIER_TYPE_NONE) {
1033  *src = SCH_DEC_OUT(dp->sch_idx, 0);
1034  return 0;
1035  }
1036 
1037  av_log(dp, AV_LOG_ERROR,
1038  "Manually selecting views with -view_ids cannot be combined "
1039  "with view selection via stream specifiers. It is strongly "
1040  "recommended you always use stream specifiers only.\n");
1041  return AVERROR(EINVAL);
1042  }
1043 
1044  // when multiview_user_config is not set, NONE specifier is treated
1045  // as requesting the base view
1046  vs = (vs && vs->type != VIEW_SPECIFIER_TYPE_NONE) ? vs :
1047  &(ViewSpecifier){ .type = VIEW_SPECIFIER_TYPE_IDX, .val = 0 };
1048 
1049  // check if the specifier matches an already-existing one
1050  for (int i = 0; i < dp->nb_views_requested; i++) {
1051  const ViewSpecifier *vs1 = &dp->views_requested[i].vs;
1052 
1053  if (vs->type == vs1->type &&
1054  (vs->type == VIEW_SPECIFIER_TYPE_ALL || vs->val == vs1->val)) {
1056  return 0;
1057  }
1058  }
1059 
1060  // we use a bitmask to map view IDs to decoder outputs, which
1061  // limits the number of outputs allowed
1062  if (dp->nb_views_requested >= sizeof(dp->view_map[0].out_mask) * 8) {
1063  av_log(dp, AV_LOG_ERROR, "Too many view specifiers\n");
1064  return AVERROR(ENOSYS);
1065  }
1066 
1068  if (ret < 0)
1069  return ret;
1070 
1071  if (dp->nb_views_requested > 1) {
1072  ret = sch_add_dec_output(dp->sch, dp->sch_idx);
1073  if (ret < 0)
1074  return ret;
1075  out_idx = ret;
1076  }
1077 
1078  dp->views_requested[dp->nb_views_requested - 1].out_idx = out_idx;
1079  dp->views_requested[dp->nb_views_requested - 1].vs = *vs;
1080 
1081  *src = SCH_DEC_OUT(dp->sch_idx,
1083 
1084  return 0;
1085 }
1086 
1088 {
1089  unsigned views_wanted = 0;
1090 
1091  unsigned nb_view_ids_av, nb_view_ids;
1092  unsigned *view_ids_av = NULL, *view_pos_av = NULL;
1093  int *view_ids = NULL;
1094  int ret;
1095 
1096  // no views/only base view were requested - do nothing
1097  if (!dp->nb_views_requested ||
1098  (dp->nb_views_requested == 1 &&
1100  dp->views_requested[0].vs.val == 0))
1101  return 0;
1102 
1103  av_freep(&dp->view_map);
1104  dp->nb_view_map = 0;
1105 
1106  // retrieve views available in current CVS
1107  ret = av_opt_get_array_size(dec_ctx, "view_ids_available",
1108  AV_OPT_SEARCH_CHILDREN, &nb_view_ids_av);
1109  if (ret < 0) {
1110  av_log(dp, AV_LOG_ERROR,
1111  "Multiview decoding requested, but decoder '%s' does not "
1112  "support it\n", dec_ctx->codec->name);
1113  return AVERROR(ENOSYS);
1114  }
1115 
1116  if (nb_view_ids_av) {
1117  unsigned nb_view_pos_av;
1118 
1119  if (nb_view_ids_av >= sizeof(views_wanted) * 8) {
1120  av_log(dp, AV_LOG_ERROR, "Too many views in video: %u\n", nb_view_ids_av);
1121  ret = AVERROR(ENOSYS);
1122  goto fail;
1123  }
1124 
1125  view_ids_av = av_calloc(nb_view_ids_av, sizeof(*view_ids_av));
1126  if (!view_ids_av) {
1127  ret = AVERROR(ENOMEM);
1128  goto fail;
1129  }
1130 
1131  ret = av_opt_get_array(dec_ctx, "view_ids_available",
1132  AV_OPT_SEARCH_CHILDREN, 0, nb_view_ids_av,
1133  AV_OPT_TYPE_UINT, view_ids_av);
1134  if (ret < 0)
1135  goto fail;
1136 
1137  ret = av_opt_get_array_size(dec_ctx, "view_pos_available",
1138  AV_OPT_SEARCH_CHILDREN, &nb_view_pos_av);
1139  if (ret >= 0 && nb_view_pos_av == nb_view_ids_av) {
1140  view_pos_av = av_calloc(nb_view_ids_av, sizeof(*view_pos_av));
1141  if (!view_pos_av) {
1142  ret = AVERROR(ENOMEM);
1143  goto fail;
1144  }
1145 
1146  ret = av_opt_get_array(dec_ctx, "view_pos_available",
1147  AV_OPT_SEARCH_CHILDREN, 0, nb_view_ids_av,
1148  AV_OPT_TYPE_UINT, view_pos_av);
1149  if (ret < 0)
1150  goto fail;
1151  }
1152  } else {
1153  // assume there is a single view with ID=0
1154  nb_view_ids_av = 1;
1155  view_ids_av = av_calloc(nb_view_ids_av, sizeof(*view_ids_av));
1156  view_pos_av = av_calloc(nb_view_ids_av, sizeof(*view_pos_av));
1157  if (!view_ids_av || !view_pos_av) {
1158  ret = AVERROR(ENOMEM);
1159  goto fail;
1160  }
1161  view_pos_av[0] = AV_STEREO3D_VIEW_UNSPEC;
1162  }
1163 
1164  dp->view_map = av_calloc(nb_view_ids_av, sizeof(*dp->view_map));
1165  if (!dp->view_map) {
1166  ret = AVERROR(ENOMEM);
1167  goto fail;
1168  }
1169  dp->nb_view_map = nb_view_ids_av;
1170 
1171  for (int i = 0; i < dp->nb_view_map; i++)
1172  dp->view_map[i].id = view_ids_av[i];
1173 
1174  // figure out which views should go to which output
1175  for (int i = 0; i < dp->nb_views_requested; i++) {
1176  const ViewSpecifier *vs = &dp->views_requested[i].vs;
1177 
1178  switch (vs->type) {
1180  if (vs->val >= nb_view_ids_av) {
1182  "View with index %u requested, but only %u views available "
1183  "in current video sequence (more views may or may not be "
1184  "available in later sequences).\n",
1185  vs->val, nb_view_ids_av);
1186  if (exit_on_error) {
1187  ret = AVERROR(EINVAL);
1188  goto fail;
1189  }
1190 
1191  continue;
1192  }
1193  views_wanted |= 1U << vs->val;
1194  dp->view_map[vs->val].out_mask |= 1ULL << i;
1195 
1196  break;
1197  case VIEW_SPECIFIER_TYPE_ID: {
1198  int view_idx = -1;
1199 
1200  for (unsigned j = 0; j < nb_view_ids_av; j++) {
1201  if (view_ids_av[j] == vs->val) {
1202  view_idx = j;
1203  break;
1204  }
1205  }
1206  if (view_idx < 0) {
1208  "View with ID %u requested, but is not available "
1209  "in the video sequence\n", vs->val);
1210  if (exit_on_error) {
1211  ret = AVERROR(EINVAL);
1212  goto fail;
1213  }
1214 
1215  continue;
1216  }
1217  views_wanted |= 1U << view_idx;
1218  dp->view_map[view_idx].out_mask |= 1ULL << i;
1219 
1220  break;
1221  }
1222  case VIEW_SPECIFIER_TYPE_POS: {
1223  int view_idx = -1;
1224 
1225  for (unsigned j = 0; view_pos_av && j < nb_view_ids_av; j++) {
1226  if (view_pos_av[j] == vs->val) {
1227  view_idx = j;
1228  break;
1229  }
1230  }
1231  if (view_idx < 0) {
1233  "View position '%s' requested, but is not available "
1234  "in the video sequence\n", av_stereo3d_view_name(vs->val));
1235  if (exit_on_error) {
1236  ret = AVERROR(EINVAL);
1237  goto fail;
1238  }
1239 
1240  continue;
1241  }
1242  views_wanted |= 1U << view_idx;
1243  dp->view_map[view_idx].out_mask |= 1ULL << i;
1244 
1245  break;
1246  }
1248  views_wanted |= (1U << nb_view_ids_av) - 1;
1249 
1250  for (int j = 0; j < dp->nb_view_map; j++)
1251  dp->view_map[j].out_mask |= 1ULL << i;
1252 
1253  break;
1254  }
1255  }
1256  if (!views_wanted) {
1257  av_log(dp, AV_LOG_ERROR, "No views were selected for decoding\n");
1258  ret = AVERROR(EINVAL);
1259  goto fail;
1260  }
1261 
1262  // signal to decoder which views we want
1263  nb_view_ids = stdc_count_ones(views_wanted);
1264  view_ids = av_malloc_array(nb_view_ids, sizeof(*view_ids));
1265  if (!view_ids) {
1266  ret = AVERROR(ENOMEM);
1267  goto fail;
1268  }
1269 
1270  for (unsigned i = 0; i < nb_view_ids; i++) {
1271  int pos;
1272 
1273  av_assert0(views_wanted);
1274  pos = stdc_trailing_zeros(views_wanted);
1275  views_wanted &= ~(1U << pos);
1276 
1277  view_ids[i] = view_ids_av[pos];
1278  }
1279 
1280  // unset view_ids in case we set it earlier
1282 
1284  0, nb_view_ids, AV_OPT_TYPE_INT, view_ids);
1285  if (ret < 0)
1286  goto fail;
1287 
1288  if (!dp->frame_tmp_ref) {
1289  dp->frame_tmp_ref = av_frame_alloc();
1290  if (!dp->frame_tmp_ref) {
1291  ret = AVERROR(ENOMEM);
1292  goto fail;
1293  }
1294  }
1295 
1296 fail:
1297  av_freep(&view_ids_av);
1298  av_freep(&view_pos_av);
1299  av_freep(&view_ids);
1300 
1301  return ret;
1302 }
1303 
1304 static void multiview_check_manual(DecoderPriv *dp, const AVDictionary *dec_opts)
1305 {
1306  if (av_dict_get(dec_opts, "view_ids", NULL, 0)) {
1307  av_log(dp, AV_LOG_WARNING, "Manually selecting views with -view_ids "
1308  "is not recommended, use view specifiers instead\n");
1309  dp->multiview_user_config = 1;
1310  }
1311 }
1312 
1314 {
1315  DecoderPriv *dp = s->opaque;
1316  const enum AVPixelFormat *p;
1317  int ret;
1318 
1319  ret = multiview_setup(dp, s);
1320  if (ret < 0) {
1321  av_log(dp, AV_LOG_ERROR, "Error setting up multiview decoding: %s\n",
1322  av_err2str(ret));
1323  return AV_PIX_FMT_NONE;
1324  }
1325 
1326  for (p = pix_fmts; *p != AV_PIX_FMT_NONE; p++) {
1328  const AVCodecHWConfig *config = NULL;
1329 
1330  if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL))
1331  break;
1332 
1333  if (dp->hwaccel_id == HWACCEL_GENERIC ||
1334  dp->hwaccel_id == HWACCEL_AUTO) {
1335  for (int i = 0;; i++) {
1336  config = avcodec_get_hw_config(s->codec, i);
1337  if (!config)
1338  break;
1339  if (!(config->methods &
1341  continue;
1342  if (config->pix_fmt == *p)
1343  break;
1344  }
1345  }
1346  if (config && config->device_type == dp->hwaccel_device_type) {
1347  dp->hwaccel_pix_fmt = *p;
1348  break;
1349  }
1350  }
1351 
1352  return *p;
1353 }
1354 
1356 {
1357  DecoderPriv *dp = dec_ctx->opaque;
1358 
1359  // for multiview video, store the output mask in frame opaque
1360  if (dp->nb_view_map) {
1362  int view_id = sd ? *(int*)sd->data : 0;
1363 
1364  for (int i = 0; i < dp->nb_view_map; i++) {
1365  if (dp->view_map[i].id == view_id) {
1366  frame->opaque = (void*)dp->view_map[i].out_mask;
1367  break;
1368  }
1369  }
1370  }
1371 
1373 }
1374 
1376 {
1377  const AVCodecHWConfig *config;
1378  HWDevice *dev;
1379  for (int i = 0;; i++) {
1380  config = avcodec_get_hw_config(codec, i);
1381  if (!config)
1382  return NULL;
1384  continue;
1385  dev = hw_device_get_by_type(config->device_type);
1386  if (dev)
1387  return dev;
1388  }
1389 }
1390 
1392  const AVCodec *codec,
1393  const char *hwaccel_device)
1394 {
1395  const AVCodecHWConfig *config;
1396  enum AVHWDeviceType type;
1397  HWDevice *dev = NULL;
1398  int err, auto_device = 0;
1399 
1400  if (hwaccel_device) {
1401  dev = hw_device_get_by_name(hwaccel_device);
1402  if (!dev) {
1403  if (dp->hwaccel_id == HWACCEL_AUTO) {
1404  auto_device = 1;
1405  } else if (dp->hwaccel_id == HWACCEL_GENERIC) {
1406  type = dp->hwaccel_device_type;
1407  err = hw_device_init_from_type(type, hwaccel_device,
1408  &dev);
1409  } else {
1410  // This will be dealt with by API-specific initialisation
1411  // (using hwaccel_device), so nothing further needed here.
1412  return 0;
1413  }
1414  } else {
1415  if (dp->hwaccel_id == HWACCEL_AUTO) {
1416  dp->hwaccel_device_type = dev->type;
1417  } else if (dp->hwaccel_device_type != dev->type) {
1418  av_log(dp, AV_LOG_ERROR, "Invalid hwaccel device "
1419  "specified for decoder: device %s of type %s is not "
1420  "usable with hwaccel %s.\n", dev->name,
1423  return AVERROR(EINVAL);
1424  }
1425  }
1426  } else {
1427  if (dp->hwaccel_id == HWACCEL_AUTO) {
1428  auto_device = 1;
1429  } else if (dp->hwaccel_id == HWACCEL_GENERIC) {
1430  type = dp->hwaccel_device_type;
1431  dev = hw_device_get_by_type(type);
1432 
1433  // When "-qsv_device device" is used, an internal QSV device named
1434  // as "__qsv_device" is created. Another QSV device is created too
1435  // if "-init_hw_device qsv=name:device" is used. There are 2 QSV devices
1436  // if both "-qsv_device device" and "-init_hw_device qsv=name:device"
1437  // are used, hw_device_get_by_type(AV_HWDEVICE_TYPE_QSV) returns NULL.
1438  // To keep back-compatibility with the removed ad-hoc libmfx setup code,
1439  // call hw_device_get_by_name("__qsv_device") to select the internal QSV
1440  // device.
1441  if (!dev && type == AV_HWDEVICE_TYPE_QSV)
1442  dev = hw_device_get_by_name("__qsv_device");
1443 
1444  if (!dev)
1445  err = hw_device_init_from_type(type, NULL, &dev);
1446  } else {
1447  dev = hw_device_match_by_codec(codec);
1448  if (!dev) {
1449  // No device for this codec, but not using generic hwaccel
1450  // and therefore may well not need one - ignore.
1451  return 0;
1452  }
1453  }
1454  }
1455 
1456  if (auto_device) {
1457  if (!avcodec_get_hw_config(codec, 0)) {
1458  // Decoder does not support any hardware devices.
1459  return 0;
1460  }
1461  for (int i = 0; !dev; i++) {
1462  config = avcodec_get_hw_config(codec, i);
1463  if (!config)
1464  break;
1465  type = config->device_type;
1466  dev = hw_device_get_by_type(type);
1467  if (dev) {
1468  av_log(dp, AV_LOG_INFO, "Using auto "
1469  "hwaccel type %s with existing device %s.\n",
1471  }
1472  }
1473  for (int i = 0; !dev; i++) {
1474  config = avcodec_get_hw_config(codec, i);
1475  if (!config)
1476  break;
1477  type = config->device_type;
1478  // Try to make a new device of this type.
1479  err = hw_device_init_from_type(type, hwaccel_device,
1480  &dev);
1481  if (err < 0) {
1482  // Can't make a device of this type.
1483  continue;
1484  }
1485  if (hwaccel_device) {
1486  av_log(dp, AV_LOG_INFO, "Using auto "
1487  "hwaccel type %s with new device created "
1488  "from %s.\n", av_hwdevice_get_type_name(type),
1489  hwaccel_device);
1490  } else {
1491  av_log(dp, AV_LOG_INFO, "Using auto "
1492  "hwaccel type %s with new default device.\n",
1494  }
1495  }
1496  if (dev) {
1497  dp->hwaccel_device_type = type;
1498  } else {
1499  av_log(dp, AV_LOG_INFO, "Auto hwaccel "
1500  "disabled: no device found.\n");
1501  dp->hwaccel_id = HWACCEL_NONE;
1502  return 0;
1503  }
1504  }
1505 
1506  if (!dev) {
1507  av_log(dp, AV_LOG_ERROR, "No device available "
1508  "for decoder: device type %s needed for codec %s.\n",
1510  return err;
1511  }
1512 
1514  if (!dp->dec_ctx->hw_device_ctx)
1515  return AVERROR(ENOMEM);
1516 
1517  return 0;
1518 }
1519 
1520 static int dec_open(DecoderPriv *dp, AVDictionary **dec_opts,
1521  const DecoderOpts *o, AVFrame *param_out)
1522 {
1523  const AVCodec *codec = o->codec;
1524  int ret;
1525 
1526  dp->flags = o->flags;
1527  dp->log_parent = o->log_parent;
1528 
1529  dp->dec.type = codec->type;
1530  dp->framerate_in = o->framerate;
1531 
1532  dp->hwaccel_id = o->hwaccel_id;
1535 
1536  snprintf(dp->log_name, sizeof(dp->log_name), "dec:%s", codec->name);
1537 
1538  dp->parent_name = av_strdup(o->name ? o->name : "");
1539  if (!dp->parent_name)
1540  return AVERROR(ENOMEM);
1541 
1542  if (codec->type == AVMEDIA_TYPE_SUBTITLE &&
1544  for (int i = 0; i < FF_ARRAY_ELEMS(dp->sub_prev); i++) {
1545  dp->sub_prev[i] = av_frame_alloc();
1546  if (!dp->sub_prev[i])
1547  return AVERROR(ENOMEM);
1548  }
1549  dp->sub_heartbeat = av_frame_alloc();
1550  if (!dp->sub_heartbeat)
1551  return AVERROR(ENOMEM);
1552  }
1553 
1555 
1556  dp->dec_ctx = avcodec_alloc_context3(codec);
1557  if (!dp->dec_ctx)
1558  return AVERROR(ENOMEM);
1559 
1561  if (ret < 0) {
1562  av_log(dp, AV_LOG_ERROR, "Error initializing the decoder context.\n");
1563  return ret;
1564  }
1565 
1566  dp->dec_ctx->opaque = dp;
1567  dp->dec_ctx->get_format = get_format;
1569  dp->dec_ctx->pkt_timebase = o->time_base;
1570 
1571  if (!av_dict_get(*dec_opts, "threads", NULL, 0))
1572  av_dict_set(dec_opts, "threads", "auto", 0);
1573 
1575  if (ret < 0) {
1576  av_log(dp, AV_LOG_ERROR,
1577  "Hardware device setup failed for decoder: %s\n",
1578  av_err2str(ret));
1579  return ret;
1580  }
1581 
1583  if (ret < 0) {
1584  av_log(dp, AV_LOG_ERROR, "Error applying decoder options: %s\n",
1585  av_err2str(ret));
1586  return ret;
1587  }
1588  ret = check_avoptions(*dec_opts);
1589  if (ret < 0)
1590  return ret;
1591 
1593  if (o->flags & DECODER_FLAG_BITEXACT)
1595 
1596  // we apply cropping ourselves
1598  dp->dec_ctx->apply_cropping = 0;
1599 
1600  if ((ret = avcodec_open2(dp->dec_ctx, codec, NULL)) < 0) {
1601  av_log(dp, AV_LOG_ERROR, "Error while opening decoder: %s\n",
1602  av_err2str(ret));
1603  return ret;
1604  }
1605 
1606  if (dp->dec_ctx->hw_device_ctx) {
1607  // Update decoder extra_hw_frames option to account for the
1608  // frames held in queues inside the ffmpeg utility. This is
1609  // called after avcodec_open2() because the user-set value of
1610  // extra_hw_frames becomes valid in there, and we need to add
1611  // this on top of it.
1612  int extra_frames = DEFAULT_FRAME_THREAD_QUEUE_SIZE;
1613  if (dp->dec_ctx->extra_hw_frames >= 0)
1614  dp->dec_ctx->extra_hw_frames += extra_frames;
1615  else
1616  dp->dec_ctx->extra_hw_frames = extra_frames;
1617  }
1618 
1619  if (dp->dec_ctx->subtitle_header) {
1620  /* ASS code assumes this buffer is null terminated so add extra byte. */
1622  if (!dp->dec.subtitle_header)
1623  return AVERROR(ENOMEM);
1624  memcpy(dp->dec.subtitle_header, dp->dec_ctx->subtitle_header,
1627  }
1628 
1629  if (param_out) {
1630  if (dp->dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
1631  param_out->format = dp->dec_ctx->sample_fmt;
1632  param_out->sample_rate = dp->dec_ctx->sample_rate;
1633 
1634  ret = av_channel_layout_copy(&param_out->ch_layout, &dp->dec_ctx->ch_layout);
1635  if (ret < 0)
1636  return ret;
1637  } else if (dp->dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO) {
1638  param_out->format = dp->dec_ctx->pix_fmt;
1639  param_out->width = dp->dec_ctx->width;
1640  param_out->height = dp->dec_ctx->height;
1642  param_out->colorspace = dp->dec_ctx->colorspace;
1643  param_out->color_range = dp->dec_ctx->color_range;
1644  param_out->alpha_mode = dp->dec_ctx->alpha_mode;
1645  }
1646 
1647  av_frame_side_data_free(&param_out->side_data, &param_out->nb_side_data);
1648  ret = clone_side_data(&param_out->side_data, &param_out->nb_side_data,
1650  if (ret < 0)
1651  return ret;
1652  param_out->time_base = dp->dec_ctx->pkt_timebase;
1653  }
1654 
1655  return 0;
1656 }
1657 
1658 int dec_init(Decoder **pdec, Scheduler *sch,
1659  AVDictionary **dec_opts, const DecoderOpts *o,
1660  AVFrame *param_out)
1661 {
1662  DecoderPriv *dp;
1663  int ret;
1664 
1665  *pdec = NULL;
1666 
1667  ret = dec_alloc(&dp, sch, !!(o->flags & DECODER_FLAG_SEND_END_TS));
1668  if (ret < 0)
1669  return ret;
1670 
1671  multiview_check_manual(dp, *dec_opts);
1672 
1673  ret = dec_open(dp, dec_opts, o, param_out);
1674  if (ret < 0)
1675  goto fail;
1676 
1677  *pdec = &dp->dec;
1678 
1679  return dp->sch_idx;
1680 fail:
1681  dec_free((Decoder**)&dp);
1682  return ret;
1683 }
1684 
1685 int dec_create(const OptionsContext *o, const char *arg, Scheduler *sch)
1686 {
1687  DecoderPriv *dp;
1688 
1689  OutputFile *of;
1690  OutputStream *ost;
1691  int of_index, ost_index;
1692  char *p;
1693 
1694  unsigned enc_idx;
1695  int ret;
1696 
1697  ret = dec_alloc(&dp, sch, 0);
1698  if (ret < 0)
1699  return ret;
1700 
1701  dp->index = nb_decoders;
1702 
1704  if (ret < 0) {
1705  dec_free((Decoder **)&dp);
1706  return ret;
1707  }
1708 
1709  decoders[nb_decoders - 1] = (Decoder *)dp;
1710 
1711  of_index = strtol(arg, &p, 0);
1712  if (of_index < 0 || of_index >= nb_output_files) {
1713  av_log(dp, AV_LOG_ERROR, "Invalid output file index '%d' in %s\n", of_index, arg);
1714  return AVERROR(EINVAL);
1715  }
1716  of = output_files[of_index];
1717 
1718  ost_index = strtol(p + 1, NULL, 0);
1719  if (ost_index < 0 || ost_index >= of->nb_streams) {
1720  av_log(dp, AV_LOG_ERROR, "Invalid output stream index '%d' in %s\n", ost_index, arg);
1721  return AVERROR(EINVAL);
1722  }
1723  ost = of->streams[ost_index];
1724 
1725  if (!ost->enc) {
1726  av_log(dp, AV_LOG_ERROR, "Output stream %s has no encoder\n", arg);
1727  return AVERROR(EINVAL);
1728  }
1729 
1730  dp->dec.type = ost->type;
1731 
1732  ret = enc_loopback(ost->enc);
1733  if (ret < 0)
1734  return ret;
1735  enc_idx = ret;
1736 
1737  ret = sch_connect(sch, SCH_ENC(enc_idx), SCH_DEC_IN(dp->sch_idx));
1738  if (ret < 0)
1739  return ret;
1740 
1741  ret = av_dict_copy(&dp->standalone_init.opts, o->g->codec_opts, 0);
1742  if (ret < 0)
1743  return ret;
1744 
1746 
1747  if (o->codec_names.nb_opt) {
1748  const char *name = o->codec_names.opt[o->codec_names.nb_opt - 1].u.str;
1750  if (!dp->standalone_init.codec) {
1751  av_log(dp, AV_LOG_ERROR, "No such decoder: %s\n", name);
1753  }
1754  }
1755 
1756  return 0;
1757 }
1758 
1760  const ViewSpecifier *vs, SchedulerNode *src)
1761 {
1762  DecoderPriv *dp = dp_from_dec(d);
1763  char name[16];
1764 
1765  snprintf(name, sizeof(name), "dec%d", dp->index);
1766  opts->name = av_strdup(name);
1767  if (!opts->name)
1768  return AVERROR(ENOMEM);
1769 
1770  return dec_request_view(d, vs, src);
1771 }
AV_OPT_SEARCH_CHILDREN
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:604
DecoderPriv::last_frame_tb
AVRational last_frame_tb
Definition: ffmpeg_dec.c:67
flags
const SwsFlags flags[]
Definition: swscale.c:85
AVSubtitle
Definition: avcodec.h:2087
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: packet.c:434
AV_ROUND_UP
@ AV_ROUND_UP
Round toward +infinity.
Definition: mathematics.h:134
FrameData::par_enc
AVCodecParameters * par_enc
Definition: ffmpeg.h:709
AVCodec
AVCodec.
Definition: codec.h:169
copy_av_subtitle
static int copy_av_subtitle(AVSubtitle *dst, const AVSubtitle *src)
Definition: ffmpeg_dec.c:449
stdc_trailing_zeros
#define stdc_trailing_zeros(value)
Definition: stdbit.h:220
fix_sub_duration_heartbeat
static int fix_sub_duration_heartbeat(DecoderPriv *dp, int64_t signal_pts)
Definition: ffmpeg_dec.c:612
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:203
av_gettime_relative
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
Definition: time.c:56
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
AVFrame::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: frame.h:717
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
AVCodecContext::alpha_mode
enum AVAlphaMode alpha_mode
Indicates how the alpha channel of the video is represented.
Definition: avcodec.h:1937
dec_ctx
static AVCodecContext * dec_ctx
Definition: decode_filter_audio.c:45
dec_class
static const AVClass dec_class
Definition: ffmpeg_dec.c:156
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
AVCodecContext::get_format
enum AVPixelFormat(* get_format)(struct AVCodecContext *s, const enum AVPixelFormat *fmt)
Callback to negotiate the pixel format.
Definition: avcodec.h:773
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:671
FrameData
Definition: ffmpeg.h:690
AVCodecContext::decoded_side_data
AVFrameSideData ** decoded_side_data
Array containing static side data, such as HDR10 CLL / MDCV structures.
Definition: avcodec.h:1929
check_avoptions
int check_avoptions(AVDictionary *m)
Definition: cmdutils.c:1605
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1040
DecoderPriv::last_frame_duration_est
int64_t last_frame_duration_est
Definition: ffmpeg_dec.c:66
DecoderOpts
Definition: ffmpeg.h:425
av_frame_get_side_data
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:659
audio_samplerate_update
static AVRational audio_samplerate_update(DecoderPriv *dp, const AVFrame *frame)
Definition: ffmpeg_dec.c:205
clone_side_data
static int clone_side_data(AVFrameSideData ***dst, int *nb_dst, AVFrameSideData *const *src, int nb_src, unsigned int flags)
Wrapper calling av_frame_side_data_clone() in a loop for all source entries.
Definition: ffmpeg_utils.h:50
DECODER_FLAG_SEND_END_TS
@ DECODER_FLAG_SEND_END_TS
Definition: ffmpeg.h:420
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3456
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
AVFrame::nb_side_data
int nb_side_data
Definition: frame.h:664
LATENCY_PROBE_DEC_POST
@ LATENCY_PROBE_DEC_POST
Definition: ffmpeg.h:89
DecoderPriv::last_frame_pts
int64_t last_frame_pts
Definition: ffmpeg_dec.c:65
dec_thread_uninit
static void dec_thread_uninit(DecThreadContext *dt)
Definition: ffmpeg_dec.c:882
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:263
dec_alloc
static int dec_alloc(DecoderPriv **pdec, Scheduler *sch, int send_end_ts)
Definition: ffmpeg_dec.c:165
int64_t
long long int64_t
Definition: coverity.c:34
output
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
Definition: filter_design.txt:226
AVSubtitleRect
Definition: avcodec.h:2060
AVSubtitle::num_rects
unsigned num_rects
Definition: avcodec.h:2091
hw_device_match_by_codec
static HWDevice * hw_device_match_by_codec(const AVCodec *codec)
Definition: ffmpeg_dec.c:1375
DecThreadContext::pkt
AVPacket * pkt
Definition: ffmpeg_dec.c:115
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:64
AVFrame::opaque
void * opaque
Frame owner's private data.
Definition: frame.h:604
AVFrame::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: frame.h:728
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:466
pixdesc.h
cleanup
static av_cold void cleanup(FlashSV2Context *s)
Definition: flashsv2enc.c:130
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:568
AVFrame::width
int width
Definition: frame.h:538
DECODER_FLAG_FRAMERATE_FORCED
@ DECODER_FLAG_FRAMERATE_FORCED
Definition: ffmpeg.h:419
DecoderOpts::par
const AVCodecParameters * par
Definition: ffmpeg.h:432
dec_item_name
static const char * dec_item_name(void *obj)
Definition: ffmpeg_dec.c:149
dec_thread_init
static int dec_thread_init(DecThreadContext *dt)
Definition: ffmpeg_dec.c:890
DecoderPriv::hwaccel_device_type
enum AVHWDeviceType hwaccel_device_type
Definition: ffmpeg_dec.c:59
DecoderPriv::sub_prev
AVFrame * sub_prev[2]
Definition: ffmpeg_dec.c:72
DecoderPriv::hwaccel_output_format
enum AVPixelFormat hwaccel_output_format
Definition: ffmpeg_dec.c:60
data
const char data[16]
Definition: mxf.c:149
DecoderOpts::hwaccel_id
enum HWAccelID hwaccel_id
Definition: ffmpeg.h:435
DecoderPriv::pkt
AVPacket * pkt
Definition: ffmpeg_dec.c:46
AVCodecContext::subtitle_header
uint8_t * subtitle_header
Definition: avcodec.h:1744
AVSubtitleRect::linesize
int linesize[4]
Definition: avcodec.h:2072
ffmpeg.h
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:226
DecoderPriv::index
int index
Definition: ffmpeg_dec.c:79
DecoderPriv::sub_heartbeat
AVFrame * sub_heartbeat
Definition: ffmpeg_dec.c:73
DecoderPriv::multiview_user_config
int multiview_user_config
Definition: ffmpeg_dec.c:85
ViewSpecifier
Definition: ffmpeg.h:116
AVDictionary
Definition: dict.c:32
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
HWDevice
Definition: ffmpeg.h:97
av_buffer_ref
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:103
VIEW_SPECIFIER_TYPE_ALL
@ VIEW_SPECIFIER_TYPE_ALL
Definition: ffmpeg.h:113
DECODER_FLAG_BITEXACT
@ DECODER_FLAG_BITEXACT
Definition: ffmpeg.h:422
AVFrame::buf
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:643
DecoderPriv::hwaccel_id
enum HWAccelID hwaccel_id
Definition: ffmpeg_dec.c:58
av_strlcatf
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:103
ost
static AVStream * ost
Definition: vaapi_transcode.c:42
AV_STEREO3D_VIEW_UNSPEC
@ AV_STEREO3D_VIEW_UNSPEC
Content is unspecified.
Definition: stereo3d.h:168
tf_sess_config.config
config
Definition: tf_sess_config.py:33
enc_loopback
int enc_loopback(Encoder *enc)
Definition: ffmpeg_enc.c:929
av_packet_free
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: packet.c:74
dec_free
void dec_free(Decoder **pdec)
Definition: ffmpeg_dec.c:118
DEFAULT_FRAME_THREAD_QUEUE_SIZE
#define DEFAULT_FRAME_THREAD_QUEUE_SIZE
Default size of a frame thread queue.
Definition: ffmpeg_sched.h:262
av_frame_apply_cropping
int av_frame_apply_cropping(AVFrame *frame, int flags)
Crop the given video AVFrame according to its crop_left/crop_top/crop_right/ crop_bottom fields.
Definition: frame.c:760
av_gcd
int64_t av_gcd(int64_t a, int64_t b)
Compute the greatest common divisor of two integer operands.
Definition: mathematics.c:37
FrameData::frame_num
uint64_t frame_num
Definition: ffmpeg.h:697
OutputFile::nb_streams
int nb_streams
Definition: ffmpeg.h:681
av_memdup
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition: mem.c:304
DecoderPriv::dec_ctx
AVCodecContext * dec_ctx
Definition: ffmpeg_dec.c:42
DecoderPriv::apply_cropping
int apply_cropping
Definition: ffmpeg_dec.c:55
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:563
DecoderOpts::hwaccel_output_format
enum AVPixelFormat hwaccel_output_format
Definition: ffmpeg.h:438
debug_ts
int debug_ts
Definition: ffmpeg_opt.c:67
AV_CODEC_FLAG_COPY_OPAQUE
#define AV_CODEC_FLAG_COPY_OPAQUE
Definition: avcodec.h:279
finish
static void finish(void)
Definition: movenc.c:374
FRAME_OPAQUE_SUB_HEARTBEAT
@ FRAME_OPAQUE_SUB_HEARTBEAT
Definition: ffmpeg.h:76
AVCodecContext::codec
const struct AVCodec * codec
Definition: avcodec.h:452
AVPacket::opaque_ref
AVBufferRef * opaque_ref
AVBufferRef for free use by the API user.
Definition: packet.h:639
DecoderPriv
Definition: ffmpeg_dec.c:39
FrameData::dec
struct FrameData::@6 dec
OptionsContext::g
OptionGroup * g
Definition: ffmpeg.h:133
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:1055
Decoder::frames_decoded
uint64_t frames_decoded
Definition: ffmpeg.h:456
AV_PIX_FMT_FLAG_HWACCEL
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition: pixdesc.h:128
get_format
static enum AVPixelFormat get_format(AVCodecContext *s, const enum AVPixelFormat *pix_fmts)
Definition: ffmpeg_dec.c:1313
AVSubtitleRect::x
int x
top left corner of pict, undefined when pict is not set
Definition: avcodec.h:2061
VIEW_SPECIFIER_TYPE_POS
@ VIEW_SPECIFIER_TYPE_POS
Definition: ffmpeg.h:111
DecoderPriv::log_parent
void * log_parent
Definition: ffmpeg_dec.c:80
DecoderOpts::log_parent
void * log_parent
Definition: ffmpeg.h:429
DecoderPriv::out_idx
unsigned out_idx
Definition: ffmpeg_dec.c:89
DecoderPriv::dec
Decoder dec
Definition: ffmpeg_dec.c:40
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:500
AVFrame::alpha_mode
enum AVAlphaMode alpha_mode
Indicates how the alpha channel of the video is to be handled.
Definition: frame.h:821
update_benchmark
void update_benchmark(const char *fmt,...)
Definition: ffmpeg.c:551
AVFrame::ch_layout
AVChannelLayout ch_layout
Channel layout of the audio data.
Definition: frame.h:809
SCH_ENC
#define SCH_ENC(encoder)
Definition: ffmpeg_sched.h:123
multiview_setup
static int multiview_setup(DecoderPriv *dp, AVCodecContext *dec_ctx)
Definition: ffmpeg_dec.c:1087
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
OptionsContext
Definition: ffmpeg.h:132
av_opt_set
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition: opt.c:824
FrameData::tb
AVRational tb
Definition: ffmpeg.h:700
codec.h
AVRational::num
int num
Numerator.
Definition: rational.h:59
DecoderPriv::parent_name
char * parent_name
Definition: ffmpeg_dec.c:82
Decoder::samples_decoded
uint64_t samples_decoded
Definition: ffmpeg.h:457
AVSubtitleRect::ass
char * ass
0 terminated ASS/SSA compatible event line.
Definition: avcodec.h:2084
av_stereo3d_view_name
const char * av_stereo3d_view_name(unsigned int view)
Provide a human-readable name of a given stereo3d view.
Definition: stereo3d.c:113
avsubtitle_free
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
Definition: avcodec.c:421
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:52
AVCodecContext::get_buffer2
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:1218
avcodec_decode_subtitle2
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, const AVPacket *avpkt)
Decode a subtitle message.
Definition: decode.c:929
avassert.h
DecThreadContext
Definition: ffmpeg_dec.c:113
DecoderPriv::log_name
char log_name[32]
Definition: ffmpeg_dec.c:81
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
dec_create
int dec_create(const OptionsContext *o, const char *arg, Scheduler *sch)
Create a standalone decoder.
Definition: ffmpeg_dec.c:1685
DecoderPriv::frame
AVFrame * frame
Definition: ffmpeg_dec.c:44
hwaccel_retrieve_data
static int hwaccel_retrieve_data(AVCodecContext *avctx, AVFrame *input)
Definition: ffmpeg_dec.c:345
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
OptionGroup::codec_opts
AVDictionary * codec_opts
Definition: cmdutils.h:347
SpecifierOptList::nb_opt
int nb_opt
Definition: cmdutils.h:185
AV_FRAME_FLAG_KEY
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition: frame.h:681
DecThreadContext::frame
AVFrame * frame
Definition: ffmpeg_dec.c:114
av_dict_get
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:60
HWACCEL_GENERIC
@ HWACCEL_GENERIC
Definition: ffmpeg.h:72
avcodec_alloc_context3
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition: options.c:149
avcodec_receive_frame_flags
int attribute_align_arg avcodec_receive_frame_flags(AVCodecContext *avctx, AVFrame *frame, unsigned flags)
Return decoded output data from a decoder or encoder (when the AV_CODEC_FLAG_RECON_FRAME flag is used...
Definition: avcodec.c:707
AVCodecDescriptor
This struct describes the properties of a single codec described by an AVCodecID.
Definition: codec_desc.h:38
stereo3d.h
s
#define s(width, name)
Definition: cbs_vp9.c:198
AVCodecParameters::sample_aspect_ratio
AVRational sample_aspect_ratio
The aspect ratio (width/height) which a single pixel should have when displayed.
Definition: codec_par.h:161
subtitle_wrap_frame
static int subtitle_wrap_frame(AVFrame *frame, AVSubtitle *subtitle, int copy)
Definition: ffmpeg_dec.c:536
AVCodecContext::nb_decoded_side_data
int nb_decoded_side_data
Definition: avcodec.h:1930
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:201
AVSubtitleRect::y
int y
top left corner of pict, undefined when pict is not set
Definition: avcodec.h:2062
VIEW_SPECIFIER_TYPE_NONE
@ VIEW_SPECIFIER_TYPE_NONE
Definition: ffmpeg.h:105
InputFilter
Definition: ffmpeg.h:354
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:42
AVHWDeviceType
AVHWDeviceType
Definition: hwcontext.h:27
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:296
AVCodecContext::bits_per_raw_sample
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:1571
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
sch_dec_send
int sch_dec_send(Scheduler *sch, unsigned dec_idx, unsigned out_idx, AVFrame *frame)
Called by decoder tasks to send a decoded frame downstream.
Definition: ffmpeg_sched.c:2442
av_opt_get_array_size
int av_opt_get_array_size(void *obj, const char *name, int search_flags, unsigned int *out_val)
For an array-type option, get the number of elements in the array.
Definition: opt.c:2158
AV_FRAME_CROP_UNALIGNED
@ AV_FRAME_CROP_UNALIGNED
Apply the maximum possible cropping, even if it requires setting the AVFrame.data[] entries to unalig...
Definition: frame.h:1041
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
max_error_rate
float max_error_rate
Definition: ffmpeg_opt.c:72
AVSubtitle::pts
int64_t pts
Same as packet pts, in AV_TIME_BASE.
Definition: avcodec.h:2093
DecoderOpts::hwaccel_device
char * hwaccel_device
Definition: ffmpeg.h:437
av_opt_set_array
int av_opt_set_array(void *obj, const char *name, int search_flags, unsigned int start_elem, unsigned int nb_elems, enum AVOptionType val_type, const void *val)
Add, replace, or remove elements for an array option.
Definition: opt.c:2264
DecoderPriv::last_filter_in_rescale_delta
int64_t last_filter_in_rescale_delta
Definition: ffmpeg_dec.c:68
av_hwdevice_get_type_name
const char * av_hwdevice_get_type_name(enum AVHWDeviceType type)
Get the string name of an AVHWDeviceType.
Definition: hwcontext.c:120
stdc_count_ones
#define stdc_count_ones(value)
Definition: stdbit.h:455
av_mallocz
#define av_mallocz(s)
Definition: tableprint_vlc.h:31
AVPacket::opaque
void * opaque
for some private data of the user
Definition: packet.h:628
AVSubtitleRect::text
char * text
0 terminated plain UTF-8 text
Definition: avcodec.h:2077
SCH_DEC_IN
#define SCH_DEC_IN(decoder)
Definition: ffmpeg_sched.h:117
av_rescale_delta
int64_t av_rescale_delta(AVRational in_tb, int64_t in_ts, AVRational fs_tb, int duration, int64_t *last, AVRational out_tb)
Rescale a timestamp while preserving known durations.
Definition: mathematics.c:168
tmp
static uint8_t tmp[40]
Definition: aes_ctr.c:52
get_buffer
static int get_buffer(AVCodecContext *dec_ctx, AVFrame *frame, int flags)
Definition: ffmpeg_dec.c:1355
arg
const char * arg
Definition: jacosubdec.c:65
video_frame_process
static int video_frame_process(DecoderPriv *dp, AVFrame *frame, unsigned *outputs_mask)
Definition: ffmpeg_dec.c:387
fields
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the then the processing requires a frame on this link and the filter is expected to make efforts in that direction The status of input links is stored by the fifo and status_out fields
Definition: filter_design.txt:155
if
if(ret)
Definition: filter_design.txt:179
fail
#define fail
Definition: test.h:478
opts
static AVDictionary * opts
Definition: movenc.c:51
audio_ts_process
static void audio_ts_process(DecoderPriv *dp, AVFrame *frame)
Definition: ffmpeg_dec.c:248
AVPacket::buf
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: packet.h:586
AVCodecParameters::avcodec_parameters_to_context
int avcodec_parameters_to_context(AVCodecContext *codec, const struct AVCodecParameters *par)
Fill the codec context based on the values from the supplied codec parameters.
AVSubtitleRect::w
int w
width of pict, undefined when pict is not set
Definition: avcodec.h:2063
dec_request_view
int dec_request_view(Decoder *d, const ViewSpecifier *vs, SchedulerNode *src)
Definition: ffmpeg_dec.c:1024
hw_device_setup_for_decode
static int hw_device_setup_for_decode(DecoderPriv *dp, const AVCodec *codec, const char *hwaccel_device)
Definition: ffmpeg_dec.c:1391
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
NULL
#define NULL
Definition: coverity.c:32
avcodec_find_decoder_by_name
const AVCodec * avcodec_find_decoder_by_name(const char *name)
Find a registered decoder with the specified name.
Definition: allcodecs.c:1016
Decoder::decode_errors
uint64_t decode_errors
Definition: ffmpeg.h:458
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:599
AVCodecContext::apply_cropping
int apply_cropping
Video decoding only.
Definition: avcodec.h:1814
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:681
DecoderPriv::framerate_in
AVRational framerate_in
Definition: ffmpeg_dec.c:51
dec_open
static int dec_open(DecoderPriv *dp, AVDictionary **dec_opts, const DecoderOpts *o, AVFrame *param_out)
Definition: ffmpeg_dec.c:1520
AVCodec::type
enum AVMediaType type
Definition: codec.h:182
Decoder
Definition: ffmpeg.h:447
dec_thread_set_name
static void dec_thread_set_name(const DecoderPriv *dp)
Definition: ffmpeg_dec.c:867
hw_device_init_from_type
int hw_device_init_from_type(enum AVHWDeviceType type, const char *device, HWDevice **dev_out)
Definition: ffmpeg_hw.c:243
avcodec_free_context
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
Definition: options.c:164
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
transcode_subtitles
static int transcode_subtitles(DecoderPriv *dp, const AVPacket *pkt, AVFrame *frame)
Definition: ffmpeg_dec.c:634
AVPALETTE_SIZE
#define AVPALETTE_SIZE
Definition: pixfmt.h:32
AVCodecContext::subtitle_header_size
int subtitle_header_size
Header containing style information for text subtitles.
Definition: avcodec.h:1743
AVSubtitleRect::data
uint8_t * data[4]
data+linesize for the bitmap of this subtitle.
Definition: avcodec.h:2071
sch_add_dec
int sch_add_dec(Scheduler *sch, SchThreadFunc func, void *ctx, int send_end_ts)
Add a decoder to the scheduler.
Definition: ffmpeg_sched.c:786
ViewSpecifier::val
unsigned val
Definition: ffmpeg.h:118
FrameData::wallclock
int64_t wallclock[LATENCY_PROBE_NB]
Definition: ffmpeg.h:707
avcodec_open2
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
Definition: avcodec.c:144
time.h
av_opt_get_array
int av_opt_get_array(void *obj, const char *name, int search_flags, unsigned int start_elem, unsigned int nb_elems, enum AVOptionType out_type, void *out_val)
For an array-type option, retrieve the values of one or more array elements.
Definition: opt.c:2176
AV_OPT_TYPE_UINT
@ AV_OPT_TYPE_UINT
Underlying C type is unsigned int.
Definition: opt.h:334
AV_CODEC_RECEIVE_FRAME_FLAG_SYNCHRONOUS
#define AV_CODEC_RECEIVE_FRAME_FLAG_SYNCHRONOUS
The decoder will bypass frame threading and return the next frame as soon as possible.
Definition: avcodec.h:428
InputFilterOptions
Definition: ffmpeg.h:256
DecoderPriv::hwaccel_pix_fmt
enum AVPixelFormat hwaccel_pix_fmt
Definition: ffmpeg_dec.c:57
DECODER_FLAG_FIX_SUB_DURATION
@ DECODER_FLAG_FIX_SUB_DURATION
Definition: ffmpeg.h:414
DecoderPriv::last_frame_sample_rate
int last_frame_sample_rate
Definition: ffmpeg_dec.c:69
DecoderPriv::frame_tmp_ref
AVFrame * frame_tmp_ref
Definition: ffmpeg_dec.c:45
DecoderPriv::out_mask
uintptr_t out_mask
Definition: ffmpeg_dec.c:97
av_buffer_create
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
Definition: buffer.c:55
OutputFile::streams
OutputStream ** streams
Definition: ffmpeg.h:680
error.h
Scheduler
Definition: ffmpeg_sched.c:278
avcodec_find_decoder
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: allcodecs.c:988
f
f
Definition: af_crystalizer.c:122
av_ts2timestr
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:83
AVPacket::size
int size
Definition: packet.h:604
DecoderPriv::sch
Scheduler * sch
Definition: ffmpeg_dec.c:75
copy
static void copy(const float *p1, float *p2, const int length)
Definition: vf_vaguedenoiser.c:186
AVCodecContext::extra_hw_frames
int extra_hw_frames
Video decoding only.
Definition: avcodec.h:1516
av_frame_ref
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition: frame.c:278
dec_init
int dec_init(Decoder **pdec, Scheduler *sch, AVDictionary **dec_opts, const DecoderOpts *o, AVFrame *param_out)
Definition: ffmpeg_dec.c:1658
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
output_files
OutputFile ** output_files
Definition: ffmpeg.c:111
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:122
AVFrame::sample_rate
int sample_rate
Sample rate of the audio data.
Definition: frame.h:629
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:424
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1047
AVCodecContext::pkt_timebase
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.
Definition: avcodec.h:554
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:247
AVFrame::time_base
AVRational time_base
Time base for the timestamps in this frame.
Definition: frame.h:583
AVFrameSideData::data
uint8_t * data
Definition: frame.h:323
HWDevice::device_ref
AVBufferRef * device_ref
Definition: ffmpeg.h:100
hw_device_get_by_type
HWDevice * hw_device_get_by_type(enum AVHWDeviceType type)
Definition: ffmpeg_hw.c:28
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:553
frame_data
FrameData * frame_data(AVFrame *frame)
Get our axiliary frame data attached to the frame, allocating it if needed.
Definition: ffmpeg.c:477
AVSubtitle::end_display_time
uint32_t end_display_time
Definition: avcodec.h:2090
AVSubtitleRect::type
enum AVSubtitleType type
Definition: avcodec.h:2075
LATENCY_PROBE_DEC_PRE
@ LATENCY_PROBE_DEC_PRE
Definition: ffmpeg.h:88
DecoderPriv::view_map
struct DecoderPriv::@8 * view_map
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:602
FrameData::pts
int64_t pts
Definition: ffmpeg.h:699
DecoderPriv::codec
const AVCodec * codec
Definition: ffmpeg_dec.c:103
SpecifierOptList::opt
SpecifierOpt * opt
Definition: cmdutils.h:184
av_packet_alloc
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: packet.c:63
av_dict_free
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition: dict.c:233
multiview_check_manual
static void multiview_check_manual(DecoderPriv *dp, const AVDictionary *dec_opts)
Definition: ffmpeg_dec.c:1304
decoders
Decoder ** decoders
Definition: ffmpeg.c:117
input
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
Definition: filter_design.txt:172
nb_decoders
int nb_decoders
Definition: ffmpeg.c:118
SUBTITLE_BITMAP
@ SUBTITLE_BITMAP
A bitmap, pict will be set.
Definition: avcodec.h:2043
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:221
AV_FRAME_DATA_VIEW_ID
@ AV_FRAME_DATA_VIEW_ID
This side data must be associated with a video frame.
Definition: frame.h:245
HWACCEL_AUTO
@ HWACCEL_AUTO
Definition: ffmpeg.h:71
AVSubtitleRect::flags
int flags
Definition: avcodec.h:2074
avcodec_default_get_buffer2
int avcodec_default_get_buffer2(AVCodecContext *s, AVFrame *frame, int flags)
The default callback for AVCodecContext.get_buffer2().
Definition: get_buffer.c:253
avcodec_send_packet
int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
Supply raw packet data as input to a decoder.
Definition: decode.c:724
video_duration_estimate
static int64_t video_duration_estimate(const DecoderPriv *dp, const AVFrame *frame)
Definition: ffmpeg_dec.c:285
log.h
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:596
process_subtitle
static int process_subtitle(DecoderPriv *dp, AVFrame *frame)
Definition: ffmpeg_dec.c:569
FrameData::bits_per_raw_sample
int bits_per_raw_sample
Definition: ffmpeg.h:705
av_frame_side_data_free
void av_frame_side_data_free(AVFrameSideData ***sd, int *nb_sd)
Free all side data entries and their contents, then zeroes out the values which the pointers are poin...
Definition: side_data.c:138
AV_FRAME_FLAG_CORRUPT
#define AV_FRAME_FLAG_CORRUPT
The frame data may be corrupted, e.g.
Definition: frame.h:677
AVSubtitleRect::nb_colors
int nb_colors
number of colors in pict, undefined when pict is not set
Definition: avcodec.h:2065
OptionsContext::codec_names
SpecifierOptList codec_names
Definition: ffmpeg.h:141
AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX
@ AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX
The codec supports this format via the hw_device_ctx interface.
Definition: codec.h:276
av_opt_set_dict2
int av_opt_set_dict2(void *obj, AVDictionary **options, int search_flags)
Set all the options from a given dictionary on an object.
Definition: opt.c:1955
AV_TIME_BASE
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:253
packet_decode
static int packet_decode(DecoderPriv *dp, AVPacket *pkt, AVFrame *frame)
Definition: ffmpeg_dec.c:692
DecoderOpts::time_base
AVRational time_base
Definition: ffmpeg.h:440
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:32
DecoderPriv::nb_views_requested
int nb_views_requested
Definition: ffmpeg_dec.c:91
SCH_DEC_OUT
#define SCH_DEC_OUT(decoder, out_idx)
Definition: ffmpeg_sched.h:120
exit_on_error
int exit_on_error
Definition: ffmpeg_opt.c:68
FRAME_OPAQUE_EOF
@ FRAME_OPAQUE_EOF
Definition: ffmpeg.h:77
av_frame_move_ref
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition: frame.c:523
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:496
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:176
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
AVCodecContext::hw_device_ctx
AVBufferRef * hw_device_ctx
A reference to the AVHWDeviceContext describing the device which will be used by a hardware encoder/d...
Definition: avcodec.h:1493
AVFrame::side_data
AVFrameSideData ** side_data
Definition: frame.h:663
SchedulerNode
Definition: ffmpeg_sched.h:103
av_rescale
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
Definition: mathematics.c:129
AVCodecContext::height
int height
Definition: avcodec.h:604
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:643
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
nb_output_files
int nb_output_files
Definition: ffmpeg.c:112
sch_connect
int sch_connect(Scheduler *sch, SchedulerNode src, SchedulerNode dst)
Definition: ffmpeg_sched.c:973
DecoderPriv::nb_view_map
int nb_view_map
Definition: ffmpeg_dec.c:99
avcodec.h
DecoderPriv::vs
ViewSpecifier vs
Definition: ffmpeg_dec.c:88
AVCodecContext::frame_num
int64_t frame_num
Frame counter, set by libavcodec.
Definition: avcodec.h:1883
ret
ret
Definition: filter_design.txt:187
AV_LOG_FATAL
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition: log.h:204
AVSubtitleRect::h
int h
height of pict, undefined when pict is not set
Definition: avcodec.h:2064
pixfmt.h
sch_dec_receive
int sch_dec_receive(Scheduler *sch, unsigned dec_idx, AVPacket *pkt)
Called by decoder tasks to receive a packet for decoding.
Definition: ffmpeg_sched.c:2336
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
avcodec_flush_buffers
void avcodec_flush_buffers(AVCodecContext *avctx)
Reset the internal codec state / flush internal buffers.
Definition: avcodec.c:389
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:81
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:265
VIEW_SPECIFIER_TYPE_IDX
@ VIEW_SPECIFIER_TYPE_IDX
Definition: ffmpeg.h:107
av_strlcat
size_t av_strlcat(char *dst, const char *src, size_t size)
Append the string src to the string dst, but to a total length of no more than size - 1 bytes,...
Definition: avstring.c:95
DecoderPriv::flags
int flags
Definition: ffmpeg_dec.c:54
AVCodecContext::opaque
void * opaque
Private data of the user, can be used to carry app specific stuff.
Definition: avcodec.h:485
pos
unsigned int pos
Definition: spdifenc.c:414
HWAccelID
HWAccelID
Definition: ffmpeg.h:69
dict.h
AVFrame::sample_aspect_ratio
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:563
av_hwframe_transfer_data
int av_hwframe_transfer_data(AVFrame *dst, const AVFrame *src, int flags)
Copy data to or from a hw surface.
Definition: hwcontext.c:448
U
#define U(x)
Definition: vpx_arith.h:37
DecoderPriv::sar_override
AVRational sar_override
Definition: ffmpeg_dec.c:49
AV_HWDEVICE_TYPE_QSV
@ AV_HWDEVICE_TYPE_QSV
Definition: hwcontext.h:33
dec_filter_add
int dec_filter_add(Decoder *d, InputFilter *ifilter, InputFilterOptions *opts, const ViewSpecifier *vs, SchedulerNode *src)
Definition: ffmpeg_dec.c:1759
av_get_media_type_string
const char * av_get_media_type_string(enum AVMediaType media_type)
Return a string describing the media_type enum, NULL if media_type is unknown.
Definition: utils.c:28
AVCodecContext
main external API structure.
Definition: avcodec.h:443
AVFrame::height
int height
Definition: frame.h:538
flush_buffers
static void flush_buffers(InputFile *ifile)
Definition: ffprobe.c:1816
DecoderPriv::opts
AVDictionary * opts
Definition: ffmpeg_dec.c:102
PKT_OPAQUE_SUB_HEARTBEAT
@ PKT_OPAQUE_SUB_HEARTBEAT
Definition: ffmpeg.h:82
HWDevice::name
const char * name
Definition: ffmpeg.h:98
dp_from_dec
static DecoderPriv * dp_from_dec(Decoder *d)
Definition: ffmpeg_dec.c:107
AVRational::den
int den
Denominator.
Definition: rational.h:60
SpecifierOpt::str
uint8_t * str
Definition: cmdutils.h:174
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:258
output_format
static char * output_format
Definition: ffprobe.c:145
Decoder::subtitle_header_size
int subtitle_header_size
Definition: ffmpeg.h:453
Windows::Graphics::DirectX::Direct3D11::p
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
Definition: vsrc_gfxcapture_winrt.hpp:53
av_mul_q
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
GROW_ARRAY
#define GROW_ARRAY(array, nb_elems)
Definition: cmdutils.h:536
HWACCEL_NONE
@ HWACCEL_NONE
Definition: ffmpeg.h:70
avcodec_get_hw_config
const AVCodecHWConfig * avcodec_get_hw_config(const AVCodec *codec, int index)
Retrieve supported hardware configurations for a codec.
Definition: utils.c:842
av_channel_layout_copy
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
Definition: channel_layout.c:450
DecoderPriv::views_requested
struct DecoderPriv::@7 * views_requested
AVERROR_DECODER_NOT_FOUND
#define AVERROR_DECODER_NOT_FOUND
Decoder not found.
Definition: error.h:54
DecoderOpts::flags
int flags
Definition: ffmpeg.h:426
AVCodecContext::codec_type
enum AVMediaType codec_type
Definition: avcodec.h:451
desc
const char * desc
Definition: libsvtav1.c:83
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
ViewSpecifier::type
enum ViewSpecifierType type
Definition: ffmpeg.h:117
mem.h
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
SpecifierOpt::u
union SpecifierOpt::@0 u
DecoderPriv::standalone_init
struct DecoderPriv::@9 standalone_init
av_strdup
#define av_strdup(s)
Definition: ops_asmgen.c:47
AV_CODEC_FLAG_BITEXACT
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:322
DECODER_FLAG_TS_UNRELIABLE
@ DECODER_FLAG_TS_UNRELIABLE
Definition: ffmpeg.h:416
DecoderOpts::codec
const AVCodec * codec
Definition: ffmpeg.h:431
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:321
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
decoder_thread
static int decoder_thread(void *arg)
Definition: ffmpeg_dec.c:909
sch_add_dec_output
int sch_add_dec_output(Scheduler *sch, unsigned dec_idx)
Add another output to decoder (e.g.
Definition: ffmpeg_sched.c:765
FFMPEG_ERROR_RATE_EXCEEDED
#define FFMPEG_ERROR_RATE_EXCEEDED
Definition: ffmpeg.h:54
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:57
AVPacket
This structure stores compressed data.
Definition: packet.h:580
VIEW_SPECIFIER_TYPE_ID
@ VIEW_SPECIFIER_TYPE_ID
Definition: ffmpeg.h:109
Decoder::class
const AVClass * class
Definition: ffmpeg.h:448
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
av_dict_set
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:86
HWDevice::type
enum AVHWDeviceType type
Definition: ffmpeg.h:99
av_dict_copy
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:247
Decoder::type
enum AVMediaType type
Definition: ffmpeg.h:450
packet_data
FrameData * packet_data(AVPacket *pkt)
Definition: ffmpeg.c:489
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:604
timestamp.h
OutputStream
Definition: mux.c:53
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
DecoderOpts::framerate
AVRational framerate
Definition: ffmpeg.h:444
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
av_ts2str
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:54
AVCodecHWConfig
Definition: codec.h:308
AVERROR_EXIT
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
Definition: error.h:58
subtitle_free
static void subtitle_free(void *opaque, uint8_t *data)
Definition: ffmpeg_dec.c:529
avcodec_descriptor_get
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:3878
DecoderPriv::sch_idx
unsigned sch_idx
Definition: ffmpeg_dec.c:76
pkt
static AVPacket * pkt
Definition: demux_decode.c:55
avstring.h
DecoderPriv::id
unsigned id
Definition: ffmpeg_dec.c:96
hw_device_get_by_name
HWDevice * hw_device_get_by_name(const char *name)
Definition: ffmpeg_hw.c:42
snprintf
#define snprintf
Definition: snprintf.h:34
PKT_OPAQUE_FIX_SUB_DURATION
@ PKT_OPAQUE_FIX_SUB_DURATION
Definition: ffmpeg.h:83
DecoderOpts::hwaccel_device_type
enum AVHWDeviceType hwaccel_device_type
Definition: ffmpeg.h:436
Decoder::subtitle_header
uint8_t * subtitle_header
Definition: ffmpeg.h:452
AVCodecContext::sample_aspect_ratio
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:628
av_rescale_q_rnd
int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq, enum AVRounding rnd)
Rescale a 64-bit integer by 2 rational numbers with specified rounding.
Definition: mathematics.c:134
src
#define src
Definition: vp8dsp.c:248
AVPacket::time_base
AVRational time_base
Time base of the packet's timestamps.
Definition: packet.h:647
AVPacket::side_data_elems
int side_data_elems
Definition: packet.h:615
stdbit.h
dec_standalone_open
static int dec_standalone_open(DecoderPriv *dp, const AVPacket *pkt)
Definition: ffmpeg_dec.c:832
OutputFile
Definition: ffmpeg.h:673
ff_thread_setname
static int ff_thread_setname(const char *name)
Definition: thread.h:216
DecoderOpts::name
char * name
Definition: ffmpeg.h:428