style: unify identifier naming per updated conventions
Automated with clang-tidy readability-identifier-naming (config added to .clang-tidy) plus scripted passes, per the updated rules now documented in CONTRIBUTING.md: - types (class/struct/enum/alias/template params): PascalCase - functions, variables, members: snake_case (incl. rational -> Rational) - private/protected members: trailing underscore; static member variables likewise (instance_, available_themes_) - constants and enum values: snake_case (kLinear -> k_linear, F32P -> f32p); ALL_CAPS reserved for macros - macros: OAK_ prefix (OLIVE_ADD_TEST/OLIVE_ASSERT/OLIVE_CONFIG -> OAK_ADD_TEST/OAK_ASSERT/OAK_CONFIG, GL_PREAMBLE -> OAK_GL_PREAMBLE, include guards -> OAK_*) - file names: all lowercase (Current/Plugin/OliveHost/OliveClip/ OlivePluginInstance -> current/plugin/olivehost/oliveclip/ oliveplugininstance) - getters share the member name sans underscore, setters set_foo() - Qt and third-party (OpenFX) virtual overrides and framework callbacks keep their original names (exempt in .clang-tidy) Manual follow-ups required where automation could not reach: - string-based QMetaObject/SIGNAL/SLOT references updated to renamed methods (AddTask, CreatedFile, DeleteSpecificFile, moveSelectionUp, ...) - macro bodies referencing renamed methods (OLIVE_CONFIG, NODE_DEFAULT_DESTRUCTOR, MANAGEDDISPLAYWIDGET_*) - self-shadowing locals renamed where signals/methods became same-named (size_changed, worker_count, selected_items, import param, filters) - third_party OFX member/namespace usages restored (OFX::Host::*, _created, _clipPrefsDirty, createInstance, clearPersistentMessage) - STL protocol aliases restored (const_iterator) with .clang-tidy ignore rules; qHash overloads restored Full build and test suite pass: ctest 4/4, ~1960 gtest cases green.
This commit is contained in:
@@ -19,8 +19,8 @@
|
||||
|
||||
***/
|
||||
|
||||
#ifndef FFMPEG_BRIDGE_H
|
||||
#define FFMPEG_BRIDGE_H
|
||||
#ifndef OAK_FFMPEG_BRIDGE_H
|
||||
#define OAK_FFMPEG_BRIDGE_H
|
||||
|
||||
/**
|
||||
* ffmpeg_bridge - pure C API isolating all FFmpeg access from the editor.
|
||||
@@ -77,94 +77,94 @@ extern "C" {
|
||||
* format has no entry here receive an opaque process-local id >= 1000.
|
||||
*/
|
||||
typedef enum FBPixelFormat {
|
||||
FB_PIX_FMT_NONE = -1,
|
||||
FB_PIX_FMT_YUV420P = 0,
|
||||
FB_PIX_FMT_RGB24 = 2,
|
||||
FB_PIX_FMT_YUV422P = 4,
|
||||
FB_PIX_FMT_YUV444P = 5,
|
||||
FB_PIX_FMT_YUV410P = 6,
|
||||
FB_PIX_FMT_YUV411P = 7,
|
||||
FB_PIX_FMT_GRAY8 = 8,
|
||||
FB_PIX_FMT_YUVJ420P = 12,
|
||||
FB_PIX_FMT_YUVJ422P = 13,
|
||||
FB_PIX_FMT_YUVJ444P = 14,
|
||||
FB_PIX_FMT_NV12 = 23,
|
||||
FB_PIX_FMT_RGBA = 26,
|
||||
FB_PIX_FMT_GRAY16LE = 30,
|
||||
FB_PIX_FMT_YUV440P = 31,
|
||||
FB_PIX_FMT_YUVJ440P = 32,
|
||||
FB_PIX_FMT_RGB48LE = 35,
|
||||
FB_PIX_FMT_YUV420P10LE = 62,
|
||||
FB_PIX_FMT_YUV422P10LE = 64,
|
||||
FB_PIX_FMT_YUV444P10LE = 68,
|
||||
FB_PIX_FMT_RGBA64LE = 105,
|
||||
FB_PIX_FMT_YUV420P12LE = 123,
|
||||
FB_PIX_FMT_YUV422P12LE = 127,
|
||||
FB_PIX_FMT_YUV444P12LE = 131,
|
||||
FB_PIX_FMT_YUVJ411P = 138,
|
||||
FB_PIX_FMT_P010LE = 158,
|
||||
FB_PIX_FMT_GRAYF32LE = 183,
|
||||
FB_PIX_FMT_RGBAF16LE = 207,
|
||||
FB_PIX_FMT_RGBF32LE = 218,
|
||||
FB_PIX_FMT_RGBAF32LE = 220,
|
||||
FB_PIX_FMT_RGBF16LE = 234,
|
||||
FB_PIX_FMT_GRAYF16LE = 248
|
||||
fb_pix_fmt_none = -1,
|
||||
fb_pix_fmt_yu_v420_p = 0,
|
||||
fb_pix_fmt_rg_b24 = 2,
|
||||
fb_pix_fmt_yu_v422_p = 4,
|
||||
fb_pix_fmt_yu_v444_p = 5,
|
||||
fb_pix_fmt_yu_v410_p = 6,
|
||||
fb_pix_fmt_yu_v411_p = 7,
|
||||
fb_pix_fmt_gra_y8 = 8,
|
||||
fb_pix_fmt_yuv_j420_p = 12,
|
||||
fb_pix_fmt_yuv_j422_p = 13,
|
||||
fb_pix_fmt_yuv_j444_p = 14,
|
||||
fb_pix_fmt_n_v12 = 23,
|
||||
fb_pix_fmt_rgba = 26,
|
||||
fb_pix_fmt_gra_y16_le = 30,
|
||||
fb_pix_fmt_yu_v440_p = 31,
|
||||
fb_pix_fmt_yuv_j440_p = 32,
|
||||
fb_pix_fmt_rg_b48_le = 35,
|
||||
fb_pix_fmt_yu_v420_p10_le = 62,
|
||||
fb_pix_fmt_yu_v422_p10_le = 64,
|
||||
fb_pix_fmt_yu_v444_p10_le = 68,
|
||||
fb_pix_fmt_rgb_a64_le = 105,
|
||||
fb_pix_fmt_yu_v420_p12_le = 123,
|
||||
fb_pix_fmt_yu_v422_p12_le = 127,
|
||||
fb_pix_fmt_yu_v444_p12_le = 131,
|
||||
fb_pix_fmt_yuv_j411_p = 138,
|
||||
fb_pix_fmt_p010_le = 158,
|
||||
fb_pix_fmt_gray_f32_le = 183,
|
||||
fb_pix_fmt_rgba_f16_le = 207,
|
||||
fb_pix_fmt_rgb_f32_le = 218,
|
||||
fb_pix_fmt_rgba_f32_le = 220,
|
||||
fb_pix_fmt_rgb_f16_le = 234,
|
||||
fb_pix_fmt_gray_f16_le = 248
|
||||
} FBPixelFormat;
|
||||
|
||||
/**
|
||||
* Sample formats. Values mirror AVSampleFormat (static_assert'ed).
|
||||
*/
|
||||
typedef enum FBSampleFormat {
|
||||
FB_SAMPLE_FMT_NONE = -1,
|
||||
FB_SAMPLE_FMT_U8 = 0,
|
||||
FB_SAMPLE_FMT_S16 = 1,
|
||||
FB_SAMPLE_FMT_S32 = 2,
|
||||
FB_SAMPLE_FMT_FLT = 3,
|
||||
FB_SAMPLE_FMT_DBL = 4,
|
||||
FB_SAMPLE_FMT_U8P = 5,
|
||||
FB_SAMPLE_FMT_S16P = 6,
|
||||
FB_SAMPLE_FMT_S32P = 7,
|
||||
FB_SAMPLE_FMT_FLTP = 8,
|
||||
FB_SAMPLE_FMT_DBLP = 9,
|
||||
FB_SAMPLE_FMT_S64 = 10,
|
||||
FB_SAMPLE_FMT_S64P = 11
|
||||
fb_sample_fmt_none = -1,
|
||||
fb_sample_fmt_u8 = 0,
|
||||
fb_sample_fmt_s16 = 1,
|
||||
fb_sample_fmt_s32 = 2,
|
||||
fb_sample_fmt_flt = 3,
|
||||
fb_sample_fmt_dbl = 4,
|
||||
fb_sample_fmt_u8_p = 5,
|
||||
fb_sample_fmt_s16_p = 6,
|
||||
fb_sample_fmt_s32_p = 7,
|
||||
fb_sample_fmt_fltp = 8,
|
||||
fb_sample_fmt_dblp = 9,
|
||||
fb_sample_fmt_s64 = 10,
|
||||
fb_sample_fmt_s64_p = 11
|
||||
} FBSampleFormat;
|
||||
|
||||
/** Color ranges. Values mirror AVColorRange (static_assert'ed). */
|
||||
typedef enum FBColorRange {
|
||||
FB_COLOR_RANGE_UNSPEC = 0,
|
||||
FB_COLOR_RANGE_MPEG = 1,
|
||||
FB_COLOR_RANGE_JPEG = 2
|
||||
fb_color_range_unspec = 0,
|
||||
fb_color_range_mpeg = 1,
|
||||
fb_color_range_jpeg = 2
|
||||
} FBColorRange;
|
||||
|
||||
/** Color spaces. Values mirror AVColorSpace (static_assert'ed). */
|
||||
typedef enum FBColorSpace {
|
||||
FB_COL_SPC_RGB = 0,
|
||||
FB_COL_SPC_BT709 = 1,
|
||||
FB_COL_SPC_UNSPEC = 2,
|
||||
FB_COL_SPC_FCC = 4,
|
||||
FB_COL_SPC_BT470BG = 5,
|
||||
FB_COL_SPC_SMPTE170M = 6,
|
||||
FB_COL_SPC_SMPTE240M = 7,
|
||||
FB_COL_SPC_BT2020_NCL = 9
|
||||
fb_col_spc_rgb = 0,
|
||||
fb_col_spc_b_t709 = 1,
|
||||
fb_col_spc_unspec = 2,
|
||||
fb_col_spc_fcc = 4,
|
||||
fb_col_spc_b_t470_bg = 5,
|
||||
fb_col_spc_smpt_e170_m = 6,
|
||||
fb_col_spc_smpt_e240_m = 7,
|
||||
fb_col_spc_b_t2020_ncl = 9
|
||||
} FBColorSpace;
|
||||
|
||||
/** Media types. Values mirror AVMediaType (static_assert'ed). */
|
||||
typedef enum FBMediaType {
|
||||
FB_MEDIA_TYPE_VIDEO = 0,
|
||||
FB_MEDIA_TYPE_AUDIO = 1,
|
||||
FB_MEDIA_TYPE_DATA = 2,
|
||||
FB_MEDIA_TYPE_SUBTITLE = 3
|
||||
fb_media_type_video = 0,
|
||||
fb_media_type_audio = 1,
|
||||
fb_media_type_data = 2,
|
||||
fb_media_type_subtitle = 3
|
||||
} FBMediaType;
|
||||
|
||||
/** Field orders. Values mirror AVFieldOrder (static_assert'ed). */
|
||||
typedef enum FBFieldOrder {
|
||||
FB_FIELD_ORDER_UNKNOWN = 0,
|
||||
FB_FIELD_ORDER_PROGRESSIVE = 1,
|
||||
FB_FIELD_ORDER_TT = 2,
|
||||
FB_FIELD_ORDER_BB = 3,
|
||||
FB_FIELD_ORDER_TB = 4,
|
||||
FB_FIELD_ORDER_BT = 5
|
||||
fb_field_order_unknown = 0,
|
||||
fb_field_order_progressive = 1,
|
||||
fb_field_order_tt = 2,
|
||||
fb_field_order_bb = 3,
|
||||
fb_field_order_tb = 4,
|
||||
fb_field_order_bt = 5
|
||||
} FBFieldOrder;
|
||||
|
||||
/**
|
||||
@@ -181,26 +181,26 @@ typedef enum FBFieldOrder {
|
||||
* caller's adapter layer (no value relationship with any app-side enum).
|
||||
*/
|
||||
typedef enum FBCodec {
|
||||
FB_CODEC_NONE = -1,
|
||||
FB_CODEC_H264 = 0,
|
||||
FB_CODEC_H264RGB,
|
||||
FB_CODEC_DNXHD,
|
||||
FB_CODEC_PRORES,
|
||||
FB_CODEC_CINEFORM,
|
||||
FB_CODEC_H265,
|
||||
FB_CODEC_VP9,
|
||||
FB_CODEC_AV1,
|
||||
FB_CODEC_OPENEXR,
|
||||
FB_CODEC_PNG,
|
||||
FB_CODEC_TIFF,
|
||||
FB_CODEC_MP2,
|
||||
FB_CODEC_MP3,
|
||||
FB_CODEC_AAC,
|
||||
FB_CODEC_PCM,
|
||||
FB_CODEC_FLAC,
|
||||
FB_CODEC_OPUS,
|
||||
FB_CODEC_VORBIS,
|
||||
FB_CODEC_SRT
|
||||
fb_codec_none = -1,
|
||||
fb_codec_h264 = 0,
|
||||
fb_codec_h264_rgb,
|
||||
fb_codec_dnxhd,
|
||||
fb_codec_prores,
|
||||
fb_codec_cineform,
|
||||
fb_codec_h265,
|
||||
fb_codec_v_p9,
|
||||
fb_codec_a_v1,
|
||||
fb_codec_openexr,
|
||||
fb_codec_png,
|
||||
fb_codec_tiff,
|
||||
fb_codec_m_p2,
|
||||
fb_codec_m_p3,
|
||||
fb_codec_aac,
|
||||
fb_codec_pcm,
|
||||
fb_codec_flac,
|
||||
fb_codec_opus,
|
||||
fb_codec_vorbis,
|
||||
fb_codec_srt
|
||||
} FBCodec;
|
||||
|
||||
/** Cancellation callback: return non-zero to request cancellation. */
|
||||
@@ -602,4 +602,4 @@ FB_API int fb_encoder_codec_get_sample_formats(int codec, int *fmts,
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // FFMPEG_BRIDGE_H
|
||||
#endif // OAK_FFMPEG_BRIDGE_H
|
||||
|
||||
@@ -32,11 +32,11 @@ struct FBAudioGraph {
|
||||
|
||||
int in_channels = 0;
|
||||
int in_sample_rate = 0;
|
||||
int in_sample_format = FB_SAMPLE_FMT_NONE;
|
||||
int in_sample_format = fb_sample_fmt_none;
|
||||
int64_t in_pts = 0;
|
||||
};
|
||||
|
||||
static AVFilterContext *CreateTempoFilter(AVFilterGraph *graph,
|
||||
static AVFilterContext *create_tempo_filter(AVFilterGraph *graph,
|
||||
AVFilterContext *link, double tempo)
|
||||
{
|
||||
char speed_param[20];
|
||||
@@ -67,9 +67,9 @@ FBAudioGraph *fb_audio_graph_create(const FBAudioGraphConfig *config)
|
||||
}
|
||||
|
||||
AVChannelLayout in_layout, out_layout;
|
||||
fb::ChannelLayoutFromMask(&in_layout, config->in_channel_layout_mask,
|
||||
fb::channel_layout_from_mask(&in_layout, config->in_channel_layout_mask,
|
||||
config->in_channels);
|
||||
fb::ChannelLayoutFromMask(&out_layout, config->out_channel_layout_mask,
|
||||
fb::channel_layout_from_mask(&out_layout, config->out_channel_layout_mask,
|
||||
config->out_channels);
|
||||
|
||||
char filter_args[200];
|
||||
@@ -104,7 +104,7 @@ FBAudioGraph *fb_audio_graph_create(const FBAudioGraphConfig *config)
|
||||
for (int i = 0; i <= whole; i++) {
|
||||
double filter_tempo = (i == whole) ? pow(base, speed_log) : base;
|
||||
previous_filter =
|
||||
CreateTempoFilter(g->graph, previous_filter, filter_tempo);
|
||||
create_tempo_filter(g->graph, previous_filter, filter_tempo);
|
||||
if (!previous_filter) {
|
||||
av_channel_layout_uninit(&in_layout);
|
||||
av_channel_layout_uninit(&out_layout);
|
||||
|
||||
@@ -30,26 +30,26 @@
|
||||
namespace
|
||||
{
|
||||
|
||||
constexpr int64_t kAnalyzeDurationUs = 5000000;
|
||||
constexpr int64_t kProbeSizeBytes = 20000000;
|
||||
constexpr int64_t k_analyze_duration_us = 5000000;
|
||||
constexpr int64_t k_probe_size_bytes = 20000000;
|
||||
|
||||
void ApplyFormatOpenOptions(AVDictionary **opts)
|
||||
void apply_format_open_options(AVDictionary **opts)
|
||||
{
|
||||
av_dict_set_int(opts, "analyzeduration", kAnalyzeDurationUs, 0);
|
||||
av_dict_set_int(opts, "probesize", kProbeSizeBytes, 0);
|
||||
av_dict_set_int(opts, "analyzeduration", k_analyze_duration_us, 0);
|
||||
av_dict_set_int(opts, "probesize", k_probe_size_bytes, 0);
|
||||
}
|
||||
|
||||
void TuneFormatContext(AVFormatContext *ctx)
|
||||
void tune_format_context(AVFormatContext *ctx)
|
||||
{
|
||||
if (!ctx) {
|
||||
return;
|
||||
}
|
||||
|
||||
ctx->probesize = kProbeSizeBytes;
|
||||
ctx->max_analyze_duration = kAnalyzeDurationUs;
|
||||
ctx->probesize = k_probe_size_bytes;
|
||||
ctx->max_analyze_duration = k_analyze_duration_us;
|
||||
}
|
||||
|
||||
void DiscardSubtitleStreams(AVFormatContext *ctx)
|
||||
void discard_subtitle_streams(AVFormatContext *ctx)
|
||||
{
|
||||
if (!ctx) {
|
||||
return;
|
||||
@@ -77,14 +77,14 @@ struct FBDecoder {
|
||||
AVPixelFormat hw_pix_fmt = AV_PIX_FMT_NONE;
|
||||
bool hwaccel_enabled = false;
|
||||
|
||||
bool Open(const char *filename, int stream_index);
|
||||
void Close();
|
||||
bool open(const char *filename, int stream_index);
|
||||
void close();
|
||||
|
||||
static AVHWDeviceType ChooseHardwareDevice();
|
||||
static AVPixelFormat GetHardwareFormat(AVCodecContext *ctx,
|
||||
static AVHWDeviceType choose_hardware_device();
|
||||
static AVPixelFormat get_hardware_format(AVCodecContext *ctx,
|
||||
const AVPixelFormat *pix_fmts);
|
||||
bool InitHardwareAcceleration(const AVCodec *codec);
|
||||
void CleanupHardwareAcceleration();
|
||||
bool init_hardware_acceleration(const AVCodec *codec);
|
||||
void cleanup_hardware_acceleration();
|
||||
};
|
||||
|
||||
FBDecoder *fb_decoder_create(void)
|
||||
@@ -95,21 +95,21 @@ FBDecoder *fb_decoder_create(void)
|
||||
void fb_decoder_free(FBDecoder **decoder)
|
||||
{
|
||||
if (decoder && *decoder) {
|
||||
(*decoder)->Close();
|
||||
(*decoder)->close();
|
||||
delete *decoder;
|
||||
*decoder = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool FBDecoder::Open(const char *filename, int stream_index)
|
||||
bool FBDecoder::open(const char *filename, int stream_index)
|
||||
{
|
||||
// Open file in a format context
|
||||
AVDictionary *format_opts = nullptr;
|
||||
ApplyFormatOpenOptions(&format_opts);
|
||||
apply_format_open_options(&format_opts);
|
||||
int error_code = avformat_open_input(&fmt_ctx, filename, nullptr, &format_opts);
|
||||
av_dict_free(&format_opts);
|
||||
TuneFormatContext(fmt_ctx);
|
||||
DiscardSubtitleStreams(fmt_ctx);
|
||||
tune_format_context(fmt_ctx);
|
||||
discard_subtitle_streams(fmt_ctx);
|
||||
|
||||
if (error_code != 0) {
|
||||
fprintf(stderr, "ffmpeg_bridge: failed to open input %s (%d)\n", filename,
|
||||
@@ -158,7 +158,7 @@ bool FBDecoder::Open(const char *filename, int stream_index)
|
||||
}
|
||||
|
||||
// Attempt hardware accelerated decoding first, then fall back to software.
|
||||
if (InitHardwareAcceleration(codec)) {
|
||||
if (init_hardware_acceleration(codec)) {
|
||||
error_code = avcodec_open2(codec_ctx, codec, &opts);
|
||||
if (error_code == 0) {
|
||||
hwaccel_enabled = true;
|
||||
@@ -171,7 +171,7 @@ bool FBDecoder::Open(const char *filename, int stream_index)
|
||||
|
||||
// Free the failed context and recreate it for software decoding.
|
||||
avcodec_free_context(&codec_ctx);
|
||||
CleanupHardwareAcceleration();
|
||||
cleanup_hardware_acceleration();
|
||||
|
||||
codec_ctx = avcodec_alloc_context3(codec);
|
||||
if (codec_ctx == nullptr) {
|
||||
@@ -198,7 +198,7 @@ bool FBDecoder::Open(const char *filename, int stream_index)
|
||||
return true;
|
||||
}
|
||||
|
||||
AVHWDeviceType FBDecoder::ChooseHardwareDevice()
|
||||
AVHWDeviceType FBDecoder::choose_hardware_device()
|
||||
{
|
||||
if (getenv("OAK_DISABLE_HWACCEL") != nullptr) {
|
||||
return AV_HWDEVICE_TYPE_NONE;
|
||||
@@ -231,7 +231,7 @@ AVHWDeviceType FBDecoder::ChooseHardwareDevice()
|
||||
return AV_HWDEVICE_TYPE_NONE;
|
||||
}
|
||||
|
||||
AVPixelFormat FBDecoder::GetHardwareFormat(AVCodecContext *ctx,
|
||||
AVPixelFormat FBDecoder::get_hardware_format(AVCodecContext *ctx,
|
||||
const AVPixelFormat *pix_fmts)
|
||||
{
|
||||
const FBDecoder *inst = static_cast<const FBDecoder *>(ctx->opaque);
|
||||
@@ -246,9 +246,9 @@ AVPixelFormat FBDecoder::GetHardwareFormat(AVCodecContext *ctx,
|
||||
return pix_fmts[0];
|
||||
}
|
||||
|
||||
bool FBDecoder::InitHardwareAcceleration(const AVCodec *codec)
|
||||
bool FBDecoder::init_hardware_acceleration(const AVCodec *codec)
|
||||
{
|
||||
const AVHWDeviceType device_type = ChooseHardwareDevice();
|
||||
const AVHWDeviceType device_type = choose_hardware_device();
|
||||
if (device_type == AV_HWDEVICE_TYPE_NONE) {
|
||||
return false;
|
||||
}
|
||||
@@ -279,20 +279,20 @@ bool FBDecoder::InitHardwareAcceleration(const AVCodec *codec)
|
||||
fprintf(stderr,
|
||||
"ffmpeg_bridge: failed to create hardware device context (%d)\n",
|
||||
ret);
|
||||
CleanupHardwareAcceleration();
|
||||
cleanup_hardware_acceleration();
|
||||
return false;
|
||||
}
|
||||
|
||||
codec_ctx->hw_device_ctx = av_buffer_ref(hw_device_ctx);
|
||||
codec_ctx->opaque = this;
|
||||
codec_ctx->get_format = GetHardwareFormat;
|
||||
codec_ctx->get_format = get_hardware_format;
|
||||
// Most hardware decoders do not support frame threading.
|
||||
av_dict_set(&opts, "threads", "1", 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void FBDecoder::CleanupHardwareAcceleration()
|
||||
void FBDecoder::cleanup_hardware_acceleration()
|
||||
{
|
||||
hwaccel_enabled = false;
|
||||
hw_device_type = AV_HWDEVICE_TYPE_NONE;
|
||||
@@ -304,7 +304,7 @@ void FBDecoder::CleanupHardwareAcceleration()
|
||||
}
|
||||
}
|
||||
|
||||
void FBDecoder::Close()
|
||||
void FBDecoder::close()
|
||||
{
|
||||
if (opts) {
|
||||
av_dict_free(&opts);
|
||||
@@ -316,7 +316,7 @@ void FBDecoder::Close()
|
||||
codec_ctx = nullptr;
|
||||
}
|
||||
|
||||
CleanupHardwareAcceleration();
|
||||
cleanup_hardware_acceleration();
|
||||
|
||||
if (fmt_ctx) {
|
||||
avformat_close_input(&fmt_ctx);
|
||||
@@ -331,13 +331,13 @@ int fb_decoder_open(FBDecoder *decoder, const char *filename, int stream_index)
|
||||
if (!decoder || !filename) {
|
||||
return AVERROR(EINVAL);
|
||||
}
|
||||
return decoder->Open(filename, stream_index) ? 0 : AVERROR_EXTERNAL;
|
||||
return decoder->open(filename, stream_index) ? 0 : AVERROR_EXTERNAL;
|
||||
}
|
||||
|
||||
void fb_decoder_close(FBDecoder *decoder)
|
||||
{
|
||||
if (decoder) {
|
||||
decoder->Close();
|
||||
decoder->close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -431,13 +431,13 @@ int fb_decoder_get_stream_info(const FBDecoder *decoder, FBStreamInfo *out)
|
||||
out->has_decoder = 1; // stream is open, so a decoder was found
|
||||
out->width = par->width;
|
||||
out->height = par->height;
|
||||
out->pixel_format = fb::PixFmtFromAV(AVPixelFormat(par->format));
|
||||
out->pixel_format = fb::pix_fmt_from_av(AVPixelFormat(par->format));
|
||||
out->field_order = decoder->codec_ctx ? decoder->codec_ctx->field_order :
|
||||
AV_FIELD_UNKNOWN;
|
||||
out->color_range = par->color_range;
|
||||
out->sample_rate = par->sample_rate;
|
||||
out->sample_format = par->format;
|
||||
out->channel_layout_mask = fb::ValidateStreamChannelLayoutMask(s);
|
||||
out->channel_layout_mask = fb::validate_stream_channel_layout_mask(s);
|
||||
out->start_time = s->start_time;
|
||||
out->duration = s->duration;
|
||||
out->time_base_num = s->time_base.num;
|
||||
@@ -502,5 +502,5 @@ int fb_decoder_hw_pix_fmt(const FBDecoder *decoder)
|
||||
// Hardware pixel formats have no static FB_PIX_FMT_* identifier, so this
|
||||
// returns a process-local dynamic id for them. Use fb_frame_is_hw() to
|
||||
// detect hardware frames.
|
||||
return decoder ? fb::PixFmtFromAV(decoder->hw_pix_fmt) : FB_PIX_FMT_NONE;
|
||||
return decoder ? fb::pix_fmt_from_av(decoder->hw_pix_fmt) : fb_pix_fmt_none;
|
||||
}
|
||||
|
||||
+111
-111
@@ -37,7 +37,7 @@
|
||||
namespace
|
||||
{
|
||||
|
||||
AVPixelFormat ConvertJPEGSpaceToRegularSpace(AVPixelFormat f)
|
||||
AVPixelFormat convert_jpeg_space_to_regular_space(AVPixelFormat f)
|
||||
{
|
||||
switch (f) {
|
||||
case AV_PIX_FMT_YUVJ420P:
|
||||
@@ -57,67 +57,67 @@ AVPixelFormat ConvertJPEGSpaceToRegularSpace(AVPixelFormat f)
|
||||
return f;
|
||||
}
|
||||
|
||||
const AVCodec *FindEncoder(int codec, int sample_format)
|
||||
const AVCodec *find_encoder(int codec, int sample_format)
|
||||
{
|
||||
switch (codec) {
|
||||
case FB_CODEC_H264:
|
||||
case fb_codec_h264:
|
||||
return avcodec_find_encoder_by_name("libx264");
|
||||
case FB_CODEC_H264RGB:
|
||||
case fb_codec_h264_rgb:
|
||||
return avcodec_find_encoder_by_name("libx264rgb");
|
||||
case FB_CODEC_DNXHD:
|
||||
case fb_codec_dnxhd:
|
||||
return avcodec_find_encoder(AV_CODEC_ID_DNXHD);
|
||||
case FB_CODEC_PRORES:
|
||||
case fb_codec_prores:
|
||||
return avcodec_find_encoder(AV_CODEC_ID_PRORES);
|
||||
case FB_CODEC_CINEFORM:
|
||||
case fb_codec_cineform:
|
||||
return avcodec_find_encoder(AV_CODEC_ID_CFHD);
|
||||
case FB_CODEC_H265:
|
||||
case fb_codec_h265:
|
||||
return avcodec_find_encoder(AV_CODEC_ID_HEVC);
|
||||
case FB_CODEC_VP9:
|
||||
case fb_codec_v_p9:
|
||||
return avcodec_find_encoder(AV_CODEC_ID_VP9);
|
||||
case FB_CODEC_AV1: {
|
||||
case fb_codec_a_v1: {
|
||||
const AVCodec *encoder = avcodec_find_encoder_by_name("libsvtav1");
|
||||
if (!encoder) {
|
||||
encoder = avcodec_find_encoder(AV_CODEC_ID_AV1);
|
||||
}
|
||||
return encoder;
|
||||
}
|
||||
case FB_CODEC_OPENEXR:
|
||||
case fb_codec_openexr:
|
||||
return avcodec_find_encoder(AV_CODEC_ID_EXR);
|
||||
case FB_CODEC_PNG:
|
||||
case fb_codec_png:
|
||||
return avcodec_find_encoder(AV_CODEC_ID_PNG);
|
||||
case FB_CODEC_TIFF:
|
||||
case fb_codec_tiff:
|
||||
return avcodec_find_encoder(AV_CODEC_ID_TIFF);
|
||||
case FB_CODEC_MP2:
|
||||
case fb_codec_m_p2:
|
||||
return avcodec_find_encoder(AV_CODEC_ID_MP2);
|
||||
case FB_CODEC_MP3:
|
||||
case fb_codec_m_p3:
|
||||
return avcodec_find_encoder(AV_CODEC_ID_MP3);
|
||||
case FB_CODEC_AAC:
|
||||
case fb_codec_aac:
|
||||
return avcodec_find_encoder(AV_CODEC_ID_AAC);
|
||||
case FB_CODEC_PCM:
|
||||
case fb_codec_pcm:
|
||||
switch (sample_format) {
|
||||
case FB_SAMPLE_FMT_U8:
|
||||
case fb_sample_fmt_u8:
|
||||
return avcodec_find_encoder(AV_CODEC_ID_PCM_U8);
|
||||
case FB_SAMPLE_FMT_S16:
|
||||
case fb_sample_fmt_s16:
|
||||
return avcodec_find_encoder(AV_CODEC_ID_PCM_S16LE);
|
||||
case FB_SAMPLE_FMT_S32:
|
||||
case fb_sample_fmt_s32:
|
||||
return avcodec_find_encoder(AV_CODEC_ID_PCM_S32LE);
|
||||
case FB_SAMPLE_FMT_S64:
|
||||
case fb_sample_fmt_s64:
|
||||
return avcodec_find_encoder(AV_CODEC_ID_PCM_S64LE);
|
||||
case FB_SAMPLE_FMT_FLT:
|
||||
case fb_sample_fmt_flt:
|
||||
return avcodec_find_encoder(AV_CODEC_ID_PCM_F32LE);
|
||||
case FB_SAMPLE_FMT_DBL:
|
||||
case fb_sample_fmt_dbl:
|
||||
return avcodec_find_encoder(AV_CODEC_ID_PCM_F64LE);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case FB_CODEC_FLAC:
|
||||
case fb_codec_flac:
|
||||
return avcodec_find_encoder(AV_CODEC_ID_FLAC);
|
||||
case FB_CODEC_OPUS:
|
||||
case fb_codec_opus:
|
||||
return avcodec_find_encoder(AV_CODEC_ID_OPUS);
|
||||
case FB_CODEC_VORBIS:
|
||||
case fb_codec_vorbis:
|
||||
return avcodec_find_encoder(AV_CODEC_ID_VORBIS);
|
||||
case FB_CODEC_SRT:
|
||||
case fb_codec_srt:
|
||||
return avcodec_find_encoder(AV_CODEC_ID_SUBRIP);
|
||||
default:
|
||||
break;
|
||||
@@ -133,7 +133,7 @@ struct FBEncoder {
|
||||
std::string filename;
|
||||
|
||||
int video_enabled = 0;
|
||||
int video_codec = FB_CODEC_NONE;
|
||||
int video_codec = fb_codec_none;
|
||||
int video_width = 0;
|
||||
int video_height = 0;
|
||||
int video_pixel_aspect_num = 1;
|
||||
@@ -144,9 +144,9 @@ struct FBEncoder {
|
||||
int video_frame_rate_den = 1;
|
||||
std::string video_pix_fmt;
|
||||
// In AVPixelFormat space (translated from the FB config value at create)
|
||||
int video_src_pix_fmt = FB_PIX_FMT_NONE;
|
||||
int video_color_range = FB_COLOR_RANGE_UNSPEC;
|
||||
int video_field_order = FB_FIELD_ORDER_PROGRESSIVE;
|
||||
int video_src_pix_fmt = fb_pix_fmt_none;
|
||||
int video_color_range = fb_color_range_unspec;
|
||||
int video_field_order = fb_field_order_progressive;
|
||||
int64_t video_bit_rate = 0;
|
||||
int64_t video_min_bit_rate = 0;
|
||||
int64_t video_max_bit_rate = 0;
|
||||
@@ -156,14 +156,14 @@ struct FBEncoder {
|
||||
std::vector<std::pair<std::string, std::string>> video_opts;
|
||||
|
||||
int audio_enabled = 0;
|
||||
int audio_codec = FB_CODEC_NONE;
|
||||
int audio_codec = fb_codec_none;
|
||||
int audio_sample_rate = 0;
|
||||
uint64_t audio_channel_layout_mask = 0;
|
||||
int audio_sample_format = FB_SAMPLE_FMT_NONE;
|
||||
int audio_sample_format = fb_sample_fmt_none;
|
||||
int64_t audio_bit_rate = 0;
|
||||
|
||||
int subtitles_enabled = 0;
|
||||
int subtitle_codec = FB_CODEC_NONE;
|
||||
int subtitle_codec = fb_codec_none;
|
||||
std::vector<uint8_t> subtitle_header;
|
||||
|
||||
// Runtime state
|
||||
@@ -190,29 +190,29 @@ struct FBEncoder {
|
||||
|
||||
char error[1024] = { 0 };
|
||||
|
||||
void SetError(const char *context, int error_code)
|
||||
void set_error(const char *context, int error_code)
|
||||
{
|
||||
fb::SetError(error, sizeof(error), context, error_code);
|
||||
fb::set_error(error, sizeof(error), context, error_code);
|
||||
}
|
||||
|
||||
void SetError(const char *message)
|
||||
void set_error(const char *message)
|
||||
{
|
||||
snprintf(error, sizeof(error), "%s", message);
|
||||
}
|
||||
|
||||
bool WriteAVFrame(AVFrame *frame, AVCodecContext *codec_ctx,
|
||||
bool write_av_frame(AVFrame *frame, AVCodecContext *codec_ctx,
|
||||
AVStream *stream);
|
||||
bool InitializeStream(AVMediaType type, AVStream **stream,
|
||||
bool initialize_stream(AVMediaType type, AVStream **stream,
|
||||
AVCodecContext **codec_ctx, int codec);
|
||||
bool InitializeCodecContext(AVStream **stream, AVCodecContext **codec_ctx,
|
||||
bool initialize_codec_context(AVStream **stream, AVCodecContext **codec_ctx,
|
||||
const AVCodec *codec);
|
||||
bool SetupCodecContext(AVStream *stream, AVCodecContext *codec_ctx,
|
||||
bool setup_codec_context(AVStream *stream, AVCodecContext *codec_ctx,
|
||||
const AVCodec *codec);
|
||||
void FlushEncoders();
|
||||
void FlushCodecCtx(AVCodecContext *codec_ctx, AVStream *stream);
|
||||
bool InitializeResampleContext(int sample_format, int sample_rate,
|
||||
void flush_encoders();
|
||||
void flush_codec_ctx(AVCodecContext *codec_ctx, AVStream *stream);
|
||||
bool initialize_resample_context(int sample_format, int sample_rate,
|
||||
uint64_t channel_layout_mask);
|
||||
bool WriteAudioData(int sample_format, int sample_rate,
|
||||
bool write_audio_data(int sample_format, int sample_rate,
|
||||
uint64_t channel_layout_mask, const uint8_t **input_data,
|
||||
int input_sample_count);
|
||||
};
|
||||
@@ -242,7 +242,7 @@ FBEncoder *fb_encoder_create(const FBEncoderConfig *config)
|
||||
}
|
||||
// Stored in AVPixelFormat space; the public config value is an
|
||||
// FB_PIX_FMT_* identifier.
|
||||
e->video_src_pix_fmt = fb::PixFmtToAV(config->video_src_pix_fmt);
|
||||
e->video_src_pix_fmt = fb::pix_fmt_to_av(config->video_src_pix_fmt);
|
||||
e->video_color_range = config->video_color_range;
|
||||
e->video_field_order = config->video_field_order;
|
||||
e->video_bit_rate = config->video_bit_rate;
|
||||
@@ -301,13 +301,13 @@ int fb_encoder_open(FBEncoder *e)
|
||||
error_code = avformat_alloc_output_context2(&e->fmt_ctx, nullptr, nullptr,
|
||||
e->filename.c_str());
|
||||
if (error_code < 0) {
|
||||
e->SetError("Failed to allocate output context", error_code);
|
||||
e->set_error("Failed to allocate output context", error_code);
|
||||
return error_code;
|
||||
}
|
||||
|
||||
// Initialize a video stream if it's enabled
|
||||
if (e->video_enabled) {
|
||||
if (!e->InitializeStream(AVMEDIA_TYPE_VIDEO, &e->video_stream,
|
||||
if (!e->initialize_stream(AVMEDIA_TYPE_VIDEO, &e->video_stream,
|
||||
&e->video_codec_ctx, e->video_codec)) {
|
||||
return AVERROR_EXTERNAL;
|
||||
}
|
||||
@@ -317,14 +317,14 @@ int fb_encoder_open(FBEncoder *e)
|
||||
|
||||
e->video_scale_ctx = avfilter_graph_alloc();
|
||||
if (!e->video_scale_ctx) {
|
||||
e->SetError("Failed to allocate filter graph");
|
||||
e->set_error("Failed to allocate filter graph");
|
||||
return AVERROR_EXTERNAL;
|
||||
}
|
||||
|
||||
static const int FILTER_ARG_SZ = 1024;
|
||||
char filter_args[FILTER_ARG_SZ];
|
||||
static const int filter_arg_sz = 1024;
|
||||
char filter_args[filter_arg_sz];
|
||||
|
||||
snprintf(filter_args, FILTER_ARG_SZ,
|
||||
snprintf(filter_args, filter_arg_sz,
|
||||
"video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
|
||||
e->video_width, e->video_height, e->video_src_pix_fmt,
|
||||
e->video_time_base_num, e->video_time_base_den,
|
||||
@@ -343,8 +343,8 @@ int fb_encoder_open(FBEncoder *e)
|
||||
// Set color range
|
||||
AVFilterContext *range_filter;
|
||||
|
||||
snprintf(filter_args, FILTER_ARG_SZ, "in_range=full:out_range=%s",
|
||||
e->video_color_range == FB_COLOR_RANGE_JPEG ? "full" :
|
||||
snprintf(filter_args, filter_arg_sz, "in_range=full:out_range=%s",
|
||||
e->video_color_range == fb_color_range_jpeg ? "full" :
|
||||
"limited");
|
||||
|
||||
avfilter_graph_create_filter(&range_filter,
|
||||
@@ -360,7 +360,7 @@ int fb_encoder_open(FBEncoder *e)
|
||||
// Transform pixel format
|
||||
AVFilterContext *format_filter;
|
||||
|
||||
snprintf(filter_args, FILTER_ARG_SZ, "pix_fmts=%u", encoder_pix_fmt);
|
||||
snprintf(filter_args, filter_arg_sz, "pix_fmts=%u", encoder_pix_fmt);
|
||||
|
||||
avfilter_graph_create_filter(&format_filter,
|
||||
avfilter_get_by_name("format"),
|
||||
@@ -374,14 +374,14 @@ int fb_encoder_open(FBEncoder *e)
|
||||
avfilter_link(last_filter, 0, e->video_buffersink_ctx, 0);
|
||||
|
||||
if (avfilter_graph_config(e->video_scale_ctx, nullptr) < 0) {
|
||||
e->SetError("Failed to configure filter graph");
|
||||
e->set_error("Failed to configure filter graph");
|
||||
return AVERROR_EXTERNAL;
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize an audio stream if it's enabled
|
||||
if (e->audio_enabled) {
|
||||
if (!e->InitializeStream(AVMEDIA_TYPE_AUDIO, &e->audio_stream,
|
||||
if (!e->initialize_stream(AVMEDIA_TYPE_AUDIO, &e->audio_stream,
|
||||
&e->audio_codec_ctx, e->audio_codec)) {
|
||||
return AVERROR_EXTERNAL;
|
||||
}
|
||||
@@ -389,7 +389,7 @@ int fb_encoder_open(FBEncoder *e)
|
||||
|
||||
// Initialize a subtitle stream if it's enabled
|
||||
if (e->subtitles_enabled) {
|
||||
if (!e->InitializeStream(AVMEDIA_TYPE_SUBTITLE, &e->subtitle_stream,
|
||||
if (!e->initialize_stream(AVMEDIA_TYPE_SUBTITLE, &e->subtitle_stream,
|
||||
&e->subtitle_codec_ctx, e->subtitle_codec)) {
|
||||
return AVERROR_EXTERNAL;
|
||||
}
|
||||
@@ -400,14 +400,14 @@ int fb_encoder_open(FBEncoder *e)
|
||||
// Open output file for writing
|
||||
error_code = avio_open(&e->fmt_ctx->pb, e->filename.c_str(), AVIO_FLAG_WRITE);
|
||||
if (error_code < 0) {
|
||||
e->SetError("Failed to open IO context", error_code);
|
||||
e->set_error("Failed to open IO context", error_code);
|
||||
return error_code;
|
||||
}
|
||||
|
||||
// Write header
|
||||
error_code = avformat_write_header(e->fmt_ctx, nullptr);
|
||||
if (error_code < 0) {
|
||||
e->SetError("Failed to write format header", error_code);
|
||||
e->set_error("Failed to write format header", error_code);
|
||||
return error_code;
|
||||
}
|
||||
|
||||
@@ -426,13 +426,13 @@ int fb_encoder_write_video_frame(FBEncoder *e, int width, int height,
|
||||
// Use the filter graph to convert formats/linesizes
|
||||
AVFrame *input_frame = av_frame_alloc();
|
||||
if (!input_frame) {
|
||||
e->SetError("Failed to allocate input frame");
|
||||
e->set_error("Failed to allocate input frame");
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
|
||||
input_frame->width = width;
|
||||
input_frame->height = height;
|
||||
input_frame->format = fb::PixFmtToAV(pix_fmt);
|
||||
input_frame->format = fb::pix_fmt_to_av(pix_fmt);
|
||||
input_frame->data[0] = const_cast<uint8_t *>(data);
|
||||
input_frame->linesize[0] = linesize;
|
||||
|
||||
@@ -445,20 +445,20 @@ int fb_encoder_write_video_frame(FBEncoder *e, int width, int height,
|
||||
AV_BUFFERSRC_FLAG_KEEP_REF);
|
||||
av_frame_free(&input_frame);
|
||||
if (r < 0) {
|
||||
e->SetError("Failed to add frame to filter graph", r);
|
||||
e->set_error("Failed to add frame to filter graph", r);
|
||||
return r;
|
||||
}
|
||||
|
||||
AVFrame *encoded_frame = av_frame_alloc();
|
||||
if (!encoded_frame) {
|
||||
e->SetError("Failed to allocate encode frame");
|
||||
e->set_error("Failed to allocate encode frame");
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
|
||||
r = av_buffersink_get_frame(e->video_buffersink_ctx, encoded_frame);
|
||||
if (r < 0) {
|
||||
av_frame_free(&encoded_frame);
|
||||
e->SetError("Failed to retrieve frame from buffer sink", r);
|
||||
e->set_error("Failed to retrieve frame from buffer sink", r);
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -466,21 +466,21 @@ int fb_encoder_write_video_frame(FBEncoder *e, int width, int height,
|
||||
llround(time_seconds / av_q2d(e->video_codec_ctx->time_base));
|
||||
|
||||
bool result =
|
||||
e->WriteAVFrame(encoded_frame, e->video_codec_ctx, e->video_stream);
|
||||
e->write_av_frame(encoded_frame, e->video_codec_ctx, e->video_stream);
|
||||
|
||||
av_frame_free(&encoded_frame);
|
||||
|
||||
return result ? 0 : AVERROR_EXTERNAL;
|
||||
}
|
||||
|
||||
bool FBEncoder::WriteAudioData(int sample_format, int sample_rate,
|
||||
bool FBEncoder::write_audio_data(int sample_format, int sample_rate,
|
||||
uint64_t channel_layout_mask,
|
||||
const uint8_t **input_data,
|
||||
int input_sample_count)
|
||||
{
|
||||
if (!InitializeResampleContext(sample_format, sample_rate,
|
||||
if (!initialize_resample_context(sample_format, sample_rate,
|
||||
channel_layout_mask)) {
|
||||
SetError("Failed to initialize resample context");
|
||||
set_error("Failed to initialize resample context");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -527,13 +527,13 @@ bool FBEncoder::WriteAudioData(int sample_format, int sample_rate,
|
||||
audio_write_count, { 1, audio_codec_ctx->sample_rate },
|
||||
audio_codec_ctx->time_base);
|
||||
|
||||
WriteAVFrame(audio_frame, audio_codec_ctx, audio_stream);
|
||||
write_av_frame(audio_frame, audio_codec_ctx, audio_stream);
|
||||
audio_write_count += audio_frame_offset;
|
||||
audio_frame_offset = 0;
|
||||
}
|
||||
}
|
||||
} else if (converted < 0) {
|
||||
SetError("Failed to resample audio", converted);
|
||||
set_error("Failed to resample audio", converted);
|
||||
result = false;
|
||||
}
|
||||
|
||||
@@ -542,7 +542,7 @@ bool FBEncoder::WriteAudioData(int sample_format, int sample_rate,
|
||||
audio_frame->pts =
|
||||
av_rescale_q(audio_write_count, { 1, audio_codec_ctx->sample_rate },
|
||||
audio_codec_ctx->time_base);
|
||||
WriteAVFrame(audio_frame, audio_codec_ctx, audio_stream);
|
||||
write_av_frame(audio_frame, audio_codec_ctx, audio_stream);
|
||||
}
|
||||
|
||||
// Free buffers created
|
||||
@@ -590,7 +590,7 @@ int fb_encoder_write_audio(FBEncoder *e, const uint8_t *const *channel_data,
|
||||
static_cast<AVSampleFormat>(sample_format), 0);
|
||||
|
||||
if (r < 0) {
|
||||
e->SetError("Failed to allocate sample array", r);
|
||||
e->set_error("Failed to allocate sample array", r);
|
||||
return r;
|
||||
} else {
|
||||
if (planar) {
|
||||
@@ -608,7 +608,7 @@ int fb_encoder_write_audio(FBEncoder *e, const uint8_t *const *channel_data,
|
||||
start += input_sample_count;
|
||||
}
|
||||
|
||||
result = e->WriteAudioData(sample_format, sample_rate,
|
||||
result = e->write_audio_data(sample_format, sample_rate,
|
||||
channel_layout_mask,
|
||||
const_cast<const uint8_t **>(input_data),
|
||||
int(input_sample_count));
|
||||
@@ -659,7 +659,7 @@ int fb_encoder_write_subtitle(FBEncoder *e, const char *utf8_text,
|
||||
bool ret = true;
|
||||
|
||||
if (err < 0) {
|
||||
e->SetError("Failed to write interleaved packet", err);
|
||||
e->set_error("Failed to write interleaved packet", err);
|
||||
ret = false;
|
||||
}
|
||||
|
||||
@@ -676,7 +676,7 @@ void fb_encoder_close(FBEncoder *e)
|
||||
|
||||
if (e->open) {
|
||||
// Flush encoders
|
||||
e->FlushEncoders();
|
||||
e->flush_encoders();
|
||||
|
||||
// We've written a header, so we'll write a trailer
|
||||
av_write_trailer(e->fmt_ctx);
|
||||
@@ -732,13 +732,13 @@ const char *fb_encoder_get_error(const FBEncoder *encoder)
|
||||
return encoder ? encoder->error : "";
|
||||
}
|
||||
|
||||
bool FBEncoder::WriteAVFrame(AVFrame *frame, AVCodecContext *codec_ctx,
|
||||
bool FBEncoder::write_av_frame(AVFrame *frame, AVCodecContext *codec_ctx,
|
||||
AVStream *stream)
|
||||
{
|
||||
// Send raw frame to the encoder
|
||||
int error_code = avcodec_send_frame(codec_ctx, frame);
|
||||
if (error_code < 0) {
|
||||
SetError("Failed to send frame to encoder", error_code);
|
||||
set_error("Failed to send frame to encoder", error_code);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -754,7 +754,7 @@ bool FBEncoder::WriteAVFrame(AVFrame *frame, AVCodecContext *codec_ctx,
|
||||
if (error_code == AVERROR(EAGAIN)) {
|
||||
break;
|
||||
} else if (error_code < 0) {
|
||||
SetError("Failed to receive packet from decoder", error_code);
|
||||
set_error("Failed to receive packet from decoder", error_code);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@@ -766,7 +766,7 @@ bool FBEncoder::WriteAVFrame(AVFrame *frame, AVCodecContext *codec_ctx,
|
||||
// Write packet to file
|
||||
error_code = av_interleaved_write_frame(fmt_ctx, pkt);
|
||||
if (error_code < 0) {
|
||||
SetError("Failed to write interleaved packet", error_code);
|
||||
set_error("Failed to write interleaved packet", error_code);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@@ -782,30 +782,30 @@ fail:
|
||||
return succeeded;
|
||||
}
|
||||
|
||||
bool FBEncoder::InitializeStream(AVMediaType type, AVStream **stream_ptr,
|
||||
bool FBEncoder::initialize_stream(AVMediaType type, AVStream **stream_ptr,
|
||||
AVCodecContext **codec_ctx_ptr, int codec)
|
||||
{
|
||||
if (type != AVMEDIA_TYPE_VIDEO && type != AVMEDIA_TYPE_AUDIO &&
|
||||
type != AVMEDIA_TYPE_SUBTITLE) {
|
||||
SetError("Cannot initialize a stream that is not a video, audio, or subtitle type");
|
||||
set_error("Cannot initialize a stream that is not a video, audio, or subtitle type");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Find encoder
|
||||
const AVCodec *encoder = FindEncoder(codec, audio_sample_format);
|
||||
const AVCodec *encoder = find_encoder(codec, audio_sample_format);
|
||||
if (!encoder) {
|
||||
char msg[128];
|
||||
snprintf(msg, sizeof(msg), "Failed to find codec for 0x%x", codec);
|
||||
SetError(msg);
|
||||
set_error(msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (encoder->type != type) {
|
||||
SetError("Retrieved unexpected codec type for codec");
|
||||
set_error("Retrieved unexpected codec type for codec");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!InitializeCodecContext(stream_ptr, codec_ctx_ptr, encoder)) {
|
||||
if (!initialize_codec_context(stream_ptr, codec_ctx_ptr, encoder)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -821,23 +821,23 @@ bool FBEncoder::InitializeStream(AVMediaType type, AVStream **stream_ptr,
|
||||
codec_ctx->time_base = { video_time_base_num, video_time_base_den };
|
||||
codec_ctx->framerate = { video_frame_rate_num, video_frame_rate_den };
|
||||
codec_ctx->pix_fmt = av_get_pix_fmt(video_pix_fmt.c_str());
|
||||
codec_ctx->color_range = video_color_range == FB_COLOR_RANGE_JPEG ?
|
||||
codec_ctx->color_range = video_color_range == fb_color_range_jpeg ?
|
||||
AVCOL_RANGE_JPEG :
|
||||
AVCOL_RANGE_MPEG;
|
||||
|
||||
if (video_field_order != FB_FIELD_ORDER_PROGRESSIVE) {
|
||||
if (video_field_order != fb_field_order_progressive) {
|
||||
// FIXME: I actually don't know what these flags do, the documentation helpfully doesn't
|
||||
// explain them at all. I hope using both of them is the right thing to do.
|
||||
codec_ctx->flags |= AV_CODEC_FLAG_INTERLACED_DCT |
|
||||
AV_CODEC_FLAG_INTERLACED_ME;
|
||||
|
||||
if (video_field_order == FB_FIELD_ORDER_TT) {
|
||||
if (video_field_order == fb_field_order_tt) {
|
||||
codec_ctx->field_order = AV_FIELD_TT;
|
||||
} else {
|
||||
codec_ctx->field_order = AV_FIELD_BB;
|
||||
|
||||
if (video_codec == FB_CODEC_H264 ||
|
||||
video_codec == FB_CODEC_H264RGB) {
|
||||
if (video_codec == fb_codec_h264 ||
|
||||
video_codec == fb_codec_h264_rgb) {
|
||||
// For some reason, FFmpeg doesn't set libx264's bff flag so we have to do it ourselves
|
||||
av_opt_set(codec_ctx->priv_data, "x264opts", "bff=1",
|
||||
AV_OPT_SEARCH_CHILDREN);
|
||||
@@ -902,34 +902,34 @@ bool FBEncoder::InitializeStream(AVMediaType type, AVStream **stream_ptr,
|
||||
}
|
||||
}
|
||||
|
||||
if (!SetupCodecContext(stream, codec_ctx, encoder)) {
|
||||
if (!setup_codec_context(stream, codec_ctx, encoder)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FBEncoder::InitializeCodecContext(AVStream **stream,
|
||||
bool FBEncoder::initialize_codec_context(AVStream **stream,
|
||||
AVCodecContext **codec_ctx,
|
||||
const AVCodec *codec)
|
||||
{
|
||||
*stream = avformat_new_stream(fmt_ctx, nullptr);
|
||||
if (!(*stream)) {
|
||||
SetError("Failed to allocate AVStream");
|
||||
set_error("Failed to allocate AVStream");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Allocate a codec context
|
||||
*codec_ctx = avcodec_alloc_context3(codec);
|
||||
if (!(*codec_ctx)) {
|
||||
SetError("Failed to allocate AVCodecContext");
|
||||
set_error("Failed to allocate AVCodecContext");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FBEncoder::SetupCodecContext(AVStream *stream, AVCodecContext *codec_ctx,
|
||||
bool FBEncoder::setup_codec_context(AVStream *stream, AVCodecContext *codec_ctx,
|
||||
const AVCodec *codec)
|
||||
{
|
||||
int error_code;
|
||||
@@ -953,14 +953,14 @@ bool FBEncoder::SetupCodecContext(AVStream *stream, AVCodecContext *codec_ctx,
|
||||
error_code = avcodec_open2(codec_ctx, codec, &codec_opts);
|
||||
av_dict_free(&codec_opts);
|
||||
if (error_code < 0) {
|
||||
SetError("Failed to open encoder", error_code);
|
||||
set_error("Failed to open encoder", error_code);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Copy context settings to codecpar object
|
||||
error_code = avcodec_parameters_from_context(stream->codecpar, codec_ctx);
|
||||
if (error_code < 0) {
|
||||
SetError("Failed to copy codec parameters to stream", error_code);
|
||||
set_error("Failed to copy codec parameters to stream", error_code);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -971,27 +971,27 @@ bool FBEncoder::SetupCodecContext(AVStream *stream, AVCodecContext *codec_ctx,
|
||||
return true;
|
||||
}
|
||||
|
||||
void FBEncoder::FlushEncoders()
|
||||
void FBEncoder::flush_encoders()
|
||||
{
|
||||
if (video_codec_ctx) {
|
||||
FlushCodecCtx(video_codec_ctx, video_stream);
|
||||
flush_codec_ctx(video_codec_ctx, video_stream);
|
||||
}
|
||||
|
||||
if (audio_codec_ctx) {
|
||||
FlushCodecCtx(audio_codec_ctx, audio_stream);
|
||||
flush_codec_ctx(audio_codec_ctx, audio_stream);
|
||||
}
|
||||
|
||||
if (fmt_ctx) {
|
||||
if (fmt_ctx->oformat->flags) {
|
||||
int r = av_interleaved_write_frame(fmt_ctx, nullptr);
|
||||
if (r < 0) {
|
||||
SetError("Failed to write interleaved packet", r);
|
||||
set_error("Failed to write interleaved packet", r);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FBEncoder::FlushCodecCtx(AVCodecContext *codec_ctx, AVStream *stream)
|
||||
void FBEncoder::flush_codec_ctx(AVCodecContext *codec_ctx, AVStream *stream)
|
||||
{
|
||||
avcodec_send_frame(codec_ctx, nullptr);
|
||||
AVPacket *pkt = av_packet_alloc();
|
||||
@@ -1008,7 +1008,7 @@ void FBEncoder::FlushCodecCtx(AVCodecContext *codec_ctx, AVStream *stream)
|
||||
av_packet_rescale_ts(pkt, codec_ctx->time_base, stream->time_base);
|
||||
int r = av_interleaved_write_frame(fmt_ctx, pkt);
|
||||
if (r < 0) {
|
||||
SetError("Failed to write interleaved packet", r);
|
||||
set_error("Failed to write interleaved packet", r);
|
||||
break;
|
||||
}
|
||||
av_packet_unref(pkt);
|
||||
@@ -1017,7 +1017,7 @@ void FBEncoder::FlushCodecCtx(AVCodecContext *codec_ctx, AVStream *stream)
|
||||
av_packet_free(&pkt);
|
||||
}
|
||||
|
||||
bool FBEncoder::InitializeResampleContext(int sample_format, int sample_rate,
|
||||
bool FBEncoder::initialize_resample_context(int sample_format, int sample_rate,
|
||||
uint64_t channel_layout_mask)
|
||||
{
|
||||
if (audio_resample_ctx) {
|
||||
@@ -1025,7 +1025,7 @@ bool FBEncoder::InitializeResampleContext(int sample_format, int sample_rate,
|
||||
}
|
||||
|
||||
AVChannelLayout layout;
|
||||
fb::ChannelLayoutFromMask(&layout, channel_layout_mask, 0);
|
||||
fb::channel_layout_from_mask(&layout, channel_layout_mask, 0);
|
||||
|
||||
// Create resample context
|
||||
swr_alloc_set_opts2(&audio_resample_ctx, &audio_codec_ctx->ch_layout,
|
||||
@@ -1041,7 +1041,7 @@ bool FBEncoder::InitializeResampleContext(int sample_format, int sample_rate,
|
||||
|
||||
int err = swr_init(audio_resample_ctx);
|
||||
if (err < 0) {
|
||||
SetError("Failed to create resampling context", err);
|
||||
set_error("Failed to create resampling context", err);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1070,7 +1070,7 @@ bool FBEncoder::InitializeResampleContext(int sample_format, int sample_rate,
|
||||
|
||||
err = av_frame_get_buffer(audio_frame, 0);
|
||||
if (err < 0) {
|
||||
SetError("Failed to create audio frame", err);
|
||||
set_error("Failed to create audio frame", err);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1083,7 +1083,7 @@ bool FBEncoder::InitializeResampleContext(int sample_format, int sample_rate,
|
||||
int fb_encoder_codec_get_pixel_formats(int codec, const char **names,
|
||||
int max_names)
|
||||
{
|
||||
const AVCodec *codec_info = FindEncoder(codec, FB_SAMPLE_FMT_NONE);
|
||||
const AVCodec *codec_info = find_encoder(codec, fb_sample_fmt_none);
|
||||
if (!codec_info || !codec_info->pix_fmts) {
|
||||
return 0;
|
||||
}
|
||||
@@ -1091,7 +1091,7 @@ int fb_encoder_codec_get_pixel_formats(int codec, const char **names,
|
||||
int count = 0;
|
||||
for (int i = 0; codec_info->pix_fmts[i] != AV_PIX_FMT_NONE; i++) {
|
||||
AVPixelFormat fmt = codec_info->pix_fmts[i];
|
||||
if (ConvertJPEGSpaceToRegularSpace(fmt) != fmt) {
|
||||
if (convert_jpeg_space_to_regular_space(fmt) != fmt) {
|
||||
// This is a deprecated "JPEG" space, skip it
|
||||
continue;
|
||||
}
|
||||
@@ -1107,7 +1107,7 @@ int fb_encoder_codec_get_pixel_formats(int codec, const char **names,
|
||||
|
||||
int fb_encoder_codec_get_sample_formats(int codec, int *fmts, int max_fmts)
|
||||
{
|
||||
const AVCodec *codec_info = FindEncoder(codec, FB_SAMPLE_FMT_NONE);
|
||||
const AVCodec *codec_info = find_encoder(codec, fb_sample_fmt_none);
|
||||
if (!codec_info || !codec_info->sample_fmts) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -114,14 +114,14 @@ void fb_frame_set_height(FBFrame *frame, int height)
|
||||
|
||||
int fb_frame_get_format(const FBFrame *frame)
|
||||
{
|
||||
return frame ? fb::PixFmtFromAV(AVPixelFormat(frame->frame->format)) :
|
||||
FB_PIX_FMT_NONE;
|
||||
return frame ? fb::pix_fmt_from_av(AVPixelFormat(frame->frame->format)) :
|
||||
fb_pix_fmt_none;
|
||||
}
|
||||
|
||||
void fb_frame_set_format(FBFrame *frame, int format)
|
||||
{
|
||||
if (frame) {
|
||||
frame->frame->format = fb::PixFmtToAV(format);
|
||||
frame->frame->format = fb::pix_fmt_to_av(format);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ void fb_frame_set_sample_rate(FBFrame *frame, int sample_rate)
|
||||
|
||||
int fb_frame_get_color_range(const FBFrame *frame)
|
||||
{
|
||||
return frame ? int(frame->frame->color_range) : FB_COLOR_RANGE_UNSPEC;
|
||||
return frame ? int(frame->frame->color_range) : fb_color_range_unspec;
|
||||
}
|
||||
|
||||
void fb_frame_set_color_range(FBFrame *frame, int color_range)
|
||||
@@ -180,7 +180,7 @@ void fb_frame_set_color_range(FBFrame *frame, int color_range)
|
||||
|
||||
int fb_frame_get_colorspace(const FBFrame *frame)
|
||||
{
|
||||
return frame ? int(frame->frame->colorspace) : FB_COL_SPC_UNSPEC;
|
||||
return frame ? int(frame->frame->colorspace) : fb_col_spc_unspec;
|
||||
}
|
||||
|
||||
void fb_frame_set_colorspace(FBFrame *frame, int colorspace)
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
|
||||
***/
|
||||
|
||||
#ifndef FFMPEG_BRIDGE_INTERNAL_H
|
||||
#define FFMPEG_BRIDGE_INTERNAL_H
|
||||
#ifndef OAK_FFMPEG_BRIDGE_INTERNAL_H
|
||||
#define OAK_FFMPEG_BRIDGE_INTERNAL_H
|
||||
|
||||
// Fixes weird define issue when including <avfilter.h>
|
||||
#include <inttypes.h>
|
||||
@@ -55,46 +55,46 @@ static_assert(FB_NOPTS_VALUE == AV_NOPTS_VALUE, "FB_NOPTS_VALUE mismatch");
|
||||
static_assert(FB_TIME_BASE == AV_TIME_BASE, "FB_TIME_BASE mismatch");
|
||||
static_assert(FB_SCALER_POINT == SWS_POINT, "FB_SCALER_POINT mismatch");
|
||||
|
||||
static_assert(FB_PIX_FMT_NONE == AV_PIX_FMT_NONE, "FB_PIX_FMT_NONE mismatch");
|
||||
static_assert(fb_pix_fmt_none == AV_PIX_FMT_NONE, "FB_PIX_FMT_NONE mismatch");
|
||||
|
||||
static_assert(FB_SAMPLE_FMT_NONE == AV_SAMPLE_FMT_NONE, "samplefmt mismatch");
|
||||
static_assert(FB_SAMPLE_FMT_U8 == AV_SAMPLE_FMT_U8, "samplefmt mismatch");
|
||||
static_assert(FB_SAMPLE_FMT_S16 == AV_SAMPLE_FMT_S16, "samplefmt mismatch");
|
||||
static_assert(FB_SAMPLE_FMT_S32 == AV_SAMPLE_FMT_S32, "samplefmt mismatch");
|
||||
static_assert(FB_SAMPLE_FMT_FLT == AV_SAMPLE_FMT_FLT, "samplefmt mismatch");
|
||||
static_assert(FB_SAMPLE_FMT_DBL == AV_SAMPLE_FMT_DBL, "samplefmt mismatch");
|
||||
static_assert(FB_SAMPLE_FMT_U8P == AV_SAMPLE_FMT_U8P, "samplefmt mismatch");
|
||||
static_assert(FB_SAMPLE_FMT_S16P == AV_SAMPLE_FMT_S16P, "samplefmt mismatch");
|
||||
static_assert(FB_SAMPLE_FMT_S32P == AV_SAMPLE_FMT_S32P, "samplefmt mismatch");
|
||||
static_assert(FB_SAMPLE_FMT_FLTP == AV_SAMPLE_FMT_FLTP, "samplefmt mismatch");
|
||||
static_assert(FB_SAMPLE_FMT_DBLP == AV_SAMPLE_FMT_DBLP, "samplefmt mismatch");
|
||||
static_assert(FB_SAMPLE_FMT_S64 == AV_SAMPLE_FMT_S64, "samplefmt mismatch");
|
||||
static_assert(FB_SAMPLE_FMT_S64P == AV_SAMPLE_FMT_S64P, "samplefmt mismatch");
|
||||
static_assert(fb_sample_fmt_none == AV_SAMPLE_FMT_NONE, "samplefmt mismatch");
|
||||
static_assert(fb_sample_fmt_u8 == AV_SAMPLE_FMT_U8, "samplefmt mismatch");
|
||||
static_assert(fb_sample_fmt_s16 == AV_SAMPLE_FMT_S16, "samplefmt mismatch");
|
||||
static_assert(fb_sample_fmt_s32 == AV_SAMPLE_FMT_S32, "samplefmt mismatch");
|
||||
static_assert(fb_sample_fmt_flt == AV_SAMPLE_FMT_FLT, "samplefmt mismatch");
|
||||
static_assert(fb_sample_fmt_dbl == AV_SAMPLE_FMT_DBL, "samplefmt mismatch");
|
||||
static_assert(fb_sample_fmt_u8_p == AV_SAMPLE_FMT_U8P, "samplefmt mismatch");
|
||||
static_assert(fb_sample_fmt_s16_p == AV_SAMPLE_FMT_S16P, "samplefmt mismatch");
|
||||
static_assert(fb_sample_fmt_s32_p == AV_SAMPLE_FMT_S32P, "samplefmt mismatch");
|
||||
static_assert(fb_sample_fmt_fltp == AV_SAMPLE_FMT_FLTP, "samplefmt mismatch");
|
||||
static_assert(fb_sample_fmt_dblp == AV_SAMPLE_FMT_DBLP, "samplefmt mismatch");
|
||||
static_assert(fb_sample_fmt_s64 == AV_SAMPLE_FMT_S64, "samplefmt mismatch");
|
||||
static_assert(fb_sample_fmt_s64_p == AV_SAMPLE_FMT_S64P, "samplefmt mismatch");
|
||||
|
||||
static_assert(FB_COLOR_RANGE_UNSPEC == AVCOL_RANGE_UNSPECIFIED, "range mismatch");
|
||||
static_assert(FB_COLOR_RANGE_MPEG == AVCOL_RANGE_MPEG, "range mismatch");
|
||||
static_assert(FB_COLOR_RANGE_JPEG == AVCOL_RANGE_JPEG, "range mismatch");
|
||||
static_assert(fb_color_range_unspec == AVCOL_RANGE_UNSPECIFIED, "range mismatch");
|
||||
static_assert(fb_color_range_mpeg == AVCOL_RANGE_MPEG, "range mismatch");
|
||||
static_assert(fb_color_range_jpeg == AVCOL_RANGE_JPEG, "range mismatch");
|
||||
|
||||
static_assert(FB_COL_SPC_RGB == AVCOL_SPC_RGB, "colspace mismatch");
|
||||
static_assert(FB_COL_SPC_BT709 == AVCOL_SPC_BT709, "colspace mismatch");
|
||||
static_assert(FB_COL_SPC_UNSPEC == AVCOL_SPC_UNSPECIFIED, "colspace mismatch");
|
||||
static_assert(FB_COL_SPC_FCC == AVCOL_SPC_FCC, "colspace mismatch");
|
||||
static_assert(FB_COL_SPC_BT470BG == AVCOL_SPC_BT470BG, "colspace mismatch");
|
||||
static_assert(FB_COL_SPC_SMPTE170M == AVCOL_SPC_SMPTE170M, "colspace mismatch");
|
||||
static_assert(FB_COL_SPC_SMPTE240M == AVCOL_SPC_SMPTE240M, "colspace mismatch");
|
||||
static_assert(FB_COL_SPC_BT2020_NCL == AVCOL_SPC_BT2020_NCL, "colspace mismatch");
|
||||
static_assert(fb_col_spc_rgb == AVCOL_SPC_RGB, "colspace mismatch");
|
||||
static_assert(fb_col_spc_b_t709 == AVCOL_SPC_BT709, "colspace mismatch");
|
||||
static_assert(fb_col_spc_unspec == AVCOL_SPC_UNSPECIFIED, "colspace mismatch");
|
||||
static_assert(fb_col_spc_fcc == AVCOL_SPC_FCC, "colspace mismatch");
|
||||
static_assert(fb_col_spc_b_t470_bg == AVCOL_SPC_BT470BG, "colspace mismatch");
|
||||
static_assert(fb_col_spc_smpt_e170_m == AVCOL_SPC_SMPTE170M, "colspace mismatch");
|
||||
static_assert(fb_col_spc_smpt_e240_m == AVCOL_SPC_SMPTE240M, "colspace mismatch");
|
||||
static_assert(fb_col_spc_b_t2020_ncl == AVCOL_SPC_BT2020_NCL, "colspace mismatch");
|
||||
|
||||
static_assert(FB_MEDIA_TYPE_VIDEO == AVMEDIA_TYPE_VIDEO, "mediatype mismatch");
|
||||
static_assert(FB_MEDIA_TYPE_AUDIO == AVMEDIA_TYPE_AUDIO, "mediatype mismatch");
|
||||
static_assert(FB_MEDIA_TYPE_DATA == AVMEDIA_TYPE_DATA, "mediatype mismatch");
|
||||
static_assert(FB_MEDIA_TYPE_SUBTITLE == AVMEDIA_TYPE_SUBTITLE, "mediatype mismatch");
|
||||
static_assert(fb_media_type_video == AVMEDIA_TYPE_VIDEO, "mediatype mismatch");
|
||||
static_assert(fb_media_type_audio == AVMEDIA_TYPE_AUDIO, "mediatype mismatch");
|
||||
static_assert(fb_media_type_data == AVMEDIA_TYPE_DATA, "mediatype mismatch");
|
||||
static_assert(fb_media_type_subtitle == AVMEDIA_TYPE_SUBTITLE, "mediatype mismatch");
|
||||
|
||||
static_assert(FB_FIELD_ORDER_UNKNOWN == AV_FIELD_UNKNOWN, "fieldorder mismatch");
|
||||
static_assert(FB_FIELD_ORDER_PROGRESSIVE == AV_FIELD_PROGRESSIVE, "fieldorder mismatch");
|
||||
static_assert(FB_FIELD_ORDER_TT == AV_FIELD_TT, "fieldorder mismatch");
|
||||
static_assert(FB_FIELD_ORDER_BB == AV_FIELD_BB, "fieldorder mismatch");
|
||||
static_assert(FB_FIELD_ORDER_TB == AV_FIELD_TB, "fieldorder mismatch");
|
||||
static_assert(FB_FIELD_ORDER_BT == AV_FIELD_BT, "fieldorder mismatch");
|
||||
static_assert(fb_field_order_unknown == AV_FIELD_UNKNOWN, "fieldorder mismatch");
|
||||
static_assert(fb_field_order_progressive == AV_FIELD_PROGRESSIVE, "fieldorder mismatch");
|
||||
static_assert(fb_field_order_tt == AV_FIELD_TT, "fieldorder mismatch");
|
||||
static_assert(fb_field_order_bb == AV_FIELD_BB, "fieldorder mismatch");
|
||||
static_assert(fb_field_order_tb == AV_FIELD_TB, "fieldorder mismatch");
|
||||
static_assert(fb_field_order_bt == AV_FIELD_BT, "fieldorder mismatch");
|
||||
|
||||
static_assert(FB_CH_LAYOUT_MONO == AV_CH_LAYOUT_MONO, "layout mismatch");
|
||||
static_assert(FB_CH_LAYOUT_STEREO == AV_CH_LAYOUT_STEREO, "layout mismatch");
|
||||
@@ -123,15 +123,15 @@ namespace fb
|
||||
|
||||
/** Allocate a channel layout from a mask, falling back to a default layout
|
||||
* derived from `fallback_channels` when the mask is zero. */
|
||||
void ChannelLayoutFromMask(AVChannelLayout *layout, uint64_t mask,
|
||||
void channel_layout_from_mask(AVChannelLayout *layout, uint64_t mask,
|
||||
int fallback_channels);
|
||||
|
||||
/** Validate a stream's channel layout, returning a usable mask (never zero
|
||||
* unless the stream truly has no channels). */
|
||||
uint64_t ValidateStreamChannelLayoutMask(const AVStream *stream);
|
||||
uint64_t validate_stream_channel_layout_mask(const AVStream *stream);
|
||||
|
||||
/** Map an AVColorSpace to the corresponding SWS_CS_* constant. */
|
||||
int SwsColorspaceFromAVColorSpace(AVColorSpace cs);
|
||||
int sws_colorspace_from_av_color_space(AVColorSpace cs);
|
||||
|
||||
/**
|
||||
* Translate an FB_PIX_FMT_* value to the AVPixelFormat of the FFmpeg build
|
||||
@@ -141,7 +141,7 @@ int SwsColorspaceFromAVColorSpace(AVColorSpace cs);
|
||||
* AV_PIX_FMT_NONE for FB_PIX_FMT_NONE and for static FB formats unknown to
|
||||
* this FFmpeg build (e.g. rgbf16le/grayf16le on FFmpeg < 7.1).
|
||||
*/
|
||||
AVPixelFormat PixFmtToAV(int fb_fmt);
|
||||
AVPixelFormat pix_fmt_to_av(int fb_fmt);
|
||||
|
||||
/**
|
||||
* Reverse of PixFmtToAV. Returns FB_PIX_FMT_NONE for AV_PIX_FMT_NONE.
|
||||
@@ -149,11 +149,11 @@ AVPixelFormat PixFmtToAV(int fb_fmt);
|
||||
* formats such as p210le, etc.) receive a process-local dynamic id >= 1000
|
||||
* so they can still round-trip through the API.
|
||||
*/
|
||||
int PixFmtFromAV(AVPixelFormat fmt);
|
||||
int pix_fmt_from_av(AVPixelFormat fmt);
|
||||
|
||||
void SetError(char *error_buffer, size_t error_buffer_size, const char *context,
|
||||
void set_error(char *error_buffer, size_t error_buffer_size, const char *context,
|
||||
int error_code);
|
||||
|
||||
} // namespace fb
|
||||
|
||||
#endif // FFMPEG_BRIDGE_INTERNAL_H
|
||||
#endif // OAK_FFMPEG_BRIDGE_INTERNAL_H
|
||||
|
||||
+15
-15
@@ -31,10 +31,10 @@ struct FBProbe {
|
||||
namespace
|
||||
{
|
||||
|
||||
constexpr int64_t kAnalyzeDurationUs = 5000000;
|
||||
constexpr int64_t kProbeSizeBytes = 20000000;
|
||||
constexpr int64_t k_analyze_duration_us = 5000000;
|
||||
constexpr int64_t k_probe_size_bytes = 20000000;
|
||||
|
||||
void FillStreamInfo(const AVStream *s, int has_decoder, FBStreamInfo *out)
|
||||
void fill_stream_info(const AVStream *s, int has_decoder, FBStreamInfo *out)
|
||||
{
|
||||
const AVCodecParameters *par = s->codecpar;
|
||||
|
||||
@@ -45,12 +45,12 @@ void FillStreamInfo(const AVStream *s, int has_decoder, FBStreamInfo *out)
|
||||
out->has_decoder = has_decoder;
|
||||
out->width = par->width;
|
||||
out->height = par->height;
|
||||
out->pixel_format = fb::PixFmtFromAV(AVPixelFormat(par->format));
|
||||
out->field_order = FB_FIELD_ORDER_UNKNOWN;
|
||||
out->pixel_format = fb::pix_fmt_from_av(AVPixelFormat(par->format));
|
||||
out->field_order = fb_field_order_unknown;
|
||||
out->color_range = par->color_range;
|
||||
out->sample_rate = par->sample_rate;
|
||||
out->sample_format = par->format;
|
||||
out->channel_layout_mask = fb::ValidateStreamChannelLayoutMask(s);
|
||||
out->channel_layout_mask = fb::validate_stream_channel_layout_mask(s);
|
||||
out->start_time = s->start_time;
|
||||
out->duration = s->duration;
|
||||
out->time_base_num = s->time_base.num;
|
||||
@@ -59,7 +59,7 @@ void FillStreamInfo(const AVStream *s, int has_decoder, FBStreamInfo *out)
|
||||
out->avg_frame_rate_den = s->avg_frame_rate.den;
|
||||
}
|
||||
|
||||
bool IsCancelled(FBCancelCallback cancel, void *userdata)
|
||||
bool is_cancelled(FBCancelCallback cancel, void *userdata)
|
||||
{
|
||||
return cancel && cancel(userdata);
|
||||
}
|
||||
@@ -87,16 +87,16 @@ int fb_probe_open(FBProbe *probe, const char *filename)
|
||||
}
|
||||
|
||||
AVDictionary *format_opts = nullptr;
|
||||
av_dict_set_int(&format_opts, "analyzeduration", kAnalyzeDurationUs, 0);
|
||||
av_dict_set_int(&format_opts, "probesize", kProbeSizeBytes, 0);
|
||||
av_dict_set_int(&format_opts, "analyzeduration", k_analyze_duration_us, 0);
|
||||
av_dict_set_int(&format_opts, "probesize", k_probe_size_bytes, 0);
|
||||
|
||||
AVFormatContext *ctx = nullptr;
|
||||
int error_code = avformat_open_input(&ctx, filename, nullptr, &format_opts);
|
||||
av_dict_free(&format_opts);
|
||||
|
||||
if (ctx) {
|
||||
ctx->probesize = kProbeSizeBytes;
|
||||
ctx->max_analyze_duration = kAnalyzeDurationUs;
|
||||
ctx->probesize = k_probe_size_bytes;
|
||||
ctx->max_analyze_duration = k_analyze_duration_us;
|
||||
|
||||
// Subtitle streams are read on demand, don't let them slow down probing
|
||||
for (unsigned int i = 0; i < ctx->nb_streams; i++) {
|
||||
@@ -144,7 +144,7 @@ int fb_probe_get_stream_info(const FBProbe *probe, int stream_index,
|
||||
|
||||
const AVStream *s = probe->fmt_ctx->streams[stream_index];
|
||||
int has_decoder = avcodec_find_decoder(s->codecpar->codec_id) != nullptr;
|
||||
FillStreamInfo(s, has_decoder, out);
|
||||
fill_stream_info(s, has_decoder, out);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ int fb_probe_video_stream_details(const char *filename, int stream_index,
|
||||
}
|
||||
|
||||
memset(out, 0, sizeof(*out));
|
||||
out->field_order = FB_FIELD_ORDER_PROGRESSIVE;
|
||||
out->field_order = fb_field_order_progressive;
|
||||
out->pixel_aspect_num = 1;
|
||||
out->pixel_aspect_den = 1;
|
||||
out->decoded_duration = FB_NOPTS_VALUE;
|
||||
@@ -250,7 +250,7 @@ int fb_probe_video_stream_details(const char *filename, int stream_index,
|
||||
// Decode until the end to determine the true duration
|
||||
int64_t last_ts = fb_frame_get_best_effort_timestamp(frame);
|
||||
while (fb_decoder_get_frame(decoder, pkt, frame) >= 0 &&
|
||||
!IsCancelled(cancel, cancel_userdata)) {
|
||||
!is_cancelled(cancel, cancel_userdata)) {
|
||||
last_ts = fb_frame_get_best_effort_timestamp(frame);
|
||||
}
|
||||
out->decoded_duration = last_ts;
|
||||
@@ -285,7 +285,7 @@ int fb_probe_audio_stream_duration(const char *filename, int stream_index,
|
||||
do {
|
||||
duration = fb_frame_get_best_effort_timestamp(frame);
|
||||
} while (fb_decoder_get_frame(decoder, pkt, frame) >= 0 &&
|
||||
!IsCancelled(cancel, cancel_userdata));
|
||||
!is_cancelled(cancel, cancel_userdata));
|
||||
|
||||
fb_frame_free(&frame);
|
||||
fb_packet_free(&pkt);
|
||||
|
||||
@@ -30,8 +30,8 @@ FBResampler *fb_resampler_create(uint64_t out_layout_mask, int out_format,
|
||||
int in_format, int in_rate)
|
||||
{
|
||||
AVChannelLayout out_layout, in_layout;
|
||||
fb::ChannelLayoutFromMask(&out_layout, out_layout_mask, 0);
|
||||
fb::ChannelLayoutFromMask(&in_layout, in_layout_mask, 0);
|
||||
fb::channel_layout_from_mask(&out_layout, out_layout_mask, 0);
|
||||
fb::channel_layout_from_mask(&in_layout, in_layout_mask, 0);
|
||||
|
||||
SwrContext *ctx = nullptr;
|
||||
int r = swr_alloc_set_opts2(&ctx, &out_layout,
|
||||
|
||||
@@ -30,8 +30,8 @@ FBScaler *fb_scaler_create(int src_width, int src_height, int src_format,
|
||||
int flags)
|
||||
{
|
||||
SwsContext *ctx = sws_getContext(
|
||||
src_width, src_height, fb::PixFmtToAV(src_format),
|
||||
dst_width, dst_height, fb::PixFmtToAV(dst_format), flags,
|
||||
src_width, src_height, fb::pix_fmt_to_av(src_format),
|
||||
dst_width, dst_height, fb::pix_fmt_to_av(dst_format), flags,
|
||||
nullptr, nullptr, nullptr);
|
||||
if (!ctx) {
|
||||
return nullptr;
|
||||
@@ -58,7 +58,7 @@ int fb_scaler_set_colorspace(FBScaler *scaler, int colorspace, int jpeg_range)
|
||||
}
|
||||
|
||||
const int *coeffs = sws_getCoefficients(
|
||||
fb::SwsColorspaceFromAVColorSpace(static_cast<AVColorSpace>(colorspace)));
|
||||
fb::sws_colorspace_from_av_color_space(static_cast<AVColorSpace>(colorspace)));
|
||||
return sws_setColorspaceDetails(scaler->ctx, coeffs, jpeg_range, coeffs,
|
||||
jpeg_range, 0, 0x10000, 0x10000);
|
||||
}
|
||||
@@ -85,7 +85,7 @@ int fb_scaler_scale_slices(FBScaler *scaler, const uint8_t *const *src_data,
|
||||
void fb_get_yuv_coefficients(int colorspace, double out[4])
|
||||
{
|
||||
const int *coeffs = sws_getCoefficients(
|
||||
fb::SwsColorspaceFromAVColorSpace(static_cast<AVColorSpace>(colorspace)));
|
||||
fb::sws_colorspace_from_av_color_space(static_cast<AVColorSpace>(colorspace)));
|
||||
// Matches the historical usage order: crv, cbu, cgu, cgv
|
||||
out[0] = coeffs[0] / 65536.0; // crv
|
||||
out[1] = coeffs[1] / 65536.0; // cbu
|
||||
|
||||
+56
-56
@@ -48,38 +48,38 @@ struct PixFmtName {
|
||||
const char *av_name;
|
||||
};
|
||||
|
||||
constexpr PixFmtName kPixFmtNames[] = {
|
||||
{ FB_PIX_FMT_YUV420P, "yuv420p" },
|
||||
{ FB_PIX_FMT_RGB24, "rgb24" },
|
||||
{ FB_PIX_FMT_YUV422P, "yuv422p" },
|
||||
{ FB_PIX_FMT_YUV444P, "yuv444p" },
|
||||
{ FB_PIX_FMT_YUV410P, "yuv410p" },
|
||||
{ FB_PIX_FMT_YUV411P, "yuv411p" },
|
||||
{ FB_PIX_FMT_GRAY8, "gray8" },
|
||||
{ FB_PIX_FMT_YUVJ420P, "yuvj420p" },
|
||||
{ FB_PIX_FMT_YUVJ422P, "yuvj422p" },
|
||||
{ FB_PIX_FMT_YUVJ444P, "yuvj444p" },
|
||||
{ FB_PIX_FMT_NV12, "nv12" },
|
||||
{ FB_PIX_FMT_RGBA, "rgba" },
|
||||
{ FB_PIX_FMT_GRAY16LE, "gray16le" },
|
||||
{ FB_PIX_FMT_YUV440P, "yuv440p" },
|
||||
{ FB_PIX_FMT_YUVJ440P, "yuvj440p" },
|
||||
{ FB_PIX_FMT_RGB48LE, "rgb48le" },
|
||||
{ FB_PIX_FMT_YUV420P10LE, "yuv420p10le" },
|
||||
{ FB_PIX_FMT_YUV422P10LE, "yuv422p10le" },
|
||||
{ FB_PIX_FMT_YUV444P10LE, "yuv444p10le" },
|
||||
{ FB_PIX_FMT_RGBA64LE, "rgba64le" },
|
||||
{ FB_PIX_FMT_YUV420P12LE, "yuv420p12le" },
|
||||
{ FB_PIX_FMT_YUV422P12LE, "yuv422p12le" },
|
||||
{ FB_PIX_FMT_YUV444P12LE, "yuv444p12le" },
|
||||
{ FB_PIX_FMT_YUVJ411P, "yuvj411p" },
|
||||
{ FB_PIX_FMT_P010LE, "p010le" },
|
||||
{ FB_PIX_FMT_GRAYF32LE, "grayf32le" },
|
||||
{ FB_PIX_FMT_RGBAF16LE, "rgbaf16le" },
|
||||
{ FB_PIX_FMT_RGBF32LE, "rgbf32le" },
|
||||
{ FB_PIX_FMT_RGBAF32LE, "rgbaf32le" },
|
||||
{ FB_PIX_FMT_RGBF16LE, "rgbf16le" },
|
||||
{ FB_PIX_FMT_GRAYF16LE, "grayf16le" },
|
||||
constexpr PixFmtName k_pix_fmt_names[] = {
|
||||
{ fb_pix_fmt_yu_v420_p, "yuv420p" },
|
||||
{ fb_pix_fmt_rg_b24, "rgb24" },
|
||||
{ fb_pix_fmt_yu_v422_p, "yuv422p" },
|
||||
{ fb_pix_fmt_yu_v444_p, "yuv444p" },
|
||||
{ fb_pix_fmt_yu_v410_p, "yuv410p" },
|
||||
{ fb_pix_fmt_yu_v411_p, "yuv411p" },
|
||||
{ fb_pix_fmt_gra_y8, "gray8" },
|
||||
{ fb_pix_fmt_yuv_j420_p, "yuvj420p" },
|
||||
{ fb_pix_fmt_yuv_j422_p, "yuvj422p" },
|
||||
{ fb_pix_fmt_yuv_j444_p, "yuvj444p" },
|
||||
{ fb_pix_fmt_n_v12, "nv12" },
|
||||
{ fb_pix_fmt_rgba, "rgba" },
|
||||
{ fb_pix_fmt_gra_y16_le, "gray16le" },
|
||||
{ fb_pix_fmt_yu_v440_p, "yuv440p" },
|
||||
{ fb_pix_fmt_yuv_j440_p, "yuvj440p" },
|
||||
{ fb_pix_fmt_rg_b48_le, "rgb48le" },
|
||||
{ fb_pix_fmt_yu_v420_p10_le, "yuv420p10le" },
|
||||
{ fb_pix_fmt_yu_v422_p10_le, "yuv422p10le" },
|
||||
{ fb_pix_fmt_yu_v444_p10_le, "yuv444p10le" },
|
||||
{ fb_pix_fmt_rgb_a64_le, "rgba64le" },
|
||||
{ fb_pix_fmt_yu_v420_p12_le, "yuv420p12le" },
|
||||
{ fb_pix_fmt_yu_v422_p12_le, "yuv422p12le" },
|
||||
{ fb_pix_fmt_yu_v444_p12_le, "yuv444p12le" },
|
||||
{ fb_pix_fmt_yuv_j411_p, "yuvj411p" },
|
||||
{ fb_pix_fmt_p010_le, "p010le" },
|
||||
{ fb_pix_fmt_gray_f32_le, "grayf32le" },
|
||||
{ fb_pix_fmt_rgba_f16_le, "rgbaf16le" },
|
||||
{ fb_pix_fmt_rgb_f32_le, "rgbf32le" },
|
||||
{ fb_pix_fmt_rgba_f32_le, "rgbaf32le" },
|
||||
{ fb_pix_fmt_rgb_f16_le, "rgbf16le" },
|
||||
{ fb_pix_fmt_gray_f16_le, "grayf16le" },
|
||||
};
|
||||
|
||||
} // namespace
|
||||
@@ -95,23 +95,23 @@ namespace
|
||||
* FB_PIX_FMT_* value and are not stable across runs, which is fine because
|
||||
* callers treat the values as opaque.
|
||||
*/
|
||||
constexpr int kDynamicPixFmtBase = 1000;
|
||||
constexpr int k_dynamic_pix_fmt_base = 1000;
|
||||
std::mutex g_dynamic_pix_fmt_mutex;
|
||||
std::vector<std::pair<int, AVPixelFormat>> g_dynamic_pix_fmts;
|
||||
|
||||
} // namespace
|
||||
|
||||
AVPixelFormat PixFmtToAV(int fb_fmt)
|
||||
AVPixelFormat pix_fmt_to_av(int fb_fmt)
|
||||
{
|
||||
if (fb_fmt == FB_PIX_FMT_NONE) {
|
||||
if (fb_fmt == fb_pix_fmt_none) {
|
||||
return AV_PIX_FMT_NONE;
|
||||
}
|
||||
for (const PixFmtName &entry : kPixFmtNames) {
|
||||
for (const PixFmtName &entry : k_pix_fmt_names) {
|
||||
if (entry.fb_fmt == fb_fmt) {
|
||||
return av_get_pix_fmt(entry.av_name);
|
||||
}
|
||||
}
|
||||
if (fb_fmt >= kDynamicPixFmtBase) {
|
||||
if (fb_fmt >= k_dynamic_pix_fmt_base) {
|
||||
std::lock_guard<std::mutex> lock(g_dynamic_pix_fmt_mutex);
|
||||
for (const auto &entry : g_dynamic_pix_fmts) {
|
||||
if (entry.first == fb_fmt) {
|
||||
@@ -122,14 +122,14 @@ AVPixelFormat PixFmtToAV(int fb_fmt)
|
||||
return AV_PIX_FMT_NONE;
|
||||
}
|
||||
|
||||
int PixFmtFromAV(AVPixelFormat fmt)
|
||||
int pix_fmt_from_av(AVPixelFormat fmt)
|
||||
{
|
||||
if (fmt == AV_PIX_FMT_NONE) {
|
||||
return FB_PIX_FMT_NONE;
|
||||
return fb_pix_fmt_none;
|
||||
}
|
||||
const char *name = av_get_pix_fmt_name(fmt);
|
||||
if (name) {
|
||||
for (const PixFmtName &entry : kPixFmtNames) {
|
||||
for (const PixFmtName &entry : k_pix_fmt_names) {
|
||||
if (strcmp(name, entry.av_name) == 0) {
|
||||
return entry.fb_fmt;
|
||||
}
|
||||
@@ -142,12 +142,12 @@ int PixFmtFromAV(AVPixelFormat fmt)
|
||||
return entry.first;
|
||||
}
|
||||
}
|
||||
const int id = kDynamicPixFmtBase + int(g_dynamic_pix_fmts.size());
|
||||
const int id = k_dynamic_pix_fmt_base + int(g_dynamic_pix_fmts.size());
|
||||
g_dynamic_pix_fmts.emplace_back(id, fmt);
|
||||
return id;
|
||||
}
|
||||
|
||||
void ChannelLayoutFromMask(AVChannelLayout *layout, uint64_t mask,
|
||||
void channel_layout_from_mask(AVChannelLayout *layout, uint64_t mask,
|
||||
int fallback_channels)
|
||||
{
|
||||
if (mask != 0) {
|
||||
@@ -161,7 +161,7 @@ void ChannelLayoutFromMask(AVChannelLayout *layout, uint64_t mask,
|
||||
av_channel_layout_default(layout, fallback_channels);
|
||||
}
|
||||
|
||||
uint64_t ValidateStreamChannelLayoutMask(const AVStream *stream)
|
||||
uint64_t validate_stream_channel_layout_mask(const AVStream *stream)
|
||||
{
|
||||
if (!stream || !stream->codecpar) {
|
||||
return 0;
|
||||
@@ -188,7 +188,7 @@ uint64_t ValidateStreamChannelLayoutMask(const AVStream *stream)
|
||||
return mask;
|
||||
}
|
||||
|
||||
int SwsColorspaceFromAVColorSpace(AVColorSpace cs)
|
||||
int sws_colorspace_from_av_color_space(AVColorSpace cs)
|
||||
{
|
||||
switch (cs) {
|
||||
case AVCOL_SPC_BT709:
|
||||
@@ -210,7 +210,7 @@ int SwsColorspaceFromAVColorSpace(AVColorSpace cs)
|
||||
return SWS_CS_DEFAULT;
|
||||
}
|
||||
|
||||
void SetError(char *error_buffer, size_t error_buffer_size, const char *context,
|
||||
void set_error(char *error_buffer, size_t error_buffer_size, const char *context,
|
||||
int error_code)
|
||||
{
|
||||
if (!error_buffer || error_buffer_size == 0) {
|
||||
@@ -252,18 +252,18 @@ const char *fb_version_string(void)
|
||||
|
||||
const char *fb_pix_fmt_name(int pix_fmt)
|
||||
{
|
||||
return av_get_pix_fmt_name(fb::PixFmtToAV(pix_fmt));
|
||||
return av_get_pix_fmt_name(fb::pix_fmt_to_av(pix_fmt));
|
||||
}
|
||||
|
||||
int fb_pix_fmt_from_name(const char *name)
|
||||
{
|
||||
return fb::PixFmtFromAV(av_get_pix_fmt(name));
|
||||
return fb::pix_fmt_from_av(av_get_pix_fmt(name));
|
||||
}
|
||||
|
||||
int fb_pix_fmt_bits_per_pixel(int pix_fmt)
|
||||
{
|
||||
const AVPixFmtDescriptor *desc =
|
||||
av_pix_fmt_desc_get(fb::PixFmtToAV(pix_fmt));
|
||||
av_pix_fmt_desc_get(fb::pix_fmt_to_av(pix_fmt));
|
||||
if (!desc) {
|
||||
return 0;
|
||||
}
|
||||
@@ -273,21 +273,21 @@ int fb_pix_fmt_bits_per_pixel(int pix_fmt)
|
||||
int fb_pix_fmt_has_alpha(int pix_fmt)
|
||||
{
|
||||
const AVPixFmtDescriptor *desc =
|
||||
av_pix_fmt_desc_get(fb::PixFmtToAV(pix_fmt));
|
||||
av_pix_fmt_desc_get(fb::pix_fmt_to_av(pix_fmt));
|
||||
return desc && (desc->flags & AV_PIX_FMT_FLAG_ALPHA);
|
||||
}
|
||||
|
||||
int fb_pix_fmt_is_planar(int pix_fmt)
|
||||
{
|
||||
const AVPixFmtDescriptor *desc =
|
||||
av_pix_fmt_desc_get(fb::PixFmtToAV(pix_fmt));
|
||||
av_pix_fmt_desc_get(fb::pix_fmt_to_av(pix_fmt));
|
||||
return desc && (desc->flags & AV_PIX_FMT_FLAG_PLANAR);
|
||||
}
|
||||
|
||||
int fb_pix_fmt_component_size(int pix_fmt)
|
||||
{
|
||||
const AVPixFmtDescriptor *desc =
|
||||
av_pix_fmt_desc_get(fb::PixFmtToAV(pix_fmt));
|
||||
av_pix_fmt_desc_get(fb::pix_fmt_to_av(pix_fmt));
|
||||
if (!desc || desc->nb_components == 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -300,25 +300,25 @@ int fb_find_best_pix_fmt_of_list(const int *list, int pix_fmt)
|
||||
// Translate the FB_PIX_FMT_NONE-terminated list to AVPixelFormat values,
|
||||
// skipping formats unknown to this FFmpeg build
|
||||
std::vector<AVPixelFormat> av_list;
|
||||
for (int i = 0; list[i] != FB_PIX_FMT_NONE; i++) {
|
||||
AVPixelFormat fmt = fb::PixFmtToAV(list[i]);
|
||||
for (int i = 0; list[i] != fb_pix_fmt_none; i++) {
|
||||
AVPixelFormat fmt = fb::pix_fmt_to_av(list[i]);
|
||||
if (fmt != AV_PIX_FMT_NONE) {
|
||||
av_list.push_back(fmt);
|
||||
}
|
||||
}
|
||||
if (av_list.empty()) {
|
||||
return FB_PIX_FMT_NONE;
|
||||
return fb_pix_fmt_none;
|
||||
}
|
||||
|
||||
// With an unknown source format there is no loss metric to compare
|
||||
// against; prefer the first (most desirable) list entry
|
||||
AVPixelFormat av_src = fb::PixFmtToAV(pix_fmt);
|
||||
AVPixelFormat av_src = fb::pix_fmt_to_av(pix_fmt);
|
||||
if (av_src == AV_PIX_FMT_NONE) {
|
||||
return list[0];
|
||||
}
|
||||
|
||||
av_list.push_back(AV_PIX_FMT_NONE);
|
||||
return fb::PixFmtFromAV(avcodec_find_best_pix_fmt_of_list(
|
||||
return fb::pix_fmt_from_av(avcodec_find_best_pix_fmt_of_list(
|
||||
av_list.data(), av_src, 1, nullptr));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user