mirror of
https://git.jami.net/savoirfairelinux/jami-daemon.git
synced 2025-08-12 22:09:25 +08:00
media: build MediaStream from AudioFormat
Keeps track of sample format in AudioFormat, because MediaStream needs a format. Change-Id: I3ee3fe05f3d5d98706a20132876685e37ffdd966 Reviewed-by: Hugo Lefeuvre <hugo.lefeuvre@savoirfairelinux.com>
This commit is contained in:

committed by
Philippe Gorley

parent
c49c89a666
commit
496fbbd618
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
|
Reference in New Issue
Block a user