]> git.sesse.net Git - nageru/blob - jpeg_frame_view.h
Decode 4:2:2 JPEGs via VA-API if available.
[nageru] / jpeg_frame_view.h
1 #ifndef _JPEG_FRAME_VIEW_H
2 #define _JPEG_FRAME_VIEW_H 1
3
4 #include <epoxy/gl.h>
5 #include <QGLWidget>
6
7 #include <stdint.h>
8
9 #include <movit/effect_chain.h>
10 #include <movit/flat_input.h>
11 #include <movit/ycbcr_input.h>
12
13 #include <memory>
14
15 #include "jpeg_frame.h"
16
17 struct JPEGID {
18         unsigned stream_idx;
19         int64_t pts;
20         bool interpolated;
21 };
22 enum CacheMissBehavior {
23         DECODE_IF_NOT_IN_CACHE,
24         RETURN_NULLPTR_IF_NOT_IN_CACHE
25 };
26
27 std::string filename_for_frame(unsigned stream_idx, int64_t pts);
28 std::shared_ptr<Frame> decode_jpeg(const std::string &filename);
29 std::shared_ptr<Frame> decode_jpeg_with_cache(JPEGID id, CacheMissBehavior cache_miss_behavior, bool *did_decode);
30
31 class JPEGFrameView : public QGLWidget {
32         Q_OBJECT
33
34 public:
35         JPEGFrameView(QWidget *parent);
36
37         void setFrame(unsigned stream_idx, int64_t pts, bool interpolated);
38         static void insert_interpolated_frame(unsigned stream_idx, int64_t pts, std::shared_ptr<Frame> frame);
39
40         void mousePressEvent(QMouseEvent *event) override;
41
42         unsigned get_stream_idx() const { return current_stream_idx; }
43
44         void setDecodedFrame(std::shared_ptr<Frame> frame);
45         void set_overlay(const std::string &text);  // Blank for none.
46
47 signals:
48         void clicked();
49
50 protected:
51         void initializeGL() override;
52         void resizeGL(int width, int height) override;
53         void paintGL() override;
54
55 private:
56         // The stream index of the latest frame we displayed.
57         unsigned current_stream_idx = 0;
58
59         std::unique_ptr<movit::EffectChain> planar_chain;
60         std::shared_ptr<Frame> current_frame;  // So that we hold on to the pixels.
61         movit::YCbCrInput *ycbcr_planar_input;
62         movit::YCbCrFormat ycbcr_format;
63
64         std::unique_ptr<movit::EffectChain> semiplanar_chain;
65         movit::YCbCrInput *ycbcr_semiplanar_input;
66
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;
73
74         int gl_width, gl_height;
75 };
76
77 #endif  // !defined(_JPEG_FRAME_VIEW_H)