ffmpegdecoder: separated instance from decoder entity
Should allow for different decoders in different threads to share a single instance.
This commit is contained in:
@@ -40,6 +40,62 @@ extern "C" {
|
||||
|
||||
OLIVE_NAMESPACE_ENTER
|
||||
|
||||
class FFmpegDecoderInstance {
|
||||
public:
|
||||
FFmpegDecoderInstance(const char* filename, int stream_index);
|
||||
virtual ~FFmpegDecoderInstance();
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
int64_t RangeStart() const;
|
||||
int64_t RangeEnd() const;
|
||||
bool CacheContainsTime(const int64_t& t) const;
|
||||
bool CacheWillContainTime(const int64_t& t) const;
|
||||
bool CacheCouldContainTime(const int64_t& t) const;
|
||||
AVFrame* GetFrameFromCache(const int64_t& t) const;
|
||||
|
||||
rational sample_aspect_ratio() const;
|
||||
AVStream* stream() const;
|
||||
|
||||
void ClearFrameCache();
|
||||
|
||||
AVFrame* RetrieveFrame(const int64_t &target_ts, bool cache_is_locked);
|
||||
|
||||
/**
|
||||
* @brief Uses the FFmpeg API to retrieve a packet (stored in pkt_) and decode it (stored in frame_)
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* An FFmpeg error code, or >= 0 on success
|
||||
*/
|
||||
int GetFrame(AVPacket* pkt, AVFrame* frame);
|
||||
|
||||
QMutex* cache_lock();
|
||||
QWaitCondition* cache_wait_cond();
|
||||
|
||||
int64_t cache_target_time_;
|
||||
|
||||
private:
|
||||
void ClearResources();
|
||||
|
||||
void Seek(int64_t timestamp);
|
||||
|
||||
AVFormatContext* fmt_ctx_;
|
||||
AVCodecContext* codec_ctx_;
|
||||
AVStream* avstream_;
|
||||
AVDictionary* opts_;
|
||||
|
||||
int64_t second_ts_;
|
||||
|
||||
QWaitCondition cache_wait_cond_;
|
||||
QMutex cache_lock_;
|
||||
QList<AVFrame*> cached_frames_;
|
||||
|
||||
bool cache_at_zero_;
|
||||
bool cache_at_eof_;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A Decoder derivative that wraps FFmpeg functions as on Olive decoder
|
||||
*/
|
||||
@@ -88,59 +144,29 @@ private:
|
||||
*/
|
||||
void FFmpegError(int error_code);
|
||||
|
||||
/**
|
||||
* @brief Uses the FFmpeg API to retrieve a packet (stored in pkt_) and decode it (stored in frame_)
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* An FFmpeg error code, or >= 0 on success
|
||||
*/
|
||||
int GetFrame(AVPacket* pkt, AVFrame* frame);
|
||||
|
||||
virtual QString GetIndexFilename() override;
|
||||
|
||||
void UnconditionalAudioIndex(const QAtomicInt* cancelled);
|
||||
|
||||
void Seek(int64_t timestamp);
|
||||
|
||||
void CacheFrameToDisk(AVFrame* f);
|
||||
|
||||
void ClearFrameCache();
|
||||
|
||||
void ClearResources();
|
||||
|
||||
void SetupScaler(const int& divider);
|
||||
void FreeScaler();
|
||||
|
||||
int64_t RangeStart() const;
|
||||
int64_t RangeEnd() const;
|
||||
bool CacheContainsTime(const int64_t& t) const;
|
||||
bool CacheWillContainTime(const rational& t) const;
|
||||
bool CacheCouldContainTime(const rational& t) const;
|
||||
AVFrame* GetFrameFromCache(const int64_t& t) const;
|
||||
|
||||
AVFormatContext* fmt_ctx_;
|
||||
AVCodecContext* codec_ctx_;
|
||||
AVStream* avstream_;
|
||||
|
||||
AVPixelFormat src_pix_fmt_;
|
||||
AVPixelFormat ideal_pix_fmt_;
|
||||
PixelFormat::Format native_pix_fmt_;
|
||||
|
||||
rational time_base_;
|
||||
rational aspect_ratio_;
|
||||
int64_t start_time_;
|
||||
|
||||
SwsContext* scale_ctx_;
|
||||
int scale_divider_;
|
||||
|
||||
QWaitCondition cache_wait_cond_;
|
||||
QWaitCondition cache_retrieve_cond_;
|
||||
QMutex cache_lock_;
|
||||
QMutex retrieve_lock_;
|
||||
QList<AVFrame*> cached_frames_;
|
||||
rational cache_target_time_;
|
||||
bool cache_at_zero_;
|
||||
bool cache_at_eof_;
|
||||
|
||||
int64_t second_ts_;
|
||||
|
||||
AVDictionary* opts_;
|
||||
FFmpegDecoderInstance* instance_;
|
||||
|
||||
//QTimer clear_timer_;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user