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
a1a6f71b
Commit
a1a6f71b
authored
Jun 25, 2020
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
HLSOutputStream: handle add_stream() errors
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
245439e6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
27 deletions
+20
-27
hlsoutputstream.cc
src/hlsoutputstream.cc
+14
-26
hlsoutputstream.hh
src/hlsoutputstream.hh
+1
-1
testhls.cc
src/testhls.cc
+5
-0
No files found.
src/hlsoutputstream.cc
View file @
a1a6f71b
...
...
@@ -54,37 +54,26 @@ HLSOutputStream::HLSOutputStream (int n_channels, int sample_rate, int bit_depth
}
/* Add an output stream. */
void
Error
HLSOutputStream
::
add_stream
(
AVCodec
**
codec
,
enum
AVCodecID
codec_id
)
{
/* find the encoder */
*
codec
=
avcodec_find_encoder
(
codec_id
);
if
(
!
(
*
codec
))
{
fprintf
(
stderr
,
"Could not find encoder for '%s'
\n
"
,
avcodec_get_name
(
codec_id
));
exit
(
1
);
}
return
Error
(
string_printf
(
"could not find encoder for '%s'"
,
avcodec_get_name
(
codec_id
)));
m_st
=
avformat_new_stream
(
m_fmt_ctx
,
NULL
);
if
(
!
m_st
)
{
fprintf
(
stderr
,
"Could not allocate stream
\n
"
);
exit
(
1
);
}
return
Error
(
"could not allocate stream"
);
m_st
->
id
=
m_fmt_ctx
->
nb_streams
-
1
;
m_enc
=
avcodec_alloc_context3
(
*
codec
);
if
(
!
m_enc
)
{
fprintf
(
stderr
,
"Could not alloc an encoding context
\n
"
);
exit
(
1
);
}
return
Error
(
"could not alloc an encoding context"
);
if
((
*
codec
)
->
type
!=
AVMEDIA_TYPE_AUDIO
)
{
error
(
"HLSOutputStream: codec type must be audio"
);
exit
(
1
);
}
return
Error
(
"codec type must be audio"
);
m_enc
->
sample_fmt
=
(
*
codec
)
->
sample_fmts
?
(
*
codec
)
->
sample_fmts
[
0
]
:
AV_SAMPLE_FMT_FLTP
;
m_enc
->
bit_rate
=
128000
;
...
...
@@ -101,10 +90,7 @@ HLSOutputStream::add_stream (AVCodec **codec, enum AVCodecID codec_id)
}
}
if
(
!
match
)
{
error
(
"HLSOutputStream: unsupported sample rate %d
\n
"
,
m_sample_rate
);
exit
(
1
);
}
return
Error
(
string_printf
(
"no codec support for sample rate %d"
,
m_sample_rate
));
}
m_enc
->
channels
=
av_get_channel_layout_nb_channels
(
m_enc
->
channel_layout
);
m_enc
->
channel_layout
=
AV_CH_LAYOUT_STEREO
;
...
...
@@ -123,6 +109,8 @@ HLSOutputStream::add_stream (AVCodec **codec, enum AVCodecID codec_id)
/* Some formats want stream headers to be separate. */
if
(
m_fmt_ctx
->
oformat
->
flags
&
AVFMT_GLOBALHEADER
)
m_enc
->
flags
|=
AV_CODEC_FLAG_GLOBAL_HEADER
;
return
Error
::
Code
::
NONE
;
}
...
...
@@ -344,14 +332,14 @@ HLSOutputStream::open (const string& out_filename, size_t cut_aac_frames, size_t
int
ret
=
avio_open
(
&
m_fmt_ctx
->
pb
,
filename
.
c_str
(),
AVIO_FLAG_WRITE
);
if
(
ret
<
0
)
{
error
(
"Could not open output: %s
\n
"
,
av_err2str
(
ret
));
return
Error
(
"open hls output failed"
);
}
return
Error
(
av_err2str
(
ret
));
AVDictionary
*
opt
=
nullptr
;
AVCodec
*
audio_codec
;
add_stream
(
&
audio_codec
,
AV_CODEC_ID_AAC
);
Error
err
=
add_stream
(
&
audio_codec
,
AV_CODEC_ID_AAC
);
if
(
err
)
return
err
;
open_audio
(
audio_codec
,
opt
);
/* Write the stream header, if any. */
...
...
src/hlsoutputstream.hh
View file @
a1a6f71b
...
...
@@ -89,7 +89,7 @@ class HLSOutputStream : public AudioOutputStream {
AudioBuffer
m_audio_buffer
;
size_t
m_delete_input_start
=
0
;
void
add_stream
(
AVCodec
**
codec
,
enum
AVCodecID
codec_id
);
Error
add_stream
(
AVCodec
**
codec
,
enum
AVCodecID
codec_id
);
void
open_audio
(
AVCodec
*
codec
,
AVDictionary
*
opt_arg
);
AVFrame
*
get_audio_frame
();
int
write_audio_frame
();
...
...
src/testhls.cc
View file @
a1a6f71b
...
...
@@ -367,6 +367,11 @@ hls_mark (const string& infile, const string& outfile, const string& bits)
const
size_t
keep_aac_frames
=
size
/
1024
;
err
=
out_stream
.
open
(
outfile
,
cut_aac_frames
,
keep_aac_frames
,
pts_start
,
delete_input_start
);
if
(
err
)
{
error
(
"audiowmark: error opening HLS output stream %s: %s
\n
"
,
outfile
.
c_str
(),
err
.
message
());
return
1
;
}
int
zrc
=
add_stream_watermark
(
&
in_stream
,
&
out_stream
,
bits
,
start_pos
-
prev_size
);
if
(
zrc
!=
0
)
...
...
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