Re: [FFmpeg-devel] [PATCH] avformat/opensrt: add Haivision Open SRT protocol

2018-02-12 Thread nablet developer



If you or any other developer is against someone receiving git write access
you only need to object to the patch adding him to the MAINTAINERS file.

Thats one of the reasons why there is a MAINTAINERs file.

It would be ideal IMO if for each part of teh codebase at least one person
with write access cares/"Maintains" it. Is there someone who already has
write access who wants to take care of opensrt.c ?
(it seemed there is little interrest from teh lack of replies in the thread so
far)

Also i belive there already is a developer from nablet who is in the
MAINTAINERs file and has write access.

thanks



thanks for your comments. I am going to send new patch later this week, 
as there are comments

from the Nicolas George to be addressed anyway.
it was your suggestion to edit MAINTAINERs file, so I followed it, but 
now I am disappointed.

so what should I do now?
I see the following options:
1) do not edit MAINTAINERs file (leave it as it was before)
2) add opensrt.c entry for existing maintainer from Nablet (Ivan Uskov 
)
3) change opensrt.c entry to another maintainer from Nablet (Sven 
Dueking )

which one do you prefer/suggest?
if I change maintainer entry, does it imply what patch should be sent 
from maintainer's email and

commit author should also match maintainer's email?
P.S. added file (opensrt.c) doesn't have a Nablet or Haivision copyright 
- it has regular ffmpeg copyright
used across the ffmpeg codebase, so it's not different in that aspect 
from other files, like tcp.c or udp.c.

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avformat/opensrt: add Haivision Open SRT protocol

2018-02-08 Thread Nablet Developer


On 1/31/2018 4:11 AM, Nablet Developer wrote:

