Skip to content

Commit

Permalink
Timeline: Add constructor accepting ReaderInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdnyc committed Apr 1, 2021
1 parent 367ab51 commit 8227a91
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 25 deletions.
20 changes: 12 additions & 8 deletions examples/Example.cpp
Expand Up @@ -31,8 +31,10 @@
#include <fstream>
#include <iostream>
#include <memory>
#include "OpenShot.h"
#include "CrashHandler.h"
#include "Clip.h"
#include "Frame.h"
#include "FFmpegReader.h"
#include "Timeline.h"

using namespace openshot;

Expand All @@ -53,16 +55,17 @@ int main(int argc, char* argv[]) {
const auto time1 = std::chrono::high_resolution_clock::now();
std::shared_ptr<Frame> f = r9.GetFrame(frame);
const auto time2 = std::chrono::high_resolution_clock::now();
std::cout << "FFmpegReader: " << frame << " (" << double_ms(time2 - time1).count() << " ms)" << std::endl;
std::cout << "FFmpegReader: " << frame
<< " (" << double_ms(time2 - time1).count() << " ms)\n";
}
const auto total_2 = std::chrono::high_resolution_clock::now();
auto total_sec = std::chrono::duration_cast<ms>(total_2 - total_1);
std::cout << "FFmpegReader TOTAL: " << total_sec.count() << " ms" << std::endl;
std::cout << "FFmpegReader TOTAL: " << total_sec.count() << " ms\n";
r9.Close();


// Timeline Reader performance test
Timeline tm(r9.info.width, r9.info.height, r9.info.fps, r9.info.sample_rate, r9.info.channels, r9.info.channel_layout);
Timeline tm(r9.info);
Clip *c = new Clip(&r9);
tm.AddClip(c);
tm.Open();
Expand All @@ -73,14 +76,15 @@ int main(int argc, char* argv[]) {
const auto time1 = std::chrono::high_resolution_clock::now();
std::shared_ptr<Frame> f = tm.GetFrame(frame);
const auto time2 = std::chrono::high_resolution_clock::now();
std::cout << "Timeline: " << frame << " (" << double_ms(time2 - time1).count() << " ms)" << std::endl;
std::cout << "Timeline: " << frame
<< " (" << double_ms(time2 - time1).count() << " ms)\n";
}
const auto total_4 = std::chrono::high_resolution_clock::now();
total_sec = std::chrono::duration_cast<ms>(total_4 - total_3);
std::cout << "Timeline TOTAL: " << total_sec.count() << " ms" << std::endl;
std::cout << "Timeline TOTAL: " << total_sec.count() << " ms\n";
tm.Close();

std::cout << "Completed successfully!" << std::endl;
std::cout << "Completed successfully!\n";

return 0;
}
14 changes: 14 additions & 0 deletions src/Timeline.cpp
Expand Up @@ -29,8 +29,17 @@
*/

#include "Timeline.h"

#include "CacheBase.h"
#include "CacheDisk.h"
#include "CacheMemory.h"
#include "CrashHandler.h"
#include "FrameMapper.h"
#include "Exceptions.h"

#include <QDir>
#include <QFileInfo>

using namespace openshot;

// Default Constructor for the timeline (which sets the canvas width and height)
Expand Down Expand Up @@ -78,6 +87,11 @@ Timeline::Timeline(int width, int height, Fraction fps, int sample_rate, int cha
SetMaxSize(info.width, info.height);
}

// Delegating constructor that copies parameters from a provided ReaderInfo
Timeline::Timeline(const ReaderInfo info) :
Timeline::Timeline(info.width, info.height, info.fps, info.sample_rate,
info.channels, info.channel_layout) {};

// Constructor for the timeline (which loads a JSON structure from a file path, and initializes a timeline)
Timeline::Timeline(const std::string& projectPath, bool convert_absolute_paths) :
is_open(false), auto_map_clips(true), managed_cache(true), path(projectPath),
Expand Down
25 changes: 12 additions & 13 deletions src/Timeline.h
Expand Up @@ -38,28 +38,23 @@
#include <QtGui/QImage>
#include <QtGui/QPainter>
#include <QtCore/QRegularExpression>
#include "CacheBase.h"
#include "CacheDisk.h"
#include "CacheMemory.h"
#include "TimelineBase.h"
#include "ReaderBase.h"

