diff mbox

[FFmpeg-devel,2/5] avutil/hwcontext_cuda: add CUstream in cuda hwctx

Message ID 20180508183640.13605-2-timo@rothenpieler.org
State Accepted
Commit c85568342741e0e1b48fc36c780342de8ad29be7
Headers show

Commit Message

Timo Rothenpieler May 8, 2018, 6:36 p.m. UTC
---
 configure                  | 6 ++++--
 doc/APIchanges             | 3 +++
 libavutil/hwcontext_cuda.c | 3 +++
 libavutil/hwcontext_cuda.h | 1 +
 libavutil/version.h        | 2 +-
 5 files changed, 12 insertions(+), 3 deletions(-)

Comments

James Almer May 8, 2018, 9 p.m. UTC | #1
On 5/8/2018 3:36 PM, Timo Rothenpieler wrote:
> ---
>  configure                  | 6 ++++--
>  doc/APIchanges             | 3 +++
>  libavutil/hwcontext_cuda.c | 3 +++
>  libavutil/hwcontext_cuda.h | 1 +
>  libavutil/version.h        | 2 +-
>  5 files changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/configure b/configure
> index 6626111ff2..9743de05d0 100755
> --- a/configure
> +++ b/configure
> @@ -5887,8 +5887,10 @@ check_type "va/va.h va/va_enc_vp9.h"  "VAEncPictureParameterBufferVP9"
>  check_type "vdpau/vdpau.h" "VdpPictureInfoHEVC"
>  
>  if ! disabled ffnvcodec; then
> -    check_pkg_config ffnvcodec "ffnvcodec >= 8.0.14.1" \
> -        "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" ""
> +    check_pkg_config ffnvcodec "ffnvcodec >= 8.1.24.2" \
> +          "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" "" || \
> +        { test_pkg_config ffnvcodec_tmp "ffnvcodec < 8.1" "" "" && check_pkg_config ffnvcodec "ffnvcodec >= 8.0.14.2" \
> +          "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" ""; }

ffnvcodec_tmp?

>  fi
>  
>  check_cpp_condition winrt windows.h "!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)"
> diff --git a/doc/APIchanges b/doc/APIchanges
> index ede5b186ae..bbefc8356e 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -15,6 +15,9 @@ libavutil:     2017-10-21
>  
>  API changes, most recent first:
>  
> +2018-05-xx - xxxxxxxxxx - lavu 56.18.101 - hwcontext_cuda.h
> +  Add AVCUDADeviceContext.stream.
> +
>  2018-04-xx - xxxxxxxxxx - lavu 56.18.100 - pixdesc.h
>    Add AV_PIX_FMT_FLAG_ALPHA to AV_PIX_FMT_PAL8.
>  
> diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c
> index 37827a770c..f3e81680e9 100644
> --- a/libavutil/hwcontext_cuda.c
> +++ b/libavutil/hwcontext_cuda.c
> @@ -386,6 +386,9 @@ static int cuda_device_create(AVHWDeviceContext *ctx, const char *device,
>          goto error;
>      }
>  
> +    // Setting stream to NULL will make functions automatically use the default CUstream
> +    hwctx->stream = NULL;
> +
>      cu->cuCtxPopCurrent(&dummy);
>  
>      hwctx->internal->is_allocated = 1;
> diff --git a/libavutil/hwcontext_cuda.h b/libavutil/hwcontext_cuda.h
> index 12dae8449e..81a0552cab 100644
> --- a/libavutil/hwcontext_cuda.h
> +++ b/libavutil/hwcontext_cuda.h
> @@ -41,6 +41,7 @@ typedef struct AVCUDADeviceContextInternal AVCUDADeviceContextInternal;
>   */
>  typedef struct AVCUDADeviceContext {
>      CUcontext cuda_ctx;
> +    CUstream stream;
>      AVCUDADeviceContextInternal *internal;
>  } AVCUDADeviceContext;
>  
> diff --git a/libavutil/version.h b/libavutil/version.h
> index 5185454d9b..186fe0794d 100644
> --- a/libavutil/version.h
> +++ b/libavutil/version.h
> @@ -80,7 +80,7 @@
>  
>  #define LIBAVUTIL_VERSION_MAJOR  56
>  #define LIBAVUTIL_VERSION_MINOR  18
> -#define LIBAVUTIL_VERSION_MICRO 100
> +#define LIBAVUTIL_VERSION_MICRO 101
>  
>  #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
>                                                 LIBAVUTIL_VERSION_MINOR, \
>
Timo Rothenpieler May 9, 2018, 8:49 a.m. UTC | #2
On 08.05.2018 23:00, James Almer wrote:
> On 5/8/2018 3:36 PM, Timo Rothenpieler wrote:
>> ---
>>  configure                  | 6 ++++--
>>  doc/APIchanges             | 3 +++
>>  libavutil/hwcontext_cuda.c | 3 +++
>>  libavutil/hwcontext_cuda.h | 1 +
>>  libavutil/version.h        | 2 +-
>>  5 files changed, 12 insertions(+), 3 deletions(-)
>>
>> diff --git a/configure b/configure
>> index 6626111ff2..9743de05d0 100755
>> --- a/configure
>> +++ b/configure
>> @@ -5887,8 +5887,10 @@ check_type "va/va.h va/va_enc_vp9.h"  "VAEncPictureParameterBufferVP9"
>>  check_type "vdpau/vdpau.h" "VdpPictureInfoHEVC"
>>  
>>  if ! disabled ffnvcodec; then
>> -    check_pkg_config ffnvcodec "ffnvcodec >= 8.0.14.1" \
>> -        "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" ""
>> +    check_pkg_config ffnvcodec "ffnvcodec >= 8.1.24.2" \
>> +          "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" "" || \
>> +        { test_pkg_config ffnvcodec_tmp "ffnvcodec < 8.1" "" "" && check_pkg_config ffnvcodec "ffnvcodec >= 8.0.14.2" \
>> +          "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" ""; }
> 
> ffnvcodec_tmp?

