24 #define __STDC_FORMAT_MACROS 1
28 #include <libavformat/avformat.h>
29 #include <libavcodec/avcodec.h>
30 #include <libswscale/swscale.h>
31 #include <libswresample/swresample.h>
32 #include <libavfilter/avfilter.h>
33 #include <libavfilter/buffersrc.h>
34 #include <libavfilter/buffersink.h>
35 #include <libavutil/opt.h>
36 #include <libavutil/pixdesc.h>
42 #include <QWaitCondition>
163 void Cache(
long playhead,
bool scrubbing, QVector<Clip*>& nests,
int playback_speed);
193 void Close(
bool wait_for_finish);
QWaitCondition wait_cond_
Main wait condition.
Definition: cacher.h:276
AVStream * stream
FFmpeg stream - used for media decoding.
Definition: cacher.h:368
void OpenWorker()
Internal function for opening the file handles and decoder.
Definition: cacher.cpp:861
void Open()
Open the cacher.
Definition: cacher.cpp:1184
AVFilterContext * buffersrc_ctx
FFmpeg buffer source.
Definition: cacher.h:406
void CacheWorker()
Internal function for starting a cache cycle.
Definition: cacher.cpp:1100
Clip * clip
Reference to the parent clip. Set in the constructor and never changed during this object's lifetime...
Definition: cacher.h:261
QWaitCondition main_thread_wait_
Main thread wait condition.
Definition: cacher.h:283
bool queued_
Signal cache to continue operation after one cycle rather than wait for another signal.
Definition: cacher.h:343
QMutex main_thread_lock_
Main thread mutex.
Definition: cacher.h:290
The ClipQueue class.
Definition: clipqueue.h:36
void SetRetrievedFrame(AVFrame *f)
Internal function for setting retrieved_frame and waking up any threads waiting for it...
Definition: cacher.cpp:833
AVPacket * pkt
FFmpeg packet - used for media decoding.
Definition: cacher.h:373
AVFrame * frame_
FFmpeg frame - used for media decoding.
Definition: cacher.h:381
void WakeMainThread()
Internal function to wake an external calling thread.
Definition: cacher.cpp:843
void Close(bool wait_for_finish)
Close the cacher and free any allocated memory.
Definition: cacher.cpp:1299
AVCodec * codec
FFmpeg codec reference.
Definition: cacher.h:418
bool reached_end
Set and used by CacheAudioWorker if the decoder receives an EOF.
Definition: cacher.h:311
void Reset()
Internal function for resetting audio state.
Definition: cacher.cpp:794
int RetrieveFrameAndProcess(AVFrame **f)
Retrieve frame from decoder and run it through filter stack.
Definition: cacher.cpp:1383
ClipQueue queue_
Frame queue.
Definition: cacher.h:268
int RetrieveFrameFromDecoder(AVFrame *f)
Retrieve frame from decoder.
Definition: cacher.cpp:1341
QMutex retrieve_lock_
Retrieve() mutex.
Definition: cacher.h:304
AVFrame * Retrieve()
Retrieve frame requested by Cache()
Definition: cacher.cpp:1263
The Cacher class.
Definition: cacher.h:100
void Cache(long playhead, bool scrubbing, QVector< Clip * > &nests, int playback_speed)
Request a frame to be cached.
Definition: cacher.cpp:1195
long playhead_
Current Sequence playhead set by Cache()
Definition: cacher.h:316
Cacher(Clip *c)
Cacher Constructor.
Definition: cacher.cpp:850
int64_t reverse_target_
Internal reverse target variable.
Definition: cacher.h:439
AVFilterContext * buffersink_ctx
FFmpeg buffer sink.
Definition: cacher.h:413
AVFrame * retrieved_frame
Retrieved frame reference for Retrieve()
Definition: cacher.h:389
int media_height()
Retrieve current media height.
Definition: cacher.cpp:1326
void CloseWorker()
Internal function for closing cacher.
Definition: cacher.cpp:1110
qint64 audio_buffer_write
Internal audio buffer write variable.
Definition: cacher.h:453
QVector< Clip * > nests_
Current nested Sequence hierarchy set by Cache()
Definition: cacher.h:331
int playback_speed_
Current Sequence playback speed set by Cache()
Definition: cacher.h:326
void run()
The main QThread loop.
Definition: cacher.cpp:1153
bool caching_
Main while loop condition to determine whether thread should continue looping.
Definition: cacher.h:466
void CacheVideoWorker()
Internal video caching function.
Definition: cacher.cpp:473
AVFilterGraph * filter_graph
FFmpeg filter stack.
Definition: cacher.h:399
AVFormatContext * formatCtx
FFmpeg format/file context - used for media decoding.
Definition: cacher.h:358
bool is_valid_state_
Internal variable for whether the current Cacher state is valid or not.
Definition: cacher.h:473
AVRational media_time_base()
Retrieve media time base.
Definition: cacher.cpp:1331
int frame_sample_index_
Internal frame sample index variable.
Definition: cacher.h:446
ClipQueue * queue()
Get cacher queue object.
Definition: cacher.cpp:1336
QWaitCondition retrieve_wait_
Retrieve() wait condition.
Definition: cacher.h:297
AVCodecContext * codecCtx
FFmpeg decoder context - used for media decoding.
Definition: cacher.h:363
bool interrupt_
Interrupt the current cache cycle.
Definition: cacher.h:352
long audio_target_frame
Internal variable that holds the playhead the last time the audio state was reset.
Definition: cacher.h:458
bool audio_reset_
Internal audio reset variable.
Definition: cacher.h:431
int media_width()
Retrieve current media width.
Definition: cacher.cpp:1321
bool IsReversed()
Internal function using the Cacher's known information to determine whether this media is playing in ...
Definition: cacher.cpp:467
bool scrubbing_
Current Sequence scrubbing state set by Cache()
Definition: cacher.h:321
AVDictionary * opts
Options set by the cacher for FFmpeg's decoders (settings like multithreading or other optimizations)...
Definition: cacher.h:423
void CacheAudioWorker()
Internal audio caching function.
Definition: cacher.cpp:104
void ResetAudio()
Interrupt and reset audio state.
Definition: cacher.cpp:1309