forked from CasparCG/server
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit 7e2f134 Author: Julian Waller <[email protected]> Date: Fri Jan 5 16:36:53 2024 +0000 chore: format commit 91e9954 Author: Julian Waller <[email protected]> Date: Fri Jan 5 16:34:23 2024 +0000 wip: rework frame flow commit 0ce2bfd Author: Julian Waller <[email protected]> Date: Fri Jan 5 16:11:02 2024 +0000 wip: inspired by #16
- Loading branch information
1 parent
8aa7084
commit 0ce8c04
Showing
5 changed files
with
211 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "audio_resampler.h" | ||
#include "av_assert.h" | ||
|
||
extern "C" { | ||
#include <libavutil/samplefmt.h> | ||
#include <libswresample/swresample.h> | ||
} | ||
|
||
namespace caspar::ffmpeg { | ||
|
||
AudioResampler::AudioResampler(int64_t sample_rate, AVSampleFormat in_sample_fmt) | ||
: ctx(std::shared_ptr<SwrContext>(swr_alloc_set_opts(nullptr, | ||
AV_CH_LAYOUT_7POINT1, | ||
AV_SAMPLE_FMT_S32, | ||
sample_rate, | ||
AV_CH_LAYOUT_7POINT1, | ||
in_sample_fmt, | ||
sample_rate, | ||
0, | ||
nullptr), | ||
[](SwrContext* ptr) { swr_free(&ptr); })) | ||
{ | ||
if (!ctx) | ||
FF_RET(AVERROR(ENOMEM), "swr_alloc_set_opts"); | ||
|
||
FF_RET(swr_init(ctx.get()), "swr_init"); | ||
} | ||
|
||
caspar::array<int32_t> AudioResampler::convert(int frames, const void** src) | ||
{ | ||
auto result = caspar::array<int32_t>(frames * 8 * sizeof(int32_t)); | ||
auto ptr = result.data(); | ||
auto ret = swr_convert(ctx.get(), (uint8_t**)&ptr, frames, reinterpret_cast<const uint8_t**>(src), frames); | ||
|
||
return result; | ||
} | ||
|
||
}; // namespace caspar::ffmpeg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <common/array.h> | ||
#include <memory> | ||
|
||
#pragma once | ||
|
||
extern "C" { | ||
#include <libavutil/samplefmt.h> | ||
} | ||
|
||
struct SwrContext; | ||
|
||
namespace caspar::ffmpeg { | ||
|
||
class AudioResampler | ||
{ | ||
std::shared_ptr<SwrContext> ctx; | ||
|
||
public: | ||
AudioResampler(int64_t sample_rate, AVSampleFormat in_sample_fmt); | ||
|
||
AudioResampler(const AudioResampler&) = delete; | ||
AudioResampler& operator=(const AudioResampler&) = delete; | ||
|
||
caspar::array<int32_t> convert(int frames, const void** src); | ||
}; | ||
|
||
}; // namespace caspar::ffmpeg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters