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
99ba52e3
Commit
99ba52e3
authored
Oct 24, 2012
by
Ilkka Ollakka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avcodec: flush buffer and use encode_audio2() on audio
Take2 as now we have new enough libavcodec
parent
527887c7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
64 deletions
+44
-64
modules/codec/avcodec/encoder.c
modules/codec/avcodec/encoder.c
+44
-64
No files found.
modules/codec/avcodec/encoder.c
View file @
99ba52e3
...
...
@@ -1023,84 +1023,64 @@ 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
;
AVFrame
*
frame
;
AVPacket
packet
;
int
got_packet
,
i_out
;
/*FIXME: change to use avcodec_encode_audio2 to be able to flush*/
if
(
unlikely
(
!
p_aout_buf
)
)
return
NULL
;
uint8_t
*
p_buffer
=
p_aout_buf
->
p_buffer
;
int
i_samples
=
p_aout_buf
->
i_nb_samples
;
int
i_samples_delay
=
p_sys
->
i_samples_delay
;
p_sys
->
i_pts
=
p_aout_buf
->
i_pts
-
(
mtime_t
)
1000000
*
(
mtime_t
)
p_sys
->
i_samples_delay
/
(
mtime_t
)
p_enc
->
fmt_in
.
audio
.
i_rate
;
p_sys
->
i_samples_delay
+=
i_samples
;
while
(
p_sys
->
i_samples_delay
>=
p_sys
->
i_frame_size
)
if
(
unlikely
(
!
p_aout_buf
)
)
{
void
*
p_samples
;
int
i_out
;
msg_Dbg
(
p_enc
,
"Flushing.."
)
;
do
{
p_block
=
block_New
(
p_enc
,
p_sys
->
i_buffer_out
);
av_init_packet
(
&
packet
);
packet
.
data
=
p_block
->
p_buffer
;
packet
.
size
=
p_block
->
i_buffer
;
i_out
=
avcodec_encode_audio2
(
p_sys
->
p_context
,
&
packet
,
NULL
,
&
got_packet
);
if
(
!
i_out
&&
got_packet
)
block_ChainAppend
(
&
p_chain
,
p_block
);
}
while
(
got_packet
&&
!
i_out
);
return
p_chain
;
}
if
(
i_samples_delay
)
{
/* Take care of the left-over from last time */
int
i_delay_size
=
i_samples_delay
;
int
i_size
=
(
p_sys
->
i_frame_size
-
i_delay_size
)
*
p_sys
->
i_sample_bytes
;
memcpy
(
p_sys
->
p_buffer
+
i_delay_size
*
p_sys
->
i_sample_bytes
,
p_buffer
,
i_size
);
p_buffer
-=
i_delay_size
*
p_sys
->
i_sample_bytes
;
i_samples
+=
i_samples_delay
;
i_samples_delay
=
0
;
p_samples
=
p_sys
->
p_buffer
;
}
else
{
p_samples
=
p_buffer
;
}
frame
=
avcodec_alloc_frame
();
i_out
=
avcodec_encode_audio
(
p_sys
->
p_context
,
p_block
->
p_buffer
,
p_block
->
i_buffer
,
p_samples
);
frame
->
nb_samples
=
p_aout_buf
->
i_nb_samples
;
avcodec_fill_audio_frame
(
frame
,
p_enc
->
fmt_in
.
audio
.
i_channels
,
p_sys
->
p_context
->
sample_fmt
,
p_aout_buf
->
p_buffer
,
p_aout_buf
->
i_buffer
,
0
);
#if 0
msg_Warn( p_enc, "avcodec_encode_audio: %d", i_out );
#endif
p_buffer
+=
p_sys
->
i_frame_size
*
p_sys
->
i_sample_bytes
;
p_sys
->
i_samples_delay
-=
p_sys
->
i_frame_size
;
i_samples
-=
p_sys
->
i_frame_size
;
if
(
i_out
<=
0
)
{
block_Release
(
p_block
);
continue
;
}
frame
->
pts
=
p_aout_buf
->
i_pts
;
p_block
->
i_buffer
=
i_out
;
p_block
=
block_New
(
p_enc
,
p_sys
->
i_buffer_out
);
av_init_packet
(
&
packet
);
packet
.
data
=
p_block
->
p_buffer
;
packet
.
size
=
p_block
->
i_buffer
;
p_block
->
i_length
=
(
mtime_t
)
1000000
*
(
mtime_t
)
p_sys
->
i_frame_size
/
(
mtime_t
)
p_sys
->
p_context
->
sample_rate
;
i_out
=
avcodec_encode_audio2
(
p_sys
->
p_context
,
&
packet
,
frame
,
&
got_packet
);
p_block
->
i_buffer
=
packet
.
size
;
avcodec_free_frame
(
&
frame
);
if
(
unlikely
(
!
got_packet
||
i_out
)
)
{
if
(
i_out
)
msg_Err
(
p_enc
,
"Encoding problem.."
);
block_Release
(
p_block
);
return
NULL
;
}
p_block
->
i_dts
=
p_block
->
i_pts
=
p_sys
->
i_pts
;
p_block
->
i_buffer
=
packet
.
size
;
/* Update pts */
p_sys
->
i_pts
+=
p_block
->
i_length
;
block_ChainAppend
(
&
p_chain
,
p_block
);
}
p_block
->
i_length
=
(
mtime_t
)
1000000
*
(
mtime_t
)
p_sys
->
i_frame_size
/
(
mtime_t
)
p_sys
->
p_context
->
sample_rate
;
/* Backup the remaining raw samples */
if
(
i_samples
)
{
memcpy
(
&
p_sys
->
p_buffer
[
i_samples_delay
*
p_sys
->
i_sample_bytes
],
p_buffer
,
i_samples
*
p_sys
->
i_sample_bytes
);
}
p_block
->
i_dts
=
p_block
->
i_pts
=
packet
.
pts
;
return
p_
chain
;
return
p_
block
;
}
/*****************************************************************************
...
...
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