#include "jpeg_frame_view.h"
-#include <jpeglib.h>
-#include <stdint.h>
-#include <unistd.h>
+#include "defs.h"
+#include "jpeg_destroyer.h"
+#include "post_to_main_thread.h"
+#include "video_stream.h"
+#include "ycbcr_converter.h"
+#include <QMouseEvent>
+#include <QScreen>
#include <atomic>
#include <condition_variable>
#include <deque>
+#include <jpeglib.h>
+#include <movit/init.h>
+#include <movit/resource_pool.h>
+#include <movit/util.h>
#include <mutex>
+#include <stdint.h>
#include <thread>
+#include <unistd.h>
#include <utility>
-#include <QMouseEvent>
-#include <QScreen>
-
-#include <movit/resource_pool.h>
-#include <movit/init.h>
-#include <movit/util.h>
-
-#include "defs.h"
-#include "post_to_main_thread.h"
+// Must come after the Qt stuff.
#include "vaapi_jpeg_decoder.h"
-#include "video_stream.h"
-#include "ycbcr_converter.h"
using namespace movit;
using namespace std;
jpeg_error_mgr jerr;
dinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&dinfo);
+ JPEGDestroyer destroy_dinfo(&dinfo);
FILE *fp = fopen(filename.c_str(), "rb");
if (fp == nullptr) {
jpeg_read_raw_data(&dinfo, data, v_mcu_size);
}
- (void) jpeg_finish_decompress(&dinfo);
- jpeg_destroy_decompress(&dinfo);
+ (void)jpeg_finish_decompress(&dinfo);
fclose(fp);
return frame;
any_pending_decodes.wait(lock, [] {
return !pending_decodes.empty() || should_quit.load();
});
- if (should_quit.load()) break;
+ if (should_quit.load())
+ break;
decode = pending_decodes.front();
pending_decodes.pop_front();
cache_updated.wait(lock, [id] {
return cache.count(id) != 0 || should_quit.load();
});
- if (should_quit.load()) break;
+ if (should_quit.load())
+ break;
found_in_cache = true; // Don't count it as a decode.
auto it = cache.find(id);
}
JPEGFrameView::JPEGFrameView(QWidget *parent)
- : QGLWidget(parent, global_share_widget) {
+ : QGLWidget(parent, global_share_widget)
+{
}
void JPEGFrameView::setFrame(unsigned stream_idx, int64_t pts, bool interpolated, int secondary_stream_idx, int64_t secondary_pts, float fade_alpha)
unique_lock<mutex> lock(cache_mu);
PendingDecode decode;
- decode.primary = JPEGID{ stream_idx, pts, interpolated };
- decode.secondary = JPEGID{ (unsigned)secondary_stream_idx, secondary_pts, /*interpolated=*/false };
+ if (interpolated && secondary_stream_idx != -1) {
+ // The frame will already be faded for us, so ask for only one; we shouldn't fade it against anything.
+ decode.primary = create_jpegid_for_interpolated_fade(stream_idx, pts, secondary_stream_idx, secondary_pts);
+ decode.secondary = JPEGID{ (unsigned)-1, -1, /*interpolated=*/false };
+ } else {
+ decode.primary = JPEGID{ stream_idx, pts, interpolated };
+ decode.secondary = JPEGID{ (unsigned)secondary_stream_idx, secondary_pts, /*interpolated=*/false };
+ }
decode.fade_alpha = fade_alpha;
decode.destination = this;
pending_decodes.push_back(decode);
any_pending_decodes.notify_all();
}
-void JPEGFrameView::insert_interpolated_frame(unsigned stream_idx, int64_t pts, shared_ptr<Frame> frame)
+void JPEGFrameView::insert_interpolated_frame(JPEGID id, shared_ptr<Frame> frame)
{
- JPEGID id{ stream_idx, pts, true };
-
// We rely on the frame not being evicted from the cache before
// jpeg_decoder_thread() sees it and can display it (otherwise,
// that thread would hang). With a default cache of 1000 elements,
namespace {
-
} // namespace
void JPEGFrameView::setDecodedFrame(shared_ptr<Frame> frame, shared_ptr<Frame> secondary_frame, float fade_alpha)