@@ -61,6 +61,26 @@ class CuvidParserException : public std::runtime_error {
61
61
CuvidParserException () : std::runtime_error(" HW reset" ) {}
62
62
};
63
63
64
+ class CudaResMgr
65
+ {
66
+ private:
67
+ CudaResMgr ();
68
+
69
+ public:
70
+ CUcontext GetCtx (size_t idx);
71
+ CUstream GetStream (size_t idx);
72
+ ~CudaResMgr ();
73
+ static CudaResMgr& Instance ();
74
+ static size_t GetNumGpus ();
75
+
76
+ std::vector<std::pair<CUdevice, CUcontext>> g_Contexts;
77
+ std::vector<CUstream> g_Streams;
78
+
79
+ static std::mutex gInsMutex ;
80
+ static std::mutex gCtxMutex ;
81
+ static std::mutex gStrMutex ;
82
+ };
83
+
64
84
class PyFrameUploader {
65
85
std::unique_ptr<CudaUploadFrame> uploader;
66
86
uint32_t surfaceWidth, surfaceHeight;
@@ -95,7 +115,7 @@ class PyBufferUploader {
95
115
CUstream str);
96
116
97
117
PyBufferUploader (uint32_t elemSize, uint32_t numElems,
98
- size_t ctx, size_t str) :
118
+ size_t ctx, size_t str) :
99
119
PyBufferUploader (elemSize, numElems, (CUcontext)ctx, (CUstream)str) {}
100
120
101
121
std::shared_ptr<CudaBuffer> UploadSingleBuffer (py::array_t <uint8_t > &buffer);
@@ -136,7 +156,7 @@ class PyCudaBufferDownloader {
136
156
CUstream str);
137
157
138
158
PyCudaBufferDownloader (uint32_t elemSize, uint32_t numElems,
139
- size_t ctx, size_t str) :
159
+ size_t ctx, size_t str) :
140
160
PyCudaBufferDownloader (elemSize, numElems, (CUcontext)ctx, (CUstream)str) {}
141
161
142
162
bool DownloadSingleCudaBuffer (std::shared_ptr<CudaBuffer> buffer,
@@ -275,11 +295,11 @@ class PyNvDecoder {
275
295
PyNvDecoder (pathToFile, (CUcontext)ctx, (CUstream)str, ffmpeg_options){}
276
296
277
297
static Buffer *getElementaryVideo (DemuxFrame *demuxer,
278
- SeekContext & seek_ctx, bool needSEI);
298
+ SeekContext * seek_ctx, bool needSEI);
279
299
280
300
static Surface *getDecodedSurface (NvdecDecodeFrame *decoder,
281
301
DemuxFrame *demuxer,
282
- SeekContext & seek_ctx, bool needSEI);
302
+ SeekContext * seek_ctx, bool needSEI);
283
303
284
304
uint32_t Width () const ;
285
305
@@ -305,148 +325,15 @@ class PyNvDecoder {
305
325
306
326
Pixel_Format GetPixelFormat () const ;
307
327
308
- std::shared_ptr<Surface> DecodeSurfaceFromPacket (py::array_t <uint8_t > &packet,
309
- py::array_t <uint8_t > &sei);
310
-
311
- std::shared_ptr<Surface> DecodeSurfaceFromPacket (PacketData &enc_packet_data,
312
- py::array_t <uint8_t > &packet,
313
- py::array_t <uint8_t > &sei);
314
-
315
- std::shared_ptr<Surface> DecodeSurfaceFromPacket (py::array_t <uint8_t > &packet,
316
- py::array_t <uint8_t > &sei,
317
- PacketData &pkt_data);
318
-
319
- std::shared_ptr<Surface> DecodeSurfaceFromPacket (PacketData &enc_packet_data,
320
- py::array_t <uint8_t > &packet,
321
- py::array_t <uint8_t > &sei,
322
- PacketData &pkt_data);
323
-
324
- std::shared_ptr<Surface> DecodeSurfaceFromPacket (py::array_t <uint8_t > &packet);
325
-
326
- std::shared_ptr<Surface> DecodeSurfaceFromPacket (PacketData &enc_packet_data,
327
- py::array_t <uint8_t > &packet);
328
-
329
- std::shared_ptr<Surface> DecodeSurfaceFromPacket (py::array_t <uint8_t > &packet,
330
- PacketData &pkt_data);
331
-
332
- std::shared_ptr<Surface> DecodeSurfaceFromPacket (PacketData &enc_packet_data,
333
- py::array_t <uint8_t > &packet,
334
- PacketData &pkt_data);
335
-
336
- std::shared_ptr<Surface> DecodeSingleSurface (py::array_t <uint8_t > &sei);
337
-
338
- std::shared_ptr<Surface> DecodeSingleSurface (py::array_t <uint8_t > &sei,
339
- PacketData &pkt_data);
340
-
341
- std::shared_ptr<Surface> DecodeSingleSurface (py::array_t <uint8_t > &sei,
342
- SeekContext &ctx);
343
-
344
- std::shared_ptr<Surface> DecodeSingleSurface (py::array_t <uint8_t > &sei,
345
- SeekContext &ctx,
346
- PacketData &pkt_data);
347
-
348
- std::shared_ptr<Surface> DecodeSingleSurface ();
349
-
350
- std::shared_ptr<Surface> DecodeSingleSurface (PacketData &pkt_data);
351
-
352
- std::shared_ptr<Surface> DecodeSingleSurface (SeekContext &ctx);
353
-
354
- std::shared_ptr<Surface> DecodeSingleSurface (SeekContext &ctx,
355
- PacketData &pkt_data);
356
-
357
- bool DecodeSingleFrame (py::array_t <uint8_t > &frame,
358
- py::array_t <uint8_t > &sei);
359
-
360
- bool DecodeSingleFrame (py::array_t <uint8_t > &frame,
361
- py::array_t <uint8_t > &sei,
362
- PacketData &pkt_data);
363
-
364
- bool DecodeSingleFrame (py::array_t <uint8_t > &frame,
365
- py::array_t <uint8_t > &sei,
366
- SeekContext &ctx);
328
+ bool DecodeSurface (class DecodeContext &ctx);
367
329
368
- bool DecodeSingleFrame (py::array_t <uint8_t > &frame,
369
- py::array_t <uint8_t > &sei,
370
- SeekContext &ctx,
371
- PacketData &pkt_data);
330
+ bool DecodeFrame (class DecodeContext &ctx, py::array_t <uint8_t >& frame);
372
331
373
- bool DecodeSingleFrame (py::array_t <uint8_t > &frame);
374
-
375
- bool DecodeSingleFrame (py::array_t <uint8_t > &frame,
376
- PacketData &pkt_data);
377
-
378
- bool DecodeSingleFrame (py::array_t <uint8_t > &frame,
379
- SeekContext &ctx);
380
-
381
- bool DecodeSingleFrame (py::array_t <uint8_t > &frame,
382
- SeekContext &ctx,
383
- PacketData &pkt_data);
384
-
385
- bool DecodeFrameFromPacket (py::array_t <uint8_t > &frame,
386
- py::array_t <uint8_t > &packet,
387
- py::array_t <uint8_t > &sei);
388
-
389
- bool DecodeFrameFromPacket (py::array_t <uint8_t > &frame,
390
- PacketData &enc_packet_data,
391
- py::array_t <uint8_t > &packet,
392
- py::array_t <uint8_t > &sei);
393
-
394
- bool DecodeFrameFromPacket (py::array_t <uint8_t > &frame,
395
- py::array_t <uint8_t > &packet,
396
- py::array_t <uint8_t > &sei,
397
- PacketData &pkt_data);
398
-
399
- bool DecodeFrameFromPacket (py::array_t <uint8_t > &frame,
400
- PacketData &enc_packet_data,
401
- py::array_t <uint8_t > &packet,
402
- py::array_t <uint8_t > &sei,
403
- PacketData &pkt_data);
404
-
405
- bool DecodeFrameFromPacket (py::array_t <uint8_t > &frame,
406
- py::array_t <uint8_t > &packet);
407
-
408
- bool DecodeFrameFromPacket (py::array_t <uint8_t > &frame,
409
- PacketData &enc_packet_data,
410
- py::array_t <uint8_t > &packet);
411
-
412
- bool DecodeFrameFromPacket (py::array_t <uint8_t > &frame,
413
- py::array_t <uint8_t > &packet,
414
- PacketData &pkt_data);
415
-
416
- bool DecodeFrameFromPacket (py::array_t <uint8_t > &frame,
417
- PacketData &enc_packet_data,
418
- py::array_t <uint8_t > &packet,
419
- PacketData &pkt_data);
420
-
421
- bool FlushSingleFrame (py::array_t <uint8_t > &frame);
422
-
423
- bool FlushSingleFrame (py::array_t <uint8_t > &frame, PacketData &pkt_data);
424
-
425
- std::shared_ptr<Surface> FlushSingleSurface ();
426
-
427
- std::shared_ptr<Surface> FlushSingleSurface (PacketData &pkt_data);
428
-
429
- private:
430
- bool DecodeSurface (struct DecodeContext &ctx);
431
-
432
- Surface *getDecodedSurfaceFromPacket (py::array_t <uint8_t > *pPacket,
433
- PacketData *p_packet_data = nullptr ,
332
+ Surface *getDecodedSurfaceFromPacket (const py::array_t <uint8_t > *pPacket,
333
+ const PacketData *p_packet_data = nullptr ,
434
334
bool no_eos = false );
435
- };
436
335
437
- struct EncodeContext {
438
- std::shared_ptr<Surface> rawSurface;
439
- py::array_t <uint8_t > *pPacket;
440
- const py::array_t <uint8_t > *pMessageSEI;
441
- bool sync;
442
- bool append;
443
-
444
- EncodeContext (std::shared_ptr<Surface> spRawSurface,
445
- py::array_t <uint8_t > *packet,
446
- const py::array_t <uint8_t > *messageSEI, bool is_sync,
447
- bool is_append)
448
- : rawSurface(spRawSurface), pPacket(packet), pMessageSEI(messageSEI),
449
- sync (is_sync), append(is_append) {}
336
+ void DownloaderLazyInit ();
450
337
};
451
338
452
339
class PyNvEncoder {
@@ -523,5 +410,5 @@ class PyNvEncoder {
523
410
bool FlushSinglePacket (py::array_t <uint8_t > &packet);
524
411
525
412
private:
526
- bool EncodeSingleSurface (EncodeContext &ctx);
413
+ bool EncodeSingleSurface (struct EncodeContext &ctx);
527
414
};
0 commit comments