feat(codec): implement software H.264 encode/decode round-trip
Add FFmpeg-based encoder/decoder with SPS/PPS extradata, Annex-B output normalization, low-latency libx264 settings, and a round-trip unit test. Includes review hardening: cached SwsContext, bitrate-only rate control, std::byte/uin8_t cast helpers, and richer test assertions.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <variant>
|
||||
|
||||
namespace sc {
|
||||
|
||||
struct CodecError {
|
||||
std::string message;
|
||||
};
|
||||
|
||||
// C++20 does not provide std::expected. Use a variant-based result type so
|
||||
// fallible codec operations do not rely on exceptions.
|
||||
template <typename T> using CodecResult = std::variant<T, CodecError>;
|
||||
|
||||
template <typename T> constexpr bool is_codec_error(const CodecResult<T>& result) noexcept {
|
||||
return std::holds_alternative<CodecError>(result);
|
||||
}
|
||||
|
||||
template <typename T> T& codec_value(CodecResult<T>& result) {
|
||||
return std::get<T>(result);
|
||||
}
|
||||
|
||||
template <typename T> const T& codec_value(const CodecResult<T>& result) {
|
||||
return std::get<T>(result);
|
||||
}
|
||||
|
||||
template <typename T> CodecError& codec_error(CodecResult<T>& result) {
|
||||
return std::get<CodecError>(result);
|
||||
}
|
||||
|
||||
template <typename T> const CodecError& codec_error(const CodecResult<T>& result) {
|
||||
return std::get<CodecError>(result);
|
||||
}
|
||||
|
||||
} // namespace sc
|
||||
Reference in New Issue
Block a user