feat: integrate tactile stream decoding

This commit is contained in:
2025-10-24 17:15:53 +08:00
parent d819d40fe1
commit 1f65ba0114
32 changed files with 1284 additions and 5400 deletions

View File

@@ -1,9 +1,6 @@
//
// Simple FFmpeg-inspired serial decoding toolkit.
//
#pragma once
#include "components/ffmsep/cpdecoder.hh"
#include <cstdint>
#include <cstddef>
#include <mutex>
@@ -15,7 +12,6 @@
namespace ffmsep {
// Error codes loosely mirroring FFmpeg semantics.
inline constexpr int CP_SUCCESS = 0;
inline constexpr int CP_ERROR_EOF = -1;
inline constexpr int CP_ERROR_EAGAIN = -2;
@@ -24,15 +20,13 @@ inline constexpr int CP_ERROR_INVALID_STATE = -4;
inline constexpr int CP_ERROR_INVALID_ARGUMENT = -5;
enum class CPMediaType : std::uint8_t {
Unknown = 0,
Unknow = 0,
Data,
Audio,
Video
};
enum class CPCodecID : std::uint32_t {
Unknown = 0,
Tactile = 0x54514354u // 'T','Q','C','T' marker for tactile quick codec.
Unknow = 0,
Tactile = 0x54514354u // 'T','Q','C','T':触觉传感器协议标识 Tactile Quick Codec Type
};
struct CPPacket {
@@ -46,7 +40,7 @@ struct CPPacket {
CPPacket(std::vector<std::uint8_t> data, std::int64_t pts_value = 0, std::int64_t dts_value = 0) noexcept
: payload(std::move(data)), pts(pts_value), dts(dts_value) {}
[[nodiscard]] bool empty() const noexcept { return payload.empty(); }
[[nodiscard]] bool empty() const noexcept {return payload.empty();}
};
struct CPFrame {
@@ -57,24 +51,24 @@ struct CPFrame {
void reset() noexcept {
data.clear();
pts = 0;
key_frame = false;
valid = false;
pts = 0;
}
};
struct CPCodecContext;
struct CPCodec {
using InitFn = int (*)(CPCodecContext*);
using CloseFn = void (*)(CPCodecContext*);
using SendPacketFn = int (*)(CPCodecContext*, const CPPacket&);
using ReceiveFrameFn = int (*)(CPCodecContext*, CPFrame&);
using InitFn = int(*)(CPCodecContext*);
using CloseFn = void(*)(CPCodecContext*);
using SendPacketFn = int(*)(CPCodecContext*, const CPPacket&);
using ReceiveFrameFn = int(*)(CPCodecContext*, CPFrame&);
const char* name = nullptr;
const char* long_name = nullptr;
CPMediaType type = CPMediaType::Unknown;
CPCodecID id = CPCodecID::Unknown;
CPMediaType type = CPMediaType::Unknow;
CPCodecID id = CPCodecID::Unknow;
std::size_t priv_data_size = 0;
InitFn init = nullptr;
CloseFn close = nullptr;
@@ -85,13 +79,13 @@ struct CPCodec {
struct CPCodecContext {
const CPCodec* codec = nullptr;
void* priv_data = nullptr;
CPMediaType codec_type = CPMediaType::Unknown;
CPMediaType codec_type = CPMediaType::Unknow;
bool is_open = false;
void clear() noexcept {
codec = nullptr;
priv_data = nullptr;
codec_type = CPMediaType::Unknown;
codec_type = CPMediaType::Unknow;
is_open = false;
priv_storage.clear();
}
@@ -99,21 +93,20 @@ struct CPCodecContext {
void* ensure_priv_storage(std::size_t size);
void release_priv_storage() noexcept;
template <typename T>
template<typename T>
[[nodiscard]] T* priv_as() noexcept {
return static_cast<T*>(priv_data);
}
template <typename T>
template<typename T>
[[nodiscard]] const T* priv_as() const noexcept {
return static_cast<const T*>(priv_data);
}
private:
std::vector<std::uint8_t> priv_storage;
friend CPCodecContext* cpcodec_alloc_context3(const CPCodec*);
friend int cpcodec_open2(CPCodecContext*, const CPCodec*);
friend CPCodecContext* cpcodec_alloc_context(const CPCodec*);
friend int cpcodec_open(CPCodecContext*, const CPCodec*);
friend int cpcodec_close(CPCodecContext*);
};
@@ -123,11 +116,10 @@ const CPCodec* cpcodec_find_decoder(CPCodecID id);
const CPCodec* cpcodec_find_decoder_by_name(std::string_view name);
std::vector<const CPCodec*> cpcodec_list_codecs();
CPCodecContext* cpcodec_alloc_context3(const CPCodec* codec);
int cpcodec_open2(CPCodecContext* ctx, const CPCodec* codec = nullptr);
int cpcodec_close(CPCodecContext* ctx);
void cpcodec_free_context(CPCodecContext** ctx);
int cpcodec_send_packet(CPCodecContext* ctx, const CPPacket* packet);
int cpcodec_receive_frame(CPCodecContext* ctx, CPFrame* frame);
} // namespace ffmsep
CPCodecContext* cpcodec_alloc_context(const CPCodec* codec);
int cpcodec_open(CPCodecContext*, const CPCodec*);
int cpcodec_close(CPCodecContext*);
void cpcodec_free_context(CPCodecContext **ctx);
int cpcodec_send_packet(CPCodecContext*, const CPPacket*);
int cpcodec_receive_frame(CPCodecContext*, CPFrame*);
}