Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
preview-generator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mediaflix
preview-generator
Commits
a33d733f
Commit
a33d733f
authored
5 years ago
by
Janne Mareike Koschinski
Browse files
Options
Downloads
Patches
Plain Diff
Improve safety yet again
parent
504f4e94
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/ffmpeg_api/api.rs
+20
-40
20 additions, 40 deletions
src/ffmpeg_api/api.rs
src/main.rs
+5
-12
5 additions, 12 deletions
src/main.rs
with
25 additions
and
52 deletions
src/ffmpeg_api/api.rs
+
20
−
40
View file @
a33d733f
...
...
@@ -6,17 +6,6 @@ use fraction::Fraction;
use
crate
::
ffmpeg_api
::
enums
::
*
;
// TODO: Use proper errors (with struct etc) for this
enum_from_primitive!
{
#[derive(Debug,
Copy,
Clone,
PartialEq)]
#[repr(i32)]
pub
enum
AVErrorKind
{
Unknown
=
ffi
::
AVERROR_EXPERIMENTAL
,
InputChanged
=
ffi
::
AVERROR_INPUT_CHANGED
,
OutputChanged
=
ffi
::
AVERROR_OUTPUT_CHANGED
}
}
pub
struct
AVFormatContext
{
base
:
*
mut
ffi
::
AVFormatContext
,
}
...
...
@@ -30,11 +19,6 @@ impl<'a> AVFormatContext {
Ok
(
AVFormatContext
{
base
})
}
// TODO: Just for testing
pub
unsafe
fn
raw
(
&
self
)
->
*
mut
ffi
::
AVFormatContext
{
self
.base
}
pub
fn
open_input
(
&
mut
self
,
path
:
&
str
)
->
Result
<
(),
failure
::
Error
>
{
match
unsafe
{
ffi
::
avformat_open_input
(
...
...
@@ -64,6 +48,13 @@ impl<'a> AVFormatContext {
})
.collect
();
}
pub
fn
read_frame
(
&
/*TODO:mut*/
self
,
packet
:
&
mut
AVPacket
)
->
Result
<
(),
failure
::
Error
>
{
match
unsafe
{
ffi
::
av_read_frame
(
self
.base
,
packet
.base
)
}
{
0
=>
Ok
(()),
errno
=>
Err
(
failure
::
format_err!
(
"Error while decoding frame: {}"
,
errno
))
}
}
}
impl
Drop
for
AVFormatContext
{
...
...
@@ -116,11 +107,6 @@ impl AVPacket {
Ok
(
AVPacket
{
base
})
}
// TODO: Just for testing
pub
unsafe
fn
as_mut
(
&
mut
self
)
->
&
mut
ffi
::
AVPacket
{
self
.base
.as_mut
()
.expect
(
"not null"
)
}
pub
fn
pts
(
&
self
)
->
i64
{
let
base
=
unsafe
{
self
.base
.as_ref
()
}
.expect
(
"not null"
);
...
...
@@ -160,11 +146,6 @@ impl AVFrame {
Ok
(
AVFrame
{
base
,
buffer
:
AVBuffer
::
empty
()
})
}
// TODO: Just for testing
pub
unsafe
fn
as_mut
(
&
mut
self
)
->
&
mut
ffi
::
AVFrame
{
self
.base
.as_mut
()
.expect
(
"not null"
)
}
pub
fn
init
(
&
mut
self
,
width
:
i32
,
height
:
i32
,
format
:
AVPixelFormat
)
->
Result
<
(),
failure
::
Error
>
{
let
mut
base
=
unsafe
{
self
.base
.as_mut
()
}
.expect
(
"not null"
);
...
...
@@ -345,11 +326,6 @@ impl<'a> AVCodecParameters<'a> {
return
AVCodecParameters
{
base
,
phantom
:
PhantomData
};
}
// TODO: Just for testing
pub
unsafe
fn
as_ref
(
&
self
)
->
&
ffi
::
AVCodecParameters
{
self
.base
}
pub
fn
codec_type
(
&
self
)
->
AVMediaType
{
AVMediaType
::
from_i32
(
self
.base.codec_type
)
.unwrap_or
(
AVMediaType
::
Unknown
)
}
...
...
@@ -376,11 +352,6 @@ impl<'a> AVCodec<'a> {
return
AVCodec
{
base
,
phantom
:
PhantomData
};
}
// TODO: Just for testing
pub
unsafe
fn
as_ref
(
&
self
)
->
&
ffi
::
AVCodec
{
self
.base
}
pub
fn
name
(
self
:
&
AVCodec
<
'a
>
)
->
std
::
string
::
String
{
String
::
from
(
unsafe
{
std
::
ffi
::
CStr
::
from_ptr
(
self
.base.name
)
}
.to_str
()
.unwrap
())
}
...
...
@@ -399,9 +370,18 @@ impl AVCodecContext {
Ok
(
AVCodecContext
{
base
})
}
// TODO: Just for testing
pub
unsafe
fn
raw
(
&
self
)
->
*
mut
ffi
::
AVCodecContext
{
self
.base
pub
fn
in_packet
(
&
mut
self
,
packet
:
&
mut
AVPacket
)
->
Result
<
(),
failure
::
Error
>
{
match
unsafe
{
ffi
::
avcodec_send_packet
(
self
.base
,
packet
.base
)
}
{
0
=>
Ok
(()),
errno
=>
Err
(
failure
::
format_err!
(
"Error while loading paclet: {}"
,
errno
))
}
}
pub
fn
out_frame
(
&
mut
self
,
frame
:
&
mut
AVFrame
)
->
Result
<
(),
failure
::
Error
>
{
match
unsafe
{
ffi
::
avcodec_receive_frame
(
self
.base
,
frame
.base
)
}
{
0
=>
Ok
(()),
errno
=>
Err
(
failure
::
format_err!
(
"Error while decoding frame: {}"
,
errno
))
}
}
pub
fn
skip_loop_filter
(
&
self
)
->
Option
<
AVDiscard
>
{
...
...
This diff is collapsed.
Click to expand it.
src/main.rs
+
5
−
12
View file @
a33d733f
use
ffmpeg_dev
::
sys
as
ffi
;
pub
(
crate
)
mod
ffmpeg_api
;
use
crate
::
ffmpeg_api
::
enums
::
*
;
...
...
@@ -63,17 +61,12 @@ fn main() -> Result<(), std::io::Error> {
let
mut
scale_context
=
SwsContext
::
new
();
//TODO: HERE BE DRAGONS
while
unsafe
{
ffi
::
av_read_frame
(
avformat_context
.raw
(),
packet
.as_mut
())
}
>=
0
&&
i
<
16
{
// TODO: END DRAGONS
while
avformat_context
.read_frame
(
&
mut
packet
)
.is_ok
()
&&
i
<
16
{
if
packet
.stream_index
()
==
stream
.index
()
{
//TODO: HERE BE DRAGONS
unsafe
{
ffi
::
avcodec_send_packet
(
codec_context
.raw
(),
packet
.as_mut
())
};
while
unsafe
{
ffi
::
avcodec_receive_frame
(
codec_context
.raw
(),
frame
.as_mut
())
}
>=
0
{
// TODO: END DRAGONS
codec_context
.in_packet
(
&
mut
packet
)
.unwrap_or_else
(|
error
|
{
panic!
(
"Could not load packet: {:?}"
,
error
)
});
while
codec_context
.out_frame
(
&
mut
frame
)
.is_ok
()
{
println!
(
"Frame {}: {:?} @ {}"
,
frame
.coded_picture_number
(),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment