diff --git a/src/blackmagic_common.cpp b/src/blackmagic_common.cpp index 25d8d46cc..4f55edd63 100644 --- a/src/blackmagic_common.cpp +++ b/src/blackmagic_common.cpp @@ -370,8 +370,8 @@ class ProfileCallback : public IDeckLinkProfileCallback /** * @param a value from BMDProfileID or bmdDuplexHalf (maximize number of IOs) */ -bool decklink_set_profile(IDeckLink *deckLink, uint32_t profileID, bool stereo) { - if (profileID == BMD_OPT_DEFAULT && !stereo) { +bool decklink_set_profile(IDeckLink *deckLink, bmd_option req_profile, bool stereo) { + if (req_profile.is_default() && !stereo) { return true; } @@ -383,14 +383,12 @@ bool decklink_set_profile(IDeckLink *deckLink, uint32_t profileID, bool stereo) ProfileCallback *p = nullptr; if (HRESULT res = deckLink->QueryInterface(IID_IDeckLinkProfileManager, (void**)&manager)) { - bool error = !(profileID == BMD_OPT_DEFAULT && res == E_NOINTERFACE); + bool error = !(req_profile.is_default() && res == E_NOINTERFACE); LOG(error ? LOG_LEVEL_ERROR : LOG_LEVEL_VERBOSE) << MOD_NAME << "Cannot set duplex - query profile manager: " << bmd_hresult_to_string(res) << "\n"; return error; } - if (profileID == BMD_OPT_DEFAULT) { - profileID = bmdProfileOneSubDeviceFullDuplex; - } + uint32_t profileID = req_profile.is_default() ? (int64_t) bmdProfileOneSubDeviceFullDuplex : req_profile.get_int(); EXIT_IF_FAILED(manager->GetProfiles(&it), "Cannot set duplex - get profiles"); diff --git a/src/blackmagic_common.hpp b/src/blackmagic_common.hpp index 6b62cf0f7..8d887a272 100644 --- a/src/blackmagic_common.hpp +++ b/src/blackmagic_common.hpp @@ -133,7 +133,7 @@ bool blackmagic_api_version_check(); void print_decklink_version(void); bool bmd_check_stereo_profile(IDeckLink *deckLink); -bool decklink_set_profile(IDeckLink *decklink, uint32_t profileID, bool stereo); +bool decklink_set_profile(IDeckLink *deckLink, bmd_option req_profile, bool stereo); std::string bmd_get_device_name(IDeckLink *decklink); std::string bmd_get_audio_connection_name(BMDAudioOutputAnalogAESSwitch audioConnection); uint32_t bmd_read_fourcc(const char *); diff --git a/src/video_capture/decklink.cpp b/src/video_capture/decklink.cpp index 3d70d60fc..e163a089c 100644 --- a/src/video_capture/decklink.cpp +++ b/src/video_capture/decklink.cpp @@ -174,7 +174,7 @@ struct vidcap_decklink_state { unsigned int requested_bit_depth = 0; // 0, bmdDetectedVideoInput8BitDepth, bmdDetectedVideoInput10BitDepth or bmdDetectedVideoInput12BitDepth bool p_not_i = false; - uint32_t profile{}; // BMD_OPT_DEFAULT, BMD_OPT_KEEP, bmdDuplexHalf or one of BMDProfileID + bmd_option profile; bool nosig_send = false; ///< send video even when no signal detected bool keep_device_defaults = false; @@ -690,16 +690,11 @@ static bool parse_option(struct vidcap_decklink_state *s, const char *opt) : bmdDeckLinkCapturePassthroughModeCleanSwitch)); } } else if (strstr(opt, "profile=") == opt) { - const char *mode = opt + strlen("profile="); - if (strcmp(mode, "keep") == 0) { - s->profile = BMD_OPT_KEEP; - } else { - s->profile = (BMDProfileID) bmd_read_fourcc(mode); - } + s->profile.parse_int(strchr(opt, '=') + 1); } else if (strstr(opt, "full-duplex") == opt) { - s->profile = bmdProfileOneSubDeviceFullDuplex; + s->profile.set_int(bmdProfileOneSubDeviceFullDuplex); } else if (strstr(opt, "half-duplex") == opt) { - s->profile = bmdDuplexHalf; + s->profile.set_int(bmdDuplexHalf); } else if (strcasecmp(opt, "nosig-send") == 0) { s->nosig_send = true; } else if (strstr(opt, "keep-settings") == opt) { @@ -1100,7 +1095,7 @@ bool device_state::init(struct vidcap_decklink_state *s, struct tile *t, BMDAudi LOG(LOG_LEVEL_INFO) << MOD_NAME "Using device " << deviceName << "\n"; } - if (!s->keep_device_defaults && s->profile != BMD_OPT_KEEP) { + if (!s->keep_device_defaults && s->profile.keep()) { decklink_set_profile(deckLink, s->profile, s->stereo); } diff --git a/src/video_display/decklink.cpp b/src/video_display/decklink.cpp index b0109701c..92f9e8bd7 100644 --- a/src/video_display/decklink.cpp +++ b/src/video_display/decklink.cpp @@ -344,7 +344,7 @@ struct state_decklink { BMDPixelFormat pixelFormat{}; - uint32_t profile_req = BMD_OPT_DEFAULT; // BMD_OPT_DEFAULT, BMD_OPT_KEEP, bmdDuplexHalf or one of BMDProfileID + bmd_option profile_req; char sdi_dual_channel_level = BMD_OPT_DEFAULT; // 'A' - level A, 'B' - level B bool quad_square_division_split = true; map device_options = { @@ -822,10 +822,10 @@ display_decklink_reconfigure_video(void *state, struct video_desc desc) int64_t link = 0; s->state.at(i).deckLinkConfiguration->GetInt(bmdDeckLinkConfigSDIOutputLinkConfiguration, &link); - if (!s->keep_device_defaults && s->profile_req == BMD_OPT_DEFAULT && link == bmdLinkConfigurationQuadLink) { + if (!s->keep_device_defaults && s->profile_req.is_default() && link == bmdLinkConfigurationQuadLink) { LOG(LOG_LEVEL_WARNING) << MOD_NAME "Quad-link detected - setting 1-subdevice-1/2-duplex profile automatically, use 'profile=keep' to override.\n"; - decklink_set_profile(s->state.at(i).deckLink, bmdProfileOneSubDeviceHalfDuplex, s->stereo); - } else if (link == bmdLinkConfigurationQuadLink && (s->profile_req != BMD_OPT_KEEP && s->profile_req == bmdProfileOneSubDeviceHalfDuplex)) { + decklink_set_profile(s->state.at(i).deckLink, bmd_option((int64_t) bmdProfileOneSubDeviceHalfDuplex), s->stereo); + } else if (link == bmdLinkConfigurationQuadLink && (!s->profile_req.keep() && s->profile_req.get_int() != bmdProfileOneSubDeviceHalfDuplex)) { LOG(LOG_LEVEL_WARNING) << MOD_NAME "Setting quad-link and an incompatible device profile may not be supported!\n"; } @@ -1005,16 +1005,11 @@ static bool settings_init(struct state_decklink *s, const char *fmt, } else if (strcasecmp(ptr, "quad-link") == 0) { s->device_options[bmdDeckLinkConfigSDIOutputLinkConfiguration].set_int(bmdLinkConfigurationQuadLink); } else if (strstr(ptr, "profile=") == ptr) { - ptr += strlen("profile="); - if (strcmp(ptr, "keep") == 0) { - s->profile_req = BMD_OPT_KEEP; - } else { - s->profile_req = (BMDProfileID) bmd_read_fourcc(ptr); - } + s->profile_req.parse_int(ptr); } else if (strcasecmp(ptr, "full-duplex") == 0) { - s->profile_req = bmdProfileOneSubDeviceFullDuplex; + s->profile_req.set_int(bmdProfileOneSubDeviceFullDuplex); } else if (strcasecmp(ptr, "half-duplex") == 0) { - s->profile_req = bmdDuplexHalf; + s->profile_req.set_int(bmdDuplexHalf); } else if (strcasecmp(ptr, "LevelA") == 0) { s->sdi_dual_channel_level = 'A'; } else if (strcasecmp(ptr, "LevelB") == 0) { @@ -1203,7 +1198,7 @@ static void *display_decklink_init(struct module *parent, const char *fmt, unsig } for(int i = 0; i < s->devices_cnt; ++i) { - if (!s->keep_device_defaults && s->profile_req != BMD_OPT_KEEP) { + if (!s->keep_device_defaults && !s->profile_req.keep()) { decklink_set_profile(s->state.at(i).deckLink, s->profile_req, s->stereo); }