Example #1
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;
}
Example #2
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);
}