]> git.sesse.net Git - nageru/blobdiff - nageru/mjpeg_encoder.h
When uploading MJPEG data to VA-API, do it directly into the buffer.
[nageru] / nageru / mjpeg_encoder.h
index 8b68294a48d9e01dfd0254b213b2770d57e0330d..b7b20431825b3fabffcf5da22f97c6ced4b5bb5d 100644 (file)
@@ -27,6 +27,12 @@ struct jpeg_compress_struct;
 struct VADisplayWithCleanup;
 struct VectorDestinationManager;
 
+#define CHECK_VASTATUS(va_status, func)                                 \
+    if (va_status != VA_STATUS_SUCCESS) {                               \
+        fprintf(stderr, "%s:%d (%s) failed with %d\n", __func__, __LINE__, func, va_status); \
+        exit(1);                                                        \
+    }
+
 class MJPEGEncoder {
 public:
        MJPEGEncoder(HTTPD *httpd, const std::string &va_display);
@@ -34,6 +40,16 @@ public:
        void stop();
        void upload_frame(int64_t pts, unsigned card_index, RefCountedFrame frame, const bmusb::VideoFormat &video_format, size_t y_offset, size_t cbcr_offset);
 
+       // If the frame was started (data_copy != nullptr) but will not be finished
+       // (MJPEG decoding was turned off in the meantime), you'll need to call finish_frame()
+       // to release any VA-API resources.
+       void finish_frame(RefCountedFrame frame);
+
+       bool using_vaapi() const { return va_dpy != nullptr; }
+
+       // Returns -1 for inactive (ie., don't encode frames for this card right now).
+       int get_mjpeg_stream_for_card(unsigned card_index);
+
 private:
        static constexpr int quality = 90;
 
@@ -153,6 +169,8 @@ private:
        std::atomic<int64_t> metric_mjpeg_frames_oversized_dropped{0};
        std::atomic<int64_t> metric_mjpeg_overrun_dropped{0};
        std::atomic<int64_t> metric_mjpeg_overrun_submitted{0};
+
+       friend class PBOFrameAllocator;  // FIXME
 };
 
 #endif  // !defined(_MJPEG_ENCODER_H)