Re: [FFmpeg-devel] [PATCH 4/4] lavc/cbs_h2645: fix no slice data trigger the assert.

2018-05-12 Thread James Almer
On 5/12/2018 8:07 PM, Mark Thompson wrote:
> On 11/05/18 16:38, James Almer wrote:
>> On 5/11/2018 7:10 AM, Mark Thompson wrote:
>>> On 11/05/18 06:11, Jun Zhao wrote:
 when the NALU data with zero, just give a warning.

 Fixes ticket #7200

 Signed-off-by: Jun Zhao 
 ---
  libavcodec/cbs_h2645.c | 6 +-
  1 file changed, 5 insertions(+), 1 deletion(-)

 diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
 index ab33cdb..08b060c 100644
 --- a/libavcodec/cbs_h2645.c
 +++ b/libavcodec/cbs_h2645.c
 @@ -521,7 +521,11 @@ static int 
 cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx,
  // Remove trailing zeroes.
  while (size > 0 && nal->data[size - 1] == 0)
  --size;
 -av_assert0(size > 0);
 +if (!size) {
 +av_log(ctx->log_ctx, AV_LOG_WARNING, "No slice data - that 
 was just the header. "
 +   "Probably invalid unaligned padding on non-final NAL 
 unit.\n");
 +continue;
 +}
  
  data = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE);
  if (!data)

>>>
>>> What do we actually want the result to be here?
>>>
>>> On IRC, James suggested:
>>>
 diff --git a/libavcodec/h2645_parse.c b/libavcodec/h2645_parse.c
 index dbf2435677..d436d65f48 100644
 --- a/libavcodec/h2645_parse.c
 +++ b/libavcodec/h2645_parse.c
 @@ -371,7 +371,7 @@ int ff_h2645_packet_split(H2645Packet *pkt, const 
 uint8_t *buf, int length,
  ret = hevc_parse_nal_header(nal, logctx);
  else
  ret = h264_parse_nal_header(nal, logctx);
 -if (ret <= 0 || nal->size <= 0) {
 +if (ret <= 0 || nal->size <= 0 || nal->size_bits <= 0) {
  if (ret < 0) {
  av_log(logctx, AV_LOG_ERROR, "Invalid NAL unit %d, 
 skipping.\n",
 nal->type);
>>>
>>> which removes it before it gets to the CBS code.
>>>
>>> Another thing we could do is:
>>>
 diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
 index ab33cdb69b..46cd887cdd 100644
 --- a/libavcodec/cbs_h2645.c
 +++ b/libavcodec/cbs_h2645.c
 @@ -519,7 +519,7 @@ static int 
 cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx,
  uint8_t *data;
  
  // Remove trailing zeroes.
 -while (size > 0 && nal->data[size - 1] == 0)
 +while (size > 1 && nal->data[size - 1] == 0)
  --size;
  av_assert0(size > 0);
  
>>>
>>> which would make it parse as an empty NAL unit of type 0 (unspecified), and 
>>> therefore pass through into the output stream in the h264_metadata case.
>>>
>>> So, what do you think?  Do you know what made your sample stream?
>>>
>>> - Mark
>>
>> Taking into account the analysis by mkver in the trac ticket, where he
>> found out the bitstream contains "00 00 00 01 00 00 00 01" with the
>> second start code being a real valid NAL, i think this should definitely
>> be fixed in h2645_parse. No reason to propagate a non existent NAL like
>> this.
>> We should either use my fix, or another that actually prevents nal->size
>> from inexplicably becoming 1 in this scenario.
> 
> I was applying the standard precisely, which I think ends up with the 
> interpretation:
> 
>  00 00 00 01 09 f0 00 00 00 01 00 00 00 01 41 e2 02 56
> |  ||  |  |  ||  ||  |
>  ^^ zero_byte  start code
>  start code^^ NAL unit header
>  ^^ NAL unit header    start code
> ^^ NAL unit content (AUD)  ^^ NAL unit header
>^^ trailing zeroes ^^^... NAL unit content (slice)
> 
> The middle NAL unit has type 0 (unspecified application use) and no content.  
> I admit that's probably not what was intended here, but currently we do 
> preserve unspecified NAL units and it's not clear that type 0 should 
> necessarily be treated differently to 24-31.
> 
> This would be a pretty absurd use, though, so I don't think it really 
> matters.  Given that, I'm fine with any of the possible answers above.

I have the feeling this file is meant to have 00 00 00 01 as start code
for all NALUs, and not 00 00 01 plus a trailing/leading zero byte, so
technically this would be a rogue four byte start code before a valid
NALU, perhaps because whatever muxed this file appends start codes to
what it expects to be NALUs stripped of them, and the slice already had one.

In any case, having no content (nal->size_bits being zero, and therefore
nal->gb being an empty context) is reason enough to drop it, IMO.

> 
> - Mark
> 
> 
> (Another data point: the reference decoder segfaults when given the sample 
> stream.)
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> 

Re: [FFmpeg-devel] [PATCH] avfilter: add bm3d filter

2018-05-12 Thread Michael Niedermayer
On Sat, May 12, 2018 at 09:04:44AM +0200, Paul B Mahol wrote:
> On 5/12/18, Michael Niedermayer  wrote:
> > On Fri, May 11, 2018 at 04:03:07PM +0200, Paul B Mahol wrote:
> >> Signed-off-by: Paul B Mahol 
> >> ---
> >>  libavfilter/Makefile |1 +
> >>  libavfilter/allfilters.c |1 +
> >>  libavfilter/vf_bm3d.c| 1002
> >> ++
> >>  3 files changed, 1004 insertions(+)
> >>  create mode 100644 libavfilter/vf_bm3d.c
> > [...]
> >> +static void block_matching_multi(BM3DContext *s, const uint8_t *ref, int
> >> ref_linesize, int y, int x,
> >> + int exclude_cur_pos, int plane)
> >> +{
> >> +const int width = s->planewidth[plane];
> >> +const int height = s->planeheight[plane];
> >> +const int block_size = s->block_size;
> >> +const int step = s->bm_step;
> >> +const int range = s->bm_range / step * step;
> >> +int l = search_boundary(0, range, step, 0, y, x);
> >> +int r = search_boundary(width - block_size, range, step, 0, y, x);
> >> +int t = search_boundary(0, range, step, 1, y, x);
> >> +int b = search_boundary(height - block_size, range, step, 1, y, x);
> >> +int j, i, index = 0;
> >> +
> >> +PosCode search_pos[((r - l) / step + 1) * ((b - t) / step + 1)];
> >
> > fails to build here:
> >
> > src/libavfilter/vf_bm3d.c: In function `block_matching_multi':
> > src/libavfilter/vf_bm3d.c:308:5: error: variable length array `search_pos'
> > is used [-Werror=vla]
> >  PosCode search_pos[((r - l) / step + 1) * ((b - t) / step + 1)];
> >  ^
> 
> Come on! Your compiler still live under the rock, doesn't it?

It lives under the -Werror=vla flag added by configure
I wonder why your compiler ignores it


[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

If you think the mosad wants you dead since a long time then you are either
wrong or dead since a long time.


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 3/5] ffserver: Implement http interface and implementation

2018-05-12 Thread Stephan Holljes
Signed-off-by: Stephan Holljes 
---
 httpd.h |  58 +++
 lavfhttpd.c | 153 
 2 files changed, 211 insertions(+)
 create mode 100644 httpd.h
 create mode 100644 lavfhttpd.c

diff --git a/httpd.h b/httpd.h
new file mode 100644
index 000..6fb91bd
--- /dev/null
+++ b/httpd.h
@@ -0,0 +1,58 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef HTTPDINTERFACE_H
+#define HTTPDINTERFACE_H
+
+#define HTTPD_OK 0
+#define HTTPD_LISTEN_TIMEOUT -1
+#define HTTPD_CLIENT_ERROR -2
+#define HTTPD_OTHER_ERROR -3
+
+#include "publisher.h"
+
+/* HTTPD Config struct */
+struct HTTPDConfig {
+char *bind_address;
+int port;
+int accept_timeout;
+};
+
+/* HTTPClient struct, this information is shared between ffserver and the 
httpd implementation */
+struct HTTPClient {
+/* the method requested by the client, this field has to be set and freed 
by the httpd implementation */
+char *method;
+/* the resource requested by the client, this field has to be set and 
freed by the httpd implementation */
+char *resource;
+void *httpd_data; // httpd implementation specific data
+};
+
+/* HTTPDInterface that an httpd implementation must provide */
+struct HTTPDInterface {
+int (*init)  (void **server, struct HTTPDConfig config);
+int (*free)  (void *server);
+int (*accept)(void *server, struct HTTPClient **client, int reply_code);
+int (*write) (void *server, struct HTTPClient *client, const unsigned char 
*buf, int size);
+int (*read)  (void *server, struct HTTPClient *client, unsigned char *buf, 
int size);
+void (*close)(void *server, struct HTTPClient *client);
+void (*shutdown)(void *server);
+};
+
+/* Current HTTPDInterface implementation using lavformat */
+extern struct HTTPDInterface lavfhttpd;
+#endif
diff --git a/lavfhttpd.c b/lavfhttpd.c
new file mode 100644
index 000..3cf9958
--- /dev/null
+++ b/lavfhttpd.c
@@ -0,0 +1,153 @@
+/*
+ * 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
+ */
+ 
+#ifndef LAVFHTTPD_H
+#define LAVFHTTPD_H
+
+#include "httpd.h"
+#include 
+
+
+int lavfhttpd_init(void **server, struct HTTPDConfig config)
+{
+char out_uri[1024];
+int ret;
+AVDictionary *opts = NULL;
+AVIOContext *server_ctx = NULL;
+
+snprintf(out_uri, 1024, "http://%s:%d;, config.bind_address, config.port);
+
+avformat_network_init();
+
+if ((ret = av_dict_set(, "listen", "2", 0)) < 0) {
+av_log(opts, AV_LOG_ERROR, "Failed to set listen mode for server: 
%s\n", av_err2str(ret));
+av_free(opts);
+return -1;
+}
+
+if ((ret = av_dict_set_int(, "listen_timeout", config.accept_timeout, 
0)) < 0) {
+av_log(opts, AV_LOG_ERROR, "Failed to set listen_timeout for server: 
%s\n", av_err2str(ret));
+av_free(opts);
+return -1;
+}
+
+if ((ret = avio_open2(_ctx, out_uri, AVIO_FLAG_WRITE, NULL, )) 
< 0) {
+av_log(server, AV_LOG_ERROR, "Failed to open server: %s\n", 
av_err2str(ret));
+av_free(opts);
+return -1;
+}
+av_free(opts);
+
+*server = server_ctx;
+return 0;
+}
+
+int lavfhttpd_accept(void *server, struct HTTPClient **client, int reply_code)
+{
+AVIOContext *server_ctx = (AVIOContext*) server;
+AVIOContext *client_ctx = NULL;
+struct HTTPClient *client_http = NULL;
+int ret, ret2, handshake;
+int reply_code2 = reply_code;
+char *method, *resource;
+if ((ret = 

[FFmpeg-devel] [PATCH 5/5] ffserver: Add basic documentation of the architecture

2018-05-12 Thread Stephan Holljes
Signed-off-by: Stephan Holljes 
---
 Documentation.txt | 89 +++
 1 file changed, 89 insertions(+)
 create mode 100644 Documentation.txt

diff --git a/Documentation.txt b/Documentation.txt
new file mode 100644
index 000..9a7f0bf
--- /dev/null
+++ b/Documentation.txt
@@ -0,0 +1,89 @@
+About
+-
+
+In its current form this is an HTTP live-streaming server. A media resource can
+be streamed to a number of clients in real-time. The server interally reads the
+input in real-time, like a media-player. It keeps a short cirular buffer to be
+able to send clients data to fill their own buffers. This is to prevent media
+players from stuttering because not enough data is available. Clients that
+connect are sent this buffer and any further data read from the file. This
+means that clients that connect later than the server was, "join" whereever
+the server is currently reading (including the short buffer).
+The stream received by the clients is simply an HTTP response to an HTTP
+request.
+
+
+Documentation
+-
+
+The current implementation has three different types of work that is done in
+different threads. These types are: reading a stream, accepting HTTP
+connections and writing media data to clients.
+
+The design tries to follow a Publisher-Subscriber-Pattern. The PublisherContext
+struct contains buffers of read media data and the list of clients. Clients
+themselves contain a buffer of media data that still has to be sent to them.
+
+The reading thread takes care of segmenting the stream into independent chunks
+of data and pushing it to the PublisherContext, which publishes the new Segment
+to connected clients. This publishing only adds this Segment to the client's
+buffer.
+
+The writing thread does the actual writing of data over the network. It checks
+each client's state and if there is data available that can be written to that
+client it is sent.
+
+The accept thread accepts new clients over HTTP and if not all client slots are
+in use, writes the stream-header and adds the client to the PublisherContext.
+
+A Segment is only stored in memory once and is refcounted. Buffers in the
+PublisherContext and clients contain pointers to Segments.
+
+Buffers are implemented using AVFifoBuffer.
+
+Client states are protected by pthread-mutex-locks, making it possible to run
+multiple write threads.
+
+HTTPD-API
+-
+
+To be independent of a specific http server implementation, an interface is
+provided that an http server implementation has to provide. At the time of
+writing an implementation using the libavformat http server is provided.
+
+The HTTPDInterface struct takes the following function pointers:
+
+struct HTTPDInterface {
+int (*init)  (void **server, struct HTTPDConfig config);
+int (*free)  (void *server);
+int (*accept)(void *server, struct HTTPClient **client, int reply_code);
+int (*write) (void *server, struct HTTPClient *client, const unsigned char 
*buf, int size);
+int (*read)  (void *server, struct HTTPClient *client, unsigned char *buf, 
int size);
+void (*close)(void *server, struct HTTPClient *client);
+void (*shutdown)(void *server);
+};
+
+
+Usage
+-
+
+Currently streams can be supplied as a stream through stdin or any ffmpeg-
+compatible URI, e.g. files or network locations. Examples:
+
+cat somefile.mkv | ./ffserver
+
+./ffserver somefile.mkv
+
+./ffserver http://somehost/somefile.mkv
+
+This will start reading the file and open port 8080 for HTTP client 
connections.
+The stream is read in real time from whatever resource it is retrieved.
+Currently a maximum of 16 clients is implemented.
+
+The server responds to any GET request with the mediastream. Any other request
+is answered with a HTTP 400 error.
+If the maximum number of clients is reached the server responds with a 503 HTTP
+error if a new client wants to connect.
+
+Once the stream ends the server will write all the remaining data to all
+connected clients before closing the connections and exiting.
-- 
2.16.2

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


[FFmpeg-devel] [PATCH 1/5] ffserver: Implement refcounted segments.

2018-05-12 Thread Stephan Holljes
Signed-off-by: Stephan Holljes 
---
 segment.c | 168 ++
 segment.h | 114 ++
 2 files changed, 282 insertions(+)
 create mode 100644 segment.c
 create mode 100644 segment.h

diff --git a/segment.c b/segment.c
new file mode 100644
index 000..c40d1ad
--- /dev/null
+++ b/segment.c
@@ -0,0 +1,168 @@
+/*
+ * 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 "segment.h"
+#include 
+
+#include 
+#include 
+
+
+void segment_save(struct Segment *seg, const char *filename)
+{
+AVFormatContext *ofmt_ctx = NULL;
+int ret;
+
+avformat_alloc_output_context2(_ctx, NULL, NULL, filename);
+if (!ofmt_ctx) {
+av_log(NULL, AV_LOG_ERROR, "Could not allocate output to save Segment 
%d.\n", seg->id);
+return;
+}
+
+if ((ret = avio_open(_ctx->pb, filename, AVIO_FLAG_WRITE)) < 0) {
+av_log(ofmt_ctx, AV_LOG_ERROR,
+"Could not open output io context to save Segment %d: %s.\n", 
seg->id, av_err2str(ret));
+return;
+}
+
+avio_write(ofmt_ctx->pb, seg->buf, seg->size);
+avio_flush(ofmt_ctx->pb);
+avio_close(ofmt_ctx->pb);
+avformat_free_context(ofmt_ctx);
+}
+
+void segment_free(struct Segment *seg)
+{
+av_log(NULL, AV_LOG_DEBUG, "Freeing segment\n");
+avformat_free_context(seg->fmt_ctx);
+av_free(seg->io_ctx->buffer);
+av_free(seg->io_ctx);
+av_free(seg->buf);
+av_free(seg->ts);
+av_free(seg);
+}
+
+void segment_ref(struct Segment *seg)
+{
+pthread_mutex_lock(>nb_read_lock);
+seg->nb_read++;
+av_log(NULL, AV_LOG_DEBUG, "%04d  ref Readers: %d\n", seg->id, 
seg->nb_read);
+pthread_mutex_unlock(>nb_read_lock);
+}
+
+void segment_unref(struct Segment *seg)
+{
+pthread_mutex_lock(>nb_read_lock);
+seg->nb_read--;
+pthread_mutex_unlock(>nb_read_lock);
+av_log(NULL, AV_LOG_DEBUG, "%04d unref Readers: %d\n", seg->id, 
seg->nb_read);
+if (seg->nb_read == 0) {
+segment_free(seg);
+}
+}
+
+int segment_write(void *opaque, unsigned char *buf, int buf_size)
+{
+struct Segment *seg = (struct Segment*) opaque;
+seg->size += buf_size;
+seg->buf = (unsigned char*) av_realloc(seg->buf, seg->size);
+memcpy(seg->buf + seg->size - buf_size, buf, buf_size);
+return buf_size;
+}
+
+int segment_read(void *opaque, unsigned char *buf, int buf_size)
+{
+struct SegmentReadInfo *info = (struct SegmentReadInfo*) opaque;
+buf_size = buf_size < info->left ? buf_size : info->left;
+
+/* copy internal buffer data to buf */
+memcpy(buf, info->buf, buf_size);
+info->buf  += buf_size;
+info->left -= buf_size;
+return buf_size ? buf_size : AVERROR_EOF;
+}
+
+
+void segment_close(struct Segment *seg)
+{
+av_write_trailer(seg->fmt_ctx);
+}
+
+void segment_init(struct Segment **seg_p, AVFormatContext *fmt)
+{
+int ret;
+int i;
+AVStream *in_stream, *out_stream;
+struct Segment *seg = (struct Segment*) av_malloc(sizeof(struct Segment));
+
+seg->ifmt = av_find_input_format("matroska");
+seg->fmt_ctx = NULL;
+seg->nb_read = 0;
+seg->size = 0;
+seg->ts = NULL;
+seg->ts_len = 0;
+seg->buf = NULL;
+seg->avio_buffer = (unsigned char*) av_malloc(AV_BUFSIZE);
+pthread_mutex_init(>nb_read_lock, NULL);
+seg->io_ctx = avio_alloc_context(seg->avio_buffer, AV_BUFSIZE, 1, seg, 
NULL, _write, NULL);
+seg->io_ctx->seekable = 0;
+avformat_alloc_output_context2(>fmt_ctx, NULL, "matroska", NULL);
+if ((ret = av_opt_set_int(seg->fmt_ctx, "flush_packets", 1, 
AV_OPT_SEARCH_CHILDREN)) < 0) {
+av_log(seg->fmt_ctx, AV_LOG_WARNING, "Could not set flush_packets!\n");
+}
+
+seg->fmt_ctx->flags |= AVFMT_FLAG_GENPTS;
+seg->fmt_ctx->oformat->flags |= AVFMT_NOFILE | AVFMT_FLAG_AUTO_BSF;
+
+av_log(seg->fmt_ctx, AV_LOG_DEBUG, "Initializing segment\n");
+
+for (i = 0; i < fmt->nb_streams; i++) {
+in_stream = fmt->streams[i];
+out_stream = avformat_new_stream(seg->fmt_ctx, NULL);
+if (!out_stream) {
+av_log(seg->fmt_ctx, AV_LOG_WARNING, "Failed allocating output 
stream\n");
+continue;
+

[FFmpeg-devel] [GSoC] Qualification task (?) FFserver, further implementation

2018-05-12 Thread Stephan Holljes
This version contains some fixes including:
  - fix compiler warning
  - initial fixing of muxing non-matroska files
  - clarify documentation
unrelated but helpful for testing:
  - add address-sanitation to compilation

As mentioned, using non-matroska files does not properly work as of now.
Muxing to in-memory matroska yields:

> [matroska @ 0x61b1ea80] Starting new cluster due to timestamp

Playback of the stream in mpv yields:

> Invalid audio PTS: 0.023220 -> 1.024000

Pointers for further investigation are appreciated! I'll next read more
doc/examples and possibly ffmpeg.c to understand more about timestamps.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/2] flvenc: Fix sequence header update timestamps

2018-05-12 Thread Michael Niedermayer
On Thu, May 10, 2018 at 06:40:08PM -0700, Alex Converse wrote:
> From: Alex Converse 
> 
> ---
>  libavformat/flvenc.c | 9 -
>  1 file changed, 4 insertions(+), 5 deletions(-)

LGTM

thx

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I know you won't believe me, but the highest form of Human Excellence is
to question oneself and others. -- Socrates


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/2] flvenc: Factorize timestamp writing

2018-05-12 Thread Michael Niedermayer
On Thu, May 10, 2018 at 06:40:07PM -0700, Alex Converse wrote:
> From: Alex Converse 
> 
> The code is trivial but the semantics in the spec are ambiguous. This
> should help keep parts of the muxer interpreting them consistently.
> ---
>  libavformat/flvenc.c | 12 
>  1 file changed, 8 insertions(+), 4 deletions(-)

LGTM

thx


-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The bravest are surely those who have the clearest vision
of what is before them, glory and danger alike, and yet
notwithstanding go out to meet it. -- Thucydides


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 2/5] ffserver: Implement publisher

2018-05-12 Thread Stephan Holljes
Signed-off-by: Stephan Holljes 
---
 publisher.c | 308 
 publisher.h | 170 +
 2 files changed, 478 insertions(+)
 create mode 100644 publisher.c
 create mode 100644 publisher.h

diff --git a/publisher.c b/publisher.c
new file mode 100644
index 000..1123056
--- /dev/null
+++ b/publisher.c
@@ -0,0 +1,308 @@
+/*
+ * 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 "publisher.h"
+#include "segment.h"
+#include 
+
+void client_log(struct Client *c)
+{
+av_log(NULL, AV_LOG_INFO, "State: ");
+switch(c->state) {
+case FREE:
+av_log(NULL, AV_LOG_INFO, "FREE\n");
+break;
+case RESERVED:
+av_log(NULL, AV_LOG_INFO, "RESERVED\n");
+break;
+case WAIT:
+av_log(NULL, AV_LOG_INFO, "WAIT\n");
+break;
+case WRITABLE:
+av_log(NULL, AV_LOG_INFO, "WRITABLE\n");
+break;
+case BUSY:
+av_log(NULL, AV_LOG_INFO, "BUSY\n");
+break;
+case BUFFER_FULL:
+av_log(NULL, AV_LOG_INFO, "BUFFER_FULL\n");
+break;
+default:
+av_log(NULL, AV_LOG_INFO, "UNKOWN\n");
+break;
+}
+}
+
+void client_disconnect(struct Client *c, int write_trailer)
+{
+struct Segment *seg;
+client_set_state(c, BUSY);
+if (write_trailer)
+av_write_trailer(c->ofmt_ctx);
+c->ffinfo->httpd->close(c->ffinfo->server, c->ffinfo->client);
+av_free(c->ofmt_ctx->pb->buffer);
+avio_context_free(>ofmt_ctx->pb);
+avformat_free_context(c->ofmt_ctx);
+av_free(c->ffinfo);
+c->ofmt_ctx = NULL;
+c->ffinfo = NULL;
+pthread_mutex_lock(>buffer_lock);
+while(av_fifo_size(c->buffer)) {
+av_fifo_generic_read(c->buffer, , sizeof(struct Segment*), NULL);
+segment_unref(seg);
+}
+pthread_mutex_unlock(>buffer_lock);
+c->current_segment_id = -1;
+client_set_state(c, FREE);
+}
+
+void client_set_state(struct Client *c, enum State state)
+{
+pthread_mutex_lock(>state_lock);
+c->state = state;
+pthread_mutex_unlock(>state_lock);
+}
+
+void client_push_segment(struct Client *c, struct Segment *seg)
+{
+pthread_mutex_lock(>buffer_lock);
+if (av_fifo_space(c->buffer) == 0) {
+av_log(NULL, AV_LOG_WARNING, "Client buffer full, dropping 
Segment.\n");
+client_set_state(c, BUFFER_FULL);
+pthread_mutex_unlock(>buffer_lock);
+return;
+}
+segment_ref(seg);
+av_fifo_generic_write(c->buffer, , sizeof(struct Segment*), NULL);
+pthread_mutex_unlock(>buffer_lock);
+client_set_state(c, WRITABLE);
+}
+
+void publisher_init(struct PublisherContext **pub)
+{
+int i;
+struct PublisherContext *pc = (struct PublisherContext*) 
av_malloc(sizeof(struct PublisherContext));
+pc->nb_threads = 8;
+pc->current_segment_id = -1;
+pc->shutdown = 0;
+pc->buffer = av_fifo_alloc_array(sizeof(struct Segment), MAX_SEGMENTS);
+pc->fs_buffer = av_fifo_alloc_array(sizeof(struct Segment), MAX_SEGMENTS);
+pthread_mutex_init(>buffer_lock, NULL);
+pthread_mutex_init(>fs_buffer_lock, NULL);
+for (i = 0; i < MAX_CLIENTS; i++) {
+struct Client *c = >clients[i];
+c->buffer = av_fifo_alloc_array(sizeof(struct Segment), MAX_SEGMENTS);
+c->ofmt_ctx = NULL;
+c->ffinfo = NULL;
+c->id = i;
+c->current_segment_id = -1;
+pthread_mutex_init(>state_lock, NULL);
+pthread_mutex_init(>buffer_lock, NULL);
+client_set_state(c, FREE);
+}
+*pub = pc;
+}
+
+void publisher_push_segment(struct PublisherContext *pub, struct Segment *seg)
+{
+struct Segment *drop;
+pthread_mutex_lock(>buffer_lock);
+pthread_mutex_lock(>fs_buffer_lock);
+av_fifo_generic_write(pub->buffer, , sizeof(struct Segment*), NULL);
+segment_ref(seg);
+if (av_fifo_size(pub->fs_buffer) >= BUFFER_SEGMENTS * sizeof(struct 
Segment*)) {
+av_fifo_generic_read(pub->fs_buffer, , sizeof(struct Segment*), 
NULL);
+segment_unref(drop);
+}
+av_fifo_generic_write(pub->fs_buffer, , sizeof(struct Segment*), NULL);
+pthread_mutex_unlock(>buffer_lock);
+pthread_mutex_unlock(>fs_buffer_lock);
+

[FFmpeg-devel] [PATCH 4/5] ffserver: Implement ffserver and add Makefile

2018-05-12 Thread Stephan Holljes
Signed-off-by: Stephan Holljes 
---
 Makefile   |  19 +++
 ffserver.c | 520 +
 2 files changed, 539 insertions(+)
 create mode 100644 Makefile
 create mode 100644 ffserver.c

diff --git a/Makefile b/Makefile
new file mode 100644
index 000..fbecdeb
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,19 @@
+all: ffserver
+LAV_FLAGS = $(shell pkg-config --libs --cflags libavformat libavcodec 
libavutil)
+CFLAGS=-fsanitize=address -fsanitize=undefined
+# LAV_FLAGS = -L/usr/local/lib -lavcodec -lavformat -lavutil
+
+ffserver: segment.o publisher.o lavfhttpd.o ffserver.c
+   cc -g -Wall $(CFLAGS) $(LAV_FLAGS) -lpthread -o ffserver segment.o 
publisher.o lavfhttpd.o ffserver.c
+
+segment.o: segment.c segment.h
+   cc -g -Wall $(CFLAGS) $(LAV_FLAGS) -lpthread -c segment.c
+
+publisher.o: publisher.c publisher.h
+   cc -g -Wall $(CFLAGS) $(LAV_FLAGS) -lpthread -c publisher.c
+
+lavfhttpd.o: lavfhttpd.c httpd.h
+   cc -g -Wall $(CFLAGS) $(LAV_FLAGS) -lpthread -c lavfhttpd.c
+
+clean:
+   rm -f *.o ffserver
diff --git a/ffserver.c b/ffserver.c
new file mode 100644
index 000..39e1c32
--- /dev/null
+++ b/ffserver.c
@@ -0,0 +1,520 @@
+/*
+ * Copyright (c) 2018 Stephan Holljes
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * multimedia server based on the FFmpeg libraries
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "segment.h"
+#include "publisher.h"
+#include "httpd.h"
+
+#define BUFFER_SECS 30
+#define LISTEN_TIMEOUT_MSEC 1000
+
+struct ReadInfo {
+struct PublisherContext *pub;
+AVFormatContext *ifmt_ctx;
+char *in_filename;
+};
+
+struct WriteInfo {
+struct PublisherContext *pub;
+int thread_id;
+};
+
+struct AcceptInfo {
+struct PublisherContext *pub;
+struct HTTPDInterface *httpd;
+AVFormatContext *ifmt_ctx;
+};
+
+
+int ffserver_write(void *opaque, unsigned char *buf, int buf_size)
+{
+struct FFServerInfo *info = (struct FFServerInfo*) opaque;
+return info->httpd->write(info->server, info->client, buf, buf_size);
+}
+
+
+void *read_thread(void *arg)
+{
+struct ReadInfo *info = (struct ReadInfo*) arg;
+AVFormatContext *ifmt_ctx = info->ifmt_ctx;
+int ret, i;
+int video_idx = -1;
+int id = 0;
+int64_t pts, now, start;
+int64_t *ts;
+struct Segment *seg = NULL;
+AVPacket pkt;
+AVStream *in_stream;
+AVRational tb;
+tb.num = 1;
+tb.den = AV_TIME_BASE;
+AVStream *stream;
+AVCodecParameters *params;
+enum AVMediaType type;
+
+if ((ret = avformat_find_stream_info(ifmt_ctx, NULL)) < 0) {
+av_log(ifmt_ctx, AV_LOG_ERROR, "Could not get input stream info.\n");
+goto end;
+}
+
+av_log(ifmt_ctx, AV_LOG_INFO, "Finding video stream.\n");
+for (i = 0; i < ifmt_ctx->nb_streams; i++) {
+av_log(ifmt_ctx, AV_LOG_DEBUG, "Checking stream %d\n", i);
+stream = ifmt_ctx->streams[i];
+params = stream->codecpar;
+type = params->codec_type;
+if (type == AVMEDIA_TYPE_VIDEO) {
+video_idx = i;
+break;
+}
+}
+if (video_idx == -1) {
+av_log(ifmt_ctx, AV_LOG_ERROR, "No video stream found.\n");
+goto end;
+}
+
+
+// All information needed to start segmenting the file is gathered now.
+// start BUFFER_SECS seconds "in the past" to "catch up" to real-time. Has 
no effect on streamed sources.
+start = av_gettime_relative() - BUFFER_SECS * AV_TIME_BASE;
+
+// segmenting main-loop
+
+for (;;) {
+ret = av_read_frame(ifmt_ctx, );
+if (ret < 0)
+break;
+
+in_stream = ifmt_ctx->streams[pkt.stream_index];
+if (pkt.pts == AV_NOPTS_VALUE) {
+pkt.pts = 0;
+}
+if (pkt.dts == AV_NOPTS_VALUE) {
+pkt.dts = 0;
+}
+
+pkt.pts = av_rescale_q_rnd(pkt.pts, in_stream->time_base, tb, 
AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
+pkt.dts = av_rescale_q_rnd(pkt.dts, in_stream->time_base, tb, 
AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
+pkt.duration = 

Re: [FFmpeg-devel] [PATCH 4/5] ffserver: Implement ffserver and add Makefile

2018-05-12 Thread Stephan Holljes
On Fri, May 11, 2018 at 3:05 PM, Stephan Holljes
 wrote:
> On Fri, May 11, 2018 at 2:49 PM, Moritz Barsnick  wrote:
>> On Thu, May 10, 2018 at 17:41:25 +0200, Stephan Holljes wrote:
>>> +ffserver: segment.o publisher.o lavfhttpd.o ffserver.c
>>> + cc -g -Wall $(LAV_FLAGS) -lpthread -o ffserver segment.o publisher.o 
>>> lavfhttpd.o ffserver.c
>> ^ $(CC) $(CFLAGS) to be more generic and allow overriding.
>>
>> The LDFLAGS "$(LAV_FLAGS) -lpthread" need to be at the end of the
>> command for my compile/link chains to work. *shrug*
>>
>>> +clean:
>>> + rm *.o ffserver
>>
>> Make this "rm -f" to silence warnings about non-existant files.
>
> Ok
>
>>
>>> diff --git a/ffserver.c b/ffserver.c
>>
>> It may be me, but the whole thing doesn't work for me.
>>
>> With any MP4 file, I get:
>>
>> [AVIOContext @ 0xa3c3b40] {
>> "free": 16,
>> "reserved": 0,
>> "wait": 0,
>> "writable": 0,
>> "busy": 0,
>> "buffer_full": 0,
>> "current_read": -1,
>> "newest_write": 0,
>> "oldest_write": -1
>> }
>> [mov,mp4,m4a,3gp,3g2,mj2 @ 0xa394580] Finding video stream.
>> [matroska @ 0xb4319700] Tag mp4a incompatible with output codec id '86018' 
>> ([255][0][0][0])
>> [matroska @ 0xb4319700] Error occured while writing header: Invalid data 
>> found when processing input
>> Segmentation fault
>>
>> gdb, if it's of interest:
>> Program received signal SIGSEGV, Segmentation fault.
>> [Switching to Thread 0xb5717b90 (LWP 26045)]
>> 0x08068d6d in compute_muxer_pkt_fields (s=0xb4c19240, st=0xfffe, 
>> pkt=0x) at src/libavformat/mux.c:640
>> 640 st->internal->priv_pts->val = pkt->dts;
>>
>> (ffmpeg of the same version as the libs has no issue processing the
>> same file to matroska.)
>>
>> Using an MKV as input, it launches as such:
>>
>> [AVIOContext @ 0xb441e5c0] {
>> "free": 16,
>> "reserved": 0,
>> "wait": 0,
>> "writable": 0,
>> "busy": 0,
>> "buffer_full": 0,
>> "current_read": -1,
>> "newest_write": 0,
>> "oldest_write": -1
>> }
>> [matroska,webm @ 0xa166580] Finding video stream.
>> [AVIOContext @ 0xb441e5c0] Shutting down http server.
>>
>> "Shutting down"??? And I can't connect and play.
>>
>> It may just be me though. Hope this helps anyway.
>>
>> Moritz
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> Hmm that *is* a problem. Maybe I should have used more than one file
> for testing. I just tested another file and it also only worked
> properly on second try. This time there was a condition I could not
> reproduce the last few days:
>>[matroska @ 0x55eb77169040] Application provided invalid, non monotonically 
>>increasing dts to muxer in stream 0: 18894 >= 18894
> I already mentioned that I'm not too sure about way I handle
> timestamps. (Currently each segment has a separate dynamic array
> filled with dts and pts as int64_t taken from the demuxer during
> reading.)
>
> I also tested an mp4 file and I can reproduce the error message. I'm
> guessing it's "only" a metadata thing, but I know ffmpeg can mux this
> without problems, so I'll investigate how to do that.
>
> Thanks for the time, I will assemble more files for testing!

I figured out how to prevent the fatal error during muxing by looking
at doc/examples/remuxing.c.
In the process I came to the conclusion that the incorrect timestamps
written to a client most likely are a race condition, since after
testing with a single thread and after tightening locking this does no
longer occur. The first hint for this was also given by compiling with
address sanitation. However, there is still something wrong with the
timestamps. Remuxing from an mp4 file to in-memory matroska segments
yields:

> [matroska @ 0x61b1ea80] Starting new cluster due to timestamp

many times in the output. The stream produced can also not properly be
played, mpv outputs:

> Invalid audio PTS: 0.023220 -> 1.024000

This does not happen with matroska files that are read.
I will send an updated version including the fixes from the other emails.

Maybe someone can point me to some resources about timestamps and how
to deal with them? Like I mentioned a few times, I'm really not sure
how to do this properly. In the meantime I'll read more doc/example
code and probably ffmpeg.c as well.

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


Re: [FFmpeg-devel] [PATCH 4/4] lavc/cbs_h2645: fix no slice data trigger the assert.

2018-05-12 Thread Mark Thompson
On 11/05/18 16:38, James Almer wrote:
> On 5/11/2018 7:10 AM, Mark Thompson wrote:
>> On 11/05/18 06:11, Jun Zhao wrote:
>>> when the NALU data with zero, just give a warning.
>>>
>>> Fixes ticket #7200
>>>
>>> Signed-off-by: Jun Zhao 
>>> ---
>>>  libavcodec/cbs_h2645.c | 6 +-
>>>  1 file changed, 5 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
>>> index ab33cdb..08b060c 100644
>>> --- a/libavcodec/cbs_h2645.c
>>> +++ b/libavcodec/cbs_h2645.c
>>> @@ -521,7 +521,11 @@ static int 
>>> cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx,
>>>  // Remove trailing zeroes.
>>>  while (size > 0 && nal->data[size - 1] == 0)
>>>  --size;
>>> -av_assert0(size > 0);
>>> +if (!size) {
>>> +av_log(ctx->log_ctx, AV_LOG_WARNING, "No slice data - that was 
>>> just the header. "
>>> +   "Probably invalid unaligned padding on non-final NAL 
>>> unit.\n");
>>> +continue;
>>> +}
>>>  
>>>  data = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE);
>>>  if (!data)
>>>
>>
>> What do we actually want the result to be here?
>>
>> On IRC, James suggested:
>>
>>> diff --git a/libavcodec/h2645_parse.c b/libavcodec/h2645_parse.c
>>> index dbf2435677..d436d65f48 100644
>>> --- a/libavcodec/h2645_parse.c
>>> +++ b/libavcodec/h2645_parse.c
>>> @@ -371,7 +371,7 @@ int ff_h2645_packet_split(H2645Packet *pkt, const 
>>> uint8_t *buf, int length,
>>>  ret = hevc_parse_nal_header(nal, logctx);
>>>  else
>>>  ret = h264_parse_nal_header(nal, logctx);
>>> -if (ret <= 0 || nal->size <= 0) {
>>> +if (ret <= 0 || nal->size <= 0 || nal->size_bits <= 0) {
>>>  if (ret < 0) {
>>>  av_log(logctx, AV_LOG_ERROR, "Invalid NAL unit %d, 
>>> skipping.\n",
>>> nal->type);
>>
>> which removes it before it gets to the CBS code.
>>
>> Another thing we could do is:
>>
>>> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
>>> index ab33cdb69b..46cd887cdd 100644
>>> --- a/libavcodec/cbs_h2645.c
>>> +++ b/libavcodec/cbs_h2645.c
>>> @@ -519,7 +519,7 @@ static int 
>>> cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx,
>>>  uint8_t *data;
>>>  
>>>  // Remove trailing zeroes.
>>> -while (size > 0 && nal->data[size - 1] == 0)
>>> +while (size > 1 && nal->data[size - 1] == 0)
>>>  --size;
>>>  av_assert0(size > 0);
>>>  
>>
>> which would make it parse as an empty NAL unit of type 0 (unspecified), and 
>> therefore pass through into the output stream in the h264_metadata case.
>>
>> So, what do you think?  Do you know what made your sample stream?
>>
>> - Mark
> 
> Taking into account the analysis by mkver in the trac ticket, where he
> found out the bitstream contains "00 00 00 01 00 00 00 01" with the
> second start code being a real valid NAL, i think this should definitely
> be fixed in h2645_parse. No reason to propagate a non existent NAL like
> this.
> We should either use my fix, or another that actually prevents nal->size
> from inexplicably becoming 1 in this scenario.

I was applying the standard precisely, which I think ends up with the 
interpretation:

 00 00 00 01 09 f0 00 00 00 01 00 00 00 01 41 e2 02 56
|  ||  |  |  ||  ||  |
 ^^ zero_byte  start code
 start code^^ NAL unit header
 ^^ NAL unit header    start code
^^ NAL unit content (AUD)  ^^ NAL unit header
   ^^ trailing zeroes ^^^... NAL unit content (slice)

The middle NAL unit has type 0 (unspecified application use) and no content.  I 
admit that's probably not what was intended here, but currently we do preserve 
unspecified NAL units and it's not clear that type 0 should necessarily be 
treated differently to 24-31.

This would be a pretty absurd use, though, so I don't think it really matters.  
Given that, I'm fine with any of the possible answers above.

- Mark


(Another data point: the reference decoder segfaults when given the sample 
stream.)
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavc/amfenc: moving amf common code (library and context) to lavu/hwcontext_amf from amfenc to be reused in other amf components

2018-05-12 Thread Mark Thompson
On 12/05/18 09:48, Alexander Kravchenko wrote:
> This patch moves AMF common parts from amfenc to hwcontext_amf.
> Now av_hwdevice_ctx API is used for AMF context creation/destroying.
> This patch does not change component behaviour.
> it contains only restructurization for further patches with new amf components
> 
> ---
> Sending updated patch based on Mark's review
> 1) simplificated library loading/unloading logic
> 2) minor fixes
> 
> 
>  libavcodec/amfenc.c| 247 +---
>  libavcodec/amfenc.h|  27 +
>  libavutil/Makefile |   2 +
>  libavutil/hwcontext.c  |   4 +
>  libavutil/hwcontext.h  |   1 +
>  libavutil/hwcontext_amf.c  | 252 
> +
>  libavutil/hwcontext_amf.h  |  43 +++
>  libavutil/hwcontext_internal.h |   1 +
>  8 files changed, 338 insertions(+), 239 deletions(-)
>  create mode 100644 libavutil/hwcontext_amf.c
>  create mode 100644 libavutil/hwcontext_amf.h
> 
> diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
> index 384d8efc92..4c907ca3bc 100644
> --- a/libavcodec/amfenc.c
> +++ b/libavcodec/amfenc.c
> @@ -21,13 +21,7 @@
>  #include "libavutil/avassert.h"
>  #include "libavutil/imgutils.h"
>  #include "libavutil/hwcontext.h"
> -#if CONFIG_D3D11VA
> -#include "libavutil/hwcontext_d3d11va.h"
> -#endif
> -#if CONFIG_DXVA2
> -#define COBJMACROS
> -#include "libavutil/hwcontext_dxva2.h"
> -#endif
> +
>  #include "libavutil/mem.h"
>  #include "libavutil/pixdesc.h"
>  #include "libavutil/time.h"
> @@ -35,14 +29,12 @@
>  #include "amfenc.h"
>  #include "internal.h"
>  
> -#if CONFIG_D3D11VA
> -#include 
> +#if CONFIG_DXVA2
> +#include 
>  #endif
>  
> -#ifdef _WIN32
> -#include "compat/w32dlfcn.h"
> -#else
> -#include 
> +#if CONFIG_D3D11VA
> +#include 
>  #endif
>  
>  #define FFMPEG_AMF_WRITER_ID L"ffmpeg_amf"
> @@ -88,34 +80,18 @@ static enum AMF_SURFACE_FORMAT amf_av_to_amf_format(enum 
> AVPixelFormat fmt)
>  return AMF_SURFACE_UNKNOWN;
>  }
>  
> -static void AMF_CDECL_CALL AMFTraceWriter_Write(AMFTraceWriter *pThis,
> -const wchar_t *scope, const wchar_t *message)
> -{
> -AmfTraceWriter *tracer = (AmfTraceWriter*)pThis;
> -av_log(tracer->avctx, AV_LOG_DEBUG, "%ls: %ls", scope, message); // \n 
> is provided from AMF
> -}
> -
> -static void AMF_CDECL_CALL AMFTraceWriter_Flush(AMFTraceWriter *pThis)
> -{
> -}
>  
> -static AMFTraceWriterVtbl tracer_vtbl =
> -{
> -.Write = AMFTraceWriter_Write,
> -.Flush = AMFTraceWriter_Flush,
> -};
> -
> -static int amf_load_library(AVCodecContext *avctx)
> +static int amf_init_context(AVCodecContext *avctx)
>  {
> -AmfContext*ctx = avctx->priv_data;
> -AMFInit_Fn init_fun;
> -AMFQueryVersion_Fn version_fun;
> -AMF_RESULT res;
> +AmfContext *ctx = avctx->priv_data;
> +AVAMFDeviceContext *amf_ctx;
> +int ret;
>  
>  ctx->delayed_frame = av_frame_alloc();
>  if (!ctx->delayed_frame) {
>  return AVERROR(ENOMEM);
>  }
> +

Stray change?

>  // hardcoded to current HW queue size - will realloc in 
> timestamp_queue_enqueue() if too small
>  ctx->timestamp_list = av_fifo_alloc((avctx->max_b_frames + 16) * 
> sizeof(int64_t));
>  if (!ctx->timestamp_list) {
> @@ -123,119 +99,9 @@ static int amf_load_library(AVCodecContext *avctx)
>  }
>  ctx->dts_delay = 0;
>  
> -
> -ctx->library = dlopen(AMF_DLL_NAMEA, RTLD_NOW | RTLD_LOCAL);
> -AMF_RETURN_IF_FALSE(ctx, ctx->library != NULL,
> -AVERROR_UNKNOWN, "DLL %s failed to open\n", AMF_DLL_NAMEA);
> -
> -init_fun = (AMFInit_Fn)dlsym(ctx->library, AMF_INIT_FUNCTION_NAME);
> -AMF_RETURN_IF_FALSE(ctx, init_fun != NULL, AVERROR_UNKNOWN, "DLL %s 
> failed to find function %s\n", AMF_DLL_NAMEA, AMF_INIT_FUNCTION_NAME);
> -
> -version_fun = (AMFQueryVersion_Fn)dlsym(ctx->library, 
> AMF_QUERY_VERSION_FUNCTION_NAME);
> -AMF_RETURN_IF_FALSE(ctx, version_fun != NULL, AVERROR_UNKNOWN, "DLL %s 
> failed to find function %s\n", AMF_DLL_NAMEA, 
> AMF_QUERY_VERSION_FUNCTION_NAME);
> -
> -res = version_fun(>version);
> -AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with 
> error %d\n", AMF_QUERY_VERSION_FUNCTION_NAME, res);
> -res = init_fun(AMF_FULL_VERSION, >factory);
> -AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with 
> error %d\n", AMF_INIT_FUNCTION_NAME, res);
> -res = ctx->factory->pVtbl->GetTrace(ctx->factory, >trace);
> -AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetTrace() 
> failed with error %d\n", res);
> -res = ctx->factory->pVtbl->GetDebug(ctx->factory, >debug);
> -AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetDebug() 
> failed with error %d\n", res);
> -return 0;
> -}
> -
> -#if CONFIG_D3D11VA
> -static int amf_init_from_d3d11_device(AVCodecContext *avctx, 
> AVD3D11VADeviceContext *hwctx)
> -{
> -AmfContext *ctx = 

Re: [FFmpeg-devel] [PATCH] lavc/amfenc: moving amf common code (library and context) to lavu/hwcontext_amf from amfenc to be reused in other amf components

2018-05-12 Thread Mark Thompson
On 11/05/18 19:37, Alexander Kravchenko wrote:
> Hi Mark, 
> Thank you for your comments.
> Could you see my comments and questions bellow
> 
>> -Original Message-
>> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of 
>> Mark Thompson
>> Sent: Thursday, May 10, 2018 11:43 PM
>> To: ffmpeg-devel@ffmpeg.org
>> Subject: Re: [FFmpeg-devel] [PATCH] lavc/amfenc: moving amf common code 
>> (library and context) to lavu/hwcontext_amf from
>> amfenc to be reused in other amf components
>>
> 
>>> +static AVBufferRef *amf_library_ctx = NULL;
>>
>> Global mutable state in libraries is strongly discouraged.  Just loading it 
>> again should be fine?
>>
> 
> Yes, loading it again could be fine.
> I wanted to prevent additional call of library loading and trace 
> initializations every time amf_device context is created.
> User can create many instances of encoder in one process. 
> Storing amf_library_ctx allows to detect when cleanup functions can be called 
> (UnregisterWriter...). Of course we can never call dclose and keep library 
> loaded all time.
> What is your opinion?

Is there any later benefit to reusing the pointer, or is it just saving on the 
load/initialisation code?  If there isn't a strong reason to do so I would 
avoid storing it.  (Note that doing so would require more machinery to guard 
against data races as well.)

>>> +
>>> +#include "frame.h"
>>> +#include "AMF/core/Context.h"
>>> +#include "AMF/core/Factory.h"
>>> +
>>> +
>>> +/**
>>> + * This struct is allocated as AVHWDeviceContext.hwctx  */ typedef
>>> +struct AVAMFDeviceContext {
>>> +AMFContext *context;
>>> +AMFFactory *factory;
>>
>> Do you actually need both of these?  It feels like you should be able to 
>> derive the creating factory (/ library instance) from the context.
>>
> 
> AMFContext does not have pointer to AMFFactory. Now AMFFactory -> 
> CreateComponent is used in encoder initialization.
> May be AMFFactory is too wide interface on this level. Pointer to function 
> like CreateComponent can be published in AVAMFDeviceContext instead of 
> factory pointer.
> or did you mean something different?

Since this is ending up as immutable public API, we should be avoiding adding 
anything which isn't absolutely needed.  If they are both needed then that's 
fine - I don't think including the CreateComponent pointer instead would be any 
simpler.

> I have another question about publish amf library level options (Trace level, 
> trace writers...). This could be in another patch if we decide this option is 
> possible.
> What is the best way to add such option? Can command line options be used to 
> configure library? Or somehow publish this API?

Maybe use the opts dict passed to av_hwdevice_ctx_create()?  (They're 
accessible in the ffmpeg utility via -init_hw_device.)

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


[FFmpeg-devel] [PATCH 2/2] libavfilter/vf_nlmeans: add amount parameter

2018-05-12 Thread Paul B Mahol
For better control of denoising.

Signed-off-by: Paul B Mahol 
---
 doc/filters.texi | 4 
 libavfilter/vf_nlmeans.c | 5 -
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index d77c67eb10..60ce18298b 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -11420,6 +11420,10 @@ Set research size.
 Same as @option{r} but for chroma planes.
 
 The default value is @var{0} and means automatic.
+
+@item a
+Set denoising amount. Lower values reduces blurring.
+Default value is @var{1.0} and means full denoising.
 @end table
 
 @section nnedi
diff --git a/libavfilter/vf_nlmeans.c b/libavfilter/vf_nlmeans.c
index 6c9c9d312d..ac6380bb83 100644
--- a/libavfilter/vf_nlmeans.c
+++ b/libavfilter/vf_nlmeans.c
@@ -53,6 +53,7 @@ typedef struct NLMeansContext {
 int chroma_w, chroma_h;
 double pdiff_scale; // invert of the filtering 
parameter (sigma*10) squared
 double sigma;   // denoising strength
+double amount;  // denoising amount
 int patch_size,patch_hsize; // patch size and half size
 int patch_size_uv, patch_hsize_uv;  // patch size and half size 
for chroma planes
 int research_size,research_hsize;   // research size and half size
@@ -77,6 +78,7 @@ static const AVOption nlmeans_options[] = {
 { "pc", "patch size for chroma planes", OFFSET(patch_size_uv), 
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 99, FLAGS },
 { "r",  "research window",   OFFSET(research_size),
AV_OPT_TYPE_INT, { .i64 = 7*2+1 }, 0, 99, FLAGS },
 { "rc", "research window for chroma planes", OFFSET(research_size_uv), 
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 99, FLAGS },
+{ "a",  "denoising amount", OFFSET(amount), AV_OPT_TYPE_DOUBLE, { .dbl = 
1.0 }, 0.001, 1.0, FLAGS },
 { NULL }
 };
 
@@ -528,13 +530,14 @@ static av_cold int init(AVFilterContext *ctx)
 int i;
 NLMeansContext *s = ctx->priv;
 const double h = s->sigma * 10.;
+const double a = 1. / (s->amount * s->amount);
 
 s->pdiff_scale = 1. / (h * h);
 s->max_meaningful_diff = -log(1/255.) / s->pdiff_scale;
 s->pdiff_lut_scale = 1./s->max_meaningful_diff * WEIGHT_LUT_SIZE;
 av_assert0((s->max_meaningful_diff - 1) * s->pdiff_lut_scale < 
FF_ARRAY_ELEMS(s->weight_lut));
 for (i = 0; i < WEIGHT_LUT_SIZE; i++)
-s->weight_lut[i] = exp(-i / s->pdiff_lut_scale * s->pdiff_scale);
+s->weight_lut[i] = exp((-i / s->pdiff_lut_scale * s->pdiff_scale) * a);
 
 CHECK_ODD_FIELD(research_size,   "Luma research window");
 CHECK_ODD_FIELD(patch_size,  "Luma patch");
-- 
2.11.0

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


[FFmpeg-devel] [PATCH 1/2] avfilter/vf_nlmeans: better weighting of centered pixel

2018-05-12 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 libavfilter/vf_nlmeans.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libavfilter/vf_nlmeans.c b/libavfilter/vf_nlmeans.c
index 82e779ce85..6c9c9d312d 100644
--- a/libavfilter/vf_nlmeans.c
+++ b/libavfilter/vf_nlmeans.c
@@ -39,6 +39,7 @@
 #include "video.h"
 
 struct weighted_avg {
+float max_weight;
 float total_weight;
 float sum;
 };
@@ -403,6 +404,7 @@ static int nlmeans_slice(AVFilterContext *ctx, void *arg, 
int jobnr, int nb_jobs
 if (patch_diff_sq < s->max_meaningful_diff) {
 const unsigned weight_lut_idx = patch_diff_sq * 
s->pdiff_lut_scale;
 const float weight = s->weight_lut[weight_lut_idx]; // 
exp(-patch_diff_sq * s->pdiff_scale)
+wa[x].max_weight = FFMAX(weight, wa[x].max_weight);
 wa[x].total_weight += weight;
 wa[x].sum += weight * src[x];
 }
@@ -422,8 +424,10 @@ static void weight_averages(uint8_t *dst, ptrdiff_t 
dst_linesize,
 for (y = 0; y < h; y++) {
 for (x = 0; x < w; x++) {
 // Also weight the centered pixel
-wa[x].total_weight += 1.f;
-wa[x].sum += 1.f * src[x];
+if (!isnormal(wa[x].max_weight))
+wa[x].max_weight = 1.f;
+wa[x].total_weight += wa[x].max_weight;
+wa[x].sum += src[x] * wa[x].max_weight;
 dst[x] = av_clip_uint8(wa[x].sum / wa[x].total_weight);
 }
 dst += dst_linesize;
-- 
2.11.0

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


Re: [FFmpeg-devel] [PATCH] avfilter/vf_nlmeans: add parameter to control weight of centered pixel

2018-05-12 Thread Paul B Mahol
On 5/11/18, Paul B Mahol  wrote:
> Signed-off-by: Paul B Mahol 
> ---
>  libavfilter/vf_nlmeans.c | 10 ++
>  1 file changed, 6 insertions(+), 4 deletions(-)
>

Please ignore, better patch posted.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 01/24] avcodec: add color_range to AVCodec struct

2018-05-12 Thread Rostislav Pehlivanov
On 12 May 2018 at 20:40, Paul B Mahol  wrote:

> On 5/12/18, Rostislav Pehlivanov  wrote:
> > On 1 May 2018 at 20:39, Paul B Mahol  wrote:
> >
> >> Signed-off-by: Paul B Mahol 
> >> ---
> >>  libavcodec/avcodec.h | 1 +
> >>  1 file changed, 1 insertion(+)
> >>
> >> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> >> index fb0c6fae70..3a8f69243c 100644
> >> --- a/libavcodec/avcodec.h
> >> +++ b/libavcodec/avcodec.h
> >> @@ -3433,6 +3433,7 @@ typedef struct AVCodec {
> >>  uint8_t max_lowres; ///< maximum value for
> lowres
> >> supported by the decoder
> >>  const AVClass *priv_class;  ///< AVClass for the
> private
> >> context
> >>  const AVProfile *profiles;  ///< array of recognized
> >> profiles, or NULL if unknown, array is terminated by
> {FF_PROFILE_UNKNOWN}
> >> +const enum AVColorRange *color_ranges;  ///< array of supported
> color
> >> ranges by encoder, or NULL if unknown, array is terminated by
> >> AVCOL_RANGE_UNSPECIFIED
> >>
> >>  /**
> >>   * Group name of the codec implementation.
> >> --
> >> 2.11.0
> >>
> >> ___
> >> ffmpeg-devel mailing list
> >> ffmpeg-devel@ffmpeg.org
> >> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >>
> >
> > Ping? I think we should ignore koda's remarks and go through with this.
>
> I moved to another stuff, sorry.
>
> I wait for non-power of 2 DCT/FFT.
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

Just send a v2 of this patch to move the color_range field to where it
doesn't break the ABI and it'll be good.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] doc/developer: update style guidelines to include for loops with declarations

2018-05-12 Thread Rostislav Pehlivanov
On 8 November 2017 at 21:26, Rostislav Pehlivanov 
wrote:

> Signed-off-by: Rostislav Pehlivanov 
> ---
>  doc/developer.texi | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/doc/developer.texi b/doc/developer.texi
> index a7b4f1d737..de7d887451 100644
> --- a/doc/developer.texi
> +++ b/doc/developer.texi
> @@ -132,6 +132,9 @@ designated struct initializers (@samp{struct s x = @{
> .i = 17 @};});
>  @item
>  compound literals (@samp{x = (struct s) @{ 17, 23 @};}).
>
> +@item
> +for loops with variable definition (@samp{for (int i = 0; i < 8; i++)});
> +
>  @item
>  Implementation defined behavior for signed integers is assumed to match
> the
>  expected behavior for two's complement. Non representable values in
> integer
> --
> 2.15.0.403.gc27cc4dac6
>
>
Ping.
Apparently we don't support old msvc versions, so there's nothing stopping
us from using them.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 01/24] avcodec: add color_range to AVCodec struct

2018-05-12 Thread Paul B Mahol
On 5/12/18, Rostislav Pehlivanov  wrote:
> On 1 May 2018 at 20:39, Paul B Mahol  wrote:
>
>> Signed-off-by: Paul B Mahol 
>> ---
>>  libavcodec/avcodec.h | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
>> index fb0c6fae70..3a8f69243c 100644
>> --- a/libavcodec/avcodec.h
>> +++ b/libavcodec/avcodec.h
>> @@ -3433,6 +3433,7 @@ typedef struct AVCodec {
>>  uint8_t max_lowres; ///< maximum value for lowres
>> supported by the decoder
>>  const AVClass *priv_class;  ///< AVClass for the private
>> context
>>  const AVProfile *profiles;  ///< array of recognized
>> profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN}
>> +const enum AVColorRange *color_ranges;  ///< array of supported color
>> ranges by encoder, or NULL if unknown, array is terminated by
>> AVCOL_RANGE_UNSPECIFIED
>>
>>  /**
>>   * Group name of the codec implementation.
>> --
>> 2.11.0
>>
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>
> Ping? I think we should ignore koda's remarks and go through with this.

I moved to another stuff, sorry.

I wait for non-power of 2 DCT/FFT.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 01/24] avcodec: add color_range to AVCodec struct

2018-05-12 Thread Rostislav Pehlivanov
On 1 May 2018 at 20:39, Paul B Mahol  wrote:

> Signed-off-by: Paul B Mahol 
> ---
>  libavcodec/avcodec.h | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index fb0c6fae70..3a8f69243c 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -3433,6 +3433,7 @@ typedef struct AVCodec {
>  uint8_t max_lowres; ///< maximum value for lowres
> supported by the decoder
>  const AVClass *priv_class;  ///< AVClass for the private
> context
>  const AVProfile *profiles;  ///< array of recognized
> profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN}
> +const enum AVColorRange *color_ranges;  ///< array of supported color
> ranges by encoder, or NULL if unknown, array is terminated by
> AVCOL_RANGE_UNSPECIFIED
>
>  /**
>   * Group name of the codec implementation.
> --
> 2.11.0
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

Ping? I think we should ignore koda's remarks and go through with this.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 5/5] avformat/mp3dec: require 90% of a file to be mp3 if only 1 mp3 frame is found in sequence

2018-05-12 Thread Aman Gupta
On Sat, May 12, 2018 at 9:33 AM, Michael Niedermayer  wrote:

> This eliminates several low score detections of non mp3 files
>

Thanks for working on this. Spurious mp3 detection has been a real headache.

Aman


>
> Signed-off-by: Michael Niedermayer 
> ---
>  libavformat/mp3dec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c
> index d419f8c9fe..ef884934e1 100644
> --- a/libavformat/mp3dec.c
> +++ b/libavformat/mp3dec.c
> @@ -112,7 +112,7 @@ static int mp3_read_probe(AVProbeData *p)
>  else if(ff_id3v2_match(buf0, ID3v2_DEFAULT_MAGIC) &&
> 2*ff_id3v2_tag_len(buf0) >= p->buf_size)
> return p->buf_size < PROBE_BUF_MAX ?
> AVPROBE_SCORE_EXTENSION / 4 : AVPROBE_SCORE_EXTENSION - 2;
>  else if(first_frames > 1 && whole_used) return 5;
> -else if(max_frames>=1 && p->buf_size < 2*max_framesizes) return 1;
> +else if(max_frames>=1 && p->buf_size < 10*max_framesizes) return 1;
>  else   return 0;
>  //mpegps_mp3_unrecognized_format.mpg has max_frames=3
>  }
> --
> 2.17.0
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 5/5] avformat/mp3dec: require 90% of a file to be mp3 if only 1 mp3 frame is found in sequence

2018-05-12 Thread Michael Niedermayer
This eliminates several low score detections of non mp3 files

Signed-off-by: Michael Niedermayer 
---
 libavformat/mp3dec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c
index d419f8c9fe..ef884934e1 100644
--- a/libavformat/mp3dec.c
+++ b/libavformat/mp3dec.c
@@ -112,7 +112,7 @@ static int mp3_read_probe(AVProbeData *p)
 else if(ff_id3v2_match(buf0, ID3v2_DEFAULT_MAGIC) && 
2*ff_id3v2_tag_len(buf0) >= p->buf_size)
return p->buf_size < PROBE_BUF_MAX ? 
AVPROBE_SCORE_EXTENSION / 4 : AVPROBE_SCORE_EXTENSION - 2;
 else if(first_frames > 1 && whole_used) return 5;
-else if(max_frames>=1 && p->buf_size < 2*max_framesizes) return 1;
+else if(max_frames>=1 && p->buf_size < 10*max_framesizes) return 1;
 else   return 0;
 //mpegps_mp3_unrecognized_format.mpg has max_frames=3
 }
-- 
2.17.0

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


[FFmpeg-devel] [PATCH 4/5] avformat/mp3dec: Require 50% of the file to be mp3 frames in the maxframes>200 probing test

2018-05-12 Thread Michael Niedermayer
This corrects several misdetections of large files

Signed-off-by: Michael Niedermayer 
---
 libavformat/mp3dec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c
index a26714ebaf..d419f8c9fe 100644
--- a/libavformat/mp3dec.c
+++ b/libavformat/mp3dec.c
@@ -107,7 +107,7 @@ static int mp3_read_probe(AVProbeData *p)
 // keep this in sync with ac3 probe, both need to avoid
 // issues with MPEG-files!
 if   (first_frames>=7) return AVPROBE_SCORE_EXTENSION + 1;
-else if(max_frames>200)return AVPROBE_SCORE_EXTENSION;
+else if(max_frames>200 && p->buf_size < 2*max_framesizes)return 
AVPROBE_SCORE_EXTENSION;
 else if(max_frames>=4 && p->buf_size < 2*max_framesizes) return 
AVPROBE_SCORE_EXTENSION / 2;
 else if(ff_id3v2_match(buf0, ID3v2_DEFAULT_MAGIC) && 
2*ff_id3v2_tag_len(buf0) >= p->buf_size)
return p->buf_size < PROBE_BUF_MAX ? 
AVPROBE_SCORE_EXTENSION / 4 : AVPROBE_SCORE_EXTENSION - 2;
-- 
2.17.0

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


[FFmpeg-devel] [PATCH 1/5] avformat/tty: Remove .txt from the extensions as it more likely is not a multimedia related file

2018-05-12 Thread Michael Niedermayer
Iam not sure if this is a good idea or not but it may make some
attacks harder. So throwing this out for discussions ...

Signed-off-by: Michael Niedermayer 
---
 libavformat/tty.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/tty.c b/libavformat/tty.c
index 8d48f2c45c..8067dd1908 100644
--- a/libavformat/tty.c
+++ b/libavformat/tty.c
@@ -155,6 +155,6 @@ AVInputFormat ff_tty_demuxer = {
 .priv_data_size = sizeof(TtyDemuxContext),
 .read_header= read_header,
 .read_packet= read_packet,
-.extensions = "ans,art,asc,diz,ice,nfo,txt,vt",
+.extensions = "ans,art,asc,diz,ice,nfo,vt",
 .priv_class = _demuxer_class,
 };
-- 
2.17.0

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


[FFmpeg-devel] [PATCH 3/5] avformat/mp3dec: Require probing data to be 50% mp3 frames for low score probing to succeed

2018-05-12 Thread Michael Niedermayer
This massively reduces the detection of random data as low score mp3
It may improve security by making it harder to read non multimedia data

Signed-off-by: Michael Niedermayer 
---
 libavformat/mp3dec.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c
index a76fe32e59..a26714ebaf 100644
--- a/libavformat/mp3dec.c
+++ b/libavformat/mp3dec.c
@@ -71,6 +71,7 @@ static int mp3_read_probe(AVProbeData *p)
 int max_frames, first_frames = 0;
 int whole_used = 0;
 int frames, ret;
+int framesizes, max_framesizes;
 uint32_t header;
 const uint8_t *buf, *buf0, *buf2, *end;
 
@@ -80,11 +81,12 @@ static int mp3_read_probe(AVProbeData *p)
 buf0++;
 
 max_frames = 0;
+max_framesizes = 0;
 buf = buf0;
 
 for(; buf < end; buf= buf2+1) {
 buf2 = buf;
-for(frames = 0; buf2 < end; frames++) {
+for(framesizes = frames = 0; buf2 < end; frames++) {
 MPADecodeHeader h;
 
 header = AV_RB32(buf2);
@@ -92,8 +94,10 @@ static int mp3_read_probe(AVProbeData *p)
 if (ret != 0)
 break;
 buf2 += h.frame_size;
+framesizes += h.frame_size;
 }
 max_frames = FFMAX(max_frames, frames);
+max_framesizes = FFMAX(max_framesizes, framesizes);
 if(buf == buf0) {
 first_frames= frames;
 if (buf2 == end + sizeof(uint32_t))
@@ -104,11 +108,11 @@ static int mp3_read_probe(AVProbeData *p)
 // issues with MPEG-files!
 if   (first_frames>=7) return AVPROBE_SCORE_EXTENSION + 1;
 else if(max_frames>200)return AVPROBE_SCORE_EXTENSION;
-else if(max_frames>=4 && max_frames >= p->buf_size/1) return 
AVPROBE_SCORE_EXTENSION / 2;
+else if(max_frames>=4 && p->buf_size < 2*max_framesizes) return 
AVPROBE_SCORE_EXTENSION / 2;
 else if(ff_id3v2_match(buf0, ID3v2_DEFAULT_MAGIC) && 
2*ff_id3v2_tag_len(buf0) >= p->buf_size)
return p->buf_size < PROBE_BUF_MAX ? 
AVPROBE_SCORE_EXTENSION / 4 : AVPROBE_SCORE_EXTENSION - 2;
 else if(first_frames > 1 && whole_used) return 5;
-else if(max_frames>=1 && max_frames >= p->buf_size/1) return 1;
+else if(max_frames>=1 && p->buf_size < 2*max_framesizes) return 1;
 else   return 0;
 //mpegps_mp3_unrecognized_format.mpg has max_frames=3
 }
-- 
2.17.0

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


[FFmpeg-devel] [PATCH 2/5] avformat/bintext: Reduce detection for random .bin files as it more likely is not a multimedia related file

2018-05-12 Thread Michael Niedermayer
Iam not sure if this is a good idea or not but it may make some
attacks harder. So throwing this out for discussions ...

Signed-off-by: Michael Niedermayer 
---
 libavformat/bintext.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/bintext.c b/libavformat/bintext.c
index f1c0b3e892..0b499d9555 100644
--- a/libavformat/bintext.c
+++ b/libavformat/bintext.c
@@ -163,7 +163,7 @@ static int bin_probe(AVProbeData *p)
 
 if (par.width * par.height * 2 / (8*16) == p->buf_size)
 return AVPROBE_SCORE_MAX / 2;
-return 1;
+return 0;
 }
 
 if (sauce)
-- 
2.17.0

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


Re: [FFmpeg-devel] [PATCH 1/2] avformat/dashenc: Added option for Segment file format

2018-05-12 Thread Jan Ekström
On Fri, May 4, 2018 at 9:32 AM, Karthick J  wrote:
> From: Karthick Jeyapal 
>
> Right now segment file format is chosen to be either mp4 or webm based on the 
> codec format.
> This patch makes that choice configurable by the user, instead of being 
> decided by the muxer.
> ---
>  doc/muxers.texi   |  8 
>  libavformat/dashenc.c | 48 ++--
>  2 files changed, 30 insertions(+), 26 deletions(-)
>

Hi,

Sorry for getting to this so late, been busy on various things (as
usual). Thanks for prodding me.

> diff --git a/doc/muxers.texi b/doc/muxers.texi
> index 6f03bba..2429f8e 100644
> --- a/doc/muxers.texi
> +++ b/doc/muxers.texi
> @@ -282,6 +282,14 @@ corrects that index value.
>  Typically this logic is needed in live streaming use cases. The network 
> bandwidth
>  fluctuations are common during long run streaming. Each fluctuation can cause
>  the segment indexes fall behind the expected real time position.
> +
> +@item dash_segment_type @var{dash_segment_type}
> +Possible values:
> +@item mp4
> +If this flag is set, the dash segment files will be in in ISOBMFF format. 
> This is the default format.
> +
> +@item webm
> +If this flag is set, the dash segment files will be in in WebM format.
>  @end table
>
>  @anchor{framecrc}
> diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
> index 1dd6333..412f074 100644
> --- a/libavformat/dashenc.c
> +++ b/libavformat/dashenc.c
> @@ -48,6 +48,11 @@
>  #include "vpcc.h"
>  #include "dash.h"
>
> +typedef enum {
> +SEGMENT_TYPE_MP4,
> +SEGMENT_TYPE_WEBM,
> +} SegmentType;
> +

Ah yes, an enum :) I really like the checks being equality/inequality
now. I've seen things like SEGMENT_TYPE_NB used for the stopper so
that in the AVOption you can then set the maximum to *_NB - 1 instead
of then having to change it if it ever gets anything added to it.

Maybe consider making something like the `codecs[]` array for formats
and make the thing in DASHContext as a char pointer, so that you can
just point the string pointer to its value in init() instead of doing
a run-time strncpy.

This does remove the "dynamicness" of  the per-stream selection, which
possibly should be mentioned. But at least personally I think this is
what people actually wanted with WebM vs ISOBMFF DASH selection ;) ,
as in not having surprises between streams.

Otherwise this patch generally looks alright, leaving just the segment
file name part not automatical just yet :) (I feel like we need to
have separate options for the general template and the extension).

Best regards,
Jan
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [RFC][PATCH] configure: Disable unsafe demuxers by default

2018-05-12 Thread Michael Niedermayer
On Fri, May 11, 2018 at 12:14:47AM +0100, Derek Buitenhuis wrote:
> > please correct me if iam wrong, theres quite a bit iam guessing here
> > IIUC the problem is that in your usecase
> > 1. ffmpeg has access to sensitive files
> > 2. one of these files can be opened by an attacker with ffmpeg
> > 2b. This involves the file being probed as a supported format
> 
> It is "probed" as file extension mostly. .txt is one of these
> extensions, which 99.999%
> of the time, is not a multimedia file, for example.
> 
> > 3. The file is then demuxed, decoded, encoded, muxed
> > 4. the result is given back to the attacker
> >
> > This patchset removes one of the demuxers involved in the attack
> 
> Not removed. Disabled. As discussed in other replies, making it manual
> also seems
> fine to me. Rendering arbitrary text files as images (as in, rendering
> the text using
> a built in font, to an image with that text in it) isn't exactly a
> great and secure default
> behavior, especially for the world's most commont text file extension...

Do you think a document converter should by default not allow to open
multimedia files and embed them into documents ?
(not saying i think it should or should not)

What you suggest is similar, a multimedia converter by default
(not) supporting reading documents.

You later in the mail compare this to ASLR, i dont think this is at
the same level. ASLR provides broad protection, disabling
the .txt/.bin demuxers (which btw does not prevent other demuxers to open
.txt/.bin files) does not seem to be a comparable feature.

Of course every time you disable a feature the attack surface decreases,
in that sense it makes sense to disable all unneeded features whenever
security matters.
Iam not sure we know what is "unneeded" to the end user.

also where are security relevant *.txt files ? i looked at my /etc
and there where none.


> 
> > The first problem of this patchset is that it does not provide any
> > evidence of how the other demuxers probe functions can trigger on
> > random text files.
> 
> ffmpeg -i something.txt a.png
> 
> But really, it is not necssarily an attack on its own (it could be),
> but it makes any
> other attack vastly easier to exploit. For example, that HLS stuff
> avformat had fixed
> last year could have pointed at various .txt files. I don't really
> understand why the
> concept of "rendering arbitrary text files as images" is not obviously bad?

as long as we support rawvideo input by default, disabling text input does
not gain much security. rawvideo is multimedia, noone suggested to disable
it.
The probing / extension based detection, yes changes there should be able
to gain some security and we should possibly tighten this down where theres
an agreement.

as i was curious i looked at my /etc/ and /etc/*/ and from
3580 files there are 929 matches for 'Probing .* score:'

  1 mpeg
  3 svg_pipe
  9 png_pipe
 10 bin
 12 image2
 25 mpegts
 39 lrc
830 mp3

and for 'probed with size|detected only with low score of'

  3 svg_pipe
  9 png_pipe
 24 mpegts
 29 lrc
161 mp3

from the stuff above, the svg and png are correct detected
  

From this it appears to me that file extension while its an issue is not
the only and based on this, not the biggest

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The real ebay dictionary, page 1
"Used only once"- "Some unspecified defect prevented a second use"
"In good condition" - "Can be repaird by experienced expert"
"As is" - "You wouldnt want it even if you were payed for it, if you knew ..."


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avfilter: add bm3d filter

2018-05-12 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 doc/filters.texi |   86 
 libavfilter/Makefile |1 +
 libavfilter/allfilters.c |1 +
 libavfilter/vf_bm3d.c| 1077 ++
 4 files changed, 1165 insertions(+)
 create mode 100644 libavfilter/vf_bm3d.c

diff --git a/doc/filters.texi b/doc/filters.texi
index afa3984447..d77c67eb10 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -5578,6 +5578,91 @@ tblend=all_mode=grainextract
 @end example
 @end itemize
 
+@section bm3d
+
+Denoise frames using BM3D algorithm.
+
+The filter accepts the following options.
+
+@table @option
+@item sigma
+Set denoising strength. Default value is 1.
+Allowed range is from 0 to 999.9.
+The denoising algorith is very sensitive to sigma, so adjust it
+according to the source.
+
+@item block
+Set local patch size. This sets dimensions in 2D.
+
+@item bstep
+Set sliding step for processing blocks. Default value is 4.
+Allowed range is from 1 to 64.
+Smaller values allows processing more reference blocks and is slower.
+
+@item group
+Set maximal number of similar blocks for 3rd dimension. Default value is 1.
+When set to 1, no block matching is done. Larger values allows more blocks
+in single group.
+Allowed range is from 1 to 256.
+
+@item range
+Set radius for search block matching. Default is 9.
+Allowed range is from 1 to INT32_MAX.
+
+@item mstep
+Set step between two search locations for block matching. Default is 1.
+Allowed range is from 1 to 64. Smaller is slower.
+
+@item thmse
+Set threshold of mean square error for block matching. Valid range is 0 to
+INT32_MAX.
+
+@item hdthr
+Set thresholding parameter for hard thresholding in 3D transformed domain.
+Larger values results in stronger hard-thresholding filtering in frequency
+domain.
+
+@item estim
+Set filtering estimation mode. Can be @code{basic} or @code{final}.
+Default is @code{basic}.
+
+@item ref
+If enabled, filter will use 2nd stream for block matching.
+Default is disabled for @code{basic} value of @var{estim} option,
+and always enabled if value of @var{estim} is @code{final}.
+
+@item planes
+Set planes to filter. Default is all available except alpha.
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Basic filtering with bm3d:
+@example
+bm3d=sigma=3:block=4:bstep=2:group=1:estim=basic
+@end example
+
+@item
+Same as above, but filtering only luma:
+@example
+bm3d=sigma=3:block=4:bstep=2:group=1:estim=basic:planes=1
+@end example
+
+@item
+Same as above, but with both estimation modes:
+@example
+split[a][b],[a]bm3d=sigma=3:block=4:bstep=2:group=1:estim=basic[a],[b][a]bm3d=sigma=3:block=4:bstep=2:group=16:estim=final:ref=1
+@end example
+
+@item
+Same as above, but prefilter with @ref{nlmeans} filter instead:
+@example
+split[a][b],[a]nlmeans=s=3:r=7:p=3[a],[b][a]bm3d=sigma=3:block=4:bstep=2:group=16:estim=final:ref=1
+@end example
+@end itemize
+
 @section boxblur
 
 Apply a boxblur algorithm to the input video.
@@ -11301,6 +11386,7 @@ Negate input video.
 It accepts an integer in input; if non-zero it negates the
 alpha component (if available). The default value in input is 0.
 
+@anchor{nlmeans}
 @section nlmeans
 
 Denoise frames using Non-Local Means algorithm.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 92f526a275..b2d6756e79 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -150,6 +150,7 @@ OBJS-$(CONFIG_BITPLANENOISE_FILTER)  += 
vf_bitplanenoise.o
 OBJS-$(CONFIG_BLACKDETECT_FILTER)+= vf_blackdetect.o
 OBJS-$(CONFIG_BLACKFRAME_FILTER) += vf_blackframe.o
 OBJS-$(CONFIG_BLEND_FILTER)  += vf_blend.o framesync.o
+OBJS-$(CONFIG_BM3D_FILTER)   += vf_bm3d.o
 OBJS-$(CONFIG_BOXBLUR_FILTER)+= vf_boxblur.o
 OBJS-$(CONFIG_BWDIF_FILTER)  += vf_bwdif.o
 OBJS-$(CONFIG_CHROMAKEY_FILTER)  += vf_chromakey.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index f3a76c4652..f28f6e47ee 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -143,6 +143,7 @@ extern AVFilter ff_vf_bitplanenoise;
 extern AVFilter ff_vf_blackdetect;
 extern AVFilter ff_vf_blackframe;
 extern AVFilter ff_vf_blend;
+extern AVFilter ff_vf_bm3d;
 extern AVFilter ff_vf_boxblur;
 extern AVFilter ff_vf_bwdif;
 extern AVFilter ff_vf_chromakey;
diff --git a/libavfilter/vf_bm3d.c b/libavfilter/vf_bm3d.c
new file mode 100644
index 00..4127149899
--- /dev/null
+++ b/libavfilter/vf_bm3d.c
@@ -0,0 +1,1077 @@
+/*
+ * Copyright (c) 2015-2016 mawen1250
+ * Copyright (c) 2018 Paul B Mahol
+ *
+ * This file is part of FFmpeg.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * 

[FFmpeg-devel] [PATCH] lavc/amfenc: moving amf common code (library and context) to lavu/hwcontext_amf from amfenc to be reused in other amf components

2018-05-12 Thread Alexander Kravchenko
This patch moves AMF common parts from amfenc to hwcontext_amf.
Now av_hwdevice_ctx API is used for AMF context creation/destroying.
This patch does not change component behaviour.
it contains only restructurization for further patches with new amf components

---
Sending updated patch based on Mark's review
1) simplificated library loading/unloading logic
2) minor fixes


 libavcodec/amfenc.c| 247 +---
 libavcodec/amfenc.h|  27 +
 libavutil/Makefile |   2 +
 libavutil/hwcontext.c  |   4 +
 libavutil/hwcontext.h  |   1 +
 libavutil/hwcontext_amf.c  | 252 +
 libavutil/hwcontext_amf.h  |  43 +++
 libavutil/hwcontext_internal.h |   1 +
 8 files changed, 338 insertions(+), 239 deletions(-)
 create mode 100644 libavutil/hwcontext_amf.c
 create mode 100644 libavutil/hwcontext_amf.h

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 384d8efc92..4c907ca3bc 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -21,13 +21,7 @@
 #include "libavutil/avassert.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/hwcontext.h"
-#if CONFIG_D3D11VA
-#include "libavutil/hwcontext_d3d11va.h"
-#endif
-#if CONFIG_DXVA2
-#define COBJMACROS
-#include "libavutil/hwcontext_dxva2.h"
-#endif
+
 #include "libavutil/mem.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/time.h"
@@ -35,14 +29,12 @@
 #include "amfenc.h"
 #include "internal.h"
 
-#if CONFIG_D3D11VA
-#include 
+#if CONFIG_DXVA2
+#include 
 #endif
 
-#ifdef _WIN32
-#include "compat/w32dlfcn.h"
-#else
-#include 
+#if CONFIG_D3D11VA
+#include 
 #endif
 
 #define FFMPEG_AMF_WRITER_ID L"ffmpeg_amf"
@@ -88,34 +80,18 @@ static enum AMF_SURFACE_FORMAT amf_av_to_amf_format(enum 
AVPixelFormat fmt)
 return AMF_SURFACE_UNKNOWN;
 }
 
-static void AMF_CDECL_CALL AMFTraceWriter_Write(AMFTraceWriter *pThis,
-const wchar_t *scope, const wchar_t *message)
-{
-AmfTraceWriter *tracer = (AmfTraceWriter*)pThis;
-av_log(tracer->avctx, AV_LOG_DEBUG, "%ls: %ls", scope, message); // \n is 
provided from AMF
-}
-
-static void AMF_CDECL_CALL AMFTraceWriter_Flush(AMFTraceWriter *pThis)
-{
-}
 
-static AMFTraceWriterVtbl tracer_vtbl =
-{
-.Write = AMFTraceWriter_Write,
-.Flush = AMFTraceWriter_Flush,
-};
-
-static int amf_load_library(AVCodecContext *avctx)
+static int amf_init_context(AVCodecContext *avctx)
 {
-AmfContext*ctx = avctx->priv_data;
-AMFInit_Fn init_fun;
-AMFQueryVersion_Fn version_fun;
-AMF_RESULT res;
+AmfContext *ctx = avctx->priv_data;
+AVAMFDeviceContext *amf_ctx;
+int ret;
 
 ctx->delayed_frame = av_frame_alloc();
 if (!ctx->delayed_frame) {
 return AVERROR(ENOMEM);
 }
+
 // hardcoded to current HW queue size - will realloc in 
timestamp_queue_enqueue() if too small
 ctx->timestamp_list = av_fifo_alloc((avctx->max_b_frames + 16) * 
sizeof(int64_t));
 if (!ctx->timestamp_list) {
@@ -123,119 +99,9 @@ static int amf_load_library(AVCodecContext *avctx)
 }
 ctx->dts_delay = 0;
 
-
-ctx->library = dlopen(AMF_DLL_NAMEA, RTLD_NOW | RTLD_LOCAL);
-AMF_RETURN_IF_FALSE(ctx, ctx->library != NULL,
-AVERROR_UNKNOWN, "DLL %s failed to open\n", AMF_DLL_NAMEA);
-
-init_fun = (AMFInit_Fn)dlsym(ctx->library, AMF_INIT_FUNCTION_NAME);
-AMF_RETURN_IF_FALSE(ctx, init_fun != NULL, AVERROR_UNKNOWN, "DLL %s failed 
to find function %s\n", AMF_DLL_NAMEA, AMF_INIT_FUNCTION_NAME);
-
-version_fun = (AMFQueryVersion_Fn)dlsym(ctx->library, 
AMF_QUERY_VERSION_FUNCTION_NAME);
-AMF_RETURN_IF_FALSE(ctx, version_fun != NULL, AVERROR_UNKNOWN, "DLL %s 
failed to find function %s\n", AMF_DLL_NAMEA, AMF_QUERY_VERSION_FUNCTION_NAME);
-
-res = version_fun(>version);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with 
error %d\n", AMF_QUERY_VERSION_FUNCTION_NAME, res);
-res = init_fun(AMF_FULL_VERSION, >factory);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with 
error %d\n", AMF_INIT_FUNCTION_NAME, res);
-res = ctx->factory->pVtbl->GetTrace(ctx->factory, >trace);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetTrace() 
failed with error %d\n", res);
-res = ctx->factory->pVtbl->GetDebug(ctx->factory, >debug);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetDebug() 
failed with error %d\n", res);
-return 0;
-}
-
-#if CONFIG_D3D11VA
-static int amf_init_from_d3d11_device(AVCodecContext *avctx, 
AVD3D11VADeviceContext *hwctx)
-{
-AmfContext *ctx = avctx->priv_data;
-AMF_RESULT res;
-
-res = ctx->context->pVtbl->InitDX11(ctx->context, hwctx->device, 
AMF_DX11_1);
-if (res != AMF_OK) {
-if (res == AMF_NOT_SUPPORTED)
-av_log(avctx, AV_LOG_ERROR, "AMF via D3D11 is not supported on the 
given device.\n");
-else
-av_log(avctx, AV_LOG_ERROR, "AMF failed 

Re: [FFmpeg-devel] [PATCH] avfilter: add bm3d filter

2018-05-12 Thread Paul B Mahol
On 5/12/18, Michael Niedermayer  wrote:
> On Fri, May 11, 2018 at 04:03:07PM +0200, Paul B Mahol wrote:
>> Signed-off-by: Paul B Mahol 
>> ---
>>  libavfilter/Makefile |1 +
>>  libavfilter/allfilters.c |1 +
>>  libavfilter/vf_bm3d.c| 1002
>> ++
>>  3 files changed, 1004 insertions(+)
>>  create mode 100644 libavfilter/vf_bm3d.c
> [...]
>> +static void block_matching_multi(BM3DContext *s, const uint8_t *ref, int
>> ref_linesize, int y, int x,
>> + int exclude_cur_pos, int plane)
>> +{
>> +const int width = s->planewidth[plane];
>> +const int height = s->planeheight[plane];
>> +const int block_size = s->block_size;
>> +const int step = s->bm_step;
>> +const int range = s->bm_range / step * step;
>> +int l = search_boundary(0, range, step, 0, y, x);
>> +int r = search_boundary(width - block_size, range, step, 0, y, x);
>> +int t = search_boundary(0, range, step, 1, y, x);
>> +int b = search_boundary(height - block_size, range, step, 1, y, x);
>> +int j, i, index = 0;
>> +
>> +PosCode search_pos[((r - l) / step + 1) * ((b - t) / step + 1)];
>
> fails to build here:
>
> src/libavfilter/vf_bm3d.c: In function `block_matching_multi':
> src/libavfilter/vf_bm3d.c:308:5: error: variable length array `search_pos'
> is used [-Werror=vla]
>  PosCode search_pos[((r - l) / step + 1) * ((b - t) / step + 1)];
>  ^

Come on! Your compiler still live under the rock, doesn't it?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel