예제 #1
0
        public static List <DeckLinkDisplayModeDescription> GetDisplayDescriptions(IDeckLinkInput deckLinkInput, List <_BMDPixelFormat> pixelFormats,
                                                                                   _BMDVideoConnection connection             = _BMDVideoConnection.bmdVideoConnectionHDMI,
                                                                                   _BMDSupportedVideoModeFlags videoModeFlags = _BMDSupportedVideoModeFlags.bmdSupportedVideoModeDefault)
        {
            List <DeckLinkDisplayModeDescription> displayDescriptions = new List <DeckLinkDisplayModeDescription>();

            IDeckLinkDisplayModeIterator iterator = null;

            try
            {
                deckLinkInput.GetDisplayModeIterator(out iterator);

                while (true)
                {
                    IDeckLinkDisplayMode displayMode = null;
                    try
                    {
                        iterator.Next(out displayMode);
                        if (displayMode == null)
                        {
                            break;
                        }

                        var displayModeId = displayMode.GetDisplayMode();

                        displayMode.GetName(out string displayName);
                        displayMode.GetFrameRate(out long frameDuration, out long timeScale);
                        var fps = (double)timeScale / frameDuration;

                        int width      = displayMode.GetWidth();
                        int height     = displayMode.GetHeight();
                        var resolution = width + "x" + height;

                        var displayModeFlags = displayMode.GetFlags();
                        var fieldDominance   = displayMode.GetFieldDominance();

                        foreach (var pixFmt in pixelFormats)
                        {
                            deckLinkInput.DoesSupportVideoMode(connection, displayModeId, pixFmt, videoModeFlags, out int supported);
                            if (supported != 0)
                            {
                                displayDescriptions.Add(new DeckLinkDisplayModeDescription
                                {
                                    ModeId      = (long)displayModeId,
                                    Width       = width,
                                    Height      = height,
                                    Fps         = fps,
                                    PixFmt      = (long)pixFmt,
                                    Description = displayName + " (" + resolution + " " + fps.ToString("0.##") + " fps " + GetFourCCStr(pixFmt) + ")",
                                });
                            }
                            else
                            {
                                //Console.WriteLine("Display mode not supported: "+ displayModeId + " " + pixFmt);
                            }
                        }
                    }
                    finally
                    {
                        if (displayMode != null)
                        {
                            Marshal.ReleaseComObject(displayMode);
                            displayMode = null;
                        }
                    }
                }
            }
            finally
            {
                if (iterator != null)
                {
                    Marshal.ReleaseComObject(iterator);
                    iterator = null;
                }
            }

            return(displayDescriptions);
        }