Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
9e3d0367
Commit
9e3d0367
authored
Nov 03, 2013
by
Ilkka Ollakka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avcodec: refactor delay buffer handling from EncodeAudio
parent
af489315
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
100 additions
and
87 deletions
+100
-87
modules/codec/avcodec/encoder.c
modules/codec/avcodec/encoder.c
+100
-87
No files found.
modules/codec/avcodec/encoder.c
View file @
9e3d0367
...
...
@@ -1115,47 +1115,12 @@ static block_t *EncodeVideo( encoder_t *p_enc, picture_t *p_pict )
return
p_block
;
}
/****************************************************************************
* EncodeAudio: the whole thing
****************************************************************************/
static
block_t
*
EncodeAudio
(
encoder_t
*
p_enc
,
block_t
*
p_aout_buf
)
static
block_t
*
handle_delay_buffer
(
encoder_t
*
p_enc
,
encoder_sys_t
*
p_sys
,
int
buffer_delay
,
block_t
*
p_aout_buf
,
int
leftover_samples
)
{
encoder_sys_t
*
p_sys
=
p_enc
->
p_sys
;
block_t
*
p_block
,
*
p_chain
=
NULL
;
int
got_packet
,
i_out
;
size_t
buffer_delay
=
0
,
i_samples_left
=
0
;
//i_bytes_left is amount of bytes we get
i_samples_left
=
p_aout_buf
?
p_aout_buf
->
i_nb_samples
:
0
;
buffer_delay
=
p_sys
->
i_samples_delay
*
p_sys
->
i_sample_bytes
*
p_sys
->
p_context
->
channels
;
//p_sys->i_buffer_out = p_sys->i_frame_size * chan * p_sys->i_sample_bytes
//Calculate how many bytes we would need from current buffer to fill frame
size_t
leftover_samples
=
__MAX
(
0
,
__MIN
((
ssize_t
)
i_samples_left
,
(
ssize_t
)(
p_sys
->
i_frame_size
-
p_sys
->
i_samples_delay
)));
if
(
(
p_aout_buf
&&
(
p_aout_buf
->
i_pts
>
VLC_TS_INVALID
)
&&
((
p_aout_buf
->
i_pts
-
p_sys
->
i_samples_delay
)
!=
date_Get
(
&
p_sys
->
buffer_date
)
)
)
)
{
date_Set
(
&
p_sys
->
buffer_date
,
p_aout_buf
->
i_dts
);
/* take back amount we have leftover from previous buffer*/
if
(
p_sys
->
i_samples_delay
>
0
)
date_Decrement
(
&
p_sys
->
buffer_date
,
p_sys
->
i_samples_delay
);
}
// Check if we have enough samples in delay_buffer and current p_aout_buf to fill frame
// Or if we are cleaning up
if
(
(
buffer_delay
>
0
)
&&
(
(
p_aout_buf
&&
(
leftover_samples
<=
p_aout_buf
->
i_nb_samples
)
&&
(
(
leftover_samples
+
p_sys
->
i_samples_delay
)
>=
p_sys
->
i_frame_size
)
)
||
(
!
p_aout_buf
)
)
)
{
block_t
*
p_block
,
*
p_chain
=
NULL
;
//How much we need to copy from new packet
const
int
leftover
=
leftover_samples
*
p_sys
->
p_context
->
channels
*
p_sys
->
i_sample_bytes
;
int
got_packet
,
i_out
;
#if LIBAVUTIL_VERSION_CHECK( 51,27,2,46,100 )
const
int
align
=
0
;
...
...
@@ -1167,6 +1132,7 @@ static block_t *EncodeAudio( encoder_t *p_enc, block_t *p_aout_buf )
avcodec_get_frame_defaults
(
p_sys
->
frame
);
p_sys
->
frame
->
format
=
p_sys
->
p_context
->
sample_fmt
;
p_sys
->
frame
->
nb_samples
=
leftover_samples
+
p_sys
->
i_samples_delay
;
p_sys
->
frame
->
format
=
p_sys
->
p_context
->
sample_fmt
;
p_sys
->
frame
->
pts
=
date_Get
(
&
p_sys
->
buffer_date
);
...
...
@@ -1210,7 +1176,7 @@ static block_t *EncodeAudio( encoder_t *p_enc, block_t *p_aout_buf )
p_sys
->
frame
->
nb_samples
=
0
;
}
buffer_delay
=
0
;
p_sys
->
i_samples_delay
=
0
;
p_block
=
block_Alloc
(
p_sys
->
i_buffer_out
);
...
...
@@ -1242,6 +1208,53 @@ static block_t *EncodeAudio( encoder_t *p_enc, block_t *p_aout_buf )
p_block
->
i_dts
=
p_block
->
i_pts
=
VLC_TS_INVALID
;
block_ChainAppend
(
&
p_chain
,
p_block
);
return
p_chain
;
}
/****************************************************************************
* EncodeAudio: the whole thing
****************************************************************************/
static
block_t
*
EncodeAudio
(
encoder_t
*
p_enc
,
block_t
*
p_aout_buf
)
{
encoder_sys_t
*
p_sys
=
p_enc
->
p_sys
;
block_t
*
p_block
,
*
p_chain
=
NULL
;
int
got_packet
,
i_out
;
size_t
buffer_delay
=
0
,
i_samples_left
=
0
;
//i_bytes_left is amount of bytes we get
i_samples_left
=
p_aout_buf
?
p_aout_buf
->
i_nb_samples
:
0
;
buffer_delay
=
p_sys
->
i_samples_delay
*
p_sys
->
i_sample_bytes
*
p_sys
->
p_context
->
channels
;
//p_sys->i_buffer_out = p_sys->i_frame_size * chan * p_sys->i_sample_bytes
//Calculate how many bytes we would need from current buffer to fill frame
size_t
leftover_samples
=
__MAX
(
0
,
__MIN
((
ssize_t
)
i_samples_left
,
(
ssize_t
)(
p_sys
->
i_frame_size
-
p_sys
->
i_samples_delay
)));
if
(
(
p_aout_buf
&&
(
p_aout_buf
->
i_pts
>
VLC_TS_INVALID
)
&&
((
p_aout_buf
->
i_pts
-
p_sys
->
i_samples_delay
)
!=
date_Get
(
&
p_sys
->
buffer_date
)
)
)
)
{
date_Set
(
&
p_sys
->
buffer_date
,
p_aout_buf
->
i_dts
);
/* take back amount we have leftover from previous buffer*/
if
(
p_sys
->
i_samples_delay
>
0
)
date_Decrement
(
&
p_sys
->
buffer_date
,
p_sys
->
i_samples_delay
);
}
// Check if we have enough samples in delay_buffer and current p_aout_buf to fill frame
// Or if we are cleaning up
if
(
(
buffer_delay
>
0
)
&&
(
(
p_aout_buf
&&
(
leftover_samples
<=
p_aout_buf
->
i_nb_samples
)
&&
(
(
leftover_samples
+
p_sys
->
i_samples_delay
)
>=
p_sys
->
i_frame_size
)
)
||
(
!
p_aout_buf
)
)
)
{
p_chain
=
handle_delay_buffer
(
p_enc
,
p_sys
,
buffer_delay
,
p_aout_buf
,
leftover_samples
);
buffer_delay
=
0
;
if
(
unlikely
(
!
p_chain
)
)
return
NULL
;
}
if
(
unlikely
(
!
p_aout_buf
)
)
...
...
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