-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
fix(linux): adding Gstreamer plugin for handling asset:// #14402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aaalloc
wants to merge
8
commits into
tauri-apps:dev
Choose a base branch
from
aaalloc:tauri-asset-gstreamer-plugin
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6558d28
adding Gstreamer plugin for handling asset:// (linux specific)
aaalloc 6ad67e8
chore(deps): update dependency vitest to v4 (#14361)
renovate[bot] 3ca4bfd
Merge branch 'dev' into tauri-asset-gstreamer-plugin
aaalloc f9df44d
Merge branch 'dev' into tauri-asset-gstreamer-plugin
aaalloc 3b88c82
feat: handle case when url is percent-encoded
aaalloc 13b82aa
Merge branch 'dev' into tauri-asset-gstreamer-plugin
aaalloc a6f31fb
Merge branch 'tauri-asset-gstreamer-plugin' of github.com:aaalloc/tau…
aaalloc 9aafc3a
feat: reducing gst shared object
aaalloc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| [package] | ||
| name = "tauri-asset-gst-plugin" | ||
| version = "0.1.0" | ||
| authors = ["Alexander Yanovskyy <contact@yanovskyy.com>"] | ||
| license = "MIT OR Apache-2.0" | ||
| edition = "2018" | ||
| repository = "https://github.com/tauri-apps/tauri" | ||
| description = "Gstreamer plugin for asset protocol" | ||
|
|
||
| [dependencies] | ||
| gstreamer = "0.24" | ||
| gstreamer-base = "0.24" | ||
| percent-encoding = "2.3.2" | ||
|
|
||
| [lib] | ||
| name = "gsttauriasset" | ||
| crate-type = ["cdylib"] | ||
| path = "src/lib.rs" | ||
|
|
||
| [build-dependencies] | ||
| gst-plugin-version-helper = "0.8.3" | ||
|
|
||
| [profile.release] | ||
| lto = true | ||
| codegen-units = 1 | ||
| opt-level = "z" | ||
| panic = 'abort' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| fn main() { | ||
| gst_plugin_version_helper::info(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| use gst::glib; | ||
| use gstreamer_base::gst; | ||
|
|
||
| mod tauri_asset; | ||
|
|
||
| fn plugin_init(plugin: &gst::Plugin) -> Result<(), glib::BoolError> { | ||
| tauri_asset::register(plugin) | ||
| } | ||
|
|
||
| gst::plugin_define!( | ||
| tauriasset, | ||
| env!("CARGO_PKG_DESCRIPTION"), | ||
| plugin_init, | ||
| concat!(env!("CARGO_PKG_VERSION"), "-", env!("COMMIT_ID")), | ||
| "The Plugin's License", | ||
| env!("CARGO_PKG_NAME"), | ||
| env!("CARGO_PKG_NAME"), | ||
| env!("CARGO_PKG_REPOSITORY"), | ||
| env!("BUILD_REL_DATE") | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| use gst::glib::subclass::types::ObjectSubclassExt; | ||
| use gst::prelude::{ElementExt, GhostPadExt, GstBinExt, PadExt}; | ||
| use gst::subclass::prelude::{BinImpl, ElementImpl, ObjectImpl, URIHandlerImpl}; | ||
| use gst::subclass::prelude::{GstObjectImpl, ObjectSubclass}; | ||
| use gst::{glib, GhostPad, PadDirection}; | ||
| use gstreamer_base::gst; | ||
|
|
||
| const ASSET_URI_SCHEME: &str = "asset"; | ||
|
|
||
| #[derive(Default)] | ||
| pub struct TauriAsset { | ||
| // uri: Option<String>, | ||
| } | ||
|
|
||
| impl TauriAsset { | ||
| pub fn new() -> Self { | ||
| Self::default() | ||
| } | ||
| } | ||
|
|
||
| #[glib::object_subclass] | ||
| impl ObjectSubclass for TauriAsset { | ||
| const NAME: &'static str = "GstTauriAsset"; | ||
| type Type = super::TauriAsset; | ||
| type ParentType = gst::Bin; | ||
| type Interfaces = (gst::URIHandler,); | ||
| } | ||
|
|
||
| impl GstObjectImpl for TauriAsset {} | ||
| impl ObjectImpl for TauriAsset {} | ||
| impl BinImpl for TauriAsset {} | ||
| impl ElementImpl for TauriAsset {} | ||
|
|
||
| impl URIHandlerImpl for TauriAsset { | ||
| const URI_TYPE: gst::URIType = gst::URIType::Src; | ||
|
|
||
| fn protocols() -> &'static [&'static str] { | ||
| &[ASSET_URI_SCHEME] | ||
| } | ||
|
|
||
| fn uri(&self) -> Option<String> { | ||
| None | ||
| } | ||
|
|
||
| fn set_uri(&self, uri: &str) -> Result<(), glib::Error> { | ||
| // uri is like: asset://path/to/asset or asset://localhost/path/to/asset | ||
| let sep = format!("{}://", ASSET_URI_SCHEME); | ||
| let mut split = uri.split(sep.as_str()); | ||
| let location = split | ||
| .nth(1) | ||
| .ok_or_else(|| glib::Error::new(gst::URIError::BadUri, "Could not get location from URI"))?; | ||
|
|
||
| // directly having full path after asset:// or having localhost | ||
| let location = location.strip_prefix("localhost").unwrap_or(location); | ||
|
|
||
| // Uri could be percent-encoded | ||
| let location = percent_encoding::percent_decode_str(location) | ||
| .decode_utf8() | ||
| .map_err(|_| { | ||
| glib::Error::new( | ||
| gst::URIError::BadUri, | ||
| "Could not decode percent-encoded URI", | ||
| ) | ||
| })? | ||
| .to_string(); | ||
|
|
||
| // now location is like: /path/to/asset | ||
| let internal_src = gst::ElementFactory::make("filesrc") | ||
| .name("filesrc") | ||
| .property("location", location) | ||
| .build() | ||
| .ok(); | ||
|
|
||
| let element = self.obj(); | ||
| element | ||
| .add(internal_src.as_ref().unwrap()) | ||
| .expect("Failed to add internal source"); | ||
|
|
||
| let srcpad = internal_src | ||
| .as_ref() | ||
| .and_then(|src| src.static_pad("src")) | ||
| .ok_or_else(|| { | ||
| glib::Error::new( | ||
| gst::URIError::BadUri, | ||
| "Could not get src pad from internal source", | ||
| ) | ||
| })?; | ||
|
|
||
| let ghostpad = GhostPad::new(PadDirection::Src); | ||
| ghostpad | ||
| .set_target(Some(&srcpad)) | ||
| .ok() | ||
| .ok_or_else(|| glib::Error::new(gst::URIError::BadUri, "Could not create ghost pad"))?; | ||
|
|
||
| ghostpad | ||
| .set_active(true) | ||
| .ok() | ||
| .ok_or_else(|| glib::Error::new(gst::URIError::BadUri, "Could not activate ghost pad"))?; | ||
|
|
||
| let element = self.obj(); | ||
| element.add_pad(&ghostpad).expect("Failed to add ghost pad"); | ||
| Ok(()) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| use gst::glib; | ||
| use gst::prelude::*; | ||
| use gstreamer_base::gst; | ||
|
|
||
| mod imp; | ||
|
|
||
| glib::wrapper! { | ||
| pub struct TauriAsset(ObjectSubclass<imp::TauriAsset>) | ||
| @extends gst::Bin, gst::Element, gst::Object, | ||
| @implements gst::URIHandler; | ||
| } | ||
|
|
||
| pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> { | ||
| gst::Element::register( | ||
| Some(plugin), | ||
| "tauriasset", | ||
| gst::Rank::PRIMARY, | ||
| TauriAsset::static_type(), | ||
| ) | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it should be like this, but I don't think it is a problem for now