AkVideoCaps::PixelFormat AkVideoCaps::pixelFormatFromString(const QString &pixelFormat) { AkVideoCaps caps; QString format = "Format_" + pixelFormat; int enumIndex = caps.metaObject()->indexOfEnumerator("PixelFormat"); QMetaEnum enumType = caps.metaObject()->enumerator(enumIndex); int enumValue = enumType.keyToValue(format.toStdString().c_str()); return static_cast<PixelFormat>(enumValue); }
QString AkVideoCaps::pixelFormatToString(AkVideoCaps::PixelFormat pixelFormat) { AkVideoCaps caps; int formatIndex = caps.metaObject()->indexOfEnumerator("PixelFormat"); QMetaEnum formatEnum = caps.metaObject()->enumerator(formatIndex); QString format(formatEnum.valueToKey(pixelFormat)); format.remove("Format_"); return format; }
AkCaps VideoStream::caps() const { AkVideoCaps caps; caps.isValid() = true; caps.format() = AkVideoCaps::Format_rgb24; caps.bpp() = AkVideoCaps::bitsPerPixel(caps.format()); caps.width() = this->codecContext()->width; caps.height() = this->codecContext()->height; caps.fps() = this->fps(); return caps.toCaps(); }
AkVideoCaps::AkVideoCaps(const AkVideoCaps &other): QObject() { this->d = new AkVideoCapsPrivate(); this->d->m_isValid = other.d->m_isValid; this->d->m_format = other.d->m_format; this->d->m_bpp = other.d->m_bpp; this->d->m_width = other.d->m_width; this->d->m_height = other.d->m_height; this->d->m_fps = other.d->m_fps; QList<QByteArray> properties = other.dynamicPropertyNames(); for (const QByteArray &property: properties) this->setProperty(property, other.property(property)); }
void DesktopCaptureElement::readFrame() { QScreen *screen = QGuiApplication::screens()[this->m_curScreenNumber]; AkFrac fps(30000, 1001); AkVideoCaps caps; caps.isValid() = true; caps.format() = AkVideoCaps::Format_rgb24; caps.bpp() = AkVideoCaps::bitsPerPixel(caps.format()); caps.width() = screen->size().width(); caps.height() = screen->size().height(); caps.fps() = fps; QPixmap frame = screen->grabWindow(QApplication::desktop()->winId()); QImage frameImg= frame.toImage().convertToFormat(QImage::Format_RGB888); AkPacket packet = AkUtils::imageToPacket(frameImg, caps.toCaps()); if (!packet) return; qint64 pts = qint64(QTime::currentTime().msecsSinceStartOfDay() * fps.value() / 1e3); packet.setPts(pts); packet.setTimeBase(fps.invert()); packet.setIndex(0); packet.setId(this->m_id); if (!this->m_threadedRead) { emit this->oStream(packet); return; } if (!this->m_threadStatus.isRunning()) { this->m_curPacket = packet; this->m_threadStatus = QtConcurrent::run(&this->m_threadPool, this->sendPacket, this, this->m_curPacket); } }
AkCaps DesktopCaptureElement::caps(int stream) const { if (this->m_curScreenNumber < 0 || stream != 0) return AkCaps(); QScreen *screen = QGuiApplication::screens()[this->m_curScreenNumber]; if (!screen) return QString(); AkVideoCaps caps; caps.isValid() = true; caps.format() = AkVideoCaps::Format_rgb24; caps.bpp() = AkVideoCaps::bitsPerPixel(caps.format()); caps.width() = screen->size().width(); caps.height() = screen->size().height(); caps.fps() = this->m_fps; return caps.toCaps(); }
QDebug operator <<(QDebug debug, const AkVideoCaps &caps) { debug.nospace() << caps.toString(); return debug.space(); }
bool AkVideoCaps::operator ==(const AkVideoCaps &other) const { return this->toString() == other.toString(); }