Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Zeeshan Ali
gstreamer-rs
Commits
a01f1385
Commit
a01f1385
authored
Nov 12, 2017
by
Sebastian Dröge
🍵
Browse files
examples: Set up a runloop on macOS
parent
10151b9f
Changes
14
Hide whitespace changes
Inline
Side-by-side
examples/src/bin/appsink.rs
View file @
a01f1385
...
...
@@ -19,6 +19,9 @@ use failure::Error;
#[macro_use]
extern
crate
failure_derive
;
#[path
=
"../examples-common.rs"
]
mod
examples_common
;
#[derive(Debug,
Fail)]
#[fail(display
=
"Missing element {}"
,
_0)]
struct
MissingElement
(
&
'static
str
);
...
...
@@ -152,9 +155,15 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
Ok
(())
}
fn
main
()
{
fn
example_
main
()
{
match
create_pipeline
()
.and_then
(
main_loop
)
{
Ok
(
r
)
=>
r
,
Err
(
e
)
=>
eprintln!
(
"Error! {}"
,
e
),
}
}
fn
main
()
{
// tutorials_common::run is only required to set up the application environent on macOS
// (but not necessary in normal Cocoa applications where this is set up autmatically)
examples_common
::
run
(
example_main
);
}
examples/src/bin/appsrc.rs
View file @
a01f1385
...
...
@@ -15,6 +15,9 @@ use failure::Error;
#[macro_use]
extern
crate
failure_derive
;
#[path
=
"../examples-common.rs"
]
mod
examples_common
;
#[derive(Debug,
Fail)]
#[fail(display
=
"Missing element {}"
,
_0)]
struct
MissingElement
(
&
'static
str
);
...
...
@@ -123,9 +126,15 @@ fn main_loop(pipeline: gst::Pipeline, appsrc: gst_app::AppSrc) -> Result<(), Err
Ok
(())
}
fn
main
()
{
fn
example_
main
()
{
match
create_pipeline
()
.and_then
(|(
pipeline
,
appsrc
)|
main_loop
(
pipeline
,
appsrc
))
{
Ok
(
r
)
=>
r
,
Err
(
e
)
=>
eprintln!
(
"Error! {}"
,
e
),
}
}
fn
main
()
{
// tutorials_common::run is only required to set up the application environent on macOS
// (but not necessary in normal Cocoa applications where this is set up autmatically)
examples_common
::
run
(
example_main
);
}
examples/src/bin/decodebin.rs
View file @
a01f1385
...
...
@@ -5,7 +5,10 @@ extern crate glib;
use
std
::
env
;
fn
main
()
{
#[path
=
"../examples-common.rs"
]
mod
examples_common
;
fn
example_main
()
{
gst
::
init
()
.unwrap
();
let
args
:
Vec
<
_
>
=
env
::
args
()
.collect
();
...
...
@@ -113,3 +116,9 @@ fn main() {
gst
::
StateChangeReturn
::
Failure
);
}
fn
main
()
{
// tutorials_common::run is only required to set up the application environent on macOS
// (but not necessary in normal Cocoa applications where this is set up autmatically)
examples_common
::
run
(
example_main
);
}
examples/src/bin/events.rs
View file @
a01f1385
...
...
@@ -3,7 +3,10 @@ use gst::prelude::*;
extern
crate
glib
;
fn
main
()
{
#[path
=
"../examples-common.rs"
]
mod
examples_common
;
fn
example_main
()
{
gst
::
init
()
.unwrap
();
let
main_loop
=
glib
::
MainLoop
::
new
(
None
,
false
);
...
...
@@ -59,3 +62,9 @@ fn main() {
let
ret
=
pipeline
.set_state
(
gst
::
State
::
Null
);
assert_ne!
(
ret
,
gst
::
StateChangeReturn
::
Failure
);
}
fn
main
()
{
// tutorials_common::run is only required to set up the application environent on macOS
// (but not necessary in normal Cocoa applications where this is set up autmatically)
examples_common
::
run
(
example_main
);
}
examples/src/bin/iterator.rs
View file @
a01f1385
extern
crate
gstreamer
as
gst
;
use
gst
::
prelude
::
*
;
fn
main
()
{
#[path
=
"../examples-common.rs"
]
mod
examples_common
;
fn
example_main
()
{
gst
::
init
()
.unwrap
();
let
identity
=
gst
::
ElementFactory
::
make
(
"identity"
,
None
)
.unwrap
();
...
...
@@ -20,3 +23,9 @@ fn main() {
}
}
}
fn
main
()
{
// tutorials_common::run is only required to set up the application environent on macOS
// (but not necessary in normal Cocoa applications where this is set up autmatically)
examples_common
::
run
(
example_main
);
}
examples/src/bin/launch.rs
View file @
a01f1385
...
...
@@ -4,7 +4,10 @@ use gst::prelude::*;
use
std
::
env
;
use
std
::
process
;
fn
main
()
{
#[path
=
"../examples-common.rs"
]
mod
examples_common
;
fn
example_main
()
{
let
pipeline_str
=
env
::
args
()
.collect
::
<
Vec
<
String
>>
()[
1
..
]
.join
(
" "
);
gst
::
init
()
.unwrap
();
...
...
@@ -49,3 +52,9 @@ fn main() {
let
ret
=
pipeline
.set_state
(
gst
::
State
::
Null
);
assert_ne!
(
ret
,
gst
::
StateChangeReturn
::
Failure
);
}
fn
main
()
{
// tutorials_common::run is only required to set up the application environent on macOS
// (but not necessary in normal Cocoa applications where this is set up autmatically)
examples_common
::
run
(
example_main
);
}
examples/src/bin/launch_glib_main.rs
View file @
a01f1385
...
...
@@ -5,7 +5,10 @@ extern crate glib;
use
std
::
env
;
fn
main
()
{
#[path
=
"../examples-common.rs"
]
mod
examples_common
;
fn
example_main
()
{
let
pipeline_str
=
env
::
args
()
.collect
::
<
Vec
<
String
>>
()[
1
..
]
.join
(
" "
);
gst
::
init
()
.unwrap
();
...
...
@@ -48,3 +51,9 @@ fn main() {
let
ret
=
pipeline
.set_state
(
gst
::
State
::
Null
);
assert_ne!
(
ret
,
gst
::
StateChangeReturn
::
Failure
);
}
fn
main
()
{
// tutorials_common::run is only required to set up the application environent on macOS
// (but not necessary in normal Cocoa applications where this is set up autmatically)
examples_common
::
run
(
example_main
);
}
examples/src/bin/pad_probes.rs
View file @
a01f1385
...
...
@@ -7,7 +7,10 @@ use byte_slice_cast::*;
use
std
::
i16
;
fn
main
()
{
#[path
=
"../examples-common.rs"
]
mod
examples_common
;
fn
example_main
()
{
gst
::
init
()
.unwrap
();
let
pipeline
=
gst
::
parse_launch
(
&
format!
(
...
...
@@ -71,3 +74,9 @@ fn main() {
let
ret
=
pipeline
.set_state
(
gst
::
State
::
Null
);
assert_ne!
(
ret
,
gst
::
StateChangeReturn
::
Failure
);
}
fn
main
()
{
// tutorials_common::run is only required to set up the application environent on macOS
// (but not necessary in normal Cocoa applications where this is set up autmatically)
examples_common
::
run
(
example_main
);
}
examples/src/bin/playbin.rs
View file @
a01f1385
...
...
@@ -5,7 +5,10 @@ extern crate glib;
use
std
::
env
;
fn
main
()
{
#[path
=
"../examples-common.rs"
]
mod
examples_common
;
fn
example_main
()
{
gst
::
init
()
.unwrap
();
let
args
:
Vec
<
_
>
=
env
::
args
()
.collect
();
...
...
@@ -86,3 +89,9 @@ fn main() {
let
ret
=
playbin
.set_state
(
gst
::
State
::
Null
);
assert_ne!
(
ret
,
gst
::
StateChangeReturn
::
Failure
);
}
fn
main
()
{
// tutorials_common::run is only required to set up the application environent on macOS
// (but not necessary in normal Cocoa applications where this is set up autmatically)
examples_common
::
run
(
example_main
);
}
examples/src/bin/player.rs
View file @
a01f1385
...
...
@@ -17,6 +17,10 @@ extern crate failure;
#[allow(unused_imports)]
use
failure
::
Error
;
#[allow(unused_imports)]
#[path
=
"../examples-common.rs"
]
mod
examples_common
;
#[cfg(feature
=
"gst-player"
)]
fn
main_loop
(
uri
:
&
str
)
->
Result
<
(),
Error
>
{
gst
::
init
()
?
;
...
...
@@ -65,7 +69,7 @@ fn main_loop(uri: &str) -> Result<(), Error> {
}
#[allow(unused_variables)]
fn
main
()
{
fn
example_
main
()
{
let
args
:
Vec
<
_
>
=
env
::
args
()
.collect
();
let
uri
:
&
str
=
if
args
.len
()
==
2
{
args
[
1
]
.as_ref
()
...
...
@@ -86,3 +90,9 @@ fn main() {
Err
(
e
)
=>
eprintln!
(
"Error! {}"
,
e
),
}
}
fn
main
()
{
// tutorials_common::run is only required to set up the application environent on macOS
// (but not necessary in normal Cocoa applications where this is set up autmatically)
examples_common
::
run
(
example_main
);
}
examples/src/bin/queries.rs
View file @
a01f1385
...
...
@@ -5,7 +5,10 @@ extern crate glib;
use
std
::
env
;
fn
main
()
{
#[path
=
"../examples-common.rs"
]
mod
examples_common
;
fn
example_main
()
{
let
pipeline_str
=
env
::
args
()
.collect
::
<
Vec
<
String
>>
()[
1
..
]
.join
(
" "
);
gst
::
init
()
.unwrap
();
...
...
@@ -87,3 +90,9 @@ fn main() {
let
ret
=
pipeline
.set_state
(
gst
::
State
::
Null
);
assert_ne!
(
ret
,
gst
::
StateChangeReturn
::
Failure
);
}
fn
main
()
{
// tutorials_common::run is only required to set up the application environent on macOS
// (but not necessary in normal Cocoa applications where this is set up autmatically)
examples_common
::
run
(
example_main
);
}
examples/src/bin/toc.rs
View file @
a01f1385
...
...
@@ -5,7 +5,10 @@ extern crate glib;
use
std
::
env
;
fn
main
()
{
#[path
=
"../examples-common.rs"
]
mod
examples_common
;
fn
example_main
()
{
gst
::
init
()
.unwrap
();
let
args
:
Vec
<
_
>
=
env
::
args
()
.collect
();
...
...
@@ -112,3 +115,9 @@ fn main() {
gst
::
StateChangeReturn
::
Failure
);
}
fn
main
()
{
// tutorials_common::run is only required to set up the application environent on macOS
// (but not necessary in normal Cocoa applications where this is set up autmatically)
examples_common
::
run
(
example_main
);
}
examples/src/bin/tokio.rs
View file @
a01f1385
...
...
@@ -15,8 +15,12 @@ use tokio_core::reactor::Core;
#[cfg(feature
=
"tokio"
)]
use
std
::
env
;
#[allow(unused_imports)]
#[path
=
"../examples-common.rs"
]
mod
examples_common
;
#[cfg(feature
=
"tokio"
)]
fn
main
()
{
fn
example_
main
()
{
let
pipeline_str
=
env
::
args
()
.collect
::
<
Vec
<
String
>>
()[
1
..
]
.join
(
" "
);
gst
::
init
()
.unwrap
();
...
...
@@ -59,6 +63,13 @@ fn main() {
assert_ne!
(
ret
,
gst
::
StateChangeReturn
::
Failure
);
}
#[cfg(feature
=
"tokio"
)]
fn
main
()
{
// tutorials_common::run is only required to set up the application environent on macOS
// (but not necessary in normal Cocoa applications where this is set up autmatically)
examples_common
::
run
(
example_main
);
}
#[cfg(not(feature
=
"tokio"
))]
fn
main
()
{
println!
(
"Please compile with --features tokio"
);
...
...
examples/src/examples-common.rs
0 → 100644
View file @
a01f1385
/// macOS has a specific requirement that there must be a run loop running
/// on the main thread in order to open windows and use OpenGL.
#[cfg(target_os
=
"macos"
)]
#[link(name
=
"foundation"
,
kind
=
"framework"
)]
extern
"C"
{
fn
CFRunLoopRun
();
}
/// On macOS this launches the callback function on a thread.
/// On other platforms it's just executed immediately.
#[cfg(not(target_os
=
"macos"
))]
pub
fn
run
<
F
:
FnOnce
()
+
Send
+
'static
>
(
main
:
F
)
{
main
();
}
#[cfg(target_os
=
"macos"
)]
pub
fn
run
<
F
:
FnOnce
()
+
Send
+
'static
>
(
main
:
F
)
{
::
std
::
thread
::
spawn
(
main
);
unsafe
{
CFRunLoopRun
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment