Skip to content

Commit eb0bdaf

Browse files
committed
blackmagic_common improvements
- headers inclusion optimized - use compat/endian instead of compat/net for endian conversion - use logger - replace Unicode degree symbol with 'deg' - this was not correctly marked as u8 neither so replace it just with a word
1 parent f929a50 commit eb0bdaf

1 file changed

Lines changed: 15 additions & 17 deletions

File tree

src/blackmagic_common.cpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@
3535
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3636
*/
3737

38+
#include "blackmagic_common.hpp"
39+
3840
#include <algorithm>
3941
#include <atomic> // for atomic
4042
#include <cassert>
41-
#include <cctype> // for isxdigit
4243
#include <chrono> // for seconds
4344
#include <climits> // for UINT_MAX
4445
#include <cinttypes> // for PRId64
4546
#include <condition_variable>
46-
#include <csignal>
47-
#include <cstdio> // for fprintf, stderr
47+
#include <cstdio> // for printf, snprintf
4848
#include <cstdint> // for int64_t, uint32_t
4949
#include <cstdlib> // for free
5050
#include <cstring> // for strlen, NULL, strdup, memcpy, size_t
@@ -56,11 +56,8 @@
5656
#include <stdexcept>
5757
#include <utility>
5858

59-
#include "compat/misc.h" // for strncasecmp
60-
#include "compat/net.h" // for htonl, ntohl
61-
#include "compat/strings.h" // for strncasecmp
6259
#include "DeckLinkAPIVersion.h"
63-
#include "blackmagic_common.hpp"
60+
#include "compat/endian.h" // for be32toh, htobe32
6461
#include "debug.h"
6562
#include "host.h"
6663
#include "tv.h"
@@ -300,13 +297,14 @@ void print_decklink_version()
300297
APIInformation = CreateDeckLinkAPIInformationInstance();
301298
if(APIInformation == NULL) {
302299
#endif
303-
fprintf(stderr, "Cannot get API information! Perhaps drivers not installed.\n");
300+
MSG(ERROR, "Cannot get API information! Perhaps drivers not "
301+
"installed.\n");
304302
goto cleanup;
305303
}
306304

307305
result = APIInformation->GetString(BMDDeckLinkAPIVersion, &current_version);
308306
if (result != S_OK) {
309-
fprintf(stderr, "Cannot get API version string!\n");
307+
MSG(ERROR, "Cannot get API version string!\n");
310308
goto cleanup;
311309
}
312310
currentVersionCString = get_cstr_from_bmd_api_str(current_version);
@@ -557,7 +555,7 @@ bool bmd_check_stereo_profile(IDeckLink *deckLink) {
557555
if (BMDProfileID profile_active = decklink_get_active_profile_id(deckLink)) {
558556
if (profile_active != bmdProfileOneSubDeviceHalfDuplex &&
559557
profile_active != bmdProfileOneSubDeviceFullDuplex) {
560-
uint32_t profile_fcc_host = ntohl(profile_active);
558+
uint32_t profile_fcc_host = be32toh(profile_active);
561559
log_msg(LOG_LEVEL_ERROR, MOD_NAME "Active profile '%.4s' may not be compatible with stereo mode.\n", (char *) &profile_fcc_host);
562560
log_msg(LOG_LEVEL_INFO, MOD_NAME "Use 'profile=' parameter to set 1-subdevice mode in either '1dhd' (half) or '1dfd' (full) duplex.\n");
563561
}
@@ -588,7 +586,7 @@ uint32_t bmd_read_fourcc(const char *str) {
588586
} u;
589587
memset(u.c4, ' ', 4);
590588
memcpy(u.c4, str, min(strlen(str), sizeof u.c4));
591-
return htonl(u.fourcc);
589+
return htobe32(u.fourcc);
592590
}
593591

594592
std::ostream &operator<<(std::ostream &output, REFIID iid)
@@ -815,7 +813,7 @@ static string fcc_to_string(uint32_t fourcc) {
815813
char c[5];
816814
uint32_t i;
817815
} fcc{};
818-
fcc.i = htonl(fourcc);
816+
fcc.i = htobe32(fourcc);
819817
return string("'") + fcc.c + "'";
820818
}
821819

@@ -954,7 +952,7 @@ bmd_opt_help()
954952
if (opt_name_map[i].fourcc == 0) {
955953
color_printf("\n%s:\n", opt_name_map[0].name);
956954
} else {
957-
uint32_t val = htonl(opt_name_map[i].fourcc);
955+
uint32_t val = htobe32(opt_name_map[i].fourcc);
958956
color_printf("- " TBOLD("%.4s") " - %s\n",
959957
(char *) &val, opt_name_map[i].name);
960958
}
@@ -967,7 +965,7 @@ bmd_opt_help()
967965
color_printf("Incomplete " TBOLD("(!)") " list of values:\n");
968966
color_printf("(note that the value belongs to its appropriate key)\n");
969967
for (unsigned i = 0; i < std::size(val_name_map); ++i) {
970-
uint32_t val = htonl(val_name_map[i].fourcc);
968+
uint32_t val = htobe32(val_name_map[i].fourcc);
971969
color_printf("- " TBOLD("%.4s") " - %s\n", (char *) &val,
972970
val_name_map[i].name);
973971
}
@@ -1234,7 +1232,7 @@ string bmd_get_flags_str(BMDDisplayModeFlags flags) {
12341232
void print_bmd_device_profiles(const char *line_prefix)
12351233
{
12361234
for (const auto &p : kDeviceProfiles) {
1237-
const uint32_t fcc = htonl(p.first);
1235+
const uint32_t fcc = htobe32(p.first);
12381236
color_printf("%s" TBOLD("%.4s") " - %s (%s)\n", line_prefix, (const char *) &fcc, p.second.first, p.second.second);
12391237
}
12401238
color_printf("%s" TBOLD("keep") " - keep device setting\n", line_prefix);
@@ -1345,7 +1343,7 @@ print_bmd_attribute(IDeckLinkProfileAttributes *deckLinkAttributes,
13451343
BMDDeckLinkAttributeID key;
13461344
};
13471345
memcpy(fcc, query_prop_fcc, min(strlen(query_prop_fcc), sizeof fcc));
1348-
key = (BMDDeckLinkAttributeID) htonl(key);
1346+
key = (BMDDeckLinkAttributeID) htobe32(key);
13491347
BMD_BOOL bool_val{};
13501348
int64_t int_val{};
13511349
double float_val{};
@@ -1741,7 +1739,7 @@ class BMDNotificationCallback : public IDeckLinkNotificationCallback
17411739
if (cur_temp >= m_tempThresholdErr) {
17421740
log_msg(LOG_LEVEL_ERROR,
17431741
"%sDevice is overheating! The temperature is "
1744-
"%" PRId64 " °C.\n",
1742+
"%" PRId64 " deg C.\n",
17451743
m_logPrefix.c_str(), cur_temp);
17461744
return;
17471745
}

0 commit comments

Comments
 (0)