feat: stream YouTube video with coordinated audio and video inputs
Resolve public YouTube URLs through external yt-dlp and play selected streams in the existing native window. Independent bounded network readers keep one authored timeline. Successful seeks clear FFmpeg's sticky aborted-read AVIO error; manifest seekability uses native format flags rather than a top-level I/O handle. Verified real YouTube playback, seeking, frame stepping, compact mode, cancellation, and the complete native regression checks.
This commit is contained in:
+471
-144
@@ -26,8 +26,11 @@ extern "C" {
|
||||
#include <mutex>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <thread>
|
||||
#include <arpa/inet.h>
|
||||
#include <vector>
|
||||
#include "network_input.hpp"
|
||||
|
||||
namespace {
|
||||
constexpr int sampleRate = 48000;
|
||||
@@ -53,11 +56,18 @@ struct VideoFrame {
|
||||
struct Track {
|
||||
AVCodecContext *codec = nullptr;
|
||||
int index = -1;
|
||||
AVFormatContext *format = nullptr;
|
||||
playback::NetworkInput *input = nullptr;
|
||||
AVPacket *packet = nullptr;
|
||||
bool packetPending = false;
|
||||
bool receiving = false;
|
||||
bool sourceEnded = false;
|
||||
bool drainSent = false;
|
||||
bool drained = false;
|
||||
double nextPts = 0;
|
||||
int64_t countedTimestamp = AV_NOPTS_VALUE;
|
||||
uint64_t timestampOccurrence = 0;
|
||||
AVStream *stream() const { return format->streams[index]; }
|
||||
};
|
||||
enum class Action { Open, Play, Pause, Seek, Step, Close };
|
||||
struct Command {
|
||||
@@ -67,6 +77,12 @@ struct Command {
|
||||
int direction = 0;
|
||||
uint64_t epoch = 0;
|
||||
uint64_t repetitions = 1;
|
||||
std::string audioURL{};
|
||||
std::string videoHeaders{};
|
||||
std::string audioHeaders{};
|
||||
double sourceDuration = 0;
|
||||
bool network = false;
|
||||
bool live = false;
|
||||
};
|
||||
|
||||
void copyError(char *destination, const char *message) noexcept {
|
||||
@@ -77,6 +93,75 @@ int64_t presentationTimestamp(const AVFrame *frame) {
|
||||
return frame->best_effort_timestamp != AV_NOPTS_VALUE ?
|
||||
frame->best_effort_timestamp : frame->pts;
|
||||
}
|
||||
|
||||
bool validNetworkURL(const char *text) {
|
||||
if (!text) return false;
|
||||
const std::string_view url(text);
|
||||
if (url.size() > 65536) return false;
|
||||
const std::size_t start = url.starts_with("https://") ? 8 : url.starts_with("http://") ? 7 : 0;
|
||||
if (!start) return false;
|
||||
for (unsigned char value : url)
|
||||
if (value <= 32 || value == 127 || value == '\\') return false;
|
||||
const auto authority = url.substr(start, url.find_first_of("/?#", start) - start);
|
||||
if (authority.empty() || authority.find('@') != std::string_view::npos) return false;
|
||||
auto host = authority;
|
||||
std::string_view port;
|
||||
if (host.front() == '[') {
|
||||
const auto end = host.find(']');
|
||||
if (end == std::string_view::npos || end == 1) return false;
|
||||
if (end + 1 < host.size()) {
|
||||
if (host[end + 1] != ':') return false;
|
||||
port = host.substr(end + 2);
|
||||
if (port.empty()) return false;
|
||||
}
|
||||
host = host.substr(1, end - 1);
|
||||
std::array<char, INET6_ADDRSTRLEN> address{};
|
||||
if (host.size() >= address.size()) return false;
|
||||
std::memcpy(address.data(), host.data(), host.size());
|
||||
in6_addr parsed{};
|
||||
if (inet_pton(AF_INET6, address.data(), &parsed) != 1) return false;
|
||||
} else {
|
||||
const auto colon = host.find(':');
|
||||
if (colon != std::string_view::npos) {
|
||||
port = host.substr(colon + 1);
|
||||
host = host.substr(0, colon);
|
||||
if (port.empty()) return false;
|
||||
}
|
||||
if (host.empty()) return false;
|
||||
for (unsigned char value : host)
|
||||
if (!((value >= 'a' && value <= 'z') || (value >= 'A' && value <= 'Z') ||
|
||||
(value >= '0' && value <= '9') || value == '.' || value == '-')) return false;
|
||||
}
|
||||
unsigned number = 0;
|
||||
for (unsigned char value : port) {
|
||||
if (value < '0' || value > '9') return false;
|
||||
number = number * 10 + value - '0';
|
||||
if (number > 65535) return false;
|
||||
}
|
||||
return port.empty() || number > 0;
|
||||
}
|
||||
|
||||
bool validHeaders(const char *text) {
|
||||
if (!text) return true;
|
||||
const std::string_view headers(text);
|
||||
if (headers.size() > 65536) return false;
|
||||
std::size_t offset = 0;
|
||||
while (offset < headers.size()) {
|
||||
const auto end = headers.find("\r\n", offset);
|
||||
if (end == std::string_view::npos) return false;
|
||||
const auto line = headers.substr(offset, end - offset);
|
||||
const auto colon = line.find(':');
|
||||
if (colon == std::string_view::npos || colon == 0) return false;
|
||||
for (unsigned char value : line.substr(0, colon))
|
||||
if (!((value >= 'a' && value <= 'z') || (value >= 'A' && value <= 'Z') ||
|
||||
(value >= '0' && value <= '9') ||
|
||||
std::string_view("!#$%&'*+-.^_`|~").find(value) != std::string_view::npos)) return false;
|
||||
for (unsigned char value : line.substr(colon + 1))
|
||||
if (value < 32 || value == 127) return false;
|
||||
offset = end + 2;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
struct Player {
|
||||
@@ -93,8 +178,12 @@ struct Player {
|
||||
std::atomic<uint64_t> requestedEpoch{0};
|
||||
uint64_t activeEpoch = 0;
|
||||
|
||||
// Everything below, including FFmpeg and Output audio operations, is worker-owned.
|
||||
// Decoders, timeline and output are worker-owned; network readers exclusively own demux I/O.
|
||||
AVFormatContext *format = nullptr;
|
||||
std::array<std::unique_ptr<playback::NetworkInput>, 2> inputs;
|
||||
bool network = false;
|
||||
bool canSeek = false;
|
||||
bool buffering = false;
|
||||
std::array<Track, 2> tracks;
|
||||
AVPacket *packet = nullptr;
|
||||
AVFrame *decoded = nullptr;
|
||||
@@ -105,7 +194,7 @@ struct Player {
|
||||
bool resamplerDrained = false;
|
||||
bool packetPending = false;
|
||||
bool demuxEnded = false;
|
||||
int receiving = -1;
|
||||
int nextDecodeSlot = 0;
|
||||
std::deque<VideoFrame> video;
|
||||
std::size_t videoBytes = 0;
|
||||
VideoFrame presented{};
|
||||
@@ -144,9 +233,10 @@ struct Player {
|
||||
bool enqueue(Command command) {
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
if (stopping.load(std::memory_order_relaxed)) return false;
|
||||
if (command.action == Action::Step &&
|
||||
(!state.has_video || publishedEpoch != requestedEpoch.load(std::memory_order_relaxed) ||
|
||||
(state.status != PLAYER_PAUSED && state.status != PLAYER_PLAYING && state.status != PLAYER_ENDED)))
|
||||
const bool ready = publishedEpoch == requestedEpoch.load(std::memory_order_relaxed) &&
|
||||
(state.status == PLAYER_PAUSED || state.status == PLAYER_PLAYING || state.status == PLAYER_ENDED);
|
||||
if (command.action == Action::Seek && ready && !state.can_seek) return false;
|
||||
if (command.action == Action::Step && (!ready || !state.has_video || !state.can_seek))
|
||||
return false;
|
||||
const bool newTimeline = command.action == Action::Open || command.action == Action::Close;
|
||||
command.epoch = requestedEpoch.load(std::memory_order_relaxed) + (newTimeline ? 1 : 0);
|
||||
@@ -182,9 +272,11 @@ struct Player {
|
||||
copyError(requestedError.data(), message);
|
||||
errorRequested = true;
|
||||
errorEpoch = requestedEpoch.fetch_add(1, std::memory_order_relaxed) + 1;
|
||||
const auto revision = state.revision + 1;
|
||||
state = {};
|
||||
state.status = PLAYER_ERROR;
|
||||
copyError(state.error, message);
|
||||
++state.revision;
|
||||
state.revision = revision;
|
||||
wake.notify_one();
|
||||
} catch (...) {
|
||||
// No exception may cross the C boundary, including a failed mutex operation.
|
||||
@@ -215,14 +307,18 @@ struct Player {
|
||||
state.duration = duration;
|
||||
state.has_audio = tracks[0].codec != nullptr;
|
||||
state.has_video = tracks[1].codec != nullptr;
|
||||
state.can_seek = canSeek;
|
||||
state.buffering = buffering;
|
||||
// Commands remain pending while executing; publication acknowledges only completed work.
|
||||
state.seek_pending = std::any_of(commands.begin(), commands.end(), [this](const Command &command) {
|
||||
return (command.action == Action::Seek || command.action == Action::Step) &&
|
||||
command.epoch == activeEpoch;
|
||||
});
|
||||
state.seek_pending = networkSeeksPending() ||
|
||||
std::any_of(commands.begin(), commands.end(), [this](const Command &command) {
|
||||
return (command.action == Action::Seek || command.action == Action::Step) &&
|
||||
command.epoch == activeEpoch;
|
||||
});
|
||||
state.video_aspect_ratio = 0;
|
||||
if (const auto *video = tracks[1].codec; video && video->width > 0 && video->height > 0) {
|
||||
const auto aspect = av_guess_sample_aspect_ratio(format, format->streams[tracks[1].index], nullptr);
|
||||
const auto &track = tracks[1];
|
||||
const auto aspect = av_guess_sample_aspect_ratio(track.format, track.stream(), nullptr);
|
||||
state.video_aspect_ratio = double(video->width) / video->height *
|
||||
(aspect.num > 0 && aspect.den > 0 ? av_q2d(aspect) : 1);
|
||||
}
|
||||
@@ -232,6 +328,7 @@ struct Player {
|
||||
|
||||
void release() {
|
||||
output.pause();
|
||||
for (auto &input : inputs) if (input) input->stop();
|
||||
output.reset();
|
||||
video.clear();
|
||||
videoBytes = 0;
|
||||
@@ -243,16 +340,20 @@ struct Player {
|
||||
av_channel_layout_uninit(&inputLayout);
|
||||
for (auto &track : tracks) {
|
||||
avcodec_free_context(&track.codec);
|
||||
av_packet_free(&track.packet);
|
||||
track = {};
|
||||
}
|
||||
av_packet_free(&packet);
|
||||
av_frame_free(&decoded);
|
||||
avformat_close_input(&format);
|
||||
if (!network) avformat_close_input(&format);
|
||||
for (auto &input : inputs) input.reset();
|
||||
format = nullptr;
|
||||
network = canSeek = buffering = false;
|
||||
inputRate = 0;
|
||||
inputFormat = AV_SAMPLE_FMT_NONE;
|
||||
pcmFrames = pcmOffset = 0;
|
||||
packetPending = demuxEnded = resamplerDrained = false;
|
||||
receiving = -1;
|
||||
nextDecodeSlot = 0;
|
||||
origin = duration = position = seekTarget = audioWriteEnd = videoEnd = resampleNextPts = 0;
|
||||
previewShown = false;
|
||||
error.fill(0);
|
||||
@@ -269,18 +370,23 @@ struct Player {
|
||||
publish();
|
||||
}
|
||||
|
||||
void openTrack(int slot, AVMediaType type, int related) {
|
||||
void openTrack(int slot, AVFormatContext *source, playback::NetworkInput *input,
|
||||
AVMediaType type, int related) {
|
||||
const AVCodec *decoder = nullptr;
|
||||
int index = av_find_best_stream(format, type, -1, related, &decoder, 0);
|
||||
int index = av_find_best_stream(source, type, -1, related, &decoder, 0);
|
||||
if (index == AVERROR_STREAM_NOT_FOUND) return;
|
||||
check(index, type == AVMEDIA_TYPE_AUDIO ? "Finding audio decoder" : "Finding video decoder");
|
||||
auto &track = tracks[slot];
|
||||
track.index = index;
|
||||
track.format = source;
|
||||
track.input = input;
|
||||
track.packet = av_packet_alloc();
|
||||
if (!track.packet) throw std::bad_alloc();
|
||||
track.codec = avcodec_alloc_context3(decoder);
|
||||
if (!track.codec) throw std::bad_alloc();
|
||||
check(avcodec_parameters_to_context(track.codec, format->streams[index]->codecpar),
|
||||
check(avcodec_parameters_to_context(track.codec, source->streams[index]->codecpar),
|
||||
"Reading codec parameters");
|
||||
track.codec->pkt_timebase = format->streams[index]->time_base;
|
||||
track.codec->pkt_timebase = source->streams[index]->time_base;
|
||||
// A bounded software decoder pool; FFmpeg owns its internal frame reorder buffer.
|
||||
track.codec->thread_count = 2;
|
||||
check(avcodec_open2(track.codec, decoder, nullptr), "Opening decoder");
|
||||
@@ -293,9 +399,11 @@ struct Player {
|
||||
if (!track.codec) continue;
|
||||
avcodec_flush_buffers(track.codec);
|
||||
track.drainSent = track.drained = false;
|
||||
av_packet_unref(track.packet);
|
||||
track.packetPending = track.receiving = track.sourceEnded = false;
|
||||
track.countedTimestamp = AV_NOPTS_VALUE;
|
||||
track.timestampOccurrence = 0;
|
||||
const AVStream *stream = format->streams[track.index];
|
||||
const AVStream *stream = track.stream();
|
||||
track.nextPts = stream->start_time == AV_NOPTS_VALUE ? target :
|
||||
std::max(target, stream->start_time * av_q2d(stream->time_base) - origin);
|
||||
}
|
||||
@@ -303,7 +411,7 @@ struct Player {
|
||||
av_channel_layout_uninit(&inputLayout);
|
||||
inputRate = 0;
|
||||
inputFormat = AV_SAMPLE_FMT_NONE;
|
||||
av_packet_unref(packet);
|
||||
if (packet) av_packet_unref(packet);
|
||||
av_frame_unref(decoded);
|
||||
video.clear();
|
||||
videoBytes = 0;
|
||||
@@ -313,69 +421,130 @@ struct Player {
|
||||
steppingAnchor = AV_NOPTS_VALUE;
|
||||
pcmFrames = pcmOffset = 0;
|
||||
packetPending = demuxEnded = resamplerDrained = false;
|
||||
receiving = -1;
|
||||
nextDecodeSlot = 0;
|
||||
position = seekTarget = audioWriteEnd = videoEnd = resampleNextPts = target;
|
||||
previewShown = false;
|
||||
steadyPosition = target;
|
||||
steadyAnchor = Clock::now();
|
||||
}
|
||||
|
||||
void open(const std::string &path) {
|
||||
playback::NetworkInput *openNetworkInput(int slot, const std::string &url, const std::string &headers) {
|
||||
inputs[slot] = std::make_unique<playback::NetworkInput>(stopping, requestedEpoch, activeEpoch, wake);
|
||||
auto &input = *inputs[slot];
|
||||
input.format = avformat_alloc_context();
|
||||
if (!input.format) throw std::bad_alloc();
|
||||
input.format->interrupt_callback = {playback::NetworkInput::interrupt, &input};
|
||||
AVDictionary *options = nullptr;
|
||||
int result = av_dict_set(&options, "protocol_whitelist", "http,https,tcp,tls,crypto", 0);
|
||||
if (result >= 0) result = av_dict_set(&options, "rw_timeout", "15000000", 0);
|
||||
if (result >= 0 && !headers.empty()) result = av_dict_set(&options, "headers", headers.c_str(), 0);
|
||||
if (result < 0) {
|
||||
av_dict_free(&options);
|
||||
check(result, "Configuring network input");
|
||||
}
|
||||
input.armIO();
|
||||
result = avformat_open_input(&input.format, url.c_str(), nullptr, &options);
|
||||
av_dict_free(&options);
|
||||
check(result, "Opening network media");
|
||||
input.armIO();
|
||||
check(avformat_find_stream_info(input.format, nullptr), "Reading network media information");
|
||||
return &input;
|
||||
}
|
||||
|
||||
bool networkSeeksPending() const {
|
||||
for (const auto &input : inputs)
|
||||
if (input && input->seekPending()) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void open(const Command &command) {
|
||||
release();
|
||||
network = command.network;
|
||||
status = PLAYER_OPENING;
|
||||
publish();
|
||||
std::error_code filesystemError;
|
||||
if (!std::filesystem::is_regular_file(path, filesystemError))
|
||||
throw std::runtime_error(filesystemError ? filesystemError.message() :
|
||||
"Open requires a local regular media file");
|
||||
const std::string localPath = std::filesystem::absolute(path).string();
|
||||
format = avformat_alloc_context();
|
||||
if (!format) throw std::bad_alloc();
|
||||
format->interrupt_callback = {interrupt, this};
|
||||
AVDictionary *options = nullptr;
|
||||
const int optionResult = av_dict_set(&options, "protocol_whitelist", "file", 0);
|
||||
if (optionResult < 0) {
|
||||
av_dict_free(&options);
|
||||
check(optionResult, "Restricting input to local files");
|
||||
}
|
||||
const int result = avformat_open_input(&format, localPath.c_str(), nullptr, &options);
|
||||
av_dict_free(&options);
|
||||
check(result, "Opening media");
|
||||
check(avformat_find_stream_info(format, nullptr), "Reading media information");
|
||||
openTrack(1, AVMEDIA_TYPE_VIDEO, -1);
|
||||
openTrack(0, AVMEDIA_TYPE_AUDIO, tracks[1].index);
|
||||
if (!tracks[0].codec && !tracks[1].codec)
|
||||
throw std::runtime_error("The file contains no playable audio or video track");
|
||||
for (unsigned i = 0; i < format->nb_streams; ++i) {
|
||||
if (static_cast<int>(i) != tracks[0].index && static_cast<int>(i) != tracks[1].index)
|
||||
format->streams[i]->discard = AVDISCARD_ALL;
|
||||
}
|
||||
if (format->start_time != AV_NOPTS_VALUE) {
|
||||
origin = static_cast<double>(format->start_time) / AV_TIME_BASE;
|
||||
} else {
|
||||
double first = std::numeric_limits<double>::infinity();
|
||||
for (const auto &track : tracks) {
|
||||
if (!track.codec) continue;
|
||||
const AVStream *stream = format->streams[track.index];
|
||||
if (stream->start_time != AV_NOPTS_VALUE)
|
||||
first = std::min(first, stream->start_time * av_q2d(stream->time_base));
|
||||
if (network) {
|
||||
auto *primary = openNetworkInput(0, command.path, command.videoHeaders);
|
||||
format = primary->format;
|
||||
openTrack(1, format, primary, AVMEDIA_TYPE_VIDEO, -1);
|
||||
if (command.audioURL.empty()) {
|
||||
openTrack(0, format, primary, AVMEDIA_TYPE_AUDIO, tracks[1].index);
|
||||
} else {
|
||||
if (!tracks[1].codec)
|
||||
throw std::runtime_error("The selected video stream contains no playable video");
|
||||
auto *audio = openNetworkInput(1, command.audioURL, command.audioHeaders);
|
||||
openTrack(0, audio->format, audio, AVMEDIA_TYPE_AUDIO, -1);
|
||||
if (!tracks[0].codec)
|
||||
throw std::runtime_error("The selected audio stream contains no playable audio");
|
||||
}
|
||||
origin = std::isfinite(first) ? first : 0;
|
||||
} else {
|
||||
std::error_code filesystemError;
|
||||
if (!std::filesystem::is_regular_file(command.path, filesystemError))
|
||||
throw std::runtime_error(filesystemError ? filesystemError.message() :
|
||||
"Open requires a local regular media file");
|
||||
const std::string localPath = std::filesystem::absolute(command.path).string();
|
||||
format = avformat_alloc_context();
|
||||
if (!format) throw std::bad_alloc();
|
||||
format->interrupt_callback = {interrupt, this};
|
||||
AVDictionary *options = nullptr;
|
||||
const int optionResult = av_dict_set(&options, "protocol_whitelist", "file", 0);
|
||||
if (optionResult < 0) {
|
||||
av_dict_free(&options);
|
||||
check(optionResult, "Restricting input to local files");
|
||||
}
|
||||
const int result = avformat_open_input(&format, localPath.c_str(), nullptr, &options);
|
||||
av_dict_free(&options);
|
||||
check(result, "Opening media");
|
||||
check(avformat_find_stream_info(format, nullptr), "Reading media information");
|
||||
openTrack(1, format, nullptr, AVMEDIA_TYPE_VIDEO, -1);
|
||||
openTrack(0, format, nullptr, AVMEDIA_TYPE_AUDIO, tracks[1].index);
|
||||
}
|
||||
if (format->duration != AV_NOPTS_VALUE && format->duration > 0)
|
||||
duration = static_cast<double>(format->duration) / AV_TIME_BASE;
|
||||
if (duration == 0) {
|
||||
if (!tracks[0].codec && !tracks[1].codec)
|
||||
throw std::runtime_error("The source contains no playable audio or video track");
|
||||
double first = std::numeric_limits<double>::infinity();
|
||||
double measuredDuration = 0;
|
||||
bool seekable = true;
|
||||
for (int source = 0; source < (inputs[1] ? 2 : 1); ++source) {
|
||||
auto *context = network ? inputs[source]->format : format;
|
||||
std::array<int, 2> indices{-1, -1};
|
||||
for (int slot = 0; slot < 2; ++slot)
|
||||
if (tracks[slot].codec && tracks[slot].format == context) indices[slot] = tracks[slot].index;
|
||||
for (unsigned i = 0; i < context->nb_streams; ++i)
|
||||
if (static_cast<int>(i) != indices[0] && static_cast<int>(i) != indices[1])
|
||||
context->streams[i]->discard = AVDISCARD_ALL;
|
||||
if (context->start_time != AV_NOPTS_VALUE) {
|
||||
first = std::min(first, static_cast<double>(context->start_time) / AV_TIME_BASE);
|
||||
} else {
|
||||
for (const auto &track : tracks) {
|
||||
if (!track.codec || track.format != context) continue;
|
||||
const auto *stream = track.stream();
|
||||
if (stream->start_time != AV_NOPTS_VALUE)
|
||||
first = std::min(first, stream->start_time * av_q2d(stream->time_base));
|
||||
}
|
||||
}
|
||||
if (context->duration != AV_NOPTS_VALUE && context->duration > 0)
|
||||
measuredDuration = std::max(measuredDuration, static_cast<double>(context->duration) / AV_TIME_BASE);
|
||||
// Manifest demuxers own their I/O; a nil top-level AVIOContext does not forbid time seeks.
|
||||
seekable = seekable && !(context->ctx_flags & AVFMTCTX_UNSEEKABLE) &&
|
||||
(context->pb ? (context->pb->seekable & AVIO_SEEKABLE_NORMAL) != 0 :
|
||||
(context->iformat->flags & AVFMT_NOFILE) != 0);
|
||||
}
|
||||
// One origin for both inputs: independently zeroing them would erase real A/V offsets.
|
||||
origin = std::isfinite(first) ? first : 0;
|
||||
duration = network && command.sourceDuration > 0 ? command.sourceDuration : measuredDuration;
|
||||
if (duration == 0 && !command.live) {
|
||||
for (const auto &track : tracks) {
|
||||
if (!track.codec) continue;
|
||||
const AVStream *stream = format->streams[track.index];
|
||||
const AVStream *stream = track.stream();
|
||||
if (stream->duration == AV_NOPTS_VALUE || stream->duration <= 0) continue;
|
||||
const double start = stream->start_time == AV_NOPTS_VALUE ? origin :
|
||||
stream->start_time * av_q2d(stream->time_base);
|
||||
duration = std::max(duration, start - origin + stream->duration * av_q2d(stream->time_base));
|
||||
}
|
||||
}
|
||||
canSeek = !command.live && duration > 0 && seekable;
|
||||
if (tracks[1].codec) {
|
||||
const AVRational rate = av_guess_frame_rate(format, format->streams[tracks[1].index], nullptr);
|
||||
const auto &track = tracks[1];
|
||||
const AVRational rate = av_guess_frame_rate(track.format, track.stream(), nullptr);
|
||||
videoFrameTime = rate.num > 0 && rate.den > 0 ? av_q2d(av_inv_q(rate)) : 1.0 / 25;
|
||||
}
|
||||
if (tracks[0].codec) {
|
||||
@@ -383,16 +552,25 @@ struct Player {
|
||||
if (!output.configure_audio(deviceError))
|
||||
throw std::runtime_error(deviceError.empty() ? "Cannot configure audio output" : deviceError);
|
||||
}
|
||||
packet = av_packet_alloc();
|
||||
if (!network) packet = av_packet_alloc();
|
||||
decoded = av_frame_alloc();
|
||||
if (!packet || !decoded) throw std::bad_alloc();
|
||||
if ((!network && !packet) || !decoded) throw std::bad_alloc();
|
||||
resetTimeline(0);
|
||||
if (network) {
|
||||
for (auto &input : inputs) {
|
||||
if (!input) continue;
|
||||
std::array<int, 2> indices{-1, -1};
|
||||
for (int slot = 0; slot < 2; ++slot)
|
||||
if (tracks[slot].input == input.get()) indices[slot] = tracks[slot].index;
|
||||
input->start(indices);
|
||||
}
|
||||
}
|
||||
status = PLAYER_PAUSED;
|
||||
publish();
|
||||
}
|
||||
|
||||
double clockPosition() const {
|
||||
if (status != PLAYER_PLAYING) return position;
|
||||
if (status != PLAYER_PLAYING || buffering) return position;
|
||||
if (tracks[0].codec) {
|
||||
const double audioClock = output.clock();
|
||||
return std::isfinite(audioClock) ? std::max(seekTarget, audioClock) : position;
|
||||
@@ -402,9 +580,13 @@ struct Player {
|
||||
|
||||
void start() {
|
||||
if (!format || status == PLAYER_ERROR || status == PLAYER_EMPTY) return;
|
||||
if (status == PLAYER_ENDED) seek(0, false);
|
||||
if (status == PLAYER_ENDED) {
|
||||
if (!canSeek) return;
|
||||
seek(0, false);
|
||||
}
|
||||
if (status == PLAYER_PLAYING) return;
|
||||
if (frameStepping) {
|
||||
for (auto &input : inputs) if (input) input->discardAudio(false);
|
||||
VideoFrame selected = std::move(presented);
|
||||
const int64_t timestamp = presentationTimestamp(selected.frame.get());
|
||||
const uint64_t occurrence = selected.timestampOccurrence;
|
||||
@@ -416,7 +598,7 @@ struct Player {
|
||||
skipPresentedTimestamp = timestamp;
|
||||
skipPresentedOccurrence = occurrence;
|
||||
}
|
||||
if (tracks[0].codec) {
|
||||
if (!network && tracks[0].codec) {
|
||||
std::string deviceError;
|
||||
if (!output.start(deviceError))
|
||||
throw std::runtime_error(deviceError.empty() ? "Cannot start audio output" : deviceError);
|
||||
@@ -424,6 +606,7 @@ struct Player {
|
||||
steadyPosition = position;
|
||||
steadyAnchor = Clock::now();
|
||||
status = PLAYER_PLAYING;
|
||||
buffering = network;
|
||||
}
|
||||
|
||||
void pause() {
|
||||
@@ -435,29 +618,85 @@ struct Player {
|
||||
if (std::isfinite(frozen)) position = std::max(seekTarget, frozen);
|
||||
}
|
||||
status = PLAYER_PAUSED;
|
||||
buffering = false;
|
||||
}
|
||||
|
||||
double audioEnd() const {
|
||||
const auto &track = tracks[0];
|
||||
if (!track.codec) return NAN;
|
||||
const auto *stream = track.stream();
|
||||
if (stream->duration != AV_NOPTS_VALUE && stream->duration > 0) {
|
||||
const double start = stream->start_time == AV_NOPTS_VALUE ? origin :
|
||||
stream->start_time * av_q2d(stream->time_base);
|
||||
return start - origin + stream->duration * av_q2d(stream->time_base);
|
||||
}
|
||||
const auto *context = track.format;
|
||||
if (context->duration == AV_NOPTS_VALUE || context->duration <= 0) return NAN;
|
||||
const double start = context->start_time == AV_NOPTS_VALUE ? origin :
|
||||
static_cast<double>(context->start_time) / AV_TIME_BASE;
|
||||
return start - origin + static_cast<double>(context->duration) / AV_TIME_BASE;
|
||||
}
|
||||
|
||||
bool beyondAudio(double target) const {
|
||||
const double end = audioEnd();
|
||||
return std::isfinite(end) && target + sampleTime * 0.5 >= end;
|
||||
}
|
||||
|
||||
void markAudioTail(double target) {
|
||||
if (!network || !beyondAudio(target)) return;
|
||||
tracks[0].sourceEnded = true;
|
||||
if (tracks[0].input == tracks[1].input && tracks[0].input)
|
||||
tracks[0].input->discardAudio(true);
|
||||
}
|
||||
|
||||
void seek(double seconds, bool resume) {
|
||||
if (!format) return;
|
||||
if (!format || !canSeek) return;
|
||||
const double target = duration > 0 ? std::clamp(seconds, 0.0, duration) : std::max(0.0, seconds);
|
||||
const long double absolute = std::round((static_cast<long double>(target) + origin) * AV_TIME_BASE);
|
||||
if (absolute < -0x1p63L || absolute >= 0x1p63L)
|
||||
throw std::runtime_error("Seek target is outside the supported timestamp range");
|
||||
output.pause();
|
||||
const int64_t timestamp = static_cast<int64_t>(absolute);
|
||||
check(avformat_seek_file(format, -1, std::numeric_limits<int64_t>::min(),
|
||||
timestamp, timestamp, 0), "Seeking media");
|
||||
if (network) {
|
||||
for (auto &input : inputs) {
|
||||
if (!input) continue;
|
||||
input->discardAudio(false);
|
||||
if (input.get() == tracks[0].input && input.get() != tracks[1].input && beyondAudio(target))
|
||||
input->finish();
|
||||
else
|
||||
input->seek(-1, timestamp);
|
||||
}
|
||||
} else {
|
||||
check(avformat_seek_file(format, -1, std::numeric_limits<int64_t>::min(),
|
||||
timestamp, timestamp, 0), "Seeking media");
|
||||
}
|
||||
resetTimeline(target);
|
||||
markAudioTail(target);
|
||||
buffering = network;
|
||||
status = PLAYER_PAUSED;
|
||||
if (resume) start();
|
||||
}
|
||||
|
||||
void seekVideo(int64_t timestamp, double target) {
|
||||
output.pause();
|
||||
check(av_seek_frame(format, tracks[1].index, timestamp, AVSEEK_FLAG_BACKWARD),
|
||||
"Seeking video keyframe");
|
||||
if (network) {
|
||||
auto &videoTrack = tracks[1];
|
||||
videoTrack.input->seek(videoTrack.index, timestamp);
|
||||
if (tracks[0].input && tracks[0].input != videoTrack.input) {
|
||||
const long double audioTime = std::round((static_cast<long double>(target) + origin) * AV_TIME_BASE);
|
||||
if (audioTime < -0x1p63L || audioTime >= 0x1p63L)
|
||||
throw std::runtime_error("Audio seek target is outside the supported timestamp range");
|
||||
if (beyondAudio(target)) tracks[0].input->finish();
|
||||
else tracks[0].input->seek(-1, static_cast<int64_t>(audioTime));
|
||||
}
|
||||
} else {
|
||||
check(av_seek_frame(format, tracks[1].index, timestamp, AVSEEK_FLAG_BACKWARD),
|
||||
"Seeking video keyframe");
|
||||
}
|
||||
// Decoder preroll must not blank the last presented frame between steps.
|
||||
resetTimeline(target, false);
|
||||
markAudioTail(target);
|
||||
buffering = network;
|
||||
status = PLAYER_PAUSED;
|
||||
}
|
||||
|
||||
@@ -483,9 +722,11 @@ struct Player {
|
||||
}
|
||||
|
||||
void step(int direction) {
|
||||
if (!format || !tracks[1].codec) return;
|
||||
if (!format || !canSeek || !tracks[1].codec) return;
|
||||
pause();
|
||||
status = PLAYER_PAUSED;
|
||||
// Combined inputs must not block video stepping behind an unused audio packet queue.
|
||||
if (network && tracks[1].input) tracks[1].input->discardAudio(true);
|
||||
// A seek followed immediately by a queued step must first establish its preview.
|
||||
while (!presented.frame) {
|
||||
auto frame = nextSteppingFrame();
|
||||
@@ -505,7 +746,7 @@ struct Player {
|
||||
const uint64_t referenceOccurrence = selected.timestampOccurrence;
|
||||
if (reference == AV_NOPTS_VALUE)
|
||||
throw std::runtime_error("Frame stepping requires video presentation timestamps");
|
||||
const AVStream *stream = format->streams[tracks[1].index];
|
||||
const AVStream *stream = tracks[1].stream();
|
||||
const long double ticksPerSecond = 1.0L / av_q2d(stream->time_base);
|
||||
const long double originTimestamp = std::clamp(std::floor(origin * ticksPerSecond),
|
||||
static_cast<long double>(std::numeric_limits<int64_t>::min() + 1),
|
||||
@@ -559,6 +800,7 @@ struct Player {
|
||||
position = selected.pts;
|
||||
steppingAnchor = target;
|
||||
frameStepping = true;
|
||||
buffering = false;
|
||||
presentVideo(std::move(selected));
|
||||
}
|
||||
|
||||
@@ -566,7 +808,7 @@ struct Player {
|
||||
if (command.epoch != requestedEpoch.load(std::memory_order_relaxed)) return;
|
||||
activeEpoch = command.epoch;
|
||||
switch (command.action) {
|
||||
case Action::Open: open(command.path); break;
|
||||
case Action::Open: open(command); break;
|
||||
case Action::Play: start(); break;
|
||||
case Action::Pause: pause(); break;
|
||||
case Action::Seek: seek(command.seconds, status == PLAYER_PLAYING); break;
|
||||
@@ -578,8 +820,11 @@ struct Player {
|
||||
|
||||
double framePts(Track &track, const AVFrame *frame) {
|
||||
const int64_t timestamp = presentationTimestamp(frame);
|
||||
if (timestamp == AV_NOPTS_VALUE) return track.nextPts;
|
||||
return timestamp * av_q2d(format->streams[track.index]->time_base) - origin;
|
||||
if (timestamp == AV_NOPTS_VALUE) {
|
||||
if (network) throw std::runtime_error("The network stream has no media presentation timestamps");
|
||||
return track.nextPts;
|
||||
}
|
||||
return timestamp * av_q2d(track.stream()->time_base) - origin;
|
||||
}
|
||||
|
||||
void convertAudio() {
|
||||
@@ -604,7 +849,7 @@ struct Player {
|
||||
throw std::runtime_error("Audio format changes within a track are not supported");
|
||||
}
|
||||
const double timestamp = framePts(track, decoded);
|
||||
const double tick = av_q2d(format->streams[track.index]->time_base);
|
||||
const double tick = av_q2d(track.stream()->time_base);
|
||||
const bool contiguous = continuing && std::abs(timestamp - track.nextPts) <= tick + 1.0 / rate;
|
||||
// Quantized packet PTS and rounded resampler delay must not insert/drop PCM samples.
|
||||
const int64_t delayBase = static_cast<int64_t>(rate) * sampleRate;
|
||||
@@ -701,7 +946,7 @@ struct Player {
|
||||
throw std::runtime_error("Frame stepping requires video presentation timestamps");
|
||||
const double pts = framePts(track, decoded);
|
||||
const double frameDuration = decoded->duration > 0 ?
|
||||
decoded->duration * av_q2d(format->streams[track.index]->time_base) : videoFrameTime;
|
||||
decoded->duration * av_q2d(track.stream()->time_base) : videoFrameTime;
|
||||
track.nextPts = pts + frameDuration;
|
||||
if (decoded->flags & AV_FRAME_FLAG_DISCARD) return;
|
||||
if (timestamp != track.countedTimestamp) {
|
||||
@@ -725,8 +970,9 @@ struct Player {
|
||||
if (bytes > videoByteLimit)
|
||||
throw std::runtime_error("A decoded video frame exceeds the 128 MiB buffer limit");
|
||||
videoEnd = std::max(videoEnd, pts + frameDuration);
|
||||
// ponytail: extreme interleaving can starve audio behind a full video queue.
|
||||
// Keep nearest frames plus the newest; packet spooling is the upgrade if that matters.
|
||||
if (network && videoBytes + bytes > videoByteLimit)
|
||||
throw std::runtime_error("Decoded video exceeds the 128 MiB buffer limit");
|
||||
// Local, extremely interleaved files retain nearest frames when audio needs to catch up.
|
||||
while (!video.empty() && (video.size() >= videoFrameLimit || videoBytes + bytes > videoByteLimit)) {
|
||||
videoBytes -= video.back().bytes;
|
||||
video.pop_back();
|
||||
@@ -741,72 +987,86 @@ struct Player {
|
||||
}
|
||||
|
||||
bool decodeOne(bool stepping = false) {
|
||||
if (!stepping && pcmOffset < pcmFrames) return false;
|
||||
if (receiving >= 0) {
|
||||
if (stepping && receiving == 0) {
|
||||
receiving = -1;
|
||||
return true;
|
||||
}
|
||||
auto &track = tracks[receiving];
|
||||
if (receiving == 1 && videoFull() &&
|
||||
(!tracks[0].codec || output.queued() >= 1024 || status != PLAYER_PLAYING))
|
||||
return false;
|
||||
const int result = avcodec_receive_frame(track.codec, decoded);
|
||||
if (result == AVERROR(EAGAIN)) {
|
||||
receiving = -1;
|
||||
return true;
|
||||
}
|
||||
if (result == AVERROR_EOF) {
|
||||
track.drained = true;
|
||||
receiving = -1;
|
||||
return true;
|
||||
}
|
||||
check(result, "Decoding media");
|
||||
if (receiving == 0) convertAudio(); else queueVideo(stepping);
|
||||
av_frame_unref(decoded);
|
||||
return true;
|
||||
}
|
||||
if (packetPending) {
|
||||
if (stepping && packet->stream_index == tracks[0].index) {
|
||||
av_packet_unref(packet);
|
||||
packetPending = false;
|
||||
return true;
|
||||
}
|
||||
const int slot = packet->stream_index == tracks[0].index ? 0 : 1;
|
||||
const int result = avcodec_send_packet(tracks[slot].codec, packet);
|
||||
if (result == AVERROR(EAGAIN)) {
|
||||
receiving = slot;
|
||||
return true;
|
||||
}
|
||||
check(result, "Sending media packet to decoder");
|
||||
av_packet_unref(packet);
|
||||
packetPending = false;
|
||||
receiving = slot;
|
||||
return true;
|
||||
}
|
||||
if (demuxEnded) {
|
||||
for (int slot = 0; slot < 2; ++slot) {
|
||||
auto &track = tracks[slot];
|
||||
if (!track.codec || track.drainSent || (stepping && slot == 0)) continue;
|
||||
const int result = avcodec_send_packet(track.codec, nullptr);
|
||||
for (const auto &input : inputs)
|
||||
if (input) check(input->error(), "Reading network media");
|
||||
for (int offset = 0; offset < 2; ++offset) {
|
||||
const int slot = (nextDecodeSlot + offset) % 2;
|
||||
auto &track = tracks[slot];
|
||||
if (!track.codec || track.drained || (stepping && slot == 0)) continue;
|
||||
if (slot == 0 && pcmOffset < pcmFrames) continue;
|
||||
if (slot == 1 && videoFull() &&
|
||||
(network || !tracks[0].codec || output.queued() >= 1024 || status != PLAYER_PLAYING)) continue;
|
||||
if (track.receiving) {
|
||||
const int result = avcodec_receive_frame(track.codec, decoded);
|
||||
if (result == AVERROR(EAGAIN)) {
|
||||
receiving = slot;
|
||||
track.receiving = false;
|
||||
} else if (result == AVERROR_EOF) {
|
||||
track.drained = true;
|
||||
track.receiving = false;
|
||||
} else {
|
||||
check(result, "Decoding media");
|
||||
if (slot == 0) convertAudio(); else queueVideo(stepping);
|
||||
av_frame_unref(decoded);
|
||||
}
|
||||
nextDecodeSlot = 1 - slot;
|
||||
return true;
|
||||
}
|
||||
if (track.packetPending) {
|
||||
const int result = avcodec_send_packet(track.codec, track.packet);
|
||||
if (result != AVERROR(EAGAIN)) {
|
||||
check(result, "Sending media packet to decoder");
|
||||
av_packet_unref(track.packet);
|
||||
track.packetPending = false;
|
||||
}
|
||||
track.receiving = true;
|
||||
nextDecodeSlot = 1 - slot;
|
||||
return true;
|
||||
}
|
||||
if (track.input && !track.sourceEnded) {
|
||||
const int result = track.input->take(slot, track.packet);
|
||||
if (result == AVERROR_EOF) track.sourceEnded = true;
|
||||
else if (result == 1) track.packetPending = true;
|
||||
else check(result, "Reading network media packet");
|
||||
if (result != 0) {
|
||||
nextDecodeSlot = 1 - slot;
|
||||
return true;
|
||||
}
|
||||
if (result != AVERROR_EOF) check(result, "Draining decoder");
|
||||
track.drainSent = true;
|
||||
receiving = slot;
|
||||
}
|
||||
if (track.sourceEnded && !track.drainSent) {
|
||||
const int result = avcodec_send_packet(track.codec, nullptr);
|
||||
if (result != AVERROR(EAGAIN)) {
|
||||
if (result != AVERROR_EOF) check(result, "Draining decoder");
|
||||
track.drainSent = true;
|
||||
}
|
||||
track.receiving = true;
|
||||
nextDecodeSlot = 1 - slot;
|
||||
return true;
|
||||
}
|
||||
if (!stepping && (!tracks[0].codec || tracks[0].drained) && !resamplerDrained) {
|
||||
drainResampler();
|
||||
return true;
|
||||
}
|
||||
if (!stepping && pcmOffset >= pcmFrames &&
|
||||
(!tracks[0].codec || tracks[0].drained) && !resamplerDrained) {
|
||||
drainResampler();
|
||||
return true;
|
||||
}
|
||||
if (network || demuxEnded) return false;
|
||||
// The local path keeps one reused demux packet and no reader or packet-queue allocation.
|
||||
if (packetPending) {
|
||||
const int slot = packet->stream_index == tracks[0].index ? 0 : 1;
|
||||
if (stepping && slot == 0) {
|
||||
av_packet_unref(packet);
|
||||
} else {
|
||||
auto &track = tracks[slot];
|
||||
if (track.packetPending) return false;
|
||||
av_packet_move_ref(track.packet, packet);
|
||||
track.packetPending = true;
|
||||
}
|
||||
return false;
|
||||
packetPending = false;
|
||||
return true;
|
||||
}
|
||||
const int result = av_read_frame(format, packet);
|
||||
if (result == AVERROR_EOF) {
|
||||
demuxEnded = true;
|
||||
for (auto &track : tracks) track.sourceEnded = true;
|
||||
return true;
|
||||
}
|
||||
if (result == AVERROR(EAGAIN)) return false;
|
||||
@@ -830,9 +1090,54 @@ struct Player {
|
||||
if (latest.frame) presentVideo(std::move(latest));
|
||||
}
|
||||
|
||||
bool audioDrained() const {
|
||||
return (!tracks[0].codec || tracks[0].drained) && resamplerDrained && pcmOffset >= pcmFrames;
|
||||
}
|
||||
|
||||
void updateBuffering() {
|
||||
if (!network || status != PLAYER_PLAYING) return;
|
||||
const bool seekPending = networkSeeksPending();
|
||||
const bool videoRemaining = tracks[1].codec &&
|
||||
(!tracks[1].drained || audioWriteEnd + sampleTime < videoEnd);
|
||||
const bool audioEmpty = tracks[0].codec && output.queued() == 0 &&
|
||||
(!audioDrained() || videoRemaining);
|
||||
const bool videoEmpty = tracks[1].codec && !tracks[1].drained && video.empty() &&
|
||||
(!presented.frame || position + 0.002 >= presented.end);
|
||||
if (!buffering && (seekPending || audioEmpty || videoEmpty)) {
|
||||
output.pause();
|
||||
if (tracks[0].codec) {
|
||||
const double frozen = output.clock();
|
||||
if (std::isfinite(frozen)) position = std::max(seekTarget, frozen);
|
||||
} else {
|
||||
position = std::min(position, std::max(seekTarget, videoEnd));
|
||||
}
|
||||
buffering = true;
|
||||
}
|
||||
const bool audioReady = !tracks[0].codec || output.queued() >= 4800 ||
|
||||
(audioDrained() && output.queued() > 0) ||
|
||||
(audioDrained() && !videoRemaining);
|
||||
const bool videoReady = !tracks[1].codec || tracks[1].drained || !video.empty() ||
|
||||
(presented.frame && presented.end > position + 0.002);
|
||||
if (buffering && !seekPending && audioReady && videoReady) {
|
||||
if (tracks[0].codec) {
|
||||
std::string deviceError;
|
||||
if (!output.start(deviceError))
|
||||
throw std::runtime_error(deviceError.empty() ? "Cannot start audio output" : deviceError);
|
||||
}
|
||||
steadyPosition = position;
|
||||
steadyAnchor = Clock::now();
|
||||
buffering = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool tick() {
|
||||
if (!format || interrupted() || status == PLAYER_ENDED || status == PLAYER_ERROR) return false;
|
||||
if (frameStepping) return false;
|
||||
for (const auto &input : inputs)
|
||||
if (input) check(input->error(), "Reading network media");
|
||||
if (frameStepping) {
|
||||
if (network) publish(); // Reader seek completion must still acknowledge a paused step.
|
||||
return false;
|
||||
}
|
||||
bool progressed = pumpAudio();
|
||||
if (status == PLAYER_PAUSED) {
|
||||
if (!previewShown && !video.empty()) {
|
||||
@@ -842,25 +1147,31 @@ struct Player {
|
||||
presentVideo(std::move(frame));
|
||||
progressed = true;
|
||||
}
|
||||
const bool needPreview = tracks[1].codec && !previewShown;
|
||||
const bool needAudio = tracks[0].codec && output.queued() < 4800;
|
||||
const bool needPreview = tracks[1].codec && !previewShown && !tracks[1].drained;
|
||||
const bool needAudio = tracks[0].codec && output.queued() < 4800 && !audioDrained();
|
||||
if (needPreview || needAudio) progressed = decodeOne() || progressed;
|
||||
if (network) {
|
||||
buffering = networkSeeksPending() || needPreview ||
|
||||
(needAudio && output.queued() == 0);
|
||||
publish();
|
||||
}
|
||||
return progressed;
|
||||
}
|
||||
position = clockPosition();
|
||||
renderVideo(position);
|
||||
progressed = decodeOne() || progressed;
|
||||
if (demuxEnded && (!tracks[0].codec || tracks[0].drained) &&
|
||||
resamplerDrained && pcmOffset >= pcmFrames && tracks[0].codec)
|
||||
// Audio ending first is not a global demux EOF: keep the audio-master clock through video's tail.
|
||||
if (tracks[0].codec && audioDrained())
|
||||
progressed = writeSilence(videoEnd) || progressed;
|
||||
const bool drained = demuxEnded && resamplerDrained && pcmOffset >= pcmFrames &&
|
||||
(!tracks[0].codec || tracks[0].drained) && (!tracks[1].codec || tracks[1].drained);
|
||||
updateBuffering();
|
||||
const bool drained = audioDrained() && (!tracks[1].codec || tracks[1].drained);
|
||||
if (drained && video.empty()) {
|
||||
const double end = std::max(audioWriteEnd, videoEnd);
|
||||
if (position + sampleTime >= end && (!tracks[0].codec || output.queued() == 0)) {
|
||||
output.pause();
|
||||
position = end;
|
||||
if (duration <= 0) duration = end;
|
||||
buffering = false;
|
||||
status = PLAYER_ENDED;
|
||||
}
|
||||
}
|
||||
@@ -946,6 +1257,22 @@ bool player_open(Player *player, const char *path) {
|
||||
if (!path || !*path) return false;
|
||||
return submit(player, [=] { return player->enqueue({Action::Open, path}); });
|
||||
}
|
||||
bool player_open_network(Player *player, const PlayerNetworkSource *source) {
|
||||
if (!source || !std::isfinite(source->duration) || source->duration < 0 ||
|
||||
!validNetworkURL(source->video_url) ||
|
||||
(source->audio_url && *source->audio_url && !validNetworkURL(source->audio_url)) ||
|
||||
!validHeaders(source->video_headers) || !validHeaders(source->audio_headers)) return false;
|
||||
return submit(player, [=] {
|
||||
Command command{Action::Open, source->video_url};
|
||||
command.audioURL = source->audio_url ? source->audio_url : "";
|
||||
command.videoHeaders = source->video_headers ? source->video_headers : "";
|
||||
command.audioHeaders = source->audio_headers ? source->audio_headers : "";
|
||||
command.sourceDuration = source->duration;
|
||||
command.network = true;
|
||||
command.live = source->is_live;
|
||||
return player->enqueue(std::move(command));
|
||||
});
|
||||
}
|
||||
bool player_play(Player *player) {
|
||||
return submit(player, [=] { return player->enqueue({Action::Play, {}}); });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user