diff --git a/src/media/audio/audiobuffer.h b/src/media/audio/audiobuffer.h index aea0205f52ae8a4a7b419bc28cb374e3aa794ec8..b0ceb12f871b2be094642d9f729aa22b166e4957 100644 --- a/src/media/audio/audiobuffer.h +++ b/src/media/audio/audiobuffer.h @@ -30,6 +30,10 @@ #include <string> #include <cstddef> // for size_t +extern "C" { +#include <libavutil/samplefmt.h> +} + #include "ring_types.h" #include <ciso646> // fix windows compiler bug @@ -44,11 +48,18 @@ namespace ring { struct AudioFormat { unsigned sample_rate; unsigned nb_channels; + AVSampleFormat sampleFormat; - constexpr AudioFormat(unsigned sr, unsigned c) : sample_rate(sr), nb_channels(c) {} + constexpr AudioFormat(unsigned sr, unsigned c) + : sample_rate(sr) + , nb_channels(c) + , sampleFormat(AV_SAMPLE_FMT_S16) + {} inline bool operator == (const AudioFormat &b) const { - return ( (b.sample_rate == sample_rate) && (b.nb_channels == nb_channels) ); + return ( (b.sample_rate == sample_rate) && + (b.nb_channels == nb_channels) && + (b.sampleFormat == sampleFormat) ); } inline bool operator != (const AudioFormat &b) const { @@ -57,7 +68,8 @@ struct AudioFormat { inline std::string toString() const { std::stringstream ss; - ss << "{" << nb_channels << " channels, " << sample_rate << "Hz}"; + ss << "{" << av_get_sample_fmt_name(sampleFormat) << ", " + << nb_channels << " channels, " << sample_rate << "Hz}"; return ss.str(); } diff --git a/src/media/media_stream.h b/src/media/media_stream.h index 1475d8882bc77701f5baf1a048eb5a398454c6df..d5318692284f2c3c5a14d07e5a0a68076a6dd682 100644 --- a/src/media/media_stream.h +++ b/src/media/media_stream.h @@ -21,6 +21,7 @@ #pragma once #include "config.h" +#include "audio/audiobuffer.h" #include "libav_deps.h" #include "rational.h" @@ -65,6 +66,15 @@ struct MediaStream { , nbChannels(channels) {} + MediaStream(std::string name, AudioFormat fmt) + : name(name) + , format(fmt.sampleFormat) + , isVideo(false) + , timeBase(1, fmt.sample_rate) + , sampleRate(fmt.sample_rate) + , nbChannels(fmt.nb_channels) + {} + MediaStream(std::string name, AVCodecContext* c) : MediaStream(name, c, 0) {