1 /*
2 * Blackmagic DeckLink input
3 * Copyright (c) 2013-2014 Luca Barbato, Deti Fliegl
4 * Copyright (c) 2014 Rafaël Carré
5 * Copyright (c) 2017 Akamai Technologies, Inc.
6 *
7 * This file is part of FFmpeg.
8 *
9 * FFmpeg is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * FFmpeg is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with FFmpeg; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 #include <atomic>
25 #include <vector>
26 using std::atomic;
27
28 /* Include internal.h first to avoid conflict between winsock.h (used by
29 * DeckLink headers) and winsock2.h (used by libavformat) in MSVC++ builds */
30 extern "C" {
32 }
33
34 #include <DeckLinkAPI.h>
35
36 extern "C" {
37 #include "config.h"
51 #if CONFIG_LIBZVBI
52 #include <libzvbi.h>
53 #endif
54 }
55
58
59 #define MAX_WIDTH_VANC 1920
61
69
70 /* These VANC line numbers need not be very accurate. In any case
71 * GetBufferForVerticalBlankingLine() will return an error when invalid
72 * ancillary line number was requested. We just need to make sure that the
73 * entire VANC region is covered, while making sure we don't decode VANC of
74 * another source during switching*/
76 /* SD Modes */
77
78 {bmdModeNTSC, 11, 19, 274, 282},
79 {bmdModeNTSC2398, 11, 19, 274, 282},
80 {bmdModePAL, 7, 22, 320, 335},
81 {bmdModeNTSCp, 11, -1, -1, 39},
82 {bmdModePALp, 7, -1, -1, 45},
83
84 /* HD 1080 Modes */
85
86 {bmdModeHD1080p2398, 8, -1, -1, 42},
87 {bmdModeHD1080p24, 8, -1, -1, 42},
88 {bmdModeHD1080p25, 8, -1, -1, 42},
89 {bmdModeHD1080p2997, 8, -1, -1, 42},
90 {bmdModeHD1080p30, 8, -1, -1, 42},
91 {bmdModeHD1080i50, 8, 20, 570, 585},
92 {bmdModeHD1080i5994, 8, 20, 570, 585},
93 {bmdModeHD1080i6000, 8, 20, 570, 585},
94 {bmdModeHD1080p50, 8, -1, -1, 42},
95 {bmdModeHD1080p5994, 8, -1, -1, 42},
96 {bmdModeHD1080p6000, 8, -1, -1, 42},
97
98 /* HD 720 Modes */
99
100 {bmdModeHD720p50, 8, -1, -1, 26},
101 {bmdModeHD720p5994, 8, -1, -1, 26},
102 {bmdModeHD720p60, 8, -1, -1, 26},
103
104 /* For all other modes, for which we don't support VANC */
105 {bmdModeUnknown, 0, -1, -1, -1}
106 };
107
109 {
110 public:
113
114 // IDeckLinkMemoryAllocator methods
115 virtual HRESULT STDMETHODCALLTYPE
AllocateBuffer(
unsigned int bufferSize,
void* *allocatedBuffer)
116 {
118 if (!buf)
119 return E_OUTOFMEMORY;
120 *allocatedBuffer = buf;
121 return S_OK;
122 }
124 {
126 return S_OK;
127 }
128 virtual HRESULT STDMETHODCALLTYPE
Commit() {
return S_OK; }
129 virtual HRESULT STDMETHODCALLTYPE
Decommit() {
return S_OK; }
130
131 // IUnknown methods
132 virtual HRESULT STDMETHODCALLTYPE
QueryInterface(REFIID iid, LPVOID *ppv) {
return E_NOINTERFACE; }
135 {
138 delete this;
140 }
141
142 private:
144 };
145
146 extern "C" {
148 {
149 IUnknown *obj = (class IUnknown *)opaque;
150 obj->Release();
151 }
152 }
153
155 {
160 }
161 /* Return the VANC idx for Unknown mode */
163 }
164
169 }
170
173 uint16_t vanc_sum = 0;
174 for (
i = 3;
i <
len - 1;
i++) {
176 int np = v >> 8;
178 if ((!!
p ^ !!(v & 0x100)) || (np != 1 && np != 2)) {
179 // Parity check failed
180 return -1;
181 }
182 vanc_sum += v;
183 }
184 vanc_sum &= 0x1ff;
185 vanc_sum |= ((~vanc_sum & 0x100) << 1);
186 if (checksum != vanc_sum) {
187 // Checksum verification failed
188 return -1;
189 }
190 return 0;
191 }
192
193 /* The 10-bit VANC data is packed in V210, we only need the luma component. */
195 {
198 *
dst++ = (
src[1] >> 2) + ((
src[2] & 15) << 6);
200 *
dst++ = (
src[6] >> 4) + ((
src[7] & 63) << 4);
202 }
203 }
204
206 {
208 for (
i = 0;
i <
width * 2 / 3;
i++) {
210 *
dst++ = (
src[1] >> 2) + ((
src[2] & 15) << 6);
211 *
dst++ = (
src[2] >> 4) + ((
src[3] & 63) << 4);
213 }
214 }
215
217 {
218 uint8_t
ret = (
line < 313) << 5;
224 }
225
227 {
228 tgt[0] = 0x02; // data_unit_id
229 tgt[1] = 0x2c; // data_unit_length
231 tgt[3] = 0xe4; // framing code
232 }
233
234 #if CONFIG_LIBZVBI
235 static uint8_t* teletext_data_unit_from_vbi_data(
int line, uint8_t *
src, uint8_t *tgt, vbi_pixfmt fmt)
236 {
237 vbi_bit_slicer slicer;
238
239 vbi_bit_slicer_init(&slicer, 720, 13500000, 6937500, 6937500, 0x00aaaae4, 0xffff, 18, 6, 42 * 8, VBI_MODULATION_NRZ_MSB, fmt);
240
241 if (vbi_bit_slice(&slicer,
src, tgt + 4) == FALSE)
242 return tgt;
243
245
246 return tgt + 46;
247 }
248
249 static uint8_t* teletext_data_unit_from_vbi_data_10bit(
int line, uint8_t *
src, uint8_t *tgt)
250 {
251 uint8_t y[720];
252 uint8_t *py = y;
253 uint8_t *pend = y + 720;
254 /* The 10-bit VBI data is packed in V210, but libzvbi only supports 8-bit,
255 * so we extract the 8 MSBs of the luma component, that is enough for
256 * teletext bit slicing. */
257 while (py < pend) {
258 *py++ = (
src[1] >> 4) + ((
src[2] & 15) << 4);
259 *py++ = (
src[4] >> 2) + ((
src[5] & 3 ) << 6);
260 *py++ = (
src[6] >> 6) + ((
src[7] & 63) << 2);
262 }
263 return teletext_data_unit_from_vbi_data(
line, y, tgt, VBI_PIXFMT_YUV420);
264 }
265 #endif
266
268 {
270
271 if (py[0] != 0x255 || py[1] != 0x255 || py[2] != 0x227)
272 return tgt;
273
275
276 py += 3;
277 tgt += 4;
278
279 for (
i = 0;
i < 42;
i++)
281
282 return tgt;
283 }
284
286 {
293 }
294
296 {
297 if (py < pend - 9) {
298 if (py[0] == 0x151 && py[1] == 0x115 && py[3] == 0x102) { // identifier, identifier, format code for WST teletext
299 uint16_t *descriptors = py + 4;
301 py += 9;
302 for (
i = 0;
i < 5 && py < pend - 45;
i++, py += 45) {
303 int line = (descriptors[
i] & 31) + (!(descriptors[
i] & 128)) * 313;
306 }
307 }
308 }
309 return tgt;
310 }
311
313 {
314 uint16_t did = py[0]; // data id
315 uint16_t sdid = py[1]; // secondary data id
316 uint16_t
dc = py[2] & 255;
// data count
317 py += 3;
319 if (did == 0x143 && sdid == 0x102) { // subtitle distribution packet
321 } else if (allow_multipacket && did == 0x143 && sdid == 0x203) { // VANC multipacket
322 py += 2; // priority, line/field
323 while (py < pend - 3) {
325 py += 4 + (py[2] & 255); // ndid, nsdid, ndc, line/field
326 }
327 }
328 return tgt;
329 }
330
332 unsigned &cc_count)
333 {
334 size_t i,
len = (buf[5] & 0xff) + 6 + 1;
335 uint8_t cdp_sum, rate;
336 uint16_t hdr, ftr;
337 uint8_t *cc;
338 uint16_t *cdp = &buf[6]; // CDP follows
339 if (cdp[0] != 0x96 || cdp[1] != 0x69) {
342 }
343
344 len -= 7;
// remove VANC header and checksum
345
349 }
350
351 cdp_sum = 0;
352 for (
i = 0;
i <
len - 1;
i++)
354 cdp_sum = cdp_sum ? 256 - cdp_sum : 0;
355 if (cdp[
len - 1] != cdp_sum) {
358 }
359
360 rate = cdp[3];
361 if (!(rate & 0x0f)) {
364 }
365 rate >>= 4;
366 if (rate > 8) {
369 }
370
371 if (!(cdp[4] & 0x43)) /* ccdata_present | caption_service_active | reserved */ {
374 }
375
376 hdr = (cdp[5] << 8) | cdp[6];
377 if (cdp[7] != 0x72) /* ccdata_id */ {
380 }
381
382 cc_count = cdp[8];
383 if (!(cc_count & 0xe0)) {
386 }
387
388 cc_count &= 0x1f;
389 if ((
len - 13) < cc_count * 3) {
392 }
393
394 if (cdp[
len - 4] != 0x74)
/* footer id */ {
397 }
398
399 ftr = (cdp[
len - 3] << 8) | cdp[
len - 2];
400 if (ftr != hdr) {
403 }
404
409 }
410
411 for (
size_t i = 0;
i < cc_count;
i++) {
412 cc[3*
i + 0] = cdp[9 + 3*
i+0]
/* & 3 */;
413 cc[3*
i + 1] = cdp[9 + 3*
i+1];
414 cc[3*
i + 2] = cdp[9 + 3*
i+2];
415 }
416
417 cc_count *= 3;
418 return cc;
419 }
420
423 {
425 uint16_t *max_buf = buf +
width;
426
427 while (buf < max_buf - 6) {
429 uint16_t did = buf[3] & 0xFF; // data id
430 uint16_t sdid = buf[4] & 0xFF; // secondary data id
431 /* Check for VANC header */
432 if (buf[0] != 0 || buf[1] != 0x3ff || buf[2] != 0x3ff) {
433 return tgt;
434 }
435
436 len = (buf[5] & 0xff) + 6 + 1;
437 if (
len > max_buf - buf) {
440 return tgt;
441 }
442
443 if (did == 0x43 && (sdid == 0x02 || sdid == 0x03) && cctx->
teletext_lines &&
444 width == 1920 && tgt_size >= 1920) {
447 goto skip_packet;
448 }
450 } else if (did == 0x61 && sdid == 0x01) {
451 unsigned int data_len;
455 goto skip_packet;
456 }
462 }
463 } else {
465 did, sdid);
466 }
467 skip_packet:
469 }
470
471 return tgt;
472 }
473
474
476 {
477 const uint8_t KLV_DID = 0x44;
478 const uint8_t KLV_IN_VANC_SDID = 0x04;
479
481 {
482 uint16_t sequence_counter;
483 std::vector<uint8_t>
data;
484 };
485
486 size_t total_size = 0;
487 std::vector<std::vector<KLVPacket>> klv_packets(256);
488
489 IDeckLinkVideoFrameAncillaryPackets *packets = nullptr;
490 if (videoFrame->QueryInterface(IID_IDeckLinkVideoFrameAncillaryPackets, (void**)&packets) != S_OK)
491 return;
492
493 IDeckLinkAncillaryPacketIterator *
it =
nullptr;
494 if (packets->GetPacketIterator(&
it) != S_OK) {
495 packets->Release();
496 return;
497 }
498
499 IDeckLinkAncillaryPacket *packet = nullptr;
500 while (
it->Next(&packet) == S_OK) {
501 uint8_t *
data =
nullptr;
503
504 if (packet->GetDID() == KLV_DID && packet->GetSDID() == KLV_IN_VANC_SDID) {
505 av_log(avctx,
AV_LOG_DEBUG,
"Found KLV VANC packet on line: %d\n", packet->GetLineNumber());
506
507 if (packet->GetBytes(bmdAncillaryPacketFormatUInt8, (
const void**) &
data, &
size) == S_OK) {
508 // MID and PSC
510 uint8_t mid =
data[0];
511 uint16_t psc =
data[1] << 8 |
data[2];
512
514
515 auto&
list = klv_packets[mid];
516 uint16_t expected_psc =
list.size() + 1;
517
518 if (psc == expected_psc) {
519 uint32_t data_len =
size - 3;
520 total_size += data_len;
521
523 packet.data.resize(data_len);
524 memcpy(packet.data.data(),
data + 3, data_len);
525
526 list.push_back(std::move(packet));
527 } else {
529
531 for (
auto& klv :
list)
532 total_size -= klv.data.size();
533
535 }
536 }
537 }
538 }
539 }
540
541 packet->Release();
542 }
543
545 packets->Release();
546
547 if (total_size > 0) {
548 std::vector<uint8_t> klv;
549 klv.reserve(total_size);
550
551 for (
size_t i = 0;
i < klv_packets.size(); ++
i) {
552 auto&
list = klv_packets[
i];
553
555 continue;
556
558
559 for (
auto& packet :
list)
560 klv.insert(klv.end(), packet.data.begin(), packet.data.end());
561 }
562
568 klv_packet.
data = klv.data();
569 klv_packet.
size = klv.size();
570
573 }
574 }
575 }
576
578 {
579 public:
582
583 virtual HRESULT STDMETHODCALLTYPE
QueryInterface(REFIID iid, LPVOID *ppv) {
return E_NOINTERFACE; }
584 virtual ULONG STDMETHODCALLTYPE
AddRef(
void);
585 virtual ULONG STDMETHODCALLTYPE
Release(
void);
586 virtual HRESULT STDMETHODCALLTYPE
VideoInputFormatChanged(BMDVideoInputFormatChangedEvents, IDeckLinkDisplayMode*, BMDDetectedVideoInputFormatFlags);
587 virtual HRESULT STDMETHODCALLTYPE
VideoInputFrameArrived(IDeckLinkVideoInputFrame*, IDeckLinkAudioInputPacket*);
588
589 private:
597 };
598
600 {
607 }
608
610 {
613 }
614
616 {
618 }
619
621 {
624 delete this;
626 }
627
629 IDeckLinkAudioInputPacket *audioFrame,
635 {
637 BMDTimeValue bmd_pts;
638 BMDTimeValue bmd_duration;
639 HRESULT res = E_INVALIDARG;
640 switch (pts_src) {
642 if (audioFrame)
643 res = audioFrame->GetPacketTime(&bmd_pts, time_base.
den);
644 break;
646 if (videoFrame)
647 res = videoFrame->GetStreamTime(&bmd_pts, &bmd_duration, time_base.
den);
648 break;
650 if (videoFrame)
651 res = videoFrame->GetHardwareReferenceTimestamp(time_base.
den, &bmd_pts, &bmd_duration);
652 break;
654 /* fall through */
656 {
657 /* MSVC does not support compound literals like AV_TIME_BASE_Q
658 * in C++ code (compiler error C4576) */
664 else
666 break;
667 }
668 }
669 if (res == S_OK)
670 pts = bmd_pts / time_base.
num;
671
677 }
678
680 }
681
683 {
684 IDeckLinkTimecode *timecode;
686 #if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b000000
687 int hfr = (
tc_format == bmdTimecodeRP188HighFrameRate);
688 #else
689 int hfr = 0;
690 #endif
691 if (videoFrame->GetTimecode(
tc_format, &timecode) == S_OK) {
692 uint8_t hh, mm,
ss, ff;
693 if (timecode->GetComponents(&hh, &mm, &
ss, &ff) == S_OK) {
696 ff = ff << 1 | !!(timecode->GetFlags() & bmdTimecodeFieldMark);
698 }
699 timecode->Release();
700 }
702 }
703
705 {
708 /* 50/60 fps content has alternating VITC1 and VITC2 timecode (see SMPTE ST
709 * 12-2, section 7), so the native ordering of RP188Any (HFR, VITC1, LTC,
710 * VITC2) would not work because LTC might not contain the field flag.
711 * Therefore we query the types manually. */
713 #if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b000000
716 #endif
722 } else {
724 }
726 }
727
729 IDeckLinkVideoInputFrame *videoFrame, IDeckLinkAudioInputPacket *audioFrame)
730 {
731 void *frameBytes;
732 void *audioFrameBytes;
733 BMDTimeValue frameTime;
734 BMDTimeValue frameDuration;
735 int64_t wallclock = 0, abs_wallclock = 0;
736 int64_t video_pkt_pts, audio_pkt_pts;
738
740 if (videoFrame && !(videoFrame->GetFlags() & bmdFrameHasNoInputSource) &&
742 {
744 }
745 return S_OK;
746 }
747
748 // Drop the frames till system's timestamp aligns with the configured value.
752 if (
av_cmp_q(remainder, frame_duration) > 0) {
754 return S_OK;
755 }
756 }
757
765
766 // Handle Video Frame
767 if (videoFrame) {
772 "Frame received (#%lu) - Valid (%liB) - QSize %fMB\n",
774 videoFrame->GetRowBytes() * videoFrame->GetHeight(),
775 (double)qsize / 1024 / 1024);
776 }
777
778 videoFrame->GetBytes(&frameBytes);
779 videoFrame->GetStreamTime(&frameTime, &frameDuration,
781
782 if (videoFrame->GetFlags() & bmdFrameHasNoInputSource) {
784 unsigned bars[8] = {
785 0xEA80EA80, 0xD292D210, 0xA910A9A5, 0x90229035,
786 0x6ADD6ACA, 0x51EF515A, 0x286D28EF, 0x10801080 };
787 int width = videoFrame->GetWidth();
788 int height = videoFrame->GetHeight();
789 unsigned *
p = (
unsigned *)frameBytes;
790
791 for (
int y = 0; y <
height; y++) {
792 for (
int x = 0; x <
width; x += 2)
793 *
p++ = bars[(x * 8) /
width];
794 }
797 videoFrame->GetBytes(&frameBytes);
798 }
799
803 }
805 } else {
811 }
815 }
817
818 // Handle Timecode (if requested)
824 if (tc) {
826 uint8_t* packed_metadata;
827
830 int size =
sizeof(uint32_t) * 4;
832
833 if (sd) {
834 *sd = 1; // one TC
835 *(sd + 1) = tc_data; // TC
836 }
837 }
838
839 if (
av_dict_set(&metadata_dict,
"timecode", tc, 0) >= 0) {
840 size_t metadata_len;
843 if (packed_metadata) {
848 }
849 }
850 }
851 } else {
853 }
854 }
855 }
856
858
862 return S_OK;
863 }
864
867
869 //To be made sure it still applies
872 pkt.
data = (uint8_t *)frameBytes;
873 pkt.
size = videoFrame->GetRowBytes() *
874 videoFrame->GetHeight();
875 //fprintf(stderr,"Video Frame size %d ts %d\n", pkt.size, pkt.pts);
876
878 IDeckLinkVideoFrameAncillary *vanc;
880 uint8_t txt_buf0[3531]; // 35 * 46 bytes decoded teletext lines + 1 byte data_identifier + 1920 bytes OP47 decode buffer
881 uint8_t *txt_buf = txt_buf0;
882
885 }
886
887 if (videoFrame->GetAncillaryData(&vanc) == S_OK) {
889 BMDPixelFormat vanc_format = vanc->GetPixelFormat();
890 txt_buf[0] = 0x10; // data_identifier - EBU_data
891 txt_buf++;
892 #if CONFIG_LIBZVBI
894 (vanc_format == bmdFormat8BitYUV || vanc_format == bmdFormat10BitYUV)) {
897 for (
i = 6;
i < 336;
i++, line_mask <<= 1) {
898 uint8_t *buf;
899 if ((
ctx->
teletext_lines & line_mask) && vanc->GetBufferForVerticalBlankingLine(
i, (
void**)&buf) == S_OK) {
900 if (vanc_format == bmdFormat8BitYUV)
901 txt_buf = teletext_data_unit_from_vbi_data(
i, buf, txt_buf, VBI_PIXFMT_UYVY);
902 else
903 txt_buf = teletext_data_unit_from_vbi_data_10bit(
i, buf, txt_buf);
904 }
907 }
908 }
909 #endif
910 if (vanc_format == bmdFormat10BitYUV && videoFrame->GetWidth() <=
MAX_WIDTH_VANC) {
913 uint8_t *buf;
914 if (vanc->GetBufferForVerticalBlankingLine(
i, (
void**)&buf) == S_OK) {
916 size_t vanc_size = videoFrame->GetWidth();
918 vanc_size = vanc_size * 2;
920 } else {
922 }
924 txt_buf,
sizeof(txt_buf0) - (txt_buf - txt_buf0), &
pkt);
925 }
928 }
929 }
930 vanc->Release();
931 if (txt_buf - txt_buf0 > 1) {
932 int stuffing_units = (4 - ((45 + txt_buf - txt_buf0) / 46) % 4) % 4;
933 while (stuffing_units--) {
934 memset(txt_buf, 0xff, 46);
935 txt_buf[1] = 0x2c; // data_unit_length
936 txt_buf += 46;
937 }
941 txt_pkt.
data = txt_buf0;
942 txt_pkt.
size = txt_buf - txt_buf0;
945 }
946 }
947 }
948 }
949
952 videoFrame->AddRef();
953
956 }
957 }
958
959 // Handle Audio Frame
960 if (audioFrame) {
962 BMDTimeValue audio_pts;
963
964 //hack among hacks
966 audioFrame->GetBytes(&audioFrameBytes);
970
971 //fprintf(stderr,"Audio Frame size %d ts %d\n", pkt.size, pkt.pts);
974 pkt.
data = (uint8_t *)audioFrameBytes;
975
978 }
979 }
980
981 return S_OK;
982 }
983
985 BMDVideoInputFormatChangedEvents events, IDeckLinkDisplayMode *
mode,
986 BMDDetectedVideoInputFormatFlags formatFlags)
987 {
990 // check the C context member to make sure we set both raw_format and bmd_mode with data from the same format change callback
992 ctx->
raw_format = (formatFlags & bmdDetectedVideoInputRGB444) ? bmdFormat8BitARGB : bmdFormat8BitYUV;
993 return S_OK;
994 }
995
1000
1001 if (
ctx->attr->GetFlag(BMDDeckLinkSupportsInputFormatDetection, &autodetect_supported) != S_OK)
1002 return -1;
1003 if (autodetect_supported == false)
1004 return -1;
1005
1006 ctx->autodetect = 1;
1007 ctx->bmd_mode = bmdModeUnknown;
1009 bmdFormat8BitYUV,
1010 bmdVideoInputEnableFormatDetection) != S_OK) {
1011 return -1;
1012 }
1013
1014 if (
ctx->dli->StartStreams() != S_OK) {
1015 return -1;
1016 }
1017
1018 // 3 second timeout
1019 for (
i = 0;
i < 30;
i++) {
1021 /* Sometimes VideoInputFrameArrived is called without the
1022 * bmdFrameHasNoInputSource flag before VideoInputFormatChanged.
1023 * So don't break for bmd_mode == AUTODETECT_DEFAULT_MODE. */
1024 if (
ctx->bmd_mode != bmdModeUnknown &&
1026 break;
1027 }
1028
1029 ctx->dli->PauseStreams();
1030 ctx->dli->FlushStreams();
1031 ctx->autodetect = 0;
1032 if (
ctx->bmd_mode != bmdModeUnknown) {
1035 return -1;
1037 return 0;
1038 } else {
1039 return -1;
1040 }
1041
1042 }
1043
1044 extern "C" {
1045
1047 {
1050
1052 ctx->dli->StopStreams();
1053 ctx->dli->DisableVideoInput();
1054 ctx->dli->DisableAudioInput();
1055 ctx->dli->SetCallback(
nullptr);
1056 }
1057
1060
1062
1063 return 0;
1064 }
1065
1067 {
1075
1097 av_log(avctx,
AV_LOG_WARNING,
"Setting signal_loss_action to none because draw_bars is false\n");
1098 }
1100 av_log(avctx,
AV_LOG_ERROR,
"options draw_bars and signal_loss_action are mutually exclusive\n");
1103 }
1108
1109 /* Check audio channel option for valid values: 2, 8 or 16 */
1111 case 2:
1112 case 8:
1113 case 16:
1114 break;
1115 default:
1119 }
1120
1121 /* Check audio bit depth option for valid values: 16 or 32 */
1123 case 16:
1124 case 32:
1125 break;
1126 default:
1127 av_log(avctx,
AV_LOG_ERROR,
"Value for audio bit depth option must be either 16 or 32\n");
1130 }
1131
1132 /* List available devices. */
1133 if (
ctx->list_devices) {
1137 }
1138
1142
1143 /* Get input device. */
1144 if (
ctx->dl->QueryInterface(IID_IDeckLinkInput, (
void **) &
ctx->dli) != S_OK) {
1149 }
1150
1155 }
1156
1157 /* List supported formats. */
1158 if (
ctx->list_formats) {
1162 }
1163
1170 }
1171
1174 allocator->Release();
1178 }
1179
1185 }
1187 }
1188 if (
ctx->raw_format == (BMDPixelFormat)0)
1189 ctx->raw_format = bmdFormat8BitYUV;
1195 }
1196
1197 #if !CONFIG_LIBZVBI
1198 if (
ctx->teletext_lines &&
ctx->bmd_mode == bmdModePAL) {
1199 av_log(avctx,
AV_LOG_ERROR,
"Libzvbi support is needed for capturing SD PAL teletext, please recompile FFmpeg.\n");
1202 }
1203 #endif
1204
1205 /* Setup streams. */
1207 if (!st) {
1211 }
1214 st->codecpar->sample_rate = bmdAudioSampleRate48kHz;
1218
1220 if (!st) {
1224 }
1226 st->codecpar->width =
ctx->bmd_width;
1227 st->codecpar->height =
ctx->bmd_height;
1228
1229 st->time_base.den =
ctx->bmd_tb_den;
1230 st->time_base.num =
ctx->bmd_tb_num;
1231 st->r_frame_rate =
av_make_q(st->time_base.den, st->time_base.num);
1232
1233 switch(
ctx->raw_format) {
1234 case bmdFormat8BitYUV:
1237 st->codecpar->bit_rate =
av_rescale(
ctx->bmd_width *
ctx->bmd_height * 16, st->time_base.den, st->time_base.num);
1238 break;
1239 case bmdFormat10BitYUV:
1241 st->codecpar->bit_rate =
av_rescale(
ctx->bmd_width *
ctx->bmd_height * 64, st->time_base.den, st->time_base.num * 3);
1242 break;
1243 case bmdFormat8BitARGB:
1246 st->codecpar->bit_rate =
av_rescale(
ctx->bmd_width *
ctx->bmd_height * 32, st->time_base.den, st->time_base.num);
1247 break;
1248 case bmdFormat8BitBGRA:
1251 st->codecpar->bit_rate =
av_rescale(
ctx->bmd_width *
ctx->bmd_height * 32, st->time_base.den, st->time_base.num);
1252 break;
1253 case bmdFormat10BitRGB:
1255 st->codecpar->bit_rate =
av_rescale(
ctx->bmd_width *
ctx->bmd_height * 30, st->time_base.den, st->time_base.num);
1256 break;
1257 default:
1263 }
1264
1265 switch (
ctx->bmd_field_dominance) {
1266 case bmdUpperFieldFirst:
1268 break;
1269 case bmdLowerFieldFirst:
1271 break;
1272 case bmdProgressiveFrame:
1273 case bmdProgressiveSegmentedFrame:
1275 break;
1276 }
1277
1279
1281
1282 if (
ctx->enable_klv) {
1284 if (!st) {
1287 }
1289 st->time_base.den =
ctx->bmd_tb_den;
1290 st->time_base.num =
ctx->bmd_tb_num;
1294 }
1295
1296 if (
ctx->teletext_lines) {
1298 if (!st) {
1302 }
1304 st->time_base.den =
ctx->bmd_tb_den;
1305 st->time_base.num =
ctx->bmd_tb_num;
1308 ctx->teletext_st = st;
1309 }
1310
1311 av_log(avctx,
AV_LOG_VERBOSE,
"Using %d input audio channels\n",
ctx->audio_st->codecpar->ch_layout.nb_channels);
1312 result =
ctx->dli->EnableAudioInput(bmdAudioSampleRate48kHz, cctx->
audio_depth == 32 ? bmdAudioSampleType32bitInteger : bmdAudioSampleType16bitInteger,
ctx->audio_st->codecpar->ch_layout.nb_channels);
1313
1318 }
1319
1322 bmdVideoInputFlagDefault);
1323
1328 }
1329
1331
1332 if (
ctx->dli->StartStreams() != S_OK) {
1336 }
1337
1338 return 0;
1339
1344 }
1345
1347 {
1350
1352
1356 if (side_metadata) {
1359 }
1360 }
1361
1362 return 0;
1363 }
1364
1366 {
1368 }
1369
1370 } /* extern "C" */