Example #1
0
QGst::BinPtr GstExporter::createDecoder(const int i) {
  qDebug() << "createDecoder start, i: " << i;
  char* decArray = nameWithIndex("decoder", i);
  QGst::BinPtr decoderBin;
  try {
    decoderBin = QGst::Bin::create(decArray);
    QGst::ElementPtr parser = QGst::ElementFactory::make("h264parse");
    QGst::ElementPtr decoder;
    if (usesOmx) {
      decoder = QGst::ElementFactory::make("omxh264dec");
    } else {
      decoder = QGst::ElementFactory::make("avdec_h264");
    }
    decoderBin->add(parser, decoder);
    parser->link(decoder);

    QGst::PadPtr parserSinkPad = parser->getStaticPad("sink");
    QGst::PadPtr decoderSrcPad = decoder->getStaticPad("src");

    // Add Ghostpads for abstraction
    decoderBin->addPad(QGst::GhostPad::create(parserSinkPad, "sink"));
    decoderBin->addPad(QGst::GhostPad::create(decoderSrcPad, "src"));

  } catch (const QGlib::Error& error) {
    qCritical() << "Failed to create a decoder:" << error;
    return QGst::BinPtr();
  }
  return decoderBin;
}
Example #2
0
void SignalsTest::closureTest()
{
    QGst::PipelinePtr pipeline = QGst::Pipeline::create("mypipeline");
    QGst::BinPtr bin = QGst::Bin::create("mybin");

    closureCalled = false;
    QGlib::connect(bin, "element-added", this, &SignalsTest::closureTestClosure, QGlib::PassSender);
    bin->add(pipeline);
    QCOMPARE(closureCalled, true);
}
Example #3
0
void SignalsTest::emitTypeTest()
{
    QGst::BinPtr bin = QGst::Bin::create("mybin");
    QGlib::connect(bin, "deep-notify", this, &SignalsTest::closureTestClosure, QGlib::PassSender);

    closureCalled = false;
    QGst::PipelinePtr pipeline = QGst::Pipeline::create("mypipeline");
    QGlib::emit<void>(bin, "deep-notify", pipeline, bin->findProperty("name"));
    QCOMPARE(closureCalled, true);
}
Example #4
0
void GstRecorder::createRtpSink(quint16 port, QString address) {
  QGst::BinPtr videoSrcBin = createVideoSrcBin();
  QGst::ElementPtr rtpbin = QGst::ElementFactory::make("rtpbin");
  QGst::ElementPtr h264pay = QGst::ElementFactory::make("rtph264pay");

  if (!videoSrcBin || !rtpbin) {
    qDebug() << "Error. One or more elements could not be created.";
    return;
  }

  m_pipeline = QGst::Pipeline::create();
  m_pipeline->add(videoSrcBin, h264pay);
  videoSrcBin->link(h264pay);

  m_pipeline->add(rtpbin);
  // send_rtp_sink_0 is needed as a parameter for rtpbin for the configuration
  h264pay->link(rtpbin, "send_rtp_sink_0");

  QGst::ElementPtr RtpUdpSink = QGst::ElementFactory::make("udpsink");
  RtpUdpSink->setProperty("port", (int)port);
  RtpUdpSink->setProperty("host", address);
  if (!RtpUdpSink) {
    qFatal("Failed to create udpsink. Aborting...");
  }
  m_pipeline->add(RtpUdpSink);
  rtpbin->link("send_rtp_src_0", RtpUdpSink);

  QGst::ElementPtr RtcpUdpSink = QGst::ElementFactory::make("udpsink");
  RtcpUdpSink->setProperty("port", port + 1);
  RtcpUdpSink->setProperty("host", address);
  RtcpUdpSink->setProperty("sync", false);  // needed for real-time
  RtcpUdpSink->setProperty("async", false);
  m_pipeline->add(RtcpUdpSink);
  rtpbin->link("send_rtcp_src_0", RtcpUdpSink);

  QGst::ElementPtr RtcpUdpSrc = QGst::ElementFactory::make("udpsrc");
  RtcpUdpSrc->setProperty("port", port + 2);
  m_pipeline->add(RtcpUdpSrc);
  RtcpUdpSrc->link(rtpbin, "recv_rtcp_sink_0");

  // watch the bus
  m_pipeline->bus()->addSignalWatch();
  QGlib::connect(m_pipeline->bus(), "message", this,
                 &GstRecorder::onBusMessage);

  qDebug() << "Streaming to RTP";

  m_pipeline->setState(QGst::StatePlaying);
}
Example #5
0
const QString GstRecorder::recordLocally() {
  QGst::BinPtr videoSrcBin = createVideoSrcBin();
  //QGst::BinPtr audioSrcBin = createAudioSrcBin();
  //QGst::ElementPtr mux = QGst::ElementFactory::make("mp4mux");

  QGst::BinPtr mux = createVideoMuxBin();
  QGst::ElementPtr sink = QGst::ElementFactory::make("filesink");

  QString currentTime =
      QDateTime::currentDateTime().toString("yyyy_MM_dd_hh_mm_ss");

  const QString filename = QDir::current().absoluteFilePath(
      currentTime + "-device-" + QString::number(deviceNumber) + ".mp4");
  qDebug() << "GstRecorder: writing to:" << filename;
  sink->setProperty("location", filename);

  if (!videoSrcBin || !sink) {
    qDebug() << "Error. One or more elements could not be created.";
    return "";
  }
  if (m_pipeline) {
    qDebug() << "Another Recording was not started. Already one in progress";
    return "";
  }

  m_pipeline = QGst::Pipeline::create();
  //m_pipeline->add(videoSrcBin, audioSrcBin, mux, sink);

  m_pipeline->add(videoSrcBin, mux, sink);

  //QGst::PadPtr videoPad = mux->getRequestPad("video_%u");
  //QGst::PadPtr audioPad = mux->getRequestPad("audio_%u");

  //videoSrcBin->getStaticPad("src")->link(videoPad);
  //audioSrcBin->getStaticPad("src")->link(audioPad);

  videoSrcBin->link(mux);
  mux->link(sink);

  m_pipeline->bus()->addSignalWatch();
  QGlib::connect(m_pipeline->bus(), "message", this,
                 &GstRecorder::onBusMessage);

  m_pipeline->setState(QGst::StatePlaying);

  return filename;
}
QGst::BinPtr QtGStreamerCaptureBackend::createAudioSrcBin()
{
    QGst::BinPtr audioBin;

    try {
        audioBin = QGst::Bin::fromDescription("autoaudiosrc name=\"audiosrc\" ! audioconvert ! "
                                              "audioresample ! audiorate ! vorbisenc name=enc quality=0.6 ! queue");
    } catch (const QGlib::Error &error) {
        qCritical() << "Failed to create audio source bin:" << error;
        return QGst::BinPtr();
    }
    QGst::ElementPtr src = audioBin->getElementByName("audiosrc");
    //autoaudiosrc creates the actual source in the READY state

    src->setState(QGst::StateReady);
    return audioBin;
}
Example #7
0
QGst::BinPtr GstExporter::createFileSrcBin(const QString path, const int i) {
  qDebug() << "creating filesrc bin, path: " << path << " i: " << i;
  QGst::BinPtr videoBin;

  QDir current = QDir::current();
  current.cd("recordings");
  const QString fullPath = current.absoluteFilePath(path);

  try {
    char* srcname = nameWithIndex("file", i);
    QGst::ElementPtr src = QGst::ElementFactory::make("filesrc", srcname);
    src->setProperty("location", fullPath);

    char* demuxName = nameWithIndex("demux", i);
    QGst::ElementPtr demuxer = QGst::ElementFactory::make("qtdemux", demuxName);
    QGst::BinPtr decoder = createDecoder(i);
    QGst::ElementPtr scale = QGst::ElementFactory::make("videoscale");
    QGst::ElementPtr capsfilter =
        createCapsFilter(elementWidthPx, elementHeightPx);

    char* binname = nameWithIndex("filebin", i);
    videoBin = QGst::Bin::create(binname);

    videoBin->add(src, demuxer, decoder, capsfilter, scale);
    src->link(demuxer);
    videoBin->linkMany(decoder, scale, capsfilter);

    qDebug() << "filesrc bin: Added and linked all elements";

    QGst::PadPtr filterPadSrc = capsfilter->getStaticPad("src");
    videoBin->addPad(QGst::GhostPad::create(filterPadSrc, "src"));

    qDebug() << "filesrc bin: Added Ghostpad to the bin";

    QGlib::connect(demuxer, "pad-added", this, &GstExporter::callbackNewPad,
                   QGlib::PassSender);

  } catch (const QGlib::Error& error) {
    qCritical() << "Failed to create a filesource:" << error;
    return QGst::BinPtr();
  }

  return videoBin;
}
Example #8
0
QGst::BinPtr GstRecorder::createAudioSrcBin() {
  QGst::BinPtr audioBin;
  qDebug() << "creating Audio Source bin.";

  try {
    audioBin = QGst::Bin::fromDescription(
        "autoaudiosrc name=\"audiosrc\" ! audioconvert ! "
        "audioresample ! audiorate ! speexenc ! queue");
  } catch (const QGlib::Error &error) {
    qCritical() << "Failed to create audioSrcBin: " << error;
    return QGst::BinPtr();
  }

  QGst::ElementPtr src = audioBin->getElementByName("audiosrc");
  //autoaudiosrc creates the actual source in the READY state
  src->setState(QGst::StateReady);

  return audioBin;
}
Example #9
0
void RefPointerTest::equalityTest()
{
    QGst::BinPtr bin = QGst::Bin::create();
    QGst::ElementPtr element = bin;
    QVERIFY(element == bin);
    QVERIFY(bin == element);
    QVERIFY(bin == bin);

    GstElement *e = element;
    QVERIFY(e == element);
    QVERIFY(element == e);
    QVERIFY(bin == e);
    QVERIFY(e == bin);

    e++;
    QVERIFY(e != element);
    QVERIFY(element != e);
    QVERIFY(bin != e);
    QVERIFY(e != bin);

    e = NULL;
    QVERIFY(e != element);
    QVERIFY(element != e);
    QVERIFY(bin != e);
    QVERIFY(e != bin);

    element.clear();
    QVERIFY(element != bin);
    QVERIFY(bin != element);
    QVERIFY(e == element);
    QVERIFY(element == e);

    bin.clear();
    QVERIFY(element == bin);
    QVERIFY(bin == element);
    QVERIFY(bin == bin);
    QVERIFY(bin == e);
    QVERIFY(e == bin);
}
Example #10
0
QGst::BinPtr GstRecorder::createVideoSrcBin() {
  QGst::BinPtr videoBin;

  try {
    videoBin = QGst::Bin::create();
    QGst::ElementPtr src = QGst::ElementFactory::make("v4l2src");
    src->setProperty("device", devicepath);

    qDebug() << "GstRecorder: v4l2src with device: " << devicepath;

    QGst::ElementPtr encoder;
    QGst::ElementPtr capsfilter =
        createCapsFilter(videoWitdhPx, videoHeightPx, framerate);

    //QGst::ElementPtr parse = QGst::ElementFactory::make("h264parse");
    //QGst::ElementPtr queue = QGst::ElementFactory::make("queue");

    if (usesOmx) {
      encoder = QGst::ElementFactory::make("omxh264enc");
    } else {
      encoder = QGst::ElementFactory::make("x264enc");
      qDebug() << "GstRecoder: created x264enc";
    }

    videoBin->add(src, capsfilter, encoder);
    videoBin->linkMany(src, capsfilter, encoder);

    qDebug() << "GstRecorder: createVideoSrcBin: added and linked the elements";

    QGst::PadPtr encoderSrcPad = encoder->getStaticPad("src");
    videoBin->addPad(QGst::GhostPad::create(encoderSrcPad, "src"));

  } catch (const QGlib::Error &error) {
    qDebug() << "Failed to create video source bin:" << error;
    return QGst::BinPtr();
  }
  return videoBin;
}
Example #11
0
void SignalsTest::emitTest()
{
    QGst::BinPtr bin = QGst::Bin::create("mybin");
    bool isConnected = QGlib::connect(bin, "notify::name",
                                      this, &SignalsTest::emitTestClosure, QGlib::PassSender);

    QVERIFY(isConnected);

    closureCalled = false;
    QGlib::emit<void>(bin, "notify::name", bin->findProperty("name"));
    QCOMPARE(closureCalled, true);

    //calling with wrong return value. should show error message but *call* the signal
    //and return default constructed value for int
    closureCalled = false;
    int r = QGlib::emit<int>(bin, "notify::name", bin->findProperty("name"));
    QCOMPARE(r, int());
    QCOMPARE(closureCalled, true);

    //calling with wrong number of arguments. should show error message and *not call* the signal
    closureCalled = false;
    QGlib::emit<void>(bin, "notify::name");
    QCOMPARE(closureCalled, false);

    //calling wrong signal. will return default constructed value for int
    closureCalled = false;
    r = QGlib::emit<int>(bin, "foobar");
    QCOMPARE(r, int());
    QCOMPARE(closureCalled, false);

    isConnected = !QGlib::disconnect(bin, "notify::name", this, &SignalsTest::emitTestClosure);
    QVERIFY(!isConnected);

    closureCalled = false;
    QGlib::emit<void>(bin, "notify::name", bin->findProperty("name"));
    QCOMPARE(closureCalled, false);
}
void QtGStreamerCaptureBackend::startCapture(const QString &filePath)
{
    // clear pipeline if still existing
    if (m_pipeline) {
        qCWarning(LIBSOUND_LOG) << "removing forgotten pipeline";
        //send an end-of-stream event to flush metadata and cause an EosMessage to be delivered
        m_pipeline->sendEvent(QGst::EosEvent::create());
    }

    QGst::BinPtr audioSrcBin = createAudioSrcBin();
    QGst::ElementPtr mux = QGst::ElementFactory::make("oggmux");
    QGst::ElementPtr sink = QGst::ElementFactory::make("filesink");

    if (!audioSrcBin || !mux || !sink) {
        qCritical() << "One or more elements could not be created. "
                 << "Verify that you have all the necessary element plugins installed.";
        return;
    }

    // set output path
    sink->setProperty("location", filePath);

    m_pipeline = QGst::Pipeline::create();
    m_pipeline->add(audioSrcBin, mux, sink);

    //link elements
    QGst::PadPtr audioPad = mux->getRequestPad("audio_%u");
    audioSrcBin->getStaticPad("src")->link(audioPad);

    mux->link(sink);

    //connect the bus
    m_pipeline->bus()->addSignalWatch();
    QGlib::connect(m_pipeline->bus(), "message", this, &QtGStreamerCaptureBackend::onBusMessage);
    m_pipeline->setState(QGst::StatePlaying);
}
Example #13
0
QGst::BinPtr GstExporter::createVideoMixer() {
  qDebug() << "createVideoMixer start";
  QGst::BinPtr videoMixerBin = QGst::Bin::create();

  try {
    QGst::ElementPtr videoMixer =
        QGst::ElementFactory::make("videomixer", "mix");
    videoMixer->setProperty("background", (int) 1); //black background
    videoMixerBin->add(videoMixer);
    int count = 0;
    // go through every element in the grid
    for (int i = 0; i < rec_->grid.height; ++i) {
      for (int j = 0; j < rec_->grid.width; ++j) {
        VideoFile* current = &rec_->grid.grid[i][j];
        if (current->id != 0) {
          qDebug() << "Working on video[" << i << "][" << j
                   << "] with id: " << current->id;

          QGst::PadPtr pad = videoMixer->getRequestPad("sink_%u");
          pad->setProperty("ypos", i * elementHeightPx);
          pad->setProperty("xpos", j * elementWidthPx);
          qDebug() << "Pad created with xpos: " << pad->property("xpos")
                   << ", ypos: " << pad->property("ypos");
          QGst::BinPtr filesrc = createFileSrcBin(current->filepath, count);
          videoMixerBin->add(filesrc);

          QGst::PadPtr sourcepad = filesrc->getStaticPad("src");
          sourcepad->link(pad);
          ++count;
        }
      }
    }
    QGst::PadPtr mixSrcPad = videoMixer->getStaticPad("src");
    videoMixerBin->addPad(QGst::GhostPad::create(mixSrcPad, "src"));

  } catch (const QGlib::Error& error) {
    qDebug() << "Failed to create a videomixer:" << error;
    return QGst::BinPtr();
  }

  return videoMixerBin;
}