AkPacket MultiplexElement::iStream(const AkPacket &packet) { if (this->m_inputIndex >= 0 && packet.index() != this->m_inputIndex) return AkPacket(); if (!this->m_caps.isEmpty() && !packet.caps().isCompatible(this->m_caps)) return AkPacket(); AkPacket oPacket(packet); if (this->m_outputIndex >= 0) oPacket.setIndex(this->m_outputIndex); akSend(oPacket) }
void CameraOutV4L2::writeFrame(const AkPacket &frame) { if (!this->m_deviceFile.isOpen()) return; if (this->m_deviceFile.write(frame.buffer()) < 0) qDebug() << "Error writing frame"; }
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); } }
AkVideoPacket::AkVideoPacket(const AkPacket &other) { this->d = new AkVideoPacketPrivate(); this->d->m_caps = other.caps(); this->data() = other.data(); this->buffer() = other.buffer(); this->pts() = other.pts(); this->timeBase() = other.timeBase(); this->index() = other.index(); this->id() = other.id(); }
AkPacket AkVideoPacket::toPacket() const { AkPacket packet; packet.caps() = this->d->m_caps.toCaps(); packet.buffer() = this->buffer(); packet.pts() = this->pts(); packet.timeBase() = this->timeBase(); packet.index() = this->index(); packet.id() = this->id(); return packet; }
QDebug operator <<(QDebug debug, const AkPacket &packet) { debug.nospace() << packet.toString().toStdString().c_str(); return debug.space(); }
AkPacket CaptureDShow::readFrame() { IBaseFilter *source = NULL; this->m_graph->FindFilterByName(SOURCE_FILTER_NAME, &source); if (source) { this->m_controlsMutex.lock(); QVariantMap imageControls = this->controlStatus(this->m_globalImageControls); this->m_controlsMutex.unlock(); if (this->m_localImageControls != imageControls) { QVariantMap controls = this->mapDiff(this->m_localImageControls, imageControls); this->setImageControls(source, controls); this->m_localImageControls = imageControls; } this->m_controlsMutex.lock(); QVariantMap cameraControls = this->controlStatus(this->m_globalCameraControls); this->m_controlsMutex.unlock(); if (this->m_localCameraControls != cameraControls) { QVariantMap controls = this->mapDiff(this->m_localCameraControls, cameraControls); this->setCameraControls(source, controls); this->m_localCameraControls = cameraControls; } source->Release(); } AM_MEDIA_TYPE mediaType; ZeroMemory(&mediaType, sizeof(AM_MEDIA_TYPE)); this->m_grabber->GetConnectedMediaType(&mediaType); AkCaps caps = this->capsFromMediaType(&mediaType); AkPacket packet; timeval timestamp; gettimeofday(×tamp, NULL); qint64 pts = qint64((timestamp.tv_sec + 1e-6 * timestamp.tv_usec) * this->m_timeBase.invert().value()); if (this->m_ioMethod != IoMethodDirectRead) { this->m_mutex.lock(); if (this->m_curBuffer.isEmpty()) this->m_waitCondition.wait(&this->m_mutex, 1000); if (!this->m_curBuffer.isEmpty()) { int bufferSize = this->m_curBuffer.size(); QByteArray oBuffer(bufferSize, Qt::Uninitialized); memcpy(oBuffer.data(), this->m_curBuffer.constData(), size_t(bufferSize)); packet = AkPacket(caps, oBuffer); packet.setPts(pts); packet.setTimeBase(this->m_timeBase); packet.setIndex(0); packet.setId(this->m_id); this->m_curBuffer.clear(); } this->m_mutex.unlock(); } else { long bufferSize; HRESULT hr = this->m_grabber->GetCurrentBuffer(&bufferSize, NULL); if (FAILED(hr)) return AkPacket(); QByteArray oBuffer(bufferSize, Qt::Uninitialized); hr = this->m_grabber->GetCurrentBuffer(&bufferSize, reinterpret_cast<long *>(oBuffer.data())); if (FAILED(hr)) return AkPacket(); packet = AkPacket(caps, oBuffer); packet.setPts(pts); packet.setTimeBase(this->m_timeBase); packet.setIndex(0); packet.setId(this->m_id); } return packet; }