}
#include "chroma_subsampler.h"
-#include "shared/context.h"
#include "flags.h"
#include "flow.h"
-#include "shared/httpd.h"
#include "jpeg_frame_view.h"
#include "movit/util.h"
-#include "shared/mux.h"
#include "player.h"
+#include "shared/context.h"
+#include "shared/httpd.h"
+#include "shared/mux.h"
#include "util.h"
#include "ycbcr_converter.h"
size_t width = global_flags.width, height = global_flags.height; // Doesn't matter for MJPEG.
mux.reset(new Mux(avctx, width, height, Mux::CODEC_MJPEG, /*video_extradata=*/"", /*audio_codec_parameters=*/nullptr,
- AVCOL_SPC_BT709, Mux::WITHOUT_AUDIO,
- COARSE_TIMEBASE, /*write_callback=*/nullptr, Mux::WRITE_FOREGROUND, {}));
+ AVCOL_SPC_BT709, COARSE_TIMEBASE, /*write_callback=*/nullptr, Mux::WRITE_FOREGROUND, {}, Mux::WITH_SUBTITLES));
encode_thread = thread(&VideoStream::encode_thread_func, this);
}
deque<QueuedFrame> q;
{
- unique_lock<mutex> lock(queue_lock);
+ lock_guard<mutex> lock(queue_lock);
q = move(frame_queue);
}
void VideoStream::schedule_original_frame(steady_clock::time_point local_pts,
int64_t output_pts, function<void()> &&display_func,
QueueSpotHolder &&queue_spot_holder,
- FrameOnDisk frame)
+ FrameOnDisk frame, const string &subtitle)
{
fprintf(stderr, "output_pts=%ld original input_pts=%ld\n", output_pts, frame.pts);
qf.frame1 = frame;
qf.display_func = move(display_func);
qf.queue_spot_holder = move(queue_spot_holder);
+ qf.subtitle = subtitle;
- unique_lock<mutex> lock(queue_lock);
+ lock_guard<mutex> lock(queue_lock);
frame_queue.push_back(move(qf));
queue_changed.notify_all();
}
function<void()> &&display_func,
QueueSpotHolder &&queue_spot_holder,
FrameOnDisk frame1_spec, FrameOnDisk frame2_spec,
- float fade_alpha)
+ float fade_alpha, const string &subtitle)
{
fprintf(stderr, "output_pts=%ld faded input_pts=%ld,%ld fade_alpha=%.2f\n", output_pts, frame1_spec.pts, frame2_spec.pts, fade_alpha);
// separate pools around.)
BorrowedInterpolatedFrameResources resources;
{
- unique_lock<mutex> lock(queue_lock);
+ lock_guard<mutex> lock(queue_lock);
if (interpolate_resources.empty()) {
fprintf(stderr, "WARNING: Too many interpolated frames already in transit; dropping one.\n");
return;
qf.frame1 = frame1_spec;
qf.display_func = move(display_func);
qf.queue_spot_holder = move(queue_spot_holder);
+ qf.subtitle = subtitle;
qf.secondary_frame = frame2_spec;
qf.resources = move(resources);
qf.local_pts = local_pts;
- unique_lock<mutex> lock(queue_lock);
+ lock_guard<mutex> lock(queue_lock);
frame_queue.push_back(move(qf));
queue_changed.notify_all();
}
int64_t output_pts, function<void(shared_ptr<Frame>)> &&display_func,
QueueSpotHolder &&queue_spot_holder,
FrameOnDisk frame1, FrameOnDisk frame2,
- float alpha, FrameOnDisk secondary_frame, float fade_alpha)
+ float alpha, FrameOnDisk secondary_frame, float fade_alpha, const string &subtitle)
{
if (secondary_frame.pts != -1) {
fprintf(stderr, "output_pts=%ld interpolated input_pts1=%ld input_pts2=%ld alpha=%.3f secondary_pts=%ld fade_alpha=%.2f\n", output_pts, frame1.pts, frame2.pts, alpha, secondary_frame.pts, fade_alpha);
// Get the temporary OpenGL resources we need for doing the interpolation.
BorrowedInterpolatedFrameResources resources;
{
- unique_lock<mutex> lock(queue_lock);
+ lock_guard<mutex> lock(queue_lock);
if (interpolate_resources.empty()) {
fprintf(stderr, "WARNING: Too many interpolated frames already in transit; dropping one.\n");
return;
qf.display_decoded_func = move(display_func);
qf.queue_spot_holder = move(queue_spot_holder);
qf.local_pts = local_pts;
+ qf.subtitle = subtitle;
check_error();
check_error();
qf.resources = move(resources);
- unique_lock<mutex> lock(queue_lock);
+ lock_guard<mutex> lock(queue_lock);
frame_queue.push_back(move(qf));
queue_changed.notify_all();
}
void VideoStream::schedule_refresh_frame(steady_clock::time_point local_pts,
int64_t output_pts, function<void()> &&display_func,
- QueueSpotHolder &&queue_spot_holder)
+ QueueSpotHolder &&queue_spot_holder, const string &subtitle)
{
QueuedFrame qf;
qf.type = QueuedFrame::REFRESH;
qf.output_pts = output_pts;
qf.display_func = move(display_func);
qf.queue_spot_holder = move(queue_spot_holder);
+ qf.subtitle = subtitle;
- unique_lock<mutex> lock(queue_lock);
+ lock_guard<mutex> lock(queue_lock);
frame_queue.push_back(move(qf));
queue_changed.notify_all();
}
unique_lock<mutex> lock(queue_lock);
// Wait until we have a frame to play.
- queue_changed.wait(lock, [this]{
+ queue_changed.wait(lock, [this] {
return !frame_queue.empty() || should_quit;
});
if (should_quit) {
if (output_fast_forward) {
aborted = frame_queue.empty() || frame_queue.front().local_pts != frame_start;
} else {
- aborted = queue_changed.wait_until(lock, frame_start, [this, frame_start]{
+ aborted = queue_changed.wait_until(lock, frame_start, [this, frame_start] {
return frame_queue.empty() || frame_queue.front().local_pts != frame_start;
});
}
} else {
assert(false);
}
+
+ if (!qf.subtitle.empty()) {
+ AVPacket pkt;
+ av_init_packet(&pkt);
+ pkt.stream_index = mux->get_subtitle_stream_idx();
+ assert(pkt.stream_index != -1);
+ pkt.data = (uint8_t *)qf.subtitle.data();
+ pkt.size = qf.subtitle.size();
+ pkt.flags = 0;
+ pkt.duration = lrint(TIMEBASE / global_flags.output_framerate); // Doesn't really matter for Nageru.
+ mux->add_packet(pkt, qf.output_pts, qf.output_pts);
+ }
+
if (qf.display_func != nullptr) {
qf.display_func();
}