Skip to content
Snippets Groups Projects
Commit 496fbbd6 authored by Philippe Gorley's avatar Philippe Gorley Committed by Philippe Gorley
Browse files

media: build MediaStream from AudioFormat


Keeps track of sample format in AudioFormat, because MediaStream needs a
format.

Change-Id: I3ee3fe05f3d5d98706a20132876685e37ffdd966
Reviewed-by: default avatarHugo Lefeuvre <hugo.lefeuvre@savoirfairelinux.com>
parent c49c89a6
No related branches found
No related tags found
No related merge requests found
...@@ -30,6 +30,10 @@ ...@@ -30,6 +30,10 @@
#include <string> #include <string>
#include <cstddef> // for size_t #include <cstddef> // for size_t
extern "C" {
#include <libavutil/samplefmt.h>
}
#include "ring_types.h" #include "ring_types.h"
#include <ciso646> // fix windows compiler bug #include <ciso646> // fix windows compiler bug
...@@ -44,11 +48,18 @@ namespace ring { ...@@ -44,11 +48,18 @@ namespace ring {
struct AudioFormat { struct AudioFormat {
unsigned sample_rate; unsigned sample_rate;
unsigned nb_channels; 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 { 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 { inline bool operator != (const AudioFormat &b) const {
...@@ -57,7 +68,8 @@ struct AudioFormat { ...@@ -57,7 +68,8 @@ struct AudioFormat {
inline std::string toString() const { inline std::string toString() const {
std::stringstream ss; 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(); return ss.str();
} }
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#pragma once #pragma once
#include "config.h" #include "config.h"
#include "audio/audiobuffer.h"
#include "libav_deps.h" #include "libav_deps.h"
#include "rational.h" #include "rational.h"
...@@ -65,6 +66,15 @@ struct MediaStream { ...@@ -65,6 +66,15 @@ struct MediaStream {
, nbChannels(channels) , 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(std::string name, AVCodecContext* c)
: MediaStream(name, c, 0) : MediaStream(name, c, 0)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment