stream: wrote indexing data into the stream classes rather than having them

in the decoders
This commit is contained in:
itsmattkc
2020-02-19 11:40:05 +11:00
parent 4c4b91afd6
commit f63106b2d6
4 changed files with 119 additions and 19 deletions
+46 -1
View File
@@ -20,7 +20,8 @@
#include "audiostream.h"
AudioStream::AudioStream()
AudioStream::AudioStream() :
index_done_(false)
{
set_type(kAudio);
}
@@ -61,3 +62,47 @@ void AudioStream::set_sample_rate(const int &sample_rate)
{
sample_rate_ = sample_rate;
}
const rational &AudioStream::index_length()
{
QMutexLocker locker(&index_access_lock_);
return index_length_;
}
void AudioStream::set_index_length(const rational &index_length)
{
{
QMutexLocker locker(&index_access_lock_);
index_length_ = index_length;
}
emit IndexChanged();
}
const bool &AudioStream::index_done()
{
QMutexLocker locker(&index_access_lock_);
return index_done_;
}
void AudioStream::set_index_done(const bool& index_done)
{
{
QMutexLocker locker(&index_access_lock_);
index_done_ = index_done;
}
emit IndexChanged();
}
void AudioStream::clear_index()
{
QMutexLocker locker(&index_access_lock_);
index_done_ = false;
index_length_ = 0;
}
+13
View File
@@ -43,10 +43,23 @@ public:
const int& sample_rate() const;
void set_sample_rate(const int& sample_rate);
const rational& index_length();
void set_index_length(const rational& index_length);
const bool& index_done();
void set_index_done(const bool &index_done);
void clear_index();
private:
int channels_;
uint64_t layout_;
int sample_rate_;
QMutex index_access_lock_;
rational index_length_;
bool index_done_;
};
using AudioStreamPtr = std::shared_ptr<AudioStream>;
+53 -16
View File
@@ -22,9 +22,12 @@
#include <QFile>
#include "common/timecodefunctions.h"
const int64_t VideoStream::kEndTimestamp = AV_NOPTS_VALUE;
VideoStream::VideoStream()
VideoStream::VideoStream() :
start_time_(0)
{
set_type(kVideo);
}
@@ -46,7 +49,26 @@ void VideoStream::set_frame_rate(const rational &frame_rate)
frame_rate_ = frame_rate;
}
int64_t VideoStream::get_closest_timestamp_in_frame_index(const int64_t &ts)
const int64_t &VideoStream::start_time() const
{
return start_time_;
}
void VideoStream::set_start_time(const int64_t &start_time)
{
start_time_ = start_time;
}
int64_t VideoStream::get_closest_timestamp_in_frame_index(const rational &time)
{
// Get rough approximation of what the timestamp would be in this timebase
int64_t target_ts = Timecode::time_to_timestamp(time, timebase());
// Find closest actual timebase in the file
return get_closest_timestamp_in_frame_index(target_ts);
}
int64_t VideoStream::get_closest_timestamp_in_frame_index(int64_t timestamp)
{
QMutexLocker locker(&index_access_lock_);
@@ -54,7 +76,10 @@ int64_t VideoStream::get_closest_timestamp_in_frame_index(const int64_t &ts)
return -1;
}
if (ts <= 0) {
// Adjust target by stream's start time
timestamp += start_time_;
if (timestamp <= 0) {
return frame_index_.first();
}
@@ -68,9 +93,9 @@ int64_t VideoStream::get_closest_timestamp_in_frame_index(const int64_t &ts)
for (int i=0;i<index_size;i++) {
int64_t this_ts = frame_index_.at(i);
if (this_ts == ts) {
return ts;
} else if (this_ts > ts) {
if (this_ts == timestamp) {
return timestamp;
} else if (this_ts > timestamp) {
return frame_index_.at(i - 1);
}
}
@@ -86,16 +111,24 @@ int64_t VideoStream::get_closest_timestamp_in_frame_index(const int64_t &ts)
void VideoStream::clear_frame_index()
{
QMutexLocker locker(&index_access_lock_);
{
QMutexLocker locker(&index_access_lock_);
frame_index_.clear();
frame_index_.clear();
}
emit IndexChanged();
}
void VideoStream::append_frame_index(const int64_t &ts)
{
QMutexLocker locker(&index_access_lock_);
{
QMutexLocker locker(&index_access_lock_);
frame_index_.append(ts);
frame_index_.append(ts);
}
emit IndexChanged();
}
bool VideoStream::is_frame_index_ready()
@@ -118,17 +151,21 @@ bool VideoStream::load_frame_index(const QString &s)
QFile index_file(s);
if (index_file.exists() && index_file.open(QFile::ReadOnly)) {
QMutexLocker locker(&index_access_lock_);
{
QMutexLocker locker(&index_access_lock_);
// Resize based on filesize
frame_index_.resize(static_cast<size_t>(index_file.size()) / sizeof(int64_t));
// Resize based on filesize
frame_index_.resize(static_cast<size_t>(index_file.size()) / sizeof(int64_t));
// Read frame index into vector
index_file.read(reinterpret_cast<char*>(frame_index_.data()),
index_file.size());
// Read frame index into vector
index_file.read(reinterpret_cast<char*>(frame_index_.data()),
index_file.size());
}
index_file.close();
emit IndexChanged();
return true;
}
+7 -2
View File
@@ -40,10 +40,13 @@ public:
const rational& frame_rate() const;
void set_frame_rate(const rational& frame_rate);
int64_t get_closest_timestamp_in_frame_index(const int64_t& ts);
const int64_t& start_time() const;
void set_start_time(const int64_t& start_time);
int64_t get_closest_timestamp_in_frame_index(const rational& time);
int64_t get_closest_timestamp_in_frame_index(int64_t timestamp);
void clear_frame_index();
void append_frame_index(const int64_t& ts);
//bool is_frame_index_empty();
bool is_frame_index_ready();
int64_t last_frame_index_timestamp();
@@ -55,6 +58,8 @@ private:
QVector<int64_t> frame_index_;
int64_t start_time_;
QMutex index_access_lock_;
};