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
e57f6a06
Commit
e57f6a06
authored
Jun 23, 2020
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
testhls: really write aac audio from WavData
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
d2a6dcea
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
18 deletions
+21
-18
testhls.cc
src/testhls.cc
+21
-18
No files found.
src/testhls.cc
View file @
e57f6a06
...
...
@@ -109,7 +109,7 @@ ff_decode (const string& filename, WavData& out_wav_data)
*/
// a wrapper around a single output AVStream
typedef
struct
OutputStream
{
struct
OutputStream
{
AVStream
*
st
;
AVCodecContext
*
enc
;
...
...
@@ -120,11 +120,12 @@ typedef struct OutputStream {
AVFrame
*
frame
;
AVFrame
*
tmp_frame
;
float
t
,
tincr
,
tincr2
;
const
WavData
*
wav_data
=
nullptr
;
int64_t
t
;
struct
SwsContext
*
sws_ctx
;
struct
SwrContext
*
swr_ctx
;
}
OutputStream
;
};
/* Add an output stream. */
...
...
@@ -160,7 +161,7 @@ static void add_stream(OutputStream *ost, AVFormatContext *oc,
case
AVMEDIA_TYPE_AUDIO
:
c
->
sample_fmt
=
(
*
codec
)
->
sample_fmts
?
(
*
codec
)
->
sample_fmts
[
0
]
:
AV_SAMPLE_FMT_FLTP
;
c
->
bit_rate
=
64
000
;
c
->
bit_rate
=
128
000
;
c
->
sample_rate
=
44100
;
if
((
*
codec
)
->
supported_samplerates
)
{
c
->
sample_rate
=
(
*
codec
)
->
supported_samplerates
[
0
];
...
...
@@ -270,9 +271,6 @@ static void open_audio(AVFormatContext *oc, AVCodec *codec, OutputStream *ost, A
/* init signal generator */
ost
->
t
=
0
;
ost
->
tincr
=
2
*
M_PI
*
110.0
/
c
->
sample_rate
;
/* increment frequency by 110 Hz per second */
ost
->
tincr2
=
2
*
M_PI
*
110.0
/
c
->
sample_rate
/
c
->
sample_rate
;
if
(
c
->
codec
->
capabilities
&
AV_CODEC_CAP_VARIABLE_FRAME_SIZE
)
nb_samples
=
10000
;
...
...
@@ -313,8 +311,6 @@ static void open_audio(AVFormatContext *oc, AVCodec *codec, OutputStream *ost, A
}
}
#define STREAM_DURATION 0.1
/* Prepare a 16 bit dummy audio frame of 'frame_size' samples and
* 'nb_channels' channels. */
static
AVFrame
*
get_audio_frame
(
OutputStream
*
ost
)
...
...
@@ -324,17 +320,23 @@ static AVFrame *get_audio_frame(OutputStream *ost)
int16_t
*
q
=
(
int16_t
*
)
frame
->
data
[
0
];
/* check if we want to generate more frames */
if
(
av_compare_ts
(
ost
->
next_pts
,
ost
->
enc
->
time_base
,
STREAM_DURATION
,
(
AVRational
){
1
,
1
})
>
0
)
return
NULL
;
if
(
ost
->
t
>=
ost
->
wav_data
->
samples
().
size
())
return
NULL
;
for
(
j
=
0
;
j
<
frame
->
nb_samples
;
j
++
)
{
v
=
(
int
)(
sin
(
ost
->
t
)
*
10000
);
const
vector
<
float
>&
wd_samples
=
ost
->
wav_data
->
samples
();
for
(
j
=
0
;
j
<
frame
->
nb_samples
;
j
++
)
{
for
(
i
=
0
;
i
<
ost
->
enc
->
channels
;
i
++
)
*
q
++
=
v
;
ost
->
t
+=
ost
->
tincr
;
ost
->
tincr
+=
ost
->
tincr2
;
}
{
if
(
ost
->
t
<
wd_samples
.
size
())
{
*
q
++
=
(
int
)(
wd_samples
[
ost
->
t
]
*
32768
);
ost
->
t
++
;
}
else
*
q
++
=
0
;
}
}
frame
->
pts
=
ost
->
next_pts
;
ost
->
next_pts
+=
frame
->
nb_samples
;
...
...
@@ -458,6 +460,7 @@ ff_encode (const WavData& wav_data, const string& filename, size_t start_pos, si
}
OutputStream
audio_st
=
{
0
};
audio_st
.
wav_data
=
&
wav_data
;
AVCodec
*
audio_codec
;
AVOutputFormat
*
fmt
;
AVDictionary
*
opt
=
nullptr
;
...
...
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