| @@ -318,7 +318,7 @@ static void vt_unmap(AVHWFramesContext *ctx, HWMapDescriptor *hwmap) · 317 unmodified lines |
| 318 | 318 | CVPixelBufferUnlockBaseAddress(pixbuf, (uintptr_t)hwmap->priv); |
| 319 | 319 | } |
| 320 | 320 | |
| 321 | | −static int vt_pixbuf_set_par(AVHWFramesContext *hwfc, |
| 321 | +static int vt_pixbuf_set_par(void *log_ctx, |
| 322 | 322 | CVPixelBufferRef pixbuf, const AVFrame *src) |
| 323 | 323 | { |
| 324 | 324 | CFMutableDictionaryRef par = NULL; |
| @@ -375,31 +375,30 @@ static int vt_pixbuf_set_par(AVHWFramesContext *hwfc, · 50 unmodified lines |
| 375 | 375 | return 0; |
| 376 | 376 | } |
| 377 | 377 | |
| 378 | | −static int vt_pixbuf_set_chromaloc(AVHWFramesContext *hwfc, |
| 379 | | − CVPixelBufferRef pixbuf, const AVFrame *src) |
| 378 | +CFStringRef av_map_videotoolbox_chroma_loc_from_av(enum AVChromaLocation loc) |
| 380 | 379 | { |
| 381 | | − CFStringRef loc = NULL; |
| 382 | | − |
| 383 | | − switch (src->chroma_location) { |
| 380 | + switch (loc) { |
| 384 | 381 | case AVCHROMA_LOC_LEFT: |
| 385 | | − loc = kCVImageBufferChromaLocation_Left; |
| 386 | | − break; |
| 382 | + return kCVImageBufferChromaLocation_Left; |
| 387 | 383 | case AVCHROMA_LOC_CENTER: |
| 388 | | − loc = kCVImageBufferChromaLocation_Center; |
| 389 | | − break; |
| 384 | + return kCVImageBufferChromaLocation_Center; |
| 390 | 385 | case AVCHROMA_LOC_TOP: |
| 391 | | − loc = kCVImageBufferChromaLocation_Top; |
| 392 | | − break; |
| 386 | + return kCVImageBufferChromaLocation_Top; |
| 393 | 387 | case AVCHROMA_LOC_BOTTOM: |
| 394 | | − loc = kCVImageBufferChromaLocation_Bottom; |
| 395 | | − break; |
| 388 | + return kCVImageBufferChromaLocation_Bottom; |
| 396 | 389 | case AVCHROMA_LOC_TOPLEFT: |
| 397 | | − loc = kCVImageBufferChromaLocation_TopLeft; |
| 398 | | − break; |
| 390 | + return kCVImageBufferChromaLocation_TopLeft; |
| 399 | 391 | case AVCHROMA_LOC_BOTTOMLEFT: |
| 400 | | − loc = kCVImageBufferChromaLocation_BottomLeft; |
| 401 | | − break; |
| 392 | + return kCVImageBufferChromaLocation_BottomLeft; |
| 393 | + default: |
| 394 | + return NULL; |
| 402 | 395 | } |
| 396 | +} |
| 397 | + |
| 398 | +static int vt_pixbuf_set_chromaloc(void *log_ctx, |
| 399 | + CVPixelBufferRef pixbuf, const AVFrame *src) |
| 400 | +{ |
| 401 | + CFStringRef loc = av_map_videotoolbox_chroma_loc_from_av(src->chroma_location); |
| 403 | 402 | |
| 404 | 403 | if (loc) { |
| 405 | 404 | CVBufferSetAttachment( |
| @@ -412,109 +411,115 @@ static int vt_pixbuf_set_chromaloc(AVHWFramesContext *hwfc, · 6 unmodified lines |
| 412 | 411 | return 0; |
| 413 | 412 | } |
| 414 | 413 | |
| 415 | | −static int vt_pixbuf_set_colorspace(AVHWFramesContext *hwfc, |
| 416 | | − CVPixelBufferRef pixbuf, const AVFrame *src) |
| 414 | +CFStringRef av_map_videotoolbox_color_matrix_from_av(enum AVColorSpace space) |
| 417 | 415 | { |
| 418 | | − CFStringRef colormatrix = NULL, colorpri = NULL, colortrc = NULL; |
| 419 | | − Float32 gamma = 0; |
| 420 | | − |
| 421 | | − switch (src->colorspace) { |
| 416 | + switch (space) { |
| 422 | 417 | case AVCOL_SPC_BT2020_CL: |
| 423 | 418 | case AVCOL_SPC_BT2020_NCL: |
| 424 | 419 | #if HAVE_KCVIMAGEBUFFERYCBCRMATRIX_ITU_R_2020 |
| 425 | | − colormatrix = kCVImageBufferYCbCrMatrix_ITU_R_2020; |
| 426 | | −#else |
| 427 | | − colormatrix = CFSTR("ITU_R_2020"); |
| 420 | + if (__builtin_available(macOS 10.11, iOS 9, *)) |
| 421 | + return kCVImageBufferYCbCrMatrix_ITU_R_2020; |
| 428 | 422 | #endif |
| 429 | | − break; |
| 423 | + return CFSTR("ITU_R_2020"); |
| 430 | 424 | case AVCOL_SPC_BT470BG: |
| 431 | 425 | case AVCOL_SPC_SMPTE170M: |
| 432 | | − colormatrix = kCVImageBufferYCbCrMatrix_ITU_R_601_4; |
| 433 | | − break; |
| 426 | + return kCVImageBufferYCbCrMatrix_ITU_R_601_4; |
| 434 | 427 | case AVCOL_SPC_BT709: |
| 435 | | − colormatrix = kCVImageBufferYCbCrMatrix_ITU_R_709_2; |
| 436 | | − break; |
| 428 | + return kCVImageBufferYCbCrMatrix_ITU_R_709_2; |
| 437 | 429 | case AVCOL_SPC_SMPTE240M: |
| 438 | | − colormatrix = kCVImageBufferYCbCrMatrix_SMPTE_240M_1995; |
| 439 | | − break; |
| 430 | + return kCVImageBufferYCbCrMatrix_SMPTE_240M_1995; |
| 440 | 431 | case AVCOL_SPC_UNSPECIFIED: |
| 441 | | − break; |
| 442 | 432 | default: |
| 443 | | − av_log(hwfc, AV_LOG_WARNING, "Color space %s is not supported.\n", av_color_space_name(src->colorspace)); |
| 433 | + return NULL; |
| 444 | 434 | } |
| 435 | +} |
| 445 | 436 | |
| 446 | | − switch (src->color_primaries) { |
| 437 | +CFStringRef av_map_videotoolbox_color_primaries_from_av(enum AVColorPrimaries pri) |
| 438 | +{ |
| 439 | + switch (pri) { |
| 447 | 440 | case AVCOL_PRI_BT2020: |
| 448 | 441 | #if HAVE_KCVIMAGEBUFFERCOLORPRIMARIES_ITU_R_2020 |
| 449 | | − colorpri = kCVImageBufferColorPrimaries_ITU_R_2020; |
| 450 | | −#else |
| 451 | | − colorpri = CFSTR("ITU_R_2020"); |
| 442 | + if (__builtin_available(macOS 10.11, iOS 9, *)) |
| 443 | + return kCVImageBufferColorPrimaries_ITU_R_2020; |
| 452 | 444 | #endif |
| 453 | | − break; |
| 445 | + return CFSTR("ITU_R_2020"); |
| 454 | 446 | case AVCOL_PRI_BT709: |
| 455 | | − colorpri = kCVImageBufferColorPrimaries_ITU_R_709_2; |
| 456 | | − break; |
| 447 | + return kCVImageBufferColorPrimaries_ITU_R_709_2; |
| 457 | 448 | case AVCOL_PRI_SMPTE170M: |
| 458 | | − colorpri = kCVImageBufferColorPrimaries_SMPTE_C; |
| 459 | | − break; |
| 449 | + return kCVImageBufferColorPrimaries_SMPTE_C; |
| 460 | 450 | case AVCOL_PRI_BT470BG: |
| 461 | | − colorpri = kCVImageBufferColorPrimaries_EBU_3213; |
| 462 | | − break; |
| 451 | + return kCVImageBufferColorPrimaries_EBU_3213; |
| 463 | 452 | case AVCOL_PRI_UNSPECIFIED: |
| 464 | | − break; |
| 465 | 453 | default: |
| 466 | | − av_log(hwfc, AV_LOG_WARNING, "Color primaries %s is not supported.\n", av_color_primaries_name(src->color_primaries)); |
| 454 | + return NULL; |
| 467 | 455 | } |
| 456 | +} |
| 457 | + |
| 458 | +CFStringRef av_map_videotoolbox_color_trc_from_av(enum AVColorTransferCharacteristic trc) |
| 459 | +{ |
| 468 | 460 | |
| 469 | | − switch (src->color_trc) { |
| 461 | + switch (trc) { |
| 470 | 462 | case AVCOL_TRC_SMPTE2084: |
| 471 | 463 | #if HAVE_KCVIMAGEBUFFERTRANSFERFUNCTION_SMPTE_ST_2084_PQ |
| 472 | | − colortrc = kCVImageBufferTransferFunction_SMPTE_ST_2084_PQ; |
| 473 | | −#else |
| 474 | | − colortrc = CFSTR("SMPTE_ST_2084_PQ"); |
| 464 | + if (__builtin_available(macOS 10.13, iOS 11, *)) |
| 465 | + return kCVImageBufferTransferFunction_SMPTE_ST_2084_PQ; |
| 475 | 466 | #endif |
| 476 | | − break; |
| 467 | + return CFSTR("SMPTE_ST_2084_PQ"); |
| 477 | 468 | case AVCOL_TRC_BT2020_10: |
| 478 | 469 | case AVCOL_TRC_BT2020_12: |
| 479 | 470 | #if HAVE_KCVIMAGEBUFFERTRANSFERFUNCTION_ITU_R_2020 |
| 480 | | − colortrc = kCVImageBufferTransferFunction_ITU_R_2020; |
| 481 | | −#else |
| 482 | | − colortrc = CFSTR("ITU_R_2020"); |
| 471 | + if (__builtin_available(macOS 10.11, iOS 9, *)) |
| 472 | + return kCVImageBufferTransferFunction_ITU_R_2020; |
| 483 | 473 | #endif |
| 484 | | − break; |
| 474 | + return CFSTR("ITU_R_2020"); |
| 485 | 475 | case AVCOL_TRC_BT709: |
| 486 | | − colortrc = kCVImageBufferTransferFunction_ITU_R_709_2; |
| 487 | | − break; |
| 476 | + return kCVImageBufferTransferFunction_ITU_R_709_2; |
| 488 | 477 | case AVCOL_TRC_SMPTE240M: |
| 489 | | − colortrc = kCVImageBufferTransferFunction_SMPTE_240M_1995; |
| 490 | | − break; |
| 478 | + return kCVImageBufferTransferFunction_SMPTE_240M_1995; |
| 491 | 479 | case AVCOL_TRC_SMPTE428: |
| 492 | 480 | #if HAVE_KCVIMAGEBUFFERTRANSFERFUNCTION_SMPTE_ST_428_1 |
| 493 | | − colortrc = kCVImageBufferTransferFunction_SMPTE_ST_428_1; |
| 494 | | −#else |
| 495 | | − colortrc = CFSTR("SMPTE_ST_428_1"); |
| 481 | + if (__builtin_available(macOS 10.12, iOS 10, *)) |
| 482 | + return kCVImageBufferTransferFunction_SMPTE_ST_428_1; |
| 496 | 483 | #endif |
| 497 | | − break; |
| 484 | + return CFSTR("SMPTE_ST_428_1"); |
| 498 | 485 | case AVCOL_TRC_ARIB_STD_B67: |
| 499 | 486 | #if HAVE_KCVIMAGEBUFFERTRANSFERFUNCTION_ITU_R_2100_HLG |
| 500 | | − colortrc = kCVImageBufferTransferFunction_ITU_R_2100_HLG; |
| 501 | | −#else |
| 502 | | − colortrc = CFSTR("ITU_R_2100_HLG"); |
| 487 | + if (__builtin_available(macOS 10.13, iOS 11, *)) |
| 488 | + return kCVImageBufferTransferFunction_ITU_R_2100_HLG; |
| 503 | 489 | #endif |
| 504 | | − break; |
| 490 | + return CFSTR("ITU_R_2100_HLG"); |
| 505 | 491 | case AVCOL_TRC_GAMMA22: |
| 506 | | − gamma = 2.2; |
| 507 | | − colortrc = kCVImageBufferTransferFunction_UseGamma; |
| 508 | | − break; |
| 492 | + return kCVImageBufferTransferFunction_UseGamma; |
| 509 | 493 | case AVCOL_TRC_GAMMA28: |
| 510 | | − gamma = 2.8; |
| 511 | | − colortrc = kCVImageBufferTransferFunction_UseGamma; |
| 512 | | − break; |
| 513 | | − case AVCOL_TRC_UNSPECIFIED: |
| 514 | | − break; |
| 494 | + return kCVImageBufferTransferFunction_UseGamma; |
| 515 | 495 | default: |
| 516 | | − av_log(hwfc, AV_LOG_WARNING, "Color transfer function %s is not supported.\n", av_color_transfer_name(src->color_trc)); |
| 496 | + case AVCOL_TRC_UNSPECIFIED: |
| 497 | + return NULL; |
| 517 | 498 | } |
| 499 | +} |
| 500 | + |
| 501 | +static int vt_pixbuf_set_colorspace(void *log_ctx, |
| 502 | + CVPixelBufferRef pixbuf, const AVFrame *src) |
| 503 | +{ |
| 504 | + CFStringRef colormatrix = NULL, colorpri = NULL, colortrc = NULL; |
| 505 | + Float32 gamma = 0; |
| 506 | + |
| 507 | + colormatrix = av_map_videotoolbox_color_matrix_from_av(src->colorspace); |
| 508 | + if (!colormatrix && src->colorspace != AVCOL_SPC_UNSPECIFIED) |
| 509 | + av_log(log_ctx, AV_LOG_WARNING, "Color space %s is not supported.\n", av_color_space_name(src->colorspace)); |
| 510 | + |
| 511 | + colorpri = av_map_videotoolbox_color_primaries_from_av(src->color_primaries); |
| 512 | + if (!colorpri && src->color_primaries != AVCOL_PRI_UNSPECIFIED) |
| 513 | + av_log(log_ctx, AV_LOG_WARNING, "Color primaries %s is not supported.\n", av_color_primaries_name(src->color_primaries)); |
| 514 | + |
| 515 | + colortrc = av_map_videotoolbox_color_trc_from_av(src->color_trc); |
| 516 | + if (!colortrc && src->color_trc != AVCOL_TRC_UNSPECIFIED) |
| 517 | + av_log(log_ctx, AV_LOG_WARNING, "Color transfer function %s is not supported.\n", av_color_transfer_name(src->color_trc)); |
| 518 | + |
| 519 | + if (src->color_trc == AVCOL_TRC_GAMMA22) |
| 520 | + gamma = 2.2; |
| 521 | + else if (src->color_trc == AVCOL_TRC_GAMMA28) |
| 522 | + gamma = 2.8; |
| 518 | 523 | |
| 519 | 524 | if (colormatrix) { |
| 520 | 525 | CVBufferSetAttachment( |
| @@ -550,17 +555,17 @@ static int vt_pixbuf_set_colorspace(AVHWFramesContext *hwfc, · 29 unmodified lines |
| 550 | 555 | return 0; |
| 551 | 556 | } |
| 552 | 557 | |
| 553 | | −static int vt_pixbuf_set_attachments(AVHWFramesContext *hwfc, |
| 558 | +static int vt_pixbuf_set_attachments(void *log_ctx, |
| 554 | 559 | CVPixelBufferRef pixbuf, const AVFrame *src) |
| 555 | 560 | { |
| 556 | 561 | int ret; |
| 557 | | − ret = vt_pixbuf_set_par(hwfc, pixbuf, src); |
| 562 | + ret = vt_pixbuf_set_par(log_ctx, pixbuf, src); |
| 558 | 563 | if (ret < 0) |
| 559 | 564 | return ret; |
| 560 | | − ret = vt_pixbuf_set_colorspace(hwfc, pixbuf, src); |
| 565 | + ret = vt_pixbuf_set_colorspace(log_ctx, pixbuf, src); |
| 561 | 566 | if (ret < 0) |
| 562 | 567 | return ret; |
| 563 | | − ret = vt_pixbuf_set_chromaloc(hwfc, pixbuf, src); |
| 568 | + ret = vt_pixbuf_set_chromaloc(log_ctx, pixbuf, src); |
| 564 | 569 | if (ret < 0) |
| 565 | 570 | return ret; |
| 566 | 571 | return 0; |