protocol requires libsrt (https://github.com/Haivision/srt) to be
installed

Signed-off-by: Nablet Developer <s...@nablet.com>
---

ping
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avformat/opensrt: add Haivision Open SRT protocol

2018-01-30 Thread Nablet Developer
protocol requires libsrt (https://github.com/Haivision/srt) to be
installed

Signed-off-by: Nablet Developer <s...@nablet.com>
---
 MAINTAINERS |   1 +
 configure   |   9 +
 doc/protocols.texi  | 116 +
 libavformat/Makefile|   1 +
 libavformat/opensrt.c   | 621 
 libavformat/protocols.c |   1 +
 6 files changed, 749 insertions(+)
 create mode 100644 libavformat/opensrt.c

diff --git a/MAINTAINERS b/MAINTAINERS
index ba7a728..0317f24 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -498,6 +498,7 @@ Protocols:
   http.cRonald S. Bultje
   libssh.c  Lukasz Marek
   mms*.cRonald S. Bultje
+  opensrt.c     Nablet Developer
   udp.c Luca Abeni
   icecast.c Marvin Scholz
 
diff --git a/configure b/configure
index fcfa7aa..57705ee 100755
--- a/configure
+++ b/configure
@@ -294,6 +294,7 @@ External library support:
   --enable-opengl  enable OpenGL rendering [no]
   --enable-openssl enable openssl, needed for https support
if gnutls or libtls is not used [no]
+  --enable-opensrt enable Haivision Open SRT protocol [no]
   --disable-sndio  disable sndio support [autodetect]
   --disable-schannel   disable SChannel SSP, needed for TLS support on
Windows if openssl and gnutls are not used 
[autodetect]
@@ -1641,6 +1642,7 @@ EXTERNAL_LIBRARY_LIST="
 mediacodec
 openal
 opengl
+opensrt
 "
 
 HWACCEL_AUTODETECT_LIBRARY_LIST="
@@ -3148,6 +3150,8 @@ libssh_protocol_deps="libssh"
 libtls_conflict="openssl gnutls"
 mmsh_protocol_select="http_protocol"
 mmst_protocol_select="network"
+opensrt_protocol_select="network"
+opensrt_protocol_deps="opensrt"
 rtmp_protocol_conflict="librtmp_protocol"
 rtmp_protocol_select="tcp_protocol"
 rtmp_protocol_suggest="zlib"
@@ -5986,6 +5990,7 @@ enabled omx   && require_header OMX_Core.h
 enabled omx_rpi   && { check_header OMX_Core.h ||
{ ! enabled cross_compile && add_cflags 
-isystem/opt/vc/include/IL && check_header OMX_Core.h ; } ||
die "ERROR: OpenMAX IL headers not found"; } && 
enable omx
+enabled opensrt   && require_pkg_config libsrt "srt >= 1.2.0" 
srt/srt.h srt_socket
 enabled openssl   && { check_pkg_config openssl openssl openssl/ssl.h 
OPENSSL_init_ssl ||
check_pkg_config openssl openssl openssl/ssl.h 
SSL_library_init ||
check_lib openssl openssl/ssl.h 
SSL_library_init -lssl -lcrypto ||
@@ -6036,6 +6041,10 @@ if enabled decklink; then
 esac
 fi
 
+if enabled opensrt; then
+opensrt_protocol_extralibs="$opensrt_protocol_extralibs -lsrt"
+fi
+
 enabled securetransport &&
 check_func SecIdentityCreate "-Wl,-framework,CoreFoundation 
-Wl,-framework,Security" &&
 check_lib securetransport "Security/SecureTransport.h Security/Security.h" 
"SSLCreateContext" "-Wl,-framework,CoreFoundation -Wl,-framework,Security" ||
diff --git a/doc/protocols.texi b/doc/protocols.texi
index 98deb73..2e5e630 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -755,6 +755,122 @@ Set the workgroup used for making connections. By default 
workgroup is not speci
 
 For more information see: @url{http://www.samba.org/}.
 
+@section srt
+
+Haivision Secure Reliable Transport Protocol via libsrt.
+
+The required syntax for a SRT url is:
+@example
+srt://@var{hostname}:@var{port}[?@var{options}]
+@end example
+
+@var{options} contains a list of &-separated options of the form
+@var{key}=@var{val}.
+
+This protocol accepts the following options.
+
+@table @option
+@item conntimeo
+Connection timeout. SRT cannot connect for RTT > 1500 msec
+(2 handshake exchanges) with the default connect timeout of 3 seconds. This 
option
+applies to the caller and rendezvous connection modes. The connect timeout is 
10 times
+the value set for the rendezvous mode (which can be used as a workaround for 
this
+connection problem with earlier versions).
+
+@item fc=@var{bytes}
+Flight Flag Size (Window Size), in bytes. FC is actually an internal parameter 
and
+you should set it to not less than @option{recv_buffer_size} and @option{mss}.
+The default value is relatively large, therefore unless you set a very large
+receiver buffer, you do not need to change this option. Default value is 25600.
+
+@item inputbw=@var{bytes/seconds}
+Sender nominal input rate, in bytes per seconds. Used along with 
@option{oheadbw},
+whe

Re: [FFmpeg-devel] [PATCH] avformat/opensrt: add Haivision Open SRT protocol

2018-01-24 Thread nablet developer

On 16-Jan-18 09:43, Michael Niedermayer wrote:

if you will maintain this code then you may want to include a
change to the MAINTAINERs file

also does anyone have any more comments on this patch ?
it seems to have not gotten much attention recently. There where
reviews/comments a few months ago but the recent versions received little
attention.
Once/If everyone is done with reviewing/commenting (i assume all requests for
changes have been made?) then it should be applied, thus if i see no more
comments from anyone and spot no obvious issue myself then i will apply
seems like no comments so far. is anything else preventing patch to be 
applied now?

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avformat/opensrt: add Haivision Open SRT protocol

2018-01-14 Thread Nablet Developer
protocol requires libsrt (https://github.com/Haivision/srt) to be
installed

Signed-off-by: Nablet Developer <s...@nablet.com>
---
 configure   |   9 +
 doc/protocols.texi  | 116 +
 libavformat/Makefile|   1 +
 libavformat/opensrt.c   | 622 
 libavformat/protocols.c |   1 +
 5 files changed, 749 insertions(+)
 create mode 100644 libavformat/opensrt.c

diff --git a/configure b/configure
index 5d53362..8b925a8 100755
--- a/configure
+++ b/configure
@@ -294,6 +294,7 @@ External library support:
   --enable-opengl  enable OpenGL rendering [no]
   --enable-openssl enable openssl, needed for https support
if gnutls or libtls is not used [no]
+  --enable-opensrt enable Haivision Open SRT protocol [no]
   --disable-sndio  disable sndio support [autodetect]
   --disable-schannel   disable SChannel SSP, needed for TLS support on
Windows if openssl and gnutls are not used 
[autodetect]
@@ -1641,6 +1642,7 @@ EXTERNAL_LIBRARY_LIST="
 mediacodec
 openal
 opengl
+opensrt
 "
 
 HWACCEL_AUTODETECT_LIBRARY_LIST="
@@ -3148,6 +3150,8 @@ libssh_protocol_deps="libssh"
 libtls_conflict="openssl gnutls"
 mmsh_protocol_select="http_protocol"
 mmst_protocol_select="network"
+opensrt_protocol_select="network"
+opensrt_protocol_deps="opensrt"
 rtmp_protocol_conflict="librtmp_protocol"
 rtmp_protocol_select="tcp_protocol"
 rtmp_protocol_suggest="zlib"
@@ -5983,6 +5987,7 @@ enabled omx   && require_header OMX_Core.h
 enabled omx_rpi   && { check_header OMX_Core.h ||
{ ! enabled cross_compile && add_cflags 
-isystem/opt/vc/include/IL && check_header OMX_Core.h ; } ||
die "ERROR: OpenMAX IL headers not found"; } && 
enable omx
+enabled opensrt   && require_pkg_config libsrt "srt >= 1.2.0" 
srt/srt.h srt_socket
 enabled openssl   && { check_pkg_config openssl openssl openssl/ssl.h 
OPENSSL_init_ssl ||
check_pkg_config openssl openssl openssl/ssl.h 
SSL_library_init ||
check_lib openssl openssl/ssl.h 
SSL_library_init -lssl -lcrypto ||
@@ -6033,6 +6038,10 @@ if enabled decklink; then
 esac
 fi
 
+if enabled opensrt; then
+opensrt_protocol_extralibs="$opensrt_protocol_extralibs -lsrt"
+fi
+
 enabled securetransport &&
 check_func SecIdentityCreate "-Wl,-framework,CoreFoundation 
-Wl,-framework,Security" &&
 check_lib securetransport "Security/SecureTransport.h Security/Security.h" 
"SSLCreateContext" "-Wl,-framework,CoreFoundation -Wl,-framework,Security" ||
diff --git a/doc/protocols.texi b/doc/protocols.texi
index 98deb73..a923749 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -755,6 +755,122 @@ Set the workgroup used for making connections. By default 
workgroup is not speci
 
 For more information see: @url{http://www.samba.org/}.
 
+@section srt
+
+Haivision Secure Reliable Transport Protocol via libsrt.
+
+The required syntax for a SRT url is:
+@example
+srt://@var{hostname}:@var{port}[?@var{options}]
+@end example
+
+@var{options} contains a list of &-separated options of the form
+@var{key}=@var{val}.
+
+This protocol accepts the following options.
+
+@table @option
+@item conntimeo=@var{milliseconds}
+Connection timeout, in milliseconds. SRT cannot connect for RTT > 1500 msec
+(2 handshake exchanges) with the default connect timeout of 3 seconds. This 
option
+applies to the caller and rendezvous connection modes. The connect timeout is 
10 times
+the value set for the rendezvous mode (which can be used as a workaround for 
this
+connection problem with earlier versions).
+
+@item fc=@var{bytes}
+Flight Flag Size (Window Size), in bytes. FC is actually an internal parameter 
and
+you should set it to not less than @option{recv_buffer_size} and @option{mss}.
+The default value is relatively large, therefore unless you set a very large
+receiver buffer, you do not need to change this option. Default value is 25600.
+
+@item inputbw=@var{bytes/seconds}
+Sender nominal input rate, in bytes per seconds. Used along with 
@option{oheadbw},
+when @option{maxbw} is set to relative (0), to calculate maximum sending rate 
when
+recovery packets are sent along with main media stream:
+@option{inputbw} * (100 + @option{oheadbw}) / 100
+if @option{inputbw} is not set while @option{maxbw} is set to relative (0), 
the actual
+ctual input rate is evaluated inside the library. Default value is 0.
+
+@item iptos=@var{tos}
+IP Type of Service. Applies to sender only. Default value is 0xB8.
+
+@item ipttl=@var{ttl}
+I

Re: [FFmpeg-devel] [PATCH] avformat/opensrt: add Haivision Open SRT protocol

2018-01-14 Thread Nablet Developer


On 1/13/2018 4:40 AM, Michael Niedermayer wrote:

On Wed, Dec 13, 2017 at 03:31:04PM +0700, Nablet Developer wrote:
[...]
this is commented out ?


yes, looks like leftover, thanks for pointing. will send updated patch soon.

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] libavformat/opensrt: add Haivision Open SRT protocol

2018-01-11 Thread Nablet Developer


On 12/25/2017 10:52 AM, nablet developer wrote:

On 19-Dec-17 15:01, nablet developer wrote:



On 13 Dec 2017, at 15:31, Nablet Developer <s...@nablet.com> wrote:

The protocol is used by thousands of Haivision customers since 2013,
in extremely sensitive medical, military and enterprise applications
with FIPS compliant encryption requirements. Since April 2017, the 
protocol
is Open Source and meanwhile >50 partners joined the SRT Alliance 
(srtalliance.org).
GStreamer already integrated the protocol and VLC has already 
accepted the pull
request for adding the SRT protocol to VLC. We see a dramatic 
adoption of the
protocol in the market and a lot of our partners are asking us 
frequently on a

ffmpeg integration.

Nablet Developer (1):
  avformat/opensrt: add Haivision Open SRT protocol

configure   |  10 +
doc/protocols.texi  | 116 +
libavformat/Makefile    |   1 +
libavformat/opensrt.c   | 622 


libavformat/protocols.c |   1 +
5 files changed, 750 insertions(+)
create mode 100644 libavformat/opensrt.c

--
2.7.4


ping

ping


ping
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] libavformat/opensrt: add Haivision Open SRT protocol

2017-12-24 Thread nablet developer

On 19-Dec-17 15:01, nablet developer wrote:



On 13 Dec 2017, at 15:31, Nablet Developer <s...@nablet.com> wrote:

The protocol is used by thousands of Haivision customers since 2013,
in extremely sensitive medical, military and enterprise applications
with FIPS compliant encryption requirements. Since April 2017, the protocol
is Open Source and meanwhile >50 partners joined the SRT Alliance 
(srtalliance.org).
GStreamer already integrated the protocol and VLC has already accepted the pull
request for adding the SRT protocol to VLC. We see a dramatic adoption of the
protocol in the market and a lot of our partners are asking us frequently on a
ffmpeg integration.

Nablet Developer (1):
  avformat/opensrt: add Haivision Open SRT protocol

configure   |  10 +
doc/protocols.texi  | 116 +
libavformat/Makefile|   1 +
libavformat/opensrt.c   | 622 
libavformat/protocols.c |   1 +
5 files changed, 750 insertions(+)
create mode 100644 libavformat/opensrt.c

--
2.7.4


ping

ping
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] libavformat/opensrt: add Haivision Open SRT protocol

2017-12-19 Thread nablet developer


> On 13 Dec 2017, at 15:31, Nablet Developer <s...@nablet.com> wrote:
> 
> The protocol is used by thousands of Haivision customers since 2013,
> in extremely sensitive medical, military and enterprise applications
> with FIPS compliant encryption requirements. Since April 2017, the protocol
> is Open Source and meanwhile >50 partners joined the SRT Alliance 
> (srtalliance.org).
> GStreamer already integrated the protocol and VLC has already accepted the 
> pull
> request for adding the SRT protocol to VLC. We see a dramatic adoption of the
> protocol in the market and a lot of our partners are asking us frequently on a
> ffmpeg integration.
> 
> Nablet Developer (1):
>  avformat/opensrt: add Haivision Open SRT protocol
> 
> configure   |  10 +
> doc/protocols.texi  | 116 +
> libavformat/Makefile|   1 +
> libavformat/opensrt.c   | 622 
> libavformat/protocols.c |   1 +
> 5 files changed, 750 insertions(+)
> create mode 100644 libavformat/opensrt.c
> 
> -- 
> 2.7.4
> 

ping
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avformat/opensrt: add Haivision Open SRT protocol

2017-12-13 Thread Nablet Developer
protocol requires libsrt (https://github.com/Haivision/srt) to be
installed

Signed-off-by: Nablet Developer <s...@nablet.com>
---
 configure   |  10 +
 doc/protocols.texi  | 116 +
 libavformat/Makefile|   1 +
 libavformat/opensrt.c   | 622 
 libavformat/protocols.c |   1 +
 5 files changed, 750 insertions(+)
 create mode 100644 libavformat/opensrt.c

diff --git a/configure b/configure
index d5bbb5b..b26c60f 100755
--- a/configure
+++ b/configure
@@ -293,6 +293,7 @@ External library support:
   --enable-opengl  enable OpenGL rendering [no]
   --enable-openssl enable openssl, needed for https support
if gnutls is not used [no]
+  --enable-opensrt enable Haivision Open SRT protocol [no]
   --disable-sndio  disable sndio support [autodetect]
   --disable-schannel   disable SChannel SSP, needed for TLS support on
Windows if openssl and gnutls are not used 
[autodetect]
@@ -1638,6 +1639,7 @@ EXTERNAL_LIBRARY_LIST="
 mediacodec
 openal
 opengl
+opensrt
 "
 
 HWACCEL_AUTODETECT_LIBRARY_LIST="
@@ -3145,6 +3147,8 @@ libsmbclient_protocol_deps="libsmbclient gplv3"
 libssh_protocol_deps="libssh"
 mmsh_protocol_select="http_protocol"
 mmst_protocol_select="network"
+opensrt_protocol_select="network"
+opensrt_protocol_deps="opensrt"
 rtmp_protocol_conflict="librtmp_protocol"
 rtmp_protocol_select="tcp_protocol"
 rtmp_protocol_suggest="zlib"
@@ -5972,6 +5976,8 @@ enabled omx   && require_header OMX_Core.h
 enabled omx_rpi   && { check_header OMX_Core.h ||
{ ! enabled cross_compile && add_cflags 
-isystem/opt/vc/include/IL && check_header OMX_Core.h ; } ||
die "ERROR: OpenMAX IL headers not found"; } && 
enable omx
+#enabled opensrt   && check_lib srt srt/srt.h srt_socket -lsrt
+enabled opensrt   && require_pkg_config libsrt "srt >= 1.2.0" 
srt/srt.h srt_socket
 enabled openssl   && { check_pkg_config openssl openssl openssl/ssl.h 
OPENSSL_init_ssl ||
check_pkg_config openssl openssl openssl/ssl.h 
SSL_library_init ||
check_lib openssl openssl/ssl.h 
SSL_library_init -lssl -lcrypto ||
@@ -6026,6 +6032,10 @@ if enabled decklink; then
 esac
 fi
 
+if enabled opensrt; then
+opensrt_protocol_extralibs="$opensrt_protocol_extralibs -lsrt"
+fi
+
 enabled securetransport &&
 check_func SecIdentityCreate "-Wl,-framework,CoreFoundation 
-Wl,-framework,Security" &&
 check_lib securetransport "Security/SecureTransport.h Security/Security.h" 
"SSLCreateContext" "-Wl,-framework,CoreFoundation -Wl,-framework,Security" ||
diff --git a/doc/protocols.texi b/doc/protocols.texi
index 8661aea..358366e 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -752,6 +752,122 @@ Set the workgroup used for making connections. By default 
workgroup is not speci
 
 For more information see: @url{http://www.samba.org/}.
 
+@section srt
+
+Haivision Secure Reliable Transport Protocol via libsrt.
+
+The required syntax for a SRT url is:
+@example
+srt://@var{hostname}:@var{port}[?@var{options}]
+@end example
+
+@var{options} contains a list of &-separated options of the form
+@var{key}=@var{val}.
+
+This protocol accepts the following options.
+
+@table @option
+@item conntimeo=@var{milliseconds}
+Connection timeout, in milliseconds. SRT cannot connect for RTT > 1500 msec
+(2 handshake exchanges) with the default connect timeout of 3 seconds. This 
option
+applies to the caller and rendezvous connection modes. The connect timeout is 
10 times
+the value set for the rendezvous mode (which can be used as a workaround for 
this
+connection problem with earlier versions).
+
+@item fc=@var{bytes}
+Flight Flag Size (Window Size), in bytes. FC is actually an internal parameter 
and
+you should set it to not less than @option{recv_buffer_size} and @option{mss}.
+The default value is relatively large, therefore unless you set a very large
+receiver buffer, you do not need to change this option. Default value is 25600.
+
+@item inputbw=@var{bytes/seconds}
+Sender nominal input rate, in bytes per seconds. Used along with 
@option{oheadbw},
+when @option{maxbw} is set to relative (0), to calculate maximum sending rate 
when
+recovery packets are sent along with main media stream:
+@option{inputbw} * (100 + @option{oheadbw}) / 100
+if @option{inputbw} is not set while @option{maxbw} is set to relative (0), 
the actual
+ctual input rate is evaluated inside the library. Default value is 0.
+
+@item iptos=@var{tos}
+IP Type 

[FFmpeg-devel] [PATCH] libavformat/opensrt: add Haivision Open SRT protocol

2017-12-13 Thread Nablet Developer
The protocol is used by thousands of Haivision customers since 2013,
in extremely sensitive medical, military and enterprise applications
with FIPS compliant encryption requirements. Since April 2017, the protocol
is Open Source and meanwhile >50 partners joined the SRT Alliance 
(srtalliance.org).
GStreamer already integrated the protocol and VLC has already accepted the pull
request for adding the SRT protocol to VLC. We see a dramatic adoption of the
protocol in the market and a lot of our partners are asking us frequently on a
ffmpeg integration.

Nablet Developer (1):
  avformat/opensrt: add Haivision Open SRT protocol

 configure   |  10 +
 doc/protocols.texi  | 116 +
 libavformat/Makefile|   1 +
 libavformat/opensrt.c   | 622 
 libavformat/protocols.c |   1 +
 5 files changed, 750 insertions(+)
 create mode 100644 libavformat/opensrt.c

-- 
2.7.4

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 3/3] avformat/opensrt: add Haivision Open SRT protocol

2017-11-21 Thread nablet developer


> On 20 Nov 2017, at 13:35, nablet developer <s...@nablet.com> wrote:
> 
> 
>> 
>> Thanks for explaining. I think it is not the best decision.
>> 
>> The reason the socket API resembles TCP is because all the sockets API
>> resemble each other, since they are based on the old BSD socket API. And
>> the protocol handlers of libavformat too.
>> 
>> Therefore, I think all the trampoline code to allow TCP to call back
>> another protocol plus all the boilerplate code that you need to make
>> opensrc callable from TCP amounts to worse than implementing a protocol
>> directly.
>> 
>> Furthermore, TCP is the most important network protocol for now, while
>> opensrt is still rather obscure, so tying one with the other is not a
>> good idea.
>> 
>> Also, implementing a real protocol from scratch would possibly allow you
>> to make use of extra features of the opensrt API: maybe they have a
>> read-with-timeout function, for example, or something like that.
>> 
>> 
> 
> thanks for the feedback.
> regarding relying on TCP protocol code it's clear - I will implement protocol 
> from scratch next time.
> regarding re-using functions from network.c (like ff_network_wait_fd, 
> ff_accept, etc)
> is suggested approach acceptable? is it okay to define such socket_api 
> structure and pass to
> network.c calls?
> 

ping

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 3/3] avformat/opensrt: add Haivision Open SRT protocol

2017-11-19 Thread nablet developer

> 
> Thanks for explaining. I think it is not the best decision.
> 
> The reason the socket API resembles TCP is because all the sockets API
> resemble each other, since they are based on the old BSD socket API. And
> the protocol handlers of libavformat too.
> 
> Therefore, I think all the trampoline code to allow TCP to call back
> another protocol plus all the boilerplate code that you need to make
> opensrc callable from TCP amounts to worse than implementing a protocol
> directly.
> 
> Furthermore, TCP is the most important network protocol for now, while
> opensrt is still rather obscure, so tying one with the other is not a
> good idea.
> 
> Also, implementing a real protocol from scratch would possibly allow you
> to make use of extra features of the opensrt API: maybe they have a
> read-with-timeout function, for example, or something like that.
> 
> 

thanks for the feedback.
regarding relying on TCP protocol code it's clear - I will implement protocol 
from scratch next time.
regarding re-using functions from network.c (like ff_network_wait_fd, 
ff_accept, etc)
is suggested approach acceptable? is it okay to define such socket_api 
structure and pass to
network.c calls?

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 3/3] avformat/opensrt: add Haivision Open SRT protocol

2017-11-09 Thread nablet developer


On 10-Nov-17 03:35, Nicolas George wrote:

Can you explain the logic of the implementation? I have a hard time
understanding why you call the tcp protocol from here after forcing it
to call back here.

Regards,


the idea is to avoid code duplication as much as possible, and try to 
re-use existing, well-maintained and well-tested code.

this time I've chosen tcp.c rather udp.c for two reasons:
1. SRT socket API actually resembles tcp, as it uses connection and 
related methods (connect/listen/accept)

2. tcp.c code is much more clean and straightforward rather udp.c
the first thing which obviously differs between tcp and srt are socket 
api calls, but there is direct mapping for most of them, e.g.:

socket -> srt_socket
connect -> srt_connect
listen -> srt_listen
very few of srt socket calls are different, e.g. srt doesn't provide 
send/recv, but provides sendmsg/recvmsg, also it doesn't provide poll, 
but has epoll_wait.
with simple wrappers, it allows to use existing logic of tcp.c and 
network.c without modifications.
for calling back srt from tcp, that's the second difference - srt has 
lots of additional socket options,
and some of these socket options has to be set prior to connection, 
others after connection (called pre and post options in srt).

Haivision explicitly requested to add these options into ffmpeg component.
so, there are two calls back in tcp_open - to set options just before 
connection, and to set options right after connections.
if you have some advice on how it can be implemented better, I am open 
for suggestions and advises.

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 2/3] avformat/tcp: use generic socket API

2017-11-09 Thread Nablet Developer
this allows to implement other protocols which use
API similar to BSD sockets (e.g. Haivision SRT)

Signed-off-by: Nablet Developer <s...@nablet.com>
---
 libavformat/tcp.c | 118 +++---
 libavformat/tcp.h |  59 +++
 2 files changed, 119 insertions(+), 58 deletions(-)
 create mode 100644 libavformat/tcp.h

diff --git a/libavformat/tcp.c b/libavformat/tcp.c
index 07b4ed9..a775230 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
@@ -32,26 +32,12 @@
 #include 
 #endif
 
-typedef struct TCPContext {
-const AVClass *class;
-int fd;
-int listen;
-int open_timeout;
-int rw_timeout;
-int listen_timeout;
-int recv_buffer_size;
-int send_buffer_size;
-} TCPContext;
-
-#define OFFSET(x) offsetof(TCPContext, x)
+#include "tcp.h"
+
 #define D AV_OPT_FLAG_DECODING_PARAM
 #define E AV_OPT_FLAG_ENCODING_PARAM
 static const AVOption options[] = {
-{ "listen",  "Listen for incoming connections",  OFFSET(listen),   
  AV_OPT_TYPE_INT, { .i64 = 0 }, 0,   2,   .flags = D|E },
-{ "timeout", "set timeout (in microseconds) of socket I/O operations", 
OFFSET(rw_timeout), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, 
.flags = D|E },
-{ "listen_timeout",  "Connection awaiting timeout (in milliseconds)",  
OFFSET(listen_timeout), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, 
.flags = D|E },
-{ "send_buffer_size", "Socket send buffer size (in bytes)",
OFFSET(send_buffer_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, 
.flags = D|E },
-{ "recv_buffer_size", "Socket receive buffer size (in bytes)", 
OFFSET(recv_buffer_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, 
.flags = D|E },
+TCP_COMMON_OPTS
 { NULL }
 };
 
@@ -63,7 +49,7 @@ static const AVClass tcp_class = {
 };
 
 /* return non zero if error */
-static int tcp_open(URLContext *h, const char *uri, int flags)
+int ff_tcp_open(URLContext *h, const char *uri, int flags)
 {
 struct addrinfo hints = { 0 }, *ai, *cur_ai;
 int port, fd = -1;
@@ -75,10 +61,15 @@ static int tcp_open(URLContext *h, const char *uri, int 
flags)
 char portstr[10];
 s->open_timeout = 500;
 
+s->api = s->api ? s->api : _socket_api;
+s->proto = s->proto ? s->proto : "tcp";
+
 av_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname),
 , path, sizeof(path), uri);
-if (strcmp(proto, "tcp"))
+if (strcmp(proto, s->proto)) {
+av_log(h, AV_LOG_ERROR, "incorrect protocol %s %s\n", proto, s->proto);
 return AVERROR(EINVAL);
+}
 if (port <= 0 || port >= 65536) {
 av_log(h, AV_LOG_ERROR, "Port missing in uri\n");
 return AVERROR(EINVAL);
@@ -132,37 +123,42 @@ static int tcp_open(URLContext *h, const char *uri, int 
flags)
 }
 #endif
 
-fd = ff_socket(cur_ai->ai_family,
-   cur_ai->ai_socktype,
-   cur_ai->ai_protocol);
+fd = s->api->socket(cur_ai->ai_family,
+cur_ai->ai_socktype,
+cur_ai->ai_protocol);
 if (fd < 0) {
-ret = ff_neterrno();
+ret = s->api->neterrno();
 goto fail;
 }
 
 /* Set the socket's send or receive buffer sizes, if specified.
If unspecified or setting fails, system default is used. */
 if (s->recv_buffer_size > 0) {
-setsockopt (fd, SOL_SOCKET, SO_RCVBUF, >recv_buffer_size, sizeof 
(s->recv_buffer_size));
+s->api->setsockopt (fd, SOL_SOCKET, SO_RCVBUF, >recv_buffer_size, 
sizeof (s->recv_buffer_size));
 }
 if (s->send_buffer_size > 0) {
-setsockopt (fd, SOL_SOCKET, SO_SNDBUF, >send_buffer_size, sizeof 
(s->send_buffer_size));
+s->api->setsockopt (fd, SOL_SOCKET, SO_SNDBUF, >send_buffer_size, 
sizeof (s->send_buffer_size));
+}
+
+if (s->set_options_pre) {
+if ((ret = s->set_options_pre(h, fd)) < 0)
+goto fail1;
 }
 
 if (s->listen == 2) {
 // multi-client
-if ((ret = ff_listen(fd, cur_ai->ai_addr, cur_ai->ai_addrlen)) < 0)
+if ((ret = ff_listen_ex(s->api, fd, cur_ai->ai_addr, 
cur_ai->ai_addrlen)) < 0)
 goto fail1;
 } else if (s->listen == 1) {
 // single client
-if ((ret = ff_listen_bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen,
-  s->listen_timeout, h)) < 0)
+if ((ret = ff_listen_bind_ex(s->api, fd, cur_ai->ai_addr, 
cur_ai->ai_addrlen,
+ s->listen_timeout, h)) < 0)
 goto fail1;

[FFmpeg-devel] [PATCH 3/3] avformat/opensrt: add Haivision Open SRT protocol

2017-11-09 Thread Nablet Developer
protocol requires libsrt (https://github.com/Haivision/srt) to be
installed

Signed-off-by: Nablet Developer <s...@nablet.com>
---
 configure   |  10 ++
 libavformat/Makefile|   1 +
 libavformat/opensrt.c   | 418 
 libavformat/protocols.c |   1 +
 4 files changed, 430 insertions(+)
 create mode 100644 libavformat/opensrt.c

diff --git a/configure b/configure
index f396abd..b44df0e 100755
--- a/configure
+++ b/configure
@@ -293,6 +293,7 @@ External library support:
   --enable-opengl  enable OpenGL rendering [no]
   --enable-openssl enable openssl, needed for https support
if gnutls is not used [no]
+  --enable-opensrt enable Haivision Open SRT protoco [no]
   --disable-sndio  disable sndio support [autodetect]
   --disable-schannel   disable SChannel SSP, needed for TLS support on
Windows if openssl and gnutls are not used 
[autodetect]
@@ -1638,6 +1639,7 @@ EXTERNAL_LIBRARY_LIST="
 openal
 opencl
 opengl
+opensrt
 "
 
 HWACCEL_AUTODETECT_LIBRARY_LIST="
@@ -3139,6 +3141,8 @@ libsmbclient_protocol_deps="libsmbclient gplv3"
 libssh_protocol_deps="libssh"
 mmsh_protocol_select="http_protocol"
 mmst_protocol_select="network"
+opensrt_protocol_select="network"
+opensrt_protocol_deps="opensrt"
 rtmp_protocol_conflict="librtmp_protocol"
 rtmp_protocol_select="tcp_protocol"
 rtmp_protocol_suggest="zlib"
@@ -6102,6 +6106,8 @@ enabled omx   && require_header OMX_Core.h
 enabled omx_rpi   && { check_header OMX_Core.h ||
{ ! enabled cross_compile && add_cflags 
-isystem/opt/vc/include/IL && check_header OMX_Core.h ; } ||
die "ERROR: OpenMAX IL headers not found"; } && 
enable omx
+#enabled opensrt   && check_lib srt srt/srt.h srt_socket -lsrt
+enabled opensrt   && require_pkg_config libsrt "srt >= 1.2.0" 
srt/srt.h srt_socket
 enabled openssl   && { use_pkg_config openssl openssl openssl/ssl.h 
OPENSSL_init_ssl ||
use_pkg_config openssl openssl openssl/ssl.h 
SSL_library_init ||
check_lib openssl openssl/ssl.h 
SSL_library_init -lssl -lcrypto ||
@@ -6156,6 +6162,10 @@ if enabled decklink; then
 esac
 fi
 
+if enabled opensrt; then
+opensrt_protocol_extralibs="$opensrt_protocol_extralibs -lsrt"
+fi
+
 enabled securetransport &&
 check_func SecIdentityCreate "-Wl,-framework,CoreFoundation 
-Wl,-framework,Security" &&
 check_lib securetransport "Security/SecureTransport.h Security/Security.h" 
"SSLCreateContext SecItemImport" "-Wl,-framework,CoreFoundation 
-Wl,-framework,Security" ||
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 146a465..5116d31 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -596,6 +596,7 @@ TLS-OBJS-$(CONFIG_SCHANNEL)  += tls_schannel.o
 OBJS-$(CONFIG_TLS_PROTOCOL)  += tls.o $(TLS-OBJS-yes)
 OBJS-$(CONFIG_UDP_PROTOCOL)  += udp.o
 OBJS-$(CONFIG_UDPLITE_PROTOCOL)  += udp.o
+OBJS-$(CONFIG_OPENSRT_PROTOCOL)  += opensrt.o
 OBJS-$(CONFIG_UNIX_PROTOCOL) += unix.o
 
 # libavdevice dependencies
diff --git a/libavformat/opensrt.c b/libavformat/opensrt.c
new file mode 100644
index 000..bc58368
--- /dev/null
+++ b/libavformat/opensrt.c
@@ -0,0 +1,418 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Haivision Open SRT (Secure Reliable Transport) protocol
+ */
+
+#include "avformat.h"
+#include "libavutil/avassert.h"
+#include "libavutil/parseutils.h"
+#include "libavutil/opt.h"
+#include "libavutil/time.h"
+
+#include "internal.h"
+#include "network.h"
+#include "os_support.h"
+#include "url.h"
+#if HAVE_POLL_H
+#include 
+#endif
+
+#include "tcp.h"
+
+#if CONFIG_

[FFmpeg-devel] [PATCH 1/3] avformat/network: allow to specify custom socket API

2017-11-09 Thread Nablet Developer
Signed-off-by: Nablet Developer <s...@nablet.com>
---
 libavformat/network.c | 196 --
 libavformat/network.h |  34 +
 2 files changed, 161 insertions(+), 69 deletions(-)

diff --git a/libavformat/network.c b/libavformat/network.c
index 6c3d9de..80d6f6e 100644
--- a/libavformat/network.c
+++ b/libavformat/network.c
@@ -74,24 +74,104 @@ int ff_network_init(void)
 return 1;
 }
 
+#if HAVE_WINSOCK2_H
+int ff_neterrno(void)
+{
+int err = WSAGetLastError();
+switch (err) {
+case WSAEWOULDBLOCK:
+return AVERROR(EAGAIN);
+case WSAEINTR:
+return AVERROR(EINTR);
+case WSAEPROTONOSUPPORT:
+return AVERROR(EPROTONOSUPPORT);
+case WSAETIMEDOUT:
+return AVERROR(ETIMEDOUT);
+case WSAECONNREFUSED:
+return AVERROR(ECONNREFUSED);
+case WSAEINPROGRESS:
+return AVERROR(EINPROGRESS);
+}
+return -err;
+}
+#endif
+
+// wrap into function as ff_neterrno is define on *nix
+static int ff_neterrno_wrapper(void)
+{
+return ff_neterrno();
+}
+
+int ff_socket(int af, int type, int proto)
+{
+int fd;
+
+#ifdef SOCK_CLOEXEC
+fd = socket(af, type | SOCK_CLOEXEC, proto);
+if (fd == -1 && errno == EINVAL)
+#endif
+{
+fd = socket(af, type, proto);
+#if HAVE_FCNTL
+if (fd != -1) {
+if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
+av_log(NULL, AV_LOG_DEBUG, "Failed to set close on exec\n");
+}
+#endif
+}
+#ifdef SO_NOSIGPIPE
+if (fd != -1)
+setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &(int){1}, sizeof(int));
+#endif
+return fd;
+}
+
+
+const struct socket_api bsd_socket_api = {
+.poll = poll,
+.bind = bind,
+.socket = ff_socket,
+.listen = listen,
+.connect = connect,
+.setsockopt = setsockopt,
+.getsockopt = getsockopt,
+.accept = accept,
+.close = closesocket,
+.socket_nonblock = ff_socket_nonblock,
+.neterrno = ff_neterrno_wrapper,
+.send = send,
+.recv = recv,
+.shutdown = shutdown
+};
+
 int ff_network_wait_fd(int fd, int write)
 {
+return ff_network_wait_fd_ex(_socket_api, fd, write);
+}
+
+int ff_network_wait_fd_ex(const struct socket_api * api, int fd, int write)
+{
 int ev = write ? POLLOUT : POLLIN;
 struct pollfd p = { .fd = fd, .events = ev, .revents = 0 };
 int ret;
-ret = poll(, 1, POLLING_TIME);
-return ret < 0 ? ff_neterrno() : p.revents & (ev | POLLERR | POLLHUP) ? 0 
: AVERROR(EAGAIN);
+ret = api->poll(, 1, POLLING_TIME);
+return ret < 0 ? api->neterrno() : p.revents & (ev | POLLERR | POLLHUP) ? 
0 : AVERROR(EAGAIN);
 }
 
 int ff_network_wait_fd_timeout(int fd, int write, int64_t timeout, 
AVIOInterruptCB *int_cb)
 {
+return ff_network_wait_fd_timeout_ex(_socket_api, fd, write, timeout, 
int_cb);
+}
+
+int ff_network_wait_fd_timeout_ex(const struct socket_api * api, int fd, int 
write, int64_t timeout, AVIOInterruptCB *int_cb)
+{
 int ret;
 int64_t wait_start = 0;
 
 while (1) {
 if (ff_check_interrupt(int_cb))
 return AVERROR_EXIT;
-ret = ff_network_wait_fd(fd, write);
+ret = ff_network_wait_fd_ex(api, fd, write);
 if (ret != AVERROR(EAGAIN))
 return ret;
 if (timeout > 0) {
@@ -110,28 +190,6 @@ void ff_network_close(void)
 #endif
 }
 
-#if HAVE_WINSOCK2_H
-int ff_neterrno(void)
-{
-int err = WSAGetLastError();
-switch (err) {
-case WSAEWOULDBLOCK:
-return AVERROR(EAGAIN);
-case WSAEINTR:
-return AVERROR(EINTR);
-case WSAEPROTONOSUPPORT:
-return AVERROR(EPROTONOSUPPORT);
-case WSAETIMEDOUT:
-return AVERROR(ETIMEDOUT);
-case WSAECONNREFUSED:
-return AVERROR(ECONNREFUSED);
-case WSAEINPROGRESS:
-return AVERROR(EINPROGRESS);
-}
-return -err;
-}
-#endif
-
 int ff_is_multicast_address(struct sockaddr *addr)
 {
 if (addr->sa_family == AF_INET) {
@@ -146,7 +204,7 @@ int ff_is_multicast_address(struct sockaddr *addr)
 return 0;
 }
 
-static int ff_poll_interrupt(struct pollfd *p, nfds_t nfds, int timeout,
+static int ff_poll_interrupt_ex(const struct socket_api * api, struct pollfd 
*p, nfds_t nfds, int timeout,
  AVIOInterruptCB *cb)
 {
 int runs = timeout / POLLING_TIME;
@@ -155,7 +213,7 @@ static int ff_poll_interrupt(struct pollfd *p, nfds_t nfds, 
int timeout,
 do {
 if (ff_check_interrupt(cb))
 return AVERROR_EXIT;
-ret = poll(p, nfds, POLLING_TIME);
+ret = api->poll(p, nfds, POLLING_TIME);
 if (ret != 0)
 break;
 } while (timeout <= 0 || runs-- > 0);
@@ -163,65 +221,52 @@ static int ff_poll_interrupt(struct pollfd *p, nfds_t 
nfds, int timeout,
 if (!ret)
 return AVERROR(ETIMEDOUT);
 if (ret < 0)
-return ff_neterrno();
+return api->neterrno();
 

[FFmpeg-devel] [PATCH 0/3] avformat/opensrt: add Haivision Open SRT protocol

2017-11-09 Thread Nablet Developer
the following patches implement Haivision SRT protocol.
name OpenSRT is used to distinguish it from SRT subtitles.
patches avoid copy-paste and associated maintanance burden
by re-using existing code as much as possible (more
specifically, tcp.c and network.c).
network.c now allows to use other BSD-like socket APIs,
for instance SRT or UDT.
tcp.c is used as base for SRT protocol implementation,
as SRT socket API closely ressambles TCP sockets.

Nablet Developer (3):
  avformat/network: allow to specify custom socket API
  avformat/tcp: use generic socket API
  avformat/opensrt: add Haivision Open SRT protocol

 configure   |  10 ++
 libavformat/Makefile|   1 +
 libavformat/network.c   | 196 +++
 libavformat/network.h   |  34 
 libavformat/opensrt.c   | 418 
 libavformat/protocols.c |   1 +
 libavformat/tcp.c   | 118 +++---
 libavformat/tcp.h   |  59 +++
 8 files changed, 710 insertions(+), 127 deletions(-)
 create mode 100644 libavformat/opensrt.c
 create mode 100644 libavformat/tcp.h

-- 
2.7.4

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avformat/srt: add Haivision SRT protocol

2017-10-05 Thread Nablet Developer

> SRT is a subtitle format: a more specific name would be better.
Haivision suggested name "opensrt" - is it acceptable to distinguish 
with SRT subtitile format?

if yes, I'll go ahead and submit new patch with name changed.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avformat/srt: add Haivision SRT protocol

2017-10-05 Thread Nablet Developer

> SRT is a subtitle format: a more specific name would be better.

for example? haivision_srt?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avformat/srt: add Haivision SRT protocol

2017-10-05 Thread Nablet Developer
protocol requires libsrt (https://github.com/Haivision/srt) to be
installed

Signed-off-by: Nablet Developer <s...@nablet.com>
---
 configure   |5 +
 libavformat/Makefile|1 +
 libavformat/protocols.c |1 +
 libavformat/srt.c   | 1105 +++
 libavformat/url.h   |4 +
 5 files changed, 1116 insertions(+)
 create mode 100644 libavformat/srt.c

diff --git a/configure b/configure
index 391c141..d955805 100755
--- a/configure
+++ b/configure
@@ -301,6 +301,7 @@ External library support:
on OSX if openssl and gnutls are not used 
[autodetect]
   --disable-xlib   disable xlib [autodetect]
   --disable-zlib   disable zlib [autodetect]
+  --enable-libsrt  enable libsrt [autodetect]
 
   The following libraries provide various hardware acceleration features:
   --disable-audiotoolbox   disable Apple AudioToolbox code [autodetect]
@@ -1638,6 +1639,7 @@ EXTERNAL_LIBRARY_LIST="
 openal
 opencl
 opengl
+libsrt
 "
 
 HWACCEL_AUTODETECT_LIBRARY_LIST="
@@ -3170,6 +3172,8 @@ tls_securetransport_protocol_select="tcp_protocol"
 tls_protocol_deps_any="tls_schannel_protocol tls_securetransport_protocol 
tls_gnutls_protocol tls_openssl_protocol"
 udp_protocol_select="network"
 udplite_protocol_select="network"
+srt_protocol_select="network"
+srt_protocol_deps="libsrt"
 unix_protocol_deps="sys_un_h"
 unix_protocol_select="network"
 
@@ -6076,6 +6080,7 @@ enabled rkmpp && { { require_pkg_config 
rockchip_mpp rockchip_mpp ro
{ enabled libdrm ||
  die "ERROR: rkmpp requires --enable-libdrm"; }
  }
+enabled libsrt   && require_pkg_config srt srt/srt.h srt_socket
 
 if enabled gcrypt; then
 GCRYPT_CONFIG="${cross_prefix}libgcrypt-config"
diff --git a/libavformat/Makefile b/libavformat/Makefile
index df709c29..695cf51 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -593,6 +593,7 @@ OBJS-$(CONFIG_TLS_SCHANNEL_PROTOCOL) += tls_schannel.o 
tls.o
 OBJS-$(CONFIG_TLS_SECURETRANSPORT_PROTOCOL) += tls_securetransport.o tls.o
 OBJS-$(CONFIG_UDP_PROTOCOL)  += udp.o
 OBJS-$(CONFIG_UDPLITE_PROTOCOL)  += udp.o
+OBJS-$(CONFIG_SRT_PROTOCOL)  += srt.o
 OBJS-$(CONFIG_UNIX_PROTOCOL) += unix.o
 
 # libavdevice dependencies
diff --git a/libavformat/protocols.c b/libavformat/protocols.c
index 8d3555e..8b4fded 100644
--- a/libavformat/protocols.c
+++ b/libavformat/protocols.c
@@ -62,6 +62,7 @@ extern const URLProtocol ff_tls_securetransport_protocol;
 extern const URLProtocol ff_tls_openssl_protocol;
 extern const URLProtocol ff_udp_protocol;
 extern const URLProtocol ff_udplite_protocol;
+extern const URLProtocol ff_srt_protocol;
 extern const URLProtocol ff_unix_protocol;
 extern const URLProtocol ff_librtmp_protocol;
 extern const URLProtocol ff_librtmpe_protocol;
diff --git a/libavformat/srt.c b/libavformat/srt.c
new file mode 100644
index 000..5950a50
--- /dev/null
+++ b/libavformat/srt.c
@@ -0,0 +1,1105 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * SRT protocol
+ */
+
+#define _DEFAULT_SOURCE
+#define _BSD_SOURCE /* Needed for using struct ip_mreq with recent glibc */
+
+#include "avformat.h"
+#include "avio_internal.h"
+#include "libavutil/avassert.h"
+#include "libavutil/parseutils.h"
+#include "libavutil/fifo.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/avstring.h"
+#include "libavutil/opt.h"
+#include "libavutil/log.h"
+#include "libavutil/time.h"
+#include "internal.h"
+#include "network.h"
+#include "os_support.h"
+#include "url.h"
+
+#ifdef __APPLE__
+#include "TargetConditionals.h"
+#endif
+
+#include 
+#include 
+
+
+#if HAVE_PTHREAD_CANCEL
+#include 
+#endif
+
+#ifndef HAVE_PTHREAD_CANCEL
+#define HAVE_PTHREAD_CANCEL 0
+#endif
+
+#ifndef IPV6_ADD_MEMBERSHIP
+#defi

[FFmpeg-devel] [PATCH] avcodec/qsvenc_h264: fix segfault when a53 SEI is not available

2016-10-04 Thread Nablet Developer
Signed-off-by: Nablet Developer <s...@nablet.com>
---
 libavcodec/qsvenc_h264.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/qsvenc_h264.c b/libavcodec/qsvenc_h264.c
index c1f6003..f5b01bb 100644
--- a/libavcodec/qsvenc_h264.c
+++ b/libavcodec/qsvenc_h264.c
@@ -53,7 +53,7 @@ static int qsv_h264_set_encode_ctrl(AVCodecContext *avctx,
 int res;
 
 res = ff_alloc_a53_sei(frame, sizeof(mfxPayload) + 2, 
(void**), _size);
-if (res < 0)
+if (res < 0 || !payload)
 return res;
 
 sei_data = (mfxU8*)(payload + 1);
-- 
1.8.3.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] hwcontext: add a QSV implementation

2016-09-17 Thread nablet developer
From: Anton Khirnov <an...@khirnov.net>

Signed-off-by: nablet developer <s...@nablet.com>
---
 libavutil/Makefile |   3 +
 libavutil/hwcontext.c  |   3 +
 libavutil/hwcontext.h  |   1 +
 libavutil/hwcontext_internal.h |   1 +
 libavutil/hwcontext_qsv.c  | 791 +
 libavutil/hwcontext_qsv.h  |  52 +++
 6 files changed, 851 insertions(+)
 create mode 100644 libavutil/hwcontext_qsv.c
 create mode 100644 libavutil/hwcontext_qsv.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 1e06176..76da7d4 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -35,6 +35,7 @@ HEADERS = adler32.h   
  \
   hwcontext.h   \
   hwcontext_cuda.h  \
   hwcontext_dxva2.h \
+  hwcontext_qsv.h   \
   hwcontext_vaapi.h \
   hwcontext_vdpau.h \
   imgutils.h\
@@ -154,6 +155,7 @@ OBJS-$(!HAVE_ATOMICS_NATIVE)+= atomic.o 
\
 
 OBJS-$(CONFIG_CUDA) += hwcontext_cuda.o
 OBJS-$(CONFIG_DXVA2)+= hwcontext_dxva2.o
+OBJS-$(CONFIG_QSV)  += hwcontext_qsv.o
 OBJS-$(CONFIG_LZO)  += lzo.o
 OBJS-$(CONFIG_OPENCL)   += opencl.o opencl_internal.o
 OBJS-$(CONFIG_VAAPI)+= hwcontext_vaapi.o
@@ -166,6 +168,7 @@ SLIBOBJS-$(HAVE_GNU_WINDRES)+= avutilres.o
 
 SKIPHEADERS-$(CONFIG_CUDA) += hwcontext_cuda.h
 SKIPHEADERS-$(CONFIG_DXVA2)+= hwcontext_dxva2.h
+SKIPHEADERS-$(CONFIG_QSV)  += hwcontext_qsv.h
 SKIPHEADERS-$(CONFIG_VAAPI)+= hwcontext_vaapi.h
 SKIPHEADERS-$(CONFIG_VDPAU)+= hwcontext_vdpau.h
 SKIPHEADERS-$(HAVE_ATOMICS_GCC)+= atomic_gcc.h
diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
index 1e9e913..be1d73e 100644
--- a/libavutil/hwcontext.c
+++ b/libavutil/hwcontext.c
@@ -35,6 +35,9 @@ static const HWContextType *hw_table[] = {
 #if CONFIG_DXVA2
 _hwcontext_type_dxva2,
 #endif
+#if CONFIG_QSV
+_hwcontext_type_qsv,
+#endif
 #if CONFIG_VAAPI
 _hwcontext_type_vaapi,
 #endif
diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h
index 4e9da02..5e2af09 100644
--- a/libavutil/hwcontext.h
+++ b/libavutil/hwcontext.h
@@ -29,6 +29,7 @@ enum AVHWDeviceType {
 AV_HWDEVICE_TYPE_CUDA,
 AV_HWDEVICE_TYPE_VAAPI,
 AV_HWDEVICE_TYPE_DXVA2,
+AV_HWDEVICE_TYPE_QSV,
 };
 
 typedef struct AVHWDeviceInternal AVHWDeviceInternal;
diff --git a/libavutil/hwcontext_internal.h b/libavutil/hwcontext_internal.h
index cf832fe..079e42b 100644
--- a/libavutil/hwcontext_internal.h
+++ b/libavutil/hwcontext_internal.h
@@ -101,6 +101,7 @@ struct AVHWFramesInternal {
 
 extern const HWContextType ff_hwcontext_type_cuda;
 extern const HWContextType ff_hwcontext_type_dxva2;
+extern const HWContextType ff_hwcontext_type_qsv;
 extern const HWContextType ff_hwcontext_type_vaapi;
 extern const HWContextType ff_hwcontext_type_vdpau;
 
diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
new file mode 100644
index 000..13be5b0
--- /dev/null
+++ b/libavutil/hwcontext_qsv.c
@@ -0,0 +1,791 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+#include 
+
+#include 
+
+#include "config.h"
+
+#if CONFIG_VAAPI
+#include "hwcontext_vaapi.h"
+#endif
+#if CONFIG_DXVA2
+#include "hwcontext_dxva2.h"
+#endif
+
+#include "buffer.h"
+#include "common.h"
+#include "hwcontext.h"
+#include "hwcontext_internal.h"
+#include "hwcontext_qsv.h"
+#include "mem.h"
+#include "pixfmt.h"
+#include "pixdesc.h"
+#include "time.h"
+
+typedef struct QSVDevicePriv {
+AVBufferRef *child_device_ctx;
+} QSVDevicePriv;
+
+typedef struct QSVDeviceContext {
+mfxHDL  h

[FFmpeg-devel] [PATCH] hwcontext: add a QSV implementation

2016-09-17 Thread nablet developer
patch is taken from libav project, authored by Anton Khirnov 
https://lists.libav.org/pipermail/libav-devel/2016-May/077126.html
the only differences from original libav patch:
1) replaced CONFIG_LIBMXF with CONFIG_QSV to match the rest of ffmpeg sources
2) changed copyright headers to match ffmpeg standard

this patch adds Intel QuickSync Video hardware context implementation to 
libavutil,
in same manner as other hardware context implementations like CUDA, VAAPI, etc.
this context will be used and shared by various Intel QuickSync Video decoders 
and
encoders component (like qsv_h264), as well as VPP filter.

Anton Khirnov (1):
  hwcontext: add a QSV implementation

 libavutil/Makefile |   3 +
 libavutil/hwcontext.c  |   3 +
 libavutil/hwcontext.h  |   1 +
 libavutil/hwcontext_internal.h |   1 +
 libavutil/hwcontext_qsv.c  | 791 +
 libavutil/hwcontext_qsv.h  |  52 +++
 6 files changed, 851 insertions(+)
 create mode 100644 libavutil/hwcontext_qsv.c
 create mode 100644 libavutil/hwcontext_qsv.h

-- 
1.8.3.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 3/6] lavc/qsv: Enable hwaccel qsv_vidmem.

2016-09-14 Thread Nablet Developer

 ffmpeg_qsv.c  | 636 +-
 libavcodec/qsv.h  |   3 +
 libavcodec/qsv_internal.h |   2 +
 libavcodec/qsvdec.c   |   5 +-
 libavcodec/qsvenc.c   |   2 +
 8 files changed, 649 insertions(+), 5 deletions(-)



This is a giant patch that doesnt even begin to describe what it does.
So, whats it good for? We can already do transcoding of video from QSV
decoder to QSV encoder all in GPU memory without 600+ lines of new
code. Admittedly it currently has a few issues, but those could be
fixed, but why do we need 600 new lines of code?


1.  In GPU level, all frames are processed in tiled mode (we called 
video memory mode) which cannot be read/write by cpu directly. The frame 
buffer should be allocated via vaCreateSurface. Any non-tiled memory 
must be copied to tiled memory when using GPU acceleration. The copying 
task is done by MediaSDK internally.


2.  In current implementation, frame buffer is allocated by ffmpeg 
in linear mode (we called system memory) ; QSV deocder’s output and QSV 
encoder’s input are all set to video memory mode ( e.g. iopattern  = 
MFX_IOPATTERN_OUT_SYSTEM_MEMORY in qsv decoder); so there are 2 memory 
copy processes in mediaSDK: one is copying from video_memory to system 
memory when output from HW decoder, another is copying from system 
memory to video memory when feeding to HW encoder. It will decrease 
transcoding performance greatly, especially for  high resolution such as 
1080 & 4K.


3.  The patches are avoiding such additional memory copy when all 
modules in transcoding pipeline can be accelerated by GPU. To achieving 
it, iopattern must be set to video_memory, and an external allocator 
must be implemented as mediaSDK requirements, and set it to QSV codec. 
Most of the 600 lines in the patches are the code to implement the 
external allocator. At the same time, the patches also add some code to 
checking whether all modules in transcoding pipeline can be accelerated 
by GPU or not, so that transcoder can select video-memory or 
system-memory automatically.


4.  As our test, the transcoding performance can be improved about 
20% or more according to resolution with patches. And it can reach the 
performance which is declared in QSV specification.


___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 6/6] lavc/qsv-lavc/vpp: Promote gpu_copy to be a selectable parameter. GPU-copy is defaultly closed because it seems to be unstable.

2016-08-25 Thread Nablet Developer
From: ChaoX A Liu 

Signed-off-by: ChaoX A Liu 
---
 libavcodec/qsv.c  |  7 ++-
 libavcodec/qsv_internal.h |  1 +
 libavcodec/qsvdec.c   | 22 +-
 libavcodec/qsvdec_h2645.c | 12 
 libavcodec/qsvdec_mpeg2.c |  6 ++
 libavcodec/qsvdec_vc1.c   |  6 ++
 libavcodec/qsvenc.h   |  4 
 libavfilter/vf_qsvvpp.c   |  8 +++-
 8 files changed, 59 insertions(+), 7 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index c180ca8..c61a29c 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -172,11 +172,16 @@ int ff_qsv_init_internal_session(void *avctx, QSVSession 
*qs)
 {
 mfxIMPL impl   = MFX_IMPL_AUTO_ANY;
 mfxVersion ver = { { QSV_VERSION_MINOR, QSV_VERSION_MAJOR } };
+mfxInitParam par;
 
 const char *desc;
 int ret;
 
-ret = MFXInit(impl, , >session);
+memset(, 0, sizeof(par));
+par.Implementation = impl;
+par.Version = ver;
+par.GPUCopy = qs->gpu_copy;
+ret = MFXInitEx(par, >session);
 if (ret < 0) {
 av_log(avctx, AV_LOG_ERROR, "Error initializing an internal MFX 
session\n");
 return ff_qsv_error(ret);
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 58589df..39778a9 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -73,6 +73,7 @@ typedef struct QSVSession {
 intfd_display;
 VADisplay  va_display;
 #endif
+intgpu_copy;
 } QSVSession;
 
 /**
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 2075a23..08a5eaa 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -176,13 +176,25 @@ static int alloc_frame(AVCodecContext *avctx, QSVFrame 
*frame)
 {
 int ret;
 
-ret = ff_get_buffer(avctx, frame->frame, AV_GET_BUFFER_FLAG_REF);
-if (ret < 0)
-return ret;
-
-if (frame->frame->format == AV_PIX_FMT_QSV) {
+if (avctx->pix_fmt == AV_PIX_FMT_QSV) {
+ret = ff_get_buffer(avctx, frame->frame, AV_GET_BUFFER_FLAG_REF);
+if (ret < 0)
+return ret;
 frame->surface = (mfxFrameSurface1*)frame->frame->data[3];
 } else {
+/*
+ * Align frame's width x height to 128x64.
+ * It's recommended to do so if GPU_Copy is turned on.
+ */
+frame->frame->format = avctx->pix_fmt;
+frame->frame->width  = FFALIGN(avctx->width, 128);
+frame->frame->height = FFALIGN(avctx->height, 64);
+ret = av_frame_get_buffer(frame->frame, 64);
+if (ret < 0)
+return ret;
+frame->frame->width  = avctx->width;
+frame->frame->height = avctx->height;
+
 frame->surface_internal.Info.BitDepthLuma   = 8;
 frame->surface_internal.Info.BitDepthChroma = 8;
 frame->surface_internal.Info.FourCC = MFX_FOURCC_NV12;
diff --git a/libavcodec/qsvdec_h2645.c b/libavcodec/qsvdec_h2645.c
index 208302b..a4adc10 100755
--- a/libavcodec/qsvdec_h2645.c
+++ b/libavcodec/qsvdec_h2645.c
@@ -248,6 +248,12 @@ static const AVOption hevc_options[] = {
 
 { "load_plugins", "A :-separate list of hexadecimal plugin UIDs to load in 
an internal session",
 OFFSET(qsv.load_plugins), AV_OPT_TYPE_STRING, { .str = "" }, 0, 0, VD 
},
+
+{ "gpu_copy", "Enable gpu copy in sysmem mode [default = off]", 
OFFSET(qsv.internal_qs.gpu_copy), AV_OPT_TYPE_INT, { .i64 = MFX_GPUCOPY_OFF }, 
MFX_GPUCOPY_DEFAULT, MFX_GPUCOPY_OFF, .flags = VD, "gpu_copy" },
+{ "default",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_DEFAULT }, 
0, 0, .flags = VD, "gpu_copy" },
+{ "on",   NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_ON },  
0, 0, .flags = VD, "gpu_copy" },
+{ "off",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_OFF }, 
0, 0, .flags = VD, "gpu_copy" },
+
 { NULL },
 };
 
@@ -286,6 +292,12 @@ AVHWAccel ff_h264_qsv_hwaccel = {
 
 static const AVOption options[] = {
 { "async_depth", "Internal parallelization depth, the higher the value the 
higher the latency.", OFFSET(qsv.async_depth), AV_OPT_TYPE_INT, { .i64 = 
ASYNC_DEPTH_DEFAULT }, 0, INT_MAX, VD },
+
+{ "gpu_copy", "Enable gpu copy in sysmem mode [default = off]", 
OFFSET(qsv.internal_qs.gpu_copy), AV_OPT_TYPE_INT, { .i64 = MFX_GPUCOPY_OFF }, 
MFX_GPUCOPY_DEFAULT, MFX_GPUCOPY_OFF, .flags = VD, "gpu_copy" },
+{ "default",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_DEFAULT }, 
0, 0, .flags = VD, "gpu_copy" },
+{ "on",   NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_ON },  
0, 0, .flags = VD, "gpu_copy" },
+{ "off",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_OFF }, 
0, 0, .flags = VD, "gpu_copy" },
+
 { NULL },
 };
 
diff --git a/libavcodec/qsvdec_mpeg2.c b/libavcodec/qsvdec_mpeg2.c
index 70ccbc5..5e2354a 100644
--- a/libavcodec/qsvdec_mpeg2.c
+++ b/libavcodec/qsvdec_mpeg2.c
@@ -72,6 +72,12 @@ AVHWAccel ff_mpeg2_qsv_hwaccel = {
 #define VD AV_OPT_FLAG_VIDEO_PARAM | 

[FFmpeg-devel] [PATCH 2/6] lavf/vpp: Enable vpp filter, an Intel GPU accelerated scaler.

2016-08-25 Thread Nablet Developer
From: ChaoX A Liu 

Signed-off-by: ChaoX A Liu 
---
 configure |   3 +
 libavcodec/qsv.c  |   2 +-
 libavcodec/qsv_internal.h |   2 +-
 libavfilter/Makefile  |   1 +
 libavfilter/allfilters.c  |   1 +
 libavfilter/vf_qsvvpp.c   | 864 ++
 6 files changed, 871 insertions(+), 2 deletions(-)
 create mode 100644 libavfilter/vf_qsvvpp.c

diff --git a/configure b/configure
index 5b017fd..525efae 100755
--- a/configure
+++ b/configure
@@ -2086,6 +2086,7 @@ CONFIG_EXTRA="
 qsv
 qsvdec
 qsvenc
+qsvvpp
 rangecoder
 riffdec
 riffenc
@@ -3044,6 +3045,8 @@ phase_filter_deps="gpl"
 pp7_filter_deps="gpl"
 pp_filter_deps="gpl postproc"
 pullup_filter_deps="gpl"
+qsvvpp_filter_deps="libmfx"
+qsvvpp_filter_select="qsv"
 removelogo_filter_deps="avcodec avformat swscale"
 repeatfields_filter_deps="gpl"
 resample_filter_deps="avresample"
diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index b505e14..c180ca8 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -168,7 +168,7 @@ static int ff_qsv_set_display_handle(AVCodecContext *avctx, 
QSVSession *qs)
  * @param avctxffmpeg metadata for this codec context
  * @param session  the MSDK session used
  */
-int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs)
+int ff_qsv_init_internal_session(void *avctx, QSVSession *qs)
 {
 mfxIMPL impl   = MFX_IMPL_AUTO_ANY;
 mfxVersion ver = { { QSV_VERSION_MINOR, QSV_VERSION_MAJOR } };
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 59d1336..e43728b 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -80,7 +80,7 @@ int ff_qsv_error(int mfx_err);
 
 int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id);
 
-int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs);
+int ff_qsv_init_internal_session(void *avctx, QSVSession *qs);
 
 int ff_qsv_load_plugins(mfxSession session, const char *load_plugins);
 
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 9dc524f..f53ff7a 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -236,6 +236,7 @@ OBJS-$(CONFIG_PP7_FILTER)+= vf_pp7.o
 OBJS-$(CONFIG_PSNR_FILTER)   += vf_psnr.o dualinput.o 
framesync.o
 OBJS-$(CONFIG_PULLUP_FILTER) += vf_pullup.o
 OBJS-$(CONFIG_QP_FILTER) += vf_qp.o
+OBJS-$(CONFIG_QSVVPP_FILTER) += vf_qsvvpp.o
 OBJS-$(CONFIG_RANDOM_FILTER) += vf_random.o
 OBJS-$(CONFIG_READVITC_FILTER)   += vf_readvitc.o
 OBJS-$(CONFIG_REALTIME_FILTER)   += f_realtime.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 05fa9c4..f7de5a5 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -252,6 +252,7 @@ void avfilter_register_all(void)
 REGISTER_FILTER(PSNR,   psnr,   vf);
 REGISTER_FILTER(PULLUP, pullup, vf);
 REGISTER_FILTER(QP, qp, vf);
+REGISTER_FILTER(QSVVPP, qsvvpp, vf);
 REGISTER_FILTER(RANDOM, random, vf);
 REGISTER_FILTER(READVITC,   readvitc,   vf);
 REGISTER_FILTER(REALTIME,   realtime,   vf);
diff --git a/libavfilter/vf_qsvvpp.c b/libavfilter/vf_qsvvpp.c
new file mode 100644
index 000..3a5d4d3
--- /dev/null
+++ b/libavfilter/vf_qsvvpp.c
@@ -0,0 +1,864 @@
+/*
+ * Intel MediaSDK Quick Sync Video VPP filter
+ *
+ * copyright (c) 2015 Sven Dueking
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "internal.h"
+#include 
+#include "libavutil/parseutils.h"
+#include "libavutil/timestamp.h"
+#include "libavcodec/qsv.h"
+
+/**
+ * ToDo :
+ *
+ * - double check surface pointers for different fourccs
+ * - handle empty extbuffers
+ * - cropping
+ * - use AV_PIX_FMT_QSV to pass surfaces to encoder
+ * - deinterlace check settings etc.
+ * - allocate number of surfaces depending modules and number of b frames
+ */
+
+#define VPP_ZERO_MEMORY(VAR){ memset(, 0, sizeof(VAR)); }
+#define VPP_ALIGN16(value)  (((value + 15) >> 4) << 4)  // 
round up to a multiple of 16
+#define VPP_ALIGN32(value)  

[FFmpeg-devel] [PATCH 1/6] lavc/qsv(hevc): Change default plugin from hevc_sw to hevc_default, which will load hevc_hw first, due to newly released MSDK.

2016-08-25 Thread Nablet Developer
From: ChaoX A Liu 

Signed-off-by: ChaoX A Liu 
---
 libavcodec/qsv.c  | 89 ---
 libavcodec/qsv_internal.h |  6 ++--
 libavcodec/qsvdec.c   | 16 ++---
 libavcodec/qsvdec_h2645.c | 17 ++---
 libavcodec/qsvenc.c   | 12 +--
 libavcodec/qsvenc_hevc.c  | 19 +-
 6 files changed, 104 insertions(+), 55 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 11d453d..b505e14 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -168,8 +168,7 @@ static int ff_qsv_set_display_handle(AVCodecContext *avctx, 
QSVSession *qs)
  * @param avctxffmpeg metadata for this codec context
  * @param session  the MSDK session used
  */
-int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs,
- const char *load_plugins)
+int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs)
 {
 mfxIMPL impl   = MFX_IMPL_AUTO_ANY;
 mfxVersion ver = { { QSV_VERSION_MINOR, QSV_VERSION_MAJOR } };
@@ -187,67 +186,87 @@ int ff_qsv_init_internal_session(AVCodecContext *avctx, 
QSVSession *qs,
 if (ret < 0)
 return ret;
 
+MFXQueryIMPL(qs->session, );
+
+switch (MFX_IMPL_BASETYPE(impl)) {
+case MFX_IMPL_SOFTWARE:
+desc = "software";
+break;
+case MFX_IMPL_HARDWARE:
+case MFX_IMPL_HARDWARE2:
+case MFX_IMPL_HARDWARE3:
+case MFX_IMPL_HARDWARE4:
+desc = "hardware accelerated";
+break;
+default:
+desc = "unknown";
+}
+
+av_log(avctx, AV_LOG_VERBOSE,
+   "Initialized an internal MFX session using %s implementation\n",
+   desc);
+
+return 0;
+}
+
+/**
+ * @brief Load plugins for a MSDK session
+ *
+ * Media SDK may need external plugins to decode/encode,
+ * such as hevc_dec and hevc_enc. So it's necessary to load
+ * proper plugins.
+ *
+ * @param session   the MSDK session used
+ * @param load_plugins  the load_plugins to be loaded.
+ */
+int ff_qsv_load_plugins(mfxSession session, const char *load_plugins)
+{
+int err = 0, load_num = 0, i;
+
 if (load_plugins && *load_plugins) {
 while (*load_plugins) {
 mfxPluginUID uid;
-int i, err = 0;
 
 char *plugin = av_get_token(_plugins, ":");
 if (!plugin)
 return AVERROR(ENOMEM);
 if (strlen(plugin) != 2 * sizeof(uid.Data)) {
-av_log(avctx, AV_LOG_ERROR, "Invalid plugin UID length\n");
 err = AVERROR(EINVAL);
 goto load_plugin_fail;
 }
+if (*load_plugins == ':')
+load_plugins ++;
 
 for (i = 0; i < sizeof(uid.Data); i++) {
 err = sscanf(plugin + 2 * i, "%2hhx", uid.Data + i);
 if (err != 1) {
-av_log(avctx, AV_LOG_ERROR, "Invalid plugin UID\n");
 err = AVERROR(EINVAL);
 goto load_plugin_fail;
 }
-
 }
 
-ret = MFXVideoUSER_Load(qs->session, , 1);
-if (ret < 0) {
-av_log(avctx, AV_LOG_ERROR, "Could not load the requested 
plugin: %s\n",
-   plugin);
-err = ff_qsv_error(ret);
+err = MFXVideoUSER_Load(session, , 1);
+if (err < 0) {
+err = ff_qsv_error(err);
 goto load_plugin_fail;
 }
+load_num ++;
 
-if (*load_plugins)
-load_plugins++;
 load_plugin_fail:
 av_freep();
-if (err < 0)
-return err;
+/*
+ * If more plugins are going to be loaded,
+ * ignore current error and continue.
+ */
+if (*load_plugins == ':') {
+load_plugins ++;
+err = 0;
+}
 }
+if (!load_num)
+return err;
 }
 
-MFXQueryIMPL(qs->session, );
-
-switch (MFX_IMPL_BASETYPE(impl)) {
-case MFX_IMPL_SOFTWARE:
-desc = "software";
-break;
-case MFX_IMPL_HARDWARE:
-case MFX_IMPL_HARDWARE2:
-case MFX_IMPL_HARDWARE3:
-case MFX_IMPL_HARDWARE4:
-desc = "hardware accelerated";
-break;
-default:
-desc = "unknown";
-}
-
-av_log(avctx, AV_LOG_VERBOSE,
-   "Initialized an internal MFX session using %s implementation\n",
-   desc);
-
 return 0;
 }
 
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index f289a2b..59d1336 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -80,8 +80,10 @@ int ff_qsv_error(int mfx_err);
 
 int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id);
 
-int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs,
- const char *load_plugins);
+int 

[FFmpeg-devel] [PATCH 4/6] lavf/vpp: enable video memory accel for transcoding with vpp. lavc/qsv: export symbols "ff_qsv_*" which will be used by vpp. ffmpeg_qsv: set default hwaccel to qsv.

2016-08-25 Thread Nablet Developer
From: ChaoX A Liu 

Signed-off-by: ChaoX A Liu 
---
 ffmpeg_qsv.c|  46 ---
 libavcodec/libavcodec.v |   1 +
 libavcodec/qsv.h|   2 +
 libavfilter/vf_qsvvpp.c | 153 
 4 files changed, 172 insertions(+), 30 deletions(-)

diff --git a/ffmpeg_qsv.c b/ffmpeg_qsv.c
index 43402d6..aed9240 100644
--- a/ffmpeg_qsv.c
+++ b/ffmpeg_qsv.c
@@ -386,7 +386,7 @@ static mfxStatus frame_alloc(mfxHDL pthis, 
mfxFrameAllocRequest *request, mfxFra
 unsigned int va_fourcc = 0;
 mfxU32 fourcc = request->Info.FourCC;
 QSVContext *q = pthis;
-AVQSVContext *qsv = q->ost->enc_ctx->hwaccel_context;
+AVQSVContext *qsv = NULL;
 mfxU16 numAllocated = 0;
 bool bCreateSrfSucceeded = false;
 mfxU32 mfx_fourcc;
@@ -394,17 +394,40 @@ static mfxStatus frame_alloc(mfxHDL pthis, 
mfxFrameAllocRequest *request, mfxFra
 int width32;
 int height32;
 void *avctx = NULL;
+FilterGraph *fg = q->ost->filter->graph;
 
-av_log(avctx, AV_LOG_INFO, "=vaapi alloc frame==\n");
 if (!request || !response || !request->NumFrameSuggested)
 return MFX_ERR_MEMORY_ALLOC;
 
 memset(response, 0, sizeof(*response));
 surface_num = request->NumFrameSuggested;
-if ((request->Type & MFX_MEMTYPE_EXTERNAL_FRAME) &&
-(request->Type & MFX_MEMTYPE_FROM_DECODE))
-surface_num += (qsv->nb_encoder_surfaces + qsv->nb_decoder_surfaces);
+if (request->Type & MFX_MEMTYPE_FROM_DECODE) {
+avctx = input_streams[q->ost->source_index]->dec_ctx;
+if (request->Type & MFX_MEMTYPE_EXTERNAL_FRAME) {
+AVFilterContext *qsvvpp = avfilter_graph_get_filter(fg->graph, 
"Parsed_qsvvpp_0");
+qsv = 
input_streams[q->ost->source_index]->dec_ctx->hwaccel_context;
+surface_num += qsv->nb_decoder_surfaces;
+if (qsvvpp) {
+qsv = qsvvpp->hw_device_ctx->data;
+surface_num += qsv->nb_vpp_surfaces;
+} else {
+qsv = q->ost->enc_ctx->hwaccel_context;
+surface_num += qsv->nb_encoder_surfaces;
+}
+}
+} else if (request->Type & MFX_MEMTYPE_FROM_VPPOUT) {
+AVFilterContext *qsvvpp = avfilter_graph_get_filter(fg->graph, 
"Parsed_qsvvpp_0");
+avctx = qsvvpp;
+if (request->Type & MFX_MEMTYPE_EXTERNAL_FRAME) {
+qsv = q->ost->enc_ctx->hwaccel_context;
+surface_num += qsv->nb_encoder_surfaces;
+}
+} else if (request->Type & MFX_MEMTYPE_FROM_ENCODE) {
+avctx = q->ost->enc_ctx;
+} else
+av_log(avctx, AV_LOG_WARNING, "FrameAlloc: may get a bug.\n");
 
+av_log(avctx, AV_LOG_INFO, "=vaapi alloc frame==\n");
 av_log(avctx, AV_LOG_INFO, "VAAPI: va_dpy =%p, surface_num=%d, width=%d, 
height=%d\n",
 g_session.va_display, surface_num, request->Info.Width, 
request->Info.Height);
 av_log(avctx, AV_LOG_INFO, "VAAPI: request->Type=%x\n",request->Type);
@@ -720,7 +743,7 @@ static int qsv_check_filters(const OutputStream *ost)
 AVFilterInOut *inputs, *outputs;
 int ret = 0;
 int i;
-const char *filter_list = "buffer|buffersink|null|format|setpts";
+const char *filter_list = "buffer|buffersink|null|format|setpts|qsvvpp";
 
 if (!ost->avfilter)
 return -1;
@@ -820,6 +843,7 @@ int qsv_transcode_init_vidmem(OutputStream *ost)
 
 QSVContext *qsv = NULL;
 AVQSVContext *enc_hwctx = NULL;
+AVQSVContext *vpp_hwctx = NULL;
 
 /* check if the encoder supports QSV */
 if (!ost->enc->pix_fmts)
@@ -836,6 +860,8 @@ int qsv_transcode_init_vidmem(OutputStream *ost)
 
 /* check if the decoder supports QSV and the output only goes to this 
stream */
 ist = input_streams[ost->source_index];
+if (ist->hwaccel_id == HWACCEL_NONE || ist->hwaccel_id == HWACCEL_AUTO)
+ist->hwaccel_id = HWACCEL_QSV;
 if (ist->nb_filters || ist->hwaccel_id != HWACCEL_QSV ||
 !ist->dec || !ist->dec->pix_fmts)
 return 0;
@@ -854,7 +880,8 @@ int qsv_transcode_init_vidmem(OutputStream *ost)
 
 qsv   = av_mallocz(sizeof(*qsv));
 enc_hwctx = av_qsv_alloc_context();
-if (!qsv || !enc_hwctx)
+vpp_hwctx = av_qsv_alloc_context();
+if (!qsv || !enc_hwctx || !vpp_hwctx)
 goto fail;
 
 err = ff_qsv_init_internal_session(NULL, _session);
@@ -891,6 +918,11 @@ int qsv_transcode_init_vidmem(OutputStream *ost)
 ist->resample_pix_fmt= AV_PIX_FMT_QSV;
 ist->hwaccel_ctx = qsv;
 
+vpp_hwctx->session   = qsv->session;
+vpp_hwctx->iopattern = MFX_IOPATTERN_IN_VIDEO_MEMORY;
+vpp_hwctx->pFrameAllocator   = >frame_allocator;
+hw_device_ctx = av_buffer_create(vpp_hwctx, sizeof(*vpp_hwctx), 
av_buffer_default_free, NULL, 0);
+
 return 0;
 
 fail:
diff --git a/libavcodec/libavcodec.v 

[FFmpeg-devel] [PATCH 0/6] fixes for HEVC GPU accelerated codec (v2)

2016-08-25 Thread Nablet Developer
From: ChaoX A Liu 

This is updated version of patchset.

Fix for license reference.
Rename vpp filter to qsvvpp



ChaoX A Liu (6):
  lavc/qsv(hevc): Change default plugin from hevc_sw to hevc_default,
which will load hevc_hw first, due to newly released MSDK.
  lavf/vpp: Enable vpp filter, an Intel GPU accelerated scaler.
  lavc/qsv: Enable hwaccel qsv_vidmem.
  lavf/vpp: enable video memory accel for transcoding with vpp. 
lavc/qsv: export symbols "ff_qsv_*" which will be used by vpp.
ffmpeg_qsv: set default hwaccel to qsv.
  lavc/qsvdec: Reset decoder if MFX_ERR_UNDEFINED_BEHAVIOR is caught,
because this error may get decoder stuck.
  lavc/qsv-lavc/vpp: Promote gpu_copy to be a selectable parameter.
GPU-copy is defaultly closed because it seems to be unstable.

 configure |   3 +
 ffmpeg.c  |   2 +-
 ffmpeg.h  |   2 +
 ffmpeg_opt.c  |   2 +-
 ffmpeg_qsv.c  | 668 ++-
 libavcodec/libavcodec.v   |   1 +
 libavcodec/qsv.c  |  96 +++--
 libavcodec/qsv.h  |   5 +
 libavcodec/qsv_internal.h |   9 +-
 libavcodec/qsvdec.c   |  52 ++-
 libavcodec/qsvdec_h2645.c |  29 +-
 libavcodec/qsvdec_mpeg2.c |   6 +
 libavcodec/qsvdec_vc1.c   |   6 +
 libavcodec/qsvenc.c   |  14 +-
 libavcodec/qsvenc.h   |   4 +
 libavcodec/qsvenc_hevc.c  |  19 +-
 libavfilter/Makefile  |   1 +
 libavfilter/allfilters.c  |   1 +
 libavfilter/vf_qsvvpp.c   | 977 ++
 19 files changed, 1829 insertions(+), 68 deletions(-)
 create mode 100644 libavfilter/vf_qsvvpp.c

-- 
2.5.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 5/6] lavc/qsvdec: Reset decoder if MFX_ERR_UNDEFINED_BEHAVIOR is caught, because this error may get decoder stuck.

2016-08-25 Thread Nablet Developer
From: ChaoX A Liu 

Signed-off-by: ChaoX A Liu 
---
 libavcodec/qsvdec.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 47dd818..2075a23 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -370,13 +370,18 @@ static int do_qsv_decode(AVCodecContext *avctx, 
QSVContext *q,
 av_usleep(500);
 } while (1);
 
-if (MFX_WRN_VIDEO_PARAM_CHANGED==ret) {
+if (MFX_WRN_VIDEO_PARAM_CHANGED == ret) {
 /* TODO: handle here minor sequence header changing */
-} else if (MFX_ERR_INCOMPATIBLE_VIDEO_PARAM==ret) {
+} else if (MFX_ERR_INCOMPATIBLE_VIDEO_PARAM == ret) {
 av_fifo_reset(q->input_fifo);
 flush = q->reinit_pending = 1;
 continue;
-}
+} else if (MFX_ERR_UNDEFINED_BEHAVIOR == ret)
+/*
+ * Decoder may get stuck with this errorcode.
+ * Reset decoder to avoid that.
+ */
+ff_qsv_decode_reset(avctx, q);
 
 if (sync) {
 QSVFrame *out_frame = find_frame(q, outsurf);
-- 
2.5.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 3/6] lavc/qsv: Enable hwaccel qsv_vidmem.

2016-08-25 Thread Nablet Developer
From: ChaoX A Liu 

Signed-off-by: ChaoX A Liu 
---
 ffmpeg.c  |   2 +-
 ffmpeg.h  |   2 +
 ffmpeg_opt.c  |   2 +-
 ffmpeg_qsv.c  | 636 +-
 libavcodec/qsv.h  |   3 +
 libavcodec/qsv_internal.h |   2 +
 libavcodec/qsvdec.c   |   5 +-
 libavcodec/qsvenc.c   |   2 +
 8 files changed, 649 insertions(+), 5 deletions(-)

diff --git a/ffmpeg.c b/ffmpeg.c
index bad311d..0bab9e9 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -3050,7 +3050,7 @@ static int transcode_init(void)
 set_encoder_id(output_files[ost->file_index], ost);
 
 #if CONFIG_LIBMFX
-if (qsv_transcode_init(ost))
+if (qsv_transcode_init_vidmem(ost))
 exit_program(1);
 #endif
 
diff --git a/ffmpeg.h b/ffmpeg.h
index 49d65d8..266 100644
--- a/ffmpeg.h
+++ b/ffmpeg.h
@@ -585,6 +585,8 @@ int vda_init(AVCodecContext *s);
 int videotoolbox_init(AVCodecContext *s);
 int qsv_init(AVCodecContext *s);
 int qsv_transcode_init(OutputStream *ost);
+int qsv_init_vidmem(AVCodecContext *s);
+int qsv_transcode_init_vidmem(OutputStream *ost);
 int vaapi_decode_init(AVCodecContext *avctx);
 int vaapi_device_init(const char *device);
 int cuvid_init(AVCodecContext *s);
diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
index 2ea09cf..b5e4483 100644
--- a/ffmpeg_opt.c
+++ b/ffmpeg_opt.c
@@ -79,7 +79,7 @@ const HWAccel hwaccels[] = {
 { "videotoolbox",   videotoolbox_init,   HWACCEL_VIDEOTOOLBOX,   
AV_PIX_FMT_VIDEOTOOLBOX },
 #endif
 #if CONFIG_LIBMFX
-{ "qsv",   qsv_init,   HWACCEL_QSV,   AV_PIX_FMT_QSV },
+{ "qsv",   qsv_init_vidmem,   HWACCEL_QSV,   AV_PIX_FMT_QSV },
 #endif
 #if CONFIG_VAAPI
 { "vaapi", vaapi_decode_init, HWACCEL_VAAPI, AV_PIX_FMT_VAAPI },
diff --git a/ffmpeg_qsv.c b/ffmpeg_qsv.c
index acc54dd..43402d6 100644
--- a/ffmpeg_qsv.c
+++ b/ffmpeg_qsv.c
@@ -18,11 +18,15 @@
 
 #include 
 #include 
+#include 
+#include 
 
 #include "libavutil/dict.h"
 #include "libavutil/mem.h"
 #include "libavutil/opt.h"
+#include "libavutil/avstring.h"
 #include "libavcodec/qsv.h"
+#include "libavcodec/qsv_internal.h"
 
 #include "ffmpeg.h"
 
@@ -34,6 +38,8 @@ typedef struct QSVContext {
 mfxExtOpaqueSurfaceAlloc opaque_alloc;
 AVBufferRef *opaque_surfaces_buf;
 
+mfxFrameAllocator frame_allocator;
+
 uint8_t   *surface_used;
 mfxFrameSurface1 **surface_ptrs;
 int nb_surfaces;
@@ -60,7 +66,7 @@ static int qsv_get_buffer(AVCodecContext *s, AVFrame *frame, 
int flags)
  buffer_release, 
>surface_used[i], 0);
 if (!frame->buf[0])
 return AVERROR(ENOMEM);
-frame->data[3]   = (uint8_t*)qsv->surface_ptrs[i];
+frame->data[3]   = frame->buf[0]->data;
 qsv->surface_used[i] = 1;
 return 0;
 }
@@ -265,3 +271,631 @@ fail:
 av_freep();
 return AVERROR_UNKNOWN;
 }
+
+enum {
+MFX_FOURCC_VP8_NV12= MFX_MAKEFOURCC('V','P','8','N'),
+MFX_FOURCC_VP8_MBDATA  = MFX_MAKEFOURCC('V','P','8','M'),
+MFX_FOURCC_VP8_SEGMAP  = MFX_MAKEFOURCC('V','P','8','S'),
+};
+
+typedef struct vaapiMemId
+{
+VASurfaceID* m_surface;
+VAImage m_image;
+unsigned int m_fourcc;
+mfxU8* m_sys_buffer;
+mfxU8* m_va_buffer;
+} vaapiMemId;
+
+static QSVSession g_session;
+
+/* 
** 
*\
+
+INTEL CORPORATION PROPRIETARY INFORMATION
+This software is supplied under the terms of a license agreement or 
nondisclosure
+agreement with Intel Corporation and may not be copied or disclosed except in
+accordance with the terms of that agreement
+Copyright(c) 2011-2014 Intel Corporation. All Rights Reserved.
+
+\* 
** 
*/
+static mfxStatus va_to_mfx_status(VAStatus va_res)
+{
+mfxStatus mfxRes = MFX_ERR_NONE;
+
+switch (va_res) {
+case VA_STATUS_SUCCESS:
+mfxRes = MFX_ERR_NONE;
+break;
+case VA_STATUS_ERROR_ALLOCATION_FAILED:
+mfxRes = MFX_ERR_MEMORY_ALLOC;
+break;
+case VA_STATUS_ERROR_ATTR_NOT_SUPPORTED:
+case VA_STATUS_ERROR_UNSUPPORTED_PROFILE:
+case VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT:
+case VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT:
+case VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE:
+case VA_STATUS_ERROR_FLAG_NOT_SUPPORTED:
+case VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED:
+mfxRes = MFX_ERR_UNSUPPORTED;
+break;
+case VA_STATUS_ERROR_INVALID_DISPLAY:
+case VA_STATUS_ERROR_INVALID_CONFIG:
+case VA_STATUS_ERROR_INVALID_CONTEXT:
+case VA_STATUS_ERROR_INVALID_SURFACE:
+case VA_STATUS_ERROR_INVALID_BUFFER:
+case VA_STATUS_ERROR_INVALID_IMAGE:
+case VA_STATUS_ERROR_INVALID_SUBPICTURE:
+

Re: [FFmpeg-devel] [PATCH 2/6] lavf/vpp: Enable vpp filter, an Intel GPU accelerated scaler.

2016-08-22 Thread Nablet Developer

Hi Micheal,

Sure. Fixed. Will send with other changes (if other comments will 
require them)



On 16.08.2016 21:33, Michael Niedermayer wrote:

On Tue, Aug 16, 2016 at 05:10:03PM +0700, Nablet Developer wrote:

From: ChaoX A Liu <chaox.a@intel.com>

Signed-off-by: ChaoX A Liu <chaox.a@intel.com>
---
  configure |   3 +
  libavcodec/qsv.c  |   2 +-
  libavcodec/qsv_internal.h |   2 +-
  libavfilter/Makefile  |   1 +
  libavfilter/allfilters.c  |   1 +
  libavfilter/vf_vpp.c  | 863 ++
  6 files changed, 870 insertions(+), 2 deletions(-)
  create mode 100644 libavfilter/vf_vpp.c


[...]

diff --git a/libavfilter/vf_vpp.c b/libavfilter/vf_vpp.c
new file mode 100644
index 000..0cfeafc
--- /dev/null
+++ b/libavfilter/vf_vpp.c
@@ -0,0 +1,863 @@
+/*
+ * Intel MediaSDK Quick Sync Video VPP filter
+ *
+ * copyright (c) 2015 Sven Dueking
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *



+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software

  ^

We have to refer to the license included in FFmpeg


[...]



___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/6] lavf/vpp: Enable vpp filter, an Intel GPU accelerated scaler.

2016-08-22 Thread Nablet Developer

Hi Paul,

Do you have any ideas of better name for this?

The term VPP is Video Processing Pipeline. This
abbreviation is used by Intel in their documentation.
Ex https://software.intel.com/en-us/node/628415



On 16.08.2016 17:14, Paul B Mahol wrote:

On 8/16/16, Nablet Developer <s...@nablet.com> wrote:

From: ChaoX A Liu <chaox.a@intel.com>

Signed-off-by: ChaoX A Liu <chaox.a@intel.com>
---
  configure |   3 +
  libavcodec/qsv.c  |   2 +-
  libavcodec/qsv_internal.h |   2 +-
  libavfilter/Makefile  |   1 +
  libavfilter/allfilters.c  |   1 +
  libavfilter/vf_vpp.c  | 863
++
  6 files changed, 870 insertions(+), 2 deletions(-)
  create mode 100644 libavfilter/vf_vpp.c



vpp is too short and cryptic name IMHO.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 1/6] lavc/qsv(hevc): Change default plugin from hevc_sw to hevc_default, which will load hevc_hw first, due to newly released MSDK.

2016-08-16 Thread Nablet Developer
From: ChaoX A Liu 

Signed-off-by: ChaoX A Liu 
---
 libavcodec/qsv.c  | 89 ---
 libavcodec/qsv_internal.h |  6 ++--
 libavcodec/qsvdec.c   | 16 ++---
 libavcodec/qsvdec_h2645.c | 17 ++---
 libavcodec/qsvenc.c   | 12 +--
 libavcodec/qsvenc_hevc.c  | 19 +-
 6 files changed, 104 insertions(+), 55 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 11d453d..b505e14 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -168,8 +168,7 @@ static int ff_qsv_set_display_handle(AVCodecContext *avctx, 
QSVSession *qs)
  * @param avctxffmpeg metadata for this codec context
  * @param session  the MSDK session used
  */
-int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs,
- const char *load_plugins)
+int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs)
 {
 mfxIMPL impl   = MFX_IMPL_AUTO_ANY;
 mfxVersion ver = { { QSV_VERSION_MINOR, QSV_VERSION_MAJOR } };
@@ -187,67 +186,87 @@ int ff_qsv_init_internal_session(AVCodecContext *avctx, 
QSVSession *qs,
 if (ret < 0)
 return ret;
 
+MFXQueryIMPL(qs->session, );
+
+switch (MFX_IMPL_BASETYPE(impl)) {
+case MFX_IMPL_SOFTWARE:
+desc = "software";
+break;
+case MFX_IMPL_HARDWARE:
+case MFX_IMPL_HARDWARE2:
+case MFX_IMPL_HARDWARE3:
+case MFX_IMPL_HARDWARE4:
+desc = "hardware accelerated";
+break;
+default:
+desc = "unknown";
+}
+
+av_log(avctx, AV_LOG_VERBOSE,
+   "Initialized an internal MFX session using %s implementation\n",
+   desc);
+
+return 0;
+}
+
+/**
+ * @brief Load plugins for a MSDK session
+ *
+ * Media SDK may need external plugins to decode/encode,
+ * such as hevc_dec and hevc_enc. So it's necessary to load
+ * proper plugins.
+ *
+ * @param session   the MSDK session used
+ * @param load_plugins  the load_plugins to be loaded.
+ */
+int ff_qsv_load_plugins(mfxSession session, const char *load_plugins)
+{
+int err = 0, load_num = 0, i;
+
 if (load_plugins && *load_plugins) {
 while (*load_plugins) {
 mfxPluginUID uid;
-int i, err = 0;
 
 char *plugin = av_get_token(_plugins, ":");
 if (!plugin)
 return AVERROR(ENOMEM);
 if (strlen(plugin) != 2 * sizeof(uid.Data)) {
-av_log(avctx, AV_LOG_ERROR, "Invalid plugin UID length\n");
 err = AVERROR(EINVAL);
 goto load_plugin_fail;
 }
+if (*load_plugins == ':')
+load_plugins ++;
 
 for (i = 0; i < sizeof(uid.Data); i++) {
 err = sscanf(plugin + 2 * i, "%2hhx", uid.Data + i);
 if (err != 1) {
-av_log(avctx, AV_LOG_ERROR, "Invalid plugin UID\n");
 err = AVERROR(EINVAL);
 goto load_plugin_fail;
 }
-
 }
 
-ret = MFXVideoUSER_Load(qs->session, , 1);
-if (ret < 0) {
-av_log(avctx, AV_LOG_ERROR, "Could not load the requested 
plugin: %s\n",
-   plugin);
-err = ff_qsv_error(ret);
+err = MFXVideoUSER_Load(session, , 1);
+if (err < 0) {
+err = ff_qsv_error(err);
 goto load_plugin_fail;
 }
+load_num ++;
 
-if (*load_plugins)
-load_plugins++;
 load_plugin_fail:
 av_freep();
-if (err < 0)
-return err;
+/*
+ * If more plugins are going to be loaded,
+ * ignore current error and continue.
+ */
+if (*load_plugins == ':') {
+load_plugins ++;
+err = 0;
+}
 }
+if (!load_num)
+return err;
 }
 
-MFXQueryIMPL(qs->session, );
-
-switch (MFX_IMPL_BASETYPE(impl)) {
-case MFX_IMPL_SOFTWARE:
-desc = "software";
-break;
-case MFX_IMPL_HARDWARE:
-case MFX_IMPL_HARDWARE2:
-case MFX_IMPL_HARDWARE3:
-case MFX_IMPL_HARDWARE4:
-desc = "hardware accelerated";
-break;
-default:
-desc = "unknown";
-}
-
-av_log(avctx, AV_LOG_VERBOSE,
-   "Initialized an internal MFX session using %s implementation\n",
-   desc);
-
 return 0;
 }
 
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index f289a2b..59d1336 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -80,8 +80,10 @@ int ff_qsv_error(int mfx_err);
 
 int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id);
 
-int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs,
- const char *load_plugins);
+int 

[FFmpeg-devel] [PATCH 4/6] lavf/vpp: enable video memory accel for transcoding with vpp. lavc/qsv: export symbols "ff_qsv_*" which will be used by vpp. ffmpeg_qsv: set default hwaccel to qsv.

2016-08-16 Thread Nablet Developer
From: ChaoX A Liu 

Signed-off-by: ChaoX A Liu 
---
 ffmpeg_qsv.c|  46 ---
 libavcodec/libavcodec.v |   1 +
 libavcodec/qsv.h|   2 +
 libavfilter/vf_vpp.c| 153 
 4 files changed, 172 insertions(+), 30 deletions(-)

diff --git a/ffmpeg_qsv.c b/ffmpeg_qsv.c
index ec8a41b..70a3ecf 100644
--- a/ffmpeg_qsv.c
+++ b/ffmpeg_qsv.c
@@ -387,7 +387,7 @@ static mfxStatus frame_alloc(mfxHDL pthis, 
mfxFrameAllocRequest *request, mfxFra
 unsigned int va_fourcc = 0;
 mfxU32 fourcc = request->Info.FourCC;
 QSVContext *q = pthis;
-AVQSVContext *qsv = q->ost->enc_ctx->hwaccel_context;
+AVQSVContext *qsv = NULL;
 mfxU16 numAllocated = 0;
 bool bCreateSrfSucceeded = false;
 mfxU32 mfx_fourcc;
@@ -395,17 +395,40 @@ static mfxStatus frame_alloc(mfxHDL pthis, 
mfxFrameAllocRequest *request, mfxFra
 int width32;
 int height32;
 void *avctx = NULL;
+FilterGraph *fg = q->ost->filter->graph;
 
-av_log(avctx, AV_LOG_INFO, "=vaapi alloc frame==\n");
 if (!request || !response || !request->NumFrameSuggested)
 return MFX_ERR_MEMORY_ALLOC;
 
 memset(response, 0, sizeof(*response));
 surface_num = request->NumFrameSuggested;
-if ((request->Type & MFX_MEMTYPE_EXTERNAL_FRAME) &&
-(request->Type & MFX_MEMTYPE_FROM_DECODE))
-surface_num += (qsv->nb_encoder_surfaces + qsv->nb_decoder_surfaces);
+if (request->Type & MFX_MEMTYPE_FROM_DECODE) {
+avctx = input_streams[q->ost->source_index]->dec_ctx;
+if (request->Type & MFX_MEMTYPE_EXTERNAL_FRAME) {
+AVFilterContext *vpp = avfilter_graph_get_filter(fg->graph, 
"Parsed_vpp_0");
+qsv = 
input_streams[q->ost->source_index]->dec_ctx->hwaccel_context;
+surface_num += qsv->nb_decoder_surfaces;
+if (vpp) {
+qsv = vpp->hw_device_ctx->data;
+surface_num += qsv->nb_vpp_surfaces;
+} else {
+qsv = q->ost->enc_ctx->hwaccel_context;
+surface_num += qsv->nb_encoder_surfaces;
+}
+}
+} else if (request->Type & MFX_MEMTYPE_FROM_VPPOUT) {
+AVFilterContext *vpp = avfilter_graph_get_filter(fg->graph, 
"Parsed_vpp_0");
+avctx = vpp;
+if (request->Type & MFX_MEMTYPE_EXTERNAL_FRAME) {
+qsv = q->ost->enc_ctx->hwaccel_context;
+surface_num += qsv->nb_encoder_surfaces;
+}
+} else if (request->Type & MFX_MEMTYPE_FROM_ENCODE) {
+avctx = q->ost->enc_ctx;
+} else
+av_log(avctx, AV_LOG_WARNING, "FrameAlloc: may get a bug.\n");
 
+av_log(avctx, AV_LOG_INFO, "=vaapi alloc frame==\n");
 av_log(avctx, AV_LOG_INFO, "VAAPI: va_dpy =%p, surface_num=%d, width=%d, 
height=%d\n",
 g_session.va_display, surface_num, request->Info.Width, 
request->Info.Height);
 av_log(avctx, AV_LOG_INFO, "VAAPI: request->Type=%x\n",request->Type);
@@ -721,7 +744,7 @@ static int qsv_check_filters(const OutputStream *ost)
 AVFilterInOut *inputs, *outputs;
 int ret = 0;
 int i;
-const char *filter_list = "buffer|buffersink|null|format|setpts";
+const char *filter_list = "buffer|buffersink|null|format|setpts|vpp";
 
 if (!ost->avfilter)
 return -1;
@@ -821,6 +844,7 @@ int qsv_transcode_init_vidmem(OutputStream *ost)
 
 QSVContext *qsv = NULL;
 AVQSVContext *enc_hwctx = NULL;
+AVQSVContext *vpp_hwctx = NULL;
 
 /* check if the encoder supports QSV */
 if (!ost->enc->pix_fmts)
@@ -837,6 +861,8 @@ int qsv_transcode_init_vidmem(OutputStream *ost)
 
 /* check if the decoder supports QSV and the output only goes to this 
stream */
 ist = input_streams[ost->source_index];
+if (ist->hwaccel_id == HWACCEL_NONE || ist->hwaccel_id == HWACCEL_AUTO)
+ist->hwaccel_id = HWACCEL_QSV;
 if (ist->nb_filters || ist->hwaccel_id != HWACCEL_QSV ||
 !ist->dec || !ist->dec->pix_fmts)
 return 0;
@@ -855,7 +881,8 @@ int qsv_transcode_init_vidmem(OutputStream *ost)
 
 qsv   = av_mallocz(sizeof(*qsv));
 enc_hwctx = av_qsv_alloc_context();
-if (!qsv || !enc_hwctx)
+vpp_hwctx = av_qsv_alloc_context();
+if (!qsv || !enc_hwctx || !vpp_hwctx)
 goto fail;
 
 err = ff_qsv_init_internal_session(NULL, _session);
@@ -892,6 +919,11 @@ int qsv_transcode_init_vidmem(OutputStream *ost)
 ist->resample_pix_fmt= AV_PIX_FMT_QSV;
 ist->hwaccel_ctx = qsv;
 
+vpp_hwctx->session   = qsv->session;
+vpp_hwctx->iopattern = MFX_IOPATTERN_IN_VIDEO_MEMORY;
+vpp_hwctx->pFrameAllocator   = >frame_allocator;
+hw_device_ctx = av_buffer_create(vpp_hwctx, sizeof(*vpp_hwctx), 
av_buffer_default_free, NULL, 0);
+
 return 0;
 
 fail:
diff --git a/libavcodec/libavcodec.v 

[FFmpeg-devel] [PATCH 3/6] lavc/qsv: Enable hwaccel qsv_vidmem.

2016-08-16 Thread Nablet Developer
From: ChaoX A Liu 

Signed-off-by: ChaoX A Liu 
---
 ffmpeg.c  |   2 +-
 ffmpeg.h  |   2 +
 ffmpeg_opt.c  |   2 +-
 ffmpeg_qsv.c  | 636 +-
 libavcodec/qsv.h  |   3 +
 libavcodec/qsv_internal.h |   2 +
 libavcodec/qsvdec.c   |   5 +-
 libavcodec/qsvenc.c   |   2 +
 8 files changed, 649 insertions(+), 5 deletions(-)

diff --git a/ffmpeg.c b/ffmpeg.c
index bae515d..a8bc237 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -3050,7 +3050,7 @@ static int transcode_init(void)
 set_encoder_id(output_files[ost->file_index], ost);
 
 #if CONFIG_LIBMFX
-if (qsv_transcode_init(ost))
+if (qsv_transcode_init_vidmem(ost))
 exit_program(1);
 #endif
 
diff --git a/ffmpeg.h b/ffmpeg.h
index 49d65d8..266 100644
--- a/ffmpeg.h
+++ b/ffmpeg.h
@@ -585,6 +585,8 @@ int vda_init(AVCodecContext *s);
 int videotoolbox_init(AVCodecContext *s);
 int qsv_init(AVCodecContext *s);
 int qsv_transcode_init(OutputStream *ost);
+int qsv_init_vidmem(AVCodecContext *s);
+int qsv_transcode_init_vidmem(OutputStream *ost);
 int vaapi_decode_init(AVCodecContext *avctx);
 int vaapi_device_init(const char *device);
 int cuvid_init(AVCodecContext *s);
diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
index 2ea09cf..b5e4483 100644
--- a/ffmpeg_opt.c
+++ b/ffmpeg_opt.c
@@ -79,7 +79,7 @@ const HWAccel hwaccels[] = {
 { "videotoolbox",   videotoolbox_init,   HWACCEL_VIDEOTOOLBOX,   
AV_PIX_FMT_VIDEOTOOLBOX },
 #endif
 #if CONFIG_LIBMFX
-{ "qsv",   qsv_init,   HWACCEL_QSV,   AV_PIX_FMT_QSV },
+{ "qsv",   qsv_init_vidmem,   HWACCEL_QSV,   AV_PIX_FMT_QSV },
 #endif
 #if CONFIG_VAAPI
 { "vaapi", vaapi_decode_init, HWACCEL_VAAPI, AV_PIX_FMT_VAAPI },
diff --git a/ffmpeg_qsv.c b/ffmpeg_qsv.c
index 95a2351..ec8a41b 100644
--- a/ffmpeg_qsv.c
+++ b/ffmpeg_qsv.c
@@ -18,11 +18,15 @@
 
 #include 
 #include 
+#include 
+#include 
 
 #include "libavutil/dict.h"
 #include "libavutil/mem.h"
 #include "libavutil/opt.h"
+#include "libavutil/avstring.h"
 #include "libavcodec/qsv.h"
+#include "libavcodec/qsv_internal.h"
 
 #include "ffmpeg.h"
 
@@ -34,6 +38,8 @@ typedef struct QSVContext {
 mfxExtOpaqueSurfaceAlloc opaque_alloc;
 AVBufferRef *opaque_surfaces_buf;
 
+mfxFrameAllocator frame_allocator;
+
 uint8_t   *surface_used;
 mfxFrameSurface1 **surface_ptrs;
 int nb_surfaces;
@@ -60,7 +66,7 @@ static int qsv_get_buffer(AVCodecContext *s, AVFrame *frame, 
int flags)
  buffer_release, 
>surface_used[i], 0);
 if (!frame->buf[0])
 return AVERROR(ENOMEM);
-frame->data[3]   = (uint8_t*)qsv->surface_ptrs[i];
+frame->data[3]   = frame->buf[0]->data;
 qsv->surface_used[i] = 1;
 return 0;
 }
@@ -266,3 +272,631 @@ fail:
 av_freep();
 return AVERROR_UNKNOWN;
 }
+
+enum {
+MFX_FOURCC_VP8_NV12= MFX_MAKEFOURCC('V','P','8','N'),
+MFX_FOURCC_VP8_MBDATA  = MFX_MAKEFOURCC('V','P','8','M'),
+MFX_FOURCC_VP8_SEGMAP  = MFX_MAKEFOURCC('V','P','8','S'),
+};
+
+typedef struct vaapiMemId
+{
+VASurfaceID* m_surface;
+VAImage m_image;
+unsigned int m_fourcc;
+mfxU8* m_sys_buffer;
+mfxU8* m_va_buffer;
+} vaapiMemId;
+
+static QSVSession g_session;
+
+/* 
** 
*\
+
+INTEL CORPORATION PROPRIETARY INFORMATION
+This software is supplied under the terms of a license agreement or 
nondisclosure
+agreement with Intel Corporation and may not be copied or disclosed except in
+accordance with the terms of that agreement
+Copyright(c) 2011-2014 Intel Corporation. All Rights Reserved.
+
+\* 
** 
*/
+static mfxStatus va_to_mfx_status(VAStatus va_res)
+{
+mfxStatus mfxRes = MFX_ERR_NONE;
+
+switch (va_res) {
+case VA_STATUS_SUCCESS:
+mfxRes = MFX_ERR_NONE;
+break;
+case VA_STATUS_ERROR_ALLOCATION_FAILED:
+mfxRes = MFX_ERR_MEMORY_ALLOC;
+break;
+case VA_STATUS_ERROR_ATTR_NOT_SUPPORTED:
+case VA_STATUS_ERROR_UNSUPPORTED_PROFILE:
+case VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT:
+case VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT:
+case VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE:
+case VA_STATUS_ERROR_FLAG_NOT_SUPPORTED:
+case VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED:
+mfxRes = MFX_ERR_UNSUPPORTED;
+break;
+case VA_STATUS_ERROR_INVALID_DISPLAY:
+case VA_STATUS_ERROR_INVALID_CONFIG:
+case VA_STATUS_ERROR_INVALID_CONTEXT:
+case VA_STATUS_ERROR_INVALID_SURFACE:
+case VA_STATUS_ERROR_INVALID_BUFFER:
+case VA_STATUS_ERROR_INVALID_IMAGE:
+case VA_STATUS_ERROR_INVALID_SUBPICTURE:
+

[FFmpeg-devel] [PATCH 5/6] lavc/qsvdec: Reset decoder if MFX_ERR_UNDEFINED_BEHAVIOR is caught, because this error may get decoder stuck.

2016-08-16 Thread Nablet Developer
From: ChaoX A Liu 

Signed-off-by: ChaoX A Liu 
---
 libavcodec/qsvdec.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 47dd818..2075a23 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -370,13 +370,18 @@ static int do_qsv_decode(AVCodecContext *avctx, 
QSVContext *q,
 av_usleep(500);
 } while (1);
 
-if (MFX_WRN_VIDEO_PARAM_CHANGED==ret) {
+if (MFX_WRN_VIDEO_PARAM_CHANGED == ret) {
 /* TODO: handle here minor sequence header changing */
-} else if (MFX_ERR_INCOMPATIBLE_VIDEO_PARAM==ret) {
+} else if (MFX_ERR_INCOMPATIBLE_VIDEO_PARAM == ret) {
 av_fifo_reset(q->input_fifo);
 flush = q->reinit_pending = 1;
 continue;
-}
+} else if (MFX_ERR_UNDEFINED_BEHAVIOR == ret)
+/*
+ * Decoder may get stuck with this errorcode.
+ * Reset decoder to avoid that.
+ */
+ff_qsv_decode_reset(avctx, q);
 
 if (sync) {
 QSVFrame *out_frame = find_frame(q, outsurf);
-- 
2.5.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 2/6] lavf/vpp: Enable vpp filter, an Intel GPU accelerated scaler.

2016-08-16 Thread Nablet Developer
From: ChaoX A Liu 

Signed-off-by: ChaoX A Liu 
---
 configure |   3 +
 libavcodec/qsv.c  |   2 +-
 libavcodec/qsv_internal.h |   2 +-
 libavfilter/Makefile  |   1 +
 libavfilter/allfilters.c  |   1 +
 libavfilter/vf_vpp.c  | 863 ++
 6 files changed, 870 insertions(+), 2 deletions(-)
 create mode 100644 libavfilter/vf_vpp.c

diff --git a/configure b/configure
index 9b92426..7eb7ffd 100755
--- a/configure
+++ b/configure
@@ -2086,6 +2086,7 @@ CONFIG_EXTRA="
 qsv
 qsvdec
 qsvenc
+qsvvpp
 rangecoder
 riffdec
 riffenc
@@ -3076,6 +3077,8 @@ tinterlace_pad_test_deps="tinterlace_filter"
 uspp_filter_deps="gpl avcodec"
 vidstabdetect_filter_deps="libvidstab"
 vidstabtransform_filter_deps="libvidstab"
+vpp_filter_deps="libmfx"
+vpp_filter_select="qsv"
 zmq_filter_deps="libzmq"
 zoompan_filter_deps="swscale"
 zscale_filter_deps="libzimg"
diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index b505e14..c180ca8 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -168,7 +168,7 @@ static int ff_qsv_set_display_handle(AVCodecContext *avctx, 
QSVSession *qs)
  * @param avctxffmpeg metadata for this codec context
  * @param session  the MSDK session used
  */
-int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs)
+int ff_qsv_init_internal_session(void *avctx, QSVSession *qs)
 {
 mfxIMPL impl   = MFX_IMPL_AUTO_ANY;
 mfxVersion ver = { { QSV_VERSION_MINOR, QSV_VERSION_MAJOR } };
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 59d1336..e43728b 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -80,7 +80,7 @@ int ff_qsv_error(int mfx_err);
 
 int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id);
 
-int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs);
+int ff_qsv_init_internal_session(void *avctx, QSVSession *qs);
 
 int ff_qsv_load_plugins(mfxSession session, const char *load_plugins);
 
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 0d94f84..a15bf3c 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -286,6 +286,7 @@ OBJS-$(CONFIG_VFLIP_FILTER)  += vf_vflip.o
 OBJS-$(CONFIG_VIDSTABDETECT_FILTER)  += vidstabutils.o 
vf_vidstabdetect.o
 OBJS-$(CONFIG_VIDSTABTRANSFORM_FILTER)   += vidstabutils.o 
vf_vidstabtransform.o
 OBJS-$(CONFIG_VIGNETTE_FILTER)   += vf_vignette.o
+OBJS-$(CONFIG_VPP_FILTER)+= vf_vpp.o
 OBJS-$(CONFIG_VSTACK_FILTER) += vf_stack.o framesync.o
 OBJS-$(CONFIG_W3FDIF_FILTER) += vf_w3fdif.o
 OBJS-$(CONFIG_WAVEFORM_FILTER)   += vf_waveform.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index feed4f8..ce209cc 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -301,6 +301,7 @@ void avfilter_register_all(void)
 REGISTER_FILTER(VIDSTABDETECT,  vidstabdetect,  vf);
 REGISTER_FILTER(VIDSTABTRANSFORM, vidstabtransform, vf);
 REGISTER_FILTER(VIGNETTE,   vignette,   vf);
+REGISTER_FILTER(VPP,vpp,vf);
 REGISTER_FILTER(VSTACK, vstack, vf);
 REGISTER_FILTER(W3FDIF, w3fdif, vf);
 REGISTER_FILTER(WAVEFORM,   waveform,   vf);
diff --git a/libavfilter/vf_vpp.c b/libavfilter/vf_vpp.c
new file mode 100644
index 000..0cfeafc
--- /dev/null
+++ b/libavfilter/vf_vpp.c
@@ -0,0 +1,863 @@
+/*
+ * Intel MediaSDK Quick Sync Video VPP filter
+ *
+ * copyright (c) 2015 Sven Dueking
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "internal.h"
+#include 
+#include "libavutil/parseutils.h"
+#include "libavutil/timestamp.h"
+#include "libavcodec/qsv.h"
+
+/**
+ * ToDo :
+ *
+ * - double check surface pointers for different fourccs
+ * - handle empty extbuffers
+ * - cropping
+ * - use AV_PIX_FMT_QSV to pass surfaces to encoder
+ * - deinterlace check settings etc.
+ * - allocate number of surfaces depending modules and number of b frames
+ */
+
+#define VPP_ZERO_MEMORY(VAR){ memset(, 0, sizeof(VAR)); }
+#define VPP_ALIGN16(value)  (((value + 15) >> 4) << 4)  // 
round up to a 

[FFmpeg-devel] [PATCH 6/6] lavc/qsv-lavc/vpp: Promote gpu_copy to be a selectable parameter. GPU-copy is defaultly closed because it seems to be unstable.

2016-08-16 Thread Nablet Developer
From: ChaoX A Liu 

Signed-off-by: ChaoX A Liu 
---
 libavcodec/qsv.c  |  7 ++-
 libavcodec/qsv_internal.h |  1 +
 libavcodec/qsvdec.c   | 22 +-
 libavcodec/qsvdec_h2645.c | 12 
 libavcodec/qsvdec_mpeg2.c |  6 ++
 libavcodec/qsvdec_vc1.c   |  6 ++
 libavcodec/qsvenc.h   |  4 
 libavfilter/vf_vpp.c  |  8 +++-
 8 files changed, 59 insertions(+), 7 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index c180ca8..c61a29c 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -172,11 +172,16 @@ int ff_qsv_init_internal_session(void *avctx, QSVSession 
*qs)
 {
 mfxIMPL impl   = MFX_IMPL_AUTO_ANY;
 mfxVersion ver = { { QSV_VERSION_MINOR, QSV_VERSION_MAJOR } };
+mfxInitParam par;
 
 const char *desc;
 int ret;
 
-ret = MFXInit(impl, , >session);
+memset(, 0, sizeof(par));
+par.Implementation = impl;
+par.Version = ver;
+par.GPUCopy = qs->gpu_copy;
+ret = MFXInitEx(par, >session);
 if (ret < 0) {
 av_log(avctx, AV_LOG_ERROR, "Error initializing an internal MFX 
session\n");
 return ff_qsv_error(ret);
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 58589df..39778a9 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -73,6 +73,7 @@ typedef struct QSVSession {
 intfd_display;
 VADisplay  va_display;
 #endif
+intgpu_copy;
 } QSVSession;
 
 /**
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 2075a23..08a5eaa 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -176,13 +176,25 @@ static int alloc_frame(AVCodecContext *avctx, QSVFrame 
*frame)
 {
 int ret;
 
-ret = ff_get_buffer(avctx, frame->frame, AV_GET_BUFFER_FLAG_REF);
-if (ret < 0)
-return ret;
-
-if (frame->frame->format == AV_PIX_FMT_QSV) {
+if (avctx->pix_fmt == AV_PIX_FMT_QSV) {
+ret = ff_get_buffer(avctx, frame->frame, AV_GET_BUFFER_FLAG_REF);
+if (ret < 0)
+return ret;
 frame->surface = (mfxFrameSurface1*)frame->frame->data[3];
 } else {
+/*
+ * Align frame's width x height to 128x64.
+ * It's recommended to do so if GPU_Copy is turned on.
+ */
+frame->frame->format = avctx->pix_fmt;
+frame->frame->width  = FFALIGN(avctx->width, 128);
+frame->frame->height = FFALIGN(avctx->height, 64);
+ret = av_frame_get_buffer(frame->frame, 64);
+if (ret < 0)
+return ret;
+frame->frame->width  = avctx->width;
+frame->frame->height = avctx->height;
+
 frame->surface_internal.Info.BitDepthLuma   = 8;
 frame->surface_internal.Info.BitDepthChroma = 8;
 frame->surface_internal.Info.FourCC = MFX_FOURCC_NV12;
diff --git a/libavcodec/qsvdec_h2645.c b/libavcodec/qsvdec_h2645.c
index 208302b..a4adc10 100755
--- a/libavcodec/qsvdec_h2645.c
+++ b/libavcodec/qsvdec_h2645.c
@@ -248,6 +248,12 @@ static const AVOption hevc_options[] = {
 
 { "load_plugins", "A :-separate list of hexadecimal plugin UIDs to load in 
an internal session",
 OFFSET(qsv.load_plugins), AV_OPT_TYPE_STRING, { .str = "" }, 0, 0, VD 
},
+
+{ "gpu_copy", "Enable gpu copy in sysmem mode [default = off]", 
OFFSET(qsv.internal_qs.gpu_copy), AV_OPT_TYPE_INT, { .i64 = MFX_GPUCOPY_OFF }, 
MFX_GPUCOPY_DEFAULT, MFX_GPUCOPY_OFF, .flags = VD, "gpu_copy" },
+{ "default",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_DEFAULT }, 
0, 0, .flags = VD, "gpu_copy" },
+{ "on",   NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_ON },  
0, 0, .flags = VD, "gpu_copy" },
+{ "off",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_OFF }, 
0, 0, .flags = VD, "gpu_copy" },
+
 { NULL },
 };
 
@@ -286,6 +292,12 @@ AVHWAccel ff_h264_qsv_hwaccel = {
 
 static const AVOption options[] = {
 { "async_depth", "Internal parallelization depth, the higher the value the 
higher the latency.", OFFSET(qsv.async_depth), AV_OPT_TYPE_INT, { .i64 = 
ASYNC_DEPTH_DEFAULT }, 0, INT_MAX, VD },
+
+{ "gpu_copy", "Enable gpu copy in sysmem mode [default = off]", 
OFFSET(qsv.internal_qs.gpu_copy), AV_OPT_TYPE_INT, { .i64 = MFX_GPUCOPY_OFF }, 
MFX_GPUCOPY_DEFAULT, MFX_GPUCOPY_OFF, .flags = VD, "gpu_copy" },
+{ "default",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_DEFAULT }, 
0, 0, .flags = VD, "gpu_copy" },
+{ "on",   NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_ON },  
0, 0, .flags = VD, "gpu_copy" },
+{ "off",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_OFF }, 
0, 0, .flags = VD, "gpu_copy" },
+
 { NULL },
 };
 
diff --git a/libavcodec/qsvdec_mpeg2.c b/libavcodec/qsvdec_mpeg2.c
index 70ccbc5..5e2354a 100644
--- a/libavcodec/qsvdec_mpeg2.c
+++ b/libavcodec/qsvdec_mpeg2.c
@@ -72,6 +72,12 @@ AVHWAccel ff_mpeg2_qsv_hwaccel = {
 #define VD AV_OPT_FLAG_VIDEO_PARAM | 

[FFmpeg-devel] [PATCH 0/6] fixes for HEVC GPU accelerated codec

2016-08-16 Thread Nablet Developer
We have create 6 patches based on latest
ffmpeg-master: 3282e31baaa77d161a4451c27ad0d45f78e1da0a
With these patches:
1.  We modify HEVC plugin loading order, default to HW plugin,
since HEVC can be supported in SKL platform.
2.  Move code in vaapi_allocator.c to ffmpeg_qsv.c, and re-use
hwaccel_context to enable video-memory transcoding.
3.  Enabled VPP and fixed some issues.
4.  Fixed some issues which is found by customer 

ChaoX A Liu (6):
  lavc/qsv(hevc): Change default plugin from hevc_sw to hevc_default,
which will load hevc_hw first, due to newly released MSDK.
  lavf/vpp: Enable vpp filter, an Intel GPU accelerated scaler.
  lavc/qsv: Enable hwaccel qsv_vidmem.
  lavf/vpp: enable video memory accel for transcoding with vpp.
lavc/qsv: export symbols "ff_qsv_*" which will be used by vpp.
ffmpeg_qsv: set default hwaccel to qsv.
  lavc/qsvdec: Reset decoder if MFX_ERR_UNDEFINED_BEHAVIOR is caught,
because this error may get decoder stuck.
  lavc/qsv-lavc/vpp: Promote gpu_copy to be a selectable parameter.
GPU-copy is defaultly closed because it seems to be unstable.

 configure |   3 +
 ffmpeg.c  |   2 +-
 ffmpeg.h  |   2 +
 ffmpeg_opt.c  |   2 +-
 ffmpeg_qsv.c  | 668 ++-
 libavcodec/libavcodec.v   |   1 +
 libavcodec/qsv.c  |  96 +++--
 libavcodec/qsv.h  |   5 +
 libavcodec/qsv_internal.h |   9 +-
 libavcodec/qsvdec.c   |  52 ++-
 libavcodec/qsvdec_h2645.c |  29 +-
 libavcodec/qsvdec_mpeg2.c |   6 +
 libavcodec/qsvdec_vc1.c   |   6 +
 libavcodec/qsvenc.c   |  14 +-
 libavcodec/qsvenc.h   |   4 +
 libavcodec/qsvenc_hevc.c  |  19 +-
 libavfilter/Makefile  |   1 +
 libavfilter/allfilters.c  |   1 +
 libavfilter/vf_vpp.c  | 976 ++
 19 files changed, 1828 insertions(+), 68 deletions(-)
 create mode 100644 libavfilter/vf_vpp.c

-- 
2.5.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] hwcontext: add a QSV implementation

2016-07-06 Thread nablet developer
existing API functions like ff_qsv_init_internal_session / 
ff_qsv_close_internal_session are private to libavcodec and are not exported 
(since they are ff_ prefixed)
first attempt was to move API functions from libavcodec to libavutil, but it 
was rejected and instead it was suggested to use existing generic hwcontext 
approach instead of adding QSV specific API

> On 06 Jul 2016, at 15:40, Carl Eugen Hoyos <ceho...@ag.or.at> wrote:
> 
> nablet developer  nablet.com> writes:
> 
>> hwcontext_qsv is needed for VPP filter (which cannot use API 
>> functions from libavcodec)
> 
> Why not?
> 
> Carl Eugen
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] hwcontext: add a QSV implementation

2016-07-06 Thread nablet developer

> On 06 Jul 2016, at 15:48, Hendrik Leppkes <h.lepp...@gmail.com> wrote:
> 
> On Wed, Jul 6, 2016 at 9:08 AM, nablet developer <s...@nablet.com> wrote:
>> add hwcontext_qsv (Intel QuickSync Video) implementation
>> basically it's adapted patch from libav 
>> (https://lists.libav.org/pipermail/libav-devel/2016-May/077126.html)
> 
> If you take a patch from libav, you need to maintain proper authorship
> information.

how is it usually done? commit message, comment block or something else?

> Also please outline what has changed from the original, if anything.
> We try to keep all the hwcontext things as close to libav as possible
> to make future enhancements easier.

patch is identical except copyright headers of hwcontext_qsv.c / 
hwcontext_qsv.h (first 17 lines) which are changed to the typical ffmpeg 
copyright.

> 
> - Hendrik
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] hwcontext: add a QSV implementation

2016-07-06 Thread nablet developer
add hwcontext_qsv (Intel QuickSync Video) implementation
basically it's adapted patch from libav 
(https://lists.libav.org/pipermail/libav-devel/2016-May/077126.html)
hwcontext_qsv is needed for VPP filter (which cannot use API functions from 
libavcodec)

nablet developer (1):
  hwcontext: add a QSV implementation

 libavutil/Makefile |   3 +
 libavutil/hwcontext.c  |   3 +
 libavutil/hwcontext.h  |   1 +
 libavutil/hwcontext_internal.h |   1 +
 libavutil/hwcontext_qsv.c  | 791 +
 libavutil/hwcontext_qsv.h  |  52 +++
 6 files changed, 851 insertions(+)
 create mode 100644 libavutil/hwcontext_qsv.c
 create mode 100644 libavutil/hwcontext_qsv.h

-- 
1.8.3.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] hwcontext: add a QSV implementation

2016-07-06 Thread nablet developer
Signed-off-by: nablet developer <s...@nablet.com>
---
 libavutil/Makefile |   3 +
 libavutil/hwcontext.c  |   3 +
 libavutil/hwcontext.h  |   1 +
 libavutil/hwcontext_internal.h |   1 +
 libavutil/hwcontext_qsv.c  | 791 +
 libavutil/hwcontext_qsv.h  |  52 +++
 6 files changed, 851 insertions(+)
 create mode 100644 libavutil/hwcontext_qsv.c
 create mode 100644 libavutil/hwcontext_qsv.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 1e06176..7385ec2 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -35,6 +35,7 @@ HEADERS = adler32.h   
  \
   hwcontext.h   \
   hwcontext_cuda.h  \
   hwcontext_dxva2.h \
+  hwcontext_qsv.h   \
   hwcontext_vaapi.h \
   hwcontext_vdpau.h \
   imgutils.h\
@@ -154,6 +155,7 @@ OBJS-$(!HAVE_ATOMICS_NATIVE)+= atomic.o 
\
 
 OBJS-$(CONFIG_CUDA) += hwcontext_cuda.o
 OBJS-$(CONFIG_DXVA2)+= hwcontext_dxva2.o
+OBJS-$(CONFIG_LIBMFX)   += hwcontext_qsv.o
 OBJS-$(CONFIG_LZO)  += lzo.o
 OBJS-$(CONFIG_OPENCL)   += opencl.o opencl_internal.o
 OBJS-$(CONFIG_VAAPI)+= hwcontext_vaapi.o
@@ -166,6 +168,7 @@ SLIBOBJS-$(HAVE_GNU_WINDRES)+= avutilres.o
 
 SKIPHEADERS-$(CONFIG_CUDA) += hwcontext_cuda.h
 SKIPHEADERS-$(CONFIG_DXVA2)+= hwcontext_dxva2.h
+SKIPHEADERS-$(CONFIG_LIBMFX)   += hwcontext_qsv.h
 SKIPHEADERS-$(CONFIG_VAAPI)+= hwcontext_vaapi.h
 SKIPHEADERS-$(CONFIG_VDPAU)+= hwcontext_vdpau.h
 SKIPHEADERS-$(HAVE_ATOMICS_GCC)+= atomic_gcc.h
diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
index 1e9e913..81b6911 100644
--- a/libavutil/hwcontext.c
+++ b/libavutil/hwcontext.c
@@ -32,6 +32,9 @@ static const HWContextType *hw_table[] = {
 #if CONFIG_CUDA
 _hwcontext_type_cuda,
 #endif
+#if CONFIG_LIBMFX
+_hwcontext_type_qsv,
+#endif
 #if CONFIG_DXVA2
 _hwcontext_type_dxva2,
 #endif
diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h
index 4e9da02..5e2af09 100644
--- a/libavutil/hwcontext.h
+++ b/libavutil/hwcontext.h
@@ -29,6 +29,7 @@ enum AVHWDeviceType {
 AV_HWDEVICE_TYPE_CUDA,
 AV_HWDEVICE_TYPE_VAAPI,
 AV_HWDEVICE_TYPE_DXVA2,
+AV_HWDEVICE_TYPE_QSV,
 };
 
 typedef struct AVHWDeviceInternal AVHWDeviceInternal;
diff --git a/libavutil/hwcontext_internal.h b/libavutil/hwcontext_internal.h
index cf832fe..079e42b 100644
--- a/libavutil/hwcontext_internal.h
+++ b/libavutil/hwcontext_internal.h
@@ -101,6 +101,7 @@ struct AVHWFramesInternal {
 
 extern const HWContextType ff_hwcontext_type_cuda;
 extern const HWContextType ff_hwcontext_type_dxva2;
+extern const HWContextType ff_hwcontext_type_qsv;
 extern const HWContextType ff_hwcontext_type_vaapi;
 extern const HWContextType ff_hwcontext_type_vdpau;
 
diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
new file mode 100644
index 000..13be5b0
--- /dev/null
+++ b/libavutil/hwcontext_qsv.c
@@ -0,0 +1,791 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+#include 
+
+#include 
+
+#include "config.h"
+
+#if CONFIG_VAAPI
+#include "hwcontext_vaapi.h"
+#endif
+#if CONFIG_DXVA2
+#include "hwcontext_dxva2.h"
+#endif
+
+#include "buffer.h"
+#include "common.h"
+#include "hwcontext.h"
+#include "hwcontext_internal.h"
+#include "hwcontext_qsv.h"
+#include "mem.h"
+#include "pixfmt.h"
+#include "pixdesc.h"
+#include "time.h"
+
+typedef struct QSVDevicePriv {
+AVBufferRef *child_device_ctx;
+} QSVDevicePriv;
+
+typedef struct QSVDeviceContext {
+mfxHDL  handle;
+mfxHandleType   handle_type;
+   

Re: [FFmpeg-devel] [PATCH 0/5] avutil/qsv add hwcontext_qsv

2016-06-10 Thread nablet developer

> On 10 Jun 2016, at 00:48, Michael Niedermayer <mich...@niedermayer.cc> wrote:
> 
> On Mon, Jun 06, 2016 at 05:25:41PM +0700, nablet developer wrote:
>> 
>>> On 06 Jun 2016, at 16:40, Mark Thompson <s...@jkqxz.net> wrote:
>>> 
>>> On 06/06/16 09:25, nablet developer wrote:
>>>> ping. any feedback?
>>> 
>>> Perhaps you could comment on the merits and functionality of your version as
>>> compared with the one here
>>> <https://lists.libav.org/pipermail/libav-devel/2016-May/077126.html> (with
>>> associated series) posted at roughly the same time?
>>> 
>> 
>> as I have understood so far, hwcontext in general handles two tasks:
>> 1. context management (context initialisation and cleanup)
>> 2. hardware frame management (initialisation, cleanup and transfer data 
>> from/to system memory)
>> 
>> patch from libav handles both 1) and 2).
>> my patches just handle 1) - context management.
>> frame management can be added as well as additional patch set, that's no 
>> problem.
>> for my task (VPP filter) just context management was enough for now.
>> 
>> so yes, changes from libav are more complete in term of feature set.
> 
> if the code is overall better than it makes sense to use it instead
> 
> are you interrested in testing and updating our code to that ?
> (aka submit a patchset that switches to the overall better code)

yes, that definitely makes sense for me, I will handle testing/updating and 
reply back with new patch-set next week then.

> 
> [...]
> -- 
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> 
> The real ebay dictionary, page 2
> "100% positive feedback" - "All either got their money back or didnt complain"
> "Best seller ever, very honest" - "Seller refunded buyer after failed scam"
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org <mailto:ffmpeg-devel@ffmpeg.org>
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel 
> <http://ffmpeg.org/mailman/listinfo/ffmpeg-devel>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 0/5] avutil/qsv add hwcontext_qsv

2016-06-06 Thread nablet developer

> On 06 Jun 2016, at 16:40, Mark Thompson <s...@jkqxz.net> wrote:
> 
> On 06/06/16 09:25, nablet developer wrote:
>> ping. any feedback?
> 
> Perhaps you could comment on the merits and functionality of your version as
> compared with the one here
> <https://lists.libav.org/pipermail/libav-devel/2016-May/077126.html> (with
> associated series) posted at roughly the same time?
> 

as I have understood so far, hwcontext in general handles two tasks:
1. context management (context initialisation and cleanup)
2. hardware frame management (initialisation, cleanup and transfer data from/to 
system memory)

patch from libav handles both 1) and 2).
my patches just handle 1) - context management.
frame management can be added as well as additional patch set, that's no 
problem.
for my task (VPP filter) just context management was enough for now.

