Browse Source

Use shared live encoder types in stream publication

stream-multiview
evgeny 1 week ago
parent
commit
45720ebaba
  1. 8
      tools/chatgui/src/stream_publish_engine.cpp
  2. 4
      tools/chatgui/src/stream_publish_engine.h
  3. 2
      tools/chatgui/src/stream_publish_window.cpp

8
tools/chatgui/src/stream_publish_engine.cpp

@ -82,7 +82,7 @@ StreamPublishEngine::StreamPublishEngine(QObject* parent) : QObject(parent), m(s
#endif #endif
try { try {
m->probeThread = std::thread([this] { m->probeThread = std::thread([this] {
auto codecs = supported() ? StreamVideoEncoder::available() : QList<int>(); auto codecs = supported() ? LiveVideoEncoder::available() : QList<int>();
std::lock_guard<std::mutex> guard(m->lock); m->codecs = std::move(codecs); m->probeReady = true; std::lock_guard<std::mutex> guard(m->lock); m->codecs = std::move(codecs); m->probeReady = true;
}); });
} catch (const std::system_error& error) { } catch (const std::system_error& error) {
@ -415,7 +415,7 @@ void StreamPublishEngine::audioLoop() {
void StreamPublishEngine::videoLoop() { void StreamPublishEngine::videoLoop() {
#ifdef HAVE_STREAM_CAPTURE #ifdef HAVE_STREAM_CAPTURE
std::unique_ptr<StreamVideoEncoder> encoder; std::unique_ptr<LiveVideoEncoder> encoder;
StreamPublishConfig encoding; StreamPublishConfig encoding;
QImage lastImage; uint64_t current = 0; uint32_t revision = 0; QImage lastImage; uint64_t current = 0; uint32_t revision = 0;
int64_t lastPts = -1, lastKey = -1000000, next = 0, report = 0; unsigned count = 0, skipped = 0; int64_t lastPts = -1, lastKey = -1000000, next = 0, report = 0; unsigned count = 0, skipped = 0;
@ -438,7 +438,7 @@ void StreamPublishEngine::videoLoop() {
if (generation == m->generation) { emit configurationChanged(); emit stateChanged(text("Live")); } if (generation == m->generation) { emit configurationChanged(); emit stateChanged(text("Live")); }
}); });
} else { } else {
auto candidate = std::make_unique<StreamVideoEncoder>(); auto candidate = std::make_unique<LiveVideoEncoder>();
if (!candidate->open(config.video)) { if (!candidate->open(config.video)) {
QString error = candidate->error(); QString error = candidate->error();
QMetaObject::invokeMethod(this, [this, generation, error] { sourceFailed(generation, error); }); QMetaObject::invokeMethod(this, [this, generation, error] { sourceFailed(generation, error); });
@ -475,7 +475,7 @@ void StreamPublishEngine::videoLoop() {
next = now + 1000000 / config.video.fps; next = now + 1000000 / config.video.fps;
stream_publisher_status status; bool needsKey = gui_stream_publish_status(m->id, status) && status.need_key; stream_publisher_status status; bool needsKey = gui_stream_publish_status(m->id, status) && status.need_key;
bool key = pts - lastKey >= 1000000 || needsKey; bool key = pts - lastKey >= 1000000 || needsKey;
QList<StreamEncodedFrame> output; QList<LiveEncodedFrame> output;
if (!encoder->encode(lastImage, std::max(lastPts + 1, pts), key, output)) { if (!encoder->encode(lastImage, std::max(lastPts + 1, pts), key, output)) {
QString error = encoder->error(); QMetaObject::invokeMethod(this, [this, generation, error] { sourceFailed(generation, error); }); continue; QString error = encoder->error(); QMetaObject::invokeMethod(this, [this, generation, error] { sourceFailed(generation, error); }); continue;
} }

4
tools/chatgui/src/stream_publish_engine.h

@ -8,7 +8,7 @@
#include <QImage> #include <QImage>
#include <QList> #include <QList>
#include <memory> #include <memory>
#include "stream_video_encoder.h" #include "live_video_encoder.h"
#include "audio_device.h" #include "audio_device.h"
#include "audio_capture_lease.h" #include "audio_capture_lease.h"
#include "../../../src/stream/stream_publisher.h" #include "../../../src/stream/stream_publisher.h"
@ -22,7 +22,7 @@ struct StreamVideoSource {
}; };
struct StreamPublishConfig { struct StreamPublishConfig {
StreamVideoSource source; StreamVideoSource source;
StreamVideoConfig video; LiveVideoConfig video;
QString microphone; QString microphone;
bool audio = true; bool audio = true;
}; };

2
tools/chatgui/src/stream_publish_window.cpp

@ -120,7 +120,7 @@ void StreamPublishWindow::refreshSources() {
} }
void StreamPublishWindow::refreshCodecs() { void StreamPublishWindow::refreshCodecs() {
m_updating = true; int previous = m_codec->currentData().toInt(); m_codec->clear(); m_updating = true; int previous = m_codec->currentData().toInt(); m_codec->clear();
for (int codec : m_engine->codecs()) m_codec->addItem(StreamVideoEncoder::codecName(codec), codec); for (int codec : m_engine->codecs()) m_codec->addItem(LiveVideoEncoder::codecName(codec), codec);
int index = m_codec->findData(previous); if (index >= 0) m_codec->setCurrentIndex(index); int index = m_codec->findData(previous); if (index >= 0) m_codec->setCurrentIndex(index);
m_updating = false; synchronize(); m_updating = false; synchronize();
} }

Loading…
Cancel
Save