UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
bmd_option Struct Reference

#include <blackmagic_common.hpp>

Collaboration diagram for bmd_option:
Collaboration graph

Public Member Functions

 bmd_option ()=default
 
 bmd_option (bool val, bool user_spec=true)
 
 bmd_option (int64_t val, bool user_spec=true)
 
bool device_write (IDeckLinkConfiguration *deckLinkConfiguration, BMDDeckLinkConfigurationID opt, std::string const &log_prefix="[DeckLink] ") const
 
bool get_flag () const
 
int64_t get_int () const
 
const char * get_string () const
 
bool is_default () const
 
bool is_help () const
 
bool is_user_set () const
 
bool keep () const
 
void parse (const char *)
 
void set_flag (bool val_)
 
void set_float (double val_)
 
void set_int (int64_t val_)
 
void set_keep ()
 
void set_string (const char *val_)
 

Private Types

enum class  type_tag : int {
  t_default , t_keep , t_flag , t_int ,
  t_float , t_string
}
 

Private Attributes

enum bmd_option::type_tag m_type = type_tag::t_default
 
bool m_user_specified = true
 ignore errors if set to false
 
union { 
 
   bool   b 
 
   double   f 
 
   int64_t   i 
 
   char   s [128] 
 
} m_val 
 

Friends

std::ostream & operator<< (std::ostream &output, const bmd_option &b)
 

Detailed Description

Definition at line 90 of file blackmagic_common.hpp.

Member Enumeration Documentation

◆ type_tag

enum class bmd_option::type_tag : int
strongprivate
Enumerator
t_default 
t_keep 
t_flag 
t_int 
t_float 
t_string 

Definition at line 92 of file blackmagic_common.hpp.

Constructor & Destructor Documentation

◆ bmd_option() [1/3]

bmd_option::bmd_option ( )
default

◆ bmd_option() [2/3]

bmd_option::bmd_option ( int64_t val,
bool user_spec = true )
explicit

Definition at line 616 of file blackmagic_common.cpp.

617 m_val.i = val;
618}
int void * val
bool m_user_specified
ignore errors if set to false
union bmd_option::@11 m_val

References m_val, and val.

◆ bmd_option() [3/3]

bmd_option::bmd_option ( bool val,
bool user_spec = true )
explicit

Definition at line 612 of file blackmagic_common.cpp.

613 m_val.b = val;
614}

References m_val, and val.

Member Function Documentation

◆ device_write()

bool bmd_option::device_write ( IDeckLinkConfiguration * deckLinkConfiguration,
BMDDeckLinkConfigurationID opt,
std::string const & log_prefix = "[DeckLink] " ) const

Definition at line 794 of file blackmagic_common.cpp.

794 {
795 HRESULT res = E_FAIL;
796 switch (m_type) {
797 case type_tag::t_flag:
798 res = deckLinkConfiguration->SetFlag(opt, get_flag());
799 break;
800 case type_tag::t_int:
801 res = deckLinkConfiguration->SetInt(opt, get_int());
802 break;
804 res = deckLinkConfiguration->SetFloat(opt, m_val.f);
805 break;
806 case type_tag::t_string: {
808 res = deckLinkConfiguration->SetString(opt, s);
810 break;
811 }
812 case type_tag::t_keep:
814 return true;
815 }
816 ostringstream value_oss;
817 if (opt == bmdDeckLinkConfigVideoInputConnection && get_connection_string_map().find((BMDVideoConnection) get_int()) != get_connection_string_map().end()) {
818 value_oss << get_connection_string_map().at((BMDVideoConnection) get_int());
819 } else {
820 value_oss << *this;
821 }
822 if (res != S_OK) {
823 const int lvl = m_user_specified ? LOG_LEVEL_ERROR
824 : res == E_NOTIMPL ? LOG_LEVEL_INFO
826 LOG(lvl) << log_prefix << "Unable to set key "
827 << fcc_to_string(opt) << " to " << value_oss.str()
828 << ": " << bmd_hresult_to_string(res) << "\n";
829 return !m_user_specified;
830 }
831 LOG(LOG_LEVEL_INFO) << log_prefix << fcc_to_string(opt) << " set to: " << value_oss.str() << "\n";
832 return true;
833}
static string fcc_to_string(uint32_t fourcc)
BMD_STR get_bmd_api_str_from_cstr(const char *cstr)
#define BMD_STR
const std::map< BMDVideoConnection, std::string > & get_connection_string_map()
std::string bmd_hresult_to_string(HRESULT res)
void release_bmd_api_str(BMD_STR string)
#define LOG_LEVEL_INFO
normal reporting
Definition debug.h:62
#define LOG_LEVEL_ERROR
general errors
Definition debug.h:59
#define LOG(level)
Definition debug.h:313
#define LOG_LEVEL_WARNING
less severe errors
Definition debug.h:60
int64_t get_int() const
bool get_flag() const

