mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-08 17:48:46 -10:00
This adds support for displaying subtitles embedded in movie files. This supports files with multiple subtitle streams where each stream contains the subtitles for one language. When the movie file is opened, the stream for the currently active language will be used and displayed. This resolves one of the points mentioned in #1522. This also depends on PR #1484.
87 lines
1.8 KiB
C++
87 lines
1.8 KiB
C++
#include "cutscene/Decoder.h"
|
|
|
|
#include <memory>
|
|
|
|
namespace cutscene {
|
|
Decoder::Decoder() : m_decoding(true) {
|
|
}
|
|
|
|
Decoder::~Decoder() {
|
|
}
|
|
|
|
bool Decoder::tryPopAudioData(AudioFramePtr& out) {
|
|
auto res = m_audioQueue->try_pull_front(out);
|
|
return res == queue_op_status::success;
|
|
}
|
|
|
|
bool Decoder::tryPopSubtitleData(SubtitleFramePtr& out) {
|
|
auto res = m_subtitleQueue->try_pull_front(out);
|
|
return res == queue_op_status::success;
|
|
}
|
|
|
|
bool Decoder::tryPopVideoFrame(VideoFramePtr& out) {
|
|
auto res = m_videoQueue->try_pull_front(out);
|
|
return res == queue_op_status::success;
|
|
}
|
|
|
|
void Decoder::initializeQueues(size_t queueSize) {
|
|
m_queueSize = queueSize;
|
|
|
|
m_videoQueue.reset(new sync_bounded_queue<VideoFramePtr>(m_queueSize));
|
|
m_audioQueue.reset(new sync_bounded_queue<AudioFramePtr>(m_queueSize));
|
|
m_subtitleQueue.reset(new sync_bounded_queue<SubtitleFramePtr>(m_queueSize));
|
|
}
|
|
|
|
void Decoder::stopDecoder() {
|
|
m_decoding = false;
|
|
|
|
m_videoQueue->close();
|
|
m_audioQueue->close();
|
|
m_subtitleQueue->close();
|
|
}
|
|
|
|
bool Decoder::canPushAudioData() {
|
|
return !isAudioQueueFull();
|
|
}
|
|
|
|
void Decoder::pushAudioData(AudioFramePtr&& data) {
|
|
Assertion(data, "Invalid audio data passed!");
|
|
|
|
try {
|
|
m_audioQueue->push_back(std::move(data));
|
|
}
|
|
catch (sync_queue_is_closed&) {
|
|
// Ignore
|
|
}
|
|
}
|
|
|
|
bool Decoder::canPushSubtitleData() {
|
|
return !isSubtitleQueueFull();
|
|
}
|
|
void Decoder::pushSubtitleData(SubtitleFramePtr&& data) {
|
|
Assertion(data, "Invalid audio data passed!");
|
|
|
|
try {
|
|
m_subtitleQueue->push_back(std::move(data));
|
|
}
|
|
catch (sync_queue_is_closed&) {
|
|
// Ignore
|
|
}
|
|
}
|
|
|
|
bool Decoder::canPushVideoData() {
|
|
return !isVideoQueueFull();
|
|
}
|
|
|
|
void Decoder::pushFrameData(VideoFramePtr&& frame) {
|
|
Assertion(frame, "Invalid video data passed!");
|
|
|
|
try {
|
|
m_videoQueue->push_back(std::move(frame));
|
|
}
|
|
catch (sync_queue_is_closed&) {
|
|
// Ignore
|
|
}
|
|
}
|
|
}
|