several conversions to smart pointers

This commit is contained in:
itsmattkc
2019-02-16 21:21:04 -08:00
parent e063a5ba8f
commit 5207a0511f
104 changed files with 972 additions and 945 deletions
+4 -8
View File
@@ -25,15 +25,11 @@
#include <QThread>
#include <QWaitCondition>
#include <QMutex>
#include <QIODevice>
#include <QAudioOutput>
#include <QComboBox>
//#define INT16_MAX 0x7fff
//#define INT16_MIN (-INT16_MAX-1)
class QIODevice;
class QAudioOutput;
class QComboBox;
struct Sequence;
#include "project/sequence.h"
class AudioSenderThread : public QThread {
Q_OBJECT
+12 -12
View File
@@ -62,13 +62,13 @@ double bytes_to_seconds(int nb_bytes, int nb_channels, int sample_rate) {
return ((double) (nb_bytes >> 1) / nb_channels / sample_rate);
}
void apply_audio_effects(Clip* c, double timecode_start, AVFrame* frame, int nb_bytes, QVector<Clip*> nests) {
void apply_audio_effects(ClipPtr c, double timecode_start, AVFrame* frame, int nb_bytes, QVector<ClipPtr> nests) {
// perform all audio effects
double timecode_end;
timecode_end = timecode_start + bytes_to_seconds(nb_bytes, frame->channels, frame->sample_rate);
for (int j=0;j<c->effects.size();j++) {
Effect* e = c->effects.at(j);
EffectPtr e = c->effects.at(j);
if (e->is_enabled()) e->process_audio(timecode_start, timecode_end, frame->data[0], nb_bytes, 2);
}
if (c->get_opening_transition() != nullptr) {
@@ -98,7 +98,7 @@ void apply_audio_effects(Clip* c, double timecode_start, AVFrame* frame, int nb_
}
if (!nests.isEmpty()) {
Clip* next_nest = nests.last();
ClipPtr next_nest = nests.last();
nests.removeLast();
apply_audio_effects(next_nest, timecode_start + (((double)c->get_timeline_in_with_transition()-c->get_clip_in_with_transition())/c->sequence->frame_rate), frame, nb_bytes, nests);
}
@@ -106,7 +106,7 @@ void apply_audio_effects(Clip* c, double timecode_start, AVFrame* frame, int nb_
#define AUDIO_BUFFER_PADDING 2048
void cache_audio_worker(Clip* c, bool scrubbing, QVector<Clip*>& nests, int playback_speed) {
void cache_audio_worker(ClipPtr c, bool scrubbing, QVector<ClipPtr>& nests, int playback_speed) {
long timeline_in = c->get_timeline_in_with_transition();
long timeline_out = c->get_timeline_out_with_transition();
long target_frame = c->audio_target_frame;
@@ -460,7 +460,7 @@ void cache_audio_worker(Clip* c, bool scrubbing, QVector<Clip*>& nests, int play
QMetaObject::invokeMethod(panel_sequence_viewer, "play_wake", Qt::QueuedConnection);
}
void cache_video_worker(Clip* c, long playhead) {
void cache_video_worker(ClipPtr c, long playhead) {
int read_ret, send_ret, retr_ret;
int64_t target_pts = seconds_to_timestamp(c, playhead_to_clip_seconds(c, playhead));
@@ -498,7 +498,7 @@ void cache_video_worker(Clip* c, long playhead) {
while (true) {
AVFrame* frame = av_frame_alloc();
Footage* media = c->media->to_footage();
FootagePtr media = c->media->to_footage();
const FootageStream* ms = media->get_stream_from_file_index(true, c->media_stream);
while ((retr_ret = av_buffersink_get_frame(c->buffersink_ctx, frame)) == AVERROR(EAGAIN)) {
@@ -585,7 +585,7 @@ void cache_video_worker(Clip* c, long playhead) {
}
}
void reset_cache(Clip* c, long target_frame, int playback_speed) {
void reset_cache(ClipPtr c, long target_frame, int playback_speed) {
// if we seek to a whole other place in the timeline, we'll need to reset the cache with new values
if (c->media == nullptr) {
if (c->track >= 0) {
@@ -671,11 +671,11 @@ void reset_cache(Clip* c, long target_frame, int playback_speed) {
}
}
Cacher::Cacher(Clip* c) : clip(c) {}
Cacher::Cacher(ClipPtr c) : clip(c) {}
AVSampleFormat sample_format = AV_SAMPLE_FMT_S16;
void open_clip_worker(Clip* clip) {
void open_clip_worker(ClipPtr clip) {
qint64 time_start = QDateTime::currentMSecsSinceEpoch();
if (clip->media == nullptr) {
@@ -694,7 +694,7 @@ void open_clip_worker(Clip* clip) {
}
} else if (clip->media->get_type() == MEDIA_TYPE_FOOTAGE) {
// opens file resource for FFmpeg and prepares Clip struct for playback
Footage* m = clip->media->to_footage();
FootagePtr m = clip->media->to_footage();
// byte array for retriving raw bytes from QString URL
QByteArray ba;
@@ -947,7 +947,7 @@ void open_clip_worker(Clip* clip) {
qInfo() << "Clip opened on track" << clip->track << "(took" << (QDateTime::currentMSecsSinceEpoch() - time_start) << "ms)";
}
void cache_clip_worker(Clip* clip, long playhead, bool reset, bool scrubbing, QVector<Clip*> nests, int playback_speed) {
void cache_clip_worker(ClipPtr clip, long playhead, bool reset, bool scrubbing, QVector<ClipPtr> nests, int playback_speed) {
if (reset) {
// note: for video, playhead is in "internal clip" frames - for audio, it's the timeline playhead
reset_cache(clip, playhead, playback_speed);
@@ -967,7 +967,7 @@ void cache_clip_worker(Clip* clip, long playhead, bool reset, bool scrubbing, QV
}
}
void close_clip_worker(Clip* clip) {
void close_clip_worker(ClipPtr clip) {
clip->finished_opening = false;
if (clip->media != nullptr && clip->media->get_type() == MEDIA_TYPE_FOOTAGE) {
+7 -6
View File
@@ -25,12 +25,13 @@
#include <QVector>
class Clip;
using ClipPtr = std::shared_ptr<Clip>;
class Cacher : public QThread
{
// Q_OBJECT
public:
Cacher(Clip* c);
Cacher(ClipPtr c);
void run();
bool caching;
@@ -42,14 +43,14 @@ public:
bool interrupt;
bool queued;
int playback_speed;
QVector<Clip*> nests;
QVector<ClipPtr> nests;
private:
Clip* clip;
ClipPtr clip;
};
void open_clip_worker(Clip* clip);
void cache_clip_worker(Clip* clip, long playhead, bool reset, bool scrubbing, QVector<Clip *> nest, int playback_speed);
void close_clip_worker(Clip* clip);
void open_clip_worker(ClipPtr clip);
void cache_clip_worker(ClipPtr clip, long playhead, bool reset, bool scrubbing, QVector<ClipPtr> nest, int playback_speed);
void close_clip_worker(ClipPtr clip);
#endif // CACHER_H
+17 -18
View File
@@ -36,7 +36,6 @@
#include "debug.h"
extern "C" {
#include <libavformat/avformat.h>
#include <libavutil/pixdesc.h>
#include <libavcodec/avcodec.h>
#include <libswscale/swscale.h>
@@ -59,11 +58,11 @@ long refactor_frame_number(long framenumber, double source_frame_rate, double ta
return qRound((double(framenumber)/source_frame_rate)*target_frame_rate);
}
bool clip_uses_cacher(Clip* clip) {
bool clip_uses_cacher(ClipPtr clip) {
return (clip->media == nullptr && clip->track >= 0) || (clip->media != nullptr && clip->media->get_type() == MEDIA_TYPE_FOOTAGE);
}
void open_clip(Clip* clip, bool multithreaded) {
void open_clip(ClipPtr clip, bool multithreaded) {
if (clip_uses_cacher(clip)) {
clip->multithreaded = multithreaded;
if (multithreaded) {
@@ -85,7 +84,7 @@ void open_clip(Clip* clip, bool multithreaded) {
}
}
void close_clip(Clip* clip, bool wait) {
void close_clip(ClipPtr clip, bool wait) {
clip->finished_opening = false;
// destroy opengl texture in main thread
@@ -129,7 +128,7 @@ void close_clip(Clip* clip, bool wait) {
}
}
void cache_clip(Clip* clip, long playhead, bool reset, bool scrubbing, QVector<Clip*>& nests, int playback_speed) {
void cache_clip(ClipPtr clip, long playhead, bool reset, bool scrubbing, QVector<ClipPtr>& nests, int playback_speed) {
if (clip_uses_cacher(clip)) {
if (clip->multithreaded) {
clip->cacher->playhead = playhead;
@@ -147,11 +146,11 @@ void cache_clip(Clip* clip, long playhead, bool reset, bool scrubbing, QVector<C
}
}
double get_timecode(Clip* c, long playhead) {
double get_timecode(ClipPtr c, long playhead) {
return ((double)(playhead-c->get_timeline_in_with_transition()+c->get_clip_in_with_transition())/(double)c->sequence->frame_rate);
}
void get_clip_frame(Clip* c, long playhead, bool& texture_failed) {
void get_clip_frame(ClipPtr c, long playhead, bool& texture_failed) {
if (c->finished_opening) {
const FootageStream* ms = c->media->to_footage()->get_stream_from_file_index(c->track < 0, c->media_stream);
@@ -336,7 +335,7 @@ void get_clip_frame(Clip* c, long playhead, bool& texture_failed) {
}
for (int i=0;i<c->effects.size();i++) {
Effect* e = c->effects.at(i);
EffectPtr e = c->effects.at(i);
if (e->enable_image && e->is_enabled()) {
if (data_buffer_1 == target_frame->data[0]) {
data_buffer_1 = new uint8_t[frame_size];
@@ -366,16 +365,16 @@ void get_clip_frame(Clip* c, long playhead, bool& texture_failed) {
c->queue_lock.unlock();
// get more frames
QVector<Clip*> empty;
QVector<ClipPtr> empty;
if (cache) cache_clip(c, playhead, reset, false, empty, false);
}
}
long playhead_to_clip_frame(Clip* c, long playhead) {
long playhead_to_clip_frame(ClipPtr c, long playhead) {
return (qMax(0L, playhead - c->get_timeline_in_with_transition()) + c->get_clip_in_with_transition());
}
double playhead_to_clip_seconds(Clip* c, long playhead) {
double playhead_to_clip_seconds(ClipPtr c, long playhead) {
// returns time in seconds
long clip_frame = playhead_to_clip_frame(c, playhead);
if (c->reverse) clip_frame = c->getMaximumLength() - clip_frame - 1;
@@ -384,15 +383,15 @@ double playhead_to_clip_seconds(Clip* c, long playhead) {
return secs;
}
int64_t seconds_to_timestamp(Clip* c, double seconds) {
int64_t seconds_to_timestamp(ClipPtr c, double seconds) {
return qRound64(seconds * av_q2d(av_inv_q(c->stream->time_base))) + qMax((int64_t) 0, c->stream->start_time);
}
int64_t playhead_to_timestamp(Clip* c, long playhead) {
int64_t playhead_to_timestamp(ClipPtr c, long playhead) {
return seconds_to_timestamp(c, playhead_to_clip_seconds(c, playhead));
}
int retrieve_next_frame(Clip* c, AVFrame* f) {
int retrieve_next_frame(ClipPtr c, AVFrame* f) {
int result = 0;
int receive_ret;
@@ -438,7 +437,7 @@ int retrieve_next_frame(Clip* c, AVFrame* f) {
return result;
}
bool is_clip_active(Clip* c, long playhead) {
bool is_clip_active(ClipPtr c, long playhead) {
// these buffers allow clips to be opened and prepared well before they're displayed
// as well as closed a little after they're not needed anymore
int open_buffer = qCeil(c->sequence->frame_rate*2);
@@ -451,7 +450,7 @@ bool is_clip_active(Clip* c, long playhead) {
&& playhead - c->get_timeline_in_with_transition() + c->get_clip_in_with_transition() < c->getMaximumLength();
}
void set_sequence(Sequence* s) {
void set_sequence(SequencePtr s) {
panel_effect_controls->clear_effects(true);
olive::ActiveSequence = s;
panel_sequence_viewer->set_main_sequence();
@@ -459,10 +458,10 @@ void set_sequence(Sequence* s) {
panel_timeline->setFocus();
}
void closeActiveClips(Sequence *s) {
void closeActiveClips(SequencePtr s) {
if (s != nullptr) {
for (int i=0;i<s->clips.size();i++) {
Clip* c = s->clips.at(i);
ClipPtr c = s->clips.at(i);
if (c != nullptr) {
if (c->media != nullptr && c->media->get_type() == MEDIA_TYPE_SEQUENCE) {
closeActiveClips(c->media->to_sequence());
+23 -21
View File
@@ -24,30 +24,32 @@
#include <QVector>
#include <QMutex>
class Clip;
struct ClipCache;
struct Sequence;
struct AVFrame;
#include "project/clip.h"
#include "project/sequence.h"
extern "C" {
#include <libavformat/avformat.h>
}
long refactor_frame_number(long framenumber, double source_frame_rate, double target_frame_rate);
bool clip_uses_cacher(Clip* clip);
void open_clip(Clip* clip, bool multithreaded);
void cache_clip(Clip* clip, long playhead, bool reset, bool scrubbing, QVector<Clip *> &nests, int playback_speed);
void close_clip(Clip* clip, bool wait);
void handle_media(Sequence* sequence, long playhead, bool multithreaded);
void reset_cache(Clip* c, long target_frame, int playback_speed);
void get_clip_frame(Clip* c, long playhead, bool &texture_failed);
double get_timecode(Clip* c, long playhead);
bool clip_uses_cacher(ClipPtr clip);
void open_clip(ClipPtr clip, bool multithreaded);
void cache_clip(ClipPtr clip, long playhead, bool reset, bool scrubbing, QVector<ClipPtr> &nests, int playback_speed);
void close_clip(ClipPtr clip, bool wait);
void handle_media(SequencePtr sequence, long playhead, bool multithreaded);
void reset_cache(ClipPtr c, long target_frame, int playback_speed);
void get_clip_frame(ClipPtr c, long playhead, bool &texture_failed);
double get_timecode(ClipPtr c, long playhead);
long playhead_to_clip_frame(Clip* c, long playhead);
double playhead_to_clip_seconds(Clip* c, long playhead);
int64_t seconds_to_timestamp(Clip* c, double seconds);
int64_t playhead_to_timestamp(Clip* c, long playhead);
long playhead_to_clip_frame(ClipPtr c, long playhead);
double playhead_to_clip_seconds(ClipPtr c, long playhead);
int64_t seconds_to_timestamp(ClipPtr c, double seconds);
int64_t playhead_to_timestamp(ClipPtr c, long playhead);
int retrieve_next_frame(Clip* c, AVFrame* f);
bool is_clip_active(Clip* c, long playhead);
void get_next_audio(Clip* c, bool mix);
void set_sequence(Sequence* s);
void closeActiveClips(Sequence* s);
int retrieve_next_frame(ClipPtr c, AVFrame* f);
bool is_clip_active(ClipPtr c, long playhead);
void get_next_audio(ClipPtr c, bool mix);
void set_sequence(SequencePtr s);
void closeActiveClips(SequencePtr s);
#endif // PLAYBACK_H