Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
audiowmark
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stefan Westerfeld
audiowmark
Commits
ff5f8c27
Commit
ff5f8c27
authored
Jun 25, 2020
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
HLSOutputStream: more error handling
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
c2c7ad1d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
19 deletions
+20
-19
hlsoutputstream.cc
src/hlsoutputstream.cc
+19
-17
hlsoutputstream.hh
src/hlsoutputstream.hh
+1
-2
No files found.
src/hlsoutputstream.cc
View file @
ff5f8c27
...
...
@@ -235,7 +235,7 @@ HLSOutputStream::write_frame (const AVRational *time_base, AVStream *st, AVPacke
* return 1 when encoding is finished, 0 otherwise
*/
int
HLSOutputStream
::
write_audio_frame
(
)
HLSOutputStream
::
write_audio_frame
(
Error
&
err
)
{
AVPacket
pkt
=
{
0
};
// data and size must be 0;
AVFrame
*
frame
;
...
...
@@ -260,7 +260,10 @@ HLSOutputStream::write_audio_frame()
*/
ret
=
av_frame_make_writable
(
m_frame
);
if
(
ret
<
0
)
exit
(
1
);
{
err
=
Error
(
"error making frame writable"
);
return
1
;
}
/* convert to destination format */
ret
=
swr_convert
(
m_swr_ctx
,
...
...
@@ -268,8 +271,8 @@ HLSOutputStream::write_audio_frame()
(
const
uint8_t
**
)
frame
->
data
,
frame
->
nb_samples
);
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"Error while converting
\n
"
);
exit
(
1
)
;
err
=
Error
(
"error while converting
"
);
return
1
;
}
frame
=
m_frame
;
...
...
@@ -280,8 +283,8 @@ HLSOutputStream::write_audio_frame()
ret
=
avcodec_encode_audio2
(
m_enc
,
&
pkt
,
frame
,
&
got_packet
);
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"Error encoding audio frame: %s
\n
"
,
av_err2str
(
ret
));
exit
(
1
)
;
err
=
Error
(
string_printf
(
"error encoding audio frame: %s"
,
av_err2str
(
ret
)
));
return
1
;
}
if
(
got_packet
)
...
...
@@ -295,9 +298,8 @@ HLSOutputStream::write_audio_frame()
ret
=
write_frame
(
&
m_enc
->
time_base
,
m_st
,
&
pkt
);
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"Error while writing audio frame: %s
\n
"
,
av_err2str
(
ret
));
exit
(
1
);
err
=
Error
(
string_printf
(
"error while writing audio frame: %s"
,
av_err2str
(
ret
)));
return
1
;
}
m_keep_aac_frames
--
;
}
...
...
@@ -363,7 +365,10 @@ HLSOutputStream::open (const string& out_filename, size_t cut_aac_frames, size_t
Error
HLSOutputStream
::
close
()
{
write
();
// drain
Error
err
;
while
(
write_audio_frame
(
err
)
==
0
);
if
(
err
)
return
err
;
av_write_trailer
(
m_fmt_ctx
);
...
...
@@ -379,12 +384,6 @@ HLSOutputStream::close()
return
Error
::
Code
::
NONE
;
}
void
HLSOutputStream
::
write
()
{
while
(
write_audio_frame
()
==
0
);
}
Error
HLSOutputStream
::
write_frames
(
const
std
::
vector
<
float
>&
frames
)
{
...
...
@@ -401,9 +400,12 @@ HLSOutputStream::write_frames (const std::vector<float>& frames)
m_delete_input_start
-=
delete_input
;
}
Error
err
;
while
(
m_audio_buffer
.
can_read_frames
()
>=
1024
)
{
write_audio_frame
();
write_audio_frame
(
err
);
if
(
err
)
return
err
;
}
return
Error
::
Code
::
NONE
;
}
...
...
src/hlsoutputstream.hh
View file @
ff5f8c27
...
...
@@ -92,7 +92,7 @@ class HLSOutputStream : public AudioOutputStream {
Error
add_stream
(
AVCodec
**
codec
,
enum
AVCodecID
codec_id
);
Error
open_audio
(
AVCodec
*
codec
,
AVDictionary
*
opt_arg
);
AVFrame
*
get_audio_frame
();
int
write_audio_frame
(
);
int
write_audio_frame
(
Error
&
err
);
void
close_stream
();
AVFrame
*
alloc_audio_frame
(
AVSampleFormat
sample_fmt
,
uint64_t
channel_layout
,
int
sample_rate
,
int
nb_samples
,
Error
&
err
);
int
write_frame
(
const
AVRational
*
time_base
,
AVStream
*
st
,
AVPacket
*
pkt
);
...
...
@@ -104,7 +104,6 @@ public:
int
sample_rate
()
const
override
;
int
n_channels
()
const
override
;
Error
write_frames
(
const
std
::
vector
<
float
>&
frames
)
override
;
void
write
();
Error
close
();
};
...
...
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