• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OpenLightingProject / ola / 17141553775

21 Aug 2025 11:23PM UTC coverage: 45.72% (-0.02%) from 45.742%
17141553775

push

github

web-flow
Merge pull request #2014 from peternewman/mac-be

Tidy the Mac OS Endian behaviour

7586 of 17462 branches covered (43.44%)

22424 of 49046 relevant lines covered (45.72%)

53.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/examples/ola-timecode.cpp
1
/*
2
 * This program is free software; you can redistribute it and/or modify
3
 * it under the terms of the GNU General Public License as published by
4
 * the Free Software Foundation; either version 2 of the License, or
5
 * (at your option) any later version.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU Library General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15
 *
16
 * ola-timecode.cpp
17
 * Send timecode data with OLA
18
 * Copyright (C) 2011 Simon Newton
19
 */
20

21
#include <errno.h>
22
#include <stdlib.h>
23
#include <ola/Logging.h>
24
#include <ola/StringUtils.h>
25
#include <ola/base/Flags.h>
26
#include <ola/base/Init.h>
27
#include <ola/base/SysExits.h>
28
#include <ola/client/ClientWrapper.h>
29
#include <ola/client/OlaClient.h>
30
#include <ola/timecode/TimeCode.h>
31
#include <ola/timecode/TimeCodeEnums.h>
32

33
#include <iostream>
34
#include <string>
35
#include <vector>
36

37
using ola::client::OlaClientWrapper;
38
using ola::StringToInt;
39
using ola::io::SelectServer;
40
using ola::timecode::TimeCode;
41
using std::cerr;
42
using std::endl;
43
using std::string;
44
using std::vector;
45

46
DEFINE_s_string(format, f, "SMPTE", "One of FILM, EBU, DF, SMPTE (default).");
47

48
/**
49
 * Called on when we return from sending timecode data.
50
 */
51
void TimeCodeDone(ola::io::SelectServer *ss,
×
52
                  const ola::client::Result &result) {
53
  if (!result.Success()) {
×
54
    OLA_WARN << result.Error();
×
55
  }
56
  ss->Terminate();
×
57
}
×
58

59
/*
60
 * Main
61
 */
62
int main(int argc, char *argv[]) {
×
63
  ola::AppInit(
×
64
      &argc,
65
      argv,
66
      "[options] <time_code>",
67
      "Send TimeCode data to OLA. time_code is in the form: \n"
68
          "Hours:Minutes:Seconds:Frames");
69
  ola::client::OlaClientWrapper ola_client;
×
70

71
  if (argc != 2)
×
72
    ola::DisplayUsageAndExit();
×
73

74
  ola::timecode::TimeCodeType time_code_type = ola::timecode::TIMECODE_SMPTE;
×
75
  if (!FLAGS_format.str().empty()) {
×
76
    string type = FLAGS_format;
×
77
    ola::ToLower(&type);
×
78
    if (type == "film") {
×
79
      time_code_type = ola::timecode::TIMECODE_FILM;
80
    } else if (type == "ebu") {
×
81
      time_code_type = ola::timecode::TIMECODE_EBU;
82
    } else if (type == "df") {
×
83
      time_code_type = ola::timecode::TIMECODE_DF;
84
    } else if (type == "smpte") {
×
85
      time_code_type = ola::timecode::TIMECODE_SMPTE;
86
    } else {
87
      cerr << "Invalid TimeCode format " << type << endl;
×
88
      exit(ola::EXIT_USAGE);
×
89
    }
90
  }
×
91

92
  vector<string> tokens;
×
93
  ola::StringSplit(argv[1], &tokens, ":");
×
94
  if (tokens.size() != 4) {
×
95
    cerr << "Invalid TimeCode value " << argv[1] << endl;
×
96
    exit(ola::EXIT_USAGE);
×
97
  }
98

99
  uint8_t hours, minutes, seconds, frames;
×
100
  if (!StringToInt(tokens[0], &hours, true)) {
×
101
    cerr << "Invalid TimeCode hours " << tokens[0] << endl;
×
102
    exit(ola::EXIT_USAGE);
×
103
  }
104
  if (!StringToInt(tokens[1], &minutes, true)) {
×
105
    cerr << "Invalid TimeCode minutes " << tokens[1] << endl;
×
106
    exit(ola::EXIT_USAGE);
×
107
  }
108
  if (!StringToInt(tokens[2], &seconds, true)) {
×
109
    cerr << "Invalid TimeCode seconds " << tokens[2] << endl;
×
110
    exit(ola::EXIT_USAGE);
×
111
  }
112
  if (!StringToInt(tokens[3], &frames, true)) {
×
113
    cerr << "Invalid TimeCode frames " << tokens[3] << endl;
×
114
    exit(ola::EXIT_USAGE);
×
115
  }
116

117
  TimeCode timecode(time_code_type, hours, minutes, seconds, frames);
×
118
  if (!timecode.IsValid()) {
×
119
    OLA_FATAL << "Invalid TimeCode value";
×
120
    exit(ola::EXIT_USAGE);
×
121
  }
122

123
  if (!ola_client.Setup()) {
×
124
    OLA_FATAL << "Setup failed";
×
125
    exit(ola::EXIT_UNAVAILABLE);
×
126
  }
127

128
  ola_client.GetClient()->SendTimeCode(
×
129
      timecode,
130
      ola::NewSingleCallback(&TimeCodeDone, ola_client.GetSelectServer()));
131

132
  ola_client.GetSelectServer()->Run();
×
133
  return ola::EXIT_OK;
×
134
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc