Пример #1
0
bool GstVideoPlayerBackend::setSpeed(double speed)
{
    if (!m_pipeline)
        return false;

    if (speed == m_playbackSpeed)
        return true;

    if (speed == 0)
        return false;

    gboolean re = gst_element_seek(m_pipeline, speed, GST_FORMAT_TIME,
                                   GstSeekFlags(GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_SKIP),
                                   GST_SEEK_TYPE_SET, position(), GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);

    if (!re)
    {
        qDebug() << "gstreamer: Setting playback speed failed";
        emit nonFatalError(tr("Playback speed failed"));
    }
    else
    {
        m_playbackSpeed = speed;
        m_lastspeed = speed;
        qDebug() << "gstreamer: set playback speed to" << m_playbackSpeed;
        emit playbackSpeedChanged(m_playbackSpeed);
    }

    return re ? true : false;
}
bool VideoPlayerBackend::seek(qint64 position)
{
    if (!m_pipeline)
        return false;

    if (state() != Playing && state() != Paused)
    {
        qDebug() << "gstreamer: Stream is not playing or paused, ignoring seek";
        return false;
    }

    gboolean re = gst_element_seek(m_pipeline, m_playbackSpeed, GST_FORMAT_TIME,
                            (GstSeekFlags)(GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_SKIP |
                                           GST_SEEK_FLAG_KEY_UNIT /* removing this will seek between
                                                                   * keyframes, but is much slower */
                                           ),
                            GST_SEEK_TYPE_SET, position, GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);

    if (!re)
    {
        qDebug() << "gstreamer: seek to position" << position << "failed";
        emit nonFatalError(tr("Seeking failed"));
    }

    return re ? true : false;
}
Пример #3
0
// Write text to the specified socket. Returns false on error.
bool Socket::nb_write(int fd, std::string& s, int *bytesSoFar)
{
  int nToWrite = int(s.length()) - *bytesSoFar;
  char *sp = const_cast<char*>(s.c_str()) + *bytesSoFar;
  bool wouldBlock = false;

  while ( nToWrite > 0 && ! wouldBlock ) {
#if defined(_WIN32)
    int n = send(fd, sp, nToWrite, 0);
#else
    int n = write(fd, sp, nToWrite);
#endif
    g_debug("Socket::nbWrite: send/write returned %d.", n);

    if (n > 0) {
      sp += n;
      *bytesSoFar += n;
      nToWrite -= n;
    } else if (nonFatalError()) {
      wouldBlock = true;
    } else {
      return false;   // Error
    }
  }
  return true;
}
Пример #4
0
// Read available text from the specified socket. Returns false on error.
bool Socket::nb_read(int fd, std::string& s, bool *eof)
{
  const int READ_SIZE = 4096;   // Number of bytes to attempt to read at a time
  char readBuf[READ_SIZE];

  bool wouldBlock = false;
  *eof = false;

  while ( ! wouldBlock && ! *eof) {
#if defined(_WIN32)
    int n = recv(fd, readBuf, READ_SIZE-1, 0);
#else
    int n = read(fd, readBuf, READ_SIZE-1);
#endif
    g_debug("Socket::nbRead: read/recv returned %d.", n);


    if (n > 0) {
      readBuf[n] = 0;
      s.append(readBuf, n);
    } else if (n == 0) {
      *eof = true;
    } else if (nonFatalError()) {
      wouldBlock = true;
    } else {
      return false;   // Error
    }
  }
  return true;
}
Пример #5
0
// Connect a unix domain socket to a server (from a client)
bool
Socket::connect(int fd, const std::string& path)
{
#if defined(_WIN32)
	return false;//unix domain sockets are not supported on windows
#else
  struct sockaddr_un saddr;
  memset(&saddr, 0, sizeof(saddr));
  saddr.sun_family = AF_UNIX;
  strcpy(saddr.sun_path, path.c_str());

  // For asynch operation, this will return EWOULDBLOCK (windows) or
  // EINPROGRESS (linux) and we just need to wait for the socket to be writable...
  int result = ::connect(fd, (struct sockaddr *)&saddr, sizeof(saddr));
  return result == 0 || nonFatalError();
#endif
}
Пример #6
0
// Connect a socket to a server (from a client)
bool
Socket::connect(int fd, std::string& host, int port)
{
  struct sockaddr_in saddr;
  memset(&saddr, 0, sizeof(saddr));
  saddr.sin_family = AF_INET;

  struct hostent *hp = gethostbyname(host.c_str());
  if (hp == 0) return false;

  saddr.sin_family = hp->h_addrtype;
  memcpy(&saddr.sin_addr, hp->h_addr, hp->h_length);
  saddr.sin_port = htons((u_short) port);

  // For asynch operation, this will return EWOULDBLOCK (windows) or
  // EINPROGRESS (linux) and we just need to wait for the socket to be writable...
  int result = ::connect(fd, (struct sockaddr *)&saddr, sizeof(saddr));
  return result == 0 || nonFatalError();
}