Skip to content

Commit

Permalink
Add the size to video data
Browse files Browse the repository at this point in the history
  • Loading branch information
darbyjohnston committed Mar 18, 2024
1 parent d8ac60e commit adb8506
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 91 deletions.
5 changes: 2 additions & 3 deletions examples/render/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ namespace tl
compare.push_back(timeline::Timeline::create(_options.compareFileName, _context));
}
_player->setCompare(compare);
_videoSizes = _player->getSizes();
_videoDataObserver = observer::ListObserver<timeline::VideoData>::create(
_player->observeCurrentVideo(),
[this](const std::vector<timeline::VideoData>& value)
Expand Down Expand Up @@ -404,7 +403,7 @@ namespace tl
const float viewportAspect = viewportSize.getAspect();
const math::Size2i renderSize = timeline::getRenderSize(
compareOptions.mode,
_videoSizes);
_videoData);
const float renderSizeAspect = renderSize.getAspect();
image::Size transformSize;
math::Vector2f transformOffset;
Expand Down Expand Up @@ -440,7 +439,7 @@ namespace tl
math::translate(math::Vector3f(-renderSize.w / 2, -renderSize.h / 2, 0.F)));
_render->drawVideo(
_videoData,
timeline::getBoxes(compareOptions.mode, _videoSizes),
timeline::getBoxes(compareOptions.mode, _videoData),
{},
{},
compareOptions);
Expand Down
1 change: 0 additions & 1 deletion examples/render/render.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ namespace tl
Options _options;

std::shared_ptr<timeline::Player> _player;
std::vector<image::Size> _videoSizes;

std::shared_ptr<gl::GLFWWindow> _window;
math::Size2i _frameBufferSize;
Expand Down
11 changes: 2 additions & 9 deletions lib/tlDevice/BMDOutputDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ namespace tl
otime::TimeRange timeRange = time::invalidTimeRange;
timeline::Playback playback = timeline::Playback::Stop;
otime::RationalTime currentTime = time::invalidTime;
std::vector<image::Size> sizes;
std::vector<timeline::VideoData> videoData;
std::shared_ptr<image::Image> overlay;
float volume = 1.F;
Expand All @@ -98,7 +97,6 @@ namespace tl
double viewZoom = 1.0;
bool frameView = true;
otime::TimeRange timeRange = time::invalidTimeRange;
std::vector<image::Size> sizes;
std::vector<timeline::VideoData> videoData;
std::shared_ptr<image::Image> overlay;

Expand Down Expand Up @@ -466,12 +464,10 @@ namespace tl
p.mutex.playback = timeline::Playback::Stop;
p.mutex.currentTime = time::invalidTime;
}
p.mutex.sizes.clear();
p.mutex.videoData.clear();
p.mutex.audioData.clear();
if (p.player)
{
p.mutex.sizes = p.player->getSizes();
p.mutex.videoData = p.player->getCurrentVideo();
p.mutex.audioData = p.player->getCurrentAudio();
}
Expand Down Expand Up @@ -554,7 +550,6 @@ namespace tl
_p->thread.timeRange != _p->mutex.timeRange ||
playback != _p->mutex.playback ||
currentTime != _p->mutex.currentTime ||
_p->thread.sizes != _p->mutex.sizes ||
_p->thread.videoData != _p->mutex.videoData ||
_p->thread.overlay != _p->mutex.overlay ||
volume != _p->mutex.volume ||
Expand Down Expand Up @@ -586,7 +581,6 @@ namespace tl
p.thread.viewPos != p.mutex.viewPos ||
p.thread.viewZoom != p.mutex.viewZoom ||
p.thread.frameView != p.mutex.frameView ||
p.thread.sizes != p.mutex.sizes ||
p.thread.videoData != p.mutex.videoData ||
p.thread.overlay != p.mutex.overlay;
ocioOptions = p.mutex.ocioOptions;
Expand All @@ -600,7 +594,6 @@ namespace tl
p.thread.viewPos = p.mutex.viewPos;
p.thread.viewZoom = p.mutex.viewZoom;
p.thread.frameView = p.mutex.frameView;
p.thread.sizes = p.mutex.sizes;
p.thread.videoData = p.mutex.videoData;
p.thread.overlay = p.mutex.overlay;

Expand Down Expand Up @@ -925,7 +918,7 @@ namespace tl
// Create the offscreen buffer.
const math::Size2i renderSize = timeline::getRenderSize(
compareOptions.mode,
p.thread.sizes);
p.thread.videoData);
gl::OffscreenBufferOptions offscreenBufferOptions;
offscreenBufferOptions.colorType = getOffscreenType(p.thread.outputPixelType);
if (!displayOptions.empty())
Expand Down Expand Up @@ -977,7 +970,7 @@ namespace tl
{
p.thread.render->drawVideo(
p.thread.videoData,
timeline::getBoxes(compareOptions.mode, p.thread.sizes),
timeline::getBoxes(compareOptions.mode, p.thread.videoData),
imageOptions,
displayOptions,
compareOptions,
Expand Down
5 changes: 0 additions & 5 deletions lib/tlQt/TimelinePlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,6 @@ namespace tl
return _p->player->getIOInfo();
}

std::vector<image::Size> TimelinePlayer::sizes() const
{
return _p->player->getSizes();
}

double TimelinePlayer::defaultSpeed() const
{
return _p->player->getDefaultSpeed();
Expand Down
3 changes: 0 additions & 3 deletions lib/tlQt/TimelinePlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,6 @@ namespace tl
//! the first clip in the timeline.
const io::Info& ioInfo() const;

//! Get the timeline sizes.
std::vector<image::Size> sizes() const;

///@}

//! \name Playback
Expand Down
11 changes: 3 additions & 8 deletions lib/tlQtWidget/TimelineViewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ namespace tl
p.render->begin(viewportSize);
p.render->setOCIOOptions(p.ocioOptions);
p.render->setLUTOptions(p.lutOptions);
if (p.player && !p.videoData.empty())
if (!p.videoData.empty())
{
math::Matrix4x4f vm;
vm = vm * math::translate(math::Vector3f(p.viewPos.x, p.viewPos.y, 0.F));
Expand All @@ -394,7 +394,7 @@ namespace tl
p.render->setTransform(pm * vm);
p.render->drawVideo(
p.videoData,
timeline::getBoxes(p.compareOptions.mode, p.player->sizes()),
timeline::getBoxes(p.compareOptions.mode, p.videoData),
p.imageOptions,
p.displayOptions,
p.compareOptions,
Expand Down Expand Up @@ -615,12 +615,7 @@ namespace tl
math::Size2i TimelineViewport::_renderSize() const
{
TLRENDER_P();
math::Size2i out;
if (p.player)
{
out = timeline::getRenderSize(p.compareOptions.mode, p.player->sizes());
}
return out;
return timeline::getRenderSize(p.compareOptions.mode, p.videoData);
}

void TimelineViewport::_frameView()
Expand Down
22 changes: 11 additions & 11 deletions lib/tlTimeline/CompareOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ namespace tl
TLRENDER_ENUM_IMPL(CompareTimeMode, "Relative", "Absolute");
TLRENDER_ENUM_SERIALIZE_IMPL(CompareTimeMode);

std::vector<math::Box2i> getBoxes(CompareMode mode, const std::vector<image::Size>& sizes)
std::vector<math::Box2i> getBoxes(CompareMode mode, const std::vector<VideoData>& videoData)
{
std::vector<math::Box2i> out;
const size_t count = sizes.size();
const size_t count = videoData.size();
switch (mode)
{
case CompareMode::Horizontal:
{
image::Size size;
if (count > 0)
{
size = sizes[0];
size = videoData[0].size;
}
if (count > 0)
{
Expand All @@ -67,7 +67,7 @@ namespace tl
image::Size size;
if (count > 0)
{
size = sizes[0];
size = videoData[0].size;
}
if (count > 0)
{
Expand All @@ -91,9 +91,9 @@ namespace tl
if (count > 0)
{
image::Size tileSize;
for (const auto& i : sizes)
for (const auto& i : videoData)
{
tileSize = std::max(tileSize, i);
tileSize = std::max(tileSize, i.size);
}

int columns = 0;
Expand All @@ -119,7 +119,7 @@ namespace tl
{
if (i < count)
{
const auto& s = sizes[i];
const auto& s = videoData[i].size;
const math::Box2i box(
x,
y,
Expand All @@ -139,19 +139,19 @@ namespace tl
out.push_back(math::Box2i(
0,
0,
sizes[0].w * sizes[0].pixelAspectRatio,
sizes[0].h));
videoData[0].size.w * videoData[0].size.pixelAspectRatio,
videoData[0].size.h));
}
break;
}
return out;
}

math::Size2i getRenderSize(CompareMode mode, const std::vector<image::Size>& sizes)
math::Size2i getRenderSize(CompareMode mode, const std::vector<VideoData>& videoData)
{
math::Size2i out;
math::Box2i box;
const auto boxes = getBoxes(mode, sizes);
const auto boxes = getBoxes(mode, videoData);
if (!boxes.empty())
{
box = boxes[0];
Expand Down
8 changes: 3 additions & 5 deletions lib/tlTimeline/CompareOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

#pragma once

#include <tlCore/Image.h>
#include <tlCore/Size.h>
#include <tlCore/Time.h>
#include <tlTimeline/Video.h>

namespace tl
{
Expand Down Expand Up @@ -55,10 +53,10 @@ namespace tl
};

//! Get the boxes for the given compare mode and sizes.
std::vector<math::Box2i> getBoxes(CompareMode, const std::vector<image::Size>&);
std::vector<math::Box2i> getBoxes(CompareMode, const std::vector<VideoData>&);

//! Get the render size for the given compare mode and sizes.
math::Size2i getRenderSize(CompareMode, const std::vector<image::Size>&);
math::Size2i getRenderSize(CompareMode, const std::vector<VideoData>&);

//! Get a compare time.
otime::RationalTime getCompareTime(
Expand Down
16 changes: 0 additions & 16 deletions lib/tlTimeline/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,22 +393,6 @@ namespace tl
return _p->ioInfo;
}

std::vector<image::Size> Player::getSizes() const
{
TLRENDER_P();
std::vector<image::Size> out;
out.push_back(!_p->ioInfo.video.empty() ?
_p->ioInfo.video.front().size :
image::Size());
for (const auto& compare : p.compare->get())
{
out.push_back(compare && !compare->getIOInfo().video.empty() ?
compare->getIOInfo().video.front().size :
image::Size());
}
return out;
}

double Player::getDefaultSpeed() const
{
return _p->timeline->getTimeRange().duration().rate();
Expand Down
3 changes: 0 additions & 3 deletions lib/tlTimeline/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@ namespace tl
//! the first clip in the timeline.
const io::Info& getIOInfo() const;

//! Get the timeline sizes.
std::vector<image::Size> getSizes() const;

///@}

//! \name Playback
Expand Down
4 changes: 4 additions & 0 deletions lib/tlTimeline/TimelinePrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ namespace tl
if (valid)
{
VideoData data;
if (!ioInfo.video.empty())
{
data.size = ioInfo.video.front().size;
}
data.time = (*videoRequestIt)->time;
try
{
Expand Down
1 change: 1 addition & 0 deletions lib/tlTimeline/Video.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace tl
//! Video data.
struct VideoData
{
image::Size size;
otime::RationalTime time = time::invalidTime;
std::vector<VideoLayer> layers;

Expand Down
1 change: 1 addition & 0 deletions lib/tlTimeline/VideoInline.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace tl
inline bool VideoData::operator == (const VideoData& other) const
{
return
size == other.size &&
time::compareExact(time, other.time) &&
layers == other.layers;
}
Expand Down
9 changes: 3 additions & 6 deletions lib/tlTimelineGL/RenderVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ namespace tl
boxes[0].h());
gl::OffscreenBufferOptions offscreenBufferOptions;
offscreenBufferOptions.colorType = gl::offscreenColorDefault;
if (!imageOptions.empty())
if (!displayOptions.empty())
{
offscreenBufferOptions.colorFilters = displayOptions[0].imageFilters;
}
Expand Down Expand Up @@ -467,7 +467,7 @@ namespace tl
{
offscreenBufferOptions = gl::OffscreenBufferOptions();
offscreenBufferOptions.colorType = gl::offscreenColorDefault;
if (imageOptions.size() > 1)
if (displayOptions.size() > 1)
{
offscreenBufferOptions.colorFilters = displayOptions[1].imageFilters;
}
Expand Down Expand Up @@ -625,10 +625,7 @@ namespace tl
const math::Size2i& offscreenBufferSize = box.getSize();
gl::OffscreenBufferOptions offscreenBufferOptions;
offscreenBufferOptions.colorType = gl::offscreenColorDefault;
if (imageOptions.get())
{
offscreenBufferOptions.colorFilters = displayOptions.imageFilters;
}
offscreenBufferOptions.colorFilters = displayOptions.imageFilters;
if (doCreate(
p.buffers["video"],
offscreenBufferSize,
Expand Down
11 changes: 3 additions & 8 deletions lib/tlTimelineUI/TimelineViewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ namespace tl
event.render->clearViewport(image::Color4f(0.F, 0.F, 0.F));
event.render->setOCIOOptions(p.ocioOptions);
event.render->setLUTOptions(p.lutOptions);
if (p.player && !p.videoData.empty())
if (!p.videoData.empty())
{
math::Matrix4x4f vm;
vm = vm * math::translate(math::Vector3f(p.viewPos.x, p.viewPos.y, 0.F));
Expand All @@ -373,7 +373,7 @@ namespace tl
event.render->setTransform(pm * vm);
event.render->drawVideo(
p.videoData,
timeline::getBoxes(p.compareOptions.mode, p.player->getSizes()),
timeline::getBoxes(p.compareOptions.mode, p.videoData),
p.imageOptions,
p.displayOptions,
p.compareOptions,
Expand Down Expand Up @@ -526,12 +526,7 @@ namespace tl
math::Size2i TimelineViewport::_getRenderSize() const
{
TLRENDER_P();
math::Size2i out;
if (p.player)
{
out = timeline::getRenderSize(p.compareOptions.mode, p.player->getSizes());
}
return out;
return timeline::getRenderSize(p.compareOptions.mode, p.videoData);
}

math::Vector2i TimelineViewport::_getViewportCenter() const
Expand Down
Loading

0 comments on commit adb8506

Please sign in to comment.