Esempio n. 1
0
core::mutable_frame make_frame(void*                    tag,
                               core::frame_factory&     frame_factory,
                               std::shared_ptr<AVFrame> video,
                               std::shared_ptr<AVFrame> audio)
{
    const auto pix_desc =
        video ? pixel_format_desc(static_cast<AVPixelFormat>(video->format), video->width, video->height)
              : core::pixel_format_desc(core::pixel_format::invalid);

    auto frame = frame_factory.create_frame(tag, pix_desc);

    if (video) {
        for (int n = 0; n < static_cast<int>(pix_desc.planes.size()); ++n) {
            tbb::parallel_for(0, pix_desc.planes[n].height, [&](int y) {
                std::memcpy(frame.image_data(n).begin() + y * pix_desc.planes[n].linesize,
                            video->data[n] + y * video->linesize[n],
                            pix_desc.planes[n].linesize);
            });
        }
    }

    if (audio) {
        // TODO This is a bit of a hack
        frame.audio_data() = std::vector<int32_t>(audio->nb_samples * 8, 0);
        auto dst           = frame.audio_data().data();
        auto src           = reinterpret_cast<int32_t*>(audio->data[0]);
        tbb::parallel_for(0, audio->nb_samples, [&](int i) {
            for (auto j = 0; j < std::min(8, audio->channels); ++j) {
                dst[i * 8 + j] = src[i * audio->channels + j];
            }
        });
    }

    return frame;
}
Esempio n. 2
0
File: frame.cpp Progetto: acfr/snark
frame::pixel_format_desc frame::format_desc() const
{
    switch( pixel_format_ )
    {
        // Run vimba-cat --list-attributes --verbose and search for PixelFormat
        // to see all allowed formats for a given camera

        case VmbPixelFormatBayerGR12Packed: // BayerGR12Packed
        case VmbPixelFormatBayerRG12Packed: // BayerRG12Packed
        case VmbPixelFormatBayerGB12Packed: // BayerGB12Packed
        case VmbPixelFormatBayerBG12Packed: // BayerBG12Packed
        case VmbPixelFormatMono12Packed:// Mono12Packed
            return pixel_format_desc( CV_8UC1, 1.5 );

        case VmbPixelFormatMono8:       // Mono8
        case VmbPixelFormatBayerGR8:    // BayerGR8
        case VmbPixelFormatBayerRG8:    // BayerRG8
        case VmbPixelFormatBayerBG8:    // BayerGB8
            return pixel_format_desc( CV_8UC1, 1.0 );

        case VmbPixelFormatRgb8:        // RGB8Packed
        case VmbPixelFormatBgr8:        // BGR8Packed
            return pixel_format_desc( CV_8UC3, 1.0 );

        case VmbPixelFormatRgba8:       // RGBA8Packed
        case VmbPixelFormatBgra8:       // BGRA8Packed
            return pixel_format_desc( CV_8UC4, 1.0 );

        case VmbPixelFormatMono10:      // Mono10
        case VmbPixelFormatMono12:      // Mono12
        case VmbPixelFormatMono14:      // Mono14
        case VmbPixelFormatBayerBG10:   // BayerBG10
        case VmbPixelFormatBayerGR12:   // BayerGR12
        case VmbPixelFormatBayerRG12:   // BayerRG12
            return pixel_format_desc( CV_16UC1, 1.0 );

                                        // RGB10Packed (no obvious mapping)
        case VmbPixelFormatRgb12:       // RGB12Packed

        case VmbPixelFormatYuv411:      // YUV411Packed
        case VmbPixelFormatYuv422:      // YUV422Packed
        case VmbPixelFormatYuv444:      // YUV444Packed

        default:
            COMMA_THROW( comma::exception, "unsupported format " << std::hex << pixel_format_ );
    }
}