FFmpeg
Data Structures | Macros | Functions | Variables
mfenc.c File Reference
#include "encode.h"
#include "mf_utils.h"
#include "libavutil/imgutils.h"
#include "libavutil/opt.h"
#include "libavutil/time.h"
#include "internal.h"

Go to the source code of this file.

Data Structures

struct  MFContext
 

Macros

#define COBJMACROS
 
#define _WIN32_WINNT   0x0602
 
#define MF_TIMEBASE   (AVRational){1, 10000000}
 
#define MF_INVALID_TIME   AV_NOPTS_VALUE
 
#define OFFSET(x)   offsetof(MFContext, x)
 
#define MF_ENCODER(MEDIATYPE, NAME, ID, OPTS, EXTRA)
 
#define AFMTS
 
#define VE   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 
#define VFMTS
 

Functions

static int mf_choose_output_type (AVCodecContext *avctx)
 
static int mf_setup_context (AVCodecContext *avctx)
 
static int mf_wait_events (AVCodecContext *avctx)
 
static AVRational mf_get_tb (AVCodecContext *avctx)
 
static LONGLONG mf_to_mf_time (AVCodecContext *avctx, int64_t av_pts)
 
static void mf_sample_set_pts (AVCodecContext *avctx, IMFSample *sample, int64_t av_pts)
 
static int64_t mf_from_mf_time (AVCodecContext *avctx, LONGLONG stime)
 
static int64_t mf_sample_get_pts (AVCodecContext *avctx, IMFSample *sample)
 
static int mf_enca_output_type_get (AVCodecContext *avctx, IMFMediaType *type)
 
static int mf_encv_output_type_get (AVCodecContext *avctx, IMFMediaType *type)
 
static int mf_output_type_get (AVCodecContext *avctx)
 
static int mf_sample_to_avpacket (AVCodecContext *avctx, IMFSample *sample, AVPacket *avpkt)
 
static IMFSample * mf_a_avframe_to_sample (AVCodecContext *avctx, const AVFrame *frame)
 
static IMFSample * mf_v_avframe_to_sample (AVCodecContext *avctx, const AVFrame *frame)
 
static IMFSample * mf_avframe_to_sample (AVCodecContext *avctx, const AVFrame *frame)
 
static int mf_send_sample (AVCodecContext *avctx, IMFSample *sample)
 
static int mf_receive_sample (AVCodecContext *avctx, IMFSample **out_sample)
 
static int mf_receive_packet (AVCodecContext *avctx, AVPacket *avpkt)
 
static int64_t mf_enca_output_score (AVCodecContext *avctx, IMFMediaType *type)
 
static int mf_enca_output_adjust (AVCodecContext *avctx, IMFMediaType *type)
 
static int64_t mf_enca_input_score (AVCodecContext *avctx, IMFMediaType *type)
 
static int mf_enca_input_adjust (AVCodecContext *avctx, IMFMediaType *type)
 
static int64_t mf_encv_output_score (AVCodecContext *avctx, IMFMediaType *type)
 
static int mf_encv_output_adjust (AVCodecContext *avctx, IMFMediaType *type)
 
static int64_t mf_encv_input_score (AVCodecContext *avctx, IMFMediaType *type)
 
static int mf_encv_input_adjust (AVCodecContext *avctx, IMFMediaType *type)
 
static int mf_choose_input_type (AVCodecContext *avctx)
 
static int mf_negotiate_types (AVCodecContext *avctx)
 
static int mf_unlock_async (AVCodecContext *avctx)
 
static int mf_create (void *log, IMFTransform **mft, const AVCodec *codec, int use_hw)
 
static int mf_init (AVCodecContext *avctx)
 
static int mf_close (AVCodecContext *avctx)
 
 MF_ENCODER (AUDIO, aac, AAC, NULL, AFMTS)
 
 MF_ENCODER (AUDIO, ac3, AC3, NULL, AFMTS)
 
 MF_ENCODER (AUDIO, mp3, MP3, NULL, AFMTS)
 
 MF_ENCODER (VIDEO, h264, H264, venc_opts, VFMTS)
 
 MF_ENCODER (VIDEO, hevc, HEVC, venc_opts, VFMTS)
 

Variables

static const AVOption venc_opts []
 

