Refactoring
This commit is contained in:
parent
6c653e5ba2
commit
00a1fe1e32
|
@ -52,7 +52,7 @@ Analyzer::Base::Base(QWidget* parent, uint scopeSize)
|
||||||
m_fht(new FHT(scopeSize)),
|
m_fht(new FHT(scopeSize)),
|
||||||
m_engine(nullptr),
|
m_engine(nullptr),
|
||||||
m_lastScope(512),
|
m_lastScope(512),
|
||||||
current_chunk(0),
|
current_chunk_(0),
|
||||||
new_frame_(false),
|
new_frame_(false),
|
||||||
is_playing_(false) {}
|
is_playing_(false) {}
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ class Base : public QWidget {
|
||||||
FHT* m_fht;
|
FHT* m_fht;
|
||||||
EngineBase* m_engine;
|
EngineBase* m_engine;
|
||||||
Scope m_lastScope;
|
Scope m_lastScope;
|
||||||
int current_chunk;
|
int current_chunk_;
|
||||||
|
|
||||||
bool new_frame_;
|
bool new_frame_;
|
||||||
bool is_playing_;
|
bool is_playing_;
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
#include "gstenginepipeline.h"
|
#include "gstenginepipeline.h"
|
||||||
#include "core/logging.h"
|
#include "core/logging.h"
|
||||||
#include "core/taskmanager.h"
|
#include "core/taskmanager.h"
|
||||||
|
#include "core/timeconstants.h"
|
||||||
#include "core/utilities.h"
|
#include "core/utilities.h"
|
||||||
|
|
||||||
#ifdef HAVE_MOODBAR
|
#ifdef HAVE_MOODBAR
|
||||||
|
@ -98,8 +99,8 @@ GstEngine::GstEngine(TaskManager* task_manager)
|
||||||
next_element_id_(0),
|
next_element_id_(0),
|
||||||
is_fading_out_to_pause_(false),
|
is_fading_out_to_pause_(false),
|
||||||
has_faded_out_(false),
|
has_faded_out_(false),
|
||||||
scope_chunk(0),
|
scope_chunk_(0),
|
||||||
have_new_buffer(false) {
|
have_new_buffer_(false) {
|
||||||
seek_timer_->setSingleShot(true);
|
seek_timer_->setSingleShot(true);
|
||||||
seek_timer_->setInterval(kSeekDelayNanosec / kNsecPerMsec);
|
seek_timer_->setInterval(kSeekDelayNanosec / kNsecPerMsec);
|
||||||
connect(seek_timer_, SIGNAL(timeout()), SLOT(SeekNow()));
|
connect(seek_timer_, SIGNAL(timeout()), SLOT(SeekNow()));
|
||||||
|
@ -240,37 +241,37 @@ void GstEngine::AddBufferToScope(GstBuffer* buf, int pipeline_id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
latest_buffer_ = buf;
|
latest_buffer_ = buf;
|
||||||
have_new_buffer = true;
|
have_new_buffer_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Engine::Scope& GstEngine::scope(int chunk_length) {
|
const Engine::Scope& GstEngine::scope(int chunk_length) {
|
||||||
// the new buffer could have a different size
|
// the new buffer could have a different size
|
||||||
if (have_new_buffer) {
|
if (have_new_buffer_) {
|
||||||
if (latest_buffer_ != nullptr) {
|
if (latest_buffer_ != nullptr) {
|
||||||
scope_chunks = ceil(((double)GST_BUFFER_DURATION(latest_buffer_) /
|
scope_chunks_ = ceil(((double)GST_BUFFER_DURATION(latest_buffer_) /
|
||||||
(double)(chunk_length * 1000000)));
|
(double)(chunk_length * 1000000)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the buffer is shorter than the chunk length
|
// if the buffer is shorter than the chunk length
|
||||||
if (scope_chunks <= 0) {
|
if (scope_chunks_ <= 0) {
|
||||||
scope_chunks = 1;
|
scope_chunks_ = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
scope_chunk = 0;
|
scope_chunk_ = 0;
|
||||||
have_new_buffer = false;
|
have_new_buffer_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateScope(chunk_length);
|
UpdateScope(chunk_length);
|
||||||
return scope_;
|
return scope_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GstEngine::UpdateScope(int chunk_length_) {
|
void GstEngine::UpdateScope(int chunk_length) {
|
||||||
typedef Engine::Scope::value_type sample_type;
|
typedef Engine::Scope::value_type sample_type;
|
||||||
|
|
||||||
// determine where to split the buffer
|
// determine where to split the buffer
|
||||||
int chunk_density = GST_BUFFER_SIZE(latest_buffer_) /
|
int chunk_density = GST_BUFFER_SIZE(latest_buffer_) /
|
||||||
(GST_BUFFER_DURATION(latest_buffer_) / 1000000);
|
(GST_BUFFER_DURATION(latest_buffer_) / kNsecPerMsec);
|
||||||
int chunk_size = chunk_length_ * chunk_density;
|
int chunk_size = chunk_length * chunk_density;
|
||||||
|
|
||||||
// determine the number of channels
|
// determine the number of channels
|
||||||
GstStructure* structure =
|
GstStructure* structure =
|
||||||
|
@ -282,31 +283,31 @@ void GstEngine::UpdateScope(int chunk_length_) {
|
||||||
if (channels > 2) return;
|
if (channels > 2) return;
|
||||||
|
|
||||||
// in case a buffer doesn't arrive in time
|
// in case a buffer doesn't arrive in time
|
||||||
if (scope_chunk >= scope_chunks) {
|
if (scope_chunk_ >= scope_chunks_) {
|
||||||
scope_chunk = 0;
|
scope_chunk_ = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the starting point in the buffer to take data from
|
// set the starting point in the buffer to take data from
|
||||||
const sample_type* source =
|
const sample_type* source =
|
||||||
reinterpret_cast<sample_type*>(GST_BUFFER_DATA(latest_buffer_));
|
reinterpret_cast<sample_type*>(GST_BUFFER_DATA(latest_buffer_));
|
||||||
source += (chunk_size / sizeof(sample_type)) * scope_chunk;
|
source += (chunk_size / sizeof(sample_type)) * scope_chunk_;
|
||||||
sample_type* dest = scope_.data();
|
sample_type* dest = scope_.data();
|
||||||
|
|
||||||
int bytes;
|
int bytes = 0;
|
||||||
|
|
||||||
// make sure we don't go beyond the end of the buffer
|
// make sure we don't go beyond the end of the buffer
|
||||||
if (scope_chunk == scope_chunks - 1) {
|
if (scope_chunk_ == scope_chunks_ - 1) {
|
||||||
bytes = qMin(
|
bytes =
|
||||||
static_cast<Engine::Scope::size_type>(GST_BUFFER_SIZE(latest_buffer_) - (chunk_size * scope_chunk)),
|
qMin(static_cast<Engine::Scope::size_type>(
|
||||||
|
GST_BUFFER_SIZE(latest_buffer_) - (chunk_size * scope_chunk_)),
|
||||||
scope_.size() * sizeof(sample_type));
|
scope_.size() * sizeof(sample_type));
|
||||||
} else {
|
} else {
|
||||||
bytes = qMin(
|
bytes = qMin(static_cast<Engine::Scope::size_type>(chunk_size),
|
||||||
static_cast<Engine::Scope::size_type>(chunk_size),
|
|
||||||
scope_.size() * sizeof(sample_type));
|
scope_.size() * sizeof(sample_type));
|
||||||
}
|
}
|
||||||
|
|
||||||
scope_chunk++;
|
scope_chunk_++;
|
||||||
|
|
||||||
memcpy(dest, source, bytes);
|
memcpy(dest, source, bytes);
|
||||||
}
|
}
|
||||||
|
|
|
@ -224,9 +224,9 @@ class GstEngine : public Engine::Base, public BufferConsumer {
|
||||||
bool is_fading_out_to_pause_;
|
bool is_fading_out_to_pause_;
|
||||||
bool has_faded_out_;
|
bool has_faded_out_;
|
||||||
|
|
||||||
int scope_chunk;
|
int scope_chunk_;
|
||||||
bool have_new_buffer;
|
bool have_new_buffer_;
|
||||||
int scope_chunks;
|
int scope_chunks_;
|
||||||
|
|
||||||
QList<DeviceFinder*> device_finders_;
|
QList<DeviceFinder*> device_finders_;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue