ffmpegdecoder: removed all old code to clean up
This commit is contained in:
@@ -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<VideoStream>(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<AudioStream>(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<VideoStream>(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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user