Skip to content

Commit fe8f6d0

Browse files
committed
feat(ffmpeg): add support for libavutil/imgutils.h
- Include libavutil/imgutils.h header across generated files - Add ptrdiff_t to primTypes mapping as int64 - Implement wrappers for image utility functions including: - AVImageGetLinesize - AVImageCopyPlane - AVImageCopyPlaneUcFrom - AVImageGetBufferSize - AVImageCheckSize - AVImageCheckSize2 - AVImageCheckSar
1 parent 2cd6991 commit fe8f6d0

7 files changed

Lines changed: 204 additions & 16 deletions

File tree

callbacks.gen.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import "unsafe"
6464
// #include <libavutil/hmac.h>
6565
// #include <libavutil/hwcontext.h>
6666
// #include <libavutil/iamf.h>
67+
// #include <libavutil/imgutils.h>
6768
// #include <libavutil/intfloat.h>
6869
// #include <libavutil/lfg.h>
6970
// #include <libavutil/log.h>

constants.gen.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ package ffmpeg
6262
// #include <libavutil/hmac.h>
6363
// #include <libavutil/hwcontext.h>
6464
// #include <libavutil/iamf.h>
65+
// #include <libavutil/imgutils.h>
6566
// #include <libavutil/intfloat.h>
6667
// #include <libavutil/lfg.h>
6768
// #include <libavutil/log.h>

enums.gen.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import "unsafe"
6464
// #include <libavutil/hmac.h>
6565
// #include <libavutil/hwcontext.h>
6666
// #include <libavutil/iamf.h>
67+
// #include <libavutil/imgutils.h>
6768
// #include <libavutil/intfloat.h>
6869
// #include <libavutil/lfg.h>
6970
// #include <libavutil/log.h>

functions.gen.go

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import "unsafe"
6464
// #include <libavutil/hmac.h>
6565
// #include <libavutil/hwcontext.h>
6666
// #include <libavutil/iamf.h>
67+
// #include <libavutil/imgutils.h>
6768
// #include <libavutil/intfloat.h>
6869
// #include <libavutil/lfg.h>
6970
// #include <libavutil/log.h>
@@ -12584,6 +12585,188 @@ func AVIamfMixPresentationFree(mixPresentation **AVIAMFMixPresentation) {
1258412585
}
1258512586
}
1258612587