References bmd_hresult_to_string(), BMD_STR, fcc_to_string(), get_bmd_api_str_from_cstr(), get_connection_string_map(), get_flag(), get_int(), LOG, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_WARNING, m_type, m_user_specified, m_val, release_bmd_api_str(), s, t_default, t_flag, t_float, t_int, t_keep, and t_string.

Referenced by display_decklink_reconfigure().

Here is the call graph for this function:

◆ get_flag()

bool bmd_option::get_flag ( ) const

Definition at line 681 of file blackmagic_common.cpp.

681 {
682 if (m_type != type_tag::t_flag) {
683 log_msg(LOG_LEVEL_WARNING, MOD_NAME "Option is not set to a flag but get_flag() called! Current type tag: %d\n", (int) m_type);
684 return {};
685 }
686 return m_val.b;
687}
#define MOD_NAME
Definition audio.cpp:110
void log_msg(int level, const char *format,...)
Definition debug.cpp:130

References LOG_LEVEL_WARNING, log_msg(), m_type, m_val, MOD_NAME, and t_flag.

Referenced by device_write().

Here is the call graph for this function:

◆ get_int()

int64_t bmd_option::get_int ( ) const

Definition at line 688 of file blackmagic_common.cpp.

688 {
689 if (m_type != type_tag::t_int) {
690 log_msg(LOG_LEVEL_WARNING, MOD_NAME "Option is not set to an int but get_int() called! Current type tag: %d\n", (int) m_type);
691 return {};
692 }
693 return m_val.i;
694}

References LOG_LEVEL_WARNING, log_msg(), m_type, m_val, MOD_NAME, and t_int.

Referenced by decklink_set_profile(), and device_write().

Here is the call graph for this function:

◆ get_string()

const char * bmd_option::get_string ( ) const
nodiscard

Definition at line 695 of file blackmagic_common.cpp.

695 {
696 if (m_type != type_tag::t_string) {
697 MSG(WARNING,
698 "Option is not set to a string but get_string() called! Current "
699 "type tag: %d\n",
700 (int) m_type);
701 return {};
702 }
703 return m_val.s;
704}
#define MSG(l, fmt,...)
Definition debug.h:96

References m_type, m_val, MSG, and t_string.

Referenced by is_help().

◆ is_default()

bool bmd_option::is_default ( ) const

Definition at line 705 of file blackmagic_common.cpp.

705 {
706 return m_type == type_tag::t_default;
707}

References m_type, and t_default.

Referenced by decklink_set_profile().

◆ is_help()

bool bmd_option::is_help ( ) const
nodiscard

Definition at line 708 of file blackmagic_common.cpp.

708 {
709 return m_type == type_tag::t_string &&
710 strcmp(get_string(), "help") == 0;
711}
const char * get_string() const

References get_string(), m_type, and t_string.

Referenced by decklink_set_profile().

Here is the call graph for this function:

◆ is_user_set()

bool bmd_option::is_user_set ( ) const

Definition at line 712 of file blackmagic_common.cpp.

712 {
713 return m_user_specified;
714}

References m_user_specified.

◆ keep()

bool bmd_option::keep ( ) const

Definition at line 678 of file blackmagic_common.cpp.

678 {
679 return m_type == type_tag::t_keep;
680}

References m_type, and t_keep.

Referenced by display_decklink_init(), and device_state::init().

◆ parse()

void bmd_option::parse ( const char * val)
Note
Returns true also for empty/NULL val - this allow specifying the flag without explicit value

Definition at line 719 of file blackmagic_common.cpp.