#include "Color.h"
#include "Clip.h"
#include "CrashHandler.h"
#include "Point.h"
#include "EffectBase.h"
#include "Effects.h"
#include "EffectInfo.h"
#include "Fraction.h"
#include "Frame.h"
#include "FrameMapper.h"
#include "KeyFrame.h"
#include "OpenMPUtilities.h"
#include "ReaderBase.h"
#include "Settings.h"
#include "TimelineBase.h"


namespace openshot {

// Forward decls
class FrameMapper;
class CacheBase;

/// Comparison method for sorting clip pointers (by Layer and then Position). Clips are sorted
/// from lowest layer to top layer (since that is the sequence they need to be combined), and then
/// by position (left to right).
Expand Down Expand Up @@ -222,7 +217,7 @@ namespace openshot {

public:

/// @brief Default Constructor for the timeline (which configures the default frame properties)
/// @brief Constructor for the timeline (which configures the default frame properties)
/// @param width The image width of generated openshot::Frame objects
/// @param height The image height of generated openshot::Frame objects
/// @param fps The frame rate of the generated video
Expand All @@ -231,6 +226,10 @@ namespace openshot {
/// @param channel_layout The channel layout (i.e. mono, stereo, 3 point surround, etc...)
Timeline(int width, int height, openshot::Fraction fps, int sample_rate, int channels, openshot::ChannelLayout channel_layout);

/// @brief Constructor which takes a ReaderInfo struct to configure parameters
/// @param info The reader parameters to configure the new timeline with
Timeline(ReaderInfo info);

/// @brief Project-file constructor for the timeline
///
/// Loads a JSON structure from a file path, and
Expand Down
25 changes: 21 additions & 4 deletions tests/Timeline_Tests.cpp
Expand Up @@ -50,25 +50,43 @@ SUITE(Timeline)

TEST(Constructor)
{
// Create a default fraction (should be 1/1)
Fraction fps(30000,1000);
Timeline t1(640, 480, fps, 44100, 2, LAYOUT_STEREO);

// Check values
CHECK_EQUAL(640, t1.info.width);
CHECK_EQUAL(480, t1.info.height);

// Create a default fraction (should be 1/1)
Timeline t2(300, 240, fps, 44100, 2, LAYOUT_STEREO);

// Check values
CHECK_EQUAL(300, t2.info.width);
CHECK_EQUAL(240, t2.info.height);
}

TEST(ReaderInfo_Constructor)
{
// Create a reader
stringstream path;
path << TEST_MEDIA_PATH << "test.mp4";
Clip clip_video(path.str());
clip_video.Open();
const auto r1 = clip_video.Reader();

// Configure a Timeline with the same parameters
Timeline t1(r1->info);

CHECK_EQUAL(r1->info.width, t1.info.width);
CHECK_EQUAL(r1->info.height, t1.info.height);
CHECK_EQUAL(r1->info.fps.num, t1.info.fps.num);
CHECK_EQUAL(r1->info.fps.den, t1.info.fps.den);
CHECK_EQUAL(r1->info.sample_rate, t1.info.sample_rate);
CHECK_EQUAL(r1->info.channels, t1.info.channels);
CHECK_EQUAL(r1->info.channel_layout, t1.info.channel_layout);
}

TEST(Width_and_Height_Functions)
{
// Create a default fraction (should be 1/1)
Fraction fps(30000,1000);
Timeline t1(640, 480, fps, 44100, 2, LAYOUT_STEREO);

Expand All @@ -93,7 +111,6 @@ TEST(Width_and_Height_Functions)

TEST(Framerate)
{
// Create a default fraction (should be 1/1)
Fraction fps(24,1);
Timeline t1(640, 480, fps, 44100, 2, LAYOUT_STEREO);

Expand Down

0 comments on commit 8227a91

Please sign in to comment.