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
7ba85493
Verified
Commit
7ba85493
authored
4 years ago
by
Janne Mareike Koschinski
Browse files
Options
Downloads
Patches
Plain Diff
Resolve some memory leaks
parent
3ce91376
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/ffmpeg_api/src/api.rs
+32
-16
32 additions, 16 deletions
lib/ffmpeg_api/src/api.rs
with
32 additions
and
16 deletions
lib/ffmpeg_api/src/api.rs
+
32
−
16
View file @
7ba85493
...
...
@@ -3,8 +3,8 @@ use std::path::{Path, PathBuf};
use
ffmpeg_dev
::
sys
as
ffi
;
use
fraction
::
Fraction
;
use
num_traits
::
FromPrimitive
;
use
media_time
::
MediaTimeError
;
use
num_traits
::
FromPrimitive
;
use
thiserror
::
Error
;
use
crate
::
enums
::
*
;
...
...
@@ -21,7 +21,7 @@ pub enum StringError {
#[error(
"String is unexpectedly null"
)]
NullError
,
#[error(transparent)]
Utf8Error
(
#[from]
std
::
str
::
Utf8Error
)
Utf8Error
(
#[from]
std
::
str
::
Utf8Error
)
,
}
fn
native_string
(
ptr
:
*
const
std
::
os
::
raw
::
c_char
)
->
Result
<
String
,
StringError
>
{
...
...
@@ -48,7 +48,7 @@ pub enum AVFormatContextError {
#[error(
"Path {0} contains null byte"
)]
PathContainsNull
(
PathBuf
,
#[source]
std
::
ffi
::
NulError
),
#[error(
"Opening media file {0} failed"
)]
OpenInputFailed
(
PathBuf
,
#[source]
AVError
)
OpenInputFailed
(
PathBuf
,
#[source]
AVError
)
,
}
impl
AVFormatContext
{
...
...
@@ -58,7 +58,7 @@ impl AVFormatContext {
Err
(
AVAllocError
::
AllocFailed
(
"AVFormatContext"
.to_string
()))
}
else
{
Ok
(
AVFormatContext
{
base
})
}
}
;
}
pub
fn
open_input
(
&
mut
self
,
path
:
&
Path
)
->
Result
<
(),
AVFormatContextError
>
{
...
...
@@ -95,6 +95,7 @@ impl AVFormatContext {
}
pub
fn
read_frame
(
&
mut
self
,
packet
:
&
mut
AVPacket
)
->
Result
<
(),
AVFrameError
>
{
unsafe
{
ffi
::
av_packet_unref
(
packet
.base
)
}
AVError
::
from_errno
(
unsafe
{
ffi
::
av_read_frame
(
self
.base
,
packet
.base
)
})
.map_err
(|
err
|
AVFrameError
::
DecodingFailed
(
packet
.stream_index
(),
packet
.pts
(),
err
))
}
...
...
@@ -171,7 +172,7 @@ impl AVBuffer {
Err
(
AVAllocError
::
AllocFailed
(
"AVBufferContext"
.to_string
()))
}
else
{
Ok
(
AVBuffer
{
base
,
size
})
}
}
;
}
pub
fn
empty
()
->
Self
{
...
...
@@ -190,6 +191,14 @@ impl AVBuffer {
}
}
impl
Drop
for
AVBuffer
{
fn
drop
(
&
mut
self
)
{
unsafe
{
ffi
::
av_free
(
self
.base
as
*
mut
std
::
ffi
::
c_void
)
}
}
}
pub
struct
AVPacket
{
base
:
*
mut
ffi
::
AVPacket
,
}
...
...
@@ -207,7 +216,7 @@ impl AVPacket {
Err
(
AVAllocError
::
AllocFailed
(
"AVPacket"
.to_string
()))
}
else
{
Ok
(
AVPacket
{
base
})
}
}
;
}
fn
as_ref
(
&
self
)
->
&
ffi
::
AVPacket
{
...
...
@@ -229,7 +238,10 @@ impl AVPacket {
impl
Drop
for
AVPacket
{
fn
drop
(
&
mut
self
)
{
unsafe
{
ffi
::
av_packet_free
(
&
mut
self
.base
)
}
unsafe
{
ffi
::
av_packet_unref
(
self
.base
);
ffi
::
av_packet_free
(
&
mut
self
.base
);
}
}
}
...
...
@@ -243,7 +255,7 @@ pub enum AVFrameError {
#[error(transparent)]
AllocFailed
(
#[from]
AVAllocError
),
#[error(
"Decoding a frame from packet of stream {0} at timestamp {1} failed"
)]
DecodingFailed
(
i32
,
i64
,
#[source]
AVError
)
DecodingFailed
(
i32
,
i64
,
#[source]
AVError
)
,
}
impl
AVFrame
{
...
...
@@ -252,8 +264,8 @@ impl AVFrame {
return
if
base
.is_null
()
{
Err
(
AVAllocError
::
AllocFailed
(
"AVFrame"
.to_string
()))
}
else
{
Ok
(
AVFrame
{
base
,
buffer
:
AVBuffer
::
empty
()
,
})
}
Ok
(
AVFrame
{
base
,
buffer
:
AVBuffer
::
empty
()
})
}
;
}
pub
fn
init
(
&
mut
self
,
width
:
i32
,
height
:
i32
,
format
:
AVPixelFormat
)
->
Result
<
(),
AVFrameError
>
{
...
...
@@ -345,7 +357,10 @@ impl AVFrame {
impl
Drop
for
AVFrame
{
fn
drop
(
&
mut
self
)
{
unsafe
{
ffi
::
av_frame_free
(
&
mut
self
.base
)
}
unsafe
{
ffi
::
av_frame_unref
(
self
.base
);
ffi
::
av_frame_free
(
&
mut
self
.base
);
}
}
}
...
...
@@ -511,6 +526,7 @@ impl AVCodecContext {
}
pub
fn
out_frame
(
&
mut
self
,
frame
:
&
mut
AVFrame
)
->
Result
<
(),
AVCodecContextError
>
{
unsafe
{
ffi
::
av_frame_unref
(
frame
.base
)
}
AVError
::
from_errno
(
unsafe
{
ffi
::
avcodec_receive_frame
(
self
.base
,
frame
.base
)
})
.map_err
(|
err
|
AVCodecContextError
::
FrameError
(
err
))
}
...
...
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