Skip to content

Commit

Permalink
misc: support fractional framerate
Browse files Browse the repository at this point in the history
This also changes the framerate spin button to a combo box.
  • Loading branch information
SeaDve committed Feb 15, 2024
1 parent ea4cf5a commit 84793f0
Show file tree
Hide file tree
Showing 11 changed files with 354 additions and 102 deletions.
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ gst = { package = "gstreamer", version = "0.22" }
gst-plugin-gif = "0.12"
gst-plugin-gtk4 = { version = "0.12", features = ["gtk_v4_14"] }
gtk = { package = "gtk4", version = "0.8", features = ["v4_14"] }
num-rational = "0.4"
num-traits = "0.2"
once_cell = "1.19.0"
pulse = { package = "libpulse-binding", version = "2.26.0" }
pulse_glib = { package = "libpulse-glib-binding", version = "2.25.1" }
Expand Down
4 changes: 2 additions & 2 deletions data/io.github.seadve.Kooha.gschema.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
<key type="ay" name="saving-location">
<default>b""</default>
</key>
<key type="u" name="video-framerate">
<default>30</default>
<key type="(ii)" name="framerate">
<default>(30, 1)</default>
</key>
<key type="s" name="screencast-restore-token">
<default>""</default>
Expand Down
29 changes: 1 addition & 28 deletions data/resources/ui/preferences-dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -54,35 +54,8 @@
</object>
</child>
<child>
<object class="AdwActionRow">
<object class="AdwComboRow" id="framerate_row">
<property name="title" translatable="yes">Frame Rate</property>
<child type="suffix">
<object class="GtkBox">
<property name="spacing">12</property>
<child>
<object class="GtkImage" id="framerate_warning">
<property name="tooltip-text" translatable="yes">This frame rate may cause performance issues.</property>
<property name="icon-name">warning-symbolic</property>
<style>
<class name="warning"/>
</style>
</object>
</child>
<child>
<object class="GtkSpinButton" id="framerate_button">
<property name="valign">center</property>
<property name="adjustment">
<object class="GtkAdjustment">
<property name="lower">0</property>
<property name="upper">120</property>
<property name="step-increment">1</property>
<property name="page-increment">5</property>
</object>
</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
Expand Down
9 changes: 7 additions & 2 deletions src/area_selector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ use std::{cell::RefCell, os::unix::prelude::RawFd};

pub use self::view_port::Selection;
use self::view_port::ViewPort;
use crate::{application::Application, cancelled::Cancelled, pipeline, screencast_session::Stream};
use crate::{
application::Application,
cancelled::Cancelled,
pipeline::{self, Framerate},
screencast_session::Stream,
};

const PREVIEW_FRAMERATE: u32 = 60;
const PREVIEW_FRAMERATE: Framerate = Framerate::new_raw(60, 1);
const WINDOW_TO_MONITOR_SCALE_FACTOR: f64 = 0.4;

// We can't get header bar height before the window is presented, so we assume "46" as the default.
Expand Down
13 changes: 8 additions & 5 deletions src/pipeline.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::{bail, Context, Ok, Result};
use gst::prelude::*;
use gtk::graphene::Rect;
use num_rational::Rational32;

use std::{
os::unix::io::RawFd,
Expand All @@ -12,11 +13,13 @@ use crate::{area_selector::SelectAreaData, profile::Profile, screencast_session:
const AUDIO_SAMPLE_RATE: i32 = 48_000;
const AUDIO_N_CHANNELS: i32 = 1;

pub type Framerate = Rational32;

#[derive(Debug)]
#[must_use]
pub struct PipelineBuilder {
file_path: PathBuf,
framerate: u32,
framerate: Framerate,
profile: Profile,
fd: RawFd,
streams: Vec<Stream>,
Expand All @@ -28,7 +31,7 @@ pub struct PipelineBuilder {
impl PipelineBuilder {
pub fn new(
file_path: &Path,
framerate: u32,
framerate: Framerate,
profile: Profile,
fd: RawFd,
streams: Vec<Stream>,
Expand Down Expand Up @@ -63,7 +66,7 @@ impl PipelineBuilder {
pub fn build(&self) -> Result<gst::Pipeline> {
tracing::debug!(
file_path = %self.file_path.display(),
framerate = self.framerate,
framerate = ?self.framerate,
profile = ?self.profile.id(),
stream_len = self.streams.len(),
streams = ?self.streams,
Expand Down Expand Up @@ -226,13 +229,13 @@ fn make_videocrop(data: &SelectAreaData) -> Result<gst::Element> {
pub fn make_pipewiresrc_bin(
fd: RawFd,
streams: &[Stream],
framerate: u32,
framerate: Framerate,
select_area_data: Option<&SelectAreaData>,
) -> Result<gst::Bin> {
let bin = gst::Bin::builder().name("kooha-pipewiresrc-bin").build();

let videorate_caps = gst::Caps::builder("video/x-raw")
.field("framerate", gst::Fraction::new(framerate as i32, 1))
.field("framerate", gst::Fraction::from(framerate))
.build();

let src_element = match streams {
Expand Down
Loading

0 comments on commit 84793f0

Please sign in to comment.