Macro Definition Documentation

#define COBJMACROS

Definition at line 19 of file mfenc.c.

#define _WIN32_WINNT   0x0602

Definition at line 22 of file mfenc.c.

#define MF_TIMEBASE   (AVRational){1, 10000000}

Definition at line 58 of file mfenc.c.

Referenced by mf_from_mf_time(), mf_get_tb(), and mf_to_mf_time().

#define MF_INVALID_TIME   AV_NOPTS_VALUE

Definition at line 60 of file mfenc.c.

Referenced by mf_sample_set_pts(), and mf_to_mf_time().

#define OFFSET (   x)    offsetof(MFContext, x)

Definition at line 1146 of file mfenc.c.

#define MF_ENCODER (   MEDIATYPE,
  NAME,
  ID,
  OPTS,
  EXTRA 
)
Value:
static const AVClass ff_ ## NAME ## _mf_encoder_class = { \
.class_name = #NAME "_mf", \
.item_name = av_default_item_name, \
.option = OPTS, \
.version = LIBAVUTIL_VERSION_INT, \
}; \
AVCodec ff_ ## NAME ## _mf_encoder = { \
.priv_class = &ff_ ## NAME ## _mf_encoder_class, \
.name = #NAME "_mf", \
.long_name = NULL_IF_CONFIG_SMALL(#ID " via MediaFoundation"), \
.type = AVMEDIA_TYPE_ ## MEDIATYPE, \
.id = AV_CODEC_ID_ ## ID, \
.priv_data_size = sizeof(MFContext), \
.init = mf_init, \
.close = mf_close, \
.receive_packet = mf_receive_packet, \
EXTRA \
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | \
};
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: internal.h:48
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:31
static int mf_close(AVCodecContext *avctx)
Definition: mfenc.c:1126
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: codec.h:75
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Definition: internal.h:40
static int mf_init(AVCodecContext *avctx)
Definition: mfenc.c:1038
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:115
#define ID(x)
Definition: cast5.c:29
#define AV_CODEC_CAP_HYBRID
Codec is potentially backed by a hardware implementation, but not necessarily.
Definition: codec.h:157
Describe the class of an AVClass context structure.
Definition: log.h:67
static int mf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
Definition: mfenc.c:483

Definition at line 1148 of file mfenc.c.

#define AFMTS
Value:
.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16, \
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
signed 16 bits
Definition: samplefmt.h:61

Definition at line 1171 of file mfenc.c.

Definition at line 1179 of file mfenc.c.

#define VFMTS
Value:
.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12, \
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:89
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64

Definition at line 1206 of file mfenc.c.

Function Documentation

static int mf_choose_output_type ( AVCodecContext avctx)
static

Definition at line 728 of file mfenc.c.

Referenced by mf_negotiate_types(), and mf_receive_sample().

static int mf_setup_context ( AVCodecContext avctx)
static

Definition at line 932 of file mfenc.c.

Referenced by mf_init(), and mf_receive_sample().

static int mf_wait_events ( AVCodecContext avctx)
static

Definition at line 62 of file mfenc.c.

Referenced by mf_receive_sample(), and mf_send_sample().

static AVRational mf_get_tb ( AVCodecContext avctx)
static

Definition at line 101 of file mfenc.c.

Referenced by mf_from_mf_time(), and mf_to_mf_time().

static LONGLONG mf_to_mf_time ( AVCodecContext avctx,
int64_t  av_pts 
)
static

Definition at line 110 of file mfenc.c.

Referenced by mf_a_avframe_to_sample(), mf_sample_set_pts(), and mf_v_avframe_to_sample().

static void mf_sample_set_pts ( AVCodecContext avctx,
IMFSample *  sample,
int64_t  av_pts 
)
static

Definition at line 117 of file mfenc.c.

Referenced by mf_avframe_to_sample().

static int64_t mf_from_mf_time ( AVCodecContext avctx,
LONGLONG  stime 
)
static

Definition at line 124 of file mfenc.c.

Referenced by mf_sample_get_pts(), and mf_sample_to_avpacket().

static int64_t mf_sample_get_pts ( AVCodecContext avctx,
IMFSample *  sample 
)
static

Definition at line 129 of file mfenc.c.

Referenced by mf_sample_to_avpacket().