so yes, changes from libav are more complete in term of feature set.

> Obviously they collide, which is somewhat unfortunate.  The libav one looks 
> more
> complete to me (hwframe support with surface upload and download, notably), 
> but
> I am not a libmfx expert so there might be something significant that I have 
> missed.
> 
> - Mark
> 
> 
>>> On 25 May 2016, at 19:20, nablet developer <s...@nablet.com> wrote:
>>> 
>>> added hwcontext_qsv (Intel QuickSync video)
>>> it will handle MFX session initialization and deinitialization,
>>> and will allow to share that code between libavcodec and libavfilter
>>> without adding new API calls for QSV, and also using similar approach
>>> to CUDA & VAAPI
>>> (VPP filter patch is postponded with suggestion to implementa hwcontext_qsv)
>>> 
>>> nablet developer (5):
>>> avutil/qsv: move ff_qsv_error function from libavcodec into libavutil,
>>>   because it's going to be shared between libavcodec (existing QSV
>>>   encoders & decoders), libavfilter (upcoming QSV VPP filter) and
>>>   libavutil itself (upcoming hwcontext_qsv implementation). prefix
>>>   changed to avpriv since it's now shared between multiple libraries.
>>> avutil/qsv: add hwcontext_qsv (QuickSync Video)
>>> avcodec/qsvdec: use hwcontext_qsv instead of
>>>   ff_qsv_init_internal_session
>>> avcodec/qsvenc: use hwcontext_qsv instead of
>>>   ff_qsv_init_internal_session
>>> avcodec/qsv: remove no longer needed functions
>>>   ff_qsv_init_internal_session & ff_qsv_close_internal_session,
>>>   structure QSVSession, since they are now replaced by
>>>   avutil/hwcontext_qsv
>>> 
>>> libavcodec/qsv.c   | 221 +--
>>> libavcodec/qsv_internal.h  |  35 --
>>> libavcodec/qsvdec.c|  36 --
>>> libavcodec/qsvdec.h|   4 +-
>>> libavcodec/qsvenc.c|  40 +--
>>> libavcodec/qsvenc.h|   3 +-
>>> libavutil/Makefile |   4 +
>>> libavutil/hwcontext.c  |   3 +
>>> libavutil/hwcontext.h  |   1 +
>>> libavutil/hwcontext_internal.h |   1 +
>>> libavutil/hwcontext_qsv.c  | 255 
>>> +
>>> libavutil/hwcontext_qsv.h  |  45 
>>> libavutil/qsv_internal.c   |  58 ++
>>> libavutil/qsv_internal.h   |  27 +
>>> 14 files changed, 452 insertions(+), 281 deletions(-)
>>> create mode 100644 libavutil/hwcontext_qsv.c
>>> create mode 100644 libavutil/hwcontext_qsv.h
>>> create mode 100644 libavutil/qsv_internal.c
>>> create mode 100644 libavutil/qsv_internal.h
>>> 
>>> -- 
>>> 1.8.3.1
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 0/5] avutil/qsv add hwcontext_qsv

