示例#1
0
        void select_input_connection(unsigned int input) {
            IDeckLinkConfiguration *config;

            assert(deckLink != NULL);
            assert(input < sizeof(connections) 
                    / sizeof(struct decklink_connection));

            if (deckLink->QueryInterface(IID_IDeckLinkConfiguration, 
                    (void**) &config) != S_OK) {
                
                throw std::runtime_error(
                    "DeckLink input: get IDeckLinkConfiguration failed"
                );
            }

            if (config->SetInt(bmdDeckLinkConfigVideoInputConnection,
                    connections[input].connection) != S_OK) {

                throw std::runtime_error(
                    "DeckLink input: set input connection failed"
                );
            }

            fprintf(stderr, "DeckLink: input connection set to %s\n",
                    connections[input].name);

            config->Release( );
        }   
示例#2
0
        void configure_card( ) {
            IDeckLinkConfiguration *config;

            assert(deckLink != NULL);

            if (deckLink->QueryInterface(IID_IDeckLinkConfiguration, 
                    (void**) &config) != S_OK) {
                
                throw std::runtime_error(
                    "DeckLink output: get IDeckLinkConfiguration failed"
                );
            }

            if (config->SetInt(bmdDeckLinkConfigLowLatencyVideoOutput, true)
                    != S_OK) {

                fprintf(stderr, "DeckLink output: warning: "
                        "cannot enable low-latency mode\n"
                );
            }

            if (config->SetInt(bmdDeckLinkConfigVideoOutputConversionMode,
                    bmdVideoOutputHardwareLetterboxDownconversion) != S_OK) {
                fprintf(stderr, "DeckLink output: warning: "
                        "cannot enable hardware letterboxing\n");
            }

            if (config->SetInt(bmdDeckLinkConfigBypass, -1) != S_OK) {
                fprintf(stderr, "DeckLink output: warning: "
                        "cannot deactivate card bypass relay\n"
                );
            }
                    
            /* throw outputs at wall, see what sticks :) */
            #if 0
            config->SetInt(bmdDeckLinkConfigVideoOutputConnection,
                bmdVideoConnectionSDI);
            config->SetInt(bmdDeckLinkConfigVideoOutputConnection,
                bmdVideoConnectionHDMI);
            config->SetInt(bmdDeckLinkConfigVideoOutputConnection,
                bmdVideoConnectionComponent);
            config->SetInt(bmdDeckLinkConfigVideoOutputConnection,
                bmdVideoConnectionComposite);
            config->SetInt(bmdDeckLinkConfigVideoOutputConnection,
                bmdVideoConnectionSVideo);
            #endif

            config->Release( );
        }
示例#3
0
        void select_audio_input_connection( ) {
            IDeckLinkConfiguration *config;

            assert(deckLink != NULL);

            if (deckLink->QueryInterface(IID_IDeckLinkConfiguration, 
                    (void**) &config) != S_OK) {
                
                throw std::runtime_error(
                    "DeckLink input: get IDeckLinkConfiguration failed"
                );
            }

            if (config->SetInt(bmdDeckLinkConfigAudioInputConnection,
                    bmdAudioConnectionEmbedded) != S_OK) {

                throw std::runtime_error(
                    "DeckLink input: set embedded audio input failed"
                );
            }

            config->Release( );
        }
static gboolean
gst_decklink_src_start (GstElement * element)
{
    GstDecklinkSrc *decklinksrc = GST_DECKLINK_SRC (element);
    IDeckLinkIterator *iterator;
    DeckLinkCaptureDelegate *delegate;
    //IDeckLinkDisplayModeIterator *mode_iterator;
    //IDeckLinkDisplayMode *mode;
    BMDAudioSampleType sample_depth;
    int channels;
    HRESULT ret;
    const GstDecklinkMode *mode;
    IDeckLinkConfiguration *config;
    BMDVideoConnection conn;
    BMDAudioConnection aconn;
    int i;

    GST_DEBUG_OBJECT (decklinksrc, "start");

    iterator = CreateDeckLinkIteratorInstance ();
    if (iterator == NULL) {
        GST_ERROR ("no driver");
        return FALSE;
    }

    ret = iterator->Next (&decklinksrc->decklink);
    if (ret != S_OK) {
        GST_ERROR ("no card");
        return FALSE;
    }
    for (i = 0; i < decklinksrc->subdevice; i++) {
        ret = iterator->Next (&decklinksrc->decklink);
        if (ret != S_OK) {
            GST_ERROR ("no card");
            return FALSE;
        }
    }

    ret = decklinksrc->decklink->QueryInterface (IID_IDeckLinkInput,
            (void **) &decklinksrc->input);
    if (ret != S_OK) {
        GST_ERROR ("query interface failed");
        return FALSE;
    }

    delegate = new DeckLinkCaptureDelegate ();
    delegate->priv = decklinksrc;
    decklinksrc->input->SetCallback (delegate);

    ret = decklinksrc->decklink->QueryInterface (IID_IDeckLinkConfiguration,
            (void **) &config);
    if (ret != S_OK) {
        GST_ERROR ("query interface failed");
        return FALSE;
    }

    switch (decklinksrc->connection) {
    default:
    case GST_DECKLINK_CONNECTION_SDI:
        conn = bmdVideoConnectionSDI;
        aconn = bmdAudioConnectionEmbedded;
        break;
    case GST_DECKLINK_CONNECTION_HDMI:
        conn = bmdVideoConnectionHDMI;
        aconn = bmdAudioConnectionEmbedded;
        break;
    case GST_DECKLINK_CONNECTION_OPTICAL_SDI:
        conn = bmdVideoConnectionOpticalSDI;
        aconn = bmdAudioConnectionEmbedded;
        break;
    case GST_DECKLINK_CONNECTION_COMPONENT:
        conn = bmdVideoConnectionComponent;
        aconn = bmdAudioConnectionAnalog;
        break;
    case GST_DECKLINK_CONNECTION_COMPOSITE:
        conn = bmdVideoConnectionComposite;
        aconn = bmdAudioConnectionAnalog;
        break;
    case GST_DECKLINK_CONNECTION_SVIDEO:
        conn = bmdVideoConnectionSVideo;
        aconn = bmdAudioConnectionAnalog;
        break;
    }

    ret = config->SetInt (bmdDeckLinkConfigVideoInputConnection, conn);
    if (ret != S_OK) {
        GST_ERROR ("set configuration (input source)");
        return FALSE;
    }

    if (decklinksrc->connection == GST_DECKLINK_CONNECTION_COMPOSITE) {
        ret = config->SetInt (bmdDeckLinkConfigAnalogVideoInputFlags,
                              bmdAnalogVideoFlagCompositeSetup75);
        if (ret != S_OK) {
            GST_ERROR ("set configuration (composite setup)");
            return FALSE;
        }
    }

    switch (decklinksrc->audio_connection) {
    default:
    case GST_DECKLINK_AUDIO_CONNECTION_AUTO:
        break;
    case GST_DECKLINK_AUDIO_CONNECTION_EMBEDDED:
        aconn = bmdAudioConnectionEmbedded;
        break;
    case GST_DECKLINK_AUDIO_CONNECTION_AES_EBU:
        aconn = bmdAudioConnectionAESEBU;
        break;
    case GST_DECKLINK_AUDIO_CONNECTION_ANALOG:
        aconn = bmdAudioConnectionAnalog;
        break;
    }
    ret = config->SetInt (bmdDeckLinkConfigAudioInputConnection, aconn);
    if (ret != S_OK) {
        GST_ERROR ("set configuration (audio input connection)");
        return FALSE;
    }
#if 0
    ret = decklinksrc->input->GetDisplayModeIterator (&mode_iterator);
    if (ret != S_OK) {
        GST_ERROR ("failed to get display mode iterator");
        return FALSE;
    }

    i = 0;
    while (mode_iterator->Next (&mode) == S_OK) {
        const char *mode_name;

        mode->GetName (&mode_name);

        GST_DEBUG ("%d: mode name: %s", i, mode_name);

        mode->Release ();
        i++;
    }
#endif

    mode = gst_decklink_get_mode (decklinksrc->mode);

    ret = decklinksrc->input->EnableVideoInput (mode->mode, bmdFormat8BitYUV, 0);
    if (ret != S_OK) {
        GST_ERROR ("enable video input failed");
        return FALSE;
    }

    sample_depth = bmdAudioSampleType16bitInteger;
    channels = 2;
    ret = decklinksrc->input->EnableAudioInput (bmdAudioSampleRate48kHz,
            sample_depth, channels);
    if (ret != S_OK) {
        GST_ERROR ("enable video input failed");
        return FALSE;
    }

    ret = decklinksrc->input->StartStreams ();
    if (ret != S_OK) {
        GST_ERROR ("start streams failed");
        return FALSE;
    }

    g_static_rec_mutex_lock (&decklinksrc->task_mutex);
    gst_task_start (decklinksrc->task);
    g_static_rec_mutex_unlock (&decklinksrc->task_mutex);

    return TRUE;
}
/* FIXME: post error messages for the misc. failures */
static gboolean
gst_decklink_src_start (GstElement * element)
{
  GstDecklinkSrc *decklinksrc = GST_DECKLINK_SRC (element);
  DeckLinkCaptureDelegate *delegate;
  BMDAudioSampleType sample_depth;
  int channels;
  HRESULT ret;
  const GstDecklinkMode *mode;
  IDeckLinkConfiguration *config;
  BMDVideoConnection conn;
  BMDAudioConnection aconn;

  GST_DEBUG_OBJECT (decklinksrc, "start");

  decklinksrc->decklink = gst_decklink_get_nth_device (decklinksrc->device);
  if (decklinksrc->decklink == NULL) {
    return FALSE;
  }

  decklinksrc->input = gst_decklink_get_nth_input (decklinksrc->device);

  delegate = new DeckLinkCaptureDelegate ();
  delegate->priv = decklinksrc;
  ret = decklinksrc->input->SetCallback (delegate);
  if (ret != S_OK) {
    GST_ERROR ("set callback failed (input source)");
    return FALSE;
  }

  decklinksrc->config = gst_decklink_get_nth_config (decklinksrc->device);
  config = decklinksrc->config;

  switch (decklinksrc->connection) {
    default:
    case GST_DECKLINK_CONNECTION_SDI:
      conn = bmdVideoConnectionSDI;
      aconn = bmdAudioConnectionEmbedded;
      break;
    case GST_DECKLINK_CONNECTION_HDMI:
      conn = bmdVideoConnectionHDMI;
      aconn = bmdAudioConnectionEmbedded;
      break;
    case GST_DECKLINK_CONNECTION_OPTICAL_SDI:
      conn = bmdVideoConnectionOpticalSDI;
      aconn = bmdAudioConnectionEmbedded;
      break;
    case GST_DECKLINK_CONNECTION_COMPONENT:
      conn = bmdVideoConnectionComponent;
      aconn = bmdAudioConnectionAnalog;
      break;
    case GST_DECKLINK_CONNECTION_COMPOSITE:
      conn = bmdVideoConnectionComposite;
      aconn = bmdAudioConnectionAnalog;
      break;
    case GST_DECKLINK_CONNECTION_SVIDEO:
      conn = bmdVideoConnectionSVideo;
      aconn = bmdAudioConnectionAnalog;
      break;
  }

  ret = config->SetInt (bmdDeckLinkConfigVideoInputConnection, conn);
  if (ret != S_OK) {
    GST_ERROR ("set configuration (input source)");
    return FALSE;
  }

  if (decklinksrc->connection == GST_DECKLINK_CONNECTION_COMPOSITE) {
    ret = config->SetInt (bmdDeckLinkConfigAnalogVideoInputFlags,
        bmdAnalogVideoFlagCompositeSetup75);
    if (ret != S_OK) {
      GST_ERROR ("set configuration (composite setup)");
      return FALSE;
    }
  }

  switch (decklinksrc->audio_connection) {
    default:
    case GST_DECKLINK_AUDIO_CONNECTION_AUTO:
      /* set above */
      break;
    case GST_DECKLINK_AUDIO_CONNECTION_EMBEDDED:
      aconn = bmdAudioConnectionEmbedded;
      break;
    case GST_DECKLINK_AUDIO_CONNECTION_AES_EBU:
      aconn = bmdAudioConnectionAESEBU;
      break;
    case GST_DECKLINK_AUDIO_CONNECTION_ANALOG:
      aconn = bmdAudioConnectionAnalog;
      break;
  }
  ret = config->SetInt (bmdDeckLinkConfigAudioInputConnection, aconn);
  if (ret != S_OK) {
    GST_ERROR ("set configuration (audio input connection)");
    return FALSE;
  }

  mode = gst_decklink_get_mode (decklinksrc->mode);

  ret = decklinksrc->input->EnableVideoInput (mode->mode, bmdFormat8BitYUV, 0);
  if (ret != S_OK) {
    GST_ERROR ("enable video input failed");
    return FALSE;
  }

  sample_depth = bmdAudioSampleType16bitInteger;
  channels = 2;
  ret = decklinksrc->input->EnableAudioInput (bmdAudioSampleRate48kHz,
      sample_depth, channels);
  if (ret != S_OK) {
    GST_ERROR ("enable video input failed");
    return FALSE;
  }

  ret = decklinksrc->input->StartStreams ();
  if (ret != S_OK) {
    GST_ERROR ("start streams failed");
    return FALSE;
  }

  g_rec_mutex_lock (&decklinksrc->task_mutex);
  gst_task_start (decklinksrc->task);
  g_rec_mutex_unlock (&decklinksrc->task_mutex);

  return TRUE;
}
/**
* process the arugments
* return negative value of failed
*/
int Window::processArguments(int argc, char* argv[]){
     IDeckLinkAttributes    *deckLinkAttributes = NULL;
     DeckLinkCaptureDelegate           *delegate;
     IDeckLinkDisplayMode               *displayMode;
     BMDVideoInputFlags              inputFlags = 0;
     BMDDisplayMode         selectedDisplayMode = bmdModeNTSC;
     BMDPixelFormat                 pixelFormat = bmdFormat8BitYUV;
     int                       displayModeCount = 0;
     int                             exitStatus = 1;
     int                                         ch;
     bool                      foundDisplayMode = false;
     HRESULT                                 result;
     int                                   dnum = 0;
     IDeckLink                        *tempLink = NULL;
     int                                  found = 0;
     bool                             supported = 0;
     int64_t                                  ports;
     int                                  itemCount;
     int                                 vinput = 0;
     int64_t                              vport = 0;
     IDeckLinkConfiguration *deckLinkConfiguration = NULL;
     bool flickerremoval                        = true;
     bool pnotpsf                               = true;
     
     // Parse command line options
     while ((ch = getopt(argc, argv, "?h3c:d:s:f:a:m:n:p:t:u::vi:jy")) != -1) 
     {
          switch (ch) 
          {
               case 'i':
                    vinput = atoi(optarg);
                    break;
               case 'd':
                    card = atoi(optarg);
                    break;
               case 'm':
                    g_videoModeIndex = atoi(optarg);
                    break;
               case 'n':
                    g_maxFrames = atoi(optarg);
                    break;
               case '3':
                    inputFlags |= bmdVideoInputDualStream3D;
                    break;
               case 'p':
                    switch(atoi(optarg))
                    {
                         case 0: pixelFormat = bmdFormat8BitYUV; break;
                         case 1: pixelFormat = bmdFormat10BitYUV; break;
                         case 2: pixelFormat = bmdFormat10BitRGB; break;
                         default:
                              fprintf(stderr, "Invalid argument: Pixel format %d is not valid", atoi(optarg));
                              exit(1);
                    }
                    break;
               case 't':
                    if (!strcmp(optarg, "rp188"))
                         g_timecodeFormat = bmdTimecodeRP188Any;
               else if (!strcmp(optarg, "vitc"))
                         g_timecodeFormat = bmdTimecodeVITC;
               else if (!strcmp(optarg, "serial"))
                         g_timecodeFormat = bmdTimecodeSerial;
                    else
                    {
                         fprintf(stderr, "Invalid argument: Timecode format \"%s\" is invalid\n", optarg);
                         exit(1);
                    }
                    break;
               case '?':
               case 'h':
                    usage();
          }
     }

     if (!deckLinkIterator)
     {
          fprintf(stderr, "This application requires the DeckLink drivers installed.\n");
          return -1;
     }


     /* Connect to the first DeckLink instance */
     while (deckLinkIterator->Next(&tempLink) == S_OK)
     {
          if (card != dnum) {
               dnum++;
               // Release the IDeckLink instance when we've finished with it to prevent leaks
               tempLink->Release();
               continue;
          }
          else {
               deckLink = tempLink;
               found = 1;
          }
          dnum++;
     }

     if (! found ) {
          fprintf(stderr, "No DeckLink PCI cards found.\n");
          return -1;
     }
     if (deckLink->QueryInterface(IID_IDeckLinkInput, (void**)&deckLinkInput) != S_OK)
          return -1;

     
     // Query the DeckLink for its attributes interface
     result = deckLink->QueryInterface(IID_IDeckLinkAttributes, (void**)&deckLinkAttributes);
     if (result != S_OK)
     {
          fprintf(stderr, "Could not obtain the IDeckLinkAttributes interface - result = %08x\n", result);
     }
     

     result = deckLinkAttributes->GetFlag(BMDDeckLinkSupportsInputFormatDetection, &supported);
     if (result == S_OK)
     {
          fprintf(stderr, " %-40s %s\n", "Input mode detection supported ?", (supported == true) ? "Yes" : "No");
     }
     else
     {
          fprintf(stderr, "Could not query the input mode detection attribute- result = %08x\n", result);
     }

     fprintf(stderr, "Supported video input connections (-i [input #]:\n  ");
     itemCount = 0;
     result = deckLinkAttributes->GetInt(BMDDeckLinkVideoInputConnections, &ports);
     if (result == S_OK)
     {
          if (ports & bmdVideoConnectionSDI)
          {
               fprintf(stderr, "%d: SDI, ", bmdVideoConnectionSDI);
               itemCount++;
          }

          if (ports & bmdVideoConnectionHDMI)
          {
               fprintf(stderr, "%d: HDMI, ", bmdVideoConnectionHDMI);
               itemCount++;
          }

          if (ports & bmdVideoConnectionOpticalSDI)
          {
               fprintf(stderr, "%d: Optical SDI, ", bmdVideoConnectionOpticalSDI);
               itemCount++;
          }

          if (ports & bmdVideoConnectionComponent)
          {
               fprintf(stderr, "%d: Component, ", bmdVideoConnectionComponent);
               itemCount++;
          }

          if (ports & bmdVideoConnectionComposite)
          {
               fprintf(stderr, "%d: Composite, ", bmdVideoConnectionComposite);
               itemCount++;
          }

          if (ports & bmdVideoConnectionSVideo)
          {
               fprintf(stderr, "%d: S-Video, ", bmdVideoConnectionSVideo);
               itemCount++;
          }
     }
     fprintf(stderr, "\n");


     //glWidget->initShaderProgram();
     delegate = new DeckLinkCaptureDelegate(glWidget);
     connect(delegate, SIGNAL(updateGLSignal()), glWidget, SLOT(updateGLSlot()));
     deckLinkInput->SetCallback(delegate);
   
     // Obtain an IDeckLinkDisplayModeIterator to enumerate the display modes supported on output
     result = deckLinkInput->GetDisplayModeIterator(&displayModeIterator);
     if (result != S_OK)
     {
          fprintf(stderr, "Could not obtain the video output display mode iterator - result = %08x\n", result);
          return -1;
     }


     if (g_videoModeIndex < 0)
     {
          fprintf(stderr, "No video mode specified\n");
          usage();
          return -1;
     }

     while (displayModeIterator->Next(&displayMode) == S_OK)
     {
          if (g_videoModeIndex == displayModeCount)
          {
               BMDDisplayModeSupport result;
               const char *displayModeName;
               
               foundDisplayMode = true;
               displayMode->GetName(&displayModeName);
               selectedDisplayMode = displayMode->GetDisplayMode();
               
               deckLinkInput->DoesSupportVideoMode(selectedDisplayMode, pixelFormat, bmdVideoInputFlagDefault, &result, NULL);

               if (result == bmdDisplayModeNotSupported)
               {
                    fprintf(stderr, "The display mode %s is not supported with the selected pixel format\n", displayModeName);
                    return -1;
               }

               if (inputFlags & bmdVideoInputDualStream3D)
               {
                    if (!(displayMode->GetFlags() & bmdDisplayModeSupports3D))
                    {
                         fprintf(stderr, "The display mode %s is not supported with 3D\n", displayModeName);
                         return -1;
                    }
               }
               fprintf(stderr, "Selecting mode: %s\n", displayModeName);
               
               break;
          }
          displayModeCount++;
          displayMode->Release();
     }

     if (!foundDisplayMode)
     {
          fprintf(stderr, "Invalid mode %d specified\n", g_videoModeIndex);
          return -1;
     }

     // Query the DeckLink for its configuration interface
     result = deckLinkInput->QueryInterface(IID_IDeckLinkConfiguration, (void**)&deckLinkConfiguration);
     if (result != S_OK)
     {
          fprintf(stderr, "Could not obtain the IDeckLinkConfiguration interface: %08x\n", result);
     }
    

     BMDVideoConnection conn;
     switch (vinput) {
     case 0:
          conn = bmdVideoConnectionSDI;
          break;
     case 1:
          conn = bmdVideoConnectionHDMI;
          break;
     case 2:
          conn = bmdVideoConnectionComponent;
          break;
     case 3:
          conn = bmdVideoConnectionComposite;
          break;
     case 4:
          conn = bmdVideoConnectionSVideo;
          break;
     case 5:
          conn = bmdVideoConnectionOpticalSDI;
          break;
     default:
          break;
     }
     conn = vinput;
     // Set the input desired
     result = deckLinkConfiguration->SetInt(bmdDeckLinkConfigVideoInputConnection, conn);
     if(result != S_OK) {
          fprintf(stderr, "Cannot set the input to [%d]\n", conn);
          return -1;
     }

     // check input
     result = deckLinkConfiguration->GetInt(bmdDeckLinkConfigVideoInputConnection, &vport);
     if (vport == bmdVideoConnectionSDI)
          fprintf(stderr, "Before Input configured for SDI\n");
     if (vport == bmdVideoConnectionHDMI)
          fprintf(stderr, "Before Input configured for HDMI\n");


     if (deckLinkConfiguration->SetFlag(bmdDeckLinkConfigFieldFlickerRemoval, flickerremoval) == S_OK) {
          fprintf(stderr, "Flicker removal set : %d\n", flickerremoval);
     }
     else {
          fprintf(stderr, "Flicker removal NOT set\n");
     }

     if (deckLinkConfiguration->SetFlag(bmdDeckLinkConfigUse1080pNotPsF, pnotpsf) == S_OK) {
          fprintf(stderr, "bmdDeckLinkConfigUse1080pNotPsF: %d\n", pnotpsf);
     }
     else {
          fprintf(stderr, "bmdDeckLinkConfigUse1080pNotPsF NOT set\n");
     }

    //if (deckLinkConfiguration->SetFlag(bmdDeckLinkConfigVideoInputConnection, conn) == S_OK) {
      //fprintf(stderr, "Input set to: %d\n", vinput);
    //}

     result = deckLinkConfiguration->GetInt(bmdDeckLinkConfigVideoInputConnection, &vport);
     if (vport == bmdVideoConnectionSDI)
          fprintf(stderr, "After Input configured for SDI\n");
     if (vport == bmdVideoConnectionHDMI)
          fprintf(stderr, "After Input configured for HDMI\n");



     result = deckLinkInput->EnableVideoInput(selectedDisplayMode, pixelFormat, inputFlags);
     if(result != S_OK)
     {
          fprintf(stderr, "Failed to enable video input. Is another application using the card?\n");
          return -1;
     }

     displayWidth = displayMode->GetWidth();
     displayHeight = displayMode->GetHeight();
     displayMode->GetFrameRate(&frameRateDuration, &frameRateScale);     
     displayFPS = (double)frameRateScale / (double)frameRateDuration;
     //set to delegate
     delegate->setWidth(displayWidth);
     delegate->setHeight(displayHeight);
     delegate->setFPS(displayFPS);
     delegate->setFrameRateDuration(frameRateDuration);
     delegate->setFrameRateScale(frameRateScale);
     //set texture width and height
     glWidget->setTextureWidth(displayWidth);
     glWidget->setTextureHeight(displayHeight);
     glWidget->initBuffer();
     fprintf(stderr, "GetFrameRate: %10ld %10ld --> fps %g\n", (long)frameRateScale, (long)frameRateDuration, displayFPS);
     result = deckLinkInput->StartStreams();
     if(result != S_OK){
     	fprintf(stderr, "Cannot start streams...\n");
	return -1;
     }
     fprintf(stderr, "Finish procesing arguments \n");
}