VideoSource::VideoSource(const std::string sFileName, FrameQueue *pFrameQueue): hVideoSource_(0) { // fill in SourceData struct as much as we can // right now. Client must specify parser at a later point // to avoid crashes (see setParser() method). assert(0 != pFrameQueue); oSourceData_.hVideoParser = 0; oSourceData_.pFrameQueue = pFrameQueue; CUVIDSOURCEPARAMS oVideoSourceParameters; // Fill parameter struct memset(&oVideoSourceParameters, 0, sizeof(CUVIDSOURCEPARAMS)); oVideoSourceParameters.pUserData = &oSourceData_; // will be passed to data handlers oVideoSourceParameters.pfnVideoDataHandler = HandleVideoData; // our local video-handler callback oVideoSourceParameters.pfnAudioDataHandler = 0; // now create the actual source CUresult oResult = cuvidCreateVideoSource(&hVideoSource_, sFileName.c_str(), &oVideoSourceParameters); assert(CUDA_SUCCESS == oResult); }
void VideoSource::ReloadVideo(const std::string sFileName, FrameQueue *pFrameQueue, VideoParser *pVideoParser) { // fill in SourceData struct as much as we can right now. Client must specify parser at a later point assert(0 != pFrameQueue); oSourceData_.hVideoParser = pVideoParser->hParser_; oSourceData_.pFrameQueue = pFrameQueue; cuvidDestroyVideoSource(hVideoSource_); CUVIDSOURCEPARAMS oVideoSourceParameters; // Fill parameter struct memset(&oVideoSourceParameters, 0, sizeof(CUVIDSOURCEPARAMS)); oVideoSourceParameters.pUserData = &oSourceData_; // will be passed to data handlers oVideoSourceParameters.pfnVideoDataHandler = HandleVideoData; // our local video-handler callback oVideoSourceParameters.pfnAudioDataHandler = 0; // now create the actual source CUresult oResult = cuvidCreateVideoSource(&hVideoSource_, sFileName.c_str(), &oVideoSourceParameters); assert(CUDA_SUCCESS == oResult); }
cv::gpu::detail::CuvidVideoSource::CuvidVideoSource(const std::string& fname) { CUVIDSOURCEPARAMS params; std::memset(¶ms, 0, sizeof(CUVIDSOURCEPARAMS)); // Fill parameter struct params.pUserData = this; // will be passed to data handlers params.pfnVideoDataHandler = HandleVideoData; // our local video-handler callback params.pfnAudioDataHandler = 0; // now create the actual source CUresult res = cuvidCreateVideoSource(&videoSource_, fname.c_str(), ¶ms); if (res == CUDA_ERROR_INVALID_SOURCE) throw std::runtime_error("Unsupported video source"); cuSafeCall( res ); CUVIDEOFORMAT vidfmt; cuSafeCall( cuvidGetSourceVideoFormat(videoSource_, &vidfmt, 0) ); format_.codec = static_cast<VideoReader_GPU::Codec>(vidfmt.codec); format_.chromaFormat = static_cast<VideoReader_GPU::ChromaFormat>(vidfmt.chroma_format); format_.width = vidfmt.coded_width; format_.height = vidfmt.coded_height; }