12588+
// --- Function av_image_fill_max_pixsteps ---
12589+
12590+
// av_image_fill_max_pixsteps skipped due to const array param maxPixsteps
12591+
12592+
// --- Function av_image_get_linesize ---
12593+
12594+
// AVImageGetLinesize wraps av_image_get_linesize.
12595+
/*
12596+
Compute the size of an image line with format pix_fmt and width
12597+
width for the plane plane.
12598+
12599+
@return the computed size in bytes
12600+
*/
12601+
func AVImageGetLinesize(pixFmt AVPixelFormat, width int, plane int) (int, error) {
12602+
ret := C.av_image_get_linesize(C.enum_AVPixelFormat(pixFmt), C.int(width), C.int(plane))
12603+
return int(ret), WrapErr(int(ret))
12604+
}
12605+
12606+
// --- Function av_image_fill_linesizes ---
12607+
12608+
// av_image_fill_linesizes skipped due to const array param linesizes
12609+
12610+
// --- Function av_image_fill_plane_sizes ---
12611+
12612+
// av_image_fill_plane_sizes skipped due to const array param size
12613+
12614+
// --- Function av_image_fill_pointers ---
12615+
12616+
// av_image_fill_pointers skipped due to const array param data
12617+
12618+
// --- Function av_image_alloc ---
12619+
12620+
// av_image_alloc skipped due to const array param pointers
12621+
12622+
// --- Function av_image_copy_plane ---
12623+
12624+
// AVImageCopyPlane wraps av_image_copy_plane.
12625+
/*
12626+
Copy image plane from src to dst.
12627+
That is, copy "height" number of lines of "bytewidth" bytes each.
12628+
The first byte of each successive line is separated by *_linesize
12629+
bytes.
12630+
12631+
bytewidth must be contained by both absolute values of dst_linesize
12632+
and src_linesize, otherwise the function behavior is undefined.
12633+
12634+
@param dst destination plane to copy to
12635+
@param dst_linesize linesize for the image plane in dst
12636+
@param src source plane to copy from
12637+
@param src_linesize linesize for the image plane in src
12638+
@param height height (number of lines) of the plane
12639+
*/
12640+
func AVImageCopyPlane(dst unsafe.Pointer, dstLinesize int, src unsafe.Pointer, srcLinesize int, bytewidth int, height int) {
12641+
C.av_image_copy_plane((*C.uint8_t)(dst), C.int(dstLinesize), (*C.uint8_t)(src), C.int(srcLinesize), C.int(bytewidth), C.int(height))
12642+
}
12643+
12644+
// --- Function av_image_copy_plane_uc_from ---
12645+
12646+
// AVImageCopyPlaneUcFrom wraps av_image_copy_plane_uc_from.
12647+
/*
12648+
Copy image data located in uncacheable (e.g. GPU mapped) memory. Where
12649+
available, this function will use special functionality for reading from such
12650+
memory, which may result in greatly improved performance compared to plain
12651+
av_image_copy_plane().
12652+
12653+
bytewidth must be contained by both absolute values of dst_linesize
12654+
and src_linesize, otherwise the function behavior is undefined.
12655+
12656+
@note The linesize parameters have the type ptrdiff_t here, while they are
12657+
int for av_image_copy_plane().
12658+
@note On x86, the linesizes currently need to be aligned to the cacheline
12659+
size (i.e. 64) to get improved performance.
12660+
*/
12661+
func AVImageCopyPlaneUcFrom(dst unsafe.Pointer, dstLinesize int64, src unsafe.Pointer, srcLinesize int64, bytewidth int64, height int) {
12662+
C.av_image_copy_plane_uc_from((*C.uint8_t)(dst), C.ptrdiff_t(dstLinesize), (*C.uint8_t)(src), C.ptrdiff_t(srcLinesize), C.ptrdiff_t(bytewidth), C.int(height))
12663+
}
12664+
12665+
// --- Function av_image_copy ---
12666+
12667+
// av_image_copy skipped due to const array param dstData
12668+
12669+
// --- Function av_image_copy2 ---
12670+
12671+
// av_image_copy2 skipped due to const array param dstData
12672+
12673+
// --- Function av_image_copy_uc_from ---
12674+
12675+
// av_image_copy_uc_from skipped due to const array param dstData
12676+
12677+
// --- Function av_image_fill_arrays ---
12678+
12679+
// av_image_fill_arrays skipped due to const array param dstData
12680+
12681+
// --- Function av_image_get_buffer_size ---
12682+
12683+
// AVImageGetBufferSize wraps av_image_get_buffer_size.
12684+
/*
12685+
Return the size in bytes of the amount of data required to store an
12686+
image with the given parameters.
12687+
12688+
@param pix_fmt the pixel format of the image
12689+
@param width the width of the image in pixels
12690+
@param height the height of the image in pixels
12691+
@param align the assumed linesize alignment
12692+
@return the buffer size in bytes, a negative error code in case of failure
12693+
*/
12694+
func AVImageGetBufferSize(pixFmt AVPixelFormat, width int, height int, align int) (int, error) {
12695+
ret := C.av_image_get_buffer_size(C.enum_AVPixelFormat(pixFmt), C.int(width), C.int(height), C.int(align))
12696+
return int(ret), WrapErr(int(ret))
12697+
}
12698+
12699+
// --- Function av_image_copy_to_buffer ---
12700+
12701+
// av_image_copy_to_buffer skipped due to const array param srcData
12702+
12703+
// --- Function av_image_check_size ---
12704+
12705+
// AVImageCheckSize wraps av_image_check_size.
12706+
/*
12707+
Check if the given dimension of an image is valid, meaning that all
12708+
bytes of the image can be addressed with a signed int.
12709+
12710+
@param w the width of the picture
12711+
@param h the height of the picture
12712+
@param log_offset the offset to sum to the log level for logging with log_ctx
12713+
@param log_ctx the parent logging context, it may be NULL
12714+
@return >= 0 if valid, a negative error code otherwise
12715+
*/
12716+
func AVImageCheckSize(w uint, h uint, logOffset int, logCtx unsafe.Pointer) (int, error) {
12717+
ret := C.av_image_check_size(C.uint(w), C.uint(h), C.int(logOffset), logCtx)
12718+
return int(ret), WrapErr(int(ret))
12719+
}
12720+
12721+
// --- Function av_image_check_size2 ---
12722+
12723+
// AVImageCheckSize2 wraps av_image_check_size2.
12724+
/*
12725+
Check if the given dimension of an image is valid, meaning that all
12726+
bytes of a plane of an image with the specified pix_fmt can be addressed
12727+
with a signed int.
12728+
12729+
@param w the width of the picture
12730+
@param h the height of the picture
12731+
@param max_pixels the maximum number of pixels the user wants to accept
12732+
@param pix_fmt the pixel format, can be AV_PIX_FMT_NONE if unknown.
12733+
@param log_offset the offset to sum to the log level for logging with log_ctx
12734+
@param log_ctx the parent logging context, it may be NULL
12735+
@return >= 0 if valid, a negative error code otherwise
12736+
*/
12737+
func AVImageCheckSize2(w uint, h uint, maxPixels int64, pixFmt AVPixelFormat, logOffset int, logCtx unsafe.Pointer) (int, error) {
12738+
ret := C.av_image_check_size2(C.uint(w), C.uint(h), C.int64_t(maxPixels), C.enum_AVPixelFormat(pixFmt), C.int(logOffset), logCtx)
12739+
return int(ret), WrapErr(int(ret))
12740+
}
12741+
12742+
// --- Function av_image_check_sar ---
12743+
12744+
// AVImageCheckSar wraps av_image_check_sar.
12745+
/*
12746+
Check if the given sample aspect ratio of an image is valid.
12747+
12748+
It is considered invalid if the denominator is 0 or if applying the ratio
12749+
to the image size would make the smaller dimension less than 1. If the
12750+
sar numerator is 0, it is considered unknown and will return as valid.
12751+
12752+
@param w width of the image
12753+
@param h height of the image
12754+
@param sar sample aspect ratio of the image
12755+
@return 0 if valid, a negative AVERROR code otherwise
12756+
*/
12757+
func AVImageCheckSar(w uint, h uint, sar *AVRational) (int, error) {
12758+
ret := C.av_image_check_sar(C.uint(w), C.uint(h), sar.value)
12759+
return int(ret), WrapErr(int(ret))
12760+
}
12761+
12762+
// --- Function av_image_fill_black ---
12763+
12764+
// av_image_fill_black skipped due to const array param dstData
12765+
12766+
// --- Function av_image_fill_color ---
12767+
12768+
// av_image_fill_color skipped due to const array param dstData
12769+
1258712770
// --- Function av_int2float ---
1258812771

