1 #ifndef _JPEG_FRAME_VIEW_H
2 #define _JPEG_FRAME_VIEW_H 1
4 #include "frame_on_disk.h"
5 #include "jpeg_frame.h"
6 #include "ycbcr_converter.h"
11 #include <movit/effect_chain.h>
12 #include <movit/flat_input.h>
13 #include <movit/mix_effect.h>
14 #include <movit/ycbcr_input.h>
18 enum CacheMissBehavior {
19 DECODE_IF_NOT_IN_CACHE,
20 RETURN_NULLPTR_IF_NOT_IN_CACHE
23 std::shared_ptr<Frame> decode_jpeg(const std::string &jpeg);
24 std::shared_ptr<Frame> decode_jpeg_with_cache(FrameOnDisk id, CacheMissBehavior cache_miss_behavior, FrameReader *frame_reader, bool *did_decode);
25 std::shared_ptr<Frame> get_black_frame();
27 class JPEGFrameView : public QGLWidget {
31 JPEGFrameView(QWidget *parent);
33 void setFrame(unsigned stream_idx, FrameOnDisk frame, FrameOnDisk secondary_frame = {}, float fade_alpha = 0.0f);
34 void setFrame(std::shared_ptr<Frame> frame);
36 void mousePressEvent(QMouseEvent *event) override;
38 unsigned get_stream_idx() const { return current_stream_idx; }
40 void setDecodedFrame(std::shared_ptr<Frame> frame, std::shared_ptr<Frame> secondary_frame, float fade_alpha);
41 void set_overlay(const std::string &text); // Blank for none.
43 static void shutdown();
49 void initializeGL() override;
50 void resizeGL(int width, int height) override;
51 void paintGL() override;
54 static void jpeg_decoder_thread_func();
56 FrameReader frame_reader;
58 // The stream index of the latest frame we displayed.
59 unsigned current_stream_idx = 0;
61 std::unique_ptr<YCbCrConverter> ycbcr_converter;
62 movit::EffectChain *current_chain = nullptr; // Owned by ycbcr_converter.
64 std::shared_ptr<Frame> current_frame; // So that we hold on to the pixels.
65 std::shared_ptr<Frame> current_secondary_frame; // Same.
67 static constexpr int overlay_base_width = 16, overlay_base_height = 16;
68 int overlay_width = overlay_base_width, overlay_height = overlay_base_height;
69 std::unique_ptr<QImage> overlay_image; // If nullptr, no overlay.
70 std::unique_ptr<movit::EffectChain> overlay_chain; // Just to get the overlay on screen in the easiest way possible.
71 movit::FlatInput *overlay_input;
72 bool overlay_input_needs_refresh = false;
74 int gl_width, gl_height;
76 static std::thread jpeg_decoder_thread;
79 #endif // !defined(_JPEG_FRAME_VIEW_H)