jkl playback is functional
This commit is contained in:
+1
-1
@@ -119,7 +119,7 @@ qint64 get_buffer_offset_from_frame(double framerate, long frame) {
|
||||
int multiplier = av_get_bytes_per_sample(AV_SAMPLE_FMT_S16)*av_get_channel_layout_nb_channels(AV_CH_LAYOUT_STEREO);
|
||||
return qFloor((double(frame - audio_ibuffer_frame)/framerate)*current_audio_freq())*multiplier;
|
||||
} else {
|
||||
qWarning() << "Invalid values passed to get_buffer_offset_from_frame";
|
||||
qWarning() << "Invalid values passed to get_buffer_offset_from_frame" << frame << "<" << audio_ibuffer_frame;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
+52
-25
@@ -86,11 +86,14 @@ 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) {
|
||||
void cache_audio_worker(Clip* c, bool scrubbing, QVector<Clip*>& 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;
|
||||
|
||||
bool temp_reverse = (playback_speed < 0);
|
||||
bool reverse_audio = (c->reverse != temp_reverse);
|
||||
|
||||
long frame_skip = 0;
|
||||
double last_fr = c->sequence->frame_rate;
|
||||
if (!nests.isEmpty()) {
|
||||
@@ -113,6 +116,17 @@ void cache_audio_worker(Clip* c, bool scrubbing, QVector<Clip*>& nests) {
|
||||
}
|
||||
}
|
||||
|
||||
if (temp_reverse) {
|
||||
long seq_end = sequence->getEndFrame();
|
||||
timeline_in = seq_end - timeline_in;
|
||||
timeline_out = seq_end - timeline_out;
|
||||
target_frame = seq_end - target_frame;
|
||||
|
||||
long temp = timeline_in;
|
||||
timeline_in = timeline_out;
|
||||
timeline_out = temp;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
AVFrame* frame;
|
||||
int nb_bytes = INT_MAX;
|
||||
@@ -147,7 +161,7 @@ void cache_audio_worker(Clip* c, bool scrubbing, QVector<Clip*>& nests) {
|
||||
if (!c->reached_end) {
|
||||
int loop = 0;
|
||||
|
||||
if (c->reverse && !c->audio_just_reset) {
|
||||
if (reverse_audio && !c->audio_just_reset) {
|
||||
avcodec_flush_buffers(c->codecCtx);
|
||||
c->reached_end = false;
|
||||
int64_t backtrack_seek = qMax(c->reverse_target - static_cast<int64_t>(av_q2d(av_inv_q(c->stream->time_base))), static_cast<int64_t>(0));
|
||||
@@ -177,7 +191,7 @@ void cache_audio_worker(Clip* c, bool scrubbing, QVector<Clip*>& nests) {
|
||||
dout << "reached EOF while reading";
|
||||
#endif
|
||||
// TODO revise usage of reached_end in audio
|
||||
if (!c->reverse) {
|
||||
if (!reverse_audio) {
|
||||
c->reached_end = true;
|
||||
} else {
|
||||
}
|
||||
@@ -198,11 +212,11 @@ void cache_audio_worker(Clip* c, bool scrubbing, QVector<Clip*>& nests) {
|
||||
#ifdef AUDIOWARNINGS
|
||||
dout << "reached EOF while pulling from filtergraph";
|
||||
#endif
|
||||
if (!c->reverse) break;
|
||||
if (!reverse_audio) break;
|
||||
}
|
||||
}
|
||||
|
||||
if (c->reverse) {
|
||||
if (reverse_audio) {
|
||||
if (loop > 1) {
|
||||
AVFrame* rev_frame = c->queue.at(1);
|
||||
if (ret != AVERROR_EOF) {
|
||||
@@ -313,7 +327,7 @@ void cache_audio_worker(Clip* c, bool scrubbing, QVector<Clip*>& nests) {
|
||||
dout << "fsts:" << frame_sts << "tsts:" << target_sts << "nbs:" << nb_samples << "nbb:" << nb_bytes << "rev_targetToSec:" << (c->reverse_target * timebase);
|
||||
dout << "fsi-calc:" << c->frame_sample_index;
|
||||
#endif
|
||||
if (c->reverse) c->frame_sample_index = nb_bytes - c->frame_sample_index;
|
||||
if (reverse_audio) c->frame_sample_index = nb_bytes - c->frame_sample_index;
|
||||
c->audio_just_reset = false;
|
||||
}
|
||||
|
||||
@@ -343,7 +357,7 @@ void cache_audio_worker(Clip* c, bool scrubbing, QVector<Clip*>& nests) {
|
||||
}
|
||||
}
|
||||
|
||||
if (c->reverse) frame = c->queue.at(1);
|
||||
if (reverse_audio) frame = c->queue.at(1);
|
||||
|
||||
#ifdef AUDIOWARNINGS
|
||||
dout << "j" << c->frame_sample_index << nb_bytes;
|
||||
@@ -368,20 +382,29 @@ void cache_audio_worker(Clip* c, bool scrubbing, QVector<Clip*>& nests) {
|
||||
|
||||
audio_write_lock.lock();
|
||||
|
||||
int audio_skip_resolution = 100; // FIXME magic number
|
||||
|
||||
int sample_skip = 4*qMax(0, qAbs(playback_speed)-1);
|
||||
int sample_byte_size = av_get_bytes_per_sample(static_cast<AVSampleFormat>(frame->format));
|
||||
|
||||
while (c->frame_sample_index < nb_bytes
|
||||
&& c->audio_buffer_write < audio_ibuffer_read+(audio_ibuffer_size>>1)
|
||||
&& c->audio_buffer_write < buffer_timeline_out) {
|
||||
int upper_byte_index = (c->audio_buffer_write+1)%audio_ibuffer_size;
|
||||
int lower_byte_index = (c->audio_buffer_write)%audio_ibuffer_size;
|
||||
qint16 old_sample = static_cast<qint16>((audio_ibuffer[upper_byte_index] & 0xFF) << 8 | (audio_ibuffer[lower_byte_index] & 0xFF));
|
||||
qint16 new_sample = static_cast<qint16>((frame->data[0][c->frame_sample_index+1] & 0xFF) << 8 | (frame->data[0][c->frame_sample_index] & 0xFF));
|
||||
qint16 mixed_sample = mix_audio_sample(old_sample, new_sample);
|
||||
for (int i=0;i<frame->channels;i++) {
|
||||
int upper_byte_index = (c->audio_buffer_write+1)%audio_ibuffer_size;
|
||||
int lower_byte_index = (c->audio_buffer_write)%audio_ibuffer_size;
|
||||
qint16 old_sample = static_cast<qint16>((audio_ibuffer[upper_byte_index] & 0xFF) << 8 | (audio_ibuffer[lower_byte_index] & 0xFF));
|
||||
qint16 new_sample = static_cast<qint16>((frame->data[0][c->frame_sample_index+1] & 0xFF) << 8 | (frame->data[0][c->frame_sample_index] & 0xFF));
|
||||
qint16 mixed_sample = mix_audio_sample(old_sample, new_sample);
|
||||
|
||||
audio_ibuffer[upper_byte_index] = quint8((mixed_sample >> 8) & 0xFF);
|
||||
audio_ibuffer[lower_byte_index] = quint8(mixed_sample & 0xFF);
|
||||
audio_ibuffer[upper_byte_index] = quint8((mixed_sample >> 8) & 0xFF);
|
||||
audio_ibuffer[lower_byte_index] = quint8(mixed_sample & 0xFF);
|
||||
|
||||
c->audio_buffer_write+=2;
|
||||
c->frame_sample_index+=2;
|
||||
c->audio_buffer_write+=sample_byte_size;
|
||||
c->frame_sample_index+=sample_byte_size;
|
||||
}
|
||||
|
||||
c->frame_sample_index += sample_skip;
|
||||
|
||||
if (c->audio_reset) break;
|
||||
}
|
||||
@@ -398,7 +421,7 @@ void cache_audio_worker(Clip* c, bool scrubbing, QVector<Clip*>& nests) {
|
||||
if (audio_thread != nullptr) audio_thread->notifyReceiver();
|
||||
}
|
||||
|
||||
if (c->frame_sample_index == nb_bytes) {
|
||||
if (c->frame_sample_index >= nb_bytes) {
|
||||
c->frame_sample_index = -1;
|
||||
} else {
|
||||
// assume we have no more data to send
|
||||
@@ -544,7 +567,7 @@ void cache_video_worker(Clip* c, long playhead) {
|
||||
}
|
||||
}
|
||||
|
||||
void reset_cache(Clip* c, long target_frame) {
|
||||
void reset_cache(Clip* 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) {
|
||||
@@ -607,9 +630,12 @@ void reset_cache(Clip* c, long target_frame) {
|
||||
|
||||
// seek (target_frame represents timeline timecode in frames, not clip timecode)
|
||||
|
||||
// bool reverse = (c->reverse != temp_reverse);
|
||||
|
||||
int64_t timestamp = seconds_to_timestamp(c, playhead_to_clip_seconds(c, target_frame));
|
||||
|
||||
if (c->reverse) {
|
||||
bool temp_reverse = (playback_speed < 0);
|
||||
if (c->reverse != temp_reverse) {
|
||||
c->reverse_target = timestamp;
|
||||
timestamp -= av_q2d(av_inv_q(c->stream->time_base));
|
||||
#ifdef AUDIOWARNINGS
|
||||
@@ -790,7 +816,8 @@ void open_clip_worker(Clip* clip) {
|
||||
|
||||
// set up cache
|
||||
clip->queue.append(av_frame_alloc());
|
||||
if (clip->reverse) {
|
||||
// if (clip->reverse) {
|
||||
if (true) {
|
||||
AVFrame* reverse_frame = av_frame_alloc();
|
||||
|
||||
reverse_frame->format = sample_format;
|
||||
@@ -886,22 +913,22 @@ void open_clip_worker(Clip* clip) {
|
||||
qInfo() << "Clip opened on track" << clip->track;
|
||||
}
|
||||
|
||||
void cache_clip_worker(Clip* clip, long playhead, bool reset, bool scrubbing, QVector<Clip*> nests) {
|
||||
void cache_clip_worker(Clip* clip, long playhead, bool reset, bool scrubbing, QVector<Clip*> 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);
|
||||
reset_cache(clip, playhead, playback_speed);
|
||||
clip->audio_reset = false;
|
||||
}
|
||||
|
||||
if (clip->media == nullptr) {
|
||||
if (clip->track >= 0) {
|
||||
cache_audio_worker(clip, scrubbing, nests);
|
||||
cache_audio_worker(clip, scrubbing, nests, playback_speed);
|
||||
}
|
||||
} else if (clip->media->get_type() == MEDIA_TYPE_FOOTAGE) {
|
||||
if (clip->stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
|
||||
cache_video_worker(clip, playhead);
|
||||
} else if (clip->stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
|
||||
cache_audio_worker(clip, scrubbing, nests);
|
||||
cache_audio_worker(clip, scrubbing, nests, playback_speed);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -945,7 +972,7 @@ void Cacher::run() {
|
||||
break;
|
||||
} else {
|
||||
while (true) {
|
||||
cache_clip_worker(clip, playhead, reset, scrubbing, nests);
|
||||
cache_clip_worker(clip, playhead, reset, scrubbing, nests, playback_speed);
|
||||
if (clip->multithreaded && clip->cacher->interrupt && clip->track < 0) {
|
||||
clip->cacher->interrupt = false;
|
||||
} else {
|
||||
|
||||
+5
-4
@@ -11,15 +11,16 @@ class Cacher : public QThread
|
||||
// Q_OBJECT
|
||||
public:
|
||||
Cacher(Clip* c);
|
||||
void run();
|
||||
void run();
|
||||
|
||||
bool caching;
|
||||
|
||||
// must be set before caching
|
||||
long playhead;
|
||||
bool reset;
|
||||
bool scrubbing;
|
||||
bool interrupt;
|
||||
bool scrubbing;
|
||||
bool interrupt;
|
||||
int playback_speed;
|
||||
QVector<Clip*> nests;
|
||||
|
||||
private:
|
||||
@@ -27,7 +28,7 @@ private:
|
||||
};
|
||||
|
||||
void open_clip_worker(Clip* clip);
|
||||
void cache_clip_worker(Clip* clip, long playhead, bool reset, bool scrubbing, QVector<Clip *> nest);
|
||||
void cache_clip_worker(Clip* clip, long playhead, bool reset, bool scrubbing, QVector<Clip *> nest, int playback_speed);
|
||||
void close_clip_worker(Clip* clip);
|
||||
|
||||
#endif // CACHER_H
|
||||
|
||||
@@ -105,18 +105,19 @@ void close_clip(Clip* clip, bool wait) {
|
||||
}
|
||||
}
|
||||
|
||||
void cache_clip(Clip* clip, long playhead, bool reset, bool scrubbing, QVector<Clip*>& nests) {
|
||||
void cache_clip(Clip* clip, long playhead, bool reset, bool scrubbing, QVector<Clip*>& nests, int playback_speed) {
|
||||
if (clip_uses_cacher(clip)) {
|
||||
if (clip->multithreaded) {
|
||||
clip->cacher->playhead = playhead;
|
||||
clip->cacher->reset = reset;
|
||||
clip->cacher->nests = nests;
|
||||
clip->cacher->scrubbing = scrubbing;
|
||||
clip->cacher->playback_speed = playback_speed;
|
||||
if (reset && clip->queue.size() > 0) clip->cacher->interrupt = true;
|
||||
|
||||
clip->can_cache.wakeAll();
|
||||
} else {
|
||||
cache_clip_worker(clip, playhead, reset, scrubbing, nests);
|
||||
cache_clip_worker(clip, playhead, reset, scrubbing, nests, playback_speed);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -264,13 +265,13 @@ void get_clip_frame(Clip* c, long playhead, bool& texture_failed) {
|
||||
uint8_t* data_buffer_1 = target_frame->data[0];
|
||||
uint8_t* data_buffer_2 = nullptr;
|
||||
|
||||
int frame_size;
|
||||
size_t frame_size;
|
||||
|
||||
for (int i=0;i<c->effects.size();i++) {
|
||||
Effect* e = c->effects.at(i);
|
||||
if (e->enable_image && e->is_enabled()) {
|
||||
if (data_buffer_1 == target_frame->data[0]) {
|
||||
frame_size = target_frame->linesize[0]*target_frame->height;
|
||||
frame_size = size_t(target_frame->linesize[0])*size_t(target_frame->height);
|
||||
|
||||
data_buffer_1 = new uint8_t[frame_size];
|
||||
data_buffer_2 = new uint8_t[frame_size];
|
||||
@@ -296,7 +297,7 @@ void get_clip_frame(Clip* c, long playhead, bool& texture_failed) {
|
||||
|
||||
// get more frames
|
||||
QVector<Clip*> empty;
|
||||
if (cache) cache_clip(c, playhead, reset, false, empty);
|
||||
if (cache) cache_clip(c, playhead, reset, false, empty, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-4
@@ -12,12 +12,10 @@ struct AVFrame;
|
||||
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);
|
||||
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 cache_audio_worker(Clip* c, bool write_A);
|
||||
void cache_video_worker(Clip* c, long playhead);
|
||||
void handle_media(Sequence* sequence, long playhead, bool multithreaded);
|
||||
void reset_cache(Clip* c, long target_frame);
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user