2022-05-10 15:20:51 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
2024-09-18 21:10:45 -07:00
|
|
|
// has to be in this order
|
2024-09-18 22:16:25 -07:00
|
|
|
#ifdef __linux__
|
2024-09-18 21:10:45 -07:00
|
|
|
#include "third_party/linux/include/v4l2-controls.h"
|
|
|
|
|
#include <linux/videodev2.h>
|
2024-09-18 22:16:25 -07:00
|
|
|
#else
|
|
|
|
|
#define V4L2_BUF_FLAG_KEYFRAME 8
|
|
|
|
|
#endif
|
2024-09-18 21:10:45 -07:00
|
|
|
|
2022-05-10 15:20:51 -07:00
|
|
|
#include <cassert>
|
|
|
|
|
#include <cstdint>
|
2023-08-24 04:25:17 +08:00
|
|
|
#include <memory>
|
2022-05-10 15:20:51 -07:00
|
|
|
#include <thread>
|
2023-12-13 11:15:47 +08:00
|
|
|
#include <vector>
|
2022-05-10 15:20:51 -07:00
|
|
|
|
|
|
|
|
#include "cereal/messaging/messaging.h"
|
2024-06-06 14:31:56 -07:00
|
|
|
#include "msgq/visionipc/visionipc.h"
|
2022-05-18 14:11:57 -07:00
|
|
|
#include "common/queue.h"
|
2023-07-16 01:39:40 +08:00
|
|
|
#include "system/loggerd/loggerd.h"
|
2022-05-10 15:20:51 -07:00
|
|
|
|
|
|
|
|
class VideoEncoder {
|
|
|
|
|
public:
|
2023-07-18 10:25:41 +08:00
|
|
|
VideoEncoder(const EncoderInfo &encoder_info, int in_width, int in_height);
|
2023-08-24 01:13:46 +08:00
|
|
|
virtual ~VideoEncoder() {}
|
2022-06-01 08:18:28 -07:00
|
|
|
virtual int encode_frame(VisionBuf* buf, VisionIpcBufExtra *extra) = 0;
|
2025-02-21 10:41:30 -08:00
|
|
|
virtual void encoder_open() = 0;
|
2022-05-10 15:20:51 -07:00
|
|
|
virtual void encoder_close() = 0;
|
|
|
|
|
|
2025-01-13 03:38:20 +08:00
|
|
|
void publisher_publish(int segment_num, uint32_t idx, VisionIpcBufExtra &extra, unsigned int flags, kj::ArrayPtr<capnp::byte> header, kj::ArrayPtr<capnp::byte> dat);
|
2022-05-10 15:20:51 -07:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
int in_width, in_height;
|
2024-02-02 12:53:12 -08:00
|
|
|
int out_width, out_height;
|
2023-07-16 01:39:40 +08:00
|
|
|
const EncoderInfo encoder_info;
|
2022-05-10 15:20:51 -07:00
|
|
|
|
|
|
|
|
private:
|
2022-05-13 17:56:02 -07:00
|
|
|
// total frames encoded
|
|
|
|
|
int cnt = 0;
|
2022-05-10 15:20:51 -07:00
|
|
|
std::unique_ptr<PubMaster> pm;
|
2023-12-13 11:15:47 +08:00
|
|
|
std::vector<capnp::byte> msg_cache;
|
2022-05-10 15:20:51 -07:00
|
|
|
};
|