Skip to content

Conversation

@ssteinbach
Copy link
Collaborator

@ssteinbach ssteinbach commented Sep 4, 2018

Hi all, this pull request adds a new subdirectory, cpp_api in which a test implementation of opentime in C++ resides, along with a pybind11 python binding. I've also copied in the test_opentime.py suite so you can see what changes had to be made in order to make things pass. This is intended more to draw out conversation and feedback, and to serve as a reference point for conversations with folks we're having about a C++ API. Let us know if you have any thoughts!

Before this can be merged in:

  • need to integrate or replace the CMake build system with the top level setup.py
  • to to move this library so that the resulting library gets put in a place where the normal opentimelineio module can find it
  • There are some outstanding TODOs
  • Should make decisions about memory management in the library and other low level policy decisions that C++ draws out (extern c bindings, exceptions, etc).

Thanks everyone!

Quick Reminder If you're curious about some of the previous discussion around this issue, see:
https://github.com/PixarAnimationStudios/OpenTimelineIO/wiki/Wrapping-OTIO-C-or-C-Plus-Plus-In-Python

@ssteinbach ssteinbach self-assigned this Sep 4, 2018
@ssteinbach ssteinbach added the WIP Work In Progress (Not ready to merge yet) label Sep 4, 2018
// number of decimal places, if you just std::cerr << total_seconds
/* DEBUG_PRINT(total_seconds); */

auto try2 = time_obj.value_rescaled_to(1.0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try2?

Copy link
Collaborator

@meshula meshula left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to see!

In addition to nerfing out exceptions, and considering whether or not exact time representation is a requirement, I'd recommend an adaptor for std::chrono as well.

&& not ARRAY_CONTAINS(VALID_NON_DROPFRAME_TIMECODE_RATES, rate)
)
{
throw std::invalid_argument(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw would be most unpleasant in a validate function. Maybe return a std::error_code if you wish more granularity than true and false.

// @TODO: Is this the right policy for C++
if (time_obj.value < 0)
{
throw std::invalid_argument("time_obj has a negative value");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"negative value" would be one of those error_codes. I'd prefer not to have to right exception handling code around something as foundational as to_timecode. I'd suggest returning std::pair<std::error_code, std::string> and use error_code::success as the check value.

}
else
{
if (rate == static_cast<rt_rate_t>(29.97))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably going to need something more subtle here, as there are PAL rates to consider as well. Probably don't want to get into exhaustively enumerating all of them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, good call. At the moment, this is what the python implementation is doing, so if its wrong here, its wrong there too. Do you have any suggestions about what that more subtle thing might be?

{
if (ARRAY_CONTAINS(time_str, ';'))
{
throw std::invalid_argument("Drop frame timecode not supported.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto on a std::pair<std::error_code, ...> return, exception allergy in play :)

{
return (
(std::hash<opentime::rt_value_t>{}(rt.value))
^ ((std::hash<opentime::rt_rate_t>{}(rt.rate)) >> 1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a robust hash_combine is considered

hash = hash1 ^ (hash2 + 0x9e3779b9 + (hash1<<6) + (hash1>>2);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, I'll snag that. There is another question: do you think these types should be hashable? I'm open to making them not hashable.

bool validate_timecode_rate(const rt_rate_t rate);

/// A point in time, value*rate samples after 0.
class RationalTime
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RationalTime classes usually carry an expectation of allowing exact representations, which would require at least templating rt_value_t and rt_rate_t.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we've talked about that but haven't built that out yet. I'm open to that as well. Thanks!

@ssteinbach ssteinbach added this to the 1.0 Release milestone Sep 7, 2018
@MartinDelille
Copy link

@ssteinbach I'm very interested into seing this PR merged. How can I help?

@MartinDelille MartinDelille mentioned this pull request Nov 3, 2018
@ssteinbach
Copy link
Collaborator Author

See #391

@ssteinbach ssteinbach closed this Mar 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

WIP Work In Progress (Not ready to merge yet)

Projects

Status: On Hold

Development

Successfully merging this pull request may close these issues.

4 participants