MCPcopy Create free account
hub / github.com/NVIDIA/DALI / RunImpl

Method RunImpl

plugins/video/pkg_src/src/decoder/video_decoder_mixed.cc:70–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68}
69
70void VideoDecoderMixed::RunImpl(dali::Workspace &ws) {
71 auto &output = ws.Output<dali::GPUBackend>(0);
72 const auto &input = ws.Input<dali::CPUBackend>(0);
73 int batch_size = input.num_samples();
74
75 CUcontext cuContext = nullptr;
76 CUstream cuStream = ws.stream();
77 cuCtxGetCurrent(&cuContext);
78
79 if (!cuContext) {
80 throw std::runtime_error("Failed to create a cuda context");
81 }
82
83 for (int i = 0; i < batch_size; i++) {
84 auto output_sample = output[i];
85 uint8_t *output_data = output_sample.template mutable_data<uint8_t>();
86
87 auto &sample = samples_[i];
88 sample.decoder_ = std::make_unique<NvDecoder>(
89 cuStream, cuContext, true, FFmpeg2NvCodecId(sample.demuxer_->GetVideoCodec()), false,
90 false /*_enableasyncallocations*/, false);
91
92
93 uint8_t *pVideo = NULL, *pFrame = nullptr;
94 int nVideoBytes = 0, nFrameReturned = 0, nFrame = 0;
95
96 int num_frames = 0;
97
98 do {
99 sample.demuxer_->Demux(&pVideo, &nVideoBytes);
100 nFrameReturned = sample.decoder_->Decode(pVideo, nVideoBytes);
101
102 for (int i = 0; i < nFrameReturned; i++) {
103 pFrame = sample.decoder_->GetFrame();
104 CUDA_CALL(cudaStreamSynchronize(cuStream));
105
106 uint8_t *dpFrame = output_data + num_frames * sample.demuxer_->GetHeight() *
107 sample.demuxer_->GetWidth() * 3;
108 int nWidth = sample.decoder_->GetWidth();
109 int nPitch = sample.decoder_->GetWidth();
110 int iMatrix =
111 sample.decoder_->GetVideoFormatInfo().video_signal_description.matrix_coefficients;
112 bool full_range =
113 sample.decoder_->GetVideoFormatInfo().video_signal_description.video_full_range_flag;
114
115
116 yuv_to_rgb(pFrame, nPitch, reinterpret_cast<uint8_t *>(dpFrame),
117 sample.decoder_->GetWidth() * 3, sample.decoder_->GetWidth(),
118 sample.decoder_->GetHeight(), full_range, cuStream);
119
120 ++num_frames;
121 if (end_frame_ > 0 && num_frames >= end_frame_) {
122 return;
123 }
124 }
125 } while (nVideoBytes);
126 }
127}

Callers

nothing calls this directly

Calls 4

CUDA_CALLFunction · 0.85
DecodeMethod · 0.80
num_samplesMethod · 0.45
streamMethod · 0.45

Tested by

no test coverage detected