I haven't found a more elegant way to do this.
Basically, the version requirement is

ffnvcodec >= 8.1.24.2 || (ffnvcodec < 8.1 && ffnvcodec >= 8.0.14.2)

As < 8.1 would also match 8.0.14.1, it must not enable ffnvcodec, which
is why i appended the _tmp.

pkg-config does not seem able to evaluate such complex version checks,
and there is no lower level function than test_pkg_config.
Timo Rothenpieler May 9, 2018, 6:03 p.m. UTC | #3
Am 09.05.2018 um 10:49 schrieb Timo Rothenpieler:
> On 08.05.2018 23:00, James Almer wrote:
>> On 5/8/2018 3:36 PM, Timo Rothenpieler wrote:
>>> ---
>>>   configure                  | 6 ++++--
>>>   doc/APIchanges             | 3 +++
>>>   libavutil/hwcontext_cuda.c | 3 +++
>>>   libavutil/hwcontext_cuda.h | 1 +
>>>   libavutil/version.h        | 2 +-
>>>   5 files changed, 12 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/configure b/configure
>>> index 6626111ff2..9743de05d0 100755
>>> --- a/configure
>>> +++ b/configure
>>> @@ -5887,8 +5887,10 @@ check_type "va/va.h va/va_enc_vp9.h"  "VAEncPictureParameterBufferVP9"
>>>   check_type "vdpau/vdpau.h" "VdpPictureInfoHEVC"
>>>   
>>>   if ! disabled ffnvcodec; then
>>> -    check_pkg_config ffnvcodec "ffnvcodec >= 8.0.14.1" \
>>> -        "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" ""
>>> +    check_pkg_config ffnvcodec "ffnvcodec >= 8.1.24.2" \
>>> +          "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" "" || \
>>> +        { test_pkg_config ffnvcodec_tmp "ffnvcodec < 8.1" "" "" && check_pkg_config ffnvcodec "ffnvcodec >= 8.0.14.2" \
>>> +          "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" ""; }
>>
>> ffnvcodec_tmp?
> 
> I haven't found a more elegant way to do this.
> Basically, the version requirement is
> 
> ffnvcodec >= 8.1.24.2 || (ffnvcodec < 8.1 && ffnvcodec >= 8.0.14.2)
> 
> As < 8.1 would also match 8.0.14.1, it must not enable ffnvcodec, which
> is why i appended the _tmp.
> 
> pkg-config does not seem able to evaluate such complex version checks,
> and there is no lower level function than test_pkg_config.

I'd like to push the series, and this is the only thing holding it up.
Did I miss a better way to do this, or is it good to go?
James Almer June 9, 2018, 1:25 a.m. UTC | #4
On 5/9/2018 5:49 AM, Timo Rothenpieler wrote:
> On 08.05.2018 23:00, James Almer wrote:
>> On 5/8/2018 3:36 PM, Timo Rothenpieler wrote:
>>> ---
>>>  configure                  | 6 ++++--
>>>  doc/APIchanges             | 3 +++
>>>  libavutil/hwcontext_cuda.c | 3 +++
>>>  libavutil/hwcontext_cuda.h | 1 +
>>>  libavutil/version.h        | 2 +-
>>>  5 files changed, 12 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/configure b/configure
>>> index 6626111ff2..9743de05d0 100755
>>> --- a/configure
>>> +++ b/configure
>>> @@ -5887,8 +5887,10 @@ check_type "va/va.h va/va_enc_vp9.h"  "VAEncPictureParameterBufferVP9"
>>>  check_type "vdpau/vdpau.h" "VdpPictureInfoHEVC"
>>>  
>>>  if ! disabled ffnvcodec; then
>>> -    check_pkg_config ffnvcodec "ffnvcodec >= 8.0.14.1" \
>>> -        "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" ""
>>> +    check_pkg_config ffnvcodec "ffnvcodec >= 8.1.24.2" \
>>> +          "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" "" || \
>>> +        { test_pkg_config ffnvcodec_tmp "ffnvcodec < 8.1" "" "" && check_pkg_config ffnvcodec "ffnvcodec >= 8.0.14.2" \
>>> +          "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" ""; }
>>
>> ffnvcodec_tmp?
> 
> I haven't found a more elegant way to do this.
> Basically, the version requirement is
> 
> ffnvcodec >= 8.1.24.2 || (ffnvcodec < 8.1 && ffnvcodec >= 8.0.14.2)
> 
> As < 8.1 would also match 8.0.14.1, it must not enable ffnvcodec, which
> is why i appended the _tmp.
> 
> pkg-config does not seem able to evaluate such complex version checks,
> and there is no lower level function than test_pkg_config.

Completely missed this reply, sorry about that.

The above check can be done with two calls to check_pkg_config(). You
can't do logical or as far as i know, but logical and is implied if you
pass two conditions.
So if what you want is any 8.1 version as long as its higher than
8.1.24.1, or as fallback any 8.0 version as long as it's higher than
8.0.14.1, you'd do

check_pkg_config ffnvcodec "ffnvcodec >= 8.1.24.2" \
"ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h \
ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" "" ||
check_pkg_config ffnvcodec "ffnvcodec >= 8.0.14.2 ffnvcodec < 8.1" \
"ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h \
ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" ""
Timo Rothenpieler June 9, 2018, 9:31 a.m. UTC | #5
Am 09.06.2018 um 03:25 schrieb James Almer:
> On 5/9/2018 5:49 AM, Timo Rothenpieler wrote:
>> On 08.05.2018 23:00, James Almer wrote:
>>> On 5/8/2018 3:36 PM, Timo Rothenpieler wrote:
>>>> ---
>>>>   configure                  | 6 ++++--
>>>>   doc/APIchanges             | 3 +++
>>>>   libavutil/hwcontext_cuda.c | 3 +++
>>>>   libavutil/hwcontext_cuda.h | 1 +
>>>>   libavutil/version.h        | 2 +-
>>>>   5 files changed, 12 insertions(+), 3 deletions(-)
>>>>
>>>> diff --git a/configure b/configure
>>>> index 6626111ff2..9743de05d0 100755
>>>> --- a/configure
>>>> +++ b/configure
>>>> @@ -5887,8 +5887,10 @@ check_type "va/va.h va/va_enc_vp9.h"  "VAEncPictureParameterBufferVP9"
>>>>   check_type "vdpau/vdpau.h" "VdpPictureInfoHEVC"
>>>>   
>>>>   if ! disabled ffnvcodec; then
>>>> -    check_pkg_config ffnvcodec "ffnvcodec >= 8.0.14.1" \
>>>> -        "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" ""
>>>> +    check_pkg_config ffnvcodec "ffnvcodec >= 8.1.24.2" \
>>>> +          "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" "" || \
>>>> +        { test_pkg_config ffnvcodec_tmp "ffnvcodec < 8.1" "" "" && check_pkg_config ffnvcodec "ffnvcodec >= 8.0.14.2" \
>>>> +          "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" ""; }
>>>
>>> ffnvcodec_tmp?
>>
>> I haven't found a more elegant way to do this.
>> Basically, the version requirement is
>>
>> ffnvcodec >= 8.1.24.2 || (ffnvcodec < 8.1 && ffnvcodec >= 8.0.14.2)
>>
>> As < 8.1 would also match 8.0.14.1, it must not enable ffnvcodec, which
>> is why i appended the _tmp.
>>
>> pkg-config does not seem able to evaluate such complex version checks,
>> and there is no lower level function than test_pkg_config.
> 
> Completely missed this reply, sorry about that.
> 
> The above check can be done with two calls to check_pkg_config(). You
> can't do logical or as far as i know, but logical and is implied if you
> pass two conditions.
> So if what you want is any 8.1 version as long as its higher than
> 8.1.24.1, or as fallback any 8.0 version as long as it's higher than
> 8.0.14.1, you'd do
> 
> check_pkg_config ffnvcodec "ffnvcodec >= 8.1.24.2" \
> "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h \
> ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" "" ||
> check_pkg_config ffnvcodec "ffnvcodec >= 8.0.14.2 ffnvcodec < 8.1" \
> "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h \
> ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" ""

That does seem better, and saves one invocation of pkg-config.
Will apply it like that.
diff mbox

Patch

diff --git a/configure b/configure
index 6626111ff2..9743de05d0 100755
--- a/configure
+++ b/configure
@@ -5887,8 +5887,10 @@  check_type "va/va.h va/va_enc_vp9.h"  "VAEncPictureParameterBufferVP9"
 check_type "vdpau/vdpau.h" "VdpPictureInfoHEVC"
 
 if ! disabled ffnvcodec; then
-    check_pkg_config ffnvcodec "ffnvcodec >= 8.0.14.1" \
-        "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" ""
+    check_pkg_config ffnvcodec "ffnvcodec >= 8.1.24.2" \
+          "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" "" || \
+        { test_pkg_config ffnvcodec_tmp "ffnvcodec < 8.1" "" "" && check_pkg_config ffnvcodec "ffnvcodec >= 8.0.14.2" \
+          "ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h" ""; }
 fi
 
 check_cpp_condition winrt windows.h "!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)"
diff --git a/doc/APIchanges b/doc/APIchanges
index ede5b186ae..bbefc8356e 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@  libavutil:     2017-10-21
 
 API changes, most recent first:
 
+2018-05-xx - xxxxxxxxxx - lavu 56.18.101 - hwcontext_cuda.h
+  Add AVCUDADeviceContext.stream.
+
 2018-04-xx - xxxxxxxxxx - lavu 56.18.100 - pixdesc.h
   Add AV_PIX_FMT_FLAG_ALPHA to AV_PIX_FMT_PAL8.
 
diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c
index 37827a770c..f3e81680e9 100644
--- a/libavutil/hwcontext_cuda.c
+++ b/libavutil/hwcontext_cuda.c
@@ -386,6 +386,9 @@  static int cuda_device_create(AVHWDeviceContext *ctx, const char *device,
         goto error;
     }
 
+    // Setting stream to NULL will make functions automatically use the default CUstream
+    hwctx->stream = NULL;
+
     cu->cuCtxPopCurrent(&dummy);
 
     hwctx->internal->is_allocated = 1;
diff --git a/libavutil/hwcontext_cuda.h b/libavutil/hwcontext_cuda.h
index 12dae8449e..81a0552cab 100644
--- a/libavutil/hwcontext_cuda.h
+++ b/libavutil/hwcontext_cuda.h
@@ -41,6 +41,7 @@  typedef struct AVCUDADeviceContextInternal AVCUDADeviceContextInternal;
  */
 typedef struct AVCUDADeviceContext {
     CUcontext cuda_ctx;
+    CUstream stream;
     AVCUDADeviceContextInternal *internal;
 } AVCUDADeviceContext;
 
diff --git a/libavutil/version.h b/libavutil/version.h
index 5185454d9b..186fe0794d 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -80,7 +80,7 @@ 
 
 #define LIBAVUTIL_VERSION_MAJOR  56
 #define LIBAVUTIL_VERSION_MINOR  18
-#define LIBAVUTIL_VERSION_MICRO 100
+#define LIBAVUTIL_VERSION_MICRO 101
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
                                                LIBAVUTIL_VERSION_MINOR, \