2016-06-06 Thread nablet developer
ping. any feedback?

> On 25 May 2016, at 19:20, nablet developer <s...@nablet.com> wrote:
> 
> added hwcontext_qsv (Intel QuickSync video)
> it will handle MFX session initialization and deinitialization,
> and will allow to share that code between libavcodec and libavfilter
> without adding new API calls for QSV, and also using similar approach
> to CUDA & VAAPI
> (VPP filter patch is postponded with suggestion to implementa hwcontext_qsv)
> 
> nablet developer (5):
>  avutil/qsv: move ff_qsv_error function from libavcodec into libavutil,
>because it's going to be shared between libavcodec (existing QSV
>encoders & decoders), libavfilter (upcoming QSV VPP filter) and
>libavutil itself (upcoming hwcontext_qsv implementation). prefix
>changed to avpriv since it's now shared between multiple libraries.
>  avutil/qsv: add hwcontext_qsv (QuickSync Video)
>  avcodec/qsvdec: use hwcontext_qsv instead of
>ff_qsv_init_internal_session
>  avcodec/qsvenc: use hwcontext_qsv instead of
>ff_qsv_init_internal_session
>  avcodec/qsv: remove no longer needed functions
>ff_qsv_init_internal_session & ff_qsv_close_internal_session,
>structure QSVSession, since they are now replaced by
>avutil/hwcontext_qsv
> 
> libavcodec/qsv.c   | 221 +--
> libavcodec/qsv_internal.h  |  35 --
> libavcodec/qsvdec.c|  36 --
> libavcodec/qsvdec.h|   4 +-
> libavcodec/qsvenc.c|  40 +--
> libavcodec/qsvenc.h|   3 +-
> libavutil/Makefile |   4 +
> libavutil/hwcontext.c  |   3 +
> libavutil/hwcontext.h  |   1 +
> libavutil/hwcontext_internal.h |   1 +
> libavutil/hwcontext_qsv.c  | 255 +
> libavutil/hwcontext_qsv.h  |  45 
> libavutil/qsv_internal.c   |  58 ++
> libavutil/qsv_internal.h   |  27 +
> 14 files changed, 452 insertions(+), 281 deletions(-)
> create mode 100644 libavutil/hwcontext_qsv.c
> create mode 100644 libavutil/hwcontext_qsv.h
> create mode 100644 libavutil/qsv_internal.c
> create mode 100644 libavutil/qsv_internal.h
> 
> -- 
> 1.8.3.1
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 5/5] avcodec/qsv: remove no longer needed functions ff_qsv_init_internal_session & ff_qsv_close_internal_session, structure QSVSession, since they are now replaced by avutil/hwco

