1 /*****************************************************************************
2 * decklink.cpp: BlackMagic DeckLink SDI input module
3 *****************************************************************************
4 * Copyright (C) 2010 Steinar H. Gunderson
5 * Copyright (C) 2012-2014 Rafaël Carré
7 * Authors: Steinar H. Gunderson <steinar+vlc@gunderson.no>
8 Rafaël Carré <funman@videolanorg>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or
13 * (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
29 #include <vlc_common.h>
30 #include <vlc_plugin.h>
31 #include <vlc_demux.h>
32 #include <vlc_atomic.h>
34 #include <arpa/inet.h>
36 #include <DeckLinkAPI.h>
37 #include <DeckLinkAPIDispatch.cpp>
41 static int Open (vlc_object_t
*);
42 static void Close(vlc_object_t
*);
44 #define CARD_INDEX_TEXT N_("Input card to use")
45 #define CARD_INDEX_LONGTEXT N_( \
46 "DeckLink capture card to use, if multiple exist. " \
47 "The cards are numbered from 0.")
49 #define MODE_TEXT N_("Desired input video mode. Leave empty for autodetection.")
50 #define MODE_LONGTEXT N_( \
51 "Desired input video mode for DeckLink captures. " \
52 "This value should be a FOURCC code in textual " \
53 "form, e.g. \"ntsc\".")
55 #define AUDIO_CONNECTION_TEXT N_("Audio connection")
56 #define AUDIO_CONNECTION_LONGTEXT N_( \
57 "Audio connection to use for DeckLink captures. " \
58 "Valid choices: embedded, aesebu, analog. " \
59 "Leave blank for card default.")
61 #define RATE_TEXT N_("Audio samplerate (Hz)")
62 #define RATE_LONGTEXT N_( \
63 "Audio sampling rate (in hertz) for DeckLink captures. " \
64 "0 disables audio input.")
66 #define CHANNELS_TEXT N_("Number of audio channels")
67 #define CHANNELS_LONGTEXT N_( \
68 "Number of input audio channels for DeckLink captures. " \
69 "Must be 2, 8 or 16. 0 disables audio input.")
71 #define VIDEO_CONNECTION_TEXT N_("Video connection")
72 #define VIDEO_CONNECTION_LONGTEXT N_( \
73 "Video connection to use for DeckLink captures. " \
74 "Valid choices: sdi, hdmi, opticalsdi, component, " \
75 "composite, svideo. " \
76 "Leave blank for card default.")
78 static const char *const ppsz_videoconns
[] = {
79 "sdi", "hdmi", "opticalsdi", "component", "composite", "svideo"
81 static const char *const ppsz_videoconns_text
[] = {
82 N_("SDI"), N_("HDMI"), N_("Optical SDI"), N_("Component"), N_("Composite"), N_("S-Video")
85 static const char *const ppsz_audioconns
[] = {
86 "embedded", "aesebu", "analog"
88 static const char *const ppsz_audioconns_text
[] = {
89 N_("Embedded"), N_("AES/EBU"), N_("Analog")
92 #define ASPECT_RATIO_TEXT N_("Aspect ratio")
93 #define ASPECT_RATIO_LONGTEXT N_(\
94 "Aspect ratio (4:3, 16:9). Default assumes square pixels.")
97 set_shortname(N_("DeckLink"))
98 set_description(N_("Blackmagic DeckLink SDI input"))
99 set_category(CAT_INPUT
)
100 set_subcategory(SUBCAT_INPUT_ACCESS
)
102 add_integer("decklink-card-index", 0,
103 CARD_INDEX_TEXT
, CARD_INDEX_LONGTEXT
, true)
104 add_string("decklink-mode", NULL
,
105 MODE_TEXT
, MODE_LONGTEXT
, true)
106 add_string("decklink-audio-connection", 0,
107 AUDIO_CONNECTION_TEXT
, AUDIO_CONNECTION_LONGTEXT
, true)
108 change_string_list(ppsz_audioconns
, ppsz_audioconns_text
)
109 add_integer("decklink-audio-rate", 48000,
110 RATE_TEXT
, RATE_LONGTEXT
, true)
111 add_integer("decklink-audio-channels", 2,
112 CHANNELS_TEXT
, CHANNELS_LONGTEXT
, true)
113 add_string("decklink-video-connection", 0,
114 VIDEO_CONNECTION_TEXT
, VIDEO_CONNECTION_LONGTEXT
, true)
115 change_string_list(ppsz_videoconns
, ppsz_videoconns_text
)
116 add_string("decklink-aspect-ratio", NULL
,
117 ASPECT_RATIO_TEXT
, ASPECT_RATIO_LONGTEXT
, true)
118 add_bool("decklink-tenbits", false, N_("10 bits"), N_("10 bits"), true)
120 add_shortcut("decklink")
121 set_capability("access_demux", 10)
122 set_callbacks(Open
, Close
)
125 static int Control(demux_t
*, int, va_list);
127 class DeckLinkCaptureDelegate
;
132 IDeckLinkInput
*input
;
133 DeckLinkCaptureDelegate
*delegate
;
135 /* We need to hold onto the IDeckLinkConfiguration object, or our settings will not apply.
136 See section 2.4.15 of the Blackmagic DeckLink SDK documentation. */
137 IDeckLinkConfiguration
*config
;
138 IDeckLinkAttributes
*attributes
;
142 es_out_id_t
*video_es
;
143 es_format_t video_fmt
;
144 es_out_id_t
*audio_es
;
147 vlc_mutex_t pts_lock
;
148 int last_pts
; /* protected by <pts_lock> */
150 uint32_t dominance_flags
;
156 static const char *GetFieldDominance(BMDFieldDominance dom
, uint32_t *flags
)
160 case bmdProgressiveFrame
:
162 case bmdProgressiveSegmentedFrame
:
163 return ", segmented";
164 case bmdLowerFieldFirst
:
165 *flags
= BLOCK_FLAG_BOTTOM_FIELD_FIRST
;
166 return ", interlaced [BFF]";
167 case bmdUpperFieldFirst
:
168 *flags
= BLOCK_FLAG_TOP_FIELD_FIRST
;
169 return ", interlaced [TFF]";
170 case bmdUnknownFieldDominance
:
172 return ", unknown field dominance";
176 static es_format_t
GetModeSettings(demux_t
*demux
, IDeckLinkDisplayMode
*m
,
177 BMDDetectedVideoInputFormatFlags fmt_flags
)
179 demux_sys_t
*sys
= (demux_sys_t
*)demux
->p_sys
;
181 (void)GetFieldDominance(m
->GetFieldDominance(), &flags
);
183 BMDTimeValue frame_duration
, time_scale
;
184 if (m
->GetFrameRate(&frame_duration
, &time_scale
) != S_OK
) {
189 es_format_t video_fmt
;
190 vlc_fourcc_t chroma
= 0;
192 case bmdDetectedVideoInputYCbCr422
:
193 chroma
= sys
->tenbits
? VLC_CODEC_I422_10L
: VLC_CODEC_UYVY
;
195 case bmdDetectedVideoInputRGB444
:
196 chroma
= VLC_CODEC_ARGB
;
199 msg_Err(demux
, "Unsupported input format");
202 es_format_Init(&video_fmt
, VIDEO_ES
, chroma
);
204 video_fmt
.video
.i_chroma
= chroma
;
205 video_fmt
.video
.i_width
= m
->GetWidth();
206 video_fmt
.video
.i_height
= m
->GetHeight();
207 video_fmt
.video
.i_sar_num
= 1;
208 video_fmt
.video
.i_sar_den
= 1;
209 video_fmt
.video
.i_frame_rate
= time_scale
;
210 video_fmt
.video
.i_frame_rate_base
= frame_duration
;
211 video_fmt
.i_bitrate
= video_fmt
.video
.i_width
* video_fmt
.video
.i_height
* video_fmt
.video
.i_frame_rate
* 2 * 8;
213 unsigned aspect_num
, aspect_den
;
214 if (!var_InheritURational(demux
, &aspect_num
, &aspect_den
, "decklink-aspect-ratio") &&
215 aspect_num
> 0 && aspect_den
> 0) {
216 video_fmt
.video
.i_sar_num
= aspect_num
* video_fmt
.video
.i_height
;
217 video_fmt
.video
.i_sar_den
= aspect_den
* video_fmt
.video
.i_width
;
220 sys
->dominance_flags
= flags
;
225 class DeckLinkCaptureDelegate
: public IDeckLinkInputCallback
228 DeckLinkCaptureDelegate(demux_t
*demux
) : demux_(demux
)
233 virtual HRESULT STDMETHODCALLTYPE
QueryInterface(REFIID
, LPVOID
*) { return E_NOINTERFACE
; }
235 virtual ULONG STDMETHODCALLTYPE
AddRef(void)
237 return m_ref_
.fetch_add(1);
240 virtual ULONG STDMETHODCALLTYPE
Release(void)
242 uintptr_t new_ref
= m_ref_
.fetch_sub(1);
248 virtual HRESULT STDMETHODCALLTYPE
VideoInputFormatChanged(BMDVideoInputFormatChangedEvents events
, IDeckLinkDisplayMode
*mode
, BMDDetectedVideoInputFormatFlags flags
)
250 demux_sys_t
*sys
= demux_
->p_sys
;
252 if( !(events
& bmdVideoInputDisplayModeChanged
))
255 const char *mode_name
;
256 if (mode
->GetName(&mode_name
) != S_OK
)
257 mode_name
= "unknown";
259 msg_Dbg(demux_
, "Video input format changed to %s", mode_name
);
260 if (!sys
->autodetect
) {
261 msg_Err(demux_
, "Video format detection disabled");
265 BMDPixelFormat fmt
= 0;
267 case bmdDetectedVideoInputYCbCr422
:
268 fmt
= sys
->tenbits
? bmdFormat10BitYUV
: bmdFormat8BitYUV
;
270 case bmdDetectedVideoInputRGB444
:
271 fmt
= bmdFormat8BitARGB
;
274 msg_Err(demux_
, "Unsupported input format");
278 es_out_Del(demux_
->out
, sys
->video_es
);
279 sys
->video_fmt
= GetModeSettings(demux_
, mode
, flags
);
280 sys
->video_es
= es_out_Add(demux_
->out
, &sys
->video_fmt
);
282 sys
->input
->PauseStreams();
283 sys
->input
->EnableVideoInput( mode
->GetDisplayMode(), fmt
, bmdVideoInputEnableFormatDetection
);
284 sys
->input
->FlushStreams();
285 sys
->input
->StartStreams();
290 virtual HRESULT STDMETHODCALLTYPE
VideoInputFrameArrived(IDeckLinkVideoInputFrame
*, IDeckLinkAudioInputPacket
*);
293 std::atomic_uint m_ref_
;
297 HRESULT
DeckLinkCaptureDelegate::VideoInputFrameArrived(IDeckLinkVideoInputFrame
* videoFrame
, IDeckLinkAudioInputPacket
* audioFrame
)
299 demux_sys_t
*sys
= demux_
->p_sys
;
302 if (videoFrame
->GetFlags() & bmdFrameHasNoInputSource
) {
303 msg_Warn(demux_
, "No input signal detected (%dx%d)",
304 videoFrame
->GetWidth(), videoFrame
->GetHeight());
308 const int width
= videoFrame
->GetWidth();
309 const int height
= videoFrame
->GetHeight();
310 const int stride
= videoFrame
->GetRowBytes();
313 switch (sys
->video_fmt
.i_codec
) {
314 case VLC_CODEC_I422_10L
:
322 block_t
*video_frame
= block_Alloc(width
* height
* bpp
);
326 const uint32_t *frame_bytes
;
327 videoFrame
->GetBytes((void**)&frame_bytes
);
329 BMDTimeValue stream_time
, frame_duration
;
330 videoFrame
->GetStreamTime(&stream_time
, &frame_duration
, CLOCK_FREQ
);
331 video_frame
->i_flags
= BLOCK_FLAG_TYPE_I
| sys
->dominance_flags
;
332 video_frame
->i_pts
= video_frame
->i_dts
= VLC_TS_0
+ stream_time
;
334 if (sys
->video_fmt
.i_codec
== VLC_CODEC_I422_10L
) {
335 v210_convert((uint16_t*)video_frame
->p_buffer
, frame_bytes
, width
, height
);
336 IDeckLinkVideoFrameAncillary
*vanc
;
337 if (videoFrame
->GetAncillaryData(&vanc
) == S_OK
) {
338 for (int i
= 1; i
< 21; i
++) {
340 if (vanc
->GetBufferForVerticalBlankingLine(i
, (void**)&buf
) != S_OK
)
342 uint16_t dec
[width
* 2];
343 v210_convert(&dec
[0], buf
, width
, 1);
344 block_t
*cc
= vanc_to_cc(demux_
, dec
, width
* 2);
347 cc
->i_pts
= cc
->i_dts
= VLC_TS_0
+ stream_time
;
352 es_format_Init( &fmt
, SPU_ES
, VLC_CODEC_CEA608
);
353 fmt
.psz_description
= strdup(N_("Closed captions 1"));
354 if (fmt
.psz_description
) {
355 sys
->cc_es
= es_out_Add(demux_
->out
, &fmt
);
356 msg_Dbg(demux_
, "Adding Closed captions stream");
360 es_out_Send(demux_
->out
, sys
->cc_es
, cc
);
363 break; // we found the line with Closed Caption data
367 } else if (sys
->video_fmt
.i_codec
== VLC_CODEC_UYVY
) {
368 for (int y
= 0; y
< height
; ++y
) {
369 const uint8_t *src
= (const uint8_t *)frame_bytes
+ stride
* y
;
370 uint8_t *dst
= video_frame
->p_buffer
+ width
* 2 * y
;
371 memcpy(dst
, src
, width
* 2);
374 memcpy(video_frame
->p_buffer
, frame_bytes
, width
* height
* bpp
);
377 vlc_mutex_lock(&sys
->pts_lock
);
378 if (video_frame
->i_pts
> sys
->last_pts
)
379 sys
->last_pts
= video_frame
->i_pts
;
380 vlc_mutex_unlock(&sys
->pts_lock
);
382 es_out_SetPCR(demux_
->out
, video_frame
->i_pts
);
383 es_out_Send(demux_
->out
, sys
->video_es
, video_frame
);
387 const int bytes
= audioFrame
->GetSampleFrameCount() * sizeof(int16_t) * sys
->channels
;
389 block_t
*audio_frame
= block_Alloc(bytes
);
394 audioFrame
->GetBytes(&frame_bytes
);
395 memcpy(audio_frame
->p_buffer
, frame_bytes
, bytes
);
397 BMDTimeValue packet_time
;
398 audioFrame
->GetPacketTime(&packet_time
, CLOCK_FREQ
);
399 audio_frame
->i_pts
= audio_frame
->i_dts
= VLC_TS_0
+ packet_time
;
401 vlc_mutex_lock(&sys
->pts_lock
);
402 if (audio_frame
->i_pts
> sys
->last_pts
)
403 sys
->last_pts
= audio_frame
->i_pts
;
404 vlc_mutex_unlock(&sys
->pts_lock
);
406 es_out_SetPCR(demux_
->out
, audio_frame
->i_pts
);
407 es_out_Send(demux_
->out
, sys
->audio_es
, audio_frame
);
414 static int GetAudioConn(demux_t
*demux
)
416 demux_sys_t
*sys
= (demux_sys_t
*)demux
->p_sys
;
418 char *opt
= var_CreateGetNonEmptyString(demux
, "decklink-audio-connection");
422 BMDAudioConnection c
;
423 if (!strcmp(opt
, "embedded"))
424 c
= bmdAudioConnectionEmbedded
;
425 else if (!strcmp(opt
, "aesebu"))
426 c
= bmdAudioConnectionAESEBU
;
427 else if (!strcmp(opt
, "analog"))
428 c
= bmdAudioConnectionAnalog
;
430 msg_Err(demux
, "Invalid audio-connection: `%s\' specified", opt
);
435 if (sys
->config
->SetInt(bmdDeckLinkConfigAudioInputConnection
, c
) != S_OK
) {
436 msg_Err(demux
, "Failed to set audio input connection");
443 static int GetVideoConn(demux_t
*demux
)
445 demux_sys_t
*sys
= (demux_sys_t
*)demux
->p_sys
;
447 char *opt
= var_InheritString(demux
, "decklink-video-connection");
451 BMDVideoConnection c
;
452 if (!strcmp(opt
, "sdi"))
453 c
= bmdVideoConnectionSDI
;
454 else if (!strcmp(opt
, "hdmi"))
455 c
= bmdVideoConnectionHDMI
;
456 else if (!strcmp(opt
, "opticalsdi"))
457 c
= bmdVideoConnectionOpticalSDI
;
458 else if (!strcmp(opt
, "component"))
459 c
= bmdVideoConnectionComponent
;
460 else if (!strcmp(opt
, "composite"))
461 c
= bmdVideoConnectionComposite
;
462 else if (!strcmp(opt
, "svideo"))
463 c
= bmdVideoConnectionSVideo
;
465 msg_Err(demux
, "Invalid video-connection: `%s\' specified", opt
);
471 if (sys
->config
->SetInt(bmdDeckLinkConfigVideoInputConnection
, c
) != S_OK
) {
472 msg_Err(demux
, "Failed to set video input connection");
479 static int Open(vlc_object_t
*p_this
)
481 demux_t
*demux
= (demux_t
*)p_this
;
483 int ret
= VLC_EGENERIC
;
485 int physical_channels
= 0;
487 BMDVideoInputFlags flags
= bmdVideoInputFlagDefault
;
490 demux
->pf_demux
= NULL
;
491 demux
->pf_control
= Control
;
492 demux
->info
.i_update
= 0;
493 demux
->p_sys
= sys
= (demux_sys_t
*)calloc(1, sizeof(demux_sys_t
));
497 vlc_mutex_init(&sys
->pts_lock
);
499 sys
->tenbits
= var_InheritBool(p_this
, "decklink-tenbits");
501 IDeckLinkIterator
*decklink_iterator
= CreateDeckLinkIteratorInstance();
502 if (!decklink_iterator
) {
503 msg_Err(demux
, "DeckLink drivers not found.");
507 card_index
= var_InheritInteger(demux
, "decklink-card-index");
508 if (card_index
< 0) {
509 msg_Err(demux
, "Invalid card index %d", card_index
);
513 for (int i
= 0; i
<= card_index
; i
++) {
515 sys
->card
->Release();
516 if (decklink_iterator
->Next(&sys
->card
) != S_OK
) {
517 msg_Err(demux
, "DeckLink PCI card %d not found", card_index
);
522 const char *model_name
;
523 if (sys
->card
->GetModelName(&model_name
) != S_OK
)
524 model_name
= "unknown";
526 msg_Dbg(demux
, "Opened DeckLink PCI card %d (%s)", card_index
, model_name
);
528 if (sys
->card
->QueryInterface(IID_IDeckLinkInput
, (void**)&sys
->input
) != S_OK
) {
529 msg_Err(demux
, "Card has no inputs");
533 /* Set up the video and audio sources. */
534 if (sys
->card
->QueryInterface(IID_IDeckLinkConfiguration
, (void**)&sys
->config
) != S_OK
) {
535 msg_Err(demux
, "Failed to get configuration interface");
539 if (sys
->card
->QueryInterface(IID_IDeckLinkAttributes
, (void**)&sys
->attributes
) != S_OK
) {
540 msg_Err(demux
, "Failed to get attributes interface");
544 if (GetVideoConn(demux
) || GetAudioConn(demux
))
548 fmt
= sys
->tenbits
? bmdFormat10BitYUV
: bmdFormat8BitYUV
;
549 if (sys
->attributes
->GetFlag(BMDDeckLinkSupportsInputFormatDetection
, &sys
->autodetect
) != S_OK
) {
550 msg_Err(demux
, "Failed to query card attribute");
554 /* Get the list of display modes. */
555 IDeckLinkDisplayModeIterator
*mode_it
;
556 if (sys
->input
->GetDisplayModeIterator(&mode_it
) != S_OK
) {
557 msg_Err(demux
, "Failed to enumerate display modes");
569 mode
= var_CreateGetNonEmptyString(demux
, "decklink-mode");
571 sys
->autodetect
= false; // disable autodetection if mode was set
573 if (sys
->autodetect
) {
574 msg_Dbg(demux
, "Card supports input format detection");
575 flags
|= bmdVideoInputEnableFormatDetection
;
576 /* Enable a random format, we will reconfigure on format detection */
577 u
.id
= htonl(bmdModeHD1080p2997
);
579 if (!mode
|| strlen(mode
) < 3 || strlen(mode
) > 4) {
580 msg_Err(demux
, "Invalid mode: \'%s\'", mode
? mode
: "");
585 msg_Dbg(demux
, "Looking for mode \'%s\'", mode
);
586 memcpy(u
.str
, mode
, 4);
587 if (u
.str
[3] == '\0')
588 u
.str
[3] = ' '; /* 'pal'\0 -> 'pal ' */
592 sys
->video_fmt
.video
.i_width
= 0;
594 for (IDeckLinkDisplayMode
*m
;; m
->Release()) {
595 if ((mode_it
->Next(&m
) != S_OK
) || !m
)
598 const char *mode_name
;
599 BMDTimeValue frame_duration
, time_scale
;
600 uint32_t field_flags
;
601 const char *field
= GetFieldDominance(m
->GetFieldDominance(), &field_flags
);
602 BMDDisplayMode id
= ntohl(m
->GetDisplayMode());
604 if (m
->GetName(&mode_name
) != S_OK
)
605 mode_name
= "unknown";
606 if (m
->GetFrameRate(&frame_duration
, &time_scale
) != S_OK
) {
611 msg_Dbg(demux
, "Found mode '%4.4s': %s (%dx%d, %.3f fps%s)",
612 (char*)&id
, mode_name
,
613 (int)m
->GetWidth(), (int)m
->GetHeight(),
614 double(time_scale
) / frame_duration
, field
);
617 sys
->video_fmt
= GetModeSettings(demux
, m
, bmdDetectedVideoInputYCbCr422
);
618 msg_Dbg(demux
, "Using that mode");
624 if (sys
->video_fmt
.video
.i_width
== 0) {
625 msg_Err(demux
, "Unknown video mode `%4.4s\' specified.", (char*)&u
.id
);
629 if (sys
->input
->EnableVideoInput(htonl(u
.id
), fmt
, flags
) != S_OK
) {
630 msg_Err(demux
, "Failed to enable video input");
635 sys
->channels
= var_InheritInteger(demux
, "decklink-audio-channels");
636 switch (sys
->channels
) {
640 physical_channels
= AOUT_CHANS_STEREO
;
643 physical_channels
= AOUT_CHANS_7_1
;
647 msg_Err(demux
, "Invalid number of channels (%d), disabling audio", sys
->channels
);
650 rate
= var_InheritInteger(demux
, "decklink-audio-rate");
651 if (rate
> 0 && sys
->channels
> 0) {
652 if (sys
->input
->EnableAudioInput(rate
, bmdAudioSampleType16bitInteger
, sys
->channels
) != S_OK
) {
653 msg_Err(demux
, "Failed to enable audio input");
658 sys
->delegate
= new DeckLinkCaptureDelegate(demux
);
659 sys
->input
->SetCallback(sys
->delegate
);
661 if (sys
->input
->StartStreams() != S_OK
) {
662 msg_Err(demux
, "Could not start streaming from SDI card. This could be caused "
663 "by invalid video mode or flags, access denied, or card already in use.");
667 msg_Dbg(demux
, "added new video es %4.4s %dx%d",
668 (char*)&sys
->video_fmt
.i_codec
, sys
->video_fmt
.video
.i_width
, sys
->video_fmt
.video
.i_height
);
669 sys
->video_es
= es_out_Add(demux
->out
, &sys
->video_fmt
);
671 es_format_t audio_fmt
;
672 es_format_Init(&audio_fmt
, AUDIO_ES
, VLC_CODEC_S16N
);
673 audio_fmt
.audio
.i_channels
= sys
->channels
;
674 audio_fmt
.audio
.i_physical_channels
= physical_channels
;
675 audio_fmt
.audio
.i_rate
= rate
;
676 audio_fmt
.audio
.i_bitspersample
= 16;
677 audio_fmt
.audio
.i_blockalign
= audio_fmt
.audio
.i_channels
* audio_fmt
.audio
.i_bitspersample
/ 8;
678 audio_fmt
.i_bitrate
= audio_fmt
.audio
.i_channels
* audio_fmt
.audio
.i_rate
* audio_fmt
.audio
.i_bitspersample
;
680 msg_Dbg(demux
, "added new audio es %4.4s %dHz %dbpp %dch",
681 (char*)&audio_fmt
.i_codec
, audio_fmt
.audio
.i_rate
, audio_fmt
.audio
.i_bitspersample
, audio_fmt
.audio
.i_channels
);
682 sys
->audio_es
= es_out_Add(demux
->out
, &audio_fmt
);
687 if (decklink_iterator
)
688 decklink_iterator
->Release();
690 if (ret
!= VLC_SUCCESS
)
696 static void Close(vlc_object_t
*p_this
)
698 demux_t
*demux
= (demux_t
*)p_this
;
699 demux_sys_t
*sys
= (demux_sys_t
*)demux
->p_sys
;
702 sys
->attributes
->Release();
705 sys
->config
->Release();
708 sys
->input
->StopStreams();
709 sys
->input
->Release();
713 sys
->card
->Release();
716 sys
->delegate
->Release();
718 vlc_mutex_destroy(&sys
->pts_lock
);
722 static int Control(demux_t
*demux
, int query
, va_list args
)
724 demux_sys_t
*sys
= (demux_sys_t
*)demux
->p_sys
;
730 /* Special for access_demux */
731 case DEMUX_CAN_PAUSE
:
733 case DEMUX_CAN_CONTROL_PACE
:
734 pb
= va_arg(args
, bool *);
738 case DEMUX_GET_PTS_DELAY
:
739 pi64
= va_arg(args
, int64_t *);
740 *pi64
= INT64_C(1000) * var_InheritInteger(demux
, "live-caching");
744 pi64
= va_arg(args
, int64_t *);
745 vlc_mutex_lock(&sys
->pts_lock
);
746 *pi64
= sys
->last_pts
;
747 vlc_mutex_unlock(&sys
->pts_lock
);