Skip to content

Instantly share code, notes, and snippets.

@roxlu
Created April 6, 2018 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roxlu/1e2bfe1d21e0784ce55a5e20103e8db1 to your computer and use it in GitHub Desktop.
Save roxlu/1e2bfe1d21e0784ce55a5e20103e8db1 to your computer and use it in GitHub Desktop.
VideoParser.cpp from the cudaDecodeGL example. Here I directly feed the a parsed frame into the decoder and when I the display callback is called I try to map the frame ... which always fails except the first 2 calls.
int
CUDAAPI
VideoParser::HandlePictureDecode(void *pUserData, CUVIDPICPARAMS *pPicParams)
{
VideoParserData *pParserData = reinterpret_cast<VideoParserData *>(pUserData);
printf("CUVIDPICPARAMS.frame_num: %d\n", pPicParams->CodecSpecific.h264.frame_num);
#if 0
bool bFrameAvailable = pParserData->pFrameQueue->waitUntilFrameAvailable(pPicParams->CurrPicIdx);
if (!bFrameAvailable)
return false;
if (pParserData->pVideoDecoder->decodePicture(pPicParams, pParserData->pContext) != CUDA_SUCCESS)
{
return false;
}
#else
if (pParserData->pVideoDecoder->decodePicture(pPicParams, pParserData->pContext) != CUDA_SUCCESS)
{
printf("ERROR: failed to decode the picture. \n");
return false;
}
#endif
return true;
}
int
CUDAAPI
VideoParser::HandlePictureDisplay(void *pUserData, CUVIDPARSERDISPINFO *pPicParams)
{
// std::cout << *pPicParams << std::endl;
VideoParserData *pParserData = reinterpret_cast<VideoParserData *>(pUserData);
#if 0
pParserData->pFrameQueue->enqueue(pPicParams);
#else
/* @todo testing by directly mapping the image. */
CUVIDPROCPARAMS vpp;
CUdeviceptr device_ptr = 0;
unsigned int pitch = 0;
CUresult r = CUDA_SUCCESS;
memset(&vpp, 0, sizeof(CUVIDPROCPARAMS));
vpp.progressive_frame = pPicParams->progressive_frame;
vpp.top_field_first = pPicParams->top_field_first;
vpp.unpaired_field = (pPicParams->repeat_first_field < 0);
r = pParserData->pVideoDecoder->mapFrame(pPicParams->picture_index, &device_ptr, &pitch,&vpp);
if (CUDA_SUCCESS == r) {
printf("---------------------------------------------------------\n");
}
else {
printf(":-(\n");
}
#endif
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment