-
Notifications
You must be signed in to change notification settings - Fork 70
Refactor order of getting metadata and adding a stream #1060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -198,6 +198,34 @@ SeekMode seekModeFromString(std::string_view seekMode) { | |
| } | ||
| } | ||
|
|
||
| void writeFallbackBasedMetadata( | ||
| std::map<std::string, std::string>& map, | ||
| const StreamMetadata& streamMetadata, | ||
| SeekMode seekMode) { | ||
| auto durationSeconds = streamMetadata.getDurationSeconds(seekMode); | ||
| if (durationSeconds.has_value()) { | ||
| map["durationSeconds"] = std::to_string(durationSeconds.value()); | ||
| } | ||
|
|
||
| auto numFrames = streamMetadata.getNumFrames(seekMode); | ||
| if (numFrames.has_value()) { | ||
| map["numFrames"] = std::to_string(numFrames.value()); | ||
| } | ||
|
|
||
| double beginStreamSeconds = streamMetadata.getBeginStreamSeconds(seekMode); | ||
| map["beginStreamSeconds"] = std::to_string(beginStreamSeconds); | ||
|
|
||
| auto endStreamSeconds = streamMetadata.getEndStreamSeconds(seekMode); | ||
| if (endStreamSeconds.has_value()) { | ||
| map["endStreamSeconds"] = std::to_string(endStreamSeconds.value()); | ||
| } | ||
|
|
||
| auto averageFps = streamMetadata.getAverageFps(seekMode); | ||
| if (averageFps.has_value()) { | ||
| map["averageFps"] = std::to_string(averageFps.value()); | ||
| } | ||
| } | ||
|
|
||
| int checkedToPositiveInt(const std::string& str) { | ||
| int ret = 0; | ||
| try { | ||
|
|
@@ -917,30 +945,28 @@ std::string get_stream_json_metadata( | |
| // In approximate mode: content-based metadata does not exist for any stream. | ||
| // In custom_frame_mappings: content-based metadata exists only for the active | ||
| // stream. | ||
| // | ||
| // Our fallback logic assumes content-based metadata is available. | ||
| // It is available for decoding on the active stream, but would break | ||
| // when getting metadata from non-active streams. | ||
| if ((seekMode != SeekMode::custom_frame_mappings) || | ||
| (seekMode == SeekMode::custom_frame_mappings && | ||
| stream_index == activeStreamIndex)) { | ||
| if (streamMetadata.getDurationSeconds(seekMode).has_value()) { | ||
| map["durationSeconds"] = | ||
| std::to_string(streamMetadata.getDurationSeconds(seekMode).value()); | ||
| } | ||
| if (streamMetadata.getNumFrames(seekMode).has_value()) { | ||
| map["numFrames"] = | ||
| std::to_string(streamMetadata.getNumFrames(seekMode).value()); | ||
| } | ||
| map["beginStreamSeconds"] = | ||
| std::to_string(streamMetadata.getBeginStreamSeconds(seekMode)); | ||
| if (streamMetadata.getEndStreamSeconds(seekMode).has_value()) { | ||
| map["endStreamSeconds"] = | ||
| std::to_string(streamMetadata.getEndStreamSeconds(seekMode).value()); | ||
| } | ||
| if (streamMetadata.getAverageFps(seekMode).has_value()) { | ||
| map["averageFps"] = | ||
| std::to_string(streamMetadata.getAverageFps(seekMode).value()); | ||
| } | ||
| writeFallbackBasedMetadata(map, streamMetadata, seekMode); | ||
| } else if (seekMode == SeekMode::custom_frame_mappings) { | ||
| // If this is not the active stream, then we don't have content-based | ||
| // metadata for custom frame mappings. In that case, we want the same | ||
| // behavior as we would get with approximate mode. Encoding this behavior in | ||
| // the fallback logic itself is tricky and not worth it for this corner | ||
| // case. So we hardcode in approximate mode. | ||
| // | ||
| // TODO: This hacky behavior is only necessary because the custom frame | ||
| // mapping is supplied in SingleStreamDecoder::addVideoStream() rather | ||
| // than in the constructor. And it's supplied to addVideoStream() and | ||
| // not the constructor because we need to know the stream index. If we | ||
| // can encode the relevant stream indices into custom frame mappings | ||
| // itself, then we can put it in the constructor. | ||
| writeFallbackBasedMetadata(map, streamMetadata, SeekMode::approximate); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand these workarounds are needed right now, but I have a really hard time cleanly reasoning about all the comments above. We might eventually want to revisit the existence of We still want to enable existing use-cases of users getting metadata without having to scan, but I'm pretty sure we can support that by passing approximate mode (that's what we do from the public Python APIs).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @NicolasHug, you're right, that's actually the cleanest resolution here: there's no value any more in differentiating the constructor from adding a stream. Created #1064 for follow-up.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To double check my understanding, the expected behaviour for custom frame mappings is
The reason we have to make this distinction with these conditions is because we don't know the active stream index during construction (since we
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your understanding is correct @mollyxu ! |
||
| } | ||
|
|
||
| return mapToJson(map); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.