Skip to content

Commit fcab52e

Browse files
committed
Restore changes
Signed-off-by: Darby Johnston <[email protected]>
1 parent d03456c commit fcab52e

29 files changed

+2215
-513
lines changed

src/deps/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ endif()
3030

3131
if(NOT OTIO_FIND_IMATH)
3232
set(BUILD_SHARED_LIBS OFF)
33+
add_subdirectory(Imath)
3334
endif()
3435

3536
if(NOT OTIO_FIND_MINIZIP_NG)

src/opentimelineio/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
set(OPENTIMELINEIO_HEADER_FILES
55
anyDictionary.h
66
anyVector.h
7+
bundle.h
8+
bundleUtils.h
79
color.h
810
clip.h
911
composable.h
@@ -13,6 +15,7 @@ set(OPENTIMELINEIO_HEADER_FILES
1315
effect.h
1416
errorStatus.h
1517
externalReference.h
18+
fileUtils.h
1619
freezeFrame.h
1720
gap.h
1821
generatorReference.h
@@ -36,10 +39,13 @@ set(OPENTIMELINEIO_HEADER_FILES
3639
transition.h
3740
typeRegistry.h
3841
unknownSchema.h
42+
urlUtils.h
3943
vectorIndexing.h
4044
version.h)
4145

4246
add_library(opentimelineio ${OTIO_SHARED_OR_STATIC_LIB}
47+
bundle.cpp
48+
bundleUtils.cpp
4349
color.cpp
4450
clip.cpp
4551
composable.cpp
@@ -49,6 +55,7 @@ add_library(opentimelineio ${OTIO_SHARED_OR_STATIC_LIB}
4955
effect.cpp
5056
errorStatus.cpp
5157
externalReference.cpp
58+
fileUtils.cpp
5259
freezeFrame.cpp
5360
gap.cpp
5461
generatorReference.cpp
@@ -58,6 +65,8 @@ add_library(opentimelineio ${OTIO_SHARED_OR_STATIC_LIB}
5865
marker.cpp
5966
mediaReference.cpp
6067
missingReference.cpp
68+
otiod.cpp
69+
otioz.cpp
6170
safely_typed_any.cpp
6271
serializableCollection.cpp
6372
serializableObject.cpp
@@ -74,6 +83,7 @@ add_library(opentimelineio ${OTIO_SHARED_OR_STATIC_LIB}
7483
transition.cpp
7584
typeRegistry.cpp
7685
unknownSchema.cpp
86+
urlUtils.cpp
7787
CORE_VERSION_MAP.cpp
7888
${OPENTIMELINEIO_HEADER_FILES})
7989

src/opentimelineio/OpenTimelineIOConfig.cmake.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
include(CMakeFindDependencyMacro)
44
find_dependency(OpenTime)
55
find_dependency(Imath)
6+
find_dependency(minizip)
67

78
include("${CMAKE_CURRENT_LIST_DIR}/OpenTimelineIOTargets.cmake")

src/opentimelineio/bundle.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright Contributors to the OpenTimelineIO project
3+
4+
#include "opentimelineio/bundle.h"
5+
6+
#include "opentimelineio/bundleUtils.h"
7+
8+
namespace opentimelineio { namespace OPENTIMELINEIO_VERSION { namespace bundle {
9+
10+
size_t
11+
get_media_size(
12+
Timeline const* timeline,
13+
WriteOptions const& options,
14+
ErrorStatus* error_status)
15+
{
16+
size_t byte_count = 0;
17+
try
18+
{
19+
// Get the file manifest.
20+
std::map<std::filesystem::path, std::filesystem::path> manifest;
21+
timeline_for_bundle_and_manifest(
22+
timeline,
23+
std::filesystem::u8path(options.parent_path),
24+
options.media_policy,
25+
manifest);
26+
27+
// Count the bytes in each file.
28+
for (auto const& file: manifest)
29+
{
30+
byte_count += std::filesystem::file_size(file.first);
31+
}
32+
}
33+
catch (std::exception const& e)
34+
{
35+
if (error_status)
36+
{
37+
*error_status =
38+
ErrorStatus(ErrorStatus::BUNDLE_SIZE_ERROR, e.what());
39+
}
40+
}
41+
return byte_count;
42+
}
43+
44+
} // namespace bundle
45+
}} // namespace opentimelineio::OPENTIMELINEIO_VERSION

src/opentimelineio/bundle.h

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright Contributors to the OpenTimelineIO project
3+
4+
#pragma once
5+
6+
#include "opentimelineio/timeline.h"
7+
8+
namespace opentimelineio { namespace OPENTIMELINEIO_VERSION {
9+
10+
namespace bundle {
11+
12+
/// @brief The current otioz version.
13+
static std::string const otioz_version = "1.0.0";
14+
15+
/// @brief The current otiod version.
16+
static std::string const otiod_version = "1.0.0";
17+
18+
/// @brief The version file name in the bundle.
19+
static std::string const version_file = "version.txt";
20+
21+
/// @brief The OTIO file name in the bundle.
22+
static std::string const otio_file = "content.otio";
23+
24+
/// @brief The media directory name in the bundle.
25+
static std::string const media_dir = "media";
26+
27+
/// @brief This enumeration provides the bundle media reference policy.
28+
enum class MediaReferencePolicy
29+
{
30+
ErrorIfNotFile, ///< Return an error if there are any non-file media references.
31+
MissingIfNotFile, ///< Replace non-file media references with missing references.
32+
AllMissing ///< Replace all media references with missing references.
33+
};
34+
35+
/// @brief Options for writing bundles.
36+
struct WriteOptions
37+
{
38+
/// @brief The parent path is used to locate media with relative paths. If
39+
/// parent path is empty, paths are relative to the current working directory.
40+
std::string parent_path;
41+
42+
/// @brief The bundle media reference policy.
43+
MediaReferencePolicy media_policy = MediaReferencePolicy::ErrorIfNotFile;
44+
45+
/// @todo Add comment.
46+
schema_version_map const* target_family_label_spec = nullptr;
47+
48+
/// @brief The number of spaces to use for JSON indentation.
49+
int indent = 4;
50+
};
51+
52+
/// @brief Options for reading .otioz bundles.
53+
struct OtiozReadOptions
54+
{
55+
/// @brief Extract the contents of the bundle to the given path. If the
56+
/// path is empty, the contents are not extracted, and only the timeline
57+
/// is read from the bundle.
58+
std::string extract_path;
59+
};
60+
61+
/// @brief Options for reading .otiod bundles.
62+
struct OtiodReadOptions
63+
{
64+
/// @brief Use absolute paths for media references.
65+
bool absolute_media_reference_paths = false;
66+
};
67+
68+
/// @brief Get the total size (in bytes) of the media files that will be
69+
/// put into the bundle.
70+
size_t get_media_size(
71+
Timeline const* timeline,
72+
WriteOptions const& options = WriteOptions(),
73+
ErrorStatus* error_status = nullptr);
74+
75+
/// @brief Write a timeline and it's referenced media to an .otioz bundle.
76+
///
77+
/// Takes as input a timeline that has media references which are all
78+
/// ExternalReferences, with target_urls to files with unique basenames that are
79+
/// accessible through the file system. The timeline .otio file, a version file,
80+
/// and media references are bundled into a single zip file with the suffix
81+
/// .otioz.
82+
///
83+
/// The timline .otio file and version file are compressed using the ZIP
84+
/// "deflate" mode. All media files are store uncompressed.
85+
///
86+
/// Can error out if files are not locally referenced. or provide missing
87+
/// references.
88+
///
89+
/// Note that .otioz files _always_ use the unix style path separator ('/').
90+
/// This ensures that regardless of which platform a bundle was created on, it
91+
/// can be read on UNIX and Windows platforms.
92+
///
93+
/// @param timeline The timeline to write.
94+
/// @param file_name The bundle file name.
95+
/// @param options The bundle options.
96+
/// @param error_status The error status.
97+
bool to_otioz(
98+
Timeline const* timeline,
99+
std::string const& file_name,
100+
WriteOptions const& options = WriteOptions(),
101+
ErrorStatus* error_status = nullptr);
102+
103+
/// @brief Read a timeline from an .otioz bundle.
104+
///
105+
/// @param file_name The bundle file name.
106+
/// @param output_dir The directory where the bundle will be extracted.
107+
/// @param error_status The error status.
108+
Timeline* from_otioz(
109+
std::string const& file_name,
110+
OtiozReadOptions const& options = OtiozReadOptions(),
111+
ErrorStatus* error_status = nullptr);
112+
113+
/// @brief Write a timeline and it's referenced media to an .otiod bundle.
114+
///
115+
/// Takes as input a timeline that has media references which are all
116+
/// ExternalReferences, with target_urls to files with unique basenames that are
117+
/// accessible through the file system. The timeline .otio file, a version file,
118+
/// and media references are bundled into a single directory named with a
119+
/// suffix of .otiod.
120+
///
121+
/// @param timeline The timeline to write.
122+
/// @param file_name The bundle file name.
123+
/// @param options The bundle options.
124+
/// @param error_status The error status.
125+
bool to_otiod(
126+
Timeline const* timeline,
127+
std::string const& file_name,
128+
WriteOptions const& options = WriteOptions(),
129+
ErrorStatus* error_status = nullptr);
130+
131+
/// @brief Read a timeline from an .otiod bundle.
132+
///
133+
/// @param file_name The bundle file name.
134+
/// @param timeline_file_name Returns the timeline file name.
135+
/// @param error_status The error status.
136+
Timeline* from_otiod(
137+
std::string const& file_name,
138+
OtiodReadOptions const& options = OtiodReadOptions(),
139+
ErrorStatus* error_status = nullptr);
140+
141+
} // namespace bundle
142+
}} // namespace opentimelineio::OPENTIMELINEIO_VERSION

0 commit comments

Comments
 (0)