示例#1
0
        virtual HRESULT VideoInputFrameArrived(IDeckLinkVideoInputFrame *in,
                IDeckLinkAudioInputPacket *audio_in) {
            
            RawFrame *out;
            AudioPacket *audio_out;
            void *data;
            uint8_t *bytes;
            size_t i, spitch, h;

            if (in != NULL) {
                if (in->GetFlags( ) & bmdFrameHasNoInputSource) {
                    fprintf(stderr, "DeckLink input: no signal\n");
                } else {
                    out = new RawFrame(in->GetWidth(), in->GetHeight(), pf);
                    out->set_field_dominance(dominance);
                    spitch = in->GetRowBytes( );
                    h = in->GetHeight( );
                    in->GetBytes(&data);

                    bytes = (uint8_t *) data;

                    for (i = 0; i < h; i++) {
                        memcpy(out->scanline(i), bytes, out->pitch( ));
                        bytes += spitch;
                    }
                    
                    if (out_pipe.can_put( )) {
                        out_pipe.put(out);
                    } else {
                        fprintf(stderr, "DeckLink: dropping input frame on floor\n");
                        delete out;
                    }
                }
            }

            if (audio_in != NULL && audio_pipe != NULL) {
                audio_out = new AudioPacket(audio_rate, n_channels, 2, 
                        audio_in->GetSampleFrameCount( ));

                if (audio_in->GetBytes(&data) != S_OK) {
                    throw std::runtime_error(
                        "DeckLink audio input: GetBytes failed"
                    );
                }

                memcpy(audio_out->data( ), data, audio_out->size( ));
                audio_pipe->put(audio_out);
            }

            return S_OK;
        }
示例#2
0
        virtual HRESULT VideoInputFrameArrived(IDeckLinkVideoInputFrame *in,
                IDeckLinkAudioInputPacket *audio_in) {
            
            RawFrame *out;
            IOAudioPacket *audio_out;

            void *data;

            if (in == NULL && audio_in == NULL) {
                fprintf(stderr, "VideoInputFrameArrived got nothing??\n");
            }

            /* Process video frame if available. */
            if (in != NULL) {
                if (in->GetFlags( ) & bmdFrameHasNoInputSource) {
                    if (!signal_lost) {
                        fprintf(stderr, "DeckLink input: signal lost\n");
                        signal_lost = true;
                    }
                } else {
                    if (signal_lost) {
                        fprintf(stderr, "DeckLink input: signal re-acquired\n");
                        signal_lost = false;
                    }
                }

                /* 
                 * we can't actually tell the card to just not send video,
                 * so if video is disabled, we just ignore the video frames...
                 */
                if (enable_video) {
                    out = create_raw_frame_from_decklink(in, pf, rotate);
                    out->set_field_dominance(dominance);
                    
                    if (out_pipe.can_put( ) && started) {
                        if (enable_video) {
                            out_pipe.put(out);
                            avsync++;
                        }
                    } else {
                        fprintf(stderr, "DeckLink: dropping input frame\n");
                        drop_audio++;
                        delete out;
                    }
                }
            } 

            /* Process audio, if available. */
            if (audio_in != NULL && audio_pipe != NULL) {
                audio_out = new IOAudioPacket(
                    audio_in->GetSampleFrameCount( ), n_channels
                );

                if (audio_in->GetBytes(&data) != S_OK) {
                    throw std::runtime_error(
                        "DeckLink audio input: GetBytes failed"
                    );
                }

                memcpy(audio_out->data( ), data, audio_out->size_bytes( ));
                if (drop_audio > 0) {
                    fprintf(stderr, "DeckLink: dropping some audio to get back in sync\n");
                    delete audio_out;
                    drop_audio--;
                } else if (audio_pipe->can_put( ) && started) {
                    audio_pipe->put(audio_out);
                    avsync--;
                } else {
                    fprintf(stderr, "DeckLink: dropping input AudioPacket\n");
                    delete audio_out;
                }
            } 


            if (
                    (avsync > 10 || avsync < -10) 
                    && audio_pipe != NULL 
                    && enable_video
            ) {
                fprintf(stderr, "DeckLink warning: avsync drift = %d\n", avsync);
            }

            return S_OK;
        }