1258912772
// AVInt2Float wraps av_int2float.

internal/generator/generator.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@ import (
1414
)
1515

1616
var primTypes = map[string]string{
17-
"int": "int",
18-
"uint": "uint",
19-
"char": "uint8",
20-
"uchar": "uint8",
21-
"ulong": "uint32",
22-
"int16_t": "int16",
23-
"int32_t": "int32",
24-
"uint8_t": "uint8",
25-
"uint16_t": "uint16",
26-
"uint32_t": "uint32",
27-
"int64_t": "int64",
28-
"uint64_t": "uint64",
29-
"size_t": "uint64",
30-
"float": "float32",
31-
"double": "float64",
17+
"int": "int",
18+
"uint": "uint",
19+
"char": "uint8",
20+
"uchar": "uint8",
21+
"ulong": "uint32",
22+
"int16_t": "int16",
23+
"int32_t": "int32",
24+
"uint8_t": "uint8",
25+
"uint16_t": "uint16",
26+
"uint32_t": "uint32",
27+
"int64_t": "int64",
28+
"uint64_t": "uint64",
29+
"size_t": "uint64",
30+
"ptrdiff_t": "int64",
31+
"float": "float32",
32+
"double": "float64",
3233
}
3334

3435
// getCType returns the correct C type name to use in C.xxx() conversions.

internal/generator/parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ var files = []string{
8787
////"libavutil/hwcontext_videotoolbox.h",
8888
////"libavutil/hwcontext_vulkan.h",
8989
"libavutil/iamf.h",
90-
////"libavutil/imgutils.h", // undefined: ptrdiff_t
90+
"libavutil/imgutils.h",
9191
"libavutil/intfloat.h",
9292
////"libavutil/intreadwrite.h", //Unknown typedef kind UnionDecl
9393
"libavutil/lfg.h",

structs.gen.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import "unsafe"
6464
// #include <libavutil/hmac.h>
6565
// #include <libavutil/hwcontext.h>
6666
// #include <libavutil/iamf.h>
67+
// #include <libavutil/imgutils.h>
6768
// #include <libavutil/intfloat.h>
6869
// #include <libavutil/lfg.h>
6970
// #include <libavutil/log.h>

0 commit comments

Comments
 (0)