]> git.sesse.net Git - nageru/blobdiff - ffmpeg_capture.h
Expose choosing video pixel format to Lua.
[nageru] / ffmpeg_capture.h
index 9753c0032f37ae184a91786335bb04534be9413c..e20f24cb5f6fdd965ac19eb5826c8b6085f6f035 100644 (file)
@@ -6,7 +6,7 @@
 // FFmpeg (thus the name), this means it can handle a very wide array of video
 // formats, and also things like network streaming and V4L capture, but it is
 // also significantly less integrated and optimized than the regular capture
-// cards.  In particular, the frames are always scaled and converted to 8-bit
+// cards. In particular, the frames are always scaled and converted to 8-bit
 // RGBA on the CPU before being sent on to the GPU.
 //
 // Since we don't really know much about the video when building the chains,
@@ -29,6 +29,8 @@
 #include <string>
 #include <thread>
 
+#include <movit/ycbcr.h>
+
 #include "bmusb/bmusb.h"
 #include "quittable_sleeper.h"
 
@@ -93,6 +95,14 @@ public:
                frame_callback = callback;
        }
 
+       // Used to get precise information about the Y'CbCr format used
+       // for a given frame. Only valid to call during the frame callback,
+       // and only when receiving a frame with pixel format PixelFormat_8BitYCbCrPlanar.
+       movit::YCbCrFormat get_current_frame_ycbcr_format() const
+       {
+               return current_frame_ycbcr_format;
+       }
+
        void set_dequeue_thread_callbacks(std::function<void()> init, std::function<void()> cleanup) override
        {
                dequeue_init_callback = init;
@@ -108,22 +118,20 @@ public:
        void configure_card() override;
        void start_bm_capture() override;
        void stop_dequeue_thread() override;
-
-       // TODO: Specify error status through this.
-       bool get_disconnected() const override { return false; }
+       bool get_disconnected() const override { return false; }  // We never unplug.
 
        std::map<uint32_t, bmusb::VideoMode> get_available_video_modes() const;
        void set_video_mode(uint32_t video_mode_id) override {}  // Ignore.
        uint32_t get_current_video_mode() const override { return 0; }
 
        std::set<bmusb::PixelFormat> get_available_pixel_formats() const override {
-               return std::set<bmusb::PixelFormat>{ bmusb::PixelFormat_8BitBGRA };
+               return std::set<bmusb::PixelFormat>{ bmusb::PixelFormat_8BitBGRA, bmusb::PixelFormat_8BitYCbCrPlanar };
        }
        void set_pixel_format(bmusb::PixelFormat pixel_format) override {
-               assert(pixel_format == bmusb::PixelFormat_8BitBGRA);
+               this->pixel_format = pixel_format;
        }       
        bmusb::PixelFormat get_current_pixel_format() const override {
-               return bmusb::PixelFormat_8BitBGRA;
+               return pixel_format;
        }
 
        std::map<uint32_t, std::string> get_available_video_inputs() const override {
@@ -139,12 +147,15 @@ public:
 
 private:
        void producer_thread_func();
+       void send_disconnected_frame();
        bool play_video(const std::string &pathname);
        void internal_rewind();
 
        std::string description, filename;
        uint16_t timecode = 0;
        unsigned width, height;
+       bmusb::PixelFormat pixel_format = bmusb::PixelFormat_8BitBGRA;
+       movit::YCbCrFormat current_frame_ycbcr_format;
        bool running = false;
        int card_index = -1;