Commit 1f083c5a authored by Stefan Westerfeld's avatar Stefan Westerfeld

Move HLSOutputStream implementation to its own cc/hh file.

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent 16500f19
......@@ -5,7 +5,7 @@ COMMON_SRC = utils.hh utils.cc convcode.hh convcode.cc random.hh random.cc wavda
audiostream.cc audiostream.hh sfinputstream.cc sfinputstream.hh stdoutwavoutputstream.cc stdoutwavoutputstream.hh \
sfoutputstream.cc sfoutputstream.hh rawinputstream.cc rawinputstream.hh rawoutputstream.cc rawoutputstream.hh \
rawconverter.cc rawconverter.hh mp3inputstream.cc mp3inputstream.hh wmcommon.cc wmcommon.hh fft.cc fft.hh \
limiter.cc limiter.hh shortcode.cc shortcode.hh mpegts.cc mpegts.hh
limiter.cc limiter.hh shortcode.cc shortcode.hh mpegts.cc mpegts.hh hlsoutputstream.cc hlsoutputstream.hh
COMMON_LIBS = $(SNDFILE_LIBS) $(FFTW_LIBS) $(LIBGCRYPT_LIBS) $(LIBMPG123_LIBS) $(FFMPEG_LIBS)
audiowmark_SOURCES = audiowmark.cc wmget.cc wmadd.cc $(COMMON_SRC)
......
This diff is collapsed.
/*
* Copyright (C) 2018-2020 Stefan Westerfeld
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef AUDIOWMARK_HLS_OUTPUT_STREAM_HH
#define AUDIOWMARK_HLS_OUTPUT_STREAM_HH
#include "audiostream.hh"
#include <assert.h>
extern "C" {
#include <libavformat/avformat.h>
#include <libavutil/opt.h>
#include <libswresample/swresample.h>
#include <libavutil/avassert.h>
#include <libavutil/timestamp.h>
#undef av_err2str
#define av_err2str(errnum) av_make_error_string((char*)__builtin_alloca(AV_ERROR_MAX_STRING_SIZE), AV_ERROR_MAX_STRING_SIZE, errnum)
}
/* FIXME: fix duplication with wmadd.cc */
class AudioBuffer
{
const int n_channels = 0;
std::vector<float> buffer;
public:
AudioBuffer (int n_channels) :
n_channels (n_channels)
{
}
void
write_frames (const std::vector<float>& samples)
{
buffer.insert (buffer.end(), samples.begin(), samples.end());
}
std::vector<float>
read_frames (size_t frames)
{
assert (frames * n_channels <= buffer.size());
const auto begin = buffer.begin();
const auto end = begin + frames * n_channels;
std::vector<float> result (begin, end);
buffer.erase (begin, end);
return result;
}
size_t
can_read_frames() const
{
return buffer.size() / n_channels;
}
};
class HLSOutputStream : public AudioOutputStream {
AVStream *m_st = nullptr;
AVCodecContext *m_enc = nullptr;
AVFormatContext *m_fmt_ctx = nullptr;
/* pts of the next frame that will be generated */
int64_t m_next_pts = 0;
int m_samples_count = 0;
int m_start_pos = 0;
AVFrame *m_frame = nullptr;
AVFrame *m_tmp_frame = nullptr;
size_t m_cut_aac_frames = 0;
size_t m_keep_aac_frames = 0;
SwrContext *m_swr_ctx = nullptr;
int m_bit_depth = 0;
int m_sample_rate = 0;
int m_n_channels = 0;
AudioBuffer m_audio_buffer;
size_t m_delete_input_start = 0;
void add_stream (AVCodec **codec, enum AVCodecID codec_id);
void open_audio (AVCodec *codec, AVDictionary *opt_arg);
AVFrame *get_audio_frame();
int write_audio_frame();
void close_stream();
AVFrame *alloc_audio_frame(enum AVSampleFormat sample_fmt, uint64_t channel_layout, int sample_rate, int nb_samples);
int write_frame (const AVRational *time_base, AVStream *st, AVPacket *pkt);
public:
HLSOutputStream (int n_channels, int sample_rate, int bit_depth);
Error open (const std::string& output_filename, size_t cut_aac_frames, size_t keep_aac_frames, double pts_start, size_t delete_input_start);
int bit_depth() const override;
int sample_rate() const override;
int n_channels() const override;
Error write_frames (const std::vector<float>& frames) override;
void write();
Error close();
};
#endif /* AUDIOWMARK_HLS_OUTPUT_STREAM_HH */
This diff is collapsed.
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