File: captions-handler.cpp

package info (click to toggle)
obs-studio 22.0.3%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 23,052 kB
  • sloc: ansic: 134,708; cpp: 49,169; objc: 1,036; makefile: 829; sh: 410; python: 360
file content (54 lines) | stat: -rw-r--r-- 1,159 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "captions-handler.hpp"

captions_handler::captions_handler(
		captions_cb       callback,
		enum audio_format format,
		uint32_t          sample_rate)
	: cb(callback)
{
	if (!reset_resampler(format, sample_rate))
		throw CAPTIONS_ERROR_GENERIC_FAIL;
}

bool captions_handler::reset_resampler(
		enum audio_format format,
		uint32_t sample_rate)
try {
	obs_audio_info ai;
	if (!obs_get_audio_info(&ai))
		throw std::string("Failed to get OBS audio info");

	resample_info src = {
		ai.samples_per_sec,
		AUDIO_FORMAT_FLOAT_PLANAR,
		ai.speakers
	};
	resample_info dst = {
		sample_rate,
		format,
		SPEAKERS_MONO
	};

	if (!resampler.reset(dst, src))
		throw std::string("Failed to create audio resampler");

	return true;

} catch (std::string text) {
	blog(LOG_WARNING, "%s: %s", __FUNCTION__, text.c_str());
	return false;
}

void captions_handler::push_audio(const audio_data *audio)
{
	uint8_t *out[MAX_AV_PLANES];
	uint32_t frames;
	uint64_t ts_offset;
	bool success;

	success = audio_resampler_resample(resampler,
			out, &frames, &ts_offset,
			(const uint8_t *const *)audio->data, audio->frames);
	if (success)
		pcm_data(out[0], frames);
}