2 * Copyright 1993-2008 NVIDIA Corporation. All rights reserved.
6 * This source code is subject to NVIDIA ownership rights under U.S. and
7 * international Copyright laws. Users and possessors of this source code
8 * are hereby granted a nonexclusive, royalty-free license to use this code
9 * in individual and commercial software.
11 * NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE
12 * CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR
13 * IMPLIED WARRANTY OF ANY KIND. NVIDIA DISCLAIMS ALL WARRANTIES WITH
14 * REGARD TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF
15 * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.
16 * IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
17 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
18 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
19 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
20 * OR PERFORMANCE OF THIS SOURCE CODE.
22 * U.S. Government End Users. This source code is a "commercial item" as
23 * that term is defined at 48 C.F.R. 2.101 (OCT 1995), consisting of
24 * "commercial computer software" and "commercial computer software
25 * documentation" as such terms are used in 48 C.F.R. 12.212 (SEPT 1995)
26 * and is provided to the U.S. Government only as a commercial end item.
27 * Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through
28 * 227.7202-4 (JUNE 1995), all U.S. Government End Users acquire the
29 * source code with only those rights set forth herein.
31 * Any use of this source code in individual and commercial software must
32 * include, in the user documentation and internal comments to the code,
33 * the above Disclaimer and U.S. Government End Users Notice.
36 #if !defined(__CUDA_VIDEO_H__)
37 #define __CUDA_VIDEO_H__
39 #ifndef __cuda_cuda_h__
41 #endif // __cuda_cuda_h__
43 #if defined(__x86_64) || defined(AMD64) || defined(_M_AMD64)
44 #if (CUDA_VERSION >= 3020) && (!defined(CUDA_FORCE_API_VERSION) || (CUDA_FORCE_API_VERSION >= 3020))
45 #define __CUVID_DEVPTR64
49 #if defined(__cplusplus)
51 #endif /* __cplusplus */
53 typedef void *CUvideodecoder;
54 typedef struct _CUcontextlock_st *CUvideoctxlock;
56 typedef enum cudaVideoCodec_enum {
57 cudaVideoCodec_MPEG1=0,
63 cudaVideoCodec_H264_SVC,
64 cudaVideoCodec_H264_MVC,
66 cudaVideoCodec_NumCodecs,
68 cudaVideoCodec_YUV420 = (('I'<<24)|('Y'<<16)|('U'<<8)|('V')), // Y,U,V (4:2:0)
69 cudaVideoCodec_YV12 = (('Y'<<24)|('V'<<16)|('1'<<8)|('2')), // Y,V,U (4:2:0)
70 cudaVideoCodec_NV12 = (('N'<<24)|('V'<<16)|('1'<<8)|('2')), // Y,UV (4:2:0)
71 cudaVideoCodec_YUYV = (('Y'<<24)|('U'<<16)|('Y'<<8)|('V')), // YUYV/YUY2 (4:2:2)
72 cudaVideoCodec_UYVY = (('U'<<24)|('Y'<<16)|('V'<<8)|('Y')) // UYVY (4:2:2)
75 typedef enum cudaVideoSurfaceFormat_enum {
76 cudaVideoSurfaceFormat_NV12=0 // NV12 (currently the only supported output format)
77 } cudaVideoSurfaceFormat;
79 typedef enum cudaVideoDeinterlaceMode_enum {
80 cudaVideoDeinterlaceMode_Weave=0, // Weave both fields (no deinterlacing)
81 cudaVideoDeinterlaceMode_Bob, // Drop one field
82 cudaVideoDeinterlaceMode_Adaptive // Adaptive deinterlacing
83 } cudaVideoDeinterlaceMode;
85 typedef enum cudaVideoChromaFormat_enum {
86 cudaVideoChromaFormat_Monochrome=0,
87 cudaVideoChromaFormat_420,
88 cudaVideoChromaFormat_422,
89 cudaVideoChromaFormat_444
90 } cudaVideoChromaFormat;
92 typedef enum cudaVideoCreateFlags_enum {
93 cudaVideoCreate_Default = 0x00, // Default operation mode: use dedicated video engines
94 cudaVideoCreate_PreferCUDA = 0x01, // Use a CUDA-based decoder if faster than dedicated engines (requires a valid vidLock object for multi-threading)
95 cudaVideoCreate_PreferDXVA = 0x02, // Go through DXVA internally if possible (requires D3D9 interop)
96 cudaVideoCreate_PreferCUVID = 0x04 // Use dedicated video engines directly
97 } cudaVideoCreateFlags;
100 typedef struct _CUVIDDECODECREATEINFO
103 unsigned long ulWidth; // Coded Sequence Width
104 unsigned long ulHeight; // Coded Sequence Height
105 unsigned long ulNumDecodeSurfaces; // Maximum number of internal decode surfaces
106 cudaVideoCodec CodecType; // cudaVideoCodec_XXX
107 cudaVideoChromaFormat ChromaFormat; // cudaVideoChromaFormat_XXX (only 4:2:0 is currently supported)
108 unsigned long ulCreationFlags; // Decoder creation flags (cudaVideoCreateFlags_XXX)
109 unsigned long Reserved1[5]; // Reserved for future use - set to zero
110 struct { // area of the frame that should be displayed
117 cudaVideoSurfaceFormat OutputFormat; // cudaVideoSurfaceFormat_XXX
118 cudaVideoDeinterlaceMode DeinterlaceMode; // cudaVideoDeinterlaceMode_XXX
119 unsigned long ulTargetWidth; // Post-processed Output Width
120 unsigned long ulTargetHeight; // Post-processed Output Height
121 unsigned long ulNumOutputSurfaces; // Maximum number of output surfaces simultaneously mapped
122 CUvideoctxlock vidLock; // If non-NULL, context lock used for synchronizing ownership of the cuda context
123 struct { // target rectangle in the output frame (for aspect ratio conversion)
128 } target_rect; // if a null rectangle is specified, {0,0,ulTargetWidth,ulTargetHeight} will be used
129 unsigned long Reserved2[5]; // Reserved for future use - set to zero
130 } CUVIDDECODECREATEINFO;
133 ////////////////////////////////////////////////////////////////////////////////////////////////
135 // H.264 Picture Parameters
138 typedef struct _CUVIDH264DPBENTRY
140 int PicIdx; // picture index of reference frame
141 int FrameIdx; // frame_num(short-term) or LongTermFrameIdx(long-term)
142 int is_long_term; // 0=short term reference, 1=long term reference
143 int not_existing; // non-existing reference frame (corresponding PicIdx should be set to -1)
144 int used_for_reference; // 0=unused, 1=top_field, 2=bottom_field, 3=both_fields
145 int FieldOrderCnt[2]; // field order count of top and bottom fields
148 typedef struct _CUVIDH264MVCEXT
150 int num_views_minus1;
152 unsigned char inter_view_flag;
153 unsigned char num_inter_view_refs_l0;
154 unsigned char num_inter_view_refs_l1;
155 unsigned char MVCReserved8Bits;
156 int InterViewRefsL0[16];
157 int InterViewRefsL1[16];
160 typedef struct _CUVIDH264SVCEXT
162 unsigned char profile_idc;
163 unsigned char level_idc;
165 unsigned char DQIdMax;
166 unsigned char disable_inter_layer_deblocking_filter_idc;
167 unsigned char ref_layer_chroma_phase_y_plus1;
168 signed char inter_layer_slice_alpha_c0_offset_div2;
169 signed char inter_layer_slice_beta_offset_div2;
171 unsigned short DPBEntryValidFlag;
172 unsigned char inter_layer_deblocking_filter_control_present_flag;
173 unsigned char extended_spatial_scalability_idc;
174 unsigned char adaptive_tcoeff_level_prediction_flag;
175 unsigned char slice_header_restriction_flag;
176 unsigned char chroma_phase_x_plus1_flag;
177 unsigned char chroma_phase_y_plus1;
179 unsigned char tcoeff_level_prediction_flag;
180 unsigned char constrained_intra_resampling_flag;
181 unsigned char ref_layer_chroma_phase_x_plus1_flag;
182 unsigned char store_ref_base_pic_flag;
183 unsigned char Reserved8BitsA;
184 unsigned char Reserved8BitsB;
185 // For the 4 scaled_ref_layer_XX fields below,
186 // if (extended_spatial_scalability_idc == 1), SPS field, G.7.3.2.1.4, add prefix "seq_"
187 // if (extended_spatial_scalability_idc == 2), SLH field, G.7.3.3.4,
188 short scaled_ref_layer_left_offset;
189 short scaled_ref_layer_top_offset;
190 short scaled_ref_layer_right_offset;
191 short scaled_ref_layer_bottom_offset;
192 unsigned short Reserved16Bits;
193 struct _CUVIDPICPARAMS *pNextLayer; // Points to the picparams for the next layer to be decoded. Linked list ends at the target layer.
194 int bRefBaseLayer; // whether to store ref base pic
197 typedef struct _CUVIDH264PICPARAMS
200 int log2_max_frame_num_minus4;
201 int pic_order_cnt_type;
202 int log2_max_pic_order_cnt_lsb_minus4;
203 int delta_pic_order_always_zero_flag;
204 int frame_mbs_only_flag;
205 int direct_8x8_inference_flag;
206 int num_ref_frames; // NOTE: shall meet level 4.1 restrictions
207 unsigned char residual_colour_transform_flag;
208 unsigned char bit_depth_luma_minus8; // Must be 0 (only 8-bit supported)
209 unsigned char bit_depth_chroma_minus8; // Must be 0 (only 8-bit supported)
210 unsigned char qpprime_y_zero_transform_bypass_flag;
212 int entropy_coding_mode_flag;
213 int pic_order_present_flag;
214 int num_ref_idx_l0_active_minus1;
215 int num_ref_idx_l1_active_minus1;
216 int weighted_pred_flag;
217 int weighted_bipred_idc;
218 int pic_init_qp_minus26;
219 int deblocking_filter_control_present_flag;
220 int redundant_pic_cnt_present_flag;
221 int transform_8x8_mode_flag;
223 int constrained_intra_pred_flag;
224 int chroma_qp_index_offset;
225 int second_chroma_qp_index_offset;
228 int CurrFieldOrderCnt[2];
230 CUVIDH264DPBENTRY dpb[16]; // List of reference frames within the DPB
231 // Quantization Matrices (raster-order)
232 unsigned char WeightScale4x4[6][16];
233 unsigned char WeightScale8x8[2][64];
235 unsigned char fmo_aso_enable;
236 unsigned char num_slice_groups_minus1;
237 unsigned char slice_group_map_type;
238 signed char pic_init_qs_minus26;
239 unsigned int slice_group_change_rate_minus1;
242 unsigned long long slice_group_map_addr;
243 const unsigned char *pMb2SliceGroupMap;
245 unsigned int Reserved[12];
249 CUVIDH264MVCEXT mvcext;
250 CUVIDH264SVCEXT svcext;
252 } CUVIDH264PICPARAMS;
255 ////////////////////////////////////////////////////////////////////////////////////////////////
257 // MPEG-2 Picture Parameters
260 typedef struct _CUVIDMPEG2PICPARAMS
262 int ForwardRefIdx; // Picture index of forward reference (P/B-frames)
263 int BackwardRefIdx; // Picture index of backward reference (B-frames)
264 int picture_coding_type;
265 int full_pel_forward_vector;
266 int full_pel_backward_vector;
268 int intra_dc_precision;
269 int frame_pred_frame_dct;
270 int concealment_motion_vectors;
272 int intra_vlc_format;
275 // Quantization matrices (raster order)
276 unsigned char QuantMatrixIntra[64];
277 unsigned char QuantMatrixInter[64];
278 } CUVIDMPEG2PICPARAMS;
280 ////////////////////////////////////////////////////////////////////////////////////////////////
282 // MPEG-4 Picture Parameters
285 // MPEG-4 has VOP types instead of Picture types
291 typedef struct _CUVIDMPEG4PICPARAMS
293 int ForwardRefIdx; // Picture index of forward reference (P/B-frames)
294 int BackwardRefIdx; // Picture index of backward reference (B-frames)
296 int video_object_layer_width;
297 int video_object_layer_height;
298 int vop_time_increment_bitcount;
300 int resync_marker_disable;
303 int short_video_header;
308 int vop_rounding_type;
309 int alternate_vertical_scan_flag;
311 int vop_fcode_forward;
312 int vop_fcode_backward;
315 // Quantization matrices (raster order)
316 unsigned char QuantMatrixIntra[64];
317 unsigned char QuantMatrixInter[64];
319 } CUVIDMPEG4PICPARAMS;
321 ////////////////////////////////////////////////////////////////////////////////////////////////
323 // VC1 Picture Parameters
326 typedef struct _CUVIDVC1PICPARAMS
328 int ForwardRefIdx; // Picture index of forward reference (P/B-frames)
329 int BackwardRefIdx; // Picture index of backward reference (B-frames)
330 int FrameWidth; // Actual frame width
331 int FrameHeight; // Actual frame height
333 int intra_pic_flag; // Set to 1 for I,BI frames
334 int ref_pic_flag; // Set to 1 for I,P frames
335 int progressive_fcm; // Progressive frame
361 int range_mapuv_flag;
363 int rangeredfrm; // range reduction state
366 ////////////////////////////////////////////////////////////////////////////////////////////////
368 // JPEG Picture Parameters
371 typedef struct _CUVIDJPEGPICPARAMS
374 } CUVIDJPEGPICPARAMS;
377 ////////////////////////////////////////////////////////////////////////////////////////////////
379 // HEVC Picture Parameters
382 typedef struct _CUVIDHEVCPICPARAMS
385 int pic_width_in_luma_samples;
386 int pic_height_in_luma_samples;
387 unsigned char log2_min_luma_coding_block_size_minus3;
388 unsigned char log2_diff_max_min_luma_coding_block_size;
389 unsigned char log2_min_transform_block_size_minus2;
390 unsigned char log2_diff_max_min_transform_block_size;
391 unsigned char pcm_enabled_flag;
392 unsigned char log2_min_pcm_luma_coding_block_size_minus3;
393 unsigned char log2_diff_max_min_pcm_luma_coding_block_size;
394 unsigned char pcm_sample_bit_depth_luma_minus1;
396 unsigned char pcm_sample_bit_depth_chroma_minus1;
397 unsigned char pcm_loop_filter_disabled_flag;
398 unsigned char strong_intra_smoothing_enabled_flag;
399 unsigned char max_transform_hierarchy_depth_intra;
400 unsigned char max_transform_hierarchy_depth_inter;
401 unsigned char amp_enabled_flag;
402 unsigned char separate_colour_plane_flag;
403 unsigned char log2_max_pic_order_cnt_lsb_minus4;
405 unsigned char num_short_term_ref_pic_sets;
406 unsigned char long_term_ref_pics_present_flag;
407 unsigned char num_long_term_ref_pics_sps;
408 unsigned char sps_temporal_mvp_enabled_flag;
409 unsigned char sample_adaptive_offset_enabled_flag;
410 unsigned char scaling_list_enable_flag;
411 unsigned char IrapPicFlag;
412 unsigned char IdrPicFlag;
413 unsigned char reserved1[16];
416 unsigned char dependent_slice_segments_enabled_flag;
417 unsigned char slice_segment_header_extension_present_flag;
418 unsigned char sign_data_hiding_enabled_flag;
419 unsigned char cu_qp_delta_enabled_flag;
420 unsigned char diff_cu_qp_delta_depth;
421 signed char init_qp_minus26;
422 signed char pps_cb_qp_offset;
423 signed char pps_cr_qp_offset;
425 unsigned char constrained_intra_pred_flag;
426 unsigned char weighted_pred_flag;
427 unsigned char weighted_bipred_flag;
428 unsigned char transform_skip_enabled_flag;
429 unsigned char transquant_bypass_enabled_flag;
430 unsigned char entropy_coding_sync_enabled_flag;
431 unsigned char log2_parallel_merge_level_minus2;
432 unsigned char num_extra_slice_header_bits;
434 unsigned char loop_filter_across_tiles_enabled_flag;
435 unsigned char loop_filter_across_slices_enabled_flag;
436 unsigned char output_flag_present_flag;
437 unsigned char num_ref_idx_l0_default_active_minus1;
438 unsigned char num_ref_idx_l1_default_active_minus1;
439 unsigned char lists_modification_present_flag;
440 unsigned char cabac_init_present_flag;
441 unsigned char pps_slice_chroma_qp_offsets_present_flag;
443 unsigned char deblocking_filter_override_enabled_flag;
444 unsigned char pps_deblocking_filter_disabled_flag;
445 signed char pps_beta_offset_div2;
446 signed char pps_tc_offset_div2;
447 unsigned char tiles_enabled_flag;
448 unsigned char uniform_spacing_flag;
449 unsigned char num_tile_columns_minus1;
450 unsigned char num_tile_rows_minus1;
452 unsigned short column_width_minus1[21];
453 unsigned short row_height_minus1[19];
454 unsigned int reserved3[16];
457 int NumBitsForShortTermRPSInSlice;
458 int NumDeltaPocsOfRefRpsIdx;
460 int NumPocStCurrBefore;
461 int NumPocStCurrAfter;
463 int CurrPicOrderCntVal;
464 int RefPicIdx[16]; // [refpic] Indices of valid reference pictures (-1 if unused for reference)
465 int PicOrderCntVal[16]; // [refpic]
466 unsigned char IsLongTerm[16]; // [refpic] 0=not a long-term reference, 1=long-term reference
467 unsigned char RefPicSetStCurrBefore[8]; // [0..NumPocStCurrBefore-1] -> refpic (0..15)
468 unsigned char RefPicSetStCurrAfter[8]; // [0..NumPocStCurrAfter-1] -> refpic (0..15)
469 unsigned char RefPicSetLtCurr[8]; // [0..NumPocLtCurr-1] -> refpic (0..15)
470 unsigned int reserved4[16];
472 // scaling lists (diag order)
473 unsigned char ScalingList4x4[6][16]; // [matrixId][i]
474 unsigned char ScalingList8x8[6][64]; // [matrixId][i]
475 unsigned char ScalingList16x16[6][64]; // [matrixId][i]
476 unsigned char ScalingList32x32[2][64]; // [matrixId][i]
477 unsigned char ScalingListDCCoeff16x16[6]; // [matrixId]
478 unsigned char ScalingListDCCoeff32x32[2]; // [matrixId]
479 } CUVIDHEVCPICPARAMS;
482 ////////////////////////////////////////////////////////////////////////////////////////////////
484 // Picture Parameters for Decoding
487 typedef struct _CUVIDPICPARAMS
489 int PicWidthInMbs; // Coded Frame Size
490 int FrameHeightInMbs; // Coded Frame Height
491 int CurrPicIdx; // Output index of the current picture
492 int field_pic_flag; // 0=frame picture, 1=field picture
493 int bottom_field_flag; // 0=top field, 1=bottom field (ignored if field_pic_flag=0)
494 int second_field; // Second field of a complementary field pair
496 unsigned int nBitstreamDataLen; // Number of bytes in bitstream data buffer
497 const unsigned char *pBitstreamData; // Ptr to bitstream data for this picture (slice-layer)
498 unsigned int nNumSlices; // Number of slices in this picture
499 const unsigned int *pSliceDataOffsets; // nNumSlices entries, contains offset of each slice within the bitstream data buffer
500 int ref_pic_flag; // This picture is a reference picture
501 int intra_pic_flag; // This picture is entirely intra coded
502 unsigned int Reserved[30]; // Reserved for future use
503 // Codec-specific data
505 CUVIDMPEG2PICPARAMS mpeg2; // Also used for MPEG-1
506 CUVIDH264PICPARAMS h264;
507 CUVIDVC1PICPARAMS vc1;
508 CUVIDMPEG4PICPARAMS mpeg4;
509 CUVIDJPEGPICPARAMS jpeg;
510 CUVIDHEVCPICPARAMS hevc;
511 unsigned int CodecReserved[1024];
516 ////////////////////////////////////////////////////////////////////////////////////////////////
521 typedef struct _CUVIDPROCPARAMS
523 int progressive_frame; // Input is progressive (deinterlace_mode will be ignored)
524 int second_field; // Output the second field (ignored if deinterlace mode is Weave)
525 int top_field_first; // Input frame is top field first (1st field is top, 2nd field is bottom)
526 int unpaired_field; // Input only contains one field (2nd field is invalid)
527 // The fields below are used for raw YUV input
528 unsigned int reserved_flags; // Reserved for future use (set to zero)
529 unsigned int reserved_zero; // Reserved (set to zero)
530 unsigned long long raw_input_dptr; // Input CUdeviceptr for raw YUV extensions
531 unsigned int raw_input_pitch; // pitch in bytes of raw YUV input (should be aligned appropriately)
532 unsigned int raw_input_format; // Reserved for future use (set to zero)
533 unsigned long long raw_output_dptr; // Reserved for future use (set to zero)
534 unsigned int raw_output_pitch; // Reserved for future use (set to zero)
535 unsigned int Reserved[48];
539 ////////////////////////////////////////////////////////////////////////////////////////////////
541 // In order to maximize decode latencies, there should be always at least 2 pictures in the decode
542 // queue at any time, in order to make sure that all decode engines are always busy.
544 // Overall data flow:
545 // - cuvidCreateDecoder(...)
547 // - cuvidDecodePicture(N)
548 // - cuvidMapVideoFrame(N-4)
549 // - do some processing in cuda
550 // - cuvidUnmapVideoFrame(N-4)
551 // - cuvidDecodePicture(N+1)
552 // - cuvidMapVideoFrame(N-3)
554 // - cuvidDestroyDecoder(...)
557 // - In the current version, the cuda context MUST be created from a D3D device, using cuD3D9CtxCreate function.
558 // For multi-threaded operation, the D3D device must also be created with the D3DCREATE_MULTITHREADED flag.
559 // - There is a limit to how many pictures can be mapped simultaneously (ulNumOutputSurfaces)
560 // - cuVidDecodePicture may block the calling thread if there are too many pictures pending
561 // in the decode queue
563 ////////////////////////////////////////////////////////////////////////////////////////////////
565 // Create/Destroy the decoder object
566 extern CUresult CUDAAPI cuvidCreateDecoder(CUvideodecoder *phDecoder, CUVIDDECODECREATEINFO *pdci);
567 extern CUresult CUDAAPI cuvidDestroyDecoder(CUvideodecoder hDecoder);
569 // Decode a single picture (field or frame)
570 extern CUresult CUDAAPI cuvidDecodePicture(CUvideodecoder hDecoder, CUVIDPICPARAMS *pPicParams);
572 #if !defined(__CUVID_DEVPTR64) || defined(__CUVID_INTERNAL)
573 // Post-process and map a video frame for use in cuda
574 extern CUresult CUDAAPI cuvidMapVideoFrame(CUvideodecoder hDecoder, int nPicIdx,
575 unsigned int *pDevPtr, unsigned int *pPitch,
576 CUVIDPROCPARAMS *pVPP);
577 // Unmap a previously mapped video frame
578 extern CUresult CUDAAPI cuvidUnmapVideoFrame(CUvideodecoder hDecoder, unsigned int DevPtr);
581 #if defined(__x86_64) || defined(AMD64) || defined(_M_AMD64)
582 extern CUresult CUDAAPI cuvidMapVideoFrame64(CUvideodecoder hDecoder, int nPicIdx, unsigned long long *pDevPtr,
583 unsigned int *pPitch, CUVIDPROCPARAMS *pVPP);
584 extern CUresult CUDAAPI cuvidUnmapVideoFrame64(CUvideodecoder hDecoder, unsigned long long DevPtr);
585 #if defined(__CUVID_DEVPTR64) && !defined(__CUVID_INTERNAL)
586 #define cuvidMapVideoFrame cuvidMapVideoFrame64
587 #define cuvidUnmapVideoFrame cuvidUnmapVideoFrame64
591 // Get the pointer to the d3d9 surface that is the decode RT
592 extern CUresult CUDAAPI cuvidGetVideoFrameSurface(CUvideodecoder hDecoder, int nPicIdx, void **pSrcSurface);
594 ////////////////////////////////////////////////////////////////////////////////////////////////
596 // Context-locking: to facilitate multi-threaded implementations, the following 4 functions
597 // provide a simple mutex-style host synchronization. If a non-NULL context is specified
598 // in CUVIDDECODECREATEINFO, the codec library will acquire the mutex associated with the given
599 // context before making any cuda calls.
600 // A multi-threaded application could create a lock associated with a context handle so that
601 // multiple threads can safely share the same cuda context:
602 // - use cuCtxPopCurrent immediately after context creation in order to create a 'floating' context
603 // that can be passed to cuvidCtxLockCreate.
604 // - When using a floating context, all cuda calls should only be made within a cuvidCtxLock/cuvidCtxUnlock section.
606 // NOTE: This is a safer alternative to cuCtxPushCurrent and cuCtxPopCurrent, and is not related to video
607 // decoder in any way (implemented as a critical section associated with cuCtx{Push|Pop}Current calls).
609 extern CUresult CUDAAPI cuvidCtxLockCreate(CUvideoctxlock *pLock, CUcontext ctx);
610 extern CUresult CUDAAPI cuvidCtxLockDestroy(CUvideoctxlock lck);
611 extern CUresult CUDAAPI cuvidCtxLock(CUvideoctxlock lck, unsigned int reserved_flags);
612 extern CUresult CUDAAPI cuvidCtxUnlock(CUvideoctxlock lck, unsigned int reserved_flags);
614 ////////////////////////////////////////////////////////////////////////////////////////////////
616 #if defined(__cplusplus)
619 // Auto-lock helper for C++ applications
623 CUvideoctxlock m_ctx;
625 CCtxAutoLock(CUvideoctxlock ctx):m_ctx(ctx) { cuvidCtxLock(m_ctx,0); }
626 ~CCtxAutoLock() { cuvidCtxUnlock(m_ctx,0); }
629 #endif /* __cplusplus */
631 #endif // __CUDA_VIDEO_H__