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 
139  av_freep(&dp->parent_name);
140 
142  av_freep(&dp->view_map);
143 
144  av_freep(pdec);
145 }
146 
147 static const char *dec_item_name(void *obj)
148 {
149  const DecoderPriv *dp = obj;
150 
151  return dp->log_name;
152 }
153 
154 static const AVClass dec_class = {
155  .class_name = "Decoder",
156  .version = LIBAVUTIL_VERSION_INT,
157  .parent_log_context_offset = offsetof(DecoderPriv, log_parent),
158  .item_name = dec_item_name,
159 };
160 
161 static int decoder_thread(void *arg);
162 
163 static int dec_alloc(DecoderPriv **pdec, Scheduler *sch, int send_end_ts)
164 {
165  DecoderPriv *dp;
166  int ret = 0;
167 
168  *pdec = NULL;
169 
170  dp = av_mallocz(sizeof(*dp));
171  if (!dp)
172  return AVERROR(ENOMEM);
173 
174  dp->frame = av_frame_alloc();
175  if (!dp->frame)
176  goto fail;
177 
178  dp->pkt = av_packet_alloc();
179  if (!dp->pkt)
180  goto fail;
181 
182  dp->index = -1;
183  dp->dec.class = &dec_class;
186  dp->last_frame_tb = (AVRational){ 1, 1 };
188 
189  ret = sch_add_dec(sch, decoder_thread, dp, send_end_ts);
190  if (ret < 0)
191  goto fail;
192  dp->sch = sch;
193  dp->sch_idx = ret;
194 
195  *pdec = dp;
196 
197  return 0;
198 fail:
199  dec_free((Decoder**)&dp);
200  return ret >= 0 ? AVERROR(ENOMEM) : ret;
201 }
202 
204  const AVFrame *frame)
205 {
206  const int prev = dp->last_frame_tb.den;
207  const int sr = frame->sample_rate;
208 
209  AVRational tb_new;
210  int64_t gcd;
211 
212  if (frame->sample_rate == dp->last_frame_sample_rate)
213  goto finish;
214 
215  gcd = av_gcd(prev, sr);
216 
217  if (prev / gcd >= INT_MAX / sr) {
219  "Audio timestamps cannot be represented exactly after "
220  "sample rate change: %d -> %d\n", prev, sr);
221 
222  // LCM of 192000, 44100, allows to represent all common samplerates
223  tb_new = (AVRational){ 1, 28224000 };
224  } else
225  tb_new = (AVRational){ 1, prev / gcd * sr };
226 
227  // keep the frame timebase if it is strictly better than
228  // the samplerate-defined one
229  if (frame->time_base.num == 1 && frame->time_base.den > tb_new.den &&
230  !(frame->time_base.den % tb_new.den))
231  tb_new = frame->time_base;
232 
235  dp->last_frame_tb, tb_new);
237  dp->last_frame_tb, tb_new);
238 
239  dp->last_frame_tb = tb_new;
240  dp->last_frame_sample_rate = frame->sample_rate;
241 
242 finish:
243  return dp->last_frame_tb;
244 }
245 
247 {
248  AVRational tb_filter = (AVRational){1, frame->sample_rate};
249  AVRational tb;
250  int64_t pts_pred;
251 
252  // on samplerate change, choose a new internal timebase for timestamp
253  // generation that can represent timestamps from all the samplerates
254  // seen so far
255  tb = audio_samplerate_update(dp, frame);
256  pts_pred = dp->last_frame_pts == AV_NOPTS_VALUE ? 0 :
258 
259  if (frame->pts == AV_NOPTS_VALUE) {
260  frame->pts = pts_pred;
261  frame->time_base = tb;
262  } else if (dp->last_frame_pts != AV_NOPTS_VALUE &&
263  frame->pts > av_rescale_q_rnd(pts_pred, tb, frame->time_base,
264  AV_ROUND_UP)) {
265  // there was a gap in timestamps, reset conversion state
267  }
268 
269  frame->pts = av_rescale_delta(frame->time_base, frame->pts,
270  tb, frame->nb_samples,
272 
273  dp->last_frame_pts = frame->pts;
274  dp->last_frame_duration_est = av_rescale_q(frame->nb_samples,
275  tb_filter, tb);
276 
277  // finally convert to filtering timebase
278  frame->pts = av_rescale_q(frame->pts, tb, tb_filter);
279  frame->duration = frame->nb_samples;
280  frame->time_base = tb_filter;
281 }
282 
284 {
285  const int ts_unreliable = dp->flags & DECODER_FLAG_TS_UNRELIABLE;
286  const int fr_forced = dp->flags & DECODER_FLAG_FRAMERATE_FORCED;
287  int64_t codec_duration = 0;
288  // difference between this and last frame's timestamps
289  const int64_t ts_diff =
290  (frame->pts != AV_NOPTS_VALUE && dp->last_frame_pts != AV_NOPTS_VALUE) ?
291  frame->pts - dp->last_frame_pts : -1;
292 
293  // XXX lavf currently makes up frame durations when they are not provided by
294  // the container. As there is no way to reliably distinguish real container
295  // durations from the fake made-up ones, we use heuristics based on whether
296  // the container has timestamps. Eventually lavf should stop making up
297  // durations, then this should be simplified.
298 
299  // frame duration is unreliable (typically guessed by lavf) when it is equal
300  // to 1 and the actual duration of the last frame is more than 2x larger
301  const int duration_unreliable = frame->duration == 1 && ts_diff > 2 * frame->duration;
302 
303  // prefer frame duration for containers with timestamps
304  if (fr_forced ||
305  (frame->duration > 0 && !ts_unreliable && !duration_unreliable))
306  return frame->duration;
307 
308  if (dp->dec_ctx->framerate.den && dp->dec_ctx->framerate.num) {
309  int fields = frame->repeat_pict + 2;
310  AVRational field_rate = av_mul_q(dp->dec_ctx->framerate,
311  (AVRational){ 2, 1 });
312  codec_duration = av_rescale_q(fields, av_inv_q(field_rate),
313  frame->time_base);
314  }
315 
316  // prefer codec-layer duration for containers without timestamps
317  if (codec_duration > 0 && ts_unreliable)
318  return codec_duration;
319 
320  // when timestamps are available, repeat last frame's actual duration
321  // (i.e. pts difference between this and last frame)
322  if (ts_diff > 0)
323  return ts_diff;
324 
325  // try frame/codec duration
326  if (frame->duration > 0)
327  return frame->duration;
328  if (codec_duration > 0)
329  return codec_duration;
330 
331  // try average framerate
332  if (dp->framerate_in.num && dp->framerate_in.den) {
334  frame->time_base);
335  if (d > 0)
336  return d;
337  }
338 
339  // last resort is last frame's estimated duration, and 1
340  return FFMAX(dp->last_frame_duration_est, 1);
341 }
342 
344 {
345  DecoderPriv *dp = avctx->opaque;
346  AVFrame *output = NULL;
348  int err;
349 
350  if (input->format == output_format) {
351  // Nothing to do.
352  return 0;
353  }
354 
356  if (!output)
357  return AVERROR(ENOMEM);
358 
359  output->format = output_format;
360 
362  if (err < 0) {
363  av_log(avctx, AV_LOG_ERROR, "Failed to transfer data to "
364  "output frame: %d.\n", err);
365  goto fail;
366  }
367 
369  if (err < 0) {
371  goto fail;
372  }
373 
377 
378  return 0;
379 
380 fail:
382  return err;
383 }
384 
386  unsigned *outputs_mask)
387 {
388 #if FFMPEG_OPT_TOP
390  av_log(dp, AV_LOG_WARNING, "-top is deprecated, use the setfield filter instead\n");
392  }
393 #endif
394 
395  if (frame->format == dp->hwaccel_pix_fmt) {
396  int err = hwaccel_retrieve_data(dp->dec_ctx, frame);
397  if (err < 0)
398  return err;
399  }
400 
401  frame->pts = frame->best_effort_timestamp;
402 
403  // forced fixed framerate
405  frame->pts = AV_NOPTS_VALUE;
406  frame->duration = 1;
407  frame->time_base = av_inv_q(dp->framerate_in);
408  }
409 
410  // no timestamp available - extrapolate from previous frame duration
411  if (frame->pts == AV_NOPTS_VALUE)
412  frame->pts = dp->last_frame_pts == AV_NOPTS_VALUE ? 0 :
414 
415  // update timestamp history
417  dp->last_frame_pts = frame->pts;
418  dp->last_frame_tb = frame->time_base;
419 
420  if (debug_ts) {
421  av_log(dp, AV_LOG_INFO,
422  "decoder -> pts:%s pts_time:%s "
423  "pkt_dts:%s pkt_dts_time:%s "
424  "duration:%s duration_time:%s "
425  "keyframe:%d frame_type:%d time_base:%d/%d\n",
426  av_ts2str(frame->pts),
427  av_ts2timestr(frame->pts, &frame->time_base),
428  av_ts2str(frame->pkt_dts),
429  av_ts2timestr(frame->pkt_dts, &frame->time_base),
430  av_ts2str(frame->duration),
431  av_ts2timestr(frame->duration, &frame->time_base),
432  !!(frame->flags & AV_FRAME_FLAG_KEY), frame->pict_type,
433  frame->time_base.num, frame->time_base.den);
434  }
435 
436  if (dp->sar_override.num)
437  frame->sample_aspect_ratio = dp->sar_override;
438 
439  if (dp->apply_cropping) {
440  // lavfi does not require aligned frame data
442  if (ret < 0) {
443  av_log(dp, AV_LOG_ERROR, "Error applying decoder cropping\n");
444  return ret;
445  }
446  }
447 
448  if (frame->opaque)
449  *outputs_mask = (uintptr_t)frame->opaque;
450 
451  return 0;
452 }
453 
455 {
456  int ret = AVERROR_BUG;
457  AVSubtitle tmp = {
458  .format = src->format,
459  .start_display_time = src->start_display_time,
460  .end_display_time = src->end_display_time,
461  .num_rects = 0,
462  .rects = NULL,
463  .pts = src->pts
464  };
465 
466  if (!src->num_rects)
467  goto success;
468 
469  if (!(tmp.rects = av_calloc(src->num_rects, sizeof(*tmp.rects))))
470  return AVERROR(ENOMEM);
471 
472  for (int i = 0; i < src->num_rects; i++) {
473  AVSubtitleRect *src_rect = src->rects[i];
474  AVSubtitleRect *dst_rect;
475 
476  if (!(dst_rect = tmp.rects[i] = av_mallocz(sizeof(*tmp.rects[0])))) {
477  ret = AVERROR(ENOMEM);
478  goto cleanup;
479  }
480 
481  tmp.num_rects++;
482 
483  dst_rect->type = src_rect->type;
484  dst_rect->flags = src_rect->flags;
485 
486  dst_rect->x = src_rect->x;
487  dst_rect->y = src_rect->y;
488  dst_rect->w = src_rect->w;
489  dst_rect->h = src_rect->h;
490  dst_rect->nb_colors = src_rect->nb_colors;
491 
492  if (src_rect->text)
493  if (!(dst_rect->text = av_strdup(src_rect->text))) {
494  ret = AVERROR(ENOMEM);
495  goto cleanup;
496  }
497 
498  if (src_rect->ass)
499  if (!(dst_rect->ass = av_strdup(src_rect->ass))) {
500  ret = AVERROR(ENOMEM);
501  goto cleanup;
502  }
503 
504  for (int j = 0; j < 4; j++) {
505  // SUBTITLE_BITMAP images are special in the sense that they
506  // are like PAL8 images. first pointer to data, second to
507  // palette. This makes the size calculation match this.
508  size_t buf_size = src_rect->type == SUBTITLE_BITMAP && j == 1 ?
510  src_rect->h * src_rect->linesize[j];
511 
512  if (!src_rect->data[j])
513  continue;
514 
515  if (!(dst_rect->data[j] = av_memdup(src_rect->data[j], buf_size))) {
516  ret = AVERROR(ENOMEM);
517  goto cleanup;
518  }
519  dst_rect->linesize[j] = src_rect->linesize[j];
520  }
521  }
522 
523 success:
524  *dst = tmp;
525 
526  return 0;
527 
528 cleanup:
530 
531  return ret;
532 }
533 
534 static void subtitle_free(void *opaque, uint8_t *data)
535 {
536  AVSubtitle *sub = (AVSubtitle*)data;
537  avsubtitle_free(sub);
538  av_free(sub);
539 }
540 
541 static int subtitle_wrap_frame(AVFrame *frame, AVSubtitle *subtitle, int copy)
542 {
543  AVBufferRef *buf;
544  AVSubtitle *sub;
545  int ret;
546 
547  if (copy) {
548  sub = av_mallocz(sizeof(*sub));
549  ret = sub ? copy_av_subtitle(sub, subtitle) : AVERROR(ENOMEM);
550  if (ret < 0) {
551  av_freep(&sub);
552  return ret;
553  }
554  } else {
555  sub = av_memdup(subtitle, sizeof(*subtitle));
556  if (!sub)
557  return AVERROR(ENOMEM);
558  memset(subtitle, 0, sizeof(*subtitle));
559  }
560 
561  buf = av_buffer_create((uint8_t*)sub, sizeof(*sub),
562  subtitle_free, NULL, 0);
563  if (!buf) {
564  avsubtitle_free(sub);
565  av_freep(&sub);
566  return AVERROR(ENOMEM);
567  }
568 
569  frame->buf[0] = buf;
570 
571  return 0;
572 }
573 
575 {
576  const AVSubtitle *subtitle = (AVSubtitle*)frame->buf[0]->data;
577  int ret = 0;
578 
580  AVSubtitle *sub_prev = dp->sub_prev[0]->buf[0] ?
581  (AVSubtitle*)dp->sub_prev[0]->buf[0]->data : NULL;
582  int end = 1;
583  if (sub_prev) {
584  end = av_rescale(subtitle->pts - sub_prev->pts,
585  1000, AV_TIME_BASE);
586  if (end < sub_prev->end_display_time) {
587  av_log(dp, AV_LOG_DEBUG,
588  "Subtitle duration reduced from %"PRId32" to %d%s\n",
589  sub_prev->end_display_time, end,
590  end <= 0 ? ", dropping it" : "");
591  sub_prev->end_display_time = end;
592  }
593  }
594 
595  av_frame_unref(dp->sub_prev[1]);
597 
598  frame = dp->sub_prev[0];
599  subtitle = frame->buf[0] ? (AVSubtitle*)frame->buf[0]->data : NULL;
600 
601  FFSWAP(AVFrame*, dp->sub_prev[0], dp->sub_prev[1]);
602 
603  if (end <= 0)
604  return 0;
605  }
606 
607  if (!subtitle)
608  return 0;
609 
610  ret = sch_dec_send(dp->sch, dp->sch_idx, 0, frame);
611  if (ret < 0)
613 
614  return ret == AVERROR_EOF ? AVERROR_EXIT : ret;
615 }
616 
617 static int fix_sub_duration_heartbeat(DecoderPriv *dp, int64_t signal_pts)
618 {
619  int ret = AVERROR_BUG;
620  AVSubtitle *prev_subtitle = dp->sub_prev[0]->buf[0] ?
621  (AVSubtitle*)dp->sub_prev[0]->buf[0]->data : NULL;
622  AVSubtitle *subtitle;
623 
624  if (!(dp->flags & DECODER_FLAG_FIX_SUB_DURATION) || !prev_subtitle ||
625  !prev_subtitle->num_rects || signal_pts <= prev_subtitle->pts)
626  return 0;
627 
629  ret = subtitle_wrap_frame(dp->sub_heartbeat, prev_subtitle, 1);
630  if (ret < 0)
631  return ret;
632 
633  subtitle = (AVSubtitle*)dp->sub_heartbeat->buf[0]->data;
634  subtitle->pts = signal_pts;
635 
636  return process_subtitle(dp, dp->sub_heartbeat);
637 }
638 
640  AVFrame *frame)
641 {
642  AVPacket *flush_pkt = NULL;
643  AVSubtitle subtitle;
644  int got_output;
645  int ret;
646 
647  if (pkt && (intptr_t)pkt->opaque == PKT_OPAQUE_SUB_HEARTBEAT) {
648  frame->pts = pkt->pts;
649  frame->time_base = pkt->time_base;
650  frame->opaque = (void*)(intptr_t)FRAME_OPAQUE_SUB_HEARTBEAT;
651 
652  ret = sch_dec_send(dp->sch, dp->sch_idx, 0, frame);
653  return ret == AVERROR_EOF ? AVERROR_EXIT : ret;
654  } else if (pkt && (intptr_t)pkt->opaque == PKT_OPAQUE_FIX_SUB_DURATION) {
656  AV_TIME_BASE_Q));
657  }
658 
659  if (!pkt) {
660  flush_pkt = av_packet_alloc();
661  if (!flush_pkt)
662  return AVERROR(ENOMEM);
663  }
664 
665  ret = avcodec_decode_subtitle2(dp->dec_ctx, &subtitle, &got_output,
666  pkt ? pkt : flush_pkt);
667  av_packet_free(&flush_pkt);
668 
669  if (ret < 0) {
670  av_log(dp, AV_LOG_ERROR, "Error decoding subtitles: %s\n",
671  av_err2str(ret));
672  dp->dec.decode_errors++;
673  return exit_on_error ? ret : 0;
674  }
675 
676  if (!got_output)
677  return pkt ? 0 : AVERROR_EOF;
678 
679  dp->dec.frames_decoded++;
680 
681  // XXX the queue for transferring data to consumers runs
682  // on AVFrames, so we wrap AVSubtitle in an AVBufferRef and put that
683  // inside the frame
684  // eventually, subtitles should be switched to use AVFrames natively
685  ret = subtitle_wrap_frame(frame, &subtitle, 0);
686  if (ret < 0) {
687  avsubtitle_free(&subtitle);
688  return ret;
689  }
690 
691  frame->width = dp->dec_ctx->width;
692  frame->height = dp->dec_ctx->height;
693 
694  return process_subtitle(dp, frame);
695 }
696 
698 {
699  AVCodecContext *dec = dp->dec_ctx;
700  const char *type_desc = av_get_media_type_string(dec->codec_type);
701  int ret;
702 
703  if (dec->codec_type == AVMEDIA_TYPE_SUBTITLE)
704  return transcode_subtitles(dp, pkt, frame);
705 
706  // With fate-indeo3-2, we're getting 0-sized packets before EOF for some
707  // reason. This seems like a semi-critical bug. Don't trigger EOF, and
708  // skip the packet.
709  if (pkt && pkt->size == 0)
710  return 0;
711 
712  if (pkt && (dp->flags & DECODER_FLAG_TS_UNRELIABLE)) {
715  }
716 
717  if (pkt) {
718  FrameData *fd = packet_data(pkt);
719  if (!fd)
720  return AVERROR(ENOMEM);
722  }
723 
724  ret = avcodec_send_packet(dec, pkt);
725  if (ret < 0 && !(ret == AVERROR_EOF && !pkt)) {
726  // In particular, we don't expect AVERROR(EAGAIN), because we read all
727  // decoded frames with avcodec_receive_frame() until done.
728  if (ret == AVERROR(EAGAIN)) {
729  av_log(dp, AV_LOG_FATAL, "A decoder returned an unexpected error code. "
730  "This is a bug, please report it.\n");
731  return AVERROR_BUG;
732  }
733  av_log(dp, AV_LOG_ERROR, "Error submitting %s to decoder: %s\n",
734  pkt ? "packet" : "EOF", av_err2str(ret));
735 
736  if (ret == AVERROR_EOF)
737  return ret;
738 
739  dp->dec.decode_errors++;
740  if (exit_on_error)
741  return ret;
742  }
743 
744  while (1) {
745  FrameData *fd;
746  unsigned outputs_mask = 1;
747  unsigned flags = 0;
748  if (!dp->dec.frames_decoded)
750 
752 
755  update_benchmark("decode_%s %s", type_desc, dp->parent_name);
756 
757  if (ret == AVERROR(EAGAIN)) {
758  av_assert0(pkt); // should never happen during flushing
759  return 0;
760  } else if (ret == AVERROR_EOF) {
761  return ret;
762  } else if (ret < 0) {
763  av_log(dp, AV_LOG_ERROR, "Decoding error: %s\n", av_err2str(ret));
764  dp->dec.decode_errors++;
765 
766  if (exit_on_error)
767  return ret;
768 
769  continue;
770  }
771 
772  if (frame->decode_error_flags || (frame->flags & AV_FRAME_FLAG_CORRUPT)) {
774  "corrupt decoded frame\n");
775  if (exit_on_error)
776  return AVERROR_INVALIDDATA;
777  }
778 
779  fd = frame_data(frame);
780  if (!fd) {
782  return AVERROR(ENOMEM);
783  }
784  fd->dec.pts = frame->pts;
785  fd->dec.tb = dec->pkt_timebase;
786  fd->dec.frame_num = dec->frame_num - 1;
788 
790 
791  frame->time_base = dec->pkt_timebase;
792 
793  if (dec->codec_type == AVMEDIA_TYPE_AUDIO) {
794  dp->dec.samples_decoded += frame->nb_samples;
795 
796  audio_ts_process(dp, frame);
797  } else {
798  ret = video_frame_process(dp, frame, &outputs_mask);
799  if (ret < 0) {
800  av_log(dp, AV_LOG_FATAL,
801  "Error while processing the decoded data\n");
802  return ret;
803  }
804  }
805 
806  dp->dec.frames_decoded++;
807 
808  for (int i = 0; i < stdc_count_ones(outputs_mask); i++) {
809  AVFrame *to_send = frame;
810  int pos;
811 
812  av_assert0(outputs_mask);
813  pos = stdc_trailing_zeros(outputs_mask);
814  outputs_mask &= ~(1U << pos);
815 
816  // this is not the last output and sch_dec_send() consumes the frame
817  // given to it, so make a temporary reference
818  if (outputs_mask) {
819  to_send = dp->frame_tmp_ref;
820  ret = av_frame_ref(to_send, frame);
821  if (ret < 0)
822  return ret;
823  }
824 
825  ret = sch_dec_send(dp->sch, dp->sch_idx, pos, to_send);
826  if (ret < 0) {
827  av_frame_unref(to_send);
828  return ret == AVERROR_EOF ? AVERROR_EXIT : ret;
829  }
830  }
831  }
832 }
833 
834 static int dec_open(DecoderPriv *dp, AVDictionary **dec_opts,
835  const DecoderOpts *o, AVFrame *param_out);
836 
838 {
839  DecoderOpts o;
840  const FrameData *fd;
841  char name[16];
842 
843  if (!pkt->opaque_ref)
844  return AVERROR_BUG;
845  fd = (FrameData *)pkt->opaque_ref->data;
846 
847  if (!fd->par_enc)
848  return AVERROR_BUG;
849 
850  memset(&o, 0, sizeof(o));
851 
852  o.par = fd->par_enc;
853  o.time_base = pkt->time_base;
854 
855  o.codec = dp->standalone_init.codec;
856  if (!o.codec)
858  if (!o.codec) {
860 
861  av_log(dp, AV_LOG_ERROR, "Cannot find a decoder for codec ID '%s'\n",
862  desc ? desc->name : "?");
864  }
865 
866  snprintf(name, sizeof(name), "dec%d", dp->index);
867  o.name = name;
868 
869  return dec_open(dp, &dp->standalone_init.opts, &o, NULL);
870 }
871 
872 static void dec_thread_set_name(const DecoderPriv *dp)
873 {
874  char name[16] = "dec";
875 
876  if (dp->index >= 0)
877  av_strlcatf(name, sizeof(name), "%d", dp->index);
878  else if (dp->parent_name)
879  av_strlcat(name, dp->parent_name, sizeof(name));
880 
881  if (dp->dec_ctx)
882  av_strlcatf(name, sizeof(name), ":%s", dp->dec_ctx->codec->name);
883 
885 }
886 
888 {
889  av_packet_free(&dt->pkt);
890  av_frame_free(&dt->frame);
891 
892  memset(dt, 0, sizeof(*dt));
893 }
894 
896 {
897  memset(dt, 0, sizeof(*dt));
898 
899  dt->frame = av_frame_alloc();
900  if (!dt->frame)
901  goto fail;
902 
903  dt->pkt = av_packet_alloc();
904  if (!dt->pkt)
905  goto fail;
906 
907  return 0;
908 
909 fail:
910  dec_thread_uninit(dt);
911  return AVERROR(ENOMEM);
912 }
913 
914 static int decoder_thread(void *arg)
915 {
916  DecoderPriv *dp = arg;
917  DecThreadContext dt;
918  int ret = 0, input_status = 0;
919 
920  ret = dec_thread_init(&dt);
921  if (ret < 0)
922  goto finish;
923 
925 
926  while (!input_status) {
927  int flush_buffers, have_data;
928 
929  input_status = sch_dec_receive(dp->sch, dp->sch_idx, dt.pkt);
930  have_data = input_status >= 0 &&
931  (dt.pkt->buf || dt.pkt->side_data_elems ||
932  (intptr_t)dt.pkt->opaque == PKT_OPAQUE_SUB_HEARTBEAT ||
933  (intptr_t)dt.pkt->opaque == PKT_OPAQUE_FIX_SUB_DURATION);
934  flush_buffers = input_status >= 0 && !have_data;
935  if (!have_data)
936  av_log(dp, AV_LOG_VERBOSE, "Decoder thread received %s packet\n",
937  flush_buffers ? "flush" : "EOF");
938 
939  // this is a standalone decoder that has not been initialized yet
940  if (!dp->dec_ctx) {
941  if (flush_buffers)
942  continue;
943  if (input_status < 0) {
944  av_log(dp, AV_LOG_ERROR,
945  "Cannot initialize a standalone decoder\n");
946  ret = input_status;
947  goto finish;
948  }
949 
950  ret = dec_standalone_open(dp, dt.pkt);
951  if (ret < 0)
952  goto finish;
953  }
954 
955  ret = packet_decode(dp, have_data ? dt.pkt : NULL, dt.frame);
956 
957  av_packet_unref(dt.pkt);
958  av_frame_unref(dt.frame);
959 
960  // AVERROR_EOF - EOF from the decoder
961  // AVERROR_EXIT - EOF from the scheduler
962  // we treat them differently when flushing
963  if (ret == AVERROR_EXIT) {
964  ret = AVERROR_EOF;
965  flush_buffers = 0;
966  }
967 
968  if (ret == AVERROR_EOF) {
969  av_log(dp, AV_LOG_VERBOSE, "Decoder returned EOF, %s\n",
970  flush_buffers ? "resetting" : "finishing");
971 
972  if (!flush_buffers)
973  break;
974 
975  /* report last frame duration to the scheduler */
976  if (dp->dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
978  dt.pkt->time_base = dp->last_frame_tb;
979  }
980 
982  } else if (ret < 0) {
983  av_log(dp, AV_LOG_ERROR, "Error processing packet in decoder: %s\n",
984  av_err2str(ret));
985  break;
986  }
987  }
988 
989  // EOF is normal thread termination
990  if (ret == AVERROR_EOF)
991  ret = 0;
992 
993  // on success send EOF timestamp to our downstreams
994  if (ret >= 0) {
995  float err_rate;
996 
997  av_frame_unref(dt.frame);
998 
999  dt.frame->opaque = (void*)(intptr_t)FRAME_OPAQUE_EOF;
1002  dt.frame->time_base = dp->last_frame_tb;
1003 
1004  ret = sch_dec_send(dp->sch, dp->sch_idx, 0, dt.frame);
1005  if (ret < 0 && ret != AVERROR_EOF) {
1006  av_log(dp, AV_LOG_FATAL,
1007  "Error signalling EOF timestamp: %s\n", av_err2str(ret));
1008  goto finish;
1009  }
1010  ret = 0;
1011 
1012  err_rate = (dp->dec.frames_decoded || dp->dec.decode_errors) ?
1013  (float)dp->dec.decode_errors / (dp->dec.frames_decoded + dp->dec.decode_errors) : 0.f;
1014  if (err_rate > max_error_rate) {
1015  av_log(dp, AV_LOG_FATAL, "Decode error rate %g exceeds maximum %g\n",
1016  err_rate, max_error_rate);
1018  } else if (err_rate)
1019  av_log(dp, AV_LOG_VERBOSE, "Decode error rate %g\n", err_rate);
1020  }
1021 
1022 finish:
1023  dec_thread_uninit(&dt);
1025 
1026  return ret;
1027 }
1028 
1030  SchedulerNode *src)
1031 {
1032  DecoderPriv *dp = dp_from_dec(d);
1033  unsigned out_idx = 0;
1034  int ret;
1035 
1036  if (dp->multiview_user_config) {
1037  if (!vs || vs->type == VIEW_SPECIFIER_TYPE_NONE) {
1038  *src = SCH_DEC_OUT(dp->sch_idx, 0);
1039  return 0;
1040  }
1041 
1042  av_log(dp, AV_LOG_ERROR,
1043  "Manually selecting views with -view_ids cannot be combined "
1044  "with view selection via stream specifiers. It is strongly "
1045  "recommended you always use stream specifiers only.\n");
1046  return AVERROR(EINVAL);
1047  }
1048 
1049  // when multiview_user_config is not set, NONE specifier is treated
1050  // as requesting the base view
1051  vs = (vs && vs->type != VIEW_SPECIFIER_TYPE_NONE) ? vs :
1052  &(ViewSpecifier){ .type = VIEW_SPECIFIER_TYPE_IDX, .val = 0 };
1053 
1054  // check if the specifier matches an already-existing one
1055  for (int i = 0; i < dp->nb_views_requested; i++) {
1056  const ViewSpecifier *vs1 = &dp->views_requested[i].vs;
1057 
1058  if (vs->type == vs1->type &&
1059  (vs->type == VIEW_SPECIFIER_TYPE_ALL || vs->val == vs1->val)) {
1061  return 0;
1062  }
1063  }
1064 
1065  // we use a bitmask to map view IDs to decoder outputs, which
1066  // limits the number of outputs allowed
1067  if (dp->nb_views_requested >= sizeof(dp->view_map[0].out_mask) * 8) {
1068  av_log(dp, AV_LOG_ERROR, "Too many view specifiers\n");
1069  return AVERROR(ENOSYS);
1070  }
1071 
1073  if (ret < 0)
1074  return ret;
1075 
1076  if (dp->nb_views_requested > 1) {
1077  ret = sch_add_dec_output(dp->sch, dp->sch_idx);
1078  if (ret < 0)
1079  return ret;
1080  out_idx = ret;
1081  }
1082 
1083  dp->views_requested[dp->nb_views_requested - 1].out_idx = out_idx;
1084  dp->views_requested[dp->nb_views_requested - 1].vs = *vs;
1085 
1086  *src = SCH_DEC_OUT(dp->sch_idx,
1088 
1089  return 0;
1090 }
1091 
1093 {
1094  unsigned views_wanted = 0;
1095 
1096  unsigned nb_view_ids_av, nb_view_ids;
1097  unsigned *view_ids_av = NULL, *view_pos_av = NULL;
1098  int *view_ids = NULL;
1099  int ret;
1100 
1101  // no views/only base view were requested - do nothing
1102  if (!dp->nb_views_requested ||
1103  (dp->nb_views_requested == 1 &&
1105  dp->views_requested[0].vs.val == 0))
1106  return 0;
1107 
1108  av_freep(&dp->view_map);
1109  dp->nb_view_map = 0;
1110 
1111  // retrieve views available in current CVS
1112  ret = av_opt_get_array_size(dec_ctx, "view_ids_available",
1113  AV_OPT_SEARCH_CHILDREN, &nb_view_ids_av);
1114  if (ret < 0) {
1115  av_log(dp, AV_LOG_ERROR,
1116  "Multiview decoding requested, but decoder '%s' does not "
1117  "support it\n", dec_ctx->codec->name);
1118  return AVERROR(ENOSYS);
1119  }
1120 
1121  if (nb_view_ids_av) {
1122  unsigned nb_view_pos_av;
1123 
1124  if (nb_view_ids_av >= sizeof(views_wanted) * 8) {
1125  av_log(dp, AV_LOG_ERROR, "Too many views in video: %u\n", nb_view_ids_av);
1126  ret = AVERROR(ENOSYS);
1127  goto fail;
1128  }
1129 
1130  view_ids_av = av_calloc(nb_view_ids_av, sizeof(*view_ids_av));
1131  if (!view_ids_av) {
1132  ret = AVERROR(ENOMEM);
1133  goto fail;
1134  }
1135 
1136  ret = av_opt_get_array(dec_ctx, "view_ids_available",
1137  AV_OPT_SEARCH_CHILDREN, 0, nb_view_ids_av,
1138  AV_OPT_TYPE_UINT, view_ids_av);
1139  if (ret < 0)
1140  goto fail;
1141 
1142  ret = av_opt_get_array_size(dec_ctx, "view_pos_available",
1143  AV_OPT_SEARCH_CHILDREN, &nb_view_pos_av);
1144  if (ret >= 0 && nb_view_pos_av == nb_view_ids_av) {
1145  view_pos_av = av_calloc(nb_view_ids_av, sizeof(*view_pos_av));
1146  if (!view_pos_av) {
1147  ret = AVERROR(ENOMEM);
1148  goto fail;
1149  }
1150 
1151  ret = av_opt_get_array(dec_ctx, "view_pos_available",
1152  AV_OPT_SEARCH_CHILDREN, 0, nb_view_ids_av,
1153  AV_OPT_TYPE_UINT, view_pos_av);
1154  if (ret < 0)
1155  goto fail;
1156  }
1157  } else {
1158  // assume there is a single view with ID=0
1159  nb_view_ids_av = 1;
1160  view_ids_av = av_calloc(nb_view_ids_av, sizeof(*view_ids_av));
1161  view_pos_av = av_calloc(nb_view_ids_av, sizeof(*view_pos_av));
1162  if (!view_ids_av || !view_pos_av) {
1163  ret = AVERROR(ENOMEM);
1164  goto fail;
1165  }
1166  view_pos_av[0] = AV_STEREO3D_VIEW_UNSPEC;
1167  }
1168 
1169  dp->view_map = av_calloc(nb_view_ids_av, sizeof(*dp->view_map));
1170  if (!dp->view_map) {
1171  ret = AVERROR(ENOMEM);
1172  goto fail;
1173  }
1174  dp->nb_view_map = nb_view_ids_av;
1175 
1176  for (int i = 0; i < dp->nb_view_map; i++)
1177  dp->view_map[i].id = view_ids_av[i];
1178 
1179  // figure out which views should go to which output
1180  for (int i = 0; i < dp->nb_views_requested; i++) {
1181  const ViewSpecifier *vs = &dp->views_requested[i].vs;
1182 
1183  switch (vs->type) {
1185  if (vs->val >= nb_view_ids_av) {
1187  "View with index %u requested, but only %u views available "
1188  "in current video sequence (more views may or may not be "
1189  "available in later sequences).\n",
1190  vs->val, nb_view_ids_av);
1191  if (exit_on_error) {
1192  ret = AVERROR(EINVAL);
1193  goto fail;
1194  }
1195 
1196  continue;
1197  }
1198  views_wanted |= 1U << vs->val;
1199  dp->view_map[vs->val].out_mask |= 1ULL << i;
1200 
1201  break;
1202  case VIEW_SPECIFIER_TYPE_ID: {
1203  int view_idx = -1;
1204 
1205  for (unsigned j = 0; j < nb_view_ids_av; j++) {
1206  if (view_ids_av[j] == vs->val) {
1207  view_idx = j;
1208  break;
1209  }
1210  }
1211  if (view_idx < 0) {
1213  "View with ID %u requested, but is not available "
1214  "in the video sequence\n", vs->val);
1215  if (exit_on_error) {
1216  ret = AVERROR(EINVAL);
1217  goto fail;
1218  }
1219 
1220  continue;
1221  }
1222  views_wanted |= 1U << view_idx;
1223  dp->view_map[view_idx].out_mask |= 1ULL << i;
1224 
1225  break;
1226  }
1227  case VIEW_SPECIFIER_TYPE_POS: {
1228  int view_idx = -1;
1229 
1230  for (unsigned j = 0; view_pos_av && j < nb_view_ids_av; j++) {
1231  if (view_pos_av[j] == vs->val) {
1232  view_idx = j;
1233  break;
1234  }
1235  }
1236  if (view_idx < 0) {
1238  "View position '%s' requested, but is not available "
1239  "in the video sequence\n", av_stereo3d_view_name(vs->val));
1240  if (exit_on_error) {
1241  ret = AVERROR(EINVAL);
1242  goto fail;
1243  }
1244 
1245  continue;
1246  }
1247  views_wanted |= 1U << view_idx;
1248  dp->view_map[view_idx].out_mask |= 1ULL << i;
1249 
1250  break;
1251  }
1253  views_wanted |= (1U << nb_view_ids_av) - 1;
1254 
1255  for (int j = 0; j < dp->nb_view_map; j++)
1256  dp->view_map[j].out_mask |= 1ULL << i;
1257 
1258  break;
1259  }
1260  }
1261  if (!views_wanted) {
1262  av_log(dp, AV_LOG_ERROR, "No views were selected for decoding\n");
1263  ret = AVERROR(EINVAL);
1264  goto fail;
1265  }
1266 
1267  // signal to decoder which views we want
1268  nb_view_ids = stdc_count_ones(views_wanted);
1269  view_ids = av_malloc_array(nb_view_ids, sizeof(*view_ids));
1270  if (!view_ids) {
1271  ret = AVERROR(ENOMEM);
1272  goto fail;
1273  }
1274 
1275  for (unsigned i = 0; i < nb_view_ids; i++) {
1276  int pos;
1277 
1278  av_assert0(views_wanted);
1279  pos = stdc_trailing_zeros(views_wanted);
1280  views_wanted &= ~(1U << pos);
1281 
1282  view_ids[i] = view_ids_av[pos];
1283  }
1284 
1285  // unset view_ids in case we set it earlier
1287 
1289  0, nb_view_ids, AV_OPT_TYPE_INT, view_ids);
1290  if (ret < 0)
1291  goto fail;
1292 
1293  if (!dp->frame_tmp_ref) {
1294  dp->frame_tmp_ref = av_frame_alloc();
1295  if (!dp->frame_tmp_ref) {
1296  ret = AVERROR(ENOMEM);
1297  goto fail;
1298  }
1299  }
1300 
1301 fail:
1302  av_freep(&view_ids_av);
1303  av_freep(&view_pos_av);
1304  av_freep(&view_ids);
1305 
1306  return ret;
1307 }
1308 
1309 static void multiview_check_manual(DecoderPriv *dp, const AVDictionary *dec_opts)
1310 {
1311  if (av_dict_get(dec_opts, "view_ids", NULL, 0)) {
1312  av_log(dp, AV_LOG_WARNING, "Manually selecting views with -view_ids "
1313  "is not recommended, use view specifiers instead\n");
1314  dp->multiview_user_config = 1;
1315  }
1316 }
1317 
1319 {
1320  DecoderPriv *dp = s->opaque;
1321  const enum AVPixelFormat *p;
1322  int ret;
1323 
1324  ret = multiview_setup(dp, s);
1325  if (ret < 0) {
1326  av_log(dp, AV_LOG_ERROR, "Error setting up multiview decoding: %s\n",
1327  av_err2str(ret));
1328  return AV_PIX_FMT_NONE;
1329  }
1330 
1331  for (p = pix_fmts; *p != AV_PIX_FMT_NONE; p++) {
1333  const AVCodecHWConfig *config = NULL;
1334 
1335  if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL))
1336  break;
1337 
1338  if (dp->hwaccel_id == HWACCEL_GENERIC ||
1339  dp->hwaccel_id == HWACCEL_AUTO) {
1340  for (int i = 0;; i++) {
1341  config = avcodec_get_hw_config(s->codec, i);
1342  if (!config)
1343  break;
1344  if (!(config->methods &
1346  continue;
1347  if (config->pix_fmt == *p)
1348  break;
1349  }
1350  }
1351  if (config && config->device_type == dp->hwaccel_device_type) {
1352  dp->hwaccel_pix_fmt = *p;
1353  break;
1354  }
1355  }
1356 
1357  return *p;
1358 }
1359 
1361 {
1362  DecoderPriv *dp = dec_ctx->opaque;
1363 
1364  // for multiview video, store the output mask in frame opaque
1365  if (dp->nb_view_map) {
1367  int view_id = sd ? *(int*)sd->data : 0;
1368 
1369  for (int i = 0; i < dp->nb_view_map; i++) {
1370  if (dp->view_map[i].id == view_id) {
1371  frame->opaque = (void*)dp->view_map[i].out_mask;
1372  break;
1373  }
1374  }
1375  }
1376 
1378 }
1379 
1381 {
1382  const AVCodecHWConfig *config;
1383  HWDevice *dev;
1384  for (int i = 0;; i++) {
1385  config = avcodec_get_hw_config(codec, i);
1386  if (!config)
1387  return NULL;
1389  continue;
1390  dev = hw_device_get_by_type(config->device_type);
1391  if (dev)
1392  return dev;
1393  }
1394 }
1395 
1397  const AVCodec *codec,
1398  const char *hwaccel_device)
1399 {
1400  const AVCodecHWConfig *config;
1401  enum AVHWDeviceType type;
1402  HWDevice *dev = NULL;
1403  int err, auto_device = 0;
1404 
1405  if (hwaccel_device) {
1406  dev = hw_device_get_by_name(hwaccel_device);
1407  if (!dev) {
1408  if (dp->hwaccel_id == HWACCEL_AUTO) {
1409  auto_device = 1;
1410  } else if (dp->hwaccel_id == HWACCEL_GENERIC) {
1411  type = dp->hwaccel_device_type;
1412  err = hw_device_init_from_type(type, hwaccel_device,
1413  &dev);
1414  } else {
1415  // This will be dealt with by API-specific initialisation
1416  // (using hwaccel_device), so nothing further needed here.
1417  return 0;
1418  }
1419  } else {
1420  if (dp->hwaccel_id == HWACCEL_AUTO) {
1421  dp->hwaccel_device_type = dev->type;
1422  } else if (dp->hwaccel_device_type != dev->type) {
1423  av_log(dp, AV_LOG_ERROR, "Invalid hwaccel device "
1424  "specified for decoder: device %s of type %s is not "
1425  "usable with hwaccel %s.\n", dev->name,
1428  return AVERROR(EINVAL);
1429  }
1430  }
1431  } else {
1432  if (dp->hwaccel_id == HWACCEL_AUTO) {
1433  auto_device = 1;
1434  } else if (dp->hwaccel_id == HWACCEL_GENERIC) {
1435  type = dp->hwaccel_device_type;
1436  dev = hw_device_get_by_type(type);
1437 
1438  // When "-qsv_device device" is used, an internal QSV device named
1439  // as "__qsv_device" is created. Another QSV device is created too
1440  // if "-init_hw_device qsv=name:device" is used. There are 2 QSV devices
1441  // if both "-qsv_device device" and "-init_hw_device qsv=name:device"
1442  // are used, hw_device_get_by_type(AV_HWDEVICE_TYPE_QSV) returns NULL.
1443  // To keep back-compatibility with the removed ad-hoc libmfx setup code,
1444  // call hw_device_get_by_name("__qsv_device") to select the internal QSV
1445  // device.
1446  if (!dev && type == AV_HWDEVICE_TYPE_QSV)
1447  dev = hw_device_get_by_name("__qsv_device");
1448 
1449  if (!dev)
1450  err = hw_device_init_from_type(type, NULL, &dev);
1451  } else {
1452  dev = hw_device_match_by_codec(codec);
1453  if (!dev) {
1454  // No device for this codec, but not using generic hwaccel
1455  // and therefore may well not need one - ignore.
1456  return 0;
1457  }
1458  }
1459  }
1460 
1461  if (auto_device) {
1462  if (!avcodec_get_hw_config(codec, 0)) {
1463  // Decoder does not support any hardware devices.
1464  return 0;
1465  }
1466  for (int i = 0; !dev; i++) {
1467  config = avcodec_get_hw_config(codec, i);
1468  if (!config)
1469  break;
1470  type = config->device_type;
1471  dev = hw_device_get_by_type(type);
1472  if (dev) {
1473  av_log(dp, AV_LOG_INFO, "Using auto "
1474  "hwaccel type %s with existing device %s.\n",
1476  }
1477  }
1478  for (int i = 0; !dev; i++) {
1479  config = avcodec_get_hw_config(codec, i);
1480  if (!config)
1481  break;
1482  type = config->device_type;
1483  // Try to make a new device of this type.
1484  err = hw_device_init_from_type(type, hwaccel_device,
1485  &dev);
1486  if (err < 0) {
1487  // Can't make a device of this type.
1488  continue;
1489  }
1490  if (hwaccel_device) {
1491  av_log(dp, AV_LOG_INFO, "Using auto "
1492  "hwaccel type %s with new device created "
1493  "from %s.\n", av_hwdevice_get_type_name(type),
1494  hwaccel_device);
1495  } else {
1496  av_log(dp, AV_LOG_INFO, "Using auto "
1497  "hwaccel type %s with new default device.\n",
1499  }
1500  }
1501  if (dev) {
1502  dp->hwaccel_device_type = type;
1503  } else {
1504  av_log(dp, AV_LOG_INFO, "Auto hwaccel "
1505  "disabled: no device found.\n");
1506  dp->hwaccel_id = HWACCEL_NONE;
1507  return 0;
1508  }
1509  }
1510 
1511  if (!dev) {
1512  av_log(dp, AV_LOG_ERROR, "No device available "
1513  "for decoder: device type %s needed for codec %s.\n",
1515  return err;
1516  }
1517 
1519  if (!dp->dec_ctx->hw_device_ctx)
1520  return AVERROR(ENOMEM);
1521 
1522  return 0;
1523 }
1524 
1525 static int dec_open(DecoderPriv *dp, AVDictionary **dec_opts,
1526  const DecoderOpts *o, AVFrame *param_out)
1527 {
1528  const AVCodec *codec = o->codec;
1529  int ret;
1530 
1531  dp->flags = o->flags;
1532  dp->log_parent = o->log_parent;
1533 
1534  dp->dec.type = codec->type;
1535  dp->framerate_in = o->framerate;
1536 
1537  dp->hwaccel_id = o->hwaccel_id;
1540 
1541  snprintf(dp->log_name, sizeof(dp->log_name), "dec:%s", codec->name);
1542 
1543  dp->parent_name = av_strdup(o->name ? o->name : "");
1544  if (!dp->parent_name)
1545  return AVERROR(ENOMEM);
1546 
1547  if (codec->type == AVMEDIA_TYPE_SUBTITLE &&
1549  for (int i = 0; i < FF_ARRAY_ELEMS(dp->sub_prev); i++) {
1550  dp->sub_prev[i] = av_frame_alloc();
1551  if (!dp->sub_prev[i])
1552  return AVERROR(ENOMEM);
1553  }
1554  dp->sub_heartbeat = av_frame_alloc();
1555  if (!dp->sub_heartbeat)
1556  return AVERROR(ENOMEM);
1557  }
1558 
1560 
1561  dp->dec_ctx = avcodec_alloc_context3(codec);
1562  if (!dp->dec_ctx)
1563  return AVERROR(ENOMEM);
1564 
1566  if (ret < 0) {
1567  av_log(dp, AV_LOG_ERROR, "Error initializing the decoder context.\n");
1568  return ret;
1569  }
1570 
1571  dp->dec_ctx->opaque = dp;
1572  dp->dec_ctx->get_format = get_format;
1574  dp->dec_ctx->pkt_timebase = o->time_base;
1575 
1576  if (!av_dict_get(*dec_opts, "threads", NULL, 0))
1577  av_dict_set(dec_opts, "threads", "auto", 0);
1578 
1580  if (ret < 0) {
1581  av_log(dp, AV_LOG_ERROR,
1582  "Hardware device setup failed for decoder: %s\n",
1583  av_err2str(ret));
1584  return ret;
1585  }
1586 
1588  if (ret < 0) {
1589  av_log(dp, AV_LOG_ERROR, "Error applying decoder options: %s\n",
1590  av_err2str(ret));
1591  return ret;
1592  }
1593  ret = check_avoptions(*dec_opts);
1594  if (ret < 0)
1595  return ret;
1596 
1598  if (o->flags & DECODER_FLAG_BITEXACT)
1600 
1601  // we apply cropping ourselves
1603  dp->dec_ctx->apply_cropping = 0;
1604 
1605  if ((ret = avcodec_open2(dp->dec_ctx, codec, NULL)) < 0) {
1606  av_log(dp, AV_LOG_ERROR, "Error while opening decoder: %s\n",
1607  av_err2str(ret));
1608  return ret;
1609  }
1610 
1611  if (dp->dec_ctx->hw_device_ctx) {
1612  // Update decoder extra_hw_frames option to account for the
1613  // frames held in queues inside the ffmpeg utility. This is
1614  // called after avcodec_open2() because the user-set value of
1615  // extra_hw_frames becomes valid in there, and we need to add
1616  // this on top of it.
1617  int extra_frames = DEFAULT_FRAME_THREAD_QUEUE_SIZE;
1618  if (dp->dec_ctx->extra_hw_frames >= 0)
1619  dp->dec_ctx->extra_hw_frames += extra_frames;
1620  else
1621  dp->dec_ctx->extra_hw_frames = extra_frames;
1622  }
1623 
1626 
1627  if (param_out) {
1628  if (dp->dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
1629  param_out->format = dp->dec_ctx->sample_fmt;
1630  param_out->sample_rate = dp->dec_ctx->sample_rate;
1631 
1632  ret = av_channel_layout_copy(&param_out->ch_layout, &dp->dec_ctx->ch_layout);
1633  if (ret < 0)
1634  return ret;
1635  } else if (dp->dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO) {
1636  param_out->format = dp->dec_ctx->pix_fmt;
1637  param_out->width = dp->dec_ctx->width;
1638  param_out->height = dp->dec_ctx->height;
1640  param_out->colorspace = dp->dec_ctx->colorspace;
1641  param_out->color_range = dp->dec_ctx->color_range;
1642  param_out->alpha_mode = dp->dec_ctx->alpha_mode;
1643  }
1644 
1645  av_frame_side_data_free(&param_out->side_data, &param_out->nb_side_data);
1646  ret = clone_side_data(&param_out->side_data, &param_out->nb_side_data,
1648  if (ret < 0)
1649  return ret;
1650  param_out->time_base = dp->dec_ctx->pkt_timebase;
1651  }
1652 
1653  return 0;
1654 }
1655 
1656 int dec_init(Decoder **pdec, Scheduler *sch,
1657  AVDictionary **dec_opts, const DecoderOpts *o,
1658  AVFrame *param_out)
1659 {
1660  DecoderPriv *dp;
1661  int ret;
1662 
1663  *pdec = NULL;
1664 
1665  ret = dec_alloc(&dp, sch, !!(o->flags & DECODER_FLAG_SEND_END_TS));
1666  if (ret < 0)
1667  return ret;
1668 
1669  multiview_check_manual(dp, *dec_opts);
1670 
1671  ret = dec_open(dp, dec_opts, o, param_out);
1672  if (ret < 0)
1673  goto fail;
1674 
1675  *pdec = &dp->dec;
1676 
1677  return dp->sch_idx;
1678 fail:
1679  dec_free((Decoder**)&dp);
1680  return ret;
1681 }
1682 
1683 int dec_create(const OptionsContext *o, const char *arg, Scheduler *sch)
1684 {
1685  DecoderPriv *dp;
1686 
1687  OutputFile *of;
1688  OutputStream *ost;
1689  int of_index, ost_index;
1690  char *p;
1691 
1692  unsigned enc_idx;
1693  int ret;
1694 
1695  ret = dec_alloc(&dp, sch, 0);
1696  if (ret < 0)
1697  return ret;
1698 
1699  dp->index = nb_decoders;
1700 
1702  if (ret < 0) {
1703  dec_free((Decoder **)&dp);
1704  return ret;
1705  }
1706 
1707  decoders[nb_decoders - 1] = (Decoder *)dp;
1708 
1709  of_index = strtol(arg, &p, 0);
1710  if (of_index < 0 || of_index >= nb_output_files) {
1711  av_log(dp, AV_LOG_ERROR, "Invalid output file index '%d' in %s\n", of_index, arg);
1712  return AVERROR(EINVAL);
1713  }
1714  of = output_files[of_index];
1715 
1716  ost_index = strtol(p + 1, NULL, 0);
1717  if (ost_index < 0 || ost_index >= of->nb_streams) {
1718  av_log(dp, AV_LOG_ERROR, "Invalid output stream index '%d' in %s\n", ost_index, arg);
1719  return AVERROR(EINVAL);
1720  }
1721  ost = of->streams[ost_index];
1722 
1723  if (!ost->enc) {
1724  av_log(dp, AV_LOG_ERROR, "Output stream %s has no encoder\n", arg);
1725  return AVERROR(EINVAL);
1726  }
1727 
1728  dp->dec.type = ost->type;
1729 
1730  ret = enc_loopback(ost->enc);
1731  if (ret < 0)
1732  return ret;
1733  enc_idx = ret;
1734 
1735  ret = sch_connect(sch, SCH_ENC(enc_idx), SCH_DEC_IN(dp->sch_idx));
1736  if (ret < 0)
1737  return ret;
1738 
1739  ret = av_dict_copy(&dp->standalone_init.opts, o->g->codec_opts, 0);
1740  if (ret < 0)
1741  return ret;
1742 
1744 
1745  if (o->codec_names.nb_opt) {
1746  const char *name = o->codec_names.opt[o->codec_names.nb_opt - 1].u.str;
1748  if (!dp->standalone_init.codec) {
1749  av_log(dp, AV_LOG_ERROR, "No such decoder: %s\n", name);
1751  }
1752  }
1753 
1754  return 0;
1755 }
1756 
1758  const ViewSpecifier *vs, SchedulerNode *src)
1759 {
1760  DecoderPriv *dp = dp_from_dec(d);
1761  char name[16];
1762 
1763  snprintf(name, sizeof(name), "dec%d", dp->index);
1764  opts->name = av_strdup(name);
1765  if (!opts->name)
1766  return AVERROR(ENOMEM);
1767 
1768  return dec_request_view(d, vs, src);
1769 }
AV_OPT_SEARCH_CHILDREN
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:605
DecoderPriv::last_frame_tb
AVRational last_frame_tb
Definition: ffmpeg_dec.c:67
flags
const SwsFlags flags[]
Definition: swscale.c:61
AVSubtitle
Definition: avcodec.h:2090
Decoder::subtitle_header
const uint8_t * subtitle_header
Definition: ffmpeg.h:467
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: packet.c:432
AV_ROUND_UP
@ AV_ROUND_UP
Round toward +infinity.
Definition: mathematics.h:134
FrameData::par_enc
AVCodecParameters * par_enc
Definition: ffmpeg.h:734
AVCodec
AVCodec.
Definition: codec.h:172
copy_av_subtitle
static int copy_av_subtitle(AVSubtitle *dst, const AVSubtitle *src)
Definition: ffmpeg_dec.c:454
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:617
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:678
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:1940
dec_ctx
static AVCodecContext * dec_ctx
Definition: decode_filter_audio.c:45
dec_class
static const AVClass dec_class
Definition: ffmpeg_dec.c:154
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:769
DecoderPriv::views_requested
struct DecoderPriv::@5 * views_requested
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:667
FrameData
Definition: ffmpeg.h:715
AVCodecContext::decoded_side_data
AVFrameSideData ** decoded_side_data
Array containing static side data, such as HDR10 CLL / MDCV structures.
Definition: avcodec.h:1932
check_avoptions
int check_avoptions(AVDictionary *m)
Definition: cmdutils.c:1605
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1032
DecoderPriv::last_frame_duration_est
int64_t last_frame_duration_est
Definition: ffmpeg_dec.c:66
DecoderOpts
Definition: ffmpeg.h:440
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:203
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:435
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:625
LATENCY_PROBE_DEC_POST
@ LATENCY_PROBE_DEC_POST
Definition: ffmpeg.h:102
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:887
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:163
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:2063
AVSubtitle::num_rects
unsigned num_rects
Definition: avcodec.h:2094
hw_device_match_by_codec
static HWDevice * hw_device_match_by_codec(const AVCodec *codec)
Definition: ffmpeg_dec.c:1380
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:565
AVFrame::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: frame.h:689
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:427
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:1002
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:529
AVFrame::width
int width
Definition: frame.h:499
DECODER_FLAG_FRAMERATE_FORCED
@ DECODER_FLAG_FRAMERATE_FORCED
Definition: ffmpeg.h:431
DecoderOpts::par
const AVCodecParameters * par
Definition: ffmpeg.h:447
dec_item_name
static const char * dec_item_name(void *obj)
Definition: ffmpeg_dec.c:147
dec_thread_init
static int dec_thread_init(DecThreadContext *dt)
Definition: ffmpeg_dec.c:895
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:450
DecoderPriv::pkt
AVPacket * pkt
Definition: ffmpeg_dec.c:46
AVCodecContext::subtitle_header
uint8_t * subtitle_header
Definition: avcodec.h:1747
AVSubtitleRect::linesize
int linesize[4]
Definition: avcodec.h:2075
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:129
AVDictionary
Definition: dict.c:32
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
HWDevice
Definition: ffmpeg.h:110
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:126
DECODER_FLAG_BITEXACT
@ DECODER_FLAG_BITEXACT
Definition: ffmpeg.h:437
AVFrame::buf
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:604
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:942
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
AV_FRAME_FLAG_TOP_FIELD_FIRST
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
Definition: frame.h:655
FrameData::frame_num
uint64_t frame_num
Definition: ffmpeg.h:722
OutputFile::nb_streams
int nb_streams
Definition: ffmpeg.h:706
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:559
DecoderOpts::hwaccel_output_format
enum AVPixelFormat hwaccel_output_format
Definition: ffmpeg.h:453
debug_ts
int debug_ts
Definition: ffmpeg_opt.c:70
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:89
AVCodecContext::codec
const struct AVCodec * codec
Definition: avcodec.h:448
AVPacket::opaque_ref
AVBufferRef * opaque_ref
AVBufferRef for free use by the API user.
Definition: packet.h:624
DecoderPriv
Definition: ffmpeg_dec.c:39
OptionsContext::g
OptionGroup * g
Definition: ffmpeg.h:146
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:1047
Decoder::frames_decoded
uint64_t frames_decoded
Definition: ffmpeg.h:471
fail
#define fail()
Definition: checkasm.h:210
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:1318
AVSubtitleRect::x
int x
top left corner of pict, undefined when pict is not set
Definition: avcodec.h:2064
VIEW_SPECIFIER_TYPE_POS
@ VIEW_SPECIFIER_TYPE_POS
Definition: ffmpeg.h:124
DecoderPriv::log_parent
void * log_parent
Definition: ffmpeg_dec.c:80
DecoderOpts::log_parent
void * log_parent
Definition: ffmpeg.h:444
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:496
AVFrame::alpha_mode
enum AVAlphaMode alpha_mode
Indicates how the alpha channel of the video is to be handled.
Definition: frame.h:782
update_benchmark
void update_benchmark(const char *fmt,...)
Definition: ffmpeg.c:550
AVFrame::ch_layout
AVChannelLayout ch_layout
Channel layout of the audio data.
Definition: frame.h:770
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:1092
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:145
av_opt_set
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition: opt.c:835
FrameData::tb
AVRational tb
Definition: ffmpeg.h:725
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:472
AVSubtitleRect::ass
char * ass
0 terminated ASS/SSA compatible event line.
Definition: avcodec.h:2087
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:411
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:1208
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:914
avassert.h
DecThreadContext
Definition: ffmpeg_dec.c:113
DecoderPriv::log_name
char log_name[32]
Definition: ffmpeg_dec.c:81
pkt
AVPacket * pkt
Definition: movenc.c:60
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:1683
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:343
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:642
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:85
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:708
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
Video only.
Definition: codec_par.h:144
subtitle_wrap_frame
static int subtitle_wrap_frame(AVFrame *frame, AVSubtitle *subtitle, int copy)
Definition: ffmpeg_dec.c:541
AVCodecContext::nb_decoded_side_data
int nb_decoded_side_data
Definition: avcodec.h:1933
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:2065
VIEW_SPECIFIER_TYPE_NONE
@ VIEW_SPECIFIER_TYPE_NONE
Definition: ffmpeg.h:118
InputFilter
Definition: ffmpeg.h:366
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:41
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:1561
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:2341
FrameData::dec
struct FrameData::@4 dec
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:2177
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:75
AVSubtitle::pts
int64_t pts
Same as packet pts, in AV_TIME_BASE.
Definition: avcodec.h:2096
DecoderOpts::hwaccel_device
char * hwaccel_device
Definition: ffmpeg.h:452
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:2283
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:613
AVSubtitleRect::text
char * text
0 terminated plain UTF-8 text
Definition: avcodec.h:2080
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:1360
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:385
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
opts
AVDictionary * opts
Definition: movenc.c:51
audio_ts_process
static void audio_ts_process(DecoderPriv *dp, AVFrame *frame)
Definition: ffmpeg_dec.c:246
AVPacket::buf
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: packet.h:571
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:2066
dec_request_view
int dec_request_view(Decoder *d, const ViewSpecifier *vs, SchedulerNode *src)
Definition: ffmpeg_dec.c:1029
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:1396
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:1069
Decoder::decode_errors
uint64_t decode_errors
Definition: ffmpeg.h:473
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:1817
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:677
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:1525
AVCodec::type
enum AVMediaType type
Definition: codec.h:185
Decoder
Definition: ffmpeg.h:462
dec_thread_set_name
static void dec_thread_set_name(const DecoderPriv *dp)
Definition: ffmpeg_dec.c:872
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:639
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:1746
AVSubtitleRect::data
uint8_t * data[4]
data+linesize for the bitmap of this subtitle.
Definition: avcodec.h:2074
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:758
ViewSpecifier::val
unsigned val
Definition: ffmpeg.h:131
FrameData::wallclock
int64_t wallclock[LATENCY_PROBE_NB]
Definition: ffmpeg.h:732
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:2195
AV_OPT_TYPE_UINT
@ AV_OPT_TYPE_UINT
Underlying C type is unsigned int.
Definition: opt.h:335
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:424
InputFilterOptions
Definition: ffmpeg.h:271
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:426
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:705
error.h
Scheduler
Definition: ffmpeg_sched.c:273
avcodec_find_decoder
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: allcodecs.c:1041
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:589
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:1506
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
DecoderPriv::standalone_init
struct DecoderPriv::@7 standalone_init
dec_init
int dec_init(Decoder **pdec, Scheduler *sch, AVDictionary **dec_opts, const DecoderOpts *o, AVFrame *param_out)
Definition: ffmpeg_dec.c:1656
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
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:590
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:1039
AVCodecContext::pkt_timebase
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.
Definition: avcodec.h:550
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:544
AVFrameSideData::data
uint8_t * data
Definition: frame.h:284
HWDevice::device_ref
AVBufferRef * device_ref
Definition: ffmpeg.h:113
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:514
frame_data
FrameData * frame_data(AVFrame *frame)
Get our axiliary frame data attached to the frame, allocating it if needed.
Definition: ffmpeg.c:476
AVSubtitle::end_display_time
uint32_t end_display_time
Definition: avcodec.h:2093
AVSubtitleRect::type
enum AVSubtitleType type
Definition: avcodec.h:2078
LATENCY_PROBE_DEC_PRE
@ LATENCY_PROBE_DEC_PRE
Definition: ffmpeg.h:101
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:587
FrameData::pts
int64_t pts
Definition: ffmpeg.h:724
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:1309
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:2046
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:84
AVSubtitleRect::flags
int flags
Definition: avcodec.h:2077
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:709
video_duration_estimate
static int64_t video_duration_estimate(const DecoderPriv *dp, const AVFrame *frame)
Definition: ffmpeg_dec.c:283
log.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:581
process_subtitle
static int process_subtitle(DecoderPriv *dp, AVFrame *frame)
Definition: ffmpeg_dec.c:574
FrameData::bits_per_raw_sample
int bits_per_raw_sample
Definition: ffmpeg.h:730
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:133
AV_FRAME_FLAG_CORRUPT
#define AV_FRAME_FLAG_CORRUPT
The frame data may be corrupted, e.g.
Definition: frame.h:638
AVSubtitleRect::nb_colors
int nb_colors
number of colors in pict, undefined when pict is not set
Definition: avcodec.h:2068
OptionsContext::codec_names
SpecifierOptList codec_names
Definition: ffmpeg.h:154
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:1962
AV_TIME_BASE
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:253
DecoderPriv::view_map
struct DecoderPriv::@6 * view_map
packet_decode
static int packet_decode(DecoderPriv *dp, AVPacket *pkt, AVFrame *frame)
Definition: ffmpeg_dec.c:697
DecoderOpts::time_base
AVRational time_base
Definition: ffmpeg.h:455
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:71
FRAME_OPAQUE_EOF
@ FRAME_OPAQUE_EOF
Definition: ffmpeg.h:90
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:179
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:1483
AVFrame::side_data
AVFrameSideData ** side_data
Definition: frame.h:624
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:600
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:639
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:937
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:1886
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:2067
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:2265
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:379
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:120
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:481
DECODER_FLAG_TOP_FIELD_FIRST
@ DECODER_FLAG_TOP_FIELD_FIRST
Definition: ffmpeg.h:433
pos
unsigned int pos
Definition: spdifenc.c:414
HWAccelID
HWAccelID
Definition: ffmpeg.h:82
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:524
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:1757
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:439
AVFrame::height
int height
Definition: frame.h:499
DecoderPriv::opts
AVDictionary * opts
Definition: ffmpeg_dec.c:102
PKT_OPAQUE_SUB_HEARTBEAT
@ PKT_OPAQUE_SUB_HEARTBEAT
Definition: ffmpeg.h:95
HWDevice::name
const char * name
Definition: ffmpeg.h:111
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:259
output_format
static char * output_format
Definition: ffprobe.c:144
Decoder::subtitle_header_size
int subtitle_header_size
Definition: ffmpeg.h:468
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:83
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:850
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:449
AVERROR_DECODER_NOT_FOUND
#define AVERROR_DECODER_NOT_FOUND
Decoder not found.
Definition: error.h:54
DecoderOpts::flags
int flags
Definition: ffmpeg.h:441
AVCodecContext::codec_type
enum AVMediaType codec_type
Definition: avcodec.h:447
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:272
desc
const char * desc
Definition: libsvtav1.c:78
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
ViewSpecifier::type
enum ViewSpecifierType type
Definition: ffmpeg.h:130
mem.h
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
SpecifierOpt::u
union SpecifierOpt::@0 u
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:428
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:298
DecoderOpts::codec
const AVCodec * codec
Definition: ffmpeg.h:446
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:282
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:914
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:737
FFMPEG_ERROR_RATE_EXCEEDED
#define FFMPEG_ERROR_RATE_EXCEEDED
Definition: ffmpeg.h:64
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:55
AVPacket
This structure stores compressed data.
Definition: packet.h:565
VIEW_SPECIFIER_TYPE_ID
@ VIEW_SPECIFIER_TYPE_ID
Definition: ffmpeg.h:122
Decoder::class
const AVClass * class
Definition: ffmpeg.h:463
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:112
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:465
packet_data
FrameData * packet_data(AVPacket *pkt)
Definition: ffmpeg.c:488
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:600
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:459
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:330
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:534
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
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:96
DecoderOpts::hwaccel_device_type
enum AVHWDeviceType hwaccel_device_type
Definition: ffmpeg.h:451
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:624
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:632
AVPacket::side_data_elems
int side_data_elems
Definition: packet.h:600
stdbit.h
dec_standalone_open
static int dec_standalone_open(DecoderPriv *dp, const AVPacket *pkt)
Definition: ffmpeg_dec.c:837
OutputFile
Definition: ffmpeg.h:698
ff_thread_setname
static int ff_thread_setname(const char *name)
Definition: thread.h:216
DecoderOpts::name
char * name
Definition: ffmpeg.h:443