720{
721 // check flag
722#ifdef __clang__
723#pragma clang diagnostic push
724#pragma clang diagnostic ignored "-Wnull-pointer-arithmetic"
725#endif // defined __clang__
726 if (val == nullptr || val == static_cast<char *>(nullptr) + 1 // allow constructions like parse_bmd_flag(strstr(opt, '=') + 1)
727 || strlen(val) == 0 || strcasecmp(val, "true") == 0 || strcasecmp(val, "on") == 0 || strcasecmp(val, "yes") == 0) {
728 set_flag(true);
729 return;
730 }
731#ifdef __clang__
732#pragma clang diagnostic pop
733#endif // defined __clang
734 if (strcasecmp(val, "false") == 0 || strcasecmp(val, "off") == 0 || strcasecmp(val, "no") == 0) {
735 set_flag(false);
736 return;
737 }
738
739 if (strcasecmp(val, "keep") == 0) {
740 set_keep();
741 return;
742 }
743
744 if (strcmp(val, "help") == 0) {
746 return;
747 }
748
749 // explicitly typed (either "str" or 'fcc')
750 if ((val[0] == '"' && val[strlen(val) - 1] == '"') || (val[0] == '\'' && val[strlen(val) - 1] == '\'')) {
751 string raw_val(val + 1);
752 raw_val.erase(raw_val.length() - 1, 1);
753 if (val[0] == '"') {
754 set_string(raw_val.c_str());
755 } else {
756 set_int(bmd_read_fourcc(raw_val.c_str()));
757 }
758 return;
759 }
760
761 // check number
762 bool is_number = true;
763 bool decimal_point = false;
764 for (size_t i = 0; i < strlen(val); ++i) {
765 if (val[i] == '.') {
766 if (decimal_point) { // there was already decimal point
767 is_number = false;
768 break;
769 }
770 decimal_point = true;
771 continue;
772 }
773 is_number = is_number && isxdigit(val[i]);
774 if (i == 0 && (val[i] == '-' || val[i] == '+')) {
775 is_number = true;
776 }
777 }
778 if (is_number) {
779 if (decimal_point) {
780 set_float(stod(val));
781 } else {
782 set_int(stoi(val, nullptr, 0));
783 }
784 return;
785 }
786 if (strlen(val) <= 4) {
788 return;
789 }
790
792}
uint32_t bmd_read_fourcc(const char *)
void set_string(const char *val_)
void set_int(int64_t val_)
void set_flag(bool val_)
void set_float(double val_)

References bmd_read_fourcc(), i, set_flag(), set_float(), set_int(), set_keep(), set_string(), and val.

Referenced by parse_option(), and settings_init().

Here is the call graph for this function:

◆ set_flag()

void bmd_option::set_flag ( bool val_)

Definition at line 656 of file blackmagic_common.cpp.

656 {
657 m_val.b = val_;
659}

References m_type, m_val, and t_flag.

Referenced by parse(), and settings_init().

◆ set_float()

void bmd_option::set_float ( double val_)

Definition at line 665 of file blackmagic_common.cpp.

665 {
666 m_val.f = val_;
668 m_user_specified = true;
669}

References m_type, m_user_specified, m_val, and t_float.

Referenced by parse().

◆ set_int()

void bmd_option::set_int ( int64_t val_)

Definition at line 660 of file blackmagic_common.cpp.

660 {
661 m_val.i = val_;
663 m_user_specified = true;
664}

References m_type, m_user_specified, m_val, and t_int.

Referenced by parse(), parse_option(), and settings_init().

◆ set_keep()

void bmd_option::set_keep ( )

Definition at line 675 of file blackmagic_common.cpp.

675 {
677}

References m_type, and t_keep.

Referenced by parse().

◆ set_string()

void bmd_option::set_string ( const char * val_)

Definition at line 670 of file blackmagic_common.cpp.

670 {
671 strncpy(m_val.s, val_, sizeof m_val.s - 1);
673 m_user_specified = true;
674}

References m_type, m_user_specified, m_val, and t_string.

Referenced by parse().

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & output,
const bmd_option & b )
friend

Definition at line 620 of file blackmagic_common.cpp.

620 {
621 switch (b.m_type) {
623 output << "(default)";
624 break;
626 output << "(keep)";
627 break;
629 output << (b.get_flag() ? "true" : "false");
630 break;
632 if (IS_FCC(b.get_int())) {
633 output << fcc_to_string(b.get_int());
634 } else if (b.get_int() >= 0) {
635 auto flags = output.flags();
636 output << b.get_int() << " (0x" << hex
637 << b.get_int() << ")";
638 output.flags(flags);
639 } else {
640 output << b.get_int();
641 }
642 break;
644 auto flags = output.flags();
645 output << fixed << b.m_val.f;
646 output.flags(flags);
647 break;
648 }
650 output << b.m_val.s;
651 break;
652 }
653 return output;
654}
const char unsigned int flags
#define IS_FCC(val)
Definition macros.h:116

Member Data Documentation

◆ b

bool bmd_option::b

Definition at line 94 of file blackmagic_common.hpp.

◆ f

double bmd_option::f

Definition at line 96 of file blackmagic_common.hpp.

◆ i

int64_t bmd_option::i

Definition at line 95 of file blackmagic_common.hpp.

Referenced by parse().

◆ m_type

◆ m_user_specified

bool bmd_option::m_user_specified = true
private

ignore errors if set to false

Definition at line 99 of file blackmagic_common.hpp.

Referenced by device_write(), is_user_set(), set_float(), set_int(), and set_string().

◆ [union]

◆ s

char bmd_option::s[128]

Definition at line 97 of file blackmagic_common.hpp.

Referenced by device_write().


The documentation for this struct was generated from the following files: