Skip to content

Commit

Permalink
cuda: fix invalid frame when copy from cuda
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Mar 24, 2014
1 parent ceaec16 commit b6e2ed3
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/VideoDecoderCUDA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "prepost.h"
#include <QtCore/QQueue>

#define COPY_ON_DECODE 1
#define COPY_ON_DECODE 0
/*
* TODO: update helper_cuda with 5.5
* avc1, ccv1 => h264 + sps, pps, nal. use filter or lavcudiv
Expand Down Expand Up @@ -252,6 +252,7 @@ class VideoDecoderCUDAPrivate : public VideoDecoderPrivate
VideoFrame vf;
CUVIDPARSERDISPINFO *cuviddisp = frame_queue.take();
processDecodedData(cuviddisp, vf);

return vf;
#endif //COPY_ON_DECODE
}
Expand Down Expand Up @@ -305,14 +306,14 @@ class VideoDecoderCUDAPrivate : public VideoDecoderPrivate
}
cuStatus = cuMemcpyDtoHAsync(host_data, devptr, size, stream);
if (cuStatus != CUDA_SUCCESS) {
qWarning("cuMemcpyDtoH failed (%p, %s)", cuStatus, _cudaGetErrorEnum(cuStatus));
qWarning("cuMemcpyDtoHAsync failed (%p, %s)", cuStatus, _cudaGetErrorEnum(cuStatus));
cuvidUnmapVideoFrame(dec, devptr);
cuvidCtxUnlock(vid_ctx_lock, 0);
return false;
}
cuStatus = cuCtxSynchronize();
if (cuStatus != CUDA_SUCCESS) {
qWarning("cuMemcpyDtoH failed (%p, %s)", cuStatus, _cudaGetErrorEnum(cuStatus));
qWarning("cuCtxSynchronize failed (%p, %s)", cuStatus, _cudaGetErrorEnum(cuStatus));
}
cuvidUnmapVideoFrame(dec, devptr);
cuvidCtxUnlock(vid_ctx_lock, 0);
Expand All @@ -326,6 +327,8 @@ class VideoDecoderCUDAPrivate : public VideoDecoderPrivate
int pitches[] = { pitch, pitch };
#if COPY_ON_DECODE
VideoFrame frame(w, h, VideoFormat::Format_NV12);
#else
frame = VideoFrame(w, h, VideoFormat::Format_NV12);
#endif
frame.setBits(planes);
frame.setBytesPerLine(pitches);
Expand Down Expand Up @@ -447,7 +450,7 @@ bool VideoDecoderCUDA::decode(const QByteArray &encoded)
//cuvidCtxUnlock(d.vid_ctx_lock, 0); //TODO: why wrong context?
CUresult cuStatus = cuvidParseVideoData(d.parser, &cuvid_pkt);
if (cuStatus != CUDA_SUCCESS) {
qWarning("cuMemcpyDtoH failed (%p, %s)", cuStatus, _cudaGetErrorEnum(cuStatus));
qWarning("cuvidParseVideoData failed (%p, %s)", cuStatus, _cudaGetErrorEnum(cuStatus));
}
}
// callbacks are in the same thread as this. so no queue is required?
Expand Down

0 comments on commit b6e2ed3

Please sign in to comment.