Ejemplo n.º 1
0
        /* 
         * Try sending some audio data to the Decklink.
         * Call only with current_audio_pkt != NULL.
         * Will set current_audio_pkt to NULL and delete the packet
         * if it is fully consumed.
         * Return number of samples consumed.
         */
        int try_finish_current_audio_packet( ) {
            uint32_t n_consumed;
            uint32_t n_left;
            
            uint32_t buffer;
            deckLinkOutput->GetBufferedAudioSampleFrameCount(&buffer);
            fprintf(stderr, "audio buffer = %u ", buffer);

            assert(current_audio_pkt != NULL);

            n_left = current_audio_pkt->n_frames( ) 
                    - samples_written_from_current_audio_pkt;

            if (n_left == 0) {
                fprintf(stderr, "Audio warning: This should not happen!\n");
                return 1;
            }

            if (deckLinkOutput->ScheduleAudioSamples(
                    current_audio_pkt->sample(
                        samples_written_from_current_audio_pkt
                    ), n_left, 0, 0, &n_consumed) != S_OK) {
                throw std::runtime_error(
                    "Failed to schedule audio samples"
                );
            }

            if (n_consumed == n_left) {
                delete current_audio_pkt;
                current_audio_pkt = NULL;
            } else if (n_consumed < n_left) {
                samples_written_from_current_audio_pkt += n_consumed;
            } else {
                throw std::runtime_error("This should not happen");
            }

            deckLinkOutput->GetBufferedAudioSampleFrameCount(&buffer);
            fprintf(stderr, "-> %u\n", buffer);

            return n_consumed;
        }
Ejemplo n.º 2
0
	virtual HRESULT STDMETHODCALLTYPE RenderAudioSamples( bool preroll )
	{
		// Provide more audio samples to the DeckLink API
		HRESULT result = S_OK;

		uint32_t count = m_fifo->used / m_channels;
		uint32_t buffered = count;

		if ( count
			// Stay under preferred buffer level
			&& ( S_OK == m_deckLinkOutput->GetBufferedAudioSampleFrameCount( &buffered ) )
			&& buffered < m_maxAudioBuffer )
		{
			uint32_t written = 0;
			
			buffered = m_maxAudioBuffer - buffered;
			count = buffered > count ? count : buffered;
			result = m_deckLinkOutput->ScheduleAudioSamples( m_fifo->buffer, count, 0, 0, &written );
			if ( written )
				sample_fifo_remove( m_fifo, written * m_channels );
		}

		return result;
	}