fix: port OmxEncoder safety fixes from upstream FrogPilot
- OMX_Init/OMX_Deinit managed per encoder instance lifecycle - Proper error handling in constructor, encoder_open, encoder_close - Null guards on done_out.pop() and handle in destructor - Codec config written directly to codecpar (no codec_ctx) - ffmpeg faststart remux on segment close - Crash handler in dashcamd for diagnostics - DashcamFrames param for live frame count in status window Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -12,10 +12,10 @@ extern "C" {
|
||||
|
||||
#include "common/queue.h"
|
||||
|
||||
// OmxEncoder, lossey codec using hardware hevc
|
||||
// OmxEncoder, lossey codec using hardware H.264
|
||||
class OmxEncoder {
|
||||
public:
|
||||
OmxEncoder(const char* path, int width, int height, int fps, int bitrate, bool h265, bool downscale);
|
||||
OmxEncoder(const char* path, int width, int height, int fps, int bitrate);
|
||||
~OmxEncoder();
|
||||
|
||||
int encode_frame_rgba(const uint8_t *ptr, int in_width, int in_height, uint64_t ts);
|
||||
@@ -44,31 +44,26 @@ private:
|
||||
int counter = 0;
|
||||
|
||||
std::string path;
|
||||
FILE *of;
|
||||
FILE *of = nullptr;
|
||||
|
||||
size_t codec_config_len;
|
||||
uint8_t *codec_config = NULL;
|
||||
bool wrote_codec_config;
|
||||
size_t codec_config_len = 0;
|
||||
uint8_t *codec_config = nullptr;
|
||||
bool wrote_codec_config = false;
|
||||
|
||||
std::mutex state_lock;
|
||||
std::condition_variable state_cv;
|
||||
OMX_STATETYPE state = OMX_StateLoaded;
|
||||
|
||||
OMX_HANDLETYPE handle;
|
||||
OMX_HANDLETYPE handle = nullptr;
|
||||
|
||||
std::vector<OMX_BUFFERHEADERTYPE *> in_buf_headers;
|
||||
std::vector<OMX_BUFFERHEADERTYPE *> out_buf_headers;
|
||||
|
||||
uint64_t last_t;
|
||||
uint64_t last_t = 0;
|
||||
|
||||
SafeQueue<OMX_BUFFERHEADERTYPE *> free_in;
|
||||
SafeQueue<OMX_BUFFERHEADERTYPE *> done_out;
|
||||
|
||||
AVFormatContext *ofmt_ctx;
|
||||
AVCodecContext *codec_ctx;
|
||||
AVStream *out_stream;
|
||||
bool remuxing;
|
||||
|
||||
bool downscale;
|
||||
uint8_t *y_ptr2, *u_ptr2, *v_ptr2;
|
||||
AVFormatContext *ofmt_ctx = nullptr;
|
||||
AVStream *out_stream = nullptr;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user