2 * Copyright (C) 2008-2015 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2009-2010 Carl Hetherington <carl@carlh.net>
4 * Copyright (C) 2009-2012 David Robillard <d@drobilla.net>
5 * Copyright (C) 2015-2017 Robin Gareus <robin@gareus.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "ardour/broadcast_info.h"
30 #include "ardour/revision.h"
31 #include "ardour/session.h"
32 #include "ardour/session_metadata.h"
40 snprintf_bounded_null_filled (char* target, size_t target_size, char const * fmt, ...)
42 std::vector<char> buf(target_size+1);
46 vsnprintf (&buf[0], target_size+1, fmt, ap);
49 memset (target, 0, target_size);
50 memcpy (target, &buf[0], target_size);
54 BroadcastInfo::BroadcastInfo ()
60 BroadcastInfo::set_from_session (Session const & session, int64_t time_ref)
62 set_description (session.name());
63 set_time_reference (time_ref);
64 set_origination_time ();
66 set_originator_ref_from_session (session);
70 BroadcastInfo::set_originator (std::string const & str)
75 AudioGrapher::BroadcastInfo::set_originator (str);
79 snprintf_bounded_null_filled (info->originator, sizeof (info->originator), Glib::get_real_name().c_str());
83 BroadcastInfo::set_originator_ref_from_session (Session const & /*session*/)
87 /* random code is 9 digits */
89 int random_code = g_random_int() % 999999999;
91 /* Serial number is 12 chars */
93 std::ostringstream serial_number;
94 serial_number << PROGRAM_NAME << revision;
96 std::string country = SessionMetadata::Metadata()->country().substr (0, 2).c_str(); // ISO 3166-1 2 digits
97 if (country.empty ()) {
98 /* "ZZ" is reserved and may be user-assigned.
99 * EBU Tech 3279 chapter 4.2.4 recommends "ZZ" for unregistered organizations
104 /* https://tech.ebu.ch/docs/tech/tech3279.pdf */
105 std::string organization = SessionMetadata::Metadata()->organization().substr (0, 3).c_str(); // EBU assigned Organisation code
106 if (organization.empty ()) {
107 organization = "---";
110 // TODO sanitize to allowed char set: tech3279.pdf chapter 1.6
111 // allowed: A-Z 0-9 <space> .,-()/=
112 // possible, but not recommended: !"%&*;<>
114 /* https://tech.ebu.ch/docs/r/r099.pdf
115 * CC Country code: (2 characters) based on the ISO 3166-1 standard
116 * OOO Organisation code: (3 characters) based on the EBU facility codes, Tech 3279
117 * NNNNNNNNNNNN Serial number: (12 characters extracted from the recorder model and serial number) This should identify the machine’s type and serial number.
118 * HHMMSS OriginationTime (6 characters,) from the <OriginationTime> field of the BWF.
119 * RRRRRRRRR Random Number (9 characters 0-9) Generated locally by the recorder using some reasonably random algorithm.
121 snprintf_bounded_null_filled (info->originator_reference, sizeof (info->originator_reference), "%2s%3s%12s%02d%02d%02d%09d",
122 country.c_str (), organization.c_str(),
123 serial_number.str().substr (0, 12).c_str(),
131 } // namespace ARDOUR