| 1025 | } |
| 1026 | |
| 1027 | static int decklink_autodetect(struct decklink_cctx *cctx) { |
| 1028 | struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx; |
| 1029 | DECKLINK_BOOL autodetect_supported = false; |
| 1030 | int i; |
| 1031 | |
| 1032 | if (ctx->attr->GetFlag(BMDDeckLinkSupportsInputFormatDetection, &autodetect_supported) != S_OK) |
| 1033 | return -1; |
| 1034 | if (autodetect_supported == false) |
| 1035 | return -1; |
| 1036 | |
| 1037 | ctx->autodetect = 1; |
| 1038 | ctx->bmd_mode = bmdModeUnknown; |
| 1039 | if (ctx->dli->EnableVideoInput(AUTODETECT_DEFAULT_MODE, |
| 1040 | bmdFormat8BitYUV, |
| 1041 | bmdVideoInputEnableFormatDetection) != S_OK) { |
| 1042 | return -1; |
| 1043 | } |
| 1044 | |
| 1045 | if (ctx->dli->StartStreams() != S_OK) { |
| 1046 | return -1; |
| 1047 | } |
| 1048 | |
| 1049 | // 3 second timeout |
| 1050 | for (i = 0; i < 30; i++) { |
| 1051 | av_usleep(100000); |
| 1052 | /* Sometimes VideoInputFrameArrived is called without the |
| 1053 | * bmdFrameHasNoInputSource flag before VideoInputFormatChanged. |
| 1054 | * So don't break for bmd_mode == AUTODETECT_DEFAULT_MODE. */ |
| 1055 | if (ctx->bmd_mode != bmdModeUnknown && |
| 1056 | ctx->bmd_mode != AUTODETECT_DEFAULT_MODE) |
| 1057 | break; |
| 1058 | } |
| 1059 | |
| 1060 | ctx->dli->PauseStreams(); |
| 1061 | ctx->dli->FlushStreams(); |
| 1062 | ctx->autodetect = 0; |
| 1063 | if (ctx->bmd_mode != bmdModeUnknown) { |
| 1064 | cctx->format_code = (char *)av_mallocz(5); |
| 1065 | if (!cctx->format_code) |
| 1066 | return -1; |
| 1067 | AV_WB32(cctx->format_code, ctx->bmd_mode); |
| 1068 | return 0; |
| 1069 | } else { |
| 1070 | return -1; |
| 1071 | } |
| 1072 | |
| 1073 | } |
| 1074 | |
| 1075 | extern "C" { |
| 1076 |
no test coverage detected