|
63 | 63 |
|
64 | 64 | // AVFrame offset discovery helpers |
65 | 65 | shimAVFrameColorOffsets func(outRange, outSpace, outPrimaries, outTransfer *int32) int32 |
| 66 | + |
| 67 | + // AVCodecParameters field helpers (optional) |
| 68 | + shimCodecParWidth func(par uintptr) int32 |
| 69 | + shimCodecParHeight func(par uintptr) int32 |
| 70 | + shimCodecParFormat func(par uintptr) int32 |
| 71 | + shimCodecParSampleRate func(par uintptr) int32 |
| 72 | + shimCodecParChannels func(par uintptr) int32 |
| 73 | + |
| 74 | + // AVCodecContext field helpers (optional) |
| 75 | + shimCodecCtxWidth func(ctx uintptr) int32 |
| 76 | + shimCodecCtxSetWidth func(ctx uintptr, width int32) |
| 77 | + shimCodecCtxHeight func(ctx uintptr) int32 |
| 78 | + shimCodecCtxSetHeight func(ctx uintptr, height int32) |
| 79 | + shimCodecCtxPixFmt func(ctx uintptr) int32 |
| 80 | + shimCodecCtxSetPixFmt func(ctx uintptr, pixFmt int32) |
| 81 | + shimCodecCtxTimeBase func(ctx uintptr, outNum, outDen *int32) |
| 82 | + shimCodecCtxSetTimeBase func(ctx uintptr, num, den int32) |
| 83 | + shimCodecCtxFramerate func(ctx uintptr, outNum, outDen *int32) |
| 84 | + shimCodecCtxSetFramerate func(ctx uintptr, num, den int32) |
66 | 85 | ) |
67 | 86 |
|
68 | 87 | // Load attempts to load the ffshim library. |
@@ -231,6 +250,25 @@ func registerBindings() { |
231 | 250 | registerOptionalLibFunc(&shimAVDeviceListInputSources, libShim, "ffshim_avdevice_list_input_sources") |
232 | 251 | registerOptionalLibFunc(&shimAVDeviceFreeStringArray, libShim, "ffshim_avdevice_free_string_array") |
233 | 252 | registerOptionalLibFunc(&shimAVFrameColorOffsets, libShim, "ffshim_avframe_color_offsets") |
| 253 | + |
| 254 | + // AVCodecParameters field helpers (optional) |
| 255 | + registerOptionalLibFunc(&shimCodecParWidth, libShim, "ffshim_codecpar_width") |
| 256 | + registerOptionalLibFunc(&shimCodecParHeight, libShim, "ffshim_codecpar_height") |
| 257 | + registerOptionalLibFunc(&shimCodecParFormat, libShim, "ffshim_codecpar_format") |
| 258 | + registerOptionalLibFunc(&shimCodecParSampleRate, libShim, "ffshim_codecpar_sample_rate") |
| 259 | + registerOptionalLibFunc(&shimCodecParChannels, libShim, "ffshim_codecpar_channels") |
| 260 | + |
| 261 | + // AVCodecContext field helpers (optional) |
| 262 | + registerOptionalLibFunc(&shimCodecCtxWidth, libShim, "ffshim_codecctx_width") |
| 263 | + registerOptionalLibFunc(&shimCodecCtxSetWidth, libShim, "ffshim_codecctx_set_width") |
| 264 | + registerOptionalLibFunc(&shimCodecCtxHeight, libShim, "ffshim_codecctx_height") |
| 265 | + registerOptionalLibFunc(&shimCodecCtxSetHeight, libShim, "ffshim_codecctx_set_height") |
| 266 | + registerOptionalLibFunc(&shimCodecCtxPixFmt, libShim, "ffshim_codecctx_pix_fmt") |
| 267 | + registerOptionalLibFunc(&shimCodecCtxSetPixFmt, libShim, "ffshim_codecctx_set_pix_fmt") |
| 268 | + registerOptionalLibFunc(&shimCodecCtxTimeBase, libShim, "ffshim_codecctx_time_base") |
| 269 | + registerOptionalLibFunc(&shimCodecCtxSetTimeBase, libShim, "ffshim_codecctx_set_time_base") |
| 270 | + registerOptionalLibFunc(&shimCodecCtxFramerate, libShim, "ffshim_codecctx_framerate") |
| 271 | + registerOptionalLibFunc(&shimCodecCtxSetFramerate, libShim, "ffshim_codecctx_set_framerate") |
234 | 272 | } |
235 | 273 |
|
236 | 274 | func registerOptionalLibFunc(fptr any, handle uintptr, name string) { |
@@ -296,9 +334,9 @@ func NewChapter(ctx unsafe.Pointer, id int64, tbNum, tbDen int32, start, end int |
296 | 334 | // AVDeviceListInputSources lists available input devices for a given avdevice input format. |
297 | 335 | // |
298 | 336 | // Returns: |
299 | | -// - count: number of devices |
300 | | -// - names/descs: pointers to shim-allocated string arrays (char**). Caller MUST free both arrays |
301 | | -// using AVDeviceFreeStringArray. |
| 337 | +// - count: number of devices |
| 338 | +// - names/descs: pointers to shim-allocated string arrays (char**). Caller MUST free both arrays |
| 339 | +// using AVDeviceFreeStringArray. |
302 | 340 | // |
303 | 341 | // This requires a shim build that links against libavdevice (built with -DFFSHIM_HAVE_AVDEVICE=1). |
304 | 342 | func AVDeviceListInputSources(formatName, deviceName string, avdictOpts unsafe.Pointer) (count int, names, descs unsafe.Pointer, err error) { |
@@ -346,6 +384,163 @@ func AVFrameColorOffsets() (rangeOff, spaceOff, primariesOff, transferOff int32, |
346 | 384 | return r, s, p, t, nil |
347 | 385 | } |
348 | 386 |
|
| 387 | +func CodecParWidth(par unsafe.Pointer) (int32, error) { |
| 388 | + if par == nil { |
| 389 | + return 0, nil |
| 390 | + } |
| 391 | + if !loaded || shimCodecParWidth == nil { |
| 392 | + return 0, ErrShimNotLoaded |
| 393 | + } |
| 394 | + return shimCodecParWidth(uintptr(par)), nil |
| 395 | +} |
| 396 | + |
| 397 | +func CodecParHeight(par unsafe.Pointer) (int32, error) { |
| 398 | + if par == nil { |
| 399 | + return 0, nil |
| 400 | + } |
| 401 | + if !loaded || shimCodecParHeight == nil { |
| 402 | + return 0, ErrShimNotLoaded |
| 403 | + } |
| 404 | + return shimCodecParHeight(uintptr(par)), nil |
| 405 | +} |
| 406 | + |
| 407 | +func CodecParFormat(par unsafe.Pointer) (int32, error) { |
| 408 | + if par == nil { |
| 409 | + return -1, nil |
| 410 | + } |
| 411 | + if !loaded || shimCodecParFormat == nil { |
| 412 | + return 0, ErrShimNotLoaded |
| 413 | + } |
| 414 | + return shimCodecParFormat(uintptr(par)), nil |
| 415 | +} |
| 416 | + |
| 417 | +func CodecParSampleRate(par unsafe.Pointer) (int32, error) { |
| 418 | + if par == nil { |
| 419 | + return 0, nil |
| 420 | + } |
| 421 | + if !loaded || shimCodecParSampleRate == nil { |
| 422 | + return 0, ErrShimNotLoaded |
| 423 | + } |
| 424 | + return shimCodecParSampleRate(uintptr(par)), nil |
| 425 | +} |
| 426 | + |
| 427 | +func CodecParChannels(par unsafe.Pointer) (int32, error) { |
| 428 | + if par == nil { |
| 429 | + return 0, nil |
| 430 | + } |
| 431 | + if !loaded || shimCodecParChannels == nil { |
| 432 | + return 0, ErrShimNotLoaded |
| 433 | + } |
| 434 | + return shimCodecParChannels(uintptr(par)), nil |
| 435 | +} |
| 436 | + |
| 437 | +func CodecCtxWidth(ctx unsafe.Pointer) (int32, error) { |
| 438 | + if ctx == nil { |
| 439 | + return 0, nil |
| 440 | + } |
| 441 | + if !loaded || shimCodecCtxWidth == nil { |
| 442 | + return 0, ErrShimNotLoaded |
| 443 | + } |
| 444 | + return shimCodecCtxWidth(uintptr(ctx)), nil |
| 445 | +} |
| 446 | + |
| 447 | +func CodecCtxSetWidth(ctx unsafe.Pointer, width int32) error { |
| 448 | + if ctx == nil { |
| 449 | + return nil |
| 450 | + } |
| 451 | + if !loaded || shimCodecCtxSetWidth == nil { |
| 452 | + return ErrShimNotLoaded |
| 453 | + } |
| 454 | + shimCodecCtxSetWidth(uintptr(ctx), width) |
| 455 | + return nil |
| 456 | +} |
| 457 | + |
| 458 | +func CodecCtxHeight(ctx unsafe.Pointer) (int32, error) { |
| 459 | + if ctx == nil { |
| 460 | + return 0, nil |
| 461 | + } |
| 462 | + if !loaded || shimCodecCtxHeight == nil { |
| 463 | + return 0, ErrShimNotLoaded |
| 464 | + } |
| 465 | + return shimCodecCtxHeight(uintptr(ctx)), nil |
| 466 | +} |
| 467 | + |
| 468 | +func CodecCtxSetHeight(ctx unsafe.Pointer, height int32) error { |
| 469 | + if ctx == nil { |
| 470 | + return nil |
| 471 | + } |
| 472 | + if !loaded || shimCodecCtxSetHeight == nil { |
| 473 | + return ErrShimNotLoaded |
| 474 | + } |
| 475 | + shimCodecCtxSetHeight(uintptr(ctx), height) |
| 476 | + return nil |
| 477 | +} |
| 478 | + |
| 479 | +func CodecCtxPixFmt(ctx unsafe.Pointer) (int32, error) { |
| 480 | + if ctx == nil { |
| 481 | + return -1, nil |
| 482 | + } |
| 483 | + if !loaded || shimCodecCtxPixFmt == nil { |
| 484 | + return 0, ErrShimNotLoaded |
| 485 | + } |
| 486 | + return shimCodecCtxPixFmt(uintptr(ctx)), nil |
| 487 | +} |
| 488 | + |
| 489 | +func CodecCtxSetPixFmt(ctx unsafe.Pointer, pixFmt int32) error { |
| 490 | + if ctx == nil { |
| 491 | + return nil |
| 492 | + } |
| 493 | + if !loaded || shimCodecCtxSetPixFmt == nil { |
| 494 | + return ErrShimNotLoaded |
| 495 | + } |
| 496 | + shimCodecCtxSetPixFmt(uintptr(ctx), pixFmt) |
| 497 | + return nil |
| 498 | +} |
| 499 | + |
| 500 | +func CodecCtxTimeBase(ctx unsafe.Pointer) (num, den int32, err error) { |
| 501 | + if ctx == nil { |
| 502 | + return 0, 0, nil |
| 503 | + } |
| 504 | + if !loaded || shimCodecCtxTimeBase == nil { |
| 505 | + return 0, 0, ErrShimNotLoaded |
| 506 | + } |
| 507 | + shimCodecCtxTimeBase(uintptr(ctx), &num, &den) |
| 508 | + return num, den, nil |
| 509 | +} |
| 510 | + |
| 511 | +func CodecCtxSetTimeBase(ctx unsafe.Pointer, num, den int32) error { |
| 512 | + if ctx == nil { |
| 513 | + return nil |
| 514 | + } |
| 515 | + if !loaded || shimCodecCtxSetTimeBase == nil { |
| 516 | + return ErrShimNotLoaded |
| 517 | + } |
| 518 | + shimCodecCtxSetTimeBase(uintptr(ctx), num, den) |
| 519 | + return nil |
| 520 | +} |
| 521 | + |
| 522 | +func CodecCtxFramerate(ctx unsafe.Pointer) (num, den int32, err error) { |
| 523 | + if ctx == nil { |
| 524 | + return 0, 0, nil |
| 525 | + } |
| 526 | + if !loaded || shimCodecCtxFramerate == nil { |
| 527 | + return 0, 0, ErrShimNotLoaded |
| 528 | + } |
| 529 | + shimCodecCtxFramerate(uintptr(ctx), &num, &den) |
| 530 | + return num, den, nil |
| 531 | +} |
| 532 | + |
| 533 | +func CodecCtxSetFramerate(ctx unsafe.Pointer, num, den int32) error { |
| 534 | + if ctx == nil { |
| 535 | + return nil |
| 536 | + } |
| 537 | + if !loaded || shimCodecCtxSetFramerate == nil { |
| 538 | + return ErrShimNotLoaded |
| 539 | + } |
| 540 | + shimCodecCtxSetFramerate(uintptr(ctx), num, den) |
| 541 | + return nil |
| 542 | +} |
| 543 | + |
349 | 544 | // findShimLibrary looks for the shim library in standard locations. |
350 | 545 | func findShimLibrary() (string, error) { |
351 | 546 | var names []string |
|
0 commit comments