Elements: Downscale: Use BaseBin as base class
Signed-off-by: Vasiliy Doylov <nekocwd@mainlining.org>
This commit is contained in:
parent
dda57d786d
commit
85213ec8c7
1 changed files with 44 additions and 48 deletions
|
@ -1,41 +1,43 @@
|
|||
public class EyeNeko.Elements.Downscale : Gst.Bin {
|
||||
public Gst.Element videoscale = Gst.ElementFactory.make("videoscale");
|
||||
public Gst.Element capsfilter = Gst.ElementFactory.make("capsfilter");
|
||||
Gst.Pad sinkpad;
|
||||
Gst.Pad srcpad;
|
||||
/* downscale.vala
|
||||
*
|
||||
* Copyright 2025 Vasiliy Doylov <nekocwd@mainlining.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
public class EyeNeko.Elements.Downscale : BinBase {
|
||||
public Gst.Element videoscale = Gst.ElementFactory.make ("videoscale");
|
||||
public Gst.Element capsfilter = Gst.ElementFactory.make ("capsfilter");
|
||||
public int max_size { get; set; default = 0; }
|
||||
|
||||
static construct {
|
||||
set_static_metadata(
|
||||
"downscale",
|
||||
"Filter",
|
||||
"Downscale video filter.",
|
||||
"nekocwd@mainlining.org");
|
||||
|
||||
add_static_pad_template(
|
||||
{
|
||||
"sink",
|
||||
Gst.PadDirection.SINK,
|
||||
Gst.PadPresence.ALWAYS,
|
||||
{ null, "video/x-raw" }
|
||||
});
|
||||
add_static_pad_template(
|
||||
{
|
||||
"src",
|
||||
Gst.PadDirection.SRC,
|
||||
Gst.PadPresence.ALWAYS,
|
||||
{ null, "video/x-raw" }
|
||||
});
|
||||
set_static_metadata ("downscale",
|
||||
"Filter",
|
||||
"Downscale video filter.",
|
||||
"nekocwd@mainlining.org");
|
||||
}
|
||||
|
||||
static bool sink_event(Gst.Pad pad, Gst.Object? parent, owned Gst.Event event) {
|
||||
static bool sink_event (Gst.Pad pad, Gst.Object? parent, owned Gst.Event event) {
|
||||
var filter = (Downscale) parent;
|
||||
if (event.type == Gst.EventType.CAPS) {
|
||||
Gst.Caps caps;
|
||||
event.parse_caps(out caps);
|
||||
var info = new Gst.Video.Info.with_caps(caps);
|
||||
var old_info = info.copy();
|
||||
var max_dim = int.max(info.width, info.height);
|
||||
event.parse_caps (out caps);
|
||||
var info = new Gst.Video.Info.with_caps (caps);
|
||||
var old_info = info.copy ();
|
||||
var max_dim = int.max (info.width, info.height);
|
||||
if (filter.max_size > 0 && max_dim > filter.max_size) {
|
||||
double mult = (double) filter.max_size / (double) max_dim;
|
||||
info.width = (int) (info.width * mult);
|
||||
|
@ -45,30 +47,24 @@ public class EyeNeko.Elements.Downscale : Gst.Bin {
|
|||
info.width++;
|
||||
if (info.height % 2 > 0)
|
||||
info.height++;
|
||||
debug("%dx%d=S=>%dx%d", old_info.width, old_info.height, info.width, info.height);
|
||||
var new_caps = caps.copy();
|
||||
new_caps.set_simple("width", typeof (int), info.width);
|
||||
new_caps.set_simple("height", typeof (int), info.height);
|
||||
filter.capsfilter.set_property("caps", new_caps);
|
||||
debug ("%dx%d=S=>%dx%d", old_info.width, old_info.height, info.width, info.height);
|
||||
var new_caps = caps.copy ();
|
||||
new_caps.set_simple ("width", typeof (int), info.width);
|
||||
new_caps.set_simple ("height", typeof (int), info.height);
|
||||
filter.capsfilter.set_property ("caps", new_caps);
|
||||
}
|
||||
return pad.event_default(parent, event);
|
||||
return pad.event_default (parent, event);
|
||||
}
|
||||
|
||||
public Downscale() {}
|
||||
public Downscale.to(int max_size) {
|
||||
public Downscale () {}
|
||||
public Downscale.to (int max_size) {
|
||||
_max_size = max_size;
|
||||
}
|
||||
|
||||
construct {
|
||||
// Child elements
|
||||
add_many(videoscale, capsfilter);
|
||||
videoscale.link(capsfilter);
|
||||
// Sink Pad
|
||||
sinkpad = new Gst.GhostPad("sink", videoscale.get_static_pad("sink"));
|
||||
sinkpad.set_event_function(sink_event, null, null);
|
||||
add_pad(sinkpad);
|
||||
// Src Pad
|
||||
srcpad = new Gst.GhostPad("src", capsfilter.get_static_pad("src"));
|
||||
add_pad(srcpad);
|
||||
add_many (videoscale, capsfilter);
|
||||
videoscale.link (capsfilter);
|
||||
add_pads (videoscale, capsfilter);
|
||||
sinkpad.set_event_function (sink_event, null, null);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue