Skip to content

Commit bfb1746

Browse files
committed
Various fixes
Signed-off-by: Darby Johnston <darbyjohnston@yahoo.com>
1 parent f72630e commit bfb1746

File tree

13 files changed

+87
-56
lines changed

13 files changed

+87
-56
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ set(OTIO_PYTHON_INSTALL_DIR "" CACHE STRING "Python installation dir (such as th
4242
# Build options
4343
#
4444
# If you are building OpenTimelineIO as a static library you will need to
45-
# defined OPENTIME_STATIC and OTIO_STATIC. If you use the provided CMake
45+
# define OPENTIME_STATIC and OTIO_STATIC. If you use the provided CMake
4646
# config files these will be automatically defined for you. To use the
4747
# provided config files add `find_package(OpenTimelineIO)` to your
4848
# CMakeLists.txt file.

examples/bundle.cpp

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// Copyright Contributors to the OpenTimelineIO project
33

4-
// Example OTIO script that can create and extract bundles.
4+
// Example OTIO program that can create and extract bundles.
5+
//
6+
// Usage:
7+
// * bundle (input.otio) (output.otioz)
8+
// Create an .otioz bundle from an .otio file.
9+
//
10+
// * bundle (input.otio) (output.otiod)
11+
// Create an .otiod bundle from an .otio file.
12+
//
13+
// * bundle (input.otioz) (output)
14+
// Extract an .otioz bundle.
515

616
#include "util.h"
717

@@ -11,9 +21,6 @@
1121

1222
#include <filesystem>
1323

14-
namespace otio = opentimelineio::OPENTIMELINEIO_VERSION;
15-
namespace bundle = opentimelineio::OPENTIMELINEIO_VERSION::bundle;
16-
1724
bool
1825
ends_with(std::string const& s, std::string const& find)
1926
{
@@ -27,6 +34,7 @@ ends_with(std::string const& s, std::string const& find)
2734
int
2835
main(int argc, char** argv)
2936
{
37+
// Command line arguments.
3038
if (argc != 3)
3139
{
3240
std::cout << "Usage:\n";
@@ -38,27 +46,29 @@ main(int argc, char** argv)
3846
<< "Extract an .otioz bundle.\n";
3947
return 1;
4048
}
41-
const std::string input = otio::to_unix_separators(argv[1]);
42-
const std::string output = otio::to_unix_separators(argv[2]);
49+
const std::string input = OTIO_NS::to_unix_separators(argv[1]);
50+
const std::string output = OTIO_NS::to_unix_separators(argv[2]);
4351

4452
if (ends_with(input, ".otio") && ends_with(output, ".otioz"))
4553
{
54+
// Create an .otioz bundle from an .otio file.
55+
4656
// Open timeline.
47-
otio::ErrorStatus error_status;
48-
otio::SerializableObject::Retainer<otio::Timeline> timeline(
49-
dynamic_cast<otio::Timeline*>(
50-
otio::Timeline::from_json_file(input, &error_status)));
51-
if (!timeline || otio::is_error(error_status))
57+
OTIO_NS::ErrorStatus error_status;
58+
OTIO_NS::SerializableObject::Retainer<OTIO_NS::Timeline> timeline(
59+
dynamic_cast<OTIO_NS::Timeline*>(
60+
OTIO_NS::Timeline::from_json_file(input, &error_status)));
61+
if (!timeline || OTIO_NS::is_error(error_status))
5262
{
5363
examples::print_error(error_status);
5464
return 1;
5565
}
5666

5767
// Create .otioz bundle.
58-
bundle::WriteOptions options;
68+
OTIO_NS::bundle::WriteOptions options;
5969
options.parent_path =
6070
std::filesystem::u8path(input).parent_path().u8string();
61-
if (!bundle::to_otioz(
71+
if (!OTIO_NS::bundle::to_otioz(
6272
timeline.value,
6373
output,
6474
options,
@@ -71,34 +81,36 @@ main(int argc, char** argv)
7181
else if (ends_with(input, ".otioz"))
7282
{
7383
// Extract .otioz bundle.
74-
bundle::OtiozReadOptions options;
84+
OTIO_NS::bundle::OtiozReadOptions options;
7585
options.extract_path = output;
76-
otio::ErrorStatus error_status;
77-
auto result = bundle::from_otioz(input, options, &error_status);
78-
if (otio::is_error(error_status))
86+
OTIO_NS::ErrorStatus error_status;
87+
auto result = OTIO_NS::bundle::from_otioz(input, options, &error_status);
88+
if (OTIO_NS::is_error(error_status))
7989
{
8090
examples::print_error(error_status);
8191
return 1;
8292
}
8393
}
8494
else if (ends_with(input, ".otio") && ends_with(output, ".otiod"))
8595
{
96+
// Create an .otiod bundle from an .otio file.
97+
8698
// Open timeline.
87-
otio::ErrorStatus error_status;
88-
otio::SerializableObject::Retainer<otio::Timeline> timeline(
89-
dynamic_cast<otio::Timeline*>(
90-
otio::Timeline::from_json_file(input, &error_status)));
91-
if (!timeline || otio::is_error(error_status))
99+
OTIO_NS::ErrorStatus error_status;
100+
OTIO_NS::SerializableObject::Retainer<OTIO_NS::Timeline> timeline(
101+
dynamic_cast<OTIO_NS::Timeline*>(
102+
OTIO_NS::Timeline::from_json_file(input, &error_status)));
103+
if (!timeline || OTIO_NS::is_error(error_status))
92104
{
93105
examples::print_error(error_status);
94106
return 1;
95107
}
96108

97109
// Create .otiod bundle.
98-
bundle::WriteOptions options;
110+
OTIO_NS::bundle::WriteOptions options;
99111
options.parent_path =
100112
std::filesystem::u8path(input).parent_path().u8string();
101-
if (!bundle::to_otiod(
113+
if (!OTIO_NS::bundle::to_otiod(
102114
timeline.value,
103115
output,
104116
options,

examples/util.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#undef min
2222
#endif // min
2323
#else // _WINDOWS
24-
#include <sys/stat.h>
2524
#include <sys/types.h>
2625
#include <dirent.h>
2726
#include <fnmatch.h>

src/opentimelineio/bundle.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
#include "opentimelineio/bundleUtils.h"
77

8-
namespace opentimelineio { namespace OPENTIMELINEIO_VERSION { namespace bundle {
8+
namespace opentimelineio { namespace OPENTIMELINEIO_VERSION {
9+
namespace bundle {
910

1011
size_t
1112
get_media_size(
@@ -42,4 +43,4 @@ get_media_size(
4243
}
4344

4445
} // namespace bundle
45-
}} // namespace opentimelineio::OPENTIMELINEIO_VERSION
46+
}} // namespace bundle::opentimelineio::OPENTIMELINEIO_VERSION

src/opentimelineio/bundle.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "opentimelineio/timeline.h"
77

88
namespace opentimelineio { namespace OPENTIMELINEIO_VERSION {
9-
109
namespace bundle {
1110

1211
/// @brief The current otioz version.
@@ -25,15 +24,15 @@ static std::string const otio_file = "content.otio";
2524
static std::string const media_dir = "media";
2625

2726
/// @brief This enumeration provides the bundle media reference policy.
28-
enum class MediaReferencePolicy
27+
enum class OTIO_API_TYPE MediaReferencePolicy
2928
{
3029
ErrorIfNotFile, ///< Return an error if there are any non-file media references.
3130
MissingIfNotFile, ///< Replace non-file media references with missing references.
3231
AllMissing ///< Replace all media references with missing references.
3332
};
3433

3534
/// @brief Options for writing bundles.
36-
struct WriteOptions
35+
struct OTIO_API_TYPE WriteOptions
3736
{
3837
/// @brief The parent path is used to locate media with relative paths. If
3938
/// parent path is empty, paths are relative to the current working directory.
@@ -50,7 +49,7 @@ struct WriteOptions
5049
};
5150

5251
/// @brief Options for reading .otioz bundles.
53-
struct OtiozReadOptions
52+
struct OTIO_API_TYPE OtiozReadOptions
5453
{
5554
/// @brief Extract the contents of the bundle to the given path. If the
5655
/// path is empty, the contents are not extracted, and only the timeline
@@ -59,15 +58,15 @@ struct OtiozReadOptions
5958
};
6059

6160
/// @brief Options for reading .otiod bundles.
62-
struct OtiodReadOptions
61+
struct OTIO_API_TYPE OtiodReadOptions
6362
{
6463
/// @brief Use absolute paths for media references.
6564
bool absolute_media_reference_paths = false;
6665
};
6766

6867
/// @brief Get the total size (in bytes) of the media files that will be
6968
/// put into the bundle.
70-
size_t get_media_size(
69+
OTIO_API size_t get_media_size(
7170
Timeline const* timeline,
7271
WriteOptions const& options = WriteOptions(),
7372
ErrorStatus* error_status = nullptr);
@@ -94,7 +93,7 @@ size_t get_media_size(
9493
/// @param file_name The bundle file name.
9594
/// @param options The bundle options.
9695
/// @param error_status The error status.
97-
bool to_otioz(
96+
OTIO_API bool to_otioz(
9897
Timeline const* timeline,
9998
std::string const& file_name,
10099
WriteOptions const& options = WriteOptions(),
@@ -105,7 +104,7 @@ bool to_otioz(
105104
/// @param file_name The bundle file name.
106105
/// @param output_dir The directory where the bundle will be extracted.
107106
/// @param error_status The error status.
108-
Timeline* from_otioz(
107+
OTIO_API Timeline* from_otioz(
109108
std::string const& file_name,
110109
OtiozReadOptions const& options = OtiozReadOptions(),
111110
ErrorStatus* error_status = nullptr);
@@ -122,7 +121,7 @@ Timeline* from_otioz(
122121
/// @param file_name The bundle file name.
123122
/// @param options The bundle options.
124123
/// @param error_status The error status.
125-
bool to_otiod(
124+
OTIO_API bool to_otiod(
126125
Timeline const* timeline,
127126
std::string const& file_name,
128127
WriteOptions const& options = WriteOptions(),
@@ -133,10 +132,10 @@ bool to_otiod(
133132
/// @param file_name The bundle file name.
134133
/// @param timeline_file_name Returns the timeline file name.
135134
/// @param error_status The error status.
136-
Timeline* from_otiod(
135+
OTIO_API Timeline* from_otiod(
137136
std::string const& file_name,
138137
OtiodReadOptions const& options = OtiodReadOptions(),
139138
ErrorStatus* error_status = nullptr);
140139

141140
} // namespace bundle
142-
}} // namespace opentimelineio::OPENTIMELINEIO_VERSION
141+
}} // namespace opentimelineio::OPENTIMELINEIO_VERSION::bundle

src/opentimelineio/bundleUtils.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
#include <sstream>
1414

15-
namespace opentimelineio { namespace OPENTIMELINEIO_VERSION { namespace bundle {
15+
namespace opentimelineio { namespace OPENTIMELINEIO_VERSION {
16+
namespace bundle {
1617

1718
std::string
1819
to_string(MediaReferencePolicy media_referenece_policy)

src/opentimelineio/bundleUtils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace opentimelineio { namespace OPENTIMELINEIO_VERSION {
1111
namespace bundle {
1212

1313
/// @brief Convert a media reference policy to a string.
14-
std::string to_string(MediaReferencePolicy);
14+
OTIO_API std::string to_string(MediaReferencePolicy);
1515

1616
/// @brief This maps absolute paths of media references to their relative
1717
/// paths in the bundle media directory.
@@ -26,7 +26,7 @@ typedef std::map<std::filesystem::path, std::filesystem::path> Manifest;
2626
/// This is considered an internal API.
2727
///
2828
/// Throws std::exception on errors.
29-
SerializableObject::Retainer<Timeline> timeline_for_bundle_and_manifest(
29+
OTIO_API SerializableObject::Retainer<Timeline> timeline_for_bundle_and_manifest(
3030
SerializableObject::Retainer<Timeline> const&,
3131
std::filesystem::path const& timeline_dir,
3232
MediaReferencePolicy media_reference_policy,

src/opentimelineio/errorStatus.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ ErrorStatus::outcome_to_string(Outcome o)
6767
case NOT_A_GAP:
6868
return "object is not descendent of Gap type";
6969
case BUNDLE_SIZE_ERROR:
70-
return "error compiting the size of the bundle";
70+
return "error computing the size of the bundle";
7171
case BUNDLE_WRITE_ERROR:
7272
return "error writing bundle";
7373
case BUNDLE_READ_ERROR:

src/opentimelineio/fileUtils.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55

66
#include <cstdio>
77
#include <filesystem>
8+
#include <iostream>
9+
10+
#if !defined(_WINDOWS)
11+
#include <stdlib.h>
12+
#include <unistd.h>
13+
#endif // _WINDOWS
814

915
namespace opentimelineio { namespace OPENTIMELINEIO_VERSION {
1016

@@ -18,11 +24,18 @@ to_unix_separators(std::string const& path)
1824

1925
std::string create_temp_dir()
2026
{
21-
// \todo Replace std::tmpnam(), since it is potentially unsafe. A possible
22-
// replacement might be mkdtemp(), but that does not seem to be available
23-
// on Cygwin.
27+
std::string out;
28+
#if defined(_WINDOWS)
29+
// \todo Replace std::tmpnam() since it is potentially unsafe.
2430
std::string const out(std::tmpnam(nullptr));
2531
std::filesystem::create_directory(out);
32+
#else // _WINDOWS
33+
std::string dir = std::filesystem::temp_directory_path() / "XXXXXX";
34+
if (mkdtemp(dir.data()))
35+
{
36+
out = dir;
37+
}
38+
#endif // _WINDOWS
2639
return out;
2740
}
2841

src/opentimelineio/fileUtils.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#pragma once
55

6+
#include "opentimelineio/export.h"
67
#include "opentimelineio/version.h"
78

89
namespace opentimelineio { namespace OPENTIMELINEIO_VERSION {
@@ -11,10 +12,12 @@ namespace opentimelineio { namespace OPENTIMELINEIO_VERSION {
1112
///@{
1213

1314
/// @brief Convert Windows path separators to UNIX path separators.
14-
std::string to_unix_separators(std::string const&);
15+
OTIO_API std::string to_unix_separators(std::string const&);
1516

16-
// Create a temporary directory.
17-
std::string create_temp_dir();
17+
/// @brief Create a temporary directory.
18+
///
19+
/// This function is only used for the tests and examples.
20+
OTIO_API std::string create_temp_dir();
1821

1922
///@}
2023

0 commit comments

Comments
 (0)