static int mf_enca_output_type_get ( AVCodecContext avctx,
IMFMediaType *  type 
)
static

Definition at line 138 of file mfenc.c.

Referenced by mf_output_type_get().

static int mf_encv_output_type_get ( AVCodecContext avctx,
IMFMediaType *  type 
)
static

Definition at line 178 of file mfenc.c.

Referenced by mf_output_type_get().

static int mf_output_type_get ( AVCodecContext avctx)
static

Definition at line 201 of file mfenc.c.

Referenced by mf_init(), and mf_setup_context().

static int mf_sample_to_avpacket ( AVCodecContext avctx,
IMFSample *  sample,
AVPacket avpkt 
)
static

Definition at line 231 of file mfenc.c.

Referenced by mf_receive_packet().

static IMFSample* mf_a_avframe_to_sample ( AVCodecContext avctx,
const AVFrame frame 
)
static

Definition at line 286 of file mfenc.c.

Referenced by mf_avframe_to_sample().

static IMFSample* mf_v_avframe_to_sample ( AVCodecContext avctx,
const AVFrame frame 
)
static

Definition at line 302 of file mfenc.c.

Referenced by mf_avframe_to_sample().

static IMFSample* mf_avframe_to_sample ( AVCodecContext avctx,
const AVFrame frame 
)
static

Definition at line 348 of file mfenc.c.

Referenced by mf_receive_packet().

static int mf_send_sample ( AVCodecContext avctx,
IMFSample *  sample 
)
static

Definition at line 365 of file mfenc.c.

Referenced by mf_receive_packet().

static int mf_receive_sample ( AVCodecContext avctx,
IMFSample **  out_sample 
)
static

Definition at line 403 of file mfenc.c.

Referenced by mf_receive_packet().

static int mf_receive_packet ( AVCodecContext avctx,
AVPacket avpkt 
)
static

Definition at line 483 of file mfenc.c.

static int64_t mf_enca_output_score ( AVCodecContext avctx,
IMFMediaType *  type 
)
static

Definition at line 528 of file mfenc.c.

Referenced by mf_choose_output_type().

static int mf_enca_output_adjust ( AVCodecContext avctx,
IMFMediaType *  type 
)
static

Definition at line 568 of file mfenc.c.

Referenced by mf_choose_output_type().

static int64_t mf_enca_input_score ( AVCodecContext avctx,
IMFMediaType *  type 
)
static

Definition at line 578 of file mfenc.c.

Referenced by mf_choose_input_type().

static int mf_enca_input_adjust ( AVCodecContext avctx,
IMFMediaType *  type 
)
static

Definition at line 602 of file mfenc.c.

Referenced by mf_choose_input_type().

static int64_t mf_encv_output_score ( AVCodecContext avctx,
IMFMediaType *  type 
)
static

Definition at line 628 of file mfenc.c.

Referenced by mf_choose_output_type().

static int mf_encv_output_adjust ( AVCodecContext avctx,
IMFMediaType *  type 
)
static

Definition at line 644 of file mfenc.c.

Referenced by mf_choose_output_type().

static int64_t mf_encv_input_score ( AVCodecContext avctx,
IMFMediaType *  type 
)
static

Definition at line 706 of file mfenc.c.

Referenced by mf_choose_input_type().

static int mf_encv_input_adjust ( AVCodecContext avctx,
IMFMediaType *  type 
)
static

Definition at line 715 of file mfenc.c.

Referenced by mf_choose_input_type().

static int mf_choose_input_type ( AVCodecContext avctx)
static

Definition at line 817 of file mfenc.c.

Referenced by mf_negotiate_types().

static int mf_negotiate_types ( AVCodecContext avctx)
static

Definition at line 905 of file mfenc.c.

Referenced by mf_init().

static int mf_unlock_async ( AVCodecContext avctx)
static

Definition at line 960 of file mfenc.c.

Referenced by mf_init().

static int mf_create ( void log,
IMFTransform **  mft,
const AVCodec codec,
int  use_hw 
)
static

Definition at line 1009 of file mfenc.c.

Referenced by mf_init().

static int mf_init ( AVCodecContext avctx)
static

Definition at line 1038 of file mfenc.c.

static int mf_close ( AVCodecContext avctx)
static

