2023-09-27 15:45:31 -07:00
|
|
|
#pragma once
|
|
|
|
|
2025-01-29 09:09:58 +00:00
|
|
|
// has to be in this order
|
|
|
|
#ifdef __linux__
|
|
|
|
#include "third_party/linux/include/v4l2-controls.h"
|
|
|
|
#include <linux/videodev2.h>
|
|
|
|
#else
|
|
|
|
#define V4L2_BUF_FLAG_KEYFRAME 8
|
|
|
|
#endif
|
|
|
|
|
2023-09-27 15:45:31 -07:00
|
|
|
#include <cassert>
|
|
|
|
#include <cstdint>
|
2023-11-17 23:53:40 +00:00
|
|
|
#include <memory>
|
2023-09-27 15:45:31 -07:00
|
|
|
#include <thread>
|
2024-02-21 23:02:43 +00:00
|
|
|
#include <vector>
|
2023-09-27 15:45:31 -07:00
|
|
|
|
|
|
|
#include "cereal/messaging/messaging.h"
|
2024-06-11 01:36:40 +00:00
|
|
|
#include "msgq/visionipc/visionipc.h"
|
2023-09-27 15:45:31 -07:00
|
|
|
#include "common/queue.h"
|
|
|
|
#include "system/loggerd/loggerd.h"
|
|
|
|
|
|
|
|
class VideoEncoder {
|
|
|
|
public:
|
|
|
|
VideoEncoder(const EncoderInfo &encoder_info, int in_width, int in_height);
|
2023-11-17 23:53:40 +00:00
|
|
|
virtual ~VideoEncoder() {}
|
2023-09-27 15:45:31 -07:00
|
|
|
virtual int encode_frame(VisionBuf* buf, VisionIpcBufExtra *extra) = 0;
|
|
|
|
virtual void encoder_open(const char* path) = 0;
|
|
|
|
virtual void encoder_close() = 0;
|
|
|
|
|
2025-01-29 09:09:58 +00: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);
|
2023-09-27 15:45:31 -07:00
|
|
|
|
|
|
|
protected:
|
2024-06-11 01:36:40 +00:00
|
|
|
void publish_thumbnail(uint32_t frame_id, uint64_t timestamp_eof, kj::ArrayPtr<capnp::byte> dat);
|
|
|
|
|
2023-09-27 15:45:31 -07:00
|
|
|
int in_width, in_height;
|
2024-02-21 23:02:43 +00:00
|
|
|
int out_width, out_height;
|
2023-09-27 15:45:31 -07:00
|
|
|
const EncoderInfo encoder_info;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// total frames encoded
|
|
|
|
int cnt = 0;
|
|
|
|
std::unique_ptr<PubMaster> pm;
|
2024-02-21 23:02:43 +00:00
|
|
|
std::vector<capnp::byte> msg_cache;
|
2023-09-27 15:45:31 -07:00
|
|
|
};
|