FFmpeg
decklink_enc.cpp
Go to the documentation of this file.
1 /*
2  * Blackmagic DeckLink output
3  * Copyright (c) 2013-2014 Ramiro Polla
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include <atomic>
23 using std::atomic;
24 
25 /* Include internal.h first to avoid conflict between winsock.h (used by
26  * DeckLink headers) and winsock2.h (used by libavformat) in MSVC++ builds */
27 extern "C" {
28 #include "libavformat/internal.h"
29 }
30 
31 #include <DeckLinkAPI.h>
32 
33 extern "C" {
34 #include "libavformat/avformat.h"
35 #include "libavutil/imgutils.h"
36 #include "avdevice.h"
37 }
38 
39 #include "decklink_common.h"
40 #include "decklink_enc.h"
41 #if CONFIG_LIBKLVANC
42 #include "libklvanc/vanc.h"
43 #include "libklvanc/vanc-lines.h"
44 #include "libklvanc/pixels.h"
45 #endif
46 
47 /* DeckLink callback class declaration */
48 class decklink_frame : public IDeckLinkVideoFrame
49 {
50 public:
55  virtual long STDMETHODCALLTYPE GetWidth (void) { return _width; }
56  virtual long STDMETHODCALLTYPE GetHeight (void) { return _height; }
57  virtual long STDMETHODCALLTYPE GetRowBytes (void)
58  {
60  return _avframe->linesize[0] < 0 ? -_avframe->linesize[0] : _avframe->linesize[0];
61  else
62  return ((GetWidth() + 47) / 48) * 128;
63  }
64  virtual BMDPixelFormat STDMETHODCALLTYPE GetPixelFormat(void)
65  {
67  return bmdFormat8BitYUV;
68  else
69  return bmdFormat10BitYUV;
70  }
71  virtual BMDFrameFlags STDMETHODCALLTYPE GetFlags (void)
72  {
74  return _avframe->linesize[0] < 0 ? bmdFrameFlagFlipVertical : bmdFrameFlagDefault;
75  else
76  return bmdFrameFlagDefault;
77  }
78 
79  virtual HRESULT STDMETHODCALLTYPE GetBytes (void **buffer)
80  {
82  if (_avframe->linesize[0] < 0)
83  *buffer = (void *)(_avframe->data[0] + _avframe->linesize[0] * (_avframe->height - 1));
84  else
85  *buffer = (void *)(_avframe->data[0]);
86  } else {
87  *buffer = (void *)(_avpacket->data);
88  }
89  return S_OK;
90  }
91 
92  virtual HRESULT STDMETHODCALLTYPE GetTimecode (BMDTimecodeFormat format, IDeckLinkTimecode **timecode) { return S_FALSE; }
93  virtual HRESULT STDMETHODCALLTYPE GetAncillaryData(IDeckLinkVideoFrameAncillary **ancillary)
94  {
95  *ancillary = _ancillary;
96  if (_ancillary) {
97  _ancillary->AddRef();
98  return S_OK;
99  } else {
100  return S_FALSE;
101  }
102  }
103  virtual HRESULT STDMETHODCALLTYPE SetAncillaryData(IDeckLinkVideoFrameAncillary *ancillary)
104  {
105  if (_ancillary)
106  _ancillary->Release();
107  _ancillary = ancillary;
108  _ancillary->AddRef();
109  return S_OK;
110  }
111  virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, LPVOID *ppv) { return E_NOINTERFACE; }
112  virtual ULONG STDMETHODCALLTYPE AddRef(void) { return ++_refs; }
113  virtual ULONG STDMETHODCALLTYPE Release(void)
114  {
115  int ret = --_refs;
116  if (!ret) {
119  if (_ancillary)
120  _ancillary->Release();
121  delete this;
122  }
123  return ret;
124  }
125 
130  IDeckLinkVideoFrameAncillary *_ancillary;
131  int _height;
132  int _width;
133 
134 private:
135  std::atomic<int> _refs;
136 };
137 
138 class decklink_output_callback : public IDeckLinkVideoOutputCallback
139 {
140 public:
141  virtual HRESULT STDMETHODCALLTYPE ScheduledFrameCompleted(IDeckLinkVideoFrame *_frame, BMDOutputFrameCompletionResult result)
142  {
143  decklink_frame *frame = static_cast<decklink_frame *>(_frame);
144  struct decklink_ctx *ctx = frame->_ctx;
145 
146  if (frame->_avframe)
147  av_frame_unref(frame->_avframe);
148  if (frame->_avpacket)
149  av_packet_unref(frame->_avpacket);
150 
151  pthread_mutex_lock(&ctx->mutex);
152  ctx->frames_buffer_available_spots++;
153  pthread_cond_broadcast(&ctx->cond);
154  pthread_mutex_unlock(&ctx->mutex);
155 
156  return S_OK;
157  }
158  virtual HRESULT STDMETHODCALLTYPE ScheduledPlaybackHasStopped(void) { return S_OK; }
159  virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, LPVOID *ppv) { return E_NOINTERFACE; }
160  virtual ULONG STDMETHODCALLTYPE AddRef(void) { return 1; }
161  virtual ULONG STDMETHODCALLTYPE Release(void) { return 1; }
162 };
163 
165 {
166  struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
167  struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
169 
170  if (ctx->video) {
171  av_log(avctx, AV_LOG_ERROR, "Only one video stream is supported!\n");
172  return -1;
173  }
174 
175  if (c->codec_id == AV_CODEC_ID_WRAPPED_AVFRAME) {
176  if (c->format != AV_PIX_FMT_UYVY422) {
177  av_log(avctx, AV_LOG_ERROR, "Unsupported pixel format!"
178  " Only AV_PIX_FMT_UYVY422 is supported.\n");
179  return -1;
180  }
181  ctx->raw_format = bmdFormat8BitYUV;
182  } else if (c->codec_id != AV_CODEC_ID_V210) {
183  av_log(avctx, AV_LOG_ERROR, "Unsupported codec type!"
184  " Only V210 and wrapped frame with AV_PIX_FMT_UYVY422 are supported.\n");
185  return -1;
186  } else {
187  ctx->raw_format = bmdFormat10BitYUV;
188  }
189 
190  if (ff_decklink_set_configs(avctx, DIRECTION_OUT) < 0) {
191  av_log(avctx, AV_LOG_ERROR, "Could not set output configuration\n");
192  return -1;
193  }
194  if (ff_decklink_set_format(avctx, c->width, c->height,
195  st->time_base.num, st->time_base.den, c->field_order)) {
196  av_log(avctx, AV_LOG_ERROR, "Unsupported video size, framerate or field order!"
197  " Check available formats with -list_formats 1.\n");
198  return -1;
199  }
200  if (ctx->supports_vanc && ctx->dlo->EnableVideoOutput(ctx->bmd_mode, bmdVideoOutputVANC) != S_OK) {
201  av_log(avctx, AV_LOG_WARNING, "Could not enable video output with VANC! Trying without...\n");
202  ctx->supports_vanc = 0;
203  }
204  if (!ctx->supports_vanc && ctx->dlo->EnableVideoOutput(ctx->bmd_mode, bmdVideoOutputFlagDefault) != S_OK) {
205  av_log(avctx, AV_LOG_ERROR, "Could not enable video output!\n");
206  return -1;
207  }
208 
209  /* Set callback. */
210  ctx->output_callback = new decklink_output_callback();
211  ctx->dlo->SetScheduledFrameCompletionCallback(ctx->output_callback);
212 
213  ctx->frames_preroll = st->time_base.den * ctx->preroll;
214  if (st->time_base.den > 1000)
215  ctx->frames_preroll /= 1000;
216 
217  /* Buffer twice as many frames as the preroll. */
218  ctx->frames_buffer = ctx->frames_preroll * 2;
219  ctx->frames_buffer = FFMIN(ctx->frames_buffer, 60);
220  pthread_mutex_init(&ctx->mutex, NULL);
221  pthread_cond_init(&ctx->cond, NULL);
222  ctx->frames_buffer_available_spots = ctx->frames_buffer;
223 
224  av_log(avctx, AV_LOG_DEBUG, "output: %s, preroll: %d, frames buffer size: %d\n",
225  avctx->url, ctx->frames_preroll, ctx->frames_buffer);
226 
227  /* The device expects the framerate to be fixed. */
228  avpriv_set_pts_info(st, 64, st->time_base.num, st->time_base.den);
229 
230  ctx->video = 1;
231 
232  return 0;
233 }
234 
236 {
237  struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
238  struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
240 
241  if (ctx->audio) {
242  av_log(avctx, AV_LOG_ERROR, "Only one audio stream is supported!\n");
243  return -1;
244  }
245  if (c->sample_rate != 48000) {
246  av_log(avctx, AV_LOG_ERROR, "Unsupported sample rate!"
247  " Only 48kHz is supported.\n");
248  return -1;
249  }
250  if (c->channels != 2 && c->channels != 8 && c->channels != 16) {
251  av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels!"
252  " Only 2, 8 or 16 channels are supported.\n");
253  return -1;
254  }
255  if (ctx->dlo->EnableAudioOutput(bmdAudioSampleRate48kHz,
256  bmdAudioSampleType16bitInteger,
257  c->channels,
258  bmdAudioOutputStreamTimestamped) != S_OK) {
259  av_log(avctx, AV_LOG_ERROR, "Could not enable audio output!\n");
260  return -1;
261  }
262  if (ctx->dlo->BeginAudioPreroll() != S_OK) {
263  av_log(avctx, AV_LOG_ERROR, "Could not begin audio preroll!\n");
264  return -1;
265  }
266 
267  /* The device expects the sample rate to be fixed. */
268  avpriv_set_pts_info(st, 64, 1, c->sample_rate);
269  ctx->channels = c->channels;
270 
271  ctx->audio = 1;
272 
273  return 0;
274 }
275 
277 {
278  struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
279  struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
280 
281  if (ctx->playback_started) {
282  BMDTimeValue actual;
283  ctx->dlo->StopScheduledPlayback(ctx->last_pts * ctx->bmd_tb_num,
284  &actual, ctx->bmd_tb_den);
285  ctx->dlo->DisableVideoOutput();
286  if (ctx->audio)
287  ctx->dlo->DisableAudioOutput();
288  }
289 
290  ff_decklink_cleanup(avctx);
291 
292  if (ctx->output_callback)
293  delete ctx->output_callback;
294 
295  pthread_mutex_destroy(&ctx->mutex);
296  pthread_cond_destroy(&ctx->cond);
297 
298 #if CONFIG_LIBKLVANC
299  klvanc_context_destroy(ctx->vanc_ctx);
300 #endif
301 
302  av_freep(&cctx->ctx);
303 
304  return 0;
305 }
306 
307 #if CONFIG_LIBKLVANC
308 static void construct_cc(AVFormatContext *avctx, struct decklink_ctx *ctx,
309  AVPacket *pkt, struct klvanc_line_set_s *vanc_lines)
310 {
311  struct klvanc_packet_eia_708b_s *cdp;
312  uint16_t *cdp_words;
313  uint16_t len;
314  uint8_t cc_count;
315  int size, ret, i;
316 
318  if (!data)
319  return;
320 
321  cc_count = size / 3;
322 
323  ret = klvanc_create_eia708_cdp(&cdp);
324  if (ret)
325  return;
326 
327  ret = klvanc_set_framerate_EIA_708B(cdp, ctx->bmd_tb_num, ctx->bmd_tb_den);
328  if (ret) {
329  av_log(avctx, AV_LOG_ERROR, "Invalid framerate specified: %lld/%lld\n",
330  ctx->bmd_tb_num, ctx->bmd_tb_den);
331  klvanc_destroy_eia708_cdp(cdp);
332  return;
333  }
334 
335  if (cc_count > KLVANC_MAX_CC_COUNT) {
336  av_log(avctx, AV_LOG_ERROR, "Illegal cc_count received: %d\n", cc_count);
337  cc_count = KLVANC_MAX_CC_COUNT;
338  }
339 
340  /* CC data */
341  cdp->header.ccdata_present = 1;
342  cdp->header.caption_service_active = 1;
343  cdp->ccdata.cc_count = cc_count;
344  for (i = 0; i < cc_count; i++) {
345  if (data [3*i] & 0x04)
346  cdp->ccdata.cc[i].cc_valid = 1;
347  cdp->ccdata.cc[i].cc_type = data[3*i] & 0x03;
348  cdp->ccdata.cc[i].cc_data[0] = data[3*i+1];
349  cdp->ccdata.cc[i].cc_data[1] = data[3*i+2];
350  }
351 
352  klvanc_finalize_EIA_708B(cdp, ctx->cdp_sequence_num++);
353  ret = klvanc_convert_EIA_708B_to_words(cdp, &cdp_words, &len);
354  klvanc_destroy_eia708_cdp(cdp);
355  if (ret != 0) {
356  av_log(avctx, AV_LOG_ERROR, "Failed converting 708 packet to words\n");
357  return;
358  }
359 
360  ret = klvanc_line_insert(ctx->vanc_ctx, vanc_lines, cdp_words, len, 11, 0);
361  free(cdp_words);
362  if (ret != 0) {
363  av_log(avctx, AV_LOG_ERROR, "VANC line insertion failed\n");
364  return;
365  }
366 }
367 
368 static int decklink_construct_vanc(AVFormatContext *avctx, struct decklink_ctx *ctx,
370 {
371  struct klvanc_line_set_s vanc_lines = { 0 };
372  int ret = 0, i;
373 
374  if (!ctx->supports_vanc)
375  return 0;
376 
377  construct_cc(avctx, ctx, pkt, &vanc_lines);
378 
379  IDeckLinkVideoFrameAncillary *vanc;
380  int result = ctx->dlo->CreateAncillaryData(bmdFormat10BitYUV, &vanc);
381  if (result != S_OK) {
382  av_log(avctx, AV_LOG_ERROR, "Failed to create vanc\n");
383  ret = AVERROR(EIO);
384  goto done;
385  }
386 
387  /* Now that we've got all the VANC lines in a nice orderly manner, generate the
388  final VANC sections for the Decklink output */
389  for (i = 0; i < vanc_lines.num_lines; i++) {
390  struct klvanc_line_s *line = vanc_lines.lines[i];
391  int real_line;
392  void *buf;
393 
394  if (!line)
395  break;
396 
397  /* FIXME: include hack for certain Decklink cards which mis-represent
398  line numbers for pSF frames */
399  real_line = line->line_number;
400 
401  result = vanc->GetBufferForVerticalBlankingLine(real_line, &buf);
402  if (result != S_OK) {
403  av_log(avctx, AV_LOG_ERROR, "Failed to get VANC line %d: %d", real_line, result);
404  continue;
405  }
406 
407  /* Generate the full line taking into account all VANC packets on that line */
408  result = klvanc_generate_vanc_line_v210(ctx->vanc_ctx, line, (uint8_t *) buf,
409  ctx->bmd_width);
410  if (result) {
411  av_log(avctx, AV_LOG_ERROR, "Failed to generate VANC line\n");
412  continue;
413  }
414  }
415 
416  result = frame->SetAncillaryData(vanc);
417  vanc->Release();
418  if (result != S_OK) {
419  av_log(avctx, AV_LOG_ERROR, "Failed to set vanc: %d", result);
420  ret = AVERROR(EIO);
421  }
422 
423 done:
424  for (i = 0; i < vanc_lines.num_lines; i++)
425  klvanc_line_free(vanc_lines.lines[i]);
426 
427  return ret;
428 }
429 #endif
430 
432 {
433  struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
434  struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
435  AVStream *st = avctx->streams[pkt->stream_index];
436  AVFrame *avframe = NULL, *tmp = (AVFrame *)pkt->data;
437  AVPacket *avpacket = NULL;
439  buffercount_type buffered;
440  HRESULT hr;
441 
443  if (tmp->format != AV_PIX_FMT_UYVY422 ||
444  tmp->width != ctx->bmd_width ||
445  tmp->height != ctx->bmd_height) {
446  av_log(avctx, AV_LOG_ERROR, "Got a frame with invalid pixel format or dimension.\n");
447  return AVERROR(EINVAL);
448  }
449 
450  avframe = av_frame_clone(tmp);
451  if (!avframe) {
452  av_log(avctx, AV_LOG_ERROR, "Could not clone video frame.\n");
453  return AVERROR(EIO);
454  }
455 
456  frame = new decklink_frame(ctx, avframe, st->codecpar->codec_id, avframe->height, avframe->width);
457  } else {
458  avpacket = av_packet_clone(pkt);
459  if (!avpacket) {
460  av_log(avctx, AV_LOG_ERROR, "Could not clone video frame.\n");
461  return AVERROR(EIO);
462  }
463 
464  frame = new decklink_frame(ctx, avpacket, st->codecpar->codec_id, ctx->bmd_height, ctx->bmd_width);
465 
466 #if CONFIG_LIBKLVANC
467  if (decklink_construct_vanc(avctx, ctx, pkt, frame))
468  av_log(avctx, AV_LOG_ERROR, "Failed to construct VANC\n");
469 #endif
470  }
471 
472  if (!frame) {
473  av_log(avctx, AV_LOG_ERROR, "Could not create new frame.\n");
474  av_frame_free(&avframe);
475  av_packet_free(&avpacket);
476  return AVERROR(EIO);
477  }
478 
479  /* Always keep at most one second of frames buffered. */
480  pthread_mutex_lock(&ctx->mutex);
481  while (ctx->frames_buffer_available_spots == 0) {
482  pthread_cond_wait(&ctx->cond, &ctx->mutex);
483  }
484  ctx->frames_buffer_available_spots--;
485  pthread_mutex_unlock(&ctx->mutex);
486 
487  /* Schedule frame for playback. */
488  hr = ctx->dlo->ScheduleVideoFrame((class IDeckLinkVideoFrame *) frame,
489  pkt->pts * ctx->bmd_tb_num,
490  ctx->bmd_tb_num, ctx->bmd_tb_den);
491  /* Pass ownership to DeckLink, or release on failure */
492  frame->Release();
493  if (hr != S_OK) {
494  av_log(avctx, AV_LOG_ERROR, "Could not schedule video frame."
495  " error %08x.\n", (uint32_t) hr);
496  return AVERROR(EIO);
497  }
498 
499  ctx->dlo->GetBufferedVideoFrameCount(&buffered);
500  av_log(avctx, AV_LOG_DEBUG, "Buffered video frames: %d.\n", (int) buffered);
501  if (pkt->pts > 2 && buffered <= 2)
502  av_log(avctx, AV_LOG_WARNING, "There are not enough buffered video frames."
503  " Video may misbehave!\n");
504 
505  /* Preroll video frames. */
506  if (!ctx->playback_started && pkt->pts > ctx->frames_preroll) {
507  av_log(avctx, AV_LOG_DEBUG, "Ending audio preroll.\n");
508  if (ctx->audio && ctx->dlo->EndAudioPreroll() != S_OK) {
509  av_log(avctx, AV_LOG_ERROR, "Could not end audio preroll!\n");
510  return AVERROR(EIO);
511  }
512  av_log(avctx, AV_LOG_DEBUG, "Starting scheduled playback.\n");
513  if (ctx->dlo->StartScheduledPlayback(0, ctx->bmd_tb_den, 1.0) != S_OK) {
514  av_log(avctx, AV_LOG_ERROR, "Could not start scheduled playback!\n");
515  return AVERROR(EIO);
516  }
517  ctx->playback_started = 1;
518  }
519 
520  return 0;
521 }
522 
524 {
525  struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
526  struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
527  int sample_count = pkt->size / (ctx->channels << 1);
528  buffercount_type buffered;
529 
530  ctx->dlo->GetBufferedAudioSampleFrameCount(&buffered);
531  if (pkt->pts > 1 && !buffered)
532  av_log(avctx, AV_LOG_WARNING, "There's no buffered audio."
533  " Audio will misbehave!\n");
534 
535  if (ctx->dlo->ScheduleAudioSamples(pkt->data, sample_count, pkt->pts,
536  bmdAudioSampleRate48kHz, NULL) != S_OK) {
537  av_log(avctx, AV_LOG_ERROR, "Could not schedule audio samples.\n");
538  return AVERROR(EIO);
539  }
540 
541  return 0;
542 }
543 
544 extern "C" {
545 
547 {
548  struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
549  struct decklink_ctx *ctx;
550  unsigned int n;
551  int ret;
552 
553  ctx = (struct decklink_ctx *) av_mallocz(sizeof(struct decklink_ctx));
554  if (!ctx)
555  return AVERROR(ENOMEM);
556  ctx->list_devices = cctx->list_devices;
557  ctx->list_formats = cctx->list_formats;
558  ctx->preroll = cctx->preroll;
559  ctx->duplex_mode = cctx->duplex_mode;
560  cctx->ctx = ctx;
561 #if CONFIG_LIBKLVANC
562  if (klvanc_context_create(&ctx->vanc_ctx) < 0) {
563  av_log(avctx, AV_LOG_ERROR, "Cannot create VANC library context\n");
564  return AVERROR(ENOMEM);
565  }
566  ctx->supports_vanc = 1;
567 #endif
568 
569  /* List available devices and exit. */
570  if (ctx->list_devices) {
571  ff_decklink_list_devices_legacy(avctx, 0, 1);
572  return AVERROR_EXIT;
573  }
574 
575  ret = ff_decklink_init_device(avctx, avctx->url);
576  if (ret < 0)
577  return ret;
578 
579  /* Get output device. */
580  if (ctx->dl->QueryInterface(IID_IDeckLinkOutput, (void **) &ctx->dlo) != S_OK) {
581  av_log(avctx, AV_LOG_ERROR, "Could not open output device from '%s'\n",
582  avctx->url);
583  ret = AVERROR(EIO);
584  goto error;
585  }
586 
587  /* List supported formats. */
588  if (ctx->list_formats) {
590  ret = AVERROR_EXIT;
591  goto error;
592  }
593 
594  /* Setup streams. */
595  ret = AVERROR(EIO);
596  for (n = 0; n < avctx->nb_streams; n++) {
597  AVStream *st = avctx->streams[n];
599  if (c->codec_type == AVMEDIA_TYPE_AUDIO) {
600  if (decklink_setup_audio(avctx, st))
601  goto error;
602  } else if (c->codec_type == AVMEDIA_TYPE_VIDEO) {
603  if (decklink_setup_video(avctx, st))
604  goto error;
605  } else {
606  av_log(avctx, AV_LOG_ERROR, "Unsupported stream type.\n");
607  goto error;
608  }
609  }
610 
611  return 0;
612 
613 error:
614  ff_decklink_cleanup(avctx);
615  return ret;
616 }
617 
619 {
620  struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
621  struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
622  AVStream *st = avctx->streams[pkt->stream_index];
623 
624  ctx->last_pts = FFMAX(ctx->last_pts, pkt->pts);
625 
627  return decklink_write_video_packet(avctx, pkt);
628  else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
629  return decklink_write_audio_packet(avctx, pkt);
630 
631  return AVERROR(EIO);
632 }
633 
635 {
636  return ff_decklink_list_devices(avctx, device_list, 0, 1);
637 }
638 
639 } /* extern "C" */
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:599
LPVOID
void * LPVOID
Definition: basicDataTypeConversions.h:19
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
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
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3953
codec_id
enum AVCodecID codec_id
Definition: qsv.c:72
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: avcodec.h:3949
n
int n
Definition: avisynth_c.h:760
pthread_mutex_init
static av_always_inline int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
Definition: os2threads.h:100
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:202
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:295
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:26
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1410
AVFrame::width
int width
Definition: frame.h:353
AVPacket::data
uint8_t * data
Definition: avcodec.h:1477
data
const char data[16]
Definition: mxf.c:91
ULONG
uint32_t ULONG
Definition: basicDataTypeConversions.h:60
E_NOINTERFACE
#define E_NOINTERFACE
Definition: windows2linux.h:42
av_packet_free
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: avpacket.c:62
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:309
S_OK
#define S_OK
Definition: windows2linux.h:40
REFIID
GUID REFIID
Definition: basicDataTypeConversions.h:77
AVRational::num
int num
Numerator.
Definition: rational.h:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
buf
void * buf
Definition: avisynth_c.h:766
av_cold
#define av_cold
Definition: attributes.h:84
width
#define width
format
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 format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
ctx
AVFormatContext * ctx
Definition: movenc.c:48
av_frame_clone
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:540
AV_CODEC_ID_WRAPPED_AVFRAME
@ AV_CODEC_ID_WRAPPED_AVFRAME
Passthrough codec, AVFrames wrapped in AVPacket.
Definition: avcodec.h:708
pthread_cond_broadcast
static av_always_inline int pthread_cond_broadcast(pthread_cond_t *cond)
Definition: os2threads.h:158
av_packet_get_side_data
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, int *size)
Get side information from packet.
Definition: avpacket.c:350
if
if(ret)
Definition: filter_design.txt:179
AVFormatContext
Format I/O context.
Definition: avformat.h:1342
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1017
result
and forward the result(frame or status change) to the corresponding input. If nothing is possible
AVStream::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avformat.h:899
NULL
#define NULL
Definition: coverity.c:32
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
pthread_mutex_unlock
#define pthread_mutex_unlock(a)
Definition: ffprobe.c:65
error
static void error(const char *err)
Definition: target_dec_fuzzer.c:61
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:215
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1398
AVPacket::size
int size
Definition: avcodec.h:1478
FFMAX
#define FFMAX(a, b)
Definition: common.h:94
avpriv_set_pts_info
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: utils.c:4910
AVFormatContext::url
char * url
input or output URL.
Definition: avformat.h:1438
size
int size
Definition: twinvq_data.h:11134
AV_CODEC_ID_V210
@ AV_CODEC_ID_V210
Definition: avcodec.h:345
avdevice.h
height
#define height
FFMIN
#define FFMIN(a, b)
Definition: common.h:96
line
Definition: graph2dot.c:48
HRESULT
DWORD HRESULT
Definition: basicDataTypeConversions.h:54
pthread_cond_destroy
static av_always_inline int pthread_cond_destroy(pthread_cond_t *cond)
Definition: os2threads.h:140
pthread_mutex_destroy
static av_always_inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
Definition: os2threads.h:108
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1470
AV_PKT_DATA_A53_CC
@ AV_PKT_DATA_A53_CC
ATSC A53 Part 4 Closed Captions.
Definition: avcodec.h:1386
uint8_t
uint8_t
Definition: audio_convert.c:194
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:553
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:236
len
int len
Definition: vorbis_enc_data.h:452
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:870
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:264
AVDeviceInfoList
List of devices.
Definition: avdevice.h:460
avformat.h
AV_PIX_FMT_UYVY422
@ AV_PIX_FMT_UYVY422
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:81
AVFrame::height
int height
Definition: frame.h:353
pkt
static AVPacket pkt
Definition: demuxing_decoding.c:54
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
AVRational::den
int den
Denominator.
Definition: rational.h:60
S_FALSE
#define S_FALSE
Definition: windows2linux.h:41
AVPacket::stream_index
int stream_index
Definition: avcodec.h:1479
pthread_cond_wait
static av_always_inline int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
Definition: os2threads.h:166
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3957
AVPacket
This structure stores compressed data.
Definition: avcodec.h:1454
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
imgutils.h
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:326
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
pthread_cond_init
static av_always_inline int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
Definition: os2threads.h:129
AVERROR_EXIT
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
Definition: error.h:56
AVFormatContext::priv_data
void * priv_data
Format private data.
Definition: avformat.h:1370
av_packet_clone
AVPacket * av_packet_clone(const AVPacket *src)
Create a new packet that references the same data as src.
Definition: avpacket.c:642
pthread_mutex_lock
#define pthread_mutex_lock(a)
Definition: ffprobe.c:61