]> git.sesse.net Git - nageru/blob - jpeg_frame_view.h
Show interpolated frames in the live window.
[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/ycbcr_input.h>
11
12 #include <memory>
13
14 struct JPEGID {
15         unsigned stream_idx;
16         int64_t pts;
17         bool interpolated;
18 };
19 struct Frame {
20         std::unique_ptr<uint8_t[]> y, cb, cr;
21         unsigned width, height;
22         unsigned chroma_subsampling_x, chroma_subsampling_y;
23         unsigned pitch_y, pitch_chroma;
24 };
25 enum CacheMissBehavior {
26         DECODE_IF_NOT_IN_CACHE,
27         RETURN_NULLPTR_IF_NOT_IN_CACHE
28 };
29
30 std::string filename_for_frame(unsigned stream_idx, int64_t pts);
31 std::shared_ptr<Frame> decode_jpeg(const std::string &filename);
32 std::shared_ptr<Frame> decode_jpeg_with_cache(JPEGID id, CacheMissBehavior cache_miss_behavior, bool *did_decode);
33
34 class JPEGFrameView : public QGLWidget {
35         Q_OBJECT
36
37 public:
38         JPEGFrameView(QWidget *parent);
39
40         void setFrame(unsigned stream_idx, int64_t pts, bool interpolated);
41         static void insert_interpolated_frame(unsigned stream_idx, int64_t pts, std::shared_ptr<Frame> frame);
42
43         void mousePressEvent(QMouseEvent *event) override;
44
45         unsigned get_stream_idx() const { return current_stream_idx; }
46
47         void setDecodedFrame(std::shared_ptr<Frame> frame);
48
49
50 signals:
51         void clicked();
52
53 protected:
54         void initializeGL() override;
55         void resizeGL(int width, int height) override;
56         void paintGL() override;
57
58 private:
59         // The stream index of the latest frame we displayed.
60         unsigned current_stream_idx;
61
62         std::unique_ptr<movit::EffectChain> chain;
63         std::shared_ptr<Frame> current_frame;  // So that we hold on to the pixels.
64         movit::YCbCrInput *ycbcr_input;
65         movit::YCbCrFormat ycbcr_format;
66 };
67
68 #endif  // !defined(_JPEG_FRAME_VIEW_H)