PassengerStatistics/Main/VideoInput.h

44 lines
992 B
C
Raw Permalink Normal View History

2024-03-13 11:40:55 +08:00
#ifndef __VIDEOINPUT_H__
#define __VIDEOINPUT_H__
2024-03-13 18:01:36 +08:00
#include <fstream>
2024-03-13 11:40:55 +08:00
#include <functional>
2024-03-25 00:09:33 +08:00
#include <memory>
2024-03-13 11:40:55 +08:00
#include <string>
#include <thread>
2024-03-13 18:01:36 +08:00
class VideoInputPrivate;
2024-03-13 11:40:55 +08:00
class VideoInput {
public:
using PacketHandler = std::function<void(const uint8_t *, uint32_t)>;
VideoInput(int32_t width, int32_t height);
~VideoInput();
bool start();
void stop();
bool isStarted() const;
bool startEncode();
2024-03-13 18:01:36 +08:00
bool startFileInput(const std::string &path, int32_t width, int32_t height);
2024-03-13 11:40:55 +08:00
void setPacketHandler(const PacketHandler &hanlder);
protected:
void run();
2024-03-13 18:01:36 +08:00
void fakeRun();
2024-03-13 11:40:55 +08:00
void encodeRun();
private:
2024-03-13 18:01:36 +08:00
VideoInputPrivate *m_d = nullptr;
2024-03-13 11:40:55 +08:00
int32_t m_width;
int32_t m_height;
2024-03-13 18:01:36 +08:00
std::string m_path;
std::shared_ptr<std::ifstream> m_ifs;
2024-03-13 11:40:55 +08:00
int32_t m_vid = -1;
2024-03-13 18:01:36 +08:00
int32_t m_decodeChannel = -1;
2024-03-13 11:40:55 +08:00
bool m_exit = true;
std::thread m_thread;
std::thread m_encodeThread;
PacketHandler m_handler;
};
#endif // __VIDEOINPUT_H__