Definition at line 1126 of file mfenc.c.

MF_ENCODER ( AUDIO  ,
aac  ,
AAC  ,
NULL  ,
AFMTS   
)
MF_ENCODER ( AUDIO  ,
ac3  ,
AC3  ,
NULL  ,
AFMTS   
)
MF_ENCODER ( AUDIO  ,
mp3  ,
MP3  ,
NULL  ,
AFMTS   
)
MF_ENCODER ( VIDEO  ,
h264  ,
H264  ,
venc_opts  ,
VFMTS   
)
MF_ENCODER ( VIDEO  ,
hevc  ,
HEVC  ,
venc_opts  ,
VFMTS   
)

Variable Documentation

const AVOption venc_opts[]
static
Initial value:
= {
{"rate_control", "Select rate control mode", OFFSET(opt_enc_rc), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, "rate_control"},
{ "default", "Default mode", 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, VE, "rate_control"},
{ "cbr", "CBR mode", 0, AV_OPT_TYPE_CONST, {.i64 = ff_eAVEncCommonRateControlMode_CBR}, 0, 0, VE, "rate_control"},
{ "pc_vbr", "Peak constrained VBR mode", 0, AV_OPT_TYPE_CONST, {.i64 = ff_eAVEncCommonRateControlMode_PeakConstrainedVBR}, 0, 0, VE, "rate_control"},
{ "u_vbr", "Unconstrained VBR mode", 0, AV_OPT_TYPE_CONST, {.i64 = ff_eAVEncCommonRateControlMode_UnconstrainedVBR}, 0, 0, VE, "rate_control"},
{ "quality", "Quality mode", 0, AV_OPT_TYPE_CONST, {.i64 = ff_eAVEncCommonRateControlMode_Quality}, 0, 0, VE, "rate_control" },
{ "ld_vbr", "Low delay VBR mode", 0, AV_OPT_TYPE_CONST, {.i64 = ff_eAVEncCommonRateControlMode_LowDelayVBR}, 0, 0, VE, "rate_control"},
{ "g_vbr", "Global VBR mode", 0, AV_OPT_TYPE_CONST, {.i64 = ff_eAVEncCommonRateControlMode_GlobalVBR}, 0, 0, VE, "rate_control" },
{ "gld_vbr", "Global low delay VBR mode", 0, AV_OPT_TYPE_CONST, {.i64 = ff_eAVEncCommonRateControlMode_GlobalLowDelayVBR}, 0, 0, VE, "rate_control"},
{"scenario", "Select usage scenario", OFFSET(opt_enc_scenario), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, "scenario"},
{ "default", "Default scenario", 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, VE, "scenario"},
{ "display_remoting", "Display remoting", 0, AV_OPT_TYPE_CONST, {.i64 = ff_eAVScenarioInfo_DisplayRemoting}, 0, 0, VE, "scenario"},
{ "video_conference", "Video conference", 0, AV_OPT_TYPE_CONST, {.i64 = ff_eAVScenarioInfo_VideoConference}, 0, 0, VE, "scenario"},
{ "archive", "Archive", 0, AV_OPT_TYPE_CONST, {.i64 = ff_eAVScenarioInfo_Archive}, 0, 0, VE, "scenario"},
{ "live_streaming", "Live streaming", 0, AV_OPT_TYPE_CONST, {.i64 = ff_eAVScenarioInfo_LiveStreaming}, 0, 0, VE, "scenario"},
{ "camera_record", "Camera record", 0, AV_OPT_TYPE_CONST, {.i64 = ff_eAVScenarioInfo_CameraRecord}, 0, 0, VE, "scenario"},
{ "display_remoting_with_feature_map", "Display remoting with feature map", 0, AV_OPT_TYPE_CONST, {.i64 = ff_eAVScenarioInfo_DisplayRemotingWithFeatureMap}, 0, 0, VE, "scenario"},
{"quality", "Quality", OFFSET(opt_enc_quality), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 100, VE},
{"hw_encoding", "Force hardware encoding", OFFSET(opt_enc_hw), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, VE},
{NULL}
}
#define NULL
Definition: coverity.c:32
#define OFFSET(x)
Definition: mfenc.c:1146
#define VE
Definition: mfenc.c:1179

Definition at line 1180 of file mfenc.c.