|
| 1 | +/* |
| 2 | + * This file is part of GStreamer Daemon |
| 3 | + * Copyright 2015-2026 RidgeRun, LLC (http://www.ridgerun.com) |
| 4 | + * |
| 5 | + * This library is free software; you can redistribute it and/or |
| 6 | + * modify it under the terms of the GNU Library General Public |
| 7 | + * License as published by the Free Software Foundation; either |
| 8 | + * version 2 of the License, or (at your option) any later version. |
| 9 | + * |
| 10 | + * This library is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | + * Library General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU Library General Public |
| 16 | + * License along with this library; if not, write to the |
| 17 | + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, |
| 18 | + * Boston, MA 02110-1301, USA. |
| 19 | + */ |
| 20 | + |
| 21 | +use gstc::{Client, Status}; |
| 22 | +use std::env; |
| 23 | +use std::io; |
| 24 | +use std::path::PathBuf; |
| 25 | +use std::sync::atomic::{AtomicBool, Ordering}; |
| 26 | +use std::sync::Arc; |
| 27 | +use std::thread; |
| 28 | + |
| 29 | +const RATE: f64 = 1.0; |
| 30 | +const FORMAT: i32 = 3; |
| 31 | +const FLAGS: i32 = 1; |
| 32 | +const START_TYPE: i32 = 1; |
| 33 | +const START: i64 = 0; |
| 34 | +const STOP_TYPE: i32 = 1; |
| 35 | +const STOP: i64 = -1; |
| 36 | + |
| 37 | +fn main() -> Result<(), Status> { |
| 38 | + let video = match env::args().nth(1) { |
| 39 | + Some(path) => path, |
| 40 | + None => { |
| 41 | + eprintln!("Please provide a video to play"); |
| 42 | + return Err(Status::NullArgument); |
| 43 | + } |
| 44 | + }; |
| 45 | + |
| 46 | + let abs_path = PathBuf::from(&video) |
| 47 | + .canonicalize() |
| 48 | + .unwrap_or_else(|_| PathBuf::from(&video)); |
| 49 | + let uri = format!("file://{}", abs_path.display()); |
| 50 | + |
| 51 | + let client = Client::new("127.0.0.1", 5000, -1, true)?; |
| 52 | + |
| 53 | + client.pipeline_create("pipe", &format!("playbin uri={}", uri))?; |
| 54 | + println!("Pipeline created successfully!"); |
| 55 | + |
| 56 | + client.pipeline_play("pipe")?; |
| 57 | + println!("Pipeline set to playing!"); |
| 58 | + |
| 59 | + println!("Press enter to stop the pipeline..."); |
| 60 | + let stop_flag = Arc::new(AtomicBool::new(false)); |
| 61 | + let thread_stop_flag = Arc::clone(&stop_flag); |
| 62 | + thread::spawn(move || { |
| 63 | + let mut line = String::new(); |
| 64 | + let _ = io::stdin().read_line(&mut line); |
| 65 | + thread_stop_flag.store(true, Ordering::Relaxed); |
| 66 | + }); |
| 67 | + |
| 68 | + while !stop_flag.load(Ordering::Relaxed) { |
| 69 | + let message = client.pipeline_bus_wait("pipe", "eos", -1)?; |
| 70 | + if message.status != Status::Ok { |
| 71 | + eprintln!("Unable to read from bus: {}", message.status.code()); |
| 72 | + break; |
| 73 | + } |
| 74 | + |
| 75 | + println!("EOS message received!"); |
| 76 | + |
| 77 | + client.pipeline_seek( |
| 78 | + "pipe", RATE, FORMAT, FLAGS, START_TYPE, START, STOP_TYPE, STOP, |
| 79 | + )?; |
| 80 | + println!("Pipeline reset!"); |
| 81 | + } |
| 82 | + |
| 83 | + client.pipeline_stop("pipe")?; |
| 84 | + println!("Pipeline set to null!"); |
| 85 | + |
| 86 | + client.pipeline_delete("pipe")?; |
| 87 | + println!("Pipeline deleted!"); |
| 88 | + |
| 89 | + Ok(()) |
| 90 | +} |
0 commit comments