2016-05-25 Thread nablet developer
Signed-off-by: nablet developer <s...@nablet.com>
---
 libavcodec/qsv.c  | 186 --
 libavcodec/qsv_internal.h |  30 
 2 files changed, 216 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 8cd03e8..22c99cf 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -19,7 +19,6 @@
  */
 
 #include 
-#include 
 
 #include 
 #include 
@@ -51,188 +50,3 @@ int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
 
 return AVERROR(ENOSYS);
 }
-
-static int ff_qsv_set_display_handle(AVCodecContext *avctx, QSVSession *qs)
-{
-// this code is only required for Linux.  It searches for a valid
-// display handle.  First in /dev/dri/renderD then in /dev/dri/card
-#ifdef AVCODEC_QSV_LINUX_SESSION_HANDLE
-// VAAPI display handle
-int ret = 0;
-VADisplay va_dpy = NULL;
-VAStatus va_res = VA_STATUS_SUCCESS;
-int major_version = 0, minor_version = 0;
-int fd = -1;
-char adapterpath[256];
-int adapter_num;
-
-qs->fd_display = -1;
-qs->va_display = NULL;
-
-//search for valid graphics device
-for (adapter_num = 0;adapter_num < 6;adapter_num++) {
-
-if (adapter_num<3) {
-snprintf(adapterpath,sizeof(adapterpath),
-"/dev/dri/renderD%d", adapter_num+128);
-} else {
-snprintf(adapterpath,sizeof(adapterpath),
-"/dev/dri/card%d", adapter_num-3);
-}
-
-fd = open(adapterpath, O_RDWR);
-if (fd < 0) {
-av_log(avctx, AV_LOG_ERROR,
-"mfx init: %s fd open failed\n", adapterpath);
-continue;
-}
-
-va_dpy = vaGetDisplayDRM(fd);
-if (!va_dpy) {
-av_log(avctx, AV_LOG_ERROR,
-"mfx init: %s vaGetDisplayDRM failed\n", adapterpath);
-close(fd);
-continue;
-}
-
-va_res = vaInitialize(va_dpy, _version, _version);
-if (VA_STATUS_SUCCESS != va_res) {
-av_log(avctx, AV_LOG_ERROR,
-"mfx init: %s vaInitialize failed\n", adapterpath);
-close(fd);
-fd = -1;
-continue;
-} else {
-av_log(avctx, AV_LOG_VERBOSE,
-"mfx initialization: %s vaInitialize successful\n",adapterpath);
-qs->fd_display = fd;
-qs->va_display = va_dpy;
-ret = MFXVideoCORE_SetHandle(qs->session,
-  (mfxHandleType)MFX_HANDLE_VA_DISPLAY, (mfxHDL)va_dpy);
-if (ret < 0) {
-av_log(avctx, AV_LOG_ERROR,
-"Error %d during set display handle\n", ret);
-return avpriv_qsv_error(ret);
-}
-break;
-}
-}
-#endif //AVCODEC_QSV_LINUX_SESSION_HANDLE
-return 0;
-}
-/**
- * @brief Initialize a MSDK session
- *
- * Media SDK is based on sessions, so this is the prerequisite
- * initialization for HW acceleration.  For Windows the session is
- * complete and ready to use, for Linux a display handle is
- * required.  For releases of Media Server Studio >= 2015 R4 the
- * render nodes interface is preferred (/dev/dri/renderD).
- * Using Media Server Studio 2015 R4 or newer is recommended
- * but the older /dev/dri/card interface is also searched
- * for broader compatibility.
- *
- * @param avctxffmpeg metadata for this codec context
- * @param session  the MSDK session used
- */
-int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs,
- const char *load_plugins)
-{
-mfxIMPL impl   = MFX_IMPL_AUTO_ANY;
-mfxVersion ver = { { QSV_VERSION_MINOR, QSV_VERSION_MAJOR } };
-
-const char *desc;
-int ret;
-
-ret = MFXInit(impl, , >session);
-if (ret < 0) {
-av_log(avctx, AV_LOG_ERROR, "Error initializing an internal MFX 
session\n");
-return avpriv_qsv_error(ret);
-}
-
-ret = ff_qsv_set_display_handle(avctx, qs);
-if (ret < 0)
-return ret;
-
-if (load_plugins && *load_plugins) {
-while (*load_plugins) {
-mfxPluginUID uid;
-int i, err = 0;
-
-char *plugin = av_get_token(_plugins, ":");
-if (!plugin)
-return AVERROR(ENOMEM);
-if (strlen(plugin) != 2 * sizeof(uid.Data)) {
-av_log(avctx, AV_LOG_ERROR, "Invalid plugin UID length\n");
-err = AVERROR(EINVAL);
-goto load_plugin_fail;
-}
-
-for (i = 0; i < sizeof(uid.Data); i++) {
-err = sscanf(plugin + 2 * i, "%2hhx", uid.Data + i);
-if (err != 1) {
-av_log(avctx, AV_LOG_ERROR, "Invalid plugin UID\n");
-err = AVERROR(EINVAL);
-goto load_plugin_fai

[FFmpeg-devel] [PATCH 1/5] avutil/qsv: move ff_qsv_error function from libavcodec into libavutil, because it's going to be shared between libavcodec (existing QSV encoders & decoders), libavfilter (up

2016-05-25 Thread nablet developer
Signed-off-by: nablet developer <s...@nablet.com>
---
 libavcodec/qsv.c  | 41 -
 libavcodec/qsv_internal.h |  5 
 libavcodec/qsvdec.c   |  7 +++---
 libavcodec/qsvenc.c   | 11 +
 libavutil/Makefile|  1 +
 libavutil/qsv_internal.c  | 58 +++
 libavutil/qsv_internal.h  | 27 ++
 7 files changed, 100 insertions(+), 50 deletions(-)
 create mode 100644 libavutil/qsv_internal.c
 create mode 100644 libavutil/qsv_internal.h

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 11d453d..8cd03e8 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -29,6 +29,7 @@
 
 #include "avcodec.h"
 #include "qsv_internal.h"
+#include "libavutil/qsv_internal.h"
 
 int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
 {
@@ -51,40 +52,6 @@ int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
 return AVERROR(ENOSYS);
 }
 
-int ff_qsv_error(int mfx_err)
-{
-switch (mfx_err) {
-case MFX_ERR_NONE:
-return 0;
-case MFX_ERR_MEMORY_ALLOC:
-case MFX_ERR_NOT_ENOUGH_BUFFER:
-return AVERROR(ENOMEM);
-case MFX_ERR_INVALID_HANDLE:
-return AVERROR(EINVAL);
-case MFX_ERR_DEVICE_FAILED:
-case MFX_ERR_DEVICE_LOST:
-case MFX_ERR_LOCK_MEMORY:
-return AVERROR(EIO);
-case MFX_ERR_NULL_PTR:
-case MFX_ERR_UNDEFINED_BEHAVIOR:
-case MFX_ERR_NOT_INITIALIZED:
-return AVERROR_BUG;
-case MFX_ERR_UNSUPPORTED:
-case MFX_ERR_NOT_FOUND:
-return AVERROR(ENOSYS);
-case MFX_ERR_MORE_DATA:
-case MFX_ERR_MORE_SURFACE:
-case MFX_ERR_MORE_BITSTREAM:
-return AVERROR(EAGAIN);
-case MFX_ERR_INCOMPATIBLE_VIDEO_PARAM:
-case MFX_ERR_INVALID_VIDEO_PARAM:
-return AVERROR(EINVAL);
-case MFX_ERR_ABORTED:
-case MFX_ERR_UNKNOWN:
-default:
-return AVERROR_UNKNOWN;
-}
-}
 static int ff_qsv_set_display_handle(AVCodecContext *avctx, QSVSession *qs)
 {
 // this code is only required for Linux.  It searches for a valid
@@ -145,7 +112,7 @@ static int ff_qsv_set_display_handle(AVCodecContext *avctx, 
QSVSession *qs)
 if (ret < 0) {
 av_log(avctx, AV_LOG_ERROR,
 "Error %d during set display handle\n", ret);
-return ff_qsv_error(ret);
+return avpriv_qsv_error(ret);
 }
 break;
 }
@@ -180,7 +147,7 @@ int ff_qsv_init_internal_session(AVCodecContext *avctx, 
QSVSession *qs,
 ret = MFXInit(impl, , >session);
 if (ret < 0) {
 av_log(avctx, AV_LOG_ERROR, "Error initializing an internal MFX 
session\n");
-return ff_qsv_error(ret);
+return avpriv_qsv_error(ret);
 }
 
 ret = ff_qsv_set_display_handle(avctx, qs);
@@ -215,7 +182,7 @@ int ff_qsv_init_internal_session(AVCodecContext *avctx, 
QSVSession *qs,
 if (ret < 0) {
 av_log(avctx, AV_LOG_ERROR, "Could not load the requested 
plugin: %s\n",
plugin);
-err = ff_qsv_error(ret);
+err = avpriv_qsv_error(ret);
 goto load_plugin_fail;
 }
 
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index f289a2b..ce2531b 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -73,11 +73,6 @@ typedef struct QSVSession {
 #endif
 } QSVSession;
 
-/**
- * Convert a libmfx error code into a ffmpeg error code.
- */
-int ff_qsv_error(int mfx_err);
-
 int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id);
 
 int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs,
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index c17606d..5253a57 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -36,6 +36,7 @@
 #include "internal.h"
 #include "qsv.h"
 #include "qsv_internal.h"
+#include "libavutil/qsv_internal.h"
 #include "qsvdec.h"
 
 int ff_qsv_map_pixfmt(enum AVPixelFormat format)
@@ -108,7 +109,7 @@ static int qsv_decode_init(AVCodecContext *avctx, 
QSVContext *q, AVPacket *avpkt
 return avpkt->size;
 } else if (ret < 0) {
 av_log(avctx, AV_LOG_ERROR, "Decode header error %d\n", ret);
-return ff_qsv_error(ret);
+return avpriv_qsv_error(ret);
 }
 param.IOPattern   = q->iopattern;
 param.AsyncDepth  = q->async_depth;
@@ -126,7 +127,7 @@ static int qsv_decode_init(AVCodecContext *avctx, 
QSVContext *q, AVPacket *avpkt
 av_log(avctx, AV_LOG_ERROR,
"Error initializing the MFX video decoder %d\n", ret);
 }
-return ff_qsv_error(ret);
+return avpriv_qsv_error(ret);
 }
 
 avctx->profile  = param.mfx.CodecProfile;
@@ -425,7 +426,7 @@ static int do_qsv_decode(AVCodecContext *avctx, QSVContext 
*

[FFmpeg-devel] [PATCH 2/5] avutil/qsv: add hwcontext_qsv (QuickSync Video)

2016-05-25 Thread nablet developer
Signed-off-by: nablet developer <s...@nablet.com>
---
 libavutil/Makefile |   3 +
 libavutil/hwcontext.c  |   3 +
 libavutil/hwcontext.h  |   1 +
 libavutil/hwcontext_internal.h |   1 +
 libavutil/hwcontext_qsv.c  | 255 +
 libavutil/hwcontext_qsv.h  |  45 
 6 files changed, 308 insertions(+)
 create mode 100644 libavutil/hwcontext_qsv.c
 create mode 100644 libavutil/hwcontext_qsv.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index e358767..e9df0fb 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -36,6 +36,7 @@ HEADERS = adler32.h   
  \
   hwcontext_cuda.h  \
   hwcontext_vaapi.h \
   hwcontext_vdpau.h \
+  hwcontext_qsv.h   \
   imgutils.h\
   intfloat.h\
   intreadwrite.h\
@@ -157,6 +158,7 @@ OBJS-$(CONFIG_OPENCL)   += opencl.o 
opencl_internal.o
 OBJS-$(CONFIG_QSV)  += qsv_internal.o
 OBJS-$(CONFIG_VAAPI)+= hwcontext_vaapi.o
 OBJS-$(CONFIG_VDPAU)+= hwcontext_vdpau.o
+OBJS-$(CONFIG_QSV)  += hwcontext_qsv.o
 
 OBJS += $(COMPAT_OBJS:%=../compat/%)
 
@@ -166,6 +168,7 @@ SLIBOBJS-$(HAVE_GNU_WINDRES)+= avutilres.o
 SKIPHEADERS-$(CONFIG_CUDA) += hwcontext_cuda.h
 SKIPHEADERS-$(CONFIG_VAAPI)+= hwcontext_vaapi.h
 SKIPHEADERS-$(CONFIG_VDPAU)+= hwcontext_vdpau.h
+SKIPHEADERS-$(CONFIG_QSV)  += hwcontext_qsv.h
 SKIPHEADERS-$(HAVE_ATOMICS_GCC)+= atomic_gcc.h
 SKIPHEADERS-$(HAVE_ATOMICS_SUNCC)  += atomic_suncc.h
 SKIPHEADERS-$(HAVE_ATOMICS_WIN32)  += atomic_win32.h
diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
index 619f21e..60a67d0 100644
--- a/libavutil/hwcontext.c
+++ b/libavutil/hwcontext.c
@@ -38,6 +38,9 @@ static const HWContextType *hw_table[] = {
 #if CONFIG_VDPAU
 _hwcontext_type_vdpau,
 #endif
+#if CONFIG_QSV
+_hwcontext_type_qsv,
+#endif
 NULL,
 };
 
diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h
index 44be197..234dd95 100644
--- a/libavutil/hwcontext.h
+++ b/libavutil/hwcontext.h
@@ -28,6 +28,7 @@ enum AVHWDeviceType {
 AV_HWDEVICE_TYPE_VDPAU,
 AV_HWDEVICE_TYPE_CUDA,
 AV_HWDEVICE_TYPE_VAAPI,
+AV_HWDEVICE_TYPE_QSV,
 };
 
 typedef struct AVHWDeviceInternal AVHWDeviceInternal;
diff --git a/libavutil/hwcontext_internal.h b/libavutil/hwcontext_internal.h
index f18b616..914c39a 100644
--- a/libavutil/hwcontext_internal.h
+++ b/libavutil/hwcontext_internal.h
@@ -99,5 +99,6 @@ struct AVHWFramesInternal {
 extern const HWContextType ff_hwcontext_type_cuda;
 extern const HWContextType ff_hwcontext_type_vaapi;
 extern const HWContextType ff_hwcontext_type_vdpau;
+extern const HWContextType ff_hwcontext_type_qsv;
 
 #endif /* AVUTIL_HWCONTEXT_INTERNAL_H */
diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
new file mode 100644
index 000..a86c20e
--- /dev/null
+++ b/libavutil/hwcontext_qsv.c
@@ -0,0 +1,255 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "buffer.h"
+#include "common.h"
+#include "hwcontext.h"
+#include "hwcontext_internal.h"
+#include "hwcontext_qsv.h"
+#include "qsv_internal.h"
+#include "mem.h"
+#include "pixdesc.h"
+#include "pixfmt.h"
+
+#include "libavutil/avstring.h"
+
+#ifdef CONFIG_VAAPI
+#define AVUTIL_QSV_LINUX_SESSION_HANDLE
+
+#include 
+#include 
+#if HAVE_UNISTD_H
+#include 
+#endif
+#include 
+#include 
+#include 
+
+#endif /* CONFIG_VAAPI */
+
+#define QSV_VERSION_MAJOR 1
+#define QSV_VERSION_MINOR 9
+
+typedef struct QSVDeviceContext {
+
+#ifdef AVUTIL_QSV_LINUX_SESSION_HANDLE
+int   fd_display;
+VADisplay va_display;
+#endif
+
+} QSVDeviceContext;
+
+static int qsv_

[FFmpeg-devel] [PATCH 3/5] avcodec/qsvdec: use hwcontext_qsv instead of ff_qsv_init_internal_session

2016-05-25 Thread nablet developer
Signed-off-by: nablet developer <s...@nablet.com>
---
 libavcodec/qsvdec.c | 29 ++---
 libavcodec/qsvdec.h |  4 +---
 2 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 5253a57..e21ed20 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -31,6 +31,8 @@
 #include "libavutil/log.h"
 #include "libavutil/pixfmt.h"
 #include "libavutil/time.h"
+#include "libavutil/hwcontext.h"
+#include "libavutil/hwcontext_qsv.h"
 
 #include "avcodec.h"
 #include "internal.h"
@@ -75,14 +77,27 @@ static int qsv_decode_init(AVCodecContext *avctx, 
QSVContext *q, AVPacket *avpkt
 q->nb_ext_buffers = qsv->nb_ext_buffers;
 }
 if (!q->session) {
-if (!q->internal_qs.session) {
-ret = ff_qsv_init_internal_session(avctx, >internal_qs,
-   q->load_plugins);
-if (ret < 0)
-return ret;
+AVHWDeviceContext *device_ctx;
+AVQSVDeviceContext *device_hwctx;
+
+if (!q->hwdevice) {
+q->hwdevice = av_hwdevice_ctx_alloc(AV_HWDEVICE_TYPE_QSV);
+if (!q->hwdevice) {
+return AVERROR(ENOMEM);
+}
 }
+device_ctx = (AVHWDeviceContext*)q->hwdevice->data;
+device_hwctx = device_ctx->hwctx;
 
-q->session = q->internal_qs.session;
+if (!device_hwctx->session) {
+device_hwctx->load_plugins = q->load_plugins;
+
+ret = av_hwdevice_ctx_init(q->hwdevice);
+if (ret < 0) {
+return ret;
+}
+}
+q->session = device_hwctx->session;
 }
 
 if (avpkt->size) {
@@ -596,7 +611,7 @@ int ff_qsv_decode_close(QSVContext *q)
 
 q->session = NULL;
 
-ff_qsv_close_internal_session(>internal_qs);
+av_buffer_unref(>hwdevice);
 
 av_fifo_free(q->async_fifo);
 q->async_fifo = NULL;
diff --git a/libavcodec/qsvdec.h b/libavcodec/qsvdec.h
index 97a3315..eba1d05 100644
--- a/libavcodec/qsvdec.h
+++ b/libavcodec/qsvdec.h
@@ -39,9 +39,7 @@ typedef struct QSVContext {
 // the session used for decoding
 mfxSession session;
 
-// the session we allocated internally, in case the caller did not provide
-// one
-QSVSession internal_qs;
+AVBufferRef *hwdevice;
 
 /**
  * a linked list of frames currently being used by QSV
-- 
1.8.3.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 4/5] avcodec/qsvenc: use hwcontext_qsv instead of ff_qsv_init_internal_session

2016-05-25 Thread nablet developer
Signed-off-by: nablet developer <s...@nablet.com>
---
 libavcodec/qsvenc.c | 29 +++--
 libavcodec/qsvenc.h |  3 +--
 2 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 6145121..8eefa06 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -30,6 +30,8 @@
 #include "libavutil/log.h"
 #include "libavutil/time.h"
 #include "libavutil/imgutils.h"
+#include "libavutil/hwcontext.h"
+#include "libavutil/hwcontext_qsv.h"
 #include "libavcodec/bytestream.h"
 
 #include "avcodec.h"
@@ -697,12 +699,27 @@ int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext 
*q)
 }
 
 if (!q->session) {
-ret = ff_qsv_init_internal_session(avctx, >internal_qs,
-   q->load_plugins);
-if (ret < 0)
-return ret;
+AVHWDeviceContext *device_ctx;
+AVQSVDeviceContext *device_hwctx;
+
+if (!q->hwdevice) {
+q->hwdevice = av_hwdevice_ctx_alloc(AV_HWDEVICE_TYPE_QSV);
+if (!q->hwdevice) {
+return AVERROR(ENOMEM);
+}
+}
+device_ctx = (AVHWDeviceContext*)q->hwdevice->data;
+device_hwctx = device_ctx->hwctx;
 
-q->session = q->internal_qs.session;
+if (!device_hwctx->session) {
+device_hwctx->load_plugins = q->load_plugins;
+
+ret = av_hwdevice_ctx_init(q->hwdevice);
+if (ret < 0) {
+return ret;
+}
+}
+q->session = device_hwctx->session;
 }
 
 ret = init_video_param(avctx, q);
@@ -1084,7 +1101,7 @@ int ff_qsv_enc_close(AVCodecContext *avctx, QSVEncContext 
*q)
 MFXVideoENCODE_Close(q->session);
 q->session = NULL;
 
-ff_qsv_close_internal_session(>internal_qs);
+av_buffer_unref(>hwdevice);
 
 cur = q->work_frames;
 while (cur) {
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 2d7bd32..7c9c1e2 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -79,8 +79,7 @@ typedef struct QSVEncContext {
 QSVFrame *work_frames;
 
 mfxSession session;
-QSVSession internal_qs;
-
+AVBufferRef *hwdevice;
 int packet_size;
 int width_align;
 int height_align;
-- 
1.8.3.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 0/5] avutil/qsv add hwcontext_qsv

2016-05-25 Thread nablet developer
added hwcontext_qsv (Intel QuickSync video)
it will handle MFX session initialization and deinitialization,
and will allow to share that code between libavcodec and libavfilter
without adding new API calls for QSV, and also using similar approach
to CUDA & VAAPI
(VPP filter patch is postponded with suggestion to implementa hwcontext_qsv)

nablet developer (5):
  avutil/qsv: move ff_qsv_error function from libavcodec into libavutil,
because it's going to be shared between libavcodec (existing QSV
encoders & decoders), libavfilter (upcoming QSV VPP filter) and
libavutil itself (upcoming hwcontext_qsv implementation). prefix
changed to avpriv since it's now shared between multiple libraries.
  avutil/qsv: add hwcontext_qsv (QuickSync Video)
  avcodec/qsvdec: use hwcontext_qsv instead of
ff_qsv_init_internal_session
  avcodec/qsvenc: use hwcontext_qsv instead of
ff_qsv_init_internal_session
  avcodec/qsv: remove no longer needed functions
ff_qsv_init_internal_session & ff_qsv_close_internal_session,
structure QSVSession, since they are now replaced by
avutil/hwcontext_qsv

 libavcodec/qsv.c   | 221 +--
 libavcodec/qsv_internal.h  |  35 --
 libavcodec/qsvdec.c|  36 --
 libavcodec/qsvdec.h|   4 +-
 libavcodec/qsvenc.c|  40 +--
 libavcodec/qsvenc.h|   3 +-
 libavutil/Makefile |   4 +
 libavutil/hwcontext.c  |   3 +
 libavutil/hwcontext.h  |   1 +
 libavutil/hwcontext_internal.h |   1 +
 libavutil/hwcontext_qsv.c  | 255 +
 libavutil/hwcontext_qsv.h  |  45 
 libavutil/qsv_internal.c   |  58 ++
 libavutil/qsv_internal.h   |  27 +
 14 files changed, 452 insertions(+), 281 deletions(-)
 create mode 100644 libavutil/hwcontext_qsv.c
 create mode 100644 libavutil/hwcontext_qsv.h
 create mode 100644 libavutil/qsv_internal.c
 create mode 100644 libavutil/qsv_internal.h

-- 
1.8.3.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avutil/qsv: move ff_qsv_error function from libavcodec into libavutil, because it's going to be shared between libavcodec (existing QSV encoders & decoders), libavfilter (up

2016-05-24 Thread nablet developer

> On 24 May 2016, at 17:01, Mark Thompson <s...@jkqxz.net> wrote:
> 
> On 13/04/16 09:18, nablet developer wrote:
>> Signed-off-by: nablet developer <s...@nablet.com>
>> ---
>> libavcodec/qsv.c  | 35 +---
>> libavcodec/qsv_internal.h |  5 
>> libavcodec/qsvdec.c   |  1 +
>> libavcodec/qsvenc.c   |  1 +
>> libavutil/Makefile|  1 +
>> libavutil/qsv_internal.c  | 58 
>> +++
>> libavutil/qsv_internal.h  | 27 ++
>> 7 files changed, 89 insertions(+), 39 deletions(-)
>> create mode 100644 libavutil/qsv_internal.c
>> create mode 100644 libavutil/qsv_internal.h
>> 
>> diff --git a/libavutil/qsv_internal.h b/libavutil/qsv_internal.h
>> new file mode 100644
>> index 000..de00d09
>> --- /dev/null
>> +++ b/libavutil/qsv_internal.h
>> ...
>> +/**
>> +  * Convert a libmfx error code into a ffmpeg error code.
>> +  */
>> +int ff_qsv_error(int mfx_err);
> 
> This fails for non-static builds because of the namespace prefix (try building
> the shared libraries).

oh, good catch, thanks. I think function then should be called 
"avpriv_qsv_error" according to the 
https://ffmpeg.org/developer.html#Naming-conventions 
<https://ffmpeg.org/developer.html#Naming-conventions>, right?
I will also test my further changes with shared builds starting from now (I was 
using instructions from https://trac.ffmpeg.org/wiki/CompilationGuide/Centos 
<https://trac.ffmpeg.org/wiki/CompilationGuide/Centos> which were for static 
build).

> 
> Does this function really need to be available everywhere?  I think you should
> wait until you have other patches which actually require it to so that this
> change can be assessed properly.  In isolation, it is not useful.

hm, if my other patches will depend on this patch, how can they be applied 
before this change? I am actually following advice from 
https://ffmpeg.org/developer.html#Submitting-patches-1 
<https://ffmpeg.org/developer.html#Submitting-patches-1> to split patches into 
small self-contained pieces. please advice how to proceed.

> 
> Also, you should have a look at your mail setup.  This arrived today dated six
> weeks ago - either it has taken unreasonably long to arrive or something 
> strange
> is going on at your sending machine.

e-mail was sent today - I was using CentOS development virtual machine which 
had no ntp installed, now it's corrected. sorry for the inconveniences.

> 
> Thanks,
> 
> - Mark
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avutil/qsv: move ff_qsv_error function from libavcodec into libavutil, because it's going to be shared between libavcodec (existing QSV encoders & decoders), libavfilter (upcomi

2016-05-24 Thread nablet developer
Signed-off-by: nablet developer <s...@nablet.com>
---
 libavcodec/qsv.c  | 35 +---
 libavcodec/qsv_internal.h |  5 
 libavcodec/qsvdec.c   |  1 +
 libavcodec/qsvenc.c   |  1 +
 libavutil/Makefile|  1 +
 libavutil/qsv_internal.c  | 58 +++
 libavutil/qsv_internal.h  | 27 ++
 7 files changed, 89 insertions(+), 39 deletions(-)
 create mode 100644 libavutil/qsv_internal.c
 create mode 100644 libavutil/qsv_internal.h

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 11d453d..6db4dd4 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -29,6 +29,7 @@
 
 #include "avcodec.h"
 #include "qsv_internal.h"
+#include "libavutil/qsv_internal.h"
 
 int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
 {
@@ -51,40 +52,6 @@ int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
 return AVERROR(ENOSYS);
 }
 
-int ff_qsv_error(int mfx_err)
-{
-switch (mfx_err) {
-case MFX_ERR_NONE:
-return 0;
-case MFX_ERR_MEMORY_ALLOC:
-case MFX_ERR_NOT_ENOUGH_BUFFER:
-return AVERROR(ENOMEM);
-case MFX_ERR_INVALID_HANDLE:
-return AVERROR(EINVAL);
-case MFX_ERR_DEVICE_FAILED:
-case MFX_ERR_DEVICE_LOST:
-case MFX_ERR_LOCK_MEMORY:
-return AVERROR(EIO);
-case MFX_ERR_NULL_PTR:
-case MFX_ERR_UNDEFINED_BEHAVIOR:
-case MFX_ERR_NOT_INITIALIZED:
-return AVERROR_BUG;
-case MFX_ERR_UNSUPPORTED:
-case MFX_ERR_NOT_FOUND:
-return AVERROR(ENOSYS);
-case MFX_ERR_MORE_DATA:
-case MFX_ERR_MORE_SURFACE:
-case MFX_ERR_MORE_BITSTREAM:
-return AVERROR(EAGAIN);
-case MFX_ERR_INCOMPATIBLE_VIDEO_PARAM:
-case MFX_ERR_INVALID_VIDEO_PARAM:
-return AVERROR(EINVAL);
-case MFX_ERR_ABORTED:
-case MFX_ERR_UNKNOWN:
-default:
-return AVERROR_UNKNOWN;
-}
-}
 static int ff_qsv_set_display_handle(AVCodecContext *avctx, QSVSession *qs)
 {
 // this code is only required for Linux.  It searches for a valid
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index f289a2b..ce2531b 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -73,11 +73,6 @@ typedef struct QSVSession {
 #endif
 } QSVSession;
 
-/**
- * Convert a libmfx error code into a ffmpeg error code.
- */
-int ff_qsv_error(int mfx_err);
-
 int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id);
 
 int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs,
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index c17606d..a2a90b5 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -36,6 +36,7 @@
 #include "internal.h"
 #include "qsv.h"
 #include "qsv_internal.h"
+#include "libavutil/qsv_internal.h"
 #include "qsvdec.h"
 
 int ff_qsv_map_pixfmt(enum AVPixelFormat format)
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 132cf47..442ead6 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -36,6 +36,7 @@
 #include "internal.h"
 #include "qsv.h"
 #include "qsv_internal.h"
+#include "libavutil/qsv_internal.h"
 #include "qsvenc.h"
 
 static const struct {
diff --git a/libavutil/Makefile b/libavutil/Makefile
index a35deb6..e358767 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -154,6 +154,7 @@ OBJS-$(!HAVE_ATOMICS_NATIVE)+= atomic.o 
\
 OBJS-$(CONFIG_CUDA) += hwcontext_cuda.o
 OBJS-$(CONFIG_LZO)  += lzo.o
 OBJS-$(CONFIG_OPENCL)   += opencl.o opencl_internal.o
+OBJS-$(CONFIG_QSV)  += qsv_internal.o
 OBJS-$(CONFIG_VAAPI)+= hwcontext_vaapi.o
 OBJS-$(CONFIG_VDPAU)+= hwcontext_vdpau.o
 
diff --git a/libavutil/qsv_internal.c b/libavutil/qsv_internal.c
new file mode 100644
index 000..9ebe035
--- /dev/null
+++ b/libavutil/qsv_internal.c
@@ -0,0 +1,58 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+#include "avutil.h"
+#include "qsv_internal.h"
+
+#include 
+
+int ff_qsv_error(int mfx_err)
+{
+switch (mfx_err) 

Re: [FFmpeg-devel] [PATCH] avcodec/qsv: export session management functionality

2016-04-13 Thread nablet developer

> On 13 Apr 2016, at 14:48, Mark Thompson <s...@jkqxz.net> wrote:
> 
> On 13/04/16 09:14, nablet developer wrote:
>> 
>>> On 13 Apr 2016, at 14:08, wm4 <nfx...@googlemail.com> wrote:
>>> 
>>> On Thu,  7 Apr 2016 11:44:20 -0400
>>> nablet developer <s...@nablet.com <mailto:s...@nablet.com>> wrote:
>>> 
>>>> Signed-off-by: nablet developer <s...@nablet.com>
>>>> ---
>>>> libavcodec/qsv.c  | 64 
>>>> +--
>>>> libavcodec/qsv.h  | 53 +++
>>>> libavcodec/qsv_api.c  | 26 +++
>>>> libavcodec/qsv_internal.h | 15 +--
>>>> libavcodec/qsvdec.c   | 13 +-
>>>> libavcodec/qsvdec.h   |  3 ++-
>>>> libavcodec/qsvenc.c   | 16 ++--
>>>> libavcodec/qsvenc.h   |  2 +-
>>>> 8 files changed, 125 insertions(+), 67 deletions(-)
>>> 
>>> Why would this API need to be exported?
>> 
>> previously QuickSync was used only by libavcodec and its components - e.g. 
>> there are QSV encoder and decoders for AVC and MPEG-2. so it was OK that 
>> QuickSync initialisation and cleanup functions were local for libavcodec.
>> 
>> but right now we're adding QuickSync VPP component to libavfilter, so 
>> mentioned functions now become shared at least between libavcodec and 
>> libavfilter.
>> therefore, patch to add QSV VPP filter was rejected because it accessed 
>> libavcodec functions which were local, and it was suggested that such 
>> functions are need to be exported from libavcodec, so libavfilter can use 
>> them.
>> 
> 
> This is precisely one of the problems that the hwcontext code was designed to
> solve.  I suggest using that rather than adding new ad-hoc codec-specific API
> calls - make libavutil/hwcontext_qsv.c; it should not require any new API 
> calls
> at all.  As a bonus, it also solves the context propagation problem which you
> will run into later when combining multiple filter and codec components.

okay, I will add libavutil/hwcontext_qsv and prepare new patch. thanks a lot 
for the suggestion.

> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avcodec/qsv: export session management functionality

2016-04-13 Thread nablet developer

> On 13 Apr 2016, at 14:33, wm4 <nfx...@googlemail.com> wrote:
> 
> On Wed, 13 Apr 2016 14:14:37 +0600
> nablet developer <s...@nablet.com> wrote:
> 
>>> Why would this API need to be exported?  
>> 
>> previously QuickSync was used only by libavcodec and its components - e.g. 
>> there are QSV encoder and decoders for AVC and MPEG-2. so it was OK that 
>> QuickSync initialisation and cleanup functions were local for libavcodec.
>> 
>> but right now we're adding QuickSync VPP component to libavfilter, so 
>> mentioned functions now become shared at least between libavcodec and 
>> libavfilter.
>> therefore, patch to add QSV VPP filter was rejected because it accessed 
>> libavcodec functions which were local, and it was suggested that such 
>> functions are need to be exported from libavcodec, so libavfilter can use 
>> them.
> 
> Wouldn't it be better to keep it internal then? Sharing code between
> the sub-libs is unfortunately messy, but possible. For example, you
> could create a dummy .c file in libavfilter that includes the
> libavcodec one. Not beautiful, but might be better than making the API
> public. Not sure what other devs think about this.

I suppose it might cause linking issues in static builds (duplicated symbols).

> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avcodec/qsv: export session management functionality

2016-04-13 Thread nablet developer

> On 13 Apr 2016, at 14:08, wm4 <nfx...@googlemail.com> wrote:
> 
> On Thu,  7 Apr 2016 11:44:20 -0400
> nablet developer <s...@nablet.com <mailto:s...@nablet.com>> wrote:
> 
>> Signed-off-by: nablet developer <s...@nablet.com>
>> ---
>> libavcodec/qsv.c  | 64 
>> +--
>> libavcodec/qsv.h  | 53 +++
>> libavcodec/qsv_api.c  | 26 +++
>> libavcodec/qsv_internal.h | 15 +--
>> libavcodec/qsvdec.c   | 13 +-
>> libavcodec/qsvdec.h   |  3 ++-
>> libavcodec/qsvenc.c   | 16 ++--
>> libavcodec/qsvenc.h   |  2 +-
>> 8 files changed, 125 insertions(+), 67 deletions(-)
>> 
>> diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
>> index 4c8e6b0..81d1f0c 100644
>> --- a/libavcodec/qsv.c
>> +++ b/libavcodec/qsv.c
>> @@ -18,14 +18,19 @@
>>  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
>> USA
>>  */
>> 
>> -#include 
>> -#include 
>> -
>> #include 
>> #include 
>> 
>> #include "libavutil/avstring.h"
>> #include "libavutil/error.h"
>> +#include "libavutil/log.h"
>> +
>> +#include "qsv.h"
>> +
>> +#if CONFIG_QSV
>> +
>> +#include 
>> +#include 
>> 
>> #include "avcodec.h"
>> #include "qsv_internal.h"
>> @@ -51,7 +56,7 @@ int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
>> return AVERROR(ENOSYS);
>> }
>> 
>> -int ff_qsv_error(int mfx_err)
>> +int av_qsv_error(int mfx_err)
>> {
>> switch (mfx_err) {
>> case MFX_ERR_NONE:
>> @@ -85,7 +90,7 @@ int ff_qsv_error(int mfx_err)
>> return AVERROR_UNKNOWN;
>> }
>> }
>> -static int ff_qsv_set_display_handle(AVCodecContext *avctx, QSVSession *qs)
>> +static int ff_qsv_set_display_handle(AVClass *avccl, struct AVQSVSession 
>> *qs)
>> {
>> // this code is only required for Linux.  It searches for a valid
>> // display handle.  First in /dev/dri/renderD then in /dev/dri/card
>> @@ -115,14 +120,14 @@ static int ff_qsv_set_display_handle(AVCodecContext 
>> *avctx, QSVSession *qs)
>> 
>> fd = open(adapterpath, O_RDWR);
>> if (fd < 0) {
>> -av_log(avctx, AV_LOG_ERROR,
>> +av_log(avccl, AV_LOG_ERROR,
>> "mfx init: %s fd open failed\n", adapterpath);
>> continue;
>> }
>> 
>> va_dpy = vaGetDisplayDRM(fd);
>> if (!va_dpy) {
>> -av_log(avctx, AV_LOG_ERROR,
>> +av_log(avccl, AV_LOG_ERROR,
>> "mfx init: %s vaGetDisplayDRM failed\n", adapterpath);
>> close(fd);
>> continue;
>> @@ -130,22 +135,22 @@ static int ff_qsv_set_display_handle(AVCodecContext 
>> *avctx, QSVSession *qs)
>> 
>> va_res = vaInitialize(va_dpy, _version, _version);
>> if (VA_STATUS_SUCCESS != va_res) {
>> -av_log(avctx, AV_LOG_ERROR,
>> +av_log(avccl, AV_LOG_ERROR,
>> "mfx init: %s vaInitialize failed\n", adapterpath);
>> close(fd);
>> fd = -1;
>> continue;
>> } else {
>> -av_log(avctx, AV_LOG_VERBOSE,
>> +av_log(avccl, AV_LOG_VERBOSE,
>> "mfx initialization: %s vaInitialize successful\n",adapterpath);
>> qs->fd_display = fd;
>> qs->va_display = va_dpy;
>> ret = MFXVideoCORE_SetHandle(qs->session,
>>   (mfxHandleType)MFX_HANDLE_VA_DISPLAY, (mfxHDL)va_dpy);
>> if (ret < 0) {
>> -av_log(avctx, AV_LOG_ERROR,
>> +av_log(avccl, AV_LOG_ERROR,
>> "Error %d during set display handle\n", ret);
>> -return ff_qsv_error(ret);
>> +return av_qsv_error(ret);
>> }
>> break;
>> }
>> @@ -153,22 +158,7 @@ static int ff_qsv_set_display_handle(AVCodecContext 
>> *avctx, QSVSession *qs)
>> #endif //AVCODEC_QSV_LINUX_SESSION_HANDLE
>> return 0;
>> }
>> -/**
>> - * @brief Initialize a MSDK session
>> - *
>> - * Media SDK is based on sessions, so this is the prerequisite
>> - * initialization for HW acceleration.  For Windows the 

Re: [FFmpeg-devel] [PATCH] avcodec/qsv: export session management functionality

2016-04-13 Thread nablet developer

> On 13 Apr 2016, at 14:16, Hendrik Leppkes <h.lepp...@gmail.com> wrote:
> 
> On Thu, Apr 7, 2016 at 5:44 PM, nablet developer <s...@nablet.com> wrote:
>> 
>> +/**
>> + * Initialize a MSDK session
>> + *
>> + * Media SDK is based on sessions, so this is the prerequisite
>> + * initialization for HW acceleration.  For Windows the session is
>> + * complete and ready to use, for Linux a display handle is
>> + * required.  For releases of Media Server Studio >= 2015 R4 the
>> + * render nodes interface is preferred (/dev/dri/renderD).
>> + * Using Media Server Studio 2015 R4 or newer is recommended
>> + * but the older /dev/dri/card interface is also searched
>> + * for broader compatibility.
>> + *
>> + * @param avccl pointer to AVClass, uses for logging
>> + * @param qsthe MSDK session used
>> + * @param load_plugins  list of hexadecimal plug-in UIDs delimeted by 
>> colons.
>> + */
>> +int av_qsv_init_session(AVClass *avccl, AVQSVSession *qs,
>> +const char *load_plugins);
> 
> This looks wrong, we don't pass pointers to an AVClass around. The
> logging functions want a pointer to a pointer to a AVClass either way
> (ie. a AVClass pointer embedded in another struct)
> If you want to pass a generic logging context, make it accept a void*,
> not AVClass.
> 
> The same for all other methods where this applies.

thanks, roger that. I'll correct that today and prepare & send new patch.

> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avcodec/qsv: export session management functionality

2016-04-13 Thread nablet developer

> On 11 Apr 2016, at 18:30, nablet developer <s...@nablet.com> wrote:
> 
> 
>>> 
>>> diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
>>> index 4c8e6b0..81d1f0c 100644
>>> --- a/libavcodec/qsv.c
>>> +++ b/libavcodec/qsv.c
>>> @@ -18,14 +18,19 @@
>>> * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
>>> USA
>>> */
>>> 
>>> -#include 
>>> -#include 
>>> -
>>> #include 
>>> #include 
>>> 
>>> #include "libavutil/avstring.h"
>>> #include "libavutil/error.h"
>>> +#include "libavutil/log.h"
>>> +
>>> +#include "qsv.h"
>>> +
>>> +#if CONFIG_QSV
>> 
>> conditional compilation belongs in the Makefile
> 
> 
> the idea here is to provide API functions for QuickSync 
> initialisation/de-initializtion stuff.
> as I understand, ffmpeg API functions must be always present, regardless if 
> QuickSync is available or not.
> if QuickSync is not available, then "dummy" functions are provides that do 
> nothing and just return an error.
> so, do I right understand that correct approach for it is providing two files 
> : one with actual implementation (qsv.c), and another with dummy 
> implementation (e.g. qsv_dummy.c), and select one of them in makefile?
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
ping. please recommend how to deal with that.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avcodec/qsv: export session management functionality

2016-04-11 Thread nablet developer

>> 
>> diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
>> index 4c8e6b0..81d1f0c 100644
>> --- a/libavcodec/qsv.c
>> +++ b/libavcodec/qsv.c
>> @@ -18,14 +18,19 @@
>>  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
>> USA
>>  */
>> 
>> -#include 
>> -#include 
>> -
>> #include 
>> #include 
>> 
>> #include "libavutil/avstring.h"
>> #include "libavutil/error.h"
>> +#include "libavutil/log.h"
>> +
>> +#include "qsv.h"
>> +
>> +#if CONFIG_QSV
> 
> conditional compilation belongs in the Makefile


the idea here is to provide API functions for QuickSync 
initialisation/de-initializtion stuff.
as I understand, ffmpeg API functions must be always present, regardless if 
QuickSync is available or not.
if QuickSync is not available, then "dummy" functions are provides that do 
nothing and just return an error.
so, do I right understand that correct approach for it is providing two files : 
one with actual implementation (qsv.c), and another with dummy implementation 
(e.g. qsv_dummy.c), and select one of them in makefile?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avcodec/qsv: export session management functionality

2016-04-11 Thread nablet developer
Signed-off-by: nablet developer <s...@nablet.com>
---
 libavcodec/qsv.c  | 64 +--
 libavcodec/qsv.h  | 53 +++
 libavcodec/qsv_api.c  | 26 +++
 libavcodec/qsv_internal.h | 15 +--
 libavcodec/qsvdec.c   | 13 +-
 libavcodec/qsvdec.h   |  3 ++-
 libavcodec/qsvenc.c   | 16 ++--
 libavcodec/qsvenc.h   |  2 +-
 8 files changed, 125 insertions(+), 67 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 4c8e6b0..81d1f0c 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -18,14 +18,19 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include 
-#include 
-
 #include 
 #include 
 
 #include "libavutil/avstring.h"
 #include "libavutil/error.h"
+#include "libavutil/log.h"
+
+#include "qsv.h"
+
+#if CONFIG_QSV
+
+#include 
+#include 
 
 #include "avcodec.h"
 #include "qsv_internal.h"
@@ -51,7 +56,7 @@ int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
 return AVERROR(ENOSYS);
 }
 
-int ff_qsv_error(int mfx_err)
+int av_qsv_error(int mfx_err)
 {
 switch (mfx_err) {
 case MFX_ERR_NONE:
@@ -85,7 +90,7 @@ int ff_qsv_error(int mfx_err)
 return AVERROR_UNKNOWN;
 }
 }
-static int ff_qsv_set_display_handle(AVCodecContext *avctx, QSVSession *qs)
+static int ff_qsv_set_display_handle(AVClass *avccl, struct AVQSVSession *qs)
 {
 // this code is only required for Linux.  It searches for a valid
 // display handle.  First in /dev/dri/renderD then in /dev/dri/card
@@ -115,14 +120,14 @@ static int ff_qsv_set_display_handle(AVCodecContext 
*avctx, QSVSession *qs)
 
 fd = open(adapterpath, O_RDWR);
 if (fd < 0) {
-av_log(avctx, AV_LOG_ERROR,
+av_log(avccl, AV_LOG_ERROR,
 "mfx init: %s fd open failed\n", adapterpath);
 continue;
 }
 
 va_dpy = vaGetDisplayDRM(fd);
 if (!va_dpy) {
-av_log(avctx, AV_LOG_ERROR,
+av_log(avccl, AV_LOG_ERROR,
 "mfx init: %s vaGetDisplayDRM failed\n", adapterpath);
 close(fd);
 continue;
@@ -130,22 +135,22 @@ static int ff_qsv_set_display_handle(AVCodecContext 
*avctx, QSVSession *qs)
 
 va_res = vaInitialize(va_dpy, _version, _version);
 if (VA_STATUS_SUCCESS != va_res) {
-av_log(avctx, AV_LOG_ERROR,
+av_log(avccl, AV_LOG_ERROR,
 "mfx init: %s vaInitialize failed\n", adapterpath);
 close(fd);
 fd = -1;
 continue;
 } else {
-av_log(avctx, AV_LOG_VERBOSE,
+av_log(avccl, AV_LOG_VERBOSE,
 "mfx initialization: %s vaInitialize successful\n",adapterpath);
 qs->fd_display = fd;
 qs->va_display = va_dpy;
 ret = MFXVideoCORE_SetHandle(qs->session,
   (mfxHandleType)MFX_HANDLE_VA_DISPLAY, (mfxHDL)va_dpy);
 if (ret < 0) {
-av_log(avctx, AV_LOG_ERROR,
+av_log(avccl, AV_LOG_ERROR,
 "Error %d during set display handle\n", ret);
-return ff_qsv_error(ret);
+return av_qsv_error(ret);
 }
 break;
 }
@@ -153,22 +158,7 @@ static int ff_qsv_set_display_handle(AVCodecContext 
*avctx, QSVSession *qs)
 #endif //AVCODEC_QSV_LINUX_SESSION_HANDLE
 return 0;
 }
-/**
- * @brief Initialize a MSDK session
- *
- * Media SDK is based on sessions, so this is the prerequisite
- * initialization for HW acceleration.  For Windows the session is
- * complete and ready to use, for Linux a display handle is
- * required.  For releases of Media Server Studio >= 2015 R4 the
- * render nodes interface is preferred (/dev/dri/renderD).
- * Using Media Server Studio 2015 R4 or newer is recommended
- * but the older /dev/dri/card interface is also searched
- * for broader compatibility.
- *
- * @param avctxffmpeg metadata for this codec context
- * @param session  the MSDK session used
- */
-int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs,
+int av_qsv_init_session(AVClass *avccl, struct AVQSVSession *qs,
  const char *load_plugins)
 {
 mfxIMPL impl   = MFX_IMPL_AUTO_ANY;
@@ -179,11 +169,11 @@ int ff_qsv_init_internal_session(AVCodecContext *avctx, 
QSVSession *qs,
 
 ret = MFXInit(impl, , >session);
 if (ret < 0) {
-av_log(avctx, AV_LOG_ERROR, "Error initializing an internal MFX 
session\n");
-return ff_qsv_error(ret);
+av_log(avccl, AV_LOG_ERROR, "Error initializing an internal MFX 
session\n");
+return av_qsv_error(ret);
 }
 
-ret = ff_qsv_set_display_handle(avctx, qs);
+