1 #ifndef _JPEG_FRAME_VIEW_H
2 #define _JPEG_FRAME_VIEW_H 1
4 #include "jpeg_frame.h"
5 #include "ycbcr_converter.h"
10 #include <movit/effect_chain.h>
11 #include <movit/flat_input.h>
12 #include <movit/mix_effect.h>
13 #include <movit/ycbcr_input.h>
21 enum CacheMissBehavior {
22 DECODE_IF_NOT_IN_CACHE,
23 RETURN_NULLPTR_IF_NOT_IN_CACHE
26 std::string filename_for_frame(unsigned stream_idx, int64_t pts);
27 std::shared_ptr<Frame> decode_jpeg(const std::string &filename);
28 std::shared_ptr<Frame> decode_jpeg_with_cache(JPEGID id, CacheMissBehavior cache_miss_behavior, bool *did_decode);
30 class JPEGFrameView : public QGLWidget {
34 JPEGFrameView(QWidget *parent);
36 void setFrame(unsigned stream_idx, int64_t pts, int secondary_stream_idx = -1, int64_t secondary_pts = -1, float fade_alpha = 0.0f);
37 void setFrame(std::shared_ptr<Frame> frame);
39 void mousePressEvent(QMouseEvent *event) override;
41 unsigned get_stream_idx() const { return current_stream_idx; }
43 void setDecodedFrame(std::shared_ptr<Frame> frame, std::shared_ptr<Frame> secondary_frame, float fade_alpha);
44 void set_overlay(const std::string &text); // Blank for none.
46 static void shutdown();
52 void initializeGL() override;
53 void resizeGL(int width, int height) override;
54 void paintGL() override;
57 // The stream index of the latest frame we displayed.
58 unsigned current_stream_idx = 0;
60 std::unique_ptr<YCbCrConverter> ycbcr_converter;
61 movit::EffectChain *current_chain = nullptr; // Owned by ycbcr_converter.
63 std::shared_ptr<Frame> current_frame; // So that we hold on to the pixels.
64 std::shared_ptr<Frame> current_secondary_frame; // Same.
66 static constexpr int overlay_base_width = 16, overlay_base_height = 16;
67 int overlay_width = overlay_base_width, overlay_height = overlay_base_height;
68 std::unique_ptr<QImage> overlay_image; // If nullptr, no overlay.
69 std::unique_ptr<movit::EffectChain> overlay_chain; // Just to get the overlay on screen in the easiest way possible.
70 movit::FlatInput *overlay_input;
71 bool overlay_input_needs_refresh = false;
73 int gl_width, gl_height;
75 static std::thread jpeg_decoder_thread;
78 #endif // !defined(_JPEG_FRAME_VIEW_H)