Ejemplo n.º 1
0
void MpvHandler::LoadOsdSize()
{
    if(mpv)
    {
        mpv_get_property(mpv, "osd-width", MPV_FORMAT_INT64, &osdWidth);
        mpv_get_property(mpv, "osd-height", MPV_FORMAT_INT64, &osdHeight);
    }
}
Ejemplo n.º 2
0
void MpvHandler::LoadVideoParams()
{
    mpv_get_property(mpv, "width",        MPV_FORMAT_INT64, &fileInfo.video_params.width);
    mpv_get_property(mpv, "height",       MPV_FORMAT_INT64, &fileInfo.video_params.height);
    mpv_get_property(mpv, "dwidth",       MPV_FORMAT_INT64, &fileInfo.video_params.dwidth);
    mpv_get_property(mpv, "dheight",      MPV_FORMAT_INT64, &fileInfo.video_params.dheight);
    // though this has become useless, removing it causes a segfault--no clue:
    mpv_get_property(mpv, "video-aspect", MPV_FORMAT_INT64, &fileInfo.video_params.aspect);

    emit videoParamsChanged(fileInfo.video_params);
}
Ejemplo n.º 3
0
void MainWindow::handle_mpv_event(mpv_event *event)
{
    switch (event->event_id) {
    case MPV_EVENT_PROPERTY_CHANGE: {
        mpv_event_property *prop = (mpv_event_property *)event->data;
        if (strcmp(prop->name, "time-pos") == 0) {
            if (prop->format == MPV_FORMAT_DOUBLE) {
                double time = *(double *)prop->data;
                std::stringstream ss;
                ss << "At: " << time;
                statusBar()->showMessage(QString::fromStdString(ss.str()));
            } else if (prop->format == MPV_FORMAT_NONE) {
                // The property is unavailable, which probably means playback
                // was stopped.
                statusBar()->showMessage("");
            }
        }
        break;
    }
    case MPV_EVENT_VIDEO_RECONFIG: {
        // Retrieve the new video size.
        int64_t w, h;
        if (mpv_get_property(mpv, "dwidth", MPV_FORMAT_INT64, &w) >= 0 &&
            mpv_get_property(mpv, "dheight", MPV_FORMAT_INT64, &h) >= 0 &&
            w > 0 && h > 0)
        {
            // Force Qt to resize the mpv window to video size. You probably
            // want to do something more sophisticated here, because:
            // A) it prevents the user from making the window smaller for no
            //    reason (I was unsure how to make Qt do the right thing)
            // B) the MPV_EVENT_VIDEO_RECONFIG event doesn't necessarily imply
            //    a resize, and you should check yourself if the video
            //    dimensions really changed
            // mpv itself will scale/letter box the video to the container size
            // if the video doesn't fit.
            mpv_container->setMinimumSize(w, h);
        }
        break;
    }
    case MPV_EVENT_SHUTDOWN: {
        mpv_terminate_destroy(mpv);
        mpv = NULL;
        break;
    }
    default: ;
        // Ignore uninteresting or unknown events.
    }
}
Ejemplo n.º 4
0
void VideoPlayer::updateTime()
{
    double t;
    mpv_get_property(mpv, "time-pos", MPV_FORMAT_DOUBLE, &t);
    TimePosition = t * 1000;
    Q_EMIT positionChanged(TimePosition);
}
Ejemplo n.º 5
0
void MpvHandler::LoadChapters()
{
    fileInfo.chapters.clear();
    mpv_node node;
    mpv_get_property(mpv, "chapter-list", MPV_FORMAT_NODE, &node);
    if(node.format == MPV_FORMAT_NODE_ARRAY)
    {
        for(int i = 0; i < node.u.list->num; i++)
        {
            if(node.u.list->values[i].format == MPV_FORMAT_NODE_MAP)
            {
                Mpv::Chapter ch;
                for(int n = 0; n < node.u.list->values[i].u.list->num; n++)
                {
                    if(QString(node.u.list->values[i].u.list->keys[n]) == "title")
                    {
                        if(node.u.list->values[i].u.list->values[n].format == MPV_FORMAT_STRING)
                            ch.title = node.u.list->values[i].u.list->values[n].u.string;
                    }
                    else if(QString(node.u.list->values[i].u.list->keys[n]) == "time")
                    {
                        if(node.u.list->values[i].u.list->values[n].format == MPV_FORMAT_DOUBLE)
                            ch.time = (int)node.u.list->values[i].u.list->values[n].u.double_;
                    }
                }
                fileInfo.chapters.push_back(ch);
            }
        }
    }
    emit chaptersChanged(fileInfo.chapters);
}
Ejemplo n.º 6
0
void MpvHandler::LoadMetadata()
{
    fileInfo.metadata.clear();
    mpv_node node;
    mpv_get_property(mpv, "metadata", MPV_FORMAT_NODE, &node);
    if(node.format == MPV_FORMAT_NODE_MAP)
        for(int n = 0; n < node.u.list->num; n++)
            if(node.u.list->values[n].format == MPV_FORMAT_STRING)
                fileInfo.metadata[node.u.list->keys[n]] = node.u.list->values[n].u.string;
}
Ejemplo n.º 7
0
void TimeUpdater::run()
{
    double val;
    int TimePosition;
    while(true)
    {
        usleep(10);
        mpv_get_property(mpv, "time-pos", MPV_FORMAT_DOUBLE, &val);
        TimePosition = val * 1000;
        emit timeChanged(TimePosition);
    }
}
Ejemplo n.º 8
0
void resize_window_to_fit(gmpv_handle *ctx, gdouble multiplier)
{
	gchar *video = mpv_get_property_string(ctx->mpv_ctx, "video");
	gint64 width;
	gint64 height;
	gint mpv_width_rc;
	gint mpv_height_rc;

	mpv_width_rc = mpv_get_property(	ctx->mpv_ctx,
						"dwidth",
						MPV_FORMAT_INT64,
						&width );

	mpv_height_rc = mpv_get_property(	ctx->mpv_ctx,
						"dheight",
						MPV_FORMAT_INT64,
						&height );

	if(video
	&& strncmp(video, "no", 3) != 0
	&& mpv_width_rc >= 0
	&& mpv_height_rc >= 0)
	{
		gint width_margin;
		gint height_margin;
		gint new_width;
		gint new_height;

		width_margin = main_window_get_width_margin(ctx->gui);
		height_margin = main_window_get_height_margin(ctx->gui);
		new_width = (gint)(multiplier*(gdouble)width)+width_margin;
		new_height = (gint)(multiplier*(gdouble)height)+height_margin;

		gtk_window_resize(	GTK_WINDOW(ctx->gui),
					new_width,
					new_height );
	}

	mpv_free(video);
}
Ejemplo n.º 9
0
void MpvHandler::LoadFileInfo()
{
    // get media-title
    fileInfo.media_title = mpv_get_property_string(mpv, "media-title");
    // get length
    double len;
    mpv_get_property(mpv, "length", MPV_FORMAT_DOUBLE, &len);
    fileInfo.length                  = (int)len;

    LoadTracks();
    LoadChapters();
    LoadVideoParams();
    LoadAudioParams();
    LoadMetadata();

    emit fileInfoChanged(fileInfo);
}
Ejemplo n.º 10
0
static void mpv_prop_change_handler(GmpvMpvObj *mpv, mpv_event_property* prop)
{
	g_debug("Received mpv property change event for \"%s\"", prop->name);

	if(g_strcmp0(prop->name, "pause") == 0)
	{
		gboolean idle;

		mpv->state.paused = prop->data?*((int *)prop->data):TRUE;

		mpv_get_property(mpv->mpv_ctx, "idle", MPV_FORMAT_FLAG, &idle);

		if(idle && !mpv->state.paused)
		{
			gmpv_mpv_obj_load(mpv, NULL, FALSE, TRUE);
		}
	}
}
Ejemplo n.º 11
0
void MpvHandler::LoadFileInfo()
{
    // get media-title
    fileInfo.media_title = mpv_get_property_string(mpv, "media-title");
    // get length
    double len;
    mpv_get_property(mpv, "length", MPV_FORMAT_DOUBLE, &len);
    fileInfo.length                  = (int)len;

    fileInfo.video_params.codec       = mpv_get_property_string(mpv, "video-codec");
    fileInfo.audio_params.codec       = mpv_get_property_string(mpv, "audio-codec");
    fileInfo.audio_params.samplerate  = mpv_get_property_string(mpv, "audio-samplerate");
    fileInfo.audio_params.channels    = mpv_get_property_string(mpv, "audio-channels");

    LoadTracks();
    LoadChapters();
    LoadVideoParams();
    LoadMetadata();

    emit fileInfoChanged(fileInfo);
}
Ejemplo n.º 12
0
gboolean gmpv_mpv_obj_get_property_flag(GmpvMpvObj *mpv, const gchar *name)
{
	gboolean value = FALSE;
	gint rc = MPV_ERROR_UNINITIALIZED;

	if(mpv->mpv_ctx)
	{
		rc =	mpv_get_property
			(mpv->mpv_ctx, name, MPV_FORMAT_FLAG, &value);
	}

	if(rc < 0)
	{
		g_info(	"Failed to retrieve property \"%s\" as flag. "
			"Reason: %s.",
			name,
			mpv_error_string(rc) );
	}

	return value;
}
Ejemplo n.º 13
0
gint gmpv_mpv_obj_get_property(	GmpvMpvObj *mpv,
				const gchar *name,
				mpv_format format,
				void *data )
{
	gint rc = MPV_ERROR_UNINITIALIZED;

	if(mpv->mpv_ctx)
	{
		rc = mpv_get_property(mpv->mpv_ctx, name, format, data);
	}

	if(rc < 0)
	{
		g_info(	"Failed to retrieve property \"%s\" "
			"using mpv format %d. Reason: %s.",
			name,
			format,
			mpv_error_string(rc) );
	}

	return rc;
}
Ejemplo n.º 14
0
gboolean update_seek_bar(gpointer data)
{
	gmpv_handle *ctx = data;
	gdouble time_pos;
	gint rc;

	rc = mpv_get_property(	ctx->mpv_ctx,
				"time-pos",
				MPV_FORMAT_DOUBLE,
				&time_pos );

	if(rc >= 0)
	{
		ControlBox *control_box
			= CONTROL_BOX(ctx->gui->control_box);

		gtk_range_set_value
			(	GTK_RANGE(control_box->seek_bar),
				time_pos );
	}

	return TRUE;
}
Ejemplo n.º 15
0
void MpvHandler::LoadAudioParams()
{
    fileInfo.audio_params.codec = mpv_get_property_string(mpv, "audio-codec");
    mpv_node node;
    mpv_get_property(mpv, "audio-params", MPV_FORMAT_NODE, &node);
    if(node.format == MPV_FORMAT_NODE_MAP)
    {
        for(int i = 0; i < node.u.list->num; i++)
        {
            if(QString(node.u.list->keys[i]) == "samplerate")
            {
                if(node.u.list->values[i].format == MPV_FORMAT_INT64)
                    fileInfo.audio_params.samplerate = node.u.list->values[i].u.int64;
            }
            else if(QString(node.u.list->keys[i]) == "channel-count")
            {
                if(node.u.list->values[i].format == MPV_FORMAT_INT64)
                    fileInfo.audio_params.channels = node.u.list->values[i].u.int64;
            }
        }
    }

    emit audioParamsChanged(fileInfo.audio_params);
}
Ejemplo n.º 16
0
bool KNMusicBackendMpvThread::event(QEvent *event)
{
    //Check out the event type.
    if(event->type()==QEvent::User)
    {
        //Get all the event until there no event.
        while(m_mpvHandle)
        {
            //Get the mpv event.
            mpv_event *mpvEvent=mpv_wait_event(m_mpvHandle, 0);
            //Check out the event pointer.
            if(mpvEvent==nullptr ||
                    MPV_EVENT_NONE == mpvEvent->event_id)
            {
                //All the event has been processed.
                break;
            }
            //Check out whether there's an error occurs.
            if(mpvEvent->error < 0)
            {
                //!FIXME: Do something here.
            }
            switch(mpvEvent->event_id)
            {
            case MPV_EVENT_PROPERTY_CHANGE:
            {
                //Cast the mpv event data to event property.
                mpv_event_property *prop=(mpv_event_property *)mpvEvent->data;
                //Check out the property name.
                // From bakamplayer:
                // playback-time does the same thing as time-pos but works for
                // streaming media
                if(strcmp(prop->name, "time-pos") == 0)
                {
                    //Cehck the format.
                    if(MPV_FORMAT_DOUBLE==prop->format)
                    {
                        //Output the playback time.
                        emit positionChanged((qint64)((*(double *)prop->data)*1000.0)-m_startPosition);
                    }
                }
                //Mission finished.
                break;
            }
                //This event is totally different, though I don't know why.
                //BakaMPlayer says it is.
            case MPV_EVENT_START_FILE:
            {
                break;
            }
            case MPV_EVENT_FILE_LOADED:
            {
                //Pause it right after the file loaded.
                pause();
                //Reset the playing state.
                m_state=MusicUtil::Stopped;
                //Emit the state changed signal.
                emit stateChanged(m_state);
                //We have to update all the file inforamtion here.
                //Get the duration of the file.
                double mediaDuration;
                //Get the property.
                mpv_get_property(m_mpvHandle,
                                 "length",
                                 MPV_FORMAT_DOUBLE,
                                 &mediaDuration);
                //Save the total duration.
                qint64 propertyDuration=(qint64)(mediaDuration*1000.0);
                //Check property duration
                if(propertyDuration>0)
                {
                    //For valid duration.
                    m_totalDuration=propertyDuration;
                    //Update the end position.
                    checkStartAndEndPosition();
                    //Emit the loaded signal.
                    emit loadSuccess();
                }
                //Mission complete.
                break;
            }
            case MPV_EVENT_PAUSE:
            {
                //We should save the state as pause.
                //We may never have stop.
                m_state=MusicUtil::Paused;
                //Emit the state changed signal.
                emit stateChanged(m_state);
                break;
            }
            case MPV_EVENT_UNPAUSE:
            {
                //We should save the state as playing.
                m_state=MusicUtil::Playing;
                //Emit the state changed signal.
                emit stateChanged(m_state);
                //Sync the playing volume.
                setVolume(m_volumeSize);
                break;
            }
            case MPV_EVENT_END_FILE:
            {
                //It should be stopped.
                m_state=MusicUtil::Stopped;
                //Emit the state changed signal.
                emit stateChanged(m_state);
                break;
            }
            }
        }
    }
    //For others, do the defualt event.
    return KNMusicStandardBackendThread::event(event);
}
Ejemplo n.º 17
0
void gmpv_mpv_obj_reset(GmpvMpvObj *mpv)
{
	const gchar *quit_cmd[] = {"quit_watch_later", NULL};
	gchar *loop_str;
	gboolean loop;
	gint64 playlist_pos;
	gint playlist_pos_rc;

	g_assert(mpv->mpv_ctx);

	loop_str = gmpv_mpv_obj_get_property_string(mpv, "loop");
	loop = (g_strcmp0(loop_str, "inf") == 0);

	mpv_free(loop_str);

	playlist_pos_rc = mpv_get_property(	mpv->mpv_ctx,
						"playlist-pos",
						MPV_FORMAT_INT64,
						&playlist_pos );

	/* Reset mpv->mpv_ctx */
	mpv->state.ready = FALSE;

	mpv_check_error(gmpv_mpv_obj_command(mpv, quit_cmd));
	gmpv_mpv_obj_quit(mpv);

	mpv->mpv_ctx = mpv_create();
	gmpv_mpv_obj_initialize(mpv);

	gmpv_mpv_obj_set_event_callback
		(	mpv,
			mpv->event_callback,
			mpv->event_callback_data );
	gmpv_mpv_obj_set_opengl_cb_callback
		(	mpv,
			mpv->opengl_cb_callback,
			mpv->opengl_cb_callback_data );

	gmpv_mpv_obj_set_property_string(mpv, "loop", loop?"inf":"no");

	if(mpv->playlist)
	{
		if(mpv->state.loaded)
		{
			gint rc;

			rc =	mpv_request_event
				(mpv->mpv_ctx, MPV_EVENT_FILE_LOADED, 0);
			mpv_check_error(rc);

			gmpv_mpv_obj_load(mpv, NULL, FALSE, TRUE);

			rc =	mpv_request_event
				(mpv->mpv_ctx, MPV_EVENT_FILE_LOADED, 1);
			mpv_check_error(rc);
		}

		if(playlist_pos_rc >= 0 && playlist_pos > 0)
		{
			gmpv_mpv_obj_set_property(	mpv,
							"playlist-pos",
							MPV_FORMAT_INT64,
							&playlist_pos );
		}

		gmpv_mpv_obj_set_property(	mpv,
						"pause",
						MPV_FORMAT_FLAG,
						&mpv->state.paused );
	}
}
Ejemplo n.º 18
0
static void mpv_obj_update_playlist(GmpvMpvObj *mpv)
{
	/* The length of "playlist//filename" including null-terminator (19)
	 * plus the number of digits in the maximum value of 64 bit int (19).
	 */
	const gsize filename_prop_str_size = 38;
	GtkListStore *store = gmpv_playlist_get_store(mpv->playlist);
	gchar *filename_prop_str = g_malloc(filename_prop_str_size);
	gboolean iter_end = FALSE;
	GtkTreeIter iter;
	mpv_node mpv_playlist;
	gint playlist_count;
	gint i;

	mpv_check_error(mpv_get_property(	mpv->mpv_ctx,
						"playlist",
						MPV_FORMAT_NODE,
						&mpv_playlist ));
	playlist_count = mpv_playlist.u.list->num;

	gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);

	for(i = 0; i < playlist_count; i++)
	{
		mpv_node_list *prop_list = mpv_playlist.u.list->values[i].u.list;
		gchar *uri = NULL;
		gchar *title = NULL;
		gchar *name = NULL;

		for(gint j = 0; j < prop_list->num; j++)
		{
			const gchar *key = prop_list->keys[j];
			const mpv_node value = prop_list->values[j];

			if(g_strcmp0(key, "filename") == 0)
			{
				g_assert(value.format == MPV_FORMAT_STRING);
				uri = value.u.string;
			}
			else if(g_strcmp0(key, "title") == 0)
			{
				g_assert(value.format == MPV_FORMAT_STRING);
				title = value.u.string;
			}
		}

		name = title?g_strdup(title):get_name_from_path(uri);

		/* Overwrite current entry if it doesn't match the new value */
		if(!iter_end)
		{
			gchar *old_name = NULL;
			gchar *old_uri = NULL;
			gboolean name_update;
			gboolean uri_update;

			gtk_tree_model_get
				(	GTK_TREE_MODEL(store), &iter,
					PLAYLIST_NAME_COLUMN, &old_name,
					PLAYLIST_URI_COLUMN, &old_uri, -1 );

			name_update = (g_strcmp0(name, old_name) != 0);
			uri_update = (g_strcmp0(uri, old_uri) != 0);

			/* Only set the name if either the title can be
			 * retrieved or the name is unset. This preserves the
			 * correct title if it becomes unavailable later such as
			 * when restarting mpv.
			 */
			if(name_update && (!old_name || title || uri_update))
			{
				gtk_list_store_set
					(	store, &iter,
						PLAYLIST_NAME_COLUMN, name, -1 );
			}

			if(uri_update)
			{
				gtk_list_store_set
					(	store, &iter,
						PLAYLIST_URI_COLUMN, uri, -1 );
			}

			iter_end = !gtk_tree_model_iter_next
					(GTK_TREE_MODEL(store), &iter);

			g_free(old_name);
			g_free(old_uri);
		}
		/* Append entries to the playlist if there are fewer entries in
		 * the playlist widget than mpv's playlist.
		 */
		else
		{
			gmpv_playlist_append(mpv->playlist, name, uri);
		}

		g_free(name);
	}

	/* If there are more entries in the playlist widget than mpv's playlist,
	 * remove the excess entries from the playlist widget.
	 */
	if(!iter_end)
	{
		while(gtk_list_store_remove(store, &iter));
	}

	g_free(filename_prop_str);
	mpv_free_node_contents(&mpv_playlist);
}
Ejemplo n.º 19
0
void MpvHandler::LoadTracks()
{
    fileInfo.tracks.clear();
    mpv_node node;
    mpv_get_property(mpv, "track-list", MPV_FORMAT_NODE, &node);
    if(node.format == MPV_FORMAT_NODE_ARRAY)
    {
        for(int i = 0; i < node.u.list->num; i++)
        {
            if(node.u.list->values[i].format == MPV_FORMAT_NODE_MAP)
            {
                Mpv::Track track;
                for(int n = 0; n < node.u.list->values[i].u.list->num; n++)
                {
                    if(QString(node.u.list->values[i].u.list->keys[n]) == "id")
                    {
                        if(node.u.list->values[i].u.list->values[n].format == MPV_FORMAT_INT64)
                            track.id = node.u.list->values[i].u.list->values[n].u.int64;
                    }
                    else if(QString(node.u.list->values[i].u.list->keys[n]) == "type")
                    {
                        if(node.u.list->values[i].u.list->values[n].format == MPV_FORMAT_STRING)
                            track.type = node.u.list->values[i].u.list->values[n].u.string;
                    }
                    else if(QString(node.u.list->values[i].u.list->keys[n]) == "src-id")
                    {
                        if(node.u.list->values[i].u.list->values[n].format == MPV_FORMAT_INT64)
                            track.src_id = node.u.list->values[i].u.list->values[n].u.int64;
                    }
                    else if(QString(node.u.list->values[i].u.list->keys[n]) == "title")
                    {
                        if(node.u.list->values[i].u.list->values[n].format == MPV_FORMAT_STRING)
                            track.title = node.u.list->values[i].u.list->values[n].u.string;
                    }
                    else if(QString(node.u.list->values[i].u.list->keys[n]) == "lang")
                    {
                        if(node.u.list->values[i].u.list->values[n].format == MPV_FORMAT_STRING)
                            track.lang = node.u.list->values[i].u.list->values[n].u.string;
                    }
                    else if(QString(node.u.list->values[i].u.list->keys[n]) == "albumart")
                    {
                        if(node.u.list->values[i].u.list->values[n].format == MPV_FORMAT_FLAG)
                            track.albumart = node.u.list->values[i].u.list->values[n].u.flag;
                    }
                    else if(QString(node.u.list->values[i].u.list->keys[n]) == "default")
                    {
                        if(node.u.list->values[i].u.list->values[n].format == MPV_FORMAT_FLAG)
                            track._default = node.u.list->values[i].u.list->values[n].u.flag;
                    }
                    else if(QString(node.u.list->values[i].u.list->keys[n]) == "external")
                    {
                        if(node.u.list->values[i].u.list->values[n].format == MPV_FORMAT_FLAG)
                            track.external = node.u.list->values[i].u.list->values[n].u.flag;
                    }
                    else if(QString(node.u.list->values[i].u.list->keys[n]) == "external-filename")
                    {
                        if(node.u.list->values[i].u.list->values[n].format == MPV_FORMAT_STRING)
                            track.external_filename = node.u.list->values[i].u.list->values[n].u.string;
                    }
                    else if(QString(node.u.list->values[i].u.list->keys[n]) == "codec")
                    {
                        if(node.u.list->values[i].u.list->values[n].format == MPV_FORMAT_STRING)
                            track.codec = node.u.list->values[i].u.list->values[n].u.string;
                    }
                }
                fileInfo.tracks.push_back(track);
            }
        }
    }

    emit trackListChanged(fileInfo.tracks);
}
Ejemplo n.º 20
0
QString MpvHandler::getMediaInfo()
{
    QFileInfo fi(path+file);

    double avsync, fps, vbitrate, abitrate;

    mpv_get_property(mpv, "avsync", MPV_FORMAT_DOUBLE, &avsync);
    mpv_get_property(mpv, "estimated-vf-fps", MPV_FORMAT_DOUBLE, &fps);
    mpv_get_property(mpv, "video-bitrate", MPV_FORMAT_DOUBLE, &vbitrate);
    mpv_get_property(mpv, "audio-bitrate", MPV_FORMAT_DOUBLE, &abitrate);
    QString current_vo = mpv_get_property_string(mpv, "current-vo"),
            current_ao = mpv_get_property_string(mpv, "current-ao"),
            hwdec_active = mpv_get_property_string(mpv, "hwdec-active");

    int vtracks = 0,
        atracks = 0;

    for(auto &track : fileInfo.tracks)
    {
        if(track.type == "video")
            ++vtracks;
        else if(track.type == "audio")
            ++atracks;
    }

    const QString outer = "%0: %1\n", inner = "    %0: %1\n";

    QString out = outer.arg(tr("File"), fi.fileName()) +
            inner.arg(tr("Title"), fileInfo.media_title) +
            inner.arg(tr("File size"), Util::HumanSize(fi.size())) +
            inner.arg(tr("Date created"), fi.created().toString()) +
            inner.arg(tr("Media length"), Util::FormatTime(fileInfo.length, fileInfo.length)) + '\n';
    if(fileInfo.video_params.codec != QString())
        out += outer.arg(tr("Video (x%0)").arg(QString::number(vtracks)), fileInfo.video_params.codec) +
            inner.arg(tr("Video Output"), QString("%0 (hwdec %1)").arg(current_vo, hwdec_active)) +
            inner.arg(tr("Resolution"), QString("%0 x %1 (%2)").arg(QString::number(fileInfo.video_params.width),
                                                                    QString::number(fileInfo.video_params.height),
                                                                    Util::Ratio(fileInfo.video_params.width, fileInfo.video_params.height))) +
            inner.arg(tr("FPS"), QString::number(fps)) +
            inner.arg(tr("A/V Sync"), QString::number(avsync)) +
            inner.arg(tr("Bitrate"), tr("%0 kbps").arg(vbitrate)) + '\n';
    if(fileInfo.audio_params.codec != QString())
        out += outer.arg(tr("Audio (x%0)").arg(QString::number(atracks)), fileInfo.audio_params.codec) +
            inner.arg(tr("Audio Output"), current_ao) +
            inner.arg(tr("Sample Rate"), QString::number(fileInfo.audio_params.samplerate)) +
            inner.arg(tr("Channels"), QString::number(fileInfo.audio_params.channels)) +
            inner.arg(tr("Bitrate"), tr("%0 kbps").arg(abitrate)) + '\n';

    if(fileInfo.chapters.length() > 0)
    {
        out += outer.arg(tr("Chapters"), QString());
        int n = 1;
        for(auto &chapter : fileInfo.chapters)
            out += inner.arg(QString::number(n++), chapter.title);
        out += '\n';
    }

    if(fileInfo.metadata.size() > 0)
    {
        out += outer.arg(tr("Metadata"), QString());
        for(auto data = fileInfo.metadata.begin(); data != fileInfo.metadata.end(); ++data)
            out += inner.arg(data.key(), *data);
        out += '\n';
    }

    return out;
}
Ejemplo n.º 21
0
void gmpv_mpv_opt_handle_autofit(GmpvMpv *mpv)
{
	gchar *scale_str = NULL;
	gchar *autofit_str = NULL;
	gchar *larger_str = NULL;
	gchar *smaller_str = NULL;
	gboolean scale_set = FALSE;
	gboolean autofit_set = FALSE;
	gboolean larger_set = FALSE;
	gboolean smaller_set = FALSE;

	scale_str =	mpv_get_property_string
			(mpv->mpv_ctx, "options/window-scale");
	autofit_str =	mpv_get_property_string
			(mpv->mpv_ctx, "options/autofit");
	larger_str =	mpv_get_property_string
			(mpv->mpv_ctx, "options/autofit-larger");
	smaller_str =	mpv_get_property_string
			(mpv->mpv_ctx, "options/autofit-smaller");

	scale_set = scale_str && scale_str[0] != '\0';
	autofit_set = autofit_str && autofit_str[0] != '\0';
	larger_set = larger_str && larger_str[0] != '\0';
	smaller_set = smaller_str && smaller_str[0] != '\0';

	if(scale_set || autofit_set || larger_set || smaller_set)
	{
		gint64 larger_dim[2] = {G_MAXINT, G_MAXINT};
		gint64 smaller_dim[2] = {0, 0};
		gint64 autofit_dim[2] = {0, 0};
		gint64 vid_dim[2];
		gdouble ratio[2];
		gdouble scale = 1;
		gint rc = 0;

		rc |= mpv_get_property(	mpv->mpv_ctx,
					"dwidth",
					MPV_FORMAT_INT64,
					&vid_dim[0] );
		rc |= mpv_get_property(	mpv->mpv_ctx,
					"dheight",
					MPV_FORMAT_INT64,
					&vid_dim[1] );

		if(rc >= 0)
		{
			g_debug(	"Retrieved video size: "
					"%" G_GINT64_FORMAT "x"
					"%" G_GINT64_FORMAT,
					vid_dim[0], vid_dim[1] );
		}

		if(rc >= 0 && scale_set)
		{
			g_debug(	"Retrieved option --window-scale=%s",
					scale_str);

			/* This should never fail since mpv_set_option() will
			 * refuse to set invalid values.
			 */
			scale = g_ascii_strtod(scale_str, NULL);
		}

		if(rc >= 0 && larger_set)
		{
			g_debug(	"Retrieved option --autofit-larger=%s",
					larger_str);

			parse_dim_string(larger_str, larger_dim);
		}

		if(rc >= 0 && smaller_set)
		{
			g_debug(	"Retrieved option --autofit-smaller=%s",
					smaller_str);

			parse_dim_string(smaller_str, smaller_dim);
		}

		if(rc >= 0)
		{
			if(autofit_set)
			{
				g_debug(	"Retrieved option --autofit=%s",
						autofit_str );

				parse_dim_string(autofit_str, autofit_dim);
			}
			else
			{
				autofit_dim[0] = vid_dim[0];
				autofit_dim[1] = vid_dim[1];
			}

			if(scale_set)
			{
				autofit_dim[0]
					= (gint64)(scale*(gdouble)autofit_dim[0]);
				autofit_dim[1]
					= (gint64)(scale*(gdouble)autofit_dim[1]);
			}
		}

		if(rc >= 0)
		{
			autofit_dim[0] = MIN(autofit_dim[0], larger_dim[0]);
			autofit_dim[1] = MIN(autofit_dim[1], larger_dim[1]);

			autofit_dim[0] = MAX(autofit_dim[0], smaller_dim[0]);
			autofit_dim[1] = MAX(autofit_dim[1], smaller_dim[1]);

			if(!autofit_set
			&& autofit_dim[0] == vid_dim[0]
			&& autofit_dim[1] == vid_dim[1])
			{
				/* Do not resize if --autofit is not set and the
				 * video size does not exceed the limits imposed
				 * by --autofit-larger and --autofit-smaller.
				 */
				ratio[0] = scale_set?scale:0;
				ratio[1] = scale_set?scale:0;
			}
			else
			{
				g_debug(	"Target video area size: "
						"%" G_GINT64_FORMAT
						"x%" G_GINT64_FORMAT,
						autofit_dim[0], autofit_dim[1] );

				ratio[0] =	(gdouble)autofit_dim[0]/
						(gdouble)vid_dim[0];
				ratio[1] =	(gdouble)autofit_dim[1]/
						(gdouble)vid_dim[1];
			}
		}

		if(rc >= 0 && ratio[0] > 0 && ratio[1] > 0)
		{
			/* Resize the window so that it is as big as possible
			 *  while preseving the aspect ratio.
			 */
			mpv->autofit_ratio = MIN(ratio[0], ratio[1]);

			g_debug(	"Set video size multiplier to %f",
					mpv->autofit_ratio );
		}
		else
		{
			mpv->autofit_ratio = -1;
		}
	}

	mpv_free(scale_str);
	mpv_free(autofit_str);
	mpv_free(larger_str);
	mpv_free(smaller_str);
}