First commit of brand new rewrite

This commit is contained in:
itsmattkc
2018-05-30 03:24:12 +10:00
commit 244c092591
86 changed files with 8016 additions and 0 deletions
+81
View File
@@ -0,0 +1,81 @@
#include "clip.h"
#include "project/effect.h"
#include "io/media.h"
#include "playback/playback.h"
#include "playback/cacher.h"
#include <QDebug>
extern "C" {
#include <libavformat/avformat.h>
}
Clip::Clip() {
init();
}
Clip::Clip(const Clip &c) {
init();
copy(c);
}
Clip& Clip::operator= (const Clip& c) {
init();
copy(c);
return *this;
}
void Clip::copy(const Clip& c) {
name = c.name;
clip_in = c.clip_in;
timeline_in = c.timeline_in;
timeline_out = c.timeline_out;
track = c.track;
color_r = c.color_r;
color_g = c.color_g;
color_b = c.color_b;
sequence = c.sequence;
media = c.media;
media_stream = c.media_stream;
}
void Clip::init() {
reset();
clip_in = timeline_in = timeline_out = track = undeletable = 0;
texture = NULL;
pkt = new AVPacket();
}
void Clip::reset() {
cache_size = cache_A.offset = cache_B.offset = open = pkt_written = cache_A.written = cache_B.written = cache_A.unread = cache_B.unread = reached_end = reset_audio = frame_sample_index = 0;
texture_frame = -1;
formatCtx = NULL;
stream = NULL;
codec = NULL;
codecCtx = NULL;
texture = NULL;
cache_A.frames = NULL;
cache_B.frames = NULL;
}
Clip::~Clip() {
if (open) {
close_clip(this);
}
// make sure clip has closed before clip is destroyed
open_lock.lock();
open_lock.unlock();
for (int i=0;i<effects.size();i++) {
delete effects.at(i);
}
av_packet_unref(pkt);
delete pkt;
}
// timeline functions
long Clip::getLength() {
return timeline_out - timeline_in;
}
+95
View File
@@ -0,0 +1,95 @@
#ifndef CLIP_H
#define CLIP_H
#include <QWaitCondition>
#include <QMutex>
#include <QVector>
class Cacher;
class Effect;
struct Sequence;
struct Media;
struct MediaStream;
struct AVFormatContext;
struct AVStream;
struct AVCodec;
struct AVCodecContext;
struct AVFrame;
struct AVPacket;
struct SwsContext;
struct SwrContext;
class QOpenGLTexture;
struct ClipCache {
AVFrame** frames;
long offset;
bool written;
bool unread;
QMutex mutex;
};
struct Clip
{
Clip();
Clip(const Clip &c);
Clip& operator= (const Clip&); // explicitly defaulted copy assignment
~Clip();
void copy(const Clip& c);
void init();
void reset();
bool undeletable;
// timeline variables
QString name;
long clip_in;
long timeline_in;
long timeline_out;
int track;
uint8_t color_r;
uint8_t color_g;
uint8_t color_b;
long getLength();
// inherited information (should be copied in copy())
Media* media; // attached media
MediaStream* media_stream;
Sequence* sequence;
// other variables (should be "duplicated" in copy())
QList<Effect*> effects;
// QVector<Clip&> linkedClips;
// media handling
AVFormatContext* formatCtx;
AVStream* stream;
AVCodec* codec;
AVCodecContext* codecCtx;
AVPacket* pkt;
AVFrame* frame;
bool pkt_written;
bool reached_end;
bool open;
// caching functions
bool multithreaded;
Cacher* cacher;
QWaitCondition can_cache;
uint16_t cache_size;
ClipCache cache_A;
ClipCache cache_B;
QMutex lock;
QMutex open_lock;
// video playback variables
SwsContext* sws_ctx;
QOpenGLTexture* texture;
long texture_frame;
// audio playback variables
SwrContext* swr_ctx;
int frame_sample_index;
bool reset_audio;
};
#endif // CLIP_H
+18
View File
@@ -0,0 +1,18 @@
#include "effect.h"
#include "panels/panels.h"
#include "panels/viewer.h"
#include "ui/viewerwidget.h"
Effect::Effect(Clip* c) : parent_clip(c)
{
name = "<unnamed effect>";
type = EFFECT_TYPE_INVALID;
}
void Effect::field_changed() {
panel_viewer->viewer_widget->update();
}
void Effect::process_gl(int* anchor_x, int* anchor_y) {}
void Effect::process_audio(uint8_t* samples, int nb_bytes) {}
+31
View File
@@ -0,0 +1,31 @@
#ifndef EFFECT_H
#define EFFECT_H
#include <QObject>
#include <QString>
class QWidget;
class CollapsibleWidget;
struct Clip;
enum EffectTypes { EFFECT_TYPE_INVALID, EFFECT_TYPE_VIDEO, EFFECT_TYPE_AUDIO };
class Effect : public QObject
{
Q_OBJECT
public:
Effect(Clip* c);
int type;
QString name;
CollapsibleWidget* container;
QWidget* ui;
Clip* parent_clip;
virtual void process_gl(int* anchor_x, int* anchor_y);
virtual void process_audio(uint8_t* samples, int nb_bytes);
public slots:
void field_changed();
};
#endif // EFFECT_H
+122
View File
@@ -0,0 +1,122 @@
#include "sequence.h"
#include "project/clip.h"
#include <QDebug>
Sequence::Sequence() {
}
Sequence::~Sequence() {
}
Clip& Sequence::new_clip() {
clips.append(Clip());
return clips[clips.size() - 1];
}
Clip& Sequence::insert_clip(const Clip& c) {
clips.append(c);
return clips[clips.size() - 1];
}
int Sequence::clip_count() {
return clips.count();
}
Clip& Sequence::get_clip(int i) {
return clips[i];
}
void Sequence::delete_clip(int i) {
// remove any potential link references to clip
// for (size_t j=0;j<clip_count();j++) {
// Clip* c = getClip(j);
// for (size_t k=0;k<c->linkedClips.size();k++) {
// if (c->linkedClips[k] == clips[i]) {
// c->linkedClips.erase(c->linkedClips.begin()+k);
// }
// }
// }
// finally remove from vector
clips.removeAt(i);
}
long Sequence::getEndFrame() {
long end = 0;
for (int j=0;j<clip_count();j++) {
Clip& c = get_clip(j);
if (c.timeline_out > end) {
end = c.timeline_out;
}
}
return end;
}
void Sequence::get_track_limits(int* video_tracks, int* audio_tracks) {
int vt = 0;
int at = 0;
for (int j=0;j<clip_count();j++) {
Clip& c = get_clip(j);
if (c.track < 0 && c.track < vt) { // video clip
vt = c.track;
} else if (c.track > at) {
at = c.track;
}
}
if (video_tracks != NULL) *video_tracks = vt;
if (audio_tracks != NULL) *audio_tracks = at;
}
void Sequence::delete_area(long in, long out, int track) {
for (int i=0;i<clip_count();i++) {
Clip& c = get_clip(i);
if (c.track == track && !c.undeletable) {
if (c.timeline_in >= in && c.timeline_out <= out) {
// clips falls entirely within deletion area
delete_clip(i);
i--;
} else if (c.timeline_in < in && c.timeline_out > out) {
// middle of clip is within deletion area
clips.append(clips.at(i)); // copy clip
Clip& pre = get_clip(i);
Clip& post = get_clip(clips.size()-1);
pre.timeline_out = in;
post.timeline_in = out;
post.clip_in = pre.clip_in + pre.getLength() + (out - in);
} else if (c.timeline_in < in && c.timeline_out > in) {
// only out point is in deletion area
c.timeline_out = in;
} else if (c.timeline_in < out && c.timeline_out > out) {
// only in point is in deletion area
c.clip_in += out - c.timeline_in;
c.timeline_in = out;
}
}
}
}
void Sequence::split_clip(int i, long frame) {
Clip& pre = get_clip(i);
if (pre.timeline_in < frame && pre.timeline_out > frame) { // guard against attempts to split at in/out points
clips.append(pre); // copy clip
Clip& post = get_clip(clips.size()-1);
pre.timeline_out = frame;
post.timeline_in = frame;
post.clip_in = pre.clip_in + pre.getLength();
}
}
void Sequence::split_at_playhead(long frame) {
for (int j=0;j<clip_count();j++) {
Clip& c = get_clip(j);
if (c.timeline_in < frame && c.timeline_out > frame) {
split_clip(j, frame);
}
}
}
+32
View File
@@ -0,0 +1,32 @@
#ifndef SEQUENCE_H
#define SEQUENCE_H
#include <QVector>
#include "project/clip.h"
struct Sequence {
public:
Sequence();
~Sequence();
QString name;
Clip& new_clip();
Clip& insert_clip(const Clip& c);
int clip_count();
Clip& get_clip(int i);
void delete_clip(int i);
void delete_area(long in, long out, int track);
void split_clip(int i, long frame);
void split_at_playhead(long frame);
void get_track_limits(int* video_tracks, int* audio_tracks);
long getEndFrame();
int width;
int height;
float frame_rate;
int audio_frequency;
int audio_layout;
private:
QList<Clip> clips;
};
#endif // SEQUENCE_H