Skip to content

Commit

Permalink
CI-Build 2022-08-19 v2
Browse files Browse the repository at this point in the history
  • Loading branch information
arch1t3cht committed Aug 19, 2022
2 parents 34d339c + 3b8cc6d commit b52d1d0
Show file tree
Hide file tree
Showing 16 changed files with 379 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
name: macOS Release,
os: macos-latest,
buildtype: release,
args: -Ddefault_library=static -Dbuild_osx_bundle=true -Dlocal_boost=true -Davisynth=enabled -Dvapoursynth=enabled
args: -Ddefault_library=static -Dbuild_osx_bundle=true -Dlocal_boost=true
}

steps:
Expand Down
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Being a collection of different feature additions, this repository consists of a
The `cibuilds` branch makes some CI builds of snapshots of `feature` at relevant points in time.

### Branch/Feature list
This list is for navigating the repository. Go to the [release page](https://github.com/arch1t3cht/Aegisub/releases) for a more structured changelog.
- [`folding`](https://github.com/arch1t3cht/Aegisub/tree/folding): Add the ability to visually group and collapse lines in the subtitle grid
- [`lua_api`](https://github.com/arch1t3cht/Aegisub/tree/lua_api): Add new functions to the Lua automation API, like controlling the selection or cursor in the text edit box
- [`vector_clip_actions`](https://github.com/arch1t3cht/Aegisub/tree/vector_clip_actions): Make the different modes of the vector clip tool (lines, bezier curves, adding points, etc) bindable to hotkeys
Expand All @@ -28,13 +29,20 @@ The `cibuilds` branch makes some CI builds of snapshots of `feature` at relevant
- [`vapoursynth`](https://github.com/arch1t3cht/Aegisub/tree/vapoursynth): Add Vapoursynth audio and video source
- [`bugfixes`](https://github.com/arch1t3cht/Aegisub/tree/bugfixes): Various fixes necessary for compilation. Most branches are based on this.
- [`fixes`](https://github.com/arch1t3cht/Aegisub/tree/fixes): Miscellaneous bugfixes
- [`misc`](https://github.com/arch1t3cht/Aegisub/tree/misc): Other miscellaneous additions
- [`misc_dc`](https://github.com/arch1t3cht/Aegisub/tree/misc_dc): Miscellaneous changes taken from AegisubDC
- [`xa-ds2`](https://github.com/arch1t3cht/Aegisub/tree/xa-ds2): Add XAudio2 backend and allow stereo playback for some other backends, by wangqr and Shinon.
- [`stereo`](https://github.com/arch1t3cht/Aegisub/tree/stereo): Add multi-channel support for the other audio backends where possible.
- [`video_panning_feature`](https://github.com/arch1t3cht/Aegisub/tree/video_panning_feature): Merge [moex3's video zoom and panning](https://github.com/TypesettingTools/Aegisub/pull/150), with an OSX fix and more options to control zoom behavior
- [`spectrum-frequency-mapping`](https://github.com/arch1t3cht/Aegisub/tree/spectrum-frequency-mapping): Merge EleonoreMizo's [spectrum display improvements](https://github.com/TypesettingTools/Aegisub/pull/94), and also make Shift+Scroll vertically zoom the audio display
- [`wangqr_time_video`](https://github.com/arch1t3cht/Aegisub/tree/wangqr_time_video): Merge wangqr's feature adding a tool for timing subtitles to changes in the video

### Troubleshooting
I'll gladly take any bug reports, but if you encounter an issue, please check first if it occurs only on my fork, or also on [earlier TSTools builds](https://github.com/TypesettingTools/Aegisub/actions).
If it wasn't introduced by my fork, I can still take a look, but I can't promise anything.

You can find me for support on various servers, including the cave and the TSTools server linked below.

#### Building fails with a "CMake sandbox violation"
This is an upstream bug in meson. For now, you need to downgrade meson using `pip install meson==0.62.2`.

Expand All @@ -55,6 +63,37 @@ If it's not because of this particular bug, you can also try an alternative vide
If you're compiling yourself, try adding `--force-fallback-for=zlib` to the meson options.


### Compilation
For compilation on Windows, see the TSTools documentation below. Also check the [GitHub workflow](https://github.com/arch1t3cht/Aegisub/blob/cibuilds/.github/workflows/ci.yml) for the project arguments.

On Linux, you can use the [TSTools PKGBUILD](https://aur.archlinux.org/packages/aegisub-ttools-meson-git) as a base, in particular for installing the necessary dependencies if you don't want to compile them yourself.
To compile manually,
- Install Meson (at the moment, you'll need to downgrade Meson below 0.63.0: `pip install meson==0.62.2`)
- Clone the repository
- In the repository, run `meson setup build` for the default configuration. See below for further options.
- `cd` to the `build` directory and run `ninja`
- You'll get an `aegisub` binary in the `build` folder. To install it to a system-wide location, run `ninja install`. To install to `/usr` instead of `/usr/local`, pass `--prefix=/usr` when configuring or reconfiguring meson.
- When recompiling after pulling new commits, skip the `meson setup` setup and just immediately run `ninja` from the build directory - even when the build configuration changed.

#### Compilation flags
Some features are not enabled by default. To enable them, pass `-D<feature>=enabled` with the `meson setup` command:

- `-Davisynth=enabled`: Avisynth support
- `-Dbestsource=enabled`: BestSource
- `-Dvapoursynth=enabled`: Vapoursynth support

You can also disable options that are active by default in the same way. Check the file `meson_options.txt` for all options.

To change the options of an existing build directory, run `meson setup --reconfigure <new arguments>` from inside the `build` directory.

### Dependencies
Apart from the dependencies for the TSTools version, there are some additional dependencies. These are cloned and compiled from scratch if not found, but you might want to install binaries instead:
- `jansson`: For BestSource
- `ffmpeg`: Becomes a direct dependency when compiling with BestSource
- `avisynth` (or `avisynthplus`): Optional run-time dependency for the Avisynth source
- `vapoursynth`: Optional run-time dependency for the VapourSynth source


# Aegisub

For binaries and general information [see the homepage](http://www.aegisub.org).
Expand Down
43 changes: 42 additions & 1 deletion libaegisub/audio/provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,47 @@ void AudioProvider::FillBufferInt16Mono(int16_t* buf, int64_t start, int64_t cou
free(buff);
}

// This entire file has turned into a mess. For now I'm just following the pattern of the wangqr code, but
// this should really be restructured entirely again. The original type constructor-based system worked very well - it could
// just give downmix/conversion control to the players instead.
void AudioProvider::GetAudioWithVolume(void *buf, int64_t start, int64_t count, double volume) const {
GetAudio(buf, start, count);
if (volume == 1.0) return;

int64_t n = count * GetChannels();

if (float_samples) {
if (bytes_per_sample == sizeof(float)) {
float *buff = reinterpret_cast<float *>(buf);
for (int64_t i = 0; i < n; ++i)
buff[i] = static_cast<float>(buff[i] * volume);
} else if (bytes_per_sample == sizeof(double)) {
double *buff = reinterpret_cast<double *>(buf);
for (int64_t i = 0; i < n; ++i)
buff[i] = buff[i] * volume;
}
}
else {
if (bytes_per_sample == sizeof(uint8_t)) {
uint8_t *buff = reinterpret_cast<uint8_t *>(buf);
for (int64_t i = 0; i < n; ++i)
buff[i] = util::mid(0, static_cast<int>(((int) buff[i] - 128) * volume + 128), 0xFF);
} else if (bytes_per_sample == sizeof(int16_t)) {
int16_t *buff = reinterpret_cast<int16_t *>(buf);
for (int64_t i = 0; i < n; ++i)
buff[i] = util::mid(-0x8000, static_cast<int>(buff[i] * volume), 0x7FFF);
} else if (bytes_per_sample == sizeof(int32_t)) {
int32_t *buff = reinterpret_cast<int32_t *>(buf);
for (int64_t i = 0; i < n; ++i)
buff[i] = static_cast<int32_t>(buff[i] * volume);
} else if (bytes_per_sample == sizeof(int64_t)) {
int64_t *buff = reinterpret_cast<int64_t *>(buf);
for (int64_t i = 0; i < n; ++i)
buff[i] = static_cast<int64_t>(buff[i] * volume);
}
}
}

void AudioProvider::GetInt16MonoAudioWithVolume(int16_t *buf, int64_t start, int64_t count, double volume) const {
GetInt16MonoAudio(buf, start, count);
if (volume == 1.0) return;
Expand Down Expand Up @@ -261,4 +302,4 @@ void SaveAudioClip(AudioProvider const& provider, fs::path const& path, int star
out.write(buf);
}
}
}
}
1 change: 1 addition & 0 deletions libaegisub/include/libaegisub/audio/provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class AudioProvider {
virtual ~AudioProvider() = default;

void GetAudio(void *buf, int64_t start, int64_t count) const;
void GetAudioWithVolume(void *buf, int64_t start, int64_t count, double volume) const;
void GetInt16MonoAudio(int16_t* buf, int64_t start, int64_t count) const;
void GetInt16MonoAudioWithVolume(int16_t *buf, int64_t start, int64_t count, double volume) const;

Expand Down
55 changes: 55 additions & 0 deletions src/async_video_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@

#include <libaegisub/dispatch.h>

#if BOOST_VERSION >= 106900
#include <boost/gil.hpp>
#else
#include <boost/gil/gil_all.hpp>
#endif

enum {
NEW_SUBS_FILE = -1,
SUBS_FILE_ALREADY_LOADED = -2
Expand Down Expand Up @@ -81,6 +87,55 @@ std::shared_ptr<VideoFrame> AsyncVideoProvider::ProcFrame(int frame_number, doub
return frame;
}

VideoFrame AsyncVideoProvider::GetBlankFrame(bool white) {
VideoFrame result;
result.width = GetWidth();
result.height = GetHeight();
result.pitch = result.width * 4;
result.flipped = false;
result.data.resize(result.pitch * result.height, white ? 255 : 0);
return result;
}

VideoFrame AsyncVideoProvider::GetSubtitles(double time) {
// We want to combine all transparent subtitle layers onto one layer.
// Instead of alpha blending them all together, which can be messy and cause
// rounding errors, we draw them once on a black frame and once on a white frame,
// and solve for the color and alpha. This has the benefit of being independent
// of the subtitle provider, as long as the provider works by alpha blending.
VideoFrame frame_black = GetBlankFrame(false);
if (!subs) return frame_black;
VideoFrame frame_white = GetBlankFrame(true);

subs_provider->LoadSubtitles(subs.get());
subs_provider->DrawSubtitles(frame_black, time / 1000.);
subs_provider->DrawSubtitles(frame_white, time / 1000.);

using namespace boost::gil;
auto blackview = interleaved_view(frame_black.width, frame_black.height, (bgra8_pixel_t*) frame_black.data.data(), frame_black.width * 4);
auto whiteview = interleaved_view(frame_white.width, frame_white.height, (bgra8_pixel_t*) frame_white.data.data(), frame_white.width * 4);

transform_pixels(blackview, whiteview, blackview, [=](const bgra8_pixel_t black, const bgra8_pixel_t white) -> bgra8_pixel_t {
int a = 255 - (white[0] - black[0]);

bgra8_pixel_t ret;
if (a == 0) {
ret[0] = 0;
ret[1] = 0;
ret[2] = 0;
ret[3] = 0;
} else {
ret[0] = black[0] / (a / 255.);
ret[1] = black[1] / (a / 255.);
ret[2] = black[2] / (a / 255.);
ret[3] = a;
}
return ret;
});

return frame_black;
}

static std::unique_ptr<SubtitlesProvider> get_subs_provider(wxEvtHandler *evt_handler, agi::BackgroundRunner *br) {
try {
return SubtitlesProviderFactory::GetProvider(br);
Expand Down
12 changes: 12 additions & 0 deletions src/async_video_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ class AsyncVideoProvider {

std::vector<std::shared_ptr<VideoFrame>> buffers;

// Returns a monochromatic frame with the current dimensions
VideoFrame GetBlankFrame(bool white);

public:
/// @brief Load the passed subtitle file
/// @param subs File to load
Expand Down Expand Up @@ -108,6 +111,15 @@ class AsyncVideoProvider {
/// @brief raw Get raw frame without subtitles
std::shared_ptr<VideoFrame> GetFrame(int frame, double time, bool raw = false);

/// @brief Synchronously get the subtitles with transparent background
/// @brief time Exact start time of the frame in seconds
///
/// This function is not used for drawing the subtitles on the screen and is not
/// guaranteed that drawing the resulting image on the current raw frame exactly
/// results in the current rendered frame with subtitles. This function is for
/// purposes like copying the current subtitles to the clipboard.
VideoFrame GetSubtitles(double time);

/// Ask the video provider to change YCbCr matricies
void SetColorSpace(std::string const& matrix);

Expand Down
67 changes: 47 additions & 20 deletions src/audio_player_alsa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class AlsaPlayer final : public AudioPlayer {
std::atomic<double> volume{1.0};
int64_t start_position = 0;
std::atomic<int64_t> end_position{0};
bool fallback_mono16 = false; // whether to convert to 16 bit mono. FIXME: more flexible conversion

std::mutex position_mutex;
int64_t last_position = 0;
Expand All @@ -88,6 +89,8 @@ class AlsaPlayer final : public AudioPlayer {

std::thread thread;

snd_pcm_format_t GetPCMFormat(const agi::AudioProvider *provider);

void PlaybackThread();

void UpdatePlaybackPosition(snd_pcm_t *pcm, int64_t position)
Expand Down Expand Up @@ -115,6 +118,36 @@ class AlsaPlayer final : public AudioPlayer {
void SetEndPosition(int64_t pos) override;
};

snd_pcm_format_t AlsaPlayer::GetPCMFormat(const agi::AudioProvider *provider) {
if (provider->AreSamplesFloat()) {
switch (provider->GetBytesPerSample()) {
case 4:
return SND_PCM_FORMAT_FLOAT_LE;
case 8:
return SND_PCM_FORMAT_FLOAT64_LE;
default:
fallback_mono16 = true;
return SND_PCM_FORMAT_S16_LE;
}
} else {
switch (provider->GetBytesPerSample()) {
case 1:
return SND_PCM_FORMAT_U8;
case 2:
return SND_PCM_FORMAT_S16_LE;
case 3:
return SND_PCM_FORMAT_S24_LE;
case 4:
return SND_PCM_FORMAT_S32_LE;
case 8:
return SND_PCM_FORMAT_S32_LE;
default:
fallback_mono16 = true;
return SND_PCM_FORMAT_S16_LE;
}
}
}

void AlsaPlayer::PlaybackThread()
{
std::unique_lock<std::mutex> lock(mutex);
Expand All @@ -126,33 +159,19 @@ void AlsaPlayer::PlaybackThread()
BOOST_SCOPE_EXIT_ALL(&) { snd_pcm_close(pcm); };

do_setup:
snd_pcm_format_t pcm_format;
switch (/*provider->GetBytesPerSample()*/ sizeof(int16_t))
{
case 1:
LOG_D("audio/player/alsa") << "format U8";
pcm_format = SND_PCM_FORMAT_U8;
break;
case 2:
LOG_D("audio/player/alsa") << "format S16_LE";
pcm_format = SND_PCM_FORMAT_S16_LE;
break;
default:
return;
}
snd_pcm_format_t pcm_format = GetPCMFormat(provider);
if (snd_pcm_set_params(pcm,
pcm_format,
SND_PCM_ACCESS_RW_INTERLEAVED,
/*provider->GetChannels()*/ 1,
fallback_mono16 ? 1 : provider->GetChannels(),
provider->GetSampleRate(),
1, // allow resample
100*1000 // 100 milliseconds latency
) != 0)
return;
LOG_D("audio/player/alsa") << "set pcm params";

//size_t framesize = provider->GetChannels() * provider->GetBytesPerSample();
size_t framesize = sizeof(int16_t);
size_t framesize = fallback_mono16 ? sizeof(int16_t) : provider->GetChannels() * provider->GetBytesPerSample();

while (true)
{
Expand All @@ -176,7 +195,11 @@ void AlsaPlayer::PlaybackThread()
{
auto avail = std::min(snd_pcm_avail(pcm), (snd_pcm_sframes_t)(end_position-position));
decode_buffer.resize(avail * framesize);
provider->GetInt16MonoAudioWithVolume(reinterpret_cast<int16_t*>(decode_buffer.data()), position, avail, volume);
if (fallback_mono16) {
provider->GetInt16MonoAudioWithVolume(reinterpret_cast<int16_t*>(decode_buffer.data()), position, avail, volume);
} else {
provider->GetAudioWithVolume(decode_buffer.data(), position, avail, volume);
}

snd_pcm_sframes_t written = 0;
while (written <= 0)
Expand Down Expand Up @@ -236,7 +259,11 @@ void AlsaPlayer::PlaybackThread()

{
decode_buffer.resize(avail * framesize);
provider->GetInt16MonoAudioWithVolume(reinterpret_cast<int16_t*>(decode_buffer.data()), position, avail, volume);
if (fallback_mono16) {
provider->GetInt16MonoAudioWithVolume(reinterpret_cast<int16_t*>(decode_buffer.data()), position, avail, volume);
} else {
provider->GetAudioWithVolume(decode_buffer.data(), position, avail, volume);
}
snd_pcm_sframes_t written = 0;
while (written <= 0)
{
Expand Down Expand Up @@ -353,4 +380,4 @@ std::unique_ptr<AudioPlayer> CreateAlsaPlayer(agi::AudioProvider *provider, wxWi
return agi::make_unique<AlsaPlayer>(provider);
}

#endif // WITH_ALSA
#endif // WITH_ALSA
Loading

0 comments on commit b52d1d0

Please sign in to comment.