#include "mux.h"
#include "player.h"
#include "util.h"
+#include "ycbcr_converter.h"
#include <epoxy/glx.h>
JSAMPARRAY data[3] = { yptr, cbptr, crptr };
for (unsigned y = 0; y < height; y += 8) {
for (unsigned yy = 0; yy < 8; ++yy) {
- yptr[yy] = const_cast<JSAMPROW>(&y_data[(height - y - yy - 1) * width]);
- cbptr[yy] = const_cast<JSAMPROW>(&cb_data[(height - y - yy - 1) * width/2]);
- crptr[yy] = const_cast<JSAMPROW>(&cr_data[(height - y - yy - 1) * width/2]);
+ yptr[yy] = const_cast<JSAMPROW>(&y_data[(y + yy) * width]);
+ cbptr[yy] = const_cast<JSAMPROW>(&cb_data[(y + yy) * width/2]);
+ crptr[yy] = const_cast<JSAMPROW>(&cr_data[(y + yy) * width/2]);
}
jpeg_write_raw_data(&cinfo, data, /*num_lines=*/8);
VideoStream::VideoStream()
{
- using namespace movit;
-
- ImageFormat inout_format;
- inout_format.color_space = COLORSPACE_sRGB;
- inout_format.gamma_curve = GAMMA_sRGB;
-
- ycbcr_format.luma_coefficients = YCBCR_REC_709;
- ycbcr_format.full_range = true; // JPEG.
- ycbcr_format.num_levels = 256;
- ycbcr_format.chroma_subsampling_x = 2;
- ycbcr_format.chroma_subsampling_y = 1;
- ycbcr_format.cb_x_position = 0.0f; // H.264 -- _not_ JPEG, even though our input is MJPEG-encoded
- ycbcr_format.cb_y_position = 0.5f; // Irrelevant.
- ycbcr_format.cr_x_position = 0.0f;
- ycbcr_format.cr_y_position = 0.5f;
-
- YCbCrFormat ycbcr_output_format = ycbcr_format;
- ycbcr_output_format.chroma_subsampling_x = 1;
-
- // TODO: deduplicate code against JPEGFrameView?
- ycbcr_planar_convert_chain.reset(new EffectChain(1280, 720));
- ycbcr_planar_input = (movit::YCbCrInput *)ycbcr_planar_convert_chain->add_input(new YCbCrInput(inout_format, ycbcr_format, 1280, 720, YCBCR_INPUT_PLANAR));
-
- // One full Y'CbCr texture (for interpolation), one that's just Y (throwing away the
- // Cb and Cr channels). The second copy is sort of redundant, but it's the easiest way
- // of getting the gray data into a layered texture.
- ycbcr_planar_convert_chain->add_ycbcr_output(inout_format, OUTPUT_ALPHA_FORMAT_POSTMULTIPLIED, ycbcr_output_format);
- ycbcr_planar_convert_chain->add_ycbcr_output(inout_format, OUTPUT_ALPHA_FORMAT_POSTMULTIPLIED, ycbcr_output_format);
- ycbcr_planar_convert_chain->set_dither_bits(8);
- ycbcr_planar_convert_chain->finalize();
-
- // Same, for semiplanar inputs.
- ycbcr_semiplanar_convert_chain.reset(new EffectChain(1280, 720));
- ycbcr_semiplanar_input = (movit::YCbCrInput *)ycbcr_semiplanar_convert_chain->add_input(new YCbCrInput(inout_format, ycbcr_format, 1280, 720, YCBCR_INPUT_SPLIT_Y_AND_CBCR));
-
- // One full Y'CbCr texture (for interpolation), one that's just Y (throwing away the
- // Cb and Cr channels). The second copy is sort of redundant, but it's the easiest way
- // of getting the gray data into a layered texture.
- ycbcr_semiplanar_convert_chain->add_ycbcr_output(inout_format, OUTPUT_ALPHA_FORMAT_POSTMULTIPLIED, ycbcr_output_format);
- ycbcr_semiplanar_convert_chain->add_ycbcr_output(inout_format, OUTPUT_ALPHA_FORMAT_POSTMULTIPLIED, ycbcr_output_format);
- ycbcr_semiplanar_convert_chain->set_dither_bits(8);
- ycbcr_semiplanar_convert_chain->finalize();
-
- GLuint input_tex[num_interpolate_slots], gray_tex[num_interpolate_slots], cb_tex[num_interpolate_slots], cr_tex[num_interpolate_slots];
+ ycbcr_converter.reset(new YCbCrConverter(YCbCrConverter::OUTPUT_TO_DUAL_YCBCR, /*resource_pool=*/nullptr));
+ ycbcr_semiplanar_converter.reset(new YCbCrConverter(YCbCrConverter::OUTPUT_TO_SEMIPLANAR, /*resource_pool=*/nullptr));
+
+ GLuint input_tex[num_interpolate_slots], gray_tex[num_interpolate_slots];
+ GLuint fade_y_output_tex[num_interpolate_slots], fade_cbcr_output_tex[num_interpolate_slots];
+ GLuint cb_tex[num_interpolate_slots], cr_tex[num_interpolate_slots];
+
glCreateTextures(GL_TEXTURE_2D_ARRAY, 10, input_tex);
glCreateTextures(GL_TEXTURE_2D_ARRAY, 10, gray_tex);
+ glCreateTextures(GL_TEXTURE_2D, 10, fade_y_output_tex);
+ glCreateTextures(GL_TEXTURE_2D, 10, fade_cbcr_output_tex);
glCreateTextures(GL_TEXTURE_2D, 10, cb_tex);
glCreateTextures(GL_TEXTURE_2D, 10, cr_tex);
check_error();
+
constexpr size_t width = 1280, height = 720; // FIXME: adjustable width, height
int levels = find_num_levels(width, height);
for (size_t i = 0; i < num_interpolate_slots; ++i) {
check_error();
glTextureStorage3D(gray_tex[i], levels, GL_R8, width, height, 2);
check_error();
+ glTextureStorage2D(fade_y_output_tex[i], 1, GL_R8, width, height);
+ check_error();
+ glTextureStorage2D(fade_cbcr_output_tex[i], 1, GL_RG8, width, height);
+ check_error();
glTextureStorage2D(cb_tex[i], 1, GL_R8, width / 2, height);
check_error();
glTextureStorage2D(cr_tex[i], 1, GL_R8, width / 2, height);
InterpolatedFrameResources resource;
resource.input_tex = input_tex[i];
resource.gray_tex = gray_tex[i];
+ resource.fade_y_output_tex = fade_y_output_tex[i];
+ resource.fade_cbcr_output_tex = fade_cbcr_output_tex[i];
resource.cb_tex = cb_tex[i];
resource.cr_tex = cr_tex[i];
glCreateFramebuffers(2, resource.input_fbos);
check_error();
+ glCreateFramebuffers(1, &resource.fade_fbo);
+ check_error();
glNamedFramebufferTextureLayer(resource.input_fbos[0], GL_COLOR_ATTACHMENT0, input_tex[i], 0, 0);
check_error();
check_error();
glNamedFramebufferTextureLayer(resource.input_fbos[1], GL_COLOR_ATTACHMENT1, gray_tex[i], 0, 1);
check_error();
+ glNamedFramebufferTexture(resource.fade_fbo, GL_COLOR_ATTACHMENT0, fade_y_output_tex[i], 0);
+ check_error();
+ glNamedFramebufferTexture(resource.fade_fbo, GL_COLOR_ATTACHMENT1, fade_cbcr_output_tex[i], 0);
+ check_error();
GLuint bufs[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
glNamedFramebufferDrawBuffers(resource.input_fbos[0], 2, bufs);
check_error();
glNamedFramebufferDrawBuffers(resource.input_fbos[1], 2, bufs);
check_error();
+ glNamedFramebufferDrawBuffers(resource.fade_fbo, 2, bufs);
+ check_error();
glCreateBuffers(1, &resource.pbo);
check_error();
check_error();
compute_flow.reset(new DISComputeFlow(width, height, operating_point2));
- interpolate.reset(new Interpolate(width, height, operating_point2, /*split_ycbcr_output=*/true));
+ interpolate.reset(new Interpolate(operating_point2, /*split_ycbcr_output=*/true));
+ interpolate_no_split.reset(new Interpolate(operating_point2, /*split_ycbcr_output=*/false));
chroma_subsampler.reset(new ChromaSubsampler);
check_error();
+
+ // The “last frame” is initially black.
+ unique_ptr<uint8_t[]> y(new uint8_t[1280 * 720]);
+ unique_ptr<uint8_t[]> cb_or_cr(new uint8_t[640 * 720]);
+ memset(y.get(), 16, 1280 * 720);
+ memset(cb_or_cr.get(), 128, 640 * 720);
+ last_frame = encode_jpeg(y.get(), cb_or_cr.get(), cb_or_cr.get(), 1280, 720);
}
VideoStream::~VideoStream() {}
queue_nonempty.notify_all();
}
-void VideoStream::schedule_interpolated_frame(int64_t output_pts, unsigned stream_idx, int64_t input_first_pts, int64_t input_second_pts, float alpha)
+void VideoStream::schedule_faded_frame(int64_t output_pts, unsigned stream_idx, int64_t input_pts, int secondary_stream_idx, int64_t secondary_input_pts, float fade_alpha)
{
- fprintf(stderr, "output_pts=%ld interpolated input_pts1=%ld input_pts2=%ld alpha=%.3f\n", output_pts, input_first_pts, input_second_pts, alpha);
+ fprintf(stderr, "output_pts=%ld faded input_pts=%ld,%ld fade_alpha=%.2f\n", output_pts, input_pts, secondary_input_pts, fade_alpha);
+
+ // Get the temporary OpenGL resources we need for doing the fade.
+ // (We share these with interpolated frames, which is slightly
+ // overkill, but there's no need to waste resources on keeping
+ // separate pools around.)
+ InterpolatedFrameResources resources;
+ {
+ unique_lock<mutex> lock(queue_lock);
+ if (interpolate_resources.empty()) {
+ fprintf(stderr, "WARNING: Too many interpolated frames already in transit; dropping one.\n");
+ return;
+ }
+ resources = interpolate_resources.front();
+ interpolate_resources.pop_front();
+ }
+
+ bool did_decode;
+
+ JPEGID jpeg_id1;
+ jpeg_id1.stream_idx = stream_idx;
+ jpeg_id1.pts = input_pts;
+ jpeg_id1.interpolated = false;
+ shared_ptr<Frame> frame1 = decode_jpeg_with_cache(jpeg_id1, DECODE_IF_NOT_IN_CACHE, &did_decode);
+
+ JPEGID jpeg_id2;
+ jpeg_id2.stream_idx = secondary_stream_idx;
+ jpeg_id2.pts = secondary_input_pts;
+ jpeg_id2.interpolated = false;
+ shared_ptr<Frame> frame2 = decode_jpeg_with_cache(jpeg_id2, DECODE_IF_NOT_IN_CACHE, &did_decode);
+
+ ycbcr_semiplanar_converter->prepare_chain_for_fade(frame1, frame2, fade_alpha)->render_to_fbo(resources.fade_fbo, 1280, 720);
+
+ QueuedFrame qf;
+ qf.type = QueuedFrame::FADED;
+ qf.output_pts = output_pts;
+ qf.stream_idx = stream_idx;
+ qf.resources = resources;
+ qf.input_first_pts = input_pts;
+
+ qf.secondary_stream_idx = secondary_stream_idx;
+ qf.secondary_input_pts = secondary_input_pts;
+
+ // Subsample and split Cb/Cr.
+ chroma_subsampler->subsample_chroma(resources.fade_cbcr_output_tex, 1280, 720, resources.cb_tex, resources.cr_tex);
+
+ // Read it down (asynchronously) to the CPU.
+ glPixelStorei(GL_PACK_ROW_LENGTH, 0);
+ glBindBuffer(GL_PIXEL_PACK_BUFFER, resources.pbo);
+ check_error();
+ glGetTextureImage(resources.fade_y_output_tex, 0, GL_RED, GL_UNSIGNED_BYTE, 1280 * 720 * 4, BUFFER_OFFSET(0));
+ check_error();
+ glGetTextureImage(resources.cb_tex, 0, GL_RED, GL_UNSIGNED_BYTE, 1280 * 720 * 3, BUFFER_OFFSET(1280 * 720));
+ check_error();
+ glGetTextureImage(resources.cr_tex, 0, GL_RED, GL_UNSIGNED_BYTE, 1280 * 720 * 3 - 640 * 720, BUFFER_OFFSET(1280 * 720 + 640 * 720));
+ check_error();
+ glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
+
+ // Set a fence we can wait for to make sure the CPU sees the read.
+ glMemoryBarrier(GL_CLIENT_MAPPED_BUFFER_BARRIER_BIT);
+ check_error();
+ qf.fence = RefCountedGLsync(GL_SYNC_GPU_COMMANDS_COMPLETE, /*flags=*/0);
+ check_error();
+
+ unique_lock<mutex> lock(queue_lock);
+ frame_queue.push_back(qf);
+ queue_nonempty.notify_all();
+}
+
+void VideoStream::schedule_interpolated_frame(int64_t output_pts, unsigned stream_idx, int64_t input_first_pts, int64_t input_second_pts, float alpha, int secondary_stream_idx, int64_t secondary_input_pts, float fade_alpha)
+{
+ if (secondary_stream_idx != -1) {
+ fprintf(stderr, "output_pts=%ld interpolated input_pts1=%ld input_pts2=%ld alpha=%.3f secondary_pts=%ld fade_alpha=%.2f\n", output_pts, input_first_pts, input_second_pts, alpha, secondary_input_pts, fade_alpha);
+ } else {
+ fprintf(stderr, "output_pts=%ld interpolated input_pts1=%ld input_pts2=%ld alpha=%.3f\n", output_pts, input_first_pts, input_second_pts, alpha);
+ }
+
+ JPEGID id;
+ if (secondary_stream_idx == -1) {
+ id = JPEGID{ stream_idx, output_pts, /*interpolated=*/true };
+ } else {
+ id = create_jpegid_for_interpolated_fade(stream_idx, output_pts, secondary_stream_idx, secondary_input_pts);
+ }
// Get the temporary OpenGL resources we need for doing the interpolation.
InterpolatedFrameResources resources;
unique_lock<mutex> lock(queue_lock);
if (interpolate_resources.empty()) {
fprintf(stderr, "WARNING: Too many interpolated frames already in transit; dropping one.\n");
- JPEGFrameView::insert_interpolated_frame(stream_idx, output_pts, nullptr);
+ JPEGFrameView::insert_interpolated_frame(id, nullptr);
return;
}
resources = interpolate_resources.front();
}
QueuedFrame qf;
- qf.type = QueuedFrame::INTERPOLATED;
+ qf.type = (secondary_stream_idx == -1) ? QueuedFrame::INTERPOLATED : QueuedFrame::FADED_INTERPOLATED;
qf.output_pts = output_pts;
qf.stream_idx = stream_idx;
qf.resources = resources;
+ qf.id = id;
check_error();
// Convert frame0 and frame1 to OpenGL textures.
- // TODO: Deduplicate against JPEGFrameView::setDecodedFrame?
for (size_t frame_no = 0; frame_no < 2; ++frame_no) {
JPEGID jpeg_id;
jpeg_id.stream_idx = stream_idx;
jpeg_id.interpolated = false;
bool did_decode;
shared_ptr<Frame> frame = decode_jpeg_with_cache(jpeg_id, DECODE_IF_NOT_IN_CACHE, &did_decode);
- ycbcr_format.chroma_subsampling_x = frame->chroma_subsampling_x;
- ycbcr_format.chroma_subsampling_y = frame->chroma_subsampling_y;
-
- if (frame->is_semiplanar) {
- ycbcr_semiplanar_input->change_ycbcr_format(ycbcr_format);
- ycbcr_semiplanar_input->set_width(frame->width);
- ycbcr_semiplanar_input->set_height(frame->height);
- ycbcr_semiplanar_input->set_pixel_data(0, frame->y.get());
- ycbcr_semiplanar_input->set_pixel_data(1, frame->cbcr.get());
- ycbcr_semiplanar_input->set_pitch(0, frame->pitch_y);
- ycbcr_semiplanar_input->set_pitch(1, frame->pitch_chroma);
- ycbcr_semiplanar_convert_chain->render_to_fbo(resources.input_fbos[frame_no], 1280, 720);
- } else {
- ycbcr_planar_input->change_ycbcr_format(ycbcr_format);
- ycbcr_planar_input->set_width(frame->width);
- ycbcr_planar_input->set_height(frame->height);
- ycbcr_planar_input->set_pixel_data(0, frame->y.get());
- ycbcr_planar_input->set_pixel_data(1, frame->cb.get());
- ycbcr_planar_input->set_pixel_data(2, frame->cr.get());
- ycbcr_planar_input->set_pitch(0, frame->pitch_y);
- ycbcr_planar_input->set_pitch(1, frame->pitch_chroma);
- ycbcr_planar_input->set_pitch(2, frame->pitch_chroma);
- ycbcr_planar_convert_chain->render_to_fbo(resources.input_fbos[frame_no], 1280, 720);
- }
+ ycbcr_converter->prepare_chain_for_conversion(frame)->render_to_fbo(resources.input_fbos[frame_no], 1280, 720);
}
glGenerateTextureMipmap(resources.input_tex);
// Compute the interpolated frame.
qf.flow_tex = compute_flow->exec(resources.gray_tex, DISComputeFlow::FORWARD_AND_BACKWARD, DISComputeFlow::DO_NOT_RESIZE_FLOW);
check_error();
- tie(qf.output_tex, qf.cbcr_tex) = interpolate->exec(resources.input_tex, resources.gray_tex, qf.flow_tex, 1280, 720, alpha);
- check_error();
- // Subsample and split Cb/Cr.
- chroma_subsampler->subsample_chroma(qf.cbcr_tex, 1280, 720, resources.cb_tex, resources.cr_tex);
+ if (secondary_stream_idx != -1) {
+ // Fade. First kick off the interpolation.
+ tie(qf.output_tex, ignore) = interpolate_no_split->exec(resources.input_tex, resources.gray_tex, qf.flow_tex, 1280, 720, alpha);
+ check_error();
+
+ // Now decode the image we are fading against.
+ JPEGID jpeg_id;
+ jpeg_id.stream_idx = secondary_stream_idx;
+ jpeg_id.pts = secondary_input_pts;
+ jpeg_id.interpolated = false;
+ bool did_decode;
+ shared_ptr<Frame> frame2 = decode_jpeg_with_cache(jpeg_id, DECODE_IF_NOT_IN_CACHE, &did_decode);
+
+ // Then fade against it, putting it into the fade Y' and CbCr textures.
+ ycbcr_semiplanar_converter->prepare_chain_for_fade_from_texture(qf.output_tex, frame2, fade_alpha)->render_to_fbo(resources.fade_fbo, 1280, 720);
+
+ // Subsample and split Cb/Cr.
+ chroma_subsampler->subsample_chroma(resources.fade_cbcr_output_tex, 1280, 720, resources.cb_tex, resources.cr_tex);
+ } else {
+ tie(qf.output_tex, qf.cbcr_tex) = interpolate->exec(resources.input_tex, resources.gray_tex, qf.flow_tex, 1280, 720, alpha);
+ check_error();
+
+ // Subsample and split Cb/Cr.
+ chroma_subsampler->subsample_chroma(qf.cbcr_tex, 1280, 720, resources.cb_tex, resources.cr_tex);
+ }
+
// We could have released qf.flow_tex here, but to make sure we don't cause a stall
// when trying to reuse it for the next frame, we can just as well hold on to it
glPixelStorei(GL_PACK_ROW_LENGTH, 0);
glBindBuffer(GL_PIXEL_PACK_BUFFER, resources.pbo);
check_error();
- glGetTextureImage(qf.output_tex, 0, GL_RED, GL_UNSIGNED_BYTE, 1280 * 720 * 4, BUFFER_OFFSET(0));
+ if (secondary_stream_idx != -1) {
+ glGetTextureImage(resources.fade_y_output_tex, 0, GL_RED, GL_UNSIGNED_BYTE, 1280 * 720 * 4, BUFFER_OFFSET(0));
+ } else {
+ glGetTextureImage(qf.output_tex, 0, GL_RED, GL_UNSIGNED_BYTE, 1280 * 720 * 4, BUFFER_OFFSET(0));
+ }
check_error();
glGetTextureImage(resources.cb_tex, 0, GL_RED, GL_UNSIGNED_BYTE, 1280 * 720 * 3, BUFFER_OFFSET(1280 * 720));
check_error();
queue_nonempty.notify_all();
}
+void VideoStream::schedule_refresh_frame(int64_t output_pts)
+{
+ AVPacket pkt;
+ av_init_packet(&pkt);
+ pkt.stream_index = 0;
+ pkt.data = (uint8_t *)last_frame.data();
+ pkt.size = last_frame.size();
+ stream_mux->add_packet(pkt, output_pts, output_pts);
+}
+
+namespace {
+
+shared_ptr<Frame> frame_from_pbo(void *contents, size_t width, size_t height)
+{
+ size_t chroma_width = width / 2;
+
+ const uint8_t *y = (const uint8_t *)contents;
+ const uint8_t *cb = (const uint8_t *)contents + width * height;
+ const uint8_t *cr = (const uint8_t *)contents + width * height + chroma_width * height;
+
+ shared_ptr<Frame> frame(new Frame);
+ frame->y.reset(new uint8_t[width * height]);
+ frame->cb.reset(new uint8_t[chroma_width * height]);
+ frame->cr.reset(new uint8_t[chroma_width * height]);
+ for (unsigned yy = 0; yy < height; ++yy) {
+ memcpy(frame->y.get() + width * yy, y + width * yy, width);
+ memcpy(frame->cb.get() + chroma_width * yy, cb + chroma_width * yy, chroma_width);
+ memcpy(frame->cr.get() + chroma_width * yy, cr + chroma_width * yy, chroma_width);
+ }
+ frame->is_semiplanar = false;
+ frame->width = width;
+ frame->height = height;
+ frame->chroma_subsampling_x = 2;
+ frame->chroma_subsampling_y = 1;
+ frame->pitch_y = width;
+ frame->pitch_chroma = chroma_width;
+ return frame;
+}
+
+} // namespace
+
void VideoStream::encode_thread_func()
{
pthread_setname_np(pthread_self(), "VideoStream");
pkt.data = (uint8_t *)jpeg.data();
pkt.size = jpeg.size();
stream_mux->add_packet(pkt, qf.output_pts, qf.output_pts);
- } else if (qf.type == QueuedFrame::INTERPOLATED) {
+
+ last_frame.assign(&jpeg[0], &jpeg[0] + jpeg.size());
+ } else if (qf.type == QueuedFrame::FADED) {
glClientWaitSync(qf.fence.get(), /*flags=*/0, GL_TIMEOUT_IGNORED);
- const uint8_t *y = (const uint8_t *)qf.resources.pbo_contents;
- const uint8_t *cb = (const uint8_t *)qf.resources.pbo_contents + 1280 * 720;
- const uint8_t *cr = (const uint8_t *)qf.resources.pbo_contents + 1280 * 720 + 640 * 720;
+ shared_ptr<Frame> frame = frame_from_pbo(qf.resources.pbo_contents, 1280, 720);
+
+ // Now JPEG encode it, and send it on to the stream.
+ vector<uint8_t> jpeg = encode_jpeg(frame->y.get(), frame->cb.get(), frame->cr.get(), 1280, 720);
+
+ AVPacket pkt;
+ av_init_packet(&pkt);
+ pkt.stream_index = 0;
+ pkt.data = (uint8_t *)jpeg.data();
+ pkt.size = jpeg.size();
+ stream_mux->add_packet(pkt, qf.output_pts, qf.output_pts);
+ last_frame = move(jpeg);
+
+ // Put the frame resources back.
+ unique_lock<mutex> lock(queue_lock);
+ interpolate_resources.push_back(qf.resources);
+ } else if (qf.type == QueuedFrame::INTERPOLATED || qf.type == QueuedFrame::FADED_INTERPOLATED) {
+ glClientWaitSync(qf.fence.get(), /*flags=*/0, GL_TIMEOUT_IGNORED);
// Send a copy of the frame on to display.
- shared_ptr<Frame> frame(new Frame);
- frame->y.reset(new uint8_t[1280 * 720]);
- frame->cb.reset(new uint8_t[640 * 720]);
- frame->cr.reset(new uint8_t[640 * 720]);
- for (unsigned yy = 0; yy < 720; ++yy) {
- memcpy(frame->y.get() + 1280 * yy, y + 1280 * (719 - yy), 1280);
- memcpy(frame->cb.get() + 640 * yy, cb + 640 * (719 - yy), 640);
- memcpy(frame->cr.get() + 640 * yy, cr + 640 * (719 - yy), 640);
- }
- frame->is_semiplanar = false;
- frame->width = 1280;
- frame->height = 720;
- frame->chroma_subsampling_x = 2;
- frame->chroma_subsampling_y = 1;
- frame->pitch_y = 1280;
- frame->pitch_chroma = 640;
- JPEGFrameView::insert_interpolated_frame(qf.stream_idx, qf.output_pts, std::move(frame));
+ shared_ptr<Frame> frame = frame_from_pbo(qf.resources.pbo_contents, 1280, 720);
+ JPEGFrameView::insert_interpolated_frame(qf.id, frame);
// Now JPEG encode it, and send it on to the stream.
- vector<uint8_t> jpeg = encode_jpeg(y, cb, cr, 1280, 720);
+ vector<uint8_t> jpeg = encode_jpeg(frame->y.get(), frame->cb.get(), frame->cr.get(), 1280, 720);
compute_flow->release_texture(qf.flow_tex);
- interpolate->release_texture(qf.output_tex);
- interpolate->release_texture(qf.cbcr_tex);
+ if (qf.type != QueuedFrame::FADED_INTERPOLATED) {
+ interpolate->release_texture(qf.output_tex);
+ interpolate->release_texture(qf.cbcr_tex);
+ }
AVPacket pkt;
av_init_packet(&pkt);
pkt.data = (uint8_t *)jpeg.data();
pkt.size = jpeg.size();
stream_mux->add_packet(pkt, qf.output_pts, qf.output_pts);
+ last_frame = move(jpeg);
// Put the frame resources back.
unique_lock<mutex> lock(queue_lock);
interpolate_resources.push_back(qf.resources);
+ } else {
+ assert(false);
}
}
}