[FFmpeg-cvslog] libavformat/flvenc: refactoring: extracted method for writing codec headers

2016-06-11 Thread Ivan
ffmpeg | branch: master | Ivan  | Thu Jun  9 
22:12:09 2016 -0400| [52985768afd27c9a582ece03d2c49556578ea90e] | committer: 
Michael Niedermayer

libavformat/flvenc: refactoring: extracted method for writing codec headers

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=52985768afd27c9a582ece03d2c49556578ea90e
---

 libavformat/flvenc.c |  116 --
 1 file changed, 64 insertions(+), 52 deletions(-)

diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index d62ff70..cf8d221 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -343,12 +343,74 @@ static int unsupported_codec(AVFormatContext *s,
 return AVERROR(ENOSYS);
 }
 
+static void flv_write_codec_header(AVFormatContext* s, AVCodecParameters* par) 
{
+int64_t data_size;
+AVIOContext *pb = s->pb;
+FLVContext *flv = s->priv_data;
+
+if (par->codec_id == AV_CODEC_ID_AAC || par->codec_id == AV_CODEC_ID_H264
+|| par->codec_id == AV_CODEC_ID_MPEG4) {
+int64_t pos;
+avio_w8(pb,
+par->codec_type == AVMEDIA_TYPE_VIDEO ?
+FLV_TAG_TYPE_VIDEO : FLV_TAG_TYPE_AUDIO);
+avio_wb24(pb, 0); // size patched later
+avio_wb24(pb, 0); // ts
+avio_w8(pb, 0);   // ts ext
+avio_wb24(pb, 0); // streamid
+pos = avio_tell(pb);
+if (par->codec_id == AV_CODEC_ID_AAC) {
+avio_w8(pb, get_audio_flags(s, par));
+avio_w8(pb, 0); // AAC sequence header
+
+if (!par->extradata_size && flv->flags & 1) {
+PutBitContext pbc;
+int samplerate_index;
+int channels = flv->audio_par->channels
+- (flv->audio_par->channels == 8 ? 1 : 0);
+uint8_t data[2];
+
+for (samplerate_index = 0; samplerate_index < 16;
+samplerate_index++)
+if (flv->audio_par->sample_rate
+== mpeg4audio_sample_rates[samplerate_index])
+break;
+
+init_put_bits(&pbc, data, sizeof(data));
+put_bits(&pbc, 5, flv->audio_par->profile + 1); //profile
+put_bits(&pbc, 4, samplerate_index); //sample rate index
+put_bits(&pbc, 4, channels);
+put_bits(&pbc, 1, 0); //frame length - 1024 samples
+put_bits(&pbc, 1, 0); //does not depend on core coder
+put_bits(&pbc, 1, 0); //is not extension
+flush_put_bits(&pbc);
+
+avio_w8(pb, data[0]);
+avio_w8(pb, data[1]);
+
+av_log(s, AV_LOG_WARNING, "AAC sequence header: %02x %02x.\n",
+data[0], data[1]);
+}
+avio_write(pb, par->extradata, par->extradata_size);
+} else {
+avio_w8(pb, par->codec_tag | FLV_FRAME_KEY); // flags
+avio_w8(pb, 0); // AVC sequence header
+avio_wb24(pb, 0); // composition time
+ff_isom_write_avcc(pb, par->extradata, par->extradata_size);
+}
+data_size = avio_tell(pb) - pos;
+avio_seek(pb, -data_size - 10, SEEK_CUR);
+avio_wb24(pb, data_size);
+avio_skip(pb, data_size + 10 - 3);
+avio_wb32(pb, data_size + 11); // previous tag size
+}
+}
+
 static int flv_write_header(AVFormatContext *s)
 {
 int i;
 AVIOContext *pb = s->pb;
 FLVContext *flv = s->priv_data;
-int64_t data_size;
 
 for (i = 0; i < s->nb_streams; i++) {
 AVCodecParameters *par = s->streams[i]->codecpar;
@@ -446,57 +508,7 @@ static int flv_write_header(AVFormatContext *s)
 write_metadata(s, 0);
 
 for (i = 0; i < s->nb_streams; i++) {
-AVCodecParameters *par = s->streams[i]->codecpar;
-if (par->codec_id == AV_CODEC_ID_AAC || par->codec_id == 
AV_CODEC_ID_H264 || par->codec_id == AV_CODEC_ID_MPEG4) {
-int64_t pos;
-avio_w8(pb, par->codec_type == AVMEDIA_TYPE_VIDEO ?
-FLV_TAG_TYPE_VIDEO : FLV_TAG_TYPE_AUDIO);
-avio_wb24(pb, 0); // size patched later
-avio_wb24(pb, 0); // ts
-avio_w8(pb, 0);   // ts ext
-avio_wb24(pb, 0); // streamid
-pos = avio_tell(pb);
-if (par->codec_id == AV_CODEC_ID_AAC) {
-avio_w8(pb, get_audio_flags(s, par));
-avio_w8(pb, 0); // AAC sequence header
-
-if (!par->extradata_size && flv->flags & 1) {
-PutBitContext pbc;
-int samplerate_index;
-int channels = flv->audio_par->channels - 
(flv->audio_par->channels ==

[FFmpeg-cvslog] libavformat/flvenc: support for codec configuration change mid stream

2016-06-11 Thread Ivan
ffmpeg | branch: master | Ivan  | Thu Jun  9 
22:12:10 2016 -0400| [c1f57e2f91e250e83830099e3cadeec4f0080bc2] | committer: 
Michael Niedermayer

libavformat/flvenc: support for codec configuration change mid stream

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c1f57e2f91e250e83830099e3cadeec4f0080bc2
---

 libavformat/flvenc.c |   13 +
 1 file changed, 13 insertions(+)

diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index cf8d221..6fd7792 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -566,6 +566,19 @@ static int flv_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 else
 flags_size = 1;
 
+if (par->codec_id == AV_CODEC_ID_AAC || par->codec_id == AV_CODEC_ID_H264
+|| par->codec_id == AV_CODEC_ID_MPEG4) {
+int side_size = 0;
+uint8_t *side = av_packet_get_side_data(pkt, 
AV_PKT_DATA_NEW_EXTRADATA, &side_size);
+if (side && side_size > 0 && (side_size != par->extradata_size || 
memcmp(side, par->extradata, side_size))) {
+av_free(par->extradata);
+par->extradata = av_mallocz(side_size + 
AV_INPUT_BUFFER_PADDING_SIZE);
+memcpy(par->extradata, side, side_size);
+par->extradata_size = side_size;
+flv_write_codec_header(s, par);
+}
+}
+
 if (flv->delay == AV_NOPTS_VALUE)
 flv->delay = -pkt->dts;
 

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


[FFmpeg-cvslog] avformat/flvenc: copyts in FLV muxer

2016-01-26 Thread Ivan
ffmpeg | branch: master | Ivan  | Mon Jan 25 
14:43:40 2016 +0200| [a0174f67298ba9494c146183dd360e637b03db64] | committer: 
Michael Niedermayer

avformat/flvenc: copyts in FLV muxer

The purpose of this patch is to preserve timestamps when using ffmpeg for 
publishing RTMP streams, e.g. ffmpeg -i rtmp://source/stream -f flv 
rtmp://target/stream.
There is a setting "copyts" for that purpose. Unfortunately it doesn't work 
with FLV muxer because it has its own timestamp correction which makes global 
setting "copyts" ineffective.

This patch removes timestamp correction in FLV muxer. This means FLV will rely 
on ffmpeg timestamp correction which makes it possible to use copyts.

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a0174f67298ba9494c146183dd360e637b03db64
---

 libavformat/flvenc.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index 3925768..8fd5d29 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -562,7 +562,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 return AVERROR(EINVAL);
 }
 
-ts = pkt->dts + flv->delay; // add delay to force positive dts
+ts = pkt->dts;
 
 if (s->event_flags & AVSTREAM_EVENT_FLAG_METADATA_UPDATED) {
 write_metadata(s, ts);

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


[FFmpeg-cvslog] avcodec/h264: Fix for H.264 configuration parsing

2016-04-16 Thread Ivan
ffmpeg | branch: master | Ivan  | Tue Apr 12 
16:32:04 2016 -0400| [3a727606c474d3d0b9efa3c900294a84bdb5e331] | committer: 
Michael Niedermayer

avcodec/h264: Fix for H.264 configuration parsing

Sometimes video fails to decode if H.264 configuration changes mid stream.
The reason is that configuration parser assumes that nal_ref_idc is equal to 11b
while actually some codecs but 01b there. The H.264 spec is somewhat
vague about this but it looks like it allows any non-zero nal_ref_idc for 
sps/pps.

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3a727606c474d3d0b9efa3c900294a84bdb5e331
---

 libavcodec/h264.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index f1399b8..88768af 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -1781,7 +1781,7 @@ static int is_extra(const uint8_t *buf, int buf_size)
 const uint8_t *p= buf+6;
 while(cnt--){
 int nalsize= AV_RB16(p) + 2;
-if(nalsize > buf_size - (p-buf) || p[2]!=0x67)
+if(nalsize > buf_size - (p-buf) || (p[2] & 0x9F) != 7)
 return 0;
 p += nalsize;
 }
@@ -1790,7 +1790,7 @@ static int is_extra(const uint8_t *buf, int buf_size)
 return 0;
 while(cnt--){
 int nalsize= AV_RB16(p) + 2;
-if(nalsize > buf_size - (p-buf) || p[2]!=0x68)
+if(nalsize > buf_size - (p-buf) || (p[2] & 0x9F) != 8)
 return 0;
 p += nalsize;
 }

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


[FFmpeg-cvslog] avcodec/h264: Fix for H.264 configuration parsing

2016-04-21 Thread Ivan
ffmpeg | branch: release/3.0 | Ivan  | Tue Apr 12 
16:32:04 2016 -0400| [76573c5239fb7d293cc350807f02cc3e91bff18d] | committer: 
Michael Niedermayer

avcodec/h264: Fix for H.264 configuration parsing

Sometimes video fails to decode if H.264 configuration changes mid stream.
The reason is that configuration parser assumes that nal_ref_idc is equal to 11b
while actually some codecs but 01b there. The H.264 spec is somewhat
vague about this but it looks like it allows any non-zero nal_ref_idc for 
sps/pps.

Signed-off-by: Michael Niedermayer 
(cherry picked from commit 3a727606c474d3d0b9efa3c900294a84bdb5e331)

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=76573c5239fb7d293cc350807f02cc3e91bff18d
---

 libavcodec/h264.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index f1399b8..88768af 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -1781,7 +1781,7 @@ static int is_extra(const uint8_t *buf, int buf_size)
 const uint8_t *p= buf+6;
 while(cnt--){
 int nalsize= AV_RB16(p) + 2;
-if(nalsize > buf_size - (p-buf) || p[2]!=0x67)
+if(nalsize > buf_size - (p-buf) || (p[2] & 0x9F) != 7)
 return 0;
 p += nalsize;
 }
@@ -1790,7 +1790,7 @@ static int is_extra(const uint8_t *buf, int buf_size)
 return 0;
 while(cnt--){
 int nalsize= AV_RB16(p) + 2;
-if(nalsize > buf_size - (p-buf) || p[2]!=0x68)
+if(nalsize > buf_size - (p-buf) || (p[2] & 0x9F) != 8)
 return 0;
 p += nalsize;
 }

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


[FFmpeg-cvslog] avcodec/h264: Fix for H.264 configuration parsing

2016-04-26 Thread Ivan
ffmpeg | branch: release/2.8 | Ivan  | Tue Apr 12 
16:32:04 2016 -0400| [70b3e170f97f4c897f12cdcdaa226d910ea88bb7] | committer: 
Michael Niedermayer

avcodec/h264: Fix for H.264 configuration parsing

Sometimes video fails to decode if H.264 configuration changes mid stream.
The reason is that configuration parser assumes that nal_ref_idc is equal to 11b
while actually some codecs but 01b there. The H.264 spec is somewhat
vague about this but it looks like it allows any non-zero nal_ref_idc for 
sps/pps.

Signed-off-by: Michael Niedermayer 
(cherry picked from commit 3a727606c474d3d0b9efa3c900294a84bdb5e331)

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=70b3e170f97f4c897f12cdcdaa226d910ea88bb7
---

 libavcodec/h264.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index ebdabbd..1c7b8a1 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -1777,7 +1777,7 @@ static int is_extra(const uint8_t *buf, int buf_size)
 const uint8_t *p= buf+6;
 while(cnt--){
 int nalsize= AV_RB16(p) + 2;
-if(nalsize > buf_size - (p-buf) || p[2]!=0x67)
+if(nalsize > buf_size - (p-buf) || (p[2] & 0x9F) != 7)
 return 0;
 p += nalsize;
 }
@@ -1786,7 +1786,7 @@ static int is_extra(const uint8_t *buf, int buf_size)
 return 0;
 while(cnt--){
 int nalsize= AV_RB16(p) + 2;
-if(nalsize > buf_size - (p-buf) || p[2]!=0x68)
+if(nalsize > buf_size - (p-buf) || (p[2] & 0x9F) != 8)
 return 0;
 p += nalsize;
 }

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


[FFmpeg-cvslog] avcodec/h264: Fix for H.264 configuration parsing

2016-04-27 Thread Ivan
ffmpeg | branch: release/2.7 | Ivan  | Tue Apr 12 
16:32:04 2016 -0400| [0696a555b6a516ce569bb2320b512dc790e747b4] | committer: 
Michael Niedermayer

avcodec/h264: Fix for H.264 configuration parsing

Sometimes video fails to decode if H.264 configuration changes mid stream.
The reason is that configuration parser assumes that nal_ref_idc is equal to 11b
while actually some codecs but 01b there. The H.264 spec is somewhat
vague about this but it looks like it allows any non-zero nal_ref_idc for 
sps/pps.

Signed-off-by: Michael Niedermayer 
(cherry picked from commit 3a727606c474d3d0b9efa3c900294a84bdb5e331)

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0696a555b6a516ce569bb2320b512dc790e747b4
---

 libavcodec/h264.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index 1f5f4a0..692cd62 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -1737,7 +1737,7 @@ static int is_extra(const uint8_t *buf, int buf_size)
 const uint8_t *p= buf+6;
 while(cnt--){
 int nalsize= AV_RB16(p) + 2;
-if(nalsize > buf_size - (p-buf) || p[2]!=0x67)
+if(nalsize > buf_size - (p-buf) || (p[2] & 0x9F) != 7)
 return 0;
 p += nalsize;
 }
@@ -1746,7 +1746,7 @@ static int is_extra(const uint8_t *buf, int buf_size)
 return 0;
 while(cnt--){
 int nalsize= AV_RB16(p) + 2;
-if(nalsize > buf_size - (p-buf) || p[2]!=0x68)
+if(nalsize > buf_size - (p-buf) || (p[2] & 0x9F) != 8)
 return 0;
 p += nalsize;
 }

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


[FFmpeg-cvslog] avcodec/h264: Fix for H.264 configuration parsing

2016-04-29 Thread Ivan
ffmpeg | branch: release/2.6 | Ivan  | Tue Apr 12 
16:32:04 2016 -0400| [f3ec2a0859f04b825ba4282275d41c1ebe735cc7] | committer: 
Michael Niedermayer

avcodec/h264: Fix for H.264 configuration parsing

Sometimes video fails to decode if H.264 configuration changes mid stream.
The reason is that configuration parser assumes that nal_ref_idc is equal to 11b
while actually some codecs but 01b there. The H.264 spec is somewhat
vague about this but it looks like it allows any non-zero nal_ref_idc for 
sps/pps.

Signed-off-by: Michael Niedermayer 
(cherry picked from commit 3a727606c474d3d0b9efa3c900294a84bdb5e331)

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f3ec2a0859f04b825ba4282275d41c1ebe735cc7
---

 libavcodec/h264.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index a32366e..4d331f1 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -1765,7 +1765,7 @@ static int is_extra(const uint8_t *buf, int buf_size)
 const uint8_t *p= buf+6;
 while(cnt--){
 int nalsize= AV_RB16(p) + 2;
-if(nalsize > buf_size - (p-buf) || p[2]!=0x67)
+if(nalsize > buf_size - (p-buf) || (p[2] & 0x9F) != 7)
 return 0;
 p += nalsize;
 }
@@ -1774,7 +1774,7 @@ static int is_extra(const uint8_t *buf, int buf_size)
 return 0;
 while(cnt--){
 int nalsize= AV_RB16(p) + 2;
-if(nalsize > buf_size - (p-buf) || p[2]!=0x68)
+if(nalsize > buf_size - (p-buf) || (p[2] & 0x9F) != 8)
 return 0;
 p += nalsize;
 }

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


[FFmpeg-cvslog] avcodec/h264: Fix for H.264 configuration parsing

2016-04-30 Thread Ivan
ffmpeg | branch: release/2.5 | Ivan  | Tue Apr 12 
16:32:04 2016 -0400| [2bb9f5d6074a08c9b7c1567c463e6cc3cdf2b450] | committer: 
Michael Niedermayer

avcodec/h264: Fix for H.264 configuration parsing

Sometimes video fails to decode if H.264 configuration changes mid stream.
The reason is that configuration parser assumes that nal_ref_idc is equal to 11b
while actually some codecs but 01b there. The H.264 spec is somewhat
vague about this but it looks like it allows any non-zero nal_ref_idc for 
sps/pps.

Signed-off-by: Michael Niedermayer 
(cherry picked from commit 3a727606c474d3d0b9efa3c900294a84bdb5e331)

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2bb9f5d6074a08c9b7c1567c463e6cc3cdf2b450
---

 libavcodec/h264.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index 436a079..ba3d910 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -1821,7 +1821,7 @@ static int is_extra(const uint8_t *buf, int buf_size)
 const uint8_t *p= buf+6;
 while(cnt--){
 int nalsize= AV_RB16(p) + 2;
-if(nalsize > buf_size - (p-buf) || p[2]!=0x67)
+if(nalsize > buf_size - (p-buf) || (p[2] & 0x9F) != 7)
 return 0;
 p += nalsize;
 }
@@ -1830,7 +1830,7 @@ static int is_extra(const uint8_t *buf, int buf_size)
 return 0;
 while(cnt--){
 int nalsize= AV_RB16(p) + 2;
-if(nalsize > buf_size - (p-buf) || p[2]!=0x68)
+if(nalsize > buf_size - (p-buf) || (p[2] & 0x9F) != 8)
 return 0;
 p += nalsize;
 }

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


[FFmpeg-cvslog] Add macros to x86util.asm .

2017-08-18 Thread Ivan Kalvachev
ffmpeg | branch: master | Ivan Kalvachev  | Sat Aug  5 
20:18:50 2017 +0300| [30ae07d7ef3555ec45fa53098849223fff204475] | committer: 
Rostislav Pehlivanov

Add macros to x86util.asm .

Improved version of VBROADCASTSS that works like the avx2 instruction.
Emulation of vpbroadcastd.
Horizontal sum HSUMPS that places the result in all elements.
Emulation of blendvps and pblendvb.

Signed-off-by: Ivan Kalvachev 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=30ae07d7ef3555ec45fa53098849223fff204475
---

 libavutil/x86/x86util.asm | 106 ++
 1 file changed, 98 insertions(+), 8 deletions(-)

diff --git a/libavutil/x86/x86util.asm b/libavutil/x86/x86util.asm
index cc7d272cad..e1220dfc1a 100644
--- a/libavutil/x86/x86util.asm
+++ b/libavutil/x86/x86util.asm
@@ -832,14 +832,25 @@
 pmaxsd  %1, %2
 %endmacro
 
-%macro VBROADCASTSS 2 ; dst xmm/ymm, src m32
-%if cpuflag(avx)
-vbroadcastss %1, %2
-%else ; sse
-%ifnidn %1, %2
-movss%1, %2
-%endif
-shufps   %1, %1, 0
+%macro VBROADCASTSS 2 ; dst xmm/ymm, src m32/xmm
+%if cpuflag(avx2)
+vbroadcastss  %1, %2
+%elif cpuflag(avx)
+%ifnum sizeof%2 ; avx1 register
+shufps  xmm%1, xmm%2, xmm%2, q
+%if sizeof%1 >= 32  ; mmsize>=32
+vinsertf128  %1, %1, xmm%1, 1
+%endif
+%else   ; avx1 memory
+vbroadcastss  %1, %2
+%endif
+%else
+%ifnum sizeof%2 ; sse register
+shufps  %1, %2, %2, q
+%else   ; sse memory
+movss   %1, %2
+shufps  %1, %1, 0
+%endif
 %endif
 %endmacro
 
@@ -854,6 +865,21 @@
 %endif
 %endmacro
 
+%macro VPBROADCASTD 2 ; dst xmm/ymm, src m32/xmm
+%if cpuflag(avx2)
+vpbroadcastd  %1, %2
+%elif cpuflag(avx) && sizeof%1 >= 32
+%error vpbroadcastd not possible with ymm on avx1. try vbroadcastss
+%else
+%ifnum sizeof%2 ; sse2 register
+pshufd  %1, %2, q
+%else   ; sse memory
+movd%1, %2
+pshufd  %1, %1, 0
+%endif
+%endif
+%endmacro
+
 %macro SHUFFLE_MASK_W 8
 %rep 8
 %if %1>=0x80
@@ -918,3 +944,67 @@
 movhlps%1, %2; may cause an int/float domain transition and 
has a dependency on dst
 %endif
 %endmacro
+
+; Horizontal Sum of Packed Single precision floats
+; The resulting sum is in all elements.
+%macro HSUMPS 2 ; dst/src, tmp
+%if cpuflag(avx)
+%if sizeof%1>=32  ; avx
+vperm2f128  %2, %1, %1, (0)*16+(1)
+addps   %1, %2
+%endif
+shufps  %2, %1, %1, q1032
+addps   %1, %2
+shufps  %2, %1, %1, q0321
+addps   %1, %2
+%else  ; this form is a bit faster than the short avx-like emulation.
+movaps  %2, %1
+shufps  %1, %1, q1032
+addps   %1, %2
+movaps  %2, %1
+shufps  %1, %1, q0321
+addps   %1, %2
+; all %1 members should be equal for as long as float a+b==b+a
+%endif
+%endmacro
+
+; Emulate blendvps if not available
+;
+; src_b is destroyed when using emulation with logical operands
+; SSE41 blendv instruction is hard coded to use xmm0 as mask
+%macro BLENDVPS 3 ; dst/src_a, src_b, mask
+%if cpuflag(avx)
+blendvps  %1, %1, %2, %3
+%elif cpuflag(sse4)
+%ifnidn %3,xmm0
+%error sse41 blendvps uses xmm0 as default 3d operand, you used %3
+%endif
+blendvps  %1, %2, %3
+%else
+xorps  %2, %1
+andps  %2, %3
+xorps  %1, %2
+%endif
+%endmacro
+
+; Emulate pblendvb if not available
+;
+; src_b is destroyed when using emulation with logical operands
+; SSE41 blendv instruction is hard coded to use xmm0 as mask
+%macro PBLENDVB 3 ; dst/src_a, src_b, mask
+%if cpuflag(avx)
+%if cpuflag(avx) && notcpuflag(avx2) && sizeof%1 >= 32
+%error pblendb not possible with ymm on avx1, try blendvps.
+%endif
+pblendvb  %1, %1, %2, %3
+%elif cpuflag(sse4)
+%ifnidn %3,xmm0
+%error sse41 pblendvd uses xmm0 as default 3d operand, you used %3
+%endif
+pblendvb  %1, %2, %3
+%else
+pxor  %2, %1
+pand  %2, %3
+pxor  %1, %2
+%endif
+%endmacro

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


[FFmpeg-cvslog] SIMD opus pvq_search implementation

2017-08-18 Thread Ivan Kalvachev
ffmpeg | branch: master | Ivan Kalvachev  | Thu Jun  8 
22:24:33 2017 +0300| [7205513f8f4b32c403c733d7d2ce2f440837397d] | committer: 
Rostislav Pehlivanov

SIMD opus pvq_search implementation

Explanation on the workings and methods used by the
Pyramid Vector Quantization Search function
could be found in the following Work-In-Progress mail threads:
http://ffmpeg.org/pipermail/ffmpeg-devel/2017-June/212146.html
http://ffmpeg.org/pipermail/ffmpeg-devel/2017-June/212816.html
http://ffmpeg.org/pipermail/ffmpeg-devel/2017-July/213030.html
http://ffmpeg.org/pipermail/ffmpeg-devel/2017-July/213436.html

Signed-off-by: Ivan Kalvachev 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7205513f8f4b32c403c733d7d2ce2f440837397d
---

 libavcodec/opus_pvq.c  |   3 +
 libavcodec/opus_pvq.h  |   5 +-
 libavcodec/x86/Makefile|   3 +
 libavcodec/x86/opus_dsp_init.c |  45 +
 libavcodec/x86/opus_pvq_search.asm | 395 +
 5 files changed, 449 insertions(+), 2 deletions(-)

diff --git a/libavcodec/opus_pvq.c b/libavcodec/opus_pvq.c
index 2ac66a0ede..2fb276099b 100644
--- a/libavcodec/opus_pvq.c
+++ b/libavcodec/opus_pvq.c
@@ -947,6 +947,9 @@ int av_cold ff_celt_pvq_init(CeltPVQ **pvq)
 s->encode_band= pvq_encode_band;
 s->band_cost  = pvq_band_cost;
 
+if (ARCH_X86)
+ff_opus_dsp_init_x86(s);
+
 *pvq = s;
 
 return 0;
diff --git a/libavcodec/opus_pvq.h b/libavcodec/opus_pvq.h
index 6691494838..9246337360 100644
--- a/libavcodec/opus_pvq.h
+++ b/libavcodec/opus_pvq.h
@@ -33,8 +33,8 @@
float *lowband_scratch, int fill)
 
 struct CeltPVQ {
-DECLARE_ALIGNED(32, int,   qcoeff  )[176];
-DECLARE_ALIGNED(32, float, hadamard_tmp)[176];
+DECLARE_ALIGNED(32, int,   qcoeff  )[256];
+DECLARE_ALIGNED(32, float, hadamard_tmp)[256];
 
 float (*pvq_search)(float *X, int *y, int K, int N);
 
@@ -45,6 +45,7 @@ struct CeltPVQ {
 };
 
 int  ff_celt_pvq_init  (struct CeltPVQ **pvq);
+void ff_opus_dsp_init_x86(struct CeltPVQ *s);
 void ff_celt_pvq_uninit(struct CeltPVQ **pvq);
 
 #endif /* AVCODEC_OPUS_PVQ_H */
diff --git a/libavcodec/x86/Makefile b/libavcodec/x86/Makefile
index 0dbc46504e..e36644c72a 100644
--- a/libavcodec/x86/Makefile
+++ b/libavcodec/x86/Makefile
@@ -52,6 +52,8 @@ OBJS-$(CONFIG_APNG_DECODER)+= x86/pngdsp_init.o
 OBJS-$(CONFIG_CAVS_DECODER)+= x86/cavsdsp.o
 OBJS-$(CONFIG_DCA_DECODER) += x86/dcadsp_init.o 
x86/synth_filter_init.o
 OBJS-$(CONFIG_DNXHD_ENCODER)   += x86/dnxhdenc_init.o
+OBJS-$(CONFIG_OPUS_DECODER)+= x86/opus_dsp_init.o
+OBJS-$(CONFIG_OPUS_ENCODER)+= x86/opus_dsp_init.o
 OBJS-$(CONFIG_HEVC_DECODER)+= x86/hevcdsp_init.o
 OBJS-$(CONFIG_JPEG2000_DECODER)+= x86/jpeg2000dsp_init.o
 OBJS-$(CONFIG_MLP_DECODER) += x86/mlpdsp_init.o
@@ -123,6 +125,7 @@ X86ASM-OBJS-$(CONFIG_MDCT15)   += x86/mdct15.o
 X86ASM-OBJS-$(CONFIG_ME_CMP)   += x86/me_cmp.o
 X86ASM-OBJS-$(CONFIG_MPEGAUDIODSP) += x86/imdct36.o
 X86ASM-OBJS-$(CONFIG_MPEGVIDEOENC) += x86/mpegvideoencdsp.o
+X86ASM-OBJS-$(CONFIG_OPUS_ENCODER) += x86/opus_pvq_search.o
 X86ASM-OBJS-$(CONFIG_PIXBLOCKDSP)  += x86/pixblockdsp.o
 X86ASM-OBJS-$(CONFIG_QPELDSP)  += x86/qpeldsp.o \
   x86/fpel.o\
diff --git a/libavcodec/x86/opus_dsp_init.c b/libavcodec/x86/opus_dsp_init.c
new file mode 100644
index 00..c51f786ee8
--- /dev/null
+++ b/libavcodec/x86/opus_dsp_init.c
@@ -0,0 +1,45 @@
+/*
+ * Opus encoder assembly optimizations
+ * Copyright (C) 2017 Ivan Kalvachev 
+ *
+ * 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 "config.h"
+
+#include "libavutil/x86/cpu.h"
+#include "libavcodec/opus_pvq.h"
+
+extern float ff_pvq_search_sse2(float *X, int *y, int K, int N);
+extern float ff_pvq_search_sse4(float *X, int *y, int K, int N);
+extern float ff_pvq_search_avx (float *X, int *y, int K, int N);
+
+av_cold void ff_opus_dsp_init_x86(CeltPVQ *s)
+{
+int cpu_flags = av_get_cpu_flags();
+
+#if CONFIG_OPUS_E

Re: [FFmpeg-cvslog] opus_pvq_search: only use rsqrtps approximation on CPUs with avx

2017-08-18 Thread Ivan Kalvachev
Please revert this.

Also, in future, please send a patch to the maillist so I could take a
look on it.

On 8/18/17, Rostislav Pehlivanov  wrote:
> ffmpeg | branch: master | Rostislav Pehlivanov  | Fri
> Aug 18 17:28:40 2017 +0100| [f386dd70acdc81d42d6bcb885d2889634cdf45b7] |
> committer: Rostislav Pehlivanov
>
> opus_pvq_search: only use rsqrtps approximation on CPUs with avx

You got the commit message in reverse.

"rsqrtps" is the instruction that uses approximation and is faster.
AVX CPUs are "allegedly" the ones that have faster divps,
so the speed hit is not so bad.

You want to use divps on new cpu and rsqrtps on old ones,
not the reverse.


> Makes the search produce idential results with the C version.
>
> Signed-off-by: Rostislav Pehlivanov 
>
>> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f386dd70acdc81d42d6bcb885d2889634cdf45b7
> ---
>
>  libavcodec/x86/opus_pvq_search.asm | 18 ++
>  1 file changed, 6 insertions(+), 12 deletions(-)
>
> diff --git a/libavcodec/x86/opus_pvq_search.asm
> b/libavcodec/x86/opus_pvq_search.asm
> index beb6cbcc9b..2f4864c95c 100644
> --- a/libavcodec/x86/opus_pvq_search.asm
> +++ b/libavcodec/x86/opus_pvq_search.asm
> @@ -28,12 +28,6 @@
>  ALIGNMODE p6
>  %endif
>
> -; Use float op that give half precision but execute for around 3 cycles.
> -; On Skylake & Ryzen the division is much faster (around 11c/3),
> -; that makes the full precision code about 2% slower.
> -; Opus also does use rsqrt approximation in their intrinsics code.
> -%define USE_APPROXIMATION   1
> -
>  SECTION_RODATA 64
>
>  const_float_abs_mask:   times 8 dd 0x7fff
> @@ -102,17 +96,17 @@ align 16
>  movaps m4, [tmpY + r4]  ; y[i]
>  movaps m5, [tmpX + r4]  ; X[i]
>
> -  %if USE_APPROXIMATION == 1
> +%if !cpuflag(avx) ; for crappy ancient CPUs that have slow packed divs but

These changes are not necessary and
they do obfuscate the code.

The define name also documents what the different code path does.
Using just "not AVX" doesn't explain why
we use one code path and not the other.


> fast 1/sqrt
>  xorps  m0, m0
>  cmpps  m0, m0, m5, 4; m0 = (X[i] != 0.0)
> -  %endif
> +%endif
>
>  addps  m4, m6   ; m4 = Syy_new = y[i] + Syy_norm
>  addps  m5, m7   ; m5 = Sxy_new = X[i] + Sxy_norm
>
> -  %if USE_APPROXIMATION == 1
> +%if !cpuflag(avx)
>  andps  m5, m0   ; if(X[i] == 0) Sxy_new = 0; Prevent
> aproximation error from setting pulses in array padding.
> -  %endif
> +%endif
>
>  %else
>  movaps m5, [tmpY + r4]  ; m5 = y[i]
> @@ -125,7 +119,7 @@ align 16
>  andps  m5, m0   ; (0  %endif
>
> -%if USE_APPROXIMATION == 1
> +%if !cpuflag(avx)
>  rsqrtpsm4, m4
>  mulps  m5, m4   ; m5 = p = Sxy_new*approx(1/sqrt(Syy) )
>  %else
> @@ -261,7 +255,7 @@ align 16
>  jz   %%zero_input   ; if (Sx==0) goto zero_input
>
>  cvtsi2ss  xm0, dword Kd ; m0 = K
> -%if USE_APPROXIMATION == 1
> +%if !cpuflag(avx)
>  rcpss xm1, xm1  ; m1 = approx(1/Sx)
>      mulss xm0, xm1  ; m0 = K*(1/Sx)
>  %else
>

The whole patch could be replaced with one liner:

@@ -391,5 +391,7 @@ PVQ_FAST_SEARCH
 INIT_XMM sse4
 PVQ_FAST_SEARCH

+%define USE_APPROXIMATION   0
+
 INIT_XMM avx
 PVQ_FAST_SEARCH


Best Regards
   Ivan Kalvachev
___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


Re: [FFmpeg-cvslog] opus_pvq_search: split functions into exactness and only use the exact if its faster

2017-08-18 Thread Ivan Kalvachev
I ask for revert, instead you commit more on it.
Ignoring everything I said on irc and in mail.

On 8/18/17, Rostislav Pehlivanov  wrote:
> ffmpeg | branch: master | Rostislav Pehlivanov  | Fri
> Aug 18 19:29:33 2017 +0100| [3c99523a2864af729a8576c3fffe81fb884fa0d5] |
> committer: Rostislav Pehlivanov
>
> opus_pvq_search: split functions into exactness and only use the exact if
> its faster
>
> This splits the asm function into exact and non-exact version. The exact
> version is as fast or faster on newer CPUs (which EXTERNAL_AVX_FAST
> describes
> well) whilst the non-exact version is faster than the exact on older CPUs.
>
> Also fixes yasm compilation which doesn't accept !cpuflags(avx) syntax.
>
> Signed-off-by: Rostislav Pehlivanov 
>
>> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3c99523a2864af729a8576c3fffe81fb884fa0d5
> ---
>
>  libavcodec/x86/opus_dsp_init.c | 14 +++---
>  libavcodec/x86/opus_pvq_search.asm | 34 +-
>  2 files changed, 28 insertions(+), 20 deletions(-)
>
> diff --git a/libavcodec/x86/opus_dsp_init.c b/libavcodec/x86/opus_dsp_init.c
> index c51f786ee8..a9f8a96159 100644
> --- a/libavcodec/x86/opus_dsp_init.c
> +++ b/libavcodec/x86/opus_dsp_init.c
> @@ -24,9 +24,9 @@
>  #include "libavutil/x86/cpu.h"
>  #include "libavcodec/opus_pvq.h"
>
> -extern float ff_pvq_search_sse2(float *X, int *y, int K, int N);
> -extern float ff_pvq_search_sse4(float *X, int *y, int K, int N);
> -extern float ff_pvq_search_avx (float *X, int *y, int K, int N);
> +extern float ff_pvq_search_approx_sse2(float *X, int *y, int K, int N);
> +extern float ff_pvq_search_approx_sse4(float *X, int *y, int K, int N);
> +extern float ff_pvq_search_exact_avx  (float *X, int *y, int K, int N);
>
>  av_cold void ff_opus_dsp_init_x86(CeltPVQ *s)
>  {
> @@ -34,12 +34,12 @@ av_cold void ff_opus_dsp_init_x86(CeltPVQ *s)
>
>  #if CONFIG_OPUS_ENCODER
>  if (EXTERNAL_SSE2(cpu_flags))
> -s->pvq_search = ff_pvq_search_sse2;
> +s->pvq_search = ff_pvq_search_approx_sse2;
>
>  if (EXTERNAL_SSE4(cpu_flags))
> -s->pvq_search = ff_pvq_search_sse4;
> +s->pvq_search = ff_pvq_search_approx_sse4;
>
> -if (EXTERNAL_AVX(cpu_flags))
> -s->pvq_search = ff_pvq_search_avx;
> +if (EXTERNAL_AVX_FAST(cpu_flags))
> +s->pvq_search = ff_pvq_search_exact_avx;
>  #endif
>  }
> diff --git a/libavcodec/x86/opus_pvq_search.asm
> b/libavcodec/x86/opus_pvq_search.asm
> index 2f4864c95c..8cf040465d 100644
> --- a/libavcodec/x86/opus_pvq_search.asm
> +++ b/libavcodec/x86/opus_pvq_search.asm
> @@ -82,7 +82,7 @@ SECTION .text
>  %endif
>  %endmacro
>
> -%macro PULSES_SEARCH 1
> +%macro PULSES_SEARCH 2 ; %1 - add or sub, %2 - use approximation
>  ; m6 Syy_norm
>  ; m7 Sxy_norm
>  addps  m6, mm_const_float_0_5   ; Syy_norm += 1.0/2
> @@ -96,7 +96,7 @@ align 16
>  movaps m4, [tmpY + r4]  ; y[i]
>  movaps m5, [tmpX + r4]  ; X[i]
>
> -%if !cpuflag(avx) ; for crappy ancient CPUs that have slow packed divs but
> fast 1/sqrt
> +%if %2
>  xorps  m0, m0
>  cmpps  m0, m0, m5, 4; m0 = (X[i] != 0.0)
>  %endif
> @@ -104,7 +104,7 @@ align 16
>  addps  m4, m6   ; m4 = Syy_new = y[i] + Syy_norm
>  addps  m5, m7   ; m5 = Sxy_new = X[i] + Sxy_norm
>
> -%if !cpuflag(avx)
> +%if %2
>  andps  m5, m0   ; if(X[i] == 0) Sxy_new = 0; Prevent
> aproximation error from setting pulses in array padding.
>  %endif
>
> @@ -119,7 +119,7 @@ align 16
>  andps  m5, m0   ; (0  %endif
>
> -%if !cpuflag(avx)
> +%if %2
>  rsqrtpsm4, m4
>  mulps  m5, m4   ; m5 = p = Sxy_new*approx(1/sqrt(Syy) )
>  %else
> @@ -211,8 +211,13 @@ align 16
>  ; uint32 K  - Number of pulses to have after quantizations.
>  ; uint32 N  - Number of vector elements. Must be 0 < N < 256
>  ;
> -%macro PVQ_FAST_SEARCH 0
> -cglobal pvq_search, 4, 5+num_pic_regs, 11, 256*4, inX, outY, K, N
> +%macro PVQ_FAST_SEARCH 1 ; %1 - use approximation
> +%if %1
> +cglobal pvq_search_approx, 4, 5+num_pic_regs, 11, 256*4, inX, outY, K, N
> +%else
> +cglobal pvq_search_exact,  4, 5+num_pic_regs, 11, 256*4, inX, outY, K, N
> +%endif
> +
>  %define tmpX rsp
>  %define tmpY outYq
>
> @@ -255,7 +260,7 @@ align 16
>  jz   %%zero_input   ; if (Sx==0) goto zero_input
>
>  cvtsi2ss  xm0, dword Kd ; m0 = K
> -%if !cpuflag(avx)
> +%if %1
>  rcpss xm1, xm1  ; m1 = approx(1/Sx)
>  mulss xm0, xm1  ; m0 = K*(1/Sx)
>  %else
> @@ -308,7 +313,7 @@ align 16
>  align 16; K - pulses > 0
>  %%add_pulses_loop:
>
> -PULSES_SEARCH add   ; m6 Syy_norm ; m7 Sxy_norm
> +PULSES_SEARCH add, %1   ; m6 Syy_norm ; m7 Sxy_norm
>
>  subKd, 1
>  jnz  %%add_pulses_loop
> @@ -320,7 +325,7 @@ align 16; K - pulses > 0
>  align 16
>  %%remove_pulses_loop:
>
> -PULSES_SEA

[FFmpeg-cvslog] opus_pvq_search: Restore the proper use of conditional define and simplify the function name suffix handling.

2017-08-19 Thread Ivan Kalvachev
ffmpeg | branch: master | Ivan Kalvachev  | Sat Aug 19 
14:29:40 2017 +0300| [43dab86bcd863739ce51a2742c9f4f5527b5ec7c] | committer: 
Rostislav Pehlivanov

opus_pvq_search: Restore the proper use of conditional define and simplify the 
function name suffix handling.

Using named define properly documents the code paths.
It also avoids passing additional numbered arguments through
multiple levels of macro templates.

The suffix handling is done by concatenation, like in
other asm functions and avoid having two separate
"cglobal" defines.

Signed-off-by: Ivan Kalvachev 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=43dab86bcd863739ce51a2742c9f4f5527b5ec7c
---

 libavcodec/x86/opus_pvq_search.asm | 37 ++---
 1 file changed, 18 insertions(+), 19 deletions(-)

diff --git a/libavcodec/x86/opus_pvq_search.asm 
b/libavcodec/x86/opus_pvq_search.asm
index 8cf040465d..5c1e6d6174 100644
--- a/libavcodec/x86/opus_pvq_search.asm
+++ b/libavcodec/x86/opus_pvq_search.asm
@@ -82,7 +82,7 @@ SECTION .text
 %endif
 %endmacro
 
-%macro PULSES_SEARCH 2 ; %1 - add or sub, %2 - use approximation
+%macro PULSES_SEARCH 1
 ; m6 Syy_norm
 ; m7 Sxy_norm
 addps  m6, mm_const_float_0_5   ; Syy_norm += 1.0/2
@@ -96,17 +96,17 @@ align 16
 movaps m4, [tmpY + r4]  ; y[i]
 movaps m5, [tmpX + r4]  ; X[i]
 
-%if %2
+  %if USE_APPROXIMATION == 1
 xorps  m0, m0
 cmpps  m0, m0, m5, 4; m0 = (X[i] != 0.0)
-%endif
+  %endif
 
 addps  m4, m6   ; m4 = Syy_new = y[i] + Syy_norm
 addps  m5, m7   ; m5 = Sxy_new = X[i] + Sxy_norm
 
-%if %2
+  %if USE_APPROXIMATION == 1
 andps  m5, m0   ; if(X[i] == 0) Sxy_new = 0; Prevent 
aproximation error from setting pulses in array padding.
-%endif
+  %endif
 
 %else
 movaps m5, [tmpY + r4]  ; m5 = y[i]
@@ -119,7 +119,7 @@ align 16
 andps  m5, m0   ; (0 0
 %%add_pulses_loop:
 
-PULSES_SEARCH add, %1   ; m6 Syy_norm ; m7 Sxy_norm
+PULSES_SEARCH add   ; m6 Syy_norm ; m7 Sxy_norm
 
 subKd, 1
 jnz  %%add_pulses_loop
@@ -325,7 +320,7 @@ align 16; K - pulses > 0
 align 16
 %%remove_pulses_loop:
 
-PULSES_SEARCH sub, %1   ; m6 Syy_norm ; m7 Sxy_norm
+PULSES_SEARCH sub   ; m6 Syy_norm ; m7 Sxy_norm
 
 addKd, 1
 jnz  %%remove_pulses_loop
@@ -376,11 +371,15 @@ align 16
 ; On Skylake & Ryzen the division is much faster (around 11c/3),
 ; that makes the full precision code about 2% slower.
 ; Opus also does use rsqrt approximation in their intrinsics code.
+%define USE_APPROXIMATION   1
+
 INIT_XMM sse2
-PVQ_FAST_SEARCH 1
+PVQ_FAST_SEARCH _approx
 
 INIT_XMM sse4
-PVQ_FAST_SEARCH 1
+PVQ_FAST_SEARCH _approx
+
+%define USE_APPROXIMATION   0
 
 INIT_XMM avx
-PVQ_FAST_SEARCH 0
+PVQ_FAST_SEARCH _exact

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


[FFmpeg-cvslog] Fix visual glitch with XvMC, caused by wrong idct permutation.

2017-10-11 Thread Ivan Kalvachev
ffmpeg | branch: master | Ivan Kalvachev  | Mon Oct  9 
01:25:00 2017 +0300| [9054439bad3307dafd9fbadc57e66c276baf22e2] | committer: 
Michael Niedermayer

Fix visual glitch with XvMC, caused by wrong idct permutation.

In the past XvMC forced simple_idct since
it was using FF_IDCT_PERM_NONE.
However now we have SIMD variants of simple_idct that
are using FF_IDCT_PERM_TRANSPOSE and if they are selected
XvMC would get coefficients in the wrong order.

The patch creates new FF_IDCT_NONE that
is used only for this kind of hardware decoding
and that fallbacks to the old C only simple idct.

Signed-off-by: Ivan Kalvachev 
Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9054439bad3307dafd9fbadc57e66c276baf22e2
---

 libavcodec/avcodec.h   | 1 +
 libavcodec/idctdsp.c   | 1 +
 libavcodec/mpeg12dec.c | 2 +-
 3 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 52cc5b0ca0..18c3e3ea1e 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3146,6 +3146,7 @@ typedef struct AVCodecContext {
 #if FF_API_ARCH_ALPHA
 #define FF_IDCT_SIMPLEALPHA   23
 #endif
+#define FF_IDCT_NONE  24 /* Used by XvMC to extract IDCT coefficients 
with FF_IDCT_PERM_NONE */
 #define FF_IDCT_SIMPLEAUTO128
 
 /**
diff --git a/libavcodec/idctdsp.c b/libavcodec/idctdsp.c
index d596aed1a9..0122d29efa 100644
--- a/libavcodec/idctdsp.c
+++ b/libavcodec/idctdsp.c
@@ -279,6 +279,7 @@ av_cold void ff_idctdsp_init(IDCTDSPContext *c, 
AVCodecContext *avctx)
 c->perm_type = FF_IDCT_PERM_NONE;
 #endif /* CONFIG_FAANIDCT */
 } else { // accurate/default
+/* Be sure FF_IDCT_NONE will select this one, since it uses 
FF_IDCT_PERM_NONE */
 c->idct_put  = ff_simple_idct_put_8;
 c->idct_add  = ff_simple_idct_add_8;
 c->idct  = ff_simple_idct_8;
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 22c29c1505..4e68be27f1 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -1217,7 +1217,7 @@ static void setup_hwaccel_for_pixfmt(AVCodecContext 
*avctx)
 #endif
 )
 if (avctx->idct_algo == FF_IDCT_AUTO)
-avctx->idct_algo = FF_IDCT_SIMPLE;
+avctx->idct_algo = FF_IDCT_NONE;
 
 if (avctx->hwaccel && avctx->pix_fmt == AV_PIX_FMT_XVMC) {
 Mpeg1Context *s1 = avctx->priv_data;

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


[FFmpeg-cvslog] Fix crash if av_vdpau_bind_context() is not used.

2017-10-12 Thread Ivan Kalvachev
ffmpeg | branch: master | Ivan Kalvachev  | Mon Oct  9 
02:40:26 2017 +0300| [3a6ded7cfcb33e06ade98c5791eae06453f65668] | committer: 
Carl Eugen Hoyos

Fix crash if av_vdpau_bind_context() is not used.

The public functions av_alloc_vdpaucontext() and
av_vdpau_alloc_context() are allocating AVVDPAUContext
structure that is supposed to be placed in avctx->hwaccel_context.

However the rest of libavcodec/vdpau.c uses avctx->hwaccel_context
as struct VDPAUHWContext, that is bigger and does contain
AVVDPAUContext as first member.

The usage includes write to the new variables in the bigger stuct,
without checking for block size.

Fix by always allocating the bigger structure.

Signed-off-by: Ivan Kalvachev 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3a6ded7cfcb33e06ade98c5791eae06453f65668
---

 libavcodec/vdpau.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/vdpau.c b/libavcodec/vdpau.c
index 42ebddbeee..4cc51cb79e 100644
--- a/libavcodec/vdpau.c
+++ b/libavcodec/vdpau.c
@@ -816,7 +816,7 @@ do {   \
 
 AVVDPAUContext *av_vdpau_alloc_context(void)
 {
-return av_mallocz(sizeof(AVVDPAUContext));
+return av_mallocz(sizeof(VDPAUHWContext));
 }
 
 int av_vdpau_bind_context(AVCodecContext *avctx, VdpDevice device,

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


[FFmpeg-cvslog] Fix crash if av_vdpau_bind_context() is not used.

2017-10-12 Thread Ivan Kalvachev
ffmpeg | branch: release/3.4 | Ivan Kalvachev  | Mon Oct  
9 02:40:26 2017 +0300| [7fb85ad3607a3fdde682ea74d6f6bcefe1f582dd] | committer: 
Carl Eugen Hoyos

Fix crash if av_vdpau_bind_context() is not used.

The public functions av_alloc_vdpaucontext() and
av_vdpau_alloc_context() are allocating AVVDPAUContext
structure that is supposed to be placed in avctx->hwaccel_context.

However the rest of libavcodec/vdpau.c uses avctx->hwaccel_context
as struct VDPAUHWContext, that is bigger and does contain
AVVDPAUContext as first member.

The usage includes write to the new variables in the bigger stuct,
without checking for block size.

Fix by always allocating the bigger structure.

Signed-off-by: Ivan Kalvachev 
(cherry picked from commit 3a6ded7cfcb33e06ade98c5791eae06453f65668)

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7fb85ad3607a3fdde682ea74d6f6bcefe1f582dd
---

 libavcodec/vdpau.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/vdpau.c b/libavcodec/vdpau.c
index 42ebddbeee..4cc51cb79e 100644
--- a/libavcodec/vdpau.c
+++ b/libavcodec/vdpau.c
@@ -816,7 +816,7 @@ do {   \
 
 AVVDPAUContext *av_vdpau_alloc_context(void)
 {
-return av_mallocz(sizeof(AVVDPAUContext));
+return av_mallocz(sizeof(VDPAUHWContext));
 }
 
 int av_vdpau_bind_context(AVCodecContext *avctx, VdpDevice device,

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


[FFmpeg-cvslog] Fix visual glitch with XvMC, caused by wrong idct permutation.

2017-10-14 Thread Ivan Kalvachev
ffmpeg | branch: release/3.4 | Ivan Kalvachev  | Mon Oct  
9 01:25:00 2017 +0300| [a11a18b284afd5ac58fd3b1835f8a3608c4ebc9f] | committer: 
Michael Niedermayer

Fix visual glitch with XvMC, caused by wrong idct permutation.

In the past XvMC forced simple_idct since
it was using FF_IDCT_PERM_NONE.
However now we have SIMD variants of simple_idct that
are using FF_IDCT_PERM_TRANSPOSE and if they are selected
XvMC would get coefficients in the wrong order.

The patch creates new FF_IDCT_NONE that
is used only for this kind of hardware decoding
and that fallbacks to the old C only simple idct.

Signed-off-by: Ivan Kalvachev 
Signed-off-by: Michael Niedermayer 
(cherry picked from commit 9054439bad3307dafd9fbadc57e66c276baf22e2)
Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a11a18b284afd5ac58fd3b1835f8a3608c4ebc9f
---

 libavcodec/avcodec.h   | 1 +
 libavcodec/idctdsp.c   | 1 +
 libavcodec/mpeg12dec.c | 2 +-
 3 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 52cc5b0ca0..18c3e3ea1e 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3146,6 +3146,7 @@ typedef struct AVCodecContext {
 #if FF_API_ARCH_ALPHA
 #define FF_IDCT_SIMPLEALPHA   23
 #endif
+#define FF_IDCT_NONE  24 /* Used by XvMC to extract IDCT coefficients 
with FF_IDCT_PERM_NONE */
 #define FF_IDCT_SIMPLEAUTO128
 
 /**
diff --git a/libavcodec/idctdsp.c b/libavcodec/idctdsp.c
index d596aed1a9..0122d29efa 100644
--- a/libavcodec/idctdsp.c
+++ b/libavcodec/idctdsp.c
@@ -279,6 +279,7 @@ av_cold void ff_idctdsp_init(IDCTDSPContext *c, 
AVCodecContext *avctx)
 c->perm_type = FF_IDCT_PERM_NONE;
 #endif /* CONFIG_FAANIDCT */
 } else { // accurate/default
+/* Be sure FF_IDCT_NONE will select this one, since it uses 
FF_IDCT_PERM_NONE */
 c->idct_put  = ff_simple_idct_put_8;
 c->idct_add  = ff_simple_idct_add_8;
 c->idct  = ff_simple_idct_8;
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 22c29c1505..4e68be27f1 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -1217,7 +1217,7 @@ static void setup_hwaccel_for_pixfmt(AVCodecContext 
*avctx)
 #endif
 )
 if (avctx->idct_algo == FF_IDCT_AUTO)
-avctx->idct_algo = FF_IDCT_SIMPLE;
+avctx->idct_algo = FF_IDCT_NONE;
 
 if (avctx->hwaccel && avctx->pix_fmt == AV_PIX_FMT_XVMC) {
 Mpeg1Context *s1 = avctx->priv_data;

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


Re: [FFmpeg-cvslog] avcodec/vp56: Implement very basic error concealment

2017-02-25 Thread Ivan Kalvachev
On 2/25/17, Michael Niedermayer  wrote:
> ffmpeg | branch: master | Michael Niedermayer  | Sat
> Feb 25 12:37:32 2017 +0100| [d34bf886e963445350c4987f7a9ed77bd9c9a5c7] |
> committer: Michael Niedermayer
>
> avcodec/vp56: Implement very basic error concealment
>
> This should fix the fate failure due to a truncated last frame.
> Alternatively the frame could be dropped.
>
> Signed-off-by: Michael Niedermayer 
>
>> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d34bf886e963445350c4987f7a9ed77bd9c9a5c7
> ---
>
>  libavcodec/vp56.c  | 81
> --
>  tests/ref/fate/vp5 |  2 +-
>  2 files changed, 79 insertions(+), 4 deletions(-)
>
> diff --git a/libavcodec/vp56.c b/libavcodec/vp56.c
> index d8fe994..b36c99f 100644
> --- a/libavcodec/vp56.c
> +++ b/libavcodec/vp56.c
> @@ -261,6 +261,25 @@ static VP56mb vp56_decode_mv(VP56Context *s, int row,
> int col)
>  return s->mb_type;
>  }
>
> +static VP56mb vp56_conceal_mv(VP56Context *s, int row, int col)
> +{
> +VP56mv *mv, vect = {0,0};
> +int b;
> +
> +s->mb_type = VP56_MB_INTER_NOVEC_PF;
> +s->macroblocks[row * s->mb_width + col].type = s->mb_type;
> +
> +mv = &vect;
> +
> +s->macroblocks[row*s->mb_width + col].mv = *mv;
> +
> +/* same vector for all blocks */
> +for (b=0; b<6; b++)
> +s->mv[b] = *mv;
> +
> +return s->mb_type;
> +}
> +
>  static void vp56_add_predictors_dc(VP56Context *s, VP56Frame ref_frame)
>  {
>  int idx = s->idct_scantable[0];
> @@ -457,6 +476,57 @@ static int vp56_decode_mb(VP56Context *s, int row, int
> col, int is_alpha)
>  return 0;
>  }
>
> +static int vp56_conceal_mb(VP56Context *s, int row, int col, int is_alpha)
> +{
> +AVFrame *frame_current, *frame_ref;
> +VP56mb mb_type;
> +VP56Frame ref_frame;
> +int b, ab, b_max, plane, off;
> +
> +if (s->frames[VP56_FRAME_CURRENT]->key_frame)
> +mb_type = VP56_MB_INTRA;
> +else
> +mb_type = vp56_conceal_mv(s, row, col);
> +ref_frame = ff_vp56_reference_frame[mb_type];
> +
> +frame_current = s->frames[VP56_FRAME_CURRENT];
> +frame_ref = s->frames[ref_frame];
> +if (mb_type != VP56_MB_INTRA && !frame_ref->data[0])
> +return 0;
> +
> +ab = 6*is_alpha;
> +b_max = 6 - 2*is_alpha;
> +
> +switch (mb_type) {
> +case VP56_MB_INTRA:
> +for (b=0; b +plane = ff_vp56_b2p[b+ab];
> +s->vp3dsp.idct_put(frame_current->data[plane] +
> s->block_offset[b],
> +s->stride[plane], s->block_coeff[b]);
> +}
> +break;
> +
> +case VP56_MB_INTER_NOVEC_PF:
> +case VP56_MB_INTER_NOVEC_GF:
> +for (b=0; b +plane = ff_vp56_b2p[b+ab];
> +off = s->block_offset[b];
> +s->hdsp.put_pixels_tab[1][0](frame_current->data[plane] +
> off,
> + frame_ref->data[plane] + off,
> + s->stride[plane], 8);
> +s->vp3dsp.idct_add(frame_current->data[plane] + off,
> +s->stride[plane], s->block_coeff[b]);
> +}
> +break;
> +}
> +
> +if (is_alpha) {
> +s->block_coeff[4][0] = 0;
> +s->block_coeff[5][0] = 0;
> +}
> +return 0;
> +}
> +
>  static int vp56_size_changed(VP56Context *s)
>  {
>  AVCodecContext *avctx = s->avctx;
> @@ -593,6 +663,7 @@ static int ff_vp56_decode_mbs(AVCodecContext *avctx,
> void *data,
>  int block, y, uv;
>  ptrdiff_t stride_y, stride_uv;
>  int res;
> +int damaged = 0;
>
>  if (p->key_frame) {
>  p->pict_type = AV_PICTURE_TYPE_I;
> @@ -657,9 +728,13 @@ static int ff_vp56_decode_mbs(AVCodecContext *avctx,
> void *data,
>  s->block_offset[5] = s->block_offset[4];
>
>  for (mb_col=0; mb_colmb_width; mb_col++) {
> -int ret = vp56_decode_mb(s, mb_row, mb_col, is_alpha);
> -if (ret < 0)
> -return ret;
> +if (!damaged) {
> +int ret = vp56_decode_mb(s, mb_row, mb_col, is_alpha);
> +if (ret < 0)
> +damaged = 1;
> +}
> +if (damaged)
> +vp56_conceal_mb(s, mb_row, mb_col, is_alpha);
>
>  for (y=0; y<4; y++) {
>  s->above_block_idx[y] += 2;
> diff --git a/tests/ref/fate/vp5 b/tests/ref/fate/vp5
> index da510fc..2469a3e 100644
> --- a/tests/ref/fate/vp5
> +++ b/tests/ref/fate/vp5
> @@ -249,4 +249,4 @@
>  0,243,243,1,   233472, 0x6f530ac6
>  0,244,244,1,   233472, 0x94f7466c
>  0,245,245,1,   233472, 0xa8c1d365
> -0,246,246,1,   233472, 0x8843293b
> +0,246,246,1,   233472, 0xbf73f1b7
>

Michael, please, send patches to the maillist,
even if the thing are tr

[FFmpeg-cvslog] Revert "Merge commit '3c53627ac17fc6bdea5029be57da1e03b32d265d'"

2016-07-24 Thread Ivan Uskov
ffmpeg | branch: master | Ivan Uskov  | Sun Jul 24 
09:59:42 2016 -0400| [b4054100f675b395204f1a0471fba0b06fe08e9f] | committer: 
Michael Niedermayer

Revert "Merge commit '3c53627ac17fc6bdea5029be57da1e03b32d265d'"

This reverts commit d30cf57a7b2097b565db02ecfffbdc9c16423d0e, reversing changes 
made to
acc155ac55baa95d1c16c0364b02244bc04d83a8. The commit 
d30cf57a7b2097b565db02ecfffbdc9c16423d0e
provided irrelevant code complexity and decoding slowdown. But the main 
disadvantage of this
commit is a decoder crash. So it should be reverted.

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b4054100f675b395204f1a0471fba0b06fe08e9f
---

 libavcodec/qsvdec.c |   34 ++
 1 file changed, 6 insertions(+), 28 deletions(-)

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index c17606d..9125700 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -142,7 +142,7 @@ static int qsv_decode_init(AVCodecContext *avctx, 
QSVContext *q, AVPacket *avpkt
  */
 if (!q->async_fifo) {
 q->async_fifo = av_fifo_alloc((1 + 16) *
-  (sizeof(mfxSyncPoint*) + 
sizeof(QSVFrame*)));
+  (sizeof(mfxSyncPoint) + 
sizeof(QSVFrame*)));
 if (!q->async_fifo)
 return AVERROR(ENOMEM);
 }
@@ -297,16 +297,6 @@ static void close_decoder(QSVContext *q)
 if (q->session)
 MFXVideoDECODE_Close(q->session);
 
-while (q->async_fifo && av_fifo_size(q->async_fifo)) {
-QSVFrame *out_frame;
-mfxSyncPoint *sync;
-
-av_fifo_generic_read(q->async_fifo, &out_frame, sizeof(out_frame), 
NULL);
-av_fifo_generic_read(q->async_fifo, &sync,  sizeof(sync),  
NULL);
-
-av_freep(&sync);
-}
-
 cur = q->work_frames;
 while (cur) {
 q->work_frames = cur->next;
@@ -326,7 +316,7 @@ static int do_qsv_decode(AVCodecContext *avctx, QSVContext 
*q,
 QSVFrame *out_frame;
 mfxFrameSurface1 *insurf;
 mfxFrameSurface1 *outsurf;
-mfxSyncPoint *sync;
+mfxSyncPoint sync;
 mfxBitstream bs = { { { 0 } } };
 int ret;
 int n_out_frames;
@@ -359,19 +349,13 @@ static int do_qsv_decode(AVCodecContext *avctx, 
QSVContext *q,
 bs.TimeStamp  = avpkt->pts;
 }
 
-sync = av_mallocz(sizeof(*sync));
-if (!sync) {
-av_freep(&sync);
-return AVERROR(ENOMEM);
-}
-
 while (1) {
 ret = get_surface(avctx, q, &insurf);
 if (ret < 0)
 return ret;
 do {
 ret = MFXVideoDECODE_DecodeFrameAsync(q->session, flush ? NULL : 
&bs,
-  insurf, &outsurf, sync);
+  insurf, &outsurf, &sync);
 if (ret != MFX_WRN_DEVICE_BUSY)
 break;
 av_usleep(500);
@@ -385,11 +369,10 @@ static int do_qsv_decode(AVCodecContext *avctx, 
QSVContext *q,
 continue;
 }
 
-if (*sync) {
+if (sync) {
 QSVFrame *out_frame = find_frame(q, outsurf);
 
 if (!out_frame) {
-av_freep(&sync);
 av_log(avctx, AV_LOG_ERROR,
"The returned surface does not correspond to any 
frame\n");
 return AVERROR_BUG;
@@ -400,8 +383,6 @@ static int do_qsv_decode(AVCodecContext *avctx, QSVContext 
*q,
 av_fifo_generic_write(q->async_fifo, &sync,  sizeof(sync), 
 NULL);
 
 continue;
-} else {
-av_freep(&sync);
 }
 if (MFX_ERR_MORE_SURFACE != ret && ret < 0)
 break;
@@ -409,7 +390,7 @@ static int do_qsv_decode(AVCodecContext *avctx, QSVContext 
*q,
 
 /* make sure we do not enter an infinite loop if the SDK
  * did not consume any data and did not return anything */
-if (!*sync && !bs.DataOffset && !flush) {
+if (!sync && !bs.DataOffset && !flush) {
 av_log(avctx, AV_LOG_WARNING, "A decode call did not consume any 
data\n");
 bs.DataOffset = avpkt->size;
 }
@@ -423,7 +404,6 @@ static int do_qsv_decode(AVCodecContext *avctx, QSVContext 
*q,
 }
 
 if (MFX_ERR_MORE_DATA!=ret && ret < 0) {
-av_freep(&sync);
 av_log(avctx, AV_LOG_ERROR, "Error %d during QSV decoding.\n", ret);
 return ff_qsv_error(ret);
 }
@@ -437,11 +417,9 @@ static int do_qsv_decode(AVCodecContext *avctx, QSVContext 
*q,
 out_frame->queued = 0;
 
 do {
-ret = MFXVideoCORE_SyncOperation(q->session, *sync, 1000);
+ret = MFXVideoCORE_SyncOperation(q->session, sync, 1000);
 } while (ret == MFX_WRN_IN_EXECUTION);
 
-  

[FFmpeg-cvslog] libavcodec/qsvdec_h2645.c: switch to the new BSF API

2016-08-14 Thread Ivan Uskov
ffmpeg | branch: master | Ivan Uskov  | Sun Jul 24 
14:04:36 2016 -0400| [b93e2233155e6c1f0a074cad4135a70d9d2934d3] | committer: 
Michael Niedermayer

libavcodec/qsvdec_h2645.c: switch to the new BSF API

This patch applies same changes as commit 
e3dfef8e3c85a64dbe6388117303f5819fa3c6a2 of libav:
instead of the obsolete AVBitStreamFilterContext now the new AVBSFContext 
filter is used to
restore annex-B prefixes.

Based-on: e3dfef8e3c85a64dbe6388117303f5819fa3c6a2 by Anton Khirnov
Push requested by maintainer
Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b93e2233155e6c1f0a074cad4135a70d9d2934d3
---

 libavcodec/qsvdec_h2645.c | 138 +++---
 1 file changed, 107 insertions(+), 31 deletions(-)

diff --git a/libavcodec/qsvdec_h2645.c b/libavcodec/qsvdec_h2645.c
old mode 100644
new mode 100755
index fda827c..98a1952
--- a/libavcodec/qsvdec_h2645.c
+++ b/libavcodec/qsvdec_h2645.c
@@ -47,17 +47,35 @@ typedef struct QSVH2645Context {
 int load_plugin;
 
 // the filter for converting to Annex B
-AVBitStreamFilterContext *bsf;
+AVBSFContext *bsf;
 
+AVFifoBuffer *packet_fifo;
+
+AVPacket pkt_filtered;
 } QSVH2645Context;
 
+static void qsv_clear_buffers(QSVH2645Context *s)
+{
+AVPacket pkt;
+while (av_fifo_size(s->packet_fifo) >= sizeof(pkt)) {
+av_fifo_generic_read(s->packet_fifo, &pkt, sizeof(pkt), NULL);
+av_packet_unref(&pkt);
+}
+
+av_bsf_free(&s->bsf);
+
+av_packet_unref(&s->pkt_filtered);
+}
+
 static av_cold int qsv_decode_close(AVCodecContext *avctx)
 {
 QSVH2645Context *s = avctx->priv_data;
 
 ff_qsv_decode_close(&s->qsv);
 
-av_bitstream_filter_close(s->bsf);
+qsv_clear_buffers(s);
+
+av_fifo_free(s->packet_fifo);
 
 return 0;
 }
@@ -81,16 +99,15 @@ static av_cold int qsv_decode_init(AVCodecContext *avctx)
 return AVERROR(ENOMEM);
 }
 }
+s->packet_fifo = av_fifo_alloc(sizeof(AVPacket));
+if (!s->packet_fifo) {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
 
 if (avctx->codec_id == AV_CODEC_ID_H264) {
-s->bsf = av_bitstream_filter_init("h264_mp4toannexb");
 //regarding ticks_per_frame description, should be 2 for h.264:
 avctx->ticks_per_frame = 2;
-} else
-s->bsf = av_bitstream_filter_init("hevc_mp4toannexb");
-if (!s->bsf) {
-ret = AVERROR(ENOMEM);
-goto fail;
 }
 
 return 0;
@@ -99,42 +116,101 @@ fail:
 return ret;
 }
 
+static int qsv_init_bsf(AVCodecContext *avctx, QSVH2645Context *s)
+{
+const char *filter_name = avctx->codec_id == AV_CODEC_ID_HEVC ?
+  "hevc_mp4toannexb" : "h264_mp4toannexb";
+const AVBitStreamFilter *filter;
+int ret;
+
+if (s->bsf)
+return 0;
+
+filter = av_bsf_get_by_name(filter_name);
+if (!filter)
+return AVERROR_BUG;
+
+ret = av_bsf_alloc(filter, &s->bsf);
+if (ret < 0)
+return ret;
+
+ret = avcodec_parameters_from_context(s->bsf->par_in, avctx);
+if (ret < 0)
+return ret;
+
+s->bsf->time_base_in = avctx->time_base;
+
+ret = av_bsf_init(s->bsf);
+if (ret < 0)
+return ret;
+
+return ret;
+}
+
 static int qsv_decode_frame(AVCodecContext *avctx, void *data,
 int *got_frame, AVPacket *avpkt)
 {
 QSVH2645Context *s = avctx->priv_data;
 AVFrame *frame= data;
 int ret;
-uint8_t *p_filtered = NULL;
-int  n_filtered = NULL;
-AVPacket pkt_filtered = { 0 };
 
+/* make sure the bitstream filter is initialized */
+ret = qsv_init_bsf(avctx, s);
+if (ret < 0)
+return ret;
+
+/* buffer the input packet */
 if (avpkt->size) {
-if (avpkt->size > 3 && !avpkt->data[0] &&
-!avpkt->data[1] && !avpkt->data[2] && 1==avpkt->data[3]) {
-/* we already have annex-b prefix */
-return ff_qsv_decode(avctx, &s->qsv, frame, got_frame, avpkt);
+AVPacket input_ref = { 0 };
 
-} else {
-/* no annex-b prefix. try to restore: */
-ret = av_bitstream_filter_filter(s->bsf, avctx, 
"private_spspps_buf",
- &p_filtered, &n_filtered,
- avpkt->data, avpkt->size, 0);
-if (ret>=0) {
-pkt_filtered.pts  = avpkt->pts;
-pkt_filtered.data = p_filtered;
-pkt_filtered.size = n_filtered;
-
-ret = ff_qsv_decode(avctx, &s->qsv, frame, got_frame, 
&pkt_filtered);
-
-if (p_filtered != avpkt->data)
-av

[FFmpeg-cvslog] avfilter/drawtext: fix frame mem leak

2015-04-14 Thread Ivan Efimov
ffmpeg | branch: master | Ivan Efimov  | Fri Apr 10 
17:28:45 2015 +0300| [2051b401cc7e9ec9051c7f575d639944a9869b67] | committer: 
Michael Niedermayer

avfilter/drawtext: fix frame mem leak

Signed-off-by: Ivan Efimov 
Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2051b401cc7e9ec9051c7f575d639944a9869b67
---

 libavfilter/vf_drawtext.c |8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
index 37eb231..cf17a55 100644
--- a/libavfilter/vf_drawtext.c
+++ b/libavfilter/vf_drawtext.c
@@ -1275,12 +1275,16 @@ static int filter_frame(AVFilterLink *inlink, AVFrame 
*frame)
 int ret;
 
 if (s->reload) {
-if ((ret = load_textfile(ctx)) < 0)
+if ((ret = load_textfile(ctx)) < 0) {
+av_frame_free(&frame);
 return ret;
+}
 #if CONFIG_LIBFRIBIDI
 if (s->text_shaping)
-if ((ret = shape_text(ctx)) < 0)
+if ((ret = shape_text(ctx)) < 0) {
+av_frame_free(&frame);
 return ret;
+}
 #endif
 }
 

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


[FFmpeg-cvslog] avcodec/qsv: Extending QSV/ MFX session initialization for the linux platform where a display handle is required.

2015-07-02 Thread Ivan Uskov
ffmpeg | branch: master | Ivan Uskov  | Tue Jun 30 
20:13:09 2015 +0300| [db89f45535aa3e99bceb5f6bf957c90e7ca39841] | committer: 
Michael Niedermayer

avcodec/qsv: Extending QSV/MFX session initialization for the linux platform 
where a display handle is required.

Now ff_qsv_init_internal_session() is able
to find appropriate display handle under linux using VAAPI.

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=db89f45535aa3e99bceb5f6bf957c90e7ca39841
---

 libavcodec/qsv.c  |   70 +
 libavcodec/qsv_internal.h |   17 ++-
 2 files changed, 86 insertions(+), 1 deletion(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 31be9d1..714c794 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -77,6 +77,21 @@ int ff_qsv_error(int mfx_err)
 }
 }
 
+/**
+ * @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, mfxSession *session)
 {
 mfxIMPL impl   = MFX_IMPL_AUTO_ANY;
@@ -91,6 +106,61 @@ int ff_qsv_init_internal_session(AVCodecContext *avctx, 
mfxSession *session)
 return ff_qsv_error(ret);
 }
 
+
+// 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
+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;
+
+//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, &major_version, &minor_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);
+break;
+}
+}
+MFXVideoCORE_SetHandle((*session), (mfxHandleType)MFX_HANDLE_VA_DISPLAY, 
(mfxHDL)va_dpy);
+
+#endif //AVCODEC_QSV_LINUX_SESSION_HANDLE
+
 MFXQueryIMPL(*session, &impl);
 
 switch (MFX_IMPL_BASETYPE(impl)) {
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 86fca5f..ae03bf3 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -21,12 +21,27 @@
 #ifndef AVCODEC_QSV_INTERNAL_H
 #define AVCODEC_QSV_INTERNAL_H
 
+#if CONFIG_VAAPI
+#define AVCODEC_QSV_LINUX_SESSION_HANDLE
+#endif //CONFIG_VAAPI
+
+#ifdef AVCODEC_QSV_LINUX_SESSION_HANDLE
+#include 
+#include 
+#if HAVE_UNISTD_H
+#include 
+#endif
+#include 
+#include 
+#include 
+#endif
+
 #include 
 
 #include "libavutil/frame.h"
 
 #define QSV_VERSION_MAJOR 1
-#define QSV_VERSION_MINOR 1
+#define QSV_VERSION_MINOR 9
 
 #define ASYNC_DEPTH_DEFAULT 4   // internal parallelism
 

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


[FFmpeg-cvslog] avcodec/qsvenc_h264: Change the set of performance presets to match with the MFX library constants.

2015-07-02 Thread Ivan Uskov
ffmpeg | branch: master | Ivan Uskov  | Thu Jul  2 
19:09:12 2015 +0300| [6e5864ab294c45814e6d417546f885a0c7dfb7cc] | committer: 
Michael Niedermayer

avcodec/qsvenc_h264: Change the set of performance presets to match with the 
MFX library constants.

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6e5864ab294c45814e6d417546f885a0c7dfb7cc
---

 libavcodec/qsvenc_h264.c |   12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/libavcodec/qsvenc_h264.c b/libavcodec/qsvenc_h264.c
index d0b9b03..d35561d 100644
--- a/libavcodec/qsvenc_h264.c
+++ b/libavcodec/qsvenc_h264.c
@@ -76,10 +76,14 @@ static const AVOption options[] = {
 { "main", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_AVC_MAIN
 }, INT_MIN, INT_MAX, VE, "profile" },
 { "high", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_PROFILE_AVC_HIGH
 }, INT_MIN, INT_MAX, VE, "profile" },
 
-{ "preset", NULL, OFFSET(qsv.preset), AV_OPT_TYPE_INT, { .i64 = 
MFX_TARGETUSAGE_BALANCED }, 0, 7,   VE, "preset" },
-{ "fast",   NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 
MFX_TARGETUSAGE_BEST_SPEED  },   INT_MIN, INT_MAX, VE, "preset" },
-{ "medium", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_TARGETUSAGE_BALANCED  
}, INT_MIN, INT_MAX, VE, "preset" },
-{ "slow",   NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 
MFX_TARGETUSAGE_BEST_QUALITY  }, INT_MIN, INT_MAX, VE, "preset" },
+{ "preset", NULL, OFFSET(qsv.preset), AV_OPT_TYPE_INT, { .i64 = 
MFX_TARGETUSAGE_BALANCED }, MFX_TARGETUSAGE_BEST_QUALITY, 
MFX_TARGETUSAGE_BEST_SPEED,   VE, "preset" },
+{ "veryfast",NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 
MFX_TARGETUSAGE_BEST_SPEED  },   INT_MIN, INT_MAX, VE, "preset" },
+{ "faster",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_TARGETUSAGE_6  
},INT_MIN, INT_MAX, VE, "preset" },
+{ "fast",NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_TARGETUSAGE_5  
},INT_MIN, INT_MAX, VE, "preset" },
+{ "medium",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 
MFX_TARGETUSAGE_BALANCED  }, INT_MIN, INT_MAX, VE, "preset" },
+{ "slow",NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_TARGETUSAGE_3  
},INT_MIN, INT_MAX, VE, "preset" },
+{ "slower",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_TARGETUSAGE_2  
},INT_MIN, INT_MAX, VE, "preset" },
+{ "veryslow",NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 
MFX_TARGETUSAGE_BEST_QUALITY  }, INT_MIN, INT_MAX, VE, "preset" },
 
 { NULL },
 };

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


[FFmpeg-cvslog] libavcodec/qsvenc.c: More correct selection of alignment of a frame height depending whether an encoded sequence progressive or not.

2015-07-06 Thread Ivan Uskov
ffmpeg | branch: master | Ivan Uskov  | Sat Jul  4 
15:33:26 2015 +0300| [38402754b97745125b25d38bf525fe46cace9370] | committer: 
Michael Niedermayer

libavcodec/qsvenc.c: More correct selection of alignment of a frame height 
depending whether an encoded sequence progressive or not.

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=38402754b97745125b25d38bf525fe46cace9370
---

 libavcodec/qsvenc.c |   17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index bcf3d73..f3008c0 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -65,18 +65,29 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
 q->param.mfx.BufferSizeInKB = 0;
 
 q->param.mfx.FrameInfo.FourCC = MFX_FOURCC_NV12;
-q->param.mfx.FrameInfo.Width  = FFALIGN(avctx->width, 16);
-q->param.mfx.FrameInfo.Height = FFALIGN(avctx->height, 32);
 q->param.mfx.FrameInfo.CropX  = 0;
 q->param.mfx.FrameInfo.CropY  = 0;
 q->param.mfx.FrameInfo.CropW  = avctx->width;
 q->param.mfx.FrameInfo.CropH  = avctx->height;
 q->param.mfx.FrameInfo.AspectRatioW   = avctx->sample_aspect_ratio.num;
 q->param.mfx.FrameInfo.AspectRatioH   = avctx->sample_aspect_ratio.den;
-q->param.mfx.FrameInfo.PicStruct  = MFX_PICSTRUCT_PROGRESSIVE;
 q->param.mfx.FrameInfo.ChromaFormat   = MFX_CHROMAFORMAT_YUV420;
 q->param.mfx.FrameInfo.BitDepthLuma   = 8;
 q->param.mfx.FrameInfo.BitDepthChroma = 8;
+q->param.mfx.FrameInfo.Width  = FFALIGN(avctx->width, 16);
+
+if (avctx->flags & CODEC_FLAG_INTERLACED_DCT) {
+   /* A true field layout (TFF or BFF) is not important here,
+  it will specified later during frame encoding. But it is important
+  to specify is frame progressive or not because allowed heigh 
alignment
+  does depend by this.
+*/
+q->param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_FIELD_TFF;
+q->param.mfx.FrameInfo.Height= FFALIGN(avctx->height, 32);
+} else {
+q->param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
+q->param.mfx.FrameInfo.Height= FFALIGN(avctx->height, 16);
+}
 
 if (avctx->framerate.den > 0 && avctx->framerate.num > 0) {
 q->param.mfx.FrameInfo.FrameRateExtN = avctx->framerate.num;

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


[FFmpeg-cvslog] libavcodec/qsvenc.c: A warning message when library will work at partial hardware acceleration.

2015-07-06 Thread Ivan Uskov
ffmpeg | branch: master | Ivan Uskov  | Mon Jul  6 
16:58:33 2015 +0300| [115c14c3b6644181e0331bfbda7f86c61e939a7d] | committer: 
Michael Niedermayer

libavcodec/qsvenc.c: A warning message when library will work at partial 
hardware acceleration.

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=115c14c3b6644181e0331bfbda7f86c61e939a7d
---

 libavcodec/qsvenc.c |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index f3008c0..dc8b5f2 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -226,7 +226,9 @@ int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q)
 }
 
 ret = MFXVideoENCODE_Init(q->session, &q->param);
-if (ret < 0) {
+if (MFX_WRN_PARTIAL_ACCELERATION==ret) {
+av_log(avctx, AV_LOG_WARNING, "Encoder will work with partial HW 
acceleration\n");
+} else if (ret < 0) {
 av_log(avctx, AV_LOG_ERROR, "Error initializing the encoder\n");
 return ff_qsv_error(ret);
 }

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


[FFmpeg-cvslog] libavcodec/qsv.c: Linux-only code part has been moved to separate function in order to avoid the "ISO C90 forbids mixed declarations and code" compiler warning.

2015-07-07 Thread Ivan Uskov
ffmpeg | branch: master | Ivan Uskov  | Mon Jul  6 
18:04:13 2015 +0300| [9c95734e1c0f1a086d1c71b65c29355ef6f7785d] | committer: 
Michael Niedermayer

libavcodec/qsv.c: Linux-only code part has been moved to separate function in 
order to avoid the "ISO C90 forbids mixed declarations and code" compiler 
warning.

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9c95734e1c0f1a086d1c71b65c29355ef6f7785d
---

 libavcodec/qsv.c |   75 +++---
 1 file changed, 43 insertions(+), 32 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 714c794..dab9d1e 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -76,41 +76,13 @@ int ff_qsv_error(int mfx_err)
 return AVERROR_UNKNOWN;
 }
 }
-
-/**
- * @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, mfxSession *session)
+static int ff_qsv_set_display_handle(AVCodecContext *avctx, mfxSession session)
 {
-mfxIMPL impl   = MFX_IMPL_AUTO_ANY;
-mfxVersion ver = { { QSV_VERSION_MINOR, QSV_VERSION_MAJOR } };
-
-const char *desc;
-int ret;
-
-ret = MFXInit(impl, &ver, session);
-if (ret < 0) {
-av_log(avctx, AV_LOG_ERROR, "Error initializing an internal MFX 
session\n");
-return ff_qsv_error(ret);
-}
-
-
 // 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;
@@ -154,12 +126,51 @@ int ff_qsv_init_internal_session(AVCodecContext *avctx, 
mfxSession *session)
 } else {
 av_log(avctx, AV_LOG_VERBOSE,
 "mfx initialization: %s vaInitialize successful\n",adapterpath);
+ret = MFXVideoCORE_SetHandle(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 ff_qsv_error(ret);
+}
 break;
 }
 }
-MFXVideoCORE_SetHandle((*session), (mfxHandleType)MFX_HANDLE_VA_DISPLAY, 
(mfxHDL)va_dpy);
-
 #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, mfxSession *session)
+{
+mfxIMPL impl   = MFX_IMPL_AUTO_ANY;
+mfxVersion ver = { { QSV_VERSION_MINOR, QSV_VERSION_MAJOR } };
+
+const char *desc;
+int ret;
+
+ret = MFXInit(impl, &ver, session);
+if (ret < 0) {
+av_log(avctx, AV_LOG_ERROR, "Error initializing an internal MFX 
session\n");
+return ff_qsv_error(ret);
+}
+
+ret = ff_qsv_set_display_handle(avctx, *session);
+if (ret < 0)
+return ret;
 
 MFXQueryIMPL(*session, &impl);
 

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


[FFmpeg-cvslog] libavcodec/qsvenc.c: fix incorrect loop condition.

2015-07-08 Thread Ivan Uskov
ffmpeg | branch: master | Ivan Uskov  | Tue Jul  7 
20:33:36 2015 +0300| [b409748bc4412fa2d8e642585c4e5ab8a4d136cb] | committer: 
Michael Niedermayer

libavcodec/qsvenc.c: fix incorrect loop condition.

For example, the encoder may return MFX_WRN_INCOMPATIBLE_VIDEO_PARAM warning
i.e. ret==5 old loop implementation will repeat several times until output 
buffer
overflow. New implementation explicitly uses loop only for device busy case.

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b409748bc4412fa2d8e642585c4e5ab8a4d136cb
---

 libavcodec/qsvenc.c |7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index dc8b5f2..024 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -399,9 +399,12 @@ int ff_qsv_encode(AVCodecContext *avctx, QSVEncContext *q,
 
 do {
 ret = MFXVideoENCODE_EncodeFrameAsync(q->session, NULL, surf, &bs, 
&sync);
-if (ret == MFX_WRN_DEVICE_BUSY)
+if (ret == MFX_WRN_DEVICE_BUSY) {
 av_usleep(1);
-} while (ret > 0);
+continue;
+}
+break;
+} while ( 1 );
 
 if (ret < 0)
 return (ret == MFX_ERR_MORE_DATA) ? 0 : ff_qsv_error(ret);

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


[FFmpeg-cvslog] libavcodec/qsvenc.c: Fix for too agressive height alignment during frame encoding which may be reason of superflous frame copying.

2015-07-09 Thread Ivan Uskov
ffmpeg | branch: master | Ivan Uskov  | Thu Jul  9 
16:49:36 2015 +0300| [dbf8352a2e8710014d5234e8e2c8294758c1ec62] | committer: 
Michael Niedermayer

libavcodec/qsvenc.c: Fix for too agressive height alignment during frame 
encoding which may be reason of superflous frame copying.

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=dbf8352a2e8710014d5234e8e2c8294758c1ec62
---

 libavcodec/qsvenc.c |   10 ++
 libavcodec/qsvenc.h |1 +
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 29f0386..5f59b6c 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -85,11 +85,12 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
   does depend by this.
 */
 q->param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_FIELD_TFF;
-q->param.mfx.FrameInfo.Height= FFALIGN(avctx->height, 32);
+q->height_align = 32;
 } else {
 q->param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
-q->param.mfx.FrameInfo.Height= FFALIGN(avctx->height, 
avctx->codec_id == AV_CODEC_ID_HEVC ? 32 : 16);
+q->height_align = 16;
 }
+   q->param.mfx.FrameInfo.Height= FFALIGN(avctx->height, q->height_align);
 
 if (avctx->framerate.den > 0 && avctx->framerate.num > 0) {
 q->param.mfx.FrameInfo.FrameRateExtN = avctx->framerate.num;
@@ -323,8 +324,9 @@ static int submit_frame(QSVEncContext *q, const AVFrame 
*frame,
 }
 
 /* make a copy if the input is not padded as libmfx requires */
-if (frame->height & 31 || frame->linesize[0] & (q->width_align - 1)) {
-qf->frame->height = FFALIGN(frame->height, 32);
+if ( frame->height & (q->height_align - 1) ||
+frame->linesize[0] & (q->width_align - 1)) {
+qf->frame->height = FFALIGN(frame->height, q->height_align);
 qf->frame->width  = FFALIGN(frame->width, q->width_align);
 
 ret = ff_get_buffer(q->avctx, qf->frame, AV_GET_BUFFER_FLAG_REF);
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 530754c..8195d9b 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -43,6 +43,7 @@ typedef struct QSVEncContext {
 
 int packet_size;
 int width_align;
+int height_align;
 
 mfxVideoParam param;
 mfxFrameAllocRequest req;

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


[FFmpeg-cvslog] libavcodec/qsvenc.c: improving handling for return codes of MFXVideoENCODE_EncodeFrameAsync

2015-07-09 Thread Ivan Uskov
ffmpeg | branch: master | Ivan Uskov  | Thu Jul  9 
22:01:00 2015 +0300| [5985316fba3b886699cc7f237bf10466d113fd08] | committer: 
Michael Niedermayer

libavcodec/qsvenc.c: improving handling for return codes of 
MFXVideoENCODE_EncodeFrameAsync

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5985316fba3b886699cc7f237bf10466d113fd08
---

 libavcodec/qsvenc.c |   18 +-
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 5f59b6c..3f37639 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -417,12 +417,20 @@ int ff_qsv_encode(AVCodecContext *avctx, QSVEncContext *q,
 break;
 } while ( 1 );
 
-if (ret < 0)
-return (ret == MFX_ERR_MORE_DATA) ? 0 : ff_qsv_error(ret);
-
-if (ret == MFX_WRN_INCOMPATIBLE_VIDEO_PARAM && frame->interlaced_frame)
-print_interlace_msg(avctx, q);
+if (ret < 0) {
+if (ret == MFX_ERR_MORE_DATA)
+return 0;
+av_log(avctx, AV_LOG_ERROR, "EncodeFrameAsync returned %d\n", ret);
+return ff_qsv_error(ret);
+}
 
+if (ret == MFX_WRN_INCOMPATIBLE_VIDEO_PARAM) {
+if (frame->interlaced_frame)
+print_interlace_msg(avctx, q);
+else
+av_log(avctx, AV_LOG_WARNING,
+   "EncodeFrameAsync returned 'incompatible param' code\n");
+}
 if (sync) {
 MFXVideoCORE_SyncOperation(q->session, sync, 6);
 

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


[FFmpeg-cvslog] libavcodec/qsv.c: Issue fixed: QSV engine does not release display handler under linux platform.

2015-07-13 Thread Ivan Uskov
ffmpeg | branch: master | Ivan Uskov  | Mon Jul 13 
10:17:54 2015 -0400| [ce91bab70f69acc1a7e5705af95cc6fa89765825] | committer: 
Michael Niedermayer

libavcodec/qsv.c: Issue fixed: QSV engine does not release display handler 
under linux platform.

Reviewed-by: Gwenole Beauchesne 
Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ce91bab70f69acc1a7e5705af95cc6fa89765825
---

 libavcodec/qsv.c  |   38 +++---
 libavcodec/qsv_internal.h |   11 ++-
 libavcodec/qsvdec.c   |   10 --
 libavcodec/qsvdec.h   |2 +-
 libavcodec/qsvenc.c   |   11 +--
 libavcodec/qsvenc.h   |2 +-
 6 files changed, 52 insertions(+), 22 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 697af87..4c8e6b0 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -85,7 +85,7 @@ int ff_qsv_error(int mfx_err)
 return AVERROR_UNKNOWN;
 }
 }
-static int ff_qsv_set_display_handle(AVCodecContext *avctx, mfxSession session)
+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
@@ -99,6 +99,9 @@ static int ff_qsv_set_display_handle(AVCodecContext *avctx, 
mfxSession session)
 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++) {
 
@@ -135,7 +138,9 @@ static int ff_qsv_set_display_handle(AVCodecContext *avctx, 
mfxSession session)
 } else {
 av_log(avctx, AV_LOG_VERBOSE,
 "mfx initialization: %s vaInitialize successful\n",adapterpath);
-ret = MFXVideoCORE_SetHandle(session,
+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,
@@ -163,7 +168,7 @@ static int ff_qsv_set_display_handle(AVCodecContext *avctx, 
mfxSession session)
  * @param avctxffmpeg metadata for this codec context
  * @param session  the MSDK session used
  */
-int ff_qsv_init_internal_session(AVCodecContext *avctx, mfxSession *session,
+int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs,
  const char *load_plugins)
 {
 mfxIMPL impl   = MFX_IMPL_AUTO_ANY;
@@ -172,17 +177,17 @@ int ff_qsv_init_internal_session(AVCodecContext *avctx, 
mfxSession *session,
 const char *desc;
 int ret;
 
-ret = MFXInit(impl, &ver, session);
+ret = MFXInit(impl, &ver, &qs->session);
 if (ret < 0) {
 av_log(avctx, AV_LOG_ERROR, "Error initializing an internal MFX 
session\n");
 return ff_qsv_error(ret);
 }
 
-ret = ff_qsv_set_display_handle(avctx, *session);
+ret = ff_qsv_set_display_handle(avctx, qs);
 if (ret < 0)
 return ret;
 
-MFXQueryIMPL(*session, &impl);
+MFXQueryIMPL(qs->session, &impl);
 
 switch (MFX_IMPL_BASETYPE(impl)) {
 case MFX_IMPL_SOFTWARE:
@@ -222,7 +227,7 @@ int ff_qsv_init_internal_session(AVCodecContext *avctx, 
mfxSession *session,
 
 }
 
-ret = MFXVideoUSER_Load(*session, &uid, 1);
+ret = MFXVideoUSER_Load(qs->session, &uid, 1);
 if (ret < 0) {
 av_log(avctx, AV_LOG_ERROR, "Could not load the requested 
plugin: %s\n",
plugin);
@@ -243,3 +248,22 @@ load_plugin_fail:
 
 return 0;
 }
+
+int ff_qsv_close_internal_session(QSVSession *qs)
+{
+if (qs->session) {
+MFXClose(qs->session);
+qs->session = NULL;
+}
+#ifdef AVCODEC_QSV_LINUX_SESSION_HANDLE
+if (qs->va_display) {
+vaTerminate(qs->va_display);
+qs->va_display = NULL;
+}
+if (qs->fd_display > 0) {
+close(qs->fd_display);
+qs->fd_display = -1;
+}
+#endif
+return 0;
+}
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index ee48a0f..3d949dc 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -58,6 +58,14 @@ typedef struct QSVFrame {
 struct QSVFrame *next;
 } QSVFrame;
 
+typedef struct QSVSession {
+mfxSession session;
+#ifdef AVCODEC_QSV_LINUX_SESSION_HANDLE
+intfd_display;
+VADisplay  va_display;
+#endif
+} QSVSession;
+
 /**
  * Convert a libmfx error code into a ffmpeg error code.
  */
@@ -65,7 +73,8 @@ 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, mfxSession *session,
+int ff_qsv_init_internal_session(AVCo

[FFmpeg-cvslog] Refactoring to move common QSV-related code part into libavcodec/qsvdec.c

2015-07-16 Thread Ivan Uskov
ffmpeg | branch: master | Ivan Uskov  | Tue Jul 14 
07:07:04 2015 -0400| [6e127990fa9ea9776a74041080ff2a9ce8a39767] | committer: 
Michael Niedermayer

Refactoring to move common QSV-related code part into libavcodec/qsvdec.c

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6e127990fa9ea9776a74041080ff2a9ce8a39767
---

 libavcodec/qsvdec.c  |   42 +-
 libavcodec/qsvdec.h  |2 +-
 libavcodec/qsvdec_h264.c |   15 +--
 3 files changed, 19 insertions(+), 40 deletions(-)

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 52df028..996d8e8 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -34,6 +34,7 @@
 
 #include "avcodec.h"
 #include "internal.h"
+#include "qsv.h"
 #include "qsv_internal.h"
 #include "qsvdec.h"
 
@@ -48,37 +49,28 @@ int ff_qsv_map_pixfmt(enum AVPixelFormat format)
 }
 }
 
-static int qsv_init_session(AVCodecContext *avctx, QSVContext *q, mfxSession 
session)
-{
-if (!session) {
-if (!q->internal_qs.session) {
-int ret = ff_qsv_init_internal_session(avctx, &q->internal_qs, 
NULL);
-if (ret < 0)
-return ret;
-}
-
-q->session = q->internal_qs.session;
-} else {
-q->session = session;
-}
-
-/* make sure the decoder is uninitialized */
-MFXVideoDECODE_Close(q->session);
-
-return 0;
-}
-
-int ff_qsv_decode_init(AVCodecContext *avctx, QSVContext *q, mfxSession 
session)
+int ff_qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
 {
 mfxVideoParam param = { { 0 } };
 int ret;
 
-ret = qsv_init_session(avctx, q, session);
-if (ret < 0) {
-av_log(avctx, AV_LOG_ERROR, "Error initializing an MFX session\n");
-return ret;
+q->iopattern  = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
+
+if (avctx->hwaccel_context) {
+AVQSVContext *qsv = avctx->hwaccel_context;
+
+q->session= qsv->session;
+q->iopattern  = qsv->iopattern;
+q->ext_buffers= qsv->ext_buffers;
+q->nb_ext_buffers = qsv->nb_ext_buffers;
 }
+if (!q->session) {
+ret = ff_qsv_init_internal_session(avctx, &q->internal_qs, NULL);
+if (ret < 0)
+return ret;
 
+q->session = q->internal_qs.session;
+}
 
 ret = ff_qsv_codec_id_to_mfx(avctx->codec_id);
 if (ret < 0)
diff --git a/libavcodec/qsvdec.h b/libavcodec/qsvdec.h
index 210e9a9..4184d33 100644
--- a/libavcodec/qsvdec.h
+++ b/libavcodec/qsvdec.h
@@ -57,7 +57,7 @@ typedef struct QSVContext {
 
 int ff_qsv_map_pixfmt(enum AVPixelFormat format);
 
-int ff_qsv_decode_init(AVCodecContext *s, QSVContext *q, mfxSession session);
+int ff_qsv_decode_init(AVCodecContext *s, QSVContext *q);
 
 int ff_qsv_decode(AVCodecContext *s, QSVContext *q,
   AVFrame *frame, int *got_frame,
diff --git a/libavcodec/qsvdec_h264.c b/libavcodec/qsvdec_h264.c
index 7eb7a6c..1e9dff1 100644
--- a/libavcodec/qsvdec_h264.c
+++ b/libavcodec/qsvdec_h264.c
@@ -33,9 +33,7 @@
 
 #include "avcodec.h"
 #include "internal.h"
-#include "qsv_internal.h"
 #include "qsvdec.h"
-#include "qsv.h"
 
 typedef struct QSVH264Context {
 AVClass *class;
@@ -130,8 +128,6 @@ static av_cold int qsv_decode_init(AVCodecContext *avctx)
 }
 s->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES;
 
-s->qsv.iopattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
-
 return 0;
 fail:
 qsv_decode_close(avctx);
@@ -157,7 +153,6 @@ static int qsv_process_data(AVCodecContext *avctx, AVFrame 
*frame,
 if (s->parser->format   != s->orig_pix_fmt||
 s->parser->coded_width  != avctx->coded_width ||
 s->parser->coded_height != avctx->coded_height) {
-mfxSession session = NULL;
 
 enum AVPixelFormat pix_fmts[3] = { AV_PIX_FMT_QSV,
AV_PIX_FMT_NONE,
@@ -187,15 +182,7 @@ static int qsv_process_data(AVCodecContext *avctx, AVFrame 
*frame,
 
 avctx->pix_fmt = ret;
 
-if (avctx->hwaccel_context) {
-AVQSVContext *user_ctx = avctx->hwaccel_context;
-session   = user_ctx->session;
-s->qsv.iopattern  = user_ctx->iopattern;
-s->qsv.ext_buffers= user_ctx->ext_buffers;
-s->qsv.nb_ext_buffers = user_ctx->nb_ext_buffers;
-}
-
-ret = ff_qsv_decode_init(avctx, &s->qsv, session);
+ret = ff_qsv_decode_init(avctx, &s->qsv);
 if (ret < 0)
 goto reinit_fail;
 }

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


[FFmpeg-cvslog] Adding myself as maintainer for qsv*

2015-07-20 Thread Ivan Uskov
ffmpeg | branch: master | Ivan Uskov  | Fri Jul 17 
04:38:57 2015 -0400| [fec0485c43803172ef11b5fcd06e70500fc9dfe6] | committer: 
Michael Niedermayer

Adding myself as maintainer for qsv*

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=fec0485c43803172ef11b5fcd06e70500fc9dfe6
---

 MAINTAINERS |1 +
 1 file changed, 1 insertion(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index c5c6572..886ecae 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -238,6 +238,7 @@ Codecs:
   qdm2.c, qdm2data.hRoberto Togni, Benjamin Larsson
   qdrw.cKostya Shishkov
   qpeg.cKostya Shishkov
+  qsv*      Ivan Uskov
   qtrle.c   Mike Melanson
   ra144.c, ra144.h, ra288.c, ra288.hRoberto Togni
   resample2.c   Michael Niedermayer

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


[FFmpeg-cvslog] libavcodec/qsvdec.c: missed MFXVideoDECODE_Close() call

2015-07-20 Thread Ivan Uskov
ffmpeg | branch: master | Ivan Uskov  | Mon Jul 20 
09:48:29 2015 -0400| [264ba3d847f93a5be8989d139a6bd4abce195304] | committer: 
Michael Niedermayer

libavcodec/qsvdec.c: missed MFXVideoDECODE_Close() call

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=264ba3d847f93a5be8989d139a6bd4abce195304
---

 libavcodec/qsvdec.c |3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index c422529..2646731 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -300,6 +300,9 @@ int ff_qsv_decode_close(QSVContext *q)
 av_fifo_free(q->async_fifo);
 q->async_fifo = NULL;
 
+MFXVideoDECODE_Close(q->session);
+q->session = NULL;
+
 ff_qsv_close_internal_session(&q->internal_qs);
 
 return 0;

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


[FFmpeg-cvslog] libavcodec/qsvdec_h264.c: SPS parsing is now performed by MFXVideoDECODE_DecodeHeader() in libavcodec/qsvdec.c

2015-07-22 Thread Ivan Uskov
ffmpeg | branch: master | Ivan Uskov  | Mon Jul 20 
11:07:34 2015 -0400| [1acb19d12bcd259c3b2be39fb3149ced5916b56e] | committer: 
Michael Niedermayer

libavcodec/qsvdec_h264.c: SPS parsing is now performed by 
MFXVideoDECODE_DecodeHeader() in libavcodec/qsvdec.c

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1acb19d12bcd259c3b2be39fb3149ced5916b56e
---

 libavcodec/qsvdec.c  |   80 +
 libavcodec/qsvdec.h  |2 +-
 libavcodec/qsvdec_h264.c |   90 --
 3 files changed, 58 insertions(+), 114 deletions(-)

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 2646731..8b06611 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -49,54 +49,60 @@ int ff_qsv_map_pixfmt(enum AVPixelFormat format)
 }
 }
 
-int ff_qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
+int ff_qsv_decode_init(AVCodecContext *avctx, QSVContext *q, AVPacket *avpkt)
 {
 mfxVideoParam param = { { 0 } };
+mfxBitstream bs   = { { { 0 } } };
 int ret;
 
-q->async_fifo = av_fifo_alloc((1 + q->async_depth) *
-  (sizeof(mfxSyncPoint) + sizeof(QSVFrame*)));
-if (!q->async_fifo)
-return AVERROR(ENOMEM);
-
 q->iopattern  = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
+if (!q->session) {
+if (avctx->hwaccel_context) {
+AVQSVContext *qsv = avctx->hwaccel_context;
 
-if (avctx->hwaccel_context) {
-AVQSVContext *qsv = avctx->hwaccel_context;
+q->session= qsv->session;
+q->iopattern  = qsv->iopattern;
+q->ext_buffers= qsv->ext_buffers;
+q->nb_ext_buffers = qsv->nb_ext_buffers;
+}
+if (!q->session) {
+ret = ff_qsv_init_internal_session(avctx, &q->internal_qs, NULL);
+if (ret < 0)
+return ret;
 
-q->session= qsv->session;
-q->iopattern  = qsv->iopattern;
-q->ext_buffers= qsv->ext_buffers;
-q->nb_ext_buffers = qsv->nb_ext_buffers;
+q->session = q->internal_qs.session;
+}
 }
-if (!q->session) {
-ret = ff_qsv_init_internal_session(avctx, &q->internal_qs, NULL);
-if (ret < 0)
-return ret;
 
-q->session = q->internal_qs.session;
-}
+if (avpkt->size) {
+bs.Data   = avpkt->data;
+bs.DataLength = avpkt->size;
+bs.MaxLength  = bs.DataLength;
+bs.TimeStamp  = avpkt->pts;
+} else
+return AVERROR_INVALIDDATA;
 
 ret = ff_qsv_codec_id_to_mfx(avctx->codec_id);
-if (ret < 0)
+if (ret < 0) {
+av_log(avctx, AV_LOG_ERROR, "Unsupported codec_id %08x\n", 
avctx->codec_id);
 return ret;
+}
 
-param.mfx.CodecId  = ret;
-param.mfx.CodecProfile = avctx->profile;
-param.mfx.CodecLevel   = avctx->level;
-
-param.mfx.FrameInfo.BitDepthLuma   = 8;
-param.mfx.FrameInfo.BitDepthChroma = 8;
-param.mfx.FrameInfo.Shift  = 0;
-param.mfx.FrameInfo.FourCC = MFX_FOURCC_NV12;
-param.mfx.FrameInfo.Width  = avctx->coded_width;
-param.mfx.FrameInfo.Height = avctx->coded_height;
-param.mfx.FrameInfo.ChromaFormat   = MFX_CHROMAFORMAT_YUV420;
+param.mfx.CodecId = ret;
 
+ret = MFXVideoDECODE_DecodeHeader(q->session, &bs, ¶m);
+if (MFX_ERR_MORE_DATA==ret) {
+return AVERROR(EAGAIN);
+} else if (ret < 0) {
+av_log(avctx, AV_LOG_ERROR, "Decode header error %d\n", ret);
+return ff_qsv_error(ret);
+}
 param.IOPattern   = q->iopattern;
 param.AsyncDepth  = q->async_depth;
 param.ExtParam= q->ext_buffers;
 param.NumExtParam = q->nb_ext_buffers;
+param.mfx.FrameInfo.BitDepthLuma   = 8;
+param.mfx.FrameInfo.BitDepthChroma = 8;
 
 ret = MFXVideoDECODE_Init(q->session, ¶m);
 if (ret < 0) {
@@ -104,6 +110,20 @@ int ff_qsv_decode_init(AVCodecContext *avctx, QSVContext 
*q)
 return ff_qsv_error(ret);
 }
 
+avctx->pix_fmt  = AV_PIX_FMT_NV12;
+avctx->profile  = param.mfx.CodecProfile;
+avctx->level= param.mfx.CodecLevel;
+avctx->coded_width  = param.mfx.FrameInfo.Width;
+avctx->coded_height = param.mfx.FrameInfo.Height;
+avctx->width= param.mfx.FrameInfo.CropW - 
param.mfx.FrameInfo.CropX;
+avctx->height   = param.mfx.FrameInfo.CropH - 
param.mfx.FrameInfo.CropY;
+
+q->async_fifo = av_fifo_alloc((1 + q->async_depth) *
+  (sizeof(mfxSyncPoint) + sizeof(QSVFrame*)));
+if (!q->async_fifo)
+return AVERROR(ENOMEM);
+
+
 return 0;
 }
 
diff --git a

[FFmpeg-cvslog] libavcodec/qsvdec_h264.c: refactoring: functionality of qsv_process_data() has been moved into qsvdec.c

2015-07-23 Thread Ivan Uskov
ffmpeg | branch: master | Ivan Uskov  | Thu Jul 23 
05:14:41 2015 -0400| [d50ab820dacf0d070805889ff69ec1f03401d835] | committer: 
Michael Niedermayer

libavcodec/qsvdec_h264.c: refactoring: functionality of qsv_process_data() has 
been moved into qsvdec.c

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d50ab820dacf0d070805889ff69ec1f03401d835
---

 libavcodec/qsvdec.c  |   13 -
 libavcodec/qsvdec.h  |4 
 libavcodec/qsvdec_h264.c |   20 +---
 3 files changed, 17 insertions(+), 20 deletions(-)

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 8b06611..4e7a0ac 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -92,7 +92,10 @@ int ff_qsv_decode_init(AVCodecContext *avctx, QSVContext *q, 
AVPacket *avpkt)
 
 ret = MFXVideoDECODE_DecodeHeader(q->session, &bs, ¶m);
 if (MFX_ERR_MORE_DATA==ret) {
-return AVERROR(EAGAIN);
+/* this code means that header not found so we return packet size to 
skip
+   a current packet
+ */
+return avpkt->size;
 } else if (ret < 0) {
 av_log(avctx, AV_LOG_ERROR, "Decode header error %d\n", ret);
 return ff_qsv_error(ret);
@@ -123,6 +126,7 @@ int ff_qsv_decode_init(AVCodecContext *avctx, QSVContext 
*q, AVPacket *avpkt)
 if (!q->async_fifo)
 return AVERROR(ENOMEM);
 
+q->engine_ready = 1;
 
 return 0;
 }
@@ -230,6 +234,11 @@ int ff_qsv_decode(AVCodecContext *avctx, QSVContext *q,
 mfxBitstream bs = { { { 0 } } };
 int ret;
 
+if (!q->engine_ready) {
+ret = ff_qsv_decode_init(avctx, q, avpkt);
+if (ret)
+return ret;
+}
 if (avpkt->size) {
 bs.Data   = avpkt->data;
 bs.DataLength = avpkt->size;
@@ -325,5 +334,7 @@ int ff_qsv_decode_close(QSVContext *q)
 
 ff_qsv_close_internal_session(&q->internal_qs);
 
+q->engine_ready = 0;
+
 return 0;
 }
diff --git a/libavcodec/qsvdec.h b/libavcodec/qsvdec.h
index 4d3c505..a4971ad 100644
--- a/libavcodec/qsvdec.h
+++ b/libavcodec/qsvdec.h
@@ -50,6 +50,10 @@ typedef struct QSVContext {
 
 AVFifoBuffer *async_fifo;
 
+// this flag indicates that header parsed,
+// decoder instance created and ready to general decoding
+int engine_ready;
+
 // options set by the caller
 int async_depth;
 int iopattern;
diff --git a/libavcodec/qsvdec_h264.c b/libavcodec/qsvdec_h264.c
index 8b3f916..314eb6c 100644
--- a/libavcodec/qsvdec_h264.c
+++ b/libavcodec/qsvdec_h264.c
@@ -101,24 +101,6 @@ fail:
 return ret;
 }
 
-static int qsv_process_data(AVCodecContext *avctx, AVFrame *frame,
-int *got_frame, AVPacket *pkt)
-{
-QSVH264Context *s = avctx->priv_data;
-int ret;
-
-if (!s->qsv.session || AV_PIX_FMT_NONE==avctx->pix_fmt) {
-ret = ff_qsv_decode_init(avctx, &s->qsv, pkt);
-/* consume packet without a header */
-if (AVERROR(EAGAIN)==ret)
-return pkt->size;
-if (ret < 0)
-return ret;
-}
-
-return ff_qsv_decode(avctx, &s->qsv, frame, got_frame, pkt);
-}
-
 static int qsv_decode_frame(AVCodecContext *avctx, void *data,
 int *got_frame, AVPacket *avpkt)
 {
@@ -171,7 +153,7 @@ static int qsv_decode_frame(AVCodecContext *avctx, void 
*data,
 s->pkt_filtered.size = size;
 }
 
-ret = qsv_process_data(avctx, frame, got_frame, &s->pkt_filtered);
+ret = ff_qsv_decode(avctx, &s->qsv, frame, got_frame, 
&s->pkt_filtered);
 if (ret < 0)
 return ret;
 

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


[FFmpeg-cvslog] libavcodec/qsvdec.c: The ff_qsv_decode() now guarantees the consumption of whole packet.

2015-07-24 Thread Ivan Uskov
ffmpeg | branch: master | Ivan Uskov  | Fri Jul 24 
06:26:14 2015 -0400| [c90dbc67ed6b849cc3e7f24d83cef3d015f2c3d0] | committer: 
Michael Niedermayer

libavcodec/qsvdec.c: The ff_qsv_decode() now guarantees the consumption of 
whole packet.

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c90dbc67ed6b849cc3e7f24d83cef3d015f2c3d0
---

 libavcodec/qsvdec.c |  133 ---
 libavcodec/qsvdec.h |1 +
 2 files changed, 105 insertions(+), 29 deletions(-)

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 4e7a0ac..9d69c1a 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -121,11 +121,19 @@ int ff_qsv_decode_init(AVCodecContext *avctx, QSVContext 
*q, AVPacket *avpkt)
 avctx->width= param.mfx.FrameInfo.CropW - 
param.mfx.FrameInfo.CropX;
 avctx->height   = param.mfx.FrameInfo.CropH - 
param.mfx.FrameInfo.CropY;
 
-q->async_fifo = av_fifo_alloc((1 + q->async_depth) *
+/* maximum decoder latency should be not exceed max DPB size for h.264 and
+   HEVC which is 16 for both cases.
+   So weare  pre-allocating fifo big enough for 17 elements:
+ */
+q->async_fifo = av_fifo_alloc((1 + 16) *
   (sizeof(mfxSyncPoint) + sizeof(QSVFrame*)));
 if (!q->async_fifo)
 return AVERROR(ENOMEM);
 
+q->input_fifo = av_fifo_alloc(1024*16);
+if (!q->input_fifo)
+return AVERROR(ENOMEM);
+
 q->engine_ready = 1;
 
 return 0;
@@ -223,6 +231,40 @@ static QSVFrame *find_frame(QSVContext *q, 
mfxFrameSurface1 *surf)
 return NULL;
 }
 
+/*  This function uses for 'smart' releasing of consumed data
+from the input bitstream fifo.
+Since the input fifo mapped to mfxBitstream which does not understand
+a wrapping of data over fifo end, we should also to relocate a possible
+data rest to fifo begin. If rest of data is absent then we just reset 
fifo's
+pointers to initial positions.
+NOTE the case when fifo does contain unconsumed data is rare and typical
+amount of such data is 1..4 bytes.
+*/
+static void qsv_fifo_relocate(AVFifoBuffer *f, int bytes_to_free)
+{
+int data_size;
+int data_rest = 0;
+
+av_fifo_drain(f, bytes_to_free);
+
+data_size = av_fifo_size(f);
+if (data_size > 0) {
+if (f->buffer!=f->rptr) {
+if ( (f->end - f->rptr) < data_size) {
+data_rest = data_size - (f->end - f->rptr);
+data_size-=data_rest;
+memmove(f->buffer+data_size, f->buffer, data_rest);
+}
+memmove(f->buffer, f->rptr, data_size);
+data_size+= data_rest;
+}
+}
+f->rptr = f->buffer;
+f->wptr = f->buffer + data_size;
+f->wndx = data_size;
+f->rndx = 0;
+}
+
 int ff_qsv_decode(AVCodecContext *avctx, QSVContext *q,
   AVFrame *frame, int *got_frame,
   AVPacket *avpkt)
@@ -233,55 +275,85 @@ int ff_qsv_decode(AVCodecContext *avctx, QSVContext *q,
 mfxSyncPoint sync;
 mfxBitstream bs = { { { 0 } } };
 int ret;
+int n_out_frames;
+int buffered = 0;
 
 if (!q->engine_ready) {
 ret = ff_qsv_decode_init(avctx, q, avpkt);
 if (ret)
 return ret;
 }
-if (avpkt->size) {
-bs.Data   = avpkt->data;
-bs.DataLength = avpkt->size;
+
+if (avpkt->size ) {
+if (av_fifo_size(q->input_fifo)) {
+/* we have got rest of previous packet into buffer */
+if (av_fifo_space(q->input_fifo) < avpkt->size) {
+ret = av_fifo_grow(q->input_fifo, avpkt->size);
+if (ret < 0)
+return ret;
+}
+av_fifo_generic_write(q->input_fifo, avpkt->data, avpkt->size, 
NULL);
+bs.Data   = q->input_fifo->rptr;
+bs.DataLength = av_fifo_size(q->input_fifo);
+buffered = 1;
+} else {
+bs.Data   = avpkt->data;
+bs.DataLength = avpkt->size;
+}
 bs.MaxLength  = bs.DataLength;
 bs.TimeStamp  = avpkt->pts;
 }
 
-do {
+while (1) {
 ret = get_surface(avctx, q, &insurf);
 if (ret < 0)
 return ret;
-
-ret = MFXVideoDECODE_DecodeFrameAsync(q->session, avpkt->size ? &bs : 
NULL,
-  insurf, &outsurf, &sync);
-if (ret == MFX_WRN_DEVICE_BUSY)
+do {
+ret = MFXVideoDECODE_DecodeFrameAsync(q->session, avpkt->size ? 
&bs : NULL,
+  insurf, &outsurf, &sync);
+if (ret != MFX_WRN_DEVICE_BUSY)
+break;
 av_u

[FFmpeg-cvslog] libavcodec/qsvdec_h264.c: packet buffering has been removed since qsvdec.c does maintain own data buffering now.

2015-07-24 Thread Ivan Uskov
ffmpeg | branch: master | Ivan Uskov  | Tue Jul 21 
08:32:09 2015 -0400| [0b159e3b65d53cbb7e66a1e10850927275fb2a1e] | committer: 
Michael Niedermayer

libavcodec/qsvdec_h264.c: packet buffering has been removed since qsvdec.c does 
maintain own data buffering now.

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0b159e3b65d53cbb7e66a1e10850927275fb2a1e
---

 libavcodec/qsvdec_h264.c |  103 +++---
 1 file changed, 24 insertions(+), 79 deletions(-)

diff --git a/libavcodec/qsvdec_h264.c b/libavcodec/qsvdec_h264.c
index 314eb6c..78356e3 100644
--- a/libavcodec/qsvdec_h264.c
+++ b/libavcodec/qsvdec_h264.c
@@ -42,37 +42,14 @@ typedef struct QSVH264Context {
 // the filter for converting to Annex B
 AVBitStreamFilterContext *bsf;
 
-AVFifoBuffer *packet_fifo;
-
-AVPacket input_ref;
-AVPacket pkt_filtered;
-uint8_t *filtered_data;
 } QSVH264Context;
 
-static void qsv_clear_buffers(QSVH264Context *s)
-{
-AVPacket pkt;
-while (av_fifo_size(s->packet_fifo) >= sizeof(pkt)) {
-av_fifo_generic_read(s->packet_fifo, &pkt, sizeof(pkt), NULL);
-av_packet_unref(&pkt);
-}
-
-if (s->filtered_data != s->input_ref.data)
-av_freep(&s->filtered_data);
-s->filtered_data = NULL;
-av_packet_unref(&s->input_ref);
-}
-
 static av_cold int qsv_decode_close(AVCodecContext *avctx)
 {
 QSVH264Context *s = avctx->priv_data;
 
 ff_qsv_decode_close(&s->qsv);
 
-qsv_clear_buffers(s);
-
-av_fifo_free(s->packet_fifo);
-
 av_bitstream_filter_close(s->bsf);
 
 return 0;
@@ -83,12 +60,6 @@ static av_cold int qsv_decode_init(AVCodecContext *avctx)
 QSVH264Context *s = avctx->priv_data;
 int ret;
 
-s->packet_fifo = av_fifo_alloc(sizeof(AVPacket));
-if (!s->packet_fifo) {
-ret = AVERROR(ENOMEM);
-goto fail;
-}
-
 s->bsf = av_bitstream_filter_init("h264_mp4toannexb");
 if (!s->bsf) {
 ret = AVERROR(ENOMEM);
@@ -107,68 +78,42 @@ static int qsv_decode_frame(AVCodecContext *avctx, void 
*data,
 QSVH264Context *s = avctx->priv_data;
 AVFrame *frame= data;
 int ret;
+uint8_t *p_filtered = NULL;
+int  n_filtered = NULL;
+AVPacket pkt_filtered = { 0 };
 
-/* buffer the input packet */
 if (avpkt->size) {
-AVPacket input_ref = { 0 };
+if (avpkt->size > 3 && !avpkt->data[0] &&
+!avpkt->data[1] && !avpkt->data[2] && 1==avpkt->data[3]) {
+/* we already have annex-b prefix */
+return ff_qsv_decode(avctx, &s->qsv, frame, got_frame, avpkt);
 
-if (av_fifo_space(s->packet_fifo) < sizeof(input_ref)) {
-ret = av_fifo_realloc2(s->packet_fifo,
-   av_fifo_size(s->packet_fifo) + 
sizeof(input_ref));
-if (ret < 0)
-return ret;
-}
-
-ret = av_packet_ref(&input_ref, avpkt);
-if (ret < 0)
-return ret;
-av_fifo_generic_write(s->packet_fifo, &input_ref, sizeof(input_ref), 
NULL);
-}
-
-/* process buffered data */
-while (!*got_frame) {
-/* prepare the input data -- convert to Annex B if needed */
-if (s->pkt_filtered.size <= 0) {
-int size;
-
-/* no more data */
-if (av_fifo_size(s->packet_fifo) < sizeof(AVPacket))
-return avpkt->size ? avpkt->size : ff_qsv_decode(avctx, 
&s->qsv, frame, got_frame, avpkt);
-
-if (s->filtered_data != s->input_ref.data)
-av_freep(&s->filtered_data);
-s->filtered_data = NULL;
-av_packet_unref(&s->input_ref);
-
-av_fifo_generic_read(s->packet_fifo, &s->input_ref, 
sizeof(s->input_ref), NULL);
+} else {
+/* no annex-b prefix. try to restore: */
 ret = av_bitstream_filter_filter(s->bsf, avctx, NULL,
- &s->filtered_data, &size,
- s->input_ref.data, 
s->input_ref.size, 0);
-if (ret < 0) {
-s->filtered_data = s->input_ref.data;
-size = s->input_ref.size;
+ &p_filtered, &n_filtered,
+ avpkt->data, avpkt->size, 0);
+if (ret>=0) {
+pkt_filtered.pts  = avpkt->pts;
+pkt_filtered.data = p_filtered;
+pkt_filtered.size = n_filtered;
+
+ret = ff_qsv_decode(avctx, &s->qsv, frame, got_frame, 
&pkt_filtered);
+
+if (p_filtered != avpkt->

[FFmpeg-cvslog] avcodec: Add QSV MPEG-2 video decoder.

2015-07-25 Thread Ivan Uskov
ffmpeg | branch: master | Ivan Uskov  | Sat Jul 25 
10:45:20 2015 -0400| [6d0123f40e2a94ae3f215af4d598919bc72b9b07] | committer: 
Michael Niedermayer

avcodec: Add QSV MPEG-2 video decoder.

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6d0123f40e2a94ae3f215af4d598919bc72b9b07
---

 Changelog |1 +
 configure |4 ++
 libavcodec/Makefile   |1 +
 libavcodec/allcodecs.c|2 +
 libavcodec/qsvdec_mpeg2.c |   95 +
 libavcodec/version.h  |2 +-
 6 files changed, 104 insertions(+), 1 deletion(-)

diff --git a/Changelog b/Changelog
index 27870ba..7a642bf 100644
--- a/Changelog
+++ b/Changelog
@@ -15,6 +15,7 @@ version :
 - adrawgraph audio and drawgraph video filter
 - removegrain video filter
 - Intel QSV-accelerated MPEG-2 video and HEVC encoding
+- Intel QSV-accelerated MPEG-2 video decoding
 - libkvazaar HEVC encoder
 - erosion, dilation, deflate and inflate video filters
 - Dynamic Audio Normalizer as dynaudnorm filter
diff --git a/configure b/configure
index 8f3bce3..c71951c 100755
--- a/configure
+++ b/configure
@@ -2273,6 +2273,8 @@ mpeg1video_decoder_select="error_resilience mpeg_er 
mpegvideo"
 mpeg1video_encoder_select="aandcttables mpegvideoenc h263dsp"
 mpeg2video_decoder_select="error_resilience mpeg_er mpegvideo"
 mpeg2video_encoder_select="aandcttables mpegvideoenc h263dsp"
+mpeg2_qsv_decoder_deps="libmfx"
+mpeg2_qsv_decoder_select="qsvdec mpeg2_qsv_hwaccel"
 mpeg2_qsv_encoder_deps="libmfx"
 mpeg2_qsv_encoder_select="qsvenc"
 mpeg4_decoder_select="h263_decoder mpeg4video_parser"
@@ -2431,6 +2433,8 @@ mpeg2_vdpau_hwaccel_deps="vdpau"
 mpeg2_vdpau_hwaccel_select="mpeg2video_decoder"
 mpeg2_xvmc_hwaccel_deps="xvmc"
 mpeg2_xvmc_hwaccel_select="mpeg2video_decoder"
+mpeg2_qsv_hwaccel_deps="libmfx"
+mpeg2_qsv_hwaccel_select="qsvdec_mpeg2"
 mpeg4_crystalhd_decoder_select="crystalhd"
 mpeg4_vaapi_hwaccel_deps="vaapi"
 mpeg4_vaapi_hwaccel_select="mpeg4_decoder"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index eea9ead..b8c24d3 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -364,6 +364,7 @@ OBJS-$(CONFIG_MPEG1VIDEO_ENCODER)  += mpeg12enc.o 
mpeg12.o
 OBJS-$(CONFIG_MPEG2VIDEO_DECODER)  += mpeg12dec.o mpeg12.o mpeg12data.o
 OBJS-$(CONFIG_MPEG2VIDEO_ENCODER)  += mpeg12enc.o mpeg12.o
 OBJS-$(CONFIG_MPEG2_QSV_ENCODER)   += qsvenc_mpeg2.o
+OBJS-$(CONFIG_MPEG2_QSV_DECODER)   += qsvdec_mpeg2.o
 OBJS-$(CONFIG_MPEG4_DECODER)   += xvididct.o
 OBJS-$(CONFIG_MPL2_DECODER)+= mpl2dec.o ass.o
 OBJS-$(CONFIG_MSMPEG4V1_DECODER)   += msmpeg4dec.o msmpeg4.o msmpeg4data.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 82db791..647cd4f 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -94,6 +94,7 @@ void avcodec_register_all(void)
 REGISTER_HWACCEL(MPEG2_DXVA2,   mpeg2_dxva2);
 REGISTER_HWACCEL(MPEG2_VAAPI,   mpeg2_vaapi);
 REGISTER_HWACCEL(MPEG2_VDPAU,   mpeg2_vdpau);
+REGISTER_HWACCEL(MPEG2_QSV, mpeg2_qsv);
 REGISTER_HWACCEL(MPEG4_VAAPI,   mpeg4_vaapi);
 REGISTER_HWACCEL(MPEG4_VDPAU,   mpeg4_vdpau);
 REGISTER_HWACCEL(VC1_D3D11VA,   vc1_d3d11va);
@@ -223,6 +224,7 @@ void avcodec_register_all(void)
 REGISTER_DECODER(MPEG_VDPAU,mpeg_vdpau);
 REGISTER_DECODER(MPEG1_VDPAU,   mpeg1_vdpau);
 REGISTER_DECODER(MPEG2_CRYSTALHD,   mpeg2_crystalhd);
+REGISTER_DECODER(MPEG2_QSV, mpeg2_qsv);
 REGISTER_DECODER(MSA1,  msa1);
 REGISTER_DECODER(MSMPEG4_CRYSTALHD, msmpeg4_crystalhd);
 REGISTER_DECODER(MSMPEG4V1, msmpeg4v1);
diff --git a/libavcodec/qsvdec_mpeg2.c b/libavcodec/qsvdec_mpeg2.c
new file mode 100644
index 000..e920da7
--- /dev/null
+++ b/libavcodec/qsvdec_mpeg2.c
@@ -0,0 +1,95 @@
+/*
+ * Intel MediaSDK QSV based MPEG2 video decoder
+ *
+ * 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 "libavutil/common.h&q

[FFmpeg-cvslog] avcodec: Add QSV VC-1 video decoder.

2015-07-25 Thread Ivan Uskov
ffmpeg | branch: master | Ivan Uskov  | Sat Jul 25 
12:28:11 2015 -0400| [fb57bc6c34b979bec995e714162fdfb4caf6db1a] | committer: 
Michael Niedermayer

avcodec: Add QSV VC-1 video decoder.

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=fb57bc6c34b979bec995e714162fdfb4caf6db1a
---

 Changelog   |1 +
 configure   |4 +++
 libavcodec/Makefile |1 +
 libavcodec/allcodecs.c  |2 ++
 libavcodec/qsvdec_vc1.c |   88 +++
 libavcodec/version.h|2 +-
 6 files changed, 97 insertions(+), 1 deletion(-)

diff --git a/Changelog b/Changelog
index 7a642bf..9079e58 100644
--- a/Changelog
+++ b/Changelog
@@ -16,6 +16,7 @@ version :
 - removegrain video filter
 - Intel QSV-accelerated MPEG-2 video and HEVC encoding
 - Intel QSV-accelerated MPEG-2 video decoding
+- Intel QSV-accelerated VC-1 video decoding
 - libkvazaar HEVC encoder
 - erosion, dilation, deflate and inflate video filters
 - Dynamic Audio Normalizer as dynaudnorm filter
diff --git a/configure b/configure
index c71951c..2d405ba 100755
--- a/configure
+++ b/configure
@@ -2340,6 +2340,8 @@ utvideo_encoder_select="bswapdsp huffman huffyuvencdsp"
 vble_decoder_select="huffyuvdsp"
 vc1_decoder_select="blockdsp error_resilience h263_decoder h264chroma h264qpel 
intrax8 mpeg_er qpeldsp startcode"
 vc1image_decoder_select="vc1_decoder"
+vc1_qsv_decoder_deps="libmfx"
+vc1_qsv_decoder_select="qsvdec vc1_qsv_hwaccel"
 vorbis_decoder_select="mdct"
 vorbis_encoder_select="mdct"
 vp3_decoder_select="hpeldsp vp3dsp videodsp"
@@ -2454,6 +2456,8 @@ vc1_vdpau_decoder_deps="vdpau"
 vc1_vdpau_decoder_select="vc1_decoder"
 vc1_vdpau_hwaccel_deps="vdpau"
 vc1_vdpau_hwaccel_select="vc1_decoder"
+vc1_qsv_hwaccel_deps="libmfx"
+vc1_qsv_hwaccel_select="qsvdec_vc1"
 wmv3_crystalhd_decoder_select="crystalhd"
 wmv3_d3d11va_hwaccel_select="vc1_d3d11va_hwaccel"
 wmv3_dxva2_hwaccel_select="vc1_dxva2_hwaccel"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index b8c24d3..647aae5 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -521,6 +521,7 @@ OBJS-$(CONFIG_VC1_DECODER) += vc1dec.o 
vc1_block.o vc1_loopfilter.o
   vc1dsp.o \
   msmpeg4dec.o msmpeg4.o msmpeg4data.o 
\
   wmv2dsp.o
+OBJS-$(CONFIG_VC1_QSV_DECODER) += qsvdec_vc1.o
 OBJS-$(CONFIG_VCR1_DECODER)+= vcr1.o
 OBJS-$(CONFIG_VMDAUDIO_DECODER)+= vmdaudio.o
 OBJS-$(CONFIG_VMDVIDEO_DECODER)+= vmdvideo.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 647cd4f..c0f2757 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -101,6 +101,7 @@ void avcodec_register_all(void)
 REGISTER_HWACCEL(VC1_DXVA2, vc1_dxva2);
 REGISTER_HWACCEL(VC1_VAAPI, vc1_vaapi);
 REGISTER_HWACCEL(VC1_VDPAU, vc1_vdpau);
+REGISTER_HWACCEL(VC1_QSV,   vc1_qsv);
 REGISTER_HWACCEL(WMV3_D3D11VA,  wmv3_d3d11va);
 REGISTER_HWACCEL(WMV3_DXVA2,wmv3_dxva2);
 REGISTER_HWACCEL(WMV3_VAAPI,wmv3_vaapi);
@@ -305,6 +306,7 @@ void avcodec_register_all(void)
 REGISTER_DECODER(VC1_CRYSTALHD, vc1_crystalhd);
 REGISTER_DECODER(VC1_VDPAU, vc1_vdpau);
 REGISTER_DECODER(VC1IMAGE,  vc1image);
+REGISTER_DECODER(VC1_QSV,   vc1_qsv);
 REGISTER_DECODER(VCR1,  vcr1);
 REGISTER_DECODER(VMDVIDEO,  vmdvideo);
 REGISTER_DECODER(VMNC,  vmnc);
diff --git a/libavcodec/qsvdec_vc1.c b/libavcodec/qsvdec_vc1.c
new file mode 100644
index 000..d5258fc
--- /dev/null
+++ b/libavcodec/qsvdec_vc1.c
@@ -0,0 +1,88 @@
+/*
+ * Intel MediaSDK QSV based VC-1 video decoder
+ *
+ * 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 "libavutil/common.h"
+#include "libavutil/fifo.h"
+#include "libavutil/opt.h"
+
+#include "avcodec.h"

[FFmpeg-cvslog] libavcodec/h264_mp4toannexb_bsf.c: Optional argument "private_spspps_buf" to avoid extradata modification.

2015-07-25 Thread Ivan Uskov
ffmpeg | branch: master | Ivan Uskov  | Sat Jul 25 
16:11:30 2015 -0400| [1defff85cb2cc98b4d7053415caed773586a1253] | committer: 
Michael Niedermayer

libavcodec/h264_mp4toannexb_bsf.c: Optional argument "private_spspps_buf" to 
avoid extradata modification.

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1defff85cb2cc98b4d7053415caed773586a1253
---

 libavcodec/h264_mp4toannexb_bsf.c |   41 ++---
 1 file changed, 34 insertions(+), 7 deletions(-)

diff --git a/libavcodec/h264_mp4toannexb_bsf.c 
b/libavcodec/h264_mp4toannexb_bsf.c
index ae96ee9..e919360 100644
--- a/libavcodec/h264_mp4toannexb_bsf.c
+++ b/libavcodec/h264_mp4toannexb_bsf.c
@@ -33,6 +33,18 @@ typedef struct H264BSFContext {
 uint8_t  idr_sps_seen;
 uint8_t  idr_pps_seen;
 int  extradata_parsed;
+
+/* When private_spspps is zero then spspps_buf points to global extradata
+   and bsf does replace a global extradata to own-allocated version 
(default
+   behaviour).
+   When private_spspps is non-zero the bsf uses a private version of 
spspps buf.
+   This mode necessary when bsf uses in decoder, else bsf has issues after
+   decoder re-initialization. Use the "private_spspps_buf" argument to
+   activate this mode.
+ */
+int  private_spspps;
+uint8_t *spspps_buf;
+uint32_t spspps_size;
 } H264BSFContext;
 
 static int alloc_and_copy(uint8_t **poutbuf, int *poutbuf_size,
@@ -129,9 +141,13 @@ pps:
"Warning: PPS NALU missing or invalid. "
"The resulting stream may not play.\n");
 
-av_free(avctx->extradata);
-avctx->extradata  = out;
-avctx->extradata_size = total_size;
+if (!ctx->private_spspps) {
+av_free(avctx->extradata);
+avctx->extradata  = out;
+avctx->extradata_size = total_size;
+}
+ctx->spspps_buf  = out;
+ctx->spspps_size = total_size;
 
 return length_size;
 }
@@ -159,6 +175,9 @@ static int h264_mp4toannexb_filter(AVBitStreamFilterContext 
*bsfc,
 
 /* retrieve sps and pps NAL units from extradata */
 if (!ctx->extradata_parsed) {
+if (args && strstr(args, "private_spspps_buf"))
+ctx->private_spspps = 1;
+
 ret = h264_extradata_to_annexb(ctx, avctx, 
FF_INPUT_BUFFER_PADDING_SIZE);
 if (ret < 0)
 return ret;
@@ -195,8 +214,8 @@ static int h264_mp4toannexb_filter(AVBitStreamFilterContext 
*bsfc,
 av_log(avctx, AV_LOG_WARNING, "SPS not present in the 
stream, nor in AVCC, stream may be unreadable\n");
 else {
 if ((ret = alloc_and_copy(poutbuf, poutbuf_size,
- avctx->extradata + ctx->sps_offset,
- ctx->pps_offset != -1 ? 
ctx->pps_offset : avctx->extradata_size - ctx->sps_offset,
+ ctx->spspps_buf + ctx->sps_offset,
+ ctx->pps_offset != -1 ? 
ctx->pps_offset : ctx->spspps_size - ctx->sps_offset,
  buf, nal_size)) < 0)
 goto fail;
 ctx->idr_sps_seen = 1;
@@ -214,7 +233,7 @@ static int h264_mp4toannexb_filter(AVBitStreamFilterContext 
*bsfc,
 /* prepend only to the first type 5 NAL unit of an IDR picture, if no 
sps/pps are already present */
 if (ctx->new_idr && unit_type == 5 && !ctx->idr_sps_seen && 
!ctx->idr_pps_seen) {
 if ((ret=alloc_and_copy(poutbuf, poutbuf_size,
-   avctx->extradata, avctx->extradata_size,
+   ctx->spspps_buf, ctx->spspps_size,
buf, nal_size)) < 0)
 goto fail;
 ctx->new_idr = 0;
@@ -226,7 +245,7 @@ static int h264_mp4toannexb_filter(AVBitStreamFilterContext 
*bsfc,
  NULL, 0, buf, nal_size)) < 0)
 goto fail;
 } else if ((ret = alloc_and_copy(poutbuf, poutbuf_size,
-avctx->extradata + ctx->pps_offset, 
avctx->extradata_size - ctx->pps_offset,
+ctx->spspps_buf + ctx->pps_offset, 
ctx->spspps_size - ctx->pps_offset,
 buf, nal_size)) < 0)
 goto fail;
 } else {
@@ -253,8 +272,16 @@ fail:
 return ret;
 }
 
+static void h264_mp4toannexb_filter_close(AVBitStreamFilterContext *bsfc)
+{
+H264BSFContext *ctx = bsfc->priv_data;
+if (ctx->private_spspps)
+av_free(ctx->spspps_buf);
+}

[FFmpeg-cvslog] libavcodec/qsvdec_h264.c: using "private_spspps_buf" argument for av_bitstream_filter_filter() to avoid failure after decoder re-initialization.

2015-07-25 Thread Ivan Uskov
ffmpeg | branch: master | Ivan Uskov  | Sat Jul 25 
15:56:08 2015 -0400| [684b7038436fba1a29e51861998dbf24681144d8] | committer: 
Michael Niedermayer

libavcodec/qsvdec_h264.c: using "private_spspps_buf" argument for 
av_bitstream_filter_filter() to avoid failure after decoder re-initialization.

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=684b7038436fba1a29e51861998dbf24681144d8
---

 libavcodec/qsvdec_h2645.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/qsvdec_h2645.c b/libavcodec/qsvdec_h2645.c
index d231b46..20cb438 100644
--- a/libavcodec/qsvdec_h2645.c
+++ b/libavcodec/qsvdec_h2645.c
@@ -115,7 +115,7 @@ static int qsv_decode_frame(AVCodecContext *avctx, void 
*data,
 
 } else {
 /* no annex-b prefix. try to restore: */
-ret = av_bitstream_filter_filter(s->bsf, avctx, NULL,
+ret = av_bitstream_filter_filter(s->bsf, avctx, 
"private_spspps_buf",
  &p_filtered, &n_filtered,
  avpkt->data, avpkt->size, 0);
 if (ret>=0) {

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


[FFmpeg-cvslog] libavcodec/hevc_mp4toannexb_bsf.c: Optional argument "private_spspps_buf" to avoid extradata modification.

2015-07-28 Thread Ivan Uskov
ffmpeg | branch: master | Ivan Uskov  | Tue Jul 28 
09:33:43 2015 -0400| [0b8b18b4fbbd800849d5381a7a90d0e2fcfe6a22] | committer: 
Michael Niedermayer

libavcodec/hevc_mp4toannexb_bsf.c: Optional argument "private_spspps_buf" to 
avoid extradata modification.

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0b8b18b4fbbd800849d5381a7a90d0e2fcfe6a22
---

 libavcodec/hevc_mp4toannexb_bsf.c |   40 ++---
 1 file changed, 33 insertions(+), 7 deletions(-)

diff --git a/libavcodec/hevc_mp4toannexb_bsf.c 
b/libavcodec/hevc_mp4toannexb_bsf.c
index 15890f7..7df5108 100644
--- a/libavcodec/hevc_mp4toannexb_bsf.c
+++ b/libavcodec/hevc_mp4toannexb_bsf.c
@@ -35,9 +35,21 @@ typedef struct HEVCBSFContext {
 int  extradata_parsed;
 
 int logged_nonmp4_warning;
+
+/* When private_spspps is zero then spspps_buf points to global extradata
+   and bsf does replace a global extradata to own-allocated version 
(default
+   behaviour).
+   When private_spspps is non-zero the bsf uses a private version of 
spspps buf.
+   This mode necessary when bsf uses in decoder, else bsf has issues after
+   decoder re-initialization. Use the "private_spspps_buf" argument to
+   activate this mode.
+ */
+int  private_spspps;
+uint8_t *spspps_buf;
+uint32_t spspps_size;
 } HEVCBSFContext;
 
-static int hevc_extradata_to_annexb(AVCodecContext *avctx)
+static int hevc_extradata_to_annexb(HEVCBSFContext* ctx, AVCodecContext *avctx)
 {
 GetByteContext gb;
 int length_size, num_arrays, i, j;
@@ -82,9 +94,13 @@ static int hevc_extradata_to_annexb(AVCodecContext *avctx)
 }
 }
 
-av_freep(&avctx->extradata);
-avctx->extradata  = new_extradata;
-avctx->extradata_size = new_extradata_size;
+if (!ctx->private_spspps) {
+av_freep(&avctx->extradata);
+avctx->extradata  = new_extradata;
+avctx->extradata_size = new_extradata_size;
+}
+ctx->spspps_buf  = new_extradata;
+ctx->spspps_size = new_extradata_size;
 
 if (!new_extradata_size)
 av_log(avctx, AV_LOG_WARNING, "No parameter sets in the extradata\n");
@@ -122,8 +138,10 @@ static int 
hevc_mp4toannexb_filter(AVBitStreamFilterContext *bsfc,
 *poutbuf_size = buf_size;
 return 0;
 }
+if (args && strstr(args, "private_spspps_buf"))
+ctx->private_spspps = 1;
 
-ret = hevc_extradata_to_annexb(avctx);
+ret = hevc_extradata_to_annexb(ctx, avctx);
 if (ret < 0)
 return ret;
 ctx->length_size  = ret;
@@ -148,7 +166,7 @@ static int hevc_mp4toannexb_filter(AVBitStreamFilterContext 
*bsfc,
 /* prepend extradata to IRAP frames */
 is_irap   = nalu_type >= 16 && nalu_type <= 23;
 add_extradata = is_irap && !got_irap;
-extra_size= add_extradata * avctx->extradata_size;
+extra_size= add_extradata * ctx->spspps_size;
 got_irap |= is_irap;
 
 if (SIZE_MAX - out_size < 4 ||
@@ -163,7 +181,7 @@ static int hevc_mp4toannexb_filter(AVBitStreamFilterContext 
*bsfc,
 goto fail;
 
 if (add_extradata)
-memcpy(out + out_size, avctx->extradata, extra_size);
+memcpy(out + out_size, ctx->spspps_buf, extra_size);
 AV_WB32(out + out_size + extra_size, 1);
 bytestream2_get_buffer(&gb, out + out_size + 4 + extra_size, 
nalu_size);
 out_size += 4 + nalu_size + extra_size;
@@ -179,8 +197,16 @@ fail:
 return ret;
 }
 
+static void hevc_mp4toannexb_close(AVBitStreamFilterContext *bsfc)
+{
+HEVCBSFContext *ctx = bsfc->priv_data;
+if (ctx->private_spspps)
+av_freep(&ctx->spspps_buf);
+}
+
 AVBitStreamFilter ff_hevc_mp4toannexb_bsf = {
 "hevc_mp4toannexb",
 sizeof(HEVCBSFContext),
 hevc_mp4toannexb_filter,
+hevc_mp4toannexb_close,
 };

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


[FFmpeg-cvslog] libavcodec/ qsvenc.c delay in 1 microsecond replaced to more appropriate 500 microseconds

2015-07-28 Thread Ivan Uskov
ffmpeg | branch: master | Ivan Uskov  | Tue Jul 28 
18:30:56 2015 +0300| [947c2aa4567782be64411a953a5b294976463e19] | committer: 
Michael Niedermayer

libavcodec/qsvenc.c delay in 1 microsecond replaced to more appropriate 500 
microseconds

This commit replaces the 1 microsecond delay by 500 microsecond for the
case when the MFX library does return MFX_WRN_DEVICE_BUSY status.
In general this warning never appears for simple encoding or
transcoding session because the GPU is so fast so it almost always is not busy 
and
any delay value just does not executes.
But for heavy transcoding tasks for example, when several QSV sessions
are running simultaneously then using a 1-microsecond delay may
result in 1000 iterations per each frame.
So here possible a paradoxical case when GPU loading also loads CPU by dummy 
tasks.
Official MFX/QSV samples by Intel are using 1 millisecond (i.e. 1000
microseconds) everywhere where MFX_WRN_DEVICE_BUSY does appear.
So 500us is a much more optimal value than 1us.

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=947c2aa4567782be64411a953a5b294976463e19
---

 libavcodec/qsvenc.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index c9dbe7d..57f5fe4 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -419,7 +419,7 @@ int ff_qsv_encode(AVCodecContext *avctx, QSVEncContext *q,
 do {
 ret = MFXVideoENCODE_EncodeFrameAsync(q->session, NULL, surf, bs, 
&sync);
 if (ret == MFX_WRN_DEVICE_BUSY) {
-av_usleep(1);
+av_usleep(500);
 continue;
 }
 break;

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


[FFmpeg-cvslog] libavcodec/ qsvdec.c delay in 1 microsecond replaced to more appropriate 500 microseconds

2015-07-28 Thread Ivan Uskov
ffmpeg | branch: master | Ivan Uskov  | Fri Jul 24 
07:45:38 2015 -0400| [9f543e01afe38996f409b4bf85ef738cda118006] | committer: 
Michael Niedermayer

libavcodec/qsvdec.c delay in 1 microsecond replaced to more appropriate 500 
microseconds

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9f543e01afe38996f409b4bf85ef738cda118006
---

 libavcodec/qsvdec.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index d1261ad..8fa44b5 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -316,7 +316,7 @@ int ff_qsv_decode(AVCodecContext *avctx, QSVContext *q,
   insurf, &outsurf, &sync);
 if (ret != MFX_WRN_DEVICE_BUSY)
 break;
-av_usleep(1);
+av_usleep(500);
 } while (1);
 
 if (MFX_WRN_VIDEO_PARAM_CHANGED==ret) {

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


[FFmpeg-cvslog] libavcodec/qsvdec.c: Extended error messages for MFXVideoDECODE_Init() result

2015-08-11 Thread Ivan Uskov
ffmpeg | branch: master | Ivan Uskov  | Thu Aug  6 
09:30:42 2015 -0400| [44857e7a3696bf1a3521be8c0b7354d04af68721] | committer: 
Michael Niedermayer

libavcodec/qsvdec.c: Extended error messages for MFXVideoDECODE_Init() result

Reviewed-by: Hendrik Leppkes 
Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=44857e7a3696bf1a3521be8c0b7354d04af68721
---

 libavcodec/qsvdec.c |8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 8fa44b5..e3c076d 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -110,7 +110,13 @@ int ff_qsv_decode_init(AVCodecContext *avctx, QSVContext 
*q, AVPacket *avpkt)
 
 ret = MFXVideoDECODE_Init(q->session, ¶m);
 if (ret < 0) {
-av_log(avctx, AV_LOG_ERROR, "Error initializing the MFX video 
decoder\n");
+if (MFX_ERR_INVALID_VIDEO_PARAM==ret) {
+av_log(avctx, AV_LOG_ERROR,
+   "Error initializing the MFX video decoder, unsupported 
video\n");
+} else {
+av_log(avctx, AV_LOG_ERROR,
+   "Error initializing the MFX video decoder %d\n", ret);
+}
 return ff_qsv_error(ret);
 }
 

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


[FFmpeg-cvslog] libavcodec/qsvdec.c: the ff_get_format() missed at refactoring has been restored

2015-08-19 Thread Ivan Uskov
ffmpeg | branch: master | Ivan Uskov  | Thu Aug  6 
09:14:59 2015 -0400| [fffae8e605c8a665eac0ae63c3c84f60efbec73e] | committer: 
Michael Niedermayer

libavcodec/qsvdec.c: the ff_get_format() missed at refactoring has been restored

Reviewed-by: Hendrik Leppkes 
Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=fffae8e605c8a665eac0ae63c3c84f60efbec73e
---

 libavcodec/qsvdec.c |9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index e3c076d..1062ef0 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -54,6 +54,9 @@ int ff_qsv_decode_init(AVCodecContext *avctx, QSVContext *q, 
AVPacket *avpkt)
 mfxVideoParam param = { { 0 } };
 mfxBitstream bs   = { { { 0 } } };
 int ret;
+enum AVPixelFormat pix_fmts[3] = { AV_PIX_FMT_QSV,
+   AV_PIX_FMT_NV12,
+   AV_PIX_FMT_NONE };
 
 q->iopattern  = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
 if (!q->session) {
@@ -120,7 +123,11 @@ int ff_qsv_decode_init(AVCodecContext *avctx, QSVContext 
*q, AVPacket *avpkt)
 return ff_qsv_error(ret);
 }
 
-avctx->pix_fmt  = AV_PIX_FMT_NV12;
+ret = ff_get_format(avctx, pix_fmts);
+if (ret < 0)
+return ret;
+
+avctx->pix_fmt  = ret;
 avctx->profile  = param.mfx.CodecProfile;
 avctx->level= param.mfx.CodecLevel;
 avctx->coded_width  = param.mfx.FrameInfo.Width;

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


[FFmpeg-cvslog] libavcodec/qsvdec.c: correct flush() handler has been implemented

2015-09-07 Thread Ivan Uskov
ffmpeg | branch: master | Ivan Uskov  | Thu Aug  6 
12:10:24 2015 -0400| [3f8e2e9953240365361e939ca2ecd788dd5bef59] | committer: 
Michael Niedermayer

libavcodec/qsvdec.c: correct flush() handler has been implemented

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3f8e2e9953240365361e939ca2ecd788dd5bef59
---

 libavcodec/qsvdec.c   |   45 +
 libavcodec/qsvdec.h   |2 ++
 libavcodec/qsvdec_h2645.c |4 ++--
 libavcodec/qsvdec_mpeg2.c |2 ++
 libavcodec/qsvdec_vc1.c   |8 +++-
 5 files changed, 58 insertions(+), 3 deletions(-)

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 51ad2f7..00990ba 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -517,6 +517,51 @@ int ff_qsv_decode(AVCodecContext *avctx, QSVContext *q,
 
 return ret;
 }
+/*
+ This function resets decoder and corresponded buffers before seek operation
+*/
+void ff_qsv_decode_reset(AVCodecContext *avctx, QSVContext *q)
+{
+QSVFrame *cur;
+AVPacket pkt;
+int ret = 0;
+mfxVideoParam param = { { 0 } };
+
+if (q->reinit_pending) {
+close_decoder(q);
+} else if (q->engine_ready) {
+ret = MFXVideoDECODE_GetVideoParam(q->session, ¶m);
+if (ret < 0) {
+av_log(avctx, AV_LOG_ERROR, "MFX decode get param error %d\n", 
ret);
+}
+
+ret = MFXVideoDECODE_Reset(q->session, ¶m);
+if (ret < 0) {
+av_log(avctx, AV_LOG_ERROR, "MFX decode reset error %d\n", ret);
+}
+
+/* Free all frames*/
+cur = q->work_frames;
+while (cur) {
+q->work_frames = cur->next;
+av_frame_free(&cur->frame);
+av_freep(&cur);
+cur = q->work_frames;
+}
+}
+
+/* Reset output surfaces */
+av_fifo_reset(q->async_fifo);
+
+/* Reset input packets fifo */
+while (av_fifo_size(q->pkt_fifo)) {
+av_fifo_generic_read(q->pkt_fifo, &pkt, sizeof(pkt), NULL);
+av_packet_unref(&pkt);
+}
+
+/* Reset input bitstream fifo */
+av_fifo_reset(q->input_fifo);
+}
 
 int ff_qsv_decode_close(QSVContext *q)
 {
diff --git a/libavcodec/qsvdec.h b/libavcodec/qsvdec.h
index 5211fb2..2b989c2 100644
--- a/libavcodec/qsvdec.h
+++ b/libavcodec/qsvdec.h
@@ -84,6 +84,8 @@ int ff_qsv_decode(AVCodecContext *s, QSVContext *q,
   AVFrame *frame, int *got_frame,
   AVPacket *avpkt);
 
+void ff_qsv_decode_reset(AVCodecContext *avctx, QSVContext *q);
+
 int ff_qsv_decode_close(QSVContext *q);
 
 #endif /* AVCODEC_QSVDEC_H */
diff --git a/libavcodec/qsvdec_h2645.c b/libavcodec/qsvdec_h2645.c
index 569b765..2d78722 100644
--- a/libavcodec/qsvdec_h2645.c
+++ b/libavcodec/qsvdec_h2645.c
@@ -137,8 +137,8 @@ static int qsv_decode_frame(AVCodecContext *avctx, void 
*data,
 
 static void qsv_decode_flush(AVCodecContext *avctx)
 {
-//QSVH2645Context *s = avctx->priv_data;
-/* TODO: flush qsv engine if necessary */
+QSVH2645Context *s = avctx->priv_data;
+ff_qsv_decode_reset(avctx, &s->qsv);
 }
 
 #define OFFSET(x) offsetof(QSVH2645Context, x)
diff --git a/libavcodec/qsvdec_mpeg2.c b/libavcodec/qsvdec_mpeg2.c
index 975dd9e..36fd3b0 100644
--- a/libavcodec/qsvdec_mpeg2.c
+++ b/libavcodec/qsvdec_mpeg2.c
@@ -57,6 +57,8 @@ static int qsv_decode_frame(AVCodecContext *avctx, void *data,
 
 static void qsv_decode_flush(AVCodecContext *avctx)
 {
+QSVMPEG2Context *s = avctx->priv_data;
+ff_qsv_decode_reset(avctx, &s->qsv);
 }
 
 AVHWAccel ff_mpeg2_qsv_hwaccel = {
diff --git a/libavcodec/qsvdec_vc1.c b/libavcodec/qsvdec_vc1.c
index a80fc83..3311d90 100644
--- a/libavcodec/qsvdec_vc1.c
+++ b/libavcodec/qsvdec_vc1.c
@@ -52,6 +52,12 @@ static int qsv_decode_frame(AVCodecContext *avctx, void 
*data,
 return ff_qsv_decode(avctx, &s->qsv, frame, got_frame, avpkt);
 }
 
+static void qsv_decode_flush(AVCodecContext *avctx)
+{
+QSVVC1Context *s = avctx->priv_data;
+ff_qsv_decode_reset(avctx, &s->qsv);
+}
+
 AVHWAccel ff_vc1_qsv_hwaccel = {
 .name   = "vc1_qsv",
 .type   = AVMEDIA_TYPE_VIDEO,
@@ -81,7 +87,7 @@ AVCodec ff_vc1_qsv_decoder = {
 .id = AV_CODEC_ID_VC1,
 .init   = NULL,
 .decode = qsv_decode_frame,
-.flush  = NULL,
+.flush  = qsv_decode_flush,
 .close  = qsv_decode_close,
 .capabilities   = AV_CODEC_CAP_DELAY,
 .priv_class = &class,

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


[FFmpeg-cvslog] libavcodec/qsvdec.c: correct handling of dynamic frame size changing has been implemented

2015-09-07 Thread Ivan Uskov
ffmpeg | branch: master | Ivan Uskov  | Tue Aug  4 
06:40:06 2015 -0400| [cc167f7e55dafdeeca7ac9622331db8d8f6cb463] | committer: 
Michael Niedermayer

libavcodec/qsvdec.c: correct handling of dynamic frame size changing has been 
implemented

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=cc167f7e55dafdeeca7ac9622331db8d8f6cb463
---

 libavcodec/qsvdec.c |  145 +++
 libavcodec/qsvdec.h |   11 
 2 files changed, 134 insertions(+), 22 deletions(-)

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 1062ef0..51ad2f7 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -146,10 +146,17 @@ int ff_qsv_decode_init(AVCodecContext *avctx, QSVContext 
*q, AVPacket *avpkt)
 return AVERROR(ENOMEM);
 }
 
-q->input_fifo = av_fifo_alloc(1024*16);
-if (!q->input_fifo)
-return AVERROR(ENOMEM);
+if (!q->input_fifo) {
+q->input_fifo = av_fifo_alloc(1024*16);
+if (!q->input_fifo)
+return AVERROR(ENOMEM);
+}
 
+if (!q->pkt_fifo) {
+q->pkt_fifo = av_fifo_alloc( sizeof(AVPacket) * (1 + 16) );
+if (!q->pkt_fifo)
+return AVERROR(ENOMEM);
+}
 q->engine_ready = 1;
 
 return 0;
@@ -281,7 +288,26 @@ static void qsv_fifo_relocate(AVFifoBuffer *f, int 
bytes_to_free)
 f->rndx = 0;
 }
 
-int ff_qsv_decode(AVCodecContext *avctx, QSVContext *q,
+
+static void close_decoder(QSVContext *q)
+{
+QSVFrame *cur;
+
+MFXVideoDECODE_Close(q->session);
+
+cur = q->work_frames;
+while (cur) {
+q->work_frames = cur->next;
+av_frame_free(&cur->frame);
+av_freep(&cur);
+cur = q->work_frames;
+}
+
+q->engine_ready   = 0;
+q->reinit_pending = 0;
+}
+
+static int do_qsv_decode(AVCodecContext *avctx, QSVContext *q,
   AVFrame *frame, int *got_frame,
   AVPacket *avpkt)
 {
@@ -293,6 +319,7 @@ int ff_qsv_decode(AVCodecContext *avctx, QSVContext *q,
 int ret;
 int n_out_frames;
 int buffered = 0;
+int flush= !avpkt->size || q->reinit_pending;
 
 if (!q->engine_ready) {
 ret = ff_qsv_decode_init(avctx, q, avpkt);
@@ -300,7 +327,7 @@ int ff_qsv_decode(AVCodecContext *avctx, QSVContext *q,
 return ret;
 }
 
-if (avpkt->size ) {
+if (!flush) {
 if (av_fifo_size(q->input_fifo)) {
 /* we have got rest of previous packet into buffer */
 if (av_fifo_space(q->input_fifo) < avpkt->size) {
@@ -325,7 +352,7 @@ int ff_qsv_decode(AVCodecContext *avctx, QSVContext *q,
 if (ret < 0)
 return ret;
 do {
-ret = MFXVideoDECODE_DecodeFrameAsync(q->session, avpkt->size ? 
&bs : NULL,
+ret = MFXVideoDECODE_DecodeFrameAsync(q->session, flush ? NULL : 
&bs,
   insurf, &outsurf, &sync);
 if (ret != MFX_WRN_DEVICE_BUSY)
 break;
@@ -333,7 +360,11 @@ int ff_qsv_decode(AVCodecContext *avctx, QSVContext *q,
 } while (1);
 
 if (MFX_WRN_VIDEO_PARAM_CHANGED==ret) {
-/* TODO: handle here sequence header changing */
+/* TODO: handle here minor sequence header changing */
+} else if (MFX_ERR_INCOMPATIBLE_VIDEO_PARAM==ret) {
+av_fifo_reset(q->input_fifo);
+flush = q->reinit_pending = 1;
+continue;
 }
 
 if (sync) {
@@ -357,7 +388,7 @@ int ff_qsv_decode(AVCodecContext *avctx, QSVContext *q,
 
 /* make sure we do not enter an infinite loop if the SDK
  * did not consume any data and did not return anything */
-if (!sync && !bs.DataOffset) {
+if (!sync && !bs.DataOffset && !flush) {
 av_log(avctx, AV_LOG_WARNING, "A decode call did not consume any 
data\n");
 bs.DataOffset = avpkt->size;
 }
@@ -376,7 +407,7 @@ int ff_qsv_decode(AVCodecContext *avctx, QSVContext *q,
 }
 n_out_frames = av_fifo_size(q->async_fifo) / 
(sizeof(out_frame)+sizeof(sync));
 
-if (n_out_frames > q->async_depth || (!avpkt->size && n_out_frames) ) {
+if (n_out_frames > q->async_depth || (flush && n_out_frames) ) {
 AVFrame *src_frame;
 
 av_fifo_generic_read(q->async_fifo, &out_frame, sizeof(out_frame), 
NULL);
@@ -409,30 +440,100 @@ int ff_qsv_decode(AVCodecContext *avctx, QSVContext *q,
 
 return avpkt->size;
 }
+/*
+ This function inserts a packet at fifo front.
+*/
+static void qsv_packet_push_front(QSVContext *q, AVPacket *avpkt)
+{
+int fifo_size = av_fifo_size(q->pkt_fifo);
+if (!fifo_size) {
+/* easy case fifo is empty */
+av_fifo_generic_write(q->pkt_fifo, avpkt, siz

Re: [FFmpeg-cvslog] intrax8: Use a constant buffer instead of a ScratchpadContext

2016-04-24 Thread Ivan Kalvachev
On 4/24/16, Vittorio Giovara  wrote:
> ffmpeg | branch: master | Vittorio Giovara  |
> Fri Feb 19 20:50:00 2016 -0500| [65f14128c4bcf8fcd9d3ba1e20b7a22057c9cfb0] |
> committer: Vittorio Giovara
>
> intrax8: Use a constant buffer instead of a ScratchpadContext
>
> The size of the block is fixed (8x8 plus padding).
>
>> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=65f14128c4bcf8fcd9d3ba1e20b7a22057c9cfb0
> ---
>
>  libavcodec/intrax8.c |5 ++---
>  libavcodec/intrax8.h |1 +
>  2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/libavcodec/intrax8.c b/libavcodec/intrax8.c
> index a05c533..f5bf795 100644
> --- a/libavcodec/intrax8.c
> +++ b/libavcodec/intrax8.c
> @@ -330,12 +330,11 @@ static int x8_get_dc_rlf(IntraX8Context *const w,
> const int mode,
>
>  static int x8_setup_spatial_predictor(IntraX8Context *const w, const int
> chroma)
>  {
> -MpegEncContext *const s = w->s;
>  int range;
>  int sum;
>  int quant;
>
> -w->dsp.setup_spatial_compensation(w->dest[chroma],
> s->sc.edge_emu_buffer,
> +w->dsp.setup_spatial_compensation(w->dest[chroma], w->scratchpad,
>w->frame->linesize[chroma > 0],
>&range, &sum, w->edges);
>  if (chroma) {
> @@ -699,7 +698,7 @@ static int x8_decode_intra_mb(IntraX8Context *const w,
> const int chroma)
>  dsp_x8_put_solidcolor(w->predicted_dc, w->dest[chroma],
>w->frame->linesize[!!chroma]);
>  } else {
> -w->dsp.spatial_compensation[w->orient](s->sc.edge_emu_buffer,
> +w->dsp.spatial_compensation[w->orient](w->scratchpad,
> w->dest[chroma],
>
> w->frame->linesize[!!chroma]);
>  }
> diff --git a/libavcodec/intrax8.h b/libavcodec/intrax8.h
> index f087b9f..f30801e 100644
> --- a/libavcodec/intrax8.h
> +++ b/libavcodec/intrax8.h
> @@ -51,6 +51,7 @@ typedef struct IntraX8Context {
>  int divide_quant_dc_luma;
>  int divide_quant_dc_chroma;
>  uint8_t *dest[3];
> +uint8_t scratchpad[42]; // size of the block is fixed (8x8 plus
> padding)

This looks wrong. 42<64
___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] qsv: Fix wrong ticks_per_frame for H.264

2016-04-27 Thread Ivan Uskov
ffmpeg | branch: master | Ivan Uskov  | Tue Apr 26 
10:13:04 2016 -0400| [b577a54a7c83986e59d2227c00a0227911c75452] | committer: 
Derek Buitenhuis

qsv: Fix wrong ticks_per_frame for H.264

For H.264 stream ticks_per_frame should be 2, as per the docs.

Signed-off-by: Derek Buitenhuis 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b577a54a7c83986e59d2227c00a0227911c75452
---

 libavcodec/qsvdec_h2645.c |6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavcodec/qsvdec_h2645.c b/libavcodec/qsvdec_h2645.c
index a396f31..fda827c 100644
--- a/libavcodec/qsvdec_h2645.c
+++ b/libavcodec/qsvdec_h2645.c
@@ -82,9 +82,11 @@ static av_cold int qsv_decode_init(AVCodecContext *avctx)
 }
 }
 
-if (avctx->codec_id == AV_CODEC_ID_H264)
+if (avctx->codec_id == AV_CODEC_ID_H264) {
 s->bsf = av_bitstream_filter_init("h264_mp4toannexb");
-else
+//regarding ticks_per_frame description, should be 2 for h.264:
+avctx->ticks_per_frame = 2;
+} else
 s->bsf = av_bitstream_filter_init("hevc_mp4toannexb");
 if (!s->bsf) {
 ret = AVERROR(ENOMEM);

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


[FFmpeg-cvslog] libavformat/isom: Add more language mappings

2022-06-08 Thread Ivan Baykalov
ffmpeg | branch: master | Ivan Baykalov <4ru...@gmail.com> | Wed Apr 27 
18:00:02 2022 +0700| [58880a8ea8d1aa0497e88f0da4e88455db9ba723] | committer: 
Anton Khirnov

libavformat/isom: Add more language mappings

mov_mdhd_language_map table doesn't contain ISO 639 codes for some of
the languages. I added a few which have no contradictory mappings

Fixes ticket #9743

Signed-off-by: Anton Khirnov 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=58880a8ea8d1aa0497e88f0da4e88455db9ba723
---

 libavformat/isom.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavformat/isom.c b/libavformat/isom.c
index 0a87d95792..cf27f58082 100644
--- a/libavformat/isom.c
+++ b/libavformat/isom.c
@@ -118,9 +118,9 @@ static const char mov_mdhd_language_map[][4] = {
 "hun",/*  26 Hungarian */
 "est",/*  27 Estonian */
 "lav",/*  28 Latvian */
-   "",/*  29 Sami */
+"smi",/*  29 Sami */
 "fo ",/*  30 Faroese */
-   "",/*  31 Farsi */
+"per",/*  31 Farsi */
 "rus",/*  32 Russian */
 "chi",/*  33 Simplified Chinese */
"",/*  34 Flemish */
@@ -165,7 +165,7 @@ static const char mov_mdhd_language_map[][4] = {
 "kan",/*  73 Kannada */
 "tam",/*  74 Tamil */
 "tel",/*  75 Telugu */
-   "",/*  76 Sinhala */
+"sin",/*  76 Sinhala */
 "bur",/*  77 Burmese */
 "khm",/*  78 Khmer */
 "lao",/*  79 Lao */
@@ -179,9 +179,9 @@ static const char mov_mdhd_language_map[][4] = {
 "orm",/*  87 Oromo */
 "som",/*  88 Somali */
 "swa",/*  89 Swahili */
-   "",/*  90 Kinyarwanda */
+"kin",/*  90 Kinyarwanda */
 "run",/*  91 Rundi */
-   "",/*  92 Nyanja */
+"nya",/*  92 Nyanja */
 "mlg",/*  93 Malagasy */
 "epo",/*  94 Esperanto */
"",/*  95  */

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] avformat/mov: read PCM audio configuration box ('pcmC') if available

2022-06-27 Thread Ivan Baykalov
ffmpeg | branch: master | Ivan Baykalov <4ru...@gmail.com> | Tue Jun  7 
15:26:18 2022 +0700| [cbe216d3a62fe22b16a1ba40b9b3f13e5b4ac9a9] | committer: 
Marton Balint

avformat/mov: read PCM audio configuration box ('pcmC') if available

For ipcm and fpcm streams, big-endian format is the default, but it can be 
changed
with additional 'pcmC' sub-atom of audio sample description.

Details can be found in ISO/IEC 23003-5:2020

Fixes ticket #9763.
Fixes ticket #9790.

Patch simplified by Marton Balint.

Signed-off-by: Marton Balint 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=cbe216d3a62fe22b16a1ba40b9b3f13e5b4ac9a9
---

 libavformat/mov.c | 22 ++
 1 file changed, 22 insertions(+)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 0660a51492..c6fbe511c0 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1553,6 +1553,9 @@ static void set_last_stream_little_endian(AVFormatContext 
*fc)
 st = fc->streams[fc->nb_streams-1];
 
 switch (st->codecpar->codec_id) {
+case AV_CODEC_ID_PCM_S16BE:
+st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE;
+break;
 case AV_CODEC_ID_PCM_S24BE:
 st->codecpar->codec_id = AV_CODEC_ID_PCM_S24LE;
 break;
@@ -1579,6 +1582,24 @@ static int mov_read_enda(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 return 0;
 }
 
+static int mov_read_pcmc(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+int format_flags;
+
+if (atom.size < 6) {
+av_log(c->fc, AV_LOG_ERROR, "Empty pcmC box\n");
+return AVERROR_INVALIDDATA;
+}
+
+avio_r8(pb);// version
+avio_rb24(pb);  // flags
+format_flags = avio_r8(pb);
+if (format_flags == 1) // indicates little-endian format. If not present, 
big-endian format is used
+set_last_stream_little_endian(c->fc);
+
+return 0;
+}
+
 static int mov_read_colr(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
 AVStream *st;
@@ -7674,6 +7695,7 @@ static const MOVParseTableEntry mov_default_parse_table[] 
= {
 { MKTAG('S','A','3','D'), mov_read_SA3D }, /* ambisonic audio box */
 { MKTAG('S','A','N','D'), mov_read_SAND }, /* non diegetic audio box */
 { MKTAG('i','l','o','c'), mov_read_iloc },
+{ MKTAG('p','c','m','C'), mov_read_pcmc }, /* PCM configuration box */
 { 0, NULL }
 };
 

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".