Exemplo n.º 1
0
//
// Get a list of the names of the cards
//
int dl_list_devices( CaptureCardList *cards ){

    IDeckLinkIterator*		deckLinkIterator;
    IDeckLink*				deckLink;
    int						numDevices = 0;
    HRESULT					result;

    // Create an IDeckLinkIterator object to enumerate all DeckLink cards in the system
    deckLinkIterator = CreateDeckLinkIteratorInstance();
    if (deckLinkIterator == NULL)
    {
        //fprintf(stderr, "A DeckLink iterator could not be created.  The DeckLink drivers may not be installed.\n");
        return 0;
    }
    while (deckLinkIterator->Next(&deckLink) == S_OK)
    {
        char *		deviceNameString = NULL;

        // *** Print the model name of the DeckLink card
        result = deckLink->GetModelName((const char **) &deviceNameString);
        if (result == S_OK){
            if(numDevices < MAX_CAPTURE_LIST_ITEMS){
                strcpy(cards->item[numDevices],deviceNameString);
            }
            numDevices++;
            free(deviceNameString);
        }
        // Release the IDeckLink instance when we've finished with it to prevent leaks
        deckLink->Release();
    }

    deckLinkIterator->Release();
    cards->items = numDevices;
    return numDevices;
}
Exemplo n.º 2
0
int krad_decklink_cpp_detect_devices () {

	IDeckLinkIterator *deckLinkIterator;
	IDeckLink *deckLink;
	int device_count;
	//HRESULT result;
	
	device_count = 0;
	
	deckLinkIterator = CreateDeckLinkIteratorInstance();
	
	if (deckLinkIterator == NULL) {
		printke ("krad_decklink_detect_devices: The DeckLink drivers may not be installed.");
		return 0;
	}
	
	while (deckLinkIterator->Next(&deckLink) == S_OK) {

		device_count++;
		
		deckLink->Release();
	}
	
	deckLinkIterator->Release();
	
	return device_count;

}
Exemplo n.º 3
0
bool DeckLinkController::init()  {
	IDeckLinkIterator* deckLinkIterator = NULL;
	IDeckLink* deckLink = NULL;
	bool result = false;
	
	// Create an iterator
	deckLinkIterator = CreateDeckLinkIteratorInstance();
	if (deckLinkIterator == NULL) {
		ofLogError("DeckLinkController") << "Please install the Blackmagic Desktop Video drivers to use the features of this application.";
		goto bail;
	}
	
	// List all DeckLink devices
	while (deckLinkIterator->Next(&deckLink) == S_OK) {
		// Add device to the device list
		deviceList.push_back(deckLink);
	}
	
	if (deviceList.size() == 0) {
		ofLogError("DeckLinkController") << "You will not be able to use the features of this application until a Blackmagic device is installed.";
		goto bail;
	}
	
	result = true;
	
bail:
	if (deckLinkIterator != NULL) {
		deckLinkIterator->Release();
		deckLinkIterator = NULL;
	}
	
	return result;
}
Exemplo n.º 4
0
IDeckLink *
gst_decklink_get_nth_device (int n)
{
  IDeckLinkIterator *iterator;
  IDeckLink *decklink = NULL;
  HRESULT ret;
  int i;

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

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

  return decklink;
}
Exemplo n.º 5
0
int		old_main (int argc, char** argv)
{
	IDeckLinkIterator*		deckLinkIterator;
	IDeckLink*				deckLink;
	int						numDevices = 0;
	HRESULT					result;
	
	// Create an IDeckLinkIterator object to enumerate all DeckLink cards in the system
	deckLinkIterator = CreateDeckLinkIteratorInstance();
	if (deckLinkIterator == NULL)
	{
		fprintf(stderr, "A DeckLink iterator could not be created.  The DeckLink drivers may not be installed.\n");
		return 1;
	}
	
	// Enumerate all cards in this system
	while (deckLinkIterator->Next(&deckLink) == S_OK)
	{
		char *		deviceNameString = NULL;
		
		// Increment the total number of DeckLink cards found
		numDevices++;
		if (numDevices > 1)
			printf("\n\n");
		
		// *** Print the model name of the DeckLink card
		result = deckLink->GetModelName((const char **) &deviceNameString);
		if (result == S_OK)
		{
			printf("=============== %s ===============\n\n", deviceNameString);
			free(deviceNameString);
		}

		print_attributes(deckLink);
		
		// ** List the video output display modes supported by the card
		print_output_modes(deckLink);
		
		// ** List the video input display modes supported by the card
		print_input_modes(deckLink);
		
		// ** List the input and output capabilities of the card
		print_capabilities(deckLink);
		
		// Release the IDeckLink instance when we've finished with it to prevent leaks
		deckLink->Release();
	}
	
	deckLinkIterator->Release();

	// If no DeckLink cards were found in the system, inform the user
	if (numDevices == 0)
		printf("No Blackmagic Design devices were found.\n");
	printf("\n");
	
	return 0;
}
Exemplo n.º 6
0
    bool open( unsigned card =  0 )
    {
        IDeckLinkIterator* decklinkIterator = NULL;
        try
        {
#ifdef WIN32
            HRESULT result =  CoInitialize( NULL );
            if ( FAILED( result ) )
                throw "COM initialization failed";
            result = CoCreateInstance( CLSID_CDeckLinkIterator, NULL, CLSCTX_ALL, IID_IDeckLinkIterator, (void**) &decklinkIterator );
            if ( FAILED( result ) )
                throw "The DeckLink drivers are not installed.";
#else
            decklinkIterator = CreateDeckLinkIteratorInstance();
            if ( !decklinkIterator )
                throw "The DeckLink drivers are not installed.";
#endif
            // Connect to the Nth DeckLink instance
            for ( unsigned i = 0; decklinkIterator->Next( &m_decklink ) == S_OK ; i++)
            {
                if ( i == card )
                    break;
                else
                    SAFE_RELEASE( m_decklink );
            }
            SAFE_RELEASE( decklinkIterator );
            if ( !m_decklink )
                throw "DeckLink card not found.";

            // Get the input interface
            if ( m_decklink->QueryInterface( IID_IDeckLinkInput, (void**) &m_decklinkInput ) != S_OK )
                throw "No DeckLink cards support input.";

            // Provide this class as a delegate to the input callback
            m_decklinkInput->SetCallback( this );

            // Initialize other members
            pthread_mutex_init( &m_mutex, NULL );
            pthread_cond_init( &m_condition, NULL );
            m_queue = mlt_deque_init();
            m_started = false;
            m_dropped = 0;
            m_isBuffering = true;
            m_cache = mlt_cache_init();

            // 3 covers YADIF and increasing framerate use cases
            mlt_cache_set_size( m_cache, 3 );
        }
        catch ( const char *error )
        {
            SAFE_RELEASE( m_decklinkInput );
            SAFE_RELEASE( m_decklink );
            mlt_log_error( getProducer(), "%s\n", error );
            return false;
        }
        return true;
    }
Exemplo n.º 7
0
static gboolean
gst_decklink_sink_start (GstDecklinkSink * decklinksink)
{
  IDeckLinkIterator *iterator;
  HRESULT ret;
  const GstDecklinkMode *mode;
  BMDAudioSampleType sample_depth;

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

  ret = iterator->Next (&decklinksink->decklink);
  if (ret != S_OK) {
    GST_ERROR ("no card");
    return FALSE;
  }

  ret = decklinksink->decklink->QueryInterface (IID_IDeckLinkOutput,
      (void **) &decklinksink->output);
  if (ret != S_OK) {
    GST_ERROR ("no output");
    return FALSE;
  }

  decklinksink->output->SetAudioCallback (decklinksink->callback);

  mode = gst_decklink_get_mode (decklinksink->mode);

  ret = decklinksink->output->EnableVideoOutput (mode->mode,
      bmdVideoOutputFlagDefault);
  if (ret != S_OK) {
    GST_ERROR ("failed to enable video output");
    return FALSE;
  }
  //decklinksink->video_enabled = TRUE;

  decklinksink->output->
      SetScheduledFrameCompletionCallback (decklinksink->callback);

  sample_depth = bmdAudioSampleType16bitInteger;
  ret = decklinksink->output->EnableAudioOutput (bmdAudioSampleRate48kHz,
      sample_depth, 2, bmdAudioOutputStreamContinuous);
  if (ret != S_OK) {
    GST_ERROR ("failed to enable audio output");
    return FALSE;
  }
  decklinksink->audio_buffer = gst_buffer_new ();

  decklinksink->num_frames = 0;

  return TRUE;
}
Exemplo n.º 8
0
bool BMDOpenGLOutput::InitDeckLink()
{
    bool bSuccess = FALSE;
    IDeckLinkIterator* pDLIterator = NULL;

    pDLIterator = CreateDeckLinkIteratorInstance();
    if (pDLIterator == NULL)
    {
        QMessageBox::critical(NULL,"This application requires the DeckLink drivers installed.", "Please install the Blackmagic DeckLink drivers to use the features of this application.");
        goto error;
    }

    if (pDLIterator->Next(&pDL) != S_OK)
    {
        QMessageBox::critical(NULL,"This application requires a DeckLink device.", "You will not be able to use the features of this application until a DeckLink device is installed.");
        goto error;
    }

    if (pDL->QueryInterface(IID_IDeckLinkOutput, (void**)&pDLOutput) != S_OK)
        goto error;

    pRenderDelegate = new RenderDelegate(this);
    if (pRenderDelegate == NULL)
        goto error;

    if (pDLOutput->SetScheduledFrameCompletionCallback(pRenderDelegate) != S_OK)
        goto error;

    bSuccess = TRUE;

error:

    if (!bSuccess)
    {
        if (pDLOutput != NULL)
        {
            pDLOutput->Release();
            pDLOutput = NULL;
        }
        if (pDL != NULL)
        {
            pDL->Release();
            pDL = NULL;
        }
    }

    if (pDLIterator != NULL)
    {
        pDLIterator->Release();
        pDLIterator = NULL;
    }

    return bSuccess;
}
Exemplo n.º 9
0
static void
init_devices (void)
{
  IDeckLinkIterator *iterator;
  IDeckLink *decklink = NULL;
  HRESULT ret;
  int i;
  static gboolean inited = FALSE;

  if (inited) return;
  inited = TRUE;

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

  i = 0;
  ret = iterator->Next (&decklink);
  while (ret == S_OK) {
    devices[i].decklink = decklink;

    ret = decklink->QueryInterface (IID_IDeckLinkInput,
        (void **) &devices[i].input);
    if (ret != S_OK) {
      GST_WARNING ("selected device does not have input interface");
    }

    ret = decklink->QueryInterface (IID_IDeckLinkOutput,
        (void **) &devices[i].output);
    if (ret != S_OK) {
      GST_WARNING ("selected device does not have output interface");
    }

    ret = decklink->QueryInterface (IID_IDeckLinkConfiguration,
        (void **) &devices[i].config);
    if (ret != S_OK) {
      GST_WARNING ("selected device does not have config interface");
    }

    ret = iterator->Next (&decklink);
    i++;

    if (i == 10) {
      GST_WARNING ("this hardware has more then 10 devices");
      break;
    }
  }

  n_devices = i;

  iterator->Release();
}
vector<ofVideoDevice> ofxBlackmagicGrabber::listDevices() {
	IDeckLinkIterator*		deckLinkIterator;
	IDeckLink*				deckLink;
	int						numDevices = 0;
	HRESULT					result;
	
	vector<ofVideoDevice> devices;

	// Create an IDeckLinkIterator object to enumerate all DeckLink cards in the system
	deckLinkIterator = CreateDeckLinkIteratorInstance();
	if (deckLinkIterator == NULL){
		ofLogError(LOG_NAME) <<  "A DeckLink iterator could not be created.  The DeckLink drivers may not be installed.";
	}

	// Enumerate all cards in this system
	while (deckLinkIterator->Next(&deckLink) == S_OK){
		CFStringRef deviceNameString;

		// Increment the total number of DeckLink cards found
		numDevices++;
		if (numDevices > 1)
			printf("\n\n");

		// *** Print the model name of the DeckLink card
		result = deckLink->GetModelName(&deviceNameString);
		if (result == S_OK)
		{
			printf("=============== %s ===============\n\n", deviceNameString);
//			free(deviceNameString);
		}

		print_attributes(deckLink);

		// ** List the video output display modes supported by the card
		print_output_modes(deckLink);

		// ** List the input and output capabilities of the card
		print_capabilities(deckLink);

		// Release the IDeckLink instance when we've finished with it to prevent leaks
		deckLink->Release();
	}

	deckLinkIterator->Release();

	// If no DeckLink cards were found in the system, inform the user
	if (numDevices == 0)
		ofLogError(LOG_NAME) <<  "No Blackmagic Design devices were found.";

	return devices;
}
Exemplo n.º 11
0
static void
gst_decklinksrc_class_probe_devices (GstElementClass * klass)
{
  IDeckLinkIterator *iterator;
  IDeckLink *decklink;

  n_devices = 0;
  iterator = CreateDeckLinkIteratorInstance ();
  if (iterator) {
    while (iterator->Next (&decklink) == S_OK) {
      n_devices++;
    }
  }

  probed = TRUE;
}
Exemplo n.º 12
0
// Listen for the list_devices property to be set
    static void on_property_changed( void*, mlt_properties properties, const char *name )
    {
        IDeckLinkIterator* decklinkIterator = NULL;
        IDeckLink* decklink = NULL;
        IDeckLinkInput* decklinkInput = NULL;
        int i = 0;

        if ( name && !strcmp( name, "list_devices" ) )
            mlt_event_block( (mlt_event) mlt_properties_get_data( properties, "list-devices-event", NULL ) );
        else
            return;

#ifdef WIN32
        if ( FAILED( CoInitialize( NULL ) ) )
            return;
        if ( FAILED( CoCreateInstance( CLSID_CDeckLinkIterator, NULL, CLSCTX_ALL, IID_IDeckLinkIterator, (void**) &decklinkIterator ) ) )
            return;
#else
        if ( !( decklinkIterator = CreateDeckLinkIteratorInstance() ) )
            return;
#endif
        for ( ; decklinkIterator->Next( &decklink ) == S_OK; i++ )
        {
            if ( decklink->QueryInterface( IID_IDeckLinkInput, (void**) &decklinkInput ) == S_OK )
            {
                DLString name = NULL;
                if ( decklink->GetModelName( &name ) == S_OK )
                {
                    char *name_cstr = getCString( name );
                    const char *format = "device.%d";
                    char *key = (char*) calloc( 1, strlen( format ) + 1 );

                    sprintf( key, format, i );
                    mlt_properties_set( properties, key, name_cstr );
                    free( key );
                    freeDLString( name );
                    freeCString( name_cstr );
                }
                SAFE_RELEASE( decklinkInput );
            }
            SAFE_RELEASE( decklink );
        }
        SAFE_RELEASE( decklinkIterator );
        mlt_properties_set_int( properties, "devices", i );
    }
/* former device probe code, redux */
static void
gst_decklinksrc_list_devices (void)
{
  IDeckLinkIterator *iterator;
  IDeckLink *decklink;
  int n_devices;

  n_devices = 0;
  iterator = CreateDeckLinkIteratorInstance ();
  if (iterator) {
    while (iterator->Next (&decklink) == S_OK) {
      n_devices++;
    }
  }
  iterator->Release();

  g_print ("%d devices\n", n_devices);
}
Exemplo n.º 14
0
QStringList BMDOutputDelegate::enumDeviceNames(bool forceReload)
{
	if(!s_knownDevices.isEmpty())
	{
		if(!forceReload)
			return s_knownDevices;
		else	
			s_knownDevices.clear();
	}
		
	IDeckLinkIterator *deckLinkIterator = CreateDeckLinkIteratorInstance();
	if (deckLinkIterator == NULL)
	{
		fprintf(stderr, "BMDCaptureDelegate::enumDeviceNames: A DeckLink iterator could not be created.  The DeckLink drivers may not be installed.\n");
		return QStringList();
	}
	
	IDeckLink	*deckLink;
	IDeckLinkInput	*deckLinkOutput;
	
	int index = 0;
	
	// Enumerate all cards in this system
	while (deckLinkIterator->Next(&deckLink) == S_OK)
	{
		if (deckLink->QueryInterface(IID_IDeckLinkOutput, (void**)&deckLinkOutput) == S_OK)
		{
			s_knownDevices << QString("bmd:%1").arg(index);
			
			deckLinkOutput->Release();
			deckLinkOutput = NULL;
		}
		
		
		index ++;
		
		// Release the IDeckLink instance when we've finished with it to prevent leaks
		deckLink->Release();
	}
	
	deckLinkIterator->Release();
	
	return s_knownDevices;
}
Exemplo n.º 15
0
int ff_decklink_list_devices(AVFormatContext *avctx)
{
    IDeckLink *dl = NULL;
    IDeckLinkIterator *iter = CreateDeckLinkIteratorInstance();
    if (!iter) {
        av_log(avctx, AV_LOG_ERROR, "Could not create DeckLink iterator\n");
        return AVERROR(EIO);
    }
    av_log(avctx, AV_LOG_INFO, "Blackmagic DeckLink devices:\n");
    while (iter->Next(&dl) == S_OK) {
        const char *displayName;
        ff_decklink_get_display_name(dl, &displayName);
        av_log(avctx, AV_LOG_INFO, "\t'%s'\n", displayName);
        av_free((void *) displayName);
        dl->Release();
    }
    iter->Release();
    return 0;
}
Exemplo n.º 16
0
	bool open( unsigned card = 0 )
	{
		IDeckLinkIterator* deckLinkIterator = CreateDeckLinkIteratorInstance();
		unsigned i = 0;
		
		if ( !deckLinkIterator )
		{
			mlt_log_verbose( NULL, "The DeckLink drivers not installed.\n" );
			return false;
		}
		
		// Connect to the Nth DeckLink instance
		do {
			if ( deckLinkIterator->Next( &m_deckLink ) != S_OK )
			{
				mlt_log_verbose( NULL, "DeckLink card not found\n" );
				deckLinkIterator->Release();
				return false;
			}
		} while ( ++i <= card );
		
		// Obtain the audio/video output interface (IDeckLinkOutput)
		if ( m_deckLink->QueryInterface( IID_IDeckLinkOutput, (void**)&m_deckLinkOutput ) != S_OK )
		{
			mlt_log_verbose( NULL, "No DeckLink cards support output\n" );
			m_deckLink->Release();
			m_deckLink = 0;
			deckLinkIterator->Release();
			return false;
		}
		
		// Provide this class as a delegate to the audio and video output interfaces
		m_deckLinkOutput->SetScheduledFrameCompletionCallback( this );
		m_deckLinkOutput->SetAudioCallback( this );
		
		pthread_mutex_init( &m_mutex, NULL );
		pthread_cond_init( &m_condition, NULL );
		m_maxAudioBuffer = bmdAudioSampleRate48kHz;
		m_videoFrameQ = mlt_deque_init();
		
		return true;
	}
Exemplo n.º 17
0
static IDeckLink *find_card(int card_index) {
    HRESULT ret;
    IDeckLinkIterator *dli = CreateDeckLinkIteratorInstance( );
    IDeckLink *dl;

    if (!dli) {
        throw std::runtime_error(
            "CreateDeckLinkIteratorInstance( ) failed"
        );
    }

    while (card_index >= 0) {
        ret = dli->Next(&dl);
        if (ret != S_OK) {
            throw std::runtime_error("DeckLink card not found");
        }
        card_index--;
    }

    return dl;
}
Exemplo n.º 18
0
int ff_decklink_init_device(AVFormatContext *avctx, const char* name)
{
    struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
    struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
    IDeckLink *dl = NULL;
    IDeckLinkIterator *iter = CreateDeckLinkIteratorInstance();
    if (!iter) {
        av_log(avctx, AV_LOG_ERROR, "Could not create DeckLink iterator\n");
        return AVERROR_EXTERNAL;
    }

    while (iter->Next(&dl) == S_OK) {
        const char *displayName;
        ff_decklink_get_display_name(dl, &displayName);
        if (!strcmp(name, displayName)) {
            av_free((void *)displayName);
            ctx->dl = dl;
            break;
        }
        av_free((void *)displayName);
        dl->Release();
    }
    iter->Release();
    if (!ctx->dl)
        return AVERROR(ENXIO);

    if (ctx->dl->QueryInterface(IID_IDeckLinkConfiguration, (void **)&ctx->cfg) != S_OK) {
        av_log(avctx, AV_LOG_ERROR, "Could not get configuration interface for '%s'\n", name);
        ff_decklink_cleanup(avctx);
        return AVERROR_EXTERNAL;
    }

    if (ctx->dl->QueryInterface(IID_IDeckLinkAttributes, (void **)&ctx->attr) != S_OK) {
        av_log(avctx, AV_LOG_ERROR, "Could not get attributes interface for '%s'\n", name);
        ff_decklink_cleanup(avctx);
        return AVERROR_EXTERNAL;
    }

    return 0;
}
Exemplo n.º 19
0
IDeckLink* BMDConfig::GetDeckLink(int idx)
{
	HRESULT				result;
	IDeckLink*			deckLink;
	IDeckLinkIterator*	deckLinkIterator = CreateDeckLinkIteratorInstance();
	int					i = idx;

	while((result = deckLinkIterator->Next(&deckLink)) == S_OK)
	{
		if (i == 0)
			break;
		--i;
		deckLink->Release();

	}
	deckLinkIterator->Release();

	if (result != S_OK)
		return NULL;

	return deckLink;
}
Exemplo n.º 20
0
krad_decklink_capture_t *krad_decklink_capture_create(int device) {

	int d;
	krad_decklink_capture_t *krad_decklink_capture = (krad_decklink_capture_t *)calloc(1, sizeof(krad_decklink_capture_t));
	
	krad_decklink_capture->device = device;
	krad_decklink_capture->inputFlags = 0;
	krad_decklink_capture->audio_input = bmdAudioConnectionEmbedded;	
	krad_decklink_capture->audio_sample_rate = bmdAudioSampleRate48kHz;
	krad_decklink_capture->audio_channels = 2;
	krad_decklink_capture->audio_bit_depth = 16;
	
	krad_decklink_capture->deckLinkIterator = CreateDeckLinkIteratorInstance();
	
	if (!krad_decklink_capture->deckLinkIterator) {
		printke("Krad Decklink: No DeckLink drivers installed.");
		free (krad_decklink_capture);
		return NULL;
	}
	
	for (d = 0; d < 64; d++) {
	
		krad_decklink_capture->result = krad_decklink_capture->deckLinkIterator->Next(&krad_decklink_capture->deckLink);
		if (krad_decklink_capture->result != S_OK) {
			printke ("Krad Decklink: No DeckLink devices found.");
			free (krad_decklink_capture);
			return NULL;
		}
		
		if (d == krad_decklink_capture->device) {
			break;
		}
		
	}

	return krad_decklink_capture;
	
}
Exemplo n.º 21
0
IDeckLink *getFirstDeckLinkCard()
{
	IDeckLink *deckLink = NULL;
	IDeckLinkIterator *deckLinkIter = CreateDeckLinkIteratorInstance();
	
	if (deckLinkIter)
	{
		// get the first decklink card
		if (deckLinkIter->Next(&deckLink) != S_OK)
		{
			printf("Could not detect a DeckLink card\n");
		}
		
		
		deckLinkIter->Release();
	}
	else
	{
		printf("Could not enumerate DeckLink cards\n");
	}
	
	return deckLink;
}
Exemplo n.º 22
0
static IDeckLinkIterator *decklink_create_iterator(AVFormatContext *avctx)
{
    IDeckLinkIterator *iter;

#ifdef _WIN32
    if (CoInitialize(NULL) < 0) {
        av_log(avctx, AV_LOG_ERROR, "COM initialization failed.\n");
        return NULL;
    }

    if (CoCreateInstance(CLSID_CDeckLinkIterator, NULL, CLSCTX_ALL,
                         IID_IDeckLinkIterator, (void**) &iter) != S_OK) {
        iter = NULL;
    }
#else
    iter = CreateDeckLinkIteratorInstance();
#endif
    if (!iter)
        av_log(avctx, AV_LOG_ERROR, "Could not create DeckLink iterator. "
                                    "Make sure you have DeckLink drivers " BLACKMAGIC_DECKLINK_API_VERSION_STRING " or newer installed.\n");

    return iter;
}
Exemplo n.º 23
0
BMDOutputDelegate *BMDOutputDelegate::openDevice(QString deviceName)
{
	if(enumDeviceNames().indexOf(deviceName) < 0)
		return 0;
		
	QString name = deviceName.replace("bmd:","");
	int cardNum = name.toInt();
	
	IDeckLinkIterator *deckLinkIterator = CreateDeckLinkIteratorInstance();
	if (deckLinkIterator == NULL)
	{
		qDebug() << "BMDOutputDelegate::openDevice: A DeckLink iterator could not be created.  The DeckLink drivers may not be installed.";
		return 0;
	}
		
	
	int index = 0;
	
	IDeckLink* deckLink;
	
	// Find the card requested
	while (deckLinkIterator->Next(&deckLink) == S_OK)
	{
		if(index == cardNum)
			return new BMDOutputDelegate(deckLink);
		
		index ++;
		
		// Release the IDeckLink instance when we've finished with it to prevent leaks
		deckLink->Release();
	}
	
	deckLinkIterator->Release();
		
	return 0;
}
CaptureBlackMagic::CaptureBlackMagic(const CaptureDevice captureDevice)
    : Capture(captureDevice)
    , mChannels(-1)
    , mReturnFrame(NULL)
{
    
    HRESULT						result;
    

    deckLinkIterator = CreateDeckLinkIteratorInstance();


    if (!deckLinkIterator)
    {
        fprintf(stderr, "This application requires the DeckLink drivers installed.\n");
    }
    else
    {
        fprintf(stderr, "found declink driver\n");
    }
    
    camera = new CameraDecklink();

}
Exemplo n.º 25
0
OFX_DECKLINK_API_BEGIN_NAMESPACE

vector<Device> listDevice()
{
    vector<Device> devinfo;
    
	IDeckLinkIterator* deckLinkIterator = CreateDeckLinkIteratorInstance();
	if (deckLinkIterator == NULL)
	{
		ofLogError("ofxDeckLinkAPI::Monitor") << "This application requires the DeckLink drivers installed." << "\n" << "Please install the Blackmagic DeckLink drivers to use the features of this application.";
	}
	
	cout << "==== ofxDeckLinkAPI::listDevice() ====" << endl;
	
	IDeckLink* deckLink = NULL;
	HRESULT result;
	int num_device = 0;
	
	while (deckLinkIterator->Next(&deckLink) == S_OK)
	{
        Device dev;
		CFStringRef deviceNameCFString = NULL;
		
		result = deckLink->GetModelName(&deviceNameCFString);
		if (result == S_OK)
		{
			char deviceName[64];
			CFStringGetCString(deviceNameCFString, deviceName, sizeof(deviceName), kCFStringEncodingUTF8);
			cout << num_device << ": " << deviceName;
			CFRelease(deviceNameCFString);
            dev.model_name = (string)deviceName;
		}
        IDeckLinkAttributes* attr = NULL;
        deckLink->QueryInterface(IID_IDeckLinkAttributes, (void**)&attr);
        if (attr != NULL) {
            {
                int64_t v = 0;
                if (attr->GetInt(BMDDeckLinkPersistentID, &v) == S_OK) {
                    dev.persistent_id = v;
                    cout << ", pid:" << v;
                }
            }
            {
                int64_t v = 0;
                if (attr->GetInt(BMDDeckLinkTopologicalID, &v) == S_OK) {
                    dev.topological_id = v;
                    cout << ", tid:" << v;
                }
            }
        }
        cout << endl;
        devinfo.push_back(dev);
		
		deckLink->Release();
		
		num_device++;
	}
	
	if (num_device == 0)
		cout << "device not found" << endl;
	
	cout << "======================================" << endl << endl;
	
	if (deckLinkIterator != NULL)
	{
		deckLinkIterator->Release();
		deckLinkIterator = NULL;
	}
    
    return devinfo;
}
Exemplo n.º 26
0
bool Player::Init(int videomode, int connection, int camera)
{
    // Initialize the DeckLink API
    IDeckLinkIterator *deckLinkIterator = CreateDeckLinkIteratorInstance();
    HRESULT result;
    int i = 0;

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

    m_audioSampleDepth =
        av_get_exact_bits_per_sample(audio_st->codec->codec_id);

    switch (audio_st->codec->channels) {
        case  2:
        case  8:
        case 16:
            break;
        default:
            fprintf(stderr,
                    "%d channels not supported, please use 2, 8 or 16\n",
                    audio_st->codec->channels);
            goto bail;
    }

    switch (m_audioSampleDepth) {
        case 16:
        case 32:
            break;
        default:
            fprintf(stderr, "%dbit audio not supported use 16bit or 32bit\n",
                    m_audioSampleDepth);
    }

    do
        result = deckLinkIterator->Next(&m_deckLink);
    while (i++ < camera);

    if (result != S_OK) {
        fprintf(stderr, "No DeckLink PCI cards found\n");
        goto bail;
    }

    // Obtain the audio/video output interface (IDeckLinkOutput)
    if (m_deckLink->QueryInterface(IID_IDeckLinkOutput,
                                   (void **)&m_deckLinkOutput) != S_OK)
        goto bail;

    result = m_deckLink->QueryInterface(IID_IDeckLinkConfiguration,
                                        (void **)&deckLinkConfiguration);
    if (result != S_OK) {
        fprintf(
            stderr,
            "Could not obtain the IDeckLinkConfiguration interface - result = %08x\n",
            result);
        goto bail;
    }
    //XXX make it generic
    switch (connection) {
    case 1:
        DECKLINK_SET_VIDEO_CONNECTION(bmdVideoConnectionComposite);
        DECKLINK_SET_AUDIO_CONNECTION(bmdAudioConnectionAnalog);
        break;
    case 2:
        DECKLINK_SET_VIDEO_CONNECTION(bmdVideoConnectionComponent);
        DECKLINK_SET_AUDIO_CONNECTION(bmdAudioConnectionAnalog);
        break;
    case 3:
        DECKLINK_SET_VIDEO_CONNECTION(bmdVideoConnectionHDMI);
        DECKLINK_SET_AUDIO_CONNECTION(bmdAudioConnectionEmbedded);
        break;
    case 4:
        DECKLINK_SET_VIDEO_CONNECTION(bmdVideoConnectionSDI);
        DECKLINK_SET_AUDIO_CONNECTION(bmdAudioConnectionEmbedded);
        break;
    default:
        // do not change it
        break;
    }

    // Provide this class as a delegate to the audio and video output interfaces
    m_deckLinkOutput->SetScheduledFrameCompletionCallback(this);
    m_deckLinkOutput->SetAudioCallback(this);

    avframe = avcodec_alloc_frame();

    packet_queue_init(&audioqueue);
    packet_queue_init(&videoqueue);
    packet_queue_init(&dataqueue);
    pthread_t th;
    pthread_create(&th, NULL, fill_queues, NULL);

    usleep(buffer); // You can add the microseconds you need for pre-buffering before start playing
    // Start playing
    StartRunning(videomode);

    pthread_mutex_lock(&sleepMutex);
    pthread_cond_wait(&sleepCond, &sleepMutex);
    pthread_mutex_unlock(&sleepMutex);
    fill_me = 0;
    fprintf(stderr, "Exiting, cleaning up\n");
    packet_queue_end(&audioqueue);
    packet_queue_end(&videoqueue);

bail:
    if (m_running == true) {
        StopRunning();
    } else {
        // Release any resources that were partially allocated
        if (m_deckLinkOutput != NULL) {
            m_deckLinkOutput->Release();
            m_deckLinkOutput = NULL;
        }
        //
        if (m_deckLink != NULL) {
            m_deckLink->Release();
            m_deckLink = NULL;
        }
    }

    if (deckLinkIterator != NULL)
        deckLinkIterator->Release();

    return true;
}
Exemplo n.º 27
0
int usage(int status)
{
    HRESULT result;
    IDeckLinkIterator *deckLinkIterator;
    IDeckLink *deckLink;
    int numDevices = 0;

    fprintf(stderr,
            "Usage: bmdplay -m <mode id> [OPTIONS]\n"
            "\n"
            "    -m <mode id>:\n"
            );

    // Create an IDeckLinkIterator object to enumerate all DeckLink cards in the system
    deckLinkIterator = CreateDeckLinkIteratorInstance();
    if (deckLinkIterator == NULL) {
        fprintf(
            stderr,
            "A DeckLink iterator could not be created.  The DeckLink drivers may not be installed.\n");
        return 1;
    }

    // Enumerate all cards in this system
    while (deckLinkIterator->Next(&deckLink) == S_OK) {
        BMDProbeString str;

        // Increment the total number of DeckLink cards found
        numDevices++;
        if (numDevices > 1)
            printf("\n\n");

        // *** Print the model name of the DeckLink card
        result = deckLink->GetModelName(&str);
        if (result == S_OK) {
            printf("-> %s (-C %d )\n\n",
                   ToStr(str),
                   numDevices - 1);
            FreeStr(str);
        }

        print_output_modes(deckLink);
        // Release the IDeckLink instance when we've finished with it to prevent leaks
        deckLink->Release();
    }
    deckLinkIterator->Release();

    // If no DeckLink cards were found in the system, inform the user
    if (numDevices == 0)
        printf("No Blackmagic Design devices were found.\n");
    printf("\n");

    fprintf(
        stderr,
        "    -f <filename>        Filename raw video will be written to\n"
        "    -C <num>             Card number to be used\n"
        "    -b <num>             Milliseconds of pre-buffering before playback (default = 2000 ms)\n"
        "    -p <pixel>           PixelFormat Depth (8 or 10 - default is 8)\n"
        "    -O <output>          Output connection:\n"
        "                         1: Composite video + analog audio\n"
        "                         2: Components video + analog audio\n"
        "                         3: HDMI video + audio\n"
        "                         4: SDI video + audio\n\n");

    return status;
}
Exemplo n.º 28
0
void krad_decklink_cpp_get_device_name (int device_num, char *device_name) {

	IDeckLinkIterator *deckLinkIterator;
	IDeckLink *deckLink;
	int device_count;
	HRESULT result;
#ifdef IS_LINUX
	char *device_name_temp;
#endif
#ifdef IS_MACOSX
  CFStringRef device_name_temp;
#endif
	device_name_temp = NULL;
	device_count = 0;
	
	deckLinkIterator = CreateDeckLinkIteratorInstance();
	
	if (deckLinkIterator == NULL) {
		printke ("krad_decklink_detect_devices: The DeckLink drivers may not be installed.");
		return;
	}
	
	while (deckLinkIterator->Next(&deckLink) == S_OK) {

		if (device_count == device_num) {
#ifdef IS_LINUX
			result = deckLink->GetModelName((const char **) &device_name_temp);
			if (result == S_OK) {
				strcpy(device_name, device_name_temp);
				free(device_name_temp);
#endif
#ifdef IS_MACOSX
			result = deckLink->GetModelName(&device_name_temp);
			if (result == S_OK) {
        CFStringGetCString(device_name_temp, device_name, 64, kCFStringEncodingMacRoman);
				CFRelease(device_name_temp);
#endif

			} else {
				strcpy(device_name, "Unknown Error in GetModelName");
			}
			deckLink->Release();
			deckLinkIterator->Release();
			return;
		}

		device_count++;
		deckLink->Release();
	}
	
	deckLinkIterator->Release();
	
	sprintf(device_name, "Could not get a device name for device %d", device_num);
	
	return;

}




}
Exemplo n.º 29
0
void krad_decklink_capture_info () {

	IDeckLink *deckLink;
	IDeckLinkInput *deckLinkInput;
	IDeckLinkIterator *deckLinkIterator;
	IDeckLinkDisplayModeIterator *displayModeIterator;
	IDeckLinkDisplayMode *displayMode;
	
	HRESULT result;
	int displayModeCount;
	char *displayModeString;

	displayModeString = NULL;
	displayModeCount = 0;
	
	deckLinkIterator = CreateDeckLinkIteratorInstance();
	
	if (!deckLinkIterator) {
		printke ("Krad Decklink: This application requires the DeckLink drivers installed.\n");
	}
	
	/* Connect to the first DeckLink instance */
	result = deckLinkIterator->Next(&deckLink);
	if (result != S_OK) {
		printke ("Krad Decklink: No DeckLink PCI cards found.\n");
	}
    
	result = deckLink->QueryInterface(IID_IDeckLinkInput, (void**)&deckLinkInput);
	if (result != S_OK) {
		printke ("Krad Decklink: Fail QueryInterface\n");
	}
	
	result = deckLinkInput->GetDisplayModeIterator(&displayModeIterator);
	if (result != S_OK) {
		printke ("Krad Decklink: Could not obtain the video output display mode iterator - result = %08x\n", result);
	}


    while (displayModeIterator->Next(&displayMode) == S_OK) {

        result = displayMode->GetName((const char **) &displayModeString);
        
        if (result == S_OK) {
			
			BMDTimeValue frameRateDuration, frameRateScale;
			displayMode->GetFrameRate(&frameRateDuration, &frameRateScale);

			printkd ("%2d:  %-20s \t %li x %li \t %g FPS\n", 
				displayModeCount, displayModeString, displayMode->GetWidth(), displayMode->GetHeight(), 
				(double)frameRateScale / (double)frameRateDuration);
			
            free (displayModeString);
			displayModeCount++;
		}
		
		displayMode->Release();
	}
	
	if (displayModeIterator != NULL) {
		displayModeIterator->Release();
		displayModeIterator = NULL;
	}

    if (deckLinkInput != NULL) {
        deckLinkInput->Release();
        deckLinkInput = NULL;
    }

    if (deckLink != NULL) {
        deckLink->Release();
        deckLink = NULL;
    }

	if (deckLinkIterator != NULL) {
		deckLinkIterator->Release();
	}
}
Exemplo n.º 30
0
int query_display_mode(DecklinkConf *c)
{
    DecklinkCapture   *capture     = (DecklinkCapture *)calloc(1, sizeof(*capture));
    BMDPixelFormat    pix[]        = { bmdFormat8BitYUV, bmdFormat10BitYUV,
                                       bmdFormat8BitARGB, bmdFormat10BitRGB,
                                       bmdFormat8BitBGRA };
    BMDDisplayMode    display_mode = -1;
    QueryDelegate     *delegate;
    HRESULT           ret;
    int               i            = 0;
    int               result       = -1;
    IDeckLinkAttributes* deckLinkAttributes;
    bool			  formatDetectionSupported;

    if (!capture)
        goto fail;

    capture->it = CreateDeckLinkIteratorInstance();

    if (!capture->it)
        goto fail;

    switch (c->audio_channels) {
    case  0:
        c->audio_channels = 2;
    case  2:
    case  8:
    case 16:
        break;
    default:
        goto fail;
    }

    switch (c->audio_sample_depth) {
    case  0:
        c->audio_sample_depth = 16;
    case 16:
    case 32:
        break;
    default:
        goto fail;
    }

    if (c->pixel_format >= sizeof(pix))
        goto fail;

    do {
        ret = capture->it->Next(&capture->dl);
    } while (i++ < c->instance);

    if (ret != S_OK)
        goto fail;

    ret = capture->dl->QueryInterface(IID_IDeckLinkAttributes, (void**)&deckLinkAttributes);

    if (ret != S_OK) {
        goto fail;
    }

    ret = deckLinkAttributes->GetFlag(BMDDeckLinkSupportsInputFormatDetection, &formatDetectionSupported);

    if (ret != S_OK) {
        goto fail;
    }

    if (!formatDetectionSupported) {
        goto fail;
    }

    ret = capture->dl->QueryInterface(IID_IDeckLinkInput,
                                      (void**)&capture->in);
    if (ret != S_OK)
        goto fail;

    ret = capture->dl->QueryInterface(IID_IDeckLinkConfiguration,
                                      (void**)&capture->conf);

    switch (c->audio_connection) {
    case 1:
        ret = capture->conf->SetInt(bmdDeckLinkConfigAudioInputConnection,
                                    bmdAudioConnectionAnalog);
        break;
    case 2:
        ret = capture->conf->SetInt(bmdDeckLinkConfigAudioInputConnection,
                                    bmdAudioConnectionEmbedded);
        break;
    default:
        // do not change it
        break;
    }

    if (ret != S_OK) {
        goto fail;
    }

    switch (c->video_connection) {
    case 1:
        ret = capture->conf->SetInt(bmdDeckLinkConfigVideoInputConnection,
                                    bmdVideoConnectionComposite);
        break;
    case 2:
        ret = capture->conf->SetInt(bmdDeckLinkConfigVideoInputConnection,
                                    bmdVideoConnectionComponent);
        break;
    case 3:
        ret = capture->conf->SetInt(bmdDeckLinkConfigVideoInputConnection,
                                    bmdVideoConnectionHDMI);
        break;
    case 4:
        ret = capture->conf->SetInt(bmdDeckLinkConfigVideoInputConnection,
                                    bmdVideoConnectionSDI);
        break;
    default:
        // do not change it
        break;
    }

    if (ret != S_OK) {
        goto fail;
    }

    ret = capture->in->GetDisplayModeIterator(&capture->dm_it);

    if (ret != S_OK) {
        goto fail;
    }

    i = 0;
    while (true) {
        if (capture->dm_it->Next(&capture->dm) != S_OK) {
            capture->dm->Release();
        } else {
            result = i;
            break;
        }
        i++;
    }

    if (result == -1) {
        return -1;
    }

    c->width      = capture->dm->GetWidth();
    c->height     = capture->dm->GetHeight();
    switch (capture->dm->GetFieldDominance()) {
    case bmdUnknownFieldDominance:
        c->field_mode = 0;
        break;
    case bmdLowerFieldFirst:
        c->field_mode = 1;
        break;
    case bmdUpperFieldFirst:
        c->field_mode = 2;
        break;
    case bmdProgressiveFrame:
        c->field_mode = 3;
        break;
    case bmdProgressiveSegmentedFrame:
        c->field_mode = 4;
        break;
    default:
        goto fail;
    }

    capture->dm->GetFrameRate(&c->tb_num, &c->tb_den);

    delegate = new QueryDelegate(capture->dm->GetDisplayMode());

    if (!delegate)
        goto fail;

    capture->in->SetCallback(delegate);

    ret = capture->in->EnableVideoInput(capture->dm->GetDisplayMode(),
                                        pix[c->pixel_format],
                                        bmdVideoInputEnableFormatDetection);

    ret = capture->in->StartStreams();

    if (ret != S_OK) {
        goto fail;
    }

    while (!delegate->isDone())
    {
        usleep(20000);
    }

    ret = capture->in->StopStreams();

    if (ret != S_OK) {
        goto fail;
    }

    if (delegate->GetDisplayMode()) {
        ret = capture->in->GetDisplayModeIterator(&capture->dm_it);

        if (ret != S_OK) {
            goto fail;
        }

        i = 0;
        while (capture->dm_it->Next(&capture->dm) == S_OK) {
            BMDDisplayMode display_mode = capture->dm->GetDisplayMode();
            capture->dm->Release();

            if (display_mode == delegate->GetDisplayMode()) {
                result = i;
            }

            i++;
        }
    }

fail:
    decklink_capture_free(capture);

    return result;
}