2015-06-11 17:47:56 +00:00
|
|
|
/* GStreamer
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015 Alexandre Moreno <alexmorenocano@gmail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qgstplayer.h"
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QSize>
|
|
|
|
#include <QMetaObject>
|
2015-10-06 15:19:03 +00:00
|
|
|
#include <functional>
|
|
|
|
#include <QThread>
|
2015-10-22 15:05:35 +00:00
|
|
|
#include <QtAlgorithms>
|
2015-06-11 17:47:56 +00:00
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
namespace QGstPlayer {
|
|
|
|
|
|
|
|
class RegisterMetaTypes
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-10-22 15:05:35 +00:00
|
|
|
RegisterMetaTypes()
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
2015-10-22 15:05:35 +00:00
|
|
|
qRegisterMetaType<Player::State>("State");
|
2015-06-11 17:47:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} _register;
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
MediaInfo::MediaInfo(Player *player)
|
|
|
|
: QObject(player)
|
|
|
|
, uri_()
|
|
|
|
, title_()
|
|
|
|
, isSeekable_(false)
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
QString MediaInfo::uri() const
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
2015-10-22 15:05:35 +00:00
|
|
|
return uri_;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString MediaInfo::title() const
|
|
|
|
{
|
|
|
|
return title_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MediaInfo::isSeekable() const
|
|
|
|
{
|
|
|
|
return isSeekable_;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QList<QObject *> &MediaInfo::videoStreams() const
|
|
|
|
{
|
|
|
|
return videoStreams_;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QList<QObject *> &MediaInfo::audioStreams() const
|
|
|
|
{
|
|
|
|
return audioStreams_;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QList<QObject*> &MediaInfo::subtitleStreams() const
|
|
|
|
{
|
|
|
|
return subtitleStreams_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaInfo::update(GstPlayerMediaInfo *info)
|
|
|
|
{
|
|
|
|
Q_ASSERT(info != 0);
|
|
|
|
|
|
|
|
// FIXME since media-info signal gets emitted
|
|
|
|
// several times, we just update info iff the
|
|
|
|
// media uri has changed.
|
|
|
|
if (uri_ == gst_player_media_info_get_uri(info)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uri_ = QString(gst_player_media_info_get_uri(info));
|
|
|
|
|
|
|
|
title_ = QString::fromLocal8Bit(gst_player_media_info_get_title(info));
|
2015-06-11 17:47:56 +00:00
|
|
|
|
|
|
|
// if media has no title, return the file name
|
2015-10-22 15:05:35 +00:00
|
|
|
if (title_.isEmpty()) {
|
|
|
|
QUrl url(gst_player_media_info_get_uri(info));
|
|
|
|
title_ = url.fileName();
|
|
|
|
}
|
|
|
|
|
|
|
|
emit titleChanged();
|
|
|
|
|
|
|
|
if (isSeekable_ != gst_player_media_info_is_seekable(info)) {
|
|
|
|
isSeekable_ = !isSeekable_;
|
|
|
|
emit seekableChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!subtitleStreams_.isEmpty()) {
|
|
|
|
qDeleteAll(subtitleStreams_);
|
|
|
|
subtitleStreams_.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!videoStreams_.isEmpty()) {
|
|
|
|
qDeleteAll(videoStreams_);
|
|
|
|
videoStreams_.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!audioStreams_.isEmpty()) {
|
|
|
|
qDeleteAll(audioStreams_);
|
|
|
|
audioStreams_.clear();
|
2015-06-11 17:47:56 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
GList *list = gst_player_get_subtitle_streams(info);
|
|
|
|
|
|
|
|
g_list_foreach (list, [](gpointer data, gpointer user_data) {
|
|
|
|
GstPlayerSubtitleInfo *info = static_cast<GstPlayerSubtitleInfo*>(data);
|
|
|
|
QList<QObject*> *subs = static_cast<QList<QObject*>*>(user_data);
|
|
|
|
|
|
|
|
subs->append(new SubtitleInfo(info));
|
|
|
|
}, &subtitleStreams_);
|
|
|
|
|
|
|
|
list = gst_player_get_video_streams(info);
|
|
|
|
|
|
|
|
g_list_foreach (list, [](gpointer data, gpointer user_data) {
|
|
|
|
GstPlayerVideoInfo *info = static_cast<GstPlayerVideoInfo*>(data);
|
|
|
|
QList<QObject*> *videos = static_cast<QList<QObject*>*>(user_data);
|
|
|
|
|
|
|
|
videos->append(new VideoInfo(info));
|
|
|
|
}, &videoStreams_);
|
|
|
|
|
|
|
|
list = gst_player_get_audio_streams(info);
|
|
|
|
|
|
|
|
g_list_foreach (list, [](gpointer data, gpointer user_data) {
|
|
|
|
GstPlayerAudioInfo *info = static_cast<GstPlayerAudioInfo*>(data);
|
|
|
|
QList<QObject*> *audios = static_cast<QList<QObject*>*>(user_data);
|
|
|
|
|
|
|
|
audios->append(new AudioInfo(info));
|
|
|
|
}, &audioStreams_);
|
|
|
|
}
|
|
|
|
|
|
|
|
VideoInfo::VideoInfo(GstPlayerVideoInfo *info)
|
|
|
|
: StreamInfo(reinterpret_cast<GstPlayerStreamInfo*>(info))
|
|
|
|
, video_(info)
|
|
|
|
, resolution_(gst_player_video_info_get_width(info), gst_player_video_info_get_height(info))
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize VideoInfo::resolution() const
|
|
|
|
{
|
|
|
|
return resolution_;
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioInfo::AudioInfo(GstPlayerAudioInfo *info)
|
|
|
|
: StreamInfo(reinterpret_cast<GstPlayerStreamInfo*>(info))
|
|
|
|
, audio_(info)
|
|
|
|
, language_(gst_player_audio_info_get_language(info))
|
|
|
|
, channels_(gst_player_audio_info_get_channels(info))
|
|
|
|
, bitRate_(gst_player_audio_info_get_bitrate(info))
|
|
|
|
, sampleRate_(gst_player_audio_info_get_sample_rate(info))
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &AudioInfo::language() const
|
|
|
|
{
|
|
|
|
return language_;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AudioInfo::channels() const
|
|
|
|
{
|
|
|
|
return channels_;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AudioInfo::bitRate() const
|
|
|
|
{
|
|
|
|
return bitRate_;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AudioInfo::sampleRate() const
|
|
|
|
{
|
|
|
|
return sampleRate_;
|
|
|
|
}
|
|
|
|
|
|
|
|
SubtitleInfo::SubtitleInfo(GstPlayerSubtitleInfo *info)
|
|
|
|
: StreamInfo(reinterpret_cast<GstPlayerStreamInfo*>(info))
|
|
|
|
, subtitle_(info)
|
|
|
|
, language_(gst_player_subtitle_info_get_language(info))
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &SubtitleInfo::language() const
|
|
|
|
{
|
|
|
|
return language_;
|
2015-06-11 17:47:56 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
int StreamInfo::index() const
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
2015-10-22 15:05:35 +00:00
|
|
|
return index_;
|
|
|
|
}
|
|
|
|
|
|
|
|
StreamInfo::StreamInfo(GstPlayerStreamInfo *info)
|
|
|
|
: stream_(info)
|
|
|
|
, index_(gst_player_stream_info_get_index(info))
|
|
|
|
{
|
|
|
|
|
2015-06-11 17:47:56 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
bool Player::isVideoAvailable() const
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
GstPlayerVideoInfo *video_info;
|
|
|
|
|
|
|
|
video_info = gst_player_get_current_video_track (player_);
|
|
|
|
if (video_info) {
|
|
|
|
g_object_unref (video_info);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
MediaInfo *Player::mediaInfo() const
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
2015-10-22 15:05:35 +00:00
|
|
|
return mediaInfo_;
|
2015-06-11 17:47:56 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
QVariant Player::currentVideo() const
|
|
|
|
{
|
|
|
|
Q_ASSERT(player_ != 0);
|
|
|
|
|
|
|
|
GstPlayerVideoInfo *track = gst_player_get_current_video_track(player_);
|
|
|
|
|
|
|
|
if (!track)
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
return QVariant::fromValue(new VideoInfo(track));
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant Player::currentAudio() const
|
|
|
|
{
|
|
|
|
Q_ASSERT(player_ != 0);
|
|
|
|
|
|
|
|
GstPlayerAudioInfo *track = gst_player_get_current_audio_track(player_);
|
|
|
|
|
|
|
|
if (!track)
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
return QVariant::fromValue(new AudioInfo(track));
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant Player::currentSubtitle() const
|
|
|
|
{
|
|
|
|
Q_ASSERT(player_ != 0);
|
|
|
|
|
|
|
|
GstPlayerSubtitleInfo *track = gst_player_get_current_subtitle_track(player_);
|
|
|
|
|
|
|
|
if (!track)
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
return QVariant::fromValue(new SubtitleInfo(track));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Player::setCurrentVideo(QVariant track)
|
|
|
|
{
|
|
|
|
Q_ASSERT(player_ != 0);
|
|
|
|
|
|
|
|
VideoInfo* info = track.value<VideoInfo*>();
|
|
|
|
Q_ASSERT(info);
|
|
|
|
|
|
|
|
gst_player_set_video_track(player_, info->index());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Player::setCurrentAudio(QVariant track)
|
|
|
|
{
|
|
|
|
Q_ASSERT(player_ != 0);
|
|
|
|
|
|
|
|
AudioInfo* info = track.value<AudioInfo*>();
|
|
|
|
Q_ASSERT(info);
|
|
|
|
|
|
|
|
gst_player_set_audio_track(player_, info->index());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Player::setCurrentSubtitle(QVariant track)
|
|
|
|
{
|
|
|
|
Q_ASSERT(player_ != 0);
|
|
|
|
|
|
|
|
SubtitleInfo* info = track.value<SubtitleInfo*>();
|
|
|
|
Q_ASSERT(info);
|
|
|
|
|
|
|
|
gst_player_set_subtitle_track(player_, info->index());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Player::isSubtitleEnabled() const
|
|
|
|
{
|
|
|
|
return subtitleEnabled_;
|
|
|
|
}
|
|
|
|
|
2015-10-24 05:28:10 +00:00
|
|
|
quint32 Player::positionUpdateInterval() const
|
|
|
|
{
|
|
|
|
Q_ASSERT(player_ != 0);
|
|
|
|
|
|
|
|
return gst_player_get_position_update_interval(player_);
|
|
|
|
}
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
void Player::setSubtitleEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
Q_ASSERT(player_ != 0);
|
|
|
|
|
|
|
|
subtitleEnabled_ = enabled;
|
|
|
|
|
|
|
|
gst_player_set_subtitle_track_enabled(player_, enabled);
|
|
|
|
|
|
|
|
emit subtitleEnabledChanged(enabled);
|
|
|
|
}
|
|
|
|
|
2015-10-24 05:28:10 +00:00
|
|
|
void Player::setPositionUpdateInterval(quint32 interval)
|
|
|
|
{
|
|
|
|
Q_ASSERT(player_ != 0);
|
|
|
|
|
|
|
|
gst_player_set_position_update_interval(player_, interval);
|
|
|
|
}
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
Player::Player(QObject *parent, VideoRenderer *renderer)
|
2015-06-11 17:47:56 +00:00
|
|
|
: QObject(parent)
|
|
|
|
, player_()
|
|
|
|
, state_(STOPPED)
|
|
|
|
, videoDimensions_(QSize())
|
2015-10-22 15:05:35 +00:00
|
|
|
, mediaInfo_()
|
2015-06-11 17:47:56 +00:00
|
|
|
, videoAvailable_(false)
|
2015-10-22 15:05:35 +00:00
|
|
|
, subtitleEnabled_(false)
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
|
2015-10-06 15:19:03 +00:00
|
|
|
player_ = gst_player_new_full(renderer ? renderer->renderer() : 0,
|
|
|
|
gst_player_qt_signal_dispatcher_new(this));
|
2015-06-11 17:47:56 +00:00
|
|
|
|
|
|
|
g_object_connect(player_,
|
2015-10-22 15:05:35 +00:00
|
|
|
"swapped-signal::state-changed", G_CALLBACK (Player::onStateChanged), this,
|
|
|
|
"swapped-signal::position-updated", G_CALLBACK (Player::onPositionUpdated), this,
|
|
|
|
"swapped-signal::duration-changed", G_CALLBACK (Player::onDurationChanged), this,
|
|
|
|
"swapped-signal::buffering", G_CALLBACK (Player::onBufferingChanged), this,
|
|
|
|
"swapped-signal::video-dimensions-changed", G_CALLBACK (Player::onVideoDimensionsChanged), this,
|
|
|
|
"swapped-signal::volume-changed", G_CALLBACK (Player::onVolumeChanged), this,
|
|
|
|
"swapped-signal::mute-changed", G_CALLBACK (Player::onMuteChanged), this,
|
|
|
|
"swapped-signal::media-info-updated", G_CALLBACK (Player::onMediaInfoUpdated), this, NULL);
|
2015-06-11 17:47:56 +00:00
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
mediaInfo_ = new MediaInfo(this);
|
|
|
|
gst_player_set_subtitle_track_enabled(player_, false);
|
2015-06-11 17:47:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-10-22 15:05:35 +00:00
|
|
|
Player::onStateChanged(Player * player, GstPlayerState state)
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
2015-10-22 15:05:35 +00:00
|
|
|
player->state_ = static_cast<Player::State>(state);
|
2015-06-11 17:47:56 +00:00
|
|
|
|
|
|
|
emit player->stateChanged(player->state_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-10-22 15:05:35 +00:00
|
|
|
Player::onPositionUpdated(Player * player, GstClockTime position)
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
2015-10-24 05:28:10 +00:00
|
|
|
emit player->positionUpdated(position);
|
2015-06-11 17:47:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-10-22 15:05:35 +00:00
|
|
|
Player::onDurationChanged(Player * player, GstClockTime duration)
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
emit player->durationChanged(duration);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-10-22 15:05:35 +00:00
|
|
|
Player::onBufferingChanged(Player * player, int percent)
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
emit player->bufferingChanged(percent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-10-22 15:05:35 +00:00
|
|
|
Player::onVideoDimensionsChanged(Player * player, int w, int h)
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
QSize res(w,h);
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
if (res == player->videoDimensions_)
|
|
|
|
return;
|
|
|
|
player->videoDimensions_ = res;
|
|
|
|
|
2015-06-11 17:47:56 +00:00
|
|
|
player->setResolution(res);
|
|
|
|
|
|
|
|
emit player->resolutionChanged(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-10-22 15:05:35 +00:00
|
|
|
Player::onVolumeChanged(Player *player)
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
qreal new_val;
|
|
|
|
|
|
|
|
new_val = gst_player_get_volume (player->player_);
|
|
|
|
|
|
|
|
emit player->volumeChanged(new_val);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-10-22 15:05:35 +00:00
|
|
|
Player::onMuteChanged(Player *player)
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
bool new_val;
|
|
|
|
|
|
|
|
new_val = gst_player_get_mute (player->player_);
|
|
|
|
|
|
|
|
emit player->mutedChanged(new_val);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-10-22 15:05:35 +00:00
|
|
|
Player::onMediaInfoUpdated(Player *player, GstPlayerMediaInfo *media_info)
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
bool val = player->isVideoAvailable();
|
|
|
|
|
|
|
|
if (player->videoAvailable_ != val) {
|
|
|
|
player->videoAvailable_ = val;
|
|
|
|
emit player->videoAvailableChanged(val);
|
|
|
|
}
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
player->mediaInfo()->update(media_info);
|
|
|
|
|
2015-06-11 17:47:56 +00:00
|
|
|
emit player->mediaInfoChanged();
|
|
|
|
}
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
QUrl Player::source() const
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
Q_ASSERT(player_ != 0);
|
|
|
|
QString url = QString::fromLocal8Bit(gst_player_get_uri(player_));
|
|
|
|
|
|
|
|
return QUrl(url);
|
|
|
|
}
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
qint64 Player::duration() const
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
Q_ASSERT(player_ != 0);
|
|
|
|
|
|
|
|
return gst_player_get_duration(player_);
|
|
|
|
}
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
qint64 Player::position() const
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
Q_ASSERT(player_ != 0);
|
|
|
|
|
|
|
|
return gst_player_get_position(player_);
|
|
|
|
}
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
qreal Player::volume() const
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
Q_ASSERT(player_ != 0);
|
|
|
|
|
|
|
|
return gst_player_get_volume(player_);
|
|
|
|
}
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
bool Player::isMuted() const
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
Q_ASSERT(player_ != 0);
|
|
|
|
|
|
|
|
return gst_player_get_mute(player_);
|
|
|
|
}
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
int Player::buffering() const
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
QSize Player::resolution() const
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
return videoDimensions_;
|
|
|
|
}
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
void Player::setResolution(QSize size)
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
videoDimensions_ = size;
|
|
|
|
}
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
Player::State Player::state() const
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
return state_;
|
|
|
|
}
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
GstElement *Player::pipeline() const
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
Q_ASSERT(player_ != 0);
|
|
|
|
|
|
|
|
return gst_player_get_pipeline(player_);
|
|
|
|
}
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
void Player::play()
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
Q_ASSERT(player_ != 0);
|
|
|
|
|
|
|
|
gst_player_play(player_);
|
|
|
|
}
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
void Player::pause()
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
Q_ASSERT(player_ != 0);
|
|
|
|
|
|
|
|
gst_player_pause(player_);
|
|
|
|
}
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
void Player::stop()
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
Q_ASSERT(player_ != 0);
|
|
|
|
|
|
|
|
gst_player_stop(player_);
|
|
|
|
}
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
void Player::seek(qint64 position)
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
Q_ASSERT(player_ != 0);
|
|
|
|
|
|
|
|
gst_player_seek(player_, position);
|
|
|
|
}
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
void Player::setSource(QUrl const& url)
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
Q_ASSERT(player_ != 0);
|
|
|
|
QByteArray uri = url.toString().toLocal8Bit();
|
|
|
|
|
|
|
|
gst_player_set_uri(player_, uri.data());
|
|
|
|
|
|
|
|
emit sourceChanged(url);
|
|
|
|
}
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
void Player::setVolume(qreal val)
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
Q_ASSERT(player_ != 0);
|
|
|
|
|
|
|
|
gst_player_set_volume(player_, val);
|
|
|
|
}
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
void Player::setMuted(bool val)
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
Q_ASSERT(player_ != 0);
|
|
|
|
|
|
|
|
gst_player_set_mute(player_, val);
|
|
|
|
}
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
void Player::setPosition(qint64 pos)
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
Q_ASSERT(player_ != 0);
|
|
|
|
|
|
|
|
gst_player_seek(player_, pos);
|
|
|
|
}
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
GstPlayerVideoRenderer *VideoRenderer::renderer()
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
return renderer_;
|
|
|
|
}
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
VideoRenderer::VideoRenderer()
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
renderer_ = static_cast<GstPlayerVideoRenderer*>
|
|
|
|
(g_object_new (GST_TYPE_PLAYER_QT_VIDEO_RENDERER, "renderer", this, NULL));
|
|
|
|
}
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
VideoRenderer::~VideoRenderer()
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
if (renderer_) gst_object_unref(renderer_);
|
|
|
|
}
|
|
|
|
|
2015-10-22 15:05:35 +00:00
|
|
|
}
|
|
|
|
|
2015-06-11 17:47:56 +00:00
|
|
|
struct _GstPlayerQtVideoRenderer
|
|
|
|
{
|
|
|
|
GObject parent;
|
|
|
|
|
|
|
|
gpointer renderer;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GstPlayerQtVideoRendererClass
|
|
|
|
{
|
|
|
|
GObjectClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_player_qt_video_renderer_interface_init
|
|
|
|
(GstPlayerVideoRendererInterface * iface);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstPlayerQtVideoRenderer,
|
|
|
|
gst_player_qt_video_renderer, G_TYPE_OBJECT,
|
|
|
|
G_IMPLEMENT_INTERFACE (GST_TYPE_PLAYER_VIDEO_RENDERER,
|
|
|
|
gst_player_qt_video_renderer_interface_init))
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
QT_VIDEO_RENDERER_PROP_0,
|
|
|
|
QT_VIDEO_RENDERER_PROP_RENDERER,
|
|
|
|
QT_VIDEO_RENDERER_PROP_LAST
|
|
|
|
};
|
|
|
|
|
|
|
|
static GParamSpec * qt_video_renderer_param_specs
|
|
|
|
[QT_VIDEO_RENDERER_PROP_LAST] = { NULL, };
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_player_qt_video_renderer_set_property (GObject * object,
|
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstPlayerQtVideoRenderer *self = GST_PLAYER_QT_VIDEO_RENDERER (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case QT_VIDEO_RENDERER_PROP_RENDERER:
|
|
|
|
self->renderer = g_value_get_pointer (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_player_qt_video_renderer_get_property (GObject * object,
|
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstPlayerQtVideoRenderer *self = GST_PLAYER_QT_VIDEO_RENDERER (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case QT_VIDEO_RENDERER_PROP_RENDERER:
|
|
|
|
g_value_set_pointer (value, self->renderer);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_player_qt_video_renderer_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
G_OBJECT_CLASS
|
|
|
|
(gst_player_qt_video_renderer_parent_class)->finalize(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_player_qt_video_renderer_class_init
|
|
|
|
(GstPlayerQtVideoRendererClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
gobject_class->set_property =
|
|
|
|
gst_player_qt_video_renderer_set_property;
|
|
|
|
gobject_class->get_property =
|
|
|
|
gst_player_qt_video_renderer_get_property;
|
|
|
|
gobject_class->finalize = gst_player_qt_video_renderer_finalize;
|
|
|
|
|
|
|
|
qt_video_renderer_param_specs
|
|
|
|
[QT_VIDEO_RENDERER_PROP_RENDERER] =
|
|
|
|
g_param_spec_pointer ("renderer", "Qt Renderer", "",
|
|
|
|
static_cast<GParamFlags>(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_properties (gobject_class,
|
|
|
|
QT_VIDEO_RENDERER_PROP_LAST,
|
|
|
|
qt_video_renderer_param_specs);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-10-23 18:54:05 +00:00
|
|
|
gst_player_qt_video_renderer_init (G_GNUC_UNUSED GstPlayerQtVideoRenderer * self)
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstElement *
|
|
|
|
gst_player_qt_video_renderer_create_video_sink
|
2015-10-23 18:54:05 +00:00
|
|
|
(GstPlayerVideoRenderer * iface, G_GNUC_UNUSED GstPlayer *player)
|
2015-06-11 17:47:56 +00:00
|
|
|
{
|
|
|
|
GstPlayerQtVideoRenderer *self = GST_PLAYER_QT_VIDEO_RENDERER (iface);
|
|
|
|
|
|
|
|
g_assert(self->renderer != NULL);
|
|
|
|
|
|
|
|
return static_cast<QGstPlayer::VideoRenderer*>(self->renderer)->createVideoSink();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_player_qt_video_renderer_interface_init
|
|
|
|
(GstPlayerVideoRendererInterface * iface)
|
|
|
|
{
|
|
|
|
iface->create_video_sink = gst_player_qt_video_renderer_create_video_sink;
|
|
|
|
}
|
2015-10-06 15:19:03 +00:00
|
|
|
|
|
|
|
struct _GstPlayerQtSignalDispatcher
|
|
|
|
{
|
|
|
|
GObject parent;
|
|
|
|
|
|
|
|
gpointer player;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GstPlayerQtSignalDispatcherClass
|
|
|
|
{
|
|
|
|
GObjectClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_player_qt_signal_dispatcher_interface_init
|
|
|
|
(GstPlayerSignalDispatcherInterface * iface);
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
QT_SIGNAL_DISPATCHER_PROP_0,
|
|
|
|
QT_SIGNAL_DISPATCHER_PROP_PLAYER,
|
|
|
|
QT_SIGNAL_DISPATCHER_PROP_LAST
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstPlayerQtSignalDispatcher,
|
|
|
|
gst_player_qt_signal_dispatcher, G_TYPE_OBJECT,
|
|
|
|
G_IMPLEMENT_INTERFACE (GST_TYPE_PLAYER_SIGNAL_DISPATCHER,
|
|
|
|
gst_player_qt_signal_dispatcher_interface_init));
|
|
|
|
|
|
|
|
static GParamSpec
|
|
|
|
* qt_signal_dispatcher_param_specs
|
|
|
|
[QT_SIGNAL_DISPATCHER_PROP_LAST] = { NULL, };
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_player_qt_signal_dispatcher_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
G_OBJECT_CLASS
|
|
|
|
(gst_player_qt_signal_dispatcher_parent_class)->finalize
|
|
|
|
(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_player_qt_signal_dispatcher_set_property (GObject * object,
|
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstPlayerQtSignalDispatcher *self =
|
|
|
|
GST_PLAYER_QT_SIGNAL_DISPATCHER (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case QT_SIGNAL_DISPATCHER_PROP_PLAYER:
|
|
|
|
self->player = g_value_get_pointer (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_player_qt_signal_dispatcher_get_property (GObject * object,
|
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstPlayerQtSignalDispatcher *self =
|
|
|
|
GST_PLAYER_QT_SIGNAL_DISPATCHER (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case QT_SIGNAL_DISPATCHER_PROP_PLAYER:
|
|
|
|
g_value_set_pointer (value, self->player);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_player_qt_signal_dispatcher_class_init
|
|
|
|
(GstPlayerQtSignalDispatcherClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
gobject_class->finalize =
|
|
|
|
gst_player_qt_signal_dispatcher_finalize;
|
|
|
|
gobject_class->set_property =
|
|
|
|
gst_player_qt_signal_dispatcher_set_property;
|
|
|
|
gobject_class->get_property =
|
|
|
|
gst_player_qt_signal_dispatcher_get_property;
|
|
|
|
|
|
|
|
qt_signal_dispatcher_param_specs
|
|
|
|
[QT_SIGNAL_DISPATCHER_PROP_PLAYER] =
|
2015-10-22 15:05:35 +00:00
|
|
|
g_param_spec_pointer ("player", "Player instance", "",
|
2015-10-06 15:19:03 +00:00
|
|
|
static_cast<GParamFlags>(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_properties (gobject_class,
|
|
|
|
QT_SIGNAL_DISPATCHER_PROP_LAST,
|
|
|
|
qt_signal_dispatcher_param_specs);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_player_qt_signal_dispatcher_init
|
2015-10-23 18:54:05 +00:00
|
|
|
(G_GNUC_UNUSED GstPlayerQtSignalDispatcher * self)
|
2015-10-06 15:19:03 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_player_qt_signal_dispatcher_dispatch (GstPlayerSignalDispatcher
|
2015-10-23 18:54:05 +00:00
|
|
|
* iface, G_GNUC_UNUSED GstPlayer * player, void (*emitter) (gpointer data), gpointer data,
|
2015-10-06 15:19:03 +00:00
|
|
|
GDestroyNotify destroy)
|
|
|
|
{
|
|
|
|
GstPlayerQtSignalDispatcher *self = GST_PLAYER_QT_SIGNAL_DISPATCHER (iface);
|
|
|
|
QObject dispatch;
|
|
|
|
QObject *receiver = static_cast<QObject*>(self->player);
|
|
|
|
|
|
|
|
QObject::connect(&dispatch, &QObject::destroyed, receiver, [=]() {
|
|
|
|
emitter(data);
|
|
|
|
if (destroy) destroy(data);
|
|
|
|
}, Qt::QueuedConnection);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_player_qt_signal_dispatcher_interface_init
|
|
|
|
(GstPlayerSignalDispatcherInterface * iface)
|
|
|
|
{
|
|
|
|
iface->dispatch = gst_player_qt_signal_dispatcher_dispatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
GstPlayerSignalDispatcher *
|
|
|
|
gst_player_qt_signal_dispatcher_new (gpointer player)
|
|
|
|
{
|
|
|
|
return static_cast<GstPlayerSignalDispatcher*>
|
|
|
|
(g_object_new (GST_TYPE_PLAYER_QT_SIGNAL_DISPATCHER,
|
|
|
|
"player", player, NULL));
|
|
|
|
}
|