From 71048f40a8d121bf5cf3c14baa130640e7e5e7ee Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Thu, 20 Feb 2020 02:22:59 +1100 Subject: [PATCH] ffmpegdecoder: removed all old code to clean up --- app/codec/ffmpeg/ffmpegdecoder.cpp | 100 +---------------------- app/codec/ffmpeg/ffmpegdecoder.h | 6 -- app/render/backend/videorenderworker.cpp | 5 +- 3 files changed, 7 insertions(+), 104 deletions(-) diff --git a/app/codec/ffmpeg/ffmpegdecoder.cpp b/app/codec/ffmpeg/ffmpegdecoder.cpp index fb16bd7d7..be49ce99f 100644 --- a/app/codec/ffmpeg/ffmpegdecoder.cpp +++ b/app/codec/ffmpeg/ffmpegdecoder.cpp @@ -46,18 +46,12 @@ FFmpegDecoder::FFmpegDecoder() : codec_ctx_(nullptr), scale_ctx_(nullptr), pkt_(nullptr), -#ifdef USE_VIDEO_INDEX - frame_(nullptr), -#else last_retrieved_frame_(nullptr), -#endif opts_(nullptr), multithreading_(false) { -#ifndef USE_VIDEO_INDEX frames_[0] = nullptr; frames_[1] = nullptr; -#endif } FFmpegDecoder::~FFmpegDecoder() @@ -188,16 +182,8 @@ bool FFmpegDecoder::Open() return false; } -#ifdef USE_VIDEO_INDEX - frame_ = av_frame_alloc(); - if (!frame_) { - Error(QStringLiteral("Failed to allocate AVFrame")); - return false; - } -#else frames_[0] = av_frame_alloc(); frames_[1] = av_frame_alloc(); -#endif // All allocation succeeded so we set the state to open open_ = true; @@ -212,12 +198,7 @@ Decoder::RetrieveState FFmpegDecoder::GetRetrieveState(const rational& time) } if (avstream_->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { - // Check index - int64_t ts = std::static_pointer_cast(stream())->get_closest_timestamp_in_frame_index(time); - if (ts < 0) { - return kIndexUnavailable; - } } else if (avstream_->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { AudioStreamPtr audio_stream = std::static_pointer_cast(stream()); @@ -239,13 +220,7 @@ FramePtr FFmpegDecoder::RetrieveVideo(const rational &timecode) return nullptr; } - // Convert timecode to AVStream timebase - int64_t target_ts = std::static_pointer_cast(stream())->get_closest_timestamp_in_frame_index(timecode); - - if (target_ts < 0) { - Error(QStringLiteral("Index failed to produce a valid timestamp")); - return nullptr; - } + int64_t target_ts = Timecode::time_to_timestamp(timecode, avstream_->time_base); // Allocate frame that we'll return FramePtr frame_container = Frame::Create(); @@ -256,23 +231,12 @@ FramePtr FFmpegDecoder::RetrieveVideo(const rational &timecode) frame_container->set_sample_aspect_ratio(av_guess_sample_aspect_ratio(fmt_ctx_, avstream_, nullptr)); frame_container->allocate(); -#ifdef USE_VIDEO_INDEX - bool got_frame = (frame_->pts == target_ts); -#else bool got_frame = false; -#endif QByteArray frame_loader; uint8_t* input_data[4]; int input_linesize[4]; -#ifdef USE_VIDEO_INDEX - // If we already have the frame, we'll need to set the pointers to it - for (int i=0;i<4;i++) { - input_data[i] = frame_->data[i]; - input_linesize[i] = frame_->linesize[i]; - } -#else { AVFrame* test_existing = nullptr; @@ -291,7 +255,6 @@ FramePtr FFmpegDecoder::RetrieveVideo(const rational &timecode) got_frame = true; } } -#endif // See if we stored this frame in the disk cache if (!got_frame) { @@ -321,14 +284,10 @@ FramePtr FFmpegDecoder::RetrieveVideo(const rational &timecode) if (!got_frame) { int64_t second_ts = qRound64(av_q2d(av_inv_q(avstream_->time_base))); -#ifdef USE_VIDEO_INDEX - if (frame_->pts < target_ts - 2*second_ts || frame_->pts > target_ts) { -#else if (!last_retrieved_frame_ || last_retrieved_frame_->pts == AV_NOPTS_VALUE || last_retrieved_frame_->pts < target_ts - 2*second_ts || last_retrieved_frame_->pts > target_ts) { -#endif Seek(target_ts); } @@ -336,37 +295,6 @@ FramePtr FFmpegDecoder::RetrieveVideo(const rational &timecode) int ret; -#ifdef USE_VIDEO_INDEX - while (true) { - ret = GetFrame(pkt_, frame_); - - if (ret < 0) { - FFmpegError(ret); - break; - } - - if (frame_->pts > target_ts) { - // Seek failed, try again - seek_ts -= second_ts; - Seek(seek_ts); - continue; - } - - if (frame_->pts == target_ts) { - // We found the frame we want - got_frame = true; - - // Set data arrays to the frame's data - for (int i=0;i<4;i++) { - input_data[i] = frame_->data[i]; - input_linesize[i] = frame_->linesize[i]; - } - - CacheFrameToDisk(frame_); - break; - } - } -#else bool frame_flipper = false; bool still_seeking = true; @@ -381,7 +309,7 @@ FramePtr FFmpegDecoder::RetrieveVideo(const rational &timecode) } if (still_seeking) { - if (working_frame->pts > target_ts) { + if (working_frame->pts > target_ts || working_frame->pts == AV_NOPTS_VALUE) { // Seek failed, try again seek_ts -= second_ts; Seek(seek_ts); @@ -409,13 +337,12 @@ FramePtr FFmpegDecoder::RetrieveVideo(const rational &timecode) input_linesize[i] = found_frame->linesize[i]; } - CacheFrameToDisk(found_frame); + //CacheFrameToDisk(found_frame); break; } frame_flipper = !frame_flipper; } -#endif } // If we're here and got the frame, we'll convert it and return it @@ -479,12 +406,6 @@ void FFmpegDecoder::Close() opts_ = nullptr; } -#ifdef USE_VIDEO_INDEX - if (frame_) { - av_frame_free(&frame_); - frame_ = nullptr; - } -#else last_retrieved_frame_ = nullptr; if (frames_[1]) { @@ -496,7 +417,6 @@ void FFmpegDecoder::Close() av_frame_free(&frames_[0]); frames_[0] = nullptr; } -#endif if (pkt_) { av_packet_free(&pkt_); @@ -708,11 +628,7 @@ void FFmpegDecoder::Index(const QAtomicInt* cancelled) QMutexLocker locker(stream()->index_process_lock()); - if (stream()->type() == Stream::kVideo) { - - ValidateVideoIndex(cancelled); - - } else if (stream()->type() == Stream::kAudio) { + if (stream()->type() == Stream::kAudio) { if (QFileInfo::exists(GetIndexFilename())) { WaveInput input(GetIndexFilename()); @@ -724,11 +640,7 @@ void FFmpegDecoder::Index(const QAtomicInt* cancelled) } } -#ifdef USE_VIDEO_INDEX - UnconditionalAudioIndex(pkt_, frame_, cancelled); -#else UnconditionalAudioIndex(pkt_, frames_[0], cancelled); -#endif } } @@ -974,11 +886,7 @@ void FFmpegDecoder::ValidateVideoIndex(const QAtomicInt* cancelled) // Reset state Seek(0); -#ifdef USE_VIDEO_INDEX - UnconditionalVideoIndex(pkt_, frame_, cancelled); -#else UnconditionalVideoIndex(pkt_, frames_[0], cancelled); -#endif Seek(0); } diff --git a/app/codec/ffmpeg/ffmpegdecoder.h b/app/codec/ffmpeg/ffmpegdecoder.h index 8115d9673..c3765c463 100644 --- a/app/codec/ffmpeg/ffmpegdecoder.h +++ b/app/codec/ffmpeg/ffmpegdecoder.h @@ -34,8 +34,6 @@ extern "C" { #include "codec/waveoutput.h" #include "project/item/footage/videostream.h" -//#define USE_VIDEO_INDEX - /** * @brief A Decoder derivative that wraps FFmpeg functions as on Olive decoder */ @@ -117,12 +115,8 @@ private: AVPacket* pkt_; -#ifdef USE_VIDEO_INDEX - AVFrame* frame_; -#else AVFrame* frames_[2]; AVFrame* last_retrieved_frame_; -#endif AVDictionary* opts_; diff --git a/app/render/backend/videorenderworker.cpp b/app/render/backend/videorenderworker.cpp index 672c94ca4..04bced33e 100644 --- a/app/render/backend/videorenderworker.cpp +++ b/app/render/backend/videorenderworker.cpp @@ -180,7 +180,8 @@ void VideoRenderWorker::HashNodeRecursively(QCryptographicHash *hash, const Node // Footage timestamp if (stream->type() == Stream::kVideo) { - Decoder::RetrieveState state = decoder->GetRetrieveState(input_time); + hash->addData(QStringLiteral("%1/%2").arg(input_time.numerator(), input_time.denominator()).toUtf8()); + /*Decoder::RetrieveState state = decoder->GetRetrieveState(input_time); if (state == Decoder::kReady) { VideoStreamPtr video_stream = std::static_pointer_cast(stream); @@ -190,7 +191,7 @@ void VideoRenderWorker::HashNodeRecursively(QCryptographicHash *hash, const Node hash->addData(QString::number(timestamp_here).toUtf8()); } else { ReportUnavailableFootage(stream, state, input_time); - } + }*/ } } }