Commit e57f6a06 authored by Stefan Westerfeld's avatar Stefan Westerfeld

testhls: really write aac audio from WavData

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent d2a6dcea
...@@ -109,7 +109,7 @@ ff_decode (const string& filename, WavData& out_wav_data) ...@@ -109,7 +109,7 @@ ff_decode (const string& filename, WavData& out_wav_data)
*/ */
// a wrapper around a single output AVStream // a wrapper around a single output AVStream
typedef struct OutputStream { struct OutputStream {
AVStream *st; AVStream *st;
AVCodecContext *enc; AVCodecContext *enc;
...@@ -120,11 +120,12 @@ typedef struct OutputStream { ...@@ -120,11 +120,12 @@ typedef struct OutputStream {
AVFrame *frame; AVFrame *frame;
AVFrame *tmp_frame; AVFrame *tmp_frame;
float t, tincr, tincr2; const WavData *wav_data = nullptr;
int64_t t;
struct SwsContext *sws_ctx; struct SwsContext *sws_ctx;
struct SwrContext *swr_ctx; struct SwrContext *swr_ctx;
} OutputStream; };
/* Add an output stream. */ /* Add an output stream. */
...@@ -160,7 +161,7 @@ static void add_stream(OutputStream *ost, AVFormatContext *oc, ...@@ -160,7 +161,7 @@ static void add_stream(OutputStream *ost, AVFormatContext *oc,
case AVMEDIA_TYPE_AUDIO: case AVMEDIA_TYPE_AUDIO:
c->sample_fmt = (*codec)->sample_fmts ? c->sample_fmt = (*codec)->sample_fmts ?
(*codec)->sample_fmts[0] : AV_SAMPLE_FMT_FLTP; (*codec)->sample_fmts[0] : AV_SAMPLE_FMT_FLTP;
c->bit_rate = 64000; c->bit_rate = 128000;
c->sample_rate = 44100; c->sample_rate = 44100;
if ((*codec)->supported_samplerates) { if ((*codec)->supported_samplerates) {
c->sample_rate = (*codec)->supported_samplerates[0]; c->sample_rate = (*codec)->supported_samplerates[0];
...@@ -270,9 +271,6 @@ static void open_audio(AVFormatContext *oc, AVCodec *codec, OutputStream *ost, A ...@@ -270,9 +271,6 @@ static void open_audio(AVFormatContext *oc, AVCodec *codec, OutputStream *ost, A
/* init signal generator */ /* init signal generator */
ost->t = 0; 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) if (c->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)
nb_samples = 10000; nb_samples = 10000;
...@@ -313,8 +311,6 @@ static void open_audio(AVFormatContext *oc, AVCodec *codec, OutputStream *ost, A ...@@ -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 /* Prepare a 16 bit dummy audio frame of 'frame_size' samples and
* 'nb_channels' channels. */ * 'nb_channels' channels. */
static AVFrame *get_audio_frame(OutputStream *ost) static AVFrame *get_audio_frame(OutputStream *ost)
...@@ -324,17 +320,23 @@ 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]; int16_t *q = (int16_t*)frame->data[0];
/* check if we want to generate more frames */ /* check if we want to generate more frames */
if (av_compare_ts(ost->next_pts, ost->enc->time_base, if (ost->t >= ost->wav_data->samples().size())
STREAM_DURATION, (AVRational){ 1, 1 }) > 0) return NULL;
return NULL;
for (j = 0; j <frame->nb_samples; j++) { const vector<float>& wd_samples = ost->wav_data->samples();
v = (int)(sin(ost->t) * 10000); for (j = 0; j < frame->nb_samples; j++)
{
for (i = 0; i < ost->enc->channels; i++) for (i = 0; i < ost->enc->channels; i++)
*q++ = v; {
ost->t += ost->tincr; if (ost->t < wd_samples.size())
ost->tincr += ost->tincr2; {
} *q++ = (int)(wd_samples[ost->t] * 32768);
ost->t++;
}
else
*q++ = 0;
}
}
frame->pts = ost->next_pts; frame->pts = ost->next_pts;
ost->next_pts += frame->nb_samples; ost->next_pts += frame->nb_samples;
...@@ -458,6 +460,7 @@ ff_encode (const WavData& wav_data, const string& filename, size_t start_pos, si ...@@ -458,6 +460,7 @@ ff_encode (const WavData& wav_data, const string& filename, size_t start_pos, si
} }
OutputStream audio_st = { 0 }; OutputStream audio_st = { 0 };
audio_st.wav_data = &wav_data;
AVCodec *audio_codec; AVCodec *audio_codec;
AVOutputFormat *fmt; AVOutputFormat *fmt;
AVDictionary *opt = nullptr; AVDictionary *